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