OpenCL implementation running on the VideoCore IV GPU of the Raspberry Pi models
C++
740
218 commits
updated Sep 14, 2022
NOTE: VC4CL will NOT work with Raspberry Pi 4, since it has an incompatible GPU!
VC4CL is an implementation of the OpenCL 1.2 standard for the VideoCore IV GPU (found in Raspberry Pi 1 - 3 models).
The implementation consists of:
The VC4CL implementation supports the EMBEDDED PROFILE of the OpenCL standard version 1.2.
Additionally the cl_khr_icd extension is supported, to allow VC4CL to be found by an installable client driver loader (ICD). This enables VC4CL to be used in parallel with another OpenCL implementation, e.g. pocl, which executes OpenCL code on the host CPU.
The OpenCL version 1.2 was selected as target standard version, since it is the last version of the OpenCL standard where all mandatory features can be supported.
VC4CL supports the EMBEDDED PROFILE of the OpenCL-standard, which is a trimmed version of the default FULL PROFILE. The most notable features, which are not supported by the VC4CL implementation are images, the long and double data-types, device-side printf and partitioning devices. See RuntimeLibrary for more details of (not) supported features.
The VideoCore IV GPU, in the configuration as found in the Raspberry Pi models, has a theoretical maximum performance of 24 GPFLOS and is therefore very powerful in comparison to the host CPU. The GPU (which is located on the same chip as the CPU) has 12 cores, able of running independent instructions each, supports a SIMD vector-width of 16 elements natively and can access the RAM directly via DMA.
sudo apt-get install libraspberrypi-dev)sudo apt-get install ocl-icd-opencl-dev ocl-icd-dev) for building with ICD-support (e.g. allows to run several OpenCL implementations on one machine)sudo apt-get install opencl-headers)The following configuration options are available in CMake:
BUILD_TESTING toggles building of test program (when configured, can be built with make TestVC4CL)CMAKE_BUILD_TYPE set to Debug, Release, RelWithDebInfo, asan, tsan or usbsan to build for the given debug/release mode or with sanitizers enabledCROSS_COMPILE toggles whether to cross-compile for the Raspberry Pi. NOTE: The Raspberry Pi cross-compiler is no longer supported!CROSS_COMPILER_PATH sets the root path to the Raspberry Pi cross compiler (.g. arm-linux-gnueabihf-g++-6)INCLUDE_COMPILER whether to include the VC4C compiler. For the compiler to be actually included, the VC4C header and library needs to be found tooVC4C_HEADER_PATH sets the path to the VC4C include headers, defaults to ../VC4C/include/VC4C.h or lib/vc4c/include/VC4C.hVC4CC_LIBRARY sets the path to the VC4C compiler library, defaults to ../VC4C/build/libVC4CC.xxx or lib/vc4c/build/libVC4CC.xxxBUILD_ICD toggles whether to build with support for the Khronos ICD loader, requires the ICD loader to be installed system-wideIMAGE_SUPPORT toggles whether to enable the very experimental image-supportThe Khronos ICD Loaders allows multiple OpenCL implementation to be used in parallel (e.g. VC4CL and pocl), but requires a bit of manual configuration:
Create a file /etc/OpenCL/vendors/VC4CL.icd with a single line containing the absolute path to the VC4CL library.
The program clinfo can be used to test, whether the ICD loader finds the VC4CL implementation. Note: the program version in the official Raspbian repository is too old and has a bug (see fix), so it must be compiled from the github repository.
Because of the DMA-interface which has no MMU between the GPU and the RAM, code executed on the GPU can access any part of the main memory! This means, an OpenCL kernel could be used to read sensitive data or write into kernel memory!
Depending on the configuration used for the VC4CL (see Experimental Features below), the process using the VC4CL library needs to be either root (e.g. via sudo <program>) or be in the video group).
The v3d_info and v3d_profiling tools in this project need to be run as root to give the maximum amount of information.
Since this software is still in development, some functionality might not work. For curious users or to be able to provide more information for bugs, additional debug information can be generated if desired.
To generate debug information, set the VC4CL_DEBUG environment variable to one (or multiple, separated by commas) of the following strings:
api enables logging OpenCL API calls, parameters and non-success errors to the standard outputcode enables dumping OpenCL C (or IR) source code as well as generated VC4C binary code into temporary files for the compilation functionssyscall enables logging detailed information for syscalls (e.g. mailbox) to the standard outputexecution enables logging of detailed kernel execution information (parameters, execution cycle, return codes) to the standard outputevents enables logging of asynchronous event processing information to the standard outputobjects enables logging of lifetime begin/end and leaks of OpenCL API objects to the standard outputperf enables collection and logging of V3D hardware performance counters to the standard outputsystem enables logging high-level information about the selected system interfaces (e.g. mailbox, V3D, VCSM, etc.) to the standard outputmemory enables logging of memory (buffer) management related information to the standard outputall enables all above logging modesMostly for development, performance comparison and debugging purposes, the system interfaces used for specific system accesses can be selected via following environment variables:
VC4CL_EMULATOR forces to use the emulator, does not actually access any specific VideoCore hardwareVC4CL_EXECUTE_MAILBOX explicitly uses the mailbox interface to execute kernels, which has a system-wide lock on the GPU accessVC4CL_EXECUTE_REGISTER_POKING explicitly directly writes the V3D registers, which is faster, but less compatible with other applications using the VideoCore IV hardwareVC4CL_EXECUTE_VCHI explicitly uses the VCHI "GPUS" service to execute kernelsVC4CL_MEMORY_CMA explicitly uses the newer VCSM CMA interface (with fall-back to the VCSM interface) to manage GPU-accessible memoryVC4CL_MEMORY_VCSM explicitly uses the older VCSM interface (with fall-back to the VCSM CMA interface) to manage GPU-accessible memoryVC4CL_MEMORY_MAILBOX explicitly uses the mailbox interface to manage GPU-accessible memoryVC4CL_NO_<COMPONENT> with <COMPONENT> either MAILBOX, V3D, VCSM or VCHI disables the given component completelyVC4CL_CACHE_FORCE=<VAL> forces the buffer caching behavior to uncached (<VAL> = 0), host-cached (<VAL> = 1), GPU-cached (<VAL> = 2) or host- and GPU-cached (<VAL> = 3)163 followers · starred Dec 2020
1,244 followers · starred Feb 2022
64 followers · starred May 2023
236 followers · starred Sep 2019
OpenCL implementation running on the VideoCore IV GPU of the Raspberry Pi models
C++
740
218 commits
updated Sep 14, 2022
NOTE: VC4CL will NOT work with Raspberry Pi 4, since it has an incompatible GPU!
VC4CL is an implementation of the OpenCL 1.2 standard for the VideoCore IV GPU (found in Raspberry Pi 1 - 3 models).
The implementation consists of:
The VC4CL implementation supports the EMBEDDED PROFILE of the OpenCL standard version 1.2.
Additionally the cl_khr_icd extension is supported, to allow VC4CL to be found by an installable client driver loader (ICD). This enables VC4CL to be used in parallel with another OpenCL implementation, e.g. pocl, which executes OpenCL code on the host CPU.
The OpenCL version 1.2 was selected as target standard version, since it is the last version of the OpenCL standard where all mandatory features can be supported.
VC4CL supports the EMBEDDED PROFILE of the OpenCL-standard, which is a trimmed version of the default FULL PROFILE. The most notable features, which are not supported by the VC4CL implementation are images, the long and double data-types, device-side printf and partitioning devices. See RuntimeLibrary for more details of (not) supported features.
The VideoCore IV GPU, in the configuration as found in the Raspberry Pi models, has a theoretical maximum performance of 24 GPFLOS and is therefore very powerful in comparison to the host CPU. The GPU (which is located on the same chip as the CPU) has 12 cores, able of running independent instructions each, supports a SIMD vector-width of 16 elements natively and can access the RAM directly via DMA.
sudo apt-get install libraspberrypi-dev)sudo apt-get install ocl-icd-opencl-dev ocl-icd-dev) for building with ICD-support (e.g. allows to run several OpenCL implementations on one machine)sudo apt-get install opencl-headers)The following configuration options are available in CMake:
BUILD_TESTING toggles building of test program (when configured, can be built with make TestVC4CL)CMAKE_BUILD_TYPE set to Debug, Release, RelWithDebInfo, asan, tsan or usbsan to build for the given debug/release mode or with sanitizers enabledCROSS_COMPILE toggles whether to cross-compile for the Raspberry Pi. NOTE: The Raspberry Pi cross-compiler is no longer supported!CROSS_COMPILER_PATH sets the root path to the Raspberry Pi cross compiler (.g. arm-linux-gnueabihf-g++-6)INCLUDE_COMPILER whether to include the VC4C compiler. For the compiler to be actually included, the VC4C header and library needs to be found tooVC4C_HEADER_PATH sets the path to the VC4C include headers, defaults to ../VC4C/include/VC4C.h or lib/vc4c/include/VC4C.hVC4CC_LIBRARY sets the path to the VC4C compiler library, defaults to ../VC4C/build/libVC4CC.xxx or lib/vc4c/build/libVC4CC.xxxBUILD_ICD toggles whether to build with support for the Khronos ICD loader, requires the ICD loader to be installed system-wideIMAGE_SUPPORT toggles whether to enable the very experimental image-supportThe Khronos ICD Loaders allows multiple OpenCL implementation to be used in parallel (e.g. VC4CL and pocl), but requires a bit of manual configuration:
Create a file /etc/OpenCL/vendors/VC4CL.icd with a single line containing the absolute path to the VC4CL library.
The program clinfo can be used to test, whether the ICD loader finds the VC4CL implementation. Note: the program version in the official Raspbian repository is too old and has a bug (see fix), so it must be compiled from the github repository.
Because of the DMA-interface which has no MMU between the GPU and the RAM, code executed on the GPU can access any part of the main memory! This means, an OpenCL kernel could be used to read sensitive data or write into kernel memory!
Depending on the configuration used for the VC4CL (see Experimental Features below), the process using the VC4CL library needs to be either root (e.g. via sudo <program>) or be in the video group).
The v3d_info and v3d_profiling tools in this project need to be run as root to give the maximum amount of information.
Since this software is still in development, some functionality might not work. For curious users or to be able to provide more information for bugs, additional debug information can be generated if desired.
To generate debug information, set the VC4CL_DEBUG environment variable to one (or multiple, separated by commas) of the following strings:
api enables logging OpenCL API calls, parameters and non-success errors to the standard outputcode enables dumping OpenCL C (or IR) source code as well as generated VC4C binary code into temporary files for the compilation functionssyscall enables logging detailed information for syscalls (e.g. mailbox) to the standard outputexecution enables logging of detailed kernel execution information (parameters, execution cycle, return codes) to the standard outputevents enables logging of asynchronous event processing information to the standard outputobjects enables logging of lifetime begin/end and leaks of OpenCL API objects to the standard outputperf enables collection and logging of V3D hardware performance counters to the standard outputsystem enables logging high-level information about the selected system interfaces (e.g. mailbox, V3D, VCSM, etc.) to the standard outputmemory enables logging of memory (buffer) management related information to the standard outputall enables all above logging modesMostly for development, performance comparison and debugging purposes, the system interfaces used for specific system accesses can be selected via following environment variables:
VC4CL_EMULATOR forces to use the emulator, does not actually access any specific VideoCore hardwareVC4CL_EXECUTE_MAILBOX explicitly uses the mailbox interface to execute kernels, which has a system-wide lock on the GPU accessVC4CL_EXECUTE_REGISTER_POKING explicitly directly writes the V3D registers, which is faster, but less compatible with other applications using the VideoCore IV hardwareVC4CL_EXECUTE_VCHI explicitly uses the VCHI "GPUS" service to execute kernelsVC4CL_MEMORY_CMA explicitly uses the newer VCSM CMA interface (with fall-back to the VCSM interface) to manage GPU-accessible memoryVC4CL_MEMORY_VCSM explicitly uses the older VCSM interface (with fall-back to the VCSM CMA interface) to manage GPU-accessible memoryVC4CL_MEMORY_MAILBOX explicitly uses the mailbox interface to manage GPU-accessible memoryVC4CL_NO_<COMPONENT> with <COMPONENT> either MAILBOX, V3D, VCSM or VCHI disables the given component completelyVC4CL_CACHE_FORCE=<VAL> forces the buffer caching behavior to uncached (<VAL> = 0), host-cached (<VAL> = 1), GPU-cached (<VAL> = 2) or host- and GPU-cached (<VAL> = 3)163 followers · starred Dec 2020
1,244 followers · starred Feb 2022
64 followers · starred May 2023
236 followers · starred Sep 2019