1
1
#
2
- # Modifications, Copyright (C) 2021 Intel Corporation
2
+ # Modifications, Copyright (C) 2022 Intel Corporation
3
3
#
4
4
# This software and the related documents are Intel copyrighted materials, and
5
5
# your use of them is governed by the express license under which they were
15
15
# file Copyright.txt or https://cmake.org/licensing for details.
16
16
17
17
#[=======================================================================[.rst:
18
- IntelDPCPPConfig
18
+ IntelSYCLConfig
19
19
-------
20
20
21
- DPCPP Library to verify DPCPP/ SYCL compatability of CMAKE_CXX_COMPILER
21
+ Library to verify SYCL compatability of CMAKE_CXX_COMPILER
22
22
and passes relevant compiler flags.
23
23
24
24
Result Variables
25
25
^^^^^^^^^^^^^^^^
26
26
27
27
This will define the following variables:
28
28
29
- ``IntelDPCPP_FOUND ``
30
- True if the system has the DPCPP library.
29
+ ``IntelSYCL_FOUND ``
30
+ True if the system has the SYCL library.
31
31
``SYCL_LANGUAGE_VERSION``
32
32
The SYCL language spec version by Compiler.
33
33
``SYCL_INCLUDE_DIR``
@@ -37,35 +37,39 @@ This will define the following variables:
37
37
``SYCL_FLAGS``
38
38
SYCL specific flags for the compiler.
39
39
40
+ ``IntelSYCL::SYCL_CXX``
41
+ Target for using Intel SYCL (DPC++). The following properties are defined
42
+ for the target: ``INTERFACE_COMPILE_OPTIONS``, ``INTERFACE_LINK_OPTIONS``,
43
+ ``INTERFACE_INCLUDE_DIRECTORIES``, and ``INTERFACE_LINK_DIRECTORIES``
44
+
40
45
Cache Variables
41
46
^^^^^^^^^^^^^^^
42
47
43
- The following cache variables may also be set:
48
+ The following cache variable may also be set:
44
49
45
- ``SYCL_INCLUDE_DIR``
46
- The directory containing ``sycl.hpp``.
47
- ``SYCL_LIBRARY_DIR``
48
- The path to the SYCL library.
49
- ``SYCL_FLAGS``
50
- SYCL specific flags for the compiler.
51
50
``SYCL_LANGUAGE_VERSION``
52
51
The SYCL language spec version by Compiler.
53
52
54
53
55
- .. note ::
54
+ .. Note ::
56
55
57
- For now, user needs to set -DCMAKE_CXX_COMPILER or environment of
56
+ 1. User needs to set -DCMAKE_CXX_COMPILER or environment of
58
57
CXX pointing to SYCL compatible compiler ( eg: icx, clang++, icpx)
59
58
60
- Note: do not set to DPCPP compiler. If set to a Compiler family
61
- that supports dpcpp ( eg: IntelLLVM) both DPCPP and SYCL
62
- features are enabled.
63
59
64
- And add this package to user's Cmake config file.
60
+ 2. Add this package to user's Cmake config file.
61
+
62
+ .. code-block:: cmake
63
+
64
+ find_package(IntelSYCL REQUIRED)
65
+
66
+ 3. Add sources to target through add_sycl_to_target()
65
67
66
68
.. code-block:: cmake
67
69
68
- find_package(IntelDPCPP REQUIRED)
70
+ # Compile specific sources for SYCL and build target for SYCL
71
+ add_executable(target_proj A.cpp B.cpp offload1.cpp offload2.cpp)
72
+ add_sycl_to_target(TARGET target_proj SOURCES offload1.cpp offload2.cpp)
69
73
70
74
#]=======================================================================]
71
75
@@ -83,25 +87,33 @@ endif()
83
87
84
88
string (COMPARE EQUAL "${CMAKE_CXX_COMPILER} " "" nocmplr )
85
89
if (nocmplr )
86
- set (IntelDPCPP_FOUND False )
90
+ set (IntelSYCL_FOUND False )
87
91
set (SYCL_REASON_FAILURE "SYCL: CMAKE_CXX_COMPILER not set!!" )
88
- set (IntelDPCPP_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE} " )
92
+ set (IntelSYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE} " )
93
+ endif ()
94
+
95
+ # Check if a Compiler ID is being set. project() should be set prior to find_package()
96
+
97
+ if ("x${CMAKE_CXX_COMPILER_ID} " STREQUAL "x" )
98
+ set (IntelSYCL_FOUND False )
99
+ set (SYCL_REASON_FAILURE "CMake CXX Compiler family is not set. Please make sure find_package(IntelSYCL) is called after project()!!" )
100
+ set (IntelSYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE} " )
101
+ return ()
89
102
endif ()
90
103
91
104
# Check for known compiler family that supports SYCL
92
105
93
106
if ( NOT "x${CMAKE_CXX_COMPILER_ID} " STREQUAL "xClang" AND
94
107
NOT "x${CMAKE_CXX_COMPILER_ID} " STREQUAL "xIntelLLVM" )
95
- set (IntelDPCPP_FOUND False )
108
+ set (IntelSYCL_FOUND False )
96
109
set (SYCL_REASON_FAILURE "Unsupported compiler family ${CMAKE_CXX_COMPILER_ID} and compiler ${CMAKE_CXX_COMPILER} !!" )
97
- set (IntelDPCPP_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE} " )
110
+ set (IntelSYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE} " )
98
111
return ()
99
112
endif ()
100
113
101
114
# Assume that CXX Compiler supports SYCL and then test to verify.
102
115
set (SYCL_COMPILER ${CMAKE_CXX_COMPILER} )
103
116
104
-
105
117
# Function to write a test case to verify SYCL features.
106
118
107
119
function (SYCL_FEATURE_TEST_WRITE src )
@@ -144,7 +156,7 @@ function(SYCL_FEATURE_TEST_BUILD TEST_SRC_FILE TEST_EXE)
144
156
OUTPUT_VARIABLE output ERROR_VARIABLE output
145
157
OUTPUT_FILE ${SYCL_TEST_DIR} /Compile.log
146
158
RESULT_VARIABLE result
147
- TIMEOUT 20
159
+ TIMEOUT 60
148
160
)
149
161
150
162
# Verify if test case build properly.
@@ -168,12 +180,12 @@ function(SYCL_FEATURE_TEST_RUN TEST_EXE)
168
180
WORKING_DIRECTORY ${SYCL_TEST_DIR}
169
181
OUTPUT_VARIABLE output ERROR_VARIABLE output
170
182
RESULT_VARIABLE result
171
- TIMEOUT 20
183
+ TIMEOUT 60
172
184
)
173
185
174
186
# Verify the test execution output.
175
187
if (test_result )
176
- set (IntelDPCPP_FOUND False )
188
+ set (IntelSYCL_FOUND False )
177
189
set (SYCL_REASON_FAILURE "SYCL: feature test execution failed!!" )
178
190
endif ()
179
191
# TODO: what iff the result is false.. error or ignore?
@@ -236,14 +248,14 @@ set(SYCL_LINK_FLAGS "")
236
248
# Based on Compiler ID, add support for SYCL
237
249
if ( "x${CMAKE_CXX_COMPILER_ID} " STREQUAL "xClang" OR
238
250
"x${CMAKE_CXX_COMPILER_ID} " STREQUAL "xIntelLLVM" )
239
- set ( SYCL_FLAGS "-fsycl " )
240
- set ( SYCL_LINK_FLAGS "-fsycl " )
251
+ list ( APPEND SYCL_FLAGS "-fsycl" )
252
+ list ( APPEND SYCL_LINK_FLAGS "-fsycl" )
241
253
endif ()
242
254
243
255
# TODO verify if this is needed
244
256
# Windows: Add Exception handling
245
257
if (WIN32 )
246
- set ( SYCL_FLAGS " ${ SYCL_FLAGS} /EHsc" )
258
+ list ( APPEND SYCL_FLAGS " /EHsc" )
247
259
endif ()
248
260
249
261
set (SYCL_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SYCL_FLAGS} " )
@@ -273,32 +285,76 @@ SYCL_FEATURE_TEST_EXTRACT(${test_output})
273
285
# define macro SYCL_LANGUAGE_VERSION
274
286
string (COMPARE EQUAL "${SYCL_LANGUAGE_VERSION} " "" nosycllang )
275
287
if (nosycllang )
276
- set (IntelDPCPP_FOUND False )
288
+ set (IntelSYCL_FOUND False )
277
289
set (SYCL_REASON_FAILURE "SYCL: It appears that the ${CMAKE_CXX_COMPILER} does not support SYCL" )
278
- set (IntelDPCPP_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE} " )
290
+ set (IntelSYCL_NOT_FOUND_MESSAGE "${SYCL_REASON_FAILURE} " )
279
291
endif ()
280
292
281
293
# Placeholder for identifying various implemenations of SYCL compilers.
282
294
# for now, set to the CMAKE_CXX_COMPILER_ID
283
295
set (SYCL_IMPLEMENTATION_ID "${CMAKE_CXX_COMPILER_ID} " )
284
296
285
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SYCL_FLAGS} " )
286
- set (CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} ${SYCL_LINK_FLAGS} " )
297
+ message (DEBUG "The SYCL compiler is ${SYCL_COMPILER} " )
298
+ message (DEBUG "The SYCL Flags are ${SYCL_FLAGS} " )
299
+ message (DEBUG "The SYCL Language Version is ${SYCL_LANGUAGE_VERSION} " )
287
300
288
- message (STATUS "Echo from ${CMAKE_CURRENT_SOURCE_DIR} /IntelDPCPPConfig.cmake" )
289
- message (STATUS "The SYCL compiler is ${SYCL_COMPILER} " )
290
- message (STATUS "The SYCL Flags are ${SYCL_FLAGS} " )
291
- message (STATUS "The SYCL Language Version is ${SYCL_LANGUAGE_VERSION} " )
301
+ add_library (IntelSYCL::SYCL_CXX INTERFACE IMPORTED )
302
+ set_property (TARGET IntelSYCL::SYCL_CXX PROPERTY
303
+ INTERFACE_COMPILE_OPTIONS ${SYCL_FLAGS} )
304
+ set_property (TARGET IntelSYCL::SYCL_CXX PROPERTY
305
+ INTERFACE_LINK_OPTIONS ${SYCL_LINK_FLAGS} )
306
+ set_property (TARGET IntelSYCL::SYCL_CXX PROPERTY
307
+ INTERFACE_INCLUDE_DIRECTORIES ${SYCL_INCLUDE_DIR} )
308
+ set_property (TARGET IntelSYCL::SYCL_CXX PROPERTY
309
+ INTERFACE_LINK_DIRECTORIES ${SYCL_LIBRARY_DIR} )
292
310
293
311
find_package_handle_standard_args (
294
- IntelDPCPP
295
- FOUND_VAR IntelDPCPP_FOUND
312
+ IntelSYCL
313
+ FOUND_VAR IntelSYCL_FOUND
296
314
REQUIRED_VARS SYCL_INCLUDE_DIR SYCL_LIBRARY_DIR SYCL_FLAGS
297
315
VERSION_VAR SYCL_LANGUAGE_VERSION
298
316
REASON_FAILURE_MESSAGE "${SYCL_REASON_FAILURE} " )
299
317
300
318
# Include in Cache
301
319
set (SYCL_LANGUAGE_VERSION "${SYCL_LANGUAGE_VERSION} " CACHE STRING "SYCL Language version" )
302
- set (SYCL_INCLUDE_DIR "${SYCL_INCLUDE_DIR} " CACHE FILEPATH "SYCL Include directory" )
303
- set (SYCL_LIBRARY_DIR "${SYCL_LIBRARY_DIR} " CACHE FILEPATH "SYCL Library Directory" )
304
- set (SYCL_FLAGS "${SYCL_FLAGS} " CACHE STRING "SYCL flags for the compiler" )
320
+
321
+ function (add_sycl_to_target )
322
+
323
+ set (one_value_args TARGET )
324
+ set (multi_value_args SOURCES )
325
+ cmake_parse_arguments (SYCL
326
+ ""
327
+ "${one_value_args} "
328
+ "${multi_value_args} "
329
+ ${ARGN} )
330
+
331
+
332
+ get_target_property (__sycl_cxx_options IntelSYCL::SYCL_CXX INTERFACE_COMPILE_OPTIONS )
333
+ get_target_property (__sycl_cxx_include_directories IntelSYCL::SYCL_CXX INTERFACE_INCLUDE_DIRECTORIES )
334
+
335
+ if (NOT ${ARGC} )
336
+ message (FATAL_ERROR " add_sycl_to_target() does not have any arguments" )
337
+ elseif (${ARGC} EQUAL 1 )
338
+ message (WARNING "add_sycl_to_target() have only one argument specified.. assuming the target to be ${ARGV} .
339
+ Adding sycl to all sources but that may effect compilation times" )
340
+ set (SYCL_TARGET ${ARGV} )
341
+ endif ()
342
+
343
+ if (NOT SYCL_SOURCES )
344
+ message (WARNING "add_sycl_to_target() does not have sources specified.. Adding sycl to all sources but that may effect compilation times" )
345
+ target_compile_options (${SYCL_TARGET} PUBLIC ${__sycl_cxx_options} )
346
+ target_include_directories (${SYCL_TARGET} PUBLIC ${__sycl_cxx_include_directories} )
347
+ endif ()
348
+
349
+ foreach (source ${SYCL_SOURCES} )
350
+ set_source_files_properties (${source} PROPERTIES COMPILE_OPTIONS "${__sycl_cxx_options} " )
351
+ set_source_files_properties (${source} PROPERTIES INCLUDE_DIRECTORIES "${__sycl_cxx_include_directories} " )
352
+ endforeach ()
353
+
354
+ get_target_property (__sycl_link_options
355
+ IntelSYCL::SYCL_CXX INTERFACE_LINK_OPTIONS )
356
+ target_link_options (${SYCL_TARGET} PRIVATE "${__sycl_link_options} " )
357
+ get_target_property (__sycl_link_directories
358
+ IntelSYCL::SYCL_CXX INTERFACE_LINK_DIRECTORIES )
359
+ target_link_directories (${SYCL_TARGET} PUBLIC "${__sycl_link_directories} " )
360
+ endfunction (add_sycl_to_target )
0 commit comments