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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.31 by root, Thu Apr 19 14:36:46 2012 UTC vs.
Revision 1.42 by root, Sat Apr 21 20:48:03 2012 UTC

3#include "XSUB.h" 3#include "XSUB.h"
4 4
5#ifdef I_DLFCN 5#ifdef I_DLFCN
6 #include <dlfcn.h> 6 #include <dlfcn.h>
7#endif 7#endif
8
9// how stupid is that, the 1.2 header files define CL_VERSION_1_1,
10// but then fail to define the api functions unless you ALSO define
11// this. This breaks 100% of the opencl 1.1 apps, for what reason?
12// after all, the functions are deprecated, not removed.
13// in addition, you cannot test for this in any future-proof way.
14// each time a new opencl version comes out, you need to make a new
15// release.
16#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
17#define CL_USE_DEPRECATED_OPENCL_1_2_APIS /* just guessing, you stupid idiots */
8 18
9#ifdef __APPLE__ 19#ifdef __APPLE__
10 #include <OpenCL/opencl.h> 20 #include <OpenCL/opencl.h>
11#else 21#else
12 #include <CL/opencl.h> 22 #include <CL/opencl.h>
23#endif
24
25#if 0 // testing
26#undef CL_USE_DEPRECATED_OPENCL_1_1_APIS
27#undef CL_VERSION_1_2
13#endif 28#endif
14 29
15typedef cl_platform_id OpenCL__Platform; 30typedef cl_platform_id OpenCL__Platform;
16typedef cl_device_id OpenCL__Device; 31typedef cl_device_id OpenCL__Device;
17typedef cl_context OpenCL__Context; 32typedef cl_context OpenCL__Context;
36typedef SV *FUTURE; 51typedef SV *FUTURE;
37 52
38/*****************************************************************************/ 53/*****************************************************************************/
39 54
40// name must include a leading underscore 55// name must include a leading underscore
56// all of this horrors would be unneceesary if somebody wrote a proper OpenGL module
57// for perl. doh.
41static void * 58static void *
42getsym (const char *name) 59glsym (const char *name)
43{ 60{
61 void *fun = 0;
62
44 #if defined I_DLFCN && defined RTLD_DEFAULT 63 #if defined I_DLFCN && defined RTLD_DEFAULT
45 #if !DLSYM_NEEDS_UNDERSCORE 64 fun = dlsym (RTLD_DEFAULT, name + 1);
46 ++name; // skip _
47 #endif
48 return dlsym (RTLD_DEFAULT, name); 65 if (!fun) fun = dlsym (RTLD_DEFAULT, name);
49 #else 66
50 return 0; 67 if (!fun)
68 {
69 static void *libgl;
70 static const char *glso[] = {
71 "libGL.so.1",
72 "libGL.so.3",
73 "libGL.so.4.0",
74 "libGL.so",
75 "/usr/lib/libGL.so",
76 "/usr/X11R6/lib/libGL.1.dylib"
77 };
78 int i;
79
80 for (i = 0; !libgl && i < sizeof (glso) / sizeof (glso [0]); ++i)
81 {
82 libgl = dlopen (glso [i], RTLD_LAZY);
83 if (libgl)
84 break;
85 }
86
87 if (libgl)
88 {
89 fun = dlsym (libgl, name + 1);
90 if (!fun) fun = dlsym (libgl, name);
91 }
92 }
51 #endif 93 #endif
94
95 return fun;
52} 96}
53 97
54/*****************************************************************************/ 98/*****************************************************************************/
55 99
56/* up to two temporary buffers */ 100/* up to two temporary buffers */
60 enum { buffers = 3 }; 104 enum { buffers = 3 };
61 static int idx; 105 static int idx;
62 static void *buf [buffers]; 106 static void *buf [buffers];
63 static size_t len [buffers]; 107 static size_t len [buffers];
64 108
65 idx = ++idx % buffers; 109 idx = (idx + 1) % buffers;
66 110
67 if (len [idx] < size) 111 if (len [idx] < size)
68 { 112 {
69 free (buf [idx]); 113 free (buf [idx]);
70 len [idx] = ((size + 31) & ~4095) + 4096 - 32; 114 len [idx] = ((size + 31) & ~4095) + 4096 - 32;
178 222
179 for (i = 0; i < len; i += 2) 223 for (i = 0; i < len; i += 2)
180 { 224 {
181 cl_context_properties t = SvIV (*av_fetch (av, i , 0)); 225 cl_context_properties t = SvIV (*av_fetch (av, i , 0));
182 SV *p_sv = *av_fetch (av, i + 1, 0); 226 SV *p_sv = *av_fetch (av, i + 1, 0);
183 cl_context_properties v; 227 cl_context_properties v = SvIV (p_sv); // code below can override
184 228
185 switch (t) 229 switch (t)
186 { 230 {
231 case CL_GLX_DISPLAY_KHR:
232 if (!SvOK (p_sv))
233 {
234 void *func = glsym ("_glXGetCurrentDisplay");
235 if (func)
236 v = (cl_context_properties)((void *(*)(void))func)();
237 }
238 break;
239
240 case CL_GL_CONTEXT_KHR:
241 if (!SvOK (p_sv))
242 {
243 void *func = glsym ("_glXGetCurrentContext");
244 if (func)
245 v = (cl_context_properties)((void *(*)(void))func)();
246 }
247 break;
248
187 default: 249 default:
188 /* unknown property, treat as int */ 250 /* unknown property, treat as int */
189 v = SvIV (p_sv);
190 break; 251 break;
191 } 252 }
192 253
193 *l++ = t; 254 *l++ = t;
194 *l++ = v; 255 *l++ = v;
211 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); 272 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0);
212 return res; 273 return res;
213} 274}
214 275
215static cl_event * 276static cl_event *
216event_list (SV **items, int count) 277event_list (SV **items, cl_uint *rcount)
217{ 278{
279 cl_uint count = *rcount;
280
218 if (!count) 281 if (!count)
219 return 0; 282 return 0;
220 283
221 cl_event *list = tmpbuf (sizeof (cl_event) * count); 284 cl_event *list = tmpbuf (sizeof (cl_event) * count);
285 int i = 0;
222 286
223 while (count--) 287 do
288 {
289 --count;
290 if (SvOK (items [count]))
224 list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); 291 list [i++] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event");
292 }
293 while (count);
225 294
295 *rcount = i;
296
226 return list; 297 return i ? list : 0;
227} 298}
228 299
229#define EVENT_LIST(items,count) \ 300#define EVENT_LIST(items,count) \
230 cl_uint event_list_count = (count); \ 301 cl_uint event_list_count = (count); \
231 cl_event *event_list_ptr = event_list (&ST (items), event_list_count) 302 cl_event *event_list_ptr = event_list (&ST (items), &event_list_count)
232 303
233#define INFO(class) \ 304#define INFO(class) \
234{ \ 305{ \
235 size_t size; \ 306 size_t size; \
236 NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ 307 NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \
268} 339}
269 340
270cl_int 341cl_int
271errno () 342errno ()
272 CODE: 343 CODE:
273 errno = res; 344 RETVAL = res;
345 OUTPUT:
346 RETVAL
274 347
275const char * 348const char *
276err2str (cl_int err) 349err2str (cl_int err)
277 350
278const char * 351const char *
297context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) 370context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
298 PPCODE: 371 PPCODE:
299 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res)); 372 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res));
300 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 373 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
301 374
375#if 0
376
302void 377void
303context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) 378context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0)
304 PPCODE: 379 PPCODE:
305 /* der Gipfel der Kunst */ 380 /* der Gipfel der Kunst */
381
382#endif
306 383
307void 384void
308wait_for_events (...) 385wait_for_events (...)
309 CODE: 386 CODE:
310 EVENT_LIST (0, items); 387 EVENT_LIST (0, items);
425 native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 502 native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT
426 native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 503 native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG
427 native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 504 native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT
428 native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 505 native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE
429 native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 506 native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF
430 reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT 507 reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT
431 PPCODE: 508 PPCODE:
432 cl_uint value [1]; 509 cl_uint value [1];
433 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0)); 510 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
434 EXTEND (SP, 1); 511 EXTEND (SP, 1);
435 const int i = 0; 512 const int i = 0;
652 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) 729 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
653 croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); 730 croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
654 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res)); 731 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res));
655 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 732 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
656 733
734#if CL_VERSION_1_2
735
657void 736void
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) 737image (OpenCL::Context self, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, cl_mem_object_type type, size_t width, size_t height, size_t depth, size_t array_size = 0, size_t row_pitch = 0, size_t slice_pitch = 0, cl_uint num_mip_level = 0, cl_uint num_samples = 0, SV *data = &PL_sv_undef)
659 PPCODE: 738 PPCODE:
660 STRLEN len; 739 STRLEN len;
661 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 740 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
662 const cl_image_format format = { channel_order, channel_type }; 741 const cl_image_format format = { channel_order, channel_type };
742 const cl_image_desc desc = {
743 type,
744 width, height, depth,
745 array_size, row_pitch, slice_pitch,
746 num_mip_level, num_samples,
747 type == CL_MEM_OBJECT_IMAGE1D_BUFFER ? (cl_mem)SvPTROBJ ("OpenCL::Context::Image", "data", data, "OpenCL::Buffer") : 0
748 };
663 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res)); 749 NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
750 char *klass = "OpenCL::Image";
751 switch (type)
752 {
753 case CL_MEM_OBJECT_IMAGE1D_BUFFER: klass = "OpenCL::Image1DBuffer"; break;
754 case CL_MEM_OBJECT_IMAGE1D: klass = "OpenCL::Image1D"; break;
755 case CL_MEM_OBJECT_IMAGE1D_ARRAY: klass = "OpenCL::Image2DArray"; break;
756 case CL_MEM_OBJECT_IMAGE2D: klass = "OpenCL::Image2D"; break;
757 case CL_MEM_OBJECT_IMAGE2D_ARRAY: klass = "OpenCL::Image2DArray"; break;
758 case CL_MEM_OBJECT_IMAGE3D: klass = "OpenCL::Image3D"; break;
759 }
664 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 760 XPUSH_NEW_OBJ (klass, mem);
665 761
762#endif
763
764#if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS
765
666void 766void
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) 767image2d (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)
668 PPCODE: 768 PPCODE:
669 STRLEN len; 769 STRLEN len;
670 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 770 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
671 const cl_image_format format = { channel_order, channel_type }; 771 const cl_image_format format = { channel_order, channel_type };
772#if CL_VERSION_1_2
773 const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE2D, width, height, 0, 0, row_pitch, 0, 0, 0, 0 };
774 NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
775#else
776 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res));
777#endif
778 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
779
780void
781image3d (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)
782 PPCODE:
783 STRLEN len;
784 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
785 const cl_image_format format = { channel_order, channel_type };
786#if CL_VERSION_1_2
787 const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE3D, width, height, depth, 0, row_pitch, slice_pitch, 0, 0, 0 };
788 NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
789#else
672 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); 790 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
791#endif
673 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 792 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
793
794#endif
674 795
675#if cl_apple_gl_sharing || cl_khr_gl_sharing 796#if cl_apple_gl_sharing || cl_khr_gl_sharing
676 797
677void 798void
678gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj) 799gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj)
679 PPCODE: 800 PPCODE:
680 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res)); 801 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res));
681 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 802 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
682 803
683void 804void
805gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer)
806 PPCODE:
807 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res));
808 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
809
810#if CL_VERSION_1_2
811
812void
813gl_texture (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
814 PPCODE:
815 char *klass = "OpenCL::Memory";
816 cl_gl_object_type type;
817 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
818 NEED_SUCCESS (GetGLObjectInfo, (mem, &type, 0));
819 switch (type)
820 {
821 case CL_GL_OBJECT_TEXTURE_BUFFER: klass = "OpenCL::Image1DBuffer"; break;
822 case CL_GL_OBJECT_TEXTURE1D: klass = "OpenCL::Image1D"; break;
823 case CL_GL_OBJECT_TEXTURE1D_ARRAY: klass = "OpenCL::Image2DArray"; break;
824 case CL_GL_OBJECT_TEXTURE2D: klass = "OpenCL::Image2D"; break;
825 case CL_GL_OBJECT_TEXTURE2D_ARRAY: klass = "OpenCL::Image2DArray"; break;
826 case CL_GL_OBJECT_TEXTURE3D: klass = "OpenCL::Image3D"; break;
827 }
828 XPUSH_NEW_OBJ (klass, mem);
829
830#endif
831
832#if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS
833
834void
684gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) 835gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
685 PPCODE: 836 PPCODE:
686 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res)); 837 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
687 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 838 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
688 839
690gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) 841gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
691 PPCODE: 842 PPCODE:
692 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res)); 843 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res));
693 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 844 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
694 845
695void 846#endif
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 847
701#endif 848#endif
702 849
703void 850void
704supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) 851supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type)
809 cl_event ev = 0; 956 cl_event ev = 0;
810 STRLEN len; 957 STRLEN len;
811 char *ptr = SvPVbyte (data, len); 958 char *ptr = SvPVbyte (data, len);
812 EVENT_LIST (5, items - 5); 959 EVENT_LIST (5, items - 5);
813 960
814 NEED_SUCCESS (EnqueueReadBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 961 NEED_SUCCESS (EnqueueWriteBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
815 962
816 if (ev) 963 if (ev)
817 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 964 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
818 965
819void 966void
885 size_t min_len = host_row_pitch * host_slice_pitch * region [2]; 1032 size_t min_len = host_row_pitch * host_slice_pitch * region [2];
886 1033
887 if (len < min_len) 1034 if (len < min_len)
888 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1035 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
889 1036
890 NEED_SUCCESS (EnqueueWriteBufferRect, (self, buf, blocking, buf_origin, host_origin, region, buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1037 NEED_SUCCESS (EnqueueWriteBufferRect, (self, buf, blocking, buf_origin, host_origin, region, buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
891 1038
892 if (ev) 1039 if (ev)
893 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1040 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
894 1041
895void 1042void
950 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height; 1097 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height;
951 1098
952 if (len < min_len) 1099 if (len < min_len)
953 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1100 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
954 1101
955 NEED_SUCCESS (EnqueueWriteImage, (self, dst, blocking, dst_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1102 NEED_SUCCESS (EnqueueWriteImage, (self, dst, blocking, dst_origin, region, row_pitch, slice_pitch, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
956 1103
957 if (ev) 1104 if (ev)
958 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1105 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
959 1106
960void 1107void
1042 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); 1189 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
1043 } 1190 }
1044 1191
1045 if (SvOK (local_work_size)) 1192 if (SvOK (local_work_size))
1046 { 1193 {
1047 if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV) 1194 if ((SvOK (local_work_size) && !SvROK (local_work_size)) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV)
1048 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference"); 1195 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference");
1049 1196
1050 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) 1197 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len)
1051 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size"); 1198 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
1052 1199
1064 1211
1065void 1212void
1066enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...) 1213enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...)
1067 ALIAS: 1214 ALIAS:
1068 enqueue_release_gl_objects = 1 1215 enqueue_release_gl_objects = 1
1069 CODE: 1216 PPCODE:
1070 if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV) 1217 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"); 1218 croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call");
1072 1219
1073 cl_event ev = 0; 1220 cl_event ev = 0;
1074 EVENT_LIST (2, items - 2); 1221 EVENT_LIST (2, items - 2);
1088 if (ev) 1235 if (ev)
1089 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1236 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1090 1237
1091#endif 1238#endif
1092 1239
1093void 1240#if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS
1094enqueue_marker (OpenCL::Queue self)
1095 PPCODE:
1096 cl_event ev;
1097 NEED_SUCCESS (EnqueueMarker, (self, &ev));
1098 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1099 1241
1100void 1242void
1101enqueue_wait_for_events (OpenCL::Queue self, ...) 1243enqueue_wait_for_events (OpenCL::Queue self, ...)
1102 CODE: 1244 CODE:
1103 EVENT_LIST (1, items - 1); 1245 EVENT_LIST (1, items - 1);
1104 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); 1246 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr));
1105 1247
1248#endif
1249
1106void 1250void
1251enqueue_marker (OpenCL::Queue self, ...)
1252 PPCODE:
1253 cl_event ev = 0;
1254 EVENT_LIST (1, items - 1);
1255#if CL_VERSION_1_2
1256 NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1257#else
1258 if (event_list_count)
1259 croak ("OpenCL::Queue->enqueue_marker does not support a wait list in OpenCL 1.1 - upgrade to 1.2");
1260 NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0));
1261#endif
1262 if (ev)
1263 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1264
1265void
1107enqueue_barrier (OpenCL::Queue self) 1266enqueue_barrier (OpenCL::Queue self, ...)
1108 CODE: 1267 PPCODE:
1268 cl_event ev = 0;
1269 EVENT_LIST (1, items - 1);
1270#if CL_VERSION_1_2
1271 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, &ev));
1272#else
1273 if (event_list_count)
1274 croak ("OpenCL::Queue->enqueue_barrier does not support a wait list in OpenCL 1.1 - upgrade to 1.2");
1275 if (GIMME_V != G_VOID)
1276 croak ("OpenCL::Queue->enqueue_barrier does not return an event object in OpenCL 1.1 - upgrade to 1.2");
1109 NEED_SUCCESS (EnqueueBarrier, (self)); 1277 NEED_SUCCESS (EnqueueBarrier, (self));
1278#endif
1279 if (ev)
1280 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1110 1281
1111void 1282void
1112flush (OpenCL::Queue self) 1283flush (OpenCL::Queue self)
1113 CODE: 1284 CODE:
1114 NEED_SUCCESS (Flush, (self)); 1285 NEED_SUCCESS (Flush, (self));
1484 { 1655 {
1485 SV *sv = sv_2mortal (newSV (sizes [i])); 1656 SV *sv = sv_2mortal (newSV (sizes [i]));
1486 SvUPGRADE (sv, SVt_PV); 1657 SvUPGRADE (sv, SVt_PV);
1487 SvPOK_only (sv); 1658 SvPOK_only (sv);
1488 SvCUR_set (sv, sizes [i]); 1659 SvCUR_set (sv, sizes [i]);
1489 ptrs [i] = SvPVX (sv); 1660 ptrs [i] = (void *)SvPVX (sv);
1490 PUSHs (sv); 1661 PUSHs (sv);
1491 } 1662 }
1492 1663
1493 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size)); 1664 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size));
1494 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; 1665 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY;
1644set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) 1815set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value)
1645 CODE: 1816 CODE:
1646 clSetKernelArg (self, idx, sizeof (value), &value); 1817 clSetKernelArg (self, idx, sizeof (value), &value);
1647 1818
1648void 1819void
1820set_local (OpenCL::Kernel self, cl_uint idx, size_t size)
1821 CODE:
1822 clSetKernelArg (self, idx, size, 0);
1823
1824void
1649set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value) 1825set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value)
1650 CODE: 1826 CODE:
1651 clSetKernelArg (self, idx, sizeof (value), &value); 1827 clSetKernelArg (self, idx, sizeof (value), &value);
1652 1828
1653void 1829void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines