--- OpenCL/OpenCL.xs 2011/11/15 21:13:42 1.4 +++ OpenCL/OpenCL.xs 2011/11/20 01:09:48 1.13 @@ -22,6 +22,33 @@ typedef cl_program OpenCL__Program; typedef cl_kernel OpenCL__Kernel; typedef cl_event OpenCL__Event; +typedef cl_event OpenCL__UserEvent; + +typedef SV *FUTURE; + +/*****************************************************************************/ + +/* up to two temporary buffers */ +static void * +tmpbuf (size_t size) +{ + static int idx; + static void *buf [2]; + static size_t len [2]; + + idx ^= 1; + + if (len [idx] < size) + { + free (buf [idx]); + len [idx] = ((size + 31) & ~4095) + 4096 - 32; + buf [idx] = malloc (len [idx]); + } + + return buf [idx]; +} + +/*****************************************************************************/ typedef struct { @@ -65,36 +92,30 @@ return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)"); } -#define FAIL(name,res) \ +/*****************************************************************************/ + +static cl_int res; + +#define FAIL(name) \ croak ("cl" # name ": %s", err2str (res)); #define NEED_SUCCESS(name,args) \ do { \ - cl_int res = cl ## name args; \ + res = cl ## name args; \ \ if (res) \ - FAIL (name, res); \ + FAIL (name); \ } while (0) -#define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr) -#define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr)) +#define NEED_SUCCESS_ARG(retdecl, name, args) \ + retdecl = cl ## name args; \ + if (res) \ + FAIL (name); -/*TODO*/ -#define EVENT_LIST(items,count) cl_uint event_list_count = 0; cl_event *event_list_ptr = 0 +/*****************************************************************************/ -#define INFO(class) \ -{ \ - size_t size; \ - SV *sv; \ - \ - NEED_SUCCESS (Get ## class ## Info, (this, name, 0, 0, &size)); \ - sv = sv_2mortal (newSV (size)); \ - SvUPGRADE (sv, SVt_PV); \ - SvPOK_only (sv); \ - SvCUR_set (sv, size); \ - NEED_SUCCESS (Get ## class ## Info, (this, name, size, SvPVX (sv), 0)); \ - XPUSHs (sv); \ -} +#define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr) +#define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr)) static void * SvPTROBJ (const char *func, const char *svname, SV *sv, const char *pkg) @@ -105,20 +126,41 @@ croak ("%s: %s is not of type %s", func, svname, pkg); } -static void * -tmpbuf (size_t size) +/*****************************************************************************/ + +static size_t +img_row_pitch (cl_mem img) { - static void *buf; - static size_t len; + size_t res; + clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); + return res; +} - if (len < size) - { - free (buf); - len = ((size + 31) & ~4095) + 4096 - 32; - buf = malloc (len); - } +static cl_event * +event_list (SV **items, int count) +{ + cl_event *list = tmpbuf (sizeof (cl_event) * count); - return buf; + while (count--) + list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); + + return list; +} + +#define EVENT_LIST(items,count) \ + cl_uint event_list_count = (count); \ + cl_event *event_list_ptr = event_list (&ST (items), event_list_count) + +#define INFO(class) \ +{ \ + size_t size; \ + NEED_SUCCESS (Get ## class ## Info, (this, name, 0, 0, &size)); \ + SV *sv = sv_2mortal (newSV (size)); \ + SvUPGRADE (sv, SVt_PV); \ + SvPOK_only (sv); \ + SvCUR_set (sv, size); \ + NEED_SUCCESS (Get ## class ## Info, (this, name, size, SvPVX (sv), 0)); \ + XPUSHs (sv); \ } MODULE = OpenCL PACKAGE = OpenCL @@ -129,22 +171,28 @@ { HV *stash = gv_stashpv ("OpenCL", 1); static const ivstr *civ, const_iv[] = { - { sizeof (cl_char ), "SIZEOF_CHAR" }, - { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, - { sizeof (cl_short ), "SIZEOF_SHORT" }, - { sizeof (cl_ushort), "SIZEOF_USHORT"}, - { sizeof (cl_int ), "SIZEOF_INT" }, - { sizeof (cl_uint ), "SIZEOF_UINT" }, - { sizeof (cl_long ), "SIZEOF_LONG" }, - { sizeof (cl_ulong ), "SIZEOF_ULONG" }, - { sizeof (cl_half ), "SIZEOF_HALF" }, - { sizeof (cl_float ), "SIZEOF_FLOAT" }, + { sizeof (cl_char ), "SIZEOF_CHAR" }, + { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, + { sizeof (cl_short ), "SIZEOF_SHORT" }, + { sizeof (cl_ushort), "SIZEOF_USHORT" }, + { sizeof (cl_int ), "SIZEOF_INT" }, + { sizeof (cl_uint ), "SIZEOF_UINT" }, + { sizeof (cl_long ), "SIZEOF_LONG" }, + { sizeof (cl_ulong ), "SIZEOF_ULONG" }, + { sizeof (cl_half ), "SIZEOF_HALF" }, + { sizeof (cl_float ), "SIZEOF_FLOAT" }, + { sizeof (cl_double), "SIZEOF_DOUBLE" }, #include "constiv.h" }; for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); } +cl_int +errno () + CODE: + errno = res; + const char * err2str (cl_int err) @@ -154,7 +202,6 @@ void platforms () PPCODE: -{ cl_platform_id *list; cl_uint count; int i; @@ -166,28 +213,23 @@ EXTEND (SP, count); for (i = 0; i < count; ++i) PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); -} void -context_from_type_simple (cl_device_type type = CL_DEVICE_TYPE_DEFAULT) +context_from_type (FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) PPCODE: -{ - cl_int res; - cl_context ctx = clCreateContextFromType (0, type, 0, 0, &res); - - if (res) - FAIL (CreateContextFromType, res); - + NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (0, type, 0, 0, &res)); XPUSH_NEW_OBJ ("OpenCL::Context", ctx); -} + +void +context (FUTURE properties, FUTURE devices, FUTURE notify = 0) + PPCODE: + /* der Gipfel der Kunst */ void wait_for_events (...) CODE: -{ EVENT_LIST (0, items); NEED_SUCCESS (WaitForEvents, (event_list_count, event_list_ptr)); -} PROTOTYPES: DISABLE @@ -198,10 +240,78 @@ PPCODE: INFO (Platform) +#BEGIN:platform + +void +profile (OpenCL::Platform this) + PPCODE: + size_t size; + int i, n; + NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_PROFILE, 0, 0, &size)); + char *value = tmpbuf (size); + NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_PROFILE, size, value, 0)); + n = 1; + EXTEND (SP, n); + for (i = 0; i < n; ++i) + PUSHs (sv_2mortal (newSVpvn (value, size))); + +void +version (OpenCL::Platform this) + PPCODE: + size_t size; + int i, n; + NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_VERSION, 0, 0, &size)); + char *value = tmpbuf (size); + NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_VERSION, size, value, 0)); + n = 1; + EXTEND (SP, n); + for (i = 0; i < n; ++i) + PUSHs (sv_2mortal (newSVpvn (value, size))); + +void +name (OpenCL::Platform this) + PPCODE: + size_t size; + int i, n; + NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_NAME, 0, 0, &size)); + char *value = tmpbuf (size); + NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_NAME, size, value, 0)); + n = 1; + EXTEND (SP, n); + for (i = 0; i < n; ++i) + PUSHs (sv_2mortal (newSVpvn (value, size))); + +void +vendor (OpenCL::Platform this) + PPCODE: + size_t size; + int i, n; + NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_VENDOR, 0, 0, &size)); + char *value = tmpbuf (size); + NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_VENDOR, size, value, 0)); + n = 1; + EXTEND (SP, n); + for (i = 0; i < n; ++i) + PUSHs (sv_2mortal (newSVpvn (value, size))); + +void +extensions (OpenCL::Platform this) + PPCODE: + size_t size; + int i, n; + NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_EXTENSIONS, 0, 0, &size)); + char *value = tmpbuf (size); + NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_EXTENSIONS, size, value, 0)); + n = 1; + EXTEND (SP, n); + for (i = 0; i < n; ++i) + PUSHs (sv_2mortal (newSVpvn (value, size))); + +#END:platform + void devices (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_ALL) PPCODE: -{ cl_device_id *list; cl_uint count; int i; @@ -213,21 +323,30 @@ EXTEND (SP, count); for (i = 0; i < count; ++i) PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); -} void -context_from_type_simple (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_DEFAULT) +context (OpenCL::Platform this, FUTURE properties, SV *devices, FUTURE notify = 0) PPCODE: -{ - cl_int res; - cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)this, 0 }; - cl_context ctx = clCreateContextFromType (props, type, 0, 0, &res); + if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) + croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call"); - if (res) - FAIL (CreateContextFromType, res); + AV *av = (AV *)SvRV (devices); + cl_uint num_devices = av_len (av) + 1; + cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); + int i; + + for (i = num_devices; i--; ) + device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device"); + NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (0, num_devices, device_list, 0, 0, &res)); + XPUSH_NEW_OBJ ("OpenCL::Context", ctx); + +void +context_from_type (OpenCL::Platform this, FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) + PPCODE: + cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)this, 0 }; + NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res)); XPUSH_NEW_OBJ ("OpenCL::Context", ctx); -} MODULE = OpenCL PACKAGE = OpenCL::Device @@ -236,19 +355,6 @@ PPCODE: INFO (Device) -void -context_simple (OpenCL::Device this) - PPCODE: -{ - cl_int res; - cl_context ctx = clCreateContext (0, 1, &this, 0, 0, &res); - - if (res) - FAIL (CreateContext, res); - - XPUSH_NEW_OBJ ("OpenCL::Context", ctx); -} - MODULE = OpenCL PACKAGE = OpenCL::Context void @@ -262,88 +368,55 @@ INFO (Context) void -command_queue_simple (OpenCL::Context this, OpenCL::Device device) +queue (OpenCL::Context this, OpenCL::Device device, cl_command_queue_properties properties = 0) PPCODE: -{ - cl_int res; - cl_command_queue queue = clCreateCommandQueue (this, device, 0, &res); - - if (res) - FAIL (CreateCommandQueue, res); - + NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (this, device, properties, &res)); XPUSH_NEW_OBJ ("OpenCL::Queue", queue); -} void -buffer (OpenCL::Context this, cl_mem_flags flags, size_t len) +user_event (OpenCL::Context this) PPCODE: -{ - cl_int res; - cl_mem mem; + NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (this, &res)); + XPUSH_NEW_OBJ ("OpenCL::UserEvent", ev); +void +buffer (OpenCL::Context this, cl_mem_flags flags, size_t len) + PPCODE: if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); - mem = clCreateBuffer (this, flags, len, 0, &res); - - if (res) - FAIL (CreateBuffer, res); - + NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, 0, &res)); XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); -} void buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data) PPCODE: -{ STRLEN len; char *ptr = SvPVbyte (data, len); - cl_int res; - cl_mem mem; if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); - mem = clCreateBuffer (this, flags, len, ptr, &res); - - if (res) - FAIL (CreateBuffer, res); - + NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, ptr, &res)); XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); -} void -image2d (OpenCL::Context this, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, SV *data) +image2d (OpenCL::Context this, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, size_t row_pitch = 0, SV *data = &PL_sv_undef) PPCODE: -{ STRLEN len; char *ptr = SvPVbyte (data, len); const cl_image_format format = { channel_order, channel_type }; - cl_int res; - cl_mem mem = clCreateImage2D (this, flags, &format, width, height, len / height, ptr, &res); - - if (res) - FAIL (CreateImage2D, res); - + NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (this, flags, &format, width, height, row_pitch, ptr, &res)); XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); -} void -image3d (OpenCL::Context this, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, size_t depth, size_t slice_pitch, SV *data) +image3d (OpenCL::Context this, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, size_t depth, size_t row_pitch = 0, size_t slice_pitch = 0, SV *data = &PL_sv_undef) PPCODE: -{ STRLEN len; char *ptr = SvPVbyte (data, len); const cl_image_format format = { channel_order, channel_type }; - cl_int res; - cl_mem mem = clCreateImage3D (this, flags, &format, width, height, - depth, len / (height * slice_pitch), slice_pitch, ptr, &res); - - if (res) - FAIL (CreateImage3D, res); - + NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (this, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); -} void supported_image_formats (OpenCL::Context this, cl_mem_flags flags, cl_mem_object_type image_type) @@ -370,34 +443,23 @@ void sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode) PPCODE: -{ - cl_int res; - cl_sampler sampler = clCreateSampler (this, normalized_coords, addressing_mode, filter_mode, &res); - - if (res) - FAIL (CreateSampler, res); - + NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (this, normalized_coords, addressing_mode, filter_mode, &res)); XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler); -} void program_with_source (OpenCL::Context this, SV *program) PPCODE: -{ STRLEN len; size_t len2; const char *ptr = SvPVbyte (program, len); - cl_int res; - cl_program prog; len2 = len; - prog = clCreateProgramWithSource (this, 1, &ptr, &len2, &res); + NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (this, 1, &ptr, &len2, &res)); + XPUSH_NEW_OBJ ("OpenCL::Program", prog); - if (res) - FAIL (CreateProgramWithSource, res); +#BEGIN:context - XPUSH_NEW_OBJ ("OpenCL::Program", prog); -} +#END:context MODULE = OpenCL PACKAGE = OpenCL::Queue @@ -414,7 +476,6 @@ void enqueue_read_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...) PPCODE: -{ cl_event ev = 0; EVENT_LIST (6, items - 6); @@ -426,12 +487,10 @@ if (ev) XPUSH_NEW_OBJ ("OpenCL::Event", ev); -} void enqueue_write_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...) PPCODE: -{ cl_event ev = 0; STRLEN len; char *ptr = SvPVbyte (data, len); @@ -441,12 +500,10 @@ if (ev) XPUSH_NEW_OBJ ("OpenCL::Event", ev); -} void enqueue_copy_buffer (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...) PPCODE: -{ cl_event ev = 0; EVENT_LIST (6, items - 6); @@ -454,20 +511,22 @@ if (ev) XPUSH_NEW_OBJ ("OpenCL::Event", ev); -} - - /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBufferRect.html */ - /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html */ void enqueue_read_image (OpenCL::Queue this, OpenCL::Image src, cl_bool blocking, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...) PPCODE: -{ cl_event ev = 0; const size_t src_origin[3] = { src_x, src_y, src_z }; const size_t region[3] = { width, height, depth }; - size_t len = row_pitch * slice_pitch * depth; - EVENT_LIST (11, items - 11); + EVENT_LIST (12, items - 12); + + if (!row_pitch) + row_pitch = img_row_pitch (src); + + if (depth > 1 && !slice_pitch) + slice_pitch = row_pitch * height; + + size_t len = slice_pitch ? slice_pitch * depth : row_pitch * height; SvUPGRADE (data, SVt_PV); SvGROW (data, len); @@ -477,30 +536,36 @@ if (ev) XPUSH_NEW_OBJ ("OpenCL::Event", ev); -} void -enqueue_write_image (OpenCL::Queue this, OpenCL::Image dst, cl_bool blocking, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t row_pitch, SV *data, ...) +enqueue_write_image (OpenCL::Queue this, OpenCL::Image dst, cl_bool blocking, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...) PPCODE: -{ cl_event ev = 0; const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; const size_t region[3] = { width, height, depth }; STRLEN len; char *ptr = SvPVbyte (data, len); - size_t slice_pitch = len / (row_pitch * height); - EVENT_LIST (11, items - 11); + EVENT_LIST (12, items - 12); + + if (!row_pitch) + row_pitch = img_row_pitch (dst); + + if (depth > 1 && !slice_pitch) + slice_pitch = row_pitch * height; + + size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height; + + if (len < min_len) + croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); NEED_SUCCESS (EnqueueWriteImage, (this, dst, blocking, dst_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); if (ev) XPUSH_NEW_OBJ ("OpenCL::Event", ev); -} void enqueue_copy_buffer_rect (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, size_t dst_slice_pitch, ...) PPCODE: -{ cl_event ev = 0; const size_t src_origin[3] = { src_x, src_y, src_z }; const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; @@ -511,12 +576,10 @@ if (ev) XPUSH_NEW_OBJ ("OpenCL::Event", ev); -} void enqueue_copy_buffer_to_image (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Image dst, size_t src_offset, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...) PPCODE: -{ cl_event ev = 0; const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; const size_t region[3] = { width, height, depth }; @@ -526,12 +589,10 @@ if (ev) XPUSH_NEW_OBJ ("OpenCL::Event", ev); -} void -enqueue_copy_image (OpenCL::Queue this, OpenCL::Image 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, ...) +enqueue_copy_image (OpenCL::Queue this, OpenCL::Image src, OpenCL::Image dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...) PPCODE: -{ cl_event ev = 0; const size_t src_origin[3] = { src_x, src_y, src_z }; const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; @@ -542,12 +603,10 @@ if (ev) XPUSH_NEW_OBJ ("OpenCL::Event", ev); -} void enqueue_copy_image_to_buffer (OpenCL::Queue this, OpenCL::Image src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t dst_offset, ...) PPCODE: -{ cl_event ev = 0; const size_t src_origin[3] = { src_x, src_y, src_z }; const size_t region[3] = { width, height, depth }; @@ -557,12 +616,10 @@ if (ev) XPUSH_NEW_OBJ ("OpenCL::Event", ev); -} void enqueue_task (OpenCL::Queue this, OpenCL::Kernel kernel, ...) PPCODE: -{ cl_event ev = 0; EVENT_LIST (2, items - 2); @@ -570,18 +627,16 @@ if (ev) XPUSH_NEW_OBJ ("OpenCL::Event", ev); -} void enqueue_nd_range_kernel (OpenCL::Queue this, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...) PPCODE: -{ cl_event ev = 0; size_t *gwo = 0, *gws, *lws = 0; int gws_len; size_t *lists; int i; - EVENT_LIST (2, items - 2); + EVENT_LIST (5, items - 5); if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV) croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference"); @@ -624,24 +679,19 @@ if (ev) XPUSH_NEW_OBJ ("OpenCL::Event", ev); -} void enqueue_marker (OpenCL::Queue this) PPCODE: -{ cl_event ev; NEED_SUCCESS (EnqueueMarker, (this, &ev)); XPUSH_NEW_OBJ ("OpenCL::Event", ev); -} void enqueue_wait_for_events (OpenCL::Queue this, ...) CODE: -{ EVENT_LIST (1, items - 1); NEED_SUCCESS (EnqueueWaitForEvents, (this, event_list_count, event_list_ptr)); -} void enqueue_barrier (OpenCL::Queue this) @@ -670,6 +720,13 @@ PPCODE: INFO (MemObject) +MODULE = OpenCL PACKAGE = OpenCL::Image + +void +image_info (OpenCL::Image this, cl_image_info name) + PPCODE: + INFO (Image) + MODULE = OpenCL PACKAGE = OpenCL::Sampler void @@ -702,31 +759,20 @@ void build_info (OpenCL::Program this, OpenCL::Device device, cl_program_build_info name) PPCODE: -{ size_t size; - SV *sv; - NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, 0, 0, &size)); - sv = sv_2mortal (newSV (size)); + SV *sv = sv_2mortal (newSV (size)); SvUPGRADE (sv, SVt_PV); SvPOK_only (sv); SvCUR_set (sv, size); NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, size, SvPVX (sv), 0)); XPUSHs (sv); -} void kernel (OpenCL::Program program, SV *function) PPCODE: -{ - cl_int res; - cl_kernel kernel = clCreateKernel (program, SvPVbyte_nolen (function), &res); - - if (res) - FAIL (CreateKernel, res); - + NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res)); XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel); -} MODULE = OpenCL PACKAGE = OpenCL::Kernel @@ -741,6 +787,18 @@ INFO (Kernel) void +work_group_info (OpenCL::Kernel this, OpenCL::Device device, cl_kernel_work_group_info name) + PPCODE: + size_t size; + NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, name, 0, 0, &size)); + SV *sv = sv_2mortal (newSV (size)); + SvUPGRADE (sv, SVt_PV); + SvPOK_only (sv); + SvCUR_set (sv, size); + NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, name, size, SvPVX (sv), 0)); + XPUSHs (sv); + +void set_char (OpenCL::Kernel this, cl_uint idx, cl_char value) CODE: clSetKernelArg (this, idx, sizeof (value), &value); @@ -791,6 +849,11 @@ clSetKernelArg (this, idx, sizeof (value), &value); void +set_double (OpenCL::Kernel this, cl_uint idx, cl_double value) + CODE: + clSetKernelArg (this, idx, sizeof (value), &value); + +void set_memory (OpenCL::Kernel this, cl_uint idx, OpenCL::Memory_ornull value) CODE: clSetKernelArg (this, idx, sizeof (value), &value); @@ -833,7 +896,19 @@ INFO (Event) void +profiling_info (OpenCL::Event this, cl_profiling_info name) + PPCODE: + INFO (EventProfiling) + +void wait (OpenCL::Event this) CODE: clWaitForEvents (1, &this); +MODULE = OpenCL PACKAGE = OpenCL::UserEvent + +void +set_status (OpenCL::UserEvent this, cl_int execution_status) + CODE: + clSetUserEventStatus (this, execution_status); +