diff --git a/sycl/CMakeLists.txt b/sycl/CMakeLists.txt index 99724b20420c4..d8be7e928745e 100644 --- a/sycl/CMakeLists.txt +++ b/sycl/CMakeLists.txt @@ -7,6 +7,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +option(SYCL_DEPLOY_OPENCL OFF) + if(MSVC) set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Skip asynchronous C++ exceptions catching and assume "extern C" functions @@ -82,6 +84,17 @@ else() add_custom_target(ocl-icd DEPENDS ${OpenCL_LIBRARIES} COMMENT "Copying OpenCL ICD Loader ...") endif() +if(NOT TARGET OpenCL) + add_library(OpenCL INTERFACE) + if (TARGET OpenCL::OpenCL) + # Since 3.8 CMake exports target for FindOpenCL + target_link_libraries(OpenCL INTERFACE OpenCL::OpenCL) + else() + target_link_libraries(OpenCL INTERFACE ${OpenCL_LIBRARIES}) + target_include_directories(OpenCL INTERFACE ${OpenCL_INCLUDE_DIRS}) + endif() +endif() + set(OPENCL_INCLUDE "${OpenCL_INCLUDE_DIRS}") # Configure SYCL version macro @@ -95,34 +108,108 @@ add_custom_target(sycl-headers ALL COMMAND ${CMAKE_COMMAND} -E copy_directory ${sycl_inc_dir}/CL ${dst_dir}/CL COMMENT "Copying SYCL headers ...") -# Configure SYCL headers -install(DIRECTORY "${sycl_inc_dir}/." DESTINATION "${LLVM_INST_INC_DIRECTORY}" COMPONENT sycl-headers) - -# Configure OpenCL header and ICD loader -include_directories(AFTER "${sycl_inc_dir}" "${OpenCL_INCLUDE_DIRS}") -link_libraries(${OpenCL_LIBRARIES}) - # SYCL runtime library add_subdirectory(source) # SYCL toolchain builds all components: compiler, libraries, headers, etc. +set(SYCL_TOOLCHAIN_DEPS + sycl + clang + clang-offload-wrapper + clang-offload-bundler + llc + llvm-as + llvm-ar + llvm-dis + llvm-no-spir-kernel + llvm-spirv + llvm-link + llvm-objcopy + opt) add_custom_target( sycl-toolchain - DEPENDS sycl - clang - clang-offload-wrapper - clang-offload-bundler - llc - llvm-as - llvm-ar - llvm-dis - llvm-no-spir-kernel - llvm-spirv - llvm-link - llvm-objcopy - opt + DEPENDS ${SYCL_TOOLCHAIN_DEPS} COMMENT "Building SYCL compiler toolchain..." ) add_subdirectory( test ) add_subdirectory( unittests ) add_subdirectory( tools ) + +# Configure SYCL toolchain installation targets +add_custom_target(deploy-sycl-toolchain) + +set(SYCL_BUNDLE_DEPS ${SYCL_TOOLCHAIN_DEPS} opencl clang-resource-headers) + +foreach(comp ${SYCL_BUNDLE_DEPS}) + add_custom_command(TARGET deploy-sycl-toolchain PRE_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -DCOMPONENT="${comp}" -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") +endforeach() + +set(LLVM_LIT_EXT "") +if(WIN32) + set(LLVM_LIT_EXT ".py") +endif() +add_custom_command(TARGET deploy-sycl-toolchain PRE_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy ${CMAKE_BINARY_DIR}/bin/llvm-lit${LLVM_LIT_EXT} + ${CMAKE_INSTALL_PREFIX}/bin/llvm-lit${LLVM_LIT_EXT}) + +# For some reason clang-cl is being created on Linux. Remove it so users +# are not confused. +if (NOT WIN32) + add_custom_command(TARGET deploy-sycl-toolchain POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E remove ${CMAKE_INSTALL_PREFIX}/bin/clang-cl) +endif() + +if (SYCL_DEPLOY_OPENCL) + install(TARGETS OpenCL EXPORT SYCL + LIBRARY + DESTINATION lib + COMPONENT opencl + ARCHIVE + DESTINATION lib + COMPONENT opencl + RUNTIME + DESTINATION bin + COMPONENT opencl + INCLUDES + DESTINATION include + COMPONENT opencl) + + # If OpenCL target is not built with SYCL, we need to copy libraries manually + if(OpenCL_LIBRARIES) + set (RESOLVED_LIBS "") + foreach (file ${OpenCL_LIBRARIES}) + get_filename_component(resolved_lib "${file}" REALPATH) + list (APPEND RESOLVED_LIBS "${resolved_lib}") + endforeach() + install(FILES ${RESOLVED_LIBS} DESTINATION lib COMPONENT opencl) + if(WIN32) + string(REPLACE ".lib" ".dll" DLL_LIBS "${RESOLVED_LIBS}") + install(FILES ${DLL_LIBS} DESTINATION bin COMPONENT opencl) + else(WIN32) + if(RESOLVED_LIBS MATCHES "libOpenCL.so.1.0.0") + # Workaround for some OpenCL ICD packages + add_custom_command(TARGET deploy-sycl-toolchain POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E rename ${CMAKE_INSTALL_PREFIX}/lib/libOpenCL.so.1.0.0 + ${CMAKE_INSTALL_PREFIX}/lib/libOpenCL.so) + endif() + add_custom_command(TARGET deploy-sycl-toolchain + COMMAND ${CMAKE_COMMAND} + ARGS -E create_symlink ${CMAKE_INSTALL_PREFIX}/lib/libOpenCL.so + ${CMAKE_INSTALL_PREFIX}/lib/libOpenCL.so.1) + add_custom_command(TARGET deploy-sycl-toolchain + COMMAND ${CMAKE_COMMAND} + ARGS -E create_symlink ${CMAKE_INSTALL_PREFIX}/lib/libOpenCL.so + ${CMAKE_INSTALL_PREFIX}/lib/libOpenCL.so.1.2) + endif() + endif() + if(OpenCL_INCLUDE_DIRS) + install(DIRECTORY ${OpenCL_INCLUDE_DIRS}/CL + DESTINATION include COMPONENT opencl) + endif() +endif() + diff --git a/sycl/doc/GetStartedWithSYCLCompiler.md b/sycl/doc/GetStartedWithSYCLCompiler.md index f38093803f738..7419d287e676b 100644 --- a/sycl/doc/GetStartedWithSYCLCompiler.md +++ b/sycl/doc/GetStartedWithSYCLCompiler.md @@ -36,6 +36,8 @@ cmake -DCMAKE_BUILD_TYPE=Release \ -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 make -j`nproc` sycl-toolchain ``` @@ -64,6 +66,14 @@ make -j`nproc` check-all ``` If no OpenCL GPU/CPU runtimes are available, the corresponding LIT tests are skipped +# Install the SYCL compiler and runtime + +Install the SYCL compiler with all dependencies using the command below. + +```bash +make deploy-sycl-toolchain +``` + # Creating a simple SYCL program A simple SYCL program consists of following parts: diff --git a/sycl/source/CMakeLists.txt b/sycl/source/CMakeLists.txt index c2c7c8badd8f1..6313520aa5711 100644 --- a/sycl/source/CMakeLists.txt +++ b/sycl/source/CMakeLists.txt @@ -61,6 +61,9 @@ add_library(sycl SHARED "spirv_ops.cpp" ) +target_link_libraries(sycl PUBLIC OpenCL) +target_include_directories(sycl PUBLIC ${sycl_inc_dir}) + add_dependencies(sycl ocl-icd ocl-headers @@ -88,9 +91,23 @@ else() # More information https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1568899 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0) - target_link_libraries(sycl gcc_s gcc) + target_link_libraries(sycl PRIVATE gcc_s gcc) endif() endif() -install(TARGETS sycl DESTINATION "lib" COMPONENT sycl) +install(TARGETS sycl EXPORT SYCL + LIBRARY + DESTINATION lib + COMPONENT sycl + ARCHIVE + DESTINATION lib + COMPONENT sycl + RUNTIME + DESTINATION bin + COMPONENT sycl + INCLUDES + DESTINATION "include" + COMPONENT sycl + ) +install(DIRECTORY ${sycl_inc_dir}/CL DESTINATION include COMPONENT sycl) diff --git a/sycl/tools/CMakeLists.txt b/sycl/tools/CMakeLists.txt index 21c7121553d29..8bb3081e561ce 100644 --- a/sycl/tools/CMakeLists.txt +++ b/sycl/tools/CMakeLists.txt @@ -4,6 +4,7 @@ set(CMAKE_CXX_EXTENSIONS OFF) add_executable(get_device_count_by_type get_device_count_by_type.cpp) add_dependencies(get_device_count_by_type ocl-headers ocl-icd) +target_link_libraries(get_device_count_by_type PRIVATE OpenCL) #Minimum supported version of Intel's OCL GPU and CPU devices add_definitions(-D MIN_INTEL_OCL_GPU_VERSION=\\"18.47.11882\\") add_definitions(-D MIN_INTEL_OCL_CPU_VERSION=\\"18.1.0.0901\\",\\"7.6.0.1202\\")