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 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
450
453void dt_opencl_release_device(const int devid);
454
456void dt_opencl_md5sum(const char **files, char **md5sums);
457
459int dt_opencl_load_program(const int dev, const int prog, const char *filename, const char *binname,
460 const char *cachedir, char *md5sum, char **includemd5, int *loaded_cached);
461
463int dt_opencl_build_program(const int dev, const int prog, const char *binname, const char *cachedir,
464 char *md5sum, int loaded_cached);
465
467int dt_opencl_create_kernel(const int program, const char *name);
468
470void dt_opencl_free_kernel(const int kernel);
471
473int dt_opencl_get_max_work_item_sizes(const int dev, size_t *sizes);
474
476int dt_opencl_get_work_group_limits(const int dev, size_t *sizes, size_t *workgroupsize,
477 unsigned long *localmemsize);
478
480int dt_opencl_get_kernel_work_group_size(const int dev, const int kernel, size_t *kernelworkgroupsize);
481
483int dt_opencl_set_kernel_arg(const int dev, const int kernel, const int num, const size_t size,
484 const void *arg);
485
487int dt_opencl_enqueue_kernel_2d(const int dev, const int kernel, const size_t *sizes);
488
490int dt_opencl_enqueue_kernel_2d_with_local(const int dev, const int kernel, const size_t *sizes,
491 const size_t *local);
492
494int dt_opencl_is_inited(void);
495
496
498int dt_opencl_is_enabled(void);
499
501void dt_opencl_disable(void);
502
505
507int dt_opencl_copy_device_to_host(const int devid, void *host, void *device, const int width,
508 const int height, const int bpp);
509
510int dt_opencl_read_host_from_device(const int devid, void *host, void *device, const int width,
511 const int height, const int bpp);
512
513int dt_opencl_read_host_from_device_rowpitch(const int devid, void *host, void *device, const int width,
514 const int height, const int rowpitch);
515
516int dt_opencl_read_host_from_device_non_blocking(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_rowpitch_non_blocking(const int devid, void *host, void *device,
520 const int width, const int height,
521 const int rowpitch);
522
523int dt_opencl_read_host_from_device_raw(const int devid, void *host, void *device, const size_t *origin,
524 const size_t *region, const int rowpitch, const int blocking);
525
526int dt_opencl_write_host_to_device(const int devid, void *host, void *device, const int width,
527 const int height, const int bpp);
528
529int dt_opencl_write_host_to_device_rowpitch(const int devid, void *host, void *device, const int width,
530 const int height, const int rowpitch);
531
532int dt_opencl_write_host_to_device_non_blocking(const int devid, void *host, void *device, const int width,
533 const int height, const int bpp);
534
535int dt_opencl_write_host_to_device_rowpitch_non_blocking(const int devid, void *host, void *device,
536 const int width, const int height,
537 const int rowpitch);
538
539int dt_opencl_write_host_to_device_raw(const int devid, const void *host, void *device, const size_t *origin,
540 const size_t *region, const int rowpitch, const int blocking);
541
542void *dt_opencl_copy_host_to_device(const int devid, void *host, const int width, const int height,
543 const int bpp);
544
545void *dt_opencl_copy_host_to_device_rowpitch(const int devid, void *host, const int width, const int height,
546 const int bpp, const int rowpitch);
547
548void *dt_opencl_copy_host_to_device_constant(const int devid, const size_t size, void *host);
549
550int dt_opencl_enqueue_copy_image(const int devid, cl_mem src, cl_mem dst, size_t *orig_src, size_t *orig_dst,
551 size_t *region);
552
553void *dt_opencl_alloc_device(const int devid, const int width, const int height, const int bpp);
554
555void *dt_opencl_alloc_device_use_host_pointer(const int devid, const int width, const int height,
556 const int bpp, void *host, const int flags);
557
558int dt_opencl_enqueue_copy_image_to_buffer(const int devid, cl_mem src_image, cl_mem dst_buffer,
559 size_t *origin, size_t *region, size_t offset);
560
561int dt_opencl_enqueue_copy_buffer_to_image(const int devid, cl_mem src_buffer, cl_mem dst_image,
562 size_t offset, size_t *origin, size_t *region);
563
564int dt_opencl_enqueue_copy_buffer_to_buffer(const int devid, cl_mem src_buffer, cl_mem dst_buffer,
565 size_t srcoffset, size_t dstoffset, size_t size);
566
567int dt_opencl_read_buffer_from_device(const int devid, void *host, void *device, const size_t offset,
568 const size_t size, const int blocking);
569
570int dt_opencl_write_buffer_to_device(const int devid, void *host, void *device, const size_t offset,
571 const size_t size, const int blocking);
572
573void *dt_opencl_alloc_device_buffer(const int devid, const size_t size);
574
575void *dt_opencl_alloc_device_buffer_with_flags(const int devid, const size_t size, const int flags, void *host_ptr);
576
577void dt_opencl_release_mem_object(cl_mem mem);
578
579void *dt_opencl_map_buffer(const int devid, cl_mem buffer, const int blocking, const int flags, size_t offset,
580 size_t size);
581
582void *dt_opencl_map_image(const int devid, cl_mem buffer, const int blocking, const int flags, size_t width, size_t height, int bpp);
583
584int dt_opencl_unmap_mem_object(const int devid, cl_mem mem_object, void *mapped_ptr);
585
586size_t dt_opencl_get_mem_object_size(cl_mem mem);
587
588int dt_opencl_get_image_width(cl_mem mem);
589
590int dt_opencl_get_image_height(cl_mem mem);
591
593
594int dt_opencl_get_mem_context_id(cl_mem mem);
595cl_mem_flags dt_opencl_get_mem_flags(cl_mem mem);
596
597// Track a cl_mem allocation/release in the per-device memory accounting.
598// On OPENCL_MEMORY_ADD, pass the byte size that was requested for `mem` on device
599// `devid`; it is recorded so the matching OPENCL_MEMORY_SUB can undo it exactly
600// without ever asking the driver about the object (see mem_sizes in dt_opencl_t).
601// On OPENCL_MEMORY_SUB, `devid` and `size` are ignored -- the recorded values win.
602void dt_opencl_memory_statistics(int devid, cl_mem mem, size_t size, dt_opencl_memory_t action);
603
605gboolean dt_opencl_image_fits_device(const int devid, const size_t width, const size_t height, const unsigned bpp,
606 const float factor, const size_t overhead);
612 const size_t height, const unsigned bpp, const float factor,
613 const size_t overhead, size_t *needed, size_t *limit);
615cl_ulong dt_opencl_get_device_available(const int devid);
616
618void dt_opencl_check_tuning(const int devid);
619
621cl_ulong dt_opencl_get_device_memalloc(const int devid);
622
624int dt_opencl_dev_roundup_width(int size, const int devid);
625int dt_opencl_dev_roundup_height(int size, const int devid);
626
628cl_event *dt_opencl_events_get_slot(const int devid, const char *tag);
629
631void dt_opencl_events_reset(const int devid);
632
635void dt_opencl_events_wait_for(const int devid);
636
639cl_int dt_opencl_events_flush(const int devid, const int reset);
640
642void dt_opencl_events_profiling(const int devid, const int aggregated);
643
645int dt_opencl_local_buffer_opt(const int devid, const int kernel, dt_opencl_local_buffer_t *factors);
646
648void dt_opencl_write_device_config(const int devid);
649gboolean dt_opencl_read_device_config(const int devid);
661gboolean dt_opencl_detected_device_enabled(const int detected);
665int dt_opencl_set_detected_device_enabled(const int detected, const gboolean enabled);
669gboolean dt_opencl_detected_device_pinned_memory(const int detected);
673int dt_opencl_set_detected_device_pinned_memory(const int detected, const gboolean enabled);
677size_t dt_opencl_detected_device_headroom(const int detected);
681int dt_opencl_set_detected_device_headroom(const int detected, const size_t headroom);
682int dt_opencl_avoid_atomics(const int devid);
683int dt_opencl_micro_nap(const int devid);
684gboolean dt_opencl_use_pinned_memory(const int devid);
685gboolean dt_opencl_is_pinned_memory(cl_mem mem);
686
687#ifdef __cplusplus
688}
689#endif
690
691#else
692
693#include "common/conf.h"
694#include <stdlib.h>
695
696#ifdef __cplusplus
697extern "C" {
698#endif
699
700/* Opaque here too, so the type name means the same thing in both configurations: private to
701 * common/opencl.c, and impossible to instantiate anywhere else. In this build there is no
702 * state at all -- every query below is a constant. */
703typedef struct dt_opencl_t dt_opencl_t;
704typedef struct dt_opencl_detected_device_t
705{
706 int config_id;
707 char *name;
708 char *cname;
709 unsigned int cltype;
710 int disabled;
711 int pinned_memory;
712 size_t forced_headroom;
713 // Mirrors dt_opencl_device_t.host_unified_memory -- lets GUI code (preferences) label the
714 // headroom setting accurately for integrated GPUs without reaching into the live device array.
715 gboolean host_unified_memory;
717static inline void dt_opencl_init(const gboolean exclude_opencl, const gboolean print_statistics)
718{
719 /* There is no state to initialise in this build: the queries below are constants. */
720 dt_conf_set_bool("opencl", FALSE);
721 dt_print(DT_DEBUG_OPENCL, "[opencl_init] this version of darktable was built without opencl support\n");
722}
723static inline void dt_opencl_clear_driver_crash_streak(void)
724{
725}
726static inline void dt_opencl_cleanup(void)
727{
728}
729static inline gboolean dt_opencl_finish(const int devid)
730{
731 return -1;
732}
733static inline int dt_opencl_enqueue_barrier(const int devid)
734{
735 return -1;
736}
737static inline int dt_opencl_reserve_device_for_pipe(const int pipetype)
738{
739 return -1;
740}
741static inline void dt_opencl_reserve_device_by_id(const int devid)
742{
743}
744static inline int dt_opencl_try_reserve_device_by_id(const int devid)
745{
746 return 1; // never free: there are no devices
747}
748static inline void dt_opencl_release_device(const int devid)
749{
750}
751static inline int dt_opencl_get_num_devices(void)
752{
753 return 0;
754}
755static inline const char *dt_opencl_get_device_name(const int devid)
756{
757 return NULL;
758}
759static inline gboolean dt_opencl_get_device_max_image_size(const int devid, int *width, int *height)
760{
761 return FALSE;
762}
763static inline size_t dt_opencl_get_device_max_global_mem(const int devid)
764{
765 return 0;
766}
767static inline int dt_opencl_report_pipe_error(void)
768{
769 return 2;
770}
771static inline int dt_opencl_load_program(const int dev, const char *filename)
772{
773 return -1;
774}
775static inline int dt_opencl_build_program(const int dev, const int program)
776{
777 return -1;
778}
779static inline int dt_opencl_create_kernel(const int program, const char *name)
780{
781 return -1;
782}
783static inline void dt_opencl_free_kernel(const int kernel)
784{
785}
786static inline int dt_opencl_get_max_work_item_sizes(const int dev, size_t *sizes)
787{
788 return -1;
789}
790static inline int dt_opencl_get_work_group_limits(const int dev, size_t *sizes, size_t *workgroupsize,
791 unsigned long *localmemsize)
792{
793 return -1;
794}
795static inline int dt_opencl_get_kernel_work_group_size(const int dev, const int kernel,
796 size_t *kernelworkgroupsize)
797{
798 return -1;
799}
800static inline int dt_opencl_set_kernel_arg(const int dev, const int kernel, const size_t size, const void *arg)
801{
802 return -1;
803}
804static inline int dt_opencl_enqueue_kernel_2d(const int dev, const int kernel, const size_t *sizes)
805{
806 return -1;
807}
808static inline int dt_opencl_enqueue_kernel_2d_with_local(const int dev, const int kernel, const size_t *sizes,
809 const size_t *local)
810{
811 return -1;
812}
813static inline int dt_opencl_is_inited(void)
814{
815 return 0;
816}
817static inline int dt_opencl_is_enabled(void)
818{
819 return 0;
820}
821static inline void dt_opencl_disable(void)
822{
823}
824static inline int dt_opencl_update_settings(void)
825{
826 return 0;
827}
828static inline int dt_opencl_get_detected_device_count(void)
829{
830 return 0;
831}
832static inline const dt_opencl_detected_device_t *dt_opencl_get_detected_device(const int detected)
833{
834 return NULL;
835}
836static inline gboolean dt_opencl_detected_device_enabled(const int detected)
837{
838 return FALSE;
839}
840static inline int dt_opencl_set_detected_device_enabled(const int detected, const gboolean enabled)
841{
842 return -1;
843}
844static inline gboolean dt_opencl_detected_device_pinned_memory(const int detected)
845{
846 return FALSE;
847}
848static inline int dt_opencl_set_detected_device_pinned_memory(const int detected, const gboolean enabled)
849{
850 return -1;
851}
852static inline size_t dt_opencl_detected_device_headroom(const int detected)
853{
854 return 0;
855}
856static inline int dt_opencl_set_detected_device_headroom(const int detected, const size_t headroom)
857{
858 return -1;
859}
860static inline gboolean dt_opencl_image_fits_device(const int devid, const size_t width, const size_t height,
861 const unsigned bpp, const float factor, const size_t overhead)
862{
863 return FALSE;
864}
865static inline size_t dt_opencl_get_device_available(const int devid)
866{
867 return 0;
868}
869static inline void dt_opencl_check_tuning(const int devid)
870{
871 return;
872}
873static inline size_t dt_opencl_get_device_memalloc(const int devid)
874{
875 return 0;
876}
877static inline unsigned long dt_opencl_get_mem_flags(void *mem)
878{
879 return 0;
880}
881static inline void dt_opencl_release_mem_object(void *mem)
882{
883}
884static inline void *dt_opencl_events_get_slot(const int devid, const char *tag)
885{
886 return NULL;
887}
888static inline void dt_opencl_events_reset(const int devid)
889{
890}
891static inline void dt_opencl_events_wait_for(const int devid)
892{
893}
894static inline int dt_opencl_events_flush(const int devid, const int reset)
895{
896 return 0;
897}
898static inline void dt_opencl_events_profiling(const int devid, const int aggregated)
899{
900}
901
902#ifdef __cplusplus
903}
904#endif
905
906#endif
907
908#ifdef __cplusplus
909extern "C" {
910#endif
911
912#ifdef __cplusplus
913}
914#endif
915
916#endif // DT_COMMON_OPENCL_H
917
918// clang-format off
919// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
920// vim: shiftwidth=2 expandtab tabstop=2 cindent
921// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
922// 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:3130
int dt_opencl_get_kernel_work_group_size(const int dev, const int kernel, size_t *kernelworkgroupsize)
Definition opencl.c:2533
cl_event * dt_opencl_events_get_slot(const int devid, const char *tag)
Definition opencl.c:3318
int dt_opencl_local_buffer_opt(const int devid, const int kernel, dt_opencl_local_buffer_t *factors)
Definition opencl.c:3713
int dt_opencl_enqueue_kernel_2d(const int dev, const int kernel, const size_t *sizes)
Definition opencl.c:2554
void * dt_opencl_alloc_device_buffer(const int devid, const size_t size)
Definition opencl.c:2970
const char * dt_opencl_get_device_name(const int devid)
Human-readable device name, owned by the OpenCL module.
Definition opencl.c:2009
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:3186
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:2593
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:2917
size_t dt_opencl_get_mem_object_size(cl_mem mem)
Definition opencl.c:2976
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:2702
void dt_opencl_events_reset(const int devid)
Definition opencl.c:3416
cl_int dt_opencl_events_flush(const int devid, const int reset)
Definition opencl.c:3511
int dt_opencl_finish(const int devid)
Definition opencl.c:1671
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:1202
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:2581
gboolean dt_opencl_read_device_config(const int devid)
Definition opencl.c:294
void dt_opencl_check_tuning(const int devid)
Definition opencl.c:3113
void * dt_opencl_alloc_device(const int devid, const int width, const int height, const int bpp)
Definition opencl.c:2894
int dt_opencl_is_inited(void)
Definition opencl.c:3255
void * dt_opencl_copy_host_to_device_constant(const int devid, const size_t size, void *host)
Definition opencl.c:2750
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:3248
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:2771
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:2640
int dt_opencl_dev_roundup_width(int size, const int devid)
Definition opencl.c:3243
void dt_opencl_write_device_config(const int devid)
Definition opencl.c:244
void dt_opencl_cleanup(void)
Definition opencl.c:1601
int dt_opencl_get_mem_context_id(cl_mem mem)
Definition opencl.c:2986
int dt_opencl_create_kernel(const int program, const char *name)
Definition opencl.c:2448
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:2650
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:2122
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:2818
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:2035
int dt_opencl_get_image_height(cl_mem mem)
Definition opencl.c:3024
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:1983
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:2610
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:2738
int dt_opencl_micro_nap(const int devid)
Definition opencl.c:225
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:2679
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:2017
int dt_opencl_set_detected_device_enabled(const int detected, const gboolean enabled)
Definition opencl.c:387
int dt_opencl_try_reserve_device_by_id(const int devid)
Reserve a device only if it is free right now.
Definition opencl.c:1994
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:2727
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:2304
int dt_opencl_get_max_work_item_sizes(const int dev, size_t *sizes)
Definition opencl.c:2505
void dt_opencl_clear_driver_crash_streak(void)
Definition opencl.c:1575
int dt_opencl_enqueue_barrier(const int devid)
Definition opencl.c:1685
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:3235
int dt_opencl_unmap_mem_object(const int devid, cl_mem mem_object, void *mapped_ptr)
Definition opencl.c:2852
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:2622
gboolean dt_opencl_detected_device_pinned_memory(const int detected)
Definition opencl.c:419
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:1887
int dt_opencl_set_detected_device_headroom(const int detected, const size_t headroom)
Definition opencl.c:465
int dt_opencl_is_enabled(void)
Definition opencl.c:3262
void dt_opencl_memory_statistics(int devid, cl_mem mem, size_t size, dt_opencl_memory_t action)
Definition opencl.c:3053
void dt_opencl_md5sum(const char **files, char **md5sums)
Definition opencl.c:2068
void dt_opencl_free_kernel(const int kernel)
Definition opencl.c:2491
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:3013
cl_ulong dt_opencl_get_device_memalloc(const int devid)
Definition opencl.c:3180
#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:2603
int dt_opencl_get_detected_device_count(void)
Definition opencl.c:358
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:2832
#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:2940
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:2656
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:2545
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:2690
int dt_opencl_update_settings(void)
Definition opencl.c:3279
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:2027
void dt_opencl_events_wait_for(const int devid)
Definition opencl.c:3454
int dt_opencl_set_detected_device_pinned_memory(const int detected, const gboolean enabled)
Definition opencl.c:432
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:2587
void dt_opencl_events_profiling(const int devid, const int aggregated)
Definition opencl.c:3614
void dt_opencl_release_device(const int devid)
Release a device reserved by either reserve function.
Definition opencl.c:1972
int dt_opencl_get_work_group_limits(const int dev, size_t *sizes, size_t *workgroupsize, unsigned long *localmemsize)
Definition opencl.c:2513
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:2560
cl_mem_flags dt_opencl_get_mem_flags(cl_mem mem)
Definition opencl.c:3004
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:2714
const dt_opencl_detected_device_t * dt_opencl_get_detected_device(const int detected)
Definition opencl.c:366
void * dt_opencl_copy_host_to_device(const int devid, void *host, const int width, const int height, const int bpp)
Definition opencl.c:2765
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:2667
size_t dt_opencl_detected_device_headroom(const int detected)
Definition opencl.c:453
#define DT_OPENCL_MAX_KERNELS
Definition opencl.h:47
void dt_opencl_release_mem_object(cl_mem mem)
Definition opencl.c:2805
void dt_opencl_init(const gboolean exclude_opencl, const gboolean print_statistics)
Definition opencl.c:1260
int dt_opencl_get_image_element_size(cl_mem mem)
Definition opencl.c:3035
int dt_opencl_get_num_devices(void)
Number of usable OpenCL devices; 0 when OpenCL is unavailable.
Definition opencl.c:2002
gboolean dt_opencl_detected_device_enabled(const int detected)
Definition opencl.c:374
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:2634
void dt_opencl_disable(void)
Definition opencl.c:3270
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