Skip to content

Commit 71a75c0

Browse files
Alexander Batashevromanovvlad
authored andcommitted
[SYCL] Add debug variant for SYCL RT
Signed-off-by: Alexander Batashev <[email protected]>
1 parent 587b27d commit 71a75c0

File tree

2 files changed

+138
-86
lines changed

2 files changed

+138
-86
lines changed

sycl/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,17 @@ COMMENT "Copying SYCL headers ...")
138138
# Configure SYCL headers
139139
install(DIRECTORY "${sycl_inc_dir}/." DESTINATION "${LLVM_INST_INC_DIRECTORY}" COMPONENT sycl-headers)
140140

141+
set(SYCL_RT_LIBS sycl)
142+
if (MSVC)
143+
list(APPEND SYCL_RT_LIBS sycld)
144+
endif()
145+
141146
# SYCL runtime library
142147
add_subdirectory(source)
143148

144149
# SYCL toolchain builds all components: compiler, libraries, headers, etc.
145150
add_custom_target( sycl-toolchain
146-
DEPENDS sycl
151+
DEPENDS ${SYCL_RT_LIBS}
147152
clang
148153
clang-offload-wrapper
149154
clang-offload-bundler

sycl/source/CMakeLists.txt

Lines changed: 132 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,101 +4,148 @@
44
#cmake_policy(SET CMP0057 NEW)
55
#include(AddLLVM)
66

7-
add_library(sycl SHARED
8-
"${sycl_inc_dir}/CL/sycl.hpp"
9-
"detail/builtins_common.cpp"
10-
"detail/builtins_geometric.cpp"
11-
"detail/builtins_integer.cpp"
12-
"detail/builtins_math.cpp"
13-
"detail/builtins_relational.cpp"
14-
"detail/pi.cpp"
15-
"detail/pi_opencl.cpp"
16-
"detail/common.cpp"
17-
"detail/context_impl.cpp"
18-
"detail/device_impl.cpp"
19-
"detail/device_info.cpp"
20-
"detail/event_impl.cpp"
21-
"detail/force_device.cpp"
22-
"detail/helpers.cpp"
23-
"detail/image_accessor_util.cpp"
24-
"detail/image_impl.cpp"
25-
"detail/kernel_impl.cpp"
26-
"detail/kernel_info.cpp"
27-
"detail/memory_manager.cpp"
28-
"detail/platform_impl.cpp"
29-
"detail/platform_info.cpp"
30-
"detail/program_impl.cpp"
31-
"detail/program_manager/program_manager.cpp"
32-
"detail/queue_impl.cpp"
33-
"detail/os_util.cpp"
34-
"detail/platform_util.cpp"
35-
"detail/sampler_impl.cpp"
36-
"detail/stream_impl.cpp"
37-
"detail/scheduler/commands.cpp"
38-
"detail/scheduler/scheduler.cpp"
39-
"detail/scheduler/graph_processor.cpp"
40-
"detail/scheduler/graph_builder.cpp"
41-
"detail/usm/clusm.cpp"
42-
"detail/usm/usm_dispatch.cpp"
43-
"detail/usm/usm_impl.cpp"
44-
"detail/util.cpp"
45-
"context.cpp"
46-
"device.cpp"
47-
"device_selector.cpp"
48-
"event.cpp"
49-
"exception.cpp"
50-
"exception_list.cpp"
51-
"half_type.cpp"
52-
"kernel.cpp"
53-
"platform.cpp"
54-
"queue.cpp"
55-
"ordered_queue.cpp"
56-
"sampler.cpp"
57-
"stream.cpp"
58-
"spirv_ops.cpp"
59-
)
7+
function(add_sycl_rt_library LIB_NAME)
8+
9+
add_library(${LIB_NAME} SHARED ${ARGN})
10+
11+
add_dependencies(${LIB_NAME}
12+
ocl-icd
13+
ocl-headers
14+
sycl-headers
15+
)
16+
17+
set_target_properties(${LIB_NAME} PROPERTIES LINKER_LANGUAGE CXX)
18+
19+
if (MSVC)
20+
target_compile_definitions(${LIB_NAME} PRIVATE __SYCL_BUILD_SYCL_DLL )
21+
endif()
22+
target_include_directories(${LIB_NAME} PRIVATE "${sycl_inc_dir}")
23+
target_link_libraries(${LIB_NAME}
24+
PRIVATE OpenCL::Headers
25+
PRIVATE ${OpenCL_LIBRARIES}
26+
)
27+
if (SYCL_USE_LIBCXX)
28+
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR
29+
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
30+
target_compile_options(${LIB_NAME} PRIVATE -nostdinc++)
31+
if ((NOT (DEFINED SYCL_LIBCXX_INCLUDE_PATH)) OR (NOT (DEFINED SYCL_LIBCXX_LIBRARY_PATH)))
32+
message(FATAL_ERROR "When building with libc++ SYCL_LIBCXX_INCLUDE_PATHS and"
33+
"SYCL_LIBCXX_LIBRARY_PATH should be set")
34+
endif()
35+
target_include_directories(${LIB_NAME} PRIVATE "${SYCL_LIBCXX_INCLUDE_PATH}")
36+
target_link_libraries(${LIB_NAME} PRIVATE "-L${SYCL_LIBCXX_LIBRARY_PATH}" -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc)
37+
else()
38+
message(FATAL_ERROR "Build with libc++ is not yet supported for this compiler")
39+
endif()
40+
else()
41+
42+
# Workaround for bug in GCC version 5 and higher.
43+
# More information https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1568899
44+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
45+
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0)
46+
target_link_libraries(${LIB_NAME} PRIVATE gcc_s gcc)
47+
endif()
6048

61-
add_dependencies(sycl
62-
ocl-icd
63-
ocl-headers
64-
sycl-headers
49+
endif()
50+
endfunction(add_sycl_rt_library)
51+
52+
set(SYCL_SOURCES
53+
"${sycl_inc_dir}/CL/sycl.hpp"
54+
"detail/builtins_common.cpp"
55+
"detail/builtins_geometric.cpp"
56+
"detail/builtins_integer.cpp"
57+
"detail/builtins_math.cpp"
58+
"detail/builtins_relational.cpp"
59+
"detail/pi.cpp"
60+
"detail/pi_opencl.cpp"
61+
"detail/common.cpp"
62+
"detail/context_impl.cpp"
63+
"detail/device_impl.cpp"
64+
"detail/device_info.cpp"
65+
"detail/event_impl.cpp"
66+
"detail/force_device.cpp"
67+
"detail/helpers.cpp"
68+
"detail/image_accessor_util.cpp"
69+
"detail/image_impl.cpp"
70+
"detail/kernel_impl.cpp"
71+
"detail/kernel_info.cpp"
72+
"detail/memory_manager.cpp"
73+
"detail/platform_impl.cpp"
74+
"detail/platform_info.cpp"
75+
"detail/program_impl.cpp"
76+
"detail/program_manager/program_manager.cpp"
77+
"detail/queue_impl.cpp"
78+
"detail/os_util.cpp"
79+
"detail/platform_util.cpp"
80+
"detail/sampler_impl.cpp"
81+
"detail/stream_impl.cpp"
82+
"detail/scheduler/commands.cpp"
83+
"detail/scheduler/scheduler.cpp"
84+
"detail/scheduler/graph_processor.cpp"
85+
"detail/scheduler/graph_builder.cpp"
86+
"detail/usm/clusm.cpp"
87+
"detail/usm/usm_dispatch.cpp"
88+
"detail/usm/usm_impl.cpp"
89+
"detail/util.cpp"
90+
"context.cpp"
91+
"device.cpp"
92+
"device_selector.cpp"
93+
"event.cpp"
94+
"exception.cpp"
95+
"exception_list.cpp"
96+
"half_type.cpp"
97+
"kernel.cpp"
98+
"platform.cpp"
99+
"queue.cpp"
100+
"ordered_queue.cpp"
101+
"sampler.cpp"
102+
"stream.cpp"
103+
"spirv_ops.cpp"
65104
)
66105

67-
set_target_properties(sycl PROPERTIES LINKER_LANGUAGE CXX)
106+
add_sycl_rt_library(sycl ${SYCL_SOURCES})
68107

69108
if (MSVC)
70-
target_compile_definitions(sycl PRIVATE __SYCL_BUILD_SYCL_DLL )
71-
endif()
72-
target_include_directories(sycl PRIVATE "${sycl_inc_dir}")
73-
target_link_libraries(sycl
74-
PRIVATE OpenCL::Headers
75-
PRIVATE ${OpenCL_LIBRARIES}
76-
)
77-
if (SYCL_USE_LIBCXX)
78-
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR
79-
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
80-
target_compile_options(sycl PRIVATE -nostdinc++)
81-
if ((NOT (DEFINED SYCL_LIBCXX_INCLUDE_PATH)) OR (NOT (DEFINED SYCL_LIBCXX_LIBRARY_PATH)))
82-
message(FATAL_ERROR "When building with libc++ SYCL_LIBCXX_INCLUDE_PATHS and"
83-
"SYCL_LIBCXX_LIBRARY_PATH should be set")
84-
endif()
85-
target_include_directories(sycl PRIVATE "${SYCL_LIBCXX_INCLUDE_PATH}")
86-
target_link_libraries(sycl PRIVATE "-L${SYCL_LIBCXX_LIBRARY_PATH}" -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc)
87-
else()
88-
message(FATAL_ERROR "Build with libc++ is not yet supported for this compiler")
109+
# MSVC provides two incompatible build variants for its CRT: release and debug
110+
# To avoid potential issues in user code we also need to provide two kinds
111+
# of SYCL Runtime Library for release and debug configurations.
112+
set(SYCL_CXX_FLAGS "")
113+
if (CMAKE_BUILD_TYPE MATCHES "Debug")
114+
set(SYCL_CXX_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}")
115+
string(REPLACE "/MDd" "" SYCL_CXX_FLAGS "${SYCL_CXX_FLAGS}")
116+
string(REPLACE "/MTd" "" SYCL_CXX_FLAGS "${SYCL_CXX_FLAGS}")
117+
else()
118+
if (CMAKE_BUILD_TYPE MATCHES "Release")
119+
set(SYCL_CXX_FLAGS "${CMAKE_CXX_FLAGS_RELEASE}")
120+
elseif (CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
121+
set(SYCL_CXX_FLAGS "${CMAKE_CXX_FLAGS_MINSIZEREL}")
122+
elseif (CMAKE_BUILD_TYPE MATCHES "MinSizeRel")
123+
set(SYCL_CXX_FLAGS "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
89124
endif()
90-
else()
125+
string(REPLACE "/MD" "" SYCL_CXX_FLAGS "${SYCL_CXX_FLAGS}")
126+
string(REPLACE "/MT" "" SYCL_CXX_FLAGS "${SYCL_CXX_FLAGS}")
127+
endif()
91128

92-
# Workaround for bug in GCC version 5 and higher.
93-
# More information https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1568899
94-
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
95-
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0)
96-
target_link_libraries(sycl PRIVATE gcc_s gcc)
97-
endif()
129+
# target_compile_options requires list of options, not a string
130+
string(REPLACE " " ";" SYCL_CXX_FLAGS "${SYCL_CXX_FLAGS}")
131+
132+
set(SYCL_CXX_FLAGS_RELEASE "${SYCL_CXX_FLAGS};/MD")
133+
set(SYCL_CXX_FLAGS_DEBUG "${SYCL_CXX_FLAGS};/MDd")
134+
135+
# CMake automatically applies these flags to all targets. To override this
136+
# behavior, options lists are reset.
137+
set(CMAKE_CXX_FLAGS_RELEASE "")
138+
set(CMAKE_CXX_FLAGS_MINSIZEREL "")
139+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "")
140+
set(CMAKE_CXX_FLAGS_DEBUG "")
141+
142+
target_compile_options(sycl PUBLIC ${SYCL_CXX_FLAGS_RELEASE})
98143

144+
add_sycl_rt_library(sycld ${SYCL_SOURCES})
145+
target_compile_options(sycld PUBLIC ${SYCL_CXX_FLAGS_DEBUG})
99146
endif()
100147

101-
install(TARGETS sycl
148+
install(TARGETS ${SYCL_RT_LIBS}
102149
ARCHIVE DESTINATION "lib" COMPONENT sycl
103150
LIBRARY DESTINATION "lib" COMPONENT sycl
104151
RUNTIME DESTINATION "bin" COMPONENT sycl)

0 commit comments

Comments
 (0)