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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.18 by root, Wed Nov 23 03:02:38 2011 UTC vs.
Revision 1.72 by root, Sat May 5 12:54:04 2012 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5#include "ecb.h"//D
6
7#define X_STACKSIZE sizeof (void *) * 512 * 1024 // 2-4mb should be enough, really
8#include "xthread.h"
9#include "schmorp.h"
10
11#ifdef I_DLFCN
12 #include <dlfcn.h>
13#endif
14
15// how stupid is that, the 1.2 header files define CL_VERSION_1_1,
16// but then fail to define the api functions unless you ALSO define
17// this. This breaks 100% of the opencl 1.1 apps, for what reason?
18// after all, the functions are deprecated, not removed.
19// in addition, you cannot test for this in any future-proof way.
20// each time a new opencl version comes out, you need to make a new
21// release.
22#define CL_USE_DEPRECATED_OPENCL_1_2_APIS /* just guessing, you stupid idiots */
23
24#ifndef PREFER_1_1
25 #define PREFER_1_1 1
26#endif
27
28#if PREFER_1_1
29 #define CL_USE_DEPRECATED_OPENCL_1_1_APIS
30#endif
31
32#ifdef __APPLE__
33 #include <OpenCL/opencl.h>
34#else
5#include <CL/opencl.h> 35 #include <CL/opencl.h>
36#endif
37
38#ifndef CL_VERSION_1_2
39 #undef PREFER_1_1
40 #define PREFER_1_1 1
41#endif
6 42
7typedef cl_platform_id OpenCL__Platform; 43typedef cl_platform_id OpenCL__Platform;
8typedef cl_device_id OpenCL__Device; 44typedef cl_device_id OpenCL__Device;
45typedef cl_device_id OpenCL__SubDevice;
9typedef cl_context OpenCL__Context; 46typedef cl_context OpenCL__Context;
10typedef cl_command_queue OpenCL__Queue; 47typedef cl_command_queue OpenCL__Queue;
11typedef cl_mem OpenCL__Memory; 48typedef cl_mem OpenCL__Memory;
12typedef cl_mem OpenCL__Buffer; 49typedef cl_mem OpenCL__Buffer;
13typedef cl_mem OpenCL__BufferObj; 50typedef cl_mem OpenCL__BufferObj;
14typedef cl_mem OpenCL__Image; 51typedef cl_mem OpenCL__Image;
15typedef cl_mem OpenCL__Image2D;
16typedef cl_mem OpenCL__Image3D;
17typedef cl_mem OpenCL__Memory_ornull; 52typedef cl_mem OpenCL__Memory_ornull;
18typedef cl_mem OpenCL__Buffer_ornull; 53typedef cl_mem OpenCL__Buffer_ornull;
19typedef cl_mem OpenCL__Image_ornull; 54typedef cl_mem OpenCL__Image_ornull;
20typedef cl_mem OpenCL__Image2D_ornull;
21typedef cl_mem OpenCL__Image3D_ornull;
22typedef cl_sampler OpenCL__Sampler; 55typedef cl_sampler OpenCL__Sampler;
23typedef cl_program OpenCL__Program; 56typedef cl_program OpenCL__Program;
24typedef cl_kernel OpenCL__Kernel; 57typedef cl_kernel OpenCL__Kernel;
25typedef cl_event OpenCL__Event; 58typedef cl_event OpenCL__Event;
26typedef cl_event OpenCL__UserEvent; 59typedef cl_event OpenCL__UserEvent;
27 60
28typedef SV *FUTURE; 61typedef struct mapped * OpenCL__Mapped;
62
63static HV
64 *stash_platform,
65 *stash_device,
66 *stash_subdevice,
67 *stash_context,
68 *stash_queue,
69 *stash_program,
70 *stash_kernel,
71 *stash_sampler,
72 *stash_event,
73 *stash_userevent,
74 *stash_memory,
75 *stash_buffer,
76 *stash_bufferobj,
77 *stash_image,
78 *stash_image1d,
79 *stash_image1darray,
80 *stash_image1dbuffer,
81 *stash_image2d,
82 *stash_image2darray,
83 *stash_image3d,
84 *stash_mapped,
85 *stash_mappedbuffer,
86 *stash_mappedimage;
29 87
30/*****************************************************************************/ 88/*****************************************************************************/
31 89
90// name must include a leading underscore
91// all of this horrors would be unneceesary if somebody wrote a proper OpenGL module
92// for perl. doh.
93static void *
94glsym (const char *name)
95{
96 void *fun = 0;
97
98 #if defined I_DLFCN && defined RTLD_DEFAULT
99 fun = dlsym (RTLD_DEFAULT, name + 1);
100 if (!fun) fun = dlsym (RTLD_DEFAULT, name);
101
102 if (!fun)
103 {
104 static void *libgl;
105 static const char *glso[] = {
106 "libGL.so.1",
107 "libGL.so.3",
108 "libGL.so.4.0",
109 "libGL.so",
110 "/usr/lib/libGL.so",
111 "/usr/X11R6/lib/libGL.1.dylib"
112 };
113 int i;
114
115 for (i = 0; !libgl && i < sizeof (glso) / sizeof (glso [0]); ++i)
116 {
117 libgl = dlopen (glso [i], RTLD_LAZY);
118 if (libgl)
119 break;
120 }
121
122 if (libgl)
123 {
124 fun = dlsym (libgl, name + 1);
125 if (!fun) fun = dlsym (libgl, name);
126 }
127 }
128 #endif
129
130 return fun;
131}
132
133/*****************************************************************************/
134
32/* up to two temporary buffers */ 135/* up to two temporary buffers */
33static void * 136static void * ecb_noinline
34tmpbuf (size_t size) 137tmpbuf (size_t size)
35{ 138{
139 enum { buffers = 4 };
36 static int idx; 140 static int idx;
37 static void *buf [2]; 141 static void *buf [buffers];
38 static size_t len [2]; 142 static size_t len [buffers];
39 143
40 idx ^= 1; 144 idx = (idx + 1) % buffers;
41 145
42 if (len [idx] < size) 146 if (len [idx] < size)
43 { 147 {
44 free (buf [idx]); 148 free (buf [idx]);
45 len [idx] = ((size + 31) & ~4095) + 4096 - 32; 149 len [idx] = ((size + 31) & ~4095) + 4096 - 32;
46 buf [idx] = malloc (len [idx]); 150 buf [idx] = malloc (len [idx]);
47 } 151 }
48 152
49 return buf [idx]; 153 return buf [idx];
154}
155
156static const char * ecb_noinline
157cv_get_name (CV *cv)
158{
159 static char fullname [256];
160
161 GV *gv = CvGV (cv); // gv better be nonzero
162
163 HV *stash = GvSTASH (gv);
164 const char *hvname = HvNAME_get (stash); // stash also better be nonzero
165 const char *gvname = GvNAME (gv);
166
167 snprintf (fullname, sizeof (fullname), "%s::%s", hvname, gvname);
168 return fullname;
50} 169}
51 170
52/*****************************************************************************/ 171/*****************************************************************************/
53 172
54typedef struct 173typedef struct
113 if (res) \ 232 if (res) \
114 FAIL (name); 233 FAIL (name);
115 234
116/*****************************************************************************/ 235/*****************************************************************************/
117 236
118#define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr)
119#define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr))
120
121static void * 237static SV *
238new_clobj (HV *stash, IV id)
239{
240 return sv_2mortal (sv_bless (newRV_noinc (newSViv (id)), stash));
241}
242
243#define PUSH_CLOBJ(stash,id) PUSHs (new_clobj ((stash), (IV)(id)))
244#define XPUSH_CLOBJ(stash,id) XPUSHs (new_clobj ((stash), (IV)(id)))
245
246/* cl objects are either \$iv, or [$iv, ...] */
247/* they can be upgraded at runtime to the array form */
248static void * ecb_noinline
122SvPTROBJ (const char *func, const char *svname, SV *sv, const char *pkg) 249SvCLOBJ (CV *cv, const char *svname, SV *sv, const char *pkg)
123{ 250{
251 // sv_derived_from is quite slow :(
124 if (SvROK (sv) && sv_derived_from (sv, pkg)) 252 if (SvROK (sv) && sv_derived_from (sv, pkg))
125 return (void *)SvIV (SvRV (sv)); 253 return (void *)SvIV (SvRV (sv));
126 254
127 croak ("%s: %s is not of type %s", func, svname, pkg); 255 croak ("%s: %s is not of type %s", cv_get_name (cv), svname, pkg);
256}
257
258// the "no-inherit" version of the above
259static void * ecb_noinline
260SvCLOBJ_ni (CV *cv, const char *svname, SV *sv, HV *stash)
261{
262 if (SvROK (sv) && SvSTASH (SvRV (sv)) == stash)
263 return (void *)SvIV (SvRV (sv));
264
265 croak ("%s: %s is not of type %s", cv_get_name (cv), svname, HvNAME (stash));
128} 266}
129 267
130/*****************************************************************************/ 268/*****************************************************************************/
269
270static cl_context_properties * ecb_noinline
271SvCONTEXTPROPERTIES (CV *cv, const char *svname, SV *sv, cl_context_properties *extra, int extracount)
272{
273 if (!sv || !SvOK (sv))
274 if (extra)
275 sv = sv_2mortal (newRV_noinc ((SV *)newAV ())); // slow, but rarely used hopefully
276 else
277 return 0;
278
279 if (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVAV)
280 {
281 AV *av = (AV *)SvRV (sv);
282 int i, len = av_len (av) + 1;
283 cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1));
284 cl_context_properties *l = p;
285
286 if (len & 1)
287 croak ("%s: %s is not a property list (must contain an even number of elements)", cv_get_name (cv), svname);
288
289 while (extracount--)
290 *l++ = *extra++;
291
292 for (i = 0; i < len; i += 2)
293 {
294 cl_context_properties t = SvIV (*av_fetch (av, i , 0));
295 SV *p_sv = *av_fetch (av, i + 1, 0);
296 cl_context_properties v = SvIV (p_sv); // code below can override
297
298 switch (t)
299 {
300 case CL_CONTEXT_PLATFORM:
301 if (SvROK (p_sv))
302 v = (cl_context_properties)SvCLOBJ (cv, svname, p_sv, "OpenCL::Platform");
303 break;
304
305 case CL_GLX_DISPLAY_KHR:
306 if (!SvOK (p_sv))
307 {
308 void *func = glsym ("_glXGetCurrentDisplay");
309 if (func)
310 v = (cl_context_properties)((void *(*)(void))func)();
311 }
312 break;
313
314 case CL_GL_CONTEXT_KHR:
315 if (!SvOK (p_sv))
316 {
317 void *func = glsym ("_glXGetCurrentContext");
318 if (func)
319 v = (cl_context_properties)((void *(*)(void))func)();
320 }
321 break;
322
323 default:
324 /* unknown property, treat as int */
325 break;
326 }
327
328 *l++ = t;
329 *l++ = v;
330 }
331
332 *l = 0;
333
334 return p;
335 }
336
337 croak ("%s: %s is not a property list (either undef or [type => value, ...])", cv_get_name (cv), svname);
338}
339
340// parse an array of CLOBJ into a void ** array in C - works only for CLOBJs whose representation
341// is a pointer (and only on well-behaved systems).
342static void * ecb_noinline
343object_list (CV *cv, int or_undef, const char *argname, SV *arg, const char *klass, cl_uint *rcount)
344{
345 if (!SvROK (arg) || SvTYPE (SvRV (arg)) != SVt_PVAV)
346 croak ("%s: '%s' parameter must be %sa reference to an array of %s objects",
347 cv_get_name (cv), argname, or_undef ? "undef or " : "", klass);
348
349 AV *av = (AV *)SvRV (arg);
350 void **list = 0;
351 cl_uint count = av_len (av) + 1;
352
353 if (count)
354 {
355 list = tmpbuf (sizeof (*list) * count);
356 int i;
357 for (i = 0; i < count; ++i)
358 list [i] = SvCLOBJ (cv, argname, *av_fetch (av, i, 1), klass);
359 }
360
361 if (!count && !or_undef)
362 croak ("%s: '%s' must contain at least one %s object",
363 cv_get_name (cv), argname, klass);
364
365 *rcount = count;
366 return (void *)list;
367}
368
369/*****************************************************************************/
370/* callback stuff */
371
372/* default context callback, log to stderr */
373static void CL_CALLBACK
374context_default_notify (const char *msg, const void *info, size_t cb, void *data)
375{
376 fprintf (stderr, "OpenCL Context Notify: %s\n", msg);
377}
378
379typedef struct
380{
381 int free_cb;
382 void (*push)(void *data1, void *data2, void *data3);
383} eq_vtbl;
384
385typedef struct eq_item
386{
387 struct eq_item *next;
388 eq_vtbl *vtbl;
389 SV *cb;
390 void *data1, *data2, *data3;
391} eq_item;
392
393static void (*eq_signal_func)(void *signal_arg, int value);
394static void *eq_signal_arg;
395static xmutex_t eq_lock = X_MUTEX_INIT;
396static eq_item *eq_head, *eq_tail;
397
398static void ecb_noinline
399eq_enq (eq_vtbl *vtbl, SV *cb, void *data1, void *data2, void *data3)
400{
401 eq_item *item = malloc (sizeof (eq_item));
402
403 item->next = 0;
404 item->vtbl = vtbl;
405 item->cb = cb;
406 item->data1 = data1;
407 item->data2 = data2;
408 item->data3 = data3;
409
410 X_LOCK (eq_lock);
411
412 *(eq_head ? &eq_tail->next : &eq_head) = item;
413 eq_tail = item;
414
415 X_UNLOCK (eq_lock);
416
417 eq_signal_func (eq_signal_arg, 0);
418}
419
420static eq_item *
421eq_dec (void)
422{
423 eq_item *res;
424
425 X_LOCK (eq_lock);
426
427 res = eq_head;
428 if (res)
429 eq_head = res->next;
430
431 X_UNLOCK (eq_lock);
432
433 return res;
434}
435
436static void
437eq_poll (void)
438{
439 eq_item *item;
440
441 while ((item = eq_dec ()))
442 {
443 ENTER;
444 SAVETMPS;
445
446 dSP;
447 PUSHMARK (SP);
448 EXTEND (SP, 2);
449
450 if (item->vtbl->free_cb)
451 sv_2mortal (item->cb);
452
453 PUTBACK;
454 item->vtbl->push (item->data1, item->data2, item->data3);
455
456 SV *cb = item->cb;
457 free (item);
458
459 call_sv (cb, G_DISCARD | G_VOID);
460
461 FREETMPS;
462 LEAVE;
463 }
464}
465
466static void
467eq_poll_interrupt (pTHX_ void *c_arg, int value)
468{
469 eq_poll ();
470}
471
472/*****************************************************************************/
473/* context notify */
474
475static void ecb_noinline
476eq_context_push (void *data1, void *data2, void *data3)
477{
478 dSP;
479 PUSHs (sv_2mortal (newSVpv (data1, 0)));
480 PUSHs (sv_2mortal (newSVpvn (data2, (STRLEN)data3)));
481 PUTBACK;
482
483 free (data1);
484 free (data2);
485}
486
487static eq_vtbl eq_context_vtbl = { 0, eq_context_push };
488
489static void CL_CALLBACK
490eq_context_notify (const char *msg, const void *pvt, size_t cb, void *user_data)
491{
492 void *pvt_copy = malloc (cb);
493 memcpy (pvt_copy, pvt, cb);
494 eq_enq (&eq_context_vtbl, user_data, strdup (msg), pvt_copy, (void *)cb);
495}
496
497#define CONTEXT_NOTIFY_CALLBACK \
498 void (CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *) = context_default_notify; \
499 void *user_data = 0; \
500 \
501 if (SvOK (notify)) \
502 { \
503 pfn_notify = eq_context_notify; \
504 user_data = s_get_cv (notify); \
505 }
506
507static SV * ecb_noinline
508new_clobj_context (cl_context ctx, void *user_data)
509{
510 SV *sv = new_clobj (stash_context, (IV)ctx);
511
512 if (user_data)
513 sv_magicext (SvRV (sv), user_data, PERL_MAGIC_ext, 0, 0, 0);
514
515 return sv;
516}
517
518#define XPUSH_CLOBJ_CONTEXT XPUSHs (new_clobj_context (ctx, user_data));
519
520/*****************************************************************************/
521/* build/compile/link notify */
522
523static void
524eq_program_push (void *data1, void *data2, void *data3)
525{
526 dSP;
527 PUSH_CLOBJ (stash_program, data1);
528 PUTBACK;
529}
530
531static eq_vtbl eq_program_vtbl = { 1, eq_program_push };
532
533static void CL_CALLBACK
534eq_program_notify (cl_program program, void *user_data)
535{
536 clRetainProgram (program);
537
538 eq_enq (&eq_program_vtbl, user_data, (void *)program, 0, 0);
539}
540
541typedef void (CL_CALLBACK *program_callback)(cl_program program, void *user_data);
542
543static program_callback ecb_noinline
544make_program_callback (SV *notify, void **ruser_data)
545{
546 if (SvOK (notify))
547 {
548 *ruser_data = SvREFCNT_inc (s_get_cv (notify));
549 return eq_program_notify;
550 }
551 else
552 {
553 *ruser_data = 0;
554 return 0;
555 }
556}
557
558struct build_args
559{
560 cl_program program;
561 char *options;
562 void *user_data;
563 cl_uint num_devices;
564};
565
566X_THREAD_PROC (build_program_thread)
567{
568 struct build_args *arg = thr_arg;
569
570 clBuildProgram (arg->program, arg->num_devices, arg->num_devices ? (void *)(arg + 1) : 0, arg->options, 0, 0);
571
572 if (arg->user_data)
573 eq_program_notify (arg->program, arg->user_data);
574 else
575 clReleaseProgram (arg->program);
576
577 free (arg->options);
578 free (arg);
579
580 return 0;
581}
582
583static void
584build_program_async (cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, void *user_data)
585{
586 struct build_args *arg = malloc (sizeof (struct build_args) + sizeof (*device_list) * num_devices);
587
588 arg->program = program;
589 arg->options = strdup (options);
590 arg->user_data = user_data;
591 arg->num_devices = num_devices;
592 memcpy (arg + 1, device_list, sizeof (*device_list) * num_devices);
593
594 xthread_t id;
595 thread_create (&id, build_program_thread, arg);
596}
597
598/*****************************************************************************/
599/* event objects */
600
601static void
602eq_event_push (void *data1, void *data2, void *data3)
603{
604 dSP;
605 PUSH_CLOBJ (stash_event, data1);
606 PUSHs (sv_2mortal (newSViv ((IV)data2)));
607 PUTBACK;
608}
609
610static eq_vtbl eq_event_vtbl = { 1, eq_event_push };
611
612static void CL_CALLBACK
613eq_event_notify (cl_event event, cl_int event_command_exec_status, void *user_data)
614{
615 clRetainEvent (event);
616 eq_enq (&eq_event_vtbl, user_data, (void *)event, (void *)(IV)event_command_exec_status, 0);
617}
618
619/*****************************************************************************/
620/* utilities for XS code */
131 621
132static size_t 622static size_t
133img_row_pitch (cl_mem img) 623img_row_pitch (cl_mem img)
134{ 624{
135 size_t res; 625 size_t res;
136 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); 626 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0);
137 return res; 627 return res;
138} 628}
139 629
140static cl_event * 630static cl_event * ecb_noinline
141event_list (SV **items, int count) 631event_list (CV *cv, SV **items, cl_uint *rcount, cl_event extra)
142{ 632{
633 cl_uint count = *rcount;
634
635 if (count > 0x7fffffffU) // yeah, it's a hack - the caller might have underflowed
636 *rcount = count = 0;
637
638 if (!count && !extra)
639 return 0;
640
143 cl_event *list = tmpbuf (sizeof (cl_event) * count); 641 cl_event *list = tmpbuf (sizeof (cl_event) * (count + 1));
642 int i = 0;
144 643
145 while (count--) 644 while (count--)
645 if (SvOK (items [count]))
146 list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); 646 list [i++] = SvCLOBJ (cv, "wait_events", items [count], "OpenCL::Event");
147 647
648 if (extra)
649 list [i++] = extra;
650
651 *rcount = i;
652
148 return list; 653 return i ? list : 0;
149} 654}
150 655
151#define EVENT_LIST(items,count) \ 656#define EVENT_LIST(skip) \
152 cl_uint event_list_count = (count); \ 657 cl_uint event_list_count = items - (skip); \
153 cl_event *event_list_ptr = event_list (&ST (items), event_list_count) 658 cl_event *event_list_ptr = event_list (cv, &ST (skip), &event_list_count, 0)
154 659
155#define INFO(class) \ 660#define INFO(class) \
156{ \ 661{ \
157 size_t size; \ 662 size_t size; \
158 NEED_SUCCESS (Get ## class ## Info, (this, name, 0, 0, &size)); \ 663 NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \
159 SV *sv = sv_2mortal (newSV (size)); \ 664 SV *sv = sv_2mortal (newSV (size)); \
160 SvUPGRADE (sv, SVt_PV); \ 665 SvUPGRADE (sv, SVt_PV); \
161 SvPOK_only (sv); \ 666 SvPOK_only (sv); \
162 SvCUR_set (sv, size); \ 667 SvCUR_set (sv, size); \
163 NEED_SUCCESS (Get ## class ## Info, (this, name, size, SvPVX (sv), 0)); \ 668 NEED_SUCCESS (Get ## class ## Info, (self, name, size, SvPVX (sv), 0)); \
164 XPUSHs (sv); \ 669 XPUSHs (sv); \
165} 670}
166 671
672/*****************************************************************************/
673/* mapped_xxx */
674
675static OpenCL__Mapped
676SvMAPPED (SV *sv)
677{
678 // no typechecking atm., keep your fingers crossed
679 return (OpenCL__Mapped)SvMAGIC (SvRV (sv))->mg_ptr;
680}
681
682struct mapped
683{
684 cl_command_queue queue;
685 cl_mem memobj;
686 void *ptr;
687 size_t cb;
688 cl_event event;
689 size_t row_pitch;
690 size_t slice_pitch;
691};
692
693static SV *
694mapped_new (HV *stash, cl_command_queue queue, cl_mem memobj, cl_map_flags flags, void *ptr, size_t cb, cl_event ev, size_t row_pitch, size_t slice_pitch)
695{
696 SV *data = newSV (0);
697 SvUPGRADE (data, SVt_PVMG);
698
699 OpenCL__Mapped mapped;
700 New (0, mapped, 1, struct mapped);
701
702 clRetainCommandQueue (queue);
703
704 mapped->queue = queue;
705 mapped->memobj = memobj;
706 mapped->ptr = ptr;
707 mapped->cb = cb;
708 mapped->event = ev;
709 mapped->row_pitch = row_pitch;
710 mapped->slice_pitch = slice_pitch;
711
712 sv_magicext (data, 0, PERL_MAGIC_ext, 0, (char *)mapped, 0);
713
714 if (SvLEN (data))
715 Safefree (data);
716
717 SvPVX (data) = (char *)ptr;
718 SvCUR_set (data, cb);
719 SvLEN_set (data, 0);
720 SvPOK_only (data);
721
722 SV *obj = sv_2mortal (sv_bless (newRV_noinc (data), stash));
723
724 if (!(flags & CL_MAP_WRITE))
725 SvREADONLY_on (data);
726
727 return obj;
728}
729
730static void
731mapped_detach (SV *sv, OpenCL__Mapped mapped)
732{
733 SV *data = SvRV (sv);
734
735 // the next check checks both before AND after detach, where SvPVX should STILL be 0
736 if (SvPVX (data) != (char *)mapped->ptr)
737 warn ("FATAL: OpenCL memory mapped scalar changed location, detected");
738 else
739 {
740 SvREADONLY_off (data);
741 SvCUR_set (data, 0);
742 SvPVX (data) = 0;
743 SvOK_off (data);
744 }
745
746 mapped->ptr = 0;
747}
748
749static void
750mapped_unmap (CV *cv, SV *self, OpenCL__Mapped mapped, cl_command_queue queue, SV **wait_list, cl_uint event_list_count)
751{
752 cl_event *event_list_ptr = event_list (cv, wait_list, &event_list_count, mapped->event);
753 cl_event ev;
754
755 NEED_SUCCESS (EnqueueUnmapMemObject, (queue, mapped->memobj, mapped->ptr, event_list_count, event_list_ptr, &ev));
756
757 clReleaseEvent (mapped->event);
758 mapped->event = ev;
759
760 mapped_detach (self, mapped);
761}
762
763/*****************************************************************************/
764
167MODULE = OpenCL PACKAGE = OpenCL 765MODULE = OpenCL PACKAGE = OpenCL
168 766
169PROTOTYPES: ENABLE 767PROTOTYPES: ENABLE
170 768
769void
770poll ()
771 CODE:
772 eq_poll ();
773
774void
775_eq_initialise (IV func, IV arg)
776 CODE:
777 eq_signal_func = (void (*)(void *, int))func;
778 eq_signal_arg = (void*)arg;
779
171BOOT: 780BOOT:
172{ 781{
173 HV *stash = gv_stashpv ("OpenCL", 1); 782 HV *stash = gv_stashpv ("OpenCL", 1);
174 static const ivstr *civ, const_iv[] = { 783 static const ivstr *civ, const_iv[] = {
175 { sizeof (cl_char ), "SIZEOF_CHAR" }, 784 { sizeof (cl_char ), "SIZEOF_CHAR" },
176 { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, 785 { sizeof (cl_uchar ), "SIZEOF_UCHAR" },
177 { sizeof (cl_short ), "SIZEOF_SHORT" }, 786 { sizeof (cl_short ), "SIZEOF_SHORT" },
178 { sizeof (cl_ushort), "SIZEOF_USHORT" }, 787 { sizeof (cl_ushort), "SIZEOF_USHORT" },
179 { sizeof (cl_int ), "SIZEOF_INT" }, 788 { sizeof (cl_int ), "SIZEOF_INT" },
180 { sizeof (cl_uint ), "SIZEOF_UINT" }, 789 { sizeof (cl_uint ), "SIZEOF_UINT" },
181 { sizeof (cl_long ), "SIZEOF_LONG" }, 790 { sizeof (cl_long ), "SIZEOF_LONG" },
182 { sizeof (cl_ulong ), "SIZEOF_ULONG" }, 791 { sizeof (cl_ulong ), "SIZEOF_ULONG" },
183 { sizeof (cl_half ), "SIZEOF_HALF" }, 792 { sizeof (cl_half ), "SIZEOF_HALF" },
184 { sizeof (cl_float ), "SIZEOF_FLOAT" }, 793 { sizeof (cl_float ), "SIZEOF_FLOAT" },
185 { sizeof (cl_double), "SIZEOF_DOUBLE" }, 794 { sizeof (cl_double), "SIZEOF_DOUBLE" },
795 { PREFER_1_1 , "PREFER_1_1" },
186#include "constiv.h" 796#include "constiv.h"
187 }; 797 };
798
188 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 799 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
189 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 800 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
801
802 stash_platform = gv_stashpv ("OpenCL::Platform", GV_ADD);
803 stash_device = gv_stashpv ("OpenCL::Device", GV_ADD);
804 stash_subdevice = gv_stashpv ("OpenCL::SubDevice", GV_ADD);
805 stash_context = gv_stashpv ("OpenCL::Context", GV_ADD);
806 stash_queue = gv_stashpv ("OpenCL::Queue", GV_ADD);
807 stash_program = gv_stashpv ("OpenCL::Program", GV_ADD);
808 stash_kernel = gv_stashpv ("OpenCL::Kernel", GV_ADD);
809 stash_sampler = gv_stashpv ("OpenCL::Sampler", GV_ADD);
810 stash_event = gv_stashpv ("OpenCL::Event", GV_ADD);
811 stash_userevent = gv_stashpv ("OpenCL::UserEvent", GV_ADD);
812 stash_memory = gv_stashpv ("OpenCL::Memory", GV_ADD);
813 stash_buffer = gv_stashpv ("OpenCL::Buffer", GV_ADD);
814 stash_bufferobj = gv_stashpv ("OpenCL::BufferObj", GV_ADD);
815 stash_image = gv_stashpv ("OpenCL::Image", GV_ADD);
816 stash_image1d = gv_stashpv ("OpenCL::Image1D", GV_ADD);
817 stash_image1darray = gv_stashpv ("OpenCL::Image1DArray", GV_ADD);
818 stash_image1dbuffer = gv_stashpv ("OpenCL::Image1DBuffer", GV_ADD);
819 stash_image2d = gv_stashpv ("OpenCL::Image2D", GV_ADD);
820 stash_image2darray = gv_stashpv ("OpenCL::Image2DArray", GV_ADD);
821 stash_image3d = gv_stashpv ("OpenCL::Image3D", GV_ADD);
822 stash_mapped = gv_stashpv ("OpenCL::Mapped", GV_ADD);
823 stash_mappedbuffer = gv_stashpv ("OpenCL::MappedBuffer", GV_ADD);
824 stash_mappedimage = gv_stashpv ("OpenCL::MappedImage", GV_ADD);
825
826 sv_setiv (perl_get_sv ("OpenCL::POLL_FUNC", TRUE), (IV)eq_poll_interrupt);
190} 827}
191 828
192cl_int 829cl_int
193errno () 830errno ()
194 CODE: 831 CODE:
195 errno = res; 832 RETVAL = res;
833 OUTPUT:
834 RETVAL
196 835
197const char * 836const char *
198err2str (cl_int err) 837err2str (cl_int err = res)
199 838
200const char * 839const char *
201enum2str (cl_uint value) 840enum2str (cl_uint value)
202 841
203void 842void
211 list = tmpbuf (sizeof (*list) * count); 850 list = tmpbuf (sizeof (*list) * count);
212 NEED_SUCCESS (GetPlatformIDs, (count, list, 0)); 851 NEED_SUCCESS (GetPlatformIDs, (count, list, 0));
213 852
214 EXTEND (SP, count); 853 EXTEND (SP, count);
215 for (i = 0; i < count; ++i) 854 for (i = 0; i < count; ++i)
216 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); 855 PUSH_CLOBJ (stash_platform, list [i]);
217 856
218void 857void
219context_from_type (FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) 858context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef)
220 PPCODE: 859 PPCODE:
860 CONTEXT_NOTIFY_CALLBACK;
221 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (0, type, 0, 0, &res)); 861 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, pfn_notify, user_data, &res));
222 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 862 XPUSH_CLOBJ_CONTEXT;
223 863
224void 864void
225context (FUTURE properties, FUTURE devices, FUTURE notify = 0) 865context (cl_context_properties *properties, SV *devices, SV *notify = &PL_sv_undef)
226 PPCODE: 866 PPCODE:
227 /* der Gipfel der Kunst */ 867 cl_uint device_count;
868 cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count);
869
870 CONTEXT_NOTIFY_CALLBACK;
871 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (properties, device_count, device_list, pfn_notify, user_data, &res));
872 XPUSH_CLOBJ_CONTEXT;
228 873
229void 874void
230wait_for_events (...) 875wait_for_events (...)
231 CODE: 876 CODE:
232 EVENT_LIST (0, items); 877 EVENT_LIST (0);
233 NEED_SUCCESS (WaitForEvents, (event_list_count, event_list_ptr)); 878 NEED_SUCCESS (WaitForEvents, (event_list_count, event_list_ptr));
234 879
235PROTOTYPES: DISABLE 880PROTOTYPES: DISABLE
236 881
237MODULE = OpenCL PACKAGE = OpenCL::Platform 882MODULE = OpenCL PACKAGE = OpenCL::Platform
238 883
239void 884void
240info (OpenCL::Platform this, cl_platform_info name) 885info (OpenCL::Platform self, cl_platform_info name)
241 PPCODE: 886 PPCODE:
242 INFO (Platform) 887 INFO (Platform)
243 888
889void
890unload_compiler (OpenCL::Platform self)
891 CODE:
892#if CL_VERSION_1_2
893 clUnloadPlatformCompiler (self);
894#endif
895
244#BEGIN:platform 896#BEGIN:platform
245 897
246void 898void
247profile (OpenCL::Platform this) 899profile (OpenCL::Platform self)
248 ALIAS: 900 ALIAS:
249 profile = CL_PLATFORM_PROFILE 901 profile = CL_PLATFORM_PROFILE
250 version = CL_PLATFORM_VERSION 902 version = CL_PLATFORM_VERSION
251 name = CL_PLATFORM_NAME 903 name = CL_PLATFORM_NAME
252 vendor = CL_PLATFORM_VENDOR 904 vendor = CL_PLATFORM_VENDOR
253 extensions = CL_PLATFORM_EXTENSIONS 905 extensions = CL_PLATFORM_EXTENSIONS
254 PPCODE: 906 PPCODE:
255 size_t size; 907 size_t size;
256 NEED_SUCCESS (GetPlatformInfo, (this, ix, 0, 0, &size)); 908 NEED_SUCCESS (GetPlatformInfo, (self, ix, 0, 0, &size));
257 char *value = tmpbuf (size); 909 char *value = tmpbuf (size);
258 NEED_SUCCESS (GetPlatformInfo, (this, ix, size, value, 0)); 910 NEED_SUCCESS (GetPlatformInfo, (self, ix, size, value, 0));
259 EXTEND (SP, 1); 911 EXTEND (SP, 1);
260 const int i = 0; 912 const int i = 0;
261 PUSHs (sv_2mortal (newSVpv (value, 0))); 913 PUSHs (sv_2mortal (newSVpv (value, 0)));
262 914
263#END:platform 915#END:platform
264 916
265void 917void
266devices (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_ALL) 918devices (OpenCL::Platform self, cl_device_type type = CL_DEVICE_TYPE_ALL)
267 PPCODE: 919 PPCODE:
268 cl_device_id *list; 920 cl_device_id *list;
269 cl_uint count; 921 cl_uint count;
270 int i; 922 int i;
271 923
272 NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count)); 924 NEED_SUCCESS (GetDeviceIDs, (self, type, 0, 0, &count));
273 list = tmpbuf (sizeof (*list) * count); 925 list = tmpbuf (sizeof (*list) * count);
274 NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0)); 926 NEED_SUCCESS (GetDeviceIDs, (self, type, count, list, 0));
275 927
276 EXTEND (SP, count); 928 EXTEND (SP, count);
277 for (i = 0; i < count; ++i) 929 for (i = 0; i < count; ++i)
278 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); 930 PUSH_CLOBJ (stash_device, list [i]);
279 931
280void 932void
281context (OpenCL::Platform this, FUTURE properties, SV *devices, FUTURE notify = 0) 933context (OpenCL::Platform self, SV *properties, SV *devices, SV *notify = &PL_sv_undef)
282 PPCODE: 934 PPCODE:
935 cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self };
936 cl_context_properties *props = SvCONTEXTPROPERTIES (cv, "properties", properties, extra, 2);
937
938 cl_uint device_count;
939 cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count);
940
941 CONTEXT_NOTIFY_CALLBACK;
942 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (props, device_count, device_list, pfn_notify, user_data, &res));
943 XPUSH_CLOBJ_CONTEXT;
944
945void
946context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef)
947 PPCODE:
948 cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self };
949 cl_context_properties *props = SvCONTEXTPROPERTIES (cv, "properties", properties, extra, 2);
950
951 CONTEXT_NOTIFY_CALLBACK;
952 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, pfn_notify, user_data, &res));
953 XPUSH_CLOBJ_CONTEXT;
954
955MODULE = OpenCL PACKAGE = OpenCL::Device
956
957void
958info (OpenCL::Device self, cl_device_info name)
959 PPCODE:
960 INFO (Device)
961
962#if CL_VERSION_1_2
963
964void
965sub_devices (OpenCL::Device self, SV *properties)
966 PPCODE:
283 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) 967 if (!SvROK (properties) || SvTYPE (SvRV (properties)) != SVt_PVAV)
284 croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call"); 968 croak ("OpenCL::Device::sub_devices: properties must be specified as reference to an array of property-value pairs");
285 969
286 AV *av = (AV *)SvRV (devices); 970 properties = SvRV (properties);
287 cl_uint num_devices = av_len (av) + 1; 971
288 cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); 972 cl_uint count = av_len ((AV *)properties) + 1;
973 cl_device_partition_property *props = tmpbuf (sizeof (*props) * count + 1);
974
289 int i; 975 int i;
976 for (i = 0; i < count; ++i)
977 props [i] = (cl_device_partition_property)SvIV (*av_fetch ((AV *)properties, i, 0));
290 978
291 for (i = num_devices; i--; ) 979 props [count] = 0;
292 device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device");
293 980
294 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (0, num_devices, device_list, 0, 0, &res)); 981 cl_uint num_devices;
295 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 982 NEED_SUCCESS (CreateSubDevices, (self, props, 0, 0, &num_devices));
983 cl_device_id *list = tmpbuf (sizeof (*list) * num_devices);
984 NEED_SUCCESS (CreateSubDevices, (self, props, num_devices, list, 0));
296 985
297void 986 EXTEND (SP, num_devices);
298context_from_type (OpenCL::Platform this, FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) 987 for (i = 0; i < count; ++i)
299 PPCODE: 988 PUSH_CLOBJ (stash_subdevice, list [i]);
300 cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)this, 0 };
301 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res));
302 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
303 989
304MODULE = OpenCL PACKAGE = OpenCL::Device 990#endif
305
306void
307info (OpenCL::Device this, cl_device_info name)
308 PPCODE:
309 INFO (Device)
310 991
311#BEGIN:device 992#BEGIN:device
312 993
313void 994void
314type (OpenCL::Device this) 995type (OpenCL::Device self)
315 PPCODE: 996 PPCODE:
316 cl_device_type value [1]; 997 cl_device_type value [1];
317 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_TYPE, sizeof (value), value, 0)); 998 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_TYPE, sizeof (value), value, 0));
318 EXTEND (SP, 1); 999 EXTEND (SP, 1);
319 const int i = 0; 1000 const int i = 0;
320 PUSHs (sv_2mortal (newSViv (value [i]))); 1001 PUSHs (sv_2mortal (newSVuv (value [i])));
321 1002
322void 1003void
323vendor_id (OpenCL::Device this) 1004vendor_id (OpenCL::Device self)
324 ALIAS: 1005 ALIAS:
325 vendor_id = CL_DEVICE_VENDOR_ID 1006 vendor_id = CL_DEVICE_VENDOR_ID
326 max_compute_units = CL_DEVICE_MAX_COMPUTE_UNITS 1007 max_compute_units = CL_DEVICE_MAX_COMPUTE_UNITS
327 max_work_item_dimensions = CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS 1008 max_work_item_dimensions = CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
328 preferred_vector_width_char = CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR 1009 preferred_vector_width_char = CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR
346 native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 1027 native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT
347 native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 1028 native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG
348 native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 1029 native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT
349 native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 1030 native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE
350 native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 1031 native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF
351 reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT 1032 reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT
352 PPCODE: 1033 PPCODE:
353 cl_uint value [1]; 1034 cl_uint value [1];
354 NEED_SUCCESS (GetDeviceInfo, (this, ix, sizeof (value), value, 0)); 1035 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
355 EXTEND (SP, 1); 1036 EXTEND (SP, 1);
356 const int i = 0; 1037 const int i = 0;
357 PUSHs (sv_2mortal (newSVuv (value [i]))); 1038 PUSHs (sv_2mortal (newSVuv (value [i])));
358 1039
359void 1040void
360max_work_group_size (OpenCL::Device this) 1041max_work_group_size (OpenCL::Device self)
361 ALIAS: 1042 ALIAS:
362 max_work_group_size = CL_DEVICE_MAX_WORK_GROUP_SIZE 1043 max_work_group_size = CL_DEVICE_MAX_WORK_GROUP_SIZE
363 image2d_max_width = CL_DEVICE_IMAGE2D_MAX_WIDTH 1044 image2d_max_width = CL_DEVICE_IMAGE2D_MAX_WIDTH
364 image2d_max_height = CL_DEVICE_IMAGE2D_MAX_HEIGHT 1045 image2d_max_height = CL_DEVICE_IMAGE2D_MAX_HEIGHT
365 image3d_max_width = CL_DEVICE_IMAGE3D_MAX_WIDTH 1046 image3d_max_width = CL_DEVICE_IMAGE3D_MAX_WIDTH
367 image3d_max_depth = CL_DEVICE_IMAGE3D_MAX_DEPTH 1048 image3d_max_depth = CL_DEVICE_IMAGE3D_MAX_DEPTH
368 max_parameter_size = CL_DEVICE_MAX_PARAMETER_SIZE 1049 max_parameter_size = CL_DEVICE_MAX_PARAMETER_SIZE
369 profiling_timer_resolution = CL_DEVICE_PROFILING_TIMER_RESOLUTION 1050 profiling_timer_resolution = CL_DEVICE_PROFILING_TIMER_RESOLUTION
370 PPCODE: 1051 PPCODE:
371 size_t value [1]; 1052 size_t value [1];
372 NEED_SUCCESS (GetDeviceInfo, (this, ix, sizeof (value), value, 0)); 1053 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
373 EXTEND (SP, 1); 1054 EXTEND (SP, 1);
374 const int i = 0; 1055 const int i = 0;
375 PUSHs (sv_2mortal (newSVuv (value [i]))); 1056 PUSHs (sv_2mortal (newSVuv (value [i])));
376 1057
377void 1058void
378max_work_item_sizes (OpenCL::Device this) 1059max_work_item_sizes (OpenCL::Device self)
379 PPCODE: 1060 PPCODE:
380 size_t size; 1061 size_t size;
381 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_WORK_ITEM_SIZES, 0, 0, &size)); 1062 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_MAX_WORK_ITEM_SIZES, 0, 0, &size));
382 size_t *value = tmpbuf (size); 1063 size_t *value = tmpbuf (size);
383 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_WORK_ITEM_SIZES, size, value, 0)); 1064 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_MAX_WORK_ITEM_SIZES, size, value, 0));
384 int i, n = size / sizeof (*value); 1065 int i, n = size / sizeof (*value);
385 EXTEND (SP, n); 1066 EXTEND (SP, n);
386 for (i = 0; i < n; ++i) 1067 for (i = 0; i < n; ++i)
387 PUSHs (sv_2mortal (newSVuv (value [i]))); 1068 PUSHs (sv_2mortal (newSVuv (value [i])));
388 1069
389void 1070void
390address_bits (OpenCL::Device this) 1071address_bits (OpenCL::Device self)
391 PPCODE: 1072 PPCODE:
392 cl_bitfield value [1]; 1073 cl_bitfield value [1];
393 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_ADDRESS_BITS, sizeof (value), value, 0)); 1074 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_ADDRESS_BITS, sizeof (value), value, 0));
394 EXTEND (SP, 1); 1075 EXTEND (SP, 1);
395 const int i = 0; 1076 const int i = 0;
396 PUSHs (sv_2mortal (newSVuv (value [i]))); 1077 PUSHs (sv_2mortal (newSVuv (value [i])));
397 1078
398void 1079void
399max_mem_alloc_size (OpenCL::Device this) 1080max_mem_alloc_size (OpenCL::Device self)
400 ALIAS: 1081 ALIAS:
401 max_mem_alloc_size = CL_DEVICE_MAX_MEM_ALLOC_SIZE 1082 max_mem_alloc_size = CL_DEVICE_MAX_MEM_ALLOC_SIZE
402 global_mem_cache_size = CL_DEVICE_GLOBAL_MEM_CACHE_SIZE 1083 global_mem_cache_size = CL_DEVICE_GLOBAL_MEM_CACHE_SIZE
403 global_mem_size = CL_DEVICE_GLOBAL_MEM_SIZE 1084 global_mem_size = CL_DEVICE_GLOBAL_MEM_SIZE
404 max_constant_buffer_size = CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE 1085 max_constant_buffer_size = CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE
405 local_mem_size = CL_DEVICE_LOCAL_MEM_SIZE 1086 local_mem_size = CL_DEVICE_LOCAL_MEM_SIZE
406 PPCODE: 1087 PPCODE:
407 cl_ulong value [1]; 1088 cl_ulong value [1];
408 NEED_SUCCESS (GetDeviceInfo, (this, ix, sizeof (value), value, 0)); 1089 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
409 EXTEND (SP, 1); 1090 EXTEND (SP, 1);
410 const int i = 0; 1091 const int i = 0;
411 PUSHs (sv_2mortal (newSVuv (value [i]))); 1092 PUSHs (sv_2mortal (newSVuv (value [i])));
412 1093
413void 1094void
414single_fp_config (OpenCL::Device this) 1095single_fp_config (OpenCL::Device self)
415 ALIAS: 1096 ALIAS:
416 single_fp_config = CL_DEVICE_SINGLE_FP_CONFIG 1097 single_fp_config = CL_DEVICE_SINGLE_FP_CONFIG
417 double_fp_config = CL_DEVICE_DOUBLE_FP_CONFIG 1098 double_fp_config = CL_DEVICE_DOUBLE_FP_CONFIG
418 half_fp_config = CL_DEVICE_HALF_FP_CONFIG 1099 half_fp_config = CL_DEVICE_HALF_FP_CONFIG
419 PPCODE: 1100 PPCODE:
420 cl_device_fp_config value [1]; 1101 cl_device_fp_config value [1];
421 NEED_SUCCESS (GetDeviceInfo, (this, ix, sizeof (value), value, 0)); 1102 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
422 EXTEND (SP, 1); 1103 EXTEND (SP, 1);
423 const int i = 0; 1104 const int i = 0;
424 PUSHs (sv_2mortal (newSVuv (value [i]))); 1105 PUSHs (sv_2mortal (newSVuv (value [i])));
425 1106
426void 1107void
427global_mem_cache_type (OpenCL::Device this) 1108global_mem_cache_type (OpenCL::Device self)
428 PPCODE: 1109 PPCODE:
429 cl_device_mem_cache_type value [1]; 1110 cl_device_mem_cache_type value [1];
430 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, sizeof (value), value, 0)); 1111 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, sizeof (value), value, 0));
431 EXTEND (SP, 1); 1112 EXTEND (SP, 1);
432 const int i = 0; 1113 const int i = 0;
433 PUSHs (sv_2mortal (newSVuv (value [i]))); 1114 PUSHs (sv_2mortal (newSVuv (value [i])));
434 1115
435void 1116void
436local_mem_type (OpenCL::Device this) 1117local_mem_type (OpenCL::Device self)
437 PPCODE: 1118 PPCODE:
438 cl_device_local_mem_type value [1]; 1119 cl_device_local_mem_type value [1];
439 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_LOCAL_MEM_TYPE, sizeof (value), value, 0)); 1120 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_LOCAL_MEM_TYPE, sizeof (value), value, 0));
440 EXTEND (SP, 1); 1121 EXTEND (SP, 1);
441 const int i = 0; 1122 const int i = 0;
442 PUSHs (sv_2mortal (newSVuv (value [i]))); 1123 PUSHs (sv_2mortal (newSVuv (value [i])));
443 1124
444void 1125void
445error_correction_support (OpenCL::Device this) 1126error_correction_support (OpenCL::Device self)
446 ALIAS: 1127 ALIAS:
447 error_correction_support = CL_DEVICE_ERROR_CORRECTION_SUPPORT 1128 error_correction_support = CL_DEVICE_ERROR_CORRECTION_SUPPORT
448 endian_little = CL_DEVICE_ENDIAN_LITTLE 1129 endian_little = CL_DEVICE_ENDIAN_LITTLE
449 available = CL_DEVICE_AVAILABLE 1130 available = CL_DEVICE_AVAILABLE
450 compiler_available = CL_DEVICE_COMPILER_AVAILABLE 1131 compiler_available = CL_DEVICE_COMPILER_AVAILABLE
451 host_unified_memory = CL_DEVICE_HOST_UNIFIED_MEMORY 1132 host_unified_memory = CL_DEVICE_HOST_UNIFIED_MEMORY
452 PPCODE: 1133 PPCODE:
453 cl_bool value [1]; 1134 cl_bool value [1];
454 NEED_SUCCESS (GetDeviceInfo, (this, ix, sizeof (value), value, 0)); 1135 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
455 EXTEND (SP, 1); 1136 EXTEND (SP, 1);
456 const int i = 0; 1137 const int i = 0;
457 PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no)); 1138 PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no));
458 1139
459void 1140void
460execution_capabilities (OpenCL::Device this) 1141execution_capabilities (OpenCL::Device self)
461 PPCODE: 1142 PPCODE:
462 cl_device_exec_capabilities value [1]; 1143 cl_device_exec_capabilities value [1];
463 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_EXECUTION_CAPABILITIES, sizeof (value), value, 0)); 1144 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_EXECUTION_CAPABILITIES, sizeof (value), value, 0));
464 EXTEND (SP, 1); 1145 EXTEND (SP, 1);
465 const int i = 0; 1146 const int i = 0;
466 PUSHs (sv_2mortal (newSVuv (value [i]))); 1147 PUSHs (sv_2mortal (newSVuv (value [i])));
467 1148
468void 1149void
469properties (OpenCL::Device this) 1150properties (OpenCL::Device self)
470 PPCODE: 1151 PPCODE:
471 cl_command_queue_properties value [1]; 1152 cl_command_queue_properties value [1];
472 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_QUEUE_PROPERTIES, sizeof (value), value, 0)); 1153 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_QUEUE_PROPERTIES, sizeof (value), value, 0));
473 EXTEND (SP, 1); 1154 EXTEND (SP, 1);
474 const int i = 0; 1155 const int i = 0;
475 PUSHs (sv_2mortal (newSViv (value [i]))); 1156 PUSHs (sv_2mortal (newSVuv (value [i])));
476 1157
477void 1158void
478platform (OpenCL::Device this) 1159platform (OpenCL::Device self)
479 PPCODE: 1160 PPCODE:
480 cl_platform_id value [1]; 1161 cl_platform_id value [1];
481 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PLATFORM, sizeof (value), value, 0)); 1162 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_PLATFORM, sizeof (value), value, 0));
482 EXTEND (SP, 1); 1163 EXTEND (SP, 1);
483 const int i = 0; 1164 const int i = 0;
484 { 1165 {
485 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", value [i])); 1166 PUSH_CLOBJ (stash_platform, value [i]);
486 } 1167 }
487 1168
488void 1169void
489name (OpenCL::Device this) 1170name (OpenCL::Device self)
490 ALIAS: 1171 ALIAS:
491 name = CL_DEVICE_NAME 1172 name = CL_DEVICE_NAME
492 vendor = CL_DEVICE_VENDOR 1173 vendor = CL_DEVICE_VENDOR
493 driver_version = CL_DRIVER_VERSION 1174 driver_version = CL_DRIVER_VERSION
494 profile = CL_DEVICE_PROFILE 1175 profile = CL_DEVICE_PROFILE
495 version = CL_DEVICE_VERSION 1176 version = CL_DEVICE_VERSION
496 extensions = CL_DEVICE_EXTENSIONS 1177 extensions = CL_DEVICE_EXTENSIONS
497 PPCODE: 1178 PPCODE:
498 size_t size; 1179 size_t size;
499 NEED_SUCCESS (GetDeviceInfo, (this, ix, 0, 0, &size)); 1180 NEED_SUCCESS (GetDeviceInfo, (self, ix, 0, 0, &size));
500 char *value = tmpbuf (size); 1181 char *value = tmpbuf (size);
501 NEED_SUCCESS (GetDeviceInfo, (this, ix, size, value, 0)); 1182 NEED_SUCCESS (GetDeviceInfo, (self, ix, size, value, 0));
502 EXTEND (SP, 1); 1183 EXTEND (SP, 1);
503 const int i = 0; 1184 const int i = 0;
504 PUSHs (sv_2mortal (newSVpv (value, 0))); 1185 PUSHs (sv_2mortal (newSVpv (value, 0)));
505 1186
506void 1187void
507parent_device_ext (OpenCL::Device this) 1188parent_device_ext (OpenCL::Device self)
508 PPCODE: 1189 PPCODE:
509 cl_device_id value [1]; 1190 cl_device_id value [1];
510 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PARENT_DEVICE_EXT, sizeof (value), value, 0)); 1191 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_PARENT_DEVICE_EXT, sizeof (value), value, 0));
511 EXTEND (SP, 1); 1192 EXTEND (SP, 1);
512 const int i = 0; 1193 const int i = 0;
513 { 1194 {
514 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i])); 1195 PUSH_CLOBJ (stash_device, value [i]);
515 } 1196 }
516 1197
517void 1198void
518partition_types_ext (OpenCL::Device this) 1199partition_types_ext (OpenCL::Device self)
519 ALIAS: 1200 ALIAS:
520 partition_types_ext = CL_DEVICE_PARTITION_TYPES_EXT 1201 partition_types_ext = CL_DEVICE_PARTITION_TYPES_EXT
521 affinity_domains_ext = CL_DEVICE_AFFINITY_DOMAINS_EXT 1202 affinity_domains_ext = CL_DEVICE_AFFINITY_DOMAINS_EXT
522 partition_style_ext = CL_DEVICE_PARTITION_STYLE_EXT 1203 partition_style_ext = CL_DEVICE_PARTITION_STYLE_EXT
523 PPCODE: 1204 PPCODE:
524 size_t size; 1205 size_t size;
525 NEED_SUCCESS (GetDeviceInfo, (this, ix, 0, 0, &size)); 1206 NEED_SUCCESS (GetDeviceInfo, (self, ix, 0, 0, &size));
526 cl_device_partition_property_ext *value = tmpbuf (size); 1207 cl_device_partition_property_ext *value = tmpbuf (size);
527 NEED_SUCCESS (GetDeviceInfo, (this, ix, size, value, 0)); 1208 NEED_SUCCESS (GetDeviceInfo, (self, ix, size, value, 0));
528 int i, n = size / sizeof (*value); 1209 int i, n = size / sizeof (*value);
529 EXTEND (SP, n); 1210 EXTEND (SP, n);
530 for (i = 0; i < n; ++i) 1211 for (i = 0; i < n; ++i)
531 PUSHs (sv_2mortal (newSVuv (value [i]))); 1212 PUSHs (sv_2mortal (newSVuv (value [i])));
532 1213
533#END:device 1214#END:device
534 1215
1216MODULE = OpenCL PACKAGE = OpenCL::SubDevice
1217
1218#if CL_VERSION_1_2
1219
1220void
1221DESTROY (OpenCL::SubDevice self)
1222 CODE:
1223 clReleaseDevice (self);
1224
1225#endif
1226
535MODULE = OpenCL PACKAGE = OpenCL::Context 1227MODULE = OpenCL PACKAGE = OpenCL::Context
536 1228
537void 1229void
538DESTROY (OpenCL::Context context) 1230DESTROY (OpenCL::Context self)
539 CODE: 1231 CODE:
540 clReleaseContext (context); 1232 clReleaseContext (self);
541 1233
542void 1234void
543info (OpenCL::Context this, cl_context_info name) 1235info (OpenCL::Context self, cl_context_info name)
544 PPCODE: 1236 PPCODE:
545 INFO (Context) 1237 INFO (Context)
546 1238
547void 1239void
548queue (OpenCL::Context this, OpenCL::Device device, cl_command_queue_properties properties = 0) 1240queue (OpenCL::Context self, OpenCL::Device device, cl_command_queue_properties properties = 0)
549 PPCODE: 1241 PPCODE:
550 NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (this, device, properties, &res)); 1242 NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (self, device, properties, &res));
551 XPUSH_NEW_OBJ ("OpenCL::Queue", queue); 1243 XPUSH_CLOBJ (stash_queue, queue);
552 1244
553void 1245void
554user_event (OpenCL::Context this) 1246user_event (OpenCL::Context self)
555 PPCODE: 1247 PPCODE:
556 NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (this, &res)); 1248 NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (self, &res));
557 XPUSH_NEW_OBJ ("OpenCL::UserEvent", ev); 1249 XPUSH_CLOBJ (stash_userevent, ev);
558 1250
559void 1251void
560buffer (OpenCL::Context this, cl_mem_flags flags, size_t len) 1252buffer (OpenCL::Context self, cl_mem_flags flags, size_t len)
561 PPCODE: 1253 PPCODE:
562 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) 1254 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
563 croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); 1255 croak ("OpenCL::Context::buffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?");
564 1256
565 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, 0, &res)); 1257 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res));
566 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 1258 XPUSH_CLOBJ (stash_bufferobj, mem);
567 1259
568void 1260void
569buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data) 1261buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data)
570 PPCODE: 1262 PPCODE:
571 STRLEN len; 1263 STRLEN len;
572 char *ptr = SvPVbyte (data, len); 1264 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
573
574 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) 1265 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
575 croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); 1266 croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
576
577 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, ptr, &res)); 1267 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res));
578 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 1268 XPUSH_CLOBJ (stash_bufferobj, mem);
579 1269
1270#if CL_VERSION_1_2
1271
580void 1272void
581image2d (OpenCL::Context this, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, size_t row_pitch = 0, SV *data = &PL_sv_undef) 1273image (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)
582 PPCODE: 1274 PPCODE:
583 STRLEN len; 1275 STRLEN len;
584 char *ptr = SvPVbyte (data, len); 1276 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
585 const cl_image_format format = { channel_order, channel_type }; 1277 const cl_image_format format = { channel_order, channel_type };
1278 const cl_image_desc desc = {
1279 type,
1280 width, height, depth,
1281 array_size, row_pitch, slice_pitch,
1282 num_mip_level, num_samples,
1283 type == CL_MEM_OBJECT_IMAGE1D_BUFFER ? (cl_mem)SvCLOBJ (cv, "data", data, "OpenCL::Buffer") : 0
1284 };
586 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (this, flags, &format, width, height, row_pitch, ptr, &res)); 1285 NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
587 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 1286 HV *stash = stash_image;
1287 switch (type)
1288 {
1289 case CL_MEM_OBJECT_IMAGE1D_BUFFER: stash = stash_image1dbuffer; break;
1290 case CL_MEM_OBJECT_IMAGE1D: stash = stash_image1d; break;
1291 case CL_MEM_OBJECT_IMAGE1D_ARRAY: stash = stash_image2darray; break;
1292 case CL_MEM_OBJECT_IMAGE2D: stash = stash_image2d; break;
1293 case CL_MEM_OBJECT_IMAGE2D_ARRAY: stash = stash_image2darray; break;
1294 case CL_MEM_OBJECT_IMAGE3D: stash = stash_image3d; break;
1295 }
1296 XPUSH_CLOBJ (stash, mem);
588 1297
1298#endif
1299
589void 1300void
590image3d (OpenCL::Context this, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, size_t depth, size_t row_pitch = 0, size_t slice_pitch = 0, SV *data = &PL_sv_undef) 1301image2d (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)
591 PPCODE: 1302 PPCODE:
592 STRLEN len; 1303 STRLEN len;
593 char *ptr = SvPVbyte (data, len); 1304 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
594 const cl_image_format format = { channel_order, channel_type }; 1305 const cl_image_format format = { channel_order, channel_type };
1306#if PREFER_1_1
1307 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res));
1308#else
1309 const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE2D, width, height, 0, 0, row_pitch, 0, 0, 0, 0 };
1310 NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
1311#endif
1312 XPUSH_CLOBJ (stash_image2d, mem);
1313
1314void
1315image3d (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)
1316 PPCODE:
1317 STRLEN len;
1318 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
1319 const cl_image_format format = { channel_order, channel_type };
1320#if PREFER_1_1
595 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (this, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); 1321 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
596 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 1322#else
1323 const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE3D, width, height, depth, 0, row_pitch, slice_pitch, 0, 0, 0 };
1324 NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
1325#endif
1326 XPUSH_CLOBJ (stash_image3d, mem);
597 1327
1328#if cl_apple_gl_sharing || cl_khr_gl_sharing
1329
598void 1330void
1331gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj)
1332 PPCODE:
1333 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res));
1334 XPUSH_CLOBJ (stash_bufferobj, mem);
1335
1336void
1337gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer)
1338 PPCODE:
1339 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res));
1340 XPUSH_CLOBJ (stash_image2d, mem);
1341
1342#if CL_VERSION_1_2
1343
1344void
1345gl_texture (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
1346 ALIAS:
1347 PPCODE:
1348 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture, (self, flags, target, miplevel, texture, &res));
1349 cl_gl_object_type type;
1350 NEED_SUCCESS (GetGLObjectInfo, (mem, &type, 0)); // TODO: use target instead?
1351 HV *stash = stash_memory;
1352 switch (type)
1353 {
1354 case CL_GL_OBJECT_TEXTURE_BUFFER: stash = stash_image1dbuffer; break;
1355 case CL_GL_OBJECT_TEXTURE1D: stash = stash_image1d; break;
1356 case CL_GL_OBJECT_TEXTURE1D_ARRAY: stash = stash_image2darray; break;
1357 case CL_GL_OBJECT_TEXTURE2D: stash = stash_image2d; break;
1358 case CL_GL_OBJECT_TEXTURE2D_ARRAY: stash = stash_image2darray; break;
1359 case CL_GL_OBJECT_TEXTURE3D: stash = stash_image3d; break;
1360 }
1361 XPUSH_CLOBJ (stash, mem);
1362
1363#endif
1364
1365void
1366gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
1367 PPCODE:
1368#if PREFER_1_1
1369 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
1370#else
1371 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture , (self, flags, target, miplevel, texture, &res));
1372#endif
1373 XPUSH_CLOBJ (stash_image2d, mem);
1374
1375void
1376gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
1377 PPCODE:
1378#if PREFER_1_1
1379 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res));
1380#else
1381 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture , (self, flags, target, miplevel, texture, &res));
1382#endif
1383 XPUSH_CLOBJ (stash_image3d, mem);
1384
1385#endif
1386
1387void
599supported_image_formats (OpenCL::Context this, cl_mem_flags flags, cl_mem_object_type image_type) 1388supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type)
600 PPCODE: 1389 PPCODE:
601{ 1390{
602 cl_uint count; 1391 cl_uint count;
603 cl_image_format *list; 1392 cl_image_format *list;
604 int i; 1393 int i;
605 1394
606 NEED_SUCCESS (GetSupportedImageFormats, (this, flags, image_type, 0, 0, &count)); 1395 NEED_SUCCESS (GetSupportedImageFormats, (self, flags, image_type, 0, 0, &count));
607 Newx (list, count, cl_image_format); 1396 Newx (list, count, cl_image_format);
608 NEED_SUCCESS (GetSupportedImageFormats, (this, flags, image_type, count, list, 0)); 1397 NEED_SUCCESS (GetSupportedImageFormats, (self, flags, image_type, count, list, 0));
609 1398
610 EXTEND (SP, count); 1399 EXTEND (SP, count);
611 for (i = 0; i < count; ++i) 1400 for (i = 0; i < count; ++i)
612 { 1401 {
613 AV *av = newAV (); 1402 AV *av = newAV ();
616 PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); 1405 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
617 } 1406 }
618} 1407}
619 1408
620void 1409void
621sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode) 1410sampler (OpenCL::Context self, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode)
622 PPCODE: 1411 PPCODE:
623 NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (this, normalized_coords, addressing_mode, filter_mode, &res)); 1412 NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (self, normalized_coords, addressing_mode, filter_mode, &res));
624 XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler); 1413 XPUSH_CLOBJ (stash_sampler, sampler);
625 1414
626void 1415void
627program_with_source (OpenCL::Context this, SV *program) 1416program_with_source (OpenCL::Context self, SV *program)
628 PPCODE: 1417 PPCODE:
629 STRLEN len; 1418 STRLEN len;
630 size_t len2; 1419 size_t len2;
631 const char *ptr = SvPVbyte (program, len); 1420 const char *ptr = SvPVbyte (program, len);
632 1421
633 len2 = len; 1422 len2 = len;
634 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (this, 1, &ptr, &len2, &res)); 1423 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (self, 1, &ptr, &len2, &res));
635 XPUSH_NEW_OBJ ("OpenCL::Program", prog); 1424 XPUSH_CLOBJ (stash_program, prog);
1425
1426void
1427program_with_binary (OpenCL::Context self, SV *devices, SV *binaries)
1428 PPCODE:
1429 cl_uint device_count;
1430 cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count);
1431
1432 if (!SvROK (binaries) || SvTYPE (SvRV (binaries)) != SVt_PVAV)
1433 croak ("OpenCL::Context::program_with_binary: binaries must be specified as reference to an array of strings");
1434
1435 binaries = SvRV (binaries);
1436
1437 if (device_count != av_len ((AV *)binaries) + 1)
1438 croak ("OpenCL::Context::program_with_binary: differing numbers of devices and binaries are not allowed");
1439
1440 size_t *length_list = tmpbuf (sizeof (*length_list) * device_count);
1441 const unsigned char **binary_list = tmpbuf (sizeof (*binary_list) * device_count);
1442 cl_int *status_list = tmpbuf (sizeof (*status_list) * device_count);
1443
1444 int i;
1445 for (i = 0; i < device_count; ++i)
1446 {
1447 STRLEN len;
1448 binary_list [i] = (const unsigned char *)SvPVbyte (*av_fetch ((AV *)binaries, i, 0), len);
1449 length_list [i] = len;
1450 }
1451
1452 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBinary, (self, device_count, device_list,
1453 length_list, binary_list,
1454 GIMME_V == G_ARRAY ? status_list : 0, &res));
1455
1456 EXTEND (SP, 2);
1457 PUSH_CLOBJ (stash_program, prog);
1458
1459 if (GIMME_V == G_ARRAY)
1460 {
1461 AV *av = newAV ();
1462 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
1463
1464 for (i = device_count; i--; )
1465 av_store (av, i, newSViv (status_list [i]));
1466 }
1467
1468#if CL_VERSION_1_2
1469
1470void
1471program_with_built_in_kernels (OpenCL::Context self, SV *devices, SV *kernel_names)
1472 PPCODE:
1473 cl_uint device_count;
1474 cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count);
1475
1476 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBuiltInKernels, (self, device_count, device_list, SvPVbyte_nolen (kernel_names), &res));
1477
1478 XPUSH_CLOBJ (stash_program, prog);
1479
1480void
1481link_program (OpenCL::Context self, SV *devices, SV *options, SV *programs, SV *notify = &PL_sv_undef)
1482 CODE:
1483 cl_uint device_count = 0;
1484 cl_device_id *device_list = 0;
1485
1486 if (SvOK (devices))
1487 device_list = object_list (cv, 1, "devices", devices, "OpenCL::Device", &device_count);
1488
1489 cl_uint program_count;
1490 cl_program *program_list = object_list (cv, 0, "programs", programs, "OpenCL::Program", &program_count);
1491
1492 void *user_data;
1493 program_callback pfn_notify = make_program_callback (notify, &user_data);
1494
1495 NEED_SUCCESS_ARG (cl_program prog, LinkProgram, (self, device_count, device_list, SvPVbyte_nolen (options),
1496 program_count, program_list, pfn_notify, user_data, &res));
1497
1498 XPUSH_CLOBJ (stash_program, prog);
1499
1500#endif
636 1501
637#BEGIN:context 1502#BEGIN:context
638 1503
639void 1504void
640reference_count (OpenCL::Context this) 1505reference_count (OpenCL::Context self)
641 ALIAS: 1506 ALIAS:
642 reference_count = CL_CONTEXT_REFERENCE_COUNT 1507 reference_count = CL_CONTEXT_REFERENCE_COUNT
643 num_devices = CL_CONTEXT_NUM_DEVICES 1508 num_devices = CL_CONTEXT_NUM_DEVICES
644 PPCODE: 1509 PPCODE:
645 cl_uint value [1]; 1510 cl_uint value [1];
646 NEED_SUCCESS (GetContextInfo, (this, ix, sizeof (value), value, 0)); 1511 NEED_SUCCESS (GetContextInfo, (self, ix, sizeof (value), value, 0));
647 EXTEND (SP, 1); 1512 EXTEND (SP, 1);
648 const int i = 0; 1513 const int i = 0;
649 PUSHs (sv_2mortal (newSVuv (value [i]))); 1514 PUSHs (sv_2mortal (newSVuv (value [i])));
650 1515
651void 1516void
652devices (OpenCL::Context this) 1517devices (OpenCL::Context self)
653 PPCODE: 1518 PPCODE:
654 size_t size; 1519 size_t size;
655 NEED_SUCCESS (GetContextInfo, (this, CL_CONTEXT_DEVICES, 0, 0, &size)); 1520 NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_DEVICES, 0, 0, &size));
656 cl_device_id *value = tmpbuf (size); 1521 cl_device_id *value = tmpbuf (size);
657 NEED_SUCCESS (GetContextInfo, (this, CL_CONTEXT_DEVICES, size, value, 0)); 1522 NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_DEVICES, size, value, 0));
658 int i, n = size / sizeof (*value); 1523 int i, n = size / sizeof (*value);
659 EXTEND (SP, n); 1524 EXTEND (SP, n);
660 for (i = 0; i < n; ++i) 1525 for (i = 0; i < n; ++i)
661 { 1526 {
662 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i])); 1527 PUSH_CLOBJ (stash_device, value [i]);
663 } 1528 }
664 1529
665void 1530void
666properties (OpenCL::Context this) 1531properties (OpenCL::Context self)
667 PPCODE: 1532 PPCODE:
668 size_t size; 1533 size_t size;
669 NEED_SUCCESS (GetContextInfo, (this, CL_CONTEXT_PROPERTIES, 0, 0, &size)); 1534 NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_PROPERTIES, 0, 0, &size));
670 cl_context_properties *value = tmpbuf (size); 1535 cl_context_properties *value = tmpbuf (size);
671 NEED_SUCCESS (GetContextInfo, (this, CL_CONTEXT_PROPERTIES, size, value, 0)); 1536 NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_PROPERTIES, size, value, 0));
672 int i, n = size / sizeof (*value); 1537 int i, n = size / sizeof (*value);
673 EXTEND (SP, n); 1538 EXTEND (SP, n);
674 for (i = 0; i < n; ++i) 1539 for (i = 0; i < n; ++i)
675 PUSHs (sv_2mortal (newSVuv ((UV)value [i]))); 1540 PUSHs (sv_2mortal (newSVuv ((UV)value [i])));
676 1541
677#END:context 1542#END:context
678 1543
679MODULE = OpenCL PACKAGE = OpenCL::Queue 1544MODULE = OpenCL PACKAGE = OpenCL::Queue
680 1545
681void 1546void
682DESTROY (OpenCL::Queue this) 1547DESTROY (OpenCL::Queue self)
683 CODE: 1548 CODE:
684 clReleaseCommandQueue (this); 1549 clReleaseCommandQueue (self);
685 1550
686void 1551void
687enqueue_read_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...) 1552read_buffer (OpenCL::Queue self, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...)
1553 ALIAS:
1554 enqueue_read_buffer = 0
688 PPCODE: 1555 PPCODE:
689 cl_event ev = 0;
690 EVENT_LIST (6, items - 6); 1556 EVENT_LIST (6);
691 1557
692 SvUPGRADE (data, SVt_PV); 1558 SvUPGRADE (data, SVt_PV);
693 SvGROW (data, len); 1559 SvGROW (data, len);
694 SvPOK_only (data); 1560 SvPOK_only (data);
695 SvCUR_set (data, len); 1561 SvCUR_set (data, len);
1562
1563 cl_event ev = 0;
696 NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1564 NEED_SUCCESS (EnqueueReadBuffer, (self, mem, blocking, offset, len, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
697 1565
698 if (ev) 1566 if (ev)
699 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1567 XPUSH_CLOBJ (stash_event, ev);
700 1568
701void 1569void
702enqueue_write_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...) 1570write_buffer (OpenCL::Queue self, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...)
1571 ALIAS:
1572 enqueue_write_buffer = 0
703 PPCODE: 1573 PPCODE:
704 cl_event ev = 0; 1574 EVENT_LIST (5);
1575
705 STRLEN len; 1576 STRLEN len;
706 char *ptr = SvPVbyte (data, len); 1577 char *ptr = SvPVbyte (data, len);
707 EVENT_LIST (5, items - 5);
708 1578
1579 cl_event ev = 0;
709 NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1580 NEED_SUCCESS (EnqueueWriteBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
710 1581
711 if (ev) 1582 if (ev)
712 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1583 XPUSH_CLOBJ (stash_event, ev);
713 1584
1585#if CL_VERSION_1_2
1586
714void 1587void
715enqueue_copy_buffer (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...) 1588fill_buffer (OpenCL::Queue self, OpenCL::Buffer mem, SV *data, size_t offset, size_t size, ...)
1589 ALIAS:
1590 enqueue_fill_buffer = 0
716 PPCODE: 1591 PPCODE:
1592 EVENT_LIST (5);
1593
1594 STRLEN len;
1595 char *ptr = SvPVbyte (data, len);
1596
717 cl_event ev = 0; 1597 cl_event ev = 0;
718 EVENT_LIST (6, items - 6);
719
720 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1598 NEED_SUCCESS (EnqueueFillBuffer, (self, mem, ptr, len, offset, size, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
721 1599
722 if (ev) 1600 if (ev)
723 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1601 XPUSH_CLOBJ (stash_event, ev);
724 1602
725void 1603void
726enqueue_read_buffer_rect (OpenCL::Queue this, 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, ...) 1604fill_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, ...)
1605 ALIAS:
1606 enqueue_fill_image = 0
727 PPCODE: 1607 PPCODE:
1608 EVENT_LIST (12);
1609
1610 const size_t origin [3] = { x, y, z };
1611 const size_t region [3] = { width, height, depth };
1612
1613 const cl_float c_f [4] = { r, g, b, a };
1614 const cl_uint c_u [4] = { r, g, b, a };
1615 const cl_int c_s [4] = { r, g, b, a };
1616 const void *c_fus [3] = { &c_f, &c_u, &c_s };
1617 static const char fus [] = { 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 1, 1, 1, 0, 0 };
1618 cl_image_format format;
1619 NEED_SUCCESS (GetImageInfo, (img, CL_IMAGE_FORMAT, sizeof (format), &format, 0));
1620 assert (sizeof (fus) == CL_FLOAT + 1 - CL_SNORM_INT8);
1621 if (format.image_channel_data_type < CL_SNORM_INT8 || CL_FLOAT < format.image_channel_data_type)
1622 croak ("enqueue_fill_image: image has unsupported channel type, only opencl 1.2 channel types supported.");
1623
728 cl_event ev = 0; 1624 cl_event ev = 0;
1625 NEED_SUCCESS (EnqueueFillImage, (self, img, c_fus [fus [format.image_channel_data_type - CL_SNORM_INT8]],
1626 origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1627
1628 if (ev)
1629 XPUSH_CLOBJ (stash_event, ev);
1630
1631#endif
1632
1633void
1634copy_buffer (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...)
1635 ALIAS:
1636 enqueue_copy_buffer = 0
1637 PPCODE:
1638 EVENT_LIST (6);
1639
1640 cl_event ev = 0;
1641 NEED_SUCCESS (EnqueueCopyBuffer, (self, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1642
1643 if (ev)
1644 XPUSH_CLOBJ (stash_event, ev);
1645
1646void
1647read_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, ...)
1648 ALIAS:
1649 enqueue_read_buffer_rect = 0
1650 PPCODE:
1651 EVENT_LIST (17);
1652
729 const size_t buf_origin [3] = { buf_x , buf_y , buf_z }; 1653 const size_t buf_origin [3] = { buf_x , buf_y , buf_z };
730 const size_t host_origin[3] = { host_x, host_y, host_z }; 1654 const size_t host_origin[3] = { host_x, host_y, host_z };
731 const size_t region[3] = { width, height, depth }; 1655 const size_t region[3] = { width, height, depth };
732 EVENT_LIST (17, items - 17);
733 1656
734 if (!buf_row_pitch) 1657 if (!buf_row_pitch)
735 buf_row_pitch = region [0]; 1658 buf_row_pitch = region [0];
736 1659
737 if (!buf_slice_pitch) 1660 if (!buf_slice_pitch)
747 1670
748 SvUPGRADE (data, SVt_PV); 1671 SvUPGRADE (data, SVt_PV);
749 SvGROW (data, len); 1672 SvGROW (data, len);
750 SvPOK_only (data); 1673 SvPOK_only (data);
751 SvCUR_set (data, len); 1674 SvCUR_set (data, len);
1675
1676 cl_event ev = 0;
752 NEED_SUCCESS (EnqueueReadBufferRect, (this, 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)); 1677 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));
753 1678
754 if (ev) 1679 if (ev)
755 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1680 XPUSH_CLOBJ (stash_event, ev);
756 1681
757void 1682void
758enqueue_write_buffer_rect (OpenCL::Queue this, 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, ...) 1683write_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, ...)
1684 ALIAS:
1685 enqueue_write_buffer_rect = 0
759 PPCODE: 1686 PPCODE:
760 cl_event ev = 0; 1687 EVENT_LIST (17);
1688
761 const size_t buf_origin [3] = { buf_x , buf_y , buf_z }; 1689 const size_t buf_origin [3] = { buf_x , buf_y , buf_z };
762 const size_t host_origin[3] = { host_x, host_y, host_z }; 1690 const size_t host_origin[3] = { host_x, host_y, host_z };
763 const size_t region[3] = { width, height, depth }; 1691 const size_t region[3] = { width, height, depth };
764 STRLEN len; 1692 STRLEN len;
765 char *ptr = SvPVbyte (data, len); 1693 char *ptr = SvPVbyte (data, len);
766 EVENT_LIST (17, items - 17);
767 1694
768 if (!buf_row_pitch) 1695 if (!buf_row_pitch)
769 buf_row_pitch = region [0]; 1696 buf_row_pitch = region [0];
770 1697
771 if (!buf_slice_pitch) 1698 if (!buf_slice_pitch)
780 size_t min_len = host_row_pitch * host_slice_pitch * region [2]; 1707 size_t min_len = host_row_pitch * host_slice_pitch * region [2];
781 1708
782 if (len < min_len) 1709 if (len < min_len)
783 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1710 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
784 1711
1712 cl_event ev = 0;
785 NEED_SUCCESS (EnqueueWriteBufferRect, (this, 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)); 1713 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));
786 1714
787 if (ev) 1715 if (ev)
788 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1716 XPUSH_CLOBJ (stash_event, ev);
789 1717
790void 1718void
791enqueue_copy_buffer_rect (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, size_t dst_slice_pitch, ...) 1719copy_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, ...)
1720 ALIAS:
1721 enqueue_copy_buffer_rect = 0
792 PPCODE: 1722 PPCODE:
793 cl_event ev = 0; 1723 EVENT_LIST (16);
1724
794 const size_t src_origin[3] = { src_x, src_y, src_z }; 1725 const size_t src_origin[3] = { src_x, src_y, src_z };
795 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 1726 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
796 const size_t region[3] = { width, height, depth }; 1727 const size_t region[3] = { width, height, depth };
797 EVENT_LIST (16, items - 16);
798 1728
1729 cl_event ev = 0;
799 NEED_SUCCESS (EnqueueCopyBufferRect, (this, src, dst, src_origin, dst_origin, region, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1730 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));
800 1731
801 if (ev) 1732 if (ev)
802 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1733 XPUSH_CLOBJ (stash_event, ev);
803 1734
804void 1735void
805enqueue_read_image (OpenCL::Queue this, OpenCL::Image src, cl_bool blocking, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...) 1736read_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, ...)
1737 ALIAS:
1738 enqueue_read_image = 0
806 PPCODE: 1739 PPCODE:
807 cl_event ev = 0; 1740 EVENT_LIST (12);
1741
808 const size_t src_origin[3] = { src_x, src_y, src_z }; 1742 const size_t src_origin[3] = { src_x, src_y, src_z };
809 const size_t region[3] = { width, height, depth }; 1743 const size_t region[3] = { width, height, depth };
810 EVENT_LIST (12, items - 12);
811 1744
812 if (!row_pitch) 1745 if (!row_pitch)
813 row_pitch = img_row_pitch (src); 1746 row_pitch = img_row_pitch (src);
814 1747
815 if (depth > 1 && !slice_pitch) 1748 if (depth > 1 && !slice_pitch)
819 1752
820 SvUPGRADE (data, SVt_PV); 1753 SvUPGRADE (data, SVt_PV);
821 SvGROW (data, len); 1754 SvGROW (data, len);
822 SvPOK_only (data); 1755 SvPOK_only (data);
823 SvCUR_set (data, len); 1756 SvCUR_set (data, len);
1757
1758 cl_event ev = 0;
824 NEED_SUCCESS (EnqueueReadImage, (this, src, blocking, src_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1759 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));
825 1760
826 if (ev) 1761 if (ev)
827 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1762 XPUSH_CLOBJ (stash_event, ev);
828 1763
829void 1764void
830enqueue_write_image (OpenCL::Queue this, OpenCL::Image dst, cl_bool blocking, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...) 1765write_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, ...)
1766 ALIAS:
1767 enqueue_write_image = 0
831 PPCODE: 1768 PPCODE:
832 cl_event ev = 0; 1769 EVENT_LIST (12);
1770
833 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 1771 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
834 const size_t region[3] = { width, height, depth }; 1772 const size_t region[3] = { width, height, depth };
835 STRLEN len; 1773 STRLEN len;
836 char *ptr = SvPVbyte (data, len); 1774 char *ptr = SvPVbyte (data, len);
837 EVENT_LIST (12, items - 12);
838 1775
839 if (!row_pitch) 1776 if (!row_pitch)
840 row_pitch = img_row_pitch (dst); 1777 row_pitch = img_row_pitch (dst);
841 1778
842 if (depth > 1 && !slice_pitch) 1779 if (depth > 1 && !slice_pitch)
845 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height; 1782 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height;
846 1783
847 if (len < min_len) 1784 if (len < min_len)
848 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1785 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
849 1786
1787 cl_event ev = 0;
850 NEED_SUCCESS (EnqueueWriteImage, (this, dst, blocking, dst_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1788 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));
851 1789
852 if (ev) 1790 if (ev)
853 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1791 XPUSH_CLOBJ (stash_event, ev);
854 1792
855void 1793void
856enqueue_copy_image (OpenCL::Queue this, 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, ...) 1794copy_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, ...)
1795 ALIAS:
1796 enqueue_copy_image = 0
857 PPCODE: 1797 PPCODE:
858 cl_event ev = 0; 1798 EVENT_LIST (12);
1799
859 const size_t src_origin[3] = { src_x, src_y, src_z }; 1800 const size_t src_origin[3] = { src_x, src_y, src_z };
860 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 1801 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
861 const size_t region[3] = { width, height, depth }; 1802 const size_t region[3] = { width, height, depth };
862 EVENT_LIST (12, items - 12);
863 1803
1804 cl_event ev = 0;
864 NEED_SUCCESS (EnqueueCopyImage, (this, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1805 NEED_SUCCESS (EnqueueCopyImage, (self, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
865 1806
866 if (ev) 1807 if (ev)
867 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1808 XPUSH_CLOBJ (stash_event, ev);
868 1809
869void 1810void
870enqueue_copy_image_to_buffer (OpenCL::Queue this, OpenCL::Image src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t dst_offset, ...) 1811copy_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, ...)
1812 ALIAS:
1813 enqueue_copy_image_to_buffer = 0
871 PPCODE: 1814 PPCODE:
1815 EVENT_LIST (10);
1816
1817 const size_t src_origin[3] = { src_x, src_y, src_z };
1818 const size_t region [3] = { width, height, depth };
1819
872 cl_event ev = 0; 1820 cl_event ev = 0;
1821 NEED_SUCCESS (EnqueueCopyImageToBuffer, (self, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1822
1823 if (ev)
1824 XPUSH_CLOBJ (stash_event, ev);
1825
1826void
1827copy_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, ...)
1828 ALIAS:
1829 enqueue_copy_buffer_to_image = 0
1830 PPCODE:
1831 EVENT_LIST (10);
1832
873 const size_t src_origin[3] = { src_x, src_y, src_z }; 1833 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
1834 const size_t region [3] = { width, height, depth };
1835
1836 cl_event ev = 0;
1837 NEED_SUCCESS (EnqueueCopyBufferToImage, (self, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1838
1839 if (ev)
1840 XPUSH_CLOBJ (stash_event, ev);
1841
1842void
1843map_buffer (OpenCL::Queue self, OpenCL::Buffer buf, cl_bool blocking = 1, cl_map_flags map_flags = CL_MAP_READ | CL_MAP_WRITE, size_t offset = 0, SV *cb_ = &PL_sv_undef, ...)
1844 ALIAS:
1845 enqueue_map_buffer = 0
1846 PPCODE:
1847 EVENT_LIST (6);
1848
1849 size_t cb = SvIV (cb_);
1850
1851 if (!SvOK (cb_))
1852 {
1853 NEED_SUCCESS (GetMemObjectInfo, (buf, CL_MEM_SIZE, sizeof (cb), &cb, 0));
1854 cb -= offset;
1855 }
1856
1857 cl_event ev;
1858 NEED_SUCCESS_ARG (void *ptr, EnqueueMapBuffer, (self, buf, blocking, map_flags, offset, cb, event_list_count, event_list_ptr, &ev, &res));
1859 XPUSHs (mapped_new (stash_mappedbuffer, self, buf, map_flags, ptr, cb, ev, 0, 0));
1860
1861void
1862map_image (OpenCL::Queue self, OpenCL::Image img, cl_bool blocking = 1, cl_map_flags map_flags = CL_MAP_READ | CL_MAP_WRITE, size_t x = 0, size_t y = 0, size_t z = 0, SV *width_ = &PL_sv_undef, SV *height_ = &PL_sv_undef, SV *depth_ = &PL_sv_undef, ...)
1863 ALIAS:
1864 enqueue_map_image = 0
1865 PPCODE:
1866 size_t width = SvIV (width_);
1867 if (!SvOK (width_))
1868 {
1869 NEED_SUCCESS (GetImageInfo, (img, CL_IMAGE_WIDTH, sizeof (width), &width, 0));
1870 width -= x;
1871 }
1872
1873 size_t height = SvIV (width_);
1874 if (!SvOK (height_))
1875 {
1876 NEED_SUCCESS (GetImageInfo, (img, CL_IMAGE_HEIGHT, sizeof (height), &height, 0));
1877 height -= y;
1878 }
1879
1880 size_t depth = SvIV (width_);
1881 if (!SvOK (depth_))
1882 {
1883 NEED_SUCCESS (GetImageInfo, (img, CL_IMAGE_DEPTH, sizeof (depth), &depth, 0));
1884 depth -= z;
1885
1886 // stupid opencl returns 0 for depth, but requires 1 for 2d images
1887 if (!depth)
1888 depth = 1;
1889 }
1890
1891 const size_t origin[3] = { x, y, z };
874 const size_t region[3] = { width, height, depth }; 1892 const size_t region[3] = { width, height, depth };
1893 size_t row_pitch, slice_pitch;
875 EVENT_LIST (10, items - 10); 1894 EVENT_LIST (10);
876 1895
877 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1896 cl_event ev;
1897 NEED_SUCCESS_ARG (void *ptr, EnqueueMapImage, (self, img, blocking, map_flags, origin, region, &row_pitch, &slice_pitch, event_list_count, event_list_ptr, &ev, &res));
1898
1899 size_t cb = slice_pitch ? slice_pitch * region [2]
1900 : row_pitch ? row_pitch * region [1]
1901 : region [0];
1902
1903 XPUSHs (mapped_new (stash_mappedimage, self, img, map_flags, ptr, cb, ev, row_pitch, slice_pitch));
1904
1905void
1906unmap (OpenCL::Queue self, OpenCL::Mapped mapped, ...)
1907 PPCODE:
1908 mapped_unmap (cv, ST (1), mapped, self, &ST (2), items - 2);
1909 if (GIMME_V != G_VOID)
1910 {
1911 clRetainEvent (mapped->event);
1912 XPUSH_CLOBJ (stash_event, mapped->event);
1913 }
1914
1915void
1916task (OpenCL::Queue self, OpenCL::Kernel kernel, ...)
1917 ALIAS:
1918 enqueue_task = 0
1919 PPCODE:
1920 EVENT_LIST (2);
1921
1922 cl_event ev = 0;
1923 NEED_SUCCESS (EnqueueTask, (self, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
878 1924
879 if (ev) 1925 if (ev)
880 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1926 XPUSH_CLOBJ (stash_event, ev);
881 1927
882void 1928void
883enqueue_copy_buffer_to_image (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Image dst, size_t src_offset, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...)
884 PPCODE:
885 cl_event ev = 0;
886 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
887 const size_t region[3] = { width, height, depth };
888 EVENT_LIST (10, items - 10);
889
890 NEED_SUCCESS (EnqueueCopyBufferToImage, (this, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
891
892 if (ev)
893 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
894
895void
896enqueue_task (OpenCL::Queue this, OpenCL::Kernel kernel, ...)
897 PPCODE:
898 cl_event ev = 0;
899 EVENT_LIST (2, items - 2);
900
901 NEED_SUCCESS (EnqueueTask, (this, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
902
903 if (ev)
904 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
905
906void
907enqueue_nd_range_kernel (OpenCL::Queue this, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...) 1929nd_range_kernel (OpenCL::Queue self, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...)
1930 ALIAS:
1931 enqueue_nd_range_kernel = 0
908 PPCODE: 1932 PPCODE:
909 cl_event ev = 0; 1933 EVENT_LIST (5);
1934
910 size_t *gwo = 0, *gws, *lws = 0; 1935 size_t *gwo = 0, *gws, *lws = 0;
911 int gws_len; 1936 int gws_len;
912 size_t *lists; 1937 size_t *lists;
913 int i; 1938 int i;
914 EVENT_LIST (5, items - 5);
915 1939
916 if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV) 1940 if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV)
917 croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference"); 1941 croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference");
918 1942
919 gws_len = AvFILLp (SvRV (global_work_size)) + 1; 1943 gws_len = AvFILLp (SvRV (global_work_size)) + 1;
920 1944
921 lists = tmpbuf (sizeof (size_t) * 3 * gws_len); 1945 lists = tmpbuf (sizeof (size_t) * 3 * gws_len);
922 1946
923 gws = lists + gws_len * 0; 1947 gws = lists + gws_len * 0;
924 for (i = 0; i < gws_len; ++i) 1948 for (i = 0; i < gws_len; ++i)
1949 {
925 gws [i] = SvIV (AvARRAY (SvRV (global_work_size))[i]); 1950 gws [i] = SvIV (AvARRAY (SvRV (global_work_size))[i]);
1951 // at least nvidia crashes for 0-sized work group sizes, work around
1952 if (!gws [i])
1953 croak ("clEnqueueNDRangeKernel: global_work_size[%d] is zero, must be non-zero", i);
1954 }
926 1955
927 if (SvOK (global_work_offset)) 1956 if (SvOK (global_work_offset))
928 { 1957 {
929 if (!SvROK (global_work_offset) || SvTYPE (SvRV (global_work_offset)) != SVt_PVAV) 1958 if (!SvROK (global_work_offset) || SvTYPE (SvRV (global_work_offset)) != SVt_PVAV)
930 croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array reference"); 1959 croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array reference");
937 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); 1966 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
938 } 1967 }
939 1968
940 if (SvOK (local_work_size)) 1969 if (SvOK (local_work_size))
941 { 1970 {
942 if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV) 1971 if ((SvOK (local_work_size) && !SvROK (local_work_size)) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV)
943 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference"); 1972 croak ("clEnqueueNDRangeKernel: local_work_size must be undef or an array reference");
944 1973
945 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) 1974 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len)
946 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size"); 1975 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
947 1976
948 lws = lists + gws_len * 2; 1977 lws = lists + gws_len * 2;
949 for (i = 0; i < gws_len; ++i) 1978 for (i = 0; i < gws_len; ++i)
1979 {
950 lws [i] = SvIV (AvARRAY (SvRV (local_work_size))[i]); 1980 lws [i] = SvIV (AvARRAY (SvRV (local_work_size))[i]);
1981 // at least nvidia crashes for 0-sized work group sizes, work around
1982 if (!lws [i])
1983 croak ("clEnqueueNDRangeKernel: local_work_size[%d] is zero, must be non-zero", i);
1984 }
951 } 1985 }
952 1986
1987 cl_event ev = 0;
953 NEED_SUCCESS (EnqueueNDRangeKernel, (this, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1988 NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
954 1989
955 if (ev) 1990 if (ev)
956 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1991 XPUSH_CLOBJ (stash_event, ev);
957 1992
1993#if CL_VERSION_1_2
1994
958void 1995void
959enqueue_marker (OpenCL::Queue this) 1996migrate_mem_objects (OpenCL::Queue self, SV *objects, cl_mem_migration_flags flags, ...)
1997 ALIAS:
1998 enqueue_migrate_mem_objects = 0
960 PPCODE: 1999 PPCODE:
2000 EVENT_LIST (3);
2001
2002 cl_uint obj_count;
2003 cl_mem *obj_list = object_list (cv, 0, "objects", objects, "OpenCL::Memory", &obj_count);
2004
2005 cl_event ev = 0;
2006 NEED_SUCCESS (EnqueueMigrateMemObjects, (self, obj_count, obj_list, flags, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
2007
2008 if (ev)
2009 XPUSH_CLOBJ (stash_event, ev);
2010
2011#endif
2012
2013#if cl_apple_gl_sharing || cl_khr_gl_sharing
2014
2015void
2016acquire_gl_objects (OpenCL::Queue self, SV *objects, ...)
2017 ALIAS:
2018 release_gl_objects = 1
2019 enqueue_acquire_gl_objects = 0
2020 enqueue_release_gl_objects = 1
2021 PPCODE:
2022 EVENT_LIST (2);
2023
2024 cl_uint obj_count;
2025 cl_mem *obj_list = object_list (cv, 0, "objects", objects, "OpenCL::Memory", &obj_count);
2026
961 cl_event ev; 2027 cl_event ev = 0;
962 NEED_SUCCESS (EnqueueMarker, (this, &ev));
963 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
964 2028
2029 if (ix)
2030 NEED_SUCCESS (EnqueueReleaseGLObjects, (self, obj_count, obj_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
2031 else
2032 NEED_SUCCESS (EnqueueAcquireGLObjects, (self, obj_count, obj_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
2033
2034 if (ev)
2035 XPUSH_CLOBJ (stash_event, ev);
2036
2037#endif
2038
965void 2039void
966enqueue_wait_for_events (OpenCL::Queue this, ...) 2040wait_for_events (OpenCL::Queue self, ...)
2041 ALIAS:
2042 enqueue_wait_for_events = 0
967 CODE: 2043 CODE:
968 EVENT_LIST (1, items - 1); 2044 EVENT_LIST (1);
2045#if PREFER_1_1
969 NEED_SUCCESS (EnqueueWaitForEvents, (this, event_list_count, event_list_ptr)); 2046 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr));
2047#else
2048 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, 0));
2049#endif
970 2050
971void 2051void
972enqueue_barrier (OpenCL::Queue this) 2052marker (OpenCL::Queue self, ...)
2053 ALIAS:
2054 enqueue_marker = 0
973 CODE: 2055 PPCODE:
2056 EVENT_LIST (1);
2057 cl_event ev = 0;
2058#if PREFER_1_1
2059 if (!event_list_count)
2060 NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0));
2061 else
2062#if CL_VERSION_1_2
2063 NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
2064#else
2065 {
2066 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); // also a barrier
2067 NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0));
2068 }
2069#endif
2070#else
2071 NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
2072#endif
2073 if (ev)
2074 XPUSH_CLOBJ (stash_event, ev);
2075
2076void
2077barrier (OpenCL::Queue self, ...)
2078 ALIAS:
2079 enqueue_barrier = 0
2080 PPCODE:
2081 EVENT_LIST (1);
2082 cl_event ev = 0;
2083#if PREFER_1_1
2084 if (!event_list_count && GIMME_V == G_VOID)
974 NEED_SUCCESS (EnqueueBarrier, (this)); 2085 NEED_SUCCESS (EnqueueBarrier, (self));
2086 else
2087#if CL_VERSION_1_2
2088 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
2089#else
2090 {
2091 if (event_list_count)
2092 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr));
975 2093
2094 if (GIMME_V != G_VOID)
2095 NEED_SUCCESS (EnqueueMarker, (self, &ev));
2096 }
2097#endif
2098#else
2099 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
2100#endif
2101 if (ev)
2102 XPUSH_CLOBJ (stash_event, ev);
2103
976void 2104void
977flush (OpenCL::Queue this) 2105flush (OpenCL::Queue self)
978 CODE: 2106 CODE:
979 NEED_SUCCESS (Flush, (this)); 2107 NEED_SUCCESS (Flush, (self));
980 2108
981void 2109void
982finish (OpenCL::Queue this) 2110finish (OpenCL::Queue self)
983 CODE: 2111 CODE:
984 NEED_SUCCESS (Finish, (this)); 2112 NEED_SUCCESS (Finish, (self));
985 2113
986void 2114void
987info (OpenCL::Queue this, cl_command_queue_info name) 2115info (OpenCL::Queue self, cl_command_queue_info name)
988 PPCODE: 2116 PPCODE:
989 INFO (CommandQueue) 2117 INFO (CommandQueue)
990 2118
991#BEGIN:command_queue 2119#BEGIN:command_queue
992 2120
993void 2121void
994context (OpenCL::Queue this) 2122context (OpenCL::Queue self)
995 PPCODE: 2123 PPCODE:
996 cl_context value [1]; 2124 cl_context value [1];
997 NEED_SUCCESS (GetCommandQueueInfo, (this, CL_QUEUE_CONTEXT, sizeof (value), value, 0)); 2125 NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_CONTEXT, sizeof (value), value, 0));
998 EXTEND (SP, 1); 2126 EXTEND (SP, 1);
999 const int i = 0; 2127 const int i = 0;
1000 { 2128 {
1001 NEED_SUCCESS (RetainContext, (value [i])); 2129 NEED_SUCCESS (RetainContext, (value [i]));
1002 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i])); 2130 PUSH_CLOBJ (stash_context, value [i]);
1003 } 2131 }
1004 2132
1005void 2133void
1006device (OpenCL::Queue this) 2134device (OpenCL::Queue self)
1007 PPCODE: 2135 PPCODE:
1008 cl_device_id value [1]; 2136 cl_device_id value [1];
1009 NEED_SUCCESS (GetCommandQueueInfo, (this, CL_QUEUE_DEVICE, sizeof (value), value, 0)); 2137 NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_DEVICE, sizeof (value), value, 0));
1010 EXTEND (SP, 1); 2138 EXTEND (SP, 1);
1011 const int i = 0; 2139 const int i = 0;
1012 { 2140 {
1013 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i])); 2141 PUSH_CLOBJ (stash_device, value [i]);
1014 } 2142 }
1015 2143
1016void 2144void
1017reference_count (OpenCL::Queue this) 2145reference_count (OpenCL::Queue self)
1018 PPCODE: 2146 PPCODE:
1019 cl_uint value [1]; 2147 cl_uint value [1];
1020 NEED_SUCCESS (GetCommandQueueInfo, (this, CL_QUEUE_REFERENCE_COUNT, sizeof (value), value, 0)); 2148 NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_REFERENCE_COUNT, sizeof (value), value, 0));
1021 EXTEND (SP, 1); 2149 EXTEND (SP, 1);
1022 const int i = 0; 2150 const int i = 0;
1023 PUSHs (sv_2mortal (newSVuv (value [i]))); 2151 PUSHs (sv_2mortal (newSVuv (value [i])));
1024 2152
1025void 2153void
1026properties (OpenCL::Queue this) 2154properties (OpenCL::Queue self)
1027 PPCODE: 2155 PPCODE:
1028 cl_command_queue_properties value [1]; 2156 cl_command_queue_properties value [1];
1029 NEED_SUCCESS (GetCommandQueueInfo, (this, CL_QUEUE_PROPERTIES, sizeof (value), value, 0)); 2157 NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_PROPERTIES, sizeof (value), value, 0));
1030 EXTEND (SP, 1); 2158 EXTEND (SP, 1);
1031 const int i = 0; 2159 const int i = 0;
1032 PUSHs (sv_2mortal (newSViv (value [i]))); 2160 PUSHs (sv_2mortal (newSVuv (value [i])));
1033 2161
1034#END:command_queue 2162#END:command_queue
1035 2163
1036MODULE = OpenCL PACKAGE = OpenCL::Memory 2164MODULE = OpenCL PACKAGE = OpenCL::Memory
1037 2165
1038void 2166void
1039DESTROY (OpenCL::Memory this) 2167DESTROY (OpenCL::Memory self)
1040 CODE: 2168 CODE:
1041 clReleaseMemObject (this); 2169 clReleaseMemObject (self);
1042 2170
1043void 2171void
1044info (OpenCL::Memory this, cl_mem_info name) 2172info (OpenCL::Memory self, cl_mem_info name)
1045 PPCODE: 2173 PPCODE:
1046 INFO (MemObject) 2174 INFO (MemObject)
1047 2175
1048#BEGIN:mem 2176#BEGIN:mem
1049 2177
1050void 2178void
1051type (OpenCL::Memory this) 2179type (OpenCL::Memory self)
1052 PPCODE: 2180 PPCODE:
1053 cl_mem_object_type value [1]; 2181 cl_mem_object_type value [1];
1054 NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_TYPE, sizeof (value), value, 0)); 2182 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_TYPE, sizeof (value), value, 0));
1055 EXTEND (SP, 1); 2183 EXTEND (SP, 1);
1056 const int i = 0; 2184 const int i = 0;
1057 PUSHs (sv_2mortal (newSViv (value [i]))); 2185 PUSHs (sv_2mortal (newSVuv (value [i])));
1058 2186
1059void 2187void
1060flags (OpenCL::Memory this) 2188flags (OpenCL::Memory self)
1061 PPCODE: 2189 PPCODE:
1062 cl_mem_flags value [1]; 2190 cl_mem_flags value [1];
1063 NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_FLAGS, sizeof (value), value, 0)); 2191 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_FLAGS, sizeof (value), value, 0));
1064 EXTEND (SP, 1); 2192 EXTEND (SP, 1);
1065 const int i = 0; 2193 const int i = 0;
1066 PUSHs (sv_2mortal (newSViv (value [i]))); 2194 PUSHs (sv_2mortal (newSVuv (value [i])));
1067 2195
1068void 2196void
1069size (OpenCL::Memory this) 2197size (OpenCL::Memory self)
1070 ALIAS: 2198 ALIAS:
1071 size = CL_MEM_SIZE 2199 size = CL_MEM_SIZE
1072 offset = CL_MEM_OFFSET 2200 offset = CL_MEM_OFFSET
1073 PPCODE: 2201 PPCODE:
1074 size_t value [1]; 2202 size_t value [1];
1075 NEED_SUCCESS (GetMemObjectInfo, (this, ix, sizeof (value), value, 0)); 2203 NEED_SUCCESS (GetMemObjectInfo, (self, ix, sizeof (value), value, 0));
1076 EXTEND (SP, 1); 2204 EXTEND (SP, 1);
1077 const int i = 0; 2205 const int i = 0;
1078 PUSHs (sv_2mortal (newSVuv (value [i]))); 2206 PUSHs (sv_2mortal (newSVuv (value [i])));
1079 2207
1080void 2208void
1081host_ptr (OpenCL::Memory this) 2209host_ptr (OpenCL::Memory self)
1082 PPCODE: 2210 PPCODE:
1083 void * value [1]; 2211 void * value [1];
1084 NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_HOST_PTR, sizeof (value), value, 0)); 2212 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_HOST_PTR, sizeof (value), value, 0));
1085 EXTEND (SP, 1); 2213 EXTEND (SP, 1);
1086 const int i = 0; 2214 const int i = 0;
1087 PUSHs (sv_2mortal (newSVuv ((IV)(intptr_t)value [i]))); 2215 PUSHs (sv_2mortal (newSVuv ((IV)(intptr_t)value [i])));
1088 2216
1089void 2217void
1090map_count (OpenCL::Memory this) 2218map_count (OpenCL::Memory self)
1091 ALIAS: 2219 ALIAS:
1092 map_count = CL_MEM_MAP_COUNT 2220 map_count = CL_MEM_MAP_COUNT
1093 reference_count = CL_MEM_REFERENCE_COUNT 2221 reference_count = CL_MEM_REFERENCE_COUNT
1094 PPCODE: 2222 PPCODE:
1095 cl_uint value [1]; 2223 cl_uint value [1];
1096 NEED_SUCCESS (GetMemObjectInfo, (this, ix, sizeof (value), value, 0)); 2224 NEED_SUCCESS (GetMemObjectInfo, (self, ix, sizeof (value), value, 0));
1097 EXTEND (SP, 1); 2225 EXTEND (SP, 1);
1098 const int i = 0; 2226 const int i = 0;
1099 PUSHs (sv_2mortal (newSVuv (value [i]))); 2227 PUSHs (sv_2mortal (newSVuv (value [i])));
1100 2228
1101void 2229void
1102context (OpenCL::Memory this) 2230context (OpenCL::Memory self)
1103 PPCODE: 2231 PPCODE:
1104 cl_context value [1]; 2232 cl_context value [1];
1105 NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_CONTEXT, sizeof (value), value, 0)); 2233 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_CONTEXT, sizeof (value), value, 0));
1106 EXTEND (SP, 1); 2234 EXTEND (SP, 1);
1107 const int i = 0; 2235 const int i = 0;
1108 { 2236 {
1109 NEED_SUCCESS (RetainContext, (value [i])); 2237 NEED_SUCCESS (RetainContext, (value [i]));
1110 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i])); 2238 PUSH_CLOBJ (stash_context, value [i]);
1111 } 2239 }
1112 2240
1113void 2241void
1114associated_memobject (OpenCL::Memory this) 2242associated_memobject (OpenCL::Memory self)
1115 PPCODE: 2243 PPCODE:
1116 cl_mem value [1]; 2244 cl_mem value [1];
1117 NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_ASSOCIATED_MEMOBJECT, sizeof (value), value, 0)); 2245 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_ASSOCIATED_MEMOBJECT, sizeof (value), value, 0));
1118 EXTEND (SP, 1); 2246 EXTEND (SP, 1);
1119 const int i = 0; 2247 const int i = 0;
1120 { 2248 {
1121 NEED_SUCCESS (RetainMemObject, (value [i])); 2249 NEED_SUCCESS (RetainMemObject, (value [i]));
1122 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i])); 2250 PUSH_CLOBJ (stash_memory, value [i]);
1123 } 2251 }
1124 2252
1125#END:mem 2253#END:mem
1126 2254
2255#if cl_apple_gl_sharing || cl_khr_gl_sharing
2256
2257void
2258gl_object_info (OpenCL::Memory self)
2259 PPCODE:
2260 cl_gl_object_type type;
2261 cl_GLuint name;
2262 NEED_SUCCESS (GetGLObjectInfo, (self, &type, &name));
2263 EXTEND (SP, 2);
2264 PUSHs (sv_2mortal (newSVuv (type)));
2265 PUSHs (sv_2mortal (newSVuv (name)));
2266
2267#endif
2268
1127MODULE = OpenCL PACKAGE = OpenCL::BufferObj 2269MODULE = OpenCL PACKAGE = OpenCL::BufferObj
1128 2270
1129void 2271void
1130sub_buffer_region (OpenCL::BufferObj this, cl_mem_flags flags, size_t origin, size_t size) 2272sub_buffer_region (OpenCL::BufferObj self, cl_mem_flags flags, size_t origin, size_t size)
1131 PPCODE: 2273 PPCODE:
1132 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_ALLOC_HOST_PTR)) 2274 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_ALLOC_HOST_PTR))
1133 croak ("clCreateSubBuffer: cannot use/copy/alloc host ptr, doesn't make sense, check your flags!"); 2275 croak ("clCreateSubBuffer: cannot use/copy/alloc host ptr, doesn't make sense, check your flags!");
1134 2276
1135 cl_buffer_region crdata = { origin, size }; 2277 cl_buffer_region crdata = { origin, size };
1136 2278
1137 NEED_SUCCESS_ARG (cl_mem mem, CreateSubBuffer, (this, flags, CL_BUFFER_CREATE_TYPE_REGION, &crdata, &res)); 2279 NEED_SUCCESS_ARG (cl_mem mem, CreateSubBuffer, (self, flags, CL_BUFFER_CREATE_TYPE_REGION, &crdata, &res));
1138 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); 2280 XPUSH_CLOBJ (stash_buffer, mem);
1139 2281
1140MODULE = OpenCL PACKAGE = OpenCL::Image 2282MODULE = OpenCL PACKAGE = OpenCL::Image
1141 2283
1142void 2284void
1143image_info (OpenCL::Image this, cl_image_info name) 2285image_info (OpenCL::Image self, cl_image_info name)
1144 PPCODE: 2286 PPCODE:
1145 INFO (Image) 2287 INFO (Image)
1146 2288
2289void
2290format (OpenCL::Image self)
2291 PPCODE:
2292 cl_image_format format;
2293 NEED_SUCCESS (GetImageInfo, (self, CL_IMAGE_FORMAT, sizeof (format), &format, 0));
2294 EXTEND (SP, 2);
2295 PUSHs (sv_2mortal (newSVuv (format.image_channel_order)));
2296 PUSHs (sv_2mortal (newSVuv (format.image_channel_data_type)));
2297
1147#BEGIN:image 2298#BEGIN:image
1148 2299
1149void 2300void
1150element_size (OpenCL::Image this) 2301element_size (OpenCL::Image self)
1151 ALIAS: 2302 ALIAS:
1152 element_size = CL_IMAGE_ELEMENT_SIZE 2303 element_size = CL_IMAGE_ELEMENT_SIZE
1153 row_pitch = CL_IMAGE_ROW_PITCH 2304 row_pitch = CL_IMAGE_ROW_PITCH
1154 slice_pitch = CL_IMAGE_SLICE_PITCH 2305 slice_pitch = CL_IMAGE_SLICE_PITCH
1155 width = CL_IMAGE_WIDTH 2306 width = CL_IMAGE_WIDTH
1156 height = CL_IMAGE_HEIGHT 2307 height = CL_IMAGE_HEIGHT
1157 depth = CL_IMAGE_DEPTH 2308 depth = CL_IMAGE_DEPTH
1158 PPCODE: 2309 PPCODE:
1159 size_t value [1]; 2310 size_t value [1];
1160 NEED_SUCCESS (GetImageInfo, (this, ix, sizeof (value), value, 0)); 2311 NEED_SUCCESS (GetImageInfo, (self, ix, sizeof (value), value, 0));
1161 EXTEND (SP, 1); 2312 EXTEND (SP, 1);
1162 const int i = 0; 2313 const int i = 0;
1163 PUSHs (sv_2mortal (newSVuv (value [i]))); 2314 PUSHs (sv_2mortal (newSVuv (value [i])));
1164 2315
1165#END:image 2316#END:image
1166 2317
2318#if cl_apple_gl_sharing || cl_khr_gl_sharing
2319
2320#BEGIN:gl_texture
2321
2322void
2323target (OpenCL::Image self)
2324 PPCODE:
2325 cl_GLenum value [1];
2326 NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0));
2327 EXTEND (SP, 1);
2328 const int i = 0;
2329 PUSHs (sv_2mortal (newSVuv (value [i])));
2330
2331void
2332gl_mipmap_level (OpenCL::Image self)
2333 PPCODE:
2334 cl_GLint value [1];
2335 NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0));
2336 EXTEND (SP, 1);
2337 const int i = 0;
2338 PUSHs (sv_2mortal (newSViv (value [i])));
2339
2340#END:gl_texture
2341
2342#endif
2343
1167MODULE = OpenCL PACKAGE = OpenCL::Sampler 2344MODULE = OpenCL PACKAGE = OpenCL::Sampler
1168 2345
1169void 2346void
1170DESTROY (OpenCL::Sampler this) 2347DESTROY (OpenCL::Sampler self)
1171 CODE: 2348 CODE:
1172 clReleaseSampler (this); 2349 clReleaseSampler (self);
1173 2350
1174void 2351void
1175info (OpenCL::Sampler this, cl_sampler_info name) 2352info (OpenCL::Sampler self, cl_sampler_info name)
1176 PPCODE: 2353 PPCODE:
1177 INFO (Sampler) 2354 INFO (Sampler)
1178 2355
1179#BEGIN:sampler 2356#BEGIN:sampler
1180 2357
1181void 2358void
1182reference_count (OpenCL::Sampler this) 2359reference_count (OpenCL::Sampler self)
1183 PPCODE: 2360 PPCODE:
1184 cl_uint value [1]; 2361 cl_uint value [1];
1185 NEED_SUCCESS (GetSamplerInfo, (this, CL_SAMPLER_REFERENCE_COUNT, sizeof (value), value, 0)); 2362 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_REFERENCE_COUNT, sizeof (value), value, 0));
1186 EXTEND (SP, 1); 2363 EXTEND (SP, 1);
1187 const int i = 0; 2364 const int i = 0;
1188 PUSHs (sv_2mortal (newSVuv (value [i]))); 2365 PUSHs (sv_2mortal (newSVuv (value [i])));
1189 2366
1190void 2367void
1191context (OpenCL::Sampler this) 2368context (OpenCL::Sampler self)
1192 PPCODE: 2369 PPCODE:
1193 cl_context value [1]; 2370 cl_context value [1];
1194 NEED_SUCCESS (GetSamplerInfo, (this, CL_SAMPLER_CONTEXT, sizeof (value), value, 0)); 2371 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_CONTEXT, sizeof (value), value, 0));
1195 EXTEND (SP, 1); 2372 EXTEND (SP, 1);
1196 const int i = 0; 2373 const int i = 0;
1197 { 2374 {
1198 NEED_SUCCESS (RetainContext, (value [i])); 2375 NEED_SUCCESS (RetainContext, (value [i]));
1199 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i])); 2376 PUSH_CLOBJ (stash_context, value [i]);
1200 } 2377 }
1201 2378
1202void 2379void
1203normalized_coords (OpenCL::Sampler this) 2380normalized_coords (OpenCL::Sampler self)
1204 PPCODE: 2381 PPCODE:
1205 cl_addressing_mode value [1]; 2382 cl_addressing_mode value [1];
1206 NEED_SUCCESS (GetSamplerInfo, (this, CL_SAMPLER_NORMALIZED_COORDS, sizeof (value), value, 0)); 2383 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_NORMALIZED_COORDS, sizeof (value), value, 0));
1207 EXTEND (SP, 1); 2384 EXTEND (SP, 1);
1208 const int i = 0; 2385 const int i = 0;
1209 PUSHs (sv_2mortal (newSViv (value [i]))); 2386 PUSHs (sv_2mortal (newSVuv (value [i])));
1210 2387
1211void 2388void
1212addressing_mode (OpenCL::Sampler this) 2389addressing_mode (OpenCL::Sampler self)
1213 PPCODE: 2390 PPCODE:
1214 cl_filter_mode value [1]; 2391 cl_filter_mode value [1];
1215 NEED_SUCCESS (GetSamplerInfo, (this, CL_SAMPLER_ADDRESSING_MODE, sizeof (value), value, 0)); 2392 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_ADDRESSING_MODE, sizeof (value), value, 0));
1216 EXTEND (SP, 1); 2393 EXTEND (SP, 1);
1217 const int i = 0; 2394 const int i = 0;
1218 PUSHs (sv_2mortal (newSViv (value [i]))); 2395 PUSHs (sv_2mortal (newSVuv (value [i])));
1219 2396
1220void 2397void
1221filter_mode (OpenCL::Sampler this) 2398filter_mode (OpenCL::Sampler self)
1222 PPCODE: 2399 PPCODE:
1223 cl_bool value [1]; 2400 cl_bool value [1];
1224 NEED_SUCCESS (GetSamplerInfo, (this, CL_SAMPLER_FILTER_MODE, sizeof (value), value, 0)); 2401 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_FILTER_MODE, sizeof (value), value, 0));
1225 EXTEND (SP, 1); 2402 EXTEND (SP, 1);
1226 const int i = 0; 2403 const int i = 0;
1227 PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no)); 2404 PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no));
1228 2405
1229#END:sampler 2406#END:sampler
1230 2407
1231MODULE = OpenCL PACKAGE = OpenCL::Program 2408MODULE = OpenCL PACKAGE = OpenCL::Program
1232 2409
1233void 2410void
1234DESTROY (OpenCL::Program this) 2411DESTROY (OpenCL::Program self)
1235 CODE: 2412 CODE:
1236 clReleaseProgram (this); 2413 clReleaseProgram (self);
1237 2414
1238void 2415void
1239build (OpenCL::Program this, OpenCL::Device device, SV *options = &PL_sv_undef) 2416build (OpenCL::Program self, SV *devices = &PL_sv_undef, SV *options = &PL_sv_undef, SV *notify = &PL_sv_undef)
2417 ALIAS:
2418 build_async = 1
1240 CODE: 2419 CODE:
2420 cl_uint device_count = 0;
2421 cl_device_id *device_list = 0;
2422
2423 if (SvOK (devices))
2424 device_list = object_list (cv, 1, "devices", devices, "OpenCL::Device", &device_count);
2425
2426 void *user_data;
2427 program_callback pfn_notify = make_program_callback (notify, &user_data);
2428
2429 if (ix)
2430 build_program_async (self, device_count, device_list, SvPVbyte_nolen (options), user_data);
2431 else
2432 NEED_SUCCESS (BuildProgram, (self, device_count, device_list, SvPVbyte_nolen (options), pfn_notify, user_data));
2433
2434#if CL_VERSION_1_2
2435
2436void
2437compile (OpenCL::Program self, SV *devices, SV *options = &PL_sv_undef, SV *headers = &PL_sv_undef, SV *notify = &PL_sv_undef)
2438 CODE:
2439 cl_uint device_count = 0;
2440 cl_device_id *device_list = 0;
2441
2442 if (SvOK (devices))
2443 device_list = object_list (cv, 1, "devices", devices, "OpenCL::Device", &device_count);
2444
2445 cl_uint header_count = 0;
2446 cl_program *header_list = 0;
2447 const char **header_name = 0;
2448
2449 if (SvOK (headers))
2450 {
2451 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVHV)
2452 croak ("clCompileProgram: headers must be undef or a hashref of name => OpenCL::Program pairs");
2453
2454 HV *hv = (HV *)SvRV (devices);
2455
2456 header_count = hv_iterinit (hv);
2457 header_list = tmpbuf (sizeof (*header_list) * header_count);
2458 header_name = tmpbuf (sizeof (*header_name) * header_count);
2459
2460 HE *he;
2461 int i = 0;
2462 while (he = hv_iternext (hv))
2463 {
2464 header_name [i] = SvPVbyte_nolen (HeSVKEY_force (he));
2465 header_list [i] = SvCLOBJ (cv, "headers", HeVAL (he), "OpenCL::Program");
2466 ++i;
2467 }
2468 }
2469
2470 void *user_data;
2471 program_callback pfn_notify = make_program_callback (notify, &user_data);
2472
1241 NEED_SUCCESS (BuildProgram, (this, 1, &device, SvPVbyte_nolen (options), 0, 0)); 2473 NEED_SUCCESS (CompileProgram, (self, device_count, device_list, SvPVbyte_nolen (options),
2474 header_count, header_list, header_name, pfn_notify, user_data));
1242 2475
2476#endif
2477
1243void 2478void
1244build_info (OpenCL::Program this, OpenCL::Device device, cl_program_build_info name) 2479build_info (OpenCL::Program self, OpenCL::Device device, cl_program_build_info name)
1245 PPCODE: 2480 PPCODE:
1246 size_t size; 2481 size_t size;
1247 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, 0, 0, &size)); 2482 NEED_SUCCESS (GetProgramBuildInfo, (self, device, name, 0, 0, &size));
1248 SV *sv = sv_2mortal (newSV (size)); 2483 SV *sv = sv_2mortal (newSV (size));
1249 SvUPGRADE (sv, SVt_PV); 2484 SvUPGRADE (sv, SVt_PV);
1250 SvPOK_only (sv); 2485 SvPOK_only (sv);
1251 SvCUR_set (sv, size); 2486 SvCUR_set (sv, size);
1252 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, size, SvPVX (sv), 0)); 2487 NEED_SUCCESS (GetProgramBuildInfo, (self, device, name, size, SvPVX (sv), 0));
1253 XPUSHs (sv); 2488 XPUSHs (sv);
1254 2489
1255#BEGIN:program_build 2490#BEGIN:program_build
1256 2491
1257void 2492void
1258build_status (OpenCL::Program this, OpenCL::Device device) 2493build_status (OpenCL::Program self, OpenCL::Device device)
1259 PPCODE: 2494 PPCODE:
1260 cl_build_status value [1]; 2495 cl_build_status value [1];
1261 NEED_SUCCESS (GetProgramBuildInfo, (this, device, CL_PROGRAM_BUILD_STATUS, sizeof (value), value, 0)); 2496 NEED_SUCCESS (GetProgramBuildInfo, (self, device, CL_PROGRAM_BUILD_STATUS, sizeof (value), value, 0));
1262 EXTEND (SP, 1); 2497 EXTEND (SP, 1);
1263 const int i = 0; 2498 const int i = 0;
1264 PUSHs (sv_2mortal (newSViv (value [i]))); 2499 PUSHs (sv_2mortal (newSViv (value [i])));
1265 2500
1266void 2501void
1267build_options (OpenCL::Program this, OpenCL::Device device) 2502build_options (OpenCL::Program self, OpenCL::Device device)
1268 ALIAS: 2503 ALIAS:
1269 build_options = CL_PROGRAM_BUILD_OPTIONS 2504 build_options = CL_PROGRAM_BUILD_OPTIONS
1270 build_log = CL_PROGRAM_BUILD_LOG 2505 build_log = CL_PROGRAM_BUILD_LOG
1271 PPCODE: 2506 PPCODE:
1272 size_t size; 2507 size_t size;
1273 NEED_SUCCESS (GetProgramBuildInfo, (this, device, ix, 0, 0, &size)); 2508 NEED_SUCCESS (GetProgramBuildInfo, (self, device, ix, 0, 0, &size));
1274 char *value = tmpbuf (size); 2509 char *value = tmpbuf (size);
1275 NEED_SUCCESS (GetProgramBuildInfo, (this, device, ix, size, value, 0)); 2510 NEED_SUCCESS (GetProgramBuildInfo, (self, device, ix, size, value, 0));
1276 EXTEND (SP, 1); 2511 EXTEND (SP, 1);
1277 const int i = 0; 2512 const int i = 0;
1278 PUSHs (sv_2mortal (newSVpv (value, 0))); 2513 PUSHs (sv_2mortal (newSVpv (value, 0)));
1279 2514
1280#END:program_build 2515#END:program_build
1281 2516
1282void 2517void
1283kernel (OpenCL::Program program, SV *function) 2518kernel (OpenCL::Program program, SV *function)
1284 PPCODE: 2519 PPCODE:
1285 NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res)); 2520 NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res));
1286 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel); 2521 XPUSH_CLOBJ (stash_kernel, kernel);
1287 2522
1288void 2523void
2524kernels_in_program (OpenCL::Program program)
2525 PPCODE:
2526 cl_uint num_kernels;
2527 NEED_SUCCESS (CreateKernelsInProgram, (program, 0, 0, &num_kernels));
2528 cl_kernel *kernels = tmpbuf (sizeof (cl_kernel) * num_kernels);
2529 NEED_SUCCESS (CreateKernelsInProgram, (program, num_kernels, kernels, 0));
2530
2531 int i;
2532 EXTEND (SP, num_kernels);
2533 for (i = 0; i < num_kernels; ++i)
2534 PUSH_CLOBJ (stash_kernel, kernels [i]);
2535
2536void
1289info (OpenCL::Program this, cl_program_info name) 2537info (OpenCL::Program self, cl_program_info name)
1290 PPCODE: 2538 PPCODE:
1291 INFO (Program) 2539 INFO (Program)
1292 2540
1293void 2541void
1294binaries (OpenCL::Program this) 2542binaries (OpenCL::Program self)
1295 PPCODE: 2543 PPCODE:
1296 cl_uint n, i; 2544 cl_uint n, i;
1297 size_t size; 2545 size_t size;
1298 2546
1299 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_NUM_DEVICES , sizeof (n) , &n , 0)); 2547 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_NUM_DEVICES , sizeof (n) , &n , 0));
1300 if (!n) XSRETURN_EMPTY; 2548 if (!n) XSRETURN_EMPTY;
1301 2549
1302 size_t *sizes = tmpbuf (sizeof (*sizes) * n); 2550 size_t *sizes = tmpbuf (sizeof (*sizes) * n);
1303 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_BINARY_SIZES, sizeof (*sizes) * n, sizes, &size)); 2551 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARY_SIZES, sizeof (*sizes) * n, sizes, &size));
1304 if (size != sizeof (*sizes) * n) XSRETURN_EMPTY; 2552 if (size != sizeof (*sizes) * n) XSRETURN_EMPTY;
1305 unsigned char **ptrs = tmpbuf (sizeof (*ptrs) * n); 2553 unsigned char **ptrs = tmpbuf (sizeof (*ptrs) * n);
1306 2554
1307 EXTEND (SP, n); 2555 EXTEND (SP, n);
1308 for (i = 0; i < n; ++i) 2556 for (i = 0; i < n; ++i)
1309 { 2557 {
1310 SV *sv = sv_2mortal (newSV (sizes [i])); 2558 SV *sv = sv_2mortal (newSV (sizes [i]));
1311 SvUPGRADE (sv, SVt_PV); 2559 SvUPGRADE (sv, SVt_PV);
1312 SvPOK_only (sv); 2560 SvPOK_only (sv);
1313 SvCUR_set (sv, sizes [i]); 2561 SvCUR_set (sv, sizes [i]);
1314 ptrs [i] = SvPVX (sv); 2562 ptrs [i] = (void *)SvPVX (sv);
1315 PUSHs (sv); 2563 PUSHs (sv);
1316 } 2564 }
1317 2565
1318 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size)); 2566 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size));
1319 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; 2567 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY;
1320 2568
1321#BEGIN:program 2569#BEGIN:program
1322 2570
1323void 2571void
1324reference_count (OpenCL::Program this) 2572reference_count (OpenCL::Program self)
1325 ALIAS: 2573 ALIAS:
1326 reference_count = CL_PROGRAM_REFERENCE_COUNT 2574 reference_count = CL_PROGRAM_REFERENCE_COUNT
1327 num_devices = CL_PROGRAM_NUM_DEVICES 2575 num_devices = CL_PROGRAM_NUM_DEVICES
1328 PPCODE: 2576 PPCODE:
1329 cl_uint value [1]; 2577 cl_uint value [1];
1330 NEED_SUCCESS (GetProgramInfo, (this, ix, sizeof (value), value, 0)); 2578 NEED_SUCCESS (GetProgramInfo, (self, ix, sizeof (value), value, 0));
1331 EXTEND (SP, 1); 2579 EXTEND (SP, 1);
1332 const int i = 0; 2580 const int i = 0;
1333 PUSHs (sv_2mortal (newSVuv (value [i]))); 2581 PUSHs (sv_2mortal (newSVuv (value [i])));
1334 2582
1335void 2583void
1336context (OpenCL::Program this) 2584context (OpenCL::Program self)
1337 PPCODE: 2585 PPCODE:
1338 cl_context value [1]; 2586 cl_context value [1];
1339 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_CONTEXT, sizeof (value), value, 0)); 2587 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_CONTEXT, sizeof (value), value, 0));
1340 EXTEND (SP, 1); 2588 EXTEND (SP, 1);
1341 const int i = 0; 2589 const int i = 0;
1342 { 2590 {
1343 NEED_SUCCESS (RetainContext, (value [i])); 2591 NEED_SUCCESS (RetainContext, (value [i]));
1344 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i])); 2592 PUSH_CLOBJ (stash_context, value [i]);
1345 } 2593 }
1346 2594
1347void 2595void
1348devices (OpenCL::Program this) 2596devices (OpenCL::Program self)
1349 PPCODE: 2597 PPCODE:
1350 size_t size; 2598 size_t size;
1351 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_DEVICES, 0, 0, &size)); 2599 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_DEVICES, 0, 0, &size));
1352 cl_device_id *value = tmpbuf (size); 2600 cl_device_id *value = tmpbuf (size);
1353 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_DEVICES, size, value, 0)); 2601 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_DEVICES, size, value, 0));
1354 int i, n = size / sizeof (*value); 2602 int i, n = size / sizeof (*value);
1355 EXTEND (SP, n); 2603 EXTEND (SP, n);
1356 for (i = 0; i < n; ++i) 2604 for (i = 0; i < n; ++i)
1357 { 2605 {
1358 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i])); 2606 PUSH_CLOBJ (stash_device, value [i]);
1359 } 2607 }
1360 2608
1361void 2609void
1362source (OpenCL::Program this) 2610source (OpenCL::Program self)
1363 PPCODE: 2611 PPCODE:
1364 size_t size; 2612 size_t size;
1365 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_SOURCE, 0, 0, &size)); 2613 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_SOURCE, 0, 0, &size));
1366 char *value = tmpbuf (size); 2614 char *value = tmpbuf (size);
1367 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_SOURCE, size, value, 0)); 2615 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_SOURCE, size, value, 0));
1368 EXTEND (SP, 1); 2616 EXTEND (SP, 1);
1369 const int i = 0; 2617 const int i = 0;
1370 PUSHs (sv_2mortal (newSVpv (value, 0))); 2618 PUSHs (sv_2mortal (newSVpv (value, 0)));
1371 2619
1372void 2620void
1373binary_sizes (OpenCL::Program this) 2621binary_sizes (OpenCL::Program self)
1374 PPCODE: 2622 PPCODE:
1375 size_t size; 2623 size_t size;
1376 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_BINARY_SIZES, 0, 0, &size)); 2624 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARY_SIZES, 0, 0, &size));
1377 size_t *value = tmpbuf (size); 2625 size_t *value = tmpbuf (size);
1378 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_BINARY_SIZES, size, value, 0)); 2626 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARY_SIZES, size, value, 0));
1379 int i, n = size / sizeof (*value); 2627 int i, n = size / sizeof (*value);
1380 EXTEND (SP, n); 2628 EXTEND (SP, n);
1381 for (i = 0; i < n; ++i) 2629 for (i = 0; i < n; ++i)
1382 PUSHs (sv_2mortal (newSVuv (value [i]))); 2630 PUSHs (sv_2mortal (newSVuv (value [i])));
1383 2631
1384#END:program 2632#END:program
1385 2633
1386MODULE = OpenCL PACKAGE = OpenCL::Kernel 2634MODULE = OpenCL PACKAGE = OpenCL::Kernel
1387 2635
1388void 2636void
1389DESTROY (OpenCL::Kernel this) 2637DESTROY (OpenCL::Kernel self)
1390 CODE: 2638 CODE:
1391 clReleaseKernel (this); 2639 clReleaseKernel (self);
1392 2640
1393void 2641void
2642setf (OpenCL::Kernel self, const char *format, ...)
2643 CODE:
2644 int i;
2645 for (i = 2; ; ++i)
2646 {
2647 while (*format == ' ')
2648 ++format;
2649
2650 char type = *format++;
2651
2652 if (!type)
2653 break;
2654
2655 if (i >= items)
2656 croak ("OpenCL::Kernel::setf format string too long (not enough arguments)");
2657
2658 SV *sv = ST (i);
2659
2660 union
2661 {
2662 cl_char cc; cl_uchar cC; cl_short cs; cl_ushort cS;
2663 cl_int ci; cl_uint cI; cl_long cl; cl_ulong cL;
2664 cl_half ch; cl_float cf; cl_double cd;
2665 cl_mem cm;
2666 cl_sampler ca;
2667 size_t cz;
2668 cl_event ce;
2669 } arg;
2670 size_t size;
2671 int nullarg = 0;
2672
2673 switch (type)
2674 {
2675 case 'c': arg.cc = SvIV (sv); size = sizeof (arg.cc); break;
2676 case 'C': arg.cC = SvUV (sv); size = sizeof (arg.cC); break;
2677 case 's': arg.cs = SvIV (sv); size = sizeof (arg.cs); break;
2678 case 'S': arg.cS = SvUV (sv); size = sizeof (arg.cS); break;
2679 case 'i': arg.ci = SvIV (sv); size = sizeof (arg.ci); break;
2680 case 'I': arg.cI = SvUV (sv); size = sizeof (arg.cI); break;
2681 case 'l': arg.cl = SvIV (sv); size = sizeof (arg.cl); break;
2682 case 'L': arg.cL = SvUV (sv); size = sizeof (arg.cL); break;
2683
2684 case 'h': arg.ch = SvUV (sv); size = sizeof (arg.ch); break;
2685 case 'f': arg.cf = SvNV (sv); size = sizeof (arg.cf); break;
2686 case 'd': arg.cd = SvNV (sv); size = sizeof (arg.cd); break;
2687
2688 case 'z': nullarg = 1; size = SvIV (sv); break;
2689
2690 case 'm': nullarg = !SvOK (sv); arg.cm = SvCLOBJ (cv, "m", sv, "OpenCL::Memory" ); size = sizeof (arg.cm); break;
2691 case 'a': nullarg = !SvOK (sv); arg.ca = SvCLOBJ (cv, "a", sv, "OpenCL::Sampler"); size = sizeof (arg.ca); break;
2692 case 'e': nullarg = !SvOK (sv); arg.ca = SvCLOBJ (cv, "e", sv, "OpenCL::Event" ); size = sizeof (arg.ce); break;
2693
2694 default:
2695 croak ("OpenCL::Kernel::setf format character '%c' not supported", type);
2696 }
2697
2698 res = clSetKernelArg (self, i - 2, size, nullarg ? 0 : &arg);
2699 if (res)
2700 croak ("OpenCL::Kernel::setf kernel parameter '%c' (#%d): %s", type, i - 2, err2str (res));
2701 }
2702
2703 if (i != items)
2704 croak ("OpenCL::Kernel::setf format string too short (too many arguments)");
2705
2706void
1394set_char (OpenCL::Kernel this, cl_uint idx, cl_char value) 2707set_char (OpenCL::Kernel self, cl_uint idx, cl_char value)
1395 CODE: 2708 CODE:
1396 clSetKernelArg (this, idx, sizeof (value), &value); 2709 clSetKernelArg (self, idx, sizeof (value), &value);
1397 2710
1398void 2711void
1399set_uchar (OpenCL::Kernel this, cl_uint idx, cl_uchar value) 2712set_uchar (OpenCL::Kernel self, cl_uint idx, cl_uchar value)
1400 CODE: 2713 CODE:
1401 clSetKernelArg (this, idx, sizeof (value), &value); 2714 clSetKernelArg (self, idx, sizeof (value), &value);
1402 2715
1403void 2716void
1404set_short (OpenCL::Kernel this, cl_uint idx, cl_short value) 2717set_short (OpenCL::Kernel self, cl_uint idx, cl_short value)
1405 CODE: 2718 CODE:
1406 clSetKernelArg (this, idx, sizeof (value), &value); 2719 clSetKernelArg (self, idx, sizeof (value), &value);
1407 2720
1408void 2721void
1409set_ushort (OpenCL::Kernel this, cl_uint idx, cl_ushort value) 2722set_ushort (OpenCL::Kernel self, cl_uint idx, cl_ushort value)
1410 CODE: 2723 CODE:
1411 clSetKernelArg (this, idx, sizeof (value), &value); 2724 clSetKernelArg (self, idx, sizeof (value), &value);
1412 2725
1413void 2726void
1414set_int (OpenCL::Kernel this, cl_uint idx, cl_int value) 2727set_int (OpenCL::Kernel self, cl_uint idx, cl_int value)
1415 CODE: 2728 CODE:
1416 clSetKernelArg (this, idx, sizeof (value), &value); 2729 clSetKernelArg (self, idx, sizeof (value), &value);
1417 2730
1418void 2731void
1419set_uint (OpenCL::Kernel this, cl_uint idx, cl_uint value) 2732set_uint (OpenCL::Kernel self, cl_uint idx, cl_uint value)
1420 CODE: 2733 CODE:
1421 clSetKernelArg (this, idx, sizeof (value), &value); 2734 clSetKernelArg (self, idx, sizeof (value), &value);
1422 2735
1423void 2736void
1424set_long (OpenCL::Kernel this, cl_uint idx, cl_long value) 2737set_long (OpenCL::Kernel self, cl_uint idx, cl_long value)
1425 CODE: 2738 CODE:
1426 clSetKernelArg (this, idx, sizeof (value), &value); 2739 clSetKernelArg (self, idx, sizeof (value), &value);
1427 2740
1428void 2741void
1429set_ulong (OpenCL::Kernel this, cl_uint idx, cl_ulong value) 2742set_ulong (OpenCL::Kernel self, cl_uint idx, cl_ulong value)
1430 CODE: 2743 CODE:
1431 clSetKernelArg (this, idx, sizeof (value), &value); 2744 clSetKernelArg (self, idx, sizeof (value), &value);
1432 2745
1433void 2746void
1434set_half (OpenCL::Kernel this, cl_uint idx, cl_half value) 2747set_half (OpenCL::Kernel self, cl_uint idx, cl_half value)
1435 CODE: 2748 CODE:
1436 clSetKernelArg (this, idx, sizeof (value), &value); 2749 clSetKernelArg (self, idx, sizeof (value), &value);
1437 2750
1438void 2751void
1439set_float (OpenCL::Kernel this, cl_uint idx, cl_float value) 2752set_float (OpenCL::Kernel self, cl_uint idx, cl_float value)
1440 CODE: 2753 CODE:
1441 clSetKernelArg (this, idx, sizeof (value), &value); 2754 clSetKernelArg (self, idx, sizeof (value), &value);
1442 2755
1443void 2756void
1444set_double (OpenCL::Kernel this, cl_uint idx, cl_double value) 2757set_double (OpenCL::Kernel self, cl_uint idx, cl_double value)
1445 CODE: 2758 CODE:
1446 clSetKernelArg (this, idx, sizeof (value), &value); 2759 clSetKernelArg (self, idx, sizeof (value), &value);
1447 2760
1448void 2761void
1449set_memory (OpenCL::Kernel this, cl_uint idx, OpenCL::Memory_ornull value) 2762set_memory (OpenCL::Kernel self, cl_uint idx, OpenCL::Memory_ornull value)
1450 CODE: 2763 CODE:
1451 clSetKernelArg (this, idx, sizeof (value), &value); 2764 clSetKernelArg (self, idx, sizeof (value), value ? &value : 0);
1452 2765
1453void 2766void
1454set_buffer (OpenCL::Kernel this, cl_uint idx, OpenCL::Buffer_ornull value) 2767set_buffer (OpenCL::Kernel self, cl_uint idx, OpenCL::Buffer_ornull value)
1455 CODE: 2768 CODE:
1456 clSetKernelArg (this, idx, sizeof (value), &value); 2769 clSetKernelArg (self, idx, sizeof (value), value ? &value : 0);
1457 2770
1458void 2771void
1459set_image2d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image2D_ornull value) 2772set_image (OpenCL::Kernel self, cl_uint idx, OpenCL::Image_ornull value)
2773 ALIAS:
2774 set_image2d = 0
2775 set_image3d = 0
1460 CODE: 2776 CODE:
1461 clSetKernelArg (this, idx, sizeof (value), &value); 2777 clSetKernelArg (self, idx, sizeof (value), value ? &value : 0);
1462 2778
1463void 2779void
1464set_image3d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image3D_ornull value)
1465 CODE:
1466 clSetKernelArg (this, idx, sizeof (value), &value);
1467
1468void
1469set_sampler (OpenCL::Kernel this, cl_uint idx, OpenCL::Sampler value) 2780set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value)
1470 CODE: 2781 CODE:
1471 clSetKernelArg (this, idx, sizeof (value), &value); 2782 clSetKernelArg (self, idx, sizeof (value), &value);
1472 2783
1473void 2784void
2785set_local (OpenCL::Kernel self, cl_uint idx, size_t size)
2786 CODE:
2787 clSetKernelArg (self, idx, size, 0);
2788
2789void
1474set_event (OpenCL::Kernel this, cl_uint idx, OpenCL::Event value) 2790set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value)
1475 CODE: 2791 CODE:
1476 clSetKernelArg (this, idx, sizeof (value), &value); 2792 clSetKernelArg (self, idx, sizeof (value), &value);
1477 2793
1478void 2794void
1479info (OpenCL::Kernel this, cl_kernel_info name) 2795info (OpenCL::Kernel self, cl_kernel_info name)
1480 PPCODE: 2796 PPCODE:
1481 INFO (Kernel) 2797 INFO (Kernel)
1482 2798
1483#BEGIN:kernel 2799#BEGIN:kernel
1484 2800
1485void 2801void
1486function_name (OpenCL::Kernel this) 2802function_name (OpenCL::Kernel self)
1487 PPCODE: 2803 PPCODE:
1488 size_t size; 2804 size_t size;
1489 NEED_SUCCESS (GetKernelInfo, (this, CL_KERNEL_FUNCTION_NAME, 0, 0, &size)); 2805 NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_FUNCTION_NAME, 0, 0, &size));
1490 char *value = tmpbuf (size); 2806 char *value = tmpbuf (size);
1491 NEED_SUCCESS (GetKernelInfo, (this, CL_KERNEL_FUNCTION_NAME, size, value, 0)); 2807 NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_FUNCTION_NAME, size, value, 0));
1492 EXTEND (SP, 1); 2808 EXTEND (SP, 1);
1493 const int i = 0; 2809 const int i = 0;
1494 PUSHs (sv_2mortal (newSVpv (value, 0))); 2810 PUSHs (sv_2mortal (newSVpv (value, 0)));
1495 2811
1496void 2812void
1497num_args (OpenCL::Kernel this) 2813num_args (OpenCL::Kernel self)
1498 ALIAS: 2814 ALIAS:
1499 num_args = CL_KERNEL_NUM_ARGS 2815 num_args = CL_KERNEL_NUM_ARGS
1500 reference_count = CL_KERNEL_REFERENCE_COUNT 2816 reference_count = CL_KERNEL_REFERENCE_COUNT
1501 PPCODE: 2817 PPCODE:
1502 cl_uint value [1]; 2818 cl_uint value [1];
1503 NEED_SUCCESS (GetKernelInfo, (this, ix, sizeof (value), value, 0)); 2819 NEED_SUCCESS (GetKernelInfo, (self, ix, sizeof (value), value, 0));
1504 EXTEND (SP, 1); 2820 EXTEND (SP, 1);
1505 const int i = 0; 2821 const int i = 0;
1506 PUSHs (sv_2mortal (newSVuv (value [i]))); 2822 PUSHs (sv_2mortal (newSVuv (value [i])));
1507 2823
1508void 2824void
1509context (OpenCL::Kernel this) 2825context (OpenCL::Kernel self)
1510 PPCODE: 2826 PPCODE:
1511 cl_context value [1]; 2827 cl_context value [1];
1512 NEED_SUCCESS (GetKernelInfo, (this, CL_KERNEL_CONTEXT, sizeof (value), value, 0)); 2828 NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_CONTEXT, sizeof (value), value, 0));
1513 EXTEND (SP, 1); 2829 EXTEND (SP, 1);
1514 const int i = 0; 2830 const int i = 0;
1515 { 2831 {
1516 NEED_SUCCESS (RetainContext, (value [i])); 2832 NEED_SUCCESS (RetainContext, (value [i]));
1517 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i])); 2833 PUSH_CLOBJ (stash_context, value [i]);
1518 } 2834 }
1519 2835
1520void 2836void
1521program (OpenCL::Kernel this) 2837program (OpenCL::Kernel self)
1522 PPCODE: 2838 PPCODE:
1523 cl_program value [1]; 2839 cl_program value [1];
1524 NEED_SUCCESS (GetKernelInfo, (this, CL_KERNEL_PROGRAM, sizeof (value), value, 0)); 2840 NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_PROGRAM, sizeof (value), value, 0));
1525 EXTEND (SP, 1); 2841 EXTEND (SP, 1);
1526 const int i = 0; 2842 const int i = 0;
1527 { 2843 {
1528 NEED_SUCCESS (RetainProgram, (value [i])); 2844 NEED_SUCCESS (RetainProgram, (value [i]));
1529 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Program", value [i])); 2845 PUSH_CLOBJ (stash_program, value [i]);
1530 } 2846 }
1531 2847
1532#END:kernel 2848#END:kernel
1533 2849
1534void 2850void
1535work_group_info (OpenCL::Kernel this, OpenCL::Device device, cl_kernel_work_group_info name) 2851work_group_info (OpenCL::Kernel self, OpenCL::Device device, cl_kernel_work_group_info name)
1536 PPCODE: 2852 PPCODE:
1537 size_t size; 2853 size_t size;
1538 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, name, 0, 0, &size)); 2854 NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, name, 0, 0, &size));
1539 SV *sv = sv_2mortal (newSV (size)); 2855 SV *sv = sv_2mortal (newSV (size));
1540 SvUPGRADE (sv, SVt_PV); 2856 SvUPGRADE (sv, SVt_PV);
1541 SvPOK_only (sv); 2857 SvPOK_only (sv);
1542 SvCUR_set (sv, size); 2858 SvCUR_set (sv, size);
1543 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, name, size, SvPVX (sv), 0)); 2859 NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, name, size, SvPVX (sv), 0));
1544 XPUSHs (sv); 2860 XPUSHs (sv);
1545 2861
1546#BEGIN:kernel_work_group 2862#BEGIN:kernel_work_group
1547 2863
1548void 2864void
1549work_group_size (OpenCL::Kernel this, OpenCL::Device device) 2865work_group_size (OpenCL::Kernel self, OpenCL::Device device)
1550 ALIAS: 2866 ALIAS:
1551 work_group_size = CL_KERNEL_WORK_GROUP_SIZE 2867 work_group_size = CL_KERNEL_WORK_GROUP_SIZE
1552 preferred_work_group_size_multiple = CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE 2868 preferred_work_group_size_multiple = CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE
1553 PPCODE: 2869 PPCODE:
1554 size_t value [1]; 2870 size_t value [1];
1555 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, ix, sizeof (value), value, 0)); 2871 NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, ix, sizeof (value), value, 0));
1556 EXTEND (SP, 1); 2872 EXTEND (SP, 1);
1557 const int i = 0; 2873 const int i = 0;
1558 PUSHs (sv_2mortal (newSVuv (value [i]))); 2874 PUSHs (sv_2mortal (newSVuv (value [i])));
1559 2875
1560void 2876void
1561compile_work_group_size (OpenCL::Kernel this, OpenCL::Device device) 2877compile_work_group_size (OpenCL::Kernel self, OpenCL::Device device)
1562 PPCODE: 2878 PPCODE:
1563 size_t size; 2879 size_t size;
1564 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, 0, 0, &size)); 2880 NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, 0, 0, &size));
1565 size_t *value = tmpbuf (size); 2881 size_t *value = tmpbuf (size);
1566 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, size, value, 0)); 2882 NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, size, value, 0));
1567 int i, n = size / sizeof (*value); 2883 int i, n = size / sizeof (*value);
1568 EXTEND (SP, n); 2884 EXTEND (SP, n);
1569 for (i = 0; i < n; ++i) 2885 for (i = 0; i < n; ++i)
1570 PUSHs (sv_2mortal (newSVuv (value [i]))); 2886 PUSHs (sv_2mortal (newSVuv (value [i])));
1571 2887
1572void 2888void
1573local_mem_size (OpenCL::Kernel this, OpenCL::Device device) 2889local_mem_size (OpenCL::Kernel self, OpenCL::Device device)
1574 ALIAS: 2890 ALIAS:
1575 local_mem_size = CL_KERNEL_LOCAL_MEM_SIZE 2891 local_mem_size = CL_KERNEL_LOCAL_MEM_SIZE
1576 private_mem_size = CL_KERNEL_PRIVATE_MEM_SIZE 2892 private_mem_size = CL_KERNEL_PRIVATE_MEM_SIZE
1577 PPCODE: 2893 PPCODE:
1578 cl_ulong value [1]; 2894 cl_ulong value [1];
1579 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, ix, sizeof (value), value, 0)); 2895 NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, ix, sizeof (value), value, 0));
1580 EXTEND (SP, 1); 2896 EXTEND (SP, 1);
1581 const int i = 0; 2897 const int i = 0;
1582 PUSHs (sv_2mortal (newSVuv (value [i]))); 2898 PUSHs (sv_2mortal (newSVuv (value [i])));
1583 2899
1584#END:kernel_work_group 2900#END:kernel_work_group
1585 2901
2902#if CL_VERSION_1_2
2903
2904void
2905arg_info (OpenCL::Kernel self, cl_uint idx, cl_kernel_arg_info name)
2906 PPCODE:
2907 size_t size;
2908 NEED_SUCCESS (GetKernelArgInfo, (self, idx, name, 0, 0, &size));
2909 SV *sv = sv_2mortal (newSV (size));
2910 SvUPGRADE (sv, SVt_PV);
2911 SvPOK_only (sv);
2912 SvCUR_set (sv, size);
2913 NEED_SUCCESS (GetKernelArgInfo, (self, idx, name, size, SvPVX (sv), 0));
2914 XPUSHs (sv);
2915
2916#BEGIN:kernel_arg
2917
2918void
2919arg_address_qualifier (OpenCL::Kernel self, cl_uint idx)
2920 PPCODE:
2921 cl_kernel_arg_address_qualifier value [1];
2922 NEED_SUCCESS (GetKernelArgInfo, (self, idx, CL_KERNEL_ARG_ADDRESS_QUALIFIER, sizeof (value), value, 0));
2923 EXTEND (SP, 1);
2924 const int i = 0;
2925 PUSHs (sv_2mortal (newSVuv (value [i])));
2926
2927void
2928arg_access_qualifier (OpenCL::Kernel self, cl_uint idx)
2929 PPCODE:
2930 cl_kernel_arg_access_qualifier value [1];
2931 NEED_SUCCESS (GetKernelArgInfo, (self, idx, CL_KERNEL_ARG_ACCESS_QUALIFIER, sizeof (value), value, 0));
2932 EXTEND (SP, 1);
2933 const int i = 0;
2934 PUSHs (sv_2mortal (newSVuv (value [i])));
2935
2936void
2937arg_type_name (OpenCL::Kernel self, cl_uint idx)
2938 ALIAS:
2939 arg_type_name = CL_KERNEL_ARG_TYPE_NAME
2940 arg_name = CL_KERNEL_ARG_NAME
2941 PPCODE:
2942 size_t size;
2943 NEED_SUCCESS (GetKernelArgInfo, (self, idx, ix, 0, 0, &size));
2944 char *value = tmpbuf (size);
2945 NEED_SUCCESS (GetKernelArgInfo, (self, idx, ix, size, value, 0));
2946 EXTEND (SP, 1);
2947 const int i = 0;
2948 PUSHs (sv_2mortal (newSVpv (value, 0)));
2949
2950void
2951arg_type_qualifier (OpenCL::Kernel self, cl_uint idx)
2952 PPCODE:
2953 cl_kernel_arg_type_qualifier value [1];
2954 NEED_SUCCESS (GetKernelArgInfo, (self, idx, CL_KERNEL_ARG_TYPE_QUALIFIER, sizeof (value), value, 0));
2955 EXTEND (SP, 1);
2956 const int i = 0;
2957 PUSHs (sv_2mortal (newSVuv (value [i])));
2958
2959#END:kernel_arg
2960
2961#endif
2962
1586MODULE = OpenCL PACKAGE = OpenCL::Event 2963MODULE = OpenCL PACKAGE = OpenCL::Event
1587 2964
1588void 2965void
1589DESTROY (OpenCL::Event this) 2966DESTROY (OpenCL::Event self)
1590 CODE: 2967 CODE:
1591 clReleaseEvent (this); 2968 clReleaseEvent (self);
1592 2969
1593void 2970void
1594wait (OpenCL::Event this) 2971wait (OpenCL::Event self)
1595 CODE: 2972 CODE:
1596 clWaitForEvents (1, &this); 2973 clWaitForEvents (1, &self);
1597 2974
1598void 2975void
2976cb (OpenCL::Event self, cl_int command_exec_callback_type, SV *cb)
2977 CODE:
2978 clSetEventCallback (self, command_exec_callback_type, eq_event_notify, SvREFCNT_inc (s_get_cv (cb)));
2979
2980void
1599info (OpenCL::Event this, cl_event_info name) 2981info (OpenCL::Event self, cl_event_info name)
1600 PPCODE: 2982 PPCODE:
1601 INFO (Event) 2983 INFO (Event)
1602 2984
1603#BEGIN:event 2985#BEGIN:event
1604 2986
1605void 2987void
1606command_queue (OpenCL::Event this) 2988command_queue (OpenCL::Event self)
1607 PPCODE: 2989 PPCODE:
1608 cl_command_queue value [1]; 2990 cl_command_queue value [1];
1609 NEED_SUCCESS (GetEventInfo, (this, CL_EVENT_COMMAND_QUEUE, sizeof (value), value, 0)); 2991 NEED_SUCCESS (GetEventInfo, (self, CL_EVENT_COMMAND_QUEUE, sizeof (value), value, 0));
1610 EXTEND (SP, 1); 2992 EXTEND (SP, 1);
1611 const int i = 0; 2993 const int i = 0;
1612 { 2994 {
1613 NEED_SUCCESS (RetainCommandQueue, (value [i])); 2995 NEED_SUCCESS (RetainCommandQueue, (value [i]));
1614 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Queue", value [i])); 2996 PUSH_CLOBJ (stash_queue, value [i]);
1615 } 2997 }
1616 2998
1617void 2999void
1618command_type (OpenCL::Event this) 3000command_type (OpenCL::Event self)
1619 PPCODE: 3001 PPCODE:
1620 cl_command_type value [1]; 3002 cl_command_type value [1];
1621 NEED_SUCCESS (GetEventInfo, (this, CL_EVENT_COMMAND_TYPE, sizeof (value), value, 0)); 3003 NEED_SUCCESS (GetEventInfo, (self, CL_EVENT_COMMAND_TYPE, sizeof (value), value, 0));
1622 EXTEND (SP, 1); 3004 EXTEND (SP, 1);
1623 const int i = 0; 3005 const int i = 0;
1624 PUSHs (sv_2mortal (newSVuv (value [i]))); 3006 PUSHs (sv_2mortal (newSVuv (value [i])));
1625 3007
1626void 3008void
1627reference_count (OpenCL::Event this) 3009reference_count (OpenCL::Event self)
1628 ALIAS: 3010 ALIAS:
1629 reference_count = CL_EVENT_REFERENCE_COUNT 3011 reference_count = CL_EVENT_REFERENCE_COUNT
1630 command_execution_status = CL_EVENT_COMMAND_EXECUTION_STATUS 3012 command_execution_status = CL_EVENT_COMMAND_EXECUTION_STATUS
1631 PPCODE: 3013 PPCODE:
1632 cl_uint value [1]; 3014 cl_uint value [1];
1633 NEED_SUCCESS (GetEventInfo, (this, ix, sizeof (value), value, 0)); 3015 NEED_SUCCESS (GetEventInfo, (self, ix, sizeof (value), value, 0));
1634 EXTEND (SP, 1); 3016 EXTEND (SP, 1);
1635 const int i = 0; 3017 const int i = 0;
1636 PUSHs (sv_2mortal (newSVuv (value [i]))); 3018 PUSHs (sv_2mortal (newSVuv (value [i])));
1637 3019
1638void 3020void
1639context (OpenCL::Event this) 3021context (OpenCL::Event self)
1640 PPCODE: 3022 PPCODE:
1641 cl_context value [1]; 3023 cl_context value [1];
1642 NEED_SUCCESS (GetEventInfo, (this, CL_EVENT_CONTEXT, sizeof (value), value, 0)); 3024 NEED_SUCCESS (GetEventInfo, (self, CL_EVENT_CONTEXT, sizeof (value), value, 0));
1643 EXTEND (SP, 1); 3025 EXTEND (SP, 1);
1644 const int i = 0; 3026 const int i = 0;
1645 { 3027 {
1646 NEED_SUCCESS (RetainContext, (value [i])); 3028 NEED_SUCCESS (RetainContext, (value [i]));
1647 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i])); 3029 PUSH_CLOBJ (stash_context, value [i]);
1648 } 3030 }
1649 3031
1650#END:event 3032#END:event
1651 3033
1652void 3034void
1653profiling_info (OpenCL::Event this, cl_profiling_info name) 3035profiling_info (OpenCL::Event self, cl_profiling_info name)
1654 PPCODE: 3036 PPCODE:
1655 INFO (EventProfiling) 3037 INFO (EventProfiling)
1656 3038
1657#BEGIN:profiling 3039#BEGIN:profiling
1658 3040
1659void 3041void
1660profiling_command_queued (OpenCL::Event this) 3042profiling_command_queued (OpenCL::Event self)
1661 ALIAS: 3043 ALIAS:
1662 profiling_command_queued = CL_PROFILING_COMMAND_QUEUED 3044 profiling_command_queued = CL_PROFILING_COMMAND_QUEUED
1663 profiling_command_submit = CL_PROFILING_COMMAND_SUBMIT 3045 profiling_command_submit = CL_PROFILING_COMMAND_SUBMIT
1664 profiling_command_start = CL_PROFILING_COMMAND_START 3046 profiling_command_start = CL_PROFILING_COMMAND_START
1665 profiling_command_end = CL_PROFILING_COMMAND_END 3047 profiling_command_end = CL_PROFILING_COMMAND_END
1666 PPCODE: 3048 PPCODE:
1667 cl_ulong value [1]; 3049 cl_ulong value [1];
1668 NEED_SUCCESS (GetEventProfilingInfo, (this, ix, sizeof (value), value, 0)); 3050 NEED_SUCCESS (GetEventProfilingInfo, (self, ix, sizeof (value), value, 0));
1669 EXTEND (SP, 1); 3051 EXTEND (SP, 1);
1670 const int i = 0; 3052 const int i = 0;
1671 PUSHs (sv_2mortal (newSVuv (value [i]))); 3053 PUSHs (sv_2mortal (newSVuv (value [i])));
1672 3054
1673#END:profiling 3055#END:profiling
1674 3056
1675MODULE = OpenCL PACKAGE = OpenCL::UserEvent 3057MODULE = OpenCL PACKAGE = OpenCL::UserEvent
1676 3058
1677void 3059void
1678set_status (OpenCL::UserEvent this, cl_int execution_status) 3060set_status (OpenCL::UserEvent self, cl_int execution_status)
1679 CODE: 3061 CODE:
1680 clSetUserEventStatus (this, execution_status); 3062 clSetUserEventStatus (self, execution_status);
1681 3063
3064MODULE = OpenCL PACKAGE = OpenCL::Mapped
3065
3066void
3067DESTROY (SV *self)
3068 CODE:
3069 OpenCL__Mapped mapped = SvMAPPED (self);
3070
3071 clEnqueueUnmapMemObject (mapped->queue, mapped->memobj, mapped->ptr, 1, &mapped->event, 0);
3072 mapped_detach (self, mapped);
3073
3074 clReleaseCommandQueue (mapped->queue);
3075 clReleaseEvent (mapped->event);
3076 Safefree (mapped);
3077
3078void
3079unmap (OpenCL::Mapped self, ...)
3080 CODE:
3081 mapped_unmap (cv, ST (0), self, self->queue, &ST (1), items - 1);
3082
3083bool
3084mapped (OpenCL::Mapped self)
3085 CODE:
3086 RETVAL = !!self->ptr;
3087 OUTPUT:
3088 RETVAL
3089
3090void
3091wait (OpenCL::Mapped self)
3092 PPCODE:
3093 if (self->event)
3094 NEED_SUCCESS (WaitForEvents, (1, &self->event));
3095
3096void
3097event (OpenCL::Mapped self)
3098 PPCODE:
3099 if (!self->event)
3100 XSRETURN_UNDEF;
3101
3102 clRetainEvent (self->event);
3103 XPUSH_CLOBJ (stash_event, self->event);
3104
3105size_t
3106size (OpenCL::Mapped self)
3107 CODE:
3108 RETVAL = self->cb;
3109 OUTPUT:
3110 RETVAL
3111
3112IV
3113ptr (OpenCL::Mapped self)
3114 CODE:
3115 RETVAL = PTR2IV (self->ptr);
3116 OUTPUT:
3117 RETVAL
3118
3119void
3120set (OpenCL::Mapped self, size_t offset, SV *data)
3121 CODE:
3122 STRLEN len;
3123 const char *ptr = SvPVbyte (data, len);
3124
3125 if (offset + len > self->cb)
3126 croak ("OpenCL::Mapped::set out of bound condition detected");
3127
3128 memcpy (offset + (char *)self->ptr, ptr, len);
3129
3130MODULE = OpenCL PACKAGE = OpenCL::MappedBuffer
3131
3132MODULE = OpenCL PACKAGE = OpenCL::MappedImage
3133
3134IV
3135row_pitch (OpenCL::Mapped self)
3136 ALIAS:
3137 slice_pitch = 1
3138 CODE:
3139 RETVAL = ix ? self->slice_pitch : self->row_pitch;
3140 OUTPUT:
3141 RETVAL
3142
3143
3144

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines