GPUBench now supports both Vulkan and OpenCL compute backends, providing flexibility for devices that may not support Vulkan.
The dual-backend architecture consists of:
- IComputeContext Interface - Abstract interface for compute backends
- VulkanContext - Vulkan backend implementation
- OpenCLContext - OpenCL backend implementation
- ComputeBackendFactory - Factory for creating and managing backends
- Backend Detection - Automatic runtime detection with fallback support
You need OpenCL development files installed:
Fedora/RHEL:
sudo dnf install ocl-icd-devel opencl-headersUbuntu/Debian:
sudo apt-get install opencl-headers ocl-icd-opencl-devArch Linux:
sudo pacman -S opencl-headers ocl-icdmkdir build
cd build
cmake ..
makeCMake will automatically detect available backends:
- If both Vulkan and OpenCL are found, both will be compiled in
- If only Vulkan is found, only Vulkan will be available
- If only OpenCL is found, only OpenCL will be available
- If neither is found, the build will fail
# Use automatic backend detection (prefers Vulkan, falls back to OpenCL)
./gpubench
# Explicitly use Vulkan
./gpubench --backend vulkan
# Explicitly use OpenCL
./gpubench --backend opencl
# List available devices
./gpubench --list-devices --backend vulkan
./gpubench --list-devices --backend openclThe -k or --backend flag supports three values:
auto(default): Automatically detect and use the best available backendvulkan: Force use of Vulkan backendopencl: Force use of OpenCL backend
- Compute backend abstraction layer (IComputeContext)
- VulkanContext implementation with IComputeContext interface
- OpenCLContext implementation
- Backend factory with automatic detection and fallback
- Command-line backend selection
- CMake build system updates for dual-backend support
- OpenCL kernel conversions (all 6 kernels: FP64, FP32, FP16, FP8, INT8, INT4)
- OpenCL-specific benchmark implementations
Currently, benchmarks only work with the Vulkan backend. When OpenCL is selected, the program will display:
Note: Benchmarks are currently only implemented for Vulkan backend.
OpenCL benchmark implementations are planned for future releases.
To complete OpenCL benchmark support, the following needs to be done:
-
Create OpenCL Benchmark Implementations
- Implement OpenCL versions of all 6 benchmarks
- Handle OpenCL buffer creation and kernel execution
- Implement timing using OpenCL events
-
Update IBenchmark Interface
- Make benchmark interface backend-agnostic
- Support both Vulkan and OpenCL execution paths
-
BenchmarkRunner Updates
- Add OpenCL execution path in BenchmarkRunner
- Implement OpenCL timing and result collection
All GLSL compute shaders have been converted to OpenCL C kernels:
| Benchmark | GLSL Shader | OpenCL Kernel |
|---|---|---|
| FP64 | shaders/fp64.comp |
kernels/fp64.cl |
| FP32 | shaders/fp32.comp |
kernels/fp32.cl |
| FP16 | shaders/fp16.comp |
kernels/fp16.cl |
| FP8 | shaders/fp8.comp |
kernels/fp8.cl |
| INT8 | shaders/int8.comp |
kernels/int8.cl |
| INT4 | shaders/int4.comp |
kernels/int4.cl |
OpenCL kernels use similar algorithmic approaches to the GLSL shaders but adapted for OpenCL syntax and vector types.
The IComputeContext interface provides:
virtual ComputeBackend getBackend() const = 0;
virtual const std::vector<DeviceInfo>& getDevices() const = 0;
virtual void pickDevice(uint32_t index) = 0;
virtual DeviceInfo getCurrentDeviceInfo() const = 0;
// Backend-specific accessors
virtual VkPhysicalDevice getVulkanPhysicalDevice() const;
virtual VkDevice getVulkanDevice() const;
virtual void* getVulkanContext() const;
virtual cl_platform_id getOpenCLPlatform() const;
virtual cl_device_id getOpenCLDevice() const;
virtual cl_context getOpenCLContext() const;The build system uses preprocessor definitions:
HAVE_VULKAN- Defined when Vulkan is availableHAVE_OPENCL- Defined when OpenCL is available
Code can conditionally compile for available backends:
#ifdef HAVE_VULKAN
// Vulkan-specific code
#endif
#ifdef HAVE_OPENCL
// OpenCL-specific code
#endifIf CMake reports "OpenCL not found" but you have OpenCL installed:
-
Check that you have both headers and libraries:
ls /usr/include/CL/cl.h ls /usr/lib64/libOpenCL.so # or /usr/lib/x86_64-linux-gnu/ -
You may need to manually specify OpenCL paths:
cmake -DOpenCL_INCLUDE_DIR=/usr/include \ -DOpenCL_LIBRARY=/usr/lib64/libOpenCL.so ..
This means the binary was not compiled with OpenCL support. Rebuild with OpenCL development files installed.
To add full OpenCL benchmark support:
- Create OpenCL benchmark classes (similar to existing Vulkan benchmarks)
- Update BenchmarkRunner to support OpenCL execution
- Test with various OpenCL devices (AMD, NVIDIA, Intel)
- Ensure timing accuracy with OpenCL events
- Submit a pull request with the changes
Same as GPUBench main project.