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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.2 by root, Tue Nov 15 09:24:40 2011 UTC vs.
Revision 1.5 by root, Wed Nov 16 00:35:30 2011 UTC

7typedef cl_platform_id OpenCL__Platform; 7typedef cl_platform_id OpenCL__Platform;
8typedef cl_device_id OpenCL__Device; 8typedef cl_device_id OpenCL__Device;
9typedef cl_context OpenCL__Context; 9typedef cl_context OpenCL__Context;
10typedef cl_command_queue OpenCL__Queue; 10typedef cl_command_queue OpenCL__Queue;
11typedef cl_mem OpenCL__Memory; 11typedef cl_mem OpenCL__Memory;
12typedef cl_mem OpenCL__Buffer;
13typedef cl_mem OpenCL__Image;
14typedef cl_mem OpenCL__Image2D;
15typedef cl_mem OpenCL__Image3D;
16typedef cl_mem OpenCL__Memory_ornull;
17typedef cl_mem OpenCL__Buffer_ornull;
18typedef cl_mem OpenCL__Image_ornull;
19typedef cl_mem OpenCL__Image2D_ornull;
20typedef cl_mem OpenCL__Image3D_ornull;
12typedef cl_sampler OpenCL__Sampler; 21typedef cl_sampler OpenCL__Sampler;
13typedef cl_program OpenCL__Program; 22typedef cl_program OpenCL__Program;
14typedef cl_kernel OpenCL__Kernel; 23typedef cl_kernel OpenCL__Kernel;
15typedef cl_event OpenCL__Event; 24typedef cl_event OpenCL__Event;
25typedef cl_event OpenCL__UserEvent;
16 26
17static const struct { 27/*****************************************************************************/
28
29/* up to two temporary buffers */
30static void *
31tmpbuf (size_t size)
32{
33 static int idx;
34 static void *buf [2];
35 static size_t len [2];
36
37 idx ^= 1;
38
39 if (len [idx] < size)
40 {
41 free (buf [idx]);
42 len [idx] = ((size + 31) & ~4095) + 4096 - 32;
43 buf [idx] = malloc (len [idx]);
44 }
45
46 return buf [idx];
47}
48
49/*****************************************************************************/
50
51typedef struct
52{
18 IV iv; 53 IV iv;
19 const char *name; 54 const char *name;
20} cl_error[] = {
21#define def_error(name) { (IV)CL_ ## name, # name }, 55 #define const_iv(name) { (IV)CL_ ## name, # name },
22#include "invalid.h" 56} ivstr;
23};
24 57
25static const char * 58static const char *
26clstrerror (cl_int res) 59iv2str (IV value, const ivstr *base, int count, const char *fallback)
27{ 60{
28 int i; 61 int i;
29 static char numbuf [32]; 62 static char strbuf [32];
30 63
31 for (i = sizeof (cl_error) / sizeof (cl_error [0]); i--; ) 64 for (i = count; i--; )
32 if (cl_error [i].iv == res) 65 if (base [i].iv == value)
33 return cl_error [i].name; 66 return base [i].name;
34 67
35 snprintf (numbuf, sizeof (numbuf), "ERROR(%d)", res); 68 snprintf (strbuf, sizeof (strbuf), fallback, (int)value);
36 69
37 return numbuf; 70 return strbuf;
38} 71}
39 72
73static const char *
74enum2str (cl_uint value)
75{
76 static const ivstr enumstr[] = {
77 #include "enumstr.h"
78 };
79
80 return iv2str (value, enumstr, sizeof (enumstr) / sizeof (enumstr [0]), "ENUM(0x%04x)");
81}
82
83static const char *
84err2str (cl_int err)
85{
86 static const ivstr errstr[] = {
87 #include "errstr.h"
88 };
89
90 return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)");
91}
92
93/*****************************************************************************/
94
95static cl_int last_error;
96
40#define FAIL(name,res) \ 97#define FAIL(name,err) \
41 croak ("cl" # name ": %s", clstrerror (res)); 98 croak ("cl" # name ": %s", err2str (last_error = err));
42 99
43#define NEED_SUCCESS(name,args) \ 100#define NEED_SUCCESS(name,args) \
44 do { \ 101 do { \
45 cl_int res = cl ## name args; \ 102 cl_int res = cl ## name args; \
46 \ 103 \
47 if (res) \ 104 if (res) \
48 FAIL (name, res); \ 105 FAIL (name, res); \
49 } while (0) 106 } while (0)
50 107
108/*****************************************************************************/
109
51#define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr) 110#define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr)
52#define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr)) 111#define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr))
53 112
54/*TODO*/ 113static void *
55#define EVENT_LIST(items,count) cl_uint event_list_count = 0; cl_event *event_list_ptr = 0 114SvPTROBJ (const char *func, const char *svname, SV *sv, const char *pkg)
115{
116 if (SvROK (sv) && sv_derived_from (sv, pkg))
117 return (void *)SvIV (SvRV (sv));
118
119 croak ("%s: %s is not of type %s", func, svname, pkg);
120}
121
122/*****************************************************************************/
123
124static cl_event *
125event_list (SV **items, int count)
126{
127 cl_event *list = tmpbuf (sizeof (cl_event) * count);
128
129 while (count--)
130 list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event");
131
132 return list;
133}
134
135#define EVENT_LIST(items,count) \
136 cl_uint event_list_count = (count); \
137 cl_event *event_list_ptr = event_list (&ST (items), event_list_count)
56 138
57#define INFO(class) \ 139#define INFO(class) \
58{ \ 140{ \
59 size_t size; \ 141 size_t size; \
60 SV *sv; \ 142 SV *sv; \
73PROTOTYPES: ENABLE 155PROTOTYPES: ENABLE
74 156
75BOOT: 157BOOT:
76{ 158{
77 HV *stash = gv_stashpv ("OpenCL", 1); 159 HV *stash = gv_stashpv ("OpenCL", 1);
78 static const struct {
79 const char *name;
80 IV iv;
81 } *civ, const_iv[] = { 160 static const ivstr *civ, const_iv[] = {
82#define const_iv(name) { # name, (IV)CL_ ## name }, 161 { sizeof (cl_char ), "SIZEOF_CHAR" },
162 { sizeof (cl_uchar ), "SIZEOF_UCHAR" },
163 { sizeof (cl_short ), "SIZEOF_SHORT" },
164 { sizeof (cl_ushort), "SIZEOF_USHORT" },
165 { sizeof (cl_int ), "SIZEOF_INT" },
166 { sizeof (cl_uint ), "SIZEOF_UINT" },
167 { sizeof (cl_long ), "SIZEOF_LONG" },
168 { sizeof (cl_ulong ), "SIZEOF_ULONG" },
169 { sizeof (cl_half ), "SIZEOF_HALF" },
170 { sizeof (cl_float ), "SIZEOF_FLOAT" },
171 { sizeof (cl_double), "SIZEOF_DOUBLE" },
83#include "constiv.h" 172#include "constiv.h"
84 }; 173 };
85 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 174 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
86 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 175 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
87} 176}
88 177
178cl_int
179errno ()
180 CODE:
181 errno = last_error;
182
183const char *
184err2str (cl_int err)
185
186const char *
187enum2str (cl_uint value)
188
89void 189void
90platforms () 190platforms ()
91 PPCODE: 191 PPCODE:
92{ 192{
93 cl_platform_id *list; 193 cl_platform_id *list;
94 cl_uint count; 194 cl_uint count;
95 int i; 195 int i;
96 196
97 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count)); 197 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count));
98 Newx (list, count, cl_platform_id); 198 list = tmpbuf (sizeof (*list) * count);
99 NEED_SUCCESS (GetPlatformIDs, (count, list, 0)); 199 NEED_SUCCESS (GetPlatformIDs, (count, list, 0));
100 200
101 EXTEND (SP, count); 201 EXTEND (SP, count);
102 for (i = 0; i < count; ++i) 202 for (i = 0; i < count; ++i)
103 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); 203 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i]));
104
105 Safefree (list);
106} 204}
107 205
108void 206void
109context_from_type_simple (cl_device_type type = CL_DEVICE_TYPE_DEFAULT) 207context_from_type_simple (cl_device_type type = CL_DEVICE_TYPE_DEFAULT)
110 PPCODE: 208 PPCODE:
142 cl_device_id *list; 240 cl_device_id *list;
143 cl_uint count; 241 cl_uint count;
144 int i; 242 int i;
145 243
146 NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count)); 244 NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count));
147 Newx (list, count, cl_device_id); 245 list = tmpbuf (sizeof (*list) * count);
148 NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0)); 246 NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0));
149 247
150 EXTEND (SP, count); 248 EXTEND (SP, count);
151 for (i = 0; i < count; ++i) 249 for (i = 0; i < count; ++i)
152 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); 250 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i]));
153
154 Safefree (list);
155} 251}
156 252
157void 253void
158context_from_type_simple (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_DEFAULT) 254context_from_type_simple (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_DEFAULT)
159 PPCODE: 255 PPCODE:
166 FAIL (CreateContextFromType, res); 262 FAIL (CreateContextFromType, res);
167 263
168 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 264 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
169} 265}
170 266
171void
172unload_compiler ()
173 CODE:
174 NEED_SUCCESS (UnloadCompiler, ());
175
176MODULE = OpenCL PACKAGE = OpenCL::Device 267MODULE = OpenCL PACKAGE = OpenCL::Device
177 268
178void 269void
179info (OpenCL::Device this, cl_device_info name) 270info (OpenCL::Device this, cl_device_info name)
180 PPCODE: 271 PPCODE:
217 308
218 XPUSH_NEW_OBJ ("OpenCL::Queue", queue); 309 XPUSH_NEW_OBJ ("OpenCL::Queue", queue);
219} 310}
220 311
221void 312void
313user_event (OpenCL::Context this)
314 PPCODE:
315{
316 cl_int res;
317 cl_event ev = clCreateUserEvent (this, &res);
318
319 if (res)
320 FAIL (CreateUserevent, res);
321
322 XPUSH_NEW_OBJ ("OpenCL::UserEvent", ev);
323}
324
325void
222buffer (OpenCL::Context this, cl_mem_flags flags, size_t len) 326buffer (OpenCL::Context this, cl_mem_flags flags, size_t len)
223 PPCODE: 327 PPCODE:
224{ 328{
225 cl_int res; 329 cl_int res;
330 cl_mem mem;
331
332 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
333 croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?");
334
226 cl_mem mem = clCreateBuffer (this, flags, len, 0, &res); 335 mem = clCreateBuffer (this, flags, len, 0, &res);
227 336
228 if (res) 337 if (res)
229 FAIL (CreateBuffer, res); 338 FAIL (CreateBuffer, res);
230 339
231 XPUSH_NEW_OBJ ("OpenCL::Memory", mem); 340 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
232} 341}
233 342
234void 343void
235buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data) 344buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data)
236 PPCODE: 345 PPCODE:
237{ 346{
238 STRLEN len; 347 STRLEN len;
239 char *ptr = SvPVbyte (data, len); 348 char *ptr = SvPVbyte (data, len);
240 cl_int res; 349 cl_int res;
350 cl_mem mem;
351
352 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
353 croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
354
241 cl_mem mem = clCreateBuffer (this, flags, len, ptr, &res); 355 mem = clCreateBuffer (this, flags, len, ptr, &res);
242 356
243 if (res) 357 if (res)
244 FAIL (CreateBuffer, res); 358 FAIL (CreateBuffer, res);
245 359
246 XPUSH_NEW_OBJ ("OpenCL::Memory", mem); 360 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
361}
362
363void
364image2d (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)
365 PPCODE:
366{
367 STRLEN len;
368 char *ptr = SvPVbyte (data, len);
369 const cl_image_format format = { channel_order, channel_type };
370 cl_int res;
371 cl_mem mem = clCreateImage2D (this, flags, &format, width, height, len / height, ptr, &res);
372
373 if (res)
374 FAIL (CreateImage2D, res);
375
376 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
377}
378
379void
380image3d (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)
381 PPCODE:
382{
383 STRLEN len;
384 char *ptr = SvPVbyte (data, len);
385 const cl_image_format format = { channel_order, channel_type };
386 cl_int res;
387 cl_mem mem = clCreateImage3D (this, flags, &format, width, height,
388 depth, len / (height * slice_pitch), slice_pitch, ptr, &res);
389
390 if (res)
391 FAIL (CreateImage3D, res);
392
393 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
394}
395
396void
397supported_image_formats (OpenCL::Context this, cl_mem_flags flags, cl_mem_object_type image_type)
398 PPCODE:
399{
400 cl_uint count;
401 cl_image_format *list;
402 int i;
403
404 NEED_SUCCESS (GetSupportedImageFormats, (this, flags, image_type, 0, 0, &count));
405 Newx (list, count, cl_image_format);
406 NEED_SUCCESS (GetSupportedImageFormats, (this, flags, image_type, count, list, 0));
407
408 EXTEND (SP, count);
409 for (i = 0; i < count; ++i)
410 {
411 AV *av = newAV ();
412 av_store (av, 1, newSVuv (list [i].image_channel_data_type));
413 av_store (av, 0, newSVuv (list [i].image_channel_order));
414 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
415 }
247} 416}
248 417
249void 418void
250sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode) 419sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode)
251 PPCODE: 420 PPCODE:
289info (OpenCL::Queue this, cl_command_queue_info name) 458info (OpenCL::Queue this, cl_command_queue_info name)
290 PPCODE: 459 PPCODE:
291 INFO (CommandQueue) 460 INFO (CommandQueue)
292 461
293void 462void
294enqueue_read_buffer (OpenCL::Queue this, OpenCL::Memory mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...) 463enqueue_read_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...)
295 PPCODE: 464 PPCODE:
296{ 465{
297 cl_event ev = 0; 466 cl_event ev = 0;
298 EVENT_LIST (6, items - 6); 467 EVENT_LIST (6, items - 6);
299 468
306 if (ev) 475 if (ev)
307 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 476 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
308} 477}
309 478
310void 479void
311enqueue_write_buffer (OpenCL::Queue this, OpenCL::Memory mem, cl_bool blocking, size_t offset, SV *data, ...) 480enqueue_write_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...)
312 PPCODE: 481 PPCODE:
313{ 482{
314 cl_event ev = 0; 483 cl_event ev = 0;
315 STRLEN len; 484 STRLEN len;
316 char *ptr = SvPVbyte (data, len); 485 char *ptr = SvPVbyte (data, len);
321 if (ev) 490 if (ev)
322 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 491 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
323} 492}
324 493
325void 494void
326enqueue_copy_buffer (OpenCL::Queue this, OpenCL::Memory src, OpenCL::Memory dst, size_t src_offset, size_t dst_offset, size_t len, ...) 495enqueue_copy_buffer (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...)
327 PPCODE: 496 PPCODE:
328{ 497{
329 cl_event ev = 0; 498 cl_event ev = 0;
330 EVENT_LIST (6, items - 6); 499 EVENT_LIST (6, items - 6);
331 500
332 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 501 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
502
503 if (ev)
504 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
505}
506
507 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBufferRect.html */
508 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html */
509
510void
511enqueue_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, ...)
512 PPCODE:
513{
514 cl_event ev = 0;
515 const size_t src_origin[3] = { src_x, src_y, src_z };
516 const size_t region[3] = { width, height, depth };
517 size_t len = row_pitch * slice_pitch * depth;
518 EVENT_LIST (11, items - 11);
519
520 SvUPGRADE (data, SVt_PV);
521 SvGROW (data, len);
522 SvPOK_only (data);
523 SvCUR_set (data, len);
524 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));
525
526 if (ev)
527 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
528}
529
530void
531enqueue_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, ...)
532 PPCODE:
533{
534 cl_event ev = 0;
535 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
536 const size_t region[3] = { width, height, depth };
537 STRLEN len;
538 char *ptr = SvPVbyte (data, len);
539 size_t slice_pitch = len / (row_pitch * height);
540 EVENT_LIST (11, items - 11);
541
542 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));
543
544 if (ev)
545 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
546}
547
548void
549enqueue_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, ...)
550 PPCODE:
551{
552 cl_event ev = 0;
553 const size_t src_origin[3] = { src_x, src_y, src_z };
554 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
555 const size_t region[3] = { width, height, depth };
556 EVENT_LIST (16, items - 16);
557
558 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));
559
560 if (ev)
561 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
562}
563
564void
565enqueue_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, ...)
566 PPCODE:
567{
568 cl_event ev = 0;
569 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
570 const size_t region[3] = { width, height, depth };
571 EVENT_LIST (10, items - 10);
572
573 NEED_SUCCESS (EnqueueCopyBufferToImage, (this, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
574
575 if (ev)
576 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
577}
578
579void
580enqueue_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, ...)
581 PPCODE:
582{
583 cl_event ev = 0;
584 const size_t src_origin[3] = { src_x, src_y, src_z };
585 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
586 const size_t region[3] = { width, height, depth };
587 EVENT_LIST (12, items - 12);
588
589 NEED_SUCCESS (EnqueueCopyImage, (this, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
590
591 if (ev)
592 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
593}
594
595void
596enqueue_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, ...)
597 PPCODE:
598{
599 cl_event ev = 0;
600 const size_t src_origin[3] = { src_x, src_y, src_z };
601 const size_t region[3] = { width, height, depth };
602 EVENT_LIST (10, items - 10);
603
604 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
605
606 if (ev)
607 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
608}
609
610void
611enqueue_task (OpenCL::Queue this, OpenCL::Kernel kernel, ...)
612 PPCODE:
613{
614 cl_event ev = 0;
615 EVENT_LIST (2, items - 2);
616
617 NEED_SUCCESS (EnqueueTask, (this, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
618
619 if (ev)
620 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
621}
622
623void
624enqueue_nd_range_kernel (OpenCL::Queue this, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...)
625 PPCODE:
626{
627 cl_event ev = 0;
628 size_t *gwo = 0, *gws, *lws = 0;
629 int gws_len;
630 size_t *lists;
631 int i;
632 EVENT_LIST (5, items - 5);
633
634 if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV)
635 croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference");
636
637 gws_len = AvFILLp (SvRV (global_work_size)) + 1;
638
639 lists = tmpbuf (sizeof (size_t) * 3 * gws_len);
640
641 gws = lists + gws_len * 0;
642 for (i = 0; i < gws_len; ++i)
643 gws [i] = SvIV (AvARRAY (SvRV (global_work_size))[i]);
644
645 if (SvOK (global_work_offset))
646 {
647 if (!SvROK (global_work_offset) || SvTYPE (SvRV (global_work_offset)) != SVt_PVAV)
648 croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array reference");
649
650 if (AvFILLp (SvRV (global_work_size)) + 1 != gws_len)
651 croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array of same size as global_work_size");
652
653 gwo = lists + gws_len * 1;
654 for (i = 0; i < gws_len; ++i)
655 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
656 }
657
658 if (SvOK (local_work_size))
659 {
660 if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV)
661 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference");
662
663 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len)
664 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
665
666 lws = lists + gws_len * 2;
667 for (i = 0; i < gws_len; ++i)
668 lws [i] = SvIV (AvARRAY (SvRV (local_work_size))[i]);
669 }
670
671 NEED_SUCCESS (EnqueueNDRangeKernel, (this, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
333 672
334 if (ev) 673 if (ev)
335 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 674 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
336} 675}
337 676
354 693
355void 694void
356enqueue_barrier (OpenCL::Queue this) 695enqueue_barrier (OpenCL::Queue this)
357 CODE: 696 CODE:
358 NEED_SUCCESS (EnqueueBarrier, (this)); 697 NEED_SUCCESS (EnqueueBarrier, (this));
698
699void
700flush (OpenCL::Queue this)
701 CODE:
702 NEED_SUCCESS (Flush, (this));
703
704void
705finish (OpenCL::Queue this)
706 CODE:
707 NEED_SUCCESS (Finish, (this));
359 708
360MODULE = OpenCL PACKAGE = OpenCL::Memory 709MODULE = OpenCL PACKAGE = OpenCL::Memory
361 710
362void 711void
363DESTROY (OpenCL::Memory this) 712DESTROY (OpenCL::Memory this)
438info (OpenCL::Kernel this, cl_kernel_info name) 787info (OpenCL::Kernel this, cl_kernel_info name)
439 PPCODE: 788 PPCODE:
440 INFO (Kernel) 789 INFO (Kernel)
441 790
442void 791void
443set_bool (OpenCL::Kernel this, cl_uint idx, cl_bool value) 792set_char (OpenCL::Kernel this, cl_uint idx, cl_char value)
444 CODE: 793 CODE:
445 clKernelSetArg (this, idx, sizeof (value), &value); 794 clSetKernelArg (this, idx, sizeof (value), &value);
795
796void
797set_uchar (OpenCL::Kernel this, cl_uint idx, cl_uchar value)
798 CODE:
799 clSetKernelArg (this, idx, sizeof (value), &value);
800
801void
802set_short (OpenCL::Kernel this, cl_uint idx, cl_short value)
803 CODE:
804 clSetKernelArg (this, idx, sizeof (value), &value);
805
806void
807set_ushort (OpenCL::Kernel this, cl_uint idx, cl_ushort value)
808 CODE:
809 clSetKernelArg (this, idx, sizeof (value), &value);
810
811void
812set_int (OpenCL::Kernel this, cl_uint idx, cl_int value)
813 CODE:
814 clSetKernelArg (this, idx, sizeof (value), &value);
815
816void
817set_uint (OpenCL::Kernel this, cl_uint idx, cl_uint value)
818 CODE:
819 clSetKernelArg (this, idx, sizeof (value), &value);
820
821void
822set_long (OpenCL::Kernel this, cl_uint idx, cl_long value)
823 CODE:
824 clSetKernelArg (this, idx, sizeof (value), &value);
825
826void
827set_ulong (OpenCL::Kernel this, cl_uint idx, cl_ulong value)
828 CODE:
829 clSetKernelArg (this, idx, sizeof (value), &value);
830
831void
832set_half (OpenCL::Kernel this, cl_uint idx, cl_half value)
833 CODE:
834 clSetKernelArg (this, idx, sizeof (value), &value);
835
836void
837set_float (OpenCL::Kernel this, cl_uint idx, cl_float value)
838 CODE:
839 clSetKernelArg (this, idx, sizeof (value), &value);
840
841void
842set_double (OpenCL::Kernel this, cl_uint idx, cl_double value)
843 CODE:
844 clSetKernelArg (this, idx, sizeof (value), &value);
845
846void
847set_memory (OpenCL::Kernel this, cl_uint idx, OpenCL::Memory_ornull value)
848 CODE:
849 clSetKernelArg (this, idx, sizeof (value), &value);
850
851void
852set_buffer (OpenCL::Kernel this, cl_uint idx, OpenCL::Buffer_ornull value)
853 CODE:
854 clSetKernelArg (this, idx, sizeof (value), &value);
855
856void
857set_image2d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image2D_ornull value)
858 CODE:
859 clSetKernelArg (this, idx, sizeof (value), &value);
860
861void
862set_image3d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image3D_ornull value)
863 CODE:
864 clSetKernelArg (this, idx, sizeof (value), &value);
865
866void
867set_sampler (OpenCL::Kernel this, cl_uint idx, OpenCL::Sampler value)
868 CODE:
869 clSetKernelArg (this, idx, sizeof (value), &value);
870
871void
872set_event (OpenCL::Kernel this, cl_uint idx, OpenCL::Event value)
873 CODE:
874 clSetKernelArg (this, idx, sizeof (value), &value);
446 875
447MODULE = OpenCL PACKAGE = OpenCL::Event 876MODULE = OpenCL PACKAGE = OpenCL::Event
448 877
449void 878void
450DESTROY (OpenCL::Event this) 879DESTROY (OpenCL::Event this)
459void 888void
460wait (OpenCL::Event this) 889wait (OpenCL::Event this)
461 CODE: 890 CODE:
462 clWaitForEvents (1, &this); 891 clWaitForEvents (1, &this);
463 892
893MODULE = OpenCL PACKAGE = OpenCL::UserEvent
894
895void
896set_status (OpenCL::UserEvent this, cl_int execution_status)
897 CODE:
898 clSetUserEventStatus (this, execution_status);
899

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines