… | |
… | |
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 | |
43 | typedef cl_platform_id OpenCL__Platform; |
60 | typedef cl_platform_id OpenCL__Platform; |
44 | typedef cl_device_id OpenCL__Device; |
61 | typedef cl_device_id OpenCL__Device; |
45 | typedef cl_device_id OpenCL__SubDevice; |
62 | typedef cl_device_id OpenCL__SubDevice; |
46 | typedef cl_context OpenCL__Context; |
63 | typedef cl_context OpenCL__Context; |
… | |
… | |
57 | typedef cl_kernel OpenCL__Kernel; |
74 | typedef cl_kernel OpenCL__Kernel; |
58 | typedef cl_event OpenCL__Event; |
75 | typedef cl_event OpenCL__Event; |
59 | typedef cl_event OpenCL__UserEvent; |
76 | typedef cl_event OpenCL__UserEvent; |
60 | |
77 | |
61 | typedef struct mapped * OpenCL__Mapped; |
78 | typedef struct mapped * OpenCL__Mapped; |
62 | |
|
|
63 | typedef SV *FUTURE; |
|
|
64 | |
79 | |
65 | static HV |
80 | static HV |
66 | *stash_platform, |
81 | *stash_platform, |
67 | *stash_device, |
82 | *stash_device, |
68 | *stash_subdevice, |
83 | *stash_subdevice, |
… | |
… | |
246 | #define XPUSH_CLOBJ(stash,id) XPUSHs (new_clobj ((stash), (IV)(id))) |
261 | #define XPUSH_CLOBJ(stash,id) XPUSHs (new_clobj ((stash), (IV)(id))) |
247 | |
262 | |
248 | /* cl objects are either \$iv, or [$iv, ...] */ |
263 | /* cl objects are either \$iv, or [$iv, ...] */ |
249 | /* they can be upgraded at runtime to the array form */ |
264 | /* they can be upgraded at runtime to the array form */ |
250 | static void * ecb_noinline |
265 | static void * ecb_noinline |
251 | SvCLOBJ (const char *func, const char *svname, SV *sv, const char *pkg) |
266 | SvCLOBJ (CV *cv, const char *svname, SV *sv, const char *pkg) |
252 | { |
267 | { |
253 | // sv_derived_from is quite slow :( |
268 | // sv_derived_from is quite slow :( |
254 | if (SvROK (sv) && sv_derived_from (sv, pkg)) |
269 | if (SvROK (sv) && sv_derived_from (sv, pkg)) |
255 | return (void *)SvIV (SvRV (sv)); |
270 | return (void *)SvIV (SvRV (sv)); |
256 | |
271 | |
257 | croak ("%s: %s is not of type %s", func, svname, pkg); |
272 | croak ("%s: %s is not of type %s", cv_get_name (cv), svname, pkg); |
258 | } |
273 | } |
259 | |
274 | |
260 | // the "no-inherit" version of the above |
275 | // the "no-inherit" version of the above |
261 | static void * ecb_noinline |
276 | static void * ecb_noinline |
262 | SvCLOBJ_ni (const char *func, const char *svname, SV *sv, HV *stash) |
277 | SvCLOBJ_ni (CV *cv, const char *svname, SV *sv, HV *stash) |
263 | { |
278 | { |
264 | if (SvROK (sv) && SvSTASH (SvRV (sv)) == stash) |
279 | if (SvROK (sv) && SvSTASH (SvRV (sv)) == stash) |
265 | return (void *)SvIV (SvRV (sv)); |
280 | return (void *)SvIV (SvRV (sv)); |
266 | |
281 | |
267 | croak ("%s: %s is not of type %s", func, svname, HvNAME (stash)); |
282 | croak ("%s: %s is not of type %s", cv_get_name (cv), svname, HvNAME (stash)); |
268 | } |
283 | } |
269 | |
284 | |
270 | /*****************************************************************************/ |
285 | /*****************************************************************************/ |
271 | |
286 | |
272 | static cl_context_properties * ecb_noinline |
287 | static cl_context_properties * ecb_noinline |
273 | SvCONTEXTPROPERTIES (const char *func, const char *svname, SV *sv, cl_context_properties *extra, int extracount) |
288 | SvCONTEXTPROPERTIES (CV *cv, const char *svname, SV *sv, cl_context_properties *extra, int extracount) |
274 | { |
289 | { |
275 | if (!sv || !SvOK (sv)) |
290 | if (!sv || !SvOK (sv)) |
276 | if (extra) |
291 | if (extra) |
277 | sv = sv_2mortal (newRV_noinc ((SV *)newAV ())); // slow, but rarely used hopefully |
292 | sv = sv_2mortal (newRV_noinc ((SV *)newAV ())); // slow, but rarely used hopefully |
278 | else |
293 | else |
… | |
… | |
284 | int i, len = av_len (av) + 1; |
299 | int i, len = av_len (av) + 1; |
285 | cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1)); |
300 | cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1)); |
286 | cl_context_properties *l = p; |
301 | cl_context_properties *l = p; |
287 | |
302 | |
288 | if (len & 1) |
303 | if (len & 1) |
289 | croak ("%s: %s is not a property list (must contain an even number of elements)", func, svname); |
304 | croak ("%s: %s is not a property list (must contain an even number of elements)", cv_get_name (cv), svname); |
290 | |
305 | |
291 | while (extracount--) |
306 | while (extracount--) |
292 | *l++ = *extra++; |
307 | *l++ = *extra++; |
293 | |
308 | |
294 | for (i = 0; i < len; i += 2) |
309 | for (i = 0; i < len; i += 2) |
… | |
… | |
299 | |
314 | |
300 | switch (t) |
315 | switch (t) |
301 | { |
316 | { |
302 | case CL_CONTEXT_PLATFORM: |
317 | case CL_CONTEXT_PLATFORM: |
303 | if (SvROK (p_sv)) |
318 | if (SvROK (p_sv)) |
304 | v = (cl_context_properties)SvCLOBJ (func, svname, p_sv, "OpenCL::Platform"); |
319 | v = (cl_context_properties)SvCLOBJ (cv, svname, p_sv, "OpenCL::Platform"); |
305 | break; |
320 | break; |
306 | |
321 | |
307 | case CL_GLX_DISPLAY_KHR: |
322 | case CL_GLX_DISPLAY_KHR: |
308 | if (!SvOK (p_sv)) |
323 | if (!SvOK (p_sv)) |
309 | { |
324 | { |
… | |
… | |
334 | *l = 0; |
349 | *l = 0; |
335 | |
350 | |
336 | return p; |
351 | return p; |
337 | } |
352 | } |
338 | |
353 | |
339 | croak ("%s: %s is not a property list (either undef or [type => value, ...])", func, svname); |
354 | croak ("%s: %s is not a property list (either undef or [type => value, ...])", cv_get_name (cv), svname); |
340 | } |
355 | } |
341 | |
356 | |
|
|
357 | // parse an array of CLOBJ into a void ** array in C - works only for CLOBJs whose representation |
|
|
358 | // is a pointer (and only on well-behaved systems). |
342 | static void * ecb_noinline |
359 | static void * ecb_noinline |
343 | object_list (CV *cv, int or_undef, const char *argname, SV *arg, const char *klass, cl_uint *rcount) |
360 | object_list (CV *cv, int or_undef, const char *argname, SV *arg, const char *klass, cl_uint *rcount) |
344 | { |
361 | { |
345 | const char *funcname = cv_get_name (cv); |
|
|
346 | |
|
|
347 | if (!SvROK (arg) || SvTYPE (SvRV (arg)) != SVt_PVAV) |
362 | if (!SvROK (arg) || SvTYPE (SvRV (arg)) != SVt_PVAV) |
348 | croak ("%s: '%s' parameter must be %sa reference to an array of %s objects", |
363 | croak ("%s: '%s' parameter must be %sa reference to an array of %s objects", |
349 | funcname, argname, or_undef ? "undef or " : "", klass); |
364 | cv_get_name (cv), argname, or_undef ? "undef or " : "", klass); |
350 | |
365 | |
351 | AV *av = (AV *)SvRV (arg); |
366 | AV *av = (AV *)SvRV (arg); |
352 | void **list = 0; |
367 | void **list = 0; |
353 | cl_uint count = av_len (av) + 1; |
368 | cl_uint count = av_len (av) + 1; |
354 | |
369 | |
355 | if (count) |
370 | if (count) |
356 | { |
371 | { |
357 | list = tmpbuf (sizeof (*list) * count); |
372 | list = tmpbuf (sizeof (*list) * count); |
358 | int i; |
373 | int i; |
359 | for (i = 0; i < count; ++i) |
374 | for (i = 0; i < count; ++i) |
360 | list [i] = SvCLOBJ (funcname, argname, *av_fetch (av, i, 1), klass); |
375 | list [i] = SvCLOBJ (cv, argname, *av_fetch (av, i, 1), klass); |
361 | } |
376 | } |
362 | |
377 | |
363 | if (!count && !or_undef) |
378 | if (!count && !or_undef) |
364 | croak ("%s: '%s' must contain at least one %s object", |
379 | croak ("%s: '%s' must contain at least one %s object", |
365 | funcname, argname, klass); |
380 | cv_get_name (cv), argname, klass); |
366 | |
381 | |
367 | *rcount = count; |
382 | *rcount = count; |
368 | return (void *)list; |
383 | return (void *)list; |
369 | } |
384 | } |
370 | |
385 | |
… | |
… | |
628 | clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); |
643 | clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); |
629 | return res; |
644 | return res; |
630 | } |
645 | } |
631 | |
646 | |
632 | static cl_event * ecb_noinline |
647 | static cl_event * ecb_noinline |
633 | event_list (SV **items, cl_uint *rcount, cl_event extra) |
648 | event_list (CV *cv, SV **items, cl_uint *rcount, cl_event extra) |
634 | { |
649 | { |
635 | cl_uint count = *rcount; |
650 | cl_uint count = *rcount; |
636 | |
651 | |
637 | if (count > 0x7fffffffU) // yeah, it's a hack - the caller might have underflowed |
652 | if (count > 0x7fffffffU) // yeah, it's a hack - the caller might have underflowed |
638 | *rcount = count = 0; |
653 | *rcount = count = 0; |
… | |
… | |
643 | cl_event *list = tmpbuf (sizeof (cl_event) * (count + 1)); |
658 | cl_event *list = tmpbuf (sizeof (cl_event) * (count + 1)); |
644 | int i = 0; |
659 | int i = 0; |
645 | |
660 | |
646 | while (count--) |
661 | while (count--) |
647 | if (SvOK (items [count])) |
662 | if (SvOK (items [count])) |
648 | list [i++] = SvCLOBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); |
663 | list [i++] = SvCLOBJ (cv, "wait_events", items [count], "OpenCL::Event"); |
649 | |
664 | |
650 | if (extra) |
665 | if (extra) |
651 | list [i++] = extra; |
666 | list [i++] = extra; |
652 | |
667 | |
653 | *rcount = i; |
668 | *rcount = i; |
… | |
… | |
655 | return i ? list : 0; |
670 | return i ? list : 0; |
656 | } |
671 | } |
657 | |
672 | |
658 | #define EVENT_LIST(skip) \ |
673 | #define EVENT_LIST(skip) \ |
659 | cl_uint event_list_count = items - (skip); \ |
674 | cl_uint event_list_count = items - (skip); \ |
660 | cl_event *event_list_ptr = event_list (&ST (skip), &event_list_count, 0) |
675 | cl_event *event_list_ptr = event_list (cv, &ST (skip), &event_list_count, 0) |
661 | |
676 | |
662 | #define INFO(class) \ |
677 | #define INFO(class) \ |
663 | { \ |
678 | { \ |
664 | size_t size; \ |
679 | size_t size; \ |
665 | NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ |
680 | NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ |
… | |
… | |
747 | |
762 | |
748 | mapped->ptr = 0; |
763 | mapped->ptr = 0; |
749 | } |
764 | } |
750 | |
765 | |
751 | static void |
766 | static void |
752 | mapped_unmap (SV *self, OpenCL__Mapped mapped, cl_command_queue queue, SV **wait_list, cl_uint event_list_count) |
767 | mapped_unmap (CV *cv, SV *self, OpenCL__Mapped mapped, cl_command_queue queue, SV **wait_list, cl_uint event_list_count) |
753 | { |
768 | { |
754 | cl_event *event_list_ptr = event_list (wait_list, &event_list_count, mapped->event); |
769 | cl_event *event_list_ptr = event_list (cv, wait_list, &event_list_count, mapped->event); |
755 | cl_event ev; |
770 | cl_event ev; |
756 | |
771 | |
757 | NEED_SUCCESS (EnqueueUnmapMemObject, (queue, mapped->memobj, mapped->ptr, event_list_count, event_list_ptr, &ev)); |
772 | NEED_SUCCESS (EnqueueUnmapMemObject, (queue, mapped->memobj, mapped->ptr, event_list_count, event_list_ptr, &ev)); |
758 | |
773 | |
759 | clReleaseEvent (mapped->event); |
774 | clReleaseEvent (mapped->event); |
… | |
… | |
792 | { sizeof (cl_long ), "SIZEOF_LONG" }, |
807 | { sizeof (cl_long ), "SIZEOF_LONG" }, |
793 | { sizeof (cl_ulong ), "SIZEOF_ULONG" }, |
808 | { sizeof (cl_ulong ), "SIZEOF_ULONG" }, |
794 | { sizeof (cl_half ), "SIZEOF_HALF" }, |
809 | { sizeof (cl_half ), "SIZEOF_HALF" }, |
795 | { sizeof (cl_float ), "SIZEOF_FLOAT" }, |
810 | { sizeof (cl_float ), "SIZEOF_FLOAT" }, |
796 | { sizeof (cl_double), "SIZEOF_DOUBLE" }, |
811 | { sizeof (cl_double), "SIZEOF_DOUBLE" }, |
|
|
812 | { PREFER_1_1 , "PREFER_1_1" }, |
797 | #include "constiv.h" |
813 | #include "constiv.h" |
798 | }; |
814 | }; |
799 | |
815 | |
800 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
816 | 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)); |
817 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
… | |
… | |
861 | CONTEXT_NOTIFY_CALLBACK; |
877 | CONTEXT_NOTIFY_CALLBACK; |
862 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, pfn_notify, user_data, &res)); |
878 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, pfn_notify, user_data, &res)); |
863 | XPUSH_CLOBJ_CONTEXT; |
879 | XPUSH_CLOBJ_CONTEXT; |
864 | |
880 | |
865 | void |
881 | void |
866 | context (FUTURE properties, FUTURE devices, FUTURE notify) |
882 | context (cl_context_properties *properties, SV *devices, SV *notify = &PL_sv_undef) |
867 | PPCODE: |
883 | PPCODE: |
868 | /* der Gipfel der Kunst */ |
884 | cl_uint device_count; |
|
|
885 | cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); |
|
|
886 | |
|
|
887 | CONTEXT_NOTIFY_CALLBACK; |
|
|
888 | NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (properties, device_count, device_list, pfn_notify, user_data, &res)); |
|
|
889 | XPUSH_CLOBJ_CONTEXT; |
869 | |
890 | |
870 | void |
891 | void |
871 | wait_for_events (...) |
892 | wait_for_events (...) |
872 | CODE: |
893 | CODE: |
873 | EVENT_LIST (0); |
894 | EVENT_LIST (0); |
… | |
… | |
924 | EXTEND (SP, count); |
945 | EXTEND (SP, count); |
925 | for (i = 0; i < count; ++i) |
946 | for (i = 0; i < count; ++i) |
926 | PUSH_CLOBJ (stash_device, list [i]); |
947 | PUSH_CLOBJ (stash_device, list [i]); |
927 | |
948 | |
928 | void |
949 | void |
929 | context (OpenCL::Platform self, SV *properties = 0, SV *devices, SV *notify = &PL_sv_undef) |
950 | context (OpenCL::Platform self, SV *properties, SV *devices, SV *notify = &PL_sv_undef) |
930 | PPCODE: |
951 | PPCODE: |
931 | cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self }; |
952 | cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self }; |
932 | cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context", "properties", properties, extra, 2); |
953 | cl_context_properties *props = SvCONTEXTPROPERTIES (cv, "properties", properties, extra, 2); |
933 | |
954 | |
934 | cl_uint device_count = 0; |
955 | cl_uint device_count; |
935 | cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); |
956 | cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); |
936 | |
957 | |
937 | CONTEXT_NOTIFY_CALLBACK; |
958 | CONTEXT_NOTIFY_CALLBACK; |
938 | NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (props, device_count, device_list, pfn_notify, user_data, &res)); |
959 | NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (props, device_count, device_list, pfn_notify, user_data, &res)); |
939 | XPUSH_CLOBJ_CONTEXT; |
960 | XPUSH_CLOBJ_CONTEXT; |
940 | |
961 | |
941 | void |
962 | void |
942 | context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef) |
963 | context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef) |
943 | PPCODE: |
964 | PPCODE: |
944 | cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self }; |
965 | 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); |
966 | cl_context_properties *props = SvCONTEXTPROPERTIES (cv, "properties", properties, extra, 2); |
946 | |
967 | |
947 | CONTEXT_NOTIFY_CALLBACK; |
968 | CONTEXT_NOTIFY_CALLBACK; |
948 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, pfn_notify, user_data, &res)); |
969 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, pfn_notify, user_data, &res)); |
949 | XPUSH_CLOBJ_CONTEXT; |
970 | XPUSH_CLOBJ_CONTEXT; |
950 | |
971 | |
… | |
… | |
1274 | const cl_image_desc desc = { |
1295 | const cl_image_desc desc = { |
1275 | type, |
1296 | type, |
1276 | width, height, depth, |
1297 | width, height, depth, |
1277 | array_size, row_pitch, slice_pitch, |
1298 | array_size, row_pitch, slice_pitch, |
1278 | num_mip_level, num_samples, |
1299 | num_mip_level, num_samples, |
1279 | type == CL_MEM_OBJECT_IMAGE1D_BUFFER ? (cl_mem)SvCLOBJ ("OpenCL::Context::Image", "data", data, "OpenCL::Buffer") : 0 |
1300 | type == CL_MEM_OBJECT_IMAGE1D_BUFFER ? (cl_mem)SvCLOBJ (cv, "data", data, "OpenCL::Buffer") : 0 |
1280 | }; |
1301 | }; |
1281 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res)); |
1302 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res)); |
1282 | HV *stash = stash_image; |
1303 | HV *stash = stash_image; |
1283 | switch (type) |
1304 | switch (type) |
1284 | { |
1305 | { |
… | |
… | |
1420 | XPUSH_CLOBJ (stash_program, prog); |
1441 | XPUSH_CLOBJ (stash_program, prog); |
1421 | |
1442 | |
1422 | void |
1443 | void |
1423 | program_with_binary (OpenCL::Context self, SV *devices, SV *binaries) |
1444 | program_with_binary (OpenCL::Context self, SV *devices, SV *binaries) |
1424 | PPCODE: |
1445 | PPCODE: |
1425 | if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) |
1446 | cl_uint device_count; |
1426 | croak ("OpenCL::Context::program_with_binary: devices must be specified as reference to an array of device objects"); |
1447 | cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); |
1427 | |
|
|
1428 | devices = SvRV (devices); |
|
|
1429 | |
1448 | |
1430 | if (!SvROK (binaries) || SvTYPE (SvRV (binaries)) != SVt_PVAV) |
1449 | if (!SvROK (binaries) || SvTYPE (SvRV (binaries)) != SVt_PVAV) |
1431 | croak ("OpenCL::Context::program_with_binary: binaries must be specified as reference to an array of strings"); |
1450 | croak ("OpenCL::Context::program_with_binary: binaries must be specified as reference to an array of strings"); |
1432 | |
1451 | |
1433 | binaries = SvRV (binaries); |
1452 | binaries = SvRV (binaries); |
1434 | |
1453 | |
1435 | if (av_len ((AV *)devices) != av_len ((AV *)binaries)) |
1454 | if (device_count != av_len ((AV *)binaries) + 1) |
1436 | croak ("OpenCL::Context::program_with_binary: differing numbers of devices and binaries are not allowed"); |
1455 | croak ("OpenCL::Context::program_with_binary: differing numbers of devices and binaries are not allowed"); |
1437 | |
1456 | |
1438 | int count = av_len ((AV *)devices) + 1; |
|
|
1439 | cl_device_id *device_list = tmpbuf (sizeof (*device_list) * count); |
|
|
1440 | size_t *length_list = tmpbuf (sizeof (*length_list) * count); |
1457 | size_t *length_list = tmpbuf (sizeof (*length_list) * device_count); |
1441 | const unsigned char **binary_list = tmpbuf (sizeof (*binary_list) * count); |
1458 | const unsigned char **binary_list = tmpbuf (sizeof (*binary_list) * device_count); |
1442 | cl_int *status_list = tmpbuf (sizeof (*status_list) * count); |
1459 | cl_int *status_list = tmpbuf (sizeof (*status_list) * device_count); |
1443 | |
1460 | |
1444 | int i; |
1461 | int i; |
1445 | for (i = 0; i < count; ++i) |
1462 | for (i = 0; i < device_count; ++i) |
1446 | { |
1463 | { |
1447 | device_list [i] = SvCLOBJ ("OpenCL::Context::program_with_binary", "devices", *av_fetch ((AV *)devices, i, 0), "OpenCL::Device"); |
|
|
1448 | STRLEN len; |
1464 | STRLEN len; |
1449 | binary_list [i] = (const unsigned char *)SvPVbyte (*av_fetch ((AV *)binaries, i, 0), len); |
1465 | binary_list [i] = (const unsigned char *)SvPVbyte (*av_fetch ((AV *)binaries, i, 0), len); |
1450 | length_list [i] = len; |
1466 | length_list [i] = len; |
1451 | } |
1467 | } |
1452 | |
1468 | |
1453 | NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBinary, (self, count, device_list, length_list, binary_list, GIMME_V == G_ARRAY ? status_list : 0, &res)); |
1469 | NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBinary, (self, device_count, device_list, |
|
|
1470 | length_list, binary_list, |
|
|
1471 | GIMME_V == G_ARRAY ? status_list : 0, &res)); |
1454 | |
1472 | |
1455 | EXTEND (SP, 2); |
1473 | EXTEND (SP, 2); |
1456 | PUSH_CLOBJ (stash_program, prog); |
1474 | PUSH_CLOBJ (stash_program, prog); |
1457 | |
1475 | |
1458 | if (GIMME_V == G_ARRAY) |
1476 | if (GIMME_V == G_ARRAY) |
1459 | { |
1477 | { |
1460 | AV *av = newAV (); |
1478 | AV *av = newAV (); |
1461 | PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
1479 | PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
1462 | |
1480 | |
1463 | for (i = count; i--; ) |
1481 | for (i = device_count; i--; ) |
1464 | av_store (av, i, newSViv (status_list [i])); |
1482 | av_store (av, i, newSViv (status_list [i])); |
1465 | } |
1483 | } |
1466 | |
1484 | |
1467 | #if CL_VERSION_1_2 |
1485 | #if CL_VERSION_1_2 |
1468 | |
1486 | |
1469 | void |
1487 | void |
1470 | program_with_built_in_kernels (OpenCL::Context self, SV *devices, SV *kernel_names) |
1488 | program_with_built_in_kernels (OpenCL::Context self, SV *devices, SV *kernel_names) |
1471 | PPCODE: |
1489 | PPCODE: |
1472 | cl_uint device_count = 0; |
1490 | cl_uint device_count; |
1473 | cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); |
1491 | cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); |
1474 | |
1492 | |
1475 | NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBuiltInKernels, (self, device_count, device_list, SvPVbyte_nolen (kernel_names), &res)); |
1493 | NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBuiltInKernels, (self, device_count, device_list, SvPVbyte_nolen (kernel_names), &res)); |
1476 | |
1494 | |
1477 | XPUSH_CLOBJ (stash_program, prog); |
1495 | XPUSH_CLOBJ (stash_program, prog); |
1478 | |
1496 | |
… | |
… | |
1902 | XPUSHs (mapped_new (stash_mappedimage, self, img, map_flags, ptr, cb, ev, row_pitch, slice_pitch)); |
1920 | XPUSHs (mapped_new (stash_mappedimage, self, img, map_flags, ptr, cb, ev, row_pitch, slice_pitch)); |
1903 | |
1921 | |
1904 | void |
1922 | void |
1905 | unmap (OpenCL::Queue self, OpenCL::Mapped mapped, ...) |
1923 | unmap (OpenCL::Queue self, OpenCL::Mapped mapped, ...) |
1906 | PPCODE: |
1924 | PPCODE: |
1907 | mapped_unmap (ST (1), mapped, self, &ST (2), items - 2); |
1925 | mapped_unmap (cv, ST (1), mapped, self, &ST (2), items - 2); |
1908 | if (GIMME_V != G_VOID) |
1926 | if (GIMME_V != G_VOID) |
1909 | { |
1927 | { |
1910 | clRetainEvent (mapped->event); |
1928 | clRetainEvent (mapped->event); |
1911 | XPUSH_CLOBJ (stash_event, mapped->event); |
1929 | XPUSH_CLOBJ (stash_event, mapped->event); |
1912 | } |
1930 | } |
… | |
… | |
2459 | HE *he; |
2477 | HE *he; |
2460 | int i = 0; |
2478 | int i = 0; |
2461 | while (he = hv_iternext (hv)) |
2479 | while (he = hv_iternext (hv)) |
2462 | { |
2480 | { |
2463 | header_name [i] = SvPVbyte_nolen (HeSVKEY_force (he)); |
2481 | header_name [i] = SvPVbyte_nolen (HeSVKEY_force (he)); |
2464 | header_list [i] = SvCLOBJ ("clCompileProgram", "headers", HeVAL (he), "OpenCL::Program"); |
2482 | header_list [i] = SvCLOBJ (cv, "headers", HeVAL (he), "OpenCL::Program"); |
2465 | ++i; |
2483 | ++i; |
2466 | } |
2484 | } |
2467 | } |
2485 | } |
2468 | |
2486 | |
2469 | void *user_data; |
2487 | void *user_data; |
… | |
… | |
2508 | char *value = tmpbuf (size); |
2526 | char *value = tmpbuf (size); |
2509 | NEED_SUCCESS (GetProgramBuildInfo, (self, device, ix, size, value, 0)); |
2527 | NEED_SUCCESS (GetProgramBuildInfo, (self, device, ix, size, value, 0)); |
2510 | EXTEND (SP, 1); |
2528 | EXTEND (SP, 1); |
2511 | const int i = 0; |
2529 | const int i = 0; |
2512 | PUSHs (sv_2mortal (newSVpv (value, 0))); |
2530 | PUSHs (sv_2mortal (newSVpv (value, 0))); |
|
|
2531 | |
|
|
2532 | void |
|
|
2533 | binary_type (OpenCL::Program self, OpenCL::Device device) |
|
|
2534 | PPCODE: |
|
|
2535 | cl_program_binary_type value [1]; |
|
|
2536 | NEED_SUCCESS (GetProgramBuildInfo, (self, device, CL_PROGRAM_BINARY_TYPE, sizeof (value), value, 0)); |
|
|
2537 | EXTEND (SP, 1); |
|
|
2538 | const int i = 0; |
|
|
2539 | PUSHs (sv_2mortal (newSVuv ((UV)value [i]))); |
2513 | |
2540 | |
2514 | #END:program_build |
2541 | #END:program_build |
2515 | |
2542 | |
2516 | void |
2543 | void |
2517 | kernel (OpenCL::Program program, SV *function) |
2544 | kernel (OpenCL::Program program, SV *function) |
… | |
… | |
2684 | case 'f': arg.cf = SvNV (sv); size = sizeof (arg.cf); break; |
2711 | case 'f': arg.cf = SvNV (sv); size = sizeof (arg.cf); break; |
2685 | case 'd': arg.cd = SvNV (sv); size = sizeof (arg.cd); break; |
2712 | case 'd': arg.cd = SvNV (sv); size = sizeof (arg.cd); break; |
2686 | |
2713 | |
2687 | case 'z': nullarg = 1; size = SvIV (sv); break; |
2714 | case 'z': nullarg = 1; size = SvIV (sv); break; |
2688 | |
2715 | |
2689 | case 'm': nullarg = !SvOK (sv); arg.cm = SvCLOBJ ("OpenCL::Kernel::setf", "m", sv, "OpenCL::Memory" ); size = sizeof (arg.cm); break; |
2716 | case 'm': nullarg = !SvOK (sv); arg.cm = SvCLOBJ (cv, "m", sv, "OpenCL::Memory" ); size = sizeof (arg.cm); break; |
2690 | case 'a': nullarg = !SvOK (sv); arg.ca = SvCLOBJ ("OpenCL::Kernel::setf", "a", sv, "OpenCL::Sampler"); size = sizeof (arg.ca); break; |
2717 | case 'a': nullarg = !SvOK (sv); arg.ca = SvCLOBJ (cv, "a", sv, "OpenCL::Sampler"); size = sizeof (arg.ca); break; |
2691 | case 'e': nullarg = !SvOK (sv); arg.ca = SvCLOBJ ("OpenCL::Kernel::setf", "e", sv, "OpenCL::Event" ); size = sizeof (arg.ce); break; |
2718 | case 'e': nullarg = !SvOK (sv); arg.ca = SvCLOBJ (cv, "e", sv, "OpenCL::Event" ); size = sizeof (arg.ce); break; |
2692 | |
2719 | |
2693 | default: |
2720 | default: |
2694 | croak ("OpenCL::Kernel::setf format character '%c' not supported", type); |
2721 | croak ("OpenCL::Kernel::setf format character '%c' not supported", type); |
2695 | } |
2722 | } |
2696 | |
2723 | |
… | |
… | |
2767 | CODE: |
2794 | CODE: |
2768 | clSetKernelArg (self, idx, sizeof (value), value ? &value : 0); |
2795 | clSetKernelArg (self, idx, sizeof (value), value ? &value : 0); |
2769 | |
2796 | |
2770 | void |
2797 | void |
2771 | set_image (OpenCL::Kernel self, cl_uint idx, OpenCL::Image_ornull value) |
2798 | set_image (OpenCL::Kernel self, cl_uint idx, OpenCL::Image_ornull value) |
2772 | ALIAS: |
|
|
2773 | set_image2d = 0 |
|
|
2774 | set_image3d = 0 |
|
|
2775 | CODE: |
2799 | CODE: |
2776 | clSetKernelArg (self, idx, sizeof (value), value ? &value : 0); |
2800 | clSetKernelArg (self, idx, sizeof (value), value ? &value : 0); |
2777 | |
2801 | |
2778 | void |
2802 | void |
2779 | set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) |
2803 | set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) |
… | |
… | |
3075 | Safefree (mapped); |
3099 | Safefree (mapped); |
3076 | |
3100 | |
3077 | void |
3101 | void |
3078 | unmap (OpenCL::Mapped self, ...) |
3102 | unmap (OpenCL::Mapped self, ...) |
3079 | CODE: |
3103 | CODE: |
3080 | mapped_unmap (ST (0), self, self->queue, &ST (1), items - 1); |
3104 | mapped_unmap (cv, ST (0), self, self->queue, &ST (1), items - 1); |
3081 | |
3105 | |
3082 | bool |
3106 | bool |
3083 | mapped (OpenCL::Mapped self) |
3107 | mapped (OpenCL::Mapped self) |
3084 | CODE: |
3108 | CODE: |
3085 | RETVAL = !!self->ptr; |
3109 | RETVAL = !!self->ptr; |