Skip to main content

Khronos Blog

What’s new in Clang release 14 for OpenCL developers?

Clang 14 was released last week, bringing some long-awaited features for the OpenCL™ community.

Perhaps the most notable feature is the ability to generate a SPIR-V™ binary from OpenCL kernel sources directly from clang using the familiar interface:

clang –target=spirv64

This command will generate the SPIR-V binary foo.o that can be loaded by OpenCL drivers supporting SPIR-V via clCreateProgramWithIL(...) or it can be used further in offline compilation tools. But there is one caveat - currently clang requires an external tool ‘llvm-spirv’ from the SPIRV-LLVM-Translator repo to be installed separately; see more details in Clang User’s Manual. Clang will use ‘spriv-link’ from the SPIRV-Tools repo when multiple translation units compiled to SPIR-V are to be linked together.

clang –target=spirv64 -o myapp.out

While separate installation of tools is required, the new functionality significantly simplifies the development for SPIR-V with clang and more improvements are yet to come with the integration of a native LLVM SPIR-V backend which is being in progress with initial functionality already planned to appear in the next release.

Moreover, Clang 14 will contain complete support for the latest OpenCL 3.0 standard.

clang -cl-std=CL3.0

In addition, Clang 14 is the first release to contain support for the C++ for OpenCL 2021 kernel language announced last year. This new version of C++ for OpenCL brings the C++-based OpenCL kernel language in alignment with OpenCL 3.0 by allowing the use of optional features just the same way as in OpenCL C 3.0. The provisional documentation of this new language has been released in December last year.

clang -cl-std=CLC++2021 foo.clcpp

These new features appear in the release as experimental and more details can be found in the Clang User’s Manual and the OpenCL Support page. The OpenCL community is invited to try the new functionality and provide any feedback by filing GitHub issues or getting in touch with {encode [email protected]} the OpenCL Tooling TSG for more detailed feedback and discussions.