Skip to content

Conversation

uditagarwal97
Copy link
Contributor

@uditagarwal97 uditagarwal97 commented Sep 26, 2025

Problem
SYCL RT loads libur_adapter_opencl.so (

"OpenCL", "libur_adapter_opencl.so", #FN)(__VA_ARGS__))
) while UR loads libur_adapter_opencl.so.0 (
MAKE_LIBRARY_NAME("ur_adapter_opencl", "0"),
). Note that SYCL RT calls dlopen() with RTLD_NOLOAD flag, which causes dlopen() to fail if this library wasn’t loaded before.

Now, in our Linux compiler packages, libur_adapter_opencl.so and libur_adapter_opencl.so.0 are symlinked so they are the same file, that’s why call to dlopen() in SYCL RT succeeds. However, the problem happens with DPCPP PyPi package, which doesn’t support symlinked files, so call to dlopen() fails because these are two different files.

Proposed solution
Lookup libur_adapter_opencl.so.0 as fallback.

Other potential solutions

  1. Why not just load libur_adapter_opencl.so.0 always? Because that causes SYCL unit tests, which rely on mocked OpenCL adapter to fail. In unit tests, we actually want SYCL RT to load libur_adapter_opencl.so (mocked) and UR to load libur_adapter_opencl.so.0, both of which are different files.
  2. Why not remove RTLD_NOLOAD flag? When using PyPi package, that can cause SYCL RT and UR to load two OpenCL adapters libraries. I'm not an expert on loaders, but that might lead to more bugs if, for example, OpenCL adapter functions that SYCL RT calls have side effects.

@uditagarwal97 uditagarwal97 force-pushed the private/udit/libur_adapter_ocl branch from 6f4c31d to 74c42b3 Compare September 29, 2025 18:51
@uditagarwal97 uditagarwal97 marked this pull request as ready for review September 29, 2025 20:41
@uditagarwal97 uditagarwal97 requested a review from a team as a code owner September 29, 2025 20:41
@uditagarwal97 uditagarwal97 requested a review from a team as a code owner September 29, 2025 21:08
@uditagarwal97 uditagarwal97 changed the title [SYCL] Load libur_adapter_opencl.so.0 to match UR loader [SYCL] Lookup versioned OpenCL adapter library as fallback Sep 29, 2025
This reverts commit 22a38f5.
Copy link
Contributor

@steffenlarsen steffenlarsen left a comment

Choose a reason for hiding this comment

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

Beautiful! 🚀

@steffenlarsen steffenlarsen merged commit 75e9e73 into sycl Sep 30, 2025
34 of 36 checks passed
@uditagarwal97 uditagarwal97 deleted the private/udit/libur_adapter_ocl branch September 30, 2025 15:26
AlexeySachkov pushed a commit to AlexeySachkov/llvm that referenced this pull request Sep 30, 2025
)

**Problem**
SYCL RT loads `libur_adapter_opencl.so`
(https://github.com/intel/llvm/blob/0ff1a5c2b4e4bc56799ec2dd17a89c3c57608890/sycl/include/sycl/detail/os_util.hpp#L129)
while UR loads `libur_adapter_opencl.so.0`
(https://github.com/intel/llvm/blob/0031df16e41bd0665e85af635b7bfd4e187ce7cd/unified-runtime/source/loader/ur_manifests.hpp#L35).
Note that SYCL RT calls `dlopen()` with `RTLD_NOLOAD` flag, which causes
`dlopen()` to fail if this library wasn’t loaded before.

Now, in our Linux compiler packages, `libur_adapter_opencl.so` and
`libur_adapter_opencl.so.0` are symlinked so they are the same file,
that’s why call to `dlopen()` in SYCL RT succeeds. However, the problem
happens with DPCPP PyPi package, which doesn’t support symlinked files,
so call to dlopen() fails because these are two different files.

**Proposed solution**
Lookup `libur_adapter_opencl.so.0` as fallback.

**Other potential solutions**
1. Why not just load `libur_adapter_opencl.so.0` always? Because that
causes SYCL unit tests, which rely on mocked OpenCL adapter to fail. In
unit tests, we actually want SYCL RT to load `libur_adapter_opencl.so`
(mocked) and UR to load `libur_adapter_opencl.so.0`, both of which are
different files.
2. Why not remove `RTLD_NOLOAD` flag? When using PyPi package, that can
cause SYCL RT and UR to load two OpenCL adapters libraries. I'm not an
expert on loaders, but that might lead to more bugs if, for example,
OpenCL adapter functions that SYCL RT calls have side effects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants