76
85
void dt_opencl_cleanup(dt_opencl_t *cl);
78
87
/** cleans up command queue. */
79
void dt_opencl_finish(cl_command_queue q);
88
int dt_opencl_finish(const int devid);
90
/** enqueues a synchronization point. */
91
int dt_opencl_enqueue_barrier(const int devid);
81
93
/** locks a device for your thread's exclusive use. blocks if it's busy. pass -1 to let dt chose a device.
82
94
* always use the devid returned, in case you didn't get your request! */
83
int dt_opencl_lock_device(dt_opencl_t *cl, const int dev);
95
int dt_opencl_lock_device(const int dev);
85
97
/** done with your command queue. */
86
void dt_opencl_unlock_device(dt_opencl_t *cl, const int dev);
98
void dt_opencl_unlock_device(const int dev);
88
100
/** loads the given .cl file and returns a reference to an internal program. */
89
int dt_opencl_load_program(dt_opencl_t *cl, const int dev, const char *filename);
101
int dt_opencl_load_program(const int dev, const char *filename);
91
103
/** builds the given program. */
92
int dt_opencl_build_program(dt_opencl_t *cl, const int dev, const int program);
104
int dt_opencl_build_program(const int dev, const int program);
94
106
/** inits a kernel. returns the index or -1 if fail. */
95
int dt_opencl_create_kernel(dt_opencl_t *cl, const int program, const char *name);
107
int dt_opencl_create_kernel(const int program, const char *name);
97
109
/** releases kernel resources again. */
98
void dt_opencl_free_kernel(dt_opencl_t *cl, const int kernel);
110
void dt_opencl_free_kernel(const int kernel);
100
112
/** return max size in sizes[3]. */
101
int dt_opencl_get_max_work_item_sizes(dt_opencl_t *cl, const int dev, size_t *sizes);
113
int dt_opencl_get_max_work_item_sizes(const int dev, size_t *sizes);
103
115
/** attach arg. */
104
int dt_opencl_set_kernel_arg(dt_opencl_t *cl, const int dev, const int kernel, const int num, const size_t size, const void *arg);
116
int dt_opencl_set_kernel_arg(const int dev, const int kernel, const int num, const size_t size, const void *arg);
106
118
/** launch kernel! */
107
int dt_opencl_enqueue_kernel_2d(dt_opencl_t *cl, const int dev, const int kernel, const size_t *sizes);
119
int dt_opencl_enqueue_kernel_2d(const int dev, const int kernel, const size_t *sizes);
109
121
/** check if opencl is inited */
110
122
int dt_opencl_is_inited(void);
116
128
void dt_opencl_disable(void);
118
130
/** update enabled flag with value from preferences */
119
void dt_opencl_update_enabled(void);
131
int dt_opencl_update_enabled(void);
121
133
/** HAVE_OPENCL mode only: copy and alloc buffers. */
122
int dt_opencl_copy_device_to_host(void *host, void *device, const int width, const int height, const int devid, const int bpp);
124
void* dt_opencl_copy_host_to_device(void *host, const int width, const int height, const int devid, const int bpp);
126
void* dt_opencl_copy_host_to_device_constant(const int size, const int devid, void *host);
128
int dt_opencl_enqueue_copy_image(cl_command_queue q, cl_mem src, cl_mem dst, size_t *orig_src, size_t *orig_dst, size_t *region, int events, cl_event *wait, cl_event *event);
130
void* dt_opencl_alloc_device(const int width, const int height, const int devid, const int bpp);
134
int dt_opencl_copy_device_to_host(const int devid, void *host, void *device, const int width, const int height, const int bpp);
136
int dt_opencl_read_host_from_device(const int devid, void *host, void *device, const int width, const int height, const int bpp);
138
int dt_opencl_write_host_to_device(const int devid, void *host, void *device, const int width, const int height, const int bpp);
140
void* dt_opencl_copy_host_to_device(const int devid, void *host, const int width, const int height, const int bpp);
142
void* dt_opencl_copy_host_to_device_constant(const int devid, const int size, void *host);
144
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);
146
void* dt_opencl_alloc_device(const int devid, const int width, const int height, const int bpp);
148
void* dt_opencl_alloc_device_use_host_pointer(const int devid, const int width, const int height, const int bpp, void *host);
132
150
void dt_opencl_release_mem_object(void *mem);
134
152
/** check if image size fit into limits given by OpenCL runtime */
135
153
int dt_opencl_image_fits_device(const int devid, const size_t width, const size_t height);
155
/** get global memory of device */
156
cl_ulong dt_opencl_get_max_global_mem(const int devid);
158
/** get next free slot in eventlist and manage size of eventlist */
159
cl_event *dt_opencl_events_get_slot(const int devid, const char *tag);
161
/** reset eventlist to empty state */
162
void dt_opencl_events_reset(const int devid);
164
/** Wait for events in eventlist to terminate -> this is a blocking synchronization point
165
Does not flush eventlist */
166
void dt_opencl_events_wait_for(const int devid);
168
/** Wait for events in eventlist to terminate, check for return status of events and
169
report summary success info (CL_COMPLETE or last error code) */
170
cl_int dt_opencl_events_flush(const int devid, const int retain);
172
/** display OpenCL profiling information. If summary is not 0, try to generate summarized info for kernels */
173
void dt_opencl_events_profiling(const int devid, int summary);
138
176
#include <stdlib.h>
139
177
#include "control/conf.h"
149
187
dt_conf_set_bool("opencl", FALSE);
151
189
static inline void dt_opencl_cleanup(dt_opencl_t *cl) {}
152
static inline int dt_opencl_lock_device(dt_opencl_t *cl, const int dev)
156
static inline void dt_opencl_unlock_device(dt_opencl_t *cl, const int dev) {}
157
static inline int dt_opencl_load_program(dt_opencl_t *cl, const int dev, const char *filename)
161
static inline int dt_opencl_build_program(dt_opencl_t *cl, const int dev, const int program)
165
static inline int dt_opencl_create_kernel(dt_opencl_t *cl, const int program, const char *name)
169
static inline void dt_opencl_free_kernel(dt_opencl_t *cl, const int kernel) {}
170
static inline int dt_opencl_get_max_work_item_sizes(dt_opencl_t *cl, const int dev, size_t *sizes)
190
static inline int dt_opencl_finish(const int devid)
194
static inline int dt_opencl_enqueue_barrier(const int devid)
198
static inline int dt_opencl_lock_device(const int dev)
202
static inline void dt_opencl_unlock_device(const int dev) {}
203
static inline int dt_opencl_load_program(const int dev, const char *filename)
207
static inline int dt_opencl_build_program(const int dev, const int program)
211
static inline int dt_opencl_create_kernel(const int program, const char *name)
215
static inline void dt_opencl_free_kernel(const int kernel) {}
216
static inline int dt_opencl_get_max_work_item_sizes(const int dev, size_t *sizes)
174
static inline int dt_opencl_set_kernel_arg(dt_opencl_t *cl, const int dev, const int kernel, const size_t size, const void *arg)
220
static inline int dt_opencl_set_kernel_arg(const int dev, const int kernel, const size_t size, const void *arg)
178
static inline int dt_opencl_enqueue_kernel_2d(dt_opencl_t *cl, const int dev, const int kernel, const size_t *sizes)
224
static inline int dt_opencl_enqueue_kernel_2d(const int dev, const int kernel, const size_t *sizes)
190
236
static inline void dt_opencl_disable(void) {}
191
static inline void dt_opencl_update_enabled(void) {}
237
static inline int dt_opencl_update_enabled(void)
241
static inline int dt_opencl_get_max_global_mem(const int devid)
192
245
static inline void dt_opencl_release_mem_object(void *mem) {}
246
static inline void *dt_opencl_events_get_slot(const int devid, const char *tag)
250
static inline void dt_opencl_events_reset(const int devid) {}
251
static void dt_opencl_events_wait_for(const int devid) {}
252
static inline int dt_opencl_events_flush(const int devid, const int retain)
256
void dt_opencl_events_profiling(const int devid, int summary) {}