Skip to content

Commit c16412b

Browse files
author
Alexander Batashev
authored
[SYCL][NFC] Refactor plugin CMakeLists.txt (#5799)
Remove duplicate code and allow build and install plugins separately.
1 parent c2f8602 commit c16412b

File tree

12 files changed

+159
-227
lines changed

12 files changed

+159
-227
lines changed

buildbot/configure.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ def do_configure(args):
3131
llvm_enable_projects = 'clang;' + llvm_external_projects
3232
libclc_targets_to_build = ''
3333
libclc_gen_remangled_variants = 'OFF'
34-
sycl_build_pi_cuda = 'OFF'
35-
sycl_build_pi_esimd_emulator = 'OFF'
36-
sycl_build_pi_hip = 'OFF'
3734
sycl_build_pi_hip_platform = 'AMD'
3835
sycl_clang_extra_flags = ''
3936
sycl_werror = 'ON'
@@ -42,6 +39,7 @@ def do_configure(args):
4239
llvm_enable_sphinx = 'OFF'
4340
llvm_build_shared_libs = 'OFF'
4441
llvm_enable_lld = 'OFF'
42+
sycl_enabled_plugins = ["opencl", "level_zero"]
4543

4644
sycl_enable_xpti_tracing = 'ON'
4745
xpti_enable_werror = 'ON'
@@ -51,7 +49,7 @@ def do_configure(args):
5149
llvm_targets_to_build = 'ARM;AArch64'
5250

5351
if args.enable_esimd_emulator:
54-
sycl_build_pi_esimd_emulator = 'ON'
52+
sycl_enabled_plugins.append("esimd_emulator")
5553

5654
if args.cuda or args.hip:
5755
llvm_enable_projects += ';libclc'
@@ -60,7 +58,7 @@ def do_configure(args):
6058
llvm_targets_to_build += ';NVPTX'
6159
libclc_targets_to_build = libclc_nvidia_target_names
6260
libclc_gen_remangled_variants = 'ON'
63-
sycl_build_pi_cuda = 'ON'
61+
sycl_enabled_plugins.append("cuda")
6462

6563
if args.hip:
6664
if args.hip_platform == 'AMD':
@@ -75,7 +73,7 @@ def do_configure(args):
7573
libclc_gen_remangled_variants = 'ON'
7674

7775
sycl_build_pi_hip_platform = args.hip_platform
78-
sycl_build_pi_hip = 'ON'
76+
sycl_enabled_plugins.append("hip")
7977

8078
if args.no_werror:
8179
sycl_werror = 'OFF'
@@ -115,6 +113,9 @@ def do_configure(args):
115113
if libclc_nvidia_target_names not in libclc_targets_to_build:
116114
libclc_targets_to_build += libclc_nvidia_target_names
117115

116+
if args.enable_plugin:
117+
sycl_enabled_plugins += args.enable_plugin
118+
118119
install_dir = os.path.join(abs_obj_dir, "install")
119120

120121
cmake_cmd = [
@@ -133,8 +134,6 @@ def do_configure(args):
133134
"-DLLVM_ENABLE_PROJECTS={}".format(llvm_enable_projects),
134135
"-DLIBCLC_TARGETS_TO_BUILD={}".format(libclc_targets_to_build),
135136
"-DLIBCLC_GENERATE_REMANGLED_VARIANTS={}".format(libclc_gen_remangled_variants),
136-
"-DSYCL_BUILD_PI_CUDA={}".format(sycl_build_pi_cuda),
137-
"-DSYCL_BUILD_PI_HIP={}".format(sycl_build_pi_hip),
138137
"-DSYCL_BUILD_PI_HIP_PLATFORM={}".format(sycl_build_pi_hip_platform),
139138
"-DLLVM_BUILD_TOOLS=ON",
140139
"-DSYCL_ENABLE_WERROR={}".format(sycl_werror),
@@ -145,9 +144,9 @@ def do_configure(args):
145144
"-DBUILD_SHARED_LIBS={}".format(llvm_build_shared_libs),
146145
"-DSYCL_ENABLE_XPTI_TRACING={}".format(sycl_enable_xpti_tracing),
147146
"-DLLVM_ENABLE_LLD={}".format(llvm_enable_lld),
148-
"-DSYCL_BUILD_PI_ESIMD_EMULATOR={}".format(sycl_build_pi_esimd_emulator),
149147
"-DXPTI_ENABLE_WERROR={}".format(xpti_enable_werror),
150-
"-DSYCL_CLANG_EXTRA_FLAGS={}".format(sycl_clang_extra_flags)
148+
"-DSYCL_CLANG_EXTRA_FLAGS={}".format(sycl_clang_extra_flags),
149+
"-DSYCL_ENABLE_PLUGINS={}".format(';'.join(set(sycl_enabled_plugins)))
151150
]
152151

153152
if args.l0_headers and args.l0_loader:
@@ -223,6 +222,7 @@ def main():
223222
parser.add_argument("--use-lld", action="store_true", help="Use LLD linker for build")
224223
parser.add_argument("--llvm-external-projects", help="Add external projects to build. Add as comma seperated list.")
225224
parser.add_argument("--ci-defaults", action="store_true", help="Enable default CI parameters")
225+
parser.add_argument("--enable-plugin", action='append', help="Enable SYCL plugin")
226226
args = parser.parse_args()
227227

228228
print("args:{}".format(args))

sycl/CMakeLists.txt

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ endif()
1616

1717
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
1818
include(AddSYCLExecutable)
19+
include(AddSYCL)
1920
include(SYCLUtils)
2021

2122
set(SYCL_MAJOR_VERSION 5)
@@ -27,6 +28,11 @@ if (SYCL_ADD_DEV_VERSION_POSTFIX)
2728
endif()
2829
set(SYCL_VERSION_STRING "${SYCL_MAJOR_VERSION}.${SYCL_MINOR_VERSION}.${SYCL_PATCH_VERSION}${SYCL_VERSION_POSTFIX}")
2930

31+
define_property(GLOBAL PROPERTY SYCL_TOOLCHAIN_INSTALL_COMPONENTS
32+
BRIEF_DOCS "List of components to deploy with SYCL toolchain"
33+
FULL_DOCS "List of components to deploy with SYCL toolchain"
34+
)
35+
3036
# enable all warnings by default
3137
if (MSVC)
3238
set(CMAKE_CXX_FLAGS "/W4 ${CMAKE_CXX_FLAGS}")
@@ -126,11 +132,16 @@ install(DIRECTORY ${OpenCL_INCLUDE_DIR}/CL
126132
DESTINATION ${SYCL_INCLUDE_DIR}/sycl
127133
COMPONENT OpenCL-Headers)
128134

129-
option(SYCL_BUILD_PI_CUDA
130-
"Enables the CUDA backend for the Plugin Interface" OFF)
131-
132-
option(SYCL_BUILD_PI_HIP
133-
"Enables the HIP backend for the Plugin Interface" OFF)
135+
# Needed for feature_test.hpp
136+
if ("cuda" IN_LIST SYCL_ENABLE_PLUGINS)
137+
set(SYCL_BUILD_PI_CUDA ON)
138+
endif()
139+
if ("hip" IN_LIST SYCL_ENABLE_PLUGINS)
140+
set(SYCL_BUILD_PI_HIP ON)
141+
endif()
142+
if ("esimd_emulator" IN_LIST SYCL_ENABLE_PLUGINS)
143+
set(SYCL_BUILD_PI_HIP ON)
144+
endif()
134145

135146
# Configure SYCL version macro
136147
set(sycl_inc_dir ${CMAKE_CURRENT_SOURCE_DIR}/include)
@@ -315,6 +326,7 @@ if(SYCL_INCLUDE_TESTS)
315326
add_subdirectory(test)
316327
endif()
317328

329+
get_property(SYCL_TOOLCHAIN_DEPS GLOBAL PROPERTY SYCL_TOOLCHAIN_INSTALL_COMPONENTS)
318330
# Package deploy support
319331
# Listed here are component names contributing the package
320332
set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS
@@ -344,10 +356,9 @@ set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS
344356
sycl-headers
345357
sycl-headers-extras
346358
sycl
347-
pi_opencl
348-
pi_level_zero
349359
libsycldevice
350360
${XPTIFW_LIBS}
361+
${SYCL_TOOLCHAIN_DEPS}
351362
)
352363

353364
if (TARGET sycl-prof)
@@ -364,7 +375,7 @@ if(OpenCL_INSTALL_KHRONOS_ICD_LOADER AND TARGET OpenCL-ICD)
364375
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS OpenCL-ICD)
365376
endif()
366377

367-
if(SYCL_BUILD_PI_CUDA)
378+
if("cuda" IN_LIST SYCL_ENABLE_PLUGINS)
368379
# Ensure that libclc is enabled.
369380
list(FIND LLVM_ENABLE_PROJECTS libclc LIBCLC_FOUND)
370381
if( LIBCLC_FOUND EQUAL -1 )
@@ -376,7 +387,7 @@ if(SYCL_BUILD_PI_CUDA)
376387
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libspirv-builtins pi_cuda)
377388
endif()
378389

379-
if(SYCL_BUILD_PI_HIP)
390+
if("hip" IN_LIST SYCL_ENABLE_PLUGINS)
380391
# Ensure that libclc is enabled.
381392
list(FIND LLVM_ENABLE_PROJECTS libclc LIBCLC_FOUND)
382393
if( LIBCLC_FOUND EQUAL -1 )
@@ -388,7 +399,7 @@ if(SYCL_BUILD_PI_HIP)
388399
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libspirv-builtins pi_hip)
389400
endif()
390401

391-
if(SYCL_BUILD_PI_ESIMD_EMULATOR)
402+
if("esimd_emulator" IN_LIST SYCL_ENABLE_PLUGINS)
392403
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS pi_esimd_emulator libcmrt-headers)
393404
if (MSVC)
394405
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libcmrt-libs libcmrt-dlls)

sycl/cmake/modules/AddSYCL.cmake

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
function(add_sycl_library LIB_NAME TYPE)
2+
cmake_parse_arguments("ARG"
3+
"TOOLCHAIN"
4+
"LINKER_SCRIPT"
5+
"SOURCES;INCLUDE_DIRS;LIBRARIES"
6+
${ARGN}
7+
)
8+
add_library(${LIB_NAME} ${TYPE} ${ARG_SOURCES})
9+
target_include_directories(${LIB_NAME} PRIVATE ${ARG_INCLUDE_DIRS})
10+
target_link_libraries(${LIB_NAME} PRIVATE ${ARG_LIBRARIES})
11+
12+
if (ARG_TOOLCHAIN)
13+
add_dependencies(sycl-toolchain ${LIB_NAME})
14+
endif()
15+
16+
if (ARG_LINKER_SCRIPT AND UNIX)
17+
target_link_libraries(${LIB_NAME} PRIVATE
18+
"-Wl,--version-script=${ARG_LINKER_SCRIPT}")
19+
endif()
20+
21+
target_compile_definitions(${LIB_NAME} PRIVATE __SYCL_BUILD_SYCL_DLL)
22+
23+
if (UNIX)
24+
target_compile_options(${LIB_NAME} PRIVATE -fvisibility=hidden)
25+
else()
26+
add_stripped_pdb(${LIB_NAME})
27+
endif()
28+
29+
# TODO remove add_common_options
30+
add_common_options(${LIB_NAME})
31+
endfunction()
32+
33+
function(add_sycl_plugin PLUGIN_NAME)
34+
cmake_parse_arguments("ARG"
35+
""
36+
""
37+
"SOURCES;INCLUDE_DIRS;LIBRARIES"
38+
${ARGN}
39+
)
40+
41+
add_sycl_library("pi_${PLUGIN_NAME}" SHARED
42+
TOOLCHAIN
43+
LINKER_SCRIPT "${PROJECT_SOURCE_DIR}/plugins/ld-version-script.txt"
44+
SOURCES ${ARG_SOURCES}
45+
INCLUDE_DIRS
46+
${ARG_INCLUDE_DIRS}
47+
${sycl_inc_dir}
48+
LIBRARIES
49+
${ARG_LIBRARIES}
50+
OpenCL-Headers
51+
)
52+
53+
install(TARGETS pi_${PLUGIN_NAME}
54+
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT pi_${PLUGIN_NAME}
55+
RUNTIME DESTINATION "bin" COMPONENT pi_${PLUGIN_NAME})
56+
57+
set (manifest_file
58+
${CMAKE_CURRENT_BINARY_DIR}/install_manifest_pi_${PLUGIN_NAME}.txt)
59+
add_custom_command(OUTPUT ${manifest_file}
60+
COMMAND "${CMAKE_COMMAND}"
61+
"-DCMAKE_INSTALL_COMPONENT=pi_${PLUGIN_NAME}"
62+
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
63+
COMMENT "Deploying component pi_${PLUGIN_NAME}"
64+
USES_TERMINAL
65+
)
66+
add_custom_target(install-sycl-plugin-${PLUGIN_NAME}
67+
DEPENDS
68+
${manifest_file} pi_${PLUGIN_NAME}
69+
)
70+
71+
set_property(GLOBAL APPEND PROPERTY SYCL_TOOLCHAIN_INSTALL_COMPONENTS
72+
pi_${PLUGIN_NAME})
73+
endfunction()

sycl/doc/GetStartedGuide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ The SYCL host device executes the SYCL application directly in the host,
695695
without using any low-level API.
696696
697697
**NOTE**: `nvptx64-nvidia-cuda` is usable with `-fsycl-targets`
698-
if clang was built with the cmake option `SYCL_BUILD_PI_CUDA=ON`.
698+
if clang was built with the cmake option `SYCL_ENABLE_PLUGINS=cuda`.
699699
700700
**Linux & Windows (64-bit)**:
701701

sycl/plugins/CMakeLists.txt

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang|IntelLLVM" )
44
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-covered-switch-default")
55
endif()
66

7-
if(SYCL_BUILD_PI_CUDA)
8-
add_subdirectory(cuda)
9-
endif()
10-
11-
if(SYCL_BUILD_PI_HIP)
12-
add_subdirectory(hip)
13-
endif()
7+
foreach(plugin ${SYCL_ENABLE_PLUGINS})
8+
add_subdirectory(${plugin})
9+
endforeach()
1410

15-
add_subdirectory(opencl)
16-
add_subdirectory(level_zero)
17-
18-
if(SYCL_BUILD_PI_ESIMD_EMULATOR)
19-
# TODO : Remove 'if (NOT MSVC)' when CM_EMU supports Windows
20-
# environment
21-
if (NOT MSVC)
22-
add_subdirectory(esimd_emulator)
23-
endif()
24-
endif()

sycl/plugins/cuda/CMakeLists.txt

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
message(STATUS "Including the PI API CUDA backend.")
32

43
# cannot rely on cmake support for CUDA; it assumes runtime API is being used.
@@ -24,51 +23,15 @@ else()
2423
)
2524
endif()
2625

27-
add_library(pi_cuda SHARED
28-
"${sycl_inc_dir}/CL/sycl/detail/pi.h"
29-
"${sycl_inc_dir}/CL/sycl/detail/pi.hpp"
30-
"pi_cuda.hpp"
31-
"pi_cuda.cpp"
32-
)
33-
34-
add_dependencies(sycl-toolchain pi_cuda)
35-
36-
set_target_properties(pi_cuda PROPERTIES LINKER_LANGUAGE CXX)
37-
38-
target_include_directories(pi_cuda
39-
PRIVATE
40-
${sycl_inc_dir}
41-
)
42-
43-
target_link_libraries(pi_cuda
44-
PRIVATE
45-
OpenCL-Headers
26+
add_sycl_plugin(cuda
27+
SOURCES
28+
"${sycl_inc_dir}/CL/sycl/detail/pi.h"
29+
"${sycl_inc_dir}/CL/sycl/detail/pi.hpp"
30+
"pi_cuda.hpp"
31+
"pi_cuda.cpp"
32+
LIBRARIES
4633
cudadrv
4734
)
4835

49-
if (MSVC)
50-
# by defining __SYCL_BUILD_SYCL_DLL, we can use __declspec(dllexport)
51-
# which are individually tagged for all pi* symbols in pi.h
52-
target_compile_definitions(pi_cuda PRIVATE __SYCL_BUILD_SYCL_DLL)
53-
# Install stripped PDB
54-
add_stripped_pdb(pi_cuda)
55-
else()
56-
# we set the visibility of all symbols 'hidden' by default.
57-
# In pi.h file, we set exported symbols with visibility==default individually
58-
target_compile_options(pi_cuda PUBLIC -fvisibility=hidden)
59-
60-
# This script file is used to allow exporting pi* symbols only.
61-
# All other symbols are regarded as local (hidden)
62-
set(linker_script "${CMAKE_CURRENT_SOURCE_DIR}/../ld-version-script.txt")
63-
64-
# Filter symbols based on the scope defined in the script file,
65-
# and export pi* function symbols in the library.
66-
target_link_libraries(pi_cuda PRIVATE "-Wl,--version-script=${linker_script}")
67-
endif()
68-
69-
add_common_options(pi_cuda)
36+
set_target_properties(pi_cuda PROPERTIES LINKER_LANGUAGE CXX)
7037

71-
install(TARGETS pi_cuda
72-
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT pi_cuda
73-
RUNTIME DESTINATION "bin" COMPONENT pi_cuda
74-
)

0 commit comments

Comments
 (0)