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

From LinuxReviews
Jump to navigationJump to search
Pcie-card-icon.svg

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

LuxMark-3.1-rocm-4.1.1.jpg
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[edit]

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?[edit]

Clspv.jpg
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 github.com/google/clspv. Then you need to run utils/fetch_sources.py from the clspv folder. You do need to fetch some dependencies with fetch_sources.py, it won't compile without them. You will, additionally, need to have git, CMake, Python 3 and a C++ compiler like gcc.

git clone https://github.com/google/clspv.git
cd clspv
utils/fetch_sources.py

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 file.cl -o file.spv.

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

Clvk-failure.jpg
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 github.com/kpet/clvk.git, checkout a huge pile of LLVM and compile it with cmake and make. The fetch_sources.py 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 https://github.com/kpet/clvk.git
cd clvk
git submodule update --init --recursive
./external/clspv/utils/fetch_sources.py --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
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[edit]

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[edit]

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 github.com/intel/compute-runtime/releases 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.

5.00
(one vote)


avatar

Chaekyung

8 months 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.
avatar

Anonymous (ce17d095c1)

6 months ago
Score 0

https://ninj...blender.html

OpenCL (Open Computing Language) is a framework for writing programs that execute across ... OpenCL is also considering Vulkan-like loader and layers and a 'Flexible Profile' ... Actual state is available in Mesamatrix. ... Open Compute) is an open source Linux project built on OpenCL 1.2 with language support for 2.0.
avatar

Anonymous (ce17d095c1)

6 months ago
Score 0

by Ryan Smith on April 27, 2020 6:00 AM EST ... Over the last 15 years, the evolution of GPU computing – and now ... OpenCL is in something of a precarious state on the PC desktop, its original home. ... The group has seen a lot of success with MoltenVK, their Vulkan-over-Metal layer, so an OpenCL ... Copyright © 2021.

https://ninj...blender.html
Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.