Skip to content

Commit 8f2184e

Browse files
author
diptorupd
committed
Changes to C API build scripts to allow using the open source dpcpp compiler.
- FindDPCPP.cmake is now renamed to FindIntelSycl.cmake. - llvm-cov and llvm-profdata now have their own cmake modules and the minimum version required is 11.0.0 for these tools. - CMAKE_C_COMPILER and CMAKE_CXX_COMPILER are now set by the FindIntelSycl.cmake module and do not need to be set manually. - A new CMAKE flag DPCTL_CUSTOM_DPCPP_INSTALL_DIR is now available that makes it possible to build the DPCTLSyclInterface with a custom dpcpp compiler. - Formatting changes to CMakeLists.txt files. - A new helper script to build the DPCTLSyclInterface library using a custom dpcpp.
1 parent d97e466 commit 8f2184e

File tree

11 files changed

+495
-241
lines changed

11 files changed

+495
-241
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ installed:
5050
- `cmake` - for building C API
5151
- `ninja` - only on Windows
5252

53-
Activate DPC++ compiler:
53+
You need DPC++ to build dpctl. If you want to build using the DPC++ in a
54+
oneAPI distribution, activate DPC++ compiler as follows:
5455
```bash
5556
export ONEAPI_ROOT=/opt/intel/oneapi
5657
source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh

dpctl-capi/CMakeLists.txt

Lines changed: 79 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
22
project("dpctl C API - A C wrapper for a subset of SYCL")
33

4+
option(DPCTL_CUSTOM_DPCPP_INSTALL_DIR
5+
"Use a custom version of DPCPP installed at the provided location."
6+
OFF
7+
)
48
# Option to turn on support for creating Level Zero interoperability programs
59
# from a SPIR-V binary file.
610
option(DPCTL_ENABLE_LO_PROGRAM_CREATION
@@ -25,7 +29,13 @@ option(DPCTL_BUILD_CAPI_TESTS
2529

2630
# Load our CMake modules to search for DPCPP and Level Zero
2731
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
28-
find_package(DPCPP 2021.2.0 REQUIRED)
32+
33+
# Minimum version requirement only when oneAPI dpcpp is used.
34+
if(DPCTL_CUSTOM_DPCPP_INSTALL_DIR)
35+
find_package(IntelSycl REQUIRED)
36+
else()
37+
find_package(IntelSycl 2021.2.0 REQUIRED)
38+
endif()
2939

3040
if(DPCTL_ENABLE_LO_PROGRAM_CREATION)
3141
set(DPCTL_ENABLE_LO_PROGRAM_CREATION 1)
@@ -35,28 +45,68 @@ endif()
3545
configure_file(${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h.in
3646
${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h)
3747

48+
# Set the C++ standard to C++17
49+
set(CMAKE_CXX_STANDARD 17)
50+
51+
# These variables are set inside FindIntelSycl.cmake
52+
set(CMAKE_C_COMPILER ${IntelSycl_C_COMPILER})
53+
set(CMAKE_CXX_COMPILER ${IntelSycl_CXX_COMPILER})
54+
3855
if(WIN32)
39-
set(CMAKE_CXX_COMPILER:PATH "${DPCPP_ROOT}/bin/dpcpp")
40-
set(CMAKE_C_COMPILER:PATH "${DPCPP_ROOT}/bin/clang-cl")
41-
set(CMAKE_LINKER:PATH "${DPCPP_ROOT}/bin/lld-link")
42-
message(STATUS "Resetting CXX compiler to: " ${CMAKE_CXX_COMPILER})
43-
message(STATUS "Resetting C compiler to: " ${CMAKE_C_COMPILER})
44-
message(STATUS "Resetting Linker to: " ${CMAKE_LINKER})
45-
set(WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations")
56+
string(CONCAT WARNING_FLAGS
57+
"-Wall "
58+
"-Wextra "
59+
"-Winit-self "
60+
"-Wunused-function "
61+
"-Wuninitialized "
62+
"-Wmissing-declarations "
63+
)
4664
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")
47-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} -Qstd=c++17")
48-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG")
49-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG -Qstd=c++17")
65+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
66+
set(CMAKE_C_FLAGS_DEBUG
67+
"${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG"
68+
)
69+
set(CMAKE_CXX_FLAGS_DEBUG
70+
"${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG"
71+
)
5072
elseif(UNIX)
51-
set(CMAKE_CXX_COMPILER:PATH "${DPCPP_ROOT}/bin/dpcpp")
52-
set(CMAKE_C_COMPILER:PATH "${DPCPP_ROOT}/bin/clang")
53-
set(CMAKE_LINKER:PATH "${DPCPP_ROOT}/bin/lld")
54-
set(SDL_FLAGS "-fstack-protector -fstack-protector-all -fpic -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -fno-strict-overflow -fno-delete-null-pointer-checks")
55-
set(WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations -fdiagnostics-color=auto")
56-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${SDL_FLAGS}")
57-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${SDL_FLAGS} -std=c++17 -fsycl")
58-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG")
59-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG -std=c++17 -fsycl")
73+
string(CONCAT WARNING_FLAGS
74+
"-Wall "
75+
"-Wextra "
76+
"-Winit-self "
77+
"-Wunused-function "
78+
"-Wuninitialized "
79+
"-Wmissing-declarations "
80+
"-fdiagnostics-color=auto "
81+
)
82+
string(CONCAT SDL_FLAGS
83+
"-fstack-protector "
84+
"-fstack-protector-all "
85+
"-fpic "
86+
"-fPIC "
87+
"-D_FORTIFY_SOURCE=2 "
88+
"-Wformat "
89+
"-Wformat-security "
90+
"-fno-strict-overflow "
91+
"-fno-delete-null-pointer-checks "
92+
)
93+
string(CONCAT CFLAGS
94+
"${WARNING_FLAGS}"
95+
"${SDL_FLAGS}"
96+
)
97+
string(CONCAT CXXFLAGS
98+
"${WARNING_FLAGS}"
99+
"${SDL_FLAGS}"
100+
"-fsycl "
101+
)
102+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAGS}")
103+
set(CMAKE_CXX_FLAGS "${CXXFLAGS}")
104+
set(CMAKE_C_FLAGS_DEBUG
105+
"${CMAKE_C_FLAGS_DEBUG} ${CFLAGS} -ggdb3 -DDEBUG"
106+
)
107+
set(CMAKE_CXX_FLAGS_DEBUG
108+
"${CMAKE_CXX_FLAGS_DEBUG} ${CXXFLAGS} -ggdb3 -DDEBUG"
109+
)
60110
else()
61111
message(FATAL_ERROR "Unsupported system.")
62112
endif()
@@ -85,12 +135,12 @@ target_include_directories(DPCTLSyclInterface
85135
PRIVATE
86136
${CMAKE_SOURCE_DIR}/include/
87137
${CMAKE_SOURCE_DIR}/helper/include/
88-
${DPCPP_SYCL_INCLUDE_DIR}
138+
${IntelSycl_SYCL_INCLUDE_DIR}
89139
)
90140

91141
target_link_libraries(DPCTLSyclInterface
92-
PRIVATE ${DPCPP_SYCL_LIBRARY}
93-
PRIVATE ${DPCPP_OPENCL_LIBRARY}
142+
PRIVATE ${IntelSycl_SYCL_LIBRARY}
143+
PRIVATE ${IntelSycl_OPENCL_LIBRARY}
94144
)
95145

96146
if(DPCTL_ENABLE_LO_PROGRAM_CREATION)
@@ -132,16 +182,14 @@ endforeach()
132182

133183
# Enable code coverage related settings
134184
if(DPCTL_GENERATE_COVERAGE)
135-
# check if llvm-cov and lcov are available
185+
# check if lcov is available
136186
find_package(Lcov REQUIRED)
137-
# These flags are set inside FindDPCPP
138-
if(NOT (${LLVM_COV_FOUND} AND ${LLVM_PROFDATA_FOUND}))
139-
message(FATAL_ERROR
140-
"llvm-cov and llvm-profdata are needed to generate coverage."
141-
)
142-
endif()
187+
# check if llvm-cov version 11 is available
188+
find_package(LLVMCov 11 REQUIRED)
189+
# check if llvm-profdata is available
190+
find_package(LLVMProfdata REQUIRED)
143191
# Turn on DPCTL_BUILD_CAPI_TESTS as building tests is needed to generate
144-
# coverage reports
192+
# coverage reports.
145193
set(DPCTL_BUILD_CAPI_TESTS "ON")
146194
if(DPCTL_COVERAGE_REPORT_OUTPUT_DIR)
147195
set(COVERAGE_OUTPUT_DIR ${DPCTL_COVERAGE_REPORT_OUTPUT_DIR})

dpctl-capi/cmake/modules/FindDPCPP.cmake

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)