Skip to content

Commit 6c570c6

Browse files
author
Alexander Batashev
committed
[SYCL] Properly deploy SYCL components
Add deploy-sycl-toolchain target that installs SYCL compiler and its dependencies to CMAKE_INSTALL_PREFIX location. Usage: 1. Configure CMake project: ``` cmake -DCMAKE_BUILD_TYPE=Release \ -DLLVM_EXTERNAL_PROJECTS="llvm-spirv;sycl" \ -DLLVM_EXTERNAL_SYCL_SOURCE_DIR=$SYCL_HOME/sycl \ -DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR=$SYCL_HOME/llvm-spirv \ -DLLVM_ENABLE_PROJECTS="clang;llvm-spirv;sycl" \ -DCMAKE_INSTALL_PREFIX=/usr/local \ -DSYCL_DEPLOY_OPENCL=ON \ $SYCL_HOME/llvm ``` 2. Build/test compiler as needed 3. Install SYCL compiler: ``` cmake --build /path/to/build/ --target deploy-sycl-toolchain ``` SYCL compiler with all its dependencies will be installed to /usr/local. New CMake options: `SYCL_DEPLOY_OPENCL` - installs OpenCL to the same location as SYCL. Defaults to `OFF`. Signed-off-by: Alexander Batashev <alexander.batashev@intel.com>
1 parent e46d919 commit 6c570c6

File tree

4 files changed

+137
-22
lines changed

4 files changed

+137
-22
lines changed

sycl/CMakeLists.txt

Lines changed: 107 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_CXX_EXTENSIONS OFF)
88
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
99

10+
option(SYCL_DEPLOY_OPENCL OFF)
11+
1012
if(MSVC)
1113
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
1214
# Skip asynchronous C++ exceptions catching and assume "extern C" functions
@@ -82,6 +84,17 @@ else()
8284
add_custom_target(ocl-icd DEPENDS ${OpenCL_LIBRARIES} COMMENT "Copying OpenCL ICD Loader ...")
8385
endif()
8486

87+
if(NOT TARGET OpenCL)
88+
add_library(OpenCL INTERFACE)
89+
if (TARGET OpenCL::OpenCL)
90+
# Since 3.8 CMake exports target for FindOpenCL
91+
target_link_libraries(OpenCL INTERFACE OpenCL::OpenCL)
92+
else()
93+
target_link_libraries(OpenCL INTERFACE ${OpenCL_LIBRARIES})
94+
target_include_directories(OpenCL INTERFACE ${OpenCL_INCLUDE_DIRS})
95+
endif()
96+
endif()
97+
8598
set(OPENCL_INCLUDE "${OpenCL_INCLUDE_DIRS}")
8699

87100
# Configure SYCL version macro
@@ -95,34 +108,108 @@ add_custom_target(sycl-headers ALL
95108
COMMAND ${CMAKE_COMMAND} -E copy_directory ${sycl_inc_dir}/CL ${dst_dir}/CL
96109
COMMENT "Copying SYCL headers ...")
97110

98-
# Configure SYCL headers
99-
install(DIRECTORY "${sycl_inc_dir}/." DESTINATION "${LLVM_INST_INC_DIRECTORY}" COMPONENT sycl-headers)
100-
101-
# Configure OpenCL header and ICD loader
102-
include_directories(AFTER "${sycl_inc_dir}" "${OpenCL_INCLUDE_DIRS}")
103-
link_libraries(${OpenCL_LIBRARIES})
104-
105111
# SYCL runtime library
106112
add_subdirectory(source)
107113

108114
# SYCL toolchain builds all components: compiler, libraries, headers, etc.
115+
set(SYCL_TOOLCHAIN_DEPS
116+
sycl
117+
clang
118+
clang-offload-wrapper
119+
clang-offload-bundler
120+
llc
121+
llvm-as
122+
llvm-ar
123+
llvm-dis
124+
llvm-no-spir-kernel
125+
llvm-spirv
126+
llvm-link
127+
llvm-objcopy
128+
opt)
109129
add_custom_target( sycl-toolchain
110-
DEPENDS sycl
111-
clang
112-
clang-offload-wrapper
113-
clang-offload-bundler
114-
llc
115-
llvm-as
116-
llvm-ar
117-
llvm-dis
118-
llvm-no-spir-kernel
119-
llvm-spirv
120-
llvm-link
121-
llvm-objcopy
122-
opt
130+
DEPENDS ${SYCL_TOOLCHAIN_DEPS}
123131
COMMENT "Building SYCL compiler toolchain..."
124132
)
125133

126134
add_subdirectory( test )
127135
add_subdirectory( unittests )
128136
add_subdirectory( tools )
137+
138+
# Configure SYCL toolchain installation targets
139+
add_custom_target(deploy-sycl-toolchain)
140+
141+
set(SYCL_BUNDLE_DEPS ${SYCL_TOOLCHAIN_DEPS} opencl clang-resource-headers)
142+
143+
foreach(comp ${SYCL_BUNDLE_DEPS})
144+
add_custom_command(TARGET deploy-sycl-toolchain PRE_BUILD
145+
COMMAND ${CMAKE_COMMAND}
146+
ARGS -DCOMPONENT="${comp}" -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
147+
endforeach()
148+
149+
set(LLVM_LIT_EXT "")
150+
if(WIN32)
151+
set(LLVM_LIT_EXT ".py")
152+
endif()
153+
add_custom_command(TARGET deploy-sycl-toolchain PRE_BUILD
154+
COMMAND ${CMAKE_COMMAND}
155+
ARGS -E copy ${CMAKE_BINARY_DIR}/bin/llvm-lit${LLVM_LIT_EXT}
156+
${CMAKE_INSTALL_PREFIX}/bin/llvm-lit${LLVM_LIT_EXT})
157+
158+
# For some reason clang-cl is being created on Linux. Remove it so users
159+
# are not confused.
160+
if (NOT WIN32)
161+
add_custom_command(TARGET deploy-sycl-toolchain POST_BUILD
162+
COMMAND ${CMAKE_COMMAND}
163+
ARGS -E remove ${CMAKE_INSTALL_PREFIX}/bin/clang-cl)
164+
endif()
165+
166+
if (SYCL_DEPLOY_OPENCL)
167+
install(TARGETS OpenCL EXPORT SYCL
168+
LIBRARY
169+
DESTINATION lib
170+
COMPONENT opencl
171+
ARCHIVE
172+
DESTINATION lib
173+
COMPONENT opencl
174+
RUNTIME
175+
DESTINATION bin
176+
COMPONENT opencl
177+
INCLUDES
178+
DESTINATION include
179+
COMPONENT opencl)
180+
181+
# If OpenCL target is not built with SYCL, we need to copy libraries manually
182+
if(OpenCL_LIBRARIES)
183+
set (RESOLVED_LIBS "")
184+
foreach (file ${OpenCL_LIBRARIES})
185+
get_filename_component(resolved_lib "${file}" REALPATH)
186+
list (APPEND RESOLVED_LIBS "${resolved_lib}")
187+
endforeach()
188+
install(FILES ${RESOLVED_LIBS} DESTINATION lib COMPONENT opencl)
189+
if(WIN32)
190+
string(REPLACE ".lib" ".dll" DLL_LIBS "${RESOLVED_LIBS}")
191+
install(FILES ${DLL_LIBS} DESTINATION bin COMPONENT opencl)
192+
else(WIN32)
193+
if(RESOLVED_LIBS MATCHES "libOpenCL.so.1.0.0")
194+
# Workaround for some OpenCL ICD packages
195+
add_custom_command(TARGET deploy-sycl-toolchain POST_BUILD
196+
COMMAND ${CMAKE_COMMAND}
197+
ARGS -E rename ${CMAKE_INSTALL_PREFIX}/lib/libOpenCL.so.1.0.0
198+
${CMAKE_INSTALL_PREFIX}/lib/libOpenCL.so)
199+
endif()
200+
add_custom_command(TARGET deploy-sycl-toolchain
201+
COMMAND ${CMAKE_COMMAND}
202+
ARGS -E create_symlink ${CMAKE_INSTALL_PREFIX}/lib/libOpenCL.so
203+
${CMAKE_INSTALL_PREFIX}/lib/libOpenCL.so.1)
204+
add_custom_command(TARGET deploy-sycl-toolchain
205+
COMMAND ${CMAKE_COMMAND}
206+
ARGS -E create_symlink ${CMAKE_INSTALL_PREFIX}/lib/libOpenCL.so
207+
${CMAKE_INSTALL_PREFIX}/lib/libOpenCL.so.1.2)
208+
endif()
209+
endif()
210+
if(OpenCL_INCLUDE_DIRS)
211+
install(DIRECTORY ${OpenCL_INCLUDE_DIRS}/CL
212+
DESTINATION include COMPONENT opencl)
213+
endif()
214+
endif()
215+

sycl/doc/GetStartedWithSYCLCompiler.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ cmake -DCMAKE_BUILD_TYPE=Release \
3636
-DLLVM_EXTERNAL_SYCL_SOURCE_DIR=$SYCL_HOME/sycl \
3737
-DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR=$SYCL_HOME/llvm-spirv \
3838
-DLLVM_ENABLE_PROJECTS="clang;llvm-spirv;sycl" \
39+
-DCMAKE_INSTALL_PREFIX=/usr/local \
40+
-DSYCL_DEPLOY_OPENCL=ON \
3941
$SYCL_HOME/llvm
4042
make -j`nproc` sycl-toolchain
4143
```
@@ -64,6 +66,14 @@ make -j`nproc` check-all
6466
```
6567
If no OpenCL GPU/CPU runtimes are available, the corresponding LIT tests are skipped
6668

69+
# Install the SYCL compiler and runtime
70+
71+
Install the SYCL compiler with all dependencies using the command below.
72+
73+
```bash
74+
make deploy-sycl-toolchain
75+
```
76+
6777
# Creating a simple SYCL program
6878

6979
A simple SYCL program consists of following parts:

sycl/source/CMakeLists.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ add_library(sycl SHARED
6161
"spirv_ops.cpp"
6262
)
6363

64+
target_link_libraries(sycl PUBLIC OpenCL)
65+
target_include_directories(sycl PUBLIC ${sycl_inc_dir})
66+
6467
add_dependencies(sycl
6568
ocl-icd
6669
ocl-headers
@@ -88,9 +91,23 @@ else()
8891
# More information https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1568899
8992
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
9093
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0)
91-
target_link_libraries(sycl gcc_s gcc)
94+
target_link_libraries(sycl PRIVATE gcc_s gcc)
9295
endif()
9396

9497
endif()
9598

96-
install(TARGETS sycl DESTINATION "lib" COMPONENT sycl)
99+
install(TARGETS sycl EXPORT SYCL
100+
LIBRARY
101+
DESTINATION lib
102+
COMPONENT sycl
103+
ARCHIVE
104+
DESTINATION lib
105+
COMPONENT sycl
106+
RUNTIME
107+
DESTINATION bin
108+
COMPONENT sycl
109+
INCLUDES
110+
DESTINATION "include"
111+
COMPONENT sycl
112+
)
113+
install(DIRECTORY ${sycl_inc_dir}/CL DESTINATION include COMPONENT sycl)

sycl/tools/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
44

55
add_executable(get_device_count_by_type get_device_count_by_type.cpp)
66
add_dependencies(get_device_count_by_type ocl-headers ocl-icd)
7+
target_link_libraries(get_device_count_by_type PRIVATE OpenCL)
78
#Minimum supported version of Intel's OCL GPU and CPU devices
89
add_definitions(-D MIN_INTEL_OCL_GPU_VERSION=\\"18.47.11882\\")
910
add_definitions(-D MIN_INTEL_OCL_CPU_VERSION=\\"18.1.0.0901\\",\\"7.6.0.1202\\")

0 commit comments

Comments
 (0)