This adds support for allocating DMA buffers on systems that support it, i.e. Linux and Android. On mainline Linux, starting version 5.6 (equivalent to Android 12), there is a new kernel module framework available called [DMA-BUF Heaps](https://github.com/torvalds/linux/blob/master/drivers/dma-buf/dma-heap.c). The goal of this framework is to provide a standardised way for user applications to allocate and share memory buffers between different devices, subsystems, etc. The main feature of interest is that the framework provides device-agnostic allocation; it abstracts away the underlying hardware, and provides a single IOCTL, `DMA_HEAP_IOCTL_ALLOC`. Mainline implementation provides two heaps that act as character devices that can allocate DMA buffers; system, which uses the buddy allocator, and cma, which uses the [CMA](https://developer.toradex.com/software/linux-resources/linux-features/contiguous-memory-allocator-cma-linux/) (Contiguous Memory Allocator). Both of these are [kernel configuration options](https://github.com/torvalds/linux/blob/master/drivers/dma-buf/heaps/Kconfig) that need to be enabled when building the Linux kernel. Generally, any kernel module implementing this framework is made available under /dev/dma_heaps/<heap_name>, e.g. /dev/dma_heaps/system. The implementation currently only supports one type of DMA heaps; `system`, the default device path for which is `/dev/dma_heap/system`. The path can be overridden at runtime using an environment variable, `OCL_CTS_DMA_HEAP_PATH_SYSTEM`, if needed. Extending this in the future should be trivial (subject to platform support), by adding an entry to the enum `dma_buf_heap_type`, and an appropriate default path and overriding environment variable name. The proposed implementation will conditionally compile if the conditions are met (i.e. building for Linux or Android, using kernel headers >= 5.6.0), and will provide a compile-time warning otherwise, and return `-1` as the DMA handle in runtime if not. To demonstrate the functionality, a new test is added for the `cl_khr_external_memory_dma_buf` extension. If the extension is supported by the device, a DMA buffer will be allocated and used to create a CL buffer, that is then used by a simple kernel. This should provide a way forward for adding more tests that depend on DMA buffers. --------- Signed-off-by: Gorazd Sumkovski <gorazd.sumkovski@arm.com> Signed-off-by: Ahmed Hesham <ahmed.hesham@arm.com> Co-authored-by: Gorazd Sumkovski <gorazd.sumkovski@arm.com>
OpenCL Conformance Test Suite (CTS)
This is the OpenCL CTS for all versions of the Khronos OpenCL standard.
Building the CTS
The CTS supports Linux, Windows, macOS, and Android platforms. In particular, GitHub Actions CI builds against Ubuntu 20.04, Windows-latest, and macos-latest.
Compiling the CTS requires the following CMake configuration options to be set:
CL_INCLUDE_DIRPoints to the unified OpenCL-Headers.CL_LIB_DIRDirectory containing the OpenCL library to build against.OPENCL_LIBRARIESName of the OpenCL library to link.
It is advised that the OpenCL ICD-Loader
is used as the OpenCL library to build against. Where CL_LIB_DIR points to a
build of the ICD loader and OPENCL_LIBRARIES is "OpenCL".
Example Build
Steps on a Linux platform to clone dependencies from GitHub sources, configure a build, and compile.
git clone https://github.com/KhronosGroup/OpenCL-CTS.git
git clone https://github.com/KhronosGroup/OpenCL-Headers.git
git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader.git
mkdir OpenCL-ICD-Loader/build
cmake -S OpenCL-ICD-Loader -B OpenCL-ICD-Loader/build \
-DOPENCL_ICD_LOADER_HEADERS_DIR=$PWD/OpenCL-Headers
cmake --build ./OpenCL-ICD-Loader/build --config Release
mkdir OpenCL-CTS/build
cmake -S OpenCL-CTS -B OpenCL-CTS/build \
-DCL_INCLUDE_DIR=$PWD/OpenCL-Headers \
-DCL_LIB_DIR=$PWD/OpenCL-ICD-Loader/build \
-DOPENCL_LIBRARIES=OpenCL
cmake --build OpenCL-CTS/build --config Release
Running the CTS
A build of the CTS contains multiple executables representing the directories in
the test_conformance folder. Each of these executables contains sub-tests, and
possibly smaller granularities of testing within the sub-tests.
See the --help output on each executable for the list of sub-tests available,
as well as other options for configuring execution.
If the OpenCL library built against is the ICD Loader, and the vendor library to be tested is not registered in the default ICD Loader location then the OCL_ICD_FILENAMES environment variable will need to be set for the ICD Loader to detect the OpenCL library to use at runtime. For example, to run the basic tests on a Linux platform:
OCL_ICD_FILENAMES=/path/to/vendor_lib.so ./test_basic
Offline Compilation
Testing OpenCL drivers which do not have a runtime compiler can be done by using additional command line arguments provided by the test harness for tests which require compilation, these are:
-
--compilation-modeSelects if OpenCL-C source code should be compiled using an external tool before being passed on to the OpenCL driver in that form for testing. Online is the default mode, but also accepts the valuesspir-v, andbinary. -
--compilation-cache-modeControls how the compiled OpenCL-C source code should be cached on disk. -
--compilation-cache-pathAccepts a path to a directory where the compiled binary cache should be stored on disk. -
--compilation-programAccepts a path to an executable (default: cl_offline_compiler) invoked by the test harness to perform offline compilation of OpenCL-C source code. This executable must match the interface description.
Generating a Conformance Report
The Khronos Conformance Process Document details the steps required for a conformance submission. In this repository opencl_conformance_tests_full.csv defines the full list of tests which must be run for conformance. The output log of which must be included alongside a filled in submission details template.
Utility script run_conformance.py can be used to help generating the submission log, although it is not required.
Git tags are used to define the version of the repository conformance submissions are made against.
Contributing
Contributions are welcome to the project from Khronos members and non-members alike via GitHub Pull Requests (PR). Alternatively, if you've found a bug or have a question please file an issue in the GitHub project. First time contributors will be required to sign the Khronos Contributor License Agreement (CLA) before their PR can be merged.
PRs to the repository are required to be clang-format clean to pass CI.
Developers can either use the git-clang-format tool locally to verify this
before contributing, or update their PR based on the diff provided by a failing
CI job.