Building the OpenCL 2.2 conformance test suite for Khronos

OpenCL only works as a standard if everyone agrees what “OpenCL” means: the same results on every GPU, FPGA, DSP and CPU, from embedded to cloud. Conformance tests make that true in practice. They give an implementation the right to call itself conformant. In September 2016, the Khronos Group sent out a request for proposals (RFP) for updating the OpenCL conformance test suite to 2.2. It chose us to extend the current conformance test suite. Work started mid-November of that year.

Such assignment fits us well. We care about correct software: correct software is the foundation of quality, and quality is the foundation of performance. A conformance suite might not be the project you’d expect from a performance company, but this kind of work is deeply embedded in our culture.

About the customer

The Khronos Group is a not-for-profit industry consortium that develops open, royalty-free standards such as OpenCL, SPIR-V and Vulkan. Its conformance tests are the quality backbone of these standards. They give implementers and end users the confidence that a conformant device behaves the same everywhere. Members include Nvidia, AMD, Intel, Qualcomm, Huawei, Imagination and Verisilicon. All sit at the same table, building a standard that will benefit them all.

The challenge

OpenCL 2.2 was a major step. It introduced the OpenCL C++ kernel language and added new functionality such as pipe storage. The kernel language uses the new SPIR-V 1.1 intermediate representation. Khronos scoped the update as four work packages, 76 man-days in total, to be delivered by two developers. Updating the test suite meant several things at once:

  • Extend the kernel tests for the OpenCL Ckernel language. This covered the new C representations of types and functions: images, samplers, pipes, address spaces, atomics, and the full set of work-group and sub-group functions.
  • Add tests for the new OpenCL 2.2 features, from specialization constants and named barriers to constructors of program-scope objects.
  • Port the existing LIT tests from LLVM IR to SPIR-V 1.1, working directly in SPIR-V where needed.
  • Add tests for the new OpenCL 2.2 API features, such as queries for program-scope constructors and destructors.
  • Analyze all test sources for the licenses needed to open-source the suite under Apache 2.0.

All of this against a moving target: parts of the toolchain, such as the C++ frontend for SPIR-V, remained experimental. Every new test also had to build across Windows, Linux, Android and Mac, inside the existing conformance framework.

Our approach

A conformance test only works if you can trust it. A false failure blocks a vendor for no reason. A false pass silently breaks the standard. False alarms are expensive, and so are tests that pass for the wrong reason. Everything in our approach was aimed at getting the tests right the first time.

Understand what we’re testing against. Before writing tests, we studied the OpenCL 2.2 specification chapter by chapter. We even spotted errors in the RFP itself. We also analyzed the existing test suite and documented its coding style. That way our additions would blend in, and future developers could keep extending it.

Design tests twice. We designed each test in two phases: proposed, then reviewed and completed. We have had good experience with this “double attack.” It identifies potential problems early, before they hide inside hundreds of near-identical test cases.

Check correctness independently. The risk of false results was highest in tests around the experimental C++ frontend. There, two developers independently implemented selected tests. We then compared the results.

Identify risks before planning. We have a “think before doing” approach. For this project, we identified the risk factors up front: incomplete specifications, experimental toolchain components, refactoring needs, and the many C++ restrictions that all need negative tests. We took them into account in planning, so nothing surprised us later.

Test our own work continuously. Our build and test environment runs a wide range of devices. It exercised the tests we wrote automatically on real hardware throughout the project.

The result

We delivered the full scope: updated and new tests for the OpenCL C++ kernel language and the OpenCL 2.2 API, plus the LIT tests ported to SPIR-V 1.1. The license analysis cleared the suite for open source under the Khronos Apache 2.0 license. We did it on time, to the customer’s satisfaction. While working from the specification, we also found and covered missing parts that earlier work overlooked. Those are exactly the kinds of gaps fresh eyes are supposed to find in a conformance suite.

Key takeaway

Conformance testing is quality work with the stakes raised. One flawed test either blocks a vendor unfairly or lets a broken implementation pass. Careful preparation and independent verification pay off directly here. That is why the Khronos Group and all its members could rely on the result.

Want this for your project?

We have developed several test suites, allowing our customers to speed up development of their compilers.

Contact us to discuss how we can help with your conformance, quality or performance engineering project.

Scroll to Top