"High Rise" painting by Huma Mulji

The rise of the GPGPU compilers

If you read Charles Petzold’s The Disasters of Visual Designer Tools, you’ll find a common thought about easy programming. Many programmers no longer learn the hard-to-grasp background. Instead, they twiddle around and click a program together. The same risk applies to GPGPU compilers: the more they do for you, the less you learn about the hardware.

In the early days of BASIC, you could add assembly code to speed up calculations. You only needed to understand registers, cache and other details of the CPU. The people who did that learnt about hardware. In my view, they are better programmers than a C++ programmer who relies completely on the compiler’s intelligence. So never be happy when someone takes control out of your hands, because it only speeds up the easy parts.

There is an important side note, though. A future compiler might turn easily readable code into faster code than your well-engineered, hand-optimised version. It’s a careful trade-off.

Okay, let’s be honest: OpenCL is not easy fun. It is more like readable assembly than click-and-play programming. But, oh boy, you learn a lot from it! You learn about architectures, the capabilities of GPUs, special-purpose processors and much more. As I blogged before, OpenCL will probably become the hidden power behind non-CPU processors, wrapped in something like OpenMP.

The evolution of GPGPU compilers

In the first stage, GPGPU compilers translate a special language into a shader language like OpenGL’s GLSL. Over time, developers learn the limits of this approach, and the optimisations eventually bypass the shader language. The special language also gets easier to program. CUDA 3 is a good example. In a few years, the language got faster in many ways, and the drivers changed a lot too.

The second stage is happening now: compilers automatically recognise which parts of the code they can accelerate. We already know we can rewrite OpenMP programs to run (partly) on the GPU. So now we only have to tell the compiler when and how.

OpenCL is an open standard, which makes it a perfect intermediate language, also for debugging. And we need an intermediate language, because every new piece of hardware needs different optimisations. Seyong Lee, Seung-Jai Min and Rudolf Eigenmann did such a study with CUDA: “OpenMP to GPGPU: A Compiler Framework for Automatic Translation and Optimization”.

I want to stress that understanding hardware architectures remains important for GPGPU, and for any other language where performance matters. In 2010 and 2011, OpenCL is still in the spotlight. Before you know it, libraries and compilers will hide it all, so learn it now! The only difference is that programmers still need to understand where their software will run.

Current GPGPU compilers

I took a week to find all GPGPU compilers, because I kept running into 404 pages and projects without changes for months. Where did those projects go? The techniques depend so much on driver optimisations that most projects were abandoned. Others now target CUDA or OpenCL instead of a shader language. I expected this shift, as I wrote above, but not this soon. More and more wrappers and compilers target OpenCL or CUDA. I will cover those in a separate post on wrappers and libraries.

These GPGPU compilers remain:

  • NVIDIA CUDA: currently the most mature GPGPU compiler, which started in 2007. It uses an LLVM-based compiler.
  • Khronos Group OpenCL: the industry standard for GPGPU, running on a growing number of processors (AMD, NVIDIA, ARM, IBM Cell). You can use LLVM, GCC and other compilers.
  • PathScale ENZO: together with CAPS and its HMPP compiler, PathScale wants to offer an alternative. It sells for $2495.
  • Codeplay Offload: targets only IBM’s Cell processor.
  • Sh: when Intel acquired RapidMind, it released the GPU code as open source.
  • Microsoft DirectCompute: it mostly runs on top of CUDA and OpenCL, but it is nicely integrated into DirectX, so I can’t leave it out.

Missing a project? Please let me know.

Disclaimer: StreamHPC gives trainings in GPGPU and OpenCL. We like to show you how to learn GPGPU and OpenCL, and to share our enthusiasm through this blog. Of course, our training goes deeper.

6 thoughts on “The rise of the GPGPU compilers”

  1. Slobodan Blazeski

    I mostly agree but I’m not sure are those libraries will be generated by compiler or just normal c++ libraries. Anyway I started an experiment with scripting language for OpenCL and will see how it goes.

  2. Vincent Hindriksen

    OpenCL is a clear target and an open standard; it doesn’t matter if it’s binary or human readable. I don’t see the difference between a compiler-as-a-library and a stand-alone compiler, since they serve the same goal.
    I tried to open the discussion how OpenMP and OpenCL would merge, but most liked the part I think OpenCL is somewhat Spartian. Thank you Khronos-group.

  3. Jacket includes a JIT compiler for GPUs and to our knowledge, it is the only JIT for GPUs outside of small research projects. Jacket’s JIT currently emits PTX code for NVIDIA chips – this is the major feature that we just released in Jacket 1.4, whereas Jacket 1.3 are earlier emitted CUDA code. Not sure if you wanted to include JIT compilers in your list.

    Currently, Jacket’s JIT capabilities are only available to MATLAB programmers, but by the end of the year, we’ll have a C/C++ version available.

    -John Melonakos, CEO, AccelerEyes

  4. There is also Brook+, unfortunately it seems no longer actively developed, as AMD is promoting only OpenCL. OpenCL is good. I’m still awaiting to see good wrappers emerged suitable for wider range of developers and its performance comparison with CUDA.

    1. Vincent Hindriksen

      xman, the article is about actively developed software, so Brook+ is not included for that reason. Performance is theoretically the same as CUDA, but NVIDIA’s drivers are currently optimised for CUDA. Once my dual GPU (one AMD, one NVIDIA) is in I can show you some benchmarks. The wrappers are getting better; I discuss a great deal of length in my book about them and an article about it is to be expected in October.

  5. Hi Vincent, that’s great. Awaiting to see more benchmarks on CUDA and OpenCL. Many people are still wondering if it’s a good time to use OpenCL as it’s still at its early stage.

Comments are closed.