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.37 by root, Sat Apr 21 18:49:21 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>
89 enum { buffers = 3 }; 99 enum { buffers = 3 };
90 static int idx; 100 static int idx;
91 static void *buf [buffers]; 101 static void *buf [buffers];
92 static size_t len [buffers]; 102 static size_t len [buffers];
93 103
94 idx = ++idx % buffers; 104 idx = (idx + 1) % buffers;
95 105
96 if (len [idx] < size) 106 if (len [idx] < size)
97 { 107 {
98 free (buf [idx]); 108 free (buf [idx]);
99 len [idx] = ((size + 31) & ~4095) + 4096 - 32; 109 len [idx] = ((size + 31) & ~4095) + 4096 - 32;
324} 334}
325 335
326cl_int 336cl_int
327errno () 337errno ()
328 CODE: 338 CODE:
329 errno = res; 339 RETVAL = res;
340 OUTPUT:
341 RETVAL
330 342
331const char * 343const char *
332err2str (cl_int err) 344err2str (cl_int err)
333 345
334const char * 346const char *
353context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) 365context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
354 PPCODE: 366 PPCODE:
355 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res)); 367 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res));
356 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 368 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
357 369
370#if 0
371
358void 372void
359context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) 373context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0)
360 PPCODE: 374 PPCODE:
361 /* der Gipfel der Kunst */ 375 /* der Gipfel der Kunst */
376
377#endif
362 378
363void 379void
364wait_for_events (...) 380wait_for_events (...)
365 CODE: 381 CODE:
366 EVENT_LIST (0, items); 382 EVENT_LIST (0, items);
708 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) 724 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?"); 725 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)); 726 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res));
711 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 727 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
712 728
729#if !defined CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS
730
713void 731void
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) 732image2d (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: 733 PPCODE:
716 STRLEN len; 734 STRLEN len;
717 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 735 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
726 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 744 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
727 const cl_image_format format = { channel_order, channel_type }; 745 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)); 746 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); 747 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
730 748
749#endif
750
731#if cl_apple_gl_sharing || cl_khr_gl_sharing 751#if cl_apple_gl_sharing || cl_khr_gl_sharing
732 752
733void 753void
734gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj) 754gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj)
735 PPCODE: 755 PPCODE:
736 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res)); 756 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res));
737 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 757 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
738 758
759#if !defined CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS
760
739void 761void
740gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) 762gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
741 PPCODE: 763 PPCODE:
742 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res)); 764 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
743 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 765 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
745void 767void
746gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) 768gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
747 PPCODE: 769 PPCODE:
748 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res)); 770 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res));
749 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 771 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
772
773#endif
750 774
751void 775void
752gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer) 776gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer)
753 PPCODE: 777 PPCODE:
754 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res)); 778 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res));
941 size_t min_len = host_row_pitch * host_slice_pitch * region [2]; 965 size_t min_len = host_row_pitch * host_slice_pitch * region [2];
942 966
943 if (len < min_len) 967 if (len < min_len)
944 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 968 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
945 969
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)); 970 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 971
948 if (ev) 972 if (ev)
949 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 973 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
950 974
951void 975void
1006 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height; 1030 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height;
1007 1031
1008 if (len < min_len) 1032 if (len < min_len)
1009 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1033 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
1010 1034
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)); 1035 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 1036
1013 if (ev) 1037 if (ev)
1014 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1038 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1015 1039
1016void 1040void
1098 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); 1122 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
1099 } 1123 }
1100 1124
1101 if (SvOK (local_work_size)) 1125 if (SvOK (local_work_size))
1102 { 1126 {
1103 if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV) 1127 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"); 1128 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference");
1105 1129
1106 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) 1130 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"); 1131 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
1108 1132
1144 if (ev) 1168 if (ev)
1145 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1169 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1146 1170
1147#endif 1171#endif
1148 1172
1173#if !defined CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS
1174
1149void 1175void
1150enqueue_marker (OpenCL::Queue self) 1176enqueue_marker (OpenCL::Queue self)
1151 PPCODE: 1177 PPCODE:
1152 cl_event ev; 1178 cl_event ev;
1153 NEED_SUCCESS (EnqueueMarker, (self, &ev)); 1179 NEED_SUCCESS (EnqueueMarker, (self, &ev));
1161 1187
1162void 1188void
1163enqueue_barrier (OpenCL::Queue self) 1189enqueue_barrier (OpenCL::Queue self)
1164 CODE: 1190 CODE:
1165 NEED_SUCCESS (EnqueueBarrier, (self)); 1191 NEED_SUCCESS (EnqueueBarrier, (self));
1192
1193#endif
1166 1194
1167void 1195void
1168flush (OpenCL::Queue self) 1196flush (OpenCL::Queue self)
1169 CODE: 1197 CODE:
1170 NEED_SUCCESS (Flush, (self)); 1198 NEED_SUCCESS (Flush, (self));
1540 { 1568 {
1541 SV *sv = sv_2mortal (newSV (sizes [i])); 1569 SV *sv = sv_2mortal (newSV (sizes [i]));
1542 SvUPGRADE (sv, SVt_PV); 1570 SvUPGRADE (sv, SVt_PV);
1543 SvPOK_only (sv); 1571 SvPOK_only (sv);
1544 SvCUR_set (sv, sizes [i]); 1572 SvCUR_set (sv, sizes [i]);
1545 ptrs [i] = SvPVX (sv); 1573 ptrs [i] = (void *)SvPVX (sv);
1546 PUSHs (sv); 1574 PUSHs (sv);
1547 } 1575 }
1548 1576
1549 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size)); 1577 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size));
1550 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; 1578 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines