Skip to content

Commit 41baa48

Browse files
committed
[SYCL] Export only *pi symbols in libpi_opencl.so
Cleaned up some unnecessary versioning code Changed library scope from SHARED to MODULE to limit its usage Moved duplicate code out of condition Signed-off-by: Byoungro So <[email protected]>
1 parent 7128d4c commit 41baa48

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

sycl/include/CL/sycl/detail/pi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
// elsewhere, e.g. in the pi_opencl, but constants/enums mapping is now
4747
// done here, for efficiency and simplicity.
4848

49-
#include "export.hpp"
49+
#include <CL/sycl/detail/export.hpp>
5050
#include <CL/cl_usm_ext.h>
5151
#include <CL/sycl/detail/cl.h>
5252
#include <cstdint>

sycl/plugins/opencl/CMakeLists.txt

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@
99
#TODO: remove dependency on pi.hpp in sycl project.
1010
#TODO: Currently, the pi.hpp header is common between sycl and plugin library sources.
1111
#This can be changed by copying the pi.hpp file in the plugins project.
12-
configure_file(
13-
${CMAKE_CURRENT_SOURCE_DIR}/../../source/version.rc.in
14-
${CMAKE_CURRENT_BINARY_DIR}/version.rc
15-
@ONLY)
1612

1713
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
18-
add_library(pi_opencl SHARED
14+
15+
# We chose MODULE type because libpi_opencl.so should never be linked dynamically to a target.
16+
# MODULE will limit this library to be used to load symbols via dllopen only
17+
add_library(pi_opencl MODULE
1918
"${sycl_inc_dir}/CL/sycl/detail/pi.h"
2019
"pi_opencl.cpp"
21-
${CMAKE_CURRENT_BINARY_DIR}/version.rc
2220
)
2321

2422
add_dependencies(pi_opencl
@@ -33,13 +31,14 @@ set_target_properties(pi_opencl PROPERTIES LINKER_LANGUAGE CXX)
3331
#preprocessor definitions for compiling a target's sources. We do not need it for pi_opencl
3432
target_include_directories(pi_opencl PRIVATE "${sycl_inc_dir}")
3533

34+
target_link_libraries( pi_opencl
35+
PRIVATE OpenCL::Headers
36+
PRIVATE ${OpenCL_LIBRARIES}
37+
)
3638
if (MSVC)
39+
# by defining __SYCL_BUILD_SYCL_DLL, we can use __declspec(dllexport)
40+
# which are individually tagged for all pi* symbols in pi_opencl.cpp
3741
target_compile_definitions(pi_opencl PRIVATE __SYCL_BUILD_SYCL_DLL)
38-
target_link_libraries(pi_opencl PRIVATE shlwapi)
39-
target_link_libraries( pi_opencl
40-
PRIVATE OpenCL::Headers
41-
PRIVATE ${OpenCL_LIBRARIES}
42-
)
4342
else()
4443
# we set the visibility of all symbols 'hidden' by default.
4544
# In *.cpp files, we set exported symbols with visibility==default individually
@@ -51,8 +50,6 @@ else()
5150

5251
#link pi_opencl with OpenCL headers and ICD Loader.
5352
target_link_libraries( pi_opencl
54-
PRIVATE OpenCL::Headers
55-
PRIVATE ${OpenCL_LIBRARIES}
5653
# Filter symbols based on the scope defined in the script file,
5754
# and export pi* function symbols in the library.
5855
PRIVATE "-Wl,--version-script=${linker_script}"
@@ -61,9 +58,6 @@ endif()
6158

6259
add_common_options(pi_opencl)
6360

64-
set_target_properties(pi_opencl PROPERTIES
65-
VERSION ${SYCL_VERSION_STRING}
66-
SOVERSION ${SYCL_MAJOR_VERSION})
6761
install(TARGETS pi_opencl
6862
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT pi_opencl
6963
RUNTIME DESTINATION "bin" COMPONENT pi_opencl)

0 commit comments

Comments
 (0)