ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/OpenCL/OpenCL.xs
Revision: 1.44
Committed: Mon Apr 23 13:50:12 2012 UTC (12 years ago) by root
Branch: MAIN
Changes since 1.43: +26 -15 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #include "EXTERN.h"
2     #include "perl.h"
3     #include "XSUB.h"
4    
5 root 1.30 #ifdef I_DLFCN
6     #include <dlfcn.h>
7     #endif
8    
9 root 1.37 // how stupid is that, the 1.2 header files define CL_VERSION_1_1,
10     // but then fail to define the api functions unless you ALSO define
11     // this. This breaks 100% of the opencl 1.1 apps, for what reason?
12     // after all, the functions are deprecated, not removed.
13     // in addition, you cannot test for this in any future-proof way.
14     // each time a new opencl version comes out, you need to make a new
15     // release.
16     #define CL_USE_DEPRECATED_OPENCL_1_2_APIS /* just guessing, you stupid idiots */
17    
18 root 1.44 #ifndef PREFER_1_!
19     #define PREFER_1_1 1
20     #endif
21    
22     #if PREFER_1_1
23     #define CL_USE_DEPRECATED_OPENCL_1_1_APIS
24     #endif
25    
26 root 1.19 #ifdef __APPLE__
27     #include <OpenCL/opencl.h>
28     #else
29     #include <CL/opencl.h>
30     #endif
31 root 1.1
32 root 1.44 #ifndef CL_VERSION_1_2
33     #undef PREFER_1_1
34     #define PREFER_1_1 1
35 root 1.38 #endif
36    
37 root 1.16 typedef cl_platform_id OpenCL__Platform;
38     typedef cl_device_id OpenCL__Device;
39     typedef cl_context OpenCL__Context;
40     typedef cl_command_queue OpenCL__Queue;
41     typedef cl_mem OpenCL__Memory;
42     typedef cl_mem OpenCL__Buffer;
43 root 1.18 typedef cl_mem OpenCL__BufferObj;
44 root 1.16 typedef cl_mem OpenCL__Image;
45     typedef cl_mem OpenCL__Image2D;
46     typedef cl_mem OpenCL__Image3D;
47     typedef cl_mem OpenCL__Memory_ornull;
48     typedef cl_mem OpenCL__Buffer_ornull;
49     typedef cl_mem OpenCL__Image_ornull;
50     typedef cl_mem OpenCL__Image2D_ornull;
51     typedef cl_mem OpenCL__Image3D_ornull;
52     typedef cl_sampler OpenCL__Sampler;
53     typedef cl_program OpenCL__Program;
54     typedef cl_kernel OpenCL__Kernel;
55     typedef cl_event OpenCL__Event;
56     typedef cl_event OpenCL__UserEvent;
57 root 1.5
58 root 1.7 typedef SV *FUTURE;
59    
60 root 1.5 /*****************************************************************************/
61    
62 root 1.30 // name must include a leading underscore
63 root 1.32 // all of this horrors would be unneceesary if somebody wrote a proper OpenGL module
64     // for perl. doh.
65 root 1.30 static void *
66 root 1.32 glsym (const char *name)
67 root 1.30 {
68 root 1.32 void *fun = 0;
69    
70 root 1.30 #if defined I_DLFCN && defined RTLD_DEFAULT
71 root 1.32 fun = dlsym (RTLD_DEFAULT, name + 1);
72     if (!fun) fun = dlsym (RTLD_DEFAULT, name);
73    
74     if (!fun)
75     {
76     static void *libgl;
77     static const char *glso[] = {
78     "libGL.so.1",
79     "libGL.so.3",
80     "libGL.so.4.0",
81     "libGL.so",
82     "/usr/lib/libGL.so",
83     "/usr/X11R6/lib/libGL.1.dylib"
84     };
85     int i;
86    
87     for (i = 0; !libgl && i < sizeof (glso) / sizeof (glso [0]); ++i)
88     {
89     libgl = dlopen (glso [i], RTLD_LAZY);
90     if (libgl)
91     break;
92     }
93    
94     if (libgl)
95     {
96     fun = dlsym (libgl, name + 1);
97     if (!fun) fun = dlsym (libgl, name);
98     }
99     }
100 root 1.30 #endif
101 root 1.32
102     return fun;
103 root 1.30 }
104    
105     /*****************************************************************************/
106    
107 root 1.5 /* up to two temporary buffers */
108     static void *
109     tmpbuf (size_t size)
110     {
111 root 1.24 enum { buffers = 3 };
112 root 1.5 static int idx;
113 root 1.24 static void *buf [buffers];
114     static size_t len [buffers];
115 root 1.5
116 root 1.37 idx = (idx + 1) % buffers;
117 root 1.5
118     if (len [idx] < size)
119     {
120     free (buf [idx]);
121     len [idx] = ((size + 31) & ~4095) + 4096 - 32;
122     buf [idx] = malloc (len [idx]);
123     }
124    
125     return buf [idx];
126     }
127    
128     /*****************************************************************************/
129 root 1.1
130 root 1.3 typedef struct
131     {
132 root 1.1 IV iv;
133     const char *name;
134 root 1.3 #define const_iv(name) { (IV)CL_ ## name, # name },
135     } ivstr;
136 root 1.1
137     static const char *
138 root 1.3 iv2str (IV value, const ivstr *base, int count, const char *fallback)
139 root 1.1 {
140     int i;
141 root 1.3 static char strbuf [32];
142    
143     for (i = count; i--; )
144     if (base [i].iv == value)
145     return base [i].name;
146    
147     snprintf (strbuf, sizeof (strbuf), fallback, (int)value);
148    
149     return strbuf;
150     }
151    
152     static const char *
153     enum2str (cl_uint value)
154     {
155     static const ivstr enumstr[] = {
156     #include "enumstr.h"
157     };
158 root 1.1
159 root 1.3 return iv2str (value, enumstr, sizeof (enumstr) / sizeof (enumstr [0]), "ENUM(0x%04x)");
160     }
161 root 1.1
162 root 1.3 static const char *
163     err2str (cl_int err)
164     {
165     static const ivstr errstr[] = {
166     #include "errstr.h"
167     };
168 root 1.1
169 root 1.3 return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)");
170 root 1.1 }
171    
172 root 1.5 /*****************************************************************************/
173    
174 root 1.8 static cl_int res;
175 root 1.5
176 root 1.8 #define FAIL(name) \
177     croak ("cl" # name ": %s", err2str (res));
178 root 1.1
179     #define NEED_SUCCESS(name,args) \
180     do { \
181 root 1.8 res = cl ## name args; \
182 root 1.1 \
183     if (res) \
184 root 1.8 FAIL (name); \
185 root 1.1 } while (0)
186    
187 root 1.8 #define NEED_SUCCESS_ARG(retdecl, name, args) \
188     retdecl = cl ## name args; \
189     if (res) \
190     FAIL (name);
191    
192 root 1.5 /*****************************************************************************/
193    
194 root 1.2 #define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr)
195     #define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr))
196    
197 root 1.5 static void *
198     SvPTROBJ (const char *func, const char *svname, SV *sv, const char *pkg)
199     {
200     if (SvROK (sv) && sv_derived_from (sv, pkg))
201     return (void *)SvIV (SvRV (sv));
202    
203     croak ("%s: %s is not of type %s", func, svname, pkg);
204     }
205    
206     /*****************************************************************************/
207    
208 root 1.24 static cl_context_properties *
209     SvCONTEXTPROPERTIES (const char *func, const char *svname, SV *sv, cl_context_properties *extra, int extracount)
210     {
211     if (!sv || !SvOK (sv))
212     if (extra)
213     sv = sv_2mortal (newRV_noinc ((SV *)newAV ())); // slow, but rarely used hopefully
214     else
215     return 0;
216    
217     if (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVAV)
218     {
219     AV *av = (AV *)SvRV (sv);
220 root 1.28 int i, len = av_len (av) + 1;
221 root 1.24 cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1));
222     cl_context_properties *l = p;
223    
224     if (len & 1)
225     croak ("%s: %s is not a property list (must be even number of elements)", func, svname);
226    
227     while (extracount--)
228     *l++ = *extra++;
229    
230 root 1.29 for (i = 0; i < len; i += 2)
231 root 1.24 {
232 root 1.29 cl_context_properties t = SvIV (*av_fetch (av, i , 0));
233     SV *p_sv = *av_fetch (av, i + 1, 0);
234 root 1.32 cl_context_properties v = SvIV (p_sv); // code below can override
235 root 1.24
236     switch (t)
237     {
238 root 1.32 case CL_GLX_DISPLAY_KHR:
239     if (!SvOK (p_sv))
240     {
241     void *func = glsym ("_glXGetCurrentDisplay");
242     if (func)
243     v = (cl_context_properties)((void *(*)(void))func)();
244     }
245     break;
246    
247     case CL_GL_CONTEXT_KHR:
248     if (!SvOK (p_sv))
249     {
250     void *func = glsym ("_glXGetCurrentContext");
251     if (func)
252     v = (cl_context_properties)((void *(*)(void))func)();
253     }
254     break;
255    
256 root 1.24 default:
257     /* unknown property, treat as int */
258     break;
259     }
260    
261     *l++ = t;
262     *l++ = v;
263     }
264    
265     *l = 0;
266    
267     return p;
268     }
269    
270     croak ("%s: %s is not a property list (either undef or [type => value, ...])", func, svname);
271     }
272    
273     /*****************************************************************************/
274    
275 root 1.11 static size_t
276     img_row_pitch (cl_mem img)
277     {
278     size_t res;
279     clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0);
280     return res;
281     }
282    
283 root 1.5 static cl_event *
284 root 1.35 event_list (SV **items, cl_uint *rcount)
285 root 1.5 {
286 root 1.35 cl_uint count = *rcount;
287    
288 root 1.20 if (!count)
289     return 0;
290    
291 root 1.5 cl_event *list = tmpbuf (sizeof (cl_event) * count);
292 root 1.35 int i = 0;
293    
294     do
295     {
296     --count;
297     if (SvOK (items [count]))
298     list [i++] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event");
299     }
300     while (count);
301 root 1.5
302 root 1.35 *rcount = i;
303 root 1.5
304 root 1.35 return i ? list : 0;
305 root 1.5 }
306    
307     #define EVENT_LIST(items,count) \
308     cl_uint event_list_count = (count); \
309 root 1.35 cl_event *event_list_ptr = event_list (&ST (items), &event_list_count)
310 root 1.2
311     #define INFO(class) \
312     { \
313 root 1.23 size_t size; \
314     NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \
315 root 1.10 SV *sv = sv_2mortal (newSV (size)); \
316 root 1.2 SvUPGRADE (sv, SVt_PV); \
317     SvPOK_only (sv); \
318     SvCUR_set (sv, size); \
319 root 1.23 NEED_SUCCESS (Get ## class ## Info, (self, name, size, SvPVX (sv), 0)); \
320 root 1.2 XPUSHs (sv); \
321     }
322    
323 root 1.1 MODULE = OpenCL PACKAGE = OpenCL
324    
325 root 1.2 PROTOTYPES: ENABLE
326    
327 root 1.1 BOOT:
328     {
329 root 1.24 HV *stash = gv_stashpv ("OpenCL", 1);
330     static const ivstr *civ, const_iv[] = {
331     { sizeof (cl_char ), "SIZEOF_CHAR" },
332     { sizeof (cl_uchar ), "SIZEOF_UCHAR" },
333     { sizeof (cl_short ), "SIZEOF_SHORT" },
334     { sizeof (cl_ushort), "SIZEOF_USHORT" },
335     { sizeof (cl_int ), "SIZEOF_INT" },
336     { sizeof (cl_uint ), "SIZEOF_UINT" },
337     { sizeof (cl_long ), "SIZEOF_LONG" },
338     { sizeof (cl_ulong ), "SIZEOF_ULONG" },
339     { sizeof (cl_half ), "SIZEOF_HALF" },
340     { sizeof (cl_float ), "SIZEOF_FLOAT" },
341     { sizeof (cl_double), "SIZEOF_DOUBLE" },
342 root 1.1 #include "constiv.h"
343 root 1.24 };
344     for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
345     newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
346 root 1.1 }
347    
348 root 1.5 cl_int
349     errno ()
350     CODE:
351 root 1.37 RETVAL = res;
352     OUTPUT:
353     RETVAL
354 root 1.5
355 root 1.3 const char *
356     err2str (cl_int err)
357    
358     const char *
359     enum2str (cl_uint value)
360    
361 root 1.1 void
362     platforms ()
363     PPCODE:
364     cl_platform_id *list;
365     cl_uint count;
366     int i;
367    
368 root 1.2 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count));
369 root 1.4 list = tmpbuf (sizeof (*list) * count);
370 root 1.2 NEED_SUCCESS (GetPlatformIDs, (count, list, 0));
371 root 1.1
372     EXTEND (SP, count);
373     for (i = 0; i < count; ++i)
374 root 1.2 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i]));
375 root 1.1
376     void
377 root 1.24 context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
378 root 1.1 PPCODE:
379 root 1.24 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res));
380 root 1.8 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
381 root 1.1
382 root 1.37 #if 0
383    
384 root 1.8 void
385 root 1.24 context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0)
386 root 1.8 PPCODE:
387     /* der Gipfel der Kunst */
388 root 1.1
389 root 1.37 #endif
390    
391 root 1.2 void
392     wait_for_events (...)
393     CODE:
394     EVENT_LIST (0, items);
395     NEED_SUCCESS (WaitForEvents, (event_list_count, event_list_ptr));
396    
397     PROTOTYPES: DISABLE
398    
399 root 1.1 MODULE = OpenCL PACKAGE = OpenCL::Platform
400    
401     void
402 root 1.22 info (OpenCL::Platform self, cl_platform_info name)
403 root 1.1 PPCODE:
404 root 1.2 INFO (Platform)
405 root 1.1
406 root 1.13 #BEGIN:platform
407    
408     void
409 root 1.22 profile (OpenCL::Platform self)
410 root 1.16 ALIAS:
411     profile = CL_PLATFORM_PROFILE
412     version = CL_PLATFORM_VERSION
413     name = CL_PLATFORM_NAME
414     vendor = CL_PLATFORM_VENDOR
415     extensions = CL_PLATFORM_EXTENSIONS
416 root 1.14 PPCODE:
417     size_t size;
418 root 1.22 NEED_SUCCESS (GetPlatformInfo, (self, ix, 0, 0, &size));
419 root 1.14 char *value = tmpbuf (size);
420 root 1.22 NEED_SUCCESS (GetPlatformInfo, (self, ix, size, value, 0));
421 root 1.16 EXTEND (SP, 1);
422     const int i = 0;
423 root 1.14 PUSHs (sv_2mortal (newSVpv (value, 0)));
424 root 1.13
425     #END:platform
426    
427 root 1.1 void
428 root 1.22 devices (OpenCL::Platform self, cl_device_type type = CL_DEVICE_TYPE_ALL)
429 root 1.1 PPCODE:
430     cl_device_id *list;
431     cl_uint count;
432     int i;
433    
434 root 1.22 NEED_SUCCESS (GetDeviceIDs, (self, type, 0, 0, &count));
435 root 1.4 list = tmpbuf (sizeof (*list) * count);
436 root 1.22 NEED_SUCCESS (GetDeviceIDs, (self, type, count, list, 0));
437 root 1.1
438     EXTEND (SP, count);
439     for (i = 0; i < count; ++i)
440     PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i]));
441    
442     void
443 root 1.24 context (OpenCL::Platform self, cl_context_properties *properties = 0, SV *devices, FUTURE notify = 0)
444 root 1.8 PPCODE:
445     if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV)
446 root 1.27 croak ("OpenCL::Platform::context argument 'device' must be an arrayref with device objects, in call");
447 root 1.8
448 root 1.11 AV *av = (AV *)SvRV (devices);
449 root 1.8 cl_uint num_devices = av_len (av) + 1;
450     cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices);
451     int i;
452    
453     for (i = num_devices; i--; )
454     device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device");
455    
456 root 1.24 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (properties, num_devices, device_list, 0, 0, &res));
457 root 1.8 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
458    
459     void
460 root 1.24 context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
461 root 1.1 PPCODE:
462 root 1.24 cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self };
463     cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context_from_type", "properties", properties, extra, 2);
464 root 1.8 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res));
465 root 1.2 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
466 root 1.1
467 root 1.16 MODULE = OpenCL PACKAGE = OpenCL::Device
468 root 1.14
469     void
470 root 1.22 info (OpenCL::Device self, cl_device_info name)
471 root 1.16 PPCODE:
472     INFO (Device)
473 root 1.14
474 root 1.16 #BEGIN:device
475 root 1.14
476     void
477 root 1.22 type (OpenCL::Device self)
478 root 1.14 PPCODE:
479 root 1.16 cl_device_type value [1];
480 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_TYPE, sizeof (value), value, 0));
481 root 1.16 EXTEND (SP, 1);
482     const int i = 0;
483     PUSHs (sv_2mortal (newSViv (value [i])));
484 root 1.14
485     void
486 root 1.22 vendor_id (OpenCL::Device self)
487 root 1.16 ALIAS:
488     vendor_id = CL_DEVICE_VENDOR_ID
489     max_compute_units = CL_DEVICE_MAX_COMPUTE_UNITS
490     max_work_item_dimensions = CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
491     preferred_vector_width_char = CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR
492     preferred_vector_width_short = CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT
493     preferred_vector_width_int = CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT
494     preferred_vector_width_long = CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG
495     preferred_vector_width_float = CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT
496     preferred_vector_width_double = CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE
497     max_clock_frequency = CL_DEVICE_MAX_CLOCK_FREQUENCY
498     max_read_image_args = CL_DEVICE_MAX_READ_IMAGE_ARGS
499     max_write_image_args = CL_DEVICE_MAX_WRITE_IMAGE_ARGS
500     image_support = CL_DEVICE_IMAGE_SUPPORT
501     max_samplers = CL_DEVICE_MAX_SAMPLERS
502     mem_base_addr_align = CL_DEVICE_MEM_BASE_ADDR_ALIGN
503     min_data_type_align_size = CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE
504     global_mem_cacheline_size = CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE
505     max_constant_args = CL_DEVICE_MAX_CONSTANT_ARGS
506     preferred_vector_width_half = CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF
507     native_vector_width_char = CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR
508     native_vector_width_short = CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT
509     native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT
510     native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG
511     native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT
512     native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE
513     native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF
514 root 1.41 reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT
515 root 1.14 PPCODE:
516     cl_uint value [1];
517 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
518 root 1.14 EXTEND (SP, 1);
519     const int i = 0;
520     PUSHs (sv_2mortal (newSVuv (value [i])));
521    
522     void
523 root 1.22 max_work_group_size (OpenCL::Device self)
524 root 1.16 ALIAS:
525     max_work_group_size = CL_DEVICE_MAX_WORK_GROUP_SIZE
526     image2d_max_width = CL_DEVICE_IMAGE2D_MAX_WIDTH
527     image2d_max_height = CL_DEVICE_IMAGE2D_MAX_HEIGHT
528     image3d_max_width = CL_DEVICE_IMAGE3D_MAX_WIDTH
529     image3d_max_height = CL_DEVICE_IMAGE3D_MAX_HEIGHT
530     image3d_max_depth = CL_DEVICE_IMAGE3D_MAX_DEPTH
531     max_parameter_size = CL_DEVICE_MAX_PARAMETER_SIZE
532     profiling_timer_resolution = CL_DEVICE_PROFILING_TIMER_RESOLUTION
533 root 1.14 PPCODE:
534 root 1.16 size_t value [1];
535 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
536 root 1.14 EXTEND (SP, 1);
537     const int i = 0;
538     PUSHs (sv_2mortal (newSVuv (value [i])));
539    
540     void
541 root 1.22 max_work_item_sizes (OpenCL::Device self)
542 root 1.14 PPCODE:
543 root 1.16 size_t size;
544 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_MAX_WORK_ITEM_SIZES, 0, 0, &size));
545 root 1.16 size_t *value = tmpbuf (size);
546 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_MAX_WORK_ITEM_SIZES, size, value, 0));
547 root 1.16 int i, n = size / sizeof (*value);
548     EXTEND (SP, n);
549     for (i = 0; i < n; ++i)
550 root 1.14 PUSHs (sv_2mortal (newSVuv (value [i])));
551    
552     void
553 root 1.22 address_bits (OpenCL::Device self)
554 root 1.14 PPCODE:
555 root 1.16 cl_bitfield value [1];
556 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_ADDRESS_BITS, sizeof (value), value, 0));
557 root 1.14 EXTEND (SP, 1);
558     const int i = 0;
559     PUSHs (sv_2mortal (newSVuv (value [i])));
560    
561     void
562 root 1.22 max_mem_alloc_size (OpenCL::Device self)
563 root 1.16 ALIAS:
564     max_mem_alloc_size = CL_DEVICE_MAX_MEM_ALLOC_SIZE
565     global_mem_cache_size = CL_DEVICE_GLOBAL_MEM_CACHE_SIZE
566     global_mem_size = CL_DEVICE_GLOBAL_MEM_SIZE
567     max_constant_buffer_size = CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE
568     local_mem_size = CL_DEVICE_LOCAL_MEM_SIZE
569 root 1.14 PPCODE:
570 root 1.16 cl_ulong value [1];
571 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
572 root 1.14 EXTEND (SP, 1);
573     const int i = 0;
574     PUSHs (sv_2mortal (newSVuv (value [i])));
575    
576     void
577 root 1.22 single_fp_config (OpenCL::Device self)
578 root 1.16 ALIAS:
579     single_fp_config = CL_DEVICE_SINGLE_FP_CONFIG
580     double_fp_config = CL_DEVICE_DOUBLE_FP_CONFIG
581     half_fp_config = CL_DEVICE_HALF_FP_CONFIG
582 root 1.14 PPCODE:
583 root 1.16 cl_device_fp_config value [1];
584 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
585 root 1.14 EXTEND (SP, 1);
586     const int i = 0;
587     PUSHs (sv_2mortal (newSVuv (value [i])));
588    
589     void
590 root 1.22 global_mem_cache_type (OpenCL::Device self)
591 root 1.14 PPCODE:
592 root 1.16 cl_device_mem_cache_type value [1];
593 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, sizeof (value), value, 0));
594 root 1.14 EXTEND (SP, 1);
595     const int i = 0;
596     PUSHs (sv_2mortal (newSVuv (value [i])));
597    
598     void
599 root 1.22 local_mem_type (OpenCL::Device self)
600 root 1.14 PPCODE:
601 root 1.16 cl_device_local_mem_type value [1];
602 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_LOCAL_MEM_TYPE, sizeof (value), value, 0));
603 root 1.14 EXTEND (SP, 1);
604     const int i = 0;
605     PUSHs (sv_2mortal (newSVuv (value [i])));
606    
607     void
608 root 1.22 error_correction_support (OpenCL::Device self)
609 root 1.16 ALIAS:
610     error_correction_support = CL_DEVICE_ERROR_CORRECTION_SUPPORT
611     endian_little = CL_DEVICE_ENDIAN_LITTLE
612     available = CL_DEVICE_AVAILABLE
613     compiler_available = CL_DEVICE_COMPILER_AVAILABLE
614     host_unified_memory = CL_DEVICE_HOST_UNIFIED_MEMORY
615 root 1.14 PPCODE:
616 root 1.16 cl_bool value [1];
617 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
618 root 1.14 EXTEND (SP, 1);
619     const int i = 0;
620 root 1.16 PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no));
621 root 1.14
622     void
623 root 1.22 execution_capabilities (OpenCL::Device self)
624 root 1.14 PPCODE:
625 root 1.16 cl_device_exec_capabilities value [1];
626 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_EXECUTION_CAPABILITIES, sizeof (value), value, 0));
627 root 1.14 EXTEND (SP, 1);
628     const int i = 0;
629     PUSHs (sv_2mortal (newSVuv (value [i])));
630    
631     void
632 root 1.22 properties (OpenCL::Device self)
633 root 1.14 PPCODE:
634 root 1.16 cl_command_queue_properties value [1];
635 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_QUEUE_PROPERTIES, sizeof (value), value, 0));
636 root 1.14 EXTEND (SP, 1);
637     const int i = 0;
638 root 1.16 PUSHs (sv_2mortal (newSViv (value [i])));
639 root 1.14
640     void
641 root 1.22 platform (OpenCL::Device self)
642 root 1.14 PPCODE:
643 root 1.16 cl_platform_id value [1];
644 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_PLATFORM, sizeof (value), value, 0));
645 root 1.14 EXTEND (SP, 1);
646     const int i = 0;
647     {
648 root 1.16 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", value [i]));
649 root 1.14 }
650    
651     void
652 root 1.22 name (OpenCL::Device self)
653 root 1.16 ALIAS:
654     name = CL_DEVICE_NAME
655     vendor = CL_DEVICE_VENDOR
656     driver_version = CL_DRIVER_VERSION
657     profile = CL_DEVICE_PROFILE
658     version = CL_DEVICE_VERSION
659     extensions = CL_DEVICE_EXTENSIONS
660 root 1.14 PPCODE:
661     size_t size;
662 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, 0, 0, &size));
663 root 1.16 char *value = tmpbuf (size);
664 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, size, value, 0));
665 root 1.16 EXTEND (SP, 1);
666     const int i = 0;
667     PUSHs (sv_2mortal (newSVpv (value, 0)));
668 root 1.14
669     void
670 root 1.22 parent_device_ext (OpenCL::Device self)
671 root 1.14 PPCODE:
672 root 1.16 cl_device_id value [1];
673 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_PARENT_DEVICE_EXT, sizeof (value), value, 0));
674 root 1.14 EXTEND (SP, 1);
675     const int i = 0;
676 root 1.16 {
677     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i]));
678     }
679 root 1.14
680     void
681 root 1.22 partition_types_ext (OpenCL::Device self)
682 root 1.16 ALIAS:
683     partition_types_ext = CL_DEVICE_PARTITION_TYPES_EXT
684     affinity_domains_ext = CL_DEVICE_AFFINITY_DOMAINS_EXT
685     partition_style_ext = CL_DEVICE_PARTITION_STYLE_EXT
686 root 1.14 PPCODE:
687     size_t size;
688 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, 0, 0, &size));
689 root 1.14 cl_device_partition_property_ext *value = tmpbuf (size);
690 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, size, value, 0));
691 root 1.15 int i, n = size / sizeof (*value);
692 root 1.14 EXTEND (SP, n);
693     for (i = 0; i < n; ++i)
694     PUSHs (sv_2mortal (newSVuv (value [i])));
695    
696     #END:device
697    
698 root 1.1 MODULE = OpenCL PACKAGE = OpenCL::Context
699    
700     void
701     DESTROY (OpenCL::Context context)
702     CODE:
703     clReleaseContext (context);
704    
705     void
706 root 1.22 info (OpenCL::Context self, cl_context_info name)
707 root 1.1 PPCODE:
708 root 1.2 INFO (Context)
709    
710     void
711 root 1.22 queue (OpenCL::Context self, OpenCL::Device device, cl_command_queue_properties properties = 0)
712 root 1.2 PPCODE:
713 root 1.23 NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (self, device, properties, &res));
714 root 1.2 XPUSH_NEW_OBJ ("OpenCL::Queue", queue);
715    
716     void
717 root 1.22 user_event (OpenCL::Context self)
718 root 1.5 PPCODE:
719 root 1.23 NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (self, &res));
720 root 1.5 XPUSH_NEW_OBJ ("OpenCL::UserEvent", ev);
721    
722     void
723 root 1.22 buffer (OpenCL::Context self, cl_mem_flags flags, size_t len)
724 root 1.2 PPCODE:
725 root 1.3 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
726 root 1.27 croak ("OpenCL::Context::buffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?");
727 root 1.3
728 root 1.22 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res));
729 root 1.18 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
730 root 1.2
731     void
732 root 1.22 buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data)
733 root 1.2 PPCODE:
734     STRLEN len;
735 root 1.21 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
736 root 1.3 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
737 root 1.27 croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
738 root 1.22 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res));
739 root 1.18 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
740 root 1.3
741 root 1.42 #if CL_VERSION_1_2
742    
743     void
744     image (OpenCL::Context self, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, cl_mem_object_type type, size_t width, size_t height, size_t depth, size_t array_size = 0, size_t row_pitch = 0, size_t slice_pitch = 0, cl_uint num_mip_level = 0, cl_uint num_samples = 0, SV *data = &PL_sv_undef)
745     PPCODE:
746     STRLEN len;
747     char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
748     const cl_image_format format = { channel_order, channel_type };
749     const cl_image_desc desc = {
750     type,
751     width, height, depth,
752     array_size, row_pitch, slice_pitch,
753     num_mip_level, num_samples,
754     type == CL_MEM_OBJECT_IMAGE1D_BUFFER ? (cl_mem)SvPTROBJ ("OpenCL::Context::Image", "data", data, "OpenCL::Buffer") : 0
755     };
756     NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
757     char *klass = "OpenCL::Image";
758     switch (type)
759     {
760     case CL_MEM_OBJECT_IMAGE1D_BUFFER: klass = "OpenCL::Image1DBuffer"; break;
761     case CL_MEM_OBJECT_IMAGE1D: klass = "OpenCL::Image1D"; break;
762     case CL_MEM_OBJECT_IMAGE1D_ARRAY: klass = "OpenCL::Image2DArray"; break;
763     case CL_MEM_OBJECT_IMAGE2D: klass = "OpenCL::Image2D"; break;
764     case CL_MEM_OBJECT_IMAGE2D_ARRAY: klass = "OpenCL::Image2DArray"; break;
765     case CL_MEM_OBJECT_IMAGE3D: klass = "OpenCL::Image3D"; break;
766     }
767     XPUSH_NEW_OBJ (klass, mem);
768    
769     #endif
770    
771 root 1.3 void
772 root 1.22 image2d (OpenCL::Context self, 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)
773 root 1.3 PPCODE:
774     STRLEN len;
775 root 1.21 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
776 root 1.3 const cl_image_format format = { channel_order, channel_type };
777 root 1.44 #if PREFER_1_1
778     NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res));
779     #else
780 root 1.42 const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE2D, width, height, 0, 0, row_pitch, 0, 0, 0, 0 };
781     NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
782     #endif
783 root 1.3 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
784    
785     void
786 root 1.22 image3d (OpenCL::Context self, 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)
787 root 1.3 PPCODE:
788     STRLEN len;
789 root 1.21 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
790 root 1.3 const cl_image_format format = { channel_order, channel_type };
791 root 1.44 #if PREFER_1_1
792     NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
793     #else
794 root 1.42 const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE3D, width, height, depth, 0, row_pitch, slice_pitch, 0, 0, 0 };
795     NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
796     #endif
797 root 1.3 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
798    
799 root 1.25 #if cl_apple_gl_sharing || cl_khr_gl_sharing
800    
801     void
802     gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj)
803     PPCODE:
804     NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res));
805     XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
806    
807     void
808 root 1.40 gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer)
809 root 1.25 PPCODE:
810 root 1.40 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res));
811 root 1.25 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
812    
813 root 1.39 #if CL_VERSION_1_2
814    
815     void
816     gl_texture (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
817 root 1.43 ALIAS:
818 root 1.39 PPCODE:
819 root 1.43 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture, (self, flags, target, miplevel, texture, &res));
820     cl_gl_object_type type;
821     NEED_SUCCESS (GetGLObjectInfo, (mem, &type, 0)); // TODO: use target instead?
822 root 1.39 char *klass = "OpenCL::Memory";
823 root 1.42 switch (type)
824 root 1.39 {
825     case CL_GL_OBJECT_TEXTURE_BUFFER: klass = "OpenCL::Image1DBuffer"; break;
826     case CL_GL_OBJECT_TEXTURE1D: klass = "OpenCL::Image1D"; break;
827     case CL_GL_OBJECT_TEXTURE1D_ARRAY: klass = "OpenCL::Image2DArray"; break;
828     case CL_GL_OBJECT_TEXTURE2D: klass = "OpenCL::Image2D"; break;
829     case CL_GL_OBJECT_TEXTURE2D_ARRAY: klass = "OpenCL::Image2DArray"; break;
830     case CL_GL_OBJECT_TEXTURE3D: klass = "OpenCL::Image3D"; break;
831     }
832     XPUSH_NEW_OBJ (klass, mem);
833    
834 root 1.44 #endif
835 root 1.40
836 root 1.25 void
837 root 1.40 gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
838 root 1.25 PPCODE:
839 root 1.44 #if PREFER_1_1
840 root 1.40 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
841 root 1.44 #else
842     NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture , (self, flags, target, miplevel, texture, &res));
843     #endif
844 root 1.25 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
845    
846 root 1.40 void
847     gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
848     PPCODE:
849 root 1.44 #if PREFER_1_1
850 root 1.40 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res));
851 root 1.44 #else
852     NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture , (self, flags, target, miplevel, texture, &res));
853     #endif
854 root 1.40 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
855    
856     #endif
857    
858 root 1.3 void
859 root 1.22 supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type)
860 root 1.3 PPCODE:
861     {
862     cl_uint count;
863     cl_image_format *list;
864     int i;
865    
866 root 1.23 NEED_SUCCESS (GetSupportedImageFormats, (self, flags, image_type, 0, 0, &count));
867 root 1.3 Newx (list, count, cl_image_format);
868 root 1.23 NEED_SUCCESS (GetSupportedImageFormats, (self, flags, image_type, count, list, 0));
869 root 1.3
870     EXTEND (SP, count);
871     for (i = 0; i < count; ++i)
872     {
873     AV *av = newAV ();
874     av_store (av, 1, newSVuv (list [i].image_channel_data_type));
875     av_store (av, 0, newSVuv (list [i].image_channel_order));
876     PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
877     }
878 root 1.2 }
879    
880     void
881 root 1.22 sampler (OpenCL::Context self, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode)
882 root 1.2 PPCODE:
883 root 1.23 NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (self, normalized_coords, addressing_mode, filter_mode, &res));
884 root 1.2 XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler);
885 root 1.1
886     void
887 root 1.22 program_with_source (OpenCL::Context self, SV *program)
888 root 1.1 PPCODE:
889 root 1.2 STRLEN len;
890     size_t len2;
891     const char *ptr = SvPVbyte (program, len);
892    
893     len2 = len;
894 root 1.23 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (self, 1, &ptr, &len2, &res));
895 root 1.2 XPUSH_NEW_OBJ ("OpenCL::Program", prog);
896 root 1.1
897 root 1.13 #BEGIN:context
898    
899 root 1.14 void
900 root 1.22 reference_count (OpenCL::Context self)
901 root 1.16 ALIAS:
902     reference_count = CL_CONTEXT_REFERENCE_COUNT
903     num_devices = CL_CONTEXT_NUM_DEVICES
904 root 1.14 PPCODE:
905     cl_uint value [1];
906 root 1.22 NEED_SUCCESS (GetContextInfo, (self, ix, sizeof (value), value, 0));
907 root 1.14 EXTEND (SP, 1);
908     const int i = 0;
909     PUSHs (sv_2mortal (newSVuv (value [i])));
910    
911     void
912 root 1.22 devices (OpenCL::Context self)
913 root 1.14 PPCODE:
914     size_t size;
915 root 1.22 NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_DEVICES, 0, 0, &size));
916 root 1.14 cl_device_id *value = tmpbuf (size);
917 root 1.22 NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_DEVICES, size, value, 0));
918 root 1.15 int i, n = size / sizeof (*value);
919 root 1.14 EXTEND (SP, n);
920     for (i = 0; i < n; ++i)
921     {
922     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i]));
923     }
924    
925     void
926 root 1.22 properties (OpenCL::Context self)
927 root 1.14 PPCODE:
928     size_t size;
929 root 1.22 NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_PROPERTIES, 0, 0, &size));
930 root 1.14 cl_context_properties *value = tmpbuf (size);
931 root 1.22 NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_PROPERTIES, size, value, 0));
932 root 1.15 int i, n = size / sizeof (*value);
933 root 1.14 EXTEND (SP, n);
934     for (i = 0; i < n; ++i)
935     PUSHs (sv_2mortal (newSVuv ((UV)value [i])));
936    
937 root 1.13 #END:context
938    
939 root 1.1 MODULE = OpenCL PACKAGE = OpenCL::Queue
940    
941     void
942 root 1.22 DESTROY (OpenCL::Queue self)
943 root 1.1 CODE:
944 root 1.22 clReleaseCommandQueue (self);
945 root 1.1
946     void
947 root 1.22 enqueue_read_buffer (OpenCL::Queue self, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...)
948 root 1.2 PPCODE:
949     cl_event ev = 0;
950     EVENT_LIST (6, items - 6);
951    
952     SvUPGRADE (data, SVt_PV);
953     SvGROW (data, len);
954     SvPOK_only (data);
955     SvCUR_set (data, len);
956 root 1.22 NEED_SUCCESS (EnqueueReadBuffer, (self, mem, blocking, offset, len, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
957 root 1.2
958     if (ev)
959     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
960    
961     void
962 root 1.22 enqueue_write_buffer (OpenCL::Queue self, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...)
963 root 1.2 PPCODE:
964     cl_event ev = 0;
965     STRLEN len;
966     char *ptr = SvPVbyte (data, len);
967     EVENT_LIST (5, items - 5);
968    
969 root 1.34 NEED_SUCCESS (EnqueueWriteBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
970 root 1.2
971     if (ev)
972     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
973    
974     void
975 root 1.22 enqueue_copy_buffer (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...)
976 root 1.2 PPCODE:
977     cl_event ev = 0;
978     EVENT_LIST (6, items - 6);
979    
980 root 1.22 NEED_SUCCESS (EnqueueCopyBuffer, (self, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
981 root 1.2
982     if (ev)
983     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
984    
985 root 1.3 void
986 root 1.22 enqueue_read_buffer_rect (OpenCL::Queue self, OpenCL::Memory buf, cl_bool blocking, size_t buf_x, size_t buf_y, size_t buf_z, size_t host_x, size_t host_y, size_t host_z, size_t width, size_t height, size_t depth, size_t buf_row_pitch, size_t buf_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, SV *data, ...)
987 root 1.17 PPCODE:
988     cl_event ev = 0;
989     const size_t buf_origin [3] = { buf_x , buf_y , buf_z };
990     const size_t host_origin[3] = { host_x, host_y, host_z };
991     const size_t region[3] = { width, height, depth };
992     EVENT_LIST (17, items - 17);
993    
994     if (!buf_row_pitch)
995     buf_row_pitch = region [0];
996    
997     if (!buf_slice_pitch)
998     buf_slice_pitch = region [1] * buf_row_pitch;
999    
1000     if (!host_row_pitch)
1001     host_row_pitch = region [0];
1002    
1003     if (!host_slice_pitch)
1004     host_slice_pitch = region [1] * host_row_pitch;
1005    
1006     size_t len = host_row_pitch * host_slice_pitch * region [2];
1007    
1008     SvUPGRADE (data, SVt_PV);
1009     SvGROW (data, len);
1010     SvPOK_only (data);
1011     SvCUR_set (data, len);
1012 root 1.22 NEED_SUCCESS (EnqueueReadBufferRect, (self, buf, blocking, buf_origin, host_origin, region, buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1013 root 1.17
1014     if (ev)
1015     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1016    
1017     void
1018 root 1.22 enqueue_write_buffer_rect (OpenCL::Queue self, OpenCL::Memory buf, cl_bool blocking, size_t buf_x, size_t buf_y, size_t buf_z, size_t host_x, size_t host_y, size_t host_z, size_t width, size_t height, size_t depth, size_t buf_row_pitch, size_t buf_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, SV *data, ...)
1019 root 1.17 PPCODE:
1020     cl_event ev = 0;
1021     const size_t buf_origin [3] = { buf_x , buf_y , buf_z };
1022     const size_t host_origin[3] = { host_x, host_y, host_z };
1023     const size_t region[3] = { width, height, depth };
1024     STRLEN len;
1025     char *ptr = SvPVbyte (data, len);
1026     EVENT_LIST (17, items - 17);
1027    
1028     if (!buf_row_pitch)
1029     buf_row_pitch = region [0];
1030    
1031     if (!buf_slice_pitch)
1032     buf_slice_pitch = region [1] * buf_row_pitch;
1033    
1034     if (!host_row_pitch)
1035     host_row_pitch = region [0];
1036    
1037     if (!host_slice_pitch)
1038     host_slice_pitch = region [1] * host_row_pitch;
1039    
1040     size_t min_len = host_row_pitch * host_slice_pitch * region [2];
1041    
1042     if (len < min_len)
1043     croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
1044    
1045 root 1.37 NEED_SUCCESS (EnqueueWriteBufferRect, (self, buf, blocking, buf_origin, host_origin, region, buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1046 root 1.17
1047     if (ev)
1048     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1049    
1050     void
1051 root 1.22 enqueue_copy_buffer_rect (OpenCL::Queue self, 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, ...)
1052 root 1.18 PPCODE:
1053     cl_event ev = 0;
1054     const size_t src_origin[3] = { src_x, src_y, src_z };
1055     const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
1056     const size_t region[3] = { width, height, depth };
1057     EVENT_LIST (16, items - 16);
1058    
1059 root 1.22 NEED_SUCCESS (EnqueueCopyBufferRect, (self, 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));
1060 root 1.18
1061     if (ev)
1062     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1063    
1064     void
1065 root 1.22 enqueue_read_image (OpenCL::Queue self, 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, ...)
1066 root 1.3 PPCODE:
1067     cl_event ev = 0;
1068     const size_t src_origin[3] = { src_x, src_y, src_z };
1069     const size_t region[3] = { width, height, depth };
1070 root 1.10 EVENT_LIST (12, items - 12);
1071    
1072 root 1.11 if (!row_pitch)
1073     row_pitch = img_row_pitch (src);
1074    
1075     if (depth > 1 && !slice_pitch)
1076     slice_pitch = row_pitch * height;
1077    
1078     size_t len = slice_pitch ? slice_pitch * depth : row_pitch * height;
1079 root 1.3
1080     SvUPGRADE (data, SVt_PV);
1081     SvGROW (data, len);
1082     SvPOK_only (data);
1083     SvCUR_set (data, len);
1084 root 1.22 NEED_SUCCESS (EnqueueReadImage, (self, src, blocking, src_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1085 root 1.3
1086     if (ev)
1087     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1088    
1089     void
1090 root 1.22 enqueue_write_image (OpenCL::Queue self, 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, ...)
1091 root 1.3 PPCODE:
1092     cl_event ev = 0;
1093     const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
1094     const size_t region[3] = { width, height, depth };
1095     STRLEN len;
1096     char *ptr = SvPVbyte (data, len);
1097 root 1.10 EVENT_LIST (12, items - 12);
1098 root 1.3
1099 root 1.11 if (!row_pitch)
1100     row_pitch = img_row_pitch (dst);
1101    
1102     if (depth > 1 && !slice_pitch)
1103     slice_pitch = row_pitch * height;
1104    
1105     size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height;
1106    
1107     if (len < min_len)
1108     croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
1109    
1110 root 1.37 NEED_SUCCESS (EnqueueWriteImage, (self, dst, blocking, dst_origin, region, row_pitch, slice_pitch, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1111 root 1.3
1112     if (ev)
1113     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1114    
1115     void
1116 root 1.22 enqueue_copy_image (OpenCL::Queue self, 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, ...)
1117 root 1.3 PPCODE:
1118     cl_event ev = 0;
1119     const size_t src_origin[3] = { src_x, src_y, src_z };
1120     const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
1121     const size_t region[3] = { width, height, depth };
1122 root 1.18 EVENT_LIST (12, items - 12);
1123 root 1.3
1124 root 1.22 NEED_SUCCESS (EnqueueCopyImage, (self, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1125 root 1.3
1126     if (ev)
1127     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1128    
1129     void
1130 root 1.22 enqueue_copy_image_to_buffer (OpenCL::Queue self, 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, ...)
1131 root 1.3 PPCODE:
1132     cl_event ev = 0;
1133 root 1.18 const size_t src_origin[3] = { src_x, src_y, src_z };
1134 root 1.3 const size_t region[3] = { width, height, depth };
1135     EVENT_LIST (10, items - 10);
1136    
1137 root 1.22 NEED_SUCCESS (EnqueueCopyImageToBuffer, (self, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1138 root 1.3
1139     if (ev)
1140     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1141    
1142     void
1143 root 1.22 enqueue_copy_buffer_to_image (OpenCL::Queue self, 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, ...)
1144 root 1.3 PPCODE:
1145     cl_event ev = 0;
1146     const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
1147     const size_t region[3] = { width, height, depth };
1148     EVENT_LIST (10, items - 10);
1149    
1150 root 1.22 NEED_SUCCESS (EnqueueCopyBufferToImage, (self, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1151 root 1.3
1152     if (ev)
1153     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1154    
1155     void
1156 root 1.22 enqueue_task (OpenCL::Queue self, OpenCL::Kernel kernel, ...)
1157 root 1.3 PPCODE:
1158     cl_event ev = 0;
1159     EVENT_LIST (2, items - 2);
1160    
1161 root 1.22 NEED_SUCCESS (EnqueueTask, (self, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1162 root 1.3
1163     if (ev)
1164     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1165    
1166 root 1.4 void
1167 root 1.22 enqueue_nd_range_kernel (OpenCL::Queue self, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...)
1168 root 1.4 PPCODE:
1169     cl_event ev = 0;
1170     size_t *gwo = 0, *gws, *lws = 0;
1171     int gws_len;
1172     size_t *lists;
1173     int i;
1174 root 1.5 EVENT_LIST (5, items - 5);
1175 root 1.4
1176     if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV)
1177     croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference");
1178    
1179     gws_len = AvFILLp (SvRV (global_work_size)) + 1;
1180    
1181     lists = tmpbuf (sizeof (size_t) * 3 * gws_len);
1182    
1183     gws = lists + gws_len * 0;
1184     for (i = 0; i < gws_len; ++i)
1185     gws [i] = SvIV (AvARRAY (SvRV (global_work_size))[i]);
1186    
1187     if (SvOK (global_work_offset))
1188     {
1189     if (!SvROK (global_work_offset) || SvTYPE (SvRV (global_work_offset)) != SVt_PVAV)
1190     croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array reference");
1191    
1192     if (AvFILLp (SvRV (global_work_size)) + 1 != gws_len)
1193     croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array of same size as global_work_size");
1194    
1195     gwo = lists + gws_len * 1;
1196     for (i = 0; i < gws_len; ++i)
1197     gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
1198     }
1199    
1200     if (SvOK (local_work_size))
1201     {
1202 root 1.37 if ((SvOK (local_work_size) && !SvROK (local_work_size)) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV)
1203 root 1.4 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference");
1204    
1205     if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len)
1206     croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
1207    
1208     lws = lists + gws_len * 2;
1209     for (i = 0; i < gws_len; ++i)
1210     lws [i] = SvIV (AvARRAY (SvRV (local_work_size))[i]);
1211     }
1212    
1213 root 1.22 NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1214 root 1.4
1215     if (ev)
1216     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1217 root 1.3
1218 root 1.25 #if cl_apple_gl_sharing || cl_khr_gl_sharing
1219    
1220     void
1221     enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...)
1222 root 1.27 ALIAS:
1223     enqueue_release_gl_objects = 1
1224 root 1.36 PPCODE:
1225 root 1.27 if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV)
1226     croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call");
1227    
1228 root 1.25 cl_event ev = 0;
1229     EVENT_LIST (2, items - 2);
1230 root 1.27 AV *av = (AV *)SvRV (objects);
1231     cl_uint num_objects = av_len (av) + 1;
1232     cl_mem *object_list = tmpbuf (sizeof (cl_mem) * num_objects);
1233     int i;
1234 root 1.25
1235 root 1.27 for (i = num_objects; i--; )
1236     object_list [i] = SvPTROBJ ("OpenCL::Queue::enqueue_acquire/release_gl_objects", "objects", *av_fetch (av, i, 0), "OpenCL::Memory");
1237 root 1.25
1238 root 1.27 if (ix)
1239     NEED_SUCCESS (EnqueueReleaseGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1240     else
1241     NEED_SUCCESS (EnqueueAcquireGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1242 root 1.25
1243     if (ev)
1244     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1245    
1246     #endif
1247    
1248 root 1.38 #if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS
1249 root 1.2
1250     void
1251 root 1.22 enqueue_wait_for_events (OpenCL::Queue self, ...)
1252 root 1.2 CODE:
1253     EVENT_LIST (1, items - 1);
1254 root 1.22 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr));
1255 root 1.2
1256 root 1.38 #endif
1257    
1258     void
1259     enqueue_marker (OpenCL::Queue self, ...)
1260     PPCODE:
1261     cl_event ev = 0;
1262     EVENT_LIST (1, items - 1);
1263     #if CL_VERSION_1_2
1264     NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1265     #else
1266     if (event_list_count)
1267     croak ("OpenCL::Queue->enqueue_marker does not support a wait list in OpenCL 1.1 - upgrade to 1.2");
1268     NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0));
1269     #endif
1270     if (ev)
1271     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1272    
1273 root 1.2 void
1274 root 1.38 enqueue_barrier (OpenCL::Queue self, ...)
1275     PPCODE:
1276     cl_event ev = 0;
1277     EVENT_LIST (1, items - 1);
1278     #if CL_VERSION_1_2
1279     NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, &ev));
1280     #else
1281     if (event_list_count)
1282     croak ("OpenCL::Queue->enqueue_barrier does not support a wait list in OpenCL 1.1 - upgrade to 1.2");
1283     if (GIMME_V != G_VOID)
1284     croak ("OpenCL::Queue->enqueue_barrier does not return an event object in OpenCL 1.1 - upgrade to 1.2");
1285 root 1.22 NEED_SUCCESS (EnqueueBarrier, (self));
1286 root 1.37 #endif
1287 root 1.38 if (ev)
1288     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1289 root 1.37
1290 root 1.3 void
1291 root 1.22 flush (OpenCL::Queue self)
1292 root 1.3 CODE:
1293 root 1.22 NEED_SUCCESS (Flush, (self));
1294 root 1.3
1295     void
1296 root 1.22 finish (OpenCL::Queue self)
1297 root 1.3 CODE:
1298 root 1.22 NEED_SUCCESS (Finish, (self));
1299 root 1.3
1300 root 1.14 void
1301 root 1.22 info (OpenCL::Queue self, cl_command_queue_info name)
1302 root 1.14 PPCODE:
1303     INFO (CommandQueue)
1304    
1305     #BEGIN:command_queue
1306    
1307     void
1308 root 1.22 context (OpenCL::Queue self)
1309 root 1.14 PPCODE:
1310     cl_context value [1];
1311 root 1.22 NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_CONTEXT, sizeof (value), value, 0));
1312 root 1.14 EXTEND (SP, 1);
1313     const int i = 0;
1314     {
1315     NEED_SUCCESS (RetainContext, (value [i]));
1316     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
1317     }
1318    
1319     void
1320 root 1.22 device (OpenCL::Queue self)
1321 root 1.14 PPCODE:
1322     cl_device_id value [1];
1323 root 1.22 NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_DEVICE, sizeof (value), value, 0));
1324 root 1.14 EXTEND (SP, 1);
1325     const int i = 0;
1326     {
1327     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i]));
1328     }
1329    
1330     void
1331 root 1.22 reference_count (OpenCL::Queue self)
1332 root 1.14 PPCODE:
1333     cl_uint value [1];
1334 root 1.22 NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_REFERENCE_COUNT, sizeof (value), value, 0));
1335 root 1.14 EXTEND (SP, 1);
1336     const int i = 0;
1337     PUSHs (sv_2mortal (newSVuv (value [i])));
1338    
1339     void
1340 root 1.22 properties (OpenCL::Queue self)
1341 root 1.14 PPCODE:
1342     cl_command_queue_properties value [1];
1343 root 1.22 NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_PROPERTIES, sizeof (value), value, 0));
1344 root 1.14 EXTEND (SP, 1);
1345     const int i = 0;
1346     PUSHs (sv_2mortal (newSViv (value [i])));
1347    
1348     #END:command_queue
1349    
1350 root 1.2 MODULE = OpenCL PACKAGE = OpenCL::Memory
1351    
1352     void
1353 root 1.22 DESTROY (OpenCL::Memory self)
1354 root 1.2 CODE:
1355 root 1.22 clReleaseMemObject (self);
1356 root 1.2
1357     void
1358 root 1.22 info (OpenCL::Memory self, cl_mem_info name)
1359 root 1.2 PPCODE:
1360     INFO (MemObject)
1361    
1362 root 1.14 #BEGIN:mem
1363    
1364     void
1365 root 1.22 type (OpenCL::Memory self)
1366 root 1.14 PPCODE:
1367     cl_mem_object_type value [1];
1368 root 1.22 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_TYPE, sizeof (value), value, 0));
1369 root 1.14 EXTEND (SP, 1);
1370     const int i = 0;
1371     PUSHs (sv_2mortal (newSViv (value [i])));
1372    
1373     void
1374 root 1.22 flags (OpenCL::Memory self)
1375 root 1.14 PPCODE:
1376     cl_mem_flags value [1];
1377 root 1.22 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_FLAGS, sizeof (value), value, 0));
1378 root 1.14 EXTEND (SP, 1);
1379     const int i = 0;
1380     PUSHs (sv_2mortal (newSViv (value [i])));
1381    
1382     void
1383 root 1.22 size (OpenCL::Memory self)
1384 root 1.16 ALIAS:
1385     size = CL_MEM_SIZE
1386     offset = CL_MEM_OFFSET
1387 root 1.14 PPCODE:
1388     size_t value [1];
1389 root 1.22 NEED_SUCCESS (GetMemObjectInfo, (self, ix, sizeof (value), value, 0));
1390 root 1.14 EXTEND (SP, 1);
1391     const int i = 0;
1392     PUSHs (sv_2mortal (newSVuv (value [i])));
1393    
1394     void
1395 root 1.22 host_ptr (OpenCL::Memory self)
1396 root 1.14 PPCODE:
1397     void * value [1];
1398 root 1.22 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_HOST_PTR, sizeof (value), value, 0));
1399 root 1.14 EXTEND (SP, 1);
1400     const int i = 0;
1401     PUSHs (sv_2mortal (newSVuv ((IV)(intptr_t)value [i])));
1402    
1403     void
1404 root 1.22 map_count (OpenCL::Memory self)
1405 root 1.16 ALIAS:
1406     map_count = CL_MEM_MAP_COUNT
1407     reference_count = CL_MEM_REFERENCE_COUNT
1408 root 1.14 PPCODE:
1409     cl_uint value [1];
1410 root 1.22 NEED_SUCCESS (GetMemObjectInfo, (self, ix, sizeof (value), value, 0));
1411 root 1.14 EXTEND (SP, 1);
1412     const int i = 0;
1413     PUSHs (sv_2mortal (newSVuv (value [i])));
1414    
1415     void
1416 root 1.22 context (OpenCL::Memory self)
1417 root 1.14 PPCODE:
1418     cl_context value [1];
1419 root 1.22 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_CONTEXT, sizeof (value), value, 0));
1420 root 1.14 EXTEND (SP, 1);
1421     const int i = 0;
1422     {
1423     NEED_SUCCESS (RetainContext, (value [i]));
1424     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
1425     }
1426    
1427     void
1428 root 1.22 associated_memobject (OpenCL::Memory self)
1429 root 1.14 PPCODE:
1430     cl_mem value [1];
1431 root 1.22 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_ASSOCIATED_MEMOBJECT, sizeof (value), value, 0));
1432 root 1.14 EXTEND (SP, 1);
1433     const int i = 0;
1434     {
1435     NEED_SUCCESS (RetainMemObject, (value [i]));
1436     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i]));
1437     }
1438    
1439     #END:mem
1440    
1441 root 1.26 #if cl_apple_gl_sharing || cl_khr_gl_sharing
1442    
1443     void
1444     gl_object_info (OpenCL::Memory self)
1445     PPCODE:
1446     cl_gl_object_type type;
1447     cl_GLuint name;
1448 root 1.31 NEED_SUCCESS (GetGLObjectInfo, (self, &type, &name));
1449 root 1.26 EXTEND (SP, 2);
1450     PUSHs (sv_2mortal (newSVuv (type)));
1451     PUSHs (sv_2mortal (newSVuv (name)));
1452    
1453     #endif
1454    
1455 root 1.18 MODULE = OpenCL PACKAGE = OpenCL::BufferObj
1456    
1457     void
1458 root 1.22 sub_buffer_region (OpenCL::BufferObj self, cl_mem_flags flags, size_t origin, size_t size)
1459 root 1.18 PPCODE:
1460     if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_ALLOC_HOST_PTR))
1461     croak ("clCreateSubBuffer: cannot use/copy/alloc host ptr, doesn't make sense, check your flags!");
1462    
1463     cl_buffer_region crdata = { origin, size };
1464    
1465 root 1.22 NEED_SUCCESS_ARG (cl_mem mem, CreateSubBuffer, (self, flags, CL_BUFFER_CREATE_TYPE_REGION, &crdata, &res));
1466 root 1.18 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
1467    
1468 root 1.13 MODULE = OpenCL PACKAGE = OpenCL::Image
1469    
1470     void
1471 root 1.22 image_info (OpenCL::Image self, cl_image_info name)
1472 root 1.13 PPCODE:
1473     INFO (Image)
1474    
1475 root 1.14 #BEGIN:image
1476    
1477     void
1478 root 1.22 element_size (OpenCL::Image self)
1479 root 1.16 ALIAS:
1480     element_size = CL_IMAGE_ELEMENT_SIZE
1481     row_pitch = CL_IMAGE_ROW_PITCH
1482     slice_pitch = CL_IMAGE_SLICE_PITCH
1483     width = CL_IMAGE_WIDTH
1484     height = CL_IMAGE_HEIGHT
1485     depth = CL_IMAGE_DEPTH
1486 root 1.14 PPCODE:
1487     size_t value [1];
1488 root 1.22 NEED_SUCCESS (GetImageInfo, (self, ix, sizeof (value), value, 0));
1489 root 1.14 EXTEND (SP, 1);
1490     const int i = 0;
1491     PUSHs (sv_2mortal (newSVuv (value [i])));
1492    
1493     #END:image
1494    
1495 root 1.26 #if cl_apple_gl_sharing || cl_khr_gl_sharing
1496    
1497     #BEGIN:gl_texture
1498    
1499     void
1500     target (OpenCL::Image self)
1501     PPCODE:
1502     cl_GLenum value [1];
1503 root 1.31 NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0));
1504 root 1.26 EXTEND (SP, 1);
1505     const int i = 0;
1506     PUSHs (sv_2mortal (newSVuv (value [i])));
1507    
1508     void
1509     gl_mipmap_level (OpenCL::Image self)
1510     PPCODE:
1511     cl_GLint value [1];
1512 root 1.31 NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0));
1513 root 1.26 EXTEND (SP, 1);
1514     const int i = 0;
1515     PUSHs (sv_2mortal (newSViv (value [i])));
1516    
1517     #END:gl_texture
1518    
1519     #endif
1520    
1521 root 1.2 MODULE = OpenCL PACKAGE = OpenCL::Sampler
1522    
1523     void
1524 root 1.22 DESTROY (OpenCL::Sampler self)
1525 root 1.2 CODE:
1526 root 1.22 clReleaseSampler (self);
1527 root 1.2
1528     void
1529 root 1.22 info (OpenCL::Sampler self, cl_sampler_info name)
1530 root 1.2 PPCODE:
1531     INFO (Sampler)
1532    
1533 root 1.14 #BEGIN:sampler
1534    
1535     void
1536 root 1.22 reference_count (OpenCL::Sampler self)
1537 root 1.14 PPCODE:
1538     cl_uint value [1];
1539 root 1.22 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_REFERENCE_COUNT, sizeof (value), value, 0));
1540 root 1.14 EXTEND (SP, 1);
1541     const int i = 0;
1542     PUSHs (sv_2mortal (newSVuv (value [i])));
1543    
1544     void
1545 root 1.22 context (OpenCL::Sampler self)
1546 root 1.14 PPCODE:
1547     cl_context value [1];
1548 root 1.22 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_CONTEXT, sizeof (value), value, 0));
1549 root 1.14 EXTEND (SP, 1);
1550     const int i = 0;
1551     {
1552     NEED_SUCCESS (RetainContext, (value [i]));
1553     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
1554     }
1555    
1556     void
1557 root 1.22 normalized_coords (OpenCL::Sampler self)
1558 root 1.14 PPCODE:
1559     cl_addressing_mode value [1];
1560 root 1.22 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_NORMALIZED_COORDS, sizeof (value), value, 0));
1561 root 1.14 EXTEND (SP, 1);
1562     const int i = 0;
1563     PUSHs (sv_2mortal (newSViv (value [i])));
1564    
1565     void
1566 root 1.22 addressing_mode (OpenCL::Sampler self)
1567 root 1.14 PPCODE:
1568     cl_filter_mode value [1];
1569 root 1.22 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_ADDRESSING_MODE, sizeof (value), value, 0));
1570 root 1.14 EXTEND (SP, 1);
1571     const int i = 0;
1572     PUSHs (sv_2mortal (newSViv (value [i])));
1573    
1574     void
1575 root 1.22 filter_mode (OpenCL::Sampler self)
1576 root 1.14 PPCODE:
1577     cl_bool value [1];
1578 root 1.22 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_FILTER_MODE, sizeof (value), value, 0));
1579 root 1.14 EXTEND (SP, 1);
1580     const int i = 0;
1581     PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no));
1582    
1583     #END:sampler
1584    
1585 root 1.2 MODULE = OpenCL PACKAGE = OpenCL::Program
1586    
1587     void
1588 root 1.22 DESTROY (OpenCL::Program self)
1589 root 1.2 CODE:
1590 root 1.22 clReleaseProgram (self);
1591 root 1.2
1592     void
1593 root 1.22 build (OpenCL::Program self, OpenCL::Device device, SV *options = &PL_sv_undef)
1594 root 1.2 CODE:
1595 root 1.22 NEED_SUCCESS (BuildProgram, (self, 1, &device, SvPVbyte_nolen (options), 0, 0));
1596 root 1.2
1597     void
1598 root 1.22 build_info (OpenCL::Program self, OpenCL::Device device, cl_program_build_info name)
1599 root 1.2 PPCODE:
1600 root 1.23 size_t size;
1601     NEED_SUCCESS (GetProgramBuildInfo, (self, device, name, 0, 0, &size));
1602 root 1.10 SV *sv = sv_2mortal (newSV (size));
1603 root 1.1 SvUPGRADE (sv, SVt_PV);
1604     SvPOK_only (sv);
1605     SvCUR_set (sv, size);
1606 root 1.23 NEED_SUCCESS (GetProgramBuildInfo, (self, device, name, size, SvPVX (sv), 0));
1607 root 1.1 XPUSHs (sv);
1608    
1609 root 1.14 #BEGIN:program_build
1610    
1611     void
1612 root 1.22 build_status (OpenCL::Program self, OpenCL::Device device)
1613 root 1.14 PPCODE:
1614     cl_build_status value [1];
1615 root 1.22 NEED_SUCCESS (GetProgramBuildInfo, (self, device, CL_PROGRAM_BUILD_STATUS, sizeof (value), value, 0));
1616 root 1.14 EXTEND (SP, 1);
1617     const int i = 0;
1618     PUSHs (sv_2mortal (newSViv (value [i])));
1619    
1620     void
1621 root 1.22 build_options (OpenCL::Program self, OpenCL::Device device)
1622 root 1.16 ALIAS:
1623     build_options = CL_PROGRAM_BUILD_OPTIONS
1624     build_log = CL_PROGRAM_BUILD_LOG
1625 root 1.14 PPCODE:
1626     size_t size;
1627 root 1.22 NEED_SUCCESS (GetProgramBuildInfo, (self, device, ix, 0, 0, &size));
1628 root 1.14 char *value = tmpbuf (size);
1629 root 1.22 NEED_SUCCESS (GetProgramBuildInfo, (self, device, ix, size, value, 0));
1630 root 1.16 EXTEND (SP, 1);
1631     const int i = 0;
1632 root 1.14 PUSHs (sv_2mortal (newSVpv (value, 0)));
1633    
1634     #END:program_build
1635    
1636 root 1.2 void
1637     kernel (OpenCL::Program program, SV *function)
1638     PPCODE:
1639 root 1.23 NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res));
1640 root 1.2 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel);
1641    
1642 root 1.14 void
1643 root 1.22 info (OpenCL::Program self, cl_program_info name)
1644 root 1.14 PPCODE:
1645     INFO (Program)
1646    
1647 root 1.15 void
1648 root 1.22 binaries (OpenCL::Program self)
1649 root 1.15 PPCODE:
1650     cl_uint n, i;
1651     size_t size;
1652    
1653 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_NUM_DEVICES , sizeof (n) , &n , 0));
1654 root 1.15 if (!n) XSRETURN_EMPTY;
1655    
1656     size_t *sizes = tmpbuf (sizeof (*sizes) * n);
1657 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARY_SIZES, sizeof (*sizes) * n, sizes, &size));
1658 root 1.15 if (size != sizeof (*sizes) * n) XSRETURN_EMPTY;
1659     unsigned char **ptrs = tmpbuf (sizeof (*ptrs) * n);
1660    
1661     EXTEND (SP, n);
1662     for (i = 0; i < n; ++i)
1663     {
1664     SV *sv = sv_2mortal (newSV (sizes [i]));
1665     SvUPGRADE (sv, SVt_PV);
1666     SvPOK_only (sv);
1667     SvCUR_set (sv, sizes [i]);
1668 root 1.37 ptrs [i] = (void *)SvPVX (sv);
1669 root 1.15 PUSHs (sv);
1670     }
1671    
1672 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size));
1673 root 1.15 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY;
1674    
1675 root 1.14 #BEGIN:program
1676    
1677     void
1678 root 1.22 reference_count (OpenCL::Program self)
1679 root 1.16 ALIAS:
1680     reference_count = CL_PROGRAM_REFERENCE_COUNT
1681     num_devices = CL_PROGRAM_NUM_DEVICES
1682 root 1.14 PPCODE:
1683     cl_uint value [1];
1684 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, ix, sizeof (value), value, 0));
1685 root 1.14 EXTEND (SP, 1);
1686     const int i = 0;
1687     PUSHs (sv_2mortal (newSVuv (value [i])));
1688    
1689     void
1690 root 1.22 context (OpenCL::Program self)
1691 root 1.14 PPCODE:
1692     cl_context value [1];
1693 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_CONTEXT, sizeof (value), value, 0));
1694 root 1.14 EXTEND (SP, 1);
1695     const int i = 0;
1696     {
1697     NEED_SUCCESS (RetainContext, (value [i]));
1698     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
1699     }
1700    
1701     void
1702 root 1.22 devices (OpenCL::Program self)
1703 root 1.14 PPCODE:
1704     size_t size;
1705 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_DEVICES, 0, 0, &size));
1706 root 1.14 cl_device_id *value = tmpbuf (size);
1707 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_DEVICES, size, value, 0));
1708 root 1.15 int i, n = size / sizeof (*value);
1709 root 1.14 EXTEND (SP, n);
1710     for (i = 0; i < n; ++i)
1711     {
1712     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i]));
1713     }
1714    
1715     void
1716 root 1.22 source (OpenCL::Program self)
1717 root 1.14 PPCODE:
1718     size_t size;
1719 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_SOURCE, 0, 0, &size));
1720 root 1.14 char *value = tmpbuf (size);
1721 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_SOURCE, size, value, 0));
1722 root 1.16 EXTEND (SP, 1);
1723     const int i = 0;
1724 root 1.14 PUSHs (sv_2mortal (newSVpv (value, 0)));
1725    
1726     void
1727 root 1.22 binary_sizes (OpenCL::Program self)
1728 root 1.14 PPCODE:
1729     size_t size;
1730 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARY_SIZES, 0, 0, &size));
1731 root 1.14 size_t *value = tmpbuf (size);
1732 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARY_SIZES, size, value, 0));
1733 root 1.15 int i, n = size / sizeof (*value);
1734 root 1.14 EXTEND (SP, n);
1735     for (i = 0; i < n; ++i)
1736     PUSHs (sv_2mortal (newSVuv (value [i])));
1737    
1738     #END:program
1739    
1740 root 1.2 MODULE = OpenCL PACKAGE = OpenCL::Kernel
1741    
1742     void
1743 root 1.22 DESTROY (OpenCL::Kernel self)
1744 root 1.2 CODE:
1745 root 1.22 clReleaseKernel (self);
1746 root 1.2
1747     void
1748 root 1.22 set_char (OpenCL::Kernel self, cl_uint idx, cl_char value)
1749 root 1.3 CODE:
1750 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1751 root 1.3
1752     void
1753 root 1.22 set_uchar (OpenCL::Kernel self, cl_uint idx, cl_uchar value)
1754 root 1.3 CODE:
1755 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1756 root 1.3
1757     void
1758 root 1.22 set_short (OpenCL::Kernel self, cl_uint idx, cl_short value)
1759 root 1.3 CODE:
1760 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1761 root 1.3
1762     void
1763 root 1.22 set_ushort (OpenCL::Kernel self, cl_uint idx, cl_ushort value)
1764 root 1.3 CODE:
1765 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1766 root 1.3
1767     void
1768 root 1.22 set_int (OpenCL::Kernel self, cl_uint idx, cl_int value)
1769 root 1.3 CODE:
1770 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1771 root 1.3
1772     void
1773 root 1.22 set_uint (OpenCL::Kernel self, cl_uint idx, cl_uint value)
1774 root 1.3 CODE:
1775 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1776 root 1.3
1777     void
1778 root 1.22 set_long (OpenCL::Kernel self, cl_uint idx, cl_long value)
1779 root 1.3 CODE:
1780 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1781 root 1.3
1782     void
1783 root 1.22 set_ulong (OpenCL::Kernel self, cl_uint idx, cl_ulong value)
1784 root 1.3 CODE:
1785 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1786 root 1.3
1787     void
1788 root 1.22 set_half (OpenCL::Kernel self, cl_uint idx, cl_half value)
1789 root 1.3 CODE:
1790 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1791 root 1.3
1792     void
1793 root 1.22 set_float (OpenCL::Kernel self, cl_uint idx, cl_float value)
1794 root 1.3 CODE:
1795 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1796 root 1.3
1797     void
1798 root 1.22 set_double (OpenCL::Kernel self, cl_uint idx, cl_double value)
1799 root 1.5 CODE:
1800 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1801 root 1.5
1802     void
1803 root 1.22 set_memory (OpenCL::Kernel self, cl_uint idx, OpenCL::Memory_ornull value)
1804 root 1.3 CODE:
1805 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1806 root 1.3
1807     void
1808 root 1.22 set_buffer (OpenCL::Kernel self, cl_uint idx, OpenCL::Buffer_ornull value)
1809 root 1.3 CODE:
1810 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1811 root 1.3
1812     void
1813 root 1.22 set_image2d (OpenCL::Kernel self, cl_uint idx, OpenCL::Image2D_ornull value)
1814 root 1.3 CODE:
1815 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1816 root 1.3
1817     void
1818 root 1.22 set_image3d (OpenCL::Kernel self, cl_uint idx, OpenCL::Image3D_ornull value)
1819 root 1.3 CODE:
1820 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1821 root 1.3
1822     void
1823 root 1.22 set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value)
1824 root 1.3 CODE:
1825 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1826 root 1.3
1827     void
1828 root 1.33 set_local (OpenCL::Kernel self, cl_uint idx, size_t size)
1829     CODE:
1830     clSetKernelArg (self, idx, size, 0);
1831    
1832     void
1833 root 1.22 set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value)
1834 root 1.2 CODE:
1835 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
1836 root 1.2
1837 root 1.14 void
1838 root 1.22 info (OpenCL::Kernel self, cl_kernel_info name)
1839 root 1.14 PPCODE:
1840     INFO (Kernel)
1841    
1842     #BEGIN:kernel
1843    
1844     void
1845 root 1.22 function_name (OpenCL::Kernel self)
1846 root 1.14 PPCODE:
1847     size_t size;
1848 root 1.22 NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_FUNCTION_NAME, 0, 0, &size));
1849 root 1.14 char *value = tmpbuf (size);
1850 root 1.22 NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_FUNCTION_NAME, size, value, 0));
1851 root 1.16 EXTEND (SP, 1);
1852     const int i = 0;
1853 root 1.14 PUSHs (sv_2mortal (newSVpv (value, 0)));
1854    
1855     void
1856 root 1.22 num_args (OpenCL::Kernel self)
1857 root 1.16 ALIAS:
1858     num_args = CL_KERNEL_NUM_ARGS
1859     reference_count = CL_KERNEL_REFERENCE_COUNT
1860 root 1.14 PPCODE:
1861     cl_uint value [1];
1862 root 1.22 NEED_SUCCESS (GetKernelInfo, (self, ix, sizeof (value), value, 0));
1863 root 1.14 EXTEND (SP, 1);
1864     const int i = 0;
1865     PUSHs (sv_2mortal (newSVuv (value [i])));
1866    
1867     void
1868 root 1.22 context (OpenCL::Kernel self)
1869 root 1.14 PPCODE:
1870     cl_context value [1];
1871 root 1.22 NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_CONTEXT, sizeof (value), value, 0));
1872 root 1.14 EXTEND (SP, 1);
1873     const int i = 0;
1874     {
1875     NEED_SUCCESS (RetainContext, (value [i]));
1876     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
1877     }
1878    
1879     void
1880 root 1.22 program (OpenCL::Kernel self)
1881 root 1.14 PPCODE:
1882     cl_program value [1];
1883 root 1.22 NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_PROGRAM, sizeof (value), value, 0));
1884 root 1.14 EXTEND (SP, 1);
1885     const int i = 0;
1886     {
1887     NEED_SUCCESS (RetainProgram, (value [i]));
1888     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Program", value [i]));
1889     }
1890    
1891     #END:kernel
1892    
1893     void
1894 root 1.22 work_group_info (OpenCL::Kernel self, OpenCL::Device device, cl_kernel_work_group_info name)
1895 root 1.14 PPCODE:
1896 root 1.22 size_t size;
1897     NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, name, 0, 0, &size));
1898 root 1.14 SV *sv = sv_2mortal (newSV (size));
1899     SvUPGRADE (sv, SVt_PV);
1900     SvPOK_only (sv);
1901     SvCUR_set (sv, size);
1902 root 1.22 NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, name, size, SvPVX (sv), 0));
1903 root 1.14 XPUSHs (sv);
1904    
1905     #BEGIN:kernel_work_group
1906    
1907     void
1908 root 1.22 work_group_size (OpenCL::Kernel self, OpenCL::Device device)
1909 root 1.16 ALIAS:
1910     work_group_size = CL_KERNEL_WORK_GROUP_SIZE
1911     preferred_work_group_size_multiple = CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE
1912 root 1.14 PPCODE:
1913     size_t value [1];
1914 root 1.22 NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, ix, sizeof (value), value, 0));
1915 root 1.14 EXTEND (SP, 1);
1916     const int i = 0;
1917     PUSHs (sv_2mortal (newSVuv (value [i])));
1918    
1919     void
1920 root 1.22 compile_work_group_size (OpenCL::Kernel self, OpenCL::Device device)
1921 root 1.14 PPCODE:
1922     size_t size;
1923 root 1.22 NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, 0, 0, &size));
1924 root 1.14 size_t *value = tmpbuf (size);
1925 root 1.22 NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, size, value, 0));
1926 root 1.15 int i, n = size / sizeof (*value);
1927 root 1.14 EXTEND (SP, n);
1928     for (i = 0; i < n; ++i)
1929     PUSHs (sv_2mortal (newSVuv (value [i])));
1930    
1931     void
1932 root 1.22 local_mem_size (OpenCL::Kernel self, OpenCL::Device device)
1933 root 1.16 ALIAS:
1934     local_mem_size = CL_KERNEL_LOCAL_MEM_SIZE
1935     private_mem_size = CL_KERNEL_PRIVATE_MEM_SIZE
1936 root 1.14 PPCODE:
1937     cl_ulong value [1];
1938 root 1.22 NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, ix, sizeof (value), value, 0));
1939 root 1.14 EXTEND (SP, 1);
1940     const int i = 0;
1941     PUSHs (sv_2mortal (newSVuv (value [i])));
1942    
1943     #END:kernel_work_group
1944    
1945 root 1.2 MODULE = OpenCL PACKAGE = OpenCL::Event
1946    
1947     void
1948 root 1.22 DESTROY (OpenCL::Event self)
1949 root 1.2 CODE:
1950 root 1.22 clReleaseEvent (self);
1951 root 1.2
1952     void
1953 root 1.22 wait (OpenCL::Event self)
1954 root 1.14 CODE:
1955 root 1.22 clWaitForEvents (1, &self);
1956 root 1.14
1957     void
1958 root 1.22 info (OpenCL::Event self, cl_event_info name)
1959 root 1.2 PPCODE:
1960     INFO (Event)
1961    
1962 root 1.14 #BEGIN:event
1963    
1964     void
1965 root 1.22 command_queue (OpenCL::Event self)
1966 root 1.14 PPCODE:
1967     cl_command_queue value [1];
1968 root 1.22 NEED_SUCCESS (GetEventInfo, (self, CL_EVENT_COMMAND_QUEUE, sizeof (value), value, 0));
1969 root 1.14 EXTEND (SP, 1);
1970     const int i = 0;
1971     {
1972     NEED_SUCCESS (RetainCommandQueue, (value [i]));
1973     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Queue", value [i]));
1974     }
1975    
1976     void
1977 root 1.22 command_type (OpenCL::Event self)
1978 root 1.14 PPCODE:
1979     cl_command_type value [1];
1980 root 1.22 NEED_SUCCESS (GetEventInfo, (self, CL_EVENT_COMMAND_TYPE, sizeof (value), value, 0));
1981 root 1.14 EXTEND (SP, 1);
1982     const int i = 0;
1983     PUSHs (sv_2mortal (newSVuv (value [i])));
1984    
1985     void
1986 root 1.22 reference_count (OpenCL::Event self)
1987 root 1.16 ALIAS:
1988     reference_count = CL_EVENT_REFERENCE_COUNT
1989     command_execution_status = CL_EVENT_COMMAND_EXECUTION_STATUS
1990 root 1.14 PPCODE:
1991     cl_uint value [1];
1992 root 1.22 NEED_SUCCESS (GetEventInfo, (self, ix, sizeof (value), value, 0));
1993 root 1.14 EXTEND (SP, 1);
1994     const int i = 0;
1995     PUSHs (sv_2mortal (newSVuv (value [i])));
1996    
1997     void
1998 root 1.22 context (OpenCL::Event self)
1999 root 1.14 PPCODE:
2000     cl_context value [1];
2001 root 1.22 NEED_SUCCESS (GetEventInfo, (self, CL_EVENT_CONTEXT, sizeof (value), value, 0));
2002 root 1.14 EXTEND (SP, 1);
2003     const int i = 0;
2004     {
2005     NEED_SUCCESS (RetainContext, (value [i]));
2006     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
2007     }
2008    
2009     #END:event
2010    
2011 root 1.2 void
2012 root 1.22 profiling_info (OpenCL::Event self, cl_profiling_info name)
2013 root 1.13 PPCODE:
2014     INFO (EventProfiling)
2015    
2016 root 1.14 #BEGIN:profiling
2017    
2018 root 1.13 void
2019 root 1.22 profiling_command_queued (OpenCL::Event self)
2020 root 1.16 ALIAS:
2021     profiling_command_queued = CL_PROFILING_COMMAND_QUEUED
2022     profiling_command_submit = CL_PROFILING_COMMAND_SUBMIT
2023     profiling_command_start = CL_PROFILING_COMMAND_START
2024     profiling_command_end = CL_PROFILING_COMMAND_END
2025 root 1.14 PPCODE:
2026     cl_ulong value [1];
2027 root 1.22 NEED_SUCCESS (GetEventProfilingInfo, (self, ix, sizeof (value), value, 0));
2028 root 1.14 EXTEND (SP, 1);
2029     const int i = 0;
2030     PUSHs (sv_2mortal (newSVuv (value [i])));
2031    
2032     #END:profiling
2033 root 1.2
2034 root 1.5 MODULE = OpenCL PACKAGE = OpenCL::UserEvent
2035    
2036     void
2037 root 1.22 set_status (OpenCL::UserEvent self, cl_int execution_status)
2038 root 1.5 CODE:
2039 root 1.22 clSetUserEventStatus (self, execution_status);
2040 root 1.5