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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.33 by root, Fri Apr 20 08:57:09 2012 UTC vs.
Revision 1.47 by root, Tue Apr 24 13:30:49 2012 UTC

2#include "perl.h" 2#include "perl.h"
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
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_2_APIS /* just guessing, you stupid idiots */
17
18#ifndef PREFER_1_1
19 #define PREFER_1_1 1
20#endif
21
22#if PREFER_1_1
23 #define CL_USE_DEPRECATED_OPENCL_1_1_APIS
7#endif 24#endif
8 25
9#ifdef __APPLE__ 26#ifdef __APPLE__
10 #include <OpenCL/opencl.h> 27 #include <OpenCL/opencl.h>
11#else 28#else
12 #include <CL/opencl.h> 29 #include <CL/opencl.h>
30#endif
31
32#ifndef CL_VERSION_1_2
33 #undef PREFER_1_1
34 #define PREFER_1_1 1
13#endif 35#endif
14 36
15typedef cl_platform_id OpenCL__Platform; 37typedef cl_platform_id OpenCL__Platform;
16typedef cl_device_id OpenCL__Device; 38typedef cl_device_id OpenCL__Device;
17typedef cl_context OpenCL__Context; 39typedef cl_context OpenCL__Context;
89 enum { buffers = 3 }; 111 enum { buffers = 3 };
90 static int idx; 112 static int idx;
91 static void *buf [buffers]; 113 static void *buf [buffers];
92 static size_t len [buffers]; 114 static size_t len [buffers];
93 115
94 idx = ++idx % buffers; 116 idx = (idx + 1) % buffers;
95 117
96 if (len [idx] < size) 118 if (len [idx] < size)
97 { 119 {
98 free (buf [idx]); 120 free (buf [idx]);
99 len [idx] = ((size + 31) & ~4095) + 4096 - 32; 121 len [idx] = ((size + 31) & ~4095) + 4096 - 32;
257 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); 279 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0);
258 return res; 280 return res;
259} 281}
260 282
261static cl_event * 283static cl_event *
262event_list (SV **items, int count) 284event_list (SV **items, cl_uint *rcount)
263{ 285{
286 cl_uint count = *rcount;
287
264 if (!count) 288 if (!count)
265 return 0; 289 return 0;
266 290
267 cl_event *list = tmpbuf (sizeof (cl_event) * count); 291 cl_event *list = tmpbuf (sizeof (cl_event) * count);
292 int i = 0;
268 293
269 while (count--) 294 do
295 {
296 --count;
297 if (SvOK (items [count]))
270 list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); 298 list [i++] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event");
299 }
300 while (count);
271 301
302 *rcount = i;
303
272 return list; 304 return i ? list : 0;
273} 305}
274 306
275#define EVENT_LIST(items,count) \ 307#define EVENT_LIST(items,count) \
276 cl_uint event_list_count = (count); \ 308 cl_uint event_list_count = (count); \
277 cl_event *event_list_ptr = event_list (&ST (items), event_list_count) 309 cl_event *event_list_ptr = event_list (&ST (items), &event_list_count)
278 310
279#define INFO(class) \ 311#define INFO(class) \
280{ \ 312{ \
281 size_t size; \ 313 size_t size; \
282 NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ 314 NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \
314} 346}
315 347
316cl_int 348cl_int
317errno () 349errno ()
318 CODE: 350 CODE:
319 errno = res; 351 RETVAL = res;
352 OUTPUT:
353 RETVAL
320 354
321const char * 355const char *
322err2str (cl_int err) 356err2str (cl_int err)
323 357
324const char * 358const char *
343context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) 377context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
344 PPCODE: 378 PPCODE:
345 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res)); 379 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res));
346 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 380 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
347 381
382#if 0
383
348void 384void
349context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) 385context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0)
350 PPCODE: 386 PPCODE:
351 /* der Gipfel der Kunst */ 387 /* der Gipfel der Kunst */
388
389#endif
352 390
353void 391void
354wait_for_events (...) 392wait_for_events (...)
355 CODE: 393 CODE:
356 EVENT_LIST (0, items); 394 EVENT_LIST (0, items);
362 400
363void 401void
364info (OpenCL::Platform self, cl_platform_info name) 402info (OpenCL::Platform self, cl_platform_info name)
365 PPCODE: 403 PPCODE:
366 INFO (Platform) 404 INFO (Platform)
405
406void
407unload_compiler (OpenCL::Platform self)
408 CODE:
409#if CL_VERSION_1_2
410 clUnloadPlatformCompiler (self);
411#endif
367 412
368#BEGIN:platform 413#BEGIN:platform
369 414
370void 415void
371profile (OpenCL::Platform self) 416profile (OpenCL::Platform self)
471 native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 516 native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT
472 native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 517 native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG
473 native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 518 native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT
474 native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 519 native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE
475 native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 520 native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF
476 reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT 521 reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT
477 PPCODE: 522 PPCODE:
478 cl_uint value [1]; 523 cl_uint value [1];
479 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0)); 524 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
480 EXTEND (SP, 1); 525 EXTEND (SP, 1);
481 const int i = 0; 526 const int i = 0;
698 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) 743 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
699 croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); 744 croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
700 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res)); 745 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res));
701 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 746 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
702 747
748#if CL_VERSION_1_2
749
703void 750void
704image2d (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) 751image (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)
705 PPCODE: 752 PPCODE:
706 STRLEN len; 753 STRLEN len;
707 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 754 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
708 const cl_image_format format = { channel_order, channel_type }; 755 const cl_image_format format = { channel_order, channel_type };
756 const cl_image_desc desc = {
757 type,
758 width, height, depth,
759 array_size, row_pitch, slice_pitch,
760 num_mip_level, num_samples,
761 type == CL_MEM_OBJECT_IMAGE1D_BUFFER ? (cl_mem)SvPTROBJ ("OpenCL::Context::Image", "data", data, "OpenCL::Buffer") : 0
762 };
709 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res)); 763 NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
764 char *klass = "OpenCL::Image";
765 switch (type)
766 {
767 case CL_MEM_OBJECT_IMAGE1D_BUFFER: klass = "OpenCL::Image1DBuffer"; break;
768 case CL_MEM_OBJECT_IMAGE1D: klass = "OpenCL::Image1D"; break;
769 case CL_MEM_OBJECT_IMAGE1D_ARRAY: klass = "OpenCL::Image2DArray"; break;
770 case CL_MEM_OBJECT_IMAGE2D: klass = "OpenCL::Image2D"; break;
771 case CL_MEM_OBJECT_IMAGE2D_ARRAY: klass = "OpenCL::Image2DArray"; break;
772 case CL_MEM_OBJECT_IMAGE3D: klass = "OpenCL::Image3D"; break;
773 }
710 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 774 XPUSH_NEW_OBJ (klass, mem);
711 775
776#endif
777
712void 778void
713image3d (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) 779image2d (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)
714 PPCODE: 780 PPCODE:
715 STRLEN len; 781 STRLEN len;
716 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 782 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
717 const cl_image_format format = { channel_order, channel_type }; 783 const cl_image_format format = { channel_order, channel_type };
784#if PREFER_1_1
785 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res));
786#else
787 const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE2D, width, height, 0, 0, row_pitch, 0, 0, 0, 0 };
788 NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
789#endif
790 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
791
792void
793image3d (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)
794 PPCODE:
795 STRLEN len;
796 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
797 const cl_image_format format = { channel_order, channel_type };
798#if PREFER_1_1
718 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); 799 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
800#else
801 const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE3D, width, height, depth, 0, row_pitch, slice_pitch, 0, 0, 0 };
802 NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res));
803#endif
719 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 804 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
720 805
721#if cl_apple_gl_sharing || cl_khr_gl_sharing 806#if cl_apple_gl_sharing || cl_khr_gl_sharing
722 807
723void 808void
725 PPCODE: 810 PPCODE:
726 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res)); 811 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res));
727 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 812 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
728 813
729void 814void
730gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
731 PPCODE:
732 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
733 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
734
735void
736gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
737 PPCODE:
738 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res));
739 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
740
741void
742gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer) 815gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer)
743 PPCODE: 816 PPCODE:
744 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res)); 817 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res));
745 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 818 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
819
820#if CL_VERSION_1_2
821
822void
823gl_texture (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
824 ALIAS:
825 PPCODE:
826 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture, (self, flags, target, miplevel, texture, &res));
827 cl_gl_object_type type;
828 NEED_SUCCESS (GetGLObjectInfo, (mem, &type, 0)); // TODO: use target instead?
829 char *klass = "OpenCL::Memory";
830 switch (type)
831 {
832 case CL_GL_OBJECT_TEXTURE_BUFFER: klass = "OpenCL::Image1DBuffer"; break;
833 case CL_GL_OBJECT_TEXTURE1D: klass = "OpenCL::Image1D"; break;
834 case CL_GL_OBJECT_TEXTURE1D_ARRAY: klass = "OpenCL::Image2DArray"; break;
835 case CL_GL_OBJECT_TEXTURE2D: klass = "OpenCL::Image2D"; break;
836 case CL_GL_OBJECT_TEXTURE2D_ARRAY: klass = "OpenCL::Image2DArray"; break;
837 case CL_GL_OBJECT_TEXTURE3D: klass = "OpenCL::Image3D"; break;
838 }
839 XPUSH_NEW_OBJ (klass, mem);
840
841#endif
842
843void
844gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
845 PPCODE:
846#if PREFER_1_1
847 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
848#else
849 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture , (self, flags, target, miplevel, texture, &res));
850#endif
851 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
852
853void
854gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
855 PPCODE:
856#if PREFER_1_1
857 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res));
858#else
859 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture , (self, flags, target, miplevel, texture, &res));
860#endif
861 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
746 862
747#endif 863#endif
748 864
749void 865void
750supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) 866supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type)
855 cl_event ev = 0; 971 cl_event ev = 0;
856 STRLEN len; 972 STRLEN len;
857 char *ptr = SvPVbyte (data, len); 973 char *ptr = SvPVbyte (data, len);
858 EVENT_LIST (5, items - 5); 974 EVENT_LIST (5, items - 5);
859 975
860 NEED_SUCCESS (EnqueueReadBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 976 NEED_SUCCESS (EnqueueWriteBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
861 977
862 if (ev) 978 if (ev)
863 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 979 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
864 980
865void 981void
931 size_t min_len = host_row_pitch * host_slice_pitch * region [2]; 1047 size_t min_len = host_row_pitch * host_slice_pitch * region [2];
932 1048
933 if (len < min_len) 1049 if (len < min_len)
934 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1050 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
935 1051
936 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)); 1052 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));
937 1053
938 if (ev) 1054 if (ev)
939 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1055 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
940 1056
941void 1057void
996 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height; 1112 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height;
997 1113
998 if (len < min_len) 1114 if (len < min_len)
999 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1115 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
1000 1116
1001 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)); 1117 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));
1002 1118
1003 if (ev) 1119 if (ev)
1004 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1120 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1005 1121
1006void 1122void
1088 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); 1204 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
1089 } 1205 }
1090 1206
1091 if (SvOK (local_work_size)) 1207 if (SvOK (local_work_size))
1092 { 1208 {
1093 if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV) 1209 if ((SvOK (local_work_size) && !SvROK (local_work_size)) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV)
1094 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference"); 1210 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference");
1095 1211
1096 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) 1212 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len)
1097 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size"); 1213 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
1098 1214
1110 1226
1111void 1227void
1112enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...) 1228enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...)
1113 ALIAS: 1229 ALIAS:
1114 enqueue_release_gl_objects = 1 1230 enqueue_release_gl_objects = 1
1115 CODE: 1231 PPCODE:
1116 if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV) 1232 if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV)
1117 croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call"); 1233 croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call");
1118 1234
1119 cl_event ev = 0; 1235 cl_event ev = 0;
1120 EVENT_LIST (2, items - 2); 1236 EVENT_LIST (2, items - 2);
1135 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1251 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1136 1252
1137#endif 1253#endif
1138 1254
1139void 1255void
1140enqueue_marker (OpenCL::Queue self)
1141 PPCODE:
1142 cl_event ev;
1143 NEED_SUCCESS (EnqueueMarker, (self, &ev));
1144 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1145
1146void
1147enqueue_wait_for_events (OpenCL::Queue self, ...) 1256enqueue_wait_for_events (OpenCL::Queue self, ...)
1148 CODE: 1257 CODE:
1149 EVENT_LIST (1, items - 1); 1258 EVENT_LIST (1, items - 1);
1259#if PREFER_1_1
1150 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); 1260 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr));
1261#else
1262 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, 0));
1263#endif
1151 1264
1152void 1265void
1266enqueue_marker (OpenCL::Queue self, ...)
1267 PPCODE:
1268 cl_event ev = 0;
1269 EVENT_LIST (1, items - 1);
1270#if PREFER_1_1
1271 if (!event_list_count)
1272 NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0));
1273 else
1274#if CL_VERSION_1_2
1275 NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1276#else
1277 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); // also a barrier
1278#endif
1279#else
1280 NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1281#endif
1282 if (ev)
1283 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1284
1285void
1153enqueue_barrier (OpenCL::Queue self) 1286enqueue_barrier (OpenCL::Queue self, ...)
1154 CODE: 1287 PPCODE:
1288 cl_event ev = 0;
1289 EVENT_LIST (1, items - 1);
1290#if PREFER_1_1
1291 if (!event_list_count && GIMME_V == G_VOID)
1155 NEED_SUCCESS (EnqueueBarrier, (self)); 1292 NEED_SUCCESS (EnqueueBarrier, (self));
1293 else
1294#if CL_VERSION_1_2
1295 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1296#else
1297 {
1298 if (event_list_count)
1299 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1300
1301 if (GIMME_V != G_VOID)
1302 NEED_SUCCESS (EnqueueMarker, (self, &ev));
1303 }
1304#endif
1305#else
1306 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1307#endif
1308 if (ev)
1309 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1156 1310
1157void 1311void
1158flush (OpenCL::Queue self) 1312flush (OpenCL::Queue self)
1159 CODE: 1313 CODE:
1160 NEED_SUCCESS (Flush, (self)); 1314 NEED_SUCCESS (Flush, (self));
1505 PPCODE: 1659 PPCODE:
1506 NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res)); 1660 NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res));
1507 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel); 1661 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel);
1508 1662
1509void 1663void
1664kernels_in_program (OpenCL::Program program)
1665 PPCODE:
1666 cl_uint num_kernels;
1667 NEED_SUCCESS (CreateKernelsInProgram, (program, 0, 0, &num_kernels));
1668 cl_kernel *kernels = tmpbuf (sizeof (cl_kernel) * num_kernels);
1669 NEED_SUCCESS (CreateKernelsInProgram, (program, num_kernels, kernels, 0));
1670
1671 int i;
1672 EXTEND (SP, num_kernels);
1673 for (i = 0; i < num_kernels; ++i)
1674 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Kernel", kernels [i]));
1675
1676void
1510info (OpenCL::Program self, cl_program_info name) 1677info (OpenCL::Program self, cl_program_info name)
1511 PPCODE: 1678 PPCODE:
1512 INFO (Program) 1679 INFO (Program)
1513 1680
1514void 1681void
1530 { 1697 {
1531 SV *sv = sv_2mortal (newSV (sizes [i])); 1698 SV *sv = sv_2mortal (newSV (sizes [i]));
1532 SvUPGRADE (sv, SVt_PV); 1699 SvUPGRADE (sv, SVt_PV);
1533 SvPOK_only (sv); 1700 SvPOK_only (sv);
1534 SvCUR_set (sv, sizes [i]); 1701 SvCUR_set (sv, sizes [i]);
1535 ptrs [i] = SvPVX (sv); 1702 ptrs [i] = (void *)SvPVX (sv);
1536 PUSHs (sv); 1703 PUSHs (sv);
1537 } 1704 }
1538 1705
1539 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size)); 1706 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size));
1540 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; 1707 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines