Skip to content

[SYCL][NFC] Refactor plugin CMakeLists.txt #5799

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

Merged
merged 7 commits into from
Apr 1, 2022
Merged
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
20 changes: 10 additions & 10 deletions buildbot/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ def do_configure(args):
llvm_enable_projects = 'clang;' + llvm_external_projects
libclc_targets_to_build = ''
libclc_gen_remangled_variants = 'OFF'
sycl_build_pi_cuda = 'OFF'
sycl_build_pi_esimd_emulator = 'OFF'
sycl_build_pi_hip = 'OFF'
sycl_build_pi_hip_platform = 'AMD'
sycl_clang_extra_flags = ''
sycl_werror = 'ON'
Expand All @@ -42,6 +39,7 @@ def do_configure(args):
llvm_enable_sphinx = 'OFF'
llvm_build_shared_libs = 'OFF'
llvm_enable_lld = 'OFF'
sycl_enabled_plugins = ["opencl", "level_zero"]

sycl_enable_xpti_tracing = 'ON'
xpti_enable_werror = 'ON'
Expand All @@ -51,7 +49,7 @@ def do_configure(args):
llvm_targets_to_build = 'ARM;AArch64'

if args.enable_esimd_emulator:
sycl_build_pi_esimd_emulator = 'ON'
sycl_enabled_plugins.append("esimd_emulator")

if args.cuda or args.hip:
llvm_enable_projects += ';libclc'
Expand All @@ -60,7 +58,7 @@ def do_configure(args):
llvm_targets_to_build += ';NVPTX'
libclc_targets_to_build = libclc_nvidia_target_names
libclc_gen_remangled_variants = 'ON'
sycl_build_pi_cuda = 'ON'
sycl_enabled_plugins.append("cuda")

if args.hip:
if args.hip_platform == 'AMD':
Expand All @@ -75,7 +73,7 @@ def do_configure(args):
libclc_gen_remangled_variants = 'ON'

sycl_build_pi_hip_platform = args.hip_platform
sycl_build_pi_hip = 'ON'
sycl_enabled_plugins.append("hip")

if args.no_werror:
sycl_werror = 'OFF'
Expand Down Expand Up @@ -115,6 +113,9 @@ def do_configure(args):
if libclc_nvidia_target_names not in libclc_targets_to_build:
libclc_targets_to_build += libclc_nvidia_target_names

if args.enable_plugin:
sycl_enabled_plugins += args.enable_plugin

install_dir = os.path.join(abs_obj_dir, "install")

cmake_cmd = [
Expand All @@ -133,8 +134,6 @@ def do_configure(args):
"-DLLVM_ENABLE_PROJECTS={}".format(llvm_enable_projects),
"-DLIBCLC_TARGETS_TO_BUILD={}".format(libclc_targets_to_build),
"-DLIBCLC_GENERATE_REMANGLED_VARIANTS={}".format(libclc_gen_remangled_variants),
"-DSYCL_BUILD_PI_CUDA={}".format(sycl_build_pi_cuda),
"-DSYCL_BUILD_PI_HIP={}".format(sycl_build_pi_hip),
"-DSYCL_BUILD_PI_HIP_PLATFORM={}".format(sycl_build_pi_hip_platform),
"-DLLVM_BUILD_TOOLS=ON",
"-DSYCL_ENABLE_WERROR={}".format(sycl_werror),
Expand All @@ -145,9 +144,9 @@ def do_configure(args):
"-DBUILD_SHARED_LIBS={}".format(llvm_build_shared_libs),
"-DSYCL_ENABLE_XPTI_TRACING={}".format(sycl_enable_xpti_tracing),
"-DLLVM_ENABLE_LLD={}".format(llvm_enable_lld),
"-DSYCL_BUILD_PI_ESIMD_EMULATOR={}".format(sycl_build_pi_esimd_emulator),
"-DXPTI_ENABLE_WERROR={}".format(xpti_enable_werror),
"-DSYCL_CLANG_EXTRA_FLAGS={}".format(sycl_clang_extra_flags)
"-DSYCL_CLANG_EXTRA_FLAGS={}".format(sycl_clang_extra_flags),
"-DSYCL_ENABLE_PLUGINS={}".format(';'.join(set(sycl_enabled_plugins)))
]

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

print("args:{}".format(args))
Expand Down
31 changes: 21 additions & 10 deletions sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(AddSYCLExecutable)
include(AddSYCL)
include(SYCLUtils)

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

define_property(GLOBAL PROPERTY SYCL_TOOLCHAIN_INSTALL_COMPONENTS
BRIEF_DOCS "List of components to deploy with SYCL toolchain"
FULL_DOCS "List of components to deploy with SYCL toolchain"
)

# enable all warnings by default
if (MSVC)
set(CMAKE_CXX_FLAGS "/W4 ${CMAKE_CXX_FLAGS}")
Expand Down Expand Up @@ -126,11 +132,16 @@ install(DIRECTORY ${OpenCL_INCLUDE_DIR}/CL
DESTINATION ${SYCL_INCLUDE_DIR}/sycl
COMPONENT OpenCL-Headers)

option(SYCL_BUILD_PI_CUDA
"Enables the CUDA backend for the Plugin Interface" OFF)

option(SYCL_BUILD_PI_HIP
"Enables the HIP backend for the Plugin Interface" OFF)
# Needed for feature_test.hpp
if ("cuda" IN_LIST SYCL_ENABLE_PLUGINS)
set(SYCL_BUILD_PI_CUDA ON)
endif()
if ("hip" IN_LIST SYCL_ENABLE_PLUGINS)
set(SYCL_BUILD_PI_HIP ON)
endif()
if ("esimd_emulator" IN_LIST SYCL_ENABLE_PLUGINS)
set(SYCL_BUILD_PI_HIP ON)
Copy link
Contributor

Choose a reason for hiding this comment

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

@pvchupin , is this typo?

Copy link
Contributor

Choose a reason for hiding this comment

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

@dongkyunahn-intel, yes, I think so. Looks like that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll apply fix in my PR later - #6027.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be SYCL_BUILD_PI_ESIMD_EMULATOR

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for catching that!

endif()

# Configure SYCL version macro
set(sycl_inc_dir ${CMAKE_CURRENT_SOURCE_DIR}/include)
Expand Down Expand Up @@ -315,6 +326,7 @@ if(SYCL_INCLUDE_TESTS)
add_subdirectory(test)
endif()

get_property(SYCL_TOOLCHAIN_DEPS GLOBAL PROPERTY SYCL_TOOLCHAIN_INSTALL_COMPONENTS)
# Package deploy support
# Listed here are component names contributing the package
set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS
Expand Down Expand Up @@ -344,10 +356,9 @@ set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS
sycl-headers
sycl-headers-extras
sycl
pi_opencl
pi_level_zero
libsycldevice
${XPTIFW_LIBS}
${SYCL_TOOLCHAIN_DEPS}
)

if (TARGET sycl-prof)
Expand All @@ -364,7 +375,7 @@ if(OpenCL_INSTALL_KHRONOS_ICD_LOADER AND TARGET OpenCL-ICD)
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS OpenCL-ICD)
endif()

if(SYCL_BUILD_PI_CUDA)
if("cuda" IN_LIST SYCL_ENABLE_PLUGINS)
# Ensure that libclc is enabled.
list(FIND LLVM_ENABLE_PROJECTS libclc LIBCLC_FOUND)
if( LIBCLC_FOUND EQUAL -1 )
Expand All @@ -376,7 +387,7 @@ if(SYCL_BUILD_PI_CUDA)
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libspirv-builtins pi_cuda)
endif()

if(SYCL_BUILD_PI_HIP)
if("hip" IN_LIST SYCL_ENABLE_PLUGINS)
# Ensure that libclc is enabled.
list(FIND LLVM_ENABLE_PROJECTS libclc LIBCLC_FOUND)
if( LIBCLC_FOUND EQUAL -1 )
Expand All @@ -388,7 +399,7 @@ if(SYCL_BUILD_PI_HIP)
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libspirv-builtins pi_hip)
endif()

if(SYCL_BUILD_PI_ESIMD_EMULATOR)
if("esimd_emulator" IN_LIST SYCL_ENABLE_PLUGINS)
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS pi_esimd_emulator libcmrt-headers)
if (MSVC)
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libcmrt-libs libcmrt-dlls)
Expand Down
73 changes: 73 additions & 0 deletions sycl/cmake/modules/AddSYCL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
function(add_sycl_library LIB_NAME TYPE)
cmake_parse_arguments("ARG"
"TOOLCHAIN"
"LINKER_SCRIPT"
"SOURCES;INCLUDE_DIRS;LIBRARIES"
${ARGN}
)
add_library(${LIB_NAME} ${TYPE} ${ARG_SOURCES})
target_include_directories(${LIB_NAME} PRIVATE ${ARG_INCLUDE_DIRS})
target_link_libraries(${LIB_NAME} PRIVATE ${ARG_LIBRARIES})

if (ARG_TOOLCHAIN)
add_dependencies(sycl-toolchain ${LIB_NAME})
endif()

if (ARG_LINKER_SCRIPT AND UNIX)
target_link_libraries(${LIB_NAME} PRIVATE
"-Wl,--version-script=${ARG_LINKER_SCRIPT}")
endif()

target_compile_definitions(${LIB_NAME} PRIVATE __SYCL_BUILD_SYCL_DLL)

if (UNIX)
target_compile_options(${LIB_NAME} PRIVATE -fvisibility=hidden)
else()
add_stripped_pdb(${LIB_NAME})
endif()

# TODO remove add_common_options
add_common_options(${LIB_NAME})
endfunction()

function(add_sycl_plugin PLUGIN_NAME)
cmake_parse_arguments("ARG"
""
""
"SOURCES;INCLUDE_DIRS;LIBRARIES"
${ARGN}
)

add_sycl_library("pi_${PLUGIN_NAME}" SHARED
TOOLCHAIN
LINKER_SCRIPT "${PROJECT_SOURCE_DIR}/plugins/ld-version-script.txt"
SOURCES ${ARG_SOURCES}
INCLUDE_DIRS
${ARG_INCLUDE_DIRS}
${sycl_inc_dir}
LIBRARIES
${ARG_LIBRARIES}
OpenCL-Headers
)

install(TARGETS pi_${PLUGIN_NAME}
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT pi_${PLUGIN_NAME}
RUNTIME DESTINATION "bin" COMPONENT pi_${PLUGIN_NAME})

set (manifest_file
${CMAKE_CURRENT_BINARY_DIR}/install_manifest_pi_${PLUGIN_NAME}.txt)
add_custom_command(OUTPUT ${manifest_file}
COMMAND "${CMAKE_COMMAND}"
"-DCMAKE_INSTALL_COMPONENT=pi_${PLUGIN_NAME}"
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
COMMENT "Deploying component pi_${PLUGIN_NAME}"
USES_TERMINAL
)
add_custom_target(install-sycl-plugin-${PLUGIN_NAME}
DEPENDS
${manifest_file} pi_${PLUGIN_NAME}
)

set_property(GLOBAL APPEND PROPERTY SYCL_TOOLCHAIN_INSTALL_COMPONENTS
pi_${PLUGIN_NAME})
endfunction()
2 changes: 1 addition & 1 deletion sycl/doc/GetStartedGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ The SYCL host device executes the SYCL application directly in the host,
without using any low-level API.

**NOTE**: `nvptx64-nvidia-cuda` is usable with `-fsycl-targets`
if clang was built with the cmake option `SYCL_BUILD_PI_CUDA=ON`.
if clang was built with the cmake option `SYCL_ENABLE_PLUGINS=cuda`.

**Linux & Windows (64-bit)**:

Expand Down
20 changes: 3 additions & 17 deletions sycl/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang|IntelLLVM" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-covered-switch-default")
endif()

if(SYCL_BUILD_PI_CUDA)
add_subdirectory(cuda)
endif()

if(SYCL_BUILD_PI_HIP)
add_subdirectory(hip)
endif()
foreach(plugin ${SYCL_ENABLE_PLUGINS})
add_subdirectory(${plugin})
endforeach()

add_subdirectory(opencl)
add_subdirectory(level_zero)

if(SYCL_BUILD_PI_ESIMD_EMULATOR)
# TODO : Remove 'if (NOT MSVC)' when CM_EMU supports Windows
# environment
if (NOT MSVC)
add_subdirectory(esimd_emulator)
endif()
endif()
53 changes: 8 additions & 45 deletions sycl/plugins/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

message(STATUS "Including the PI API CUDA backend.")

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

add_library(pi_cuda SHARED
"${sycl_inc_dir}/CL/sycl/detail/pi.h"
"${sycl_inc_dir}/CL/sycl/detail/pi.hpp"
"pi_cuda.hpp"
"pi_cuda.cpp"
)

add_dependencies(sycl-toolchain pi_cuda)

set_target_properties(pi_cuda PROPERTIES LINKER_LANGUAGE CXX)

target_include_directories(pi_cuda
PRIVATE
${sycl_inc_dir}
)

target_link_libraries(pi_cuda
PRIVATE
OpenCL-Headers
add_sycl_plugin(cuda
SOURCES
"${sycl_inc_dir}/CL/sycl/detail/pi.h"
"${sycl_inc_dir}/CL/sycl/detail/pi.hpp"
"pi_cuda.hpp"
"pi_cuda.cpp"
LIBRARIES
cudadrv
)

if (MSVC)
# by defining __SYCL_BUILD_SYCL_DLL, we can use __declspec(dllexport)
# which are individually tagged for all pi* symbols in pi.h
target_compile_definitions(pi_cuda PRIVATE __SYCL_BUILD_SYCL_DLL)
# Install stripped PDB
add_stripped_pdb(pi_cuda)
else()
# we set the visibility of all symbols 'hidden' by default.
# In pi.h file, we set exported symbols with visibility==default individually
target_compile_options(pi_cuda PUBLIC -fvisibility=hidden)

# This script file is used to allow exporting pi* symbols only.
# All other symbols are regarded as local (hidden)
set(linker_script "${CMAKE_CURRENT_SOURCE_DIR}/../ld-version-script.txt")

# Filter symbols based on the scope defined in the script file,
# and export pi* function symbols in the library.
target_link_libraries(pi_cuda PRIVATE "-Wl,--version-script=${linker_script}")
endif()

add_common_options(pi_cuda)
set_target_properties(pi_cuda PROPERTIES LINKER_LANGUAGE CXX)

install(TARGETS pi_cuda
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT pi_cuda
RUNTIME DESTINATION "bin" COMPONENT pi_cuda
)
Loading