Skip to content

Commit fd64c8f

Browse files
authored
[SYCL] Add the ability to install the OpenCL ICD loader with LLVM
In certain cases one will want to install the same OpenCL ICD library along with LLVM that the code was built against. The new option, OpenCL_INSTALL_KHRONOS_ICD_LOADER can be used to set this up. - Add the (conditional) installation of the OpenCL ICD library to the deploy-sycl-toolchain target. - Add a protection for not trying to install the OpenCL ICD library, if it is not being built. This is meant to avoid running into issues when the user mis-configures the build.
1 parent cf65794 commit fd64c8f

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

sycl/CMakeLists.txt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ set(SYCL_INCLUDE_DEPLOY_DIR ${CMAKE_INSTALL_PREFIX}/${SYCL_INCLUDE_DIR})
7171
# build SYCL runtime.
7272
# WARNING: use with caution, building SYCL runtime with OpenCL implementation
7373
# instead of Khronos ICD loader might cause build and/or portability issues.
74-
option(OpenCL_BUILD_WITH_SYSTEM_SDK OFF)
74+
option(OpenCL_BUILD_WITH_SYSTEM_SDK "Build SYCL with OpenCL coming from the build system" OFF)
7575

7676
if( (OpenCL_INCLUDE_DIR AND OpenCL_LIBRARY) OR OpenCL_BUILD_WITH_SYSTEM_SDK)
7777
find_package(OpenCL)
@@ -80,7 +80,7 @@ endif()
8080
include(ExternalProject)
8181

8282
if( NOT OpenCL_INCLUDE_DIRS )
83-
message("OpenCL_INCLUDE_DIRS is missing. Will try to download OpenCL headers from github.com")
83+
message(STATUS "OpenCL_INCLUDE_DIRS is missing. Will try to download OpenCL headers from github.com")
8484
set(OpenCL_INCLUDE_DIRS "${CMAKE_CURRENT_BINARY_DIR}/OpenCL/inc")
8585
ExternalProject_Add(ocl-headers
8686
GIT_REPOSITORY https://github.com/KhronosGroup/OpenCL-Headers.git
@@ -102,7 +102,7 @@ else()
102102
endif()
103103

104104
if( NOT OpenCL_LIBRARIES )
105-
message("OpenCL_LIBRARIES is missing. Will try to download OpenCL ICD Loader from github.com")
105+
message(STATUS "OpenCL_LIBRARIES is missing. Will try to download OpenCL ICD Loader from github.com")
106106
if(MSVC)
107107
set(OpenCL_LIBRARIES
108108
"${LLVM_LIBRARY_OUTPUT_INTDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}OpenCL${CMAKE_STATIC_LIBRARY_SUFFIX}")
@@ -123,16 +123,31 @@ if( NOT OpenCL_LIBRARIES )
123123
GIT_TAG origin/master
124124
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/OpenCL/icd"
125125
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/icd_build"
126+
INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/icd_install"
126127
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
127128
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
128129
-DOPENCL_ICD_LOADER_HEADERS_DIR=${OpenCL_INCLUDE_DIRS}
129-
-DCMAKE_INSTALL_PREFIX=${LLVM_BINARY_DIR}
130+
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
130131
-DCMAKE_INSTALL_LIBDIR:PATH=lib${LLVM_LIBDIR_SUFFIX}
131132
${AUX_CMAKE_FLAGS}
132133
STEP_TARGETS configure,build,install
133134
DEPENDS ocl-headers
134135
BUILD_BYPRODUCTS ${OpenCL_LIBRARIES}
135136
)
137+
ExternalProject_Add_Step(ocl-icd llvminstall
138+
COMMAND ${CMAKE_COMMAND} -E copy_directory <INSTALL_DIR>/ ${LLVM_BINARY_DIR}
139+
COMMENT "Installing ocl-icd into the LLVM binary directory"
140+
DEPENDEES install
141+
)
142+
# Optionally install the ICD library along with LLVM.
143+
option(OpenCL_INSTALL_KHRONOS_ICD_LOADER
144+
"Install the Khronos ICD Loader built as part of LLVM" OFF)
145+
if (OpenCL_INSTALL_KHRONOS_ICD_LOADER)
146+
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/icd_install/"
147+
DESTINATION "."
148+
COMPONENT opencl-icd
149+
)
150+
endif()
136151
else()
137152
file(GLOB ICD_LOADER_SRC "${OpenCL_LIBRARIES}*")
138153
file(COPY ${ICD_LOADER_SRC} DESTINATION ${LLVM_LIBRARY_OUTPUT_INTDIR})
@@ -291,6 +306,9 @@ set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS
291306
pi_opencl
292307
libsycldevice
293308
)
309+
if(OpenCL_INSTALL_KHRONOS_ICD_LOADER AND TARGET ocl-icd)
310+
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS opencl-icd)
311+
endif()
294312

295313
if(SYCL_BUILD_PI_CUDA)
296314
# Ensure that libclc is enabled.

0 commit comments

Comments
 (0)