darktable icon indicating copy to clipboard operation
darktable copied to clipboard

opencl crash when demosaicing with markesteijn an x-trans raw (X-T20)

Open aefkha opened this issue 8 months ago • 5 comments

Is there an existing issue for this?

  • [x] I checked and did not find my issue in the already reported ones

Describe the bug

Opencl multiple crashes when attempting to edit an X-T20 raw with markesteijn set as demosaicing algorithm.

At some point, darktable disables opencl and use only CPU: an alert is shown. I tested with a fresh clean config folder and no sidecar file associated.

Happens on all my X-T20 raw, but not on X-M1 files. Never with frequential chroma domain (is that it in english?). Can't be sure with VNG.

Steps to reproduce

  1. With a clean config folder, add the attached X-T20 picture to the library
  2. Open darkroom to start editing the file and look at opencl going mad

The bug triggers inconsistently: sometimes, you need to have edited at least one time the file, close darktable, open and edit again. Can also be triggered randomly when editing or almost always when displaying a snapshot taken a few clicks ago. I could not find any pattern linked to a particular module

Expected behavior

opencl should run smoothly with no hickups

Logfile | Screenshot | Screencast

Output of darktable -d opencl

darktable 5.0.1
Copyright (C) 2012-2025 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.4.0
  Colord                 -> ENABLED
  gPhoto2                -> ENABLED
  GMIC                   -> ENABLED  - Compressed LUTs are supported
  GraphicsMagick         -> ENABLED
  ImageMagick            -> DISABLED
  libavif                -> ENABLED
  libheif                -> ENABLED
  libjxl                 -> ENABLED
  LibRaw                 -> ENABLED  - Version 0.22.0-Devel202403
  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.0001 [dt starting]
 darktable -d opencl
     0,1859 [dt_get_sysresource_level] switched to 1 as `default'
     0,1859   total mem:       15933MB
     0,1859   mipmap cache:    1991MB
     0,1859   available mem:   7966MB
     0,1859   singlebuff:      124MB
     0.2150 [opencl_init] opencl library 'libOpenCL' found on your system and loaded, preference 'default path'
     0.2510 [opencl_init] found 2 platforms
     0.2511 [opencl_init] possibly a multiple platform problem for `AMD Accelerated Parallel Processing'
     0.2511 [opencl_init] no devices found for Advanced Micro Devices, Inc. (vendor) - AMD Accelerated Parallel Processing (name)
[opencl_init] found 1 device

[dt_opencl_device_init]
   DEVICE:                   0: 'Ellesmere'
   CONF KEY:                 cldevice_v5_amdacceleratedparallelprocessingellesmere
   PLATFORM, VENDOR & ID:    AMD Accelerated Parallel Processing, Advanced Micro Devices, Inc., ID=4098
   CANONICAL NAME:           amdacceleratedparallelprocessingellesmere
   DRIVER VERSION:           3380.4 (PAL,HSAIL)
   DEVICE VERSION:           OpenCL 2.0 AMD-APP (3380.4)
   DEVICE_TYPE:              GPU, dedicated mem
   GLOBAL MEM SIZE:          4096 MB
   MAX MEM ALLOC:            3264 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/denis/.cache/darktable/cached_v5_kernels_for_AMDAcceleratedParallelProcessingEllesmere_33804PALHSAIL
   CL COMPILER OPTION:       -cl-fast-relaxed-math
   CL COMPILER COMMAND:      -w -cl-fast-relaxed-math -DAMD=1 -I"/usr/share/darktable/kernels"
   KERNEL LOADING TIME:       0.0740 sec
[opencl_init] OpenCL successfully initialized. internal numbers and names of available devices:
[opencl_init]		0	'AMD Accelerated Parallel Processing Ellesmere'
     0.5136 [opencl_init] FINALLY: opencl PREFERENCE=ON is AVAILABLE and ENABLED.
[opencl_init] opencl_scheduling_profile: 'default'
[opencl_init] opencl_device_priority: '*/!0,*/*/*/!0,*'
[opencl_init] opencl_mandatory_timeout: 1000
[opencl_update_priorities] these are your device priorities:
[opencl_update_priorities] 		image	preview	export	thumbs	preview2
[dt_opencl_update_priorities]		0	-1	0	0	-1
[opencl_update_priorities] show if opencl use is mandatory for a given pixelpipe:
[opencl_update_priorities] 		image	preview	export	thumbs	preview2
[opencl_update_priorities]		0	0	0	0	0
[opencl_synchronization_timeout] synchronization timeout set to 200
[opencl_update_priorities] these are your device priorities:
[opencl_update_priorities] 		image	preview	export	thumbs	preview2
[dt_opencl_update_priorities]		0	-1	0	0	-1
[opencl_update_priorities] show if opencl use is mandatory for a given pixelpipe:
[opencl_update_priorities] 		image	preview	export	thumbs	preview2
[opencl_update_priorities]		0	0	0	0	0
[opencl_synchronization_timeout] synchronization timeout set to 200
     1,6618 [lib_load_module] failed to open `midi': libportmidi.so.2: Ne peut ouvrir le fichier d'objet partagé: Aucun fichier ou dossier de ce nom
     2,3160 [dt_opencl_check_tuning] use 2389MB (headroom=OFF, pinning=OFF) on device `AMD Accelerated Parallel Processing Ellesmere' id=0
     5,7278 [opencl_events_flush] execution of '[Read Image (from device to host)]' failed: -59
     5,7279 pipe aborts               CL0 [full]           demosaic                800 (   0/   0) 6032x4011 scale=1,0000 --> (   0/   0) 1284x 854 scale=0,2129  couldn't run module on GPU, falling back to CPU
     6,8030 pipe aborts               CL0 [full]           exposure               2400 (   0/   0) 1284x 854 scale=0,2129 --> (   0/   0) 1284x 854 scale=0,2129  couldn't run module on GPU, falling back to CPU
     6,8378 pipe aborts               CL0 [full]           colorin                3200 (   0/   0) 1284x 854 scale=0,2129 --> (   0/   0) 1284x 854 scale=0,2129  couldn't run module on GPU, falling back to CPU
     6,9024 pipe aborts               CL0 [full]           colorequal             5100 (   0/   0) 1284x 854 scale=0,2129 --> (   0/   0) 1284x 854 scale=0,2129  couldn't run module on GPU, falling back to CPU
     7,1855 pipe aborts               CL0 [full]           colorbalancergb        5200 (   0/   0) 1284x 854 scale=0,2129 --> (   0/   0) 1284x 854 scale=0,2129  couldn't run module on GPU, falling back to CPU
     7,3575 pipe aborts               CL0 [full]           colorout               8300 (   0/   0) 1284x 854 scale=0,2129 --> (   0/   0) 1284x 854 scale=0,2129  couldn't run module on GPU, falling back to CPU
     7,3758 pipe restarting on CPU    CL0 [full]                                       (   0/   0) 1284x 854 scale=0,2129 --> (   0/   0) 1284x 854 scale=0,2129  ID=11
 [opencl_summary_statistics] device 'AMD Accelerated Parallel Processing Ellesmere' (0): 485 out of 486 events were successful and 0 events lost. max event=245

Commit

No response

Where did you obtain darktable from?

distro packaging

darktable version

5.1.0

What OS are you using?

Linux

What is the version of your OS?

Arch (endeavourOS)

Describe your system

No response

Are you using OpenCL GPU in darktable?

Yes

If yes, what is the GPU card and driver?

radeon RX 480 ellesmere (polaris 10) 4GB; driver: AMDGPU via package vulkan-radeon; ROCm v6.3.2-1 for opencl

Please provide additional context if applicable. You can attach files too, but might need to rename to .txt or .zip

  • Happens also with 5.0.1 and 4.8.1 appimage
  • X-T20 raw only, tested with X-M1 no problem, as for the rest...?
  • yes, happens with fresh edit, but not always
  • yes with a new config dir
  • no lua

Attached raw: DSCF9118.txt

aefkha avatar Apr 04 '25 23:04 aefkha

  1. You have two OpenCL drivers installed so there are two platforms and that often leads to OpenCL instabilities.
  2. Could you check clinfo if at least that works correcly ?
  3. We often had OpenCL problems with AMD as drivers & hardware mix might not be correctly supported.

jenshannoschwalm avatar Apr 05 '25 06:04 jenshannoschwalm

There is an idea here , could you please carefully test and report on these two questions

  1. Can you confirm there are absolutely no crashes if you use bayer sensor raw images with no modules activated except the defaults?
  2. Only if (1) is confirmed, could you try out on bayer images if there are any errors if you enable the "darkroom visualize overexposure" button?
  3. Only if (1) is confirmed, do you have issues on bayer images while using the "colorreconstruction" module?

jenshannoschwalm avatar Apr 05 '25 08:04 jenshannoschwalm

  1. You have two OpenCL drivers installed so there are two platforms and that often leads to OpenCL instabilities.

Yeah, there is something odd going on here, I'm still investigating it. There is no reason that 2 "platforms" appear on my install because it is quite fresh, I only have one graphic card with one single GPU, I never installed anything else than AMDGPU free and opencl components and my CPU is an intel...

  1. Could you check clinfo if at least that works correcly ?

Yes, it works properly, also listing the 2nd platform for which there is no device. Below for the records.

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

  Platform Name                                   AMD Accelerated Parallel Processing
  Platform Vendor                                 Advanced Micro Devices, Inc.
  Platform Version                                OpenCL 2.1 AMD-APP (3635.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                                     Ellesmere
  Device Vendor                                   Advanced Micro Devices, Inc.
  Device Vendor ID                                0x1002
  Device Version                                  OpenCL 2.0 AMD-APP (3380.4)
  Driver Version                                  3380.4 (PAL,HSAIL)
  Device OpenCL C Version                         OpenCL C 2.0 
  Device Type                                     GPU
  Device Board Name (AMD)                         AMD Radeon RX 480 Graphics
  Device PCI-e ID (AMD)                           0x67df
  Device Topology (AMD)                           PCI-E, 0000:01:00.0
  Device Profile                                  FULL_PROFILE
  Device Available                                Yes
  Compiler Available                              Yes
  Linker Available                                Yes
  Max compute units                               36
  SIMD per compute unit (AMD)                     4
  SIMD width (AMD)                                16
  SIMD instruction width (AMD)                    1
  Max clock frequency                             1303MHz
  Graphics IP (AMD)                               8.0
  Device Partition                                (core)
    Max number of sub-devices                     36
    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                                     No
    Infinity and NANs                             No
    Round to nearest                              No
    Round to zero                                 No
    Round to infinity                             No
    IEEE754-2008 fused multiply-add               No
    Support is emulated in software               No
  Single-precision Floating-point support         (core)
    Denormals                                     No
    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                              4294967296 (4GiB)
  Global free memory (AMD)                        4128768 (3.938GiB) 3866624 (3.688GiB)
  Global memory channels (AMD)                    8
  Global memory banks per channel (AMD)           4
  Global memory bank width (AMD)                  256 bytes
  Error Correction support                        No
  Max memory allocation                           3422552064 (3.188GiB)
  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                       2048 bits (256 bytes)
  Preferred alignment for atomics                 
    SVM                                           0 bytes
    Global                                        0 bytes
    Local                                         0 bytes
  Max size for global variable                    3080296704 (2.869GiB)
  Preferred total size of global vars             4294967296 (4GiB)
  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            213909504 pixels
    Max 1D or 2D image array size                 2048 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                             2048x2048x2048 pixels
    Max number of read image args                 128
    Max number of write image args                64
    Max number of read/write image args           64
  Max number of pipe args                         16
  Max active pipe reservations                    16
  Max pipe packet size                            3422552064 (3.188GiB)
  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                        3422552064 (3.188GiB)
  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)        1743922974474923267ns (Sun Apr  6 09:02:54 2025)
  Execution capabilities                          
    Run OpenCL kernels                            Yes
    Run native kernels                            No
    Thread trace supported (AMD)                  Yes
    Number of async queues (AMD)                  4
    Max real-time compute queues (AMD)            1
    Max real-time compute units (AMD)             0
  printf() buffer size                            4194304 (4MiB)
  Built-in kernels                                (n/a)
  Device Extensions                               cl_khr_fp64 cl_amd_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_khr_gl_depth_images cl_amd_device_attribute_query cl_amd_vec3 cl_amd_printf cl_amd_media_ops cl_amd_media_ops2 cl_amd_popcnt cl_khr_image2d_from_buffer cl_khr_subgroups cl_khr_gl_event cl_khr_depth_images cl_khr_mipmap_image cl_khr_mipmap_image_writes cl_amd_copy_buffer_p2p 

  Platform Name                                   AMD Accelerated Parallel Processing
Number of devices                                 0

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]
  clCreateContext(NULL, ...) [other]              <error: no devices in non-default plaforms>
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT)  Success (1)
    Platform Name                                 AMD Accelerated Parallel Processing
    Device Name                                   Ellesmere
  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                                   Ellesmere
  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                                   Ellesmere

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

aefkha avatar Apr 07 '25 20:04 aefkha

  1. Can you confirm there are absolutely no crashes if you use bayer sensor raw images with no modules activated except the defaults?

No crashes whatsoever with only defaults modules, and also none when applying my method to crash x-trans pictures. I've been using the x-a1 sample from raw.pixls.us

  1. Only if (1) is confirmed, could you try out on bayer images if there are any errors if you enable the "darkroom visualize overexposure" button?

Works like a charm

  1. Only if (1) is confirmed, do you have issues on bayer images while using the "colorreconstruction" module?

No problem either

To help a little bit more, I tested several generations of x-trans sensor using samples from raw.pixls.us. The bug happens with x-trans 2, 3 and 4 generation (x-T2, x-T20, x-T4 samples respectively), no bug with x-trans 1 (x-M1 + x-E1). With X-T20 at least, the bug occurs with uncompressed and compressed raw. Tested only uncompressed for the others.

aefkha avatar Apr 07 '25 20:04 aefkha

This issue has been marked as stale due to inactivity for the last 60 days. It will be automatically closed in 300 days if no update occurs. Please check if the master branch has fixed it and report again or close the issue.

github-actions[bot] avatar Jun 07 '25 00:06 github-actions[bot]