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.4 by root, Tue Nov 15 21:13:42 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;
16 25
17static const struct { 26typedef struct
27{
18 IV iv; 28 IV iv;
19 const char *name; 29 const char *name;
20} cl_error[] = {
21#define def_error(name) { (IV)CL_ ## name, # name }, 30 #define const_iv(name) { (IV)CL_ ## name, # name },
22#include "invalid.h" 31} ivstr;
23};
24 32
25static const char * 33static const char *
26clstrerror (cl_int res) 34iv2str (IV value, const ivstr *base, int count, const char *fallback)
27{ 35{
28 int i; 36 int i;
29 static char numbuf [32]; 37 static char strbuf [32];
30 38
31 for (i = sizeof (cl_error) / sizeof (cl_error [0]); i--; ) 39 for (i = count; i--; )
32 if (cl_error [i].iv == res) 40 if (base [i].iv == value)
33 return cl_error [i].name; 41 return base [i].name;
34 42
35 snprintf (numbuf, sizeof (numbuf), "ERROR(%d)", res); 43 snprintf (strbuf, sizeof (strbuf), fallback, (int)value);
36 44
37 return numbuf; 45 return strbuf;
46}
47
48static const char *
49enum2str (cl_uint value)
50{
51 static const ivstr enumstr[] = {
52 #include "enumstr.h"
53 };
54
55 return iv2str (value, enumstr, sizeof (enumstr) / sizeof (enumstr [0]), "ENUM(0x%04x)");
56}
57
58static const char *
59err2str (cl_int err)
60{
61 static const ivstr errstr[] = {
62 #include "errstr.h"
63 };
64
65 return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)");
38} 66}
39 67
40#define FAIL(name,res) \ 68#define FAIL(name,res) \
41 croak ("cl" # name ": %s", clstrerror (res)); 69 croak ("cl" # name ": %s", err2str (res));
42 70
43#define NEED_SUCCESS(name,args) \ 71#define NEED_SUCCESS(name,args) \
44 do { \ 72 do { \
45 cl_int res = cl ## name args; \ 73 cl_int res = cl ## name args; \
46 \ 74 \
66 SvCUR_set (sv, size); \ 94 SvCUR_set (sv, size); \
67 NEED_SUCCESS (Get ## class ## Info, (this, name, size, SvPVX (sv), 0)); \ 95 NEED_SUCCESS (Get ## class ## Info, (this, name, size, SvPVX (sv), 0)); \
68 XPUSHs (sv); \ 96 XPUSHs (sv); \
69} 97}
70 98
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
108static void *
109tmpbuf (size_t size)
110{
111 static void *buf;
112 static size_t len;
113
114 if (len < size)
115 {
116 free (buf);
117 len = ((size + 31) & ~4095) + 4096 - 32;
118 buf = malloc (len);
119 }
120
121 return buf;
122}
123
71MODULE = OpenCL PACKAGE = OpenCL 124MODULE = OpenCL PACKAGE = OpenCL
72 125
73PROTOTYPES: ENABLE 126PROTOTYPES: ENABLE
74 127
75BOOT: 128BOOT:
76{ 129{
77 HV *stash = gv_stashpv ("OpenCL", 1); 130 HV *stash = gv_stashpv ("OpenCL", 1);
78 static const struct {
79 const char *name;
80 IV iv;
81 } *civ, const_iv[] = { 131 static const ivstr *civ, const_iv[] = {
82#define const_iv(name) { # name, (IV)CL_ ## name }, 132 { sizeof (cl_char ), "SIZEOF_CHAR" },
133 { sizeof (cl_uchar ), "SIZEOF_UCHAR" },
134 { sizeof (cl_short ), "SIZEOF_SHORT" },
135 { sizeof (cl_ushort), "SIZEOF_USHORT"},
136 { sizeof (cl_int ), "SIZEOF_INT" },
137 { sizeof (cl_uint ), "SIZEOF_UINT" },
138 { sizeof (cl_long ), "SIZEOF_LONG" },
139 { sizeof (cl_ulong ), "SIZEOF_ULONG" },
140 { sizeof (cl_half ), "SIZEOF_HALF" },
141 { sizeof (cl_float ), "SIZEOF_FLOAT" },
83#include "constiv.h" 142#include "constiv.h"
84 }; 143 };
85 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 144 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)); 145 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
87} 146}
88 147
148const char *
149err2str (cl_int err)
150
151const char *
152enum2str (cl_uint value)
153
89void 154void
90platforms () 155platforms ()
91 PPCODE: 156 PPCODE:
92{ 157{
93 cl_platform_id *list; 158 cl_platform_id *list;
94 cl_uint count; 159 cl_uint count;
95 int i; 160 int i;
96 161
97 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count)); 162 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count));
98 Newx (list, count, cl_platform_id); 163 list = tmpbuf (sizeof (*list) * count);
99 NEED_SUCCESS (GetPlatformIDs, (count, list, 0)); 164 NEED_SUCCESS (GetPlatformIDs, (count, list, 0));
100 165
101 EXTEND (SP, count); 166 EXTEND (SP, count);
102 for (i = 0; i < count; ++i) 167 for (i = 0; i < count; ++i)
103 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); 168 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i]));
104
105 Safefree (list);
106} 169}
107 170
108void 171void
109context_from_type_simple (cl_device_type type = CL_DEVICE_TYPE_DEFAULT) 172context_from_type_simple (cl_device_type type = CL_DEVICE_TYPE_DEFAULT)
110 PPCODE: 173 PPCODE:
142 cl_device_id *list; 205 cl_device_id *list;
143 cl_uint count; 206 cl_uint count;
144 int i; 207 int i;
145 208
146 NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count)); 209 NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count));
147 Newx (list, count, cl_device_id); 210 list = tmpbuf (sizeof (*list) * count);
148 NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0)); 211 NEED_SUCCESS (GetDeviceIDs, (this, type, 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 (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); 215 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i]));
153
154 Safefree (list);
155} 216}
156 217
157void 218void
158context_from_type_simple (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_DEFAULT) 219context_from_type_simple (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_DEFAULT)
159 PPCODE: 220 PPCODE:
166 FAIL (CreateContextFromType, res); 227 FAIL (CreateContextFromType, res);
167 228
168 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 229 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
169} 230}
170 231
171void
172unload_compiler ()
173 CODE:
174 NEED_SUCCESS (UnloadCompiler, ());
175
176MODULE = OpenCL PACKAGE = OpenCL::Device 232MODULE = OpenCL PACKAGE = OpenCL::Device
177 233
178void 234void
179info (OpenCL::Device this, cl_device_info name) 235info (OpenCL::Device this, cl_device_info name)
180 PPCODE: 236 PPCODE:
221void 277void
222buffer (OpenCL::Context this, cl_mem_flags flags, size_t len) 278buffer (OpenCL::Context this, cl_mem_flags flags, size_t len)
223 PPCODE: 279 PPCODE:
224{ 280{
225 cl_int res; 281 cl_int res;
282 cl_mem mem;
283
284 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
285 croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?");
286
226 cl_mem mem = clCreateBuffer (this, flags, len, 0, &res); 287 mem = clCreateBuffer (this, flags, len, 0, &res);
227 288
228 if (res) 289 if (res)
229 FAIL (CreateBuffer, res); 290 FAIL (CreateBuffer, res);
230 291
231 XPUSH_NEW_OBJ ("OpenCL::Memory", mem); 292 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
232} 293}
233 294
234void 295void
235buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data) 296buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data)
236 PPCODE: 297 PPCODE:
237{ 298{
238 STRLEN len; 299 STRLEN len;
239 char *ptr = SvPVbyte (data, len); 300 char *ptr = SvPVbyte (data, len);
240 cl_int res; 301 cl_int res;
302 cl_mem mem;
303
304 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
305 croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
306
241 cl_mem mem = clCreateBuffer (this, flags, len, ptr, &res); 307 mem = clCreateBuffer (this, flags, len, ptr, &res);
242 308
243 if (res) 309 if (res)
244 FAIL (CreateBuffer, res); 310 FAIL (CreateBuffer, res);
245 311
246 XPUSH_NEW_OBJ ("OpenCL::Memory", mem); 312 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
313}
314
315void
316image2d (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)
317 PPCODE:
318{
319 STRLEN len;
320 char *ptr = SvPVbyte (data, len);
321 const cl_image_format format = { channel_order, channel_type };
322 cl_int res;
323 cl_mem mem = clCreateImage2D (this, flags, &format, width, height, len / height, ptr, &res);
324
325 if (res)
326 FAIL (CreateImage2D, res);
327
328 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
329}
330
331void
332image3d (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)
333 PPCODE:
334{
335 STRLEN len;
336 char *ptr = SvPVbyte (data, len);
337 const cl_image_format format = { channel_order, channel_type };
338 cl_int res;
339 cl_mem mem = clCreateImage3D (this, flags, &format, width, height,
340 depth, len / (height * slice_pitch), slice_pitch, ptr, &res);
341
342 if (res)
343 FAIL (CreateImage3D, res);
344
345 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
346}
347
348void
349supported_image_formats (OpenCL::Context this, cl_mem_flags flags, cl_mem_object_type image_type)
350 PPCODE:
351{
352 cl_uint count;
353 cl_image_format *list;
354 int i;
355
356 NEED_SUCCESS (GetSupportedImageFormats, (this, flags, image_type, 0, 0, &count));
357 Newx (list, count, cl_image_format);
358 NEED_SUCCESS (GetSupportedImageFormats, (this, flags, image_type, count, list, 0));
359
360 EXTEND (SP, count);
361 for (i = 0; i < count; ++i)
362 {
363 AV *av = newAV ();
364 av_store (av, 1, newSVuv (list [i].image_channel_data_type));
365 av_store (av, 0, newSVuv (list [i].image_channel_order));
366 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
367 }
247} 368}
248 369
249void 370void
250sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode) 371sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode)
251 PPCODE: 372 PPCODE:
289info (OpenCL::Queue this, cl_command_queue_info name) 410info (OpenCL::Queue this, cl_command_queue_info name)
290 PPCODE: 411 PPCODE:
291 INFO (CommandQueue) 412 INFO (CommandQueue)
292 413
293void 414void
294enqueue_read_buffer (OpenCL::Queue this, OpenCL::Memory mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...) 415enqueue_read_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...)
295 PPCODE: 416 PPCODE:
296{ 417{
297 cl_event ev = 0; 418 cl_event ev = 0;
298 EVENT_LIST (6, items - 6); 419 EVENT_LIST (6, items - 6);
299 420
306 if (ev) 427 if (ev)
307 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 428 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
308} 429}
309 430
310void 431void
311enqueue_write_buffer (OpenCL::Queue this, OpenCL::Memory mem, cl_bool blocking, size_t offset, SV *data, ...) 432enqueue_write_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...)
312 PPCODE: 433 PPCODE:
313{ 434{
314 cl_event ev = 0; 435 cl_event ev = 0;
315 STRLEN len; 436 STRLEN len;
316 char *ptr = SvPVbyte (data, len); 437 char *ptr = SvPVbyte (data, len);
321 if (ev) 442 if (ev)
322 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 443 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
323} 444}
324 445
325void 446void
326enqueue_copy_buffer (OpenCL::Queue this, OpenCL::Memory src, OpenCL::Memory dst, size_t src_offset, size_t dst_offset, size_t len, ...) 447enqueue_copy_buffer (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...)
327 PPCODE: 448 PPCODE:
328{ 449{
329 cl_event ev = 0; 450 cl_event ev = 0;
330 EVENT_LIST (6, items - 6); 451 EVENT_LIST (6, items - 6);
331 452
332 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 453 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, 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
459 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBufferRect.html */
460 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html */
461
462void
463enqueue_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, ...)
464 PPCODE:
465{
466 cl_event ev = 0;
467 const size_t src_origin[3] = { src_x, src_y, src_z };
468 const size_t region[3] = { width, height, depth };
469 size_t len = row_pitch * slice_pitch * depth;
470 EVENT_LIST (11, items - 11);
471
472 SvUPGRADE (data, SVt_PV);
473 SvGROW (data, len);
474 SvPOK_only (data);
475 SvCUR_set (data, len);
476 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));
477
478 if (ev)
479 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
480}
481
482void
483enqueue_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, ...)
484 PPCODE:
485{
486 cl_event ev = 0;
487 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
488 const size_t region[3] = { width, height, depth };
489 STRLEN len;
490 char *ptr = SvPVbyte (data, len);
491 size_t slice_pitch = len / (row_pitch * height);
492 EVENT_LIST (11, items - 11);
493
494 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));
495
496 if (ev)
497 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
498}
499
500void
501enqueue_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, ...)
502 PPCODE:
503{
504 cl_event ev = 0;
505 const size_t src_origin[3] = { src_x, src_y, src_z };
506 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
507 const size_t region[3] = { width, height, depth };
508 EVENT_LIST (16, items - 16);
509
510 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));
511
512 if (ev)
513 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
514}
515
516void
517enqueue_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, ...)
518 PPCODE:
519{
520 cl_event ev = 0;
521 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
522 const size_t region[3] = { width, height, depth };
523 EVENT_LIST (10, items - 10);
524
525 NEED_SUCCESS (EnqueueCopyBufferToImage, (this, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
526
527 if (ev)
528 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
529}
530
531void
532enqueue_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, ...)
533 PPCODE:
534{
535 cl_event ev = 0;
536 const size_t src_origin[3] = { src_x, src_y, src_z };
537 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
538 const size_t region[3] = { width, height, depth };
539 EVENT_LIST (12, items - 12);
540
541 NEED_SUCCESS (EnqueueCopyImage, (this, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
542
543 if (ev)
544 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
545}
546
547void
548enqueue_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, ...)
549 PPCODE:
550{
551 cl_event ev = 0;
552 const size_t src_origin[3] = { src_x, src_y, src_z };
553 const size_t region[3] = { width, height, depth };
554 EVENT_LIST (10, items - 10);
555
556 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
557
558 if (ev)
559 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
560}
561
562void
563enqueue_task (OpenCL::Queue this, OpenCL::Kernel kernel, ...)
564 PPCODE:
565{
566 cl_event ev = 0;
567 EVENT_LIST (2, items - 2);
568
569 NEED_SUCCESS (EnqueueTask, (this, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
570
571 if (ev)
572 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
573}
574
575void
576enqueue_nd_range_kernel (OpenCL::Queue this, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...)
577 PPCODE:
578{
579 cl_event ev = 0;
580 size_t *gwo = 0, *gws, *lws = 0;
581 int gws_len;
582 size_t *lists;
583 int i;
584 EVENT_LIST (2, items - 2);
585
586 if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV)
587 croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference");
588
589 gws_len = AvFILLp (SvRV (global_work_size)) + 1;
590
591 lists = tmpbuf (sizeof (size_t) * 3 * gws_len);
592
593 gws = lists + gws_len * 0;
594 for (i = 0; i < gws_len; ++i)
595 gws [i] = SvIV (AvARRAY (SvRV (global_work_size))[i]);
596
597 if (SvOK (global_work_offset))
598 {
599 if (!SvROK (global_work_offset) || SvTYPE (SvRV (global_work_offset)) != SVt_PVAV)
600 croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array reference");
601
602 if (AvFILLp (SvRV (global_work_size)) + 1 != gws_len)
603 croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array of same size as global_work_size");
604
605 gwo = lists + gws_len * 1;
606 for (i = 0; i < gws_len; ++i)
607 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
608 }
609
610 if (SvOK (local_work_size))
611 {
612 if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV)
613 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference");
614
615 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len)
616 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
617
618 lws = lists + gws_len * 2;
619 for (i = 0; i < gws_len; ++i)
620 lws [i] = SvIV (AvARRAY (SvRV (local_work_size))[i]);
621 }
622
623 NEED_SUCCESS (EnqueueNDRangeKernel, (this, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
333 624
334 if (ev) 625 if (ev)
335 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 626 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
336} 627}
337 628
354 645
355void 646void
356enqueue_barrier (OpenCL::Queue this) 647enqueue_barrier (OpenCL::Queue this)
357 CODE: 648 CODE:
358 NEED_SUCCESS (EnqueueBarrier, (this)); 649 NEED_SUCCESS (EnqueueBarrier, (this));
650
651void
652flush (OpenCL::Queue this)
653 CODE:
654 NEED_SUCCESS (Flush, (this));
655
656void
657finish (OpenCL::Queue this)
658 CODE:
659 NEED_SUCCESS (Finish, (this));
359 660
360MODULE = OpenCL PACKAGE = OpenCL::Memory 661MODULE = OpenCL PACKAGE = OpenCL::Memory
361 662
362void 663void
363DESTROY (OpenCL::Memory this) 664DESTROY (OpenCL::Memory this)
438info (OpenCL::Kernel this, cl_kernel_info name) 739info (OpenCL::Kernel this, cl_kernel_info name)
439 PPCODE: 740 PPCODE:
440 INFO (Kernel) 741 INFO (Kernel)
441 742
442void 743void
443set_bool (OpenCL::Kernel this, cl_uint idx, cl_bool value) 744set_char (OpenCL::Kernel this, cl_uint idx, cl_char value)
444 CODE: 745 CODE:
445 clKernelSetArg (this, idx, sizeof (value), &value); 746 clSetKernelArg (this, idx, sizeof (value), &value);
747
748void
749set_uchar (OpenCL::Kernel this, cl_uint idx, cl_uchar value)
750 CODE:
751 clSetKernelArg (this, idx, sizeof (value), &value);
752
753void
754set_short (OpenCL::Kernel this, cl_uint idx, cl_short value)
755 CODE:
756 clSetKernelArg (this, idx, sizeof (value), &value);
757
758void
759set_ushort (OpenCL::Kernel this, cl_uint idx, cl_ushort value)
760 CODE:
761 clSetKernelArg (this, idx, sizeof (value), &value);
762
763void
764set_int (OpenCL::Kernel this, cl_uint idx, cl_int value)
765 CODE:
766 clSetKernelArg (this, idx, sizeof (value), &value);
767
768void
769set_uint (OpenCL::Kernel this, cl_uint idx, cl_uint value)
770 CODE:
771 clSetKernelArg (this, idx, sizeof (value), &value);
772
773void
774set_long (OpenCL::Kernel this, cl_uint idx, cl_long value)
775 CODE:
776 clSetKernelArg (this, idx, sizeof (value), &value);
777
778void
779set_ulong (OpenCL::Kernel this, cl_uint idx, cl_ulong value)
780 CODE:
781 clSetKernelArg (this, idx, sizeof (value), &value);
782
783void
784set_half (OpenCL::Kernel this, cl_uint idx, cl_half value)
785 CODE:
786 clSetKernelArg (this, idx, sizeof (value), &value);
787
788void
789set_float (OpenCL::Kernel this, cl_uint idx, cl_float value)
790 CODE:
791 clSetKernelArg (this, idx, sizeof (value), &value);
792
793void
794set_memory (OpenCL::Kernel this, cl_uint idx, OpenCL::Memory_ornull value)
795 CODE:
796 clSetKernelArg (this, idx, sizeof (value), &value);
797
798void
799set_buffer (OpenCL::Kernel this, cl_uint idx, OpenCL::Buffer_ornull value)
800 CODE:
801 clSetKernelArg (this, idx, sizeof (value), &value);
802
803void
804set_image2d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image2D_ornull value)
805 CODE:
806 clSetKernelArg (this, idx, sizeof (value), &value);
807
808void
809set_image3d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image3D_ornull value)
810 CODE:
811 clSetKernelArg (this, idx, sizeof (value), &value);
812
813void
814set_sampler (OpenCL::Kernel this, cl_uint idx, OpenCL::Sampler value)
815 CODE:
816 clSetKernelArg (this, idx, sizeof (value), &value);
817
818void
819set_event (OpenCL::Kernel this, cl_uint idx, OpenCL::Event value)
820 CODE:
821 clSetKernelArg (this, idx, sizeof (value), &value);
446 822
447MODULE = OpenCL PACKAGE = OpenCL::Event 823MODULE = OpenCL PACKAGE = OpenCL::Event
448 824
449void 825void
450DESTROY (OpenCL::Event this) 826DESTROY (OpenCL::Event this)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines