OpenCL on Fedora 40 with ROCm (AMD) not working

The problem: When running darktable-cltest -d verbose, I see that Darktable has trouble compiling demosaic_ppg.cl because it can’t find opencl-c-base.h. This file is present on the system, but at another location.

Context: I’m using Fedora 40 and have installed darktable with DNF. I’m using a Lenovo E495 with AMD Radeon Vega 8 GPU (device name gfx902:xnack+). Fedora comes pre-installed with ROCm 6, and OpenCL works. I have dedicated 2GB memory to the GPU in BIOS. Some more infromation:

Output of clinfo

Summary
Number of platforms                               1
  Platform Name                                   AMD Accelerated Parallel Processing
  Platform Vendor                                 Advanced Micro Devices, Inc.
  Platform Version                                OpenCL 2.1 AMD-APP (3602.0)
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             cl_khr_icd cl_amd_event_callback 
  Platform Extensions function suffix             AMD
  Platform Host timer resolution                  1ns

  Platform Name                                   AMD Accelerated Parallel Processing
Number of devices                                 1
  Device Name                                     gfx902:xnack+
  Device Vendor                                   Advanced Micro Devices, Inc.
  Device Vendor ID                                0x1002
  Device Version                                  OpenCL 2.0 
  Driver Version                                  3602.0 (HSA1.1,LC)
  Device OpenCL C Version                         OpenCL C 2.0 
  Device Type                                     GPU
  Device Board Name (AMD)                         AMD Radeon Vega 8 Graphics
  Device PCI-e ID (AMD)                           0x15d8
  Device Topology (AMD)                           PCI-E, 0000:05:00.0
  Device Profile                                  FULL_PROFILE
  Device Available                                Yes
  Compiler Available                              Yes
  Linker Available                                Yes
  Max compute units                               8
  SIMD per compute unit (AMD)                     4
  SIMD width (AMD)                                16
  SIMD instruction width (AMD)                    1
  Max clock frequency                             1200MHz
  Graphics IP (AMD)                               9.0
  Device Partition                                (core)
    Max number of sub-devices                     8
    Supported partition types                     None
    Supported affinity domains                    (n/a)
  Max work item dimensions                        3
  Max work item sizes                             1024x1024x1024
  Max work group size                             256
  Preferred work group size (AMD)                 256
  Max work group size (AMD)                       1024
  Preferred work group size multiple (kernel)     64
  Wavefront width (AMD)                           64
  Preferred / native vector sizes                 
    char                                                 4 / 4       
    short                                                2 / 2       
    int                                                  1 / 1       
    long                                                 1 / 1       
    half                                                 1 / 1        (cl_khr_fp16)
    float                                                1 / 1       
    double                                               1 / 1        (cl_khr_fp64)
  Half-precision Floating-point support           (cl_khr_fp16)
    Denormals                                     Yes
    Infinity and NANs                             Yes
    Round to nearest                              Yes
    Round to zero                                 Yes
    Round to infinity                             Yes
    IEEE754-2008 fused multiply-add               Yes
    Support is emulated in software               No
  Single-precision Floating-point support         (core)
    Denormals                                     Yes
    Infinity and NANs                             Yes
    Round to nearest                              Yes
    Round to zero                                 Yes
    Round to infinity                             Yes
    IEEE754-2008 fused multiply-add               Yes
    Support is emulated in software               No
    Correctly-rounded divide and sqrt operations  Yes
  Double-precision Floating-point support         (cl_khr_fp64)
    Denormals                                     Yes
    Infinity and NANs                             Yes
    Round to nearest                              Yes
    Round to zero                                 Yes
    Round to infinity                             Yes
    IEEE754-2008 fused multiply-add               Yes
    Support is emulated in software               No
  Address bits                                    64, Little-Endian
  Global memory size                              2147483648 (2GiB)
  Global free memory (AMD)                        1927168 (1.838GiB) 1927168 (1.838GiB)
  Global memory channels (AMD)                    4
  Global memory banks per channel (AMD)           4
  Global memory bank width (AMD)                  256 bytes
  Error Correction support                        No
  Max memory allocation                           1825361096 (1.7GiB)
  Unified memory for Host and Device              No
  Shared Virtual Memory (SVM) capabilities        (core)
    Coarse-grained buffer sharing                 Yes
    Fine-grained buffer sharing                   Yes
    Fine-grained system sharing                   No
    Atomics                                       No
  Minimum alignment for any data type             128 bytes
  Alignment of base address                       1024 bits (128 bytes)
  Preferred alignment for atomics                 
    SVM                                           0 bytes
    Global                                        0 bytes
    Local                                         0 bytes
  Max size for global variable                    1825361096 (1.7GiB)
  Preferred total size of global vars             2147483648 (2GiB)
  Global Memory cache type                        Read/Write
  Global Memory cache size                        16384 (16KiB)
  Global Memory cache line size                   64 bytes
  Image support                                   Yes
    Max number of samplers per kernel             16
    Max size for 1D images from buffer            134217728 pixels
    Max 1D or 2D image array size                 8192 images
    Base address alignment for 2D image buffers   256 bytes
    Pitch alignment for 2D image buffers          256 pixels
    Max 2D image size                             16384x16384 pixels
    Max 3D image size                             16384x16384x8192 pixels
    Max number of read image args                 128
    Max number of write image args                8
    Max number of read/write image args           64
  Max number of pipe args                         16
  Max active pipe reservations                    16
  Max pipe packet size                            1825361096 (1.7GiB)
  Local memory type                               Local
  Local memory size                               65536 (64KiB)
  Local memory size per CU (AMD)                  65536 (64KiB)
  Local memory banks (AMD)                        32
  Max number of constant args                     8
  Max constant buffer size                        1825361096 (1.7GiB)
  Preferred constant buffer size (AMD)            16384 (16KiB)
  Max size of kernel argument                     1024
  Queue properties (on host)                      
    Out-of-order execution                        No
    Profiling                                     Yes
  Queue properties (on device)                    
    Out-of-order execution                        Yes
    Profiling                                     Yes
    Preferred size                                262144 (256KiB)
    Max size                                      8388608 (8MiB)
  Max queues on device                            1
  Max events on device                            1024
  Prefer user sync for interop                    Yes
  Number of P2P devices (AMD)                     0
  Profiling timer resolution                      1ns
  Profiling timer offset since Epoch (AMD)        0ns (Thu Jan  1 01:00:00 1970)
  Execution capabilities                          
    Run OpenCL kernels                            Yes
    Run native kernels                            No
    Thread trace supported (AMD)                  No
    Number of async queues (AMD)                  8
    Max real-time compute queues (AMD)            8
    Max real-time compute units (AMD)             8
  printf() buffer size                            4194304 (4MiB)
  Built-in kernels                                (n/a)
  Device Extensions                               cl_khr_fp64 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_3d_image_writes cl_khr_byte_addressable_store cl_khr_fp16 cl_khr_gl_sharing cl_amd_device_attribute_query cl_amd_media_ops cl_amd_media_ops2 cl_khr_image2d_from_buffer cl_khr_subgroups cl_khr_depth_images cl_amd_copy_buffer_p2p cl_amd_assembly_program 

NULL platform behavior
  clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...)  AMD Accelerated Parallel Processing
  clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...)   Success [AMD]
  clCreateContext(NULL, ...) [default]            Success [AMD]
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT)  Success (1)
    Platform Name                                 AMD Accelerated Parallel Processing
    Device Name                                   gfx902:xnack+
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU)  Success (1)
    Platform Name                                 AMD Accelerated Parallel Processing
    Device Name                                   gfx902:xnack+
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL)  Success (1)
    Platform Name                                 AMD Accelerated Parallel Processing
    Device Name                                   gfx902:xnack+

ICD loader properties
  ICD loader Name                                 OpenCL ICD Loader
  ICD loader Vendor                               OCL Icd free software
  ICD loader Version                              2.3.2
  ICD loader Profile                              OpenCL 3.0

Output of rocminfo

Summary
ROCk module is loaded
=====================    
HSA System Attributes    
=====================    
Runtime Version:         1.1
System Timestamp Freq.:  1000.000000MHz
Sig. Max Wait Duration:  18446744073709551615 (0xFFFFFFFFFFFFFFFF) (timestamp count)
Machine Model:           LARGE                              
System Endianness:       LITTLE                             
Mwaitx:                  DISABLED
DMAbuf Support:          YES

==========               
HSA Agents               
==========               
*******                  
Agent 1                  
*******                  
  Name:                    AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx
  Uuid:                    CPU-XX                             
  Marketing Name:          AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx
  Vendor Name:             CPU                                
  Feature:                 None specified                     
  Profile:                 FULL_PROFILE                       
  Float Round Mode:        NEAR                               
  Max Queue Number:        0(0x0)                             
  Queue Min Size:          0(0x0)                             
  Queue Max Size:          0(0x0)                             
  Queue Type:              MULTI                              
  Node:                    0                                  
  Device Type:             CPU                                
  Cache Info:              
    L1:                      32768(0x8000) KB                   
  Chip ID:                 0(0x0)                             
  ASIC Revision:           0(0x0)                             
  Cacheline Size:          64(0x40)                           
  Max Clock Freq. (MHz):   2100                               
  BDFID:                   0                                  
  Internal Node ID:        0                                  
  Compute Unit:            8                                  
  SIMDs per CU:            0                                  
  Shader Engines:          0                                  
  Shader Arrs. per Eng.:   0                                  
  WatchPts on Addr. Ranges:1                                  
  Features:                None
  Pool Info:               
    Pool 1                   
      Segment:                 GLOBAL; FLAGS: FINE GRAINED        
      Size:                    30677972(0x1d41bd4) KB             
      Allocatable:             TRUE                               
      Alloc Granule:           4KB                                
      Alloc Alignment:         4KB                                
      Accessible by all:       TRUE                               
    Pool 2                   
      Segment:                 GLOBAL; FLAGS: KERNARG, FINE GRAINED
      Size:                    30677972(0x1d41bd4) KB             
      Allocatable:             TRUE                               
      Alloc Granule:           4KB                                
      Alloc Alignment:         4KB                                
      Accessible by all:       TRUE                               
    Pool 3                   
      Segment:                 GLOBAL; FLAGS: COARSE GRAINED      
      Size:                    30677972(0x1d41bd4) KB             
      Allocatable:             TRUE                               
      Alloc Granule:           4KB                                
      Alloc Alignment:         4KB                                
      Accessible by all:       TRUE                               
  ISA Info:                
*******                  
Agent 2                  
*******                  
  Name:                    gfx902                             
  Uuid:                    GPU-XX                             
  Marketing Name:          AMD Radeon Vega 8 Graphics         
  Vendor Name:             AMD                                
  Feature:                 KERNEL_DISPATCH                    
  Profile:                 BASE_PROFILE                       
  Float Round Mode:        NEAR                               
  Max Queue Number:        128(0x80)                          
  Queue Min Size:          64(0x40)                           
  Queue Max Size:          131072(0x20000)                    
  Queue Type:              MULTI                              
  Node:                    1                                  
  Device Type:             GPU                                
  Cache Info:              
    L1:                      16(0x10) KB                        
    L2:                      1024(0x400) KB                     
  Chip ID:                 5592(0x15d8)                       
  ASIC Revision:           1(0x1)                             
  Cacheline Size:          64(0x40)                           
  Max Clock Freq. (MHz):   1200                               
  BDFID:                   1280                               
  Internal Node ID:        1                                  
  Compute Unit:            8                                  
  SIMDs per CU:            4                                  
  Shader Engines:          1                                  
  Shader Arrs. per Eng.:   1                                  
  WatchPts on Addr. Ranges:4                                  
  Coherent Host Access:    FALSE                              
  Features:                KERNEL_DISPATCH 
  Fast F16 Operation:      TRUE                               
  Wavefront Size:          64(0x40)                           
  Workgroup Max Size:      1024(0x400)                        
  Workgroup Max Size per Dimension:
    x                        1024(0x400)                        
    y                        1024(0x400)                        
    z                        1024(0x400)                        
  Max Waves Per CU:        40(0x28)                           
  Max Work-item Per CU:    2560(0xa00)                        
  Grid Max Size:           4294967295(0xffffffff)             
  Grid Max Size per Dimension:
    x                        4294967295(0xffffffff)             
    y                        4294967295(0xffffffff)             
    z                        4294967295(0xffffffff)             
  Max fbarriers/Workgrp:   32                                 
  Packet Processor uCode:: 471                                
  SDMA engine uCode::      169                                
  IOMMU Support::          None                               
  Pool Info:               
    Pool 1                   
      Segment:                 GLOBAL; FLAGS: COARSE GRAINED      
      Size:                    2097152(0x200000) KB               
      Allocatable:             TRUE                               
      Alloc Granule:           4KB                                
      Alloc Alignment:         4KB                                
      Accessible by all:       FALSE                              
    Pool 2                   
      Segment:                 GLOBAL; FLAGS: EXTENDED FINE GRAINED
      Size:                    2097152(0x200000) KB               
      Allocatable:             TRUE                               
      Alloc Granule:           4KB                                
      Alloc Alignment:         4KB                                
      Accessible by all:       FALSE                              
    Pool 3                   
      Segment:                 GROUP                              
      Size:                    64(0x40) KB                        
      Allocatable:             FALSE                              
      Alloc Granule:           0KB                                
      Alloc Alignment:         0KB                                
      Accessible by all:       FALSE                              
  ISA Info:                
    ISA 1                    
      Name:                    amdgcn-amd-amdhsa--gfx902:xnack+   
      Machine Models:          HSA_MACHINE_MODEL_LARGE            
      Profiles:                HSA_PROFILE_BASE                   
      Default Rounding Mode:   NEAR                               
      Default Rounding Mode:   NEAR                               
      Fast f16:                TRUE                               
      Workgroup Max Size:      1024(0x400)                        
      Workgroup Max Size per Dimension:
        x                        1024(0x400)                        
        y                        1024(0x400)                        
        z                        1024(0x400)                        
      Grid Max Size:           4294967295(0xffffffff)             
      Grid Max Size per Dimension:
        x                        4294967295(0xffffffff)             
        y                        4294967295(0xffffffff)             
        z                        4294967295(0xffffffff)             
      FBarrier Max Size:       32                                 
*** Done ***

Output of darktable-cltest -d verbose

Summary
darktable 4.6.1
Copyright (C) 2012-2024 Johannes Hanika and other contributors.

Compile options:
  Bit depth              -> 64 bit
  Debug                  -> DISABLED
  SSE2 optimizations     -> ENABLED
  OpenMP                 -> ENABLED
  OpenCL                 -> ENABLED
  Lua                    -> ENABLED  - API version 9.2.0
  Colord                 -> ENABLED
  gPhoto2                -> ENABLED
  GMIC                   -> ENABLED  - Compressed LUTs are supported
  GraphicsMagick         -> ENABLED
  ImageMagick            -> DISABLED
  libavif                -> ENABLED
  libheif                -> ENABLED
  libjxl                 -> ENABLED
  OpenJPEG               -> ENABLED
  OpenEXR                -> ENABLED
  WebP                   -> ENABLED

See https://www.darktable.org/resources/ for detailed documentation.
See https://github.com/darktable-org/darktable/issues/new/choose to report bugs.

     0,0274 [dt_get_sysresource_level] switched to 1 as `default'
     0,0274   total mem:       29958MB
     0,0274   mipmap cache:    3744MB
     0,0274   available mem:   14979MB
     0,0274   singlebuff:      234MB
     0.2173 [opencl_init] opencl disabled via darktable preferences
     0.2175 [dt_dlopencl_init] could not find default opencl runtime library 'libOpenCL'
     0.2175 [dt_dlopencl_init] could not find default opencl runtime library 'libOpenCL.so'
     0.2175 [dt_dlopencl_init] found default opencl runtime library 'libOpenCL.so.1'
     0.2176 [opencl_init] opencl library 'libOpenCL.so.1' found on your system and loaded, preference 'default path'
     0.2824 [opencl_init] found 1 platform
[opencl_init] found 1 device

[dt_opencl_device_init]
     0.2824 [dt_opencl_write_device_config] writing data '0 250 0 16 16 128 0 0 0.000 0.000 0.250' for 'cldevice_v5_amdacceleratedparallelprocessinggfx902xnack'
     0.2825 [dt_opencl_write_device_config] writing data '600' for 'cldevice_v5_amdacceleratedparallelprocessinggfx902xnack_id0'
   DEVICE:                   0: 'gfx902:xnack+'
   PLATFORM, VENDOR & ID:    AMD Accelerated Parallel Processing, Advanced Micro Devices, Inc., ID=4098
   CANONICAL NAME:           amdacceleratedparallelprocessinggfx902xnack
   DRIVER VERSION:           3602.0 (HSA1.1,LC)
   DEVICE VERSION:           OpenCL 2.0 
   DEVICE_TYPE:              GPU, dedicated mem
   GLOBAL MEM SIZE:          2048 MB
   MAX MEM ALLOC:            1741 MB
   MAX IMAGE SIZE:           16384 x 16384
   MAX WORK GROUP SIZE:      256
   MAX WORK ITEM DIMENSIONS: 3
   MAX WORK ITEM SIZES:      [ 1024 1024 1024 ]
   ASYNC PIXELPIPE:          NO
   PINNED MEMORY TRANSFER:   NO
   AVOID ATOMICS:            NO
   MICRO NAP:                250
   ROUNDUP WIDTH & HEIGHT    16x16
   CHECK EVENT HANDLES:      128
   TILING ADVANTAGE:         0.000
   DEFAULT DEVICE:           NO
   KERNEL BUILD DIRECTORY:   /usr/share/darktable/kernels
   KERNEL DIRECTORY:         /home/ruben/.cache/darktable/cached_v3_kernels_for_AMDAcceleratedParallelProcessinggfx902xnack_36020HSA11LC
   CL COMPILER OPTION:       -cl-fast-relaxed-math
   CL COMPILER COMMAND:      -w -cl-fast-relaxed-math  -DAMD=1 -I"/usr/share/darktable/kernels"
     0.6095 [dt_opencl_device_init] testing program `demosaic_ppg.cl' ..
     0.6097 [opencl_fopen_stat] could not open file `/home/ruben/.cache/darktable/cached_v3_kernels_for_AMDAcceleratedParallelProcessinggfx902xnack_36020HSA11LC/demosaic_ppg.cl.bin'!
     0.6097 [opencl_load_program] could not load cached binary program, trying to compile source
     0.6098 [opencl_load_program] successfully loaded program from '/usr/share/darktable/kernels/demosaic_ppg.cl' MD5: '199039a5cc99dbce630b32a1345f6d70'
     0.6492 [opencl_build_program] could not build program: CL_BUILD_PROGRAM_FAILURE
     0.6493 [opencl_build_program] BUILD STATUS: -2
     0.6493 BUILD LOG:
     0.6493 fatal error: malformed or corrupted AST file: 'could not find file '/usr/lib64/llvm17/bin/../../../lib/clang/17/include/opencl-c-base.h' referenced by AST file '/tmp/comgr-00ca7b/include/opencl1.2-c.pch''
1 error generated.
Error: Failed to compile source (from CL or HIP source to LLVM IR).

     0.6493 [dt_opencl_device_init] failed to compile program `demosaic_ppg.cl'!
     0.6493 [dt_opencl_write_device_config] writing data '0 250 0 16 16 128 0 0 0.000 0.000 0.250' for 'cldevice_v5_amdacceleratedparallelprocessinggfx902xnack'
     0.6493 [dt_opencl_write_device_config] writing data '600' for 'cldevice_v5_amdacceleratedparallelprocessinggfx902xnack_id0'
[opencl_init] no suitable devices found.
     0.6493 [opencl_init] FINALLY: opencl is NOT AVAILABLE and NOT ENABLED.

The relevant error is the following:

fatal error: malformed or corrupted AST file: 
'could not find file '/usr/lib64/llvm17/bin/../../../lib/clang/17/include/opencl-c-base.h' referenced by AST file '/tmp/comgr-00ca7b/include/opencl1.2-c.pch''
Error: Failed to compile source (from CL or HIP source to LLVM IR).

However, I do have the opencl-c-base.h, but it is located at /usr/lib/clang/18/include/

Not sure where to go from here. If I knew the whole path that is truncated in the error message, I could try to symlink the directory, but not sure if it would help.

Are you absolutely sure you’re using the latest darktable-4.6.1-5 package from updates?

But even w/ that one, there still seems to be ROCm specific problems present:
https://bugzilla.redhat.com/show_bug.cgi?id=2270556
https://bugzilla.redhat.com/show_bug.cgi?id=2276697

Yes, DNF confirms it is the 4.6.1-5 release. The two bug reports you found seems unrelated to the problem I have, but I can’t be sure. Darktable start fine, but does not support OpenCL without the modules that it tries to compile at startup. It seems like a trivial “looking for files in the wrong place” situation to me, but I might be wrong.

4.6.1-5 is built against clang-18, so it would have no business referencing clang-17 folders. You might have to clear the opencl kernel cache or something… From the linked build log:

-- Found LLVM 18.1.1
-- Found clang compiler - /usr/bin/clang-18
-- Found clang opencl-c.h header in /usr/lib/clang/18/include
-- Will be able to test-compile OpenCL programs. Nice.

and

[ 25%] Test-compiling OpenCL program demosaic_ppg.cl
cd /builddir/build/BUILD/darktable-4.6.1/redhat-linux-build/share/darktable/kernels && /usr/bin/clang-18 -cc1 -cl-std=CL1.2 -isystem /usr/lib/clang/18/include -finclude-default-header -I/builddir/build/BUILD/darktable-4.6.1/data/kernels /builddir/build/BUILD/darktable-4.6.1/data/kernels/demosaic_ppg.cl
[ 25%] Built target opencl-program-demosaic_ppg.cl

They are indeed unrelated, but even with your hurdle cleared I suspect you might run into them next.

I’m noticing the same issue with rocm-opencl acceleration not working with darktable on Fedora 40. It seemed to work during the beta phase, but isn’t working now. I guess something changed recently?

As a fallback, I’ve enabled rusticl for the time being. This is from Mesa and it also works on AMD cards (7900 XTX here) and is now working fine in darktable, according to How to enable RusticCL with darktable 4.6? (opencl fails to init) (near the bottom of that thread) and my own quick testing this evening.

Summary: You basically need:

  1. install mesa-libOpenCL
  2. add this environment variable somewhere (more details below): RUSTICL_ENABLE=radeonsi
  3. reboot (details below)
  4. Enable Rusticl & OpenCL support in darktable’s “Processing” settings

…and then darktable should hopefully work with acceleration via Rusticl on your system with an AMD GPU. (Although you might need to still turn it on in the settings.)

Detailed installation instructions

So… first install Rusticl.

  • Fedora transactional (standard, like Workstation):

    sudo dnf install mesa-libOpenCL
    
  • Fedora Atomic (like Silverblue, Kinoite, etc.):

    rpm-ostree install -A mesa-libOpenCL
    

    (this will attempt a live install, as -A is shorthand for --apply-live, which tries to install something without rebooting… but you might still need to reboot if that doesn’t work)

Then you can do one of the following:

  • To test it from the command line (this isn’t good for general use, but useful for testing), run this:

    RUSTICL_ENABLE=radeonsi darktable
    

    You might want to run this instead to really test and see if it’s working, as it’ll specifically test and tell you if OpenCL works (however, this may depend on settings in darktable, like turning on support):

    RUSTICL_ENABLE=radeonsi darktable-cltest
    
  • System environment: If you have admin access (root) on your machine: add RUSTICL_ENABLE=radeonsi to /etc/environment

  • Local environment: Create a local environment file:

    mkdir -p ~/.config/environment.d/
    echo RUSTICL_ENABLE=radeonsi > ~/.config/environment.d/rusticl.conf
    

The latter two options where you add the environment variable requires rebooting afterward.

If you happen to be using the flatpak version of darktable (from Flathub), then — unlike ROCm at the moment — you can actually even have hardware acceleration there too. Choose one of the following:

  • Graphical: Add RUSTICL_ENABLE=radeonsi to the “Environment” section using Flatseal

  • Command line: Run this after installing darktable from Flathub:

    sudo flatpak override --env=RUSTICL_ENABLE=radeonsi org.darktable.Darktable
    

…after all that, make sure Rusticl and OpenCL is turned on in darktable’s settings.

If you do notice graphical or stability issues, don’t forget you turned this on. Turn if off if you run into problems. (You’ll likely notice if so.) It seems to work fine for me here, so far.

I’m not sure if I’ll stick with Rusticl or switch back to ROCm OpenCL when it works again. It seems Rusticl is plenty fast? https://www.phoronix.com/news/Rusticl-Outperformed-ROCm — but this is an old article, before it worked well enough to run darktable. I’d love to see real world performance tests of ROCm vs. Rusticl in darktable some day.

Anyway, I hope this helps! It seems like it’s working here. Best of luck!

(If this is a bad idea, to use Rusticl with darktable, I’m sure someone will show up after this post and tell us so. But it seems to work for me for now. I know people worked on sorting out the issues, both on Mesa/Rusticl’s side of things as well as darktable’s. But this support is still new.)

2 Likes

After all that, while my Fuji photos looked fine, it seems that there are some artifacts in raw photos from my Pixel 6 Pro (phone). There’s a visible tile grid in some photos and others have banding. Turning off OpenCL from Rusticl fixed the artifacts.

So, it may work fine with some cameras and not with others. I’ll have to look more into this and file a bug when I get a chance.

Meanwhile, here’s the issue with a food photo I snapped, originally to share with my family. The flat white plate helps to illustrate the problem.

Screenshot with Rusticl on:

No GPU acceleration:

You can see the grid at 100% too, so this isn’t just a problem with the preview and scaling:

It shows in the resulting image as well. Here’s an export constrained to 1000 wide (it also shows up in 1:1):

So, meanwhile, I guess those of us with AMD cards might just want to use CPU until ROCm works for us again… unless this bug is limited to just some camera raw files and not others.

Edit:

  1. So far, this only shows up for me on all raw files from phones: Pixel 6 Pro and OnePlus 6T with a sideloaded Google Camera app (not the default camera app). I checked across my archive spanning decades, and so far it seems that it’s visibly fine with Canon DSLRs, Panasonic GF1, Ricoh GRIIIx, Fuji X-Trans sensors, and some various play raws from various from here. This seems like a Google Camera DNG file problem with Rusticl OpenCL in darktable.

  2. I’ve filed a bug @ openCL, rusticl: Square grid artifacts show up on raw photos from phones · Issue #16717 · darktable-org/darktable · GitHub

2 Likes

Thank you so much for these instructions! I’ll give it a go next time I’m behind the screen :+1:

Are you seeing the same error as the OP? I checked my F40 on VM and it still has LVMM 17 instead of 18. Can you provide your output from darktable-cltest under rocm?

@garrett

I have the same issue with Google Pixel 4XL. Original foto app and Open Camera create the same artifacts. Converting the DNG to TIF (from dt w/o Rusticl enabled) solves the issue.

Sony a6000 and a6400 RAW are OK.

I currently have: llvm-libs 18.x (llvm-libs-18.1.1-1.fc40.x86_64) and 17.x (llvm17-libs-17.0.6-7.fc40.x86_64). I guess I should see about sorting out the version, as I’m pretty sure ROCm worked on F40 beta darktable last week… but I reinstalled my system last Sunday.

My current darktable-cltest output, which has both rocm-opencl and rusticl in the output. I get the compile failure with rocm ([opencl_build_program] could not build program: CL_BUILD_PROGRAM_FAILURE):

darktable 4.6.1
Copyright (C) 2012-2024 Johannes Hanika and other contributors.

Compile options:
  Bit depth              -> 64 bit
  Debug                  -> DISABLED
  SSE2 optimizations     -> ENABLED
  OpenMP                 -> ENABLED
  OpenCL                 -> ENABLED
  Lua                    -> ENABLED  - API version 9.2.0
  Colord                 -> ENABLED
  gPhoto2                -> ENABLED
  GMIC                   -> ENABLED  - Compressed LUTs are supported
  GraphicsMagick         -> ENABLED
  ImageMagick            -> DISABLED
  libavif                -> ENABLED
  libheif                -> ENABLED
  libjxl                 -> ENABLED
  OpenJPEG               -> ENABLED
  OpenEXR                -> ENABLED
  WebP                   -> ENABLED

See https://www.darktable.org/resources/ for detailed documentation.
See https://github.com/darktable-org/darktable/issues/new/choose to report bugs.

     0.0112 [dt_get_sysresource_level] switched to 2 as `large'
     0.0112   total mem:       63930MB
     0.0112   mipmap cache:    7991MB
     0.0112   available mem:   43702MB
     0.0112   singlebuff:      998MB
     0.0123 [opencl_init] opencl disabled via darktable preferences
     0.0124 [opencl_init] opencl library 'libOpenCL' found on your system and loaded, preference 'default path'
     0.1048 [opencl_init] found 3 platforms
     0.1049 [check platform] platform 'Clover' with key 'clplatform_clover' is NOT active
[opencl_init] found 2 devices

[dt_opencl_device_init]
   DEVICE:                   0: 'gfx1100'
   PLATFORM, VENDOR & ID:    AMD Accelerated Parallel Processing, Advanced Micro Devices, Inc., ID=4098
   CANONICAL NAME:           amdacceleratedparallelprocessinggfx1100
   DRIVER VERSION:           3602.0 (HSA1.1,LC)
   DEVICE VERSION:           OpenCL 2.0 
   DEVICE_TYPE:              GPU, dedicated mem
   GLOBAL MEM SIZE:          24560 MB
   MAX MEM ALLOC:            20876 MB
   MAX IMAGE SIZE:           16384 x 16384
   MAX WORK GROUP SIZE:      256
   MAX WORK ITEM DIMENSIONS: 3
   MAX WORK ITEM SIZES:      [ 1024 1024 1024 ]
   ASYNC PIXELPIPE:          NO
   PINNED MEMORY TRANSFER:   NO
   AVOID ATOMICS:            NO
   MICRO NAP:                250
   ROUNDUP WIDTH & HEIGHT    16x16
   CHECK EVENT HANDLES:      128
   TILING ADVANTAGE:         0.000
   DEFAULT DEVICE:           NO
   KERNEL BUILD DIRECTORY:   /usr/share/darktable/kernels
   KERNEL DIRECTORY:         /var/home/garrett/.cache/darktable/cached_v3_kernels_for_AMDAcceleratedParallelProcessinggfx1100_36020HSA11LC
   CL COMPILER OPTION:       -cl-fast-relaxed-math
   CL COMPILER COMMAND:      -w -cl-fast-relaxed-math  -DAMD=1 -I"/usr/share/darktable/kernels"
     0.2634 [opencl_build_program] could not build program: CL_BUILD_PROGRAM_FAILURE
     0.2634 [dt_opencl_device_init] failed to compile program `demosaic_ppg.cl'!

[dt_opencl_device_init]
   DEVICE:                   1: 'AMD Radeon RX 7900 XTX (radeonsi, navi31, LLVM 18.1.1, DRM 3.57, 6.8.8-300.fc40.x86_64)'
   PLATFORM, VENDOR & ID:    rusticl, Mesa/X.org, ID=4098
   CANONICAL NAME:           rusticlamdradeonrx7900xtx
   DRIVER VERSION:           24.0.6
   DEVICE VERSION:           OpenCL 3.0 
   DEVICE_TYPE:              GPU, dedicated mem
   GLOBAL MEM SIZE:          24576 MB
   MAX MEM ALLOC:            2048 MB
   MAX IMAGE SIZE:           16384 x 16384
   MAX WORK GROUP SIZE:      1024
   MAX WORK ITEM DIMENSIONS: 3
   MAX WORK ITEM SIZES:      [ 1024 1024 1024 ]
   ASYNC PIXELPIPE:          NO
   PINNED MEMORY TRANSFER:   NO
   AVOID ATOMICS:            NO
   MICRO NAP:                250
   ROUNDUP WIDTH & HEIGHT    16x16
   CHECK EVENT HANDLES:      128
   TILING ADVANTAGE:         0.000
   DEFAULT DEVICE:           NO
   KERNEL BUILD DIRECTORY:   /usr/share/darktable/kernels
   KERNEL DIRECTORY:         /var/home/garrett/.cache/darktable/cached_v3_kernels_for_rusticlAMDRadeonRX7900XTX_2406
   CL COMPILER OPTION:       
   CL COMPILER COMMAND:      -w   -DAMD=1 -I"/usr/share/darktable/kernels"
   KERNEL LOADING TIME:       0.2216 sec
[opencl_init] OpenCL successfully initialized. internal numbers and names of available devices:
[opencl_init]		0	'rusticl AMD Radeon RX 7900 XTX'
     0.4855 [opencl_init] FINALLY: opencl is AVAILABLE and NOT ENABLED.
[dt_opencl_update_priorities] these are your device priorities:
[dt_opencl_update_priorities] 		image	preview	export	thumbs	preview2
[dt_opencl_update_priorities]		0	0	0	0	0
[dt_opencl_update_priorities] show if opencl use is mandatory for a given pixelpipe:
[dt_opencl_update_priorities] 		image	preview	export	thumbs	preview2
[dt_opencl_update_priorities]		1	1	1	1	1
[opencl_synchronization_timeout] synchronization timeout set to 0
[dt_opencl_update_priorities] these are your device priorities:
[dt_opencl_update_priorities] 		image	preview	export	thumbs	preview2
[dt_opencl_update_priorities]		0	0	0	0	0
[dt_opencl_update_priorities] show if opencl use is mandatory for a given pixelpipe:
[dt_opencl_update_priorities] 		image	preview	export	thumbs	preview2
[dt_opencl_update_priorities]		1	1	1	1	1
[opencl_synchronization_timeout] synchronization timeout set to 0

Oddly, darktable-cltest is working in a container for me with just darktable and rocm-opencl. I think I’ll try updating and removing extra packages on my main system to see what happens.

Update: darktable-cltest doesn’t work on my host, doesn’t work in a toolbox container, but does work in a distrobox container. All are Fedora 40 with darktable and rocm-opencl installed. I don’t know what the difference is; I’ve been comparing package sets and nothing looks significant (as I’ve tried installing all the packages that differ within in a container… and it still doesn’t work). I’ve also tried adjusting the $PATH. There must be something different.

I should note that a workaround is to create a Fedora 40 distrobox container, install darktable and rocm-opencl in there, run darktable-cltest, have it compile the OpenCL parts, and then darktable works on the host with OpenCL as they’re cached. If you remove your cache or upgrade darktable, you’ll have to regenerate.

Anyway, I’ve spent a while on this and can’t figure it out. Hopefully there’s a hint somewhere in here. If someone wants me to try something, please let me know. Also, it would explain why darktable was working for me before reinstalltion and is working for some others on Fedora 40 — we had caches of the OpenCL compilation. When I reinstalled, it wiped my cache (I didn’t back that up) and hit the problem. I’m guessing for the people it works, they probably have a prior cached version and @rsolva and I didn’t. Although, it is working for me in Fedora 40 in distrobox, oddly… Weird, right?

Can you post darktbale-cltest -d verbose?

Do all systems have the 2 versions of llvm?

maybe distrobox does set the proper parameters to forward the GPU into the container?

I have F40 KDE running in a VM and F39 as my main system. I see the same two packages for llvm. But I only see the clang 17 folders along with the opencl-c-base.h.

Did you check the clang-libs package?

clang17-libs 17.0.6-7.fc40

So install 18, it’s available for fc40.

The rusticl option worked for me both for flatpak and the RPM from DNF, thanks! I’ll try ROCm again when Fedora 40 is out of beta.

Fedora 40 is out of beta for like 2 weeks.

Ah, rocm-opencl and rocm-compgr are actually built w/ LLVM 17 even on F40, so the message above 'could not find file '/usr/lib64/llvm17/bin/../../../lib/clang/17/include/opencl-c-base.h' is actually correct.

rocm-compgr should already pull in clang17-libs though, so I wonder if some packages were not upgraded properly…

Edit: I think maybe there was a missed bump for the rocm-device-libs package. (You can test by manually force installing the rawhide/fc41 one.)

1 Like

I tried sudo mkdir /usr/lib64/llvm17/bin to create the bin folder and that seems to allow the path to resolve to the existing file (at least on my system) /lib/clang/17/include/opencl-c-base.h.

I’m using a AMD 780M iGPU in Fedora 40. Here’s the final output of darktable-cltest:

[opencl_init]		0	'AMD Accelerated Parallel Processing gfx1103'
     0.5114 [opencl_init] FINALLY: opencl is AVAILABLE and ENABLED.

EDIT: Turns out I had to additionally install rocm-hip to get llvm17 properly installed and the above path resolved without synthetically creating the bin folder. See SIGs/HC - Fedora Project Wiki.