Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
opencl.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2010-2012, 2016 johannes hanika.
4 Copyright (C) 2010, 2020-2021 Pascal Obry.
5 Copyright (C) 2011 Henrik Andersson.
6 Copyright (C) 2011, 2013-2014, 2016 Tobias Ellinghaus.
7 Copyright (C) 2011-2017 Ulrich Pegelow.
8 Copyright (C) 2012 Michal Babej.
9 Copyright (C) 2012 Richard Wonka.
10 Copyright (C) 2013 Pascal de Bruijn.
11 Copyright (C) 2015, 2019 Dan Torop.
12 Copyright (C) 2016 Roman Lebedev.
13 Copyright (C) 2017-2019 Edgardo Hoszowski.
14 Copyright (C) 2017 luzpaz.
15 Copyright (C) 2019 Heiko Bauke.
16 Copyright (C) 2019 jakubfi.
17 Copyright (C) 2021-2022, 2025-2026 Aurélien PIERRE.
18 Copyright (C) 2021 Hubert Kowalski.
19 Copyright (C) 2022 Hanno Schwalm.
20 Copyright (C) 2022 Martin Bařinka.
21 Copyright (C) 2025 Alynx Zhou.
22 Copyright (C) 2025-2026 Guillaume Stutin.
23
24 darktable is free software: you can redistribute it and/or modify
25 it under the terms of the GNU General Public License as published by
26 the Free Software Foundation, either version 3 of the License, or
27 (at your option) any later version.
28
29 darktable is distributed in the hope that it will be useful,
30 but WITHOUT ANY WARRANTY; without even the implied warranty of
31 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 GNU General Public License for more details.
33
34 You should have received a copy of the GNU General Public License
35 along with darktable. If not, see <http://www.gnu.org/licenses/>.
36*/
37
38#ifndef DT_COMMON_OPENCL_H
39#define DT_COMMON_OPENCL_H
40
41#ifdef HAVE_CONFIG_H
42#include "config.h"
43#endif
44
45#define DT_OPENCL_MAX_PLATFORMS 5
46#define DT_OPENCL_MAX_PROGRAMS 256
47#define DT_OPENCL_MAX_KERNELS 512
48#define DT_OPENCL_EVENTLISTSIZE 256
49#define DT_OPENCL_EVENTNAMELENGTH 64
50#define DT_OPENCL_MAX_ERRORS 5
51/* Size of the clincludes[] table in dt_opencl_priority_parse()'s caller, NULL terminator
52 * included. dt_opencl_md5sum() walks exactly this many entries, so the table must have
53 * room for its terminator: adding an include without raising this reads past the end. */
54#define DT_OPENCL_MAX_INCLUDES 8
55#define DT_OPENCL_VENDOR_AMD 4098
56#define DT_OPENCL_VENDOR_NVIDIA 4318
57#define DT_OPENCL_VENDOR_INTEL 0x8086u
58#define DT_OPENCL_CBUFFSIZE 1024
59
60// some pseudo error codes in dt opencl usage
61#define DT_OPENCL_DEFAULT_ERROR -999
62#define DT_OPENCL_SYSMEM_ALLOCATION -998
63
64#include "common/logging.h"
65
66#include <stdint.h>
67
68#ifdef HAVE_OPENCL
69
70#include "common/dlopencl.h"
71#include "common/conf.h"
72
73// #pragma GCC diagnostic push
74// #pragma GCC diagnostic ignored "-Wcomment"
75#include <CL/cl.h>
76// #pragma GCC diagnostic
77
78#ifdef __cplusplus
79extern "C" {
80#endif
81
82#define ROUNDUP(a, n) ((a) % (n) == 0 ? (a) : ((a) / (n)+1) * (n))
83
84// use per device roundups here
85#define ROUNDUPDWD(a, b) dt_opencl_dev_roundup_width(a, b)
86#define ROUNDUPDHT(a, b) dt_opencl_dev_roundup_height(a, b)
87
88#define DT_OPENCL_BPP_TAG_RGBA8 (1u << 30)
89#define DT_OPENCL_BPP_ENCODE_RGBA8(bpp) ((int)((unsigned int)(bpp) | DT_OPENCL_BPP_TAG_RGBA8))
90#define DT_OPENCL_BPP_IS_RGBA8(bpp) ((((unsigned int)(bpp)) & DT_OPENCL_BPP_TAG_RGBA8) != 0u)
91#define DT_OPENCL_BPP_DECODE(bpp) ((int)(((unsigned int)(bpp)) & ~DT_OPENCL_BPP_TAG_RGBA8))
92
93/* Per-vendor kernel build options. The per-device conf key
94 * `cldevice_v4/<n>/<cname>/building` overrides these and is what a user edits in anselrc; these
95 * are only the value written there on first sight of a device.
96 *
97 * `-cl-unsafe-math-optimizations` (and `-cl-fast-relaxed-math`, which implies it) lets the
98 * driver substitute a low-precision implementation for any libm function. That is a per-vendor
99 * gamble, not a uniform speedup, and Intel loses it badly: measured on an HD Graphics P630
100 * (NEO 24.35, max relative error of erf() against a double-precision host reference over
101 * x in [-8, 8])
102 *
103 * safe flags 1.39e-07 correct to float precision
104 * unsafe 1.00e+00 erf() returns exactly 0.0 for |x| < ~1e-3, and is 22 % low
105 * at 1e-2
106 *
107 * `iop/rawdenoiseai.c`'s GELU is 0.5*x*(1+erf(x/sqrt(2))) and a convolutional net spends most
108 * of its activations in exactly that small-|x| band, so the whole denoiser drifts: the same
109 * export differs from the CPU path by 0.78 % mean / 3.1 % p99 with the flag, and by 0.0023 %
110 * without it -- the latter being bit-for-bit what NVIDIA produces. It is visible, and it is
111 * what users report as a grid or mesh on X-Trans (discussion #1104).
112 *
113 * And it buys nothing to pay for that. Measured wall-clock, same image, kernels already cached:
114 *
115 * P630, denoiser export 96.8 s unsafe 93.9 s safe
116 * Quadro M2200, denoiser export 8.10 s unsafe 8.14 s safe
117 * Quadro M2200, whole pipeline
118 * with the denoiser OFF, so
119 * every other module dominates 5.38/4.81/4.84 unsafe 5.27/4.92/4.89 safe
120 *
121 * i.e. a 0.4 % spread, inside run-to-run noise, on hardware old enough to show a real
122 * difference if there were one. Dropping the flag also barely moves the existing NVIDIA render
123 * (0.00024 % mean over the whole pipeline), so this is not a visual change for users who were
124 * already getting correct output.
125 *
126 * So every vendor gets the same conservative set. `-cl-mad-enable` keeps the fused multiply-add
127 * that actually matters for convolution throughput, `-cl-no-signed-zeros` is free, and neither
128 * licenses a substitute libm. NVIDIA happens to keep erf() exact under the unsafe flag
129 * (7.97e-08) but still degrades log(), and AMD has never been measured here at all -- there is
130 * no reason to keep taking a per-driver gamble for a speedup that does not show up.
131 *
132 * The per-vendor macros are kept separate rather than collapsed: they are the natural place to
133 * record a future measurement that justifies diverging again. Run tools/opencl-math-accuracy.c
134 * to regenerate every number above on any machine; see doc/opencl-math-accuracy.md. */
135#define DT_OPENCL_DEFAULT_COMPILE_INTEL ("-cl-mad-enable -cl-no-signed-zeros")
136#define DT_OPENCL_DEFAULT_COMPILE_AMD ("-cl-mad-enable -cl-no-signed-zeros")
137#define DT_OPENCL_DEFAULT_COMPILE_NVIDIA ("-cl-mad-enable -cl-no-signed-zeros")
138#define DT_OPENCL_DEFAULT_COMPILE ("-cl-mad-enable -cl-no-signed-zeros")
139#define DT_CLDEVICE_HEAD ("cldevice_v4")
140
146
156
163
164// Why an image did (or did not) fit on an OpenCL device. Each non-OK reason maps
165// to a *different* limit, so a caller logging "needs X but limit is Y" must report
166// the quantities that were actually compared for the returned reason -- see
167// dt_opencl_image_fits_device_reason().
169{
170 DT_OPENCL_FIT_OK = 0, // the image fits, the device can process it
171 DT_OPENCL_FIT_DIMENSION, // width/height exceed the device 2D image limits
172 DT_OPENCL_FIT_ALLOC_LIMIT, // a single buffer exceeds CL_DEVICE_MAX_MEM_ALLOC_SIZE
173 DT_OPENCL_FIT_AVAILABLE, // not enough free vRAM headroom for the factored allocation
174 DT_OPENCL_FIT_UNINITED // OpenCL unavailable / invalid device
176
181typedef struct dt_opencl_device_t
182{
183 dt_pthread_mutex_t lock;
184 cl_device_id devid;
185 cl_context context;
186 cl_command_queue cmd_queue;
196 cl_event *eventlist;
207 const char *vendor;
208 /* Numeric CL_DEVICE_VENDOR_ID, kept alongside the name for reporting. It is NOT what a
209 * crash is attributed to -- see `runtime_id' below. */
210 unsigned int vendor_id;
211 /* The OpenCL runtime publishing this device, named by the conf-key suffix its crash streak
212 * is stored under ("rusticl", "amd", "intel", ...), resolved from CL_PLATFORM_NAME. NULL
213 * when the platform matches no rule we ship, in which case no crash can be attributed to
214 * this device. A string literal owned by the runtime table in opencl.c: never freed, and
215 * not to be freed alongside the strdup'd fields around it. */
216 const char *runtime_id;
217 const char *name;
218 const char *cname;
219 const char *options;
220 const char *options_md5;
221 cl_int summary;
225
226 // flags detected errors
228 // if set to TRUE darktable will not use OpenCL kernels which contain atomic operations (example bilateral).
229 // pixelpipe processing will be done on CPU for the affected modules.
230 // useful (only for very old devices) if your OpenCL implementation freezes/crashes on atomics or if
231 // they are processed with a bad performance.
233
234 // pause OpenCL processing for this number of microseconds from time to time
236
237 // During tiling huge amounts of memory need to be transferred between host and device.
238 // For some OpenCL implementations direct memory transfers give a drastic performance penalty,
239 // this can often be avoided by using indirect transfers via pinned memory,
240 // other devices have more efficient direct memory transfer implementations.
241 // We can't predict on solid grounds if a device belongs to the first or second group,
242 // also pinned mem transfer requires slightly more ram.
243 // this holds a bitmask defined by dt_opencl_pinmode_t
244 // the device specific conf key might hold
245 // 0 -> disabled by default; might be switched on by tune for performance
246 // 1 -> enabled by default
247 // 2 -> disabled under all circumstances. This could/should be used if we give away / ship specific keys for buggy systems
249
250 // in OpenCL processing round width/height of global work groups to a multiple of these values.
251 // reasonable values are powers of 2. this parameter can have high impact on OpenCL performance.
254
255 // A bitfield that identifies the type of OpenCL device required to test for on-CPU and more.
256 unsigned int cltype;
257
258 // This defines how often should dt_opencl_events_get_slot do a dt_opencl_events_flush.
259 // It should definitely le lower than the number of events that can be handled by the device/driver.
260 // FIXME we should be able to test for that with using >= OpenCl 2.0
262
263 // opencl_events enabled for the device, set internally via event_handles
265
266 // a device might be turned off by force by setting this value to 1
267 // also used for blacklisted drivers
269
270 // CL_DEVICE_HOST_UNIFIED_MEMORY: TRUE for integrated GPUs that share the system's RAM
271 // instead of owning dedicated vRAM. On these devices, "available memory" as reported by
272 // the driver (max_global_mem, max_mem_alloc) and tracked by our own memory_in_use
273 // bookkeeping is a much less reliable estimate of what can actually be allocated: the
274 // whole OS, desktop compositor and every other process compete for that same pool, and we
275 // have no visibility into that competition. Used to pick a larger default forced_headroom
276 // (see dt_opencl_read_device_config()) so a size that our own accounting says "fits" is
277 // less likely to still exceed real availability and abort inside the driver instead of
278 // failing cleanly with CL_OUT_OF_RESOURCES.
280
281 // Some devices are known to be unused by other apps so there is no need to test for available memory at all.
282 // Also some devices might behave badly with the checking code, in this case we could enforce a headroom here.
285
287{
289 char *name;
290 char *cname;
291 unsigned int cltype;
295 // Mirrors dt_opencl_device_t.host_unified_memory -- lets GUI code (preferences) label the
296 // headroom setting accurately for integrated GPUs without reaching into the live device array.
299
302struct dt_dwt_cl_global_t; // wavelet decompose
303struct dt_heal_cl_global_t; // healing
304struct dt_colorspaces_cl_global_t; // colorspaces transform
306
311/* dt_opencl_t is PRIVATE to common/opencl.c.
312 *
313 * It used to be defined here and instantiated on the application god-struct, so its device
314 * array, its lock and nine other subsystems' kernel bundles were reachable from any file that
315 * included darktable.h. Callers ask questions now -- dt_opencl_get_num_devices(),
316 * dt_opencl_get_device_name(), dt_opencl_get_device_max_image_size() -- and reserve devices
317 * through dt_opencl_reserve_device_for_pipe() / _by_id(). Nothing outside the module needs
318 * the layout, so nothing outside the module has it. */
320
325{
326 const int xoffset;
327 const int xfactor;
328 const int yoffset;
329 const int yfactor;
330 const size_t cellsize;
331 const size_t overhead;
332 int sizex; // initial value and final values after optimization
333 int sizey; // initial value and final values after optimization
335
360void dt_opencl_note_crash_backtrace(const char *backtrace, size_t backtrace_len);
361
362void dt_opencl_init(const gboolean exclude_opencl, const gboolean print_statistics);
363
368
370void dt_opencl_cleanup(void);
371
377int dt_opencl_finish(const int devid);
378
380int dt_opencl_enqueue_barrier(const int devid);
381
398int dt_opencl_reserve_device_for_pipe(const int pipetype);
399
404void dt_opencl_reserve_device_by_id(const int devid);
405
413int dt_opencl_try_reserve_device_by_id(const int devid);
414
417
424const char *dt_opencl_get_device_name(const int devid);
425
433gboolean dt_opencl_get_device_max_image_size(const int devid, int *width, int *height);
434
436size_t dt_opencl_get_device_max_global_mem(const int devid);
437
440size_t dt_opencl_get_device_memory_in_use(const int devid);
441
445size_t dt_opencl_get_device_headroom(const int devid);
446
459
462void dt_opencl_release_device(const int devid);
463
465void dt_opencl_md5sum(const char **files, char **md5sums);
466
468int dt_opencl_load_program(const int dev, const int prog, const char *filename, const char *binname,
469 const char *cachedir, char *md5sum, char **includemd5, int *loaded_cached);
470
472int dt_opencl_build_program(const int dev, const int prog, const char *binname, const char *cachedir,
473 char *md5sum, int loaded_cached);
474
476int dt_opencl_create_kernel(const int program, const char *name);
477
479void dt_opencl_free_kernel(const int kernel);
480
482int dt_opencl_get_max_work_item_sizes(const int dev, size_t *sizes);
483
485int dt_opencl_get_work_group_limits(const int dev, size_t *sizes, size_t *workgroupsize,
486 unsigned long *localmemsize);
487
489int dt_opencl_get_kernel_work_group_size(const int dev, const int kernel, size_t *kernelworkgroupsize);
490
492int dt_opencl_set_kernel_arg(const int dev, const int kernel, const int num, const size_t size,
493 const void *arg);
494
496int dt_opencl_enqueue_kernel_2d(const int dev, const int kernel, const size_t *sizes);
497
499int dt_opencl_enqueue_kernel_2d_with_local(const int dev, const int kernel, const size_t *sizes,
500 const size_t *local);
501
503int dt_opencl_is_inited(void);
504
505
507int dt_opencl_is_enabled(void);
508
510void dt_opencl_disable(void);
511
514
516int dt_opencl_copy_device_to_host(const int devid, void *host, void *device, const int width,
517 const int height, const int bpp);
518
519int dt_opencl_read_host_from_device(const int devid, void *host, void *device, const int width,
520 const int height, const int bpp);
521
522int dt_opencl_read_host_from_device_rowpitch(const int devid, void *host, void *device, const int width,
523 const int height, const int rowpitch);
524
525int dt_opencl_read_host_from_device_non_blocking(const int devid, void *host, void *device, const int width,
526 const int height, const int bpp);
527
528int dt_opencl_read_host_from_device_rowpitch_non_blocking(const int devid, void *host, void *device,
529 const int width, const int height,
530 const int rowpitch);
531
532int dt_opencl_read_host_from_device_raw(const int devid, void *host, void *device, const size_t *origin,
533 const size_t *region, const int rowpitch, const int blocking);
534
535int dt_opencl_write_host_to_device(const int devid, void *host, void *device, const int width,
536 const int height, const int bpp);
537
538int dt_opencl_write_host_to_device_rowpitch(const int devid, void *host, void *device, const int width,
539 const int height, const int rowpitch);
540
541int dt_opencl_write_host_to_device_non_blocking(const int devid, void *host, void *device, const int width,
542 const int height, const int bpp);
543
544int dt_opencl_write_host_to_device_rowpitch_non_blocking(const int devid, void *host, void *device,
545 const int width, const int height,
546 const int rowpitch);
547
548int dt_opencl_write_host_to_device_raw(const int devid, const void *host, void *device, const size_t *origin,
549 const size_t *region, const int rowpitch, const int blocking);
550
551void *dt_opencl_copy_host_to_device(const int devid, void *host, const int width, const int height,
552 const int bpp);
553
554void *dt_opencl_copy_host_to_device_rowpitch(const int devid, void *host, const int width, const int height,
555 const int bpp, const int rowpitch);
556
557void *dt_opencl_copy_host_to_device_constant(const int devid, const size_t size, void *host);
558
559int dt_opencl_enqueue_copy_image(const int devid, cl_mem src, cl_mem dst, size_t *orig_src, size_t *orig_dst,
560 size_t *region);
561
562void *dt_opencl_alloc_device(const int devid, const int width, const int height, const int bpp);
563
564void *dt_opencl_alloc_device_use_host_pointer(const int devid, const int width, const int height,
565 const int bpp, void *host, const int flags);
566
567int dt_opencl_enqueue_copy_image_to_buffer(const int devid, cl_mem src_image, cl_mem dst_buffer,
568 size_t *origin, size_t *region, size_t offset);
569
570int dt_opencl_enqueue_copy_buffer_to_image(const int devid, cl_mem src_buffer, cl_mem dst_image,
571 size_t offset, size_t *origin, size_t *region);
572
573int dt_opencl_enqueue_copy_buffer_to_buffer(const int devid, cl_mem src_buffer, cl_mem dst_buffer,
574 size_t srcoffset, size_t dstoffset, size_t size);
575
576int dt_opencl_read_buffer_from_device(const int devid, void *host, void *device, const size_t offset,
577 const size_t size, const int blocking);
578
579int dt_opencl_write_buffer_to_device(const int devid, void *host, void *device, const size_t offset,
580 const size_t size, const int blocking);
581
582void *dt_opencl_alloc_device_buffer(const int devid, const size_t size);
583
584void *dt_opencl_alloc_device_buffer_with_flags(const int devid, const size_t size, const int flags, void *host_ptr);
585
586void dt_opencl_release_mem_object(cl_mem mem);
587
588void *dt_opencl_map_buffer(const int devid, cl_mem buffer, const int blocking, const int flags, size_t offset,
589 size_t size);
590
591void *dt_opencl_map_image(const int devid, cl_mem buffer, const int blocking, const int flags, size_t width, size_t height, int bpp);
592
593int dt_opencl_unmap_mem_object(const int devid, cl_mem mem_object, void *mapped_ptr);
594
595size_t dt_opencl_get_mem_object_size(cl_mem mem);
596
597int dt_opencl_get_image_width(cl_mem mem);
598
599int dt_opencl_get_image_height(cl_mem mem);
600
602
603int dt_opencl_get_mem_context_id(cl_mem mem);
604cl_mem_flags dt_opencl_get_mem_flags(cl_mem mem);
605
606// Track a cl_mem allocation/release in the per-device memory accounting.
607// On OPENCL_MEMORY_ADD, pass the byte size that was requested for `mem` on device
608// `devid`; it is recorded so the matching OPENCL_MEMORY_SUB can undo it exactly
609// without ever asking the driver about the object (see mem_sizes in dt_opencl_t).
610// On OPENCL_MEMORY_SUB, `devid` and `size` are ignored -- the recorded values win.
611void dt_opencl_memory_statistics(int devid, cl_mem mem, size_t size, dt_opencl_memory_t action);
612
613// The device and size dt_opencl_memory_statistics() recorded when `mem` was allocated, without
614// asking the driver. FALSE, and nothing written, for an object it never recorded.
615gboolean dt_opencl_get_mem_record(cl_mem mem, int *devid, size_t *size);
616
618gboolean dt_opencl_image_fits_device(const int devid, const size_t width, const size_t height, const unsigned bpp,
619 const float factor, const size_t overhead);
625 const size_t height, const unsigned bpp, const float factor,
626 const size_t overhead, size_t *needed, size_t *limit);
628cl_ulong dt_opencl_get_device_available(const int devid);
629
631void dt_opencl_check_tuning(const int devid);
632
634cl_ulong dt_opencl_get_device_memalloc(const int devid);
635
637int dt_opencl_dev_roundup_width(int size, const int devid);
638int dt_opencl_dev_roundup_height(int size, const int devid);
639
641cl_event *dt_opencl_events_get_slot(const int devid, const char *tag);
642
644void dt_opencl_events_reset(const int devid);
645
648void dt_opencl_events_wait_for(const int devid);
649
652cl_int dt_opencl_events_flush(const int devid, const int reset);
653
655void dt_opencl_events_profiling(const int devid, const int aggregated);
656
658int dt_opencl_local_buffer_opt(const int devid, const int kernel, dt_opencl_local_buffer_t *factors);
659
661void dt_opencl_write_device_config(const int devid);
662gboolean dt_opencl_read_device_config(const int devid);
674gboolean dt_opencl_detected_device_enabled(const int detected);
678int dt_opencl_set_detected_device_enabled(const int detected, const gboolean enabled);
682gboolean dt_opencl_detected_device_pinned_memory(const int detected);
686int dt_opencl_set_detected_device_pinned_memory(const int detected, const gboolean enabled);
690size_t dt_opencl_detected_device_headroom(const int detected);
694int dt_opencl_set_detected_device_headroom(const int detected, const size_t headroom);
695int dt_opencl_avoid_atomics(const int devid);
696int dt_opencl_micro_nap(const int devid);
697gboolean dt_opencl_use_pinned_memory(const int devid);
698gboolean dt_opencl_is_pinned_memory(cl_mem mem);
699
700#ifdef __cplusplus
701}
702#endif
703
704#else
705
706#include "common/conf.h"
707#include <stdlib.h>
708
709#ifdef __cplusplus
710extern "C" {
711#endif
712
713/* Opaque here too, so the type name means the same thing in both configurations: private to
714 * common/opencl.c, and impossible to instantiate anywhere else. In this build there is no
715 * state at all -- every query below is a constant. */
716typedef struct dt_opencl_t dt_opencl_t;
717typedef struct dt_opencl_detected_device_t
718{
719 int config_id;
720 char *name;
721 char *cname;
722 unsigned int cltype;
723 int disabled;
724 int pinned_memory;
725 size_t forced_headroom;
726 // Mirrors dt_opencl_device_t.host_unified_memory -- lets GUI code (preferences) label the
727 // headroom setting accurately for integrated GPUs without reaching into the live device array.
728 gboolean host_unified_memory;
730static inline void dt_opencl_init(const gboolean exclude_opencl, const gboolean print_statistics)
731{
732 /* There is no state to initialise in this build: the queries below are constants. */
733 dt_conf_set_bool("opencl", FALSE);
734 dt_print(DT_DEBUG_OPENCL, "[opencl_init] this version of darktable was built without opencl support\n");
735}
736static inline void dt_opencl_clear_driver_crash_streak(void)
737{
738}
739static inline void dt_opencl_cleanup(void)
740{
741}
742static inline gboolean dt_opencl_finish(const int devid)
743{
744 return -1;
745}
746static inline int dt_opencl_enqueue_barrier(const int devid)
747{
748 return -1;
749}
750static inline int dt_opencl_reserve_device_for_pipe(const int pipetype)
751{
752 return -1;
753}
754static inline void dt_opencl_reserve_device_by_id(const int devid)
755{
756}
757static inline int dt_opencl_try_reserve_device_by_id(const int devid)
758{
759 return 1; // never free: there are no devices
760}
761static inline void dt_opencl_release_device(const int devid)
762{
763}
764static inline int dt_opencl_get_num_devices(void)
765{
766 return 0;
767}
768static inline const char *dt_opencl_get_device_name(const int devid)
769{
770 return NULL;
771}
772static inline gboolean dt_opencl_get_device_max_image_size(const int devid, int *width, int *height)
773{
774 return FALSE;
775}
776static inline size_t dt_opencl_get_device_max_global_mem(const int devid)
777{
778 return 0;
779}
780static inline size_t dt_opencl_get_device_memory_in_use(const int devid)
781{
782 return 0;
783}
784static inline size_t dt_opencl_get_device_headroom(const int devid)
785{
786 return 0;
787}
788static inline int dt_opencl_report_pipe_error(void)
789{
790 return 2;
791}
792static inline int dt_opencl_load_program(const int dev, const char *filename)
793{
794 return -1;
795}
796static inline int dt_opencl_build_program(const int dev, const int program)
797{
798 return -1;
799}
800static inline int dt_opencl_create_kernel(const int program, const char *name)
801{
802 return -1;
803}
804static inline void dt_opencl_free_kernel(const int kernel)
805{
806}
807static inline int dt_opencl_get_max_work_item_sizes(const int dev, size_t *sizes)
808{
809 return -1;
810}
811static inline int dt_opencl_get_work_group_limits(const int dev, size_t *sizes, size_t *workgroupsize,
812 unsigned long *localmemsize)
813{
814 return -1;
815}
816static inline int dt_opencl_get_kernel_work_group_size(const int dev, const int kernel,
817 size_t *kernelworkgroupsize)
818{
819 return -1;
820}
821static inline int dt_opencl_set_kernel_arg(const int dev, const int kernel, const size_t size, const void *arg)
822{
823 return -1;
824}
825static inline int dt_opencl_enqueue_kernel_2d(const int dev, const int kernel, const size_t *sizes)
826{
827 return -1;
828}
829static inline int dt_opencl_enqueue_kernel_2d_with_local(const int dev, const int kernel, const size_t *sizes,
830 const size_t *local)
831{
832 return -1;
833}
834static inline int dt_opencl_is_inited(void)
835{
836 return 0;
837}
838static inline int dt_opencl_is_enabled(void)
839{
840 return 0;
841}
842static inline void dt_opencl_disable(void)
843{
844}
845static inline int dt_opencl_update_settings(void)
846{
847 return 0;
848}
849static inline int dt_opencl_get_detected_device_count(void)
850{
851 return 0;
852}
853static inline const dt_opencl_detected_device_t *dt_opencl_get_detected_device(const int detected)
854{
855 return NULL;
856}
857static inline gboolean dt_opencl_detected_device_enabled(const int detected)
858{
859 return FALSE;
860}
861static inline int dt_opencl_set_detected_device_enabled(const int detected, const gboolean enabled)
862{
863 return -1;
864}
865static inline gboolean dt_opencl_detected_device_pinned_memory(const int detected)
866{
867 return FALSE;
868}
869static inline int dt_opencl_set_detected_device_pinned_memory(const int detected, const gboolean enabled)
870{
871 return -1;
872}
873static inline size_t dt_opencl_detected_device_headroom(const int detected)
874{
875 return 0;
876}
877static inline int dt_opencl_set_detected_device_headroom(const int detected, const size_t headroom)
878{
879 return -1;
880}
881static inline gboolean dt_opencl_image_fits_device(const int devid, const size_t width, const size_t height,
882 const unsigned bpp, const float factor, const size_t overhead)
883{
884 return FALSE;
885}
886static inline size_t dt_opencl_get_device_available(const int devid)
887{
888 return 0;
889}
890static inline void dt_opencl_check_tuning(const int devid)
891{
892 return;
893}
894static inline size_t dt_opencl_get_device_memalloc(const int devid)
895{
896 return 0;
897}
898static inline unsigned long dt_opencl_get_mem_flags(void *mem)
899{
900 return 0;
901}
902static inline void dt_opencl_release_mem_object(void *mem)
903{
904}
905static inline void *dt_opencl_events_get_slot(const int devid, const char *tag)
906{
907 return NULL;
908}
909static inline void dt_opencl_events_reset(const int devid)
910{
911}
912static inline void dt_opencl_events_wait_for(const int devid)
913{
914}
915static inline int dt_opencl_events_flush(const int devid, const int reset)
916{
917 return 0;
918}
919static inline void dt_opencl_events_profiling(const int devid, const int aggregated)
920{
921}
922
923#ifdef __cplusplus
924}
925#endif
926
927#endif
928
929#ifdef __cplusplus
930extern "C" {
931#endif
932
933#ifdef __cplusplus
934}
935#endif
936
937#endif // DT_COMMON_OPENCL_H
938
939// clang-format off
940// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
941// vim: shiftwidth=2 expandtab tabstop=2 cindent
942// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
943// clang-format on
#define FALSE
Definition ashift_lsd.c:158
void dt_conf_set_bool(const char *name, int val)
void reset(dt_view_t *self)
Definition darkroom.c:1222
gboolean enabled
–doc was passed on the command line
int bpp
static float kernel(const float *x, const float *y)
@ DT_DEBUG_OPENCL
Definition logging.h:57
void dt_print(dt_debug_thread_t thread, const char *msg,...) __attribute__((format(printf
Print to stdout when thread is enabled, prefixed with seconds since startup.
uint32_t width
Definition mipmap_cache.c:0
uint32_t height
Definition mipmap_cache.c:1
size_t size
Definition mipmap_cache.c:3
dt_mipmap_buffer_dsc_flags flags
Definition mipmap_cache.c:4
cl_ulong dt_opencl_get_device_available(const int devid)
Definition opencl.c:3203
int dt_opencl_get_kernel_work_group_size(const int dev, const int kernel, size_t *kernelworkgroupsize)
Definition opencl.c:2591
cl_event * dt_opencl_events_get_slot(const int devid, const char *tag)
Definition opencl.c:3391
int dt_opencl_local_buffer_opt(const int devid, const int kernel, dt_opencl_local_buffer_t *factors)
Definition opencl.c:3786
int dt_opencl_enqueue_kernel_2d(const int dev, const int kernel, const size_t *sizes)
Definition opencl.c:2612
void * dt_opencl_alloc_device_buffer(const int devid, const size_t size)
Definition opencl.c:3028
const char * dt_opencl_get_device_name(const int devid)
Human-readable device name, owned by the OpenCL module.
Definition opencl.c:2050
dt_opencl_fit_reason_t dt_opencl_image_fits_device_reason(const int devid, const size_t width, const size_t height, const unsigned bpp, const float factor, const size_t overhead, size_t *needed, size_t *limit)
Definition opencl.c:3259
dt_opencl_memory_t
Definition opencl.h:142
@ OPENCL_MEMORY_ADD
Definition opencl.h:143
@ OPENCL_MEMORY_SUB
Definition opencl.h:144
int dt_opencl_read_host_from_device_rowpitch(const int devid, void *host, void *device, const int width, const int height, const int rowpitch)
Definition opencl.c:2651
void * dt_opencl_alloc_device_use_host_pointer(const int devid, const int width, const int height, const int bpp, void *host, const int flags)
Definition opencl.c:2975
size_t dt_opencl_get_mem_object_size(cl_mem mem)
Definition opencl.c:3034
gboolean dt_opencl_is_pinned_memory(cl_mem mem)
Definition opencl.c:238
int dt_opencl_enqueue_copy_buffer_to_image(const int devid, cl_mem src_buffer, cl_mem dst_image, size_t offset, size_t *origin, size_t *region)
Definition opencl.c:2760
void dt_opencl_events_reset(const int devid)
Definition opencl.c:3489
cl_int dt_opencl_events_flush(const int devid, const int reset)
Definition opencl.c:3584
int dt_opencl_finish(const int devid)
Definition opencl.c:1712
void dt_opencl_note_crash_backtrace(const char *backtrace, size_t backtrace_len)
Tell the OpenCL module that the process crashed, and let it judge whether the crash was its driver's ...
Definition opencl.c:1243
int dt_opencl_copy_device_to_host(const int devid, void *host, void *device, const int width, const int height, const int bpp)
Definition opencl.c:2639
gboolean dt_opencl_read_device_config(const int devid)
Definition opencl.c:294
void dt_opencl_check_tuning(const int devid)
Definition opencl.c:3186
void * dt_opencl_alloc_device(const int devid, const int width, const int height, const int bpp)
Definition opencl.c:2952
int dt_opencl_is_inited(void)
Definition opencl.c:3328
void * dt_opencl_copy_host_to_device_constant(const int devid, const size_t size, void *host)
Definition opencl.c:2808
dt_opencl_pinmode_t
Definition opencl.h:158
@ DT_OPENCL_PINNING_DISABLED
Definition opencl.h:161
@ DT_OPENCL_PINNING_OFF
Definition opencl.h:159
@ DT_OPENCL_PINNING_ON
Definition opencl.h:160
int dt_opencl_dev_roundup_height(int size, const int devid)
Definition opencl.c:3321
void * dt_opencl_copy_host_to_device_rowpitch(const int devid, void *host, const int width, const int height, const int bpp, const int rowpitch)
Definition opencl.c:2829
int dt_opencl_write_host_to_device_rowpitch(const int devid, void *host, void *device, const int width, const int height, const int rowpitch)
Definition opencl.c:2698
int dt_opencl_dev_roundup_width(int size, const int devid)
Definition opencl.c:3316
void dt_opencl_write_device_config(const int devid)
Definition opencl.c:244
void dt_opencl_cleanup(void)
Definition opencl.c:1642
int dt_opencl_get_mem_context_id(cl_mem mem)
Definition opencl.c:3044
int dt_opencl_create_kernel(const int program, const char *name)
Definition opencl.c:2506
int dt_opencl_write_host_to_device_non_blocking(const int devid, void *host, void *device, const int width, const int height, const int bpp)
Definition opencl.c:2708
int dt_opencl_load_program(const int dev, const int prog, const char *filename, const char *binname, const char *cachedir, char *md5sum, char **includemd5, int *loaded_cached)
Definition opencl.c:2180
dt_opencl_fit_reason_t
Definition opencl.h:169
@ DT_OPENCL_FIT_ALLOC_LIMIT
Definition opencl.h:172
@ DT_OPENCL_FIT_AVAILABLE
Definition opencl.h:173
@ DT_OPENCL_FIT_DIMENSION
Definition opencl.h:171
@ DT_OPENCL_FIT_UNINITED
Definition opencl.h:174
@ DT_OPENCL_FIT_OK
Definition opencl.h:170
void * dt_opencl_map_buffer(const int devid, cl_mem buffer, const int blocking, const int flags, size_t offset, size_t size)
Definition opencl.c:2876
int dt_opencl_report_pipe_error(void)
Record that a pipe run failed on OpenCL, and decide whether to give up on it.
Definition opencl.c:2093
int dt_opencl_get_image_height(cl_mem mem)
Definition opencl.c:3082
void dt_opencl_reserve_device_by_id(const int devid)
Reserve a device the caller has already identified, blocking until it is free.
Definition opencl.c:2024
size_t dt_opencl_get_device_headroom(const int devid)
Bytes of the device left to other applications (its forced_headroom, from its own config key or memor...
Definition opencl.c:2084
int dt_opencl_read_host_from_device_rowpitch_non_blocking(const int devid, void *host, void *device, const int width, const int height, const int rowpitch)
Definition opencl.c:2668
int dt_opencl_write_buffer_to_device(const int devid, void *host, void *device, const size_t offset, const size_t size, const int blocking)
Definition opencl.c:2796
int dt_opencl_micro_nap(const int devid)
Definition opencl.c:225
size_t dt_opencl_get_device_memory_in_use(const int devid)
Bytes Ansel holds on the device by its own accounting (dt_opencl_memory_statistics()),...
Definition opencl.c:2076
int dt_opencl_enqueue_copy_image(const int devid, cl_mem src, cl_mem dst, size_t *orig_src, size_t *orig_dst, size_t *region)
Definition opencl.c:2737
gboolean dt_opencl_get_device_max_image_size(const int devid, int *width, int *height)
Largest 2D image the device will accept, which is what bounds tile size.
Definition opencl.c:2058
int dt_opencl_set_detected_device_enabled(const int detected, const gboolean enabled)
Definition opencl.c:428
int dt_opencl_try_reserve_device_by_id(const int devid)
Reserve a device only if it is free right now.
Definition opencl.c:2035
int dt_opencl_read_buffer_from_device(const int devid, void *host, void *device, const size_t offset, const size_t size, const int blocking)
Definition opencl.c:2785
int dt_opencl_build_program(const int dev, const int prog, const char *binname, const char *cachedir, char *md5sum, int loaded_cached)
Definition opencl.c:2362
int dt_opencl_get_max_work_item_sizes(const int dev, size_t *sizes)
Definition opencl.c:2563
void dt_opencl_clear_driver_crash_streak(void)
Definition opencl.c:1616
int dt_opencl_enqueue_barrier(const int devid)
Definition opencl.c:1726
gboolean dt_opencl_image_fits_device(const int devid, const size_t width, const size_t height, const unsigned bpp, const float factor, const size_t overhead)
Definition opencl.c:3308
int dt_opencl_unmap_mem_object(const int devid, cl_mem mem_object, void *mapped_ptr)
Definition opencl.c:2910
int dt_opencl_read_host_from_device_raw(const int devid, void *host, void *device, const size_t *origin, const size_t *region, const int rowpitch, const int blocking)
Definition opencl.c:2680
gboolean dt_opencl_detected_device_pinned_memory(const int detected)
Definition opencl.c:460
int dt_opencl_reserve_device_for_pipe(const int pipetype)
Reserve a device for a pipe run: choose a free one by the pipe's priority list and take its lock....
Definition opencl.c:1928
int dt_opencl_set_detected_device_headroom(const int detected, const size_t headroom)
Definition opencl.c:506
int dt_opencl_is_enabled(void)
Definition opencl.c:3335
void dt_opencl_memory_statistics(int devid, cl_mem mem, size_t size, dt_opencl_memory_t action)
Definition opencl.c:3111
void dt_opencl_md5sum(const char **files, char **md5sums)
Definition opencl.c:2126
void dt_opencl_free_kernel(const int kernel)
Definition opencl.c:2549
gboolean dt_opencl_use_pinned_memory(const int devid)
Definition opencl.c:231
int dt_opencl_get_image_width(cl_mem mem)
Definition opencl.c:3071
cl_ulong dt_opencl_get_device_memalloc(const int devid)
Definition opencl.c:3253
#define DT_OPENCL_EVENTNAMELENGTH
Definition opencl.h:49
int dt_opencl_read_host_from_device_non_blocking(const int devid, void *host, void *device, const int width, const int height, const int bpp)
Definition opencl.c:2661
int dt_opencl_get_detected_device_count(void)
Definition opencl.c:399
void * dt_opencl_map_image(const int devid, cl_mem buffer, const int blocking, const int flags, size_t width, size_t height, int bpp)
Definition opencl.c:2890
#define DT_OPENCL_MAX_PROGRAMS
Definition opencl.h:46
void * dt_opencl_alloc_device_buffer_with_flags(const int devid, const size_t size, const int flags, void *host_ptr)
Definition opencl.c:2998
int dt_opencl_write_host_to_device_rowpitch_non_blocking(const int devid, void *host, void *device, const int width, const int height, const int rowpitch)
Definition opencl.c:2714
int dt_opencl_set_kernel_arg(const int dev, const int kernel, const int num, const size_t size, const void *arg)
Definition opencl.c:2603
int dt_opencl_enqueue_copy_image_to_buffer(const int devid, cl_mem src_image, cl_mem dst_buffer, size_t *origin, size_t *region, size_t offset)
Definition opencl.c:2748
int dt_opencl_update_settings(void)
Definition opencl.c:3352
size_t dt_opencl_get_device_max_global_mem(const int devid)
Total device memory in bytes, or 0 for an out-of-range id.
Definition opencl.c:2068
void dt_opencl_events_wait_for(const int devid)
Definition opencl.c:3527
int dt_opencl_set_detected_device_pinned_memory(const int detected, const gboolean enabled)
Definition opencl.c:473
int dt_opencl_read_host_from_device(const int devid, void *host, void *device, const int width, const int height, const int bpp)
Definition opencl.c:2645
void dt_opencl_events_profiling(const int devid, const int aggregated)
Definition opencl.c:3687
void dt_opencl_release_device(const int devid)
Release a device reserved by either reserve function.
Definition opencl.c:2013
int dt_opencl_get_work_group_limits(const int dev, size_t *sizes, size_t *workgroupsize, unsigned long *localmemsize)
Definition opencl.c:2571
int dt_opencl_enqueue_kernel_2d_with_local(const int dev, const int kernel, const size_t *sizes, const size_t *local)
Definition opencl.c:2618
cl_mem_flags dt_opencl_get_mem_flags(cl_mem mem)
Definition opencl.c:3062
int dt_opencl_enqueue_copy_buffer_to_buffer(const int devid, cl_mem src_buffer, cl_mem dst_buffer, size_t srcoffset, size_t dstoffset, size_t size)
Definition opencl.c:2772
const dt_opencl_detected_device_t * dt_opencl_get_detected_device(const int detected)
Definition opencl.c:407
void * dt_opencl_copy_host_to_device(const int devid, void *host, const int width, const int height, const int bpp)
Definition opencl.c:2823
int dt_opencl_write_host_to_device_raw(const int devid, const void *host, void *device, const size_t *origin, const size_t *region, const int rowpitch, const int blocking)
Definition opencl.c:2725
size_t dt_opencl_detected_device_headroom(const int detected)
Definition opencl.c:494
#define DT_OPENCL_MAX_KERNELS
Definition opencl.h:47
void dt_opencl_release_mem_object(cl_mem mem)
Definition opencl.c:2863
void dt_opencl_init(const gboolean exclude_opencl, const gboolean print_statistics)
Definition opencl.c:1301
int dt_opencl_get_image_element_size(cl_mem mem)
Definition opencl.c:3093
int dt_opencl_get_num_devices(void)
Number of usable OpenCL devices; 0 when OpenCL is unavailable.
Definition opencl.c:2043
gboolean dt_opencl_detected_device_enabled(const int detected)
Definition opencl.c:415
gboolean dt_opencl_get_mem_record(cl_mem mem, int *devid, size_t *size)
Definition opencl.c:3171
int dt_opencl_avoid_atomics(const int devid)
Definition opencl.c:219
int dt_opencl_write_host_to_device(const int devid, void *host, void *device, const int width, const int height, const int bpp)
Definition opencl.c:2692
void dt_opencl_disable(void)
Definition opencl.c:3343
const float factor
Definition pdf.h:91
const char * name
Definition pdf.h:90
The three colorspace kernels, compiled once and held by common/opencl.c.
size_t forced_headroom
Definition opencl.h:283
gboolean host_unified_memory
Definition opencl.h:279
unsigned int cltype
Definition opencl.h:256
const char * runtime_id
Definition opencl.h:216
const char * name
Definition opencl.h:217
size_t used_available
Definition opencl.h:224
cl_event * eventlist
Definition opencl.h:196
cl_command_queue cmd_queue
Definition opencl.h:186
cl_context context
Definition opencl.h:185
const char * options_md5
Definition opencl.h:220
cl_ulong max_mem_alloc
Definition opencl.h:189
cl_ulong max_global_mem
Definition opencl.h:190
size_t max_image_width
Definition opencl.h:187
cl_ulong used_global_mem
Definition opencl.h:191
cl_device_id devid
Definition opencl.h:184
int program_used[256]
Definition opencl.h:194
dt_pthread_mutex_t lock
Definition opencl.h:183
size_t peak_memory
Definition opencl.h:223
cl_kernel kernel[512]
Definition opencl.h:193
int kernel_used[512]
Definition opencl.h:195
size_t max_image_height
Definition opencl.h:188
cl_program program[256]
Definition opencl.h:192
size_t memory_in_use
Definition opencl.h:222
const char * vendor
Definition opencl.h:207
dt_opencl_eventtag_t * eventtags
Definition opencl.h:197
const char * options
Definition opencl.h:219
unsigned int vendor_id
Definition opencl.h:210
const char * cname
Definition opencl.h:218
cl_ulong timelapsed
Definition opencl.h:153
const size_t cellsize
Definition opencl.h:330
const size_t overhead
Definition opencl.h:331