ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/OpenCL/OpenCL.xs
Revision: 1.58
Committed: Sun Apr 29 18:39:31 2012 UTC (12 years ago) by root
Branch: MAIN
Changes since 1.57: +13 -3 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.51 #define X_STACKSIZE sizeof (void *) * 512 * 1024 // 2-4mb should be enough, really
6     #include "xthread.h"
7     #include "schmorp.h"
8    
9 root 1.30 #ifdef I_DLFCN
10     #include <dlfcn.h>
11     #endif
12    
13 root 1.37 // how stupid is that, the 1.2 header files define CL_VERSION_1_1,
14     // but then fail to define the api functions unless you ALSO define
15     // this. This breaks 100% of the opencl 1.1 apps, for what reason?
16     // after all, the functions are deprecated, not removed.
17     // in addition, you cannot test for this in any future-proof way.
18     // each time a new opencl version comes out, you need to make a new
19     // release.
20     #define CL_USE_DEPRECATED_OPENCL_1_2_APIS /* just guessing, you stupid idiots */
21    
22 root 1.45 #ifndef PREFER_1_1
23 root 1.44 #define PREFER_1_1 1
24     #endif
25    
26     #if PREFER_1_1
27     #define CL_USE_DEPRECATED_OPENCL_1_1_APIS
28     #endif
29    
30 root 1.19 #ifdef __APPLE__
31     #include <OpenCL/opencl.h>
32     #else
33     #include <CL/opencl.h>
34     #endif
35 root 1.1
36 root 1.44 #ifndef CL_VERSION_1_2
37     #undef PREFER_1_1
38     #define PREFER_1_1 1
39 root 1.38 #endif
40    
41 root 1.16 typedef cl_platform_id OpenCL__Platform;
42     typedef cl_device_id OpenCL__Device;
43     typedef cl_context OpenCL__Context;
44     typedef cl_command_queue OpenCL__Queue;
45     typedef cl_mem OpenCL__Memory;
46     typedef cl_mem OpenCL__Buffer;
47 root 1.18 typedef cl_mem OpenCL__BufferObj;
48 root 1.16 typedef cl_mem OpenCL__Image;
49     typedef cl_mem OpenCL__Image2D;
50     typedef cl_mem OpenCL__Image3D;
51     typedef cl_mem OpenCL__Memory_ornull;
52     typedef cl_mem OpenCL__Buffer_ornull;
53     typedef cl_mem OpenCL__Image_ornull;
54     typedef cl_mem OpenCL__Image2D_ornull;
55     typedef cl_mem OpenCL__Image3D_ornull;
56     typedef cl_sampler OpenCL__Sampler;
57     typedef cl_program OpenCL__Program;
58     typedef cl_kernel OpenCL__Kernel;
59     typedef cl_event OpenCL__Event;
60     typedef cl_event OpenCL__UserEvent;
61 root 1.5
62 root 1.7 typedef SV *FUTURE;
63    
64 root 1.5 /*****************************************************************************/
65    
66 root 1.30 // name must include a leading underscore
67 root 1.32 // all of this horrors would be unneceesary if somebody wrote a proper OpenGL module
68     // for perl. doh.
69 root 1.30 static void *
70 root 1.32 glsym (const char *name)
71 root 1.30 {
72 root 1.32 void *fun = 0;
73    
74 root 1.30 #if defined I_DLFCN && defined RTLD_DEFAULT
75 root 1.32 fun = dlsym (RTLD_DEFAULT, name + 1);
76     if (!fun) fun = dlsym (RTLD_DEFAULT, name);
77    
78     if (!fun)
79     {
80     static void *libgl;
81     static const char *glso[] = {
82     "libGL.so.1",
83     "libGL.so.3",
84     "libGL.so.4.0",
85     "libGL.so",
86     "/usr/lib/libGL.so",
87     "/usr/X11R6/lib/libGL.1.dylib"
88     };
89     int i;
90    
91     for (i = 0; !libgl && i < sizeof (glso) / sizeof (glso [0]); ++i)
92     {
93     libgl = dlopen (glso [i], RTLD_LAZY);
94     if (libgl)
95     break;
96     }
97    
98     if (libgl)
99     {
100     fun = dlsym (libgl, name + 1);
101     if (!fun) fun = dlsym (libgl, name);
102     }
103     }
104 root 1.30 #endif
105 root 1.32
106     return fun;
107 root 1.30 }
108    
109     /*****************************************************************************/
110    
111 root 1.5 /* up to two temporary buffers */
112     static void *
113     tmpbuf (size_t size)
114     {
115 root 1.24 enum { buffers = 3 };
116 root 1.5 static int idx;
117 root 1.24 static void *buf [buffers];
118     static size_t len [buffers];
119 root 1.5
120 root 1.37 idx = (idx + 1) % buffers;
121 root 1.5
122     if (len [idx] < size)
123     {
124     free (buf [idx]);
125     len [idx] = ((size + 31) & ~4095) + 4096 - 32;
126     buf [idx] = malloc (len [idx]);
127     }
128    
129     return buf [idx];
130     }
131    
132     /*****************************************************************************/
133 root 1.1
134 root 1.3 typedef struct
135     {
136 root 1.1 IV iv;
137     const char *name;
138 root 1.3 #define const_iv(name) { (IV)CL_ ## name, # name },
139     } ivstr;
140 root 1.1
141     static const char *
142 root 1.3 iv2str (IV value, const ivstr *base, int count, const char *fallback)
143 root 1.1 {
144     int i;
145 root 1.3 static char strbuf [32];
146    
147     for (i = count; i--; )
148     if (base [i].iv == value)
149     return base [i].name;
150    
151     snprintf (strbuf, sizeof (strbuf), fallback, (int)value);
152    
153     return strbuf;
154     }
155    
156     static const char *
157     enum2str (cl_uint value)
158     {
159     static const ivstr enumstr[] = {
160     #include "enumstr.h"
161     };
162 root 1.1
163 root 1.3 return iv2str (value, enumstr, sizeof (enumstr) / sizeof (enumstr [0]), "ENUM(0x%04x)");
164     }
165 root 1.1
166 root 1.3 static const char *
167     err2str (cl_int err)
168     {
169     static const ivstr errstr[] = {
170     #include "errstr.h"
171     };
172 root 1.1
173 root 1.3 return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)");
174 root 1.1 }
175    
176 root 1.5 /*****************************************************************************/
177    
178 root 1.8 static cl_int res;
179 root 1.5
180 root 1.8 #define FAIL(name) \
181     croak ("cl" # name ": %s", err2str (res));
182 root 1.1
183     #define NEED_SUCCESS(name,args) \
184     do { \
185 root 1.8 res = cl ## name args; \
186 root 1.1 \
187     if (res) \
188 root 1.8 FAIL (name); \
189 root 1.1 } while (0)
190    
191 root 1.8 #define NEED_SUCCESS_ARG(retdecl, name, args) \
192     retdecl = cl ## name args; \
193     if (res) \
194     FAIL (name);
195    
196 root 1.5 /*****************************************************************************/
197    
198 root 1.24 static cl_context_properties *
199     SvCONTEXTPROPERTIES (const char *func, const char *svname, SV *sv, cl_context_properties *extra, int extracount)
200     {
201     if (!sv || !SvOK (sv))
202     if (extra)
203     sv = sv_2mortal (newRV_noinc ((SV *)newAV ())); // slow, but rarely used hopefully
204     else
205     return 0;
206    
207     if (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVAV)
208     {
209     AV *av = (AV *)SvRV (sv);
210 root 1.28 int i, len = av_len (av) + 1;
211 root 1.24 cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1));
212     cl_context_properties *l = p;
213    
214     if (len & 1)
215     croak ("%s: %s is not a property list (must be even number of elements)", func, svname);
216    
217     while (extracount--)
218     *l++ = *extra++;
219    
220 root 1.29 for (i = 0; i < len; i += 2)
221 root 1.24 {
222 root 1.29 cl_context_properties t = SvIV (*av_fetch (av, i , 0));
223     SV *p_sv = *av_fetch (av, i + 1, 0);
224 root 1.32 cl_context_properties v = SvIV (p_sv); // code below can override
225 root 1.24
226     switch (t)
227     {
228 root 1.32 case CL_GLX_DISPLAY_KHR:
229     if (!SvOK (p_sv))
230     {
231     void *func = glsym ("_glXGetCurrentDisplay");
232     if (func)
233     v = (cl_context_properties)((void *(*)(void))func)();
234     }
235     break;
236    
237     case CL_GL_CONTEXT_KHR:
238     if (!SvOK (p_sv))
239     {
240     void *func = glsym ("_glXGetCurrentContext");
241     if (func)
242     v = (cl_context_properties)((void *(*)(void))func)();
243     }
244     break;
245    
246 root 1.24 default:
247     /* unknown property, treat as int */
248     break;
249     }
250    
251     *l++ = t;
252     *l++ = v;
253     }
254    
255     *l = 0;
256    
257     return p;
258     }
259    
260     croak ("%s: %s is not a property list (either undef or [type => value, ...])", func, svname);
261     }
262    
263     /*****************************************************************************/
264    
265 root 1.51 #define NEW_CLOBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr)
266     #define PUSH_CLOBJ(class,ptr) PUSHs (NEW_CLOBJ (class, ptr))
267     #define XPUSH_CLOBJ(class,ptr) XPUSHs (NEW_CLOBJ (class, ptr))
268    
269     /* cl objects are either \$iv, or [$iv, ...] */
270     /* they can be upgraded at runtime to the array form */
271     static void *
272     SvCLOBJ (const char *func, const char *svname, SV *sv, const char *pkg)
273     {
274     if (SvROK (sv) && sv_derived_from (sv, pkg))
275 root 1.53 return (void *)SvIV (SvRV (sv));
276 root 1.51
277     croak ("%s: %s is not of type %s", func, svname, pkg);
278     }
279    
280     /*****************************************************************************/
281     /* callback stuff */
282    
283     /* default context callback, log to stderr */
284     static void CL_CALLBACK
285     context_default_notify (const char *msg, const void *info, size_t cb, void *data)
286     {
287     fprintf (stderr, "OpenCL Context Notify: %s\n", msg);
288     }
289    
290     typedef struct
291     {
292     int free_cb;
293     void (*push)(void *data1, void *data2, void *data3);
294     } eq_vtbl;
295    
296     typedef struct eq_item
297     {
298     struct eq_item *next;
299     eq_vtbl *vtbl;
300     SV *cb;
301     void *data1, *data2, *data3;
302     } eq_item;
303    
304     static void (*eq_signal_func)(void *signal_arg, int value);
305     static void *eq_signal_arg;
306     static xmutex_t eq_lock = X_MUTEX_INIT;
307     static eq_item *eq_head, *eq_tail;
308    
309     static void
310     eq_enq (eq_vtbl *vtbl, SV *cb, void *data1, void *data2, void *data3)
311     {
312     eq_item *item = malloc (sizeof (eq_item));
313    
314     item->next = 0;
315     item->vtbl = vtbl;
316     item->cb = cb;
317     item->data1 = data1;
318     item->data2 = data2;
319     item->data3 = data3;
320    
321     X_LOCK (eq_lock);
322    
323     *(eq_head ? &eq_tail->next : &eq_head) = item;
324     eq_tail = item;
325    
326     X_UNLOCK (eq_lock);
327    
328     eq_signal_func (eq_signal_arg, 0);
329     }
330    
331     static eq_item *
332     eq_dec (void)
333     {
334     eq_item *res;
335    
336     X_LOCK (eq_lock);
337    
338     res = eq_head;
339     if (res)
340     eq_head = res->next;
341    
342     X_UNLOCK (eq_lock);
343    
344     return res;
345     }
346    
347     static void
348     eq_poll (void)
349     {
350     eq_item *item;
351    
352     while ((item = eq_dec ()))
353     {
354     ENTER;
355     SAVETMPS;
356    
357     dSP;
358     PUSHMARK (SP);
359     EXTEND (SP, 2);
360    
361     if (item->vtbl->free_cb)
362     sv_2mortal (item->cb);
363    
364     PUTBACK;
365     item->vtbl->push (item->data1, item->data2, item->data3);
366    
367     SV *cb = item->cb;
368     free (item);
369    
370     call_sv (cb, G_DISCARD | G_VOID);
371    
372     FREETMPS;
373     LEAVE;
374     }
375     }
376    
377     static void
378     eq_poll_interrupt (pTHX_ void *c_arg, int value)
379     {
380     eq_poll ();
381     }
382    
383 root 1.52 /*****************************************************************************/
384 root 1.51 /* context notify */
385    
386     static void
387     eq_context_push (void *data1, void *data2, void *data3)
388     {
389     dSP;
390     PUSHs (sv_2mortal (newSVpv (data1, 0)));
391     PUSHs (sv_2mortal (newSVpvn (data2, (STRLEN)data3)));
392     PUTBACK;
393 root 1.52
394     free (data1);
395     free (data2);
396 root 1.51 }
397    
398     static eq_vtbl eq_context_vtbl = { 0, eq_context_push };
399    
400 root 1.52 static void CL_CALLBACK
401     eq_context_notify (const char *msg, const void *pvt, size_t cb, void *user_data)
402     {
403     void *pvt_copy = malloc (cb);
404     memcpy (pvt_copy, pvt, cb);
405     eq_enq (&eq_context_vtbl, user_data, strdup (msg), pvt_copy, (void *)cb);
406     }
407    
408     #define CONTEXT_NOTIFY_CALLBACK \
409     void (CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *) = context_default_notify; \
410     void *user_data = 0; \
411     \
412     if (SvOK (notify)) \
413     { \
414     pfn_notify = eq_context_notify; \
415     user_data = s_get_cv (notify); \
416     }
417    
418     static SV *
419     new_clobj_context (cl_context ctx, void *user_data)
420     {
421     SV *sv = NEW_CLOBJ ("OpenCL::Context", ctx);
422    
423     if (user_data)
424     sv_magicext (SvRV (sv), user_data, PERL_MAGIC_ext, 0, 0, 0);
425    
426     return sv;
427     }
428    
429     #define XPUSH_CLOBJ_CONTEXT XPUSHs (new_clobj_context (ctx, user_data));
430    
431     /*****************************************************************************/
432 root 1.51 /* build/compile/link notify */
433    
434     static void
435     eq_program_push (void *data1, void *data2, void *data3)
436     {
437     dSP;
438     PUSH_CLOBJ ("OpenCL::Program", data1);
439     PUTBACK;
440     }
441    
442     static eq_vtbl eq_program_vtbl = { 1, eq_program_push };
443    
444     static void CL_CALLBACK
445     eq_program_notify (cl_program program, void *user_data)
446     {
447     eq_enq (&eq_program_vtbl, user_data, (void *)program, 0, 0);
448     }
449    
450     struct build_args
451     {
452     cl_program program;
453     char *options;
454     void *user_data;
455     cl_uint num_devices;
456     };
457    
458     X_THREAD_PROC (build_program_thread)
459     {
460     struct build_args *arg = thr_arg;
461    
462     clBuildProgram (arg->program, arg->num_devices, arg->num_devices ? (void *)(arg + 1) : 0, arg->options, 0, 0);
463    
464     if (arg->user_data)
465     eq_program_notify (arg->program, arg->user_data);
466     else
467     clReleaseProgram (arg->program);
468    
469     free (arg->options);
470     free (arg);
471     }
472    
473     static void
474     build_program_async (cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, void *user_data)
475     {
476     struct build_args *arg = malloc (sizeof (struct build_args) + sizeof (*device_list) * num_devices);
477    
478     arg->program = program;
479     arg->options = strdup (options);
480     arg->user_data = user_data;
481     arg->num_devices = num_devices;
482     memcpy (arg + 1, device_list, sizeof (*device_list) * num_devices);
483    
484     xthread_t id;
485     thread_create (&id, build_program_thread, arg);
486     }
487    
488 root 1.52 /*****************************************************************************/
489 root 1.51 /* event objects */
490    
491     static void
492     eq_event_push (void *data1, void *data2, void *data3)
493     {
494     dSP;
495     PUSH_CLOBJ ("OpenCL::Event", data1);
496     PUSHs (sv_2mortal (newSViv ((IV)data2)));
497     PUTBACK;
498     }
499    
500     static eq_vtbl eq_event_vtbl = { 1, eq_event_push };
501    
502     static void CL_CALLBACK
503     eq_event_notify (cl_event event, cl_int event_command_exec_status, void *user_data)
504     {
505     clRetainEvent (event);
506 root 1.52 eq_enq (&eq_event_vtbl, user_data, (void *)event, (void *)(IV)event_command_exec_status, 0);
507 root 1.51 }
508    
509     /*****************************************************************************/
510    
511 root 1.11 static size_t
512     img_row_pitch (cl_mem img)
513     {
514     size_t res;
515     clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0);
516     return res;
517     }
518    
519 root 1.5 static cl_event *
520 root 1.35 event_list (SV **items, cl_uint *rcount)
521 root 1.5 {
522 root 1.35 cl_uint count = *rcount;
523    
524 root 1.20 if (!count)
525     return 0;
526    
527 root 1.5 cl_event *list = tmpbuf (sizeof (cl_event) * count);
528 root 1.35 int i = 0;
529    
530     do
531     {
532     --count;
533     if (SvOK (items [count]))
534 root 1.51 list [i++] = SvCLOBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event");
535 root 1.35 }
536     while (count);
537 root 1.5
538 root 1.35 *rcount = i;
539 root 1.5
540 root 1.35 return i ? list : 0;
541 root 1.5 }
542    
543     #define EVENT_LIST(items,count) \
544     cl_uint event_list_count = (count); \
545 root 1.35 cl_event *event_list_ptr = event_list (&ST (items), &event_list_count)
546 root 1.2
547     #define INFO(class) \
548     { \
549 root 1.23 size_t size; \
550     NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \
551 root 1.10 SV *sv = sv_2mortal (newSV (size)); \
552 root 1.2 SvUPGRADE (sv, SVt_PV); \
553     SvPOK_only (sv); \
554     SvCUR_set (sv, size); \
555 root 1.23 NEED_SUCCESS (Get ## class ## Info, (self, name, size, SvPVX (sv), 0)); \
556 root 1.2 XPUSHs (sv); \
557     }
558    
559 root 1.1 MODULE = OpenCL PACKAGE = OpenCL
560    
561 root 1.2 PROTOTYPES: ENABLE
562    
563 root 1.51 void
564     poll ()
565     CODE:
566     eq_poll ();
567    
568     void
569     _eq_initialise (IV func, IV arg)
570     CODE:
571     eq_signal_func = (void (*)(void *, int))func;
572     eq_signal_arg = (void*)arg;
573    
574 root 1.1 BOOT:
575     {
576 root 1.24 HV *stash = gv_stashpv ("OpenCL", 1);
577     static const ivstr *civ, const_iv[] = {
578     { sizeof (cl_char ), "SIZEOF_CHAR" },
579     { sizeof (cl_uchar ), "SIZEOF_UCHAR" },
580     { sizeof (cl_short ), "SIZEOF_SHORT" },
581     { sizeof (cl_ushort), "SIZEOF_USHORT" },
582     { sizeof (cl_int ), "SIZEOF_INT" },
583     { sizeof (cl_uint ), "SIZEOF_UINT" },
584     { sizeof (cl_long ), "SIZEOF_LONG" },
585     { sizeof (cl_ulong ), "SIZEOF_ULONG" },
586     { sizeof (cl_half ), "SIZEOF_HALF" },
587     { sizeof (cl_float ), "SIZEOF_FLOAT" },
588     { sizeof (cl_double), "SIZEOF_DOUBLE" },
589 root 1.1 #include "constiv.h"
590 root 1.24 };
591 root 1.51
592 root 1.24 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
593     newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
594 root 1.51
595     sv_setiv (perl_get_sv ("OpenCL::POLL_FUNC", TRUE), (IV)eq_poll_interrupt);
596 root 1.1 }
597    
598 root 1.5 cl_int
599     errno ()
600     CODE:
601 root 1.37 RETVAL = res;
602     OUTPUT:
603     RETVAL
604 root 1.5
605 root 1.3 const char *
606 root 1.57 err2str (cl_int err = res)
607 root 1.3
608     const char *
609     enum2str (cl_uint value)
610    
611 root 1.1 void
612     platforms ()
613     PPCODE:
614     cl_platform_id *list;
615     cl_uint count;
616     int i;
617    
618 root 1.2 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count));
619 root 1.4 list = tmpbuf (sizeof (*list) * count);
620 root 1.2 NEED_SUCCESS (GetPlatformIDs, (count, list, 0));
621 root 1.1
622     EXTEND (SP, count);
623     for (i = 0; i < count; ++i)
624 root 1.51 PUSH_CLOBJ ("OpenCL::Platform", list [i]);
625 root 1.1
626     void
627 root 1.52 context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef)
628 root 1.1 PPCODE:
629 root 1.52 CONTEXT_NOTIFY_CALLBACK;
630 root 1.24 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res));
631 root 1.52 XPUSH_CLOBJ_CONTEXT;
632 root 1.37
633 root 1.8 void
634 root 1.52 context (FUTURE properties, FUTURE devices, FUTURE notify)
635 root 1.8 PPCODE:
636     /* der Gipfel der Kunst */
637 root 1.1
638 root 1.2 void
639     wait_for_events (...)
640     CODE:
641     EVENT_LIST (0, items);
642     NEED_SUCCESS (WaitForEvents, (event_list_count, event_list_ptr));
643    
644     PROTOTYPES: DISABLE
645    
646 root 1.1 MODULE = OpenCL PACKAGE = OpenCL::Platform
647    
648     void
649 root 1.22 info (OpenCL::Platform self, cl_platform_info name)
650 root 1.1 PPCODE:
651 root 1.2 INFO (Platform)
652 root 1.1
653 root 1.47 void
654     unload_compiler (OpenCL::Platform self)
655     CODE:
656     #if CL_VERSION_1_2
657     clUnloadPlatformCompiler (self);
658     #endif
659    
660 root 1.13 #BEGIN:platform
661    
662     void
663 root 1.22 profile (OpenCL::Platform self)
664 root 1.16 ALIAS:
665     profile = CL_PLATFORM_PROFILE
666     version = CL_PLATFORM_VERSION
667     name = CL_PLATFORM_NAME
668     vendor = CL_PLATFORM_VENDOR
669     extensions = CL_PLATFORM_EXTENSIONS
670 root 1.14 PPCODE:
671     size_t size;
672 root 1.22 NEED_SUCCESS (GetPlatformInfo, (self, ix, 0, 0, &size));
673 root 1.14 char *value = tmpbuf (size);
674 root 1.22 NEED_SUCCESS (GetPlatformInfo, (self, ix, size, value, 0));
675 root 1.16 EXTEND (SP, 1);
676     const int i = 0;
677 root 1.14 PUSHs (sv_2mortal (newSVpv (value, 0)));
678 root 1.13
679     #END:platform
680    
681 root 1.1 void
682 root 1.22 devices (OpenCL::Platform self, cl_device_type type = CL_DEVICE_TYPE_ALL)
683 root 1.1 PPCODE:
684     cl_device_id *list;
685     cl_uint count;
686     int i;
687    
688 root 1.22 NEED_SUCCESS (GetDeviceIDs, (self, type, 0, 0, &count));
689 root 1.4 list = tmpbuf (sizeof (*list) * count);
690 root 1.22 NEED_SUCCESS (GetDeviceIDs, (self, type, count, list, 0));
691 root 1.1
692     EXTEND (SP, count);
693     for (i = 0; i < count; ++i)
694     PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i]));
695    
696     void
697 root 1.52 context (OpenCL::Platform self, cl_context_properties *properties, SV *devices, SV *notify = &PL_sv_undef)
698 root 1.8 PPCODE:
699     if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV)
700 root 1.27 croak ("OpenCL::Platform::context argument 'device' must be an arrayref with device objects, in call");
701 root 1.8
702 root 1.11 AV *av = (AV *)SvRV (devices);
703 root 1.8 cl_uint num_devices = av_len (av) + 1;
704     cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices);
705 root 1.51
706 root 1.8 int i;
707     for (i = num_devices; i--; )
708 root 1.51 device_list [i] = SvCLOBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device");
709 root 1.8
710 root 1.52 CONTEXT_NOTIFY_CALLBACK;
711 root 1.51 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (properties, num_devices, device_list, pfn_notify, user_data, &res));
712 root 1.52 XPUSH_CLOBJ_CONTEXT;
713 root 1.8
714     void
715 root 1.52 context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef)
716 root 1.1 PPCODE:
717 root 1.24 cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self };
718     cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context_from_type", "properties", properties, extra, 2);
719 root 1.52
720     CONTEXT_NOTIFY_CALLBACK;
721 root 1.8 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res));
722 root 1.52 XPUSH_CLOBJ_CONTEXT;
723 root 1.1
724 root 1.16 MODULE = OpenCL PACKAGE = OpenCL::Device
725 root 1.14
726     void
727 root 1.22 info (OpenCL::Device self, cl_device_info name)
728 root 1.16 PPCODE:
729     INFO (Device)
730 root 1.14
731 root 1.16 #BEGIN:device
732 root 1.14
733     void
734 root 1.22 type (OpenCL::Device self)
735 root 1.14 PPCODE:
736 root 1.16 cl_device_type value [1];
737 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_TYPE, sizeof (value), value, 0));
738 root 1.16 EXTEND (SP, 1);
739     const int i = 0;
740     PUSHs (sv_2mortal (newSViv (value [i])));
741 root 1.14
742     void
743 root 1.22 vendor_id (OpenCL::Device self)
744 root 1.16 ALIAS:
745     vendor_id = CL_DEVICE_VENDOR_ID
746     max_compute_units = CL_DEVICE_MAX_COMPUTE_UNITS
747     max_work_item_dimensions = CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
748     preferred_vector_width_char = CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR
749     preferred_vector_width_short = CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT
750     preferred_vector_width_int = CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT
751     preferred_vector_width_long = CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG
752     preferred_vector_width_float = CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT
753     preferred_vector_width_double = CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE
754     max_clock_frequency = CL_DEVICE_MAX_CLOCK_FREQUENCY
755     max_read_image_args = CL_DEVICE_MAX_READ_IMAGE_ARGS
756     max_write_image_args = CL_DEVICE_MAX_WRITE_IMAGE_ARGS
757     image_support = CL_DEVICE_IMAGE_SUPPORT
758     max_samplers = CL_DEVICE_MAX_SAMPLERS
759     mem_base_addr_align = CL_DEVICE_MEM_BASE_ADDR_ALIGN
760     min_data_type_align_size = CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE
761     global_mem_cacheline_size = CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE
762     max_constant_args = CL_DEVICE_MAX_CONSTANT_ARGS
763     preferred_vector_width_half = CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF
764     native_vector_width_char = CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR
765     native_vector_width_short = CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT
766     native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT
767     native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG
768     native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT
769     native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE
770     native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF
771 root 1.41 reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT
772 root 1.14 PPCODE:
773     cl_uint value [1];
774 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
775 root 1.14 EXTEND (SP, 1);
776     const int i = 0;
777     PUSHs (sv_2mortal (newSVuv (value [i])));
778    
779     void
780 root 1.22 max_work_group_size (OpenCL::Device self)
781 root 1.16 ALIAS:
782     max_work_group_size = CL_DEVICE_MAX_WORK_GROUP_SIZE
783     image2d_max_width = CL_DEVICE_IMAGE2D_MAX_WIDTH
784     image2d_max_height = CL_DEVICE_IMAGE2D_MAX_HEIGHT
785     image3d_max_width = CL_DEVICE_IMAGE3D_MAX_WIDTH
786     image3d_max_height = CL_DEVICE_IMAGE3D_MAX_HEIGHT
787     image3d_max_depth = CL_DEVICE_IMAGE3D_MAX_DEPTH
788     max_parameter_size = CL_DEVICE_MAX_PARAMETER_SIZE
789     profiling_timer_resolution = CL_DEVICE_PROFILING_TIMER_RESOLUTION
790 root 1.14 PPCODE:
791 root 1.16 size_t value [1];
792 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
793 root 1.14 EXTEND (SP, 1);
794     const int i = 0;
795     PUSHs (sv_2mortal (newSVuv (value [i])));
796    
797     void
798 root 1.22 max_work_item_sizes (OpenCL::Device self)
799 root 1.14 PPCODE:
800 root 1.16 size_t size;
801 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_MAX_WORK_ITEM_SIZES, 0, 0, &size));
802 root 1.16 size_t *value = tmpbuf (size);
803 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_MAX_WORK_ITEM_SIZES, size, value, 0));
804 root 1.16 int i, n = size / sizeof (*value);
805     EXTEND (SP, n);
806     for (i = 0; i < n; ++i)
807 root 1.14 PUSHs (sv_2mortal (newSVuv (value [i])));
808    
809     void
810 root 1.22 address_bits (OpenCL::Device self)
811 root 1.14 PPCODE:
812 root 1.16 cl_bitfield value [1];
813 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_ADDRESS_BITS, sizeof (value), value, 0));
814 root 1.14 EXTEND (SP, 1);
815     const int i = 0;
816     PUSHs (sv_2mortal (newSVuv (value [i])));
817    
818     void
819 root 1.22 max_mem_alloc_size (OpenCL::Device self)
820 root 1.16 ALIAS:
821     max_mem_alloc_size = CL_DEVICE_MAX_MEM_ALLOC_SIZE
822     global_mem_cache_size = CL_DEVICE_GLOBAL_MEM_CACHE_SIZE
823     global_mem_size = CL_DEVICE_GLOBAL_MEM_SIZE
824     max_constant_buffer_size = CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE
825     local_mem_size = CL_DEVICE_LOCAL_MEM_SIZE
826 root 1.14 PPCODE:
827 root 1.16 cl_ulong value [1];
828 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
829 root 1.14 EXTEND (SP, 1);
830     const int i = 0;
831     PUSHs (sv_2mortal (newSVuv (value [i])));
832    
833     void
834 root 1.22 single_fp_config (OpenCL::Device self)
835 root 1.16 ALIAS:
836     single_fp_config = CL_DEVICE_SINGLE_FP_CONFIG
837     double_fp_config = CL_DEVICE_DOUBLE_FP_CONFIG
838     half_fp_config = CL_DEVICE_HALF_FP_CONFIG
839 root 1.14 PPCODE:
840 root 1.16 cl_device_fp_config value [1];
841 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
842 root 1.14 EXTEND (SP, 1);
843     const int i = 0;
844     PUSHs (sv_2mortal (newSVuv (value [i])));
845    
846     void
847 root 1.22 global_mem_cache_type (OpenCL::Device self)
848 root 1.14 PPCODE:
849 root 1.16 cl_device_mem_cache_type value [1];
850 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, sizeof (value), value, 0));
851 root 1.14 EXTEND (SP, 1);
852     const int i = 0;
853     PUSHs (sv_2mortal (newSVuv (value [i])));
854    
855     void
856 root 1.22 local_mem_type (OpenCL::Device self)
857 root 1.14 PPCODE:
858 root 1.16 cl_device_local_mem_type value [1];
859 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_LOCAL_MEM_TYPE, sizeof (value), value, 0));
860 root 1.14 EXTEND (SP, 1);
861     const int i = 0;
862     PUSHs (sv_2mortal (newSVuv (value [i])));
863    
864     void
865 root 1.22 error_correction_support (OpenCL::Device self)
866 root 1.16 ALIAS:
867     error_correction_support = CL_DEVICE_ERROR_CORRECTION_SUPPORT
868     endian_little = CL_DEVICE_ENDIAN_LITTLE
869     available = CL_DEVICE_AVAILABLE
870     compiler_available = CL_DEVICE_COMPILER_AVAILABLE
871     host_unified_memory = CL_DEVICE_HOST_UNIFIED_MEMORY
872 root 1.14 PPCODE:
873 root 1.16 cl_bool value [1];
874 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
875 root 1.14 EXTEND (SP, 1);
876     const int i = 0;
877 root 1.16 PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no));
878 root 1.14
879     void
880 root 1.22 execution_capabilities (OpenCL::Device self)
881 root 1.14 PPCODE:
882 root 1.16 cl_device_exec_capabilities value [1];
883 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_EXECUTION_CAPABILITIES, sizeof (value), value, 0));
884 root 1.14 EXTEND (SP, 1);
885     const int i = 0;
886     PUSHs (sv_2mortal (newSVuv (value [i])));
887    
888     void
889 root 1.22 properties (OpenCL::Device self)
890 root 1.14 PPCODE:
891 root 1.16 cl_command_queue_properties value [1];
892 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_QUEUE_PROPERTIES, sizeof (value), value, 0));
893 root 1.14 EXTEND (SP, 1);
894     const int i = 0;
895 root 1.16 PUSHs (sv_2mortal (newSViv (value [i])));
896 root 1.14
897     void
898 root 1.22 platform (OpenCL::Device self)
899 root 1.14 PPCODE:
900 root 1.16 cl_platform_id value [1];
901 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_PLATFORM, sizeof (value), value, 0));
902 root 1.14 EXTEND (SP, 1);
903     const int i = 0;
904     {
905 root 1.51 PUSH_CLOBJ ("OpenCL::Platform", value [i]);
906 root 1.14 }
907    
908     void
909 root 1.22 name (OpenCL::Device self)
910 root 1.16 ALIAS:
911     name = CL_DEVICE_NAME
912     vendor = CL_DEVICE_VENDOR
913     driver_version = CL_DRIVER_VERSION
914     profile = CL_DEVICE_PROFILE
915     version = CL_DEVICE_VERSION
916     extensions = CL_DEVICE_EXTENSIONS
917 root 1.14 PPCODE:
918     size_t size;
919 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, 0, 0, &size));
920 root 1.16 char *value = tmpbuf (size);
921 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, size, value, 0));
922 root 1.16 EXTEND (SP, 1);
923     const int i = 0;
924     PUSHs (sv_2mortal (newSVpv (value, 0)));
925 root 1.14
926     void
927 root 1.22 parent_device_ext (OpenCL::Device self)
928 root 1.14 PPCODE:
929 root 1.16 cl_device_id value [1];
930 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_PARENT_DEVICE_EXT, sizeof (value), value, 0));
931 root 1.14 EXTEND (SP, 1);
932     const int i = 0;
933 root 1.16 {
934 root 1.51 PUSH_CLOBJ ("OpenCL::Device", value [i]);
935 root 1.16 }
936 root 1.14
937     void
938 root 1.22 partition_types_ext (OpenCL::Device self)
939 root 1.16 ALIAS:
940     partition_types_ext = CL_DEVICE_PARTITION_TYPES_EXT
941     affinity_domains_ext = CL_DEVICE_AFFINITY_DOMAINS_EXT
942     partition_style_ext = CL_DEVICE_PARTITION_STYLE_EXT
943 root 1.14 PPCODE:
944     size_t size;
945 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, 0, 0, &size));
946 root 1.14 cl_device_partition_property_ext *value = tmpbuf (size);
947 root 1.22 NEED_SUCCESS (GetDeviceInfo, (self, ix, size, value, 0));
948 root 1.15 int i, n = size / sizeof (*value);
949 root 1.14 EXTEND (SP, n);
950     for (i = 0; i < n; ++i)
951     PUSHs (sv_2mortal (newSVuv (value [i])));
952    
953     #END:device
954    
955 root 1.1 MODULE = OpenCL PACKAGE = OpenCL::Context
956    
957     void
958     DESTROY (OpenCL::Context context)
959     CODE:
960     clReleaseContext (context);
961    
962     void
963 root 1.22 info (OpenCL::Context self, cl_context_info name)
964 root 1.1 PPCODE:
965 root 1.2 INFO (Context)
966    
967     void
968 root 1.22 queue (OpenCL::Context self, OpenCL::Device device, cl_command_queue_properties properties = 0)
969 root 1.2 PPCODE:
970 root 1.23 NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (self, device, properties, &res));
971 root 1.51 XPUSH_CLOBJ ("OpenCL::Queue", queue);
972 root 1.2
973     void
974 root 1.22 user_event (OpenCL::Context self)
975 root 1.5 PPCODE:
976 root 1.23 NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (self, &res));
977 root 1.51 XPUSH_CLOBJ ("OpenCL::UserEvent", ev);
978 root 1.5
979     void
980 root 1.22 buffer (OpenCL::Context self, cl_mem_flags flags, size_t len)
981 root 1.2 PPCODE:
982 root 1.3 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
983 root 1.27 croak ("OpenCL::Context::buffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?");
984 root 1.3
985 root 1.22 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res));
986 root 1.51 XPUSH_CLOBJ ("OpenCL::BufferObj", mem);
987 root 1.2
988     void
989 root 1.22 buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data)
990 root 1.2 PPCODE:
991     STRLEN len;
992 root 1.21 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
993 root 1.3 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
994 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?");
995 root 1.22 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res));
996 root 1.51 XPUSH_CLOBJ ("OpenCL::BufferObj", mem);
997 root 1.3
998 root 1.42 #if CL_VERSION_1_2
999    
1000     void
1001 root 1.55 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 = 0, 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)
1002 root 1.42 PPCODE:
1003     STRLEN len;
1004     char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
1005     const cl_image_format format = { channel_order, channel_type };
1006     const cl_image_desc desc = {
1007     type,
1008     width, height, depth,
1009     array_size, row_pitch, slice_pitch,
1010     num_mip_level, num_samples,
1011 root 1.51 type == CL_MEM_OBJECT_IMAGE1D_BUFFER ? (cl_mem)SvCLOBJ ("OpenCL::Context::Image", "data", data, "OpenCL::Buffer") : 0
1012 root 1.42 };
1013     NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
1014     char *klass = "OpenCL::Image";
1015     switch (type)
1016     {
1017     case CL_MEM_OBJECT_IMAGE1D_BUFFER: klass = "OpenCL::Image1DBuffer"; break;
1018     case CL_MEM_OBJECT_IMAGE1D: klass = "OpenCL::Image1D"; break;
1019     case CL_MEM_OBJECT_IMAGE1D_ARRAY: klass = "OpenCL::Image2DArray"; break;
1020     case CL_MEM_OBJECT_IMAGE2D: klass = "OpenCL::Image2D"; break;
1021     case CL_MEM_OBJECT_IMAGE2D_ARRAY: klass = "OpenCL::Image2DArray"; break;
1022     case CL_MEM_OBJECT_IMAGE3D: klass = "OpenCL::Image3D"; break;
1023     }
1024 root 1.51 XPUSH_CLOBJ (klass, mem);
1025 root 1.42
1026     #endif
1027    
1028 root 1.3 void
1029 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)
1030 root 1.3 PPCODE:
1031     STRLEN len;
1032 root 1.21 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
1033 root 1.3 const cl_image_format format = { channel_order, channel_type };
1034 root 1.44 #if PREFER_1_1
1035     NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res));
1036     #else
1037 root 1.42 const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE2D, width, height, 0, 0, row_pitch, 0, 0, 0, 0 };
1038     NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
1039     #endif
1040 root 1.51 XPUSH_CLOBJ ("OpenCL::Image2D", mem);
1041 root 1.3
1042     void
1043 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)
1044 root 1.3 PPCODE:
1045     STRLEN len;
1046 root 1.21 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
1047 root 1.3 const cl_image_format format = { channel_order, channel_type };
1048 root 1.44 #if PREFER_1_1
1049     NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
1050     #else
1051 root 1.42 const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE3D, width, height, depth, 0, row_pitch, slice_pitch, 0, 0, 0 };
1052     NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
1053     #endif
1054 root 1.51 XPUSH_CLOBJ ("OpenCL::Image3D", mem);
1055 root 1.3
1056 root 1.25 #if cl_apple_gl_sharing || cl_khr_gl_sharing
1057    
1058     void
1059     gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj)
1060     PPCODE:
1061     NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res));
1062 root 1.51 XPUSH_CLOBJ ("OpenCL::BufferObj", mem);
1063 root 1.25
1064     void
1065 root 1.40 gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer)
1066 root 1.25 PPCODE:
1067 root 1.40 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res));
1068 root 1.51 XPUSH_CLOBJ ("OpenCL::Image2D", mem);
1069 root 1.25
1070 root 1.39 #if CL_VERSION_1_2
1071    
1072     void
1073     gl_texture (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
1074 root 1.43 ALIAS:
1075 root 1.39 PPCODE:
1076 root 1.43 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture, (self, flags, target, miplevel, texture, &res));
1077     cl_gl_object_type type;
1078     NEED_SUCCESS (GetGLObjectInfo, (mem, &type, 0)); // TODO: use target instead?
1079 root 1.39 char *klass = "OpenCL::Memory";
1080 root 1.42 switch (type)
1081 root 1.39 {
1082     case CL_GL_OBJECT_TEXTURE_BUFFER: klass = "OpenCL::Image1DBuffer"; break;
1083     case CL_GL_OBJECT_TEXTURE1D: klass = "OpenCL::Image1D"; break;
1084     case CL_GL_OBJECT_TEXTURE1D_ARRAY: klass = "OpenCL::Image2DArray"; break;
1085     case CL_GL_OBJECT_TEXTURE2D: klass = "OpenCL::Image2D"; break;
1086     case CL_GL_OBJECT_TEXTURE2D_ARRAY: klass = "OpenCL::Image2DArray"; break;
1087     case CL_GL_OBJECT_TEXTURE3D: klass = "OpenCL::Image3D"; break;
1088     }
1089 root 1.51 XPUSH_CLOBJ (klass, mem);
1090 root 1.39
1091 root 1.44 #endif
1092 root 1.40
1093 root 1.25 void
1094 root 1.40 gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
1095 root 1.25 PPCODE:
1096 root 1.44 #if PREFER_1_1
1097 root 1.40 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
1098 root 1.44 #else
1099     NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture , (self, flags, target, miplevel, texture, &res));
1100     #endif
1101 root 1.51 XPUSH_CLOBJ ("OpenCL::Image2D", mem);
1102 root 1.25
1103 root 1.40 void
1104     gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
1105     PPCODE:
1106 root 1.44 #if PREFER_1_1
1107 root 1.40 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res));
1108 root 1.44 #else
1109     NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture , (self, flags, target, miplevel, texture, &res));
1110     #endif
1111 root 1.51 XPUSH_CLOBJ ("OpenCL::Image3D", mem);
1112 root 1.40
1113     #endif
1114    
1115 root 1.3 void
1116 root 1.22 supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type)
1117 root 1.3 PPCODE:
1118     {
1119     cl_uint count;
1120     cl_image_format *list;
1121     int i;
1122    
1123 root 1.23 NEED_SUCCESS (GetSupportedImageFormats, (self, flags, image_type, 0, 0, &count));
1124 root 1.3 Newx (list, count, cl_image_format);
1125 root 1.23 NEED_SUCCESS (GetSupportedImageFormats, (self, flags, image_type, count, list, 0));
1126 root 1.3
1127     EXTEND (SP, count);
1128     for (i = 0; i < count; ++i)
1129     {
1130     AV *av = newAV ();
1131     av_store (av, 1, newSVuv (list [i].image_channel_data_type));
1132     av_store (av, 0, newSVuv (list [i].image_channel_order));
1133     PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
1134     }
1135 root 1.2 }
1136    
1137     void
1138 root 1.22 sampler (OpenCL::Context self, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode)
1139 root 1.2 PPCODE:
1140 root 1.23 NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (self, normalized_coords, addressing_mode, filter_mode, &res));
1141 root 1.51 XPUSH_CLOBJ ("OpenCL::Sampler", sampler);
1142 root 1.1
1143     void
1144 root 1.22 program_with_source (OpenCL::Context self, SV *program)
1145 root 1.1 PPCODE:
1146 root 1.2 STRLEN len;
1147     size_t len2;
1148     const char *ptr = SvPVbyte (program, len);
1149    
1150     len2 = len;
1151 root 1.23 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (self, 1, &ptr, &len2, &res));
1152 root 1.51 XPUSH_CLOBJ ("OpenCL::Program", prog);
1153 root 1.1
1154 root 1.13 #BEGIN:context
1155    
1156 root 1.14 void
1157 root 1.22 reference_count (OpenCL::Context self)
1158 root 1.16 ALIAS:
1159     reference_count = CL_CONTEXT_REFERENCE_COUNT
1160     num_devices = CL_CONTEXT_NUM_DEVICES
1161 root 1.14 PPCODE:
1162     cl_uint value [1];
1163 root 1.22 NEED_SUCCESS (GetContextInfo, (self, ix, sizeof (value), value, 0));
1164 root 1.14 EXTEND (SP, 1);
1165     const int i = 0;
1166     PUSHs (sv_2mortal (newSVuv (value [i])));
1167    
1168     void
1169 root 1.22 devices (OpenCL::Context self)
1170 root 1.14 PPCODE:
1171     size_t size;
1172 root 1.22 NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_DEVICES, 0, 0, &size));
1173 root 1.14 cl_device_id *value = tmpbuf (size);
1174 root 1.22 NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_DEVICES, size, value, 0));
1175 root 1.15 int i, n = size / sizeof (*value);
1176 root 1.14 EXTEND (SP, n);
1177     for (i = 0; i < n; ++i)
1178     {
1179 root 1.51 PUSH_CLOBJ ("OpenCL::Device", value [i]);
1180 root 1.14 }
1181    
1182     void
1183 root 1.22 properties (OpenCL::Context self)
1184 root 1.14 PPCODE:
1185     size_t size;
1186 root 1.22 NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_PROPERTIES, 0, 0, &size));
1187 root 1.14 cl_context_properties *value = tmpbuf (size);
1188 root 1.22 NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_PROPERTIES, size, value, 0));
1189 root 1.15 int i, n = size / sizeof (*value);
1190 root 1.14 EXTEND (SP, n);
1191     for (i = 0; i < n; ++i)
1192     PUSHs (sv_2mortal (newSVuv ((UV)value [i])));
1193    
1194 root 1.13 #END:context
1195    
1196 root 1.1 MODULE = OpenCL PACKAGE = OpenCL::Queue
1197    
1198     void
1199 root 1.22 DESTROY (OpenCL::Queue self)
1200 root 1.1 CODE:
1201 root 1.22 clReleaseCommandQueue (self);
1202 root 1.1
1203     void
1204 root 1.55 read_buffer (OpenCL::Queue self, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...)
1205     ALIAS:
1206     enqueue_read_buffer = 0
1207 root 1.2 PPCODE:
1208     cl_event ev = 0;
1209     EVENT_LIST (6, items - 6);
1210    
1211     SvUPGRADE (data, SVt_PV);
1212     SvGROW (data, len);
1213     SvPOK_only (data);
1214     SvCUR_set (data, len);
1215 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));
1216 root 1.2
1217     if (ev)
1218 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1219 root 1.2
1220     void
1221 root 1.55 write_buffer (OpenCL::Queue self, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...)
1222     ALIAS:
1223     enqueue_write_buffer = 0
1224 root 1.2 PPCODE:
1225     cl_event ev = 0;
1226     STRLEN len;
1227     char *ptr = SvPVbyte (data, len);
1228     EVENT_LIST (5, items - 5);
1229    
1230 root 1.34 NEED_SUCCESS (EnqueueWriteBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1231 root 1.2
1232     if (ev)
1233 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1234 root 1.2
1235 root 1.48 #if CL_VERSION_1_2
1236    
1237     void
1238 root 1.55 fill_buffer (OpenCL::Queue self, OpenCL::Buffer mem, SV *data, size_t offset, size_t size, ...)
1239     ALIAS:
1240     enqueue_fill_buffer = 0
1241 root 1.48 PPCODE:
1242     cl_event ev = 0;
1243     STRLEN len;
1244     char *ptr = SvPVbyte (data, len);
1245     EVENT_LIST (5, items - 5);
1246    
1247     NEED_SUCCESS (EnqueueFillBuffer, (self, mem, ptr, len, offset, size, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1248    
1249     if (ev)
1250 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1251 root 1.48
1252     void
1253 root 1.55 fill_image (OpenCL::Queue self, OpenCL::Image img, NV r, NV g, NV b, NV a, size_t x, size_t y, size_t z, size_t width, size_t height, size_t depth, ...)
1254     ALIAS:
1255     enqueue_fill_image = 0
1256 root 1.48 PPCODE:
1257     cl_event ev = 0;
1258     STRLEN len;
1259     const size_t origin [3] = { x, y, z };
1260     const size_t region [3] = { width, height, depth };
1261     EVENT_LIST (12, items - 12);
1262    
1263     const cl_float c_f [4] = { r, g, b, a };
1264     const cl_uint c_u [4] = { r, g, b, a };
1265     const cl_int c_s [4] = { r, g, b, a };
1266     const void *c_fus [3] = { &c_f, &c_u, &c_s };
1267     static const char fus [] = { 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 1, 1, 1, 0, 0 };
1268     cl_image_format format;
1269 root 1.50 NEED_SUCCESS (GetImageInfo, (img, CL_IMAGE_FORMAT, sizeof (format), &format, 0));
1270 root 1.48 assert (sizeof (fus) == CL_FLOAT + 1 - CL_SNORM_INT8);
1271     if (format.image_channel_data_type < CL_SNORM_INT8 || CL_FLOAT < format.image_channel_data_type)
1272     croak ("enqueue_fill_image: image has unsupported channel type, only opencl 1.2 channel types supported.");
1273    
1274 root 1.55 NEED_SUCCESS (EnqueueFillImage, (self, img, c_fus [fus [format.image_channel_data_type - CL_SNORM_INT8]],
1275 root 1.48 origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1276    
1277     if (ev)
1278 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1279 root 1.48
1280     #endif
1281    
1282 root 1.2 void
1283 root 1.55 copy_buffer (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...)
1284     ALIAS:
1285     enqueue_copy_buffer = 0
1286 root 1.2 PPCODE:
1287     cl_event ev = 0;
1288     EVENT_LIST (6, items - 6);
1289    
1290 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));
1291 root 1.2
1292     if (ev)
1293 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1294 root 1.2
1295 root 1.3 void
1296 root 1.55 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, ...)
1297     ALIAS:
1298     enqueue_read_buffer_rect = 0
1299 root 1.17 PPCODE:
1300     cl_event ev = 0;
1301     const size_t buf_origin [3] = { buf_x , buf_y , buf_z };
1302     const size_t host_origin[3] = { host_x, host_y, host_z };
1303     const size_t region[3] = { width, height, depth };
1304     EVENT_LIST (17, items - 17);
1305    
1306     if (!buf_row_pitch)
1307     buf_row_pitch = region [0];
1308    
1309     if (!buf_slice_pitch)
1310     buf_slice_pitch = region [1] * buf_row_pitch;
1311    
1312     if (!host_row_pitch)
1313     host_row_pitch = region [0];
1314    
1315     if (!host_slice_pitch)
1316     host_slice_pitch = region [1] * host_row_pitch;
1317    
1318     size_t len = host_row_pitch * host_slice_pitch * region [2];
1319    
1320     SvUPGRADE (data, SVt_PV);
1321     SvGROW (data, len);
1322     SvPOK_only (data);
1323     SvCUR_set (data, len);
1324 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));
1325 root 1.17
1326     if (ev)
1327 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1328 root 1.17
1329     void
1330 root 1.55 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, ...)
1331     ALIAS:
1332     enqueue_write_buffer_rect = 0
1333 root 1.17 PPCODE:
1334     cl_event ev = 0;
1335     const size_t buf_origin [3] = { buf_x , buf_y , buf_z };
1336     const size_t host_origin[3] = { host_x, host_y, host_z };
1337     const size_t region[3] = { width, height, depth };
1338     STRLEN len;
1339     char *ptr = SvPVbyte (data, len);
1340     EVENT_LIST (17, items - 17);
1341    
1342     if (!buf_row_pitch)
1343     buf_row_pitch = region [0];
1344    
1345     if (!buf_slice_pitch)
1346     buf_slice_pitch = region [1] * buf_row_pitch;
1347    
1348     if (!host_row_pitch)
1349     host_row_pitch = region [0];
1350    
1351     if (!host_slice_pitch)
1352     host_slice_pitch = region [1] * host_row_pitch;
1353    
1354     size_t min_len = host_row_pitch * host_slice_pitch * region [2];
1355    
1356     if (len < min_len)
1357     croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
1358    
1359 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));
1360 root 1.17
1361     if (ev)
1362 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1363 root 1.17
1364     void
1365 root 1.55 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, ...)
1366     ALIAS:
1367     enqueue_copy_buffer_rect = 0
1368 root 1.18 PPCODE:
1369     cl_event ev = 0;
1370     const size_t src_origin[3] = { src_x, src_y, src_z };
1371     const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
1372     const size_t region[3] = { width, height, depth };
1373     EVENT_LIST (16, items - 16);
1374    
1375 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));
1376 root 1.18
1377     if (ev)
1378 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1379 root 1.18
1380     void
1381 root 1.55 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, ...)
1382     ALIAS:
1383     enqueue_read_image = 0
1384 root 1.3 PPCODE:
1385     cl_event ev = 0;
1386     const size_t src_origin[3] = { src_x, src_y, src_z };
1387     const size_t region[3] = { width, height, depth };
1388 root 1.10 EVENT_LIST (12, items - 12);
1389    
1390 root 1.11 if (!row_pitch)
1391     row_pitch = img_row_pitch (src);
1392    
1393     if (depth > 1 && !slice_pitch)
1394     slice_pitch = row_pitch * height;
1395    
1396     size_t len = slice_pitch ? slice_pitch * depth : row_pitch * height;
1397 root 1.3
1398     SvUPGRADE (data, SVt_PV);
1399     SvGROW (data, len);
1400     SvPOK_only (data);
1401     SvCUR_set (data, len);
1402 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));
1403 root 1.3
1404     if (ev)
1405 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1406 root 1.3
1407     void
1408 root 1.55 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, ...)
1409     ALIAS:
1410     enqueue_write_image = 0
1411 root 1.3 PPCODE:
1412     cl_event ev = 0;
1413     const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
1414     const size_t region[3] = { width, height, depth };
1415     STRLEN len;
1416     char *ptr = SvPVbyte (data, len);
1417 root 1.10 EVENT_LIST (12, items - 12);
1418 root 1.3
1419 root 1.11 if (!row_pitch)
1420     row_pitch = img_row_pitch (dst);
1421    
1422     if (depth > 1 && !slice_pitch)
1423     slice_pitch = row_pitch * height;
1424    
1425     size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height;
1426    
1427     if (len < min_len)
1428     croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
1429    
1430 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));
1431 root 1.3
1432     if (ev)
1433 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1434 root 1.3
1435     void
1436 root 1.55 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, ...)
1437     ALIAS:
1438     enqueue_copy_image = 0
1439 root 1.3 PPCODE:
1440     cl_event ev = 0;
1441     const size_t src_origin[3] = { src_x, src_y, src_z };
1442     const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
1443     const size_t region[3] = { width, height, depth };
1444 root 1.18 EVENT_LIST (12, items - 12);
1445 root 1.3
1446 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));
1447 root 1.3
1448     if (ev)
1449 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1450 root 1.3
1451     void
1452 root 1.55 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, ...)
1453     ALIAS:
1454     enqueue_copy_image_to_buffer = 0
1455 root 1.3 PPCODE:
1456     cl_event ev = 0;
1457 root 1.18 const size_t src_origin[3] = { src_x, src_y, src_z };
1458 root 1.3 const size_t region[3] = { width, height, depth };
1459     EVENT_LIST (10, items - 10);
1460    
1461 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));
1462 root 1.3
1463     if (ev)
1464 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1465 root 1.3
1466     void
1467 root 1.55 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, ...)
1468     ALIAS:
1469     enqueue_copy_buffer_to_image = 0
1470 root 1.3 PPCODE:
1471     cl_event ev = 0;
1472     const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
1473     const size_t region[3] = { width, height, depth };
1474     EVENT_LIST (10, items - 10);
1475    
1476 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));
1477 root 1.3
1478     if (ev)
1479 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1480 root 1.3
1481     void
1482 root 1.55 task (OpenCL::Queue self, OpenCL::Kernel kernel, ...)
1483     ALIAS:
1484     enqueue_task = 0
1485 root 1.3 PPCODE:
1486     cl_event ev = 0;
1487     EVENT_LIST (2, items - 2);
1488    
1489 root 1.22 NEED_SUCCESS (EnqueueTask, (self, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1490 root 1.3
1491     if (ev)
1492 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1493 root 1.3
1494 root 1.4 void
1495 root 1.55 nd_range_kernel (OpenCL::Queue self, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...)
1496     ALIAS:
1497     enqueue_nd_range_kernel = 0
1498 root 1.4 PPCODE:
1499     cl_event ev = 0;
1500     size_t *gwo = 0, *gws, *lws = 0;
1501     int gws_len;
1502     size_t *lists;
1503     int i;
1504 root 1.5 EVENT_LIST (5, items - 5);
1505 root 1.4
1506     if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV)
1507     croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference");
1508    
1509     gws_len = AvFILLp (SvRV (global_work_size)) + 1;
1510    
1511     lists = tmpbuf (sizeof (size_t) * 3 * gws_len);
1512    
1513     gws = lists + gws_len * 0;
1514     for (i = 0; i < gws_len; ++i)
1515 root 1.58 {
1516     gws [i] = SvIV (AvARRAY (SvRV (global_work_size))[i]);
1517     // at least nvidia crashes for 0-sized work group sizes, work around
1518     if (!gws [i])
1519     croak ("clEnqueueNDRangeKernel: global_work_size[%d] is zero, must be non-zero", i);
1520     }
1521 root 1.4
1522     if (SvOK (global_work_offset))
1523     {
1524     if (!SvROK (global_work_offset) || SvTYPE (SvRV (global_work_offset)) != SVt_PVAV)
1525     croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array reference");
1526    
1527     if (AvFILLp (SvRV (global_work_size)) + 1 != gws_len)
1528     croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array of same size as global_work_size");
1529    
1530     gwo = lists + gws_len * 1;
1531     for (i = 0; i < gws_len; ++i)
1532     gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
1533     }
1534    
1535     if (SvOK (local_work_size))
1536     {
1537 root 1.37 if ((SvOK (local_work_size) && !SvROK (local_work_size)) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV)
1538 root 1.58 croak ("clEnqueueNDRangeKernel: local_work_size must be undef or an array reference");
1539 root 1.4
1540     if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len)
1541     croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
1542    
1543     lws = lists + gws_len * 2;
1544     for (i = 0; i < gws_len; ++i)
1545 root 1.58 {
1546     lws [i] = SvIV (AvARRAY (SvRV (local_work_size))[i]);
1547     // at least nvidia crashes for 0-sized work group sizes, work around
1548     if (!lws [i])
1549     croak ("clEnqueueNDRangeKernel: local_work_size[%d] is zero, must be non-zero", i);
1550     }
1551 root 1.4 }
1552    
1553 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));
1554 root 1.4
1555     if (ev)
1556 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1557 root 1.3
1558 root 1.25 #if cl_apple_gl_sharing || cl_khr_gl_sharing
1559    
1560     void
1561 root 1.55 acquire_gl_objects (OpenCL::Queue self, SV *objects, ...)
1562     ALIAS:
1563     enqueue_acquire_gl_objects = 0
1564 root 1.27 ALIAS:
1565     enqueue_release_gl_objects = 1
1566 root 1.36 PPCODE:
1567 root 1.27 if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV)
1568     croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call");
1569    
1570 root 1.25 cl_event ev = 0;
1571     EVENT_LIST (2, items - 2);
1572 root 1.27 AV *av = (AV *)SvRV (objects);
1573     cl_uint num_objects = av_len (av) + 1;
1574     cl_mem *object_list = tmpbuf (sizeof (cl_mem) * num_objects);
1575     int i;
1576 root 1.25
1577 root 1.27 for (i = num_objects; i--; )
1578 root 1.51 object_list [i] = SvCLOBJ ("OpenCL::Queue::enqueue_acquire/release_gl_objects", "objects", *av_fetch (av, i, 0), "OpenCL::Memory");
1579 root 1.25
1580 root 1.27 if (ix)
1581     NEED_SUCCESS (EnqueueReleaseGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1582     else
1583     NEED_SUCCESS (EnqueueAcquireGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1584 root 1.25
1585     if (ev)
1586 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1587 root 1.25
1588     #endif
1589    
1590 root 1.2 void
1591 root 1.55 wait_for_events (OpenCL::Queue self, ...)
1592     ALIAS:
1593     enqueue_wait_for_events = 0
1594 root 1.2 CODE:
1595     EVENT_LIST (1, items - 1);
1596 root 1.47 #if PREFER_1_1
1597 root 1.22 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr));
1598 root 1.47 #else
1599     NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, 0));
1600 root 1.38 #endif
1601    
1602     void
1603 root 1.55 marker (OpenCL::Queue self, ...)
1604     ALIAS:
1605     enqueue_marker = 0
1606 root 1.38 PPCODE:
1607     cl_event ev = 0;
1608     EVENT_LIST (1, items - 1);
1609 root 1.45 #if PREFER_1_1
1610 root 1.47 if (!event_list_count)
1611     NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0));
1612     else
1613 root 1.46 #if CL_VERSION_1_2
1614     NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1615     #else
1616 root 1.50 {
1617     NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); // also a barrier
1618     NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0));
1619     }
1620 root 1.46 #endif
1621 root 1.45 #else
1622     NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1623 root 1.38 #endif
1624     if (ev)
1625 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1626 root 1.38
1627 root 1.2 void
1628 root 1.55 barrier (OpenCL::Queue self, ...)
1629     ALIAS:
1630     enqueue_barrier = 0
1631 root 1.38 PPCODE:
1632     cl_event ev = 0;
1633     EVENT_LIST (1, items - 1);
1634 root 1.45 #if PREFER_1_1
1635 root 1.47 if (!event_list_count && GIMME_V == G_VOID)
1636     NEED_SUCCESS (EnqueueBarrier, (self));
1637     else
1638 root 1.46 #if CL_VERSION_1_2
1639     NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1640     #else
1641 root 1.47 {
1642     if (event_list_count)
1643 root 1.50 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr));
1644 root 1.47
1645     if (GIMME_V != G_VOID)
1646     NEED_SUCCESS (EnqueueMarker, (self, &ev));
1647     }
1648 root 1.46 #endif
1649 root 1.45 #else
1650 root 1.46 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1651 root 1.37 #endif
1652 root 1.38 if (ev)
1653 root 1.51 XPUSH_CLOBJ ("OpenCL::Event", ev);
1654 root 1.37
1655 root 1.3 void
1656 root 1.22 flush (OpenCL::Queue self)
1657 root 1.3 CODE:
1658 root 1.22 NEED_SUCCESS (Flush, (self));
1659 root 1.3
1660     void
1661 root 1.22 finish (OpenCL::Queue self)
1662 root 1.3 CODE:
1663 root 1.22 NEED_SUCCESS (Finish, (self));
1664 root 1.3
1665 root 1.14 void
1666 root 1.22 info (OpenCL::Queue self, cl_command_queue_info name)
1667 root 1.14 PPCODE:
1668     INFO (CommandQueue)
1669    
1670     #BEGIN:command_queue
1671    
1672     void
1673 root 1.22 context (OpenCL::Queue self)
1674 root 1.14 PPCODE:
1675     cl_context value [1];
1676 root 1.22 NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_CONTEXT, sizeof (value), value, 0));
1677 root 1.14 EXTEND (SP, 1);
1678     const int i = 0;
1679     {
1680     NEED_SUCCESS (RetainContext, (value [i]));
1681 root 1.51 PUSH_CLOBJ ("OpenCL::Context", value [i]);
1682 root 1.14 }
1683    
1684     void
1685 root 1.22 device (OpenCL::Queue self)
1686 root 1.14 PPCODE:
1687     cl_device_id value [1];
1688 root 1.22 NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_DEVICE, sizeof (value), value, 0));
1689 root 1.14 EXTEND (SP, 1);
1690     const int i = 0;
1691     {
1692 root 1.51 PUSH_CLOBJ ("OpenCL::Device", value [i]);
1693 root 1.14 }
1694    
1695     void
1696 root 1.22 reference_count (OpenCL::Queue self)
1697 root 1.14 PPCODE:
1698     cl_uint value [1];
1699 root 1.22 NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_REFERENCE_COUNT, sizeof (value), value, 0));
1700 root 1.14 EXTEND (SP, 1);
1701     const int i = 0;
1702     PUSHs (sv_2mortal (newSVuv (value [i])));
1703    
1704     void
1705 root 1.22 properties (OpenCL::Queue self)
1706 root 1.14 PPCODE:
1707     cl_command_queue_properties value [1];
1708 root 1.22 NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_PROPERTIES, sizeof (value), value, 0));
1709 root 1.14 EXTEND (SP, 1);
1710     const int i = 0;
1711     PUSHs (sv_2mortal (newSViv (value [i])));
1712    
1713     #END:command_queue
1714    
1715 root 1.2 MODULE = OpenCL PACKAGE = OpenCL::Memory
1716    
1717     void
1718 root 1.22 DESTROY (OpenCL::Memory self)
1719 root 1.2 CODE:
1720 root 1.22 clReleaseMemObject (self);
1721 root 1.2
1722     void
1723 root 1.22 info (OpenCL::Memory self, cl_mem_info name)
1724 root 1.2 PPCODE:
1725     INFO (MemObject)
1726    
1727 root 1.14 #BEGIN:mem
1728    
1729     void
1730 root 1.22 type (OpenCL::Memory self)
1731 root 1.14 PPCODE:
1732     cl_mem_object_type value [1];
1733 root 1.22 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_TYPE, sizeof (value), value, 0));
1734 root 1.14 EXTEND (SP, 1);
1735     const int i = 0;
1736     PUSHs (sv_2mortal (newSViv (value [i])));
1737    
1738     void
1739 root 1.22 flags (OpenCL::Memory self)
1740 root 1.14 PPCODE:
1741     cl_mem_flags value [1];
1742 root 1.22 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_FLAGS, sizeof (value), value, 0));
1743 root 1.14 EXTEND (SP, 1);
1744     const int i = 0;
1745     PUSHs (sv_2mortal (newSViv (value [i])));
1746    
1747     void
1748 root 1.22 size (OpenCL::Memory self)
1749 root 1.16 ALIAS:
1750     size = CL_MEM_SIZE
1751     offset = CL_MEM_OFFSET
1752 root 1.14 PPCODE:
1753     size_t value [1];
1754 root 1.22 NEED_SUCCESS (GetMemObjectInfo, (self, ix, sizeof (value), value, 0));
1755 root 1.14 EXTEND (SP, 1);
1756     const int i = 0;
1757     PUSHs (sv_2mortal (newSVuv (value [i])));
1758    
1759     void
1760 root 1.22 host_ptr (OpenCL::Memory self)
1761 root 1.14 PPCODE:
1762     void * value [1];
1763 root 1.22 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_HOST_PTR, sizeof (value), value, 0));
1764 root 1.14 EXTEND (SP, 1);
1765     const int i = 0;
1766     PUSHs (sv_2mortal (newSVuv ((IV)(intptr_t)value [i])));
1767    
1768     void
1769 root 1.22 map_count (OpenCL::Memory self)
1770 root 1.16 ALIAS:
1771     map_count = CL_MEM_MAP_COUNT
1772     reference_count = CL_MEM_REFERENCE_COUNT
1773 root 1.14 PPCODE:
1774     cl_uint value [1];
1775 root 1.22 NEED_SUCCESS (GetMemObjectInfo, (self, ix, sizeof (value), value, 0));
1776 root 1.14 EXTEND (SP, 1);
1777     const int i = 0;
1778     PUSHs (sv_2mortal (newSVuv (value [i])));
1779    
1780     void
1781 root 1.22 context (OpenCL::Memory self)
1782 root 1.14 PPCODE:
1783     cl_context value [1];
1784 root 1.22 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_CONTEXT, sizeof (value), value, 0));
1785 root 1.14 EXTEND (SP, 1);
1786     const int i = 0;
1787     {
1788     NEED_SUCCESS (RetainContext, (value [i]));
1789 root 1.51 PUSH_CLOBJ ("OpenCL::Context", value [i]);
1790 root 1.14 }
1791    
1792     void
1793 root 1.22 associated_memobject (OpenCL::Memory self)
1794 root 1.14 PPCODE:
1795     cl_mem value [1];
1796 root 1.22 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_ASSOCIATED_MEMOBJECT, sizeof (value), value, 0));
1797 root 1.14 EXTEND (SP, 1);
1798     const int i = 0;
1799     {
1800     NEED_SUCCESS (RetainMemObject, (value [i]));
1801 root 1.51 PUSH_CLOBJ ("OpenCL::Memory", value [i]);
1802 root 1.14 }
1803    
1804     #END:mem
1805    
1806 root 1.26 #if cl_apple_gl_sharing || cl_khr_gl_sharing
1807    
1808     void
1809     gl_object_info (OpenCL::Memory self)
1810     PPCODE:
1811     cl_gl_object_type type;
1812     cl_GLuint name;
1813 root 1.31 NEED_SUCCESS (GetGLObjectInfo, (self, &type, &name));
1814 root 1.26 EXTEND (SP, 2);
1815     PUSHs (sv_2mortal (newSVuv (type)));
1816     PUSHs (sv_2mortal (newSVuv (name)));
1817    
1818     #endif
1819    
1820 root 1.18 MODULE = OpenCL PACKAGE = OpenCL::BufferObj
1821    
1822     void
1823 root 1.22 sub_buffer_region (OpenCL::BufferObj self, cl_mem_flags flags, size_t origin, size_t size)
1824 root 1.18 PPCODE:
1825     if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_ALLOC_HOST_PTR))
1826     croak ("clCreateSubBuffer: cannot use/copy/alloc host ptr, doesn't make sense, check your flags!");
1827    
1828     cl_buffer_region crdata = { origin, size };
1829    
1830 root 1.22 NEED_SUCCESS_ARG (cl_mem mem, CreateSubBuffer, (self, flags, CL_BUFFER_CREATE_TYPE_REGION, &crdata, &res));
1831 root 1.51 XPUSH_CLOBJ ("OpenCL::Buffer", mem);
1832 root 1.18
1833 root 1.13 MODULE = OpenCL PACKAGE = OpenCL::Image
1834    
1835     void
1836 root 1.22 image_info (OpenCL::Image self, cl_image_info name)
1837 root 1.13 PPCODE:
1838     INFO (Image)
1839    
1840 root 1.49 void
1841     format (OpenCL::Image self)
1842     PPCODE:
1843     cl_image_format format;
1844     NEED_SUCCESS (GetImageInfo, (self, CL_IMAGE_FORMAT, sizeof (format), &format, 0));
1845     EXTEND (SP, 2);
1846     PUSHs (sv_2mortal (newSVuv (format.image_channel_order)));
1847     PUSHs (sv_2mortal (newSVuv (format.image_channel_data_type)));
1848    
1849 root 1.14 #BEGIN:image
1850    
1851     void
1852 root 1.22 element_size (OpenCL::Image self)
1853 root 1.16 ALIAS:
1854     element_size = CL_IMAGE_ELEMENT_SIZE
1855     row_pitch = CL_IMAGE_ROW_PITCH
1856     slice_pitch = CL_IMAGE_SLICE_PITCH
1857     width = CL_IMAGE_WIDTH
1858     height = CL_IMAGE_HEIGHT
1859     depth = CL_IMAGE_DEPTH
1860 root 1.14 PPCODE:
1861     size_t value [1];
1862 root 1.22 NEED_SUCCESS (GetImageInfo, (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     #END:image
1868    
1869 root 1.26 #if cl_apple_gl_sharing || cl_khr_gl_sharing
1870    
1871     #BEGIN:gl_texture
1872    
1873     void
1874     target (OpenCL::Image self)
1875     PPCODE:
1876     cl_GLenum value [1];
1877 root 1.31 NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0));
1878 root 1.26 EXTEND (SP, 1);
1879     const int i = 0;
1880     PUSHs (sv_2mortal (newSVuv (value [i])));
1881    
1882     void
1883     gl_mipmap_level (OpenCL::Image self)
1884     PPCODE:
1885     cl_GLint value [1];
1886 root 1.31 NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0));
1887 root 1.26 EXTEND (SP, 1);
1888     const int i = 0;
1889     PUSHs (sv_2mortal (newSViv (value [i])));
1890    
1891     #END:gl_texture
1892    
1893     #endif
1894    
1895 root 1.2 MODULE = OpenCL PACKAGE = OpenCL::Sampler
1896    
1897     void
1898 root 1.22 DESTROY (OpenCL::Sampler self)
1899 root 1.2 CODE:
1900 root 1.22 clReleaseSampler (self);
1901 root 1.2
1902     void
1903 root 1.22 info (OpenCL::Sampler self, cl_sampler_info name)
1904 root 1.2 PPCODE:
1905     INFO (Sampler)
1906    
1907 root 1.14 #BEGIN:sampler
1908    
1909     void
1910 root 1.22 reference_count (OpenCL::Sampler self)
1911 root 1.14 PPCODE:
1912     cl_uint value [1];
1913 root 1.22 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_REFERENCE_COUNT, sizeof (value), value, 0));
1914 root 1.14 EXTEND (SP, 1);
1915     const int i = 0;
1916     PUSHs (sv_2mortal (newSVuv (value [i])));
1917    
1918     void
1919 root 1.22 context (OpenCL::Sampler self)
1920 root 1.14 PPCODE:
1921     cl_context value [1];
1922 root 1.22 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_CONTEXT, sizeof (value), value, 0));
1923 root 1.14 EXTEND (SP, 1);
1924     const int i = 0;
1925     {
1926     NEED_SUCCESS (RetainContext, (value [i]));
1927 root 1.51 PUSH_CLOBJ ("OpenCL::Context", value [i]);
1928 root 1.14 }
1929    
1930     void
1931 root 1.22 normalized_coords (OpenCL::Sampler self)
1932 root 1.14 PPCODE:
1933     cl_addressing_mode value [1];
1934 root 1.22 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_NORMALIZED_COORDS, sizeof (value), value, 0));
1935 root 1.14 EXTEND (SP, 1);
1936     const int i = 0;
1937     PUSHs (sv_2mortal (newSViv (value [i])));
1938    
1939     void
1940 root 1.22 addressing_mode (OpenCL::Sampler self)
1941 root 1.14 PPCODE:
1942     cl_filter_mode value [1];
1943 root 1.22 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_ADDRESSING_MODE, sizeof (value), value, 0));
1944 root 1.14 EXTEND (SP, 1);
1945     const int i = 0;
1946     PUSHs (sv_2mortal (newSViv (value [i])));
1947    
1948     void
1949 root 1.22 filter_mode (OpenCL::Sampler self)
1950 root 1.14 PPCODE:
1951     cl_bool value [1];
1952 root 1.22 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_FILTER_MODE, sizeof (value), value, 0));
1953 root 1.14 EXTEND (SP, 1);
1954     const int i = 0;
1955     PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no));
1956    
1957     #END:sampler
1958    
1959 root 1.2 MODULE = OpenCL PACKAGE = OpenCL::Program
1960    
1961     void
1962 root 1.22 DESTROY (OpenCL::Program self)
1963 root 1.2 CODE:
1964 root 1.22 clReleaseProgram (self);
1965 root 1.2
1966     void
1967 root 1.51 build (OpenCL::Program self, SV *devices = &PL_sv_undef, SV *options = &PL_sv_undef, SV *notify = &PL_sv_undef)
1968     ALIAS:
1969     build_async = 1
1970 root 1.2 CODE:
1971 root 1.51 void (CL_CALLBACK *pfn_notify)(cl_program program, void *user_data) = 0;
1972     void *user_data = 0;
1973     cl_uint num_devices = 0;
1974     cl_device_id *device_list = 0;
1975    
1976     if (SvOK (devices))
1977     {
1978     if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV)
1979     croak ("clProgramBuild: devices must be undef or an array of OpenCL::Device objects.");
1980    
1981     AV *av = (AV *)SvRV (devices);
1982     num_devices = av_len (av) + 1;
1983    
1984     if (num_devices)
1985     {
1986     device_list = tmpbuf (sizeof (*device_list) * num_devices);
1987     int count;
1988     for (count = 0; count < num_devices; ++count)
1989     device_list [count] = SvCLOBJ ("clBuildProgram", "devices", *av_fetch (av, count, 1), "OpenCL::Device");
1990     }
1991     }
1992    
1993     if (SvOK (notify))
1994     {
1995     NEED_SUCCESS (RetainProgram, (self));
1996     pfn_notify = eq_program_notify;
1997     user_data = SvREFCNT_inc (s_get_cv (notify));
1998     }
1999    
2000     if (ix)
2001     build_program_async (self, num_devices, device_list, SvPVbyte_nolen (options), user_data);
2002     else
2003     NEED_SUCCESS (BuildProgram, (self, num_devices, device_list, SvPVbyte_nolen (options), pfn_notify, user_data));
2004 root 1.2
2005     void
2006 root 1.22 build_info (OpenCL::Program self, OpenCL::Device device, cl_program_build_info name)
2007 root 1.2 PPCODE:
2008 root 1.23 size_t size;
2009     NEED_SUCCESS (GetProgramBuildInfo, (self, device, name, 0, 0, &size));
2010 root 1.10 SV *sv = sv_2mortal (newSV (size));
2011 root 1.1 SvUPGRADE (sv, SVt_PV);
2012     SvPOK_only (sv);
2013     SvCUR_set (sv, size);
2014 root 1.23 NEED_SUCCESS (GetProgramBuildInfo, (self, device, name, size, SvPVX (sv), 0));
2015 root 1.1 XPUSHs (sv);
2016    
2017 root 1.14 #BEGIN:program_build
2018    
2019     void
2020 root 1.22 build_status (OpenCL::Program self, OpenCL::Device device)
2021 root 1.14 PPCODE:
2022     cl_build_status value [1];
2023 root 1.22 NEED_SUCCESS (GetProgramBuildInfo, (self, device, CL_PROGRAM_BUILD_STATUS, sizeof (value), value, 0));
2024 root 1.14 EXTEND (SP, 1);
2025     const int i = 0;
2026     PUSHs (sv_2mortal (newSViv (value [i])));
2027    
2028     void
2029 root 1.22 build_options (OpenCL::Program self, OpenCL::Device device)
2030 root 1.16 ALIAS:
2031     build_options = CL_PROGRAM_BUILD_OPTIONS
2032     build_log = CL_PROGRAM_BUILD_LOG
2033 root 1.14 PPCODE:
2034     size_t size;
2035 root 1.22 NEED_SUCCESS (GetProgramBuildInfo, (self, device, ix, 0, 0, &size));
2036 root 1.14 char *value = tmpbuf (size);
2037 root 1.22 NEED_SUCCESS (GetProgramBuildInfo, (self, device, ix, size, value, 0));
2038 root 1.16 EXTEND (SP, 1);
2039     const int i = 0;
2040 root 1.14 PUSHs (sv_2mortal (newSVpv (value, 0)));
2041    
2042     #END:program_build
2043    
2044 root 1.2 void
2045     kernel (OpenCL::Program program, SV *function)
2046     PPCODE:
2047 root 1.23 NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res));
2048 root 1.51 XPUSH_CLOBJ ("OpenCL::Kernel", kernel);
2049 root 1.2
2050 root 1.14 void
2051 root 1.47 kernels_in_program (OpenCL::Program program)
2052     PPCODE:
2053     cl_uint num_kernels;
2054     NEED_SUCCESS (CreateKernelsInProgram, (program, 0, 0, &num_kernels));
2055     cl_kernel *kernels = tmpbuf (sizeof (cl_kernel) * num_kernels);
2056     NEED_SUCCESS (CreateKernelsInProgram, (program, num_kernels, kernels, 0));
2057    
2058     int i;
2059     EXTEND (SP, num_kernels);
2060     for (i = 0; i < num_kernels; ++i)
2061 root 1.51 PUSH_CLOBJ ("OpenCL::Kernel", kernels [i]);
2062 root 1.47
2063     void
2064 root 1.22 info (OpenCL::Program self, cl_program_info name)
2065 root 1.14 PPCODE:
2066     INFO (Program)
2067    
2068 root 1.15 void
2069 root 1.22 binaries (OpenCL::Program self)
2070 root 1.15 PPCODE:
2071     cl_uint n, i;
2072     size_t size;
2073    
2074 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_NUM_DEVICES , sizeof (n) , &n , 0));
2075 root 1.15 if (!n) XSRETURN_EMPTY;
2076    
2077     size_t *sizes = tmpbuf (sizeof (*sizes) * n);
2078 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARY_SIZES, sizeof (*sizes) * n, sizes, &size));
2079 root 1.15 if (size != sizeof (*sizes) * n) XSRETURN_EMPTY;
2080     unsigned char **ptrs = tmpbuf (sizeof (*ptrs) * n);
2081    
2082     EXTEND (SP, n);
2083     for (i = 0; i < n; ++i)
2084     {
2085     SV *sv = sv_2mortal (newSV (sizes [i]));
2086     SvUPGRADE (sv, SVt_PV);
2087     SvPOK_only (sv);
2088     SvCUR_set (sv, sizes [i]);
2089 root 1.37 ptrs [i] = (void *)SvPVX (sv);
2090 root 1.15 PUSHs (sv);
2091     }
2092    
2093 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size));
2094 root 1.15 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY;
2095    
2096 root 1.14 #BEGIN:program
2097    
2098     void
2099 root 1.22 reference_count (OpenCL::Program self)
2100 root 1.16 ALIAS:
2101     reference_count = CL_PROGRAM_REFERENCE_COUNT
2102     num_devices = CL_PROGRAM_NUM_DEVICES
2103 root 1.14 PPCODE:
2104     cl_uint value [1];
2105 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, ix, sizeof (value), value, 0));
2106 root 1.14 EXTEND (SP, 1);
2107     const int i = 0;
2108     PUSHs (sv_2mortal (newSVuv (value [i])));
2109    
2110     void
2111 root 1.22 context (OpenCL::Program self)
2112 root 1.14 PPCODE:
2113     cl_context value [1];
2114 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_CONTEXT, sizeof (value), value, 0));
2115 root 1.14 EXTEND (SP, 1);
2116     const int i = 0;
2117     {
2118     NEED_SUCCESS (RetainContext, (value [i]));
2119 root 1.51 PUSH_CLOBJ ("OpenCL::Context", value [i]);
2120 root 1.14 }
2121    
2122     void
2123 root 1.22 devices (OpenCL::Program self)
2124 root 1.14 PPCODE:
2125     size_t size;
2126 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_DEVICES, 0, 0, &size));
2127 root 1.14 cl_device_id *value = tmpbuf (size);
2128 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_DEVICES, size, value, 0));
2129 root 1.15 int i, n = size / sizeof (*value);
2130 root 1.14 EXTEND (SP, n);
2131     for (i = 0; i < n; ++i)
2132     {
2133 root 1.51 PUSH_CLOBJ ("OpenCL::Device", value [i]);
2134 root 1.14 }
2135    
2136     void
2137 root 1.22 source (OpenCL::Program self)
2138 root 1.14 PPCODE:
2139     size_t size;
2140 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_SOURCE, 0, 0, &size));
2141 root 1.14 char *value = tmpbuf (size);
2142 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_SOURCE, size, value, 0));
2143 root 1.16 EXTEND (SP, 1);
2144     const int i = 0;
2145 root 1.14 PUSHs (sv_2mortal (newSVpv (value, 0)));
2146    
2147     void
2148 root 1.22 binary_sizes (OpenCL::Program self)
2149 root 1.14 PPCODE:
2150     size_t size;
2151 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARY_SIZES, 0, 0, &size));
2152 root 1.14 size_t *value = tmpbuf (size);
2153 root 1.22 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARY_SIZES, size, value, 0));
2154 root 1.15 int i, n = size / sizeof (*value);
2155 root 1.14 EXTEND (SP, n);
2156     for (i = 0; i < n; ++i)
2157     PUSHs (sv_2mortal (newSVuv (value [i])));
2158    
2159     #END:program
2160    
2161 root 1.2 MODULE = OpenCL PACKAGE = OpenCL::Kernel
2162    
2163     void
2164 root 1.22 DESTROY (OpenCL::Kernel self)
2165 root 1.2 CODE:
2166 root 1.22 clReleaseKernel (self);
2167 root 1.2
2168     void
2169 root 1.56 setf (OpenCL::Kernel self, const char *format, ...)
2170     CODE:
2171     int i;
2172     for (i = 2; ; ++i)
2173     {
2174     while (*format == ' ')
2175     ++format;
2176    
2177     char type = *format++;
2178    
2179     if (!type)
2180     break;
2181    
2182     if (i >= items)
2183     croak ("OpenCL::Kernel::setf format string too long (not enough arguments)");
2184    
2185     SV *sv = ST (i);
2186    
2187     union
2188     {
2189     cl_char cc; cl_uchar cC; cl_short cs; cl_ushort cS;
2190     cl_int ci; cl_uint cI; cl_long cl; cl_ulong cL;
2191     cl_half ch; cl_float cf; cl_double cd;
2192     cl_mem cm;
2193     cl_sampler ca;
2194     size_t cz;
2195     cl_event ce;
2196     } arg;
2197     size_t size;
2198    
2199     switch (type)
2200     {
2201     case 'c': arg.cc = SvIV (sv); size = sizeof (arg.cc); break;
2202     case 'C': arg.cC = SvUV (sv); size = sizeof (arg.cC); break;
2203     case 's': arg.cs = SvIV (sv); size = sizeof (arg.cs); break;
2204     case 'S': arg.cS = SvUV (sv); size = sizeof (arg.cS); break;
2205     case 'i': arg.ci = SvIV (sv); size = sizeof (arg.ci); break;
2206     case 'I': arg.cI = SvUV (sv); size = sizeof (arg.cI); break;
2207     case 'l': arg.cl = SvIV (sv); size = sizeof (arg.cl); break;
2208     case 'L': arg.cL = SvUV (sv); size = sizeof (arg.cL); break;
2209    
2210     case 'h': arg.ch = SvUV (sv); size = sizeof (arg.ch); break;
2211     case 'f': arg.cf = SvNV (sv); size = sizeof (arg.cf); break;
2212     case 'd': arg.cd = SvNV (sv); size = sizeof (arg.cd); break;
2213     case 'z': arg.cz = SvUV (sv); size = sizeof (arg.cz); break;
2214    
2215     case 'm': arg.cm = SvCLOBJ ("OpenCL::Kernel::setf", "m", sv, "OpenCL::Memory" ); size = sizeof (arg.cm); break;
2216     case 'a': arg.ca = SvCLOBJ ("OpenCL::Kernel::setf", "a", sv, "OpenCL::Sampler"); size = sizeof (arg.ca); break;
2217     case 'e': arg.ca = SvCLOBJ ("OpenCL::Kernel::setf", "e", sv, "OpenCL::Event" ); size = sizeof (arg.ce); break;
2218    
2219     default:
2220     croak ("OpenCL::Kernel::setf format character '%c' not supported", type);
2221     }
2222    
2223     clSetKernelArg (self, i - 2, size, &arg);
2224     }
2225    
2226     if (i != items)
2227     croak ("OpenCL::Kernel::setf format string too short (too many arguments)");
2228    
2229     void
2230 root 1.22 set_char (OpenCL::Kernel self, cl_uint idx, cl_char value)
2231 root 1.3 CODE:
2232 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
2233 root 1.3
2234     void
2235 root 1.22 set_uchar (OpenCL::Kernel self, cl_uint idx, cl_uchar value)
2236 root 1.3 CODE:
2237 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
2238 root 1.3
2239     void
2240 root 1.22 set_short (OpenCL::Kernel self, cl_uint idx, cl_short value)
2241 root 1.3 CODE:
2242 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
2243 root 1.3
2244     void
2245 root 1.22 set_ushort (OpenCL::Kernel self, cl_uint idx, cl_ushort value)
2246 root 1.3 CODE:
2247 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
2248 root 1.3
2249     void
2250 root 1.22 set_int (OpenCL::Kernel self, cl_uint idx, cl_int value)
2251 root 1.3 CODE:
2252 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
2253 root 1.3
2254     void
2255 root 1.22 set_uint (OpenCL::Kernel self, cl_uint idx, cl_uint value)
2256 root 1.3 CODE:
2257 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
2258 root 1.3
2259     void
2260 root 1.22 set_long (OpenCL::Kernel self, cl_uint idx, cl_long value)
2261 root 1.3 CODE:
2262 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
2263 root 1.3
2264     void
2265 root 1.22 set_ulong (OpenCL::Kernel self, cl_uint idx, cl_ulong value)
2266 root 1.3 CODE:
2267 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
2268 root 1.3
2269     void
2270 root 1.22 set_half (OpenCL::Kernel self, cl_uint idx, cl_half value)
2271 root 1.3 CODE:
2272 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
2273 root 1.3
2274     void
2275 root 1.22 set_float (OpenCL::Kernel self, cl_uint idx, cl_float value)
2276 root 1.3 CODE:
2277 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
2278 root 1.3
2279     void
2280 root 1.22 set_double (OpenCL::Kernel self, cl_uint idx, cl_double value)
2281 root 1.5 CODE:
2282 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
2283 root 1.5
2284     void
2285 root 1.22 set_memory (OpenCL::Kernel self, cl_uint idx, OpenCL::Memory_ornull value)
2286 root 1.3 CODE:
2287 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
2288 root 1.3
2289     void
2290 root 1.22 set_buffer (OpenCL::Kernel self, cl_uint idx, OpenCL::Buffer_ornull value)
2291 root 1.3 CODE:
2292 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
2293 root 1.3
2294     void
2295 root 1.54 set_image (OpenCL::Kernel self, cl_uint idx, OpenCL::Image_ornull value)
2296     ALIAS:
2297     set_image2d = 0
2298     set_image3d = 0
2299 root 1.3 CODE:
2300 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
2301 root 1.3
2302     void
2303 root 1.22 set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value)
2304 root 1.3 CODE:
2305 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
2306 root 1.3
2307     void
2308 root 1.33 set_local (OpenCL::Kernel self, cl_uint idx, size_t size)
2309     CODE:
2310     clSetKernelArg (self, idx, size, 0);
2311    
2312     void
2313 root 1.22 set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value)
2314 root 1.2 CODE:
2315 root 1.22 clSetKernelArg (self, idx, sizeof (value), &value);
2316 root 1.2
2317 root 1.14 void
2318 root 1.22 info (OpenCL::Kernel self, cl_kernel_info name)
2319 root 1.14 PPCODE:
2320     INFO (Kernel)
2321    
2322     #BEGIN:kernel
2323    
2324     void
2325 root 1.22 function_name (OpenCL::Kernel self)
2326 root 1.14 PPCODE:
2327     size_t size;
2328 root 1.22 NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_FUNCTION_NAME, 0, 0, &size));
2329 root 1.14 char *value = tmpbuf (size);
2330 root 1.22 NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_FUNCTION_NAME, size, value, 0));
2331 root 1.16 EXTEND (SP, 1);
2332     const int i = 0;
2333 root 1.14 PUSHs (sv_2mortal (newSVpv (value, 0)));
2334    
2335     void
2336 root 1.22 num_args (OpenCL::Kernel self)
2337 root 1.16 ALIAS:
2338     num_args = CL_KERNEL_NUM_ARGS
2339     reference_count = CL_KERNEL_REFERENCE_COUNT
2340 root 1.14 PPCODE:
2341     cl_uint value [1];
2342 root 1.22 NEED_SUCCESS (GetKernelInfo, (self, ix, sizeof (value), value, 0));
2343 root 1.14 EXTEND (SP, 1);
2344     const int i = 0;
2345     PUSHs (sv_2mortal (newSVuv (value [i])));
2346    
2347     void
2348 root 1.22 context (OpenCL::Kernel self)
2349 root 1.14 PPCODE:
2350     cl_context value [1];
2351 root 1.22 NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_CONTEXT, sizeof (value), value, 0));
2352 root 1.14 EXTEND (SP, 1);
2353     const int i = 0;
2354     {
2355     NEED_SUCCESS (RetainContext, (value [i]));
2356 root 1.51 PUSH_CLOBJ ("OpenCL::Context", value [i]);
2357 root 1.14 }
2358    
2359     void
2360 root 1.22 program (OpenCL::Kernel self)
2361 root 1.14 PPCODE:
2362     cl_program value [1];
2363 root 1.22 NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_PROGRAM, sizeof (value), value, 0));
2364 root 1.14 EXTEND (SP, 1);
2365     const int i = 0;
2366     {
2367     NEED_SUCCESS (RetainProgram, (value [i]));
2368 root 1.51 PUSH_CLOBJ ("OpenCL::Program", value [i]);
2369 root 1.14 }
2370    
2371     #END:kernel
2372    
2373     void
2374 root 1.22 work_group_info (OpenCL::Kernel self, OpenCL::Device device, cl_kernel_work_group_info name)
2375 root 1.14 PPCODE:
2376 root 1.22 size_t size;
2377     NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, name, 0, 0, &size));
2378 root 1.14 SV *sv = sv_2mortal (newSV (size));
2379     SvUPGRADE (sv, SVt_PV);
2380     SvPOK_only (sv);
2381     SvCUR_set (sv, size);
2382 root 1.22 NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, name, size, SvPVX (sv), 0));
2383 root 1.14 XPUSHs (sv);
2384    
2385     #BEGIN:kernel_work_group
2386    
2387     void
2388 root 1.22 work_group_size (OpenCL::Kernel self, OpenCL::Device device)
2389 root 1.16 ALIAS:
2390     work_group_size = CL_KERNEL_WORK_GROUP_SIZE
2391     preferred_work_group_size_multiple = CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE
2392 root 1.14 PPCODE:
2393     size_t value [1];
2394 root 1.22 NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, ix, sizeof (value), value, 0));
2395 root 1.14 EXTEND (SP, 1);
2396     const int i = 0;
2397     PUSHs (sv_2mortal (newSVuv (value [i])));
2398    
2399     void
2400 root 1.22 compile_work_group_size (OpenCL::Kernel self, OpenCL::Device device)
2401 root 1.14 PPCODE:
2402     size_t size;
2403 root 1.22 NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, 0, 0, &size));
2404 root 1.14 size_t *value = tmpbuf (size);
2405 root 1.22 NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, size, value, 0));
2406 root 1.15 int i, n = size / sizeof (*value);
2407 root 1.14 EXTEND (SP, n);
2408     for (i = 0; i < n; ++i)
2409     PUSHs (sv_2mortal (newSVuv (value [i])));
2410    
2411     void
2412 root 1.22 local_mem_size (OpenCL::Kernel self, OpenCL::Device device)
2413 root 1.16 ALIAS:
2414     local_mem_size = CL_KERNEL_LOCAL_MEM_SIZE
2415     private_mem_size = CL_KERNEL_PRIVATE_MEM_SIZE
2416 root 1.14 PPCODE:
2417     cl_ulong value [1];
2418 root 1.22 NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, ix, sizeof (value), value, 0));
2419 root 1.14 EXTEND (SP, 1);
2420     const int i = 0;
2421     PUSHs (sv_2mortal (newSVuv (value [i])));
2422    
2423     #END:kernel_work_group
2424    
2425 root 1.2 MODULE = OpenCL PACKAGE = OpenCL::Event
2426    
2427     void
2428 root 1.22 DESTROY (OpenCL::Event self)
2429 root 1.2 CODE:
2430 root 1.22 clReleaseEvent (self);
2431 root 1.2
2432     void
2433 root 1.22 wait (OpenCL::Event self)
2434 root 1.14 CODE:
2435 root 1.22 clWaitForEvents (1, &self);
2436 root 1.14
2437     void
2438 root 1.51 cb (OpenCL::Event self, cl_int command_exec_callback_type, SV *cb)
2439     CODE:
2440     clSetEventCallback (self, command_exec_callback_type, eq_event_notify, SvREFCNT_inc (s_get_cv (cb)));
2441    
2442     void
2443 root 1.22 info (OpenCL::Event self, cl_event_info name)
2444 root 1.2 PPCODE:
2445     INFO (Event)
2446    
2447 root 1.14 #BEGIN:event
2448    
2449     void
2450 root 1.22 command_queue (OpenCL::Event self)
2451 root 1.14 PPCODE:
2452     cl_command_queue value [1];
2453 root 1.22 NEED_SUCCESS (GetEventInfo, (self, CL_EVENT_COMMAND_QUEUE, sizeof (value), value, 0));
2454 root 1.14 EXTEND (SP, 1);
2455     const int i = 0;
2456     {
2457     NEED_SUCCESS (RetainCommandQueue, (value [i]));
2458 root 1.51 PUSH_CLOBJ ("OpenCL::Queue", value [i]);
2459 root 1.14 }
2460    
2461     void
2462 root 1.22 command_type (OpenCL::Event self)
2463 root 1.14 PPCODE:
2464     cl_command_type value [1];
2465 root 1.22 NEED_SUCCESS (GetEventInfo, (self, CL_EVENT_COMMAND_TYPE, sizeof (value), value, 0));
2466 root 1.14 EXTEND (SP, 1);
2467     const int i = 0;
2468     PUSHs (sv_2mortal (newSVuv (value [i])));
2469    
2470     void
2471 root 1.22 reference_count (OpenCL::Event self)
2472 root 1.16 ALIAS:
2473     reference_count = CL_EVENT_REFERENCE_COUNT
2474     command_execution_status = CL_EVENT_COMMAND_EXECUTION_STATUS
2475 root 1.14 PPCODE:
2476     cl_uint value [1];
2477 root 1.22 NEED_SUCCESS (GetEventInfo, (self, ix, sizeof (value), value, 0));
2478 root 1.14 EXTEND (SP, 1);
2479     const int i = 0;
2480     PUSHs (sv_2mortal (newSVuv (value [i])));
2481    
2482     void
2483 root 1.22 context (OpenCL::Event self)
2484 root 1.14 PPCODE:
2485     cl_context value [1];
2486 root 1.22 NEED_SUCCESS (GetEventInfo, (self, CL_EVENT_CONTEXT, sizeof (value), value, 0));
2487 root 1.14 EXTEND (SP, 1);
2488     const int i = 0;
2489     {
2490     NEED_SUCCESS (RetainContext, (value [i]));
2491 root 1.51 PUSH_CLOBJ ("OpenCL::Context", value [i]);
2492 root 1.14 }
2493    
2494     #END:event
2495    
2496 root 1.2 void
2497 root 1.22 profiling_info (OpenCL::Event self, cl_profiling_info name)
2498 root 1.13 PPCODE:
2499     INFO (EventProfiling)
2500    
2501 root 1.14 #BEGIN:profiling
2502    
2503 root 1.13 void
2504 root 1.22 profiling_command_queued (OpenCL::Event self)
2505 root 1.16 ALIAS:
2506     profiling_command_queued = CL_PROFILING_COMMAND_QUEUED
2507     profiling_command_submit = CL_PROFILING_COMMAND_SUBMIT
2508     profiling_command_start = CL_PROFILING_COMMAND_START
2509     profiling_command_end = CL_PROFILING_COMMAND_END
2510 root 1.14 PPCODE:
2511     cl_ulong value [1];
2512 root 1.22 NEED_SUCCESS (GetEventProfilingInfo, (self, ix, sizeof (value), value, 0));
2513 root 1.14 EXTEND (SP, 1);
2514     const int i = 0;
2515     PUSHs (sv_2mortal (newSVuv (value [i])));
2516    
2517     #END:profiling
2518 root 1.2
2519 root 1.5 MODULE = OpenCL PACKAGE = OpenCL::UserEvent
2520    
2521     void
2522 root 1.22 set_status (OpenCL::UserEvent self, cl_int execution_status)
2523 root 1.5 CODE:
2524 root 1.22 clSetUserEventStatus (self, execution_status);
2525 root 1.5