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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.36 by root, Sat Apr 21 17:56:21 2012 UTC vs.
Revision 1.41 by root, Sat Apr 21 19:53:29 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;
89 enum { buffers = 3 }; 104 enum { buffers = 3 };
90 static int idx; 105 static int idx;
91 static void *buf [buffers]; 106 static void *buf [buffers];
92 static size_t len [buffers]; 107 static size_t len [buffers];
93 108
94 idx = ++idx % buffers; 109 idx = (idx + 1) % buffers;
95 110
96 if (len [idx] < size) 111 if (len [idx] < size)
97 { 112 {
98 free (buf [idx]); 113 free (buf [idx]);
99 len [idx] = ((size + 31) & ~4095) + 4096 - 32; 114 len [idx] = ((size + 31) & ~4095) + 4096 - 32;
324} 339}
325 340
326cl_int 341cl_int
327errno () 342errno ()
328 CODE: 343 CODE:
329 errno = res; 344 RETVAL = res;
345 OUTPUT:
346 RETVAL
330 347
331const char * 348const char *
332err2str (cl_int err) 349err2str (cl_int err)
333 350
334const char * 351const char *
353context_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)
354 PPCODE: 371 PPCODE:
355 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));
356 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 373 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
357 374
375#if 0
376
358void 377void
359context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) 378context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0)
360 PPCODE: 379 PPCODE:
361 /* der Gipfel der Kunst */ 380 /* der Gipfel der Kunst */
381
382#endif
362 383
363void 384void
364wait_for_events (...) 385wait_for_events (...)
365 CODE: 386 CODE:
366 EVENT_LIST (0, items); 387 EVENT_LIST (0, items);
481 native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 502 native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT
482 native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 503 native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG
483 native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 504 native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT
484 native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 505 native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE
485 native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 506 native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF
486 reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT 507 reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT
487 PPCODE: 508 PPCODE:
488 cl_uint value [1]; 509 cl_uint value [1];
489 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0)); 510 NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0));
490 EXTEND (SP, 1); 511 EXTEND (SP, 1);
491 const int i = 0; 512 const int i = 0;
708 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)))
709 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?");
710 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));
711 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 732 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
712 733
734#if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS
735
713void 736void
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) 737image2d (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)
715 PPCODE: 738 PPCODE:
716 STRLEN len; 739 STRLEN len;
717 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 740 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
726 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 749 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
727 const cl_image_format format = { channel_order, channel_type }; 750 const cl_image_format format = { channel_order, channel_type };
728 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); 751 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
729 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 752 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
730 753
754#endif
755
731#if cl_apple_gl_sharing || cl_khr_gl_sharing 756#if cl_apple_gl_sharing || cl_khr_gl_sharing
732 757
733void 758void
734gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj) 759gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj)
735 PPCODE: 760 PPCODE:
736 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res)); 761 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res));
737 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 762 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
738 763
739void 764void
765gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer)
766 PPCODE:
767 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res));
768 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
769
770#if CL_VERSION_1_2
771
772void
773gl_texture (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
774 PPCODE:
775 char *klass = "OpenCL::Memory";
776 cl_gl_object_type t;
777 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
778 NEED_SUCCESS (GetGLObjectInfo, (mem, &t, 0));
779 switch (t)
780 {
781 case CL_GL_OBJECT_TEXTURE_BUFFER: klass = "OpenCL::Image1DBuffer"; break;
782 case CL_GL_OBJECT_TEXTURE1D: klass = "OpenCL::Image1D"; break;
783 case CL_GL_OBJECT_TEXTURE1D_ARRAY: klass = "OpenCL::Image2DArray"; break;
784 case CL_GL_OBJECT_TEXTURE2D: klass = "OpenCL::Image2D"; break;
785 case CL_GL_OBJECT_TEXTURE2D_ARRAY: klass = "OpenCL::Image2DArray"; break;
786 case CL_GL_OBJECT_TEXTURE3D: klass = "OpenCL::Image3D"; break;
787 }
788 XPUSH_NEW_OBJ (klass, mem);
789
790#endif
791
792#if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS
793
794void
740gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) 795gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
741 PPCODE: 796 PPCODE:
742 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res)); 797 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
743 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 798 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
744 799
746gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) 801gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
747 PPCODE: 802 PPCODE:
748 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res)); 803 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res));
749 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 804 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
750 805
751void 806#endif
752gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer)
753 PPCODE:
754 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res));
755 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
756 807
757#endif 808#endif
758 809
759void 810void
760supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) 811supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type)
941 size_t min_len = host_row_pitch * host_slice_pitch * region [2]; 992 size_t min_len = host_row_pitch * host_slice_pitch * region [2];
942 993
943 if (len < min_len) 994 if (len < min_len)
944 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 995 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
945 996
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)); 997 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 998
948 if (ev) 999 if (ev)
949 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1000 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
950 1001
951void 1002void
1006 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height; 1057 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height;
1007 1058
1008 if (len < min_len) 1059 if (len < min_len)
1009 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1060 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
1010 1061
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)); 1062 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 1063
1013 if (ev) 1064 if (ev)
1014 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1065 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1015 1066
1016void 1067void
1098 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); 1149 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
1099 } 1150 }
1100 1151
1101 if (SvOK (local_work_size)) 1152 if (SvOK (local_work_size))
1102 { 1153 {
1103 if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV) 1154 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"); 1155 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference");
1105 1156
1106 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) 1157 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"); 1158 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
1108 1159
1144 if (ev) 1195 if (ev)
1145 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1196 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1146 1197
1147#endif 1198#endif
1148 1199
1149void 1200#if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS
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 1201
1156void 1202void
1157enqueue_wait_for_events (OpenCL::Queue self, ...) 1203enqueue_wait_for_events (OpenCL::Queue self, ...)
1158 CODE: 1204 CODE:
1159 EVENT_LIST (1, items - 1); 1205 EVENT_LIST (1, items - 1);
1160 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); 1206 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr));
1161 1207
1208#endif
1209
1162void 1210void
1211enqueue_marker (OpenCL::Queue self, ...)
1212 PPCODE:
1213 cl_event ev = 0;
1214 EVENT_LIST (1, items - 1);
1215#if CL_VERSION_1_2
1216 NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1217#else
1218 if (event_list_count)
1219 croak ("OpenCL::Queue->enqueue_marker does not support a wait list in OpenCL 1.1 - upgrade to 1.2");
1220 NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0));
1221#endif
1222 if (ev)
1223 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1224
1225void
1163enqueue_barrier (OpenCL::Queue self) 1226enqueue_barrier (OpenCL::Queue self, ...)
1164 CODE: 1227 PPCODE:
1228 cl_event ev = 0;
1229 EVENT_LIST (1, items - 1);
1230#if CL_VERSION_1_2
1231 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, &ev));
1232#else
1233 if (event_list_count)
1234 croak ("OpenCL::Queue->enqueue_barrier does not support a wait list in OpenCL 1.1 - upgrade to 1.2");
1235 if (GIMME_V != G_VOID)
1236 croak ("OpenCL::Queue->enqueue_barrier does not return an event object in OpenCL 1.1 - upgrade to 1.2");
1165 NEED_SUCCESS (EnqueueBarrier, (self)); 1237 NEED_SUCCESS (EnqueueBarrier, (self));
1238#endif
1239 if (ev)
1240 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1166 1241
1167void 1242void
1168flush (OpenCL::Queue self) 1243flush (OpenCL::Queue self)
1169 CODE: 1244 CODE:
1170 NEED_SUCCESS (Flush, (self)); 1245 NEED_SUCCESS (Flush, (self));
1540 { 1615 {
1541 SV *sv = sv_2mortal (newSV (sizes [i])); 1616 SV *sv = sv_2mortal (newSV (sizes [i]));
1542 SvUPGRADE (sv, SVt_PV); 1617 SvUPGRADE (sv, SVt_PV);
1543 SvPOK_only (sv); 1618 SvPOK_only (sv);
1544 SvCUR_set (sv, sizes [i]); 1619 SvCUR_set (sv, sizes [i]);
1545 ptrs [i] = SvPVX (sv); 1620 ptrs [i] = (void *)SvPVX (sv);
1546 PUSHs (sv); 1621 PUSHs (sv);
1547 } 1622 }
1548 1623
1549 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size)); 1624 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size));
1550 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; 1625 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines