38#ifndef DT_COMMON_OPENCL_H
39#define DT_COMMON_OPENCL_H
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
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
61#define DT_OPENCL_DEFAULT_ERROR -999
62#define DT_OPENCL_SYSMEM_ALLOCATION -998
82#define ROUNDUP(a, n) ((a) % (n) == 0 ? (a) : ((a) / (n)+1) * (n))
85#define ROUNDUPDWD(a, b) dt_opencl_dev_roundup_width(a, b)
86#define ROUNDUPDHT(a, b) dt_opencl_dev_roundup_height(a, b)
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))
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")
362void dt_opencl_init(
const gboolean exclude_opencl,
const gboolean print_statistics);
460 const char *cachedir,
char *md5sum,
char **includemd5,
int *loaded_cached);
464 char *md5sum,
int loaded_cached);
477 unsigned long *localmemsize);
491 const size_t *local);
514 const int height,
const int rowpitch);
524 const size_t *region,
const int rowpitch,
const int blocking);
530 const int height,
const int rowpitch);
540 const size_t *region,
const int rowpitch,
const int blocking);
546 const int bpp,
const int rowpitch);
556 const int bpp,
void *host,
const int flags);
559 size_t *origin,
size_t *region,
size_t offset);
562 size_t offset,
size_t *origin,
size_t *region);
565 size_t srcoffset,
size_t dstoffset,
size_t size);
568 const size_t size,
const int blocking);
571 const size_t size,
const int blocking);
606 const float factor,
const size_t overhead);
613 const size_t overhead,
size_t *needed,
size_t *limit);
717static inline void dt_opencl_init(
const gboolean exclude_opencl,
const gboolean print_statistics)
791 unsigned long *localmemsize)
796 size_t *kernelworkgroupsize)
861 const unsigned bpp,
const float factor,
const size_t overhead)
void dt_conf_set_bool(const char *name, int val)
void reset(dt_view_t *self)
gboolean enabled
–doc was passed on the command line
static float kernel(const float *x, const float *y)
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.
dt_mipmap_buffer_dsc_flags flags
cl_ulong dt_opencl_get_device_available(const int devid)
int dt_opencl_get_kernel_work_group_size(const int dev, const int kernel, size_t *kernelworkgroupsize)
cl_event * dt_opencl_events_get_slot(const int devid, const char *tag)
int dt_opencl_local_buffer_opt(const int devid, const int kernel, dt_opencl_local_buffer_t *factors)
int dt_opencl_enqueue_kernel_2d(const int dev, const int kernel, const size_t *sizes)
void * dt_opencl_alloc_device_buffer(const int devid, const size_t size)
const char * dt_opencl_get_device_name(const int devid)
Human-readable device name, owned by the OpenCL module.
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)
int dt_opencl_read_host_from_device_rowpitch(const int devid, void *host, void *device, const int width, const int height, const int rowpitch)
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)
size_t dt_opencl_get_mem_object_size(cl_mem mem)
gboolean dt_opencl_is_pinned_memory(cl_mem mem)
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)
void dt_opencl_events_reset(const int devid)
cl_int dt_opencl_events_flush(const int devid, const int reset)
int dt_opencl_finish(const int devid)
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 ...
int dt_opencl_copy_device_to_host(const int devid, void *host, void *device, const int width, const int height, const int bpp)
gboolean dt_opencl_read_device_config(const int devid)
void dt_opencl_check_tuning(const int devid)
void * dt_opencl_alloc_device(const int devid, const int width, const int height, const int bpp)
int dt_opencl_is_inited(void)
void * dt_opencl_copy_host_to_device_constant(const int devid, const size_t size, void *host)
@ DT_OPENCL_PINNING_DISABLED
int dt_opencl_dev_roundup_height(int size, const int devid)
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)
int dt_opencl_write_host_to_device_rowpitch(const int devid, void *host, void *device, const int width, const int height, const int rowpitch)
int dt_opencl_dev_roundup_width(int size, const int devid)
void dt_opencl_write_device_config(const int devid)
void dt_opencl_cleanup(void)
int dt_opencl_get_mem_context_id(cl_mem mem)
int dt_opencl_create_kernel(const int program, const char *name)
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)
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)
@ DT_OPENCL_FIT_ALLOC_LIMIT
@ DT_OPENCL_FIT_AVAILABLE
@ DT_OPENCL_FIT_DIMENSION
void * dt_opencl_map_buffer(const int devid, cl_mem buffer, const int blocking, const int flags, size_t offset, size_t size)
int dt_opencl_report_pipe_error(void)
Record that a pipe run failed on OpenCL, and decide whether to give up on it.
int dt_opencl_get_image_height(cl_mem mem)
void dt_opencl_reserve_device_by_id(const int devid)
Reserve a device the caller has already identified, blocking until it is free.
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)
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)
int dt_opencl_micro_nap(const int devid)
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)
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.
int dt_opencl_set_detected_device_enabled(const int detected, const gboolean enabled)
int dt_opencl_try_reserve_device_by_id(const int devid)
Reserve a device only if it is free right now.
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)
int dt_opencl_build_program(const int dev, const int prog, const char *binname, const char *cachedir, char *md5sum, int loaded_cached)
int dt_opencl_get_max_work_item_sizes(const int dev, size_t *sizes)
void dt_opencl_clear_driver_crash_streak(void)
int dt_opencl_enqueue_barrier(const int devid)
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)
int dt_opencl_unmap_mem_object(const int devid, cl_mem mem_object, void *mapped_ptr)
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)
gboolean dt_opencl_detected_device_pinned_memory(const int detected)
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....
int dt_opencl_set_detected_device_headroom(const int detected, const size_t headroom)
int dt_opencl_is_enabled(void)
void dt_opencl_memory_statistics(int devid, cl_mem mem, size_t size, dt_opencl_memory_t action)
void dt_opencl_md5sum(const char **files, char **md5sums)
void dt_opencl_free_kernel(const int kernel)
gboolean dt_opencl_use_pinned_memory(const int devid)
int dt_opencl_get_image_width(cl_mem mem)
cl_ulong dt_opencl_get_device_memalloc(const int devid)
#define DT_OPENCL_EVENTNAMELENGTH
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)
int dt_opencl_get_detected_device_count(void)
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)
#define DT_OPENCL_MAX_PROGRAMS
void * dt_opencl_alloc_device_buffer_with_flags(const int devid, const size_t size, const int flags, void *host_ptr)
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)
int dt_opencl_set_kernel_arg(const int dev, const int kernel, const int num, const size_t size, const void *arg)
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)
int dt_opencl_update_settings(void)
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.
void dt_opencl_events_wait_for(const int devid)
int dt_opencl_set_detected_device_pinned_memory(const int detected, const gboolean enabled)
int dt_opencl_read_host_from_device(const int devid, void *host, void *device, const int width, const int height, const int bpp)
void dt_opencl_events_profiling(const int devid, const int aggregated)
void dt_opencl_release_device(const int devid)
Release a device reserved by either reserve function.
int dt_opencl_get_work_group_limits(const int dev, size_t *sizes, size_t *workgroupsize, unsigned long *localmemsize)
int dt_opencl_enqueue_kernel_2d_with_local(const int dev, const int kernel, const size_t *sizes, const size_t *local)
cl_mem_flags dt_opencl_get_mem_flags(cl_mem mem)
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)
const dt_opencl_detected_device_t * dt_opencl_get_detected_device(const int detected)
void * dt_opencl_copy_host_to_device(const int devid, void *host, const int width, const int height, const int bpp)
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)
size_t dt_opencl_detected_device_headroom(const int detected)
#define DT_OPENCL_MAX_KERNELS
void dt_opencl_release_mem_object(cl_mem mem)
void dt_opencl_init(const gboolean exclude_opencl, const gboolean print_statistics)
int dt_opencl_get_image_element_size(cl_mem mem)
int dt_opencl_get_num_devices(void)
Number of usable OpenCL devices; 0 when OpenCL is unavailable.
gboolean dt_opencl_detected_device_enabled(const int detected)
int dt_opencl_avoid_atomics(const int devid)
int dt_opencl_write_host_to_device(const int devid, void *host, void *device, const int width, const int height, const int bpp)
void dt_opencl_disable(void)
The three colorspace kernels, compiled once and held by common/opencl.c.
gboolean host_unified_memory
gboolean host_unified_memory
cl_command_queue cmd_queue
dt_opencl_eventtag_t * eventtags