ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/OpenCL/OpenCL.xs
(Generate patch)

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.3 by root, Tue Nov 15 20:38:07 2011 UTC vs.
Revision 1.13 by root, Sun Nov 20 01:09:48 2011 UTC

20typedef cl_mem OpenCL__Image3D_ornull; 20typedef cl_mem OpenCL__Image3D_ornull;
21typedef cl_sampler OpenCL__Sampler; 21typedef cl_sampler OpenCL__Sampler;
22typedef cl_program OpenCL__Program; 22typedef cl_program OpenCL__Program;
23typedef cl_kernel OpenCL__Kernel; 23typedef cl_kernel OpenCL__Kernel;
24typedef cl_event OpenCL__Event; 24typedef cl_event OpenCL__Event;
25typedef cl_event OpenCL__UserEvent;
26
27typedef SV *FUTURE;
28
29/*****************************************************************************/
30
31/* up to two temporary buffers */
32static void *
33tmpbuf (size_t size)
34{
35 static int idx;
36 static void *buf [2];
37 static size_t len [2];
38
39 idx ^= 1;
40
41 if (len [idx] < size)
42 {
43 free (buf [idx]);
44 len [idx] = ((size + 31) & ~4095) + 4096 - 32;
45 buf [idx] = malloc (len [idx]);
46 }
47
48 return buf [idx];
49}
50
51/*****************************************************************************/
25 52
26typedef struct 53typedef struct
27{ 54{
28 IV iv; 55 IV iv;
29 const char *name; 56 const char *name;
63 }; 90 };
64 91
65 return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)"); 92 return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)");
66} 93}
67 94
95/*****************************************************************************/
96
97static cl_int res;
98
68#define FAIL(name,res) \ 99#define FAIL(name) \
69 croak ("cl" # name ": %s", err2str (res)); 100 croak ("cl" # name ": %s", err2str (res));
70 101
71#define NEED_SUCCESS(name,args) \ 102#define NEED_SUCCESS(name,args) \
72 do { \ 103 do { \
73 cl_int res = cl ## name args; \ 104 res = cl ## name args; \
74 \ 105 \
75 if (res) \ 106 if (res) \
76 FAIL (name, res); \ 107 FAIL (name); \
77 } while (0) 108 } while (0)
109
110#define NEED_SUCCESS_ARG(retdecl, name, args) \
111 retdecl = cl ## name args; \
112 if (res) \
113 FAIL (name);
114
115/*****************************************************************************/
78 116
79#define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr) 117#define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr)
80#define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr)) 118#define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr))
81 119
82/*TODO*/ 120static void *
83#define EVENT_LIST(items,count) cl_uint event_list_count = 0; cl_event *event_list_ptr = 0 121SvPTROBJ (const char *func, const char *svname, SV *sv, const char *pkg)
122{
123 if (SvROK (sv) && sv_derived_from (sv, pkg))
124 return (void *)SvIV (SvRV (sv));
125
126 croak ("%s: %s is not of type %s", func, svname, pkg);
127}
128
129/*****************************************************************************/
130
131static size_t
132img_row_pitch (cl_mem img)
133{
134 size_t res;
135 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0);
136 return res;
137}
138
139static cl_event *
140event_list (SV **items, int count)
141{
142 cl_event *list = tmpbuf (sizeof (cl_event) * count);
143
144 while (count--)
145 list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event");
146
147 return list;
148}
149
150#define EVENT_LIST(items,count) \
151 cl_uint event_list_count = (count); \
152 cl_event *event_list_ptr = event_list (&ST (items), event_list_count)
84 153
85#define INFO(class) \ 154#define INFO(class) \
86{ \ 155{ \
87 size_t size; \ 156 size_t size; \
88 SV *sv; \
89 \
90 NEED_SUCCESS (Get ## class ## Info, (this, name, 0, 0, &size)); \ 157 NEED_SUCCESS (Get ## class ## Info, (this, name, 0, 0, &size)); \
91 sv = sv_2mortal (newSV (size)); \ 158 SV *sv = sv_2mortal (newSV (size)); \
92 SvUPGRADE (sv, SVt_PV); \ 159 SvUPGRADE (sv, SVt_PV); \
93 SvPOK_only (sv); \ 160 SvPOK_only (sv); \
94 SvCUR_set (sv, size); \ 161 SvCUR_set (sv, size); \
95 NEED_SUCCESS (Get ## class ## Info, (this, name, size, SvPVX (sv), 0)); \ 162 NEED_SUCCESS (Get ## class ## Info, (this, name, size, SvPVX (sv), 0)); \
96 XPUSHs (sv); \ 163 XPUSHs (sv); \
97} 164}
98 165
99static void *
100SvPTROBJ (const char *func, const char *svname, SV *sv, const char *pkg)
101{
102 if (SvROK (sv) && sv_derived_from (sv, pkg))
103 return (void *)SvIV (SvRV (sv));
104
105 croak ("%s: %s is not of type %s", func, svname, pkg);
106}
107
108MODULE = OpenCL PACKAGE = OpenCL 166MODULE = OpenCL PACKAGE = OpenCL
109 167
110PROTOTYPES: ENABLE 168PROTOTYPES: ENABLE
111 169
112BOOT: 170BOOT:
113{ 171{
114 HV *stash = gv_stashpv ("OpenCL", 1); 172 HV *stash = gv_stashpv ("OpenCL", 1);
115 static const ivstr *civ, const_iv[] = { 173 static const ivstr *civ, const_iv[] = {
116 { sizeof (cl_char ), "SIZEOF_CHAR" }, 174 { sizeof (cl_char ), "SIZEOF_CHAR" },
117 { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, 175 { sizeof (cl_uchar ), "SIZEOF_UCHAR" },
118 { sizeof (cl_short ), "SIZEOF_SHORT" }, 176 { sizeof (cl_short ), "SIZEOF_SHORT" },
119 { sizeof (cl_ushort), "SIZEOF_USHORT"}, 177 { sizeof (cl_ushort), "SIZEOF_USHORT" },
120 { sizeof (cl_int ), "SIZEOF_INT" }, 178 { sizeof (cl_int ), "SIZEOF_INT" },
121 { sizeof (cl_uint ), "SIZEOF_UINT" }, 179 { sizeof (cl_uint ), "SIZEOF_UINT" },
122 { sizeof (cl_long ), "SIZEOF_LONG" }, 180 { sizeof (cl_long ), "SIZEOF_LONG" },
123 { sizeof (cl_ulong ), "SIZEOF_ULONG" }, 181 { sizeof (cl_ulong ), "SIZEOF_ULONG" },
124 { sizeof (cl_half ), "SIZEOF_HALF" }, 182 { sizeof (cl_half ), "SIZEOF_HALF" },
125 { sizeof (cl_float ), "SIZEOF_FLOAT" }, 183 { sizeof (cl_float ), "SIZEOF_FLOAT" },
184 { sizeof (cl_double), "SIZEOF_DOUBLE" },
126#include "constiv.h" 185#include "constiv.h"
127 }; 186 };
128 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 187 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
129 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 188 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
130} 189}
131 190
191cl_int
192errno ()
193 CODE:
194 errno = res;
195
132const char * 196const char *
133err2str (cl_int err) 197err2str (cl_int err)
134 198
135const char * 199const char *
136enum2str (cl_uint value) 200enum2str (cl_uint value)
137 201
138void 202void
139platforms () 203platforms ()
140 PPCODE: 204 PPCODE:
141{
142 cl_platform_id *list; 205 cl_platform_id *list;
143 cl_uint count; 206 cl_uint count;
144 int i; 207 int i;
145 208
146 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count)); 209 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count));
147 Newx (list, count, cl_platform_id); 210 list = tmpbuf (sizeof (*list) * count);
148 NEED_SUCCESS (GetPlatformIDs, (count, list, 0)); 211 NEED_SUCCESS (GetPlatformIDs, (count, list, 0));
149 212
150 EXTEND (SP, count); 213 EXTEND (SP, count);
151 for (i = 0; i < count; ++i) 214 for (i = 0; i < count; ++i)
152 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); 215 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i]));
153 216
154 Safefree (list);
155}
156
157void 217void
158context_from_type_simple (cl_device_type type = CL_DEVICE_TYPE_DEFAULT) 218context_from_type (FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
159 PPCODE: 219 PPCODE:
160{
161 cl_int res;
162 cl_context ctx = clCreateContextFromType (0, type, 0, 0, &res); 220 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (0, type, 0, 0, &res));
163
164 if (res)
165 FAIL (CreateContextFromType, res);
166
167 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 221 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
168} 222
223void
224context (FUTURE properties, FUTURE devices, FUTURE notify = 0)
225 PPCODE:
226 /* der Gipfel der Kunst */
169 227
170void 228void
171wait_for_events (...) 229wait_for_events (...)
172 CODE: 230 CODE:
173{
174 EVENT_LIST (0, items); 231 EVENT_LIST (0, items);
175 NEED_SUCCESS (WaitForEvents, (event_list_count, event_list_ptr)); 232 NEED_SUCCESS (WaitForEvents, (event_list_count, event_list_ptr));
176}
177 233
178PROTOTYPES: DISABLE 234PROTOTYPES: DISABLE
179 235
180MODULE = OpenCL PACKAGE = OpenCL::Platform 236MODULE = OpenCL PACKAGE = OpenCL::Platform
181 237
182void 238void
183info (OpenCL::Platform this, cl_platform_info name) 239info (OpenCL::Platform this, cl_platform_info name)
184 PPCODE: 240 PPCODE:
185 INFO (Platform) 241 INFO (Platform)
186 242
243#BEGIN:platform
244
245void
246profile (OpenCL::Platform this)
247 PPCODE:
248 size_t size;
249 int i, n;
250 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_PROFILE, 0, 0, &size));
251 char *value = tmpbuf (size);
252 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_PROFILE, size, value, 0));
253 n = 1;
254 EXTEND (SP, n);
255 for (i = 0; i < n; ++i)
256 PUSHs (sv_2mortal (newSVpvn (value, size)));
257
258void
259version (OpenCL::Platform this)
260 PPCODE:
261 size_t size;
262 int i, n;
263 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_VERSION, 0, 0, &size));
264 char *value = tmpbuf (size);
265 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_VERSION, size, value, 0));
266 n = 1;
267 EXTEND (SP, n);
268 for (i = 0; i < n; ++i)
269 PUSHs (sv_2mortal (newSVpvn (value, size)));
270
271void
272name (OpenCL::Platform this)
273 PPCODE:
274 size_t size;
275 int i, n;
276 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_NAME, 0, 0, &size));
277 char *value = tmpbuf (size);
278 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_NAME, size, value, 0));
279 n = 1;
280 EXTEND (SP, n);
281 for (i = 0; i < n; ++i)
282 PUSHs (sv_2mortal (newSVpvn (value, size)));
283
284void
285vendor (OpenCL::Platform this)
286 PPCODE:
287 size_t size;
288 int i, n;
289 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_VENDOR, 0, 0, &size));
290 char *value = tmpbuf (size);
291 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_VENDOR, size, value, 0));
292 n = 1;
293 EXTEND (SP, n);
294 for (i = 0; i < n; ++i)
295 PUSHs (sv_2mortal (newSVpvn (value, size)));
296
297void
298extensions (OpenCL::Platform this)
299 PPCODE:
300 size_t size;
301 int i, n;
302 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_EXTENSIONS, 0, 0, &size));
303 char *value = tmpbuf (size);
304 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_EXTENSIONS, size, value, 0));
305 n = 1;
306 EXTEND (SP, n);
307 for (i = 0; i < n; ++i)
308 PUSHs (sv_2mortal (newSVpvn (value, size)));
309
310#END:platform
311
187void 312void
188devices (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_ALL) 313devices (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_ALL)
189 PPCODE: 314 PPCODE:
190{
191 cl_device_id *list; 315 cl_device_id *list;
192 cl_uint count; 316 cl_uint count;
193 int i; 317 int i;
194 318
195 NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count)); 319 NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count));
196 Newx (list, count, cl_device_id); 320 list = tmpbuf (sizeof (*list) * count);
197 NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0)); 321 NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0));
198 322
199 EXTEND (SP, count); 323 EXTEND (SP, count);
200 for (i = 0; i < count; ++i) 324 for (i = 0; i < count; ++i)
201 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); 325 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i]));
202 326
203 Safefree (list);
204}
205
206void 327void
328context (OpenCL::Platform this, FUTURE properties, SV *devices, FUTURE notify = 0)
329 PPCODE:
330 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV)
331 croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call");
332
333 AV *av = (AV *)SvRV (devices);
334 cl_uint num_devices = av_len (av) + 1;
335 cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices);
336 int i;
337
338 for (i = num_devices; i--; )
339 device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device");
340
341 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (0, num_devices, device_list, 0, 0, &res));
342 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
343
344void
207context_from_type_simple (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_DEFAULT) 345context_from_type (OpenCL::Platform this, FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
208 PPCODE: 346 PPCODE:
209{
210 cl_int res;
211 cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)this, 0 }; 347 cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)this, 0 };
212 cl_context ctx = clCreateContextFromType (props, type, 0, 0, &res); 348 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res));
213
214 if (res)
215 FAIL (CreateContextFromType, res);
216
217 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 349 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
218}
219 350
220MODULE = OpenCL PACKAGE = OpenCL::Device 351MODULE = OpenCL PACKAGE = OpenCL::Device
221 352
222void 353void
223info (OpenCL::Device this, cl_device_info name) 354info (OpenCL::Device this, cl_device_info name)
224 PPCODE: 355 PPCODE:
225 INFO (Device) 356 INFO (Device)
226 357
227void
228context_simple (OpenCL::Device this)
229 PPCODE:
230{
231 cl_int res;
232 cl_context ctx = clCreateContext (0, 1, &this, 0, 0, &res);
233
234 if (res)
235 FAIL (CreateContext, res);
236
237 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
238}
239
240MODULE = OpenCL PACKAGE = OpenCL::Context 358MODULE = OpenCL PACKAGE = OpenCL::Context
241 359
242void 360void
243DESTROY (OpenCL::Context context) 361DESTROY (OpenCL::Context context)
244 CODE: 362 CODE:
248info (OpenCL::Context this, cl_context_info name) 366info (OpenCL::Context this, cl_context_info name)
249 PPCODE: 367 PPCODE:
250 INFO (Context) 368 INFO (Context)
251 369
252void 370void
253command_queue_simple (OpenCL::Context this, OpenCL::Device device) 371queue (OpenCL::Context this, OpenCL::Device device, cl_command_queue_properties properties = 0)
254 PPCODE: 372 PPCODE:
255{
256 cl_int res;
257 cl_command_queue queue = clCreateCommandQueue (this, device, 0, &res); 373 NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (this, device, properties, &res));
258
259 if (res)
260 FAIL (CreateCommandQueue, res);
261
262 XPUSH_NEW_OBJ ("OpenCL::Queue", queue); 374 XPUSH_NEW_OBJ ("OpenCL::Queue", queue);
263} 375
376void
377user_event (OpenCL::Context this)
378 PPCODE:
379 NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (this, &res));
380 XPUSH_NEW_OBJ ("OpenCL::UserEvent", ev);
264 381
265void 382void
266buffer (OpenCL::Context this, cl_mem_flags flags, size_t len) 383buffer (OpenCL::Context this, cl_mem_flags flags, size_t len)
267 PPCODE: 384 PPCODE:
268{
269 cl_int res;
270 cl_mem mem;
271
272 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) 385 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
273 croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); 386 croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?");
274 387
275 mem = clCreateBuffer (this, flags, len, 0, &res); 388 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, 0, &res));
276
277 if (res)
278 FAIL (CreateBuffer, res);
279
280 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); 389 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
281}
282 390
283void 391void
284buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data) 392buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data)
285 PPCODE: 393 PPCODE:
286{
287 STRLEN len; 394 STRLEN len;
288 char *ptr = SvPVbyte (data, len); 395 char *ptr = SvPVbyte (data, len);
289 cl_int res;
290 cl_mem mem;
291 396
292 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) 397 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
293 croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); 398 croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
294 399
295 mem = clCreateBuffer (this, flags, len, ptr, &res); 400 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, ptr, &res));
296
297 if (res)
298 FAIL (CreateBuffer, res);
299
300 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); 401 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
301}
302 402
303void 403void
304image2d (OpenCL::Context this, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, SV *data) 404image2d (OpenCL::Context this, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, size_t row_pitch = 0, SV *data = &PL_sv_undef)
305 PPCODE: 405 PPCODE:
306{
307 STRLEN len; 406 STRLEN len;
308 char *ptr = SvPVbyte (data, len); 407 char *ptr = SvPVbyte (data, len);
309 const cl_image_format format = { channel_order, channel_type }; 408 const cl_image_format format = { channel_order, channel_type };
310 cl_int res;
311 cl_mem mem = clCreateImage2D (this, flags, &format, width, height, len / height, ptr, &res); 409 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (this, flags, &format, width, height, row_pitch, ptr, &res));
312
313 if (res)
314 FAIL (CreateImage2D, res);
315
316 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 410 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
317}
318 411
319void 412void
320image3d (OpenCL::Context this, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, size_t depth, size_t slice_pitch, SV *data) 413image3d (OpenCL::Context this, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, size_t depth, size_t row_pitch = 0, size_t slice_pitch = 0, SV *data = &PL_sv_undef)
321 PPCODE: 414 PPCODE:
322{
323 STRLEN len; 415 STRLEN len;
324 char *ptr = SvPVbyte (data, len); 416 char *ptr = SvPVbyte (data, len);
325 const cl_image_format format = { channel_order, channel_type }; 417 const cl_image_format format = { channel_order, channel_type };
326 cl_int res; 418 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (this, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
327 cl_mem mem = clCreateImage3D (this, flags, &format, width, height,
328 depth, len / (height * slice_pitch), slice_pitch, ptr, &res);
329
330 if (res)
331 FAIL (CreateImage3D, res);
332
333 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 419 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
334}
335 420
336void 421void
337supported_image_formats (OpenCL::Context this, cl_mem_flags flags, cl_mem_object_type image_type) 422supported_image_formats (OpenCL::Context this, cl_mem_flags flags, cl_mem_object_type image_type)
338 PPCODE: 423 PPCODE:
339{ 424{
356} 441}
357 442
358void 443void
359sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode) 444sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode)
360 PPCODE: 445 PPCODE:
361{
362 cl_int res;
363 cl_sampler sampler = clCreateSampler (this, normalized_coords, addressing_mode, filter_mode, &res); 446 NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (this, normalized_coords, addressing_mode, filter_mode, &res));
364
365 if (res)
366 FAIL (CreateSampler, res);
367
368 XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler); 447 XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler);
369}
370 448
371void 449void
372program_with_source (OpenCL::Context this, SV *program) 450program_with_source (OpenCL::Context this, SV *program)
373 PPCODE: 451 PPCODE:
374{
375 STRLEN len; 452 STRLEN len;
376 size_t len2; 453 size_t len2;
377 const char *ptr = SvPVbyte (program, len); 454 const char *ptr = SvPVbyte (program, len);
378 cl_int res;
379 cl_program prog;
380 455
381 len2 = len; 456 len2 = len;
382 prog = clCreateProgramWithSource (this, 1, &ptr, &len2, &res); 457 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (this, 1, &ptr, &len2, &res));
383
384 if (res)
385 FAIL (CreateProgramWithSource, res);
386
387 XPUSH_NEW_OBJ ("OpenCL::Program", prog); 458 XPUSH_NEW_OBJ ("OpenCL::Program", prog);
388} 459
460#BEGIN:context
461
462#END:context
389 463
390MODULE = OpenCL PACKAGE = OpenCL::Queue 464MODULE = OpenCL PACKAGE = OpenCL::Queue
391 465
392void 466void
393DESTROY (OpenCL::Queue this) 467DESTROY (OpenCL::Queue this)
400 INFO (CommandQueue) 474 INFO (CommandQueue)
401 475
402void 476void
403enqueue_read_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...) 477enqueue_read_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...)
404 PPCODE: 478 PPCODE:
405{
406 cl_event ev = 0; 479 cl_event ev = 0;
407 EVENT_LIST (6, items - 6); 480 EVENT_LIST (6, items - 6);
408 481
409 SvUPGRADE (data, SVt_PV); 482 SvUPGRADE (data, SVt_PV);
410 SvGROW (data, len); 483 SvGROW (data, len);
412 SvCUR_set (data, len); 485 SvCUR_set (data, len);
413 NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 486 NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
414 487
415 if (ev) 488 if (ev)
416 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 489 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
417}
418 490
419void 491void
420enqueue_write_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...) 492enqueue_write_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...)
421 PPCODE: 493 PPCODE:
422{
423 cl_event ev = 0; 494 cl_event ev = 0;
424 STRLEN len; 495 STRLEN len;
425 char *ptr = SvPVbyte (data, len); 496 char *ptr = SvPVbyte (data, len);
426 EVENT_LIST (5, items - 5); 497 EVENT_LIST (5, items - 5);
427 498
428 NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 499 NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
429 500
430 if (ev) 501 if (ev)
431 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 502 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
432}
433 503
434void 504void
435enqueue_copy_buffer (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...) 505enqueue_copy_buffer (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...)
436 PPCODE: 506 PPCODE:
437{
438 cl_event ev = 0; 507 cl_event ev = 0;
439 EVENT_LIST (6, items - 6); 508 EVENT_LIST (6, items - 6);
440 509
441 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 510 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
442 511
443 if (ev) 512 if (ev)
444 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 513 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
445}
446
447 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBufferRect.html */
448 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html */
449 514
450void 515void
451enqueue_read_image (OpenCL::Queue this, OpenCL::Image src, cl_bool blocking, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...) 516enqueue_read_image (OpenCL::Queue this, OpenCL::Image src, cl_bool blocking, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...)
452 PPCODE: 517 PPCODE:
453{
454 cl_event ev = 0; 518 cl_event ev = 0;
455 const size_t src_origin[3] = { src_x, src_y, src_z }; 519 const size_t src_origin[3] = { src_x, src_y, src_z };
456 const size_t region[3] = { width, height, depth }; 520 const size_t region[3] = { width, height, depth };
457 size_t len = row_pitch * slice_pitch * depth;
458 EVENT_LIST (11, items - 11); 521 EVENT_LIST (12, items - 12);
522
523 if (!row_pitch)
524 row_pitch = img_row_pitch (src);
525
526 if (depth > 1 && !slice_pitch)
527 slice_pitch = row_pitch * height;
528
529 size_t len = slice_pitch ? slice_pitch * depth : row_pitch * height;
459 530
460 SvUPGRADE (data, SVt_PV); 531 SvUPGRADE (data, SVt_PV);
461 SvGROW (data, len); 532 SvGROW (data, len);
462 SvPOK_only (data); 533 SvPOK_only (data);
463 SvCUR_set (data, len); 534 SvCUR_set (data, len);
464 NEED_SUCCESS (EnqueueReadImage, (this, src, blocking, src_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 535 NEED_SUCCESS (EnqueueReadImage, (this, src, blocking, src_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
465 536
466 if (ev) 537 if (ev)
467 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 538 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
468}
469 539
470void 540void
471enqueue_write_image (OpenCL::Queue this, OpenCL::Image dst, cl_bool blocking, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t row_pitch, SV *data, ...) 541enqueue_write_image (OpenCL::Queue this, OpenCL::Image dst, cl_bool blocking, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...)
472 PPCODE: 542 PPCODE:
473{
474 cl_event ev = 0; 543 cl_event ev = 0;
475 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 544 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
476 const size_t region[3] = { width, height, depth }; 545 const size_t region[3] = { width, height, depth };
477 STRLEN len; 546 STRLEN len;
478 char *ptr = SvPVbyte (data, len); 547 char *ptr = SvPVbyte (data, len);
479 size_t slice_pitch = len / (row_pitch * height);
480 EVENT_LIST (11, items - 11); 548 EVENT_LIST (12, items - 12);
549
550 if (!row_pitch)
551 row_pitch = img_row_pitch (dst);
552
553 if (depth > 1 && !slice_pitch)
554 slice_pitch = row_pitch * height;
555
556 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height;
557
558 if (len < min_len)
559 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
481 560
482 NEED_SUCCESS (EnqueueWriteImage, (this, dst, blocking, dst_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 561 NEED_SUCCESS (EnqueueWriteImage, (this, dst, blocking, dst_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
483 562
484 if (ev) 563 if (ev)
485 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 564 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
486}
487 565
488void 566void
489enqueue_copy_buffer_rect (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, size_t dst_slice_pitch, ...) 567enqueue_copy_buffer_rect (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, size_t dst_slice_pitch, ...)
490 PPCODE: 568 PPCODE:
491{
492 cl_event ev = 0; 569 cl_event ev = 0;
493 const size_t src_origin[3] = { src_x, src_y, src_z }; 570 const size_t src_origin[3] = { src_x, src_y, src_z };
494 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 571 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
495 const size_t region[3] = { width, height, depth }; 572 const size_t region[3] = { width, height, depth };
496 EVENT_LIST (16, items - 16); 573 EVENT_LIST (16, items - 16);
497 574
498 NEED_SUCCESS (EnqueueCopyBufferRect, (this, src, dst, src_origin, dst_origin, region, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 575 NEED_SUCCESS (EnqueueCopyBufferRect, (this, src, dst, src_origin, dst_origin, region, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
499 576
500 if (ev) 577 if (ev)
501 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 578 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
502}
503 579
504void 580void
505enqueue_copy_buffer_to_image (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Image dst, size_t src_offset, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...) 581enqueue_copy_buffer_to_image (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Image dst, size_t src_offset, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...)
506 PPCODE: 582 PPCODE:
507{
508 cl_event ev = 0; 583 cl_event ev = 0;
509 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 584 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
510 const size_t region[3] = { width, height, depth }; 585 const size_t region[3] = { width, height, depth };
511 EVENT_LIST (10, items - 10); 586 EVENT_LIST (10, items - 10);
512 587
513 NEED_SUCCESS (EnqueueCopyBufferToImage, (this, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 588 NEED_SUCCESS (EnqueueCopyBufferToImage, (this, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
514 589
515 if (ev) 590 if (ev)
516 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 591 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
517}
518 592
519void 593void
520enqueue_copy_image (OpenCL::Queue this, OpenCL::Image src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...) 594enqueue_copy_image (OpenCL::Queue this, OpenCL::Image src, OpenCL::Image dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...)
521 PPCODE: 595 PPCODE:
522{
523 cl_event ev = 0; 596 cl_event ev = 0;
524 const size_t src_origin[3] = { src_x, src_y, src_z }; 597 const size_t src_origin[3] = { src_x, src_y, src_z };
525 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 598 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
526 const size_t region[3] = { width, height, depth }; 599 const size_t region[3] = { width, height, depth };
527 EVENT_LIST (12, items - 12); 600 EVENT_LIST (12, items - 12);
528 601
529 NEED_SUCCESS (EnqueueCopyImage, (this, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 602 NEED_SUCCESS (EnqueueCopyImage, (this, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
530 603
531 if (ev) 604 if (ev)
532 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 605 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
533}
534 606
535void 607void
536enqueue_copy_image_to_buffer (OpenCL::Queue this, OpenCL::Image src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t dst_offset, ...) 608enqueue_copy_image_to_buffer (OpenCL::Queue this, OpenCL::Image src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t dst_offset, ...)
537 PPCODE: 609 PPCODE:
538{
539 cl_event ev = 0; 610 cl_event ev = 0;
540 const size_t src_origin[3] = { src_x, src_y, src_z }; 611 const size_t src_origin[3] = { src_x, src_y, src_z };
541 const size_t region[3] = { width, height, depth }; 612 const size_t region[3] = { width, height, depth };
542 EVENT_LIST (10, items - 10); 613 EVENT_LIST (10, items - 10);
543 614
544 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 615 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
545 616
546 if (ev) 617 if (ev)
547 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 618 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
548}
549 619
550void 620void
551enqueue_task (OpenCL::Queue this, OpenCL::Kernel kernel, ...) 621enqueue_task (OpenCL::Queue this, OpenCL::Kernel kernel, ...)
552 PPCODE: 622 PPCODE:
553{
554 cl_event ev = 0; 623 cl_event ev = 0;
555 EVENT_LIST (2, items - 2); 624 EVENT_LIST (2, items - 2);
556 625
557 NEED_SUCCESS (EnqueueTask, (this, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 626 NEED_SUCCESS (EnqueueTask, (this, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
558 627
559 if (ev) 628 if (ev)
560 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 629 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
561}
562 630
563 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueNDRangeKernel.html */ 631void
632enqueue_nd_range_kernel (OpenCL::Queue this, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...)
633 PPCODE:
634 cl_event ev = 0;
635 size_t *gwo = 0, *gws, *lws = 0;
636 int gws_len;
637 size_t *lists;
638 int i;
639 EVENT_LIST (5, items - 5);
640
641 if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV)
642 croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference");
643
644 gws_len = AvFILLp (SvRV (global_work_size)) + 1;
645
646 lists = tmpbuf (sizeof (size_t) * 3 * gws_len);
647
648 gws = lists + gws_len * 0;
649 for (i = 0; i < gws_len; ++i)
650 gws [i] = SvIV (AvARRAY (SvRV (global_work_size))[i]);
651
652 if (SvOK (global_work_offset))
653 {
654 if (!SvROK (global_work_offset) || SvTYPE (SvRV (global_work_offset)) != SVt_PVAV)
655 croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array reference");
656
657 if (AvFILLp (SvRV (global_work_size)) + 1 != gws_len)
658 croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array of same size as global_work_size");
659
660 gwo = lists + gws_len * 1;
661 for (i = 0; i < gws_len; ++i)
662 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
663 }
664
665 if (SvOK (local_work_size))
666 {
667 if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV)
668 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference");
669
670 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len)
671 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
672
673 lws = lists + gws_len * 2;
674 for (i = 0; i < gws_len; ++i)
675 lws [i] = SvIV (AvARRAY (SvRV (local_work_size))[i]);
676 }
677
678 NEED_SUCCESS (EnqueueNDRangeKernel, (this, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
679
680 if (ev)
681 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
564 682
565void 683void
566enqueue_marker (OpenCL::Queue this) 684enqueue_marker (OpenCL::Queue this)
567 PPCODE: 685 PPCODE:
568{
569 cl_event ev; 686 cl_event ev;
570 NEED_SUCCESS (EnqueueMarker, (this, &ev)); 687 NEED_SUCCESS (EnqueueMarker, (this, &ev));
571 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 688 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
572}
573 689
574void 690void
575enqueue_wait_for_events (OpenCL::Queue this, ...) 691enqueue_wait_for_events (OpenCL::Queue this, ...)
576 CODE: 692 CODE:
577{
578 EVENT_LIST (1, items - 1); 693 EVENT_LIST (1, items - 1);
579 NEED_SUCCESS (EnqueueWaitForEvents, (this, event_list_count, event_list_ptr)); 694 NEED_SUCCESS (EnqueueWaitForEvents, (this, event_list_count, event_list_ptr));
580}
581 695
582void 696void
583enqueue_barrier (OpenCL::Queue this) 697enqueue_barrier (OpenCL::Queue this)
584 CODE: 698 CODE:
585 NEED_SUCCESS (EnqueueBarrier, (this)); 699 NEED_SUCCESS (EnqueueBarrier, (this));
604void 718void
605info (OpenCL::Memory this, cl_mem_info name) 719info (OpenCL::Memory this, cl_mem_info name)
606 PPCODE: 720 PPCODE:
607 INFO (MemObject) 721 INFO (MemObject)
608 722
723MODULE = OpenCL PACKAGE = OpenCL::Image
724
725void
726image_info (OpenCL::Image this, cl_image_info name)
727 PPCODE:
728 INFO (Image)
729
609MODULE = OpenCL PACKAGE = OpenCL::Sampler 730MODULE = OpenCL PACKAGE = OpenCL::Sampler
610 731
611void 732void
612DESTROY (OpenCL::Sampler this) 733DESTROY (OpenCL::Sampler this)
613 CODE: 734 CODE:
636 NEED_SUCCESS (BuildProgram, (this, 1, &device, SvPVbyte_nolen (options), 0, 0)); 757 NEED_SUCCESS (BuildProgram, (this, 1, &device, SvPVbyte_nolen (options), 0, 0));
637 758
638void 759void
639build_info (OpenCL::Program this, OpenCL::Device device, cl_program_build_info name) 760build_info (OpenCL::Program this, OpenCL::Device device, cl_program_build_info name)
640 PPCODE: 761 PPCODE:
641{
642 size_t size; 762 size_t size;
643 SV *sv;
644
645 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, 0, 0, &size)); 763 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, 0, 0, &size));
646 sv = sv_2mortal (newSV (size)); 764 SV *sv = sv_2mortal (newSV (size));
647 SvUPGRADE (sv, SVt_PV); 765 SvUPGRADE (sv, SVt_PV);
648 SvPOK_only (sv); 766 SvPOK_only (sv);
649 SvCUR_set (sv, size); 767 SvCUR_set (sv, size);
650 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, size, SvPVX (sv), 0)); 768 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, size, SvPVX (sv), 0));
651 XPUSHs (sv); 769 XPUSHs (sv);
652}
653 770
654void 771void
655kernel (OpenCL::Program program, SV *function) 772kernel (OpenCL::Program program, SV *function)
656 PPCODE: 773 PPCODE:
657{
658 cl_int res;
659 cl_kernel kernel = clCreateKernel (program, SvPVbyte_nolen (function), &res); 774 NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res));
660
661 if (res)
662 FAIL (CreateKernel, res);
663
664 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel); 775 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel);
665}
666 776
667MODULE = OpenCL PACKAGE = OpenCL::Kernel 777MODULE = OpenCL PACKAGE = OpenCL::Kernel
668 778
669void 779void
670DESTROY (OpenCL::Kernel this) 780DESTROY (OpenCL::Kernel this)
675info (OpenCL::Kernel this, cl_kernel_info name) 785info (OpenCL::Kernel this, cl_kernel_info name)
676 PPCODE: 786 PPCODE:
677 INFO (Kernel) 787 INFO (Kernel)
678 788
679void 789void
790work_group_info (OpenCL::Kernel this, OpenCL::Device device, cl_kernel_work_group_info name)
791 PPCODE:
792 size_t size;
793 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, name, 0, 0, &size));
794 SV *sv = sv_2mortal (newSV (size));
795 SvUPGRADE (sv, SVt_PV);
796 SvPOK_only (sv);
797 SvCUR_set (sv, size);
798 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, name, size, SvPVX (sv), 0));
799 XPUSHs (sv);
800
801void
680set_char (OpenCL::Kernel this, cl_uint idx, cl_char value) 802set_char (OpenCL::Kernel this, cl_uint idx, cl_char value)
681 CODE: 803 CODE:
682 clSetKernelArg (this, idx, sizeof (value), &value); 804 clSetKernelArg (this, idx, sizeof (value), &value);
683 805
684void 806void
725set_float (OpenCL::Kernel this, cl_uint idx, cl_float value) 847set_float (OpenCL::Kernel this, cl_uint idx, cl_float value)
726 CODE: 848 CODE:
727 clSetKernelArg (this, idx, sizeof (value), &value); 849 clSetKernelArg (this, idx, sizeof (value), &value);
728 850
729void 851void
852set_double (OpenCL::Kernel this, cl_uint idx, cl_double value)
853 CODE:
854 clSetKernelArg (this, idx, sizeof (value), &value);
855
856void
730set_memory (OpenCL::Kernel this, cl_uint idx, OpenCL::Memory_ornull value) 857set_memory (OpenCL::Kernel this, cl_uint idx, OpenCL::Memory_ornull value)
731 CODE: 858 CODE:
732 clSetKernelArg (this, idx, sizeof (value), &value); 859 clSetKernelArg (this, idx, sizeof (value), &value);
733 860
734void 861void
767info (OpenCL::Event this, cl_event_info name) 894info (OpenCL::Event this, cl_event_info name)
768 PPCODE: 895 PPCODE:
769 INFO (Event) 896 INFO (Event)
770 897
771void 898void
899profiling_info (OpenCL::Event this, cl_profiling_info name)
900 PPCODE:
901 INFO (EventProfiling)
902
903void
772wait (OpenCL::Event this) 904wait (OpenCL::Event this)
773 CODE: 905 CODE:
774 clWaitForEvents (1, &this); 906 clWaitForEvents (1, &this);
775 907
908MODULE = OpenCL PACKAGE = OpenCL::UserEvent
909
910void
911set_status (OpenCL::UserEvent this, cl_int execution_status)
912 CODE:
913 clSetUserEventStatus (this, execution_status);
914

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines