For detailed information gained with my old nvidia setup, see my blogpost about darktable and opencl with nvidia.

GPU support via opencl

Having a new PC to edit my photos, I have to add this post to show you how to enable the opencl support using AMD GPUs. There have to be some different packages be installed.

First my new hardware specs:

Type Component
CPU core i9-9900k
RAM 32GB
Graphics Sapphire RX 580 Nitro Plus SE (8GB))
Disk Samsung SSD 970 Pro M.2

Packages to install

To make opencl available you have to install some packages. Most are part of the official repositories, but not all of them.

These two packages are required to make amdgpu and opencl with mesa working in general.

  • opencl-mesa
  • xf86-video-amdgpu

Unfortunately this is not enough as there is the non mesa libOpenCL missing. To fix that you have to install a little part of the amd pro user space driver. The package is intended to work with the free amdgpu stack and does not require you to install the whole closed amd parts. The second package is to gain some insights of the gpu state.

**Warning: ** These packages are located in the AUR. Use at own risk. You have been warned!

  • opencl-amd (AUR)
  • rocm-smi (AUR)

Validate your setup

To check if darktable activated the opencl stack or why it does not work, you can run darktable using darktable -d opencl to get detailed information about the opencl part. My first try showed me the problem.

darktable -d opencl
0.050487 [opencl_init] opencl related configuration options:
0.050492 [opencl_init] 
0.050494 [opencl_init] opencl: 1
0.050495 [opencl_init] opencl_library: ''
0.050496 [opencl_init] opencl_memory_requirement: 768
0.050497 [opencl_init] opencl_memory_headroom: 1000
0.050498 [opencl_init] opencl_device_priority: '*/!0,*/*/*'
0.050500 [opencl_init] opencl_mandatory_timeout: 200
0.050501 [opencl_init] opencl_size_roundup: 16
0.050502 [opencl_init] opencl_async_pixelpipe: 0
0.050503 [opencl_init] opencl_synch_cache: 0
0.050504 [opencl_init] opencl_number_event_handles: 25
0.050505 [opencl_init] opencl_micro_nap: 1000
0.050506 [opencl_init] opencl_use_pinned_memory: 0
0.050507 [opencl_init] opencl_use_cpu_devices: 0
0.050508 [opencl_init] opencl_avoid_atomics: 0
0.050509 [opencl_init] 
0.050552 [opencl_init] could not find opencl runtime library 'libOpenCL'
0.050575 [opencl_init] could not find opencl runtime library 'libOpenCL.so'
0.050595 [opencl_init] could not find opencl runtime library 'libOpenCL.so.1'
0.050597 [opencl_init] no working opencl library found. Continue with opencl disabled
0.050598 [opencl_init] FINALLY: opencl is NOT AVAILABLE on this system.
0.050599 [opencl_init] initial status of opencl enabled flag is OFF.

After installing opencl-amd, the opencl stack started working and I got some more information about my system capabilities.

darktable -d opencl
0.047022 [opencl_init] opencl related configuration options:
0.047028 [opencl_init] 
0.047029 [opencl_init] opencl: 1
0.047030 [opencl_init] opencl_library: ''
0.047031 [opencl_init] opencl_memory_requirement: 768
0.047033 [opencl_init] opencl_memory_headroom: 1000
0.047034 [opencl_init] opencl_device_priority: '*/!0,*/*/*'
0.047035 [opencl_init] opencl_mandatory_timeout: 200
0.047037 [opencl_init] opencl_size_roundup: 16
0.047037 [opencl_init] opencl_async_pixelpipe: 0
0.047038 [opencl_init] opencl_synch_cache: 0
0.047040 [opencl_init] opencl_number_event_handles: 25
0.047041 [opencl_init] opencl_micro_nap: 1000
0.047042 [opencl_init] opencl_use_pinned_memory: 0
0.047043 [opencl_init] opencl_use_cpu_devices: 0
0.047044 [opencl_init] opencl_avoid_atomics: 0
0.047045 [opencl_init] 
0.047142 [opencl_init] found opencl runtime library 'libOpenCL'
0.047153 [opencl_init] opencl library 'libOpenCL' found on your system and loaded
0.176574 [opencl_init] found 2 platforms
0.176584 [opencl_init] found 2 devices
0.176593 [opencl_init] device 0 `Ellesmere' supports image sizes of 16384 x 16384
0.176594 [opencl_init] device 0 `Ellesmere' allows GPU memory allocations of up to 4048MB
[opencl_init] device 0: Ellesmere 
     GLOBAL_MEM_SIZE:          6844MB
     MAX_WORK_GROUP_SIZE:      256
     MAX_WORK_ITEM_DIMENSIONS: 3
     MAX_WORK_ITEM_SIZES:      [ 1024 1024 1024 ]
     DRIVER_VERSION:           2766.4
     DEVICE_VERSION:           OpenCL 1.2 AMD-APP (2766.4)
0.243778 [opencl_init] options for OpenCL compiler: -cl-fast-relaxed-math  -DAMD=1 -I"/usr/share/darktable/kernels"
0.246630 [opencl_init] compiling program `demosaic_ppg.cl' ..
0.246820 [opencl_fopen_stat] could not open file `/home/philipp/.cache/darktable/cached_kernels_for_Ellesmere/demosaic_ppg.cl.bin'!
0.246826 [opencl_load_program] could not load cached binary program, trying to compile source
0.246844 [opencl_load_program] successfully loaded program from `/usr/share/darktable/kernels/demosaic_ppg.cl'
0.389301 [opencl_build_program] successfully built program
0.389309 [opencl_build_program] BUILD STATUS: 0
0.389311 BUILD LOG: