1
1
cmake_minimum_required (VERSION 3.10 FATAL_ERROR )
2
- project ("dpCtl - A lightweight SYCL wrapper for Python " )
2
+ project ("dpCtl C API - A C wrapper for a subset of SYCL " )
3
3
4
- # The function checks is DPCPP_ROOT is valid and points to a dpcpp installation
5
- function (check_for_dpcpp )
6
- string (COMPARE EQUAL "${DPCPP_ROOT} " "" no_dpcpp_root )
7
- if (${no_dpcpp_root} )
8
- message (FATAL_ERROR "Set the DPCPP_ROOT argument providing the path to \
9
- a dpcpp installation." )
10
- endif ()
11
-
12
- if (WIN32 )
13
- set (dpcpp_cmd "${DPCPP_ROOT} /bin/dpcpp" )
14
- set (dpcpp_arg "--version" )
15
- elseif (UNIX )
16
- set (dpcpp_cmd "${DPCPP_ROOT} /bin/dpcpp" )
17
- set (dpcpp_arg "--version" )
18
- else ()
19
- message (FATAL_ERROR "Unsupported system." )
20
- endif ()
4
+ # Option to turn on support for creating Level Zero interoperability programs
5
+ # from a SPIR-V binary file.
6
+ option (DPCTL_ENABLE_LO_PROGRAM_CREATION
7
+ "Enable Level Zero Program creation from SPIR-V"
8
+ OFF
9
+ )
10
+ # Option to generate code coverage report using llvm-cov and lcov.
11
+ option (DPCTL_GENERATE_COVERAGE
12
+ "Build dpctl C API with coverage instrumentation instrumentation"
13
+ OFF
14
+ )
15
+ # Option to output html coverage report at a specific location.
16
+ option (DPCTL_COVERAGE_REPORT_OUTPUT_DIR
17
+ "Save the generated lcov html report to the specified location"
18
+ OFF
19
+ )
20
+ # Option to build the Gtests for dpctl C API
21
+ option (DPCTL_BUILD_CAPI_TESTS
22
+ "Build dpctl C API google tests"
23
+ OFF
24
+ )
21
25
22
- # Check if dpcpp is available
23
- execute_process (
24
- COMMAND ${dpcpp_cmd} ${dpcpp_arg}
25
- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
26
- RESULT_VARIABLE dpcpp_result
27
- OUTPUT_VARIABLE dpcpp_ver
28
- )
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 REQUIRED )
29
29
30
- if (${dpcpp_result} MATCHES "0" )
31
- string (REPLACE "\n " ";" DPCPP_VERSION_LIST "${dpcpp_ver} " )
32
- list (GET DPCPP_VERSION_LIST 0 dpcpp_ver_line )
33
- foreach (X ${DPCPP_VERSION_LIST} )
34
- message (STATUS "dpcpp ver[${dpcpp_result} ]: ${X} " )
35
- endforeach ()
36
- else ()
37
- message (FATAL_ERROR "DPCPP needed to build dpctl_sycl_interface" )
38
- endif ()
39
- endfunction ()
30
+ if (DPCTL_ENABLE_LO_PROGRAM_CREATION )
31
+ set (DPCTL_ENABLE_LO_PROGRAM_CREATION 1 )
32
+ find_package (LevelZero REQUIRED )
33
+ endif ()
40
34
41
- # Check for dpcpp in the specified DPCPP_ROOT
42
- check_for_dpcpp ( )
35
+ configure_file ( ${CMAKE_SOURCE_DIR} /include/Config/dpctl_config.h.in
36
+ ${CMAKE_SOURCE_DIR} /include/Config/dpctl_config.h )
43
37
44
38
if (WIN32 )
45
39
set (CMAKE_CXX_COMPILER :PATH "${DPCPP_ROOT} /bin/dpcpp" )
@@ -54,6 +48,9 @@ if(WIN32)
54
48
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG" )
55
49
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG -Qstd=c++17" )
56
50
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" )
57
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" )
58
55
set (WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations -fdiagnostics-color=auto" )
59
56
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${SDL_FLAGS} " )
@@ -80,30 +77,29 @@ add_library(
80
77
helper/source/dpctl_utils_helper.cpp
81
78
)
82
79
83
- # Install DPCTLSyclInterface
84
- target_include_directories (
85
- DPCTLSyclInterface
86
- PRIVATE
87
- ${CMAKE_SOURCE_DIR} /include/
88
- ${CMAKE_SOURCE_DIR} /helper/include/
80
+ target_include_directories (DPCTLSyclInterface
81
+ PRIVATE
82
+ ${CMAKE_SOURCE_DIR} /include/
83
+ ${CMAKE_SOURCE_DIR} /helper/include/
84
+ ${DPCPP_SYCL_INCLUDE_DIR}
85
+ )
86
+ target_link_libraries (DPCTLSyclInterface
87
+ PRIVATE ${DPCPP_SYCL_LIBRARY}
88
+ PRIVATE ${DPCPP_OPENCL_LIBRARY}
89
89
)
90
90
91
- if (WIN32 )
92
- message (
93
- STATUS
94
- "SYCL_INCLUDE_DIR: "
95
- ${DPCPP_ROOT} /include/sycl
96
- )
97
- target_include_directories (
98
- DPCTLSyclInterface
99
- PUBLIC
100
- ${DPCPP_ROOT} /include/sycl
101
- )
102
- target_link_libraries (
103
- DPCTLSyclInterface
104
- PRIVATE ${DPCPP_ROOT} /lib/sycl.lib
105
- PRIVATE ${DPCPP_ROOT} /lib/OpenCL.lib
106
- )
91
+ if (DPCTL_ENABLE_LO_PROGRAM_CREATION )
92
+ if (UNIX )
93
+ target_include_directories (DPCTLSyclInterface
94
+ PRIVATE
95
+ ${LEVEL_ZERO_INCLUDE_DIR}
96
+ )
97
+ else ()
98
+ message (WARNING
99
+ "DPCTL support Level Zero program creation not supported "
100
+ "on this system."
101
+ )
102
+ endif ()
107
103
endif ()
108
104
109
105
install (
@@ -114,34 +110,46 @@ install(
114
110
)
115
111
116
112
# Install all headers
117
- file (GLOB HEADERS "${CMAKE_SOURCE_DIR} /include/*.h* " )
113
+ file (GLOB HEADERS "${CMAKE_SOURCE_DIR} /include/*.h" )
118
114
foreach (HEADER ${HEADERS} )
119
115
install (FILES "${HEADER} " DESTINATION include )
120
116
endforeach ()
121
117
122
118
# Install all headers in include/Support
123
- file (GLOB HEADERS "${CMAKE_SOURCE_DIR} /include/Support/*.h* " )
119
+ file (GLOB HEADERS "${CMAKE_SOURCE_DIR} /include/Support/*.h" )
124
120
foreach (HEADER ${HEADERS} )
125
121
install (FILES "${HEADER} " DESTINATION include /Support )
126
122
endforeach ()
127
123
128
- # Install all headers in helper/ include
129
- file (GLOB HEADERS "${CMAKE_SOURCE_DIR} /helper/ include/*.h* " )
124
+ # Install all headers in include/Config
125
+ file (GLOB HEADERS "${CMAKE_SOURCE_DIR} /include/Config/ *.h" )
130
126
foreach (HEADER ${HEADERS} )
131
- install (FILES "${HEADER} " DESTINATION helper/ include )
127
+ install (FILES "${HEADER} " DESTINATION include /Config )
132
128
endforeach ()
133
129
134
- option (
135
- BUILD_CAPI_TESTS
136
- "Build dpctl C API google tests"
137
- OFF
138
- )
130
+ # Enable code coverage related settings
131
+ if (DPCTL_GENERATE_COVERAGE )
132
+ # check if llvm-cov and lcov are available
133
+ find_package (Lcov REQUIRED )
134
+ # These flags are set inside FindDPCPP
135
+ if (NOT (${LLVM_COV_FOUND} AND ${LLVM_PROFDATA_FOUND} ))
136
+ message (FATAL_ERROR
137
+ "llvm-cov and llvm-profdata are needed to generate coverage."
138
+ )
139
+ endif ()
140
+ # Turn on DPCTL_BUILD_CAPI_TESTS as building tests is needed to generate
141
+ # coverage reports
142
+ set (DPCTL_BUILD_CAPI_TESTS "ON" )
143
+ if (DPCTL_COVERAGE_REPORT_OUTPUT_DIR )
144
+ set (COVERAGE_OUTPUT_DIR ${DPCTL_COVERAGE_REPORT_OUTPUT_DIR} )
145
+ message (STATUS "Coverage reports to be saved at ${COVERAGE_OUTPUT_DIR} " )
146
+ else ()
147
+ set (COVERAGE_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} )
148
+ message (STATUS "Coverage reports to be saved at ${COVERAGE_OUTPUT_DIR} " )
149
+ endif ()
150
+ endif ()
139
151
140
- # Enable to build the dpCtl backend test cases
141
- if (BUILD_CAPI_TESTS )
152
+ # Add sub-directory to build the dpCtl C API test cases
153
+ if (DPCTL_BUILD_CAPI_TESTS )
142
154
add_subdirectory (tests )
143
155
endif ()
144
-
145
-
146
- # Todo : Add build rules for doxygen
147
- # maybe refer https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/
0 commit comments