-
Notifications
You must be signed in to change notification settings - Fork 787
[UR] Replace calls to UR in native handle functions to proper OpenCL functions #17016
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
Conversation
8a1e5a3
to
d3e930c
Compare
d3e930c
to
cd73105
Compare
cd73105
to
dae0641
Compare
dae0641
to
7664104
Compare
7664104
to
6b55d56
Compare
6b55d56
to
38563a4
Compare
38563a4
to
55f9034
Compare
85c448c
to
93ce35e
Compare
93ce35e
to
7c29c52
Compare
7c29c52
to
d16b32d
Compare
d16b32d
to
4b996d2
Compare
688137b
to
2238fb5
Compare
a73f57f
to
18a4a0c
Compare
a91b855
to
1cd11bc
Compare
1cd11bc
to
75bbc1d
Compare
@cperkinsintel Do you still have concerns about this approach? @aelovikov-intel I'm not sure what testing could be done here. If my understanding is correct, only one "OpenCL" implementation may be loaded at a time, and if that were unloaded in some way it would break a lot of things internal to the OpenCL UR backend. @nrspruit After an embarrassing amount of time trying to get Windows to work, CI seems to be working now. |
I think the answer to my question is that ICD loader "unifies" all available OpenCL implementations in the system and properly dispatches to the correct one when called. As such, that function pointer is the same for both OpenCL CPU and GPU devices (and is provided by the ICD loader itself) even though the actual implementations are different. |
That's my understanding as well; each handle type in OpenCL has a field for the "implementation" which points to a struct containing function pointers for each On Linux, running gdb on |
@intel/llvm-reviewers-runtime Can I get this reviewed? It's blocking a few UR improvements I want to merge. |
sycl/include/sycl/detail/os_util.hpp
Outdated
#define __SYCL_OCL_GET_FUNCTION(FN) \ | ||
(sycl::_V1::detail::dynLookupFunction<decltype(FN)>("OpenCL", \ | ||
"libOpenCL.so", #FN)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, this generalization is unnecessary at this point. Can we just have a non-macro
template <typename FnTy> FnTy *get_ocl_func(const char *FuncName) { ... }
void *get_ocl_func_impl(const char *FuncName);
? All the win/lin dispatch for the shared library name can be done inside libsycl.so/.dll
Maybe even
void *get_ocl_func_impl(const char *FuncName);
template <typename... Tys>
auto call_ocl(const char *func, Tys&& ...args);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your get_ocl_func
requires specifying the function name twice; once as a string and once as a value for decltype(x)
. Without that, callers would have to do something like:
void *fn = reinterpret_cast<decltype(clDoThing)>("clDoThing");
which I think is less ergonomic than a macro.
call_ocl
could work, but it looks like it relies on the programmer getting the signature exactly correct, and gives no feedback if they get it wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about __SYCL_OCL_CALL
macro then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, __SYCL_OCL_CALL
looks much nicer. Updated.
At various points, OpenCL native handles need to be retained to ensure SYCL semantics. Previously, this relied on the fact that UR handles were typecast CL handles and shared the same reference count. However, the SYCL RT shouldn't assume this, so instead we call the appropriate (dynamically looked-up) CL functions on the native handles instead. This is in preperation for oneapi-src/unified-runtime#1176 . This change should also have no observable effect for SYCL code; there is no change in lifetime semantics.
75bbc1d
to
4c0d2be
Compare
@intel/llvm-gatekeepers Please merge. |
@RossBrunton @kbenzie Build is failing in Windows postcommit
Can you please fix asap or revert? Thx |
I've created #17574 which I hope will resolve this |
… OpenCL functions (intel#17016)" This reverts commit e1cf106. In testing, it turns out a number of people link against `libOpenCL.so.1` rather than `libOpenCL.so`, which is considered a seperate library by the linker. Reverting this change for now while we consider the best option.
At various points, OpenCL native handles need to be retained to ensure
SYCL semantics. Previously, this relied on the fact that UR handles were
typecast CL handles and shared the same reference count.
However, the SYCL RT shouldn't assume this, so instead we call the
appropriate (dynamically looked-up) CL functions on the native handles
instead.
This is in preperation for oneapi-src/unified-runtime#1176 .
This change should also have no observable effect for SYCL code; there
is no change in lifetime semantics.