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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.35 by root, Sat Apr 21 17:47:23 2012 UTC vs.
Revision 1.49 by root, Tue Apr 24 14:30:57 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;
324} 346}
325 347
326cl_int 348cl_int
327errno () 349errno ()
328 CODE: 350 CODE:
329 errno = res; 351 RETVAL = res;
352 OUTPUT:
353 RETVAL
330 354
331const char * 355const char *
332err2str (cl_int err) 356err2str (cl_int err)
333 357
334const char * 358const char *
353context_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)
354 PPCODE: 378 PPCODE:
355 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));
356 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 380 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
357 381
382#if 0
383
358void 384void
359context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) 385context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0)
360 PPCODE: 386 PPCODE:
361 /* der Gipfel der Kunst */ 387 /* der Gipfel der Kunst */
388
389#endif
362 390
363void 391void
364wait_for_events (...) 392wait_for_events (...)
365 CODE: 393 CODE:
366 EVENT_LIST (0, items); 394 EVENT_LIST (0, items);
372 400
373void 401void
374info (OpenCL::Platform self, cl_platform_info name) 402info (OpenCL::Platform self, cl_platform_info name)
375 PPCODE: 403 PPCODE:
376 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
377 412
378#BEGIN:platform 413#BEGIN:platform
379 414
380void 415void
381profile (OpenCL::Platform self) 416profile (OpenCL::Platform self)
481 native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 516 native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT
482 native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 517 native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG
483 native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 518 native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT
484 native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 519 native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE
485 native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 520 native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF
486 reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT 521 reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT
487 PPCODE: 522 PPCODE:
488 cl_uint value [1]; 523 cl_uint value [1];
489 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0)); 524 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
490 EXTEND (SP, 1); 525 EXTEND (SP, 1);
491 const int i = 0; 526 const int i = 0;
708 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)))
709 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?");
710 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));
711 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 746 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
712 747
748#if CL_VERSION_1_2
749
713void 750void
714image2d (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)
715 PPCODE: 752 PPCODE:
716 STRLEN len; 753 STRLEN len;
717 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 754 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
718 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 };
719 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 }
720 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 774 XPUSH_NEW_OBJ (klass, mem);
721 775
776#endif
777
722void 778void
723image3d (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)
724 PPCODE: 780 PPCODE:
725 STRLEN len; 781 STRLEN len;
726 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 782 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
727 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
728 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
729 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 804 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
730 805
731#if cl_apple_gl_sharing || cl_khr_gl_sharing 806#if cl_apple_gl_sharing || cl_khr_gl_sharing
732 807
733void 808void
735 PPCODE: 810 PPCODE:
736 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res)); 811 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res));
737 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 812 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
738 813
739void 814void
740gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
741 PPCODE:
742 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
743 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
744
745void
746gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
747 PPCODE:
748 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res));
749 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
750
751void
752gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer) 815gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer)
753 PPCODE: 816 PPCODE:
754 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res)); 817 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res));
755 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);
756 862
757#endif 863#endif
758 864
759void 865void
760supported_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)
870 NEED_SUCCESS (EnqueueWriteBuffer, (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));
871 977
872 if (ev) 978 if (ev)
873 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 979 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
874 980
981#if CL_VERSION_1_2
982
983void
984enqueue_fill_buffer (OpenCL::Queue self, OpenCL::Buffer mem, SV *data, size_t offset, size_t size, ...)
985 PPCODE:
986 cl_event ev = 0;
987 STRLEN len;
988 char *ptr = SvPVbyte (data, len);
989 EVENT_LIST (5, items - 5);
990
991 NEED_SUCCESS (EnqueueFillBuffer, (self, mem, ptr, len, offset, size, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
992
993 if (ev)
994 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
995
996void
997enqueue_fill_image (OpenCL::Queue self, OpenCL::Image img, NV r, NV g, NV b, NV a, size_t x, size_t y, size_t z, size_t width, size_t height, size_t depth, ...)
998 PPCODE:
999 cl_event ev = 0;
1000 STRLEN len;
1001 const size_t origin [3] = { x, y, z };
1002 const size_t region [3] = { width, height, depth };
1003 EVENT_LIST (12, items - 12);
1004
1005 const cl_float c_f [4] = { r, g, b, a };
1006 const cl_uint c_u [4] = { r, g, b, a };
1007 const cl_int c_s [4] = { r, g, b, a };
1008 const void *c_fus [3] = { &c_f, &c_u, &c_s };
1009 static const char fus [] = { 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 1, 1, 1, 0, 0 };
1010 cl_image_format format;
1011 NEED_SUCCESS (clGetImageInfo, (img, CL_IMAGE_FORMAT, sizeof (format), &format, 0));
1012 assert (sizeof (fus) == CL_FLOAT + 1 - CL_SNORM_INT8);
1013 if (format.image_channel_data_type < CL_SNORM_INT8 || CL_FLOAT < format.image_channel_data_type)
1014 croak ("enqueue_fill_image: image has unsupported channel type, only opencl 1.2 channel types supported.");
1015
1016 NEED_SUCCESS (EnqueueFillImage, (self, img, c_fus [fus [format.image_channel_data_type]],
1017 origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1018
1019 if (ev)
1020 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1021
1022#endif
1023
875void 1024void
876enqueue_copy_buffer (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...) 1025enqueue_copy_buffer (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...)
877 PPCODE: 1026 PPCODE:
878 cl_event ev = 0; 1027 cl_event ev = 0;
879 EVENT_LIST (6, items - 6); 1028 EVENT_LIST (6, items - 6);
941 size_t min_len = host_row_pitch * host_slice_pitch * region [2]; 1090 size_t min_len = host_row_pitch * host_slice_pitch * region [2];
942 1091
943 if (len < min_len) 1092 if (len < min_len)
944 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1093 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
945 1094
946 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)); 1095 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));
947 1096
948 if (ev) 1097 if (ev)
949 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1098 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
950 1099
951void 1100void
1006 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height; 1155 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height;
1007 1156
1008 if (len < min_len) 1157 if (len < min_len)
1009 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1158 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
1010 1159
1011 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)); 1160 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));
1012 1161
1013 if (ev) 1162 if (ev)
1014 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1163 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1015 1164
1016void 1165void
1098 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); 1247 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
1099 } 1248 }
1100 1249
1101 if (SvOK (local_work_size)) 1250 if (SvOK (local_work_size))
1102 { 1251 {
1103 if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV) 1252 if ((SvOK (local_work_size) && !SvROK (local_work_size)) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV)
1104 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference"); 1253 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference");
1105 1254
1106 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) 1255 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len)
1107 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size"); 1256 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
1108 1257
1120 1269
1121void 1270void
1122enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...) 1271enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...)
1123 ALIAS: 1272 ALIAS:
1124 enqueue_release_gl_objects = 1 1273 enqueue_release_gl_objects = 1
1125 CODE: 1274 PPCODE:
1126 if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV) 1275 if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV)
1127 croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call"); 1276 croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call");
1128 1277
1129 cl_event ev = 0; 1278 cl_event ev = 0;
1130 EVENT_LIST (2, items - 2); 1279 EVENT_LIST (2, items - 2);
1145 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1294 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1146 1295
1147#endif 1296#endif
1148 1297
1149void 1298void
1150enqueue_marker (OpenCL::Queue self)
1151 PPCODE:
1152 cl_event ev;
1153 NEED_SUCCESS (EnqueueMarker, (self, &ev));
1154 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1155
1156void
1157enqueue_wait_for_events (OpenCL::Queue self, ...) 1299enqueue_wait_for_events (OpenCL::Queue self, ...)
1158 CODE: 1300 CODE:
1159 EVENT_LIST (1, items - 1); 1301 EVENT_LIST (1, items - 1);
1302#if PREFER_1_1
1160 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); 1303 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr));
1304#else
1305 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, 0));
1306#endif
1161 1307
1162void 1308void
1309enqueue_marker (OpenCL::Queue self, ...)
1310 PPCODE:
1311 cl_event ev = 0;
1312 EVENT_LIST (1, items - 1);
1313#if PREFER_1_1
1314 if (!event_list_count)
1315 NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0));
1316 else
1317#if CL_VERSION_1_2
1318 NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1319#else
1320 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); // also a barrier
1321#endif
1322#else
1323 NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1324#endif
1325 if (ev)
1326 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1327
1328void
1163enqueue_barrier (OpenCL::Queue self) 1329enqueue_barrier (OpenCL::Queue self, ...)
1164 CODE: 1330 PPCODE:
1331 cl_event ev = 0;
1332 EVENT_LIST (1, items - 1);
1333#if PREFER_1_1
1334 if (!event_list_count && GIMME_V == G_VOID)
1165 NEED_SUCCESS (EnqueueBarrier, (self)); 1335 NEED_SUCCESS (EnqueueBarrier, (self));
1336 else
1337#if CL_VERSION_1_2
1338 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1339#else
1340 {
1341 if (event_list_count)
1342 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1343
1344 if (GIMME_V != G_VOID)
1345 NEED_SUCCESS (EnqueueMarker, (self, &ev));
1346 }
1347#endif
1348#else
1349 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1350#endif
1351 if (ev)
1352 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1166 1353
1167void 1354void
1168flush (OpenCL::Queue self) 1355flush (OpenCL::Queue self)
1169 CODE: 1356 CODE:
1170 NEED_SUCCESS (Flush, (self)); 1357 NEED_SUCCESS (Flush, (self));
1347void 1534void
1348image_info (OpenCL::Image self, cl_image_info name) 1535image_info (OpenCL::Image self, cl_image_info name)
1349 PPCODE: 1536 PPCODE:
1350 INFO (Image) 1537 INFO (Image)
1351 1538
1539void
1540format (OpenCL::Image self)
1541 PPCODE:
1542 cl_image_format format;
1543 NEED_SUCCESS (GetImageInfo, (self, CL_IMAGE_FORMAT, sizeof (format), &format, 0));
1544 EXTEND (SP, 2);
1545 PUSHs (sv_2mortal (newSVuv (format.image_channel_order)));
1546 PUSHs (sv_2mortal (newSVuv (format.image_channel_data_type)));
1547
1352#BEGIN:image 1548#BEGIN:image
1353 1549
1354void 1550void
1355element_size (OpenCL::Image self) 1551element_size (OpenCL::Image self)
1356 ALIAS: 1552 ALIAS:
1515 PPCODE: 1711 PPCODE:
1516 NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res)); 1712 NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res));
1517 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel); 1713 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel);
1518 1714
1519void 1715void
1716kernels_in_program (OpenCL::Program program)
1717 PPCODE:
1718 cl_uint num_kernels;
1719 NEED_SUCCESS (CreateKernelsInProgram, (program, 0, 0, &num_kernels));
1720 cl_kernel *kernels = tmpbuf (sizeof (cl_kernel) * num_kernels);
1721 NEED_SUCCESS (CreateKernelsInProgram, (program, num_kernels, kernels, 0));
1722
1723 int i;
1724 EXTEND (SP, num_kernels);
1725 for (i = 0; i < num_kernels; ++i)
1726 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Kernel", kernels [i]));
1727
1728void
1520info (OpenCL::Program self, cl_program_info name) 1729info (OpenCL::Program self, cl_program_info name)
1521 PPCODE: 1730 PPCODE:
1522 INFO (Program) 1731 INFO (Program)
1523 1732
1524void 1733void
1540 { 1749 {
1541 SV *sv = sv_2mortal (newSV (sizes [i])); 1750 SV *sv = sv_2mortal (newSV (sizes [i]));
1542 SvUPGRADE (sv, SVt_PV); 1751 SvUPGRADE (sv, SVt_PV);
1543 SvPOK_only (sv); 1752 SvPOK_only (sv);
1544 SvCUR_set (sv, sizes [i]); 1753 SvCUR_set (sv, sizes [i]);
1545 ptrs [i] = SvPVX (sv); 1754 ptrs [i] = (void *)SvPVX (sv);
1546 PUSHs (sv); 1755 PUSHs (sv);
1547 } 1756 }
1548 1757
1549 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size)); 1758 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size));
1550 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; 1759 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines