From ff947d1aeefd33c62b23beacc0368518777e3156 Mon Sep 17 00:00:00 2001 From: Steffen Larsen Date: Fri, 23 Apr 2021 16:21:52 +0100 Subject: [PATCH 1/7] [SYCL][CUDA] Add support for MSVC Signed-off-by: Steffen Larsen --- clang/lib/Driver/ToolChains/Cuda.cpp | 48 +++++++++++++------ libclc/cmake/modules/HandleInLLVMTree.cmake | 36 +++++++------- libclc/utils/prepare-builtins.cpp | 11 +++++ sycl/include/CL/sycl/detail/pi.hpp | 2 +- sycl/plugins/cuda/CMakeLists.txt | 36 ++++++++++++-- sycl/plugins/cuda/pi_cuda.cpp | 12 +++-- sycl/plugins/level_zero/CMakeLists.txt | 9 ++++ sycl/unittests/pi/TestGetPlugin.hpp | 8 ++-- sycl/unittests/pi/cuda/test_base_objects.cpp | 4 +- sycl/unittests/pi/cuda/test_commands.cpp | 6 +-- sycl/unittests/pi/cuda/test_device.cpp | 6 +-- sycl/unittests/pi/cuda/test_kernels.cpp | 6 +-- sycl/unittests/pi/cuda/test_mem_obj.cpp | 6 +-- sycl/unittests/pi/cuda/test_queue.cpp | 6 +-- .../pi/cuda/test_sampler_properties.cpp | 14 +++--- 15 files changed, 143 insertions(+), 67 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp index b37ac80dfc73d..f137570a522a7 100644 --- a/clang/lib/Driver/ToolChains/Cuda.cpp +++ b/clang/lib/Driver/ToolChains/Cuda.cpp @@ -77,6 +77,8 @@ CudaVersion getCudaVersion(uint32_t raw_version) { return CudaVersion::CUDA_110; if (raw_version < 11020) return CudaVersion::CUDA_111; + if (raw_version < 11030) + return CudaVersion::CUDA_112; return CudaVersion::LATEST; } @@ -131,7 +133,9 @@ CudaInstallationDetector::CudaInstallationDetector( SmallVector Candidates; // In decreasing order so we prefer newer versions to older versions. - std::initializer_list Versions = {"8.0", "7.5", "7.0"}; + std::initializer_list Versions = { + "11.4", "11.3", "11.2", "11.1", "10.2", "10.1", "10.0", + "9.2", "9.1", "9.0", "8.0", "7.5", "7.0"}; auto &FS = D.getVFS(); if (Args.hasArg(clang::driver::options::OPT_cuda_path_EQ)) { @@ -193,18 +197,27 @@ CudaInstallationDetector::CudaInstallationDetector( if (CheckLibDevice && !FS.exists(LibDevicePath)) continue; - // On Linux, we have both lib and lib64 directories, and we need to choose - // based on our triple. On MacOS, we have only a lib directory. - // - // It's sufficient for our purposes to be flexible: If both lib and lib64 - // exist, we choose whichever one matches our triple. Otherwise, if only - // lib exists, we use it. - if (HostTriple.isArch64Bit() && FS.exists(InstallPath + "/lib64")) - LibPath = InstallPath + "/lib64"; - else if (FS.exists(InstallPath + "/lib")) - LibPath = InstallPath + "/lib"; - else - continue; + if (HostTriple.isOSWindows()) { + if (HostTriple.isArch64Bit() && FS.exists(InstallPath + "/lib/x64")) + LibPath = InstallPath + "/lib/x64"; + else if (FS.exists(InstallPath + "/lib/Win32")) + LibPath = InstallPath + "/lib/Win32"; + else + continue; + } else { + // On Linux, we have both lib and lib64 directories, and we need to choose + // based on our triple. On MacOS, we have only a lib directory. + // + // It's sufficient for our purposes to be flexible: If both lib and lib64 + // exist, we choose whichever one matches our triple. Otherwise, if only + // lib exists, we use it. + if (HostTriple.isArch64Bit() && FS.exists(InstallPath + "/lib64")) + LibPath = InstallPath + "/lib64"; + else if (FS.exists(InstallPath + "/lib")) + LibPath = InstallPath + "/lib"; + else + continue; + } CudaVersionInfo VersionInfo = {"", CudaVersion::UNKNOWN}; if (auto VersionFile = FS.getBufferForFile(InstallPath + "/version.txt")) @@ -722,7 +735,14 @@ void CudaToolChain::addClangTargetOptions( llvm::sys::path::append(WithInstallPath, Twine("../../../share/clc")); LibraryPaths.emplace_back(WithInstallPath.c_str()); - std::string LibSpirvTargetName = "libspirv-nvptx64--nvidiacl.bc"; + // Select remangled libclc variant. 64-bit longs default, 32-bit longs on + // Windows + std::string LibSpirvTargetName = + "remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc"; + if (HostTC.getTriple().isOSWindows()) + LibSpirvTargetName = + "remangled-l32-signed_char.libspirv-nvptx64--nvidiacl.bc"; + for (StringRef LibraryPath : LibraryPaths) { SmallString<128> LibSpirvTargetFile(LibraryPath); llvm::sys::path::append(LibSpirvTargetFile, LibSpirvTargetName); diff --git a/libclc/cmake/modules/HandleInLLVMTree.cmake b/libclc/cmake/modules/HandleInLLVMTree.cmake index 674c22b22fff2..5298bd41c539b 100644 --- a/libclc/cmake/modules/HandleInLLVMTree.cmake +++ b/libclc/cmake/modules/HandleInLLVMTree.cmake @@ -1,21 +1,25 @@ macro(configure_in_llvm_tree) - set(LLVM_CLANG ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang) - set(LLVM_AS ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-as) - set(LLVM_LINK ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-link) - set(LLVM_OPT ${LLVM_RUNTIME_OUTPUT_INTDIR}/opt) + set(LLVM_CLANG ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX}) + set(LLVM_AS ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-as${CMAKE_EXECUTABLE_SUFFIX}) + set(LLVM_LINK ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-link${CMAKE_EXECUTABLE_SUFFIX}) + set(LLVM_OPT ${LLVM_RUNTIME_OUTPUT_INTDIR}/opt${CMAKE_EXECUTABLE_SUFFIX}) + set(LIBCLC_REMANGLER ${LLVM_RUNTIME_OUTPUT_INTDIR}/libclc-remangler${CMAKE_EXECUTABLE_SUFFIX}) - if (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang) - file(WRITE ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang "" ) - endif (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang) - if (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-as) - file(WRITE ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-as "" ) - endif (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-as) - if (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-link) - file(WRITE ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-link "" ) - endif (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-link) - if (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/opt) - file(WRITE ${LLVM_RUNTIME_OUTPUT_INTDIR}/opt "" ) - endif (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/opt) + if (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX}) + file(WRITE ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX} "" ) + endif (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX}) + if (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-as${CMAKE_EXECUTABLE_SUFFIX}) + file(WRITE ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-as${CMAKE_EXECUTABLE_SUFFIX} "" ) + endif (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-as${CMAKE_EXECUTABLE_SUFFIX}) + if (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-link${CMAKE_EXECUTABLE_SUFFIX}) + file(WRITE ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-link${CMAKE_EXECUTABLE_SUFFIX} "" ) + endif (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-link${CMAKE_EXECUTABLE_SUFFIX}) + if (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/opt${CMAKE_EXECUTABLE_SUFFIX}) + file(WRITE ${LLVM_RUNTIME_OUTPUT_INTDIR}/opt${CMAKE_EXECUTABLE_SUFFIX} "" ) + endif (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/opt${CMAKE_EXECUTABLE_SUFFIX}) + if (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/libclc-remangler${CMAKE_EXECUTABLE_SUFFIX}) + file(WRITE ${LLVM_RUNTIME_OUTPUT_INTDIR}/libclc-remangler${CMAKE_EXECUTABLE_SUFFIX} "" ) + endif (NOT EXISTS ${LLVM_RUNTIME_OUTPUT_INTDIR}/libclc-remangler${CMAKE_EXECUTABLE_SUFFIX}) # Assume all works well # We can't test the compilers as they haven't been built yet diff --git a/libclc/utils/prepare-builtins.cpp b/libclc/utils/prepare-builtins.cpp index 550b5971913f4..2479c964f3b98 100644 --- a/libclc/utils/prepare-builtins.cpp +++ b/libclc/utils/prepare-builtins.cpp @@ -75,6 +75,17 @@ int main(int argc, char **argv) { if (NamedMDNode *OCLVersion = M->getNamedMetadata("opencl.ocl.version")) M->eraseNamedMetadata(OCLVersion); + // Drop wchar_size module flag + if (M->getModuleFlag("wchar_size")) { + SmallVector ModuleFlags; + M->getModuleFlagsMetadata(ModuleFlags); + M->getModuleFlagsMetadata()->clearOperands(); + for (const Module::ModuleFlagEntry ModuleFlag : ModuleFlags) + if (ModuleFlag.Key->getString() != "wchar_size") + M->addModuleFlag(ModuleFlag.Behavior, ModuleFlag.Key->getString(), + ModuleFlag.Val); + } + // Set linkage of every external definition to linkonce_odr. for (Module::iterator i = M->begin(), e = M->end(); i != e; ++i) { if (!i->isDeclaration() && i->getLinkage() == GlobalValue::ExternalLinkage) diff --git a/sycl/include/CL/sycl/detail/pi.hpp b/sycl/include/CL/sycl/detail/pi.hpp index a0f553309b5cf..007ef5406c556 100644 --- a/sycl/include/CL/sycl/detail/pi.hpp +++ b/sycl/include/CL/sycl/detail/pi.hpp @@ -14,13 +14,13 @@ #pragma once #include -#include #include #include #include #include #include +#include #include #include #include diff --git a/sycl/plugins/cuda/CMakeLists.txt b/sycl/plugins/cuda/CMakeLists.txt index be94f687e12d0..1518bc5640890 100644 --- a/sycl/plugins/cuda/CMakeLists.txt +++ b/sycl/plugins/cuda/CMakeLists.txt @@ -9,11 +9,19 @@ find_package(CUDA 10.1 REQUIRED) # Make imported library global to use it within the project. add_library(cudadrv SHARED IMPORTED GLOBAL) -set_target_properties( - cudadrv PROPERTIES - IMPORTED_LOCATION ${CUDA_CUDA_LIBRARY} - INTERFACE_INCLUDE_DIRECTORIES ${CUDA_INCLUDE_DIRS} -) +if (WIN32) + set_target_properties( + cudadrv PROPERTIES + IMPORTED_IMPLIB ${CUDA_CUDA_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${CUDA_INCLUDE_DIRS} + ) +else() + set_target_properties( + cudadrv PROPERTIES + IMPORTED_LOCATION ${CUDA_CUDA_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${CUDA_INCLUDE_DIRS} + ) +endif() add_library(pi_cuda SHARED "${sycl_inc_dir}/CL/sycl/detail/pi.h" @@ -37,6 +45,24 @@ target_link_libraries(pi_cuda 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) +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) install(TARGETS pi_cuda diff --git a/sycl/plugins/cuda/pi_cuda.cpp b/sycl/plugins/cuda/pi_cuda.cpp index 92993d47ebb8a..9f54d89299b4b 100644 --- a/sycl/plugins/cuda/pi_cuda.cpp +++ b/sycl/plugins/cuda/pi_cuda.cpp @@ -680,10 +680,10 @@ pi_result cuda_piPlatformsGet(pi_uint32 num_entries, pi_platform *platforms, static pi_uint32 numPlatforms = 1; static _pi_platform platformId; - if (num_entries == 0 and platforms != nullptr) { + if (num_entries == 0 && platforms != nullptr) { return PI_INVALID_VALUE; } - if (platforms == nullptr and num_platforms == nullptr) { + if (platforms == nullptr && num_platforms == nullptr) { return PI_INVALID_VALUE; } @@ -4480,7 +4480,7 @@ pi_result cuda_piextUSMFree(pi_context context, void *ptr) { CU_POINTER_ATTRIBUTE_MEMORY_TYPE}; result = PI_CHECK_ERROR(cuPointerGetAttributes( 2, attributes, attribute_values, (CUdeviceptr)ptr)); - assert(type == CU_MEMORYTYPE_DEVICE or type == CU_MEMORYTYPE_HOST); + assert(type == CU_MEMORYTYPE_DEVICE || type == CU_MEMORYTYPE_HOST); if (is_managed || type == CU_MEMORYTYPE_DEVICE) { // Memory allocated with cuMemAlloc and cuMemAllocManaged must be freed // with cuMemFree @@ -4684,7 +4684,7 @@ pi_result cuda_piextUSMGetMemAllocInfo(pi_context context, const void *ptr, } result = PI_CHECK_ERROR(cuPointerGetAttribute( &value, CU_POINTER_ATTRIBUTE_MEMORY_TYPE, (CUdeviceptr)ptr)); - assert(value == CU_MEMORYTYPE_DEVICE or value == CU_MEMORYTYPE_HOST); + assert(value == CU_MEMORYTYPE_DEVICE || value == CU_MEMORYTYPE_HOST); if (value == CU_MEMORYTYPE_DEVICE) { // pointer to device memory return getInfo(param_value_size, param_value, param_value_size_ret, @@ -4696,7 +4696,11 @@ pi_result cuda_piextUSMGetMemAllocInfo(pi_context context, const void *ptr, PI_MEM_TYPE_HOST); } // should never get here +#ifdef _MSC_VER + __assume(0); +#else __builtin_unreachable(); +#endif return getInfo(param_value_size, param_value, param_value_size_ret, PI_MEM_TYPE_UNKNOWN); } diff --git a/sycl/plugins/level_zero/CMakeLists.txt b/sycl/plugins/level_zero/CMakeLists.txt index 52f205f1abb81..772a0972946e9 100755 --- a/sycl/plugins/level_zero/CMakeLists.txt +++ b/sycl/plugins/level_zero/CMakeLists.txt @@ -58,6 +58,15 @@ if (NOT DEFINED LEVEL_ZERO_LIBRARY OR NOT DEFINED LEVEL_ZERO_INCLUDE_DIR) DEPENDEES install ) + if (WIN32) + # Copy DLL into binary directory + ExternalProject_Add_Step(level-zero-loader llvmbininstall + COMMAND ${CMAKE_COMMAND} -E copy_directory /bin/ ${LLVM_BINARY_DIR}/bin + COMMENT "Installing level-zero-loader into the LLVM binary directory" + DEPENDEES install + ) + endif() + install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/level_zero_loader_install/" DESTINATION "." COMPONENT level-zero-loader diff --git a/sycl/unittests/pi/TestGetPlugin.hpp b/sycl/unittests/pi/TestGetPlugin.hpp index 3b5fd14bd41d4..bc4744a169e36 100644 --- a/sycl/unittests/pi/TestGetPlugin.hpp +++ b/sycl/unittests/pi/TestGetPlugin.hpp @@ -8,9 +8,11 @@ #include #include #include +#include namespace pi { -inline cl::sycl::detail::plugin *initializeAndGet(cl::sycl::backend backend) { +inline std::optional +initializeAndGet(cl::sycl::backend backend) { auto plugins = cl::sycl::detail::pi::initialize(); auto it = std::find_if(plugins.begin(), plugins.end(), [=](cl::sycl::detail::plugin p) -> bool { @@ -20,9 +22,9 @@ inline cl::sycl::detail::plugin *initializeAndGet(cl::sycl::backend backend) { std::string msg = GetBackendString(backend); msg += " PI plugin not found!"; std::cerr << "Warning: " << msg << " Tests using it will be skipped.\n"; - return nullptr; + return std::nullopt; } - return &*it; + return std::optional(*it); } inline std::vector initializeAndRemoveInvalid() { diff --git a/sycl/unittests/pi/cuda/test_base_objects.cpp b/sycl/unittests/pi/cuda/test_base_objects.cpp index 1c34734f4f55c..b81e2c62b79b2 100644 --- a/sycl/unittests/pi/cuda/test_base_objects.cpp +++ b/sycl/unittests/pi/cuda/test_base_objects.cpp @@ -24,11 +24,11 @@ using namespace cl::sycl; class CudaBaseObjectsTest : public ::testing::Test { protected: - detail::plugin *plugin = pi::initializeAndGet(backend::cuda); + std::optional plugin = pi::initializeAndGet(backend::cuda); void SetUp() override { // skip the tests if the CUDA backend is not available - if (!plugin) { + if (!plugin.has_value()) { GTEST_SKIP(); } } diff --git a/sycl/unittests/pi/cuda/test_commands.cpp b/sycl/unittests/pi/cuda/test_commands.cpp index d3d9ad4baf31e..dd531b440007e 100644 --- a/sycl/unittests/pi/cuda/test_commands.cpp +++ b/sycl/unittests/pi/cuda/test_commands.cpp @@ -21,7 +21,7 @@ using namespace cl::sycl; struct CudaCommandsTest : public ::testing::Test { protected: - detail::plugin *plugin = pi::initializeAndGet(backend::cuda); + std::optional plugin = pi::initializeAndGet(backend::cuda); pi_platform platform_; pi_device device_; @@ -30,7 +30,7 @@ struct CudaCommandsTest : public ::testing::Test { void SetUp() override { // skip the tests if the CUDA backend is not available - if (!plugin) { + if (!plugin.has_value()) { GTEST_SKIP(); } @@ -65,7 +65,7 @@ struct CudaCommandsTest : public ::testing::Test { } void TearDown() override { - if (plugin) { + if (plugin.has_value()) { plugin->call(queue_); plugin->call(context_); } diff --git a/sycl/unittests/pi/cuda/test_device.cpp b/sycl/unittests/pi/cuda/test_device.cpp index ba048cada8b64..3a5890f167802 100644 --- a/sycl/unittests/pi/cuda/test_device.cpp +++ b/sycl/unittests/pi/cuda/test_device.cpp @@ -21,7 +21,7 @@ using namespace cl::sycl; struct CudaDeviceTests : public ::testing::Test { protected: - detail::plugin *plugin = pi::initializeAndGet(backend::cuda); + std::optional plugin = pi::initializeAndGet(backend::cuda); pi_platform platform_; pi_device device_; @@ -29,7 +29,7 @@ struct CudaDeviceTests : public ::testing::Test { void SetUp() override { // skip the tests if the CUDA backend is not available - if (!plugin) { + if (!plugin.has_value()) { GTEST_SKIP(); } @@ -56,7 +56,7 @@ struct CudaDeviceTests : public ::testing::Test { } void TearDown() override { - if (plugin) { + if (plugin.has_value()) { plugin->call(device_); plugin->call(context_); } diff --git a/sycl/unittests/pi/cuda/test_kernels.cpp b/sycl/unittests/pi/cuda/test_kernels.cpp index c4bdc3230de48..fc8c314d1570d 100644 --- a/sycl/unittests/pi/cuda/test_kernels.cpp +++ b/sycl/unittests/pi/cuda/test_kernels.cpp @@ -24,7 +24,7 @@ using namespace cl::sycl; struct CudaKernelsTest : public ::testing::Test { protected: - detail::plugin *plugin = pi::initializeAndGet(backend::cuda); + std::optional plugin = pi::initializeAndGet(backend::cuda); pi_platform platform_; pi_device device_; pi_context context_; @@ -32,7 +32,7 @@ struct CudaKernelsTest : public ::testing::Test { void SetUp() override { // skip the tests if the CUDA backend is not available - if (!plugin) { + if (!plugin.has_value()) { GTEST_SKIP(); } @@ -65,7 +65,7 @@ struct CudaKernelsTest : public ::testing::Test { } void TearDown() override { - if (plugin) { + if (plugin.has_value()) { plugin->call(device_); plugin->call(queue_); plugin->call(context_); diff --git a/sycl/unittests/pi/cuda/test_mem_obj.cpp b/sycl/unittests/pi/cuda/test_mem_obj.cpp index b3d85682279fc..1d6df4986bd87 100644 --- a/sycl/unittests/pi/cuda/test_mem_obj.cpp +++ b/sycl/unittests/pi/cuda/test_mem_obj.cpp @@ -22,7 +22,7 @@ using namespace cl::sycl; struct CudaTestMemObj : public ::testing::Test { protected: - detail::plugin *plugin = pi::initializeAndGet(backend::cuda); + std::optional plugin = pi::initializeAndGet(backend::cuda); pi_platform platform_; pi_device device_; @@ -30,7 +30,7 @@ struct CudaTestMemObj : public ::testing::Test { void SetUp() override { // skip the tests if the CUDA backend is not available - if (!plugin) { + if (!plugin.has_value()) { GTEST_SKIP(); } @@ -58,7 +58,7 @@ struct CudaTestMemObj : public ::testing::Test { } void TearDown() override { - if (plugin) { + if (plugin.has_value()) { plugin->call(device_); plugin->call(context_); } diff --git a/sycl/unittests/pi/cuda/test_queue.cpp b/sycl/unittests/pi/cuda/test_queue.cpp index 979bbdca7b57d..2ac1203f7512b 100644 --- a/sycl/unittests/pi/cuda/test_queue.cpp +++ b/sycl/unittests/pi/cuda/test_queue.cpp @@ -24,7 +24,7 @@ using namespace sycl; struct CudaTestQueue : public ::testing::TestWithParam { protected: - detail::plugin *plugin = pi::initializeAndGet(backend::cuda); + std::optional plugin = pi::initializeAndGet(backend::cuda); pi_platform platform_; pi_device device_; @@ -32,7 +32,7 @@ struct CudaTestQueue : public ::testing::TestWithParam { void SetUp() override { // skip the tests if the CUDA backend is not available - if (!plugin) { + if (!plugin.has_value()) { GTEST_SKIP(); } @@ -59,7 +59,7 @@ struct CudaTestQueue : public ::testing::TestWithParam { } void TearDown() override { - if (plugin) { + if (plugin.has_value()) { plugin->call(device_); plugin->call(context_); } diff --git a/sycl/unittests/pi/cuda/test_sampler_properties.cpp b/sycl/unittests/pi/cuda/test_sampler_properties.cpp index dd6ae7faea22b..077b054c099a6 100644 --- a/sycl/unittests/pi/cuda/test_sampler_properties.cpp +++ b/sycl/unittests/pi/cuda/test_sampler_properties.cpp @@ -21,7 +21,7 @@ class SamplerPropertiesTest : public ::testing::TestWithParam> { protected: - detail::plugin *plugin = pi::initializeAndGet(backend::cuda); + std::optional plugin = pi::initializeAndGet(backend::cuda); pi_platform platform_; pi_device device_; @@ -38,7 +38,7 @@ class SamplerPropertiesTest void SetUp() override { // skip the tests if the CUDA backend is not available - if (plugin == nullptr) { + if (!plugin.has_value()) { GTEST_SKIP(); } @@ -67,11 +67,11 @@ class SamplerPropertiesTest pi_sampler_properties sampler_properties[] = { PI_SAMPLER_PROPERTIES_NORMALIZED_COORDS, - normalizedCoords_, + static_cast(normalizedCoords_), PI_SAMPLER_PROPERTIES_ADDRESSING_MODE, - addressMode_, + static_cast(addressMode_), PI_SAMPLER_PROPERTIES_FILTER_MODE, - filterMode_, + static_cast(filterMode_), 0}; ASSERT_EQ((plugin->call_nocheck( @@ -80,7 +80,7 @@ class SamplerPropertiesTest } void TearDown() override { - if (plugin) { + if (plugin.has_value()) { plugin->call(sampler_); plugin->call(device_); plugin->call(context_); @@ -119,7 +119,7 @@ TEST_P(SamplerPropertiesTest, piCheckAddressingMode) { } INSTANTIATE_TEST_CASE_P( - SamplerPropertiesTesttImpl, SamplerPropertiesTest, + SamplerPropertiesTestImpl, SamplerPropertiesTest, ::testing::Combine( ::testing::Values(PI_TRUE, PI_FALSE), ::testing::Values(PI_SAMPLER_FILTER_MODE_LINEAR, From 02a842628a218e58b6718150e92974eaa3d899cc Mon Sep 17 00:00:00 2001 From: "aidan.belton" Date: Thu, 19 Aug 2021 13:26:14 +0100 Subject: [PATCH 2/7] Added comments for wchar_size drop --- libclc/utils/prepare-builtins.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libclc/utils/prepare-builtins.cpp b/libclc/utils/prepare-builtins.cpp index 2479c964f3b98..96c2434f6d32f 100644 --- a/libclc/utils/prepare-builtins.cpp +++ b/libclc/utils/prepare-builtins.cpp @@ -75,7 +75,8 @@ int main(int argc, char **argv) { if (NamedMDNode *OCLVersion = M->getNamedMetadata("opencl.ocl.version")) M->eraseNamedMetadata(OCLVersion); - // Drop wchar_size module flag + //wchar_size flag can cause a mismatch between libclc libraries and + //modules using them. Since wchar is not used by libclc we drop the flag if (M->getModuleFlag("wchar_size")) { SmallVector ModuleFlags; M->getModuleFlagsMetadata(ModuleFlags); From cf1279b9b7109d16efe3b1e05d459145930d6670 Mon Sep 17 00:00:00 2001 From: "aidan.belton" Date: Wed, 25 Aug 2021 13:23:14 +0100 Subject: [PATCH 3/7] Update from feedback --- clang/lib/Driver/ToolChains/Cuda.cpp | 4 +++- clang/test/Driver/cuda-nvptx-target.cpp | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 clang/test/Driver/cuda-nvptx-target.cpp diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp index e13030bb2444f..c059ec859deaa 100644 --- a/clang/lib/Driver/ToolChains/Cuda.cpp +++ b/clang/lib/Driver/ToolChains/Cuda.cpp @@ -202,6 +202,8 @@ CudaInstallationDetector::CudaInstallationDetector( LibPath = InstallPath + "/lib/x64"; else if (FS.exists(InstallPath + "/lib/Win32")) LibPath = InstallPath + "/lib/Win32"; + else if (FS.exists(InstallPath + "/lib")) + LibPath = InstallPath + "/lib"; else continue; } else { @@ -746,7 +748,7 @@ void CudaToolChain::addClangTargetOptions( for (StringRef LibraryPath : LibraryPaths) { SmallString<128> LibSpirvTargetFile(LibraryPath); llvm::sys::path::append(LibSpirvTargetFile, LibSpirvTargetName); - if (llvm::sys::fs::exists(LibSpirvTargetFile)) { + if (llvm::sys::fs::exists(LibSpirvTargetFile) || DriverArgs.hasArg(options::OPT__HASH_HASH_HASH)) { LibSpirvFile = std::string(LibSpirvTargetFile.str()); break; } diff --git a/clang/test/Driver/cuda-nvptx-target.cpp b/clang/test/Driver/cuda-nvptx-target.cpp new file mode 100644 index 0000000000000..f5063bd5cd464 --- /dev/null +++ b/clang/test/Driver/cuda-nvptx-target.cpp @@ -0,0 +1,7 @@ +// RUN: %clang -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda-sycldevice -nocudalib -target x86_64-unknown-windows-msvc %s 2> %t.win.out +// RUN: FileCheck %s --check-prefixes=CHECK-WINDOWS --input-file %t.win.out +// CHECK-WINDOWS: remangled-l32-signed_char.libspirv-nvptx64--nvidiacl.bc +// +// RUN: %clang -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda-sycldevice -nocudalib -target x86_64-unknown-linux-gnu %s 2> %t.lnx.out +// RUN: FileCheck %s --check-prefixes=CHECK-LINUX --input-file %t.lnx.out +// CHECK-LINUX: remangled-l64-signed_char.libspirv-nvptx64--nvidiacl.bc From ecb24c445c29a857452d38d6e599ca7ed433ca26 Mon Sep 17 00:00:00 2001 From: "aidan.belton" Date: Wed, 25 Aug 2021 13:25:16 +0100 Subject: [PATCH 4/7] clang format --- clang/lib/Driver/ToolChains/Cuda.cpp | 3 ++- libclc/utils/prepare-builtins.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp index c059ec859deaa..1859ad22788c3 100644 --- a/clang/lib/Driver/ToolChains/Cuda.cpp +++ b/clang/lib/Driver/ToolChains/Cuda.cpp @@ -748,7 +748,8 @@ void CudaToolChain::addClangTargetOptions( for (StringRef LibraryPath : LibraryPaths) { SmallString<128> LibSpirvTargetFile(LibraryPath); llvm::sys::path::append(LibSpirvTargetFile, LibSpirvTargetName); - if (llvm::sys::fs::exists(LibSpirvTargetFile) || DriverArgs.hasArg(options::OPT__HASH_HASH_HASH)) { + if (llvm::sys::fs::exists(LibSpirvTargetFile) || + DriverArgs.hasArg(options::OPT__HASH_HASH_HASH)) { LibSpirvFile = std::string(LibSpirvTargetFile.str()); break; } diff --git a/libclc/utils/prepare-builtins.cpp b/libclc/utils/prepare-builtins.cpp index 96c2434f6d32f..1dce580ed02ae 100644 --- a/libclc/utils/prepare-builtins.cpp +++ b/libclc/utils/prepare-builtins.cpp @@ -75,8 +75,8 @@ int main(int argc, char **argv) { if (NamedMDNode *OCLVersion = M->getNamedMetadata("opencl.ocl.version")) M->eraseNamedMetadata(OCLVersion); - //wchar_size flag can cause a mismatch between libclc libraries and - //modules using them. Since wchar is not used by libclc we drop the flag + // wchar_size flag can cause a mismatch between libclc libraries and + // modules using them. Since wchar is not used by libclc we drop the flag if (M->getModuleFlag("wchar_size")) { SmallVector ModuleFlags; M->getModuleFlagsMetadata(ModuleFlags); From aa27c35926727f51c90f918cd5f3f9968a0265cb Mon Sep 17 00:00:00 2001 From: "aidan.belton" Date: Tue, 7 Sep 2021 13:34:40 +0100 Subject: [PATCH 5/7] Update CMake based on feedback --- sycl/plugins/CMakeLists.txt | 34 ++++++++++++++++++++++++++ sycl/plugins/cuda/CMakeLists.txt | 18 -------------- sycl/plugins/esimd_cpu/CMakeLists.txt | 20 --------------- sycl/plugins/level_zero/CMakeLists.txt | 29 ---------------------- sycl/plugins/opencl/CMakeLists.txt | 19 -------------- 5 files changed, 34 insertions(+), 86 deletions(-) diff --git a/sycl/plugins/CMakeLists.txt b/sycl/plugins/CMakeLists.txt index 10f22d881da84..16d4fe2762ab9 100644 --- a/sycl/plugins/CMakeLists.txt +++ b/sycl/plugins/CMakeLists.txt @@ -22,3 +22,37 @@ if (NOT MSVC) add_subdirectory(esimd_cpu) endif() endif() + +set( SYCL_PLUGIN_TARGETS + pi_opencl + pi_level_zero) + +if(SYCL_BUILD_PI_ESIMD_CPU) + list(APPEND SYCL_PLUGIN_TARGETS pi_esimd_cpu) +endif() + +if(SYCL_BUILD_PI_CUDA) + list(APPEND SYCL_PLUGIN_TARGETS pi_cuda) +endif() + +foreach(pi_plugin ${SYCL_PLUGIN_TARGETS}) + 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_plugin} PRIVATE __SYCL_BUILD_SYCL_DLL) + 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_plugin} 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_plugin} PRIVATE "-Wl,--version-script=${linker_script}") + endif() + +endforeach() + diff --git a/sycl/plugins/cuda/CMakeLists.txt b/sycl/plugins/cuda/CMakeLists.txt index 1518bc5640890..160bed6a8307a 100644 --- a/sycl/plugins/cuda/CMakeLists.txt +++ b/sycl/plugins/cuda/CMakeLists.txt @@ -45,24 +45,6 @@ target_link_libraries(pi_cuda 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) -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) install(TARGETS pi_cuda diff --git a/sycl/plugins/esimd_cpu/CMakeLists.txt b/sycl/plugins/esimd_cpu/CMakeLists.txt index e520e63137efd..6686fa1f33047 100755 --- a/sycl/plugins/esimd_cpu/CMakeLists.txt +++ b/sycl/plugins/esimd_cpu/CMakeLists.txt @@ -101,26 +101,6 @@ add_library(pi_esimd_cpu SHARED "pi_esimd_cpu.cpp" ) -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_esimd_cpu PRIVATE __SYCL_BUILD_SYCL_DLL) -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_esimd_cpu 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_esimd_cpu - PRIVATE "-Wl,--version-script=${linker_script}" - ) -endif() - add_dependencies(pi_esimd_cpu OpenCL-Headers) add_dependencies(pi_esimd_cpu cm-emu) add_dependencies(sycl-toolchain pi_esimd_cpu) diff --git a/sycl/plugins/level_zero/CMakeLists.txt b/sycl/plugins/level_zero/CMakeLists.txt index 772a0972946e9..927394a9c4c5f 100755 --- a/sycl/plugins/level_zero/CMakeLists.txt +++ b/sycl/plugins/level_zero/CMakeLists.txt @@ -58,15 +58,6 @@ if (NOT DEFINED LEVEL_ZERO_LIBRARY OR NOT DEFINED LEVEL_ZERO_INCLUDE_DIR) DEPENDEES install ) - if (WIN32) - # Copy DLL into binary directory - ExternalProject_Add_Step(level-zero-loader llvmbininstall - COMMAND ${CMAKE_COMMAND} -E copy_directory /bin/ ${LLVM_BINARY_DIR}/bin - COMMENT "Installing level-zero-loader into the LLVM binary directory" - DEPENDEES install - ) - endif() - install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/level_zero_loader_install/" DESTINATION "." COMPONENT level-zero-loader @@ -119,26 +110,6 @@ add_library(pi_level_zero SHARED "${CMAKE_CURRENT_SOURCE_DIR}/usm_allocator.hpp" ) -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_level_zero PRIVATE __SYCL_BUILD_SYCL_DLL) -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_level_zero 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_level_zero - PRIVATE "-Wl,--version-script=${linker_script}" - ) -endif() - if (TARGET level-zero-loader) add_dependencies(pi_level_zero level-zero-loader) endif() diff --git a/sycl/plugins/opencl/CMakeLists.txt b/sycl/plugins/opencl/CMakeLists.txt index bd7ac1e50fe28..ba2b9cd9bbfbb 100644 --- a/sycl/plugins/opencl/CMakeLists.txt +++ b/sycl/plugins/opencl/CMakeLists.txt @@ -28,25 +28,6 @@ target_link_libraries(pi_opencl OpenCL-Headers OpenCL-ICD ) -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_opencl PRIVATE __SYCL_BUILD_SYCL_DLL) -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_opencl 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_opencl - PRIVATE "-Wl,--version-script=${linker_script}" - ) -endif() add_common_options(pi_opencl) From 2826576e2db9f61d89b91f1b784e3fd5b6e40fc2 Mon Sep 17 00:00:00 2001 From: "aidan.belton" Date: Tue, 7 Sep 2021 13:35:54 +0100 Subject: [PATCH 6/7] Set test_contexts to use std::optional --- sycl/unittests/pi/cuda/test_contexts.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl/unittests/pi/cuda/test_contexts.cpp b/sycl/unittests/pi/cuda/test_contexts.cpp index 4007341f94839..5473b22ba85ac 100644 --- a/sycl/unittests/pi/cuda/test_contexts.cpp +++ b/sycl/unittests/pi/cuda/test_contexts.cpp @@ -25,14 +25,14 @@ using namespace cl::sycl; struct CudaContextsTest : public ::testing::Test { protected: - detail::plugin *plugin = pi::initializeAndGet(backend::cuda); + std::optional plugin = pi::initializeAndGet(backend::cuda); pi_platform platform_; pi_device device_; void SetUp() override { // skip the tests if the CUDA backend is not available - if (!plugin) { + if (!plugin.has_value()) { GTEST_SKIP(); } From 6c8cc4755a133a1bcbfe73da2cacc962c5738190 Mon Sep 17 00:00:00 2001 From: "aidan.belton" Date: Fri, 10 Sep 2021 14:11:12 +0100 Subject: [PATCH 7/7] Partly undo CMake changes based on feedback --- sycl/plugins/CMakeLists.txt | 34 -------------------------- sycl/plugins/cuda/CMakeLists.txt | 18 ++++++++++++++ sycl/plugins/esimd_cpu/CMakeLists.txt | 20 +++++++++++++++ sycl/plugins/level_zero/CMakeLists.txt | 20 +++++++++++++++ sycl/plugins/opencl/CMakeLists.txt | 19 ++++++++++++++ 5 files changed, 77 insertions(+), 34 deletions(-) diff --git a/sycl/plugins/CMakeLists.txt b/sycl/plugins/CMakeLists.txt index 16d4fe2762ab9..10f22d881da84 100644 --- a/sycl/plugins/CMakeLists.txt +++ b/sycl/plugins/CMakeLists.txt @@ -22,37 +22,3 @@ if (NOT MSVC) add_subdirectory(esimd_cpu) endif() endif() - -set( SYCL_PLUGIN_TARGETS - pi_opencl - pi_level_zero) - -if(SYCL_BUILD_PI_ESIMD_CPU) - list(APPEND SYCL_PLUGIN_TARGETS pi_esimd_cpu) -endif() - -if(SYCL_BUILD_PI_CUDA) - list(APPEND SYCL_PLUGIN_TARGETS pi_cuda) -endif() - -foreach(pi_plugin ${SYCL_PLUGIN_TARGETS}) - 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_plugin} PRIVATE __SYCL_BUILD_SYCL_DLL) - 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_plugin} 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_plugin} PRIVATE "-Wl,--version-script=${linker_script}") - endif() - -endforeach() - diff --git a/sycl/plugins/cuda/CMakeLists.txt b/sycl/plugins/cuda/CMakeLists.txt index 160bed6a8307a..1518bc5640890 100644 --- a/sycl/plugins/cuda/CMakeLists.txt +++ b/sycl/plugins/cuda/CMakeLists.txt @@ -45,6 +45,24 @@ target_link_libraries(pi_cuda 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) +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) install(TARGETS pi_cuda diff --git a/sycl/plugins/esimd_cpu/CMakeLists.txt b/sycl/plugins/esimd_cpu/CMakeLists.txt index 6686fa1f33047..e520e63137efd 100755 --- a/sycl/plugins/esimd_cpu/CMakeLists.txt +++ b/sycl/plugins/esimd_cpu/CMakeLists.txt @@ -101,6 +101,26 @@ add_library(pi_esimd_cpu SHARED "pi_esimd_cpu.cpp" ) +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_esimd_cpu PRIVATE __SYCL_BUILD_SYCL_DLL) +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_esimd_cpu 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_esimd_cpu + PRIVATE "-Wl,--version-script=${linker_script}" + ) +endif() + add_dependencies(pi_esimd_cpu OpenCL-Headers) add_dependencies(pi_esimd_cpu cm-emu) add_dependencies(sycl-toolchain pi_esimd_cpu) diff --git a/sycl/plugins/level_zero/CMakeLists.txt b/sycl/plugins/level_zero/CMakeLists.txt index 927394a9c4c5f..52f205f1abb81 100755 --- a/sycl/plugins/level_zero/CMakeLists.txt +++ b/sycl/plugins/level_zero/CMakeLists.txt @@ -110,6 +110,26 @@ add_library(pi_level_zero SHARED "${CMAKE_CURRENT_SOURCE_DIR}/usm_allocator.hpp" ) +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_level_zero PRIVATE __SYCL_BUILD_SYCL_DLL) +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_level_zero 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_level_zero + PRIVATE "-Wl,--version-script=${linker_script}" + ) +endif() + if (TARGET level-zero-loader) add_dependencies(pi_level_zero level-zero-loader) endif() diff --git a/sycl/plugins/opencl/CMakeLists.txt b/sycl/plugins/opencl/CMakeLists.txt index ba2b9cd9bbfbb..bd7ac1e50fe28 100644 --- a/sycl/plugins/opencl/CMakeLists.txt +++ b/sycl/plugins/opencl/CMakeLists.txt @@ -28,6 +28,25 @@ target_link_libraries(pi_opencl OpenCL-Headers OpenCL-ICD ) +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_opencl PRIVATE __SYCL_BUILD_SYCL_DLL) +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_opencl 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_opencl + PRIVATE "-Wl,--version-script=${linker_script}" + ) +endif() add_common_options(pi_opencl)