This is a simple matrix multiplication benchmark, comparing SIMD execution on a single GPU compute unit with SISD execution on a single CPU thread.
The benchmark utilizes the java library JOCL to execute opencl kernels from within java applications.
In order to run the benchmark, you require:
- conventional gcc based linux distribution like Ubuntu
- opencl runtime installation as described here Official OpenCL-Guide
(essentially just
sudo apt install opencl-headers ocl-icd-opencl-dev -y) - lts jdk version (e.g
openjdk-21) - supported OpenCl device with drivers supporting OpenCl (e.g. RTX 2070 Super + linux game ready drivers)
To run the benchmark, just use ./gradlew :run
You should see something like this:
Platform 0:
Device 0: NVIDIA GeForce RTX 2070 SUPER (GPU)
SIMD parallel matrix multiplication on GPU took 0 min, 1 s, 235 ms
SISD sequential matrix multiplication on CPU took 0 min, 56 s, 243 ms
Here, matrix multiplication was accelerated about 50x on the GPU using just one out of 48 compute units on the RTX 2070 Super. OpenCL is potentially capable of using all of them in parallel, but this requires a more complex OpenCl command.
The benchmark application is not meant to produce output, but Application.java contains a smaller example that produces matrices on the standard output.
The libJOCL_<version>-<platform>.so file contained in this repo is already build from the JOCL submodules.
Building the native library is document in the JOCL Readme.md
If you have access to the nix package manager,
feel free to use shell.nix as dev environment.
It contains all required dependencies
to build the libJOCL_<version>-<platform>.so file
from the JOCL submodules.
However I did not achieve running the benchmark successfully on nixos.
The following problem occurs, when opencl was not properly installed natively or if your system does not have c libraries at conventional places.
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not initialize native OpenCL library. Implementation library could not be loaded
at org.jocl.LibInitializer.initNativeLibrary(LibInitializer.java:74)
at org.jocl.CL.loadNativeLibrary(CL.java:66)
at org.jocl.CL.<clinit>(CL.java:51)
at com.example.jocl.OpenCLPlatformUtil.GetDevices(OpenCLPlatformUtil.java:22)
at com.example.jocl.Benchmark.main(Benchmark.java:17)
Could not load libOpenCL.so, error libOpenCL.so: cannot open shared object file: No such file or directory