This page covers the installation of the C and C++ headers of the OpenCL API, which allows running functions, or kernels, on CPUs and GPUs. This can speed up certain actions, allowing for better performance.
First, create a list of files to be downloaded:
cat > ocl-headers-list << "EOF"
OpenCL-Headers/archive/v2025.07.22/OpenCL-Headers-2025.07.22.tar.gz
OpenCL-CLHPP/archive/v2025.07.22/OpenCL-CLHPP-2025.07.22.tar.gz
EOF
To download the needed files using Wget-1.25.0, use the following commands:
mkdir ocl-headers &&
cd ocl-headers &&
grep -v '^#' ../ocl-headers-list | wget -i- -c \
-B https://github.com/KhronosGroup/
When installing multiple packages in a script, the installation needs to be done as the root user. There are three general options that can be used to do this:
Run the entire script as the root user (not recommended).
Use the sudo command from the sudo package.
Use su -c "command arguments" (quotes required) which will ask for the root password for every iteration of the loop.
One way to handle this situation is to create a short bash function that automatically selects the appropriate method. Once the command is set in the environment, it does not need to be set again.
as_root()
{
if [ $EUID = 0 ]; then $*
elif [ -x /usr/bin/sudo ]; then sudo $*
else su -c \\"$*\\"
fi
}
export -f as_root
First, start a subshell that will exit on error:
bash -e
Install all of the packages by running the following commands:
for package in OpenCL-{Headers,CLHPP}
do
longpackage=$package-2025.07.22.tar.?z*
packagedir=${longpackage%.tar.?z*}
tar -xf $longpackage
pushd $packagedir
mkdir build
cd build
cmake -D CMAKE_INSTALL_PREFIX=/usr \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_TESTING=OFF \
-D BUILD_EXAMPLES=OFF \
-G Ninja ..
as_root ninja install
popd
rm -rf $packagedir
done
Finally, exit the shell that was started earlier:
exit