DEV Community

Cover image for Manage Legacy OpenCL Driver in a Distrobox Container!
Archer Allstars
Archer Allstars

Posted on

Manage Legacy OpenCL Driver in a Distrobox Container!

I would say OpenCL driver support is short-lived. For example, the current Intel Graphics Media Driver for VA-API provides the support way back to Intel Gen 5. On the other hand, Intel Graphics Compute Runtime for OpenCL provides the support for Intel Gen 12+. If you want OpenCL to work at all with older hardware, you will need a legacy driver.

The real issue, however, is the fact that you cannot have both intel-media-driver and intel-compute-runtime-legacy at the same time due to intel-gmmlib vs intel-gmmlib-legacy conflict. Meaning by that, you will have to choose between VA-API and OpenCL.

Fortunately, we have a container technology on Linux! We can simply have OpenCL apps inside one container, other VA-API apps can live inside another container or on the host. Therefore, you can have both VA-API and OpenCL working with legacy hardware.

There are some apps that uses OpenCL for its hardware acceleration, e.g. darktable, DaVinci Resolve. This walkthrough will make them (and you) happy 😆

👉️ Table of Contents

  1. Installing distrobox and podman
  2. Configure distrobox to use podman
  3. Create a Container
  4. Enable Optimized Packages
  5. Install yay to Manage AUR
  6. Install the Legacy Driver
  7. Zero Maintenance Your Container!

1. Installing distrobox and podman

The command will differ based on your specific package manager. Refer to your distro's docs. For example, on Arch based distros:

sudo pacman -S distrobox podman
Enter fullscreen mode Exit fullscreen mode

2. Configure distrobox to use podman

echo 'container_manager="podman"' > ~/.config/distrobox/distrobox.conf
Enter fullscreen mode Exit fullscreen mode

3. Create a Container

I use the official container image from CachyOS because it has x86-64-v3 and even x86-64-v4 repositories configured out of the box. Moreover, it doesn't have any issues with proprietary codecs, as all the codecs, free and proprietary ones, are available on the main Arch repositories.

The image uses the rolling-release model. Therefore, you don't have to recreate the container every time there's a new major release upgrade. You basically set it up once and can forget about it. Zero maintenance!

But most importantly, AUR is the easiest way to install the legacy OpenCL driver.

distrobox-create -i docker.io/cachyos/cachyos-v3:latest -n legacy-opencl-dbx -H ~/distrobox/legacy-opencl-dbx
Enter fullscreen mode Exit fullscreen mode

You can use docker.io/cachyos/cachyos-v4:latest instead if your CPU supports x86-64-v4.


4. Enable Optimized Packages

Update all the packages first:

sudo pacman -Syu
Enter fullscreen mode Exit fullscreen mode

Reinstall all the packages from CachyOS repos (this will replace x86-64 AKA x86-64-v1 packages with x86-64-v3 or x86-64-v4 ones):

sudo pacman -Qqn | sudo pacman -S -
Enter fullscreen mode Exit fullscreen mode

5. Install yay to Manage AUR

sudo pacman -S yay
Enter fullscreen mode Exit fullscreen mode

6. Install the Legacy Driver

yay -S intel-compute-runtime-legacy 
Enter fullscreen mode Exit fullscreen mode

⚠️ This will require a huge download, hence a fast internet connection, and a really long compile time. Fortunately, there won't be many updates for a legacy driver 😀

Lastly, install ocl-icd and clinfo

sudo pacman -S ocl-icd clinfo
Enter fullscreen mode Exit fullscreen mode

7. Zero Maintenance Your Container!

We will have the container update itself daily automatically! So, we can focus more on our works, not on the system.

On the host, we create a new service file:

nano ~/.config/systemd/user/dbx-upgrade.service
Enter fullscreen mode Exit fullscreen mode

Inside the service file:

[Unit]
Description=Upgrade all Distrobox containers
RequiresMountsFor=/run/user/1000/containers
StartLimitBurst=3
StartLimitIntervalSec=600

[Service]
Type=exec
ExecStart=sh -c "distrobox-upgrade --all && distrobox enter legacy-opencl-dbx -- yay -Syu --noconfirm"
Restart=on-failure
RestartSec=60
Enter fullscreen mode Exit fullscreen mode

💡 Since distrobox-upgrade --all doesn't manage yay, we chain the command to update AUR packages with yay.

As for the timer file:

nano ~/.config/systemd/user/dbx-upgrade.timer
Enter fullscreen mode Exit fullscreen mode

Inside the timer file:

[Unit]
Description=Start Distrobox containers upgrade service with some delay.

[Timer]
OnStartupSec=30
RandomizedDelaySec=15
Persistent=true

[Install]
WantedBy=timers.target
Enter fullscreen mode Exit fullscreen mode

Lastly, reload and enable the timer:

systemctl --user daemon-reload && systemctl --user enable dbx-upgrade.timer
Enter fullscreen mode Exit fullscreen mode

Now, you can put all the apps that requires OpenCL to work inside this container. For example, the easiest way to install DaVinci Resolve on Linux is by:

yay -S davinci-resolve
Enter fullscreen mode Exit fullscreen mode

Or for DaVinci Resolve Studio (the pro version):

yay -S davinci-resolve-studio
Enter fullscreen mode Exit fullscreen mode

⚠️ You don't run yay with sudo.

See more on AUR pages: davinci-resolve, davinci-resolve-studio.

Then, you can export it to the host, for example:

distrobox-export -b /opt/resolve/bin/resolve
Enter fullscreen mode Exit fullscreen mode

The bin will be saved at ~/.local/bin/resolve on the host. You can use Launcher Studio to create the app's icon. Just make sure the StartupWMClass value in your desktop file is corresponding to the app's window class name, of which can be checked by Alt+F2, then type in lg (looking glass). This works in GNOME.

DaVinci Resolve 20 on GNOME

DaVinci Resolve 20 shows a working OpenCL hardware acceleration with legacy Intel iGPU

😆 At first, I want to write about how to install DaVinci Resolve on Linux, considered there are like 100 different methods on the internet. However, the only true manageable method is by AUR in a distrobox container. It works across all distros, clean, and it's only one line of command for the installation without any other mods needed.

For darktable, it's equally easy:

sudo pacman -S darktable portmidi libcanberra
Enter fullscreen mode Exit fullscreen mode

Then:

distrobox-export -a darktable
Enter fullscreen mode Exit fullscreen mode

darktable shows a working OpenCL hardware acceleration with legacy Intel iGPU


I hope you all like this walkthrough. Thanks for reading 😁


Cover Photo by Aldrin Rachman Pradana on Unsplash

Top comments (0)