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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.39 by root, Sat Apr 21 19:48:58 2012 UTC vs.
Revision 1.51 by root, Tue Apr 24 22:45:38 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
5#define X_STACKSIZE sizeof (void *) * 512 * 1024 // 2-4mb should be enough, really
6#include "xthread.h"
7#include "schmorp.h"
4 8
5#ifdef I_DLFCN 9#ifdef I_DLFCN
6 #include <dlfcn.h> 10 #include <dlfcn.h>
7#endif 11#endif
8 12
11// this. This breaks 100% of the opencl 1.1 apps, for what reason? 15// this. This breaks 100% of the opencl 1.1 apps, for what reason?
12// after all, the functions are deprecated, not removed. 16// after all, the functions are deprecated, not removed.
13// in addition, you cannot test for this in any future-proof way. 17// in addition, you cannot test for this in any future-proof way.
14// each time a new opencl version comes out, you need to make a new 18// each time a new opencl version comes out, you need to make a new
15// release. 19// release.
16#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
17#define CL_USE_DEPRECATED_OPENCL_1_2_APIS /* just guessing, you stupid idiots */ 20#define CL_USE_DEPRECATED_OPENCL_1_2_APIS /* just guessing, you stupid idiots */
21
22#ifndef PREFER_1_1
23 #define PREFER_1_1 1
24#endif
25
26#if PREFER_1_1
27 #define CL_USE_DEPRECATED_OPENCL_1_1_APIS
28#endif
18 29
19#ifdef __APPLE__ 30#ifdef __APPLE__
20 #include <OpenCL/opencl.h> 31 #include <OpenCL/opencl.h>
21#else 32#else
22 #include <CL/opencl.h> 33 #include <CL/opencl.h>
23#endif 34#endif
24 35
25#if 0 // testing
26#undef CL_USE_DEPRECATED_OPENCL_1_1_APIS
27#undef CL_VERSION_1_2 36#ifndef CL_VERSION_1_2
37 #undef PREFER_1_1
38 #define PREFER_1_1 1
28#endif 39#endif
29 40
30typedef cl_platform_id OpenCL__Platform; 41typedef cl_platform_id OpenCL__Platform;
31typedef cl_device_id OpenCL__Device; 42typedef cl_device_id OpenCL__Device;
32typedef cl_context OpenCL__Context; 43typedef cl_context OpenCL__Context;
182 if (res) \ 193 if (res) \
183 FAIL (name); 194 FAIL (name);
184 195
185/*****************************************************************************/ 196/*****************************************************************************/
186 197
187#define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr)
188#define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr))
189
190static void *
191SvPTROBJ (const char *func, const char *svname, SV *sv, const char *pkg)
192{
193 if (SvROK (sv) && sv_derived_from (sv, pkg))
194 return (void *)SvIV (SvRV (sv));
195
196 croak ("%s: %s is not of type %s", func, svname, pkg);
197}
198
199/*****************************************************************************/
200
201static cl_context_properties * 198static cl_context_properties *
202SvCONTEXTPROPERTIES (const char *func, const char *svname, SV *sv, cl_context_properties *extra, int extracount) 199SvCONTEXTPROPERTIES (const char *func, const char *svname, SV *sv, cl_context_properties *extra, int extracount)
203{ 200{
204 if (!sv || !SvOK (sv)) 201 if (!sv || !SvOK (sv))
205 if (extra) 202 if (extra)
263 croak ("%s: %s is not a property list (either undef or [type => value, ...])", func, svname); 260 croak ("%s: %s is not a property list (either undef or [type => value, ...])", func, svname);
264} 261}
265 262
266/*****************************************************************************/ 263/*****************************************************************************/
267 264
265#define NEW_CLOBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr)
266#define PUSH_CLOBJ(class,ptr) PUSHs (NEW_CLOBJ (class, ptr))
267#define XPUSH_CLOBJ(class,ptr) XPUSHs (NEW_CLOBJ (class, ptr))
268
269/* cl objects are either \$iv, or [$iv, ...] */
270/* they can be upgraded at runtime to the array form */
271static void *
272SvCLOBJ (const char *func, const char *svname, SV *sv, const char *pkg)
273{
274 if (SvROK (sv) && sv_derived_from (sv, pkg))
275 {
276 SV *rv = SvRV (sv);
277
278 if (SvTYPE (rv) == SVt_PVAV)
279 rv = AvARRAY (rv)[0];
280
281 return (void *)SvIV (SvRV (sv));
282 }
283
284 croak ("%s: %s is not of type %s", func, svname, pkg);
285}
286
287static void
288CLOBJ_push (SV *self, SV *data)
289{
290 SV *rv = SvRV (self);
291
292 if (SvTYPE (rv) != SVt_PVAV)
293 {
294 AV *av = newAV ();
295 av_push (av, rv);
296 rv = (SV *)av;
297 SvRV_set (self, rv);
298 }
299
300 av_push ((AV *)rv, data);
301}
302
303static SV *
304sv_struct (STRLEN size)
305{
306 SV *sv = newSV (size);
307 SvPOK_only (sv);
308 return sv;
309}
310
311static void *
312CLOBJ_push_struct (SV *self, STRLEN size)
313{
314 SV *sv = sv_struct (size);
315 CLOBJ_push (self, sv);
316 return SvPVX (sv);
317}
318
319/*****************************************************************************/
320/* callback stuff */
321
322/* default context callback, log to stderr */
323static void CL_CALLBACK
324context_default_notify (const char *msg, const void *info, size_t cb, void *data)
325{
326 fprintf (stderr, "OpenCL Context Notify: %s\n", msg);
327}
328
329typedef struct
330{
331 int free_cb;
332 void (*push)(void *data1, void *data2, void *data3);
333} eq_vtbl;
334
335typedef struct eq_item
336{
337 struct eq_item *next;
338 eq_vtbl *vtbl;
339 SV *cb;
340 void *data1, *data2, *data3;
341} eq_item;
342
343static void (*eq_signal_func)(void *signal_arg, int value);
344static void *eq_signal_arg;
345static xmutex_t eq_lock = X_MUTEX_INIT;
346static eq_item *eq_head, *eq_tail;
347
348static void
349eq_enq (eq_vtbl *vtbl, SV *cb, void *data1, void *data2, void *data3)
350{
351 eq_item *item = malloc (sizeof (eq_item));
352
353 printf ("enq(%p,%p,%p,%p,%p)\n", vtbl, cb, data1, data2, data3);//D
354
355 item->next = 0;
356 item->vtbl = vtbl;
357 item->cb = cb;
358 item->data1 = data1;
359 item->data2 = data2;
360 item->data3 = data3;
361
362 X_LOCK (eq_lock);
363
364 *(eq_head ? &eq_tail->next : &eq_head) = item;
365 eq_tail = item;
366
367 X_UNLOCK (eq_lock);
368
369 eq_signal_func (eq_signal_arg, 0);
370}
371
372static eq_item *
373eq_dec (void)
374{
375 eq_item *res;
376
377 X_LOCK (eq_lock);
378
379 res = eq_head;
380 if (res)
381 eq_head = res->next;
382
383 X_UNLOCK (eq_lock);
384
385 return res;
386}
387
388#if 0
389static void
390mem_free (pTHX_ void *p)
391{
392 free (p);
393}
394//SAVEDESTRUCTOR_X (mem_free, item);
395#endif
396
397static void
398eq_poll (void)
399{
400 eq_item *item;
401
402 while ((item = eq_dec ()))
403 {
404 ENTER;
405 SAVETMPS;
406
407 dSP;
408 PUSHMARK (SP);
409 EXTEND (SP, 2);
410
411 if (item->vtbl->free_cb)
412 sv_2mortal (item->cb);
413
414 PUTBACK;
415 item->vtbl->push (item->data1, item->data2, item->data3);
416
417 SV *cb = item->cb;
418 free (item);
419
420 call_sv (cb, G_DISCARD | G_VOID);
421
422 FREETMPS;
423 LEAVE;
424 }
425}
426
427static void
428eq_poll_interrupt (pTHX_ void *c_arg, int value)
429{
430 eq_poll ();
431}
432
433/* context notify */
434
435static void
436eq_context_push (void *data1, void *data2, void *data3)
437{
438 dSP;
439 PUSHs (sv_2mortal (newSVpv (data1, 0)));
440 PUSHs (sv_2mortal (newSVpvn (data2, (STRLEN)data3)));
441 PUTBACK;
442}
443
444static eq_vtbl eq_context_vtbl = { 0, eq_context_push };
445
446/* build/compile/link notify */
447
448static void
449eq_program_push (void *data1, void *data2, void *data3)
450{
451 dSP;
452 PUSH_CLOBJ ("OpenCL::Program", data1);
453 PUTBACK;
454}
455
456static eq_vtbl eq_program_vtbl = { 1, eq_program_push };
457
458static void CL_CALLBACK
459eq_program_notify (cl_program program, void *user_data)
460{
461 eq_enq (&eq_program_vtbl, user_data, (void *)program, 0, 0);
462}
463
464struct build_args
465{
466 cl_program program;
467 char *options;
468 void *user_data;
469 cl_uint num_devices;
470};
471
472X_THREAD_PROC (build_program_thread)
473{
474 struct build_args *arg = thr_arg;
475
476 clBuildProgram (arg->program, arg->num_devices, arg->num_devices ? (void *)(arg + 1) : 0, arg->options, 0, 0);
477
478 if (arg->user_data)
479 eq_program_notify (arg->program, arg->user_data);
480 else
481 clReleaseProgram (arg->program);
482
483 free (arg->options);
484 free (arg);
485}
486
487static void
488build_program_async (cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, void *user_data)
489{
490 struct build_args *arg = malloc (sizeof (struct build_args) + sizeof (*device_list) * num_devices);
491
492 arg->program = program;
493 arg->options = strdup (options);
494 arg->user_data = user_data;
495 arg->num_devices = num_devices;
496 memcpy (arg + 1, device_list, sizeof (*device_list) * num_devices);
497
498 xthread_t id;
499 thread_create (&id, build_program_thread, arg);
500}
501
502/* event objects */
503
504static void
505eq_event_push (void *data1, void *data2, void *data3)
506{
507 dSP;
508 PUSH_CLOBJ ("OpenCL::Event", data1);
509 PUSHs (sv_2mortal (newSViv ((IV)data2)));
510 PUTBACK;
511}
512
513static eq_vtbl eq_event_vtbl = { 1, eq_event_push };
514
515static void CL_CALLBACK
516eq_event_notify (cl_event event, cl_int event_command_exec_status, void *user_data)
517{
518 clRetainEvent (event);
519 eq_enq (&eq_event_vtbl, user_data, (void *)event, (void *)event_command_exec_status, 0);
520}
521
522/*****************************************************************************/
523
268static size_t 524static size_t
269img_row_pitch (cl_mem img) 525img_row_pitch (cl_mem img)
270{ 526{
271 size_t res; 527 size_t res;
272 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); 528 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0);
286 542
287 do 543 do
288 { 544 {
289 --count; 545 --count;
290 if (SvOK (items [count])) 546 if (SvOK (items [count]))
291 list [i++] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); 547 list [i++] = SvCLOBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event");
292 } 548 }
293 while (count); 549 while (count);
294 550
295 *rcount = i; 551 *rcount = i;
296 552
314} 570}
315 571
316MODULE = OpenCL PACKAGE = OpenCL 572MODULE = OpenCL PACKAGE = OpenCL
317 573
318PROTOTYPES: ENABLE 574PROTOTYPES: ENABLE
575
576void
577poll ()
578 CODE:
579 eq_poll ();
580
581void
582_eq_initialise (IV func, IV arg)
583 CODE:
584 eq_signal_func = (void (*)(void *, int))func;
585 eq_signal_arg = (void*)arg;
319 586
320BOOT: 587BOOT:
321{ 588{
322 HV *stash = gv_stashpv ("OpenCL", 1); 589 HV *stash = gv_stashpv ("OpenCL", 1);
323 static const ivstr *civ, const_iv[] = { 590 static const ivstr *civ, const_iv[] = {
332 { sizeof (cl_half ), "SIZEOF_HALF" }, 599 { sizeof (cl_half ), "SIZEOF_HALF" },
333 { sizeof (cl_float ), "SIZEOF_FLOAT" }, 600 { sizeof (cl_float ), "SIZEOF_FLOAT" },
334 { sizeof (cl_double), "SIZEOF_DOUBLE" }, 601 { sizeof (cl_double), "SIZEOF_DOUBLE" },
335#include "constiv.h" 602#include "constiv.h"
336 }; 603 };
604
337 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 605 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
338 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 606 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
607
608 sv_setiv (perl_get_sv ("OpenCL::POLL_FUNC", TRUE), (IV)eq_poll_interrupt);
339} 609}
340 610
341cl_int 611cl_int
342errno () 612errno ()
343 CODE: 613 CODE:
362 list = tmpbuf (sizeof (*list) * count); 632 list = tmpbuf (sizeof (*list) * count);
363 NEED_SUCCESS (GetPlatformIDs, (count, list, 0)); 633 NEED_SUCCESS (GetPlatformIDs, (count, list, 0));
364 634
365 EXTEND (SP, count); 635 EXTEND (SP, count);
366 for (i = 0; i < count; ++i) 636 for (i = 0; i < count; ++i)
367 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); 637 PUSH_CLOBJ ("OpenCL::Platform", list [i]);
368 638
369void 639void
370context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) 640context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
371 PPCODE: 641 PPCODE:
372 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res)); 642 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res));
373 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 643 XPUSH_CLOBJ ("OpenCL::Context", ctx);
374 644
375#if 0 645#if 0
376 646
377void 647void
378context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) 648context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0)
393 663
394void 664void
395info (OpenCL::Platform self, cl_platform_info name) 665info (OpenCL::Platform self, cl_platform_info name)
396 PPCODE: 666 PPCODE:
397 INFO (Platform) 667 INFO (Platform)
668
669void
670unload_compiler (OpenCL::Platform self)
671 CODE:
672#if CL_VERSION_1_2
673 clUnloadPlatformCompiler (self);
674#endif
398 675
399#BEGIN:platform 676#BEGIN:platform
400 677
401void 678void
402profile (OpenCL::Platform self) 679profile (OpenCL::Platform self)
431 EXTEND (SP, count); 708 EXTEND (SP, count);
432 for (i = 0; i < count; ++i) 709 for (i = 0; i < count; ++i)
433 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); 710 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i]));
434 711
435void 712void
436context (OpenCL::Platform self, cl_context_properties *properties = 0, SV *devices, FUTURE notify = 0) 713context (OpenCL::Platform self, cl_context_properties *properties, SV *devices, SV *notify = 0)
437 PPCODE: 714 PPCODE:
438 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) 715 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV)
439 croak ("OpenCL::Platform::context argument 'device' must be an arrayref with device objects, in call"); 716 croak ("OpenCL::Platform::context argument 'device' must be an arrayref with device objects, in call");
440 717
441 AV *av = (AV *)SvRV (devices); 718 AV *av = (AV *)SvRV (devices);
442 cl_uint num_devices = av_len (av) + 1; 719 cl_uint num_devices = av_len (av) + 1;
443 cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); 720 cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices);
721
444 int i; 722 int i;
445
446 for (i = num_devices; i--; ) 723 for (i = num_devices; i--; )
447 device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device"); 724 device_list [i] = SvCLOBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device");
448 725
726 void (CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *) = context_default_notify;
727 void *user_data = 0;
728
449 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (properties, num_devices, device_list, 0, 0, &res)); 729 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (properties, num_devices, device_list, pfn_notify, user_data, &res));
450 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 730 XPUSH_CLOBJ ("OpenCL::Context", ctx);
451 731
452void 732void
453context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) 733context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
454 PPCODE: 734 PPCODE:
455 cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self }; 735 cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self };
456 cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context_from_type", "properties", properties, extra, 2); 736 cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context_from_type", "properties", properties, extra, 2);
457 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res)); 737 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res));
458 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 738 XPUSH_CLOBJ ("OpenCL::Context", ctx);
459 739
460MODULE = OpenCL PACKAGE = OpenCL::Device 740MODULE = OpenCL PACKAGE = OpenCL::Device
461 741
462void 742void
463info (OpenCL::Device self, cl_device_info name) 743info (OpenCL::Device self, cl_device_info name)
502 native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 782 native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT
503 native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 783 native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG
504 native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 784 native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT
505 native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 785 native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE
506 native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 786 native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF
507 reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT 787 reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT
508 PPCODE: 788 PPCODE:
509 cl_uint value [1]; 789 cl_uint value [1];
510 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0)); 790 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
511 EXTEND (SP, 1); 791 EXTEND (SP, 1);
512 const int i = 0; 792 const int i = 0;
636 cl_platform_id value [1]; 916 cl_platform_id value [1];
637 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_PLATFORM, sizeof (value), value, 0)); 917 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_PLATFORM, sizeof (value), value, 0));
638 EXTEND (SP, 1); 918 EXTEND (SP, 1);
639 const int i = 0; 919 const int i = 0;
640 { 920 {
641 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", value [i])); 921 PUSH_CLOBJ ("OpenCL::Platform", value [i]);
642 } 922 }
643 923
644void 924void
645name (OpenCL::Device self) 925name (OpenCL::Device self)
646 ALIAS: 926 ALIAS:
665 cl_device_id value [1]; 945 cl_device_id value [1];
666 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_PARENT_DEVICE_EXT, sizeof (value), value, 0)); 946 NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_PARENT_DEVICE_EXT, sizeof (value), value, 0));
667 EXTEND (SP, 1); 947 EXTEND (SP, 1);
668 const int i = 0; 948 const int i = 0;
669 { 949 {
670 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i])); 950 PUSH_CLOBJ ("OpenCL::Device", value [i]);
671 } 951 }
672 952
673void 953void
674partition_types_ext (OpenCL::Device self) 954partition_types_ext (OpenCL::Device self)
675 ALIAS: 955 ALIAS:
702 982
703void 983void
704queue (OpenCL::Context self, OpenCL::Device device, cl_command_queue_properties properties = 0) 984queue (OpenCL::Context self, OpenCL::Device device, cl_command_queue_properties properties = 0)
705 PPCODE: 985 PPCODE:
706 NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (self, device, properties, &res)); 986 NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (self, device, properties, &res));
707 XPUSH_NEW_OBJ ("OpenCL::Queue", queue); 987 XPUSH_CLOBJ ("OpenCL::Queue", queue);
708 988
709void 989void
710user_event (OpenCL::Context self) 990user_event (OpenCL::Context self)
711 PPCODE: 991 PPCODE:
712 NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (self, &res)); 992 NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (self, &res));
713 XPUSH_NEW_OBJ ("OpenCL::UserEvent", ev); 993 XPUSH_CLOBJ ("OpenCL::UserEvent", ev);
714 994
715void 995void
716buffer (OpenCL::Context self, cl_mem_flags flags, size_t len) 996buffer (OpenCL::Context self, cl_mem_flags flags, size_t len)
717 PPCODE: 997 PPCODE:
718 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) 998 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
719 croak ("OpenCL::Context::buffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); 999 croak ("OpenCL::Context::buffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?");
720 1000
721 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res)); 1001 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res));
722 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 1002 XPUSH_CLOBJ ("OpenCL::BufferObj", mem);
723 1003
724void 1004void
725buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data) 1005buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data)
726 PPCODE: 1006 PPCODE:
727 STRLEN len; 1007 STRLEN len;
728 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 1008 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
729 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) 1009 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
730 croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); 1010 croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
731 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res)); 1011 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res));
732 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 1012 XPUSH_CLOBJ ("OpenCL::BufferObj", mem);
733 1013
734#if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS 1014#if CL_VERSION_1_2
735 1015
736void 1016void
737image2d (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) 1017image (OpenCL::Context self, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, cl_mem_object_type type, size_t width, size_t height, size_t depth, size_t array_size = 0, size_t row_pitch = 0, size_t slice_pitch = 0, cl_uint num_mip_level = 0, cl_uint num_samples = 0, SV *data = &PL_sv_undef)
738 PPCODE: 1018 PPCODE:
739 STRLEN len; 1019 STRLEN len;
740 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 1020 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
741 const cl_image_format format = { channel_order, channel_type }; 1021 const cl_image_format format = { channel_order, channel_type };
1022 const cl_image_desc desc = {
1023 type,
1024 width, height, depth,
1025 array_size, row_pitch, slice_pitch,
1026 num_mip_level, num_samples,
1027 type == CL_MEM_OBJECT_IMAGE1D_BUFFER ? (cl_mem)SvCLOBJ ("OpenCL::Context::Image", "data", data, "OpenCL::Buffer") : 0
1028 };
742 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res)); 1029 NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
743 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 1030 char *klass = "OpenCL::Image";
1031 switch (type)
1032 {
1033 case CL_MEM_OBJECT_IMAGE1D_BUFFER: klass = "OpenCL::Image1DBuffer"; break;
1034 case CL_MEM_OBJECT_IMAGE1D: klass = "OpenCL::Image1D"; break;
1035 case CL_MEM_OBJECT_IMAGE1D_ARRAY: klass = "OpenCL::Image2DArray"; break;
1036 case CL_MEM_OBJECT_IMAGE2D: klass = "OpenCL::Image2D"; break;
1037 case CL_MEM_OBJECT_IMAGE2D_ARRAY: klass = "OpenCL::Image2DArray"; break;
1038 case CL_MEM_OBJECT_IMAGE3D: klass = "OpenCL::Image3D"; break;
1039 }
1040 XPUSH_CLOBJ (klass, mem);
744 1041
1042#endif
1043
745void 1044void
746image3d (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) 1045image2d (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)
747 PPCODE: 1046 PPCODE:
748 STRLEN len; 1047 STRLEN len;
749 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 1048 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
750 const cl_image_format format = { channel_order, channel_type }; 1049 const cl_image_format format = { channel_order, channel_type };
1050#if PREFER_1_1
1051 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res));
1052#else
1053 const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE2D, width, height, 0, 0, row_pitch, 0, 0, 0, 0 };
1054 NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
1055#endif
1056 XPUSH_CLOBJ ("OpenCL::Image2D", mem);
1057
1058void
1059image3d (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)
1060 PPCODE:
1061 STRLEN len;
1062 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
1063 const cl_image_format format = { channel_order, channel_type };
1064#if PREFER_1_1
751 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); 1065 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
752 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 1066#else
753 1067 const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE3D, width, height, depth, 0, row_pitch, slice_pitch, 0, 0, 0 };
1068 NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
754#endif 1069#endif
1070 XPUSH_CLOBJ ("OpenCL::Image3D", mem);
755 1071
756#if cl_apple_gl_sharing || cl_khr_gl_sharing 1072#if cl_apple_gl_sharing || cl_khr_gl_sharing
757 1073
758void 1074void
759gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj) 1075gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj)
760 PPCODE: 1076 PPCODE:
761 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res)); 1077 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res));
762 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 1078 XPUSH_CLOBJ ("OpenCL::BufferObj", mem);
763 1079
764#if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS
765
766void 1080void
767gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) 1081gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer)
768 PPCODE: 1082 PPCODE:
769 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res)); 1083 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res));
770 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 1084 XPUSH_CLOBJ ("OpenCL::Image2D", mem);
771
772void
773gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
774 PPCODE:
775 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res));
776 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
777
778#endif
779 1085
780#if CL_VERSION_1_2 1086#if CL_VERSION_1_2
781 1087
782void 1088void
783gl_texture (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) 1089gl_texture (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
1090 ALIAS:
784 PPCODE: 1091 PPCODE:
1092 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture, (self, flags, target, miplevel, texture, &res));
1093 cl_gl_object_type type;
1094 NEED_SUCCESS (GetGLObjectInfo, (mem, &type, 0)); // TODO: use target instead?
785 char *klass = "OpenCL::Memory"; 1095 char *klass = "OpenCL::Memory";
786 cl_gl_object_type t;
787 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
788 NEED_SUCCESS (GetGLObjectInfo, (mem, &t, 0));
789 switch (t) 1096 switch (type)
790 { 1097 {
791 case CL_GL_OBJECT_TEXTURE_BUFFER: klass = "OpenCL::Image1DBuffer"; break; 1098 case CL_GL_OBJECT_TEXTURE_BUFFER: klass = "OpenCL::Image1DBuffer"; break;
792 case CL_GL_OBJECT_TEXTURE1D: klass = "OpenCL::Image1D"; break; 1099 case CL_GL_OBJECT_TEXTURE1D: klass = "OpenCL::Image1D"; break;
793 case CL_GL_OBJECT_TEXTURE1D_ARRAY: klass = "OpenCL::Image2DArray"; break; 1100 case CL_GL_OBJECT_TEXTURE1D_ARRAY: klass = "OpenCL::Image2DArray"; break;
794 case CL_GL_OBJECT_TEXTURE2D: klass = "OpenCL::Image2D"; break; 1101 case CL_GL_OBJECT_TEXTURE2D: klass = "OpenCL::Image2D"; break;
795 case CL_GL_OBJECT_TEXTURE2D_ARRAY: klass = "OpenCL::Image2DArray"; break; 1102 case CL_GL_OBJECT_TEXTURE2D_ARRAY: klass = "OpenCL::Image2DArray"; break;
796 case CL_GL_OBJECT_TEXTURE3D: klass = "OpenCL::Image3D"; break; 1103 case CL_GL_OBJECT_TEXTURE3D: klass = "OpenCL::Image3D"; break;
797 } 1104 }
798 XPUSH_NEW_OBJ (klass, mem); 1105 XPUSH_CLOBJ (klass, mem);
799 1106
800#endif 1107#endif
801 1108
802void 1109void
803gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer) 1110gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
804 PPCODE: 1111 PPCODE:
805 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res)); 1112#if PREFER_1_1
1113 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
1114#else
1115 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture , (self, flags, target, miplevel, texture, &res));
1116#endif
806 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 1117 XPUSH_CLOBJ ("OpenCL::Image2D", mem);
1118
1119void
1120gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
1121 PPCODE:
1122#if PREFER_1_1
1123 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res));
1124#else
1125 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture , (self, flags, target, miplevel, texture, &res));
1126#endif
1127 XPUSH_CLOBJ ("OpenCL::Image3D", mem);
807 1128
808#endif 1129#endif
809 1130
810void 1131void
811supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) 1132supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type)
831 1152
832void 1153void
833sampler (OpenCL::Context self, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode) 1154sampler (OpenCL::Context self, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode)
834 PPCODE: 1155 PPCODE:
835 NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (self, normalized_coords, addressing_mode, filter_mode, &res)); 1156 NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (self, normalized_coords, addressing_mode, filter_mode, &res));
836 XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler); 1157 XPUSH_CLOBJ ("OpenCL::Sampler", sampler);
837 1158
838void 1159void
839program_with_source (OpenCL::Context self, SV *program) 1160program_with_source (OpenCL::Context self, SV *program)
840 PPCODE: 1161 PPCODE:
841 STRLEN len; 1162 STRLEN len;
842 size_t len2; 1163 size_t len2;
843 const char *ptr = SvPVbyte (program, len); 1164 const char *ptr = SvPVbyte (program, len);
844 1165
845 len2 = len; 1166 len2 = len;
846 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (self, 1, &ptr, &len2, &res)); 1167 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (self, 1, &ptr, &len2, &res));
847 XPUSH_NEW_OBJ ("OpenCL::Program", prog); 1168 XPUSH_CLOBJ ("OpenCL::Program", prog);
848 1169
849#BEGIN:context 1170#BEGIN:context
850 1171
851void 1172void
852reference_count (OpenCL::Context self) 1173reference_count (OpenCL::Context self)
869 NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_DEVICES, size, value, 0)); 1190 NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_DEVICES, size, value, 0));
870 int i, n = size / sizeof (*value); 1191 int i, n = size / sizeof (*value);
871 EXTEND (SP, n); 1192 EXTEND (SP, n);
872 for (i = 0; i < n; ++i) 1193 for (i = 0; i < n; ++i)
873 { 1194 {
874 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i])); 1195 PUSH_CLOBJ ("OpenCL::Device", value [i]);
875 } 1196 }
876 1197
877void 1198void
878properties (OpenCL::Context self) 1199properties (OpenCL::Context self)
879 PPCODE: 1200 PPCODE:
906 SvPOK_only (data); 1227 SvPOK_only (data);
907 SvCUR_set (data, len); 1228 SvCUR_set (data, len);
908 NEED_SUCCESS (EnqueueReadBuffer, (self, mem, blocking, offset, len, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1229 NEED_SUCCESS (EnqueueReadBuffer, (self, mem, blocking, offset, len, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
909 1230
910 if (ev) 1231 if (ev)
911 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1232 XPUSH_CLOBJ ("OpenCL::Event", ev);
912 1233
913void 1234void
914enqueue_write_buffer (OpenCL::Queue self, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...) 1235enqueue_write_buffer (OpenCL::Queue self, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...)
915 PPCODE: 1236 PPCODE:
916 cl_event ev = 0; 1237 cl_event ev = 0;
919 EVENT_LIST (5, items - 5); 1240 EVENT_LIST (5, items - 5);
920 1241
921 NEED_SUCCESS (EnqueueWriteBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1242 NEED_SUCCESS (EnqueueWriteBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
922 1243
923 if (ev) 1244 if (ev)
924 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1245 XPUSH_CLOBJ ("OpenCL::Event", ev);
1246
1247#if CL_VERSION_1_2
1248
1249void
1250enqueue_fill_buffer (OpenCL::Queue self, OpenCL::Buffer mem, SV *data, size_t offset, size_t size, ...)
1251 PPCODE:
1252 cl_event ev = 0;
1253 STRLEN len;
1254 char *ptr = SvPVbyte (data, len);
1255 EVENT_LIST (5, items - 5);
1256
1257 NEED_SUCCESS (EnqueueFillBuffer, (self, mem, ptr, len, offset, size, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1258
1259 if (ev)
1260 XPUSH_CLOBJ ("OpenCL::Event", ev);
1261
1262void
1263enqueue_fill_image (OpenCL::Queue self, OpenCL::Image img, NV r, NV g, NV b, NV a, size_t x, size_t y, size_t z, size_t width, size_t height, size_t depth, ...)
1264 PPCODE:
1265 cl_event ev = 0;
1266 STRLEN len;
1267 const size_t origin [3] = { x, y, z };
1268 const size_t region [3] = { width, height, depth };
1269 EVENT_LIST (12, items - 12);
1270
1271 const cl_float c_f [4] = { r, g, b, a };
1272 const cl_uint c_u [4] = { r, g, b, a };
1273 const cl_int c_s [4] = { r, g, b, a };
1274 const void *c_fus [3] = { &c_f, &c_u, &c_s };
1275 static const char fus [] = { 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 1, 1, 1, 0, 0 };
1276 cl_image_format format;
1277 NEED_SUCCESS (GetImageInfo, (img, CL_IMAGE_FORMAT, sizeof (format), &format, 0));
1278 assert (sizeof (fus) == CL_FLOAT + 1 - CL_SNORM_INT8);
1279 if (format.image_channel_data_type < CL_SNORM_INT8 || CL_FLOAT < format.image_channel_data_type)
1280 croak ("enqueue_fill_image: image has unsupported channel type, only opencl 1.2 channel types supported.");
1281
1282 NEED_SUCCESS (EnqueueFillImage, (self, img, c_fus [fus [format.image_channel_data_type]],
1283 origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1284
1285 if (ev)
1286 XPUSH_CLOBJ ("OpenCL::Event", ev);
1287
1288#endif
925 1289
926void 1290void
927enqueue_copy_buffer (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...) 1291enqueue_copy_buffer (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...)
928 PPCODE: 1292 PPCODE:
929 cl_event ev = 0; 1293 cl_event ev = 0;
930 EVENT_LIST (6, items - 6); 1294 EVENT_LIST (6, items - 6);
931 1295
932 NEED_SUCCESS (EnqueueCopyBuffer, (self, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1296 NEED_SUCCESS (EnqueueCopyBuffer, (self, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
933 1297
934 if (ev) 1298 if (ev)
935 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1299 XPUSH_CLOBJ ("OpenCL::Event", ev);
936 1300
937void 1301void
938enqueue_read_buffer_rect (OpenCL::Queue self, OpenCL::Memory buf, cl_bool blocking, size_t buf_x, size_t buf_y, size_t buf_z, size_t host_x, size_t host_y, size_t host_z, size_t width, size_t height, size_t depth, size_t buf_row_pitch, size_t buf_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, SV *data, ...) 1302enqueue_read_buffer_rect (OpenCL::Queue self, OpenCL::Memory buf, cl_bool blocking, size_t buf_x, size_t buf_y, size_t buf_z, size_t host_x, size_t host_y, size_t host_z, size_t width, size_t height, size_t depth, size_t buf_row_pitch, size_t buf_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, SV *data, ...)
939 PPCODE: 1303 PPCODE:
940 cl_event ev = 0; 1304 cl_event ev = 0;
962 SvPOK_only (data); 1326 SvPOK_only (data);
963 SvCUR_set (data, len); 1327 SvCUR_set (data, len);
964 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)); 1328 NEED_SUCCESS (EnqueueReadBufferRect, (self, buf, blocking, buf_origin, host_origin, region, buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
965 1329
966 if (ev) 1330 if (ev)
967 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1331 XPUSH_CLOBJ ("OpenCL::Event", ev);
968 1332
969void 1333void
970enqueue_write_buffer_rect (OpenCL::Queue self, OpenCL::Memory buf, cl_bool blocking, size_t buf_x, size_t buf_y, size_t buf_z, size_t host_x, size_t host_y, size_t host_z, size_t width, size_t height, size_t depth, size_t buf_row_pitch, size_t buf_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, SV *data, ...) 1334enqueue_write_buffer_rect (OpenCL::Queue self, OpenCL::Memory buf, cl_bool blocking, size_t buf_x, size_t buf_y, size_t buf_z, size_t host_x, size_t host_y, size_t host_z, size_t width, size_t height, size_t depth, size_t buf_row_pitch, size_t buf_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, SV *data, ...)
971 PPCODE: 1335 PPCODE:
972 cl_event ev = 0; 1336 cl_event ev = 0;
995 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1359 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
996 1360
997 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)); 1361 NEED_SUCCESS (EnqueueWriteBufferRect, (self, buf, blocking, buf_origin, host_origin, region, buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
998 1362
999 if (ev) 1363 if (ev)
1000 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1364 XPUSH_CLOBJ ("OpenCL::Event", ev);
1001 1365
1002void 1366void
1003enqueue_copy_buffer_rect (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, size_t dst_slice_pitch, ...) 1367enqueue_copy_buffer_rect (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, size_t dst_slice_pitch, ...)
1004 PPCODE: 1368 PPCODE:
1005 cl_event ev = 0; 1369 cl_event ev = 0;
1009 EVENT_LIST (16, items - 16); 1373 EVENT_LIST (16, items - 16);
1010 1374
1011 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)); 1375 NEED_SUCCESS (EnqueueCopyBufferRect, (self, src, dst, src_origin, dst_origin, region, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1012 1376
1013 if (ev) 1377 if (ev)
1014 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1378 XPUSH_CLOBJ ("OpenCL::Event", ev);
1015 1379
1016void 1380void
1017enqueue_read_image (OpenCL::Queue self, OpenCL::Image src, cl_bool blocking, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...) 1381enqueue_read_image (OpenCL::Queue self, OpenCL::Image src, cl_bool blocking, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...)
1018 PPCODE: 1382 PPCODE:
1019 cl_event ev = 0; 1383 cl_event ev = 0;
1034 SvPOK_only (data); 1398 SvPOK_only (data);
1035 SvCUR_set (data, len); 1399 SvCUR_set (data, len);
1036 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)); 1400 NEED_SUCCESS (EnqueueReadImage, (self, src, blocking, src_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1037 1401
1038 if (ev) 1402 if (ev)
1039 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1403 XPUSH_CLOBJ ("OpenCL::Event", ev);
1040 1404
1041void 1405void
1042enqueue_write_image (OpenCL::Queue self, OpenCL::Image dst, cl_bool blocking, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...) 1406enqueue_write_image (OpenCL::Queue self, OpenCL::Image dst, cl_bool blocking, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...)
1043 PPCODE: 1407 PPCODE:
1044 cl_event ev = 0; 1408 cl_event ev = 0;
1060 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1424 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
1061 1425
1062 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)); 1426 NEED_SUCCESS (EnqueueWriteImage, (self, dst, blocking, dst_origin, region, row_pitch, slice_pitch, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1063 1427
1064 if (ev) 1428 if (ev)
1065 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1429 XPUSH_CLOBJ ("OpenCL::Event", ev);
1066 1430
1067void 1431void
1068enqueue_copy_image (OpenCL::Queue self, OpenCL::Image src, OpenCL::Image dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...) 1432enqueue_copy_image (OpenCL::Queue self, OpenCL::Image src, OpenCL::Image dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...)
1069 PPCODE: 1433 PPCODE:
1070 cl_event ev = 0; 1434 cl_event ev = 0;
1074 EVENT_LIST (12, items - 12); 1438 EVENT_LIST (12, items - 12);
1075 1439
1076 NEED_SUCCESS (EnqueueCopyImage, (self, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1440 NEED_SUCCESS (EnqueueCopyImage, (self, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1077 1441
1078 if (ev) 1442 if (ev)
1079 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1443 XPUSH_CLOBJ ("OpenCL::Event", ev);
1080 1444
1081void 1445void
1082enqueue_copy_image_to_buffer (OpenCL::Queue self, OpenCL::Image src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t dst_offset, ...) 1446enqueue_copy_image_to_buffer (OpenCL::Queue self, OpenCL::Image src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t dst_offset, ...)
1083 PPCODE: 1447 PPCODE:
1084 cl_event ev = 0; 1448 cl_event ev = 0;
1087 EVENT_LIST (10, items - 10); 1451 EVENT_LIST (10, items - 10);
1088 1452
1089 NEED_SUCCESS (EnqueueCopyImageToBuffer, (self, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1453 NEED_SUCCESS (EnqueueCopyImageToBuffer, (self, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1090 1454
1091 if (ev) 1455 if (ev)
1092 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1456 XPUSH_CLOBJ ("OpenCL::Event", ev);
1093 1457
1094void 1458void
1095enqueue_copy_buffer_to_image (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Image dst, size_t src_offset, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...) 1459enqueue_copy_buffer_to_image (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Image dst, size_t src_offset, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...)
1096 PPCODE: 1460 PPCODE:
1097 cl_event ev = 0; 1461 cl_event ev = 0;
1100 EVENT_LIST (10, items - 10); 1464 EVENT_LIST (10, items - 10);
1101 1465
1102 NEED_SUCCESS (EnqueueCopyBufferToImage, (self, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1466 NEED_SUCCESS (EnqueueCopyBufferToImage, (self, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1103 1467
1104 if (ev) 1468 if (ev)
1105 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1469 XPUSH_CLOBJ ("OpenCL::Event", ev);
1106 1470
1107void 1471void
1108enqueue_task (OpenCL::Queue self, OpenCL::Kernel kernel, ...) 1472enqueue_task (OpenCL::Queue self, OpenCL::Kernel kernel, ...)
1109 PPCODE: 1473 PPCODE:
1110 cl_event ev = 0; 1474 cl_event ev = 0;
1111 EVENT_LIST (2, items - 2); 1475 EVENT_LIST (2, items - 2);
1112 1476
1113 NEED_SUCCESS (EnqueueTask, (self, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1477 NEED_SUCCESS (EnqueueTask, (self, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1114 1478
1115 if (ev) 1479 if (ev)
1116 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1480 XPUSH_CLOBJ ("OpenCL::Event", ev);
1117 1481
1118void 1482void
1119enqueue_nd_range_kernel (OpenCL::Queue self, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...) 1483enqueue_nd_range_kernel (OpenCL::Queue self, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...)
1120 PPCODE: 1484 PPCODE:
1121 cl_event ev = 0; 1485 cl_event ev = 0;
1163 } 1527 }
1164 1528
1165 NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1529 NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1166 1530
1167 if (ev) 1531 if (ev)
1168 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1532 XPUSH_CLOBJ ("OpenCL::Event", ev);
1169 1533
1170#if cl_apple_gl_sharing || cl_khr_gl_sharing 1534#if cl_apple_gl_sharing || cl_khr_gl_sharing
1171 1535
1172void 1536void
1173enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...) 1537enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...)
1183 cl_uint num_objects = av_len (av) + 1; 1547 cl_uint num_objects = av_len (av) + 1;
1184 cl_mem *object_list = tmpbuf (sizeof (cl_mem) * num_objects); 1548 cl_mem *object_list = tmpbuf (sizeof (cl_mem) * num_objects);
1185 int i; 1549 int i;
1186 1550
1187 for (i = num_objects; i--; ) 1551 for (i = num_objects; i--; )
1188 object_list [i] = SvPTROBJ ("OpenCL::Queue::enqueue_acquire/release_gl_objects", "objects", *av_fetch (av, i, 0), "OpenCL::Memory"); 1552 object_list [i] = SvCLOBJ ("OpenCL::Queue::enqueue_acquire/release_gl_objects", "objects", *av_fetch (av, i, 0), "OpenCL::Memory");
1189 1553
1190 if (ix) 1554 if (ix)
1191 NEED_SUCCESS (EnqueueReleaseGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1555 NEED_SUCCESS (EnqueueReleaseGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1192 else 1556 else
1193 NEED_SUCCESS (EnqueueAcquireGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1557 NEED_SUCCESS (EnqueueAcquireGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1194 1558
1195 if (ev) 1559 if (ev)
1196 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1560 XPUSH_CLOBJ ("OpenCL::Event", ev);
1197 1561
1198#endif 1562#endif
1199 1563
1200#if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS
1201
1202void 1564void
1203enqueue_wait_for_events (OpenCL::Queue self, ...) 1565enqueue_wait_for_events (OpenCL::Queue self, ...)
1204 CODE: 1566 CODE:
1205 EVENT_LIST (1, items - 1); 1567 EVENT_LIST (1, items - 1);
1568#if PREFER_1_1
1206 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); 1569 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr));
1207 1570#else
1571 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, 0));
1208#endif 1572#endif
1209 1573
1210void 1574void
1211enqueue_marker (OpenCL::Queue self, ...) 1575enqueue_marker (OpenCL::Queue self, ...)
1212 PPCODE: 1576 PPCODE:
1213 cl_event ev = 0; 1577 cl_event ev = 0;
1214 EVENT_LIST (1, items - 1); 1578 EVENT_LIST (1, items - 1);
1579#if PREFER_1_1
1580 if (!event_list_count)
1581 NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0));
1582 else
1215#if CL_VERSION_1_2 1583#if CL_VERSION_1_2
1584 NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1585#else
1586 {
1587 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); // also a barrier
1588 NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0));
1589 }
1590#endif
1591#else
1216 NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1592 NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1217#else
1218 if (event_list_count)
1219 croak ("OpenCL::Queue->enqueue_marker does not support a wait list in OpenCL 1.1 - upgrade to 1.2");
1220 NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0));
1221#endif 1593#endif
1222 if (ev) 1594 if (ev)
1223 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1595 XPUSH_CLOBJ ("OpenCL::Event", ev);
1224 1596
1225void 1597void
1226enqueue_barrier (OpenCL::Queue self, ...) 1598enqueue_barrier (OpenCL::Queue self, ...)
1227 PPCODE: 1599 PPCODE:
1228 cl_event ev = 0; 1600 cl_event ev = 0;
1229 EVENT_LIST (1, items - 1); 1601 EVENT_LIST (1, items - 1);
1602#if PREFER_1_1
1603 if (!event_list_count && GIMME_V == G_VOID)
1604 NEED_SUCCESS (EnqueueBarrier, (self));
1605 else
1230#if CL_VERSION_1_2 1606#if CL_VERSION_1_2
1231 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, &ev)); 1607 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1232#else 1608#else
1609 {
1233 if (event_list_count) 1610 if (event_list_count)
1234 croak ("OpenCL::Queue->enqueue_barrier does not support a wait list in OpenCL 1.1 - upgrade to 1.2"); 1611 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr));
1612
1235 if (GIMME_V != G_VOID) 1613 if (GIMME_V != G_VOID)
1236 croak ("OpenCL::Queue->enqueue_barrier does not return an event object in OpenCL 1.1 - upgrade to 1.2");
1237 NEED_SUCCESS (EnqueueBarrier, (self)); 1614 NEED_SUCCESS (EnqueueMarker, (self, &ev));
1615 }
1616#endif
1617#else
1618 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1238#endif 1619#endif
1239 if (ev) 1620 if (ev)
1240 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1621 XPUSH_CLOBJ ("OpenCL::Event", ev);
1241 1622
1242void 1623void
1243flush (OpenCL::Queue self) 1624flush (OpenCL::Queue self)
1244 CODE: 1625 CODE:
1245 NEED_SUCCESS (Flush, (self)); 1626 NEED_SUCCESS (Flush, (self));
1263 NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_CONTEXT, sizeof (value), value, 0)); 1644 NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_CONTEXT, sizeof (value), value, 0));
1264 EXTEND (SP, 1); 1645 EXTEND (SP, 1);
1265 const int i = 0; 1646 const int i = 0;
1266 { 1647 {
1267 NEED_SUCCESS (RetainContext, (value [i])); 1648 NEED_SUCCESS (RetainContext, (value [i]));
1268 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i])); 1649 PUSH_CLOBJ ("OpenCL::Context", value [i]);
1269 } 1650 }
1270 1651
1271void 1652void
1272device (OpenCL::Queue self) 1653device (OpenCL::Queue self)
1273 PPCODE: 1654 PPCODE:
1274 cl_device_id value [1]; 1655 cl_device_id value [1];
1275 NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_DEVICE, sizeof (value), value, 0)); 1656 NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_DEVICE, sizeof (value), value, 0));
1276 EXTEND (SP, 1); 1657 EXTEND (SP, 1);
1277 const int i = 0; 1658 const int i = 0;
1278 { 1659 {
1279 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i])); 1660 PUSH_CLOBJ ("OpenCL::Device", value [i]);
1280 } 1661 }
1281 1662
1282void 1663void
1283reference_count (OpenCL::Queue self) 1664reference_count (OpenCL::Queue self)
1284 PPCODE: 1665 PPCODE:
1371 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_CONTEXT, sizeof (value), value, 0)); 1752 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_CONTEXT, sizeof (value), value, 0));
1372 EXTEND (SP, 1); 1753 EXTEND (SP, 1);
1373 const int i = 0; 1754 const int i = 0;
1374 { 1755 {
1375 NEED_SUCCESS (RetainContext, (value [i])); 1756 NEED_SUCCESS (RetainContext, (value [i]));
1376 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i])); 1757 PUSH_CLOBJ ("OpenCL::Context", value [i]);
1377 } 1758 }
1378 1759
1379void 1760void
1380associated_memobject (OpenCL::Memory self) 1761associated_memobject (OpenCL::Memory self)
1381 PPCODE: 1762 PPCODE:
1383 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_ASSOCIATED_MEMOBJECT, sizeof (value), value, 0)); 1764 NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_ASSOCIATED_MEMOBJECT, sizeof (value), value, 0));
1384 EXTEND (SP, 1); 1765 EXTEND (SP, 1);
1385 const int i = 0; 1766 const int i = 0;
1386 { 1767 {
1387 NEED_SUCCESS (RetainMemObject, (value [i])); 1768 NEED_SUCCESS (RetainMemObject, (value [i]));
1388 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i])); 1769 PUSH_CLOBJ ("OpenCL::Memory", value [i]);
1389 } 1770 }
1390 1771
1391#END:mem 1772#END:mem
1392 1773
1393#if cl_apple_gl_sharing || cl_khr_gl_sharing 1774#if cl_apple_gl_sharing || cl_khr_gl_sharing
1413 croak ("clCreateSubBuffer: cannot use/copy/alloc host ptr, doesn't make sense, check your flags!"); 1794 croak ("clCreateSubBuffer: cannot use/copy/alloc host ptr, doesn't make sense, check your flags!");
1414 1795
1415 cl_buffer_region crdata = { origin, size }; 1796 cl_buffer_region crdata = { origin, size };
1416 1797
1417 NEED_SUCCESS_ARG (cl_mem mem, CreateSubBuffer, (self, flags, CL_BUFFER_CREATE_TYPE_REGION, &crdata, &res)); 1798 NEED_SUCCESS_ARG (cl_mem mem, CreateSubBuffer, (self, flags, CL_BUFFER_CREATE_TYPE_REGION, &crdata, &res));
1418 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); 1799 XPUSH_CLOBJ ("OpenCL::Buffer", mem);
1419 1800
1420MODULE = OpenCL PACKAGE = OpenCL::Image 1801MODULE = OpenCL PACKAGE = OpenCL::Image
1421 1802
1422void 1803void
1423image_info (OpenCL::Image self, cl_image_info name) 1804image_info (OpenCL::Image self, cl_image_info name)
1424 PPCODE: 1805 PPCODE:
1425 INFO (Image) 1806 INFO (Image)
1807
1808void
1809format (OpenCL::Image self)
1810 PPCODE:
1811 cl_image_format format;
1812 NEED_SUCCESS (GetImageInfo, (self, CL_IMAGE_FORMAT, sizeof (format), &format, 0));
1813 EXTEND (SP, 2);
1814 PUSHs (sv_2mortal (newSVuv (format.image_channel_order)));
1815 PUSHs (sv_2mortal (newSVuv (format.image_channel_data_type)));
1426 1816
1427#BEGIN:image 1817#BEGIN:image
1428 1818
1429void 1819void
1430element_size (OpenCL::Image self) 1820element_size (OpenCL::Image self)
1500 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_CONTEXT, sizeof (value), value, 0)); 1890 NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_CONTEXT, sizeof (value), value, 0));
1501 EXTEND (SP, 1); 1891 EXTEND (SP, 1);
1502 const int i = 0; 1892 const int i = 0;
1503 { 1893 {
1504 NEED_SUCCESS (RetainContext, (value [i])); 1894 NEED_SUCCESS (RetainContext, (value [i]));
1505 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i])); 1895 PUSH_CLOBJ ("OpenCL::Context", value [i]);
1506 } 1896 }
1507 1897
1508void 1898void
1509normalized_coords (OpenCL::Sampler self) 1899normalized_coords (OpenCL::Sampler self)
1510 PPCODE: 1900 PPCODE:
1540DESTROY (OpenCL::Program self) 1930DESTROY (OpenCL::Program self)
1541 CODE: 1931 CODE:
1542 clReleaseProgram (self); 1932 clReleaseProgram (self);
1543 1933
1544void 1934void
1545build (OpenCL::Program self, OpenCL::Device device, SV *options = &PL_sv_undef) 1935build (OpenCL::Program self, SV *devices = &PL_sv_undef, SV *options = &PL_sv_undef, SV *notify = &PL_sv_undef)
1936 ALIAS:
1937 build_async = 1
1546 CODE: 1938 CODE:
1939 void (CL_CALLBACK *pfn_notify)(cl_program program, void *user_data) = 0;
1940 void *user_data = 0;
1941 cl_uint num_devices = 0;
1942 cl_device_id *device_list = 0;
1943
1944 if (SvOK (devices))
1945 {
1946 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV)
1947 croak ("clProgramBuild: devices must be undef or an array of OpenCL::Device objects.");
1948
1949 AV *av = (AV *)SvRV (devices);
1950 num_devices = av_len (av) + 1;
1951
1952 if (num_devices)
1953 {
1954 device_list = tmpbuf (sizeof (*device_list) * num_devices);
1955 int count;
1956 for (count = 0; count < num_devices; ++count)
1957 device_list [count] = SvCLOBJ ("clBuildProgram", "devices", *av_fetch (av, count, 1), "OpenCL::Device");
1958 }
1959 }
1960
1961 if (SvOK (notify))
1962 {
1963 NEED_SUCCESS (RetainProgram, (self));
1964 pfn_notify = eq_program_notify;
1965 user_data = SvREFCNT_inc (s_get_cv (notify));
1966 }
1967
1968 if (ix)
1969 build_program_async (self, num_devices, device_list, SvPVbyte_nolen (options), user_data);
1970 else
1547 NEED_SUCCESS (BuildProgram, (self, 1, &device, SvPVbyte_nolen (options), 0, 0)); 1971 NEED_SUCCESS (BuildProgram, (self, num_devices, device_list, SvPVbyte_nolen (options), pfn_notify, user_data));
1548 1972
1549void 1973void
1550build_info (OpenCL::Program self, OpenCL::Device device, cl_program_build_info name) 1974build_info (OpenCL::Program self, OpenCL::Device device, cl_program_build_info name)
1551 PPCODE: 1975 PPCODE:
1552 size_t size; 1976 size_t size;
1587 2011
1588void 2012void
1589kernel (OpenCL::Program program, SV *function) 2013kernel (OpenCL::Program program, SV *function)
1590 PPCODE: 2014 PPCODE:
1591 NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res)); 2015 NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res));
1592 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel); 2016 XPUSH_CLOBJ ("OpenCL::Kernel", kernel);
2017
2018void
2019kernels_in_program (OpenCL::Program program)
2020 PPCODE:
2021 cl_uint num_kernels;
2022 NEED_SUCCESS (CreateKernelsInProgram, (program, 0, 0, &num_kernels));
2023 cl_kernel *kernels = tmpbuf (sizeof (cl_kernel) * num_kernels);
2024 NEED_SUCCESS (CreateKernelsInProgram, (program, num_kernels, kernels, 0));
2025
2026 int i;
2027 EXTEND (SP, num_kernels);
2028 for (i = 0; i < num_kernels; ++i)
2029 PUSH_CLOBJ ("OpenCL::Kernel", kernels [i]);
1593 2030
1594void 2031void
1595info (OpenCL::Program self, cl_program_info name) 2032info (OpenCL::Program self, cl_program_info name)
1596 PPCODE: 2033 PPCODE:
1597 INFO (Program) 2034 INFO (Program)
1645 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_CONTEXT, sizeof (value), value, 0)); 2082 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_CONTEXT, sizeof (value), value, 0));
1646 EXTEND (SP, 1); 2083 EXTEND (SP, 1);
1647 const int i = 0; 2084 const int i = 0;
1648 { 2085 {
1649 NEED_SUCCESS (RetainContext, (value [i])); 2086 NEED_SUCCESS (RetainContext, (value [i]));
1650 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i])); 2087 PUSH_CLOBJ ("OpenCL::Context", value [i]);
1651 } 2088 }
1652 2089
1653void 2090void
1654devices (OpenCL::Program self) 2091devices (OpenCL::Program self)
1655 PPCODE: 2092 PPCODE:
1659 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_DEVICES, size, value, 0)); 2096 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_DEVICES, size, value, 0));
1660 int i, n = size / sizeof (*value); 2097 int i, n = size / sizeof (*value);
1661 EXTEND (SP, n); 2098 EXTEND (SP, n);
1662 for (i = 0; i < n; ++i) 2099 for (i = 0; i < n; ++i)
1663 { 2100 {
1664 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i])); 2101 PUSH_CLOBJ ("OpenCL::Device", value [i]);
1665 } 2102 }
1666 2103
1667void 2104void
1668source (OpenCL::Program self) 2105source (OpenCL::Program self)
1669 PPCODE: 2106 PPCODE:
1823 NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_CONTEXT, sizeof (value), value, 0)); 2260 NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_CONTEXT, sizeof (value), value, 0));
1824 EXTEND (SP, 1); 2261 EXTEND (SP, 1);
1825 const int i = 0; 2262 const int i = 0;
1826 { 2263 {
1827 NEED_SUCCESS (RetainContext, (value [i])); 2264 NEED_SUCCESS (RetainContext, (value [i]));
1828 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i])); 2265 PUSH_CLOBJ ("OpenCL::Context", value [i]);
1829 } 2266 }
1830 2267
1831void 2268void
1832program (OpenCL::Kernel self) 2269program (OpenCL::Kernel self)
1833 PPCODE: 2270 PPCODE:
1835 NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_PROGRAM, sizeof (value), value, 0)); 2272 NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_PROGRAM, sizeof (value), value, 0));
1836 EXTEND (SP, 1); 2273 EXTEND (SP, 1);
1837 const int i = 0; 2274 const int i = 0;
1838 { 2275 {
1839 NEED_SUCCESS (RetainProgram, (value [i])); 2276 NEED_SUCCESS (RetainProgram, (value [i]));
1840 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Program", value [i])); 2277 PUSH_CLOBJ ("OpenCL::Program", value [i]);
1841 } 2278 }
1842 2279
1843#END:kernel 2280#END:kernel
1844 2281
1845void 2282void
1905wait (OpenCL::Event self) 2342wait (OpenCL::Event self)
1906 CODE: 2343 CODE:
1907 clWaitForEvents (1, &self); 2344 clWaitForEvents (1, &self);
1908 2345
1909void 2346void
2347cb (OpenCL::Event self, cl_int command_exec_callback_type, SV *cb)
2348 CODE:
2349 clSetEventCallback (self, command_exec_callback_type, eq_event_notify, SvREFCNT_inc (s_get_cv (cb)));
2350
2351void
1910info (OpenCL::Event self, cl_event_info name) 2352info (OpenCL::Event self, cl_event_info name)
1911 PPCODE: 2353 PPCODE:
1912 INFO (Event) 2354 INFO (Event)
1913 2355
1914#BEGIN:event 2356#BEGIN:event
1920 NEED_SUCCESS (GetEventInfo, (self, CL_EVENT_COMMAND_QUEUE, sizeof (value), value, 0)); 2362 NEED_SUCCESS (GetEventInfo, (self, CL_EVENT_COMMAND_QUEUE, sizeof (value), value, 0));
1921 EXTEND (SP, 1); 2363 EXTEND (SP, 1);
1922 const int i = 0; 2364 const int i = 0;
1923 { 2365 {
1924 NEED_SUCCESS (RetainCommandQueue, (value [i])); 2366 NEED_SUCCESS (RetainCommandQueue, (value [i]));
1925 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Queue", value [i])); 2367 PUSH_CLOBJ ("OpenCL::Queue", value [i]);
1926 } 2368 }
1927 2369
1928void 2370void
1929command_type (OpenCL::Event self) 2371command_type (OpenCL::Event self)
1930 PPCODE: 2372 PPCODE:
1953 NEED_SUCCESS (GetEventInfo, (self, CL_EVENT_CONTEXT, sizeof (value), value, 0)); 2395 NEED_SUCCESS (GetEventInfo, (self, CL_EVENT_CONTEXT, sizeof (value), value, 0));
1954 EXTEND (SP, 1); 2396 EXTEND (SP, 1);
1955 const int i = 0; 2397 const int i = 0;
1956 { 2398 {
1957 NEED_SUCCESS (RetainContext, (value [i])); 2399 NEED_SUCCESS (RetainContext, (value [i]));
1958 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i])); 2400 PUSH_CLOBJ ("OpenCL::Context", value [i]);
1959 } 2401 }
1960 2402
1961#END:event 2403#END:event
1962 2404
1963void 2405void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines