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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.22 by root, Mon Apr 16 09:42:33 2012 UTC vs.
Revision 1.31 by root, Thu Apr 19 14:36:46 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#ifdef I_DLFCN
6 #include <dlfcn.h>
7#endif
4 8
5#ifdef __APPLE__ 9#ifdef __APPLE__
6 #include <OpenCL/opencl.h> 10 #include <OpenCL/opencl.h>
7#else 11#else
8 #include <CL/opencl.h> 12 #include <CL/opencl.h>
31 35
32typedef SV *FUTURE; 36typedef SV *FUTURE;
33 37
34/*****************************************************************************/ 38/*****************************************************************************/
35 39
40// name must include a leading underscore
41static void *
42getsym (const char *name)
43{
44 #if defined I_DLFCN && defined RTLD_DEFAULT
45 #if !DLSYM_NEEDS_UNDERSCORE
46 ++name; // skip _
47 #endif
48 return dlsym (RTLD_DEFAULT, name);
49 #else
50 return 0;
51 #endif
52}
53
54/*****************************************************************************/
55
36/* up to two temporary buffers */ 56/* up to two temporary buffers */
37static void * 57static void *
38tmpbuf (size_t size) 58tmpbuf (size_t size)
39{ 59{
60 enum { buffers = 3 };
40 static int idx; 61 static int idx;
41 static void *buf [2]; 62 static void *buf [buffers];
42 static size_t len [2]; 63 static size_t len [buffers];
43 64
44 idx ^= 1; 65 idx = ++idx % buffers;
45 66
46 if (len [idx] < size) 67 if (len [idx] < size)
47 { 68 {
48 free (buf [idx]); 69 free (buf [idx]);
49 len [idx] = ((size + 31) & ~4095) + 4096 - 32; 70 len [idx] = ((size + 31) & ~4095) + 4096 - 32;
131 croak ("%s: %s is not of type %s", func, svname, pkg); 152 croak ("%s: %s is not of type %s", func, svname, pkg);
132} 153}
133 154
134/*****************************************************************************/ 155/*****************************************************************************/
135 156
157static cl_context_properties *
158SvCONTEXTPROPERTIES (const char *func, const char *svname, SV *sv, cl_context_properties *extra, int extracount)
159{
160 if (!sv || !SvOK (sv))
161 if (extra)
162 sv = sv_2mortal (newRV_noinc ((SV *)newAV ())); // slow, but rarely used hopefully
163 else
164 return 0;
165
166 if (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVAV)
167 {
168 AV *av = (AV *)SvRV (sv);
169 int i, len = av_len (av) + 1;
170 cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1));
171 cl_context_properties *l = p;
172
173 if (len & 1)
174 croak ("%s: %s is not a property list (must be even number of elements)", func, svname);
175
176 while (extracount--)
177 *l++ = *extra++;
178
179 for (i = 0; i < len; i += 2)
180 {
181 cl_context_properties t = SvIV (*av_fetch (av, i , 0));
182 SV *p_sv = *av_fetch (av, i + 1, 0);
183 cl_context_properties v;
184
185 switch (t)
186 {
187 default:
188 /* unknown property, treat as int */
189 v = SvIV (p_sv);
190 break;
191 }
192
193 *l++ = t;
194 *l++ = v;
195 }
196
197 *l = 0;
198
199 return p;
200 }
201
202 croak ("%s: %s is not a property list (either undef or [type => value, ...])", func, svname);
203}
204
205/*****************************************************************************/
206
136static size_t 207static size_t
137img_row_pitch (cl_mem img) 208img_row_pitch (cl_mem img)
138{ 209{
139 size_t res; 210 size_t res;
140 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); 211 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0);
159 cl_uint event_list_count = (count); \ 230 cl_uint event_list_count = (count); \
160 cl_event *event_list_ptr = event_list (&ST (items), event_list_count) 231 cl_event *event_list_ptr = event_list (&ST (items), event_list_count)
161 232
162#define INFO(class) \ 233#define INFO(class) \
163{ \ 234{ \
164 size_t size; \ 235 size_t size; \
165 NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ 236 NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \
166 SV *sv = sv_2mortal (newSV (size)); \ 237 SV *sv = sv_2mortal (newSV (size)); \
167 SvUPGRADE (sv, SVt_PV); \ 238 SvUPGRADE (sv, SVt_PV); \
168 SvPOK_only (sv); \ 239 SvPOK_only (sv); \
169 SvCUR_set (sv, size); \ 240 SvCUR_set (sv, size); \
170 NEED_SUCCESS (Get ## class ## Info, (self, name, size, SvPVX (sv), 0)); \ 241 NEED_SUCCESS (Get ## class ## Info, (self, name, size, SvPVX (sv), 0)); \
171 XPUSHs (sv); \ 242 XPUSHs (sv); \
172} 243}
173 244
174MODULE = OpenCL PACKAGE = OpenCL 245MODULE = OpenCL PACKAGE = OpenCL
175 246
176PROTOTYPES: ENABLE 247PROTOTYPES: ENABLE
177 248
178BOOT: 249BOOT:
179{ 250{
180 HV *stash = gv_stashpv ("OpenCL", 1); 251 HV *stash = gv_stashpv ("OpenCL", 1);
181 static const ivstr *civ, const_iv[] = { 252 static const ivstr *civ, const_iv[] = {
182 { sizeof (cl_char ), "SIZEOF_CHAR" }, 253 { sizeof (cl_char ), "SIZEOF_CHAR" },
183 { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, 254 { sizeof (cl_uchar ), "SIZEOF_UCHAR" },
184 { sizeof (cl_short ), "SIZEOF_SHORT" }, 255 { sizeof (cl_short ), "SIZEOF_SHORT" },
185 { sizeof (cl_ushort), "SIZEOF_USHORT" }, 256 { sizeof (cl_ushort), "SIZEOF_USHORT" },
186 { sizeof (cl_int ), "SIZEOF_INT" }, 257 { sizeof (cl_int ), "SIZEOF_INT" },
187 { sizeof (cl_uint ), "SIZEOF_UINT" }, 258 { sizeof (cl_uint ), "SIZEOF_UINT" },
188 { sizeof (cl_long ), "SIZEOF_LONG" }, 259 { sizeof (cl_long ), "SIZEOF_LONG" },
189 { sizeof (cl_ulong ), "SIZEOF_ULONG" }, 260 { sizeof (cl_ulong ), "SIZEOF_ULONG" },
190 { sizeof (cl_half ), "SIZEOF_HALF" }, 261 { sizeof (cl_half ), "SIZEOF_HALF" },
191 { sizeof (cl_float ), "SIZEOF_FLOAT" }, 262 { sizeof (cl_float ), "SIZEOF_FLOAT" },
192 { sizeof (cl_double), "SIZEOF_DOUBLE" }, 263 { sizeof (cl_double), "SIZEOF_DOUBLE" },
193#include "constiv.h" 264#include "constiv.h"
194 }; 265 };
195 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 266 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
196 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 267 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
197} 268}
198 269
199cl_int 270cl_int
200errno () 271errno ()
201 CODE: 272 CODE:
221 EXTEND (SP, count); 292 EXTEND (SP, count);
222 for (i = 0; i < count; ++i) 293 for (i = 0; i < count; ++i)
223 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); 294 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i]));
224 295
225void 296void
226context_from_type (FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) 297context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
227 PPCODE: 298 PPCODE:
228 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (0, type, 0, 0, &res)); 299 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res));
229 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 300 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
230 301
231void 302void
232context (FUTURE properties, FUTURE devices, FUTURE notify = 0) 303context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0)
233 PPCODE: 304 PPCODE:
234 /* der Gipfel der Kunst */ 305 /* der Gipfel der Kunst */
235 306
236void 307void
237wait_for_events (...) 308wait_for_events (...)
283 EXTEND (SP, count); 354 EXTEND (SP, count);
284 for (i = 0; i < count; ++i) 355 for (i = 0; i < count; ++i)
285 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); 356 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i]));
286 357
287void 358void
288context (OpenCL::Platform self, FUTURE properties, SV *devices, FUTURE notify = 0) 359context (OpenCL::Platform self, cl_context_properties *properties = 0, SV *devices, FUTURE notify = 0)
289 PPCODE: 360 PPCODE:
290 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) 361 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV)
291 croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call"); 362 croak ("OpenCL::Platform::context argument 'device' must be an arrayref with device objects, in call");
292 363
293 AV *av = (AV *)SvRV (devices); 364 AV *av = (AV *)SvRV (devices);
294 cl_uint num_devices = av_len (av) + 1; 365 cl_uint num_devices = av_len (av) + 1;
295 cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); 366 cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices);
296 int i; 367 int i;
297 368
298 for (i = num_devices; i--; ) 369 for (i = num_devices; i--; )
299 device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device"); 370 device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device");
300 371
301 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (0, num_devices, device_list, 0, 0, &res)); 372 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (properties, num_devices, device_list, 0, 0, &res));
302 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 373 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
303 374
304void 375void
305context_from_type (OpenCL::Platform self, FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) 376context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
306 PPCODE: 377 PPCODE:
307 cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self, 0 }; 378 cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self };
379 cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context_from_type", "properties", properties, extra, 2);
308 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res)); 380 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res));
309 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 381 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
310 382
311MODULE = OpenCL PACKAGE = OpenCL::Device 383MODULE = OpenCL PACKAGE = OpenCL::Device
312 384
552 INFO (Context) 624 INFO (Context)
553 625
554void 626void
555queue (OpenCL::Context self, OpenCL::Device device, cl_command_queue_properties properties = 0) 627queue (OpenCL::Context self, OpenCL::Device device, cl_command_queue_properties properties = 0)
556 PPCODE: 628 PPCODE:
557 NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (self, device, properties, &res)); 629 NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (self, device, properties, &res));
558 XPUSH_NEW_OBJ ("OpenCL::Queue", queue); 630 XPUSH_NEW_OBJ ("OpenCL::Queue", queue);
559 631
560void 632void
561user_event (OpenCL::Context self) 633user_event (OpenCL::Context self)
562 PPCODE: 634 PPCODE:
563 NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (self, &res)); 635 NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (self, &res));
564 XPUSH_NEW_OBJ ("OpenCL::UserEvent", ev); 636 XPUSH_NEW_OBJ ("OpenCL::UserEvent", ev);
565 637
566void 638void
567buffer (OpenCL::Context self, cl_mem_flags flags, size_t len) 639buffer (OpenCL::Context self, cl_mem_flags flags, size_t len)
568 PPCODE: 640 PPCODE:
569 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) 641 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
570 croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); 642 croak ("OpenCL::Context::buffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?");
571 643
572 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res)); 644 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res));
573 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 645 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
574 646
575void 647void
576buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data) 648buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data)
577 PPCODE: 649 PPCODE:
578 STRLEN len; 650 STRLEN len;
579 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 651 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
580 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) 652 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
581 croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); 653 croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
582 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res)); 654 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res));
583 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 655 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
584 656
585void 657void
586image2d (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) 658image2d (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)
587 PPCODE: 659 PPCODE:
588 STRLEN len; 660 STRLEN len;
589 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 661 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
590 const cl_image_format format = { channel_order, channel_type }; 662 const cl_image_format format = { channel_order, channel_type };
591 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res)); 663 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res));
592 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 664 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
593 665
594void 666void
595image3d (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) 667image3d (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)
596 PPCODE: 668 PPCODE:
597 STRLEN len; 669 STRLEN len;
598 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 670 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
599 const cl_image_format format = { channel_order, channel_type }; 671 const cl_image_format format = { channel_order, channel_type };
600 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); 672 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
601 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 673 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
674
675#if cl_apple_gl_sharing || cl_khr_gl_sharing
676
677void
678gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj)
679 PPCODE:
680 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res));
681 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
682
683void
684gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
685 PPCODE:
686 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
687 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
688
689void
690gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
691 PPCODE:
692 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res));
693 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
694
695void
696gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer)
697 PPCODE:
698 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res));
699 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
700
701#endif
602 702
603void 703void
604supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) 704supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type)
605 PPCODE: 705 PPCODE:
606{ 706{
607 cl_uint count; 707 cl_uint count;
608 cl_image_format *list; 708 cl_image_format *list;
609 int i; 709 int i;
610 710
611 NEED_SUCCESS (GetSupportedImageFormats, (self, flags, image_type, 0, 0, &count)); 711 NEED_SUCCESS (GetSupportedImageFormats, (self, flags, image_type, 0, 0, &count));
612 Newx (list, count, cl_image_format); 712 Newx (list, count, cl_image_format);
613 NEED_SUCCESS (GetSupportedImageFormats, (self, flags, image_type, count, list, 0)); 713 NEED_SUCCESS (GetSupportedImageFormats, (self, flags, image_type, count, list, 0));
614 714
615 EXTEND (SP, count); 715 EXTEND (SP, count);
616 for (i = 0; i < count; ++i) 716 for (i = 0; i < count; ++i)
617 { 717 {
618 AV *av = newAV (); 718 AV *av = newAV ();
623} 723}
624 724
625void 725void
626sampler (OpenCL::Context self, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode) 726sampler (OpenCL::Context self, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode)
627 PPCODE: 727 PPCODE:
628 NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (self, normalized_coords, addressing_mode, filter_mode, &res)); 728 NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (self, normalized_coords, addressing_mode, filter_mode, &res));
629 XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler); 729 XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler);
630 730
631void 731void
632program_with_source (OpenCL::Context self, SV *program) 732program_with_source (OpenCL::Context self, SV *program)
633 PPCODE: 733 PPCODE:
634 STRLEN len; 734 STRLEN len;
635 size_t len2; 735 size_t len2;
636 const char *ptr = SvPVbyte (program, len); 736 const char *ptr = SvPVbyte (program, len);
637 737
638 len2 = len; 738 len2 = len;
639 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (self, 1, &ptr, &len2, &res)); 739 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (self, 1, &ptr, &len2, &res));
640 XPUSH_NEW_OBJ ("OpenCL::Program", prog); 740 XPUSH_NEW_OBJ ("OpenCL::Program", prog);
641 741
642#BEGIN:context 742#BEGIN:context
643 743
644void 744void
958 NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1058 NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
959 1059
960 if (ev) 1060 if (ev)
961 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1061 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
962 1062
1063#if cl_apple_gl_sharing || cl_khr_gl_sharing
1064
1065void
1066enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...)
1067 ALIAS:
1068 enqueue_release_gl_objects = 1
1069 CODE:
1070 if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV)
1071 croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call");
1072
1073 cl_event ev = 0;
1074 EVENT_LIST (2, items - 2);
1075 AV *av = (AV *)SvRV (objects);
1076 cl_uint num_objects = av_len (av) + 1;
1077 cl_mem *object_list = tmpbuf (sizeof (cl_mem) * num_objects);
1078 int i;
1079
1080 for (i = num_objects; i--; )
1081 object_list [i] = SvPTROBJ ("OpenCL::Queue::enqueue_acquire/release_gl_objects", "objects", *av_fetch (av, i, 0), "OpenCL::Memory");
1082
1083 if (ix)
1084 NEED_SUCCESS (EnqueueReleaseGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1085 else
1086 NEED_SUCCESS (EnqueueAcquireGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1087
1088 if (ev)
1089 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1090
1091#endif
1092
963void 1093void
964enqueue_marker (OpenCL::Queue self) 1094enqueue_marker (OpenCL::Queue self)
965 PPCODE: 1095 PPCODE:
966 cl_event ev; 1096 cl_event ev;
967 NEED_SUCCESS (EnqueueMarker, (self, &ev)); 1097 NEED_SUCCESS (EnqueueMarker, (self, &ev));
1126 NEED_SUCCESS (RetainMemObject, (value [i])); 1256 NEED_SUCCESS (RetainMemObject, (value [i]));
1127 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i])); 1257 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i]));
1128 } 1258 }
1129 1259
1130#END:mem 1260#END:mem
1261
1262#if cl_apple_gl_sharing || cl_khr_gl_sharing
1263
1264void
1265gl_object_info (OpenCL::Memory self)
1266 PPCODE:
1267 cl_gl_object_type type;
1268 cl_GLuint name;
1269 NEED_SUCCESS (GetGLObjectInfo, (self, &type, &name));
1270 EXTEND (SP, 2);
1271 PUSHs (sv_2mortal (newSVuv (type)));
1272 PUSHs (sv_2mortal (newSVuv (name)));
1273
1274#endif
1131 1275
1132MODULE = OpenCL PACKAGE = OpenCL::BufferObj 1276MODULE = OpenCL PACKAGE = OpenCL::BufferObj
1133 1277
1134void 1278void
1135sub_buffer_region (OpenCL::BufferObj self, cl_mem_flags flags, size_t origin, size_t size) 1279sub_buffer_region (OpenCL::BufferObj self, cl_mem_flags flags, size_t origin, size_t size)
1167 const int i = 0; 1311 const int i = 0;
1168 PUSHs (sv_2mortal (newSVuv (value [i]))); 1312 PUSHs (sv_2mortal (newSVuv (value [i])));
1169 1313
1170#END:image 1314#END:image
1171 1315
1316#if cl_apple_gl_sharing || cl_khr_gl_sharing
1317
1318#BEGIN:gl_texture
1319
1320void
1321target (OpenCL::Image self)
1322 PPCODE:
1323 cl_GLenum value [1];
1324 NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0));
1325 EXTEND (SP, 1);
1326 const int i = 0;
1327 PUSHs (sv_2mortal (newSVuv (value [i])));
1328
1329void
1330gl_mipmap_level (OpenCL::Image self)
1331 PPCODE:
1332 cl_GLint value [1];
1333 NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0));
1334 EXTEND (SP, 1);
1335 const int i = 0;
1336 PUSHs (sv_2mortal (newSViv (value [i])));
1337
1338#END:gl_texture
1339
1340#endif
1341
1172MODULE = OpenCL PACKAGE = OpenCL::Sampler 1342MODULE = OpenCL PACKAGE = OpenCL::Sampler
1173 1343
1174void 1344void
1175DESTROY (OpenCL::Sampler self) 1345DESTROY (OpenCL::Sampler self)
1176 CODE: 1346 CODE:
1246 NEED_SUCCESS (BuildProgram, (self, 1, &device, SvPVbyte_nolen (options), 0, 0)); 1416 NEED_SUCCESS (BuildProgram, (self, 1, &device, SvPVbyte_nolen (options), 0, 0));
1247 1417
1248void 1418void
1249build_info (OpenCL::Program self, OpenCL::Device device, cl_program_build_info name) 1419build_info (OpenCL::Program self, OpenCL::Device device, cl_program_build_info name)
1250 PPCODE: 1420 PPCODE:
1251 size_t size; 1421 size_t size;
1252 NEED_SUCCESS (GetProgramBuildInfo, (self, device, name, 0, 0, &size)); 1422 NEED_SUCCESS (GetProgramBuildInfo, (self, device, name, 0, 0, &size));
1253 SV *sv = sv_2mortal (newSV (size)); 1423 SV *sv = sv_2mortal (newSV (size));
1254 SvUPGRADE (sv, SVt_PV); 1424 SvUPGRADE (sv, SVt_PV);
1255 SvPOK_only (sv); 1425 SvPOK_only (sv);
1256 SvCUR_set (sv, size); 1426 SvCUR_set (sv, size);
1257 NEED_SUCCESS (GetProgramBuildInfo, (self, device, name, size, SvPVX (sv), 0)); 1427 NEED_SUCCESS (GetProgramBuildInfo, (self, device, name, size, SvPVX (sv), 0));
1258 XPUSHs (sv); 1428 XPUSHs (sv);
1259 1429
1260#BEGIN:program_build 1430#BEGIN:program_build
1261 1431
1262void 1432void
1285#END:program_build 1455#END:program_build
1286 1456
1287void 1457void
1288kernel (OpenCL::Program program, SV *function) 1458kernel (OpenCL::Program program, SV *function)
1289 PPCODE: 1459 PPCODE:
1290 NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res)); 1460 NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res));
1291 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel); 1461 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel);
1292 1462
1293void 1463void
1294info (OpenCL::Program self, cl_program_info name) 1464info (OpenCL::Program self, cl_program_info name)
1295 PPCODE: 1465 PPCODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines