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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.70 by root, Sat May 5 02:33:55 2012 UTC vs.
Revision 1.77 by root, Sat May 5 14:57:32 2012 UTC

28#if PREFER_1_1 28#if PREFER_1_1
29 #define CL_USE_DEPRECATED_OPENCL_1_1_APIS 29 #define CL_USE_DEPRECATED_OPENCL_1_1_APIS
30#endif 30#endif
31 31
32#ifdef __APPLE__ 32#ifdef __APPLE__
33 #include <OpenCL/opencl.h> 33 #define CLHDR(name) <OpenCL/name>
34#else 34#else
35 #define CLHDR(name) <CL/name>
36#endif
37
35 #include <CL/opencl.h> 38#include CLHDR(opencl.h)
39
40#ifndef CL_VERSION_1_2
41 #include CLHDR(cl_d3d9.h)
42#endif
43
44#if _WIN32
45 #include CLHDR(cl_d3d10.h)
46 #if CL_VERSION_1_2
47 #include CLHDR<cl_d3d11.h>
48 #endif
49 #include CLHDR<cl_dx9_media_sharing.h.h>
36#endif 50#endif
37 51
38#ifndef CL_VERSION_1_2 52#ifndef CL_VERSION_1_2
39 #undef PREFER_1_1 53 #undef PREFER_1_1
40 #define PREFER_1_1 1 54 #define PREFER_1_1 1
41#endif 55#endif
56
57// make sure all constants we might use are actually defined
58#include "default.h"
42 59
43typedef cl_platform_id OpenCL__Platform; 60typedef cl_platform_id OpenCL__Platform;
44typedef cl_device_id OpenCL__Device; 61typedef cl_device_id OpenCL__Device;
45typedef cl_device_id OpenCL__SubDevice; 62typedef cl_device_id OpenCL__SubDevice;
46typedef cl_context OpenCL__Context; 63typedef cl_context OpenCL__Context;
57typedef cl_kernel OpenCL__Kernel; 74typedef cl_kernel OpenCL__Kernel;
58typedef cl_event OpenCL__Event; 75typedef cl_event OpenCL__Event;
59typedef cl_event OpenCL__UserEvent; 76typedef cl_event OpenCL__UserEvent;
60 77
61typedef struct mapped * OpenCL__Mapped; 78typedef struct mapped * OpenCL__Mapped;
62
63typedef SV *FUTURE;
64 79
65static HV 80static HV
66 *stash_platform, 81 *stash_platform,
67 *stash_device, 82 *stash_device,
68 *stash_subdevice, 83 *stash_subdevice,
177 IV iv; 192 IV iv;
178 const char *name; 193 const char *name;
179 #define const_iv(name) { (IV)CL_ ## name, # name }, 194 #define const_iv(name) { (IV)CL_ ## name, # name },
180} ivstr; 195} ivstr;
181 196
197typedef struct
198{
199 NV nv;
200 const char *name;
201 #define const_nv(name) { (NV)CL_ ## name, # name },
202} nvstr;
203
182static const char * 204static const char *
183iv2str (IV value, const ivstr *base, int count, const char *fallback) 205iv2str (IV value, const ivstr *base, int count, const char *fallback)
184{ 206{
185 int i; 207 int i;
186 static char strbuf [32]; 208 static char strbuf [32];
246#define XPUSH_CLOBJ(stash,id) XPUSHs (new_clobj ((stash), (IV)(id))) 268#define XPUSH_CLOBJ(stash,id) XPUSHs (new_clobj ((stash), (IV)(id)))
247 269
248/* cl objects are either \$iv, or [$iv, ...] */ 270/* cl objects are either \$iv, or [$iv, ...] */
249/* they can be upgraded at runtime to the array form */ 271/* they can be upgraded at runtime to the array form */
250static void * ecb_noinline 272static void * ecb_noinline
251SvCLOBJ (const char *func, const char *svname, SV *sv, const char *pkg) 273SvCLOBJ (CV *cv, const char *svname, SV *sv, const char *pkg)
252{ 274{
253 // sv_derived_from is quite slow :( 275 // sv_derived_from is quite slow :(
254 if (SvROK (sv) && sv_derived_from (sv, pkg)) 276 if (SvROK (sv) && sv_derived_from (sv, pkg))
255 return (void *)SvIV (SvRV (sv)); 277 return (void *)SvIV (SvRV (sv));
256 278
257 croak ("%s: %s is not of type %s", func, svname, pkg); 279 croak ("%s: %s is not of type %s", cv_get_name (cv), svname, pkg);
258} 280}
259 281
260// the "no-inherit" version of the above 282// the "no-inherit" version of the above
261static void * ecb_noinline 283static void * ecb_noinline
262SvCLOBJ_ni (const char *func, const char *svname, SV *sv, HV *stash) 284SvCLOBJ_ni (CV *cv, const char *svname, SV *sv, HV *stash)
263{ 285{
264 if (SvROK (sv) && SvSTASH (SvRV (sv)) == stash) 286 if (SvROK (sv) && SvSTASH (SvRV (sv)) == stash)
265 return (void *)SvIV (SvRV (sv)); 287 return (void *)SvIV (SvRV (sv));
266 288
267 croak ("%s: %s is not of type %s", func, svname, HvNAME (stash)); 289 croak ("%s: %s is not of type %s", cv_get_name (cv), svname, HvNAME (stash));
268} 290}
269 291
270/*****************************************************************************/ 292/*****************************************************************************/
271 293
272static cl_context_properties * ecb_noinline 294static cl_context_properties * ecb_noinline
273SvCONTEXTPROPERTIES (const char *func, const char *svname, SV *sv, cl_context_properties *extra, int extracount) 295SvCONTEXTPROPERTIES (CV *cv, const char *svname, SV *sv, cl_context_properties *extra, int extracount)
274{ 296{
275 if (!sv || !SvOK (sv)) 297 if (!sv || !SvOK (sv))
276 if (extra) 298 if (extra)
277 sv = sv_2mortal (newRV_noinc ((SV *)newAV ())); // slow, but rarely used hopefully 299 sv = sv_2mortal (newRV_noinc ((SV *)newAV ())); // slow, but rarely used hopefully
278 else 300 else
284 int i, len = av_len (av) + 1; 306 int i, len = av_len (av) + 1;
285 cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1)); 307 cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1));
286 cl_context_properties *l = p; 308 cl_context_properties *l = p;
287 309
288 if (len & 1) 310 if (len & 1)
289 croak ("%s: %s is not a property list (must contain an even number of elements)", func, svname); 311 croak ("%s: %s is not a property list (must contain an even number of elements)", cv_get_name (cv), svname);
290 312
291 while (extracount--) 313 while (extracount--)
292 *l++ = *extra++; 314 *l++ = *extra++;
293 315
294 for (i = 0; i < len; i += 2) 316 for (i = 0; i < len; i += 2)
299 321
300 switch (t) 322 switch (t)
301 { 323 {
302 case CL_CONTEXT_PLATFORM: 324 case CL_CONTEXT_PLATFORM:
303 if (SvROK (p_sv)) 325 if (SvROK (p_sv))
304 v = (cl_context_properties)SvCLOBJ (func, svname, p_sv, "OpenCL::Platform"); 326 v = (cl_context_properties)SvCLOBJ (cv, svname, p_sv, "OpenCL::Platform");
305 break; 327 break;
306 328
307 case CL_GLX_DISPLAY_KHR: 329 case CL_GLX_DISPLAY_KHR:
308 if (!SvOK (p_sv)) 330 if (!SvOK (p_sv))
309 { 331 {
334 *l = 0; 356 *l = 0;
335 357
336 return p; 358 return p;
337 } 359 }
338 360
339 croak ("%s: %s is not a property list (either undef or [type => value, ...])", func, svname); 361 croak ("%s: %s is not a property list (either undef or [type => value, ...])", cv_get_name (cv), svname);
340} 362}
341 363
364// parse an array of CLOBJ into a void ** array in C - works only for CLOBJs whose representation
365// is a pointer (and only on well-behaved systems).
342static void * ecb_noinline 366static void * ecb_noinline
343object_list (CV *cv, int or_undef, const char *argname, SV *arg, const char *klass, cl_uint *rcount) 367object_list (CV *cv, int or_undef, const char *argname, SV *arg, const char *klass, cl_uint *rcount)
344{ 368{
345 const char *funcname = cv_get_name (cv);
346
347 if (!SvROK (arg) || SvTYPE (SvRV (arg)) != SVt_PVAV) 369 if (!SvROK (arg) || SvTYPE (SvRV (arg)) != SVt_PVAV)
348 croak ("%s: '%s' parameter must be %sa reference to an array of %s objects", 370 croak ("%s: '%s' parameter must be %sa reference to an array of %s objects",
349 funcname, argname, or_undef ? "undef or " : "", klass); 371 cv_get_name (cv), argname, or_undef ? "undef or " : "", klass);
350 372
351 AV *av = (AV *)SvRV (arg); 373 AV *av = (AV *)SvRV (arg);
352 void **list = 0; 374 void **list = 0;
353 cl_uint count = av_len (av) + 1; 375 cl_uint count = av_len (av) + 1;
354 376
355 if (count) 377 if (count)
356 { 378 {
357 list = tmpbuf (sizeof (*list) * count); 379 list = tmpbuf (sizeof (*list) * count);
358 int i; 380 int i;
359 for (i = 0; i < count; ++i) 381 for (i = 0; i < count; ++i)
360 list [i] = SvCLOBJ (funcname, argname, *av_fetch (av, i, 1), klass); 382 list [i] = SvCLOBJ (cv, argname, *av_fetch (av, i, 1), klass);
361 } 383 }
362 384
363 if (!count && !or_undef) 385 if (!count && !or_undef)
364 croak ("%s: '%s' must contain at least one %s object", 386 croak ("%s: '%s' must contain at least one %s object",
365 funcname, argname, klass); 387 cv_get_name (cv), argname, klass);
366 388
367 *rcount = count; 389 *rcount = count;
368 return (void *)list; 390 return (void *)list;
369} 391}
370 392
628 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); 650 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0);
629 return res; 651 return res;
630} 652}
631 653
632static cl_event * ecb_noinline 654static cl_event * ecb_noinline
633event_list (SV **items, cl_uint *rcount, cl_event extra) 655event_list (CV *cv, SV **items, cl_uint *rcount, cl_event extra)
634{ 656{
635 cl_uint count = *rcount; 657 cl_uint count = *rcount;
636 658
637 if (count > 0x7fffffffU) // yeah, it's a hack - the caller might have underflowed 659 if (count > 0x7fffffffU) // yeah, it's a hack - the caller might have underflowed
638 *rcount = count = 0; 660 *rcount = count = 0;
643 cl_event *list = tmpbuf (sizeof (cl_event) * (count + 1)); 665 cl_event *list = tmpbuf (sizeof (cl_event) * (count + 1));
644 int i = 0; 666 int i = 0;
645 667
646 while (count--) 668 while (count--)
647 if (SvOK (items [count])) 669 if (SvOK (items [count]))
648 list [i++] = SvCLOBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); 670 list [i++] = SvCLOBJ (cv, "wait_events", items [count], "OpenCL::Event");
649 671
650 if (extra) 672 if (extra)
651 list [i++] = extra; 673 list [i++] = extra;
652 674
653 *rcount = i; 675 *rcount = i;
655 return i ? list : 0; 677 return i ? list : 0;
656} 678}
657 679
658#define EVENT_LIST(skip) \ 680#define EVENT_LIST(skip) \
659 cl_uint event_list_count = items - (skip); \ 681 cl_uint event_list_count = items - (skip); \
660 cl_event *event_list_ptr = event_list (&ST (skip), &event_list_count, 0) 682 cl_event *event_list_ptr = event_list (cv, &ST (skip), &event_list_count, 0)
661 683
662#define INFO(class) \ 684#define INFO(class) \
663{ \ 685{ \
664 size_t size; \ 686 size_t size; \
665 NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ 687 NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \
747 769
748 mapped->ptr = 0; 770 mapped->ptr = 0;
749} 771}
750 772
751static void 773static void
752mapped_unmap (SV *self, OpenCL__Mapped mapped, cl_command_queue queue, SV **wait_list, cl_uint event_list_count) 774mapped_unmap (CV *cv, SV *self, OpenCL__Mapped mapped, cl_command_queue queue, SV **wait_list, cl_uint event_list_count)
753{ 775{
754 cl_event *event_list_ptr = event_list (wait_list, &event_list_count, mapped->event); 776 cl_event *event_list_ptr = event_list (cv, wait_list, &event_list_count, mapped->event);
755 cl_event ev; 777 cl_event ev;
756 778
757 NEED_SUCCESS (EnqueueUnmapMemObject, (queue, mapped->memobj, mapped->ptr, event_list_count, event_list_ptr, &ev)); 779 NEED_SUCCESS (EnqueueUnmapMemObject, (queue, mapped->memobj, mapped->ptr, event_list_count, event_list_ptr, &ev));
758 780
759 clReleaseEvent (mapped->event); 781 clReleaseEvent (mapped->event);
780 eq_signal_arg = (void*)arg; 802 eq_signal_arg = (void*)arg;
781 803
782BOOT: 804BOOT:
783{ 805{
784 HV *stash = gv_stashpv ("OpenCL", 1); 806 HV *stash = gv_stashpv ("OpenCL", 1);
807
785 static const ivstr *civ, const_iv[] = { 808 static const ivstr *civ, const_iv[] = {
786 { sizeof (cl_char ), "SIZEOF_CHAR" }, 809 { sizeof (cl_char ), "SIZEOF_CHAR" },
787 { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, 810 { sizeof (cl_uchar ), "SIZEOF_UCHAR" },
788 { sizeof (cl_short ), "SIZEOF_SHORT" }, 811 { sizeof (cl_short ), "SIZEOF_SHORT" },
789 { sizeof (cl_ushort), "SIZEOF_USHORT" }, 812 { sizeof (cl_ushort), "SIZEOF_USHORT" },
792 { sizeof (cl_long ), "SIZEOF_LONG" }, 815 { sizeof (cl_long ), "SIZEOF_LONG" },
793 { sizeof (cl_ulong ), "SIZEOF_ULONG" }, 816 { sizeof (cl_ulong ), "SIZEOF_ULONG" },
794 { sizeof (cl_half ), "SIZEOF_HALF" }, 817 { sizeof (cl_half ), "SIZEOF_HALF" },
795 { sizeof (cl_float ), "SIZEOF_FLOAT" }, 818 { sizeof (cl_float ), "SIZEOF_FLOAT" },
796 { sizeof (cl_double), "SIZEOF_DOUBLE" }, 819 { sizeof (cl_double), "SIZEOF_DOUBLE" },
820 { PREFER_1_1 , "PREFER_1_1" },
797#include "constiv.h" 821#include "constiv.h"
798 }; 822 };
799 823
800 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 824 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
801 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 825 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
826
827 static const nvstr *cnv, const_nv[] = {
828#include "constnv.h"
829 };
830
831 for (cnv = const_nv + sizeof (const_nv) / sizeof (const_nv [0]); cnv > const_nv; cnv--)
832 newCONSTSUB (stash, (char *)cnv[-1].name, newSVnv (cnv[-1].nv));
833
834 newCONSTSUB (stash, "NAN", newSVnv (CL_NAN)); // CL_NAN might be a function call
802 835
803 stash_platform = gv_stashpv ("OpenCL::Platform", GV_ADD); 836 stash_platform = gv_stashpv ("OpenCL::Platform", GV_ADD);
804 stash_device = gv_stashpv ("OpenCL::Device", GV_ADD); 837 stash_device = gv_stashpv ("OpenCL::Device", GV_ADD);
805 stash_subdevice = gv_stashpv ("OpenCL::SubDevice", GV_ADD); 838 stash_subdevice = gv_stashpv ("OpenCL::SubDevice", GV_ADD);
806 stash_context = gv_stashpv ("OpenCL::Context", GV_ADD); 839 stash_context = gv_stashpv ("OpenCL::Context", GV_ADD);
861 CONTEXT_NOTIFY_CALLBACK; 894 CONTEXT_NOTIFY_CALLBACK;
862 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, pfn_notify, user_data, &res)); 895 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, pfn_notify, user_data, &res));
863 XPUSH_CLOBJ_CONTEXT; 896 XPUSH_CLOBJ_CONTEXT;
864 897
865void 898void
866context (FUTURE properties, FUTURE devices, FUTURE notify) 899context (cl_context_properties *properties, SV *devices, SV *notify = &PL_sv_undef)
867 PPCODE: 900 PPCODE:
868 /* der Gipfel der Kunst */ 901 cl_uint device_count;
902 cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count);
903
904 CONTEXT_NOTIFY_CALLBACK;
905 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (properties, device_count, device_list, pfn_notify, user_data, &res));
906 XPUSH_CLOBJ_CONTEXT;
869 907
870void 908void
871wait_for_events (...) 909wait_for_events (...)
872 CODE: 910 CODE:
873 EVENT_LIST (0); 911 EVENT_LIST (0);
924 EXTEND (SP, count); 962 EXTEND (SP, count);
925 for (i = 0; i < count; ++i) 963 for (i = 0; i < count; ++i)
926 PUSH_CLOBJ (stash_device, list [i]); 964 PUSH_CLOBJ (stash_device, list [i]);
927 965
928void 966void
929context (OpenCL::Platform self, SV *properties = 0, SV *devices, SV *notify = &PL_sv_undef) 967context (OpenCL::Platform self, SV *properties, SV *devices, SV *notify = &PL_sv_undef)
930 PPCODE: 968 PPCODE:
931 cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self }; 969 cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self };
932 cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context", "properties", properties, extra, 2); 970 cl_context_properties *props = SvCONTEXTPROPERTIES (cv, "properties", properties, extra, 2);
933 971
934 cl_uint device_count = 0; 972 cl_uint device_count;
935 cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); 973 cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count);
936 974
937 CONTEXT_NOTIFY_CALLBACK; 975 CONTEXT_NOTIFY_CALLBACK;
938 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (props, device_count, device_list, pfn_notify, user_data, &res)); 976 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (props, device_count, device_list, pfn_notify, user_data, &res));
939 XPUSH_CLOBJ_CONTEXT; 977 XPUSH_CLOBJ_CONTEXT;
940 978
941void 979void
942context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef) 980context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef)
943 PPCODE: 981 PPCODE:
944 cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self }; 982 cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self };
945 cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context_from_type", "properties", properties, extra, 2); 983 cl_context_properties *props = SvCONTEXTPROPERTIES (cv, "properties", properties, extra, 2);
946 984
947 CONTEXT_NOTIFY_CALLBACK; 985 CONTEXT_NOTIFY_CALLBACK;
948 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, pfn_notify, user_data, &res)); 986 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, pfn_notify, user_data, &res));
949 XPUSH_CLOBJ_CONTEXT; 987 XPUSH_CLOBJ_CONTEXT;
950 988
1274 const cl_image_desc desc = { 1312 const cl_image_desc desc = {
1275 type, 1313 type,
1276 width, height, depth, 1314 width, height, depth,
1277 array_size, row_pitch, slice_pitch, 1315 array_size, row_pitch, slice_pitch,
1278 num_mip_level, num_samples, 1316 num_mip_level, num_samples,
1279 type == CL_MEM_OBJECT_IMAGE1D_BUFFER ? (cl_mem)SvCLOBJ ("OpenCL::Context::Image", "data", data, "OpenCL::Buffer") : 0 1317 type == CL_MEM_OBJECT_IMAGE1D_BUFFER ? (cl_mem)SvCLOBJ (cv, "data", data, "OpenCL::Buffer") : 0
1280 }; 1318 };
1281 NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res)); 1319 NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
1282 HV *stash = stash_image; 1320 HV *stash = stash_image;
1283 switch (type) 1321 switch (type)
1284 { 1322 {
1464#if CL_VERSION_1_2 1502#if CL_VERSION_1_2
1465 1503
1466void 1504void
1467program_with_built_in_kernels (OpenCL::Context self, SV *devices, SV *kernel_names) 1505program_with_built_in_kernels (OpenCL::Context self, SV *devices, SV *kernel_names)
1468 PPCODE: 1506 PPCODE:
1469 cl_uint device_count = 0; 1507 cl_uint device_count;
1470 cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); 1508 cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count);
1471 1509
1472 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBuiltInKernels, (self, device_count, device_list, SvPVbyte_nolen (kernel_names), &res)); 1510 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBuiltInKernels, (self, device_count, device_list, SvPVbyte_nolen (kernel_names), &res));
1473 1511
1474 XPUSH_CLOBJ (stash_program, prog); 1512 XPUSH_CLOBJ (stash_program, prog);
1475 1513
1899 XPUSHs (mapped_new (stash_mappedimage, self, img, map_flags, ptr, cb, ev, row_pitch, slice_pitch)); 1937 XPUSHs (mapped_new (stash_mappedimage, self, img, map_flags, ptr, cb, ev, row_pitch, slice_pitch));
1900 1938
1901void 1939void
1902unmap (OpenCL::Queue self, OpenCL::Mapped mapped, ...) 1940unmap (OpenCL::Queue self, OpenCL::Mapped mapped, ...)
1903 PPCODE: 1941 PPCODE:
1904 mapped_unmap (ST (1), mapped, self, &ST (2), items - 2); 1942 mapped_unmap (cv, ST (1), mapped, self, &ST (2), items - 2);
1905 if (GIMME_V != G_VOID) 1943 if (GIMME_V != G_VOID)
1906 { 1944 {
1907 clRetainEvent (mapped->event); 1945 clRetainEvent (mapped->event);
1908 XPUSH_CLOBJ (stash_event, mapped->event); 1946 XPUSH_CLOBJ (stash_event, mapped->event);
1909 } 1947 }
2167void 2205void
2168info (OpenCL::Memory self, cl_mem_info name) 2206info (OpenCL::Memory self, cl_mem_info name)
2169 PPCODE: 2207 PPCODE:
2170 INFO (MemObject) 2208 INFO (MemObject)
2171 2209
2210void
2211destructor_callback (OpenCL::Memory self, SV *notify)
2212 PPCODE:
2213
2172#BEGIN:mem 2214#BEGIN:mem
2173 2215
2174void 2216void
2175type (OpenCL::Memory self) 2217type (OpenCL::Memory self)
2176 PPCODE: 2218 PPCODE:
2456 HE *he; 2498 HE *he;
2457 int i = 0; 2499 int i = 0;
2458 while (he = hv_iternext (hv)) 2500 while (he = hv_iternext (hv))
2459 { 2501 {
2460 header_name [i] = SvPVbyte_nolen (HeSVKEY_force (he)); 2502 header_name [i] = SvPVbyte_nolen (HeSVKEY_force (he));
2461 header_list [i] = SvCLOBJ ("clCompileProgram", "headers", HeVAL (he), "OpenCL::Program"); 2503 header_list [i] = SvCLOBJ (cv, "headers", HeVAL (he), "OpenCL::Program");
2462 ++i; 2504 ++i;
2463 } 2505 }
2464 } 2506 }
2465 2507
2466 void *user_data; 2508 void *user_data;
2505 char *value = tmpbuf (size); 2547 char *value = tmpbuf (size);
2506 NEED_SUCCESS (GetProgramBuildInfo, (self, device, ix, size, value, 0)); 2548 NEED_SUCCESS (GetProgramBuildInfo, (self, device, ix, size, value, 0));
2507 EXTEND (SP, 1); 2549 EXTEND (SP, 1);
2508 const int i = 0; 2550 const int i = 0;
2509 PUSHs (sv_2mortal (newSVpv (value, 0))); 2551 PUSHs (sv_2mortal (newSVpv (value, 0)));
2552
2553void
2554binary_type (OpenCL::Program self, OpenCL::Device device)
2555 PPCODE:
2556 cl_program_binary_type value [1];
2557 NEED_SUCCESS (GetProgramBuildInfo, (self, device, CL_PROGRAM_BINARY_TYPE, sizeof (value), value, 0));
2558 EXTEND (SP, 1);
2559 const int i = 0;
2560 PUSHs (sv_2mortal (newSVuv ((UV)value [i])));
2510 2561
2511#END:program_build 2562#END:program_build
2512 2563
2513void 2564void
2514kernel (OpenCL::Program program, SV *function) 2565kernel (OpenCL::Program program, SV *function)
2681 case 'f': arg.cf = SvNV (sv); size = sizeof (arg.cf); break; 2732 case 'f': arg.cf = SvNV (sv); size = sizeof (arg.cf); break;
2682 case 'd': arg.cd = SvNV (sv); size = sizeof (arg.cd); break; 2733 case 'd': arg.cd = SvNV (sv); size = sizeof (arg.cd); break;
2683 2734
2684 case 'z': nullarg = 1; size = SvIV (sv); break; 2735 case 'z': nullarg = 1; size = SvIV (sv); break;
2685 2736
2686 case 'm': nullarg = !SvOK (sv); arg.cm = SvCLOBJ ("OpenCL::Kernel::setf", "m", sv, "OpenCL::Memory" ); size = sizeof (arg.cm); break; 2737 case 'm': nullarg = !SvOK (sv); arg.cm = SvCLOBJ (cv, "m", sv, "OpenCL::Memory" ); size = sizeof (arg.cm); break;
2687 case 'a': nullarg = !SvOK (sv); arg.ca = SvCLOBJ ("OpenCL::Kernel::setf", "a", sv, "OpenCL::Sampler"); size = sizeof (arg.ca); break; 2738 case 'a': nullarg = !SvOK (sv); arg.ca = SvCLOBJ (cv, "a", sv, "OpenCL::Sampler"); size = sizeof (arg.ca); break;
2688 case 'e': nullarg = !SvOK (sv); arg.ca = SvCLOBJ ("OpenCL::Kernel::setf", "e", sv, "OpenCL::Event" ); size = sizeof (arg.ce); break; 2739 case 'e': nullarg = !SvOK (sv); arg.ca = SvCLOBJ (cv, "e", sv, "OpenCL::Event" ); size = sizeof (arg.ce); break;
2689 2740
2690 default: 2741 default:
2691 croak ("OpenCL::Kernel::setf format character '%c' not supported", type); 2742 croak ("OpenCL::Kernel::setf format character '%c' not supported", type);
2692 } 2743 }
2693 2744
2764 CODE: 2815 CODE:
2765 clSetKernelArg (self, idx, sizeof (value), value ? &value : 0); 2816 clSetKernelArg (self, idx, sizeof (value), value ? &value : 0);
2766 2817
2767void 2818void
2768set_image (OpenCL::Kernel self, cl_uint idx, OpenCL::Image_ornull value) 2819set_image (OpenCL::Kernel self, cl_uint idx, OpenCL::Image_ornull value)
2769 ALIAS:
2770 set_image2d = 0
2771 set_image3d = 0
2772 CODE: 2820 CODE:
2773 clSetKernelArg (self, idx, sizeof (value), value ? &value : 0); 2821 clSetKernelArg (self, idx, sizeof (value), value ? &value : 0);
2774 2822
2775void 2823void
2776set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) 2824set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value)
3072 Safefree (mapped); 3120 Safefree (mapped);
3073 3121
3074void 3122void
3075unmap (OpenCL::Mapped self, ...) 3123unmap (OpenCL::Mapped self, ...)
3076 CODE: 3124 CODE:
3077 mapped_unmap (ST (0), self, self->queue, &ST (1), items - 1); 3125 mapped_unmap (cv, ST (0), self, self->queue, &ST (1), items - 1);
3078 3126
3079bool 3127bool
3080mapped (OpenCL::Mapped self) 3128mapped (OpenCL::Mapped self)
3081 CODE: 3129 CODE:
3082 RETVAL = !!self->ptr; 3130 RETVAL = !!self->ptr;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines