The State Of OpenCL To Vulkan Compute Layers On Linux In April 2021

From LinuxReviews
Jump to navigationJump to search

It is, in theory, possible to run OpenCL applications on Linux using any graphics driver capable of doing Vulkan Compute. We have examined the alternatives for doing so and found them to be technically interesting and practically useless. It may become possible to run Blender with OpenCL compute using Vulkan at some point in the far distant future. Don't expect to be able to do that today or next month.

written by 윤채경 (Yoon Chae-kyung)  2021-04-16 - last edited 2021-04-23. © CC BY

The LuxMark OpenCL benchmark using AMD ROCm 4.1.1.

OpenCL is an open API for doing GPU compute operations. It is far less used than Nvidia's proprietary CUDA API, but it can be used by a variety of both free and non-free software like Blender, LibreOffice and DaVinci Resolve.

OpenCL isn't all that easy to do on GNU/Linux, which is a shame. The OpenCL support you get out-of-the-box from the latest Mesa graphics library provides is dismal. You can get somewhat better OpenCL support if you have a moderately new Intel GPU by manually installing Intel's NEO OpenCL library (only for Broadwell+), and you can get somewhat decent OpenCL support if you have a AMD GPU by installing AMD's server-focused ROCm package. Those with a Nvidia GPU can install Nvidia's binary blob driver and get really good OpenCL 2.0 support.

clspv and clvk

Mesa has a neat translation layer called Zink that translates OpenGL graphics calls to Vulkan. There are currently two entirely different projects trying to do something similar with OpenCL.

UK-based Kévin Petit, who works for ARM, is leading a small project developing an OpenCL to Vulkan translation layer called clvk.

clvk relies on a Google-developed OpenCL to Vulkan compiler called clspv. Both projects are free software under the Apache License 2.0. Neither of these projects has had an actual release and both are in their early stages.

clspv, and therefore clvk too, is limited to OpenCL 1.2 support. Is is therefore impossible to use clvk with applications requiring OpenCL 2.0 support (most do, even LibreOffice calc needs OpenCL 2.0 support).

Can You Buy Now?

clspv compiled in Cool-Retro-Term.

You can attempt to get the clvk if you want to. We tried - and failed.

First, you need to acquire the clspv compiler. Start by cloning Then you need to run utils/ from the clspv folder. You do need to fetch some dependencies with, it won't compile without them. You will, additionally, need to have git, CMake, Python 3 and a C++ compiler like gcc.

git clone
cd clspv

Compiling clspv is straightforward, but it takes forever and your build/ folder will balloon to a whopping 16 GiB. You might as well talk a walk or watch some Rockit Girl music videos or do some work while it compiles.

mkdir build; cd build
cmake ..
make -j$(nproc)  # This takes hours
sudo make install

The /usr/local/bin/clspv binary you get by installing it with make install is a fat 1.5 GiB. It does not come with a manual page, so you have to run clspv --help to list all the options. There's a lot of them.

Acquiring a working clspv is not enough unless you are content with manually compiling OpenCL kernels into SPIR-V modules with a commands such as clspv -o file.spv.

You need clvk to use clspv with regular applications with OpenCL support. We did not get it to compile.

clvk failing to compile in Cool-Retro-Term.

You can try to get clvk working, your luck may be better than ours. You will have to clone the code from, checkout a huge pile of LLVM and compile it with cmake and make. The script will download a whopping 2.8 GiB of who knows what and store that in the external/ folder. It will take forever if you have a slow shoe-string Internet connection.

git clone
cd clvk
git submodule update --init --recursive
./external/clspv/utils/ --deps llvm  # This takes ages

Compiling it is supposed to be done by running:

mkdir -p build
cd build
cmake ..
cmake --build .

All we got out that was this sad compile failure. Building it with ninja instead, by replacing the two cmake commands with:

cmake -G Ninja

..produced the exact same result.

It does seem to be a tad too early to buy the clvk now since the current clvk git tree doesn't even compile.

Clover On Zink

Mike Blumenkrantz, who has experience from the Mesa Zink project and generally codes "super good", is working on a Clover On Zink driver for Mesa that would allow OpenCL programs to be executed using Vulkan compute using the standard graphics stack that comes with all the common GNU/Linux distributions. It is still in its very early stages.

"It is 100% of the way from being usable, as zink lacks wsi support and thus cannot initialize a clover context.

There's no sw init path for clover."

Mike Blumenkrantz, April 15th 2021

The Mesa Clover OpenCL to Vulkan compute translator is, in other words, far away from being a usable product. Clover itself isn't very good, and it is limited to OpenCL 1.2, so it is questionable how useful a OpenCL to Vulkan translation layer based on it would be when it comes to real-world applications. Clover can't even render the LuxMark benchmarks without a 20%+ error-rate.

The More Realistic Alternatives

It would be really cool to have a working magic OpenCL to Vulkan translator that could be used with software like Blender and Darktable. It seems like we are far, far away from anything like that. clvk and Clover On Zink are both far away from being usable and the perhaps worse part is that they won't be much good to anyone even if they do mature and become deployable technologies. Both are aiming for OpenCL 1.2 compliance. That's nice, you can run things like the LuxMark benchmark using OpenCL 1.2. Most applications require OpenCL 2.0, you can't even use OpenCL acceleration in LibreOffice spreadsheets with OpenCL 1.2. That leaves GNU/Linux users where they are now: Use the rather poor OpenCL 1.2 "Clover" implementation that comes with the Mesa graphics library included in all GNU/Linux distributions or download and install a vendor-specific OpenCL package.

The best, but not great, options you have are:

  • NEO (MIT licensed) from if you have a Intel GPU. Intel is only providing packages for Ubuntu, so you will have to convert them with alien or another package conversion tool to use it on other distributions. It will only work with Broadwell and newer.
  • Radeon Open Compute (GPL/Apache/MIT) if you have a AMD GPU that actually works with it. It can't be too old (older than Polaris) and it can't be too new (RX 5000/RX 6000). Some OpenCL applications will work fine with ROCm, others won't. Application support is hit-and-miss, which is quite sad.
  • The proprietary Nvidia driver if you have a Nvidia card. It works great if you have a Nvidia GPU and you are willing to install proprietary software. It is the overall best OpenCL implementation you can have on Linux.

It is a shame that a firmware-locked Nvidia GPU with the proprietary binary blob Nvidia driver really is the best option if you want to use the OpenCL API on GNU/Linux, but that's the current state of affairs. And a working OpenCL to Vulkan solution is far, far away.

(one vote)



11 days ago
Score 0++

I have not installed it, and I am not about to agree to any https://www....gpu-pro-eula where it says things like:

"The Software, including all Intellectual Property Rights therein, is and remains the sole and exclusive property of AMD or its licensors, and You shall have no right, title or interest therein except as expressly set forth in this Agreement."

I guess I could do it if AMD paid me to do a paid review/article that is very clearly marked "Paid for by AMD", I mean paid work is paid work. But I ain't about to voluntarily install some binary blob proprietary software to perhaps, perhaps not, get better OpenCL support.
Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.