[Cython] OpenCL support

Robert Bradshaw robertwb at math.washington.edu
Wed Feb 8 09:53:12 CET 2012


On Tue, Feb 7, 2012 at 9:58 AM, Sturla Molden <sturla at molden.no> wrote:
> On 07.02.2012 18:22, Dimitri Tcaciuc wrote:
>
>> I'm not sure I understand you, maybe you could elaborate on that?
>
>
> OpenCL code is a text string that is compiled when the program runs. So it
> can be generated from run-time data. Think of it like dynamic HTML.
>
>
>> Again, not sure what you mean here. As I mentioned in the thread,
>> PyOpenCL worked quite fine, however if Cython is getting OpenCL
>> support, I'd much rather use that than keeping a dependency on another
>> library.
>
>
> You can use PyOpenCL or OpenCL C or C++ headers with Cython. The latter you
> just use as you would with any other C or C++ library. You don't need to
> change the compiler to use a library: It seems like you think OpenCL is
> compiled from code when you build the program. It is actually compiled from
> text strings when you run the program. It is meaningless to ask if Cython
> supports OpenCL because Cython supports any C library.

I view this more as a proposal to have an OpenCL backend for prange
loops and other vectorized operations. The advantage of integrating
OpenCL into Cython is that one can write a single implementation of
your algorithm (using traditional for...(p)range loops) and have it
use the GPU in the background transparently (without having to
manually learn and call the library yourself). This is analogous to
the compiler/runtime system deciding to use sse instructions for a
portion of your code because it thinks it will be faster. I really
like the idea of decoupling the logic of the algorithm from the SIMD
implementation (which is one of the reasons that prange, and in part
OpenMP, works so well) but I think this is best done at the language
level in our case.

Whether OpenCL is mature enough/the abstractions are clean enough/the
heuristics can be good enough to pull this off is another question,
but it'd be great if it can be done (ideally with minimal impact to
the language and isolated changes to the internals).

- Robert


More information about the cython-devel mailing list