--- OpenCL/OpenCL.xs 2012/05/05 02:33:55 1.70 +++ OpenCL/OpenCL.xs 2012/05/05 13:30:07 1.73 @@ -60,8 +60,6 @@ typedef struct mapped * OpenCL__Mapped; -typedef SV *FUTURE; - static HV *stash_platform, *stash_device, @@ -248,29 +246,29 @@ /* cl objects are either \$iv, or [$iv, ...] */ /* they can be upgraded at runtime to the array form */ static void * ecb_noinline -SvCLOBJ (const char *func, const char *svname, SV *sv, const char *pkg) +SvCLOBJ (CV *cv, const char *svname, SV *sv, const char *pkg) { // sv_derived_from is quite slow :( if (SvROK (sv) && sv_derived_from (sv, pkg)) return (void *)SvIV (SvRV (sv)); - croak ("%s: %s is not of type %s", func, svname, pkg); + croak ("%s: %s is not of type %s", cv_get_name (cv), svname, pkg); } // the "no-inherit" version of the above static void * ecb_noinline -SvCLOBJ_ni (const char *func, const char *svname, SV *sv, HV *stash) +SvCLOBJ_ni (CV *cv, const char *svname, SV *sv, HV *stash) { if (SvROK (sv) && SvSTASH (SvRV (sv)) == stash) return (void *)SvIV (SvRV (sv)); - croak ("%s: %s is not of type %s", func, svname, HvNAME (stash)); + croak ("%s: %s is not of type %s", cv_get_name (cv), svname, HvNAME (stash)); } /*****************************************************************************/ static cl_context_properties * ecb_noinline -SvCONTEXTPROPERTIES (const char *func, const char *svname, SV *sv, cl_context_properties *extra, int extracount) +SvCONTEXTPROPERTIES (CV *cv, const char *svname, SV *sv, cl_context_properties *extra, int extracount) { if (!sv || !SvOK (sv)) if (extra) @@ -286,7 +284,7 @@ cl_context_properties *l = p; if (len & 1) - croak ("%s: %s is not a property list (must contain an even number of elements)", func, svname); + croak ("%s: %s is not a property list (must contain an even number of elements)", cv_get_name (cv), svname); while (extracount--) *l++ = *extra++; @@ -301,7 +299,7 @@ { case CL_CONTEXT_PLATFORM: if (SvROK (p_sv)) - v = (cl_context_properties)SvCLOBJ (func, svname, p_sv, "OpenCL::Platform"); + v = (cl_context_properties)SvCLOBJ (cv, svname, p_sv, "OpenCL::Platform"); break; case CL_GLX_DISPLAY_KHR: @@ -336,17 +334,17 @@ return p; } - croak ("%s: %s is not a property list (either undef or [type => value, ...])", func, svname); + croak ("%s: %s is not a property list (either undef or [type => value, ...])", cv_get_name (cv), svname); } +// parse an array of CLOBJ into a void ** array in C - works only for CLOBJs whose representation +// is a pointer (and only on well-behaved systems). static void * ecb_noinline object_list (CV *cv, int or_undef, const char *argname, SV *arg, const char *klass, cl_uint *rcount) { - const char *funcname = cv_get_name (cv); - if (!SvROK (arg) || SvTYPE (SvRV (arg)) != SVt_PVAV) croak ("%s: '%s' parameter must be %sa reference to an array of %s objects", - funcname, argname, or_undef ? "undef or " : "", klass); + cv_get_name (cv), argname, or_undef ? "undef or " : "", klass); AV *av = (AV *)SvRV (arg); void **list = 0; @@ -357,12 +355,12 @@ list = tmpbuf (sizeof (*list) * count); int i; for (i = 0; i < count; ++i) - list [i] = SvCLOBJ (funcname, argname, *av_fetch (av, i, 1), klass); + list [i] = SvCLOBJ (cv, argname, *av_fetch (av, i, 1), klass); } if (!count && !or_undef) croak ("%s: '%s' must contain at least one %s object", - funcname, argname, klass); + cv_get_name (cv), argname, klass); *rcount = count; return (void *)list; @@ -630,7 +628,7 @@ } static cl_event * ecb_noinline -event_list (SV **items, cl_uint *rcount, cl_event extra) +event_list (CV *cv, SV **items, cl_uint *rcount, cl_event extra) { cl_uint count = *rcount; @@ -645,7 +643,7 @@ while (count--) if (SvOK (items [count])) - list [i++] = SvCLOBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); + list [i++] = SvCLOBJ (cv, "wait_events", items [count], "OpenCL::Event"); if (extra) list [i++] = extra; @@ -657,7 +655,7 @@ #define EVENT_LIST(skip) \ cl_uint event_list_count = items - (skip); \ - cl_event *event_list_ptr = event_list (&ST (skip), &event_list_count, 0) + cl_event *event_list_ptr = event_list (cv, &ST (skip), &event_list_count, 0) #define INFO(class) \ { \ @@ -749,9 +747,9 @@ } static void -mapped_unmap (SV *self, OpenCL__Mapped mapped, cl_command_queue queue, SV **wait_list, cl_uint event_list_count) +mapped_unmap (CV *cv, SV *self, OpenCL__Mapped mapped, cl_command_queue queue, SV **wait_list, cl_uint event_list_count) { - cl_event *event_list_ptr = event_list (wait_list, &event_list_count, mapped->event); + cl_event *event_list_ptr = event_list (cv, wait_list, &event_list_count, mapped->event); cl_event ev; NEED_SUCCESS (EnqueueUnmapMemObject, (queue, mapped->memobj, mapped->ptr, event_list_count, event_list_ptr, &ev)); @@ -794,6 +792,7 @@ { sizeof (cl_half ), "SIZEOF_HALF" }, { sizeof (cl_float ), "SIZEOF_FLOAT" }, { sizeof (cl_double), "SIZEOF_DOUBLE" }, + { PREFER_1_1 , "PREFER_1_1" }, #include "constiv.h" }; @@ -863,9 +862,14 @@ XPUSH_CLOBJ_CONTEXT; void -context (FUTURE properties, FUTURE devices, FUTURE notify) +context (cl_context_properties *properties, SV *devices, SV *notify = &PL_sv_undef) PPCODE: - /* der Gipfel der Kunst */ + cl_uint device_count; + cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); + + CONTEXT_NOTIFY_CALLBACK; + NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (properties, device_count, device_list, pfn_notify, user_data, &res)); + XPUSH_CLOBJ_CONTEXT; void wait_for_events (...) @@ -926,13 +930,13 @@ PUSH_CLOBJ (stash_device, list [i]); void -context (OpenCL::Platform self, SV *properties = 0, SV *devices, SV *notify = &PL_sv_undef) +context (OpenCL::Platform self, SV *properties, SV *devices, SV *notify = &PL_sv_undef) PPCODE: cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self }; - cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context", "properties", properties, extra, 2); + cl_context_properties *props = SvCONTEXTPROPERTIES (cv, "properties", properties, extra, 2); - cl_uint device_count = 0; - cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); + cl_uint device_count; + cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); CONTEXT_NOTIFY_CALLBACK; NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (props, device_count, device_list, pfn_notify, user_data, &res)); @@ -942,7 +946,7 @@ context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef) PPCODE: cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self }; - cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context_from_type", "properties", properties, extra, 2); + cl_context_properties *props = SvCONTEXTPROPERTIES (cv, "properties", properties, extra, 2); CONTEXT_NOTIFY_CALLBACK; NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, pfn_notify, user_data, &res)); @@ -1276,7 +1280,7 @@ width, height, depth, array_size, row_pitch, slice_pitch, num_mip_level, num_samples, - type == CL_MEM_OBJECT_IMAGE1D_BUFFER ? (cl_mem)SvCLOBJ ("OpenCL::Context::Image", "data", data, "OpenCL::Buffer") : 0 + type == CL_MEM_OBJECT_IMAGE1D_BUFFER ? (cl_mem)SvCLOBJ (cv, "data", data, "OpenCL::Buffer") : 0 }; NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res)); HV *stash = stash_image; @@ -1466,8 +1470,8 @@ void program_with_built_in_kernels (OpenCL::Context self, SV *devices, SV *kernel_names) PPCODE: - cl_uint device_count = 0; - cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); + cl_uint device_count; + cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBuiltInKernels, (self, device_count, device_list, SvPVbyte_nolen (kernel_names), &res)); @@ -1901,7 +1905,7 @@ void unmap (OpenCL::Queue self, OpenCL::Mapped mapped, ...) PPCODE: - mapped_unmap (ST (1), mapped, self, &ST (2), items - 2); + mapped_unmap (cv, ST (1), mapped, self, &ST (2), items - 2); if (GIMME_V != G_VOID) { clRetainEvent (mapped->event); @@ -2458,7 +2462,7 @@ while (he = hv_iternext (hv)) { header_name [i] = SvPVbyte_nolen (HeSVKEY_force (he)); - header_list [i] = SvCLOBJ ("clCompileProgram", "headers", HeVAL (he), "OpenCL::Program"); + header_list [i] = SvCLOBJ (cv, "headers", HeVAL (he), "OpenCL::Program"); ++i; } } @@ -2508,6 +2512,15 @@ const int i = 0; PUSHs (sv_2mortal (newSVpv (value, 0))); +void +binary_type (OpenCL::Program self, OpenCL::Device device) + PPCODE: + cl_program_binary_type value [1]; + NEED_SUCCESS (GetProgramBuildInfo, (self, device, CL_PROGRAM_BINARY_TYPE, sizeof (value), value, 0)); + EXTEND (SP, 1); + const int i = 0; + PUSHs (sv_2mortal (newSVuv (UV)value [i]))); + #END:program_build void @@ -2683,9 +2696,9 @@ case 'z': nullarg = 1; size = SvIV (sv); break; - case 'm': nullarg = !SvOK (sv); arg.cm = SvCLOBJ ("OpenCL::Kernel::setf", "m", sv, "OpenCL::Memory" ); size = sizeof (arg.cm); break; - case 'a': nullarg = !SvOK (sv); arg.ca = SvCLOBJ ("OpenCL::Kernel::setf", "a", sv, "OpenCL::Sampler"); size = sizeof (arg.ca); break; - case 'e': nullarg = !SvOK (sv); arg.ca = SvCLOBJ ("OpenCL::Kernel::setf", "e", sv, "OpenCL::Event" ); size = sizeof (arg.ce); break; + case 'm': nullarg = !SvOK (sv); arg.cm = SvCLOBJ (cv, "m", sv, "OpenCL::Memory" ); size = sizeof (arg.cm); break; + case 'a': nullarg = !SvOK (sv); arg.ca = SvCLOBJ (cv, "a", sv, "OpenCL::Sampler"); size = sizeof (arg.ca); break; + case 'e': nullarg = !SvOK (sv); arg.ca = SvCLOBJ (cv, "e", sv, "OpenCL::Event" ); size = sizeof (arg.ce); break; default: croak ("OpenCL::Kernel::setf format character '%c' not supported", type); @@ -3074,7 +3087,7 @@ void unmap (OpenCL::Mapped self, ...) CODE: - mapped_unmap (ST (0), self, self->queue, &ST (1), items - 1); + mapped_unmap (cv, ST (0), self, self->queue, &ST (1), items - 1); bool mapped (OpenCL::Mapped self)