pyopencl icon indicating copy to clipboard operation
pyopencl copied to clipboard

feat: support offline compilers

Open yxliang01 opened this issue 4 years ago • 3 comments

For some devices, online compilers might not be available. For the code written in C/C++ invoking OpenCL library, they will choose to call clCreateProgramWithBinary instead of clCreateProgramWithSource, so that the subsequent build method will not try to find a compiler for compiling. However, in the case of PyOpenCL, it provides encapsulation that it tries to make all these transparent, so like the case of #312, the unavailability of online compiler makes the PyOpenCL library unusable. Therefore, it would be great if there can add support for offline compilers.

One way to do it is to modify https://github.com/inducer/pyopencl/blob/4bfb2d65d31c8132de46bbb007cfebd3b934328d/src/wrap_cl.hpp#L3977 , so that, we can make it compile the source using the specified offline compiler, then feed the binary to the OpenCL. But, this only happens when we set certain flags to indicate offline compilers should be used.

yxliang01 avatar Nov 08 '19 18:11 yxliang01

You can call clCreateProgramWithBinary without a problem, see here. As for more direct support for offline compilers, since I don't have a device that uses one, I would have to rely on someone submitting patches.

inducer avatar Nov 08 '19 22:11 inducer

@inducer Yes, but, won't it be nicer, if we can expose certain PyOpenCL API that allows us to set certain offline compiler to provide this encapsulation? More importantly, it helps addresses https://github.com/inducer/pyopencl/issues/312 . #312 can be resolved straightaway.

yxliang01 avatar Nov 09 '19 04:11 yxliang01

@inducer Are you interested in working on this issue? You actually have all the environment to implement and test with. For example, you can use nvcc as an example offline compiler(looks like you have been using Nvidia GPUs and some people suggested it can compile OpenCL kernel, haven't tested myself).

yxliang01 avatar Feb 14 '20 20:02 yxliang01