Skip to content

Commit d227ab9

Browse files
author
Diptorup Deb
authored
Merge pull request #319 from diptorupd/build_system_fixes
C API build script improvements to build dpctl with a custom DPC++ and other changes
2 parents a317220 + b7bd9b9 commit d227ab9

16 files changed

+710
-281
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: 106 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
2-
project("dpctl C API - A C wrapper for a subset of SYCL")
32

3+
# Load our CMake modules to search for DPCPP and Level Zero
4+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
5+
find_package(Git REQUIRED)
6+
include(GetProjectVersion)
7+
# the get_version function is defined in the GetProjectVersion module and
8+
# defines: VERSION, SEMVER, MAJOR, MINOR, PATCH. These variables are populated
9+
# by parsing the output of git describe.
10+
get_version()
11+
project(
12+
"libDPCTLSYCLInterface"
13+
DESCRIPTION "A C API for a subset of SYCL"
14+
)
15+
16+
option(DPCTL_CUSTOM_DPCPP_INSTALL_DIR
17+
"Use a custom version of DPCPP installed at the provided location."
18+
OFF
19+
)
420
# Option to turn on support for creating Level Zero interoperability programs
521
# from a SPIR-V binary file.
622
option(DPCTL_ENABLE_LO_PROGRAM_CREATION
@@ -23,40 +39,82 @@ option(DPCTL_BUILD_CAPI_TESTS
2339
OFF
2440
)
2541

26-
# Load our CMake modules to search for DPCPP and Level Zero
27-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
28-
find_package(DPCPP 2021.2.0 REQUIRED)
42+
# Minimum version requirement only when oneAPI dpcpp is used.
43+
if(DPCTL_CUSTOM_DPCPP_INSTALL_DIR)
44+
find_package(IntelSycl REQUIRED)
45+
else()
46+
find_package(IntelSycl 2021.2.0 REQUIRED)
47+
endif()
2948

3049
if(DPCTL_ENABLE_LO_PROGRAM_CREATION)
3150
set(DPCTL_ENABLE_LO_PROGRAM_CREATION 1)
32-
find_package(LevelZero REQUIRED)
51+
include(GetLevelZeroHeaders)
52+
get_level_zero_headers()
3353
endif()
3454

35-
configure_file(${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h.in
36-
${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h)
55+
configure_file(
56+
${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h.in
57+
${CMAKE_SOURCE_DIR}/include/Config/dpctl_config.h
58+
)
59+
60+
# Set the C++ standard to C++17
61+
set(CMAKE_CXX_STANDARD 17)
3762

3863
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")
64+
string(CONCAT WARNING_FLAGS
65+
"-Wall "
66+
"-Wextra "
67+
"-Winit-self "
68+
"-Wunused-function "
69+
"-Wuninitialized "
70+
"-Wmissing-declarations "
71+
)
4672
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")
73+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
74+
set(CMAKE_C_FLAGS_DEBUG
75+
"${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG"
76+
)
77+
set(CMAKE_CXX_FLAGS_DEBUG
78+
"${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG"
79+
)
5080
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")
81+
string(CONCAT WARNING_FLAGS
82+
"-Wall "
83+
"-Wextra "
84+
"-Winit-self "
85+
"-Wunused-function "
86+
"-Wuninitialized "
87+
"-Wmissing-declarations "
88+
"-fdiagnostics-color=auto "
89+
)
90+
string(CONCAT SDL_FLAGS
91+
"-fstack-protector "
92+
"-fstack-protector-all "
93+
"-fpic "
94+
"-fPIC "
95+
"-D_FORTIFY_SOURCE=2 "
96+
"-Wformat "
97+
"-Wformat-security "
98+
"-fno-strict-overflow "
99+
"-fno-delete-null-pointer-checks "
100+
)
101+
string(CONCAT CFLAGS
102+
"${WARNING_FLAGS}"
103+
"${SDL_FLAGS}"
104+
)
105+
string(CONCAT CXXFLAGS
106+
"${WARNING_FLAGS}"
107+
"${SDL_FLAGS}"
108+
"-fsycl "
109+
)
110+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CFLAGS}")
111+
set(CMAKE_CXX_FLAGS "${CXXFLAGS}")
112+
set(CMAKE_C_FLAGS_DEBUG
113+
"${CMAKE_C_FLAGS_DEBUG} ${CFLAGS} -ggdb3 -DDEBUG"
114+
)
115+
set(CMAKE_CXX_FLAGS_DEBUG
116+
"${CMAKE_CXX_FLAGS_DEBUG} ${CXXFLAGS} -ggdb3 -DDEBUG"
117+
)
60118
else()
61119
message(FATAL_ERROR "Unsupported system.")
62120
endif()
@@ -85,31 +143,30 @@ target_include_directories(DPCTLSyclInterface
85143
PRIVATE
86144
${CMAKE_SOURCE_DIR}/include/
87145
${CMAKE_SOURCE_DIR}/helper/include/
88-
${DPCPP_SYCL_INCLUDE_DIR}
146+
${IntelSycl_SYCL_INCLUDE_DIR}
89147
)
90148

91149
target_link_libraries(DPCTLSyclInterface
92-
PRIVATE ${DPCPP_SYCL_LIBRARY}
93-
PRIVATE ${DPCPP_OPENCL_LIBRARY}
150+
PRIVATE ${IntelSycl_SYCL_LIBRARY}
151+
PRIVATE ${IntelSycl_OPENCL_LIBRARY}
94152
)
95153

96154
if(DPCTL_ENABLE_LO_PROGRAM_CREATION)
97-
if(UNIX)
98-
target_include_directories(DPCTLSyclInterface
99-
PRIVATE
100-
${LEVEL_ZERO_INCLUDE_DIR}
101-
)
102-
else()
103-
message(WARNING
104-
"DPCTL support Level Zero program creation not supported "
105-
"on this system."
106-
)
107-
endif()
155+
target_include_directories(DPCTLSyclInterface
156+
PRIVATE
157+
${LEVEL_ZERO_INCLUDE_DIR}
158+
)
108159
endif()
109160

110-
install(
111-
TARGETS DPCTLSyclInterface
112-
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/
161+
# NOTE: Till we hit 1.0.0 we will keep using the MINOR version to set the API
162+
# version of the library.
163+
set_target_properties(DPCTLSyclInterface PROPERTIES VERSION ${VERSION_MINOR})
164+
set_target_properties(DPCTLSyclInterface PROPERTIES SOVERSION 1)
165+
166+
install(TARGETS
167+
DPCTLSyclInterface
168+
LIBRARY
169+
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/
113170
)
114171

115172
# Install all headers
@@ -132,16 +189,14 @@ endforeach()
132189

133190
# Enable code coverage related settings
134191
if(DPCTL_GENERATE_COVERAGE)
135-
# check if llvm-cov and lcov are available
192+
# check if lcov is available
136193
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()
194+
# check if llvm-cov version 11 is available
195+
find_package(LLVMCov 11 REQUIRED)
196+
# check if llvm-profdata is available
197+
find_package(LLVMProfdata REQUIRED)
143198
# Turn on DPCTL_BUILD_CAPI_TESTS as building tests is needed to generate
144-
# coverage reports
199+
# coverage reports.
145200
set(DPCTL_BUILD_CAPI_TESTS "ON")
146201
if(DPCTL_COVERAGE_REPORT_OUTPUT_DIR)
147202
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)