~ubuntu-branches/ubuntu/saucy/darktable/saucy

« back to all changes in this revision

Viewing changes to src/common/opencl.h

  • Committer: Bazaar Package Importer
  • Author(s): David Bremner
  • Date: 2011-08-02 21:32:31 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110802213231-r9v63trgyk1e822j
Tags: 0.9.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#define DT_OPENCL_MAX_PROGRAMS 256
26
26
#define DT_OPENCL_MAX_KERNELS 512
 
27
#define DT_OPENCL_EVENTLISTSIZE 128
 
28
#define DT_OPENCL_EVENTNAMELENGTH 64
27
29
 
28
30
#ifdef HAVE_OPENCL
29
31
 
47
49
  cl_command_queue cmd_queue;
48
50
  size_t max_image_width;
49
51
  size_t max_image_height;
 
52
  cl_ulong max_mem_alloc;
 
53
  cl_ulong max_global_mem;
 
54
  cl_ulong used_global_mem;
50
55
  cl_program program[DT_OPENCL_MAX_PROGRAMS];
51
56
  cl_kernel  kernel [DT_OPENCL_MAX_KERNELS];
52
57
  int program_used[DT_OPENCL_MAX_PROGRAMS];
53
58
  int kernel_used [DT_OPENCL_MAX_KERNELS];
 
59
  cl_event *eventlist;
 
60
  char *eventnames;
 
61
  int numevents;
 
62
  int maxevents;
54
63
}
55
64
dt_opencl_device_t;
56
65
 
76
85
void dt_opencl_cleanup(dt_opencl_t *cl);
77
86
 
78
87
/** cleans up command queue. */
79
 
void dt_opencl_finish(cl_command_queue q);
 
88
int dt_opencl_finish(const int devid);
 
89
 
 
90
/** enqueues a synchronization point. */
 
91
int dt_opencl_enqueue_barrier(const int devid);
80
92
 
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);
84
96
 
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);
87
99
 
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);
90
102
 
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);
93
105
 
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);
96
108
 
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);
99
111
 
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);
102
114
 
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);
105
117
 
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);
108
120
 
109
121
/** check if opencl is inited */
110
122
int dt_opencl_is_inited(void);
116
128
void dt_opencl_disable(void);
117
129
 
118
130
/** update enabled flag with value from preferences */
119
 
void dt_opencl_update_enabled(void);
 
131
int dt_opencl_update_enabled(void);
120
132
 
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);
123
 
 
124
 
void* dt_opencl_copy_host_to_device(void *host, const int width, const int height, const int devid, const int bpp);
125
 
 
126
 
void* dt_opencl_copy_host_to_device_constant(const int size, const int devid, void *host);
127
 
 
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);
129
 
 
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);
 
135
 
 
136
int dt_opencl_read_host_from_device(const int devid, void *host, void *device, const int width, const int height, const int bpp);
 
137
 
 
138
int dt_opencl_write_host_to_device(const int devid, void *host, void *device, const int width, const int height, const int bpp);
 
139
 
 
140
void* dt_opencl_copy_host_to_device(const int devid, void *host, const int width, const int height, const int bpp);
 
141
 
 
142
void* dt_opencl_copy_host_to_device_constant(const int devid, const int size, void *host);
 
143
 
 
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);
 
145
 
 
146
void* dt_opencl_alloc_device(const int devid, const int width, const int height, const int bpp);
 
147
 
 
148
void* dt_opencl_alloc_device_use_host_pointer(const int devid, const int width, const int height, const int bpp, void *host);
131
149
 
132
150
void dt_opencl_release_mem_object(void *mem);
133
151
 
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);
136
154
 
 
155
/** get global memory of device */
 
156
cl_ulong dt_opencl_get_max_global_mem(const int devid);
 
157
 
 
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);
 
160
 
 
161
/** reset eventlist to empty state */
 
162
void dt_opencl_events_reset(const int devid);
 
163
 
 
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);
 
167
 
 
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);
 
171
 
 
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);
 
174
 
137
175
#else
138
176
#include <stdlib.h>
139
177
#include "control/conf.h"
149
187
  dt_conf_set_bool("opencl", FALSE);
150
188
}
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)
153
 
{
154
 
  return -1;
155
 
}
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)
158
 
{
159
 
  return -1;
160
 
}
161
 
static inline int dt_opencl_build_program(dt_opencl_t *cl, const int dev, const int program)
162
 
{
163
 
  return -1;
164
 
}
165
 
static inline int dt_opencl_create_kernel(dt_opencl_t *cl, const int program, const char *name)
166
 
{
167
 
  return -1;
168
 
}
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)
 
191
{
 
192
  return -1;
 
193
}
 
194
static inline int dt_opencl_enqueue_barrier(const int devid)
 
195
{
 
196
  return -1;
 
197
}
 
198
static inline int dt_opencl_lock_device(const int dev)
 
199
{
 
200
  return -1;
 
201
}
 
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)
 
204
{
 
205
  return -1;
 
206
}
 
207
static inline int dt_opencl_build_program(const int dev, const int program)
 
208
{
 
209
  return -1;
 
210
}
 
211
static inline int dt_opencl_create_kernel(const int program, const char *name)
 
212
{
 
213
  return -1;
 
214
}
 
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)
171
217
{
172
218
  return 0;
173
219
}
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)
175
221
{
176
222
  return -1;
177
223
}
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)
179
225
{
180
226
  return -1;
181
227
}
188
234
  return 0;
189
235
}
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)
 
238
{
 
239
  return 0;
 
240
}
 
241
static inline int dt_opencl_get_max_global_mem(const int devid)
 
242
{
 
243
  return 0;
 
244
}
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)
 
247
{
 
248
  return NULL;
 
249
}
 
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)
 
253
{
 
254
  return -1;
 
255
}
 
256
void dt_opencl_events_profiling(const int devid, int summary) {}
193
257
#endif
194
258
 
195
259