Skip to content

Commit 5df6571

Browse files
committed
Driver installation instructions will be printed to console if no OpenCL devices are available
1 parent b91f51a commit 5df6571

File tree

3 files changed

+81
-6
lines changed

3 files changed

+81
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Works with any GPU in Windows, Linux, macOS and Android.
4141
```
4242

4343
### Run only for a specified list of devices
44-
- call `OpenCL-Benchmark.exe 0 2 5` (Windows) or `bin/OpenCL-Benchmark 0 2 5` (Linux/macOS) with the number(s) being the device IDs to be benchmarked
44+
- call `bin\OpenCL-Benchmark.exe 0 2 5` (Windows) or `bin/OpenCL-Benchmark 0 2 5` (Linux/macOS) with the number(s) being the device IDs to be benchmarked
4545

4646

4747

make.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ mkdir -p bin # create directory for executable
55
rm -f bin/OpenCL-Benchmark # prevent execution of old version if compiling fails
66

77
case "$(uname -a)" in # automatically detect operating system and X11 support on Linux
8-
Darwin*) g++ src/*.cpp -o ./bin/OpenCL-Benchmark -std=c++17 -pthread -O -Wno-comment -I./src/OpenCL/include -framework OpenCL ;; # compile on macOS
9-
*Android) g++ src/*.cpp -o ./bin/OpenCL-Benchmark -std=c++17 -pthread -O -Wno-comment -I./src/OpenCL/include -L/system/vendor/lib64 -lOpenCL ;; # compile on Android
10-
* ) g++ src/*.cpp -o ./bin/OpenCL-Benchmark -std=c++17 -pthread -O -Wno-comment -I./src/OpenCL/include -L./src/OpenCL/lib -lOpenCL ;; # compile on Linux
8+
Darwin*) g++ src/*.cpp -o bin/OpenCL-Benchmark -std=c++17 -pthread -O -Wno-comment -I./src/OpenCL/include -framework OpenCL ;; # macOS
9+
*Android) g++ src/*.cpp -o bin/OpenCL-Benchmark -std=c++17 -pthread -O -Wno-comment -I./src/OpenCL/include -L/system/vendor/lib64 -lOpenCL ;; # Android
10+
* ) g++ src/*.cpp -o bin/OpenCL-Benchmark -std=c++17 -pthread -O -Wno-comment -I./src/OpenCL/include -L./src/OpenCL/lib -lOpenCL ;; # Linux
1111
esac
1212

13-
if [[ $? == 0 ]]; then bin/OpenCL-Benchmark "$@"; fi # run OpenCL-Benchmark only if last compilation was successful
13+
if [[ $? == 0 ]]; then bin/OpenCL-Benchmark "$@"; fi # run executable only if last compilation was successful

src/opencl.hpp

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,76 @@
1111
#include "utilities.hpp"
1212
using cl::Event;
1313

14+
static const string driver_installation_instructions =
15+
#if defined(_WIN32)
16+
R"(|----------------.------------------------------------------------------------'
17+
| AMD GPUs | https://www.amd.com/en/support/download/drivers.html
18+
| Intel GPUs | https://www.intel.com/content/www/us/en/download/785597/intel-arc-iris-xe-graphics-windows.html
19+
| Nvidia GPUs | https://www.nvidia.com/Download/index.aspx
20+
| AMD/Intel CPUs | https://www.intel.com/content/www/us/en/developer/articles/technical/intel-cpu-runtime-for-opencl-applications-with-sycl-support.html
21+
|----------------'------------------------------------------------------------.
22+
| Don't forget to reboot after installation! Press Enter to exit. |
23+
'-----------------------------------------------------------------------------')""\n";
24+
#else // Linux
25+
string("'-----------------------------------------------------------------------------'\n")+R"(
26+
)"+string("\033[31m")+R"(.-----------------------------------------------------------------------------.
27+
| AMD GPU Drivers, which contain the OpenCL Runtime |
28+
'-----------------------------------------------------------------------------'
29+
sudo apt update && sudo apt upgrade -y
30+
sudo apt install -y g++ git make ocl-icd-libopencl1 ocl-icd-opencl-dev
31+
mkdir -p ~/amdgpu
32+
wget -P ~/amdgpu https://repo.radeon.com/amdgpu-install/6.1.3/ubuntu/jammy/amdgpu-install_6.1.60103-1_all.deb
33+
sudo apt install -y ~/amdgpu/amdgpu-install*.deb
34+
sudo amdgpu-install -y --usecase=graphics,rocm,opencl --opencl=rocr
35+
sudo usermod -a -G render,video $(whoami)
36+
rm -r ~/amdgpu
37+
sudo shutdown -r now
38+
39+
)"+string("\033[94m")+R"(.-----------------------------------------------------------------------------.
40+
| Intel GPU Drivers are already installed, only the OpenCL Runtime is needed |
41+
'-----------------------------------------------------------------------------'
42+
sudo apt update && sudo apt upgrade -y
43+
sudo apt install -y g++ git make ocl-icd-libopencl1 ocl-icd-opencl-dev intel-opencl-icd
44+
sudo usermod -a -G render $(whoami)
45+
sudo shutdown -r now
46+
47+
)"+string("\033[32m")+R"(.-----------------------------------------------------------------------------.
48+
| Nvidia GPU Drivers, which contain the OpenCL Runtime |
49+
'-----------------------------------------------------------------------------'
50+
sudo apt update && sudo apt upgrade -y
51+
sudo apt install -y g++ git make ocl-icd-libopencl1 ocl-icd-opencl-dev nvidia-driver-550
52+
sudo shutdown -r now
53+
54+
)"+string("\033[96m")+R"(.-----------------------------------------------------------------------------.
55+
| CPU Option 1: Intel CPU Runtime for OpenCL (works for both AMD/Intel CPUs) |
56+
'-----------------------------------------------------------------------------'
57+
export OCLCPUEXP_VERSION="2024.18.6.0.02_rel"
58+
export ONEAPI_TBB_VERSION="2021.13.0"
59+
sudo apt update && sudo apt upgrade -y
60+
sudo apt install -y g++ git make ocl-icd-libopencl1 ocl-icd-opencl-dev
61+
sudo mkdir -p ~/cpuruntime /opt/intel/oclcpuexp_${OCLCPUEXP_VERSION} /etc/OpenCL/vendors /etc/ld.so.conf.d
62+
sudo wget -P ~/cpuruntime https://github.com/intel/llvm/releases/download/2024-WW25/oclcpuexp-${OCLCPUEXP_VERSION}.tar.gz
63+
sudo wget -P ~/cpuruntime https://github.com/oneapi-src/oneTBB/releases/download/v${ONEAPI_TBB_VERSION}/oneapi-tbb-${ONEAPI_TBB_VERSION}-lin.tgz
64+
sudo tar -zxvf ~/cpuruntime/oclcpuexp-${OCLCPUEXP_VERSION}.tar.gz -C /opt/intel/oclcpuexp_${OCLCPUEXP_VERSION}
65+
sudo tar -zxvf ~/cpuruntime/oneapi-tbb-${ONEAPI_TBB_VERSION}-lin.tgz -C /opt/intel
66+
echo /opt/intel/oclcpuexp_${OCLCPUEXP_VERSION}/x64/libintelocl.so | sudo tee /etc/OpenCL/vendors/intel_expcpu.icd
67+
echo /opt/intel/oclcpuexp_${OCLCPUEXP_VERSION}/x64 | sudo tee /etc/ld.so.conf.d/libintelopenclexp.conf
68+
sudo ln -sf /opt/intel/oneapi-tbb-${ONEAPI_TBB_VERSION}/lib/intel64/gcc4.8/libtbb.so /opt/intel/oclcpuexp_${OCLCPUEXP_VERSION}/x64
69+
sudo ln -sf /opt/intel/oneapi-tbb-${ONEAPI_TBB_VERSION}/lib/intel64/gcc4.8/libtbbmalloc.so /opt/intel/oclcpuexp_${OCLCPUEXP_VERSION}/x64
70+
sudo ln -sf /opt/intel/oneapi-tbb-${ONEAPI_TBB_VERSION}/lib/intel64/gcc4.8/libtbb.so.12 /opt/intel/oclcpuexp_${OCLCPUEXP_VERSION}/x64
71+
sudo ln -sf /opt/intel/oneapi-tbb-${ONEAPI_TBB_VERSION}/lib/intel64/gcc4.8/libtbbmalloc.so.2 /opt/intel/oclcpuexp_${OCLCPUEXP_VERSION}/x64
72+
sudo ldconfig -f /etc/ld.so.conf.d/libintelopenclexp.conf
73+
sudo rm -r ~/cpuruntime
74+
75+
)"+string("\033[33m")+R"(.-----------------------------------------------------------------------------.
76+
| CPU Option 2: PoCL |
77+
'-----------------------------------------------------------------------------'
78+
sudo apt update && sudo apt upgrade -y
79+
sudo apt install -y g++ git make ocl-icd-libopencl1 ocl-icd-opencl-dev pocl-opencl-icd
80+
81+
)"+string("\033[0m");
82+
#endif // Linux
83+
1484
struct Device_Info {
1585
cl::Device cl_device; // OpenCL device
1686
cl::Context cl_context; // multiple devices in the same context can communicate buffers
@@ -120,7 +190,12 @@ inline vector<Device_Info> get_devices(const bool print_info=true) { // returns
120190
}
121191
}
122192
if((uint)cl_platforms.size()==0u||(uint)devices.size()==0u) {
123-
print_error("There are no OpenCL devices available. Make sure that the OpenCL 1.2 Runtime for your device is installed. For GPUs it comes by default with the graphics driver, for CPUs it has to be installed separately.");
193+
print_message("No OpenCL devices are available. Please install the drivers for your GPU(s) and/or the CPU Runtime for OpenCL. Instructions:", "Error", 12);
194+
print(driver_installation_instructions);
195+
#ifdef _WIN32
196+
wait();
197+
#endif // Windows
198+
exit(1);
124199
}
125200
if(print_info) {
126201
println("\r|----------------.------------------------------------------------------------|");

0 commit comments

Comments
 (0)