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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.28 by root, Thu Apr 19 13:49:33 2012 UTC vs.
Revision 1.43 by root, Sat Apr 21 22:16:09 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
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 */
4 18
5#ifdef __APPLE__ 19#ifdef __APPLE__
6 #include <OpenCL/opencl.h> 20 #include <OpenCL/opencl.h>
7#else 21#else
8 #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
9#endif 28#endif
10 29
11typedef cl_platform_id OpenCL__Platform; 30typedef cl_platform_id OpenCL__Platform;
12typedef cl_device_id OpenCL__Device; 31typedef cl_device_id OpenCL__Device;
13typedef cl_context OpenCL__Context; 32typedef cl_context OpenCL__Context;
31 50
32typedef SV *FUTURE; 51typedef SV *FUTURE;
33 52
34/*****************************************************************************/ 53/*****************************************************************************/
35 54
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.
58static void *
59glsym (const char *name)
60{
61 void *fun = 0;
62
63 #if defined I_DLFCN && defined RTLD_DEFAULT
64 fun = dlsym (RTLD_DEFAULT, name + 1);
65 if (!fun) fun = dlsym (RTLD_DEFAULT, name);
66
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 }
93 #endif
94
95 return fun;
96}
97
98/*****************************************************************************/
99
36/* up to two temporary buffers */ 100/* up to two temporary buffers */
37static void * 101static void *
38tmpbuf (size_t size) 102tmpbuf (size_t size)
39{ 103{
40 enum { buffers = 3 }; 104 enum { buffers = 3 };
41 static int idx; 105 static int idx;
42 static void *buf [buffers]; 106 static void *buf [buffers];
43 static size_t len [buffers]; 107 static size_t len [buffers];
44 108
45 idx = ++idx % buffers; 109 idx = (idx + 1) % buffers;
46 110
47 if (len [idx] < size) 111 if (len [idx] < size)
48 { 112 {
49 free (buf [idx]); 113 free (buf [idx]);
50 len [idx] = ((size + 31) & ~4095) + 4096 - 32; 114 len [idx] = ((size + 31) & ~4095) + 4096 - 32;
154 croak ("%s: %s is not a property list (must be even number of elements)", func, svname); 218 croak ("%s: %s is not a property list (must be even number of elements)", func, svname);
155 219
156 while (extracount--) 220 while (extracount--)
157 *l++ = *extra++; 221 *l++ = *extra++;
158 222
159 for (i = 0; i < len; ++i) 223 for (i = 0; i < len; i += 2)
160 { 224 {
161 cl_context_properties t = SvIV (*av_fetch (av, i, 0)); 225 cl_context_properties t = SvIV (*av_fetch (av, i , 0));
162 cl_context_properties v; 226 SV *p_sv = *av_fetch (av, i + 1, 0);
163 227 cl_context_properties v = SvIV (p_sv); // code below can override
164 ++i;
165 228
166 switch (t) 229 switch (t)
167 { 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
168 default: 249 default:
169 /* unknown property, treat as int */ 250 /* unknown property, treat as int */
170 v = SvIV (*av_fetch (av, i, 0));
171 break; 251 break;
172 } 252 }
173 253
174 *l++ = t; 254 *l++ = t;
175 *l++ = v; 255 *l++ = v;
192 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); 272 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0);
193 return res; 273 return res;
194} 274}
195 275
196static cl_event * 276static cl_event *
197event_list (SV **items, int count) 277event_list (SV **items, cl_uint *rcount)
198{ 278{
279 cl_uint count = *rcount;
280
199 if (!count) 281 if (!count)
200 return 0; 282 return 0;
201 283
202 cl_event *list = tmpbuf (sizeof (cl_event) * count); 284 cl_event *list = tmpbuf (sizeof (cl_event) * count);
285 int i = 0;
203 286
204 while (count--) 287 do
288 {
289 --count;
290 if (SvOK (items [count]))
205 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);
206 294
295 *rcount = i;
296
207 return list; 297 return i ? list : 0;
208} 298}
209 299
210#define EVENT_LIST(items,count) \ 300#define EVENT_LIST(items,count) \
211 cl_uint event_list_count = (count); \ 301 cl_uint event_list_count = (count); \
212 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)
213 303
214#define INFO(class) \ 304#define INFO(class) \
215{ \ 305{ \
216 size_t size; \ 306 size_t size; \
217 NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ 307 NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \
249} 339}
250 340
251cl_int 341cl_int
252errno () 342errno ()
253 CODE: 343 CODE:
254 errno = res; 344 RETVAL = res;
345 OUTPUT:
346 RETVAL
255 347
256const char * 348const char *
257err2str (cl_int err) 349err2str (cl_int err)
258 350
259const char * 351const char *
278context_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)
279 PPCODE: 371 PPCODE:
280 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));
281 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 373 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
282 374
375#if 0
376
283void 377void
284context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) 378context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0)
285 PPCODE: 379 PPCODE:
286 /* der Gipfel der Kunst */ 380 /* der Gipfel der Kunst */
381
382#endif
287 383
288void 384void
289wait_for_events (...) 385wait_for_events (...)
290 CODE: 386 CODE:
291 EVENT_LIST (0, items); 387 EVENT_LIST (0, items);
406 native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 502 native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT
407 native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 503 native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG
408 native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 504 native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT
409 native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 505 native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE
410 native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 506 native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF
411 reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT 507 reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT
412 PPCODE: 508 PPCODE:
413 cl_uint value [1]; 509 cl_uint value [1];
414 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0)); 510 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
415 EXTEND (SP, 1); 511 EXTEND (SP, 1);
416 const int i = 0; 512 const int i = 0;
633 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)))
634 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?");
635 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));
636 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 732 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
637 733
734#if CL_VERSION_1_2
735
638void 736void
639image2d (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)
640 PPCODE: 738 PPCODE:
641 STRLEN len; 739 STRLEN len;
642 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 740 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
643 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 };
644 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 }
645 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 760 XPUSH_NEW_OBJ (klass, mem);
646 761
762#endif
763
647void 764void
648image3d (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) 765image2d (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)
649 PPCODE: 766 PPCODE:
650 STRLEN len; 767 STRLEN len;
651 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 768 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
652 const cl_image_format format = { channel_order, channel_type }; 769 const cl_image_format format = { channel_order, channel_type };
770#if CL_VERSION_1_2
771 const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE2D, width, height, 0, 0, row_pitch, 0, 0, 0, 0 };
772 NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
773#else
774 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res));
775#endif
776 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
777
778void
779image3d (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)
780 PPCODE:
781 STRLEN len;
782 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
783 const cl_image_format format = { channel_order, channel_type };
784#if CL_VERSION_1_2
785 const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE3D, width, height, depth, 0, row_pitch, slice_pitch, 0, 0, 0 };
786 NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
787#else
653 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); 788 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
789#endif
654 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 790 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
655 791
656#if cl_apple_gl_sharing || cl_khr_gl_sharing 792#if cl_apple_gl_sharing || cl_khr_gl_sharing
657 793
658void 794void
660 PPCODE: 796 PPCODE:
661 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res)); 797 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res));
662 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 798 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
663 799
664void 800void
801gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer)
802 PPCODE:
803 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res));
804 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
805
806#if CL_VERSION_1_2
807
808void
809gl_texture (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
810 ALIAS:
811 gl_texture2d = 0
812 gl_texture3d = 0
813 PPCODE:
814 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture, (self, flags, target, miplevel, texture, &res));
815 cl_gl_object_type type;
816 NEED_SUCCESS (GetGLObjectInfo, (mem, &type, 0)); // TODO: use target instead?
817 char *klass = "OpenCL::Memory";
818 switch (type)
819 {
820 case CL_GL_OBJECT_TEXTURE_BUFFER: klass = "OpenCL::Image1DBuffer"; break;
821 case CL_GL_OBJECT_TEXTURE1D: klass = "OpenCL::Image1D"; break;
822 case CL_GL_OBJECT_TEXTURE1D_ARRAY: klass = "OpenCL::Image2DArray"; break;
823 case CL_GL_OBJECT_TEXTURE2D: klass = "OpenCL::Image2D"; break;
824 case CL_GL_OBJECT_TEXTURE2D_ARRAY: klass = "OpenCL::Image2DArray"; break;
825 case CL_GL_OBJECT_TEXTURE3D: klass = "OpenCL::Image3D"; break;
826 }
827 XPUSH_NEW_OBJ (klass, mem);
828
829#else
830
831void
665gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) 832gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
666 PPCODE: 833 PPCODE:
667 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res)); 834 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
668 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 835 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
669 836
671gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) 838gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
672 PPCODE: 839 PPCODE:
673 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res)); 840 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res));
674 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 841 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
675 842
676void 843#endif
677gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer)
678 PPCODE:
679 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res));
680 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
681 844
682#endif 845#endif
683 846
684void 847void
685supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) 848supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type)
790 cl_event ev = 0; 953 cl_event ev = 0;
791 STRLEN len; 954 STRLEN len;
792 char *ptr = SvPVbyte (data, len); 955 char *ptr = SvPVbyte (data, len);
793 EVENT_LIST (5, items - 5); 956 EVENT_LIST (5, items - 5);
794 957
795 NEED_SUCCESS (EnqueueReadBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 958 NEED_SUCCESS (EnqueueWriteBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
796 959
797 if (ev) 960 if (ev)
798 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 961 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
799 962
800void 963void
866 size_t min_len = host_row_pitch * host_slice_pitch * region [2]; 1029 size_t min_len = host_row_pitch * host_slice_pitch * region [2];
867 1030
868 if (len < min_len) 1031 if (len < min_len)
869 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1032 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
870 1033
871 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)); 1034 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));
872 1035
873 if (ev) 1036 if (ev)
874 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1037 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
875 1038
876void 1039void
931 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height; 1094 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height;
932 1095
933 if (len < min_len) 1096 if (len < min_len)
934 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1097 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
935 1098
936 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)); 1099 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));
937 1100
938 if (ev) 1101 if (ev)
939 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1102 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
940 1103
941void 1104void
1023 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); 1186 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
1024 } 1187 }
1025 1188
1026 if (SvOK (local_work_size)) 1189 if (SvOK (local_work_size))
1027 { 1190 {
1028 if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV) 1191 if ((SvOK (local_work_size) && !SvROK (local_work_size)) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV)
1029 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference"); 1192 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference");
1030 1193
1031 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) 1194 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len)
1032 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size"); 1195 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
1033 1196
1045 1208
1046void 1209void
1047enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...) 1210enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...)
1048 ALIAS: 1211 ALIAS:
1049 enqueue_release_gl_objects = 1 1212 enqueue_release_gl_objects = 1
1050 CODE: 1213 PPCODE:
1051 if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV) 1214 if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV)
1052 croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call"); 1215 croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call");
1053 1216
1054 cl_event ev = 0; 1217 cl_event ev = 0;
1055 EVENT_LIST (2, items - 2); 1218 EVENT_LIST (2, items - 2);
1069 if (ev) 1232 if (ev)
1070 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1233 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1071 1234
1072#endif 1235#endif
1073 1236
1074void 1237#if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS
1075enqueue_marker (OpenCL::Queue self)
1076 PPCODE:
1077 cl_event ev;
1078 NEED_SUCCESS (EnqueueMarker, (self, &ev));
1079 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1080 1238
1081void 1239void
1082enqueue_wait_for_events (OpenCL::Queue self, ...) 1240enqueue_wait_for_events (OpenCL::Queue self, ...)
1083 CODE: 1241 CODE:
1084 EVENT_LIST (1, items - 1); 1242 EVENT_LIST (1, items - 1);
1085 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); 1243 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr));
1086 1244
1245#endif
1246
1087void 1247void
1248enqueue_marker (OpenCL::Queue self, ...)
1249 PPCODE:
1250 cl_event ev = 0;
1251 EVENT_LIST (1, items - 1);
1252#if CL_VERSION_1_2
1253 NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1254#else
1255 if (event_list_count)
1256 croak ("OpenCL::Queue->enqueue_marker does not support a wait list in OpenCL 1.1 - upgrade to 1.2");
1257 NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0));
1258#endif
1259 if (ev)
1260 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1261
1262void
1088enqueue_barrier (OpenCL::Queue self) 1263enqueue_barrier (OpenCL::Queue self, ...)
1089 CODE: 1264 PPCODE:
1265 cl_event ev = 0;
1266 EVENT_LIST (1, items - 1);
1267#if CL_VERSION_1_2
1268 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, &ev));
1269#else
1270 if (event_list_count)
1271 croak ("OpenCL::Queue->enqueue_barrier does not support a wait list in OpenCL 1.1 - upgrade to 1.2");
1272 if (GIMME_V != G_VOID)
1273 croak ("OpenCL::Queue->enqueue_barrier does not return an event object in OpenCL 1.1 - upgrade to 1.2");
1090 NEED_SUCCESS (EnqueueBarrier, (self)); 1274 NEED_SUCCESS (EnqueueBarrier, (self));
1275#endif
1276 if (ev)
1277 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1091 1278
1092void 1279void
1093flush (OpenCL::Queue self) 1280flush (OpenCL::Queue self)
1094 CODE: 1281 CODE:
1095 NEED_SUCCESS (Flush, (self)); 1282 NEED_SUCCESS (Flush, (self));
1245void 1432void
1246gl_object_info (OpenCL::Memory self) 1433gl_object_info (OpenCL::Memory self)
1247 PPCODE: 1434 PPCODE:
1248 cl_gl_object_type type; 1435 cl_gl_object_type type;
1249 cl_GLuint name; 1436 cl_GLuint name;
1250 NEED_SUCCESS (clGetGLObjectInfo, (self, &type, &name)); 1437 NEED_SUCCESS (GetGLObjectInfo, (self, &type, &name));
1251 EXTEND (SP, 2); 1438 EXTEND (SP, 2);
1252 PUSHs (sv_2mortal (newSVuv (type))); 1439 PUSHs (sv_2mortal (newSVuv (type)));
1253 PUSHs (sv_2mortal (newSVuv (name))); 1440 PUSHs (sv_2mortal (newSVuv (name)));
1254 1441
1255#endif 1442#endif
1300 1487
1301void 1488void
1302target (OpenCL::Image self) 1489target (OpenCL::Image self)
1303 PPCODE: 1490 PPCODE:
1304 cl_GLenum value [1]; 1491 cl_GLenum value [1];
1305 NEED_SUCCESS (GetGlTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0)); 1492 NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0));
1306 EXTEND (SP, 1); 1493 EXTEND (SP, 1);
1307 const int i = 0; 1494 const int i = 0;
1308 PUSHs (sv_2mortal (newSVuv (value [i]))); 1495 PUSHs (sv_2mortal (newSVuv (value [i])));
1309 1496
1310void 1497void
1311gl_mipmap_level (OpenCL::Image self) 1498gl_mipmap_level (OpenCL::Image self)
1312 PPCODE: 1499 PPCODE:
1313 cl_GLint value [1]; 1500 cl_GLint value [1];
1314 NEED_SUCCESS (GetGlTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0)); 1501 NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0));
1315 EXTEND (SP, 1); 1502 EXTEND (SP, 1);
1316 const int i = 0; 1503 const int i = 0;
1317 PUSHs (sv_2mortal (newSViv (value [i]))); 1504 PUSHs (sv_2mortal (newSViv (value [i])));
1318 1505
1319#END:gl_texture 1506#END:gl_texture
1465 { 1652 {
1466 SV *sv = sv_2mortal (newSV (sizes [i])); 1653 SV *sv = sv_2mortal (newSV (sizes [i]));
1467 SvUPGRADE (sv, SVt_PV); 1654 SvUPGRADE (sv, SVt_PV);
1468 SvPOK_only (sv); 1655 SvPOK_only (sv);
1469 SvCUR_set (sv, sizes [i]); 1656 SvCUR_set (sv, sizes [i]);
1470 ptrs [i] = SvPVX (sv); 1657 ptrs [i] = (void *)SvPVX (sv);
1471 PUSHs (sv); 1658 PUSHs (sv);
1472 } 1659 }
1473 1660
1474 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size)); 1661 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size));
1475 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; 1662 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY;
1625set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) 1812set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value)
1626 CODE: 1813 CODE:
1627 clSetKernelArg (self, idx, sizeof (value), &value); 1814 clSetKernelArg (self, idx, sizeof (value), &value);
1628 1815
1629void 1816void
1817set_local (OpenCL::Kernel self, cl_uint idx, size_t size)
1818 CODE:
1819 clSetKernelArg (self, idx, size, 0);
1820
1821void
1630set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value) 1822set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value)
1631 CODE: 1823 CODE:
1632 clSetKernelArg (self, idx, sizeof (value), &value); 1824 clSetKernelArg (self, idx, sizeof (value), &value);
1633 1825
1634void 1826void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines