Skip to content

[SYCL] Properly deploy SYCL components #509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 107 additions & 20 deletions sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to have separate variable per component.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these tools are not part of the SYCL toolchain and actually dependency of check-sycl target. If possible, please, fix with this patch, if not, I'm okay to resolve it separately.

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})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code relies on assumption that target names do match names of associated components.

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})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why llvm-lit is deployed with the SYCL toolchain?


# For some reason clang-cl is being created on Linux. Remove it so users
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest fix this on clang side rather than add such a post build adjustment.
Is it reproduced consistently? Do you have steps to reproduce?

Copy link
Contributor Author

@alexbatashev alexbatashev Aug 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@valerydmit when I build sycl-toolchain target, I get clang-cl in bin directory. And at the time I'm not sure it is a bug in clang. There are tests that call clang-cl, and they seem to run and pass on Linux. On the other hand, all clang-cl can do on Linux is show help and crash, complaining about missing MSVC. So, it worths double checking.

# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploying OpenCL to the same directory as SYCL is probably bad idea. It complicates the configuration.
Please, add TODO to make OpenCL deploy path configurable.

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel something is wrong with this WA.
I suggest removing it...
I think we should start with deploying only latest Khronos ICD, if it's downloaded and build from sources by this script.
I'm not sure there is a reason to deploy anything else.

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()

10 changes: 10 additions & 0 deletions sycl/doc/GetStartedWithSYCLCompiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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:
Expand Down
21 changes: 19 additions & 2 deletions sycl/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions sycl/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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\\")
Expand Down