OpenCL SPIR 1.2: An Intermediate Format For OpenCL

Moving on from OpenGL, the rest of Khronos’ major news for SIGGRAPH revolves around their OpenCL standard for GPGPU compute. OpenCL was first released in 2008, and has since then been iterated on in conjunction with further software developments and the release of newer, more capable hardware. Khronos in turn is announcing two new OpenCL standards, OpenCL SPIR 1.2 and OpenCL 2.0.

Starting off with OpenCL SPIR 1.2, SPIR is an extension of OpenCL designed around filling in some of the software deployment holes the standard OpenCL software stack exposes. Standing for Standard Portable Intermediate Representation, SPIR is the format and specifications needed to represent OpenCL programs in an intermediate format, between high level C kernels and low level fully compiled binaries.

SPIR seeks to solve one of the outstanding issues with deploying OpenCL programs, which relates to OpenCL’s Just-In-Time (JIT) compilation nature. By default OpenCL programs can be shipped in one of two forms, either as a low-level binary compiled to specific devices, or in a high level form with the original high level C code being compiled all the way down to binary form at runtime; the botton and top of the compilation stack respectively. Importantly, with OpenCL core there is nothing in between, leaving the only options being to expose the original code or put together binaries for each and every device family. To use a Java analogy, OpenCL core lacks the equivalent of an intermediate format like a class file, and this is what SPIR is intended to solve.

SPIR solves this by defining a standard intermediate representation for OpenCL code, along with creating the frontends and backends necessary to support SPIR. With the appropriate systems in place, software vendors would then be able to ship OpenCL programs and kernels compiled down to the SPIR format, with device drivers then consuming the SPIR code and compiling the programs to their final device specific formats.

Ultimately SPIR is primarily being driven by the needs of software vendors, whose needs are expanding as OpenCL stabilizes and matures, and the number of capable devices increases. The exposure of high level code in fully portable (and forward-compatible) programs was not a problem in the early days of OpenCL, but as additional developers come on board and OpenCL programs move from complexity levels similar to OpenGL shaders (simple) to full blown applications (complex) there’s a need to protect code from trivial reverse engineering and source code theft. Though by no means perfect, compiling code to lower levels – be it intermediate or low level – prevents trivial reverse engineering and provides a reasonable level of protection for code. And since the OpenCL JIT model means that low level binaries are not portable to other devices, there is a clear need for an intermediate format that provides similar protection while maintaining portability.

On a technical level, it should come as no great surprise that SPIR will be borrowing heavily from the tag-team duo of LLVM and Clang. LLVM is a widely popular compiler backend, used in both CPU and GPU environments alike. Meanwhile Clang is the C language compiler frontend for LLVM. By going this route Khronos is able to leverage the strengths of LLVM, mainly LLVM’s wide portability and existing high quality intermediate representation format, not to mention the fact that many of the OpenCL vendors already use LLVM for their GPGPU compilers (particularly NVIDIA’s CUDA toolchain).

As an added bonus, much like NVIDIA and their use of LLVM for CUDA, by moving to LLVM Khronos gains the ability to quickly and efficiently add support for new high level languages to OpenCL. The separation of backend from the frontend means that Clang merely needs to be extended or replaced to add new languages, and as it stands Clang offers Khronos a very clear path towards enabling C++ in future versions of OpenCL, something that developers have been asking about for quite some time now.

Of course SPIR still needs to do some evolving of its own, along with OpenCL core itself. OpenCL SPIR 1.2 is being released as a provisional specification today, which in Khronos governance means that it’s a proposed specification that’s still open to comments and modification. Khronos’s goal here is to finalize SPIR in 6 months, assuming everything goes well, making this the first standardized version of SPIR. In turn, once OpenCL 2.0 is finalized, the SPIR working group can then begin work on SPIR for OpenCL 2.0.

Ultimately if Khronos plays their cards right, SPIR could drive the kick in adoption that OpenCL has been lacking thus far. The ability to protect programs by shipping intermediate code provides a benefit today, but by moving to LLVM and greatly simplifying the process of adding new languages it also gives OpenCL a new level of flexibility that will help OpenCL in the future.

OpenGL 4.4 Specification Released OpenCL 2.0: What's New
Comments Locked

28 Comments

View All Comments

  • chris81 - Monday, July 22, 2013 - link

    Standing for Standard Portable Interface Representation -> Intermediate Representation
  • Ryan Smith - Monday, July 22, 2013 - link

    Aww geeze. Thanks for catching that. Fixed.
  • iwod - Tuesday, July 23, 2013 - link

    Hopefully within a year or two we should finally see some adoption into OpenCL acceleration. Which i have yet to see much software using it. ( May be CPU today is already fast enough for 95% of what we need. )

    Does OpenGL 4.4 matters? Do Microsoft Still support it on Windows ( I remember there were words on dropping support etc i didn't remember what turns out )
    And Apple, even with their unreleased OSX Maverick has ONLY just updated to OpenGL 4.0
    ( Yeah this is depressing )

    So the most important OpenGL would be OpenGL ES, where it is dominating / monopolizing the mobile world. Why isn't there any update on it?
  • Klimax - Tuesday, July 23, 2013 - link

    OpenGL is implemented by GPU vendors and connecting into graphics subsystem using provided interfaces.
    http://msdn.microsoft.com/en-us/library/windows/ha...
  • Krysto - Tuesday, July 23, 2013 - link

    What do you mean? They've just updated it to Open GL ES 3.0 last year. They won't update ES every year.

    That being said, with Nvidia starting to use the full OpenGL in mobile next year, I think Khronos needs to release ES 4.0 next year, so the other GPU chip makers can catch-up a bit, since adopting the full OpenGL 4.3/4.4 might be too hard for them. Nvidia had to use its PC architecture to do that, and even Intel on its latest Haswell for notebooks and PC's doesn't support more than 4.0, which they barely adopted at the last moment, too.

    So either Khronos gives the others ES 4.0 to work with, or the other mobile GPU makers will be literally *years* behind future Tegra devices, when it comes to graphics capability.
  • przemo_li - Thursday, July 25, 2013 - link

    Geometry shaders, and tesselation shaders consume much power and that was reason why they did not landed in OpenGL ES 3.0. It will be interesting to see if Nvidia can come up with some good solution here.

    (Also Intel is utilizing Mesa drivers for their Android efforts, those are already at full OGL 3.1, and 3.2/3.3 should come this year.)
  • Codeledger - Tuesday, July 23, 2013 - link

    As someone who is following Google's GPGPU efforts with Renderscript, it looks like OpenCL 2.0 and OpenCL SIPR are trying to address some of the issues brought up by the Android team. I would be curious to know if the various vendors are using Renderscript as a test bed DSL or in the future will Android adopt and expose OpenCL formally.
  • Wwhat - Sunday, July 28, 2013 - link

    New in OpenCl: DRM type crap

    No need to worry though, we keep the word 'open' in the name...for 'your' convenience.

Log in

Don't have an account? Sign up now