there are so many cores

Just another site

Trivial example of the JIT with OpenCL

Well, just got something to run through OpenCL with a true JIT. It takes this statement:

C = sqrt(B + sum(A + B * mean(A)));

generates the equivalent OpenCL kernel:

__kernel void kx(
    __global float* a0x1d72b00, 
    __global float* a0x7ffff8234f30, 
    __global float* a0x7ffff82350c0)
    const size_t x0 = get_global_id(0);

    float a2 = 0;
    for (size_t x2 = 0; x2 < 100; x2++) {
        a2 += a0x7ffff82350c0[x2];

    float a1 = 0;
    for (size_t x1 = 0; x1 < 100; x1++) {
        a1 += (a0x7ffff82350c0[x1] + (a0x7ffff8234f30[x1] * (a2 / 100)));

    a0x1d72b00[x0] = sqrt((a0x7ffff8234f30[x0] + a1));

enqueues, waits and continues after kernel output data is transferred from the device back to the host.

This is the first “end-to-end” functionality (with a trivial and completely unrealistic example as the OpenCL index space has only a single thread).

The compiler will have to develop a modular architecture allowing optimizations. Some of the basic but necessary compiler features I can see are:

  1. loops in the execution trace
  2. batch multiple reductions
  3. asynchronous JIT and interpreter execution
  4. JIT code cache

At the same time, I am cautious to avoid over investing in the wrong problems.

An excellent JIT may not improve real world application performance as much as a good kernel library. My experience is high GPGPU throughput is mostly due to pre-optimized kernels, arithmetically intense algorithms like matrix multiply and n-body simulation with far more calculation than memory access. The benefit of a managed platform and JIT is making it easy to write software to use those library kernels in a way that does not kill performance (minimize PCIe bus data transfer and kernel scheduling overheads).


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: