ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/OpenCL/OpenCL.xs
Revision: 1.10
Committed: Thu Nov 17 03:56:07 2011 UTC (12 years, 6 months ago) by root
Branch: MAIN
Changes since 1.9: +13 -50 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4
5 #include <CL/opencl.h>
6
7 typedef cl_platform_id OpenCL__Platform;
8 typedef cl_device_id OpenCL__Device;
9 typedef cl_context OpenCL__Context;
10 typedef cl_command_queue OpenCL__Queue;
11 typedef cl_mem OpenCL__Memory;
12 typedef cl_mem OpenCL__Buffer;
13 typedef cl_mem OpenCL__Image;
14 typedef cl_mem OpenCL__Image2D;
15 typedef cl_mem OpenCL__Image3D;
16 typedef cl_mem OpenCL__Memory_ornull;
17 typedef cl_mem OpenCL__Buffer_ornull;
18 typedef cl_mem OpenCL__Image_ornull;
19 typedef cl_mem OpenCL__Image2D_ornull;
20 typedef cl_mem OpenCL__Image3D_ornull;
21 typedef cl_sampler OpenCL__Sampler;
22 typedef cl_program OpenCL__Program;
23 typedef cl_kernel OpenCL__Kernel;
24 typedef cl_event OpenCL__Event;
25 typedef cl_event OpenCL__UserEvent;
26
27 typedef SV *FUTURE;
28
29 /*****************************************************************************/
30
31 /* up to two temporary buffers */
32 static void *
33 tmpbuf (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 /*****************************************************************************/
52
53 typedef struct
54 {
55 IV iv;
56 const char *name;
57 #define const_iv(name) { (IV)CL_ ## name, # name },
58 } ivstr;
59
60 static const char *
61 iv2str (IV value, const ivstr *base, int count, const char *fallback)
62 {
63 int i;
64 static char strbuf [32];
65
66 for (i = count; i--; )
67 if (base [i].iv == value)
68 return base [i].name;
69
70 snprintf (strbuf, sizeof (strbuf), fallback, (int)value);
71
72 return strbuf;
73 }
74
75 static const char *
76 enum2str (cl_uint value)
77 {
78 static const ivstr enumstr[] = {
79 #include "enumstr.h"
80 };
81
82 return iv2str (value, enumstr, sizeof (enumstr) / sizeof (enumstr [0]), "ENUM(0x%04x)");
83 }
84
85 static const char *
86 err2str (cl_int err)
87 {
88 static const ivstr errstr[] = {
89 #include "errstr.h"
90 };
91
92 return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)");
93 }
94
95 /*****************************************************************************/
96
97 static cl_int res;
98
99 #define FAIL(name) \
100 croak ("cl" # name ": %s", err2str (res));
101
102 #define NEED_SUCCESS(name,args) \
103 do { \
104 res = cl ## name args; \
105 \
106 if (res) \
107 FAIL (name); \
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 /*****************************************************************************/
116
117 #define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr)
118 #define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr))
119
120 static void *
121 SvPTROBJ (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
131 static cl_event *
132 event_list (SV **items, int count)
133 {
134 cl_event *list = tmpbuf (sizeof (cl_event) * count);
135
136 while (count--)
137 list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event");
138
139 return list;
140 }
141
142 #define EVENT_LIST(items,count) \
143 cl_uint event_list_count = (count); \
144 cl_event *event_list_ptr = event_list (&ST (items), event_list_count)
145
146 #define INFO(class) \
147 { \
148 size_t size; \
149 NEED_SUCCESS (Get ## class ## Info, (this, name, 0, 0, &size)); \
150 SV *sv = sv_2mortal (newSV (size)); \
151 SvUPGRADE (sv, SVt_PV); \
152 SvPOK_only (sv); \
153 SvCUR_set (sv, size); \
154 NEED_SUCCESS (Get ## class ## Info, (this, name, size, SvPVX (sv), 0)); \
155 XPUSHs (sv); \
156 }
157
158 MODULE = OpenCL PACKAGE = OpenCL
159
160 PROTOTYPES: ENABLE
161
162 BOOT:
163 {
164 HV *stash = gv_stashpv ("OpenCL", 1);
165 static const ivstr *civ, const_iv[] = {
166 { sizeof (cl_char ), "SIZEOF_CHAR" },
167 { sizeof (cl_uchar ), "SIZEOF_UCHAR" },
168 { sizeof (cl_short ), "SIZEOF_SHORT" },
169 { sizeof (cl_ushort), "SIZEOF_USHORT" },
170 { sizeof (cl_int ), "SIZEOF_INT" },
171 { sizeof (cl_uint ), "SIZEOF_UINT" },
172 { sizeof (cl_long ), "SIZEOF_LONG" },
173 { sizeof (cl_ulong ), "SIZEOF_ULONG" },
174 { sizeof (cl_half ), "SIZEOF_HALF" },
175 { sizeof (cl_float ), "SIZEOF_FLOAT" },
176 { sizeof (cl_double), "SIZEOF_DOUBLE" },
177 #include "constiv.h"
178 };
179 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
180 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
181 }
182
183 cl_int
184 errno ()
185 CODE:
186 errno = res;
187
188 const char *
189 err2str (cl_int err)
190
191 const char *
192 enum2str (cl_uint value)
193
194 void
195 platforms ()
196 PPCODE:
197 cl_platform_id *list;
198 cl_uint count;
199 int i;
200
201 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count));
202 list = tmpbuf (sizeof (*list) * count);
203 NEED_SUCCESS (GetPlatformIDs, (count, list, 0));
204
205 EXTEND (SP, count);
206 for (i = 0; i < count; ++i)
207 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i]));
208
209 void
210 context_from_type (FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
211 PPCODE:
212 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (0, type, 0, 0, &res));
213 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
214
215 void
216 context (FUTURE properties, FUTURE devices, FUTURE notify = 0)
217 PPCODE:
218 /* der Gipfel der Kunst */
219
220 void
221 wait_for_events (...)
222 CODE:
223 EVENT_LIST (0, items);
224 NEED_SUCCESS (WaitForEvents, (event_list_count, event_list_ptr));
225
226 PROTOTYPES: DISABLE
227
228 MODULE = OpenCL PACKAGE = OpenCL::Platform
229
230 void
231 info (OpenCL::Platform this, cl_platform_info name)
232 PPCODE:
233 INFO (Platform)
234
235 void
236 devices (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_ALL)
237 PPCODE:
238 cl_device_id *list;
239 cl_uint count;
240 int i;
241
242 NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count));
243 list = tmpbuf (sizeof (*list) * count);
244 NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0));
245
246 EXTEND (SP, count);
247 for (i = 0; i < count; ++i)
248 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i]));
249
250 void
251 context (OpenCL::Platform this, FUTURE properties, SV *devices, FUTURE notify = 0)
252 PPCODE:
253 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV)
254 croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call");
255
256 AV *av = (SV *)SvRV (devices);
257 cl_uint num_devices = av_len (av) + 1;
258 cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices);
259 int i;
260
261 for (i = num_devices; i--; )
262 device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device");
263
264 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (0, num_devices, device_list, 0, 0, &res));
265 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
266
267 void
268 context_from_type (OpenCL::Platform this, FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
269 PPCODE:
270 cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)this, 0 };
271 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res));
272 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
273
274 MODULE = OpenCL PACKAGE = OpenCL::Device
275
276 void
277 info (OpenCL::Device this, cl_device_info name)
278 PPCODE:
279 INFO (Device)
280
281 MODULE = OpenCL PACKAGE = OpenCL::Context
282
283 void
284 DESTROY (OpenCL::Context context)
285 CODE:
286 clReleaseContext (context);
287
288 void
289 info (OpenCL::Context this, cl_context_info name)
290 PPCODE:
291 INFO (Context)
292
293 void
294 queue (OpenCL::Context this, OpenCL::Device device, cl_command_queue_properties properties = 0)
295 PPCODE:
296 NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (this, device, properties, &res));
297 XPUSH_NEW_OBJ ("OpenCL::Queue", queue);
298
299 void
300 user_event (OpenCL::Context this)
301 PPCODE:
302 NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (this, &res));
303 XPUSH_NEW_OBJ ("OpenCL::UserEvent", ev);
304
305 void
306 buffer (OpenCL::Context this, cl_mem_flags flags, size_t len)
307 PPCODE:
308 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
309 croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?");
310
311 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, 0, &res));
312 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
313
314 void
315 buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data)
316 PPCODE:
317 STRLEN len;
318 char *ptr = SvPVbyte (data, len);
319
320 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
321 croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
322
323 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, ptr, &res));
324 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
325
326 void
327 image2d (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, SV *data)
328 PPCODE:
329 STRLEN len;
330 char *ptr = SvPVbyte (data, len);
331 const cl_image_format format = { channel_order, channel_type };
332 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (this, flags, &format, width, height, row_pitch, ptr, &res));
333 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
334
335 void
336 image3d (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, size_t slice_pitch, SV *data)
337 PPCODE:
338 STRLEN len;
339 char *ptr = SvPVbyte (data, len);
340 const cl_image_format format = { channel_order, channel_type };
341 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (this, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
342 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
343
344 void
345 supported_image_formats (OpenCL::Context this, cl_mem_flags flags, cl_mem_object_type image_type)
346 PPCODE:
347 {
348 cl_uint count;
349 cl_image_format *list;
350 int i;
351
352 NEED_SUCCESS (GetSupportedImageFormats, (this, flags, image_type, 0, 0, &count));
353 Newx (list, count, cl_image_format);
354 NEED_SUCCESS (GetSupportedImageFormats, (this, flags, image_type, count, list, 0));
355
356 EXTEND (SP, count);
357 for (i = 0; i < count; ++i)
358 {
359 AV *av = newAV ();
360 av_store (av, 1, newSVuv (list [i].image_channel_data_type));
361 av_store (av, 0, newSVuv (list [i].image_channel_order));
362 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
363 }
364 }
365
366 void
367 sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode)
368 PPCODE:
369 NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (this, normalized_coords, addressing_mode, filter_mode, &res));
370 XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler);
371
372 void
373 program_with_source (OpenCL::Context this, SV *program)
374 PPCODE:
375 STRLEN len;
376 size_t len2;
377 const char *ptr = SvPVbyte (program, len);
378
379 len2 = len;
380 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (this, 1, &ptr, &len2, &res));
381 XPUSH_NEW_OBJ ("OpenCL::Program", prog);
382
383 MODULE = OpenCL PACKAGE = OpenCL::Queue
384
385 void
386 DESTROY (OpenCL::Queue this)
387 CODE:
388 clReleaseCommandQueue (this);
389
390 void
391 info (OpenCL::Queue this, cl_command_queue_info name)
392 PPCODE:
393 INFO (CommandQueue)
394
395 void
396 enqueue_read_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...)
397 PPCODE:
398 cl_event ev = 0;
399 EVENT_LIST (6, items - 6);
400
401 SvUPGRADE (data, SVt_PV);
402 SvGROW (data, len);
403 SvPOK_only (data);
404 SvCUR_set (data, len);
405 NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
406
407 if (ev)
408 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
409
410 void
411 enqueue_write_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...)
412 PPCODE:
413 cl_event ev = 0;
414 STRLEN len;
415 char *ptr = SvPVbyte (data, len);
416 EVENT_LIST (5, items - 5);
417
418 NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
419
420 if (ev)
421 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
422
423 void
424 enqueue_copy_buffer (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...)
425 PPCODE:
426 cl_event ev = 0;
427 EVENT_LIST (6, items - 6);
428
429 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
430
431 if (ev)
432 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
433
434 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBufferRect.html */
435 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html */
436
437 void
438 enqueue_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, ...)
439 PPCODE:
440 cl_event ev = 0;
441 const size_t src_origin[3] = { src_x, src_y, src_z };
442 const size_t region[3] = { width, height, depth };
443 size_t len = row_pitch * (slice_pitch ? slice_pitch : 1) * depth;
444 EVENT_LIST (12, items - 12);
445
446 if (!len)
447 croak ("enqueue_read_image: currently, row_pitch must be specified to be non-zero");
448
449 SvUPGRADE (data, SVt_PV);
450 SvGROW (data, len);
451 SvPOK_only (data);
452 SvCUR_set (data, len);
453 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));
454
455 if (ev)
456 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
457
458 void
459 enqueue_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, ...)
460 PPCODE:
461 cl_event ev = 0;
462 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
463 const size_t region[3] = { width, height, depth };
464 STRLEN len;
465 char *ptr = SvPVbyte (data, len);
466 EVENT_LIST (12, items - 12);
467
468 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));
469
470 if (ev)
471 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
472
473 void
474 enqueue_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, ...)
475 PPCODE:
476 cl_event ev = 0;
477 const size_t src_origin[3] = { src_x, src_y, src_z };
478 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
479 const size_t region[3] = { width, height, depth };
480 EVENT_LIST (16, items - 16);
481
482 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));
483
484 if (ev)
485 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
486
487 void
488 enqueue_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, ...)
489 PPCODE:
490 cl_event ev = 0;
491 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
492 const size_t region[3] = { width, height, depth };
493 EVENT_LIST (10, items - 10);
494
495 NEED_SUCCESS (EnqueueCopyBufferToImage, (this, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
496
497 if (ev)
498 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
499
500 void
501 enqueue_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, ...)
502 PPCODE:
503 cl_event ev = 0;
504 const size_t src_origin[3] = { src_x, src_y, src_z };
505 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
506 const size_t region[3] = { width, height, depth };
507 EVENT_LIST (12, items - 12);
508
509 NEED_SUCCESS (EnqueueCopyImage, (this, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
510
511 if (ev)
512 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
513
514 void
515 enqueue_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, ...)
516 PPCODE:
517 cl_event ev = 0;
518 const size_t src_origin[3] = { src_x, src_y, src_z };
519 const size_t region[3] = { width, height, depth };
520 EVENT_LIST (10, items - 10);
521
522 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
523
524 if (ev)
525 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
526
527 void
528 enqueue_task (OpenCL::Queue this, OpenCL::Kernel kernel, ...)
529 PPCODE:
530 cl_event ev = 0;
531 EVENT_LIST (2, items - 2);
532
533 NEED_SUCCESS (EnqueueTask, (this, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
534
535 if (ev)
536 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
537
538 void
539 enqueue_nd_range_kernel (OpenCL::Queue this, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...)
540 PPCODE:
541 cl_event ev = 0;
542 size_t *gwo = 0, *gws, *lws = 0;
543 int gws_len;
544 size_t *lists;
545 int i;
546 EVENT_LIST (5, items - 5);
547
548 if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV)
549 croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference");
550
551 gws_len = AvFILLp (SvRV (global_work_size)) + 1;
552
553 lists = tmpbuf (sizeof (size_t) * 3 * gws_len);
554
555 gws = lists + gws_len * 0;
556 for (i = 0; i < gws_len; ++i)
557 gws [i] = SvIV (AvARRAY (SvRV (global_work_size))[i]);
558
559 if (SvOK (global_work_offset))
560 {
561 if (!SvROK (global_work_offset) || SvTYPE (SvRV (global_work_offset)) != SVt_PVAV)
562 croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array reference");
563
564 if (AvFILLp (SvRV (global_work_size)) + 1 != gws_len)
565 croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array of same size as global_work_size");
566
567 gwo = lists + gws_len * 1;
568 for (i = 0; i < gws_len; ++i)
569 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
570 }
571
572 if (SvOK (local_work_size))
573 {
574 if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV)
575 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference");
576
577 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len)
578 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
579
580 lws = lists + gws_len * 2;
581 for (i = 0; i < gws_len; ++i)
582 lws [i] = SvIV (AvARRAY (SvRV (local_work_size))[i]);
583 }
584
585 NEED_SUCCESS (EnqueueNDRangeKernel, (this, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
586
587 if (ev)
588 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
589
590 void
591 enqueue_marker (OpenCL::Queue this)
592 PPCODE:
593 cl_event ev;
594 NEED_SUCCESS (EnqueueMarker, (this, &ev));
595 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
596
597 void
598 enqueue_wait_for_events (OpenCL::Queue this, ...)
599 CODE:
600 EVENT_LIST (1, items - 1);
601 NEED_SUCCESS (EnqueueWaitForEvents, (this, event_list_count, event_list_ptr));
602
603 void
604 enqueue_barrier (OpenCL::Queue this)
605 CODE:
606 NEED_SUCCESS (EnqueueBarrier, (this));
607
608 void
609 flush (OpenCL::Queue this)
610 CODE:
611 NEED_SUCCESS (Flush, (this));
612
613 void
614 finish (OpenCL::Queue this)
615 CODE:
616 NEED_SUCCESS (Finish, (this));
617
618 MODULE = OpenCL PACKAGE = OpenCL::Memory
619
620 void
621 DESTROY (OpenCL::Memory this)
622 CODE:
623 clReleaseMemObject (this);
624
625 void
626 info (OpenCL::Memory this, cl_mem_info name)
627 PPCODE:
628 INFO (MemObject)
629
630 MODULE = OpenCL PACKAGE = OpenCL::Sampler
631
632 void
633 DESTROY (OpenCL::Sampler this)
634 CODE:
635 clReleaseSampler (this);
636
637 void
638 info (OpenCL::Sampler this, cl_sampler_info name)
639 PPCODE:
640 INFO (Sampler)
641
642 MODULE = OpenCL PACKAGE = OpenCL::Program
643
644 void
645 DESTROY (OpenCL::Program this)
646 CODE:
647 clReleaseProgram (this);
648
649 void
650 info (OpenCL::Program this, cl_program_info name)
651 PPCODE:
652 INFO (Program)
653
654 void
655 build (OpenCL::Program this, OpenCL::Device device, SV *options = &PL_sv_undef)
656 CODE:
657 NEED_SUCCESS (BuildProgram, (this, 1, &device, SvPVbyte_nolen (options), 0, 0));
658
659 void
660 build_info (OpenCL::Program this, OpenCL::Device device, cl_program_build_info name)
661 PPCODE:
662 size_t size;
663 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, 0, 0, &size));
664 SV *sv = sv_2mortal (newSV (size));
665 SvUPGRADE (sv, SVt_PV);
666 SvPOK_only (sv);
667 SvCUR_set (sv, size);
668 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, size, SvPVX (sv), 0));
669 XPUSHs (sv);
670
671 void
672 kernel (OpenCL::Program program, SV *function)
673 PPCODE:
674 NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res));
675 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel);
676
677 MODULE = OpenCL PACKAGE = OpenCL::Kernel
678
679 void
680 DESTROY (OpenCL::Kernel this)
681 CODE:
682 clReleaseKernel (this);
683
684 void
685 info (OpenCL::Kernel this, cl_kernel_info name)
686 PPCODE:
687 INFO (Kernel)
688
689 void
690 set_char (OpenCL::Kernel this, cl_uint idx, cl_char value)
691 CODE:
692 clSetKernelArg (this, idx, sizeof (value), &value);
693
694 void
695 set_uchar (OpenCL::Kernel this, cl_uint idx, cl_uchar value)
696 CODE:
697 clSetKernelArg (this, idx, sizeof (value), &value);
698
699 void
700 set_short (OpenCL::Kernel this, cl_uint idx, cl_short value)
701 CODE:
702 clSetKernelArg (this, idx, sizeof (value), &value);
703
704 void
705 set_ushort (OpenCL::Kernel this, cl_uint idx, cl_ushort value)
706 CODE:
707 clSetKernelArg (this, idx, sizeof (value), &value);
708
709 void
710 set_int (OpenCL::Kernel this, cl_uint idx, cl_int value)
711 CODE:
712 clSetKernelArg (this, idx, sizeof (value), &value);
713
714 void
715 set_uint (OpenCL::Kernel this, cl_uint idx, cl_uint value)
716 CODE:
717 clSetKernelArg (this, idx, sizeof (value), &value);
718
719 void
720 set_long (OpenCL::Kernel this, cl_uint idx, cl_long value)
721 CODE:
722 clSetKernelArg (this, idx, sizeof (value), &value);
723
724 void
725 set_ulong (OpenCL::Kernel this, cl_uint idx, cl_ulong value)
726 CODE:
727 clSetKernelArg (this, idx, sizeof (value), &value);
728
729 void
730 set_half (OpenCL::Kernel this, cl_uint idx, cl_half value)
731 CODE:
732 clSetKernelArg (this, idx, sizeof (value), &value);
733
734 void
735 set_float (OpenCL::Kernel this, cl_uint idx, cl_float value)
736 CODE:
737 clSetKernelArg (this, idx, sizeof (value), &value);
738
739 void
740 set_double (OpenCL::Kernel this, cl_uint idx, cl_double value)
741 CODE:
742 clSetKernelArg (this, idx, sizeof (value), &value);
743
744 void
745 set_memory (OpenCL::Kernel this, cl_uint idx, OpenCL::Memory_ornull value)
746 CODE:
747 clSetKernelArg (this, idx, sizeof (value), &value);
748
749 void
750 set_buffer (OpenCL::Kernel this, cl_uint idx, OpenCL::Buffer_ornull value)
751 CODE:
752 clSetKernelArg (this, idx, sizeof (value), &value);
753
754 void
755 set_image2d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image2D_ornull value)
756 CODE:
757 clSetKernelArg (this, idx, sizeof (value), &value);
758
759 void
760 set_image3d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image3D_ornull value)
761 CODE:
762 clSetKernelArg (this, idx, sizeof (value), &value);
763
764 void
765 set_sampler (OpenCL::Kernel this, cl_uint idx, OpenCL::Sampler value)
766 CODE:
767 clSetKernelArg (this, idx, sizeof (value), &value);
768
769 void
770 set_event (OpenCL::Kernel this, cl_uint idx, OpenCL::Event value)
771 CODE:
772 clSetKernelArg (this, idx, sizeof (value), &value);
773
774 MODULE = OpenCL PACKAGE = OpenCL::Event
775
776 void
777 DESTROY (OpenCL::Event this)
778 CODE:
779 clReleaseEvent (this);
780
781 void
782 info (OpenCL::Event this, cl_event_info name)
783 PPCODE:
784 INFO (Event)
785
786 void
787 wait (OpenCL::Event this)
788 CODE:
789 clWaitForEvents (1, &this);
790
791 MODULE = OpenCL PACKAGE = OpenCL::UserEvent
792
793 void
794 set_status (OpenCL::UserEvent this, cl_int execution_status)
795 CODE:
796 clSetUserEventStatus (this, execution_status);
797