Skip to content

Commit 2e7528e

Browse files
authored
[SYCL] Use libur_loader_opencl.so rather than libOpenCL.so on Linux (#17708)
The name of OpenCL may vary between different implementations, but libur_adapter_opencl.so shouldn't.
1 parent 8d34f2a commit 2e7528e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

sycl/include/sycl/detail/os_util.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,13 @@ fn *dynLookupFunction(const char *WinName, const char *LinName,
120120
const char *FunName) {
121121
return reinterpret_cast<fn *>(dynLookup(WinName, LinName, FunName));
122122
}
123+
// On Linux, the name of OpenCL that was used to link against may be either
124+
// `OpenCL.so`, `OpenCL.so.1` or possibly anything else.
125+
// `libur_adapter_opencl.so` is a more stable name, since it is hardcoded into
126+
// the loader.
123127
#define __SYCL_OCL_CALL(FN, ...) \
124128
(sycl::_V1::detail::dynLookupFunction<decltype(FN)>( \
125-
"OpenCL", "libOpenCL.so", #FN)(__VA_ARGS__))
129+
"OpenCL", "libur_adapter_opencl.so", #FN)(__VA_ARGS__))
126130

127131
} // namespace detail
128132
} // namespace _V1
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
get_target_property(SYCL_BINARY_DIR sycl-toolchain BINARY_DIR)
22

3+
# Linux looks up ur_adapter_opencl rather than libOpenCL.
4+
# On Windows, this is copied into libOpenCL.dll.
5+
if(WIN32)
6+
set(LIBNAME OpenCL)
7+
else()
8+
set(LIBNAME ur_adapter_opencl)
9+
endif()
10+
311
add_library(mockOpenCL SHARED EXCLUDE_FROM_ALL mock_opencl.cpp)
412
set_target_properties(mockOpenCL PROPERTIES
513
LIBRARY_OUTPUT_DIRECTORY ${SYCL_BINARY_DIR}/unittests/lib
6-
LIBRARY_OUTPUT_NAME OpenCL
14+
LIBRARY_OUTPUT_NAME ${LIBNAME}
715
RUNTIME_OUTPUT_DIRECTORY ${SYCL_BINARY_DIR}/unittests/lib
8-
RUNTIME_OUTPUT_NAME OpenCL
16+
RUNTIME_OUTPUT_NAME ${LIBNAME}
917
)

0 commit comments

Comments
 (0)