KhronosGroup / OpenCL-Headers

Khronos OpenCL-Headers
Apache License 2.0
666 stars 236 forks source link

OpenCL Header only Dynamically Opened ICD Loader Proposal #169

Open Kerilk opened 3 years ago

Kerilk commented 3 years ago

This is a (full fledged, functional) straw-man proposal of an implementation of one of @bashbaug ideas for easing OpenCL ICD loader issues. These headers allow an OpenCL application to be built normally or with the -DOPENCL_LOAD flag active. In this case, linking with the loader is not necessary anymore as it is opened dynamically. The title is slightly misleading as ONE source file from the project must also include the CL/opencl_load_lib.h to have a single definitions of the global variables used. (on windows this could go away as on MSVC inline functions can declare non const static variables).

This allows:

This does not allow an application to:

The last point could be fixed using indirect dispatch in the loader. I will add CI tests for it.

bashbaug commented 3 years ago

Cool! This looks like a mix between the previous Static Lib with Dynamic Loader and ICD Loader Header File proposals. Having working code to play around with and demonstrate that it works is awesome.

Out of curiousity are you generating these files, or did you author them manually? I think it should be possible to generate most of them.

I think we mostly need to figure out which solution (or solutions, this doesn't need to be one-size-fits-all) we want and then start adding them to the SDK / CI / etc. There are clearly lots of different options, with different pros and cons.

Note that there are some aspects of this PR that we may want to adopt regardless, for example it looks like we both added some sort of a define to control linkage in the header file - see CLLD_INLINE in this PR and CL_API_LINKAGE in my proposal.

Kerilk commented 3 years ago

Cool! This looks like a mix between the previous Static Lib with Dynamic Loader and ICD Loader Header File proposals. Having working code to play around with and demonstrate that it works is awesome.

Thanks, I didn't knew about those (only about your presentation, I didn't find pointer to code in it), I will need to study them, they look great.

Out of curiousity are you generating these files, or did you author them manually? I think it should be possible to generate most of them.

I did not generate them yet because I wanted to do a full pass on the headers to be sure not to miss something. There are some strange inconsistencies:

I think we mostly need to figure out which solution (or solutions, this doesn't need to be one-size-fits-all) we want and then start adding them to the SDK / CI / etc. There are clearly lots of different options, with different pros and cons.

Yes, hopefully this one will help accomplish this goal. For this work there is some thread safety involved, so maybe using it to run the conformance test may be better (though I don't know how much parallel testing the conformance tests do). We also need some way to be able to install a working driver on windows image in GitHub actions. Ubuntu is easy, MacOS can work (with reservations), but for now I don't have a solution for windows...

Note that there are some aspects of this PR that we may want to adopt regardless, for example it looks like we both added some sort of a define to control linkage in the header file - see CLLD_INLINE in this PR and CL_API_LINKAGE in my proposal.

I agree with you completely. I started with a slighly more complex proposal initially that allowed even more flexibility, by having non static inline functions with extern declarations in the library. And you could switch between static inline/inline mode. This may be desirable and could allow to adapt the scheme to more exotic platforms.