AMDGPU-PRO OpenCL on Fedora and Debian

Since the open source AMD GPU Linux drivers are now quite good I swapped my GTX 970 from my old machine for a Vega 56 in the new Threadripper build. Unforuntely the kernel and mesa drivers do not support OpenCL, I tried ROCm for a while but only one build of version 1.2 would work with Fedora 30 and it would sometime casuse kernel panic when in use with Darktable. Not to mention some strange image artifacts when using certain modules.

AMD does have a proprietary closed source driver for Linux but it only supports a very small set of distributions and their checks on the installer are very strict. So there's no just running the installer script or installing the RPMs or DEBs. Plus there's the fact that I just need the OpenCL portions of the driver and not the display portions. You can continue to use the open source kernel drivers for display, OpenGL and Vulkan which is preferable as they outperform the proprietary AMD drivers. Just to reiterate: this is not necessary for 4D acceleration and gaming. The AMDGPU-PRO proprietary drivers are needed for OpenCL and compute only. If you're just looking to play games or run Steam the open source mesa implementation shipping in up-to-date distributions these days is more than good enough.

Fortunately there are just a few packages needed from the proprietary AMD driver for OpenCL to work and it is completely decoupled form the display driver. Start off by downloading the admgpu-pro package for the latest version of Ubuntu. This will work for Debian or Fedora as you're just going to be extracting the .deb packages anyway. You can do the same thing with RPMs and rpm2cpio but it's just a bit more troublesome. dpkg is available on Fedora anyway so it's no big deal.

At any rate you'll need the following packages:

libdrm-amdgpu-amdgpu
libdrm-amdgpu-common
opencl-amdgpu-pro-icd
opencl-orca-amdgpu-pro-icd
libopencl1-amdgpu-pro

The version numbers will vary depending on when you read this and download your package. First extract the tarball:

tar vxf amdgpu-pro-19.20-812932-ubuntu-18.04.tar.xz

Move the DEB packages out that you to a seperate directory

dpkg-deb -x opencllibdrm-amdgpu-amdgpu1_2.4.97-812932_amd64.deb opencl_root
dpkg-deb -x libdrm-amdgpu-common_1.0.0-812932_all.deb opencl_root
dpkg-deb -x opencl-amdgpu-pro-icd_19.20-812932_amd64.deb opencl_root
dpkg-deb -x opencl-orca-amdgpu-pro-icd_19.20-812932_amd64.deb opencl_root
dpkg-deb -x libopencl1-amdgpu-pro_19.20-812932_amd64.deb opencl_root

Change directory to where you extracted those files:

cd opencl_root

Copy the necessary files into place:

sudo cp etc/OpenCL/vendors/* /etc/OpenCL/vendors/
sudo cp -R opt/amdgpu* /opt/.

Now the dynamic linker needs to be updated so it knows where the libraries are located. In /etc/ld.so.conf.d/ create two files and put the following lines in them:

/etc/ld.so.conf.d/amdgpu-pro.conf:

/opt/amdgpu-pro/lib/x86_64-linux-gnu/

/etc/ld.so.conf.d/amdgpu.conf:

/opt/amdgpu/lib/x86_64-linux-gnu/

Then run ldconfig:

sudo ldconfig

Test and see if it works with clinfo -l, if it's working you'll see something like this:

clinfo -l 
...
Platform #0: AMD Accelerated Parallel Processing
 `-- Device #0: gfx900
Platform #1: Clover
 `-- Device #0: Radeon RX Vega (VEGA10, DRM 3.30.0, 5.1.20-300.fc30.x86_64, LLVM 8.0.0)
 ...

Darktable should also allow OpenCL now, you may need to delete the pre-compliled OpenCL kernels in ~/.caches/darktable if you were using ROCm before.

Darktable OpenCL

While this isn't the perfect option in terms of free software it's still preferable to nVidia's driver in my opinion. Hopefully ROCm will become more stable and will be packaged by Debian and Fedora in the near future, which seems likely given AMD has blessed ROCm as their future compute solution.