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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.24 by root, Thu Apr 19 12:12:04 2012 UTC vs.
Revision 1.29 by root, Thu Apr 19 13:51:36 2012 UTC

4 4
5#ifdef __APPLE__ 5#ifdef __APPLE__
6 #include <OpenCL/opencl.h> 6 #include <OpenCL/opencl.h>
7#else 7#else
8 #include <CL/opencl.h> 8 #include <CL/opencl.h>
9#endif
10#if HAVE_OPENGL
11 #ifdef __APPLE__
12 #include <OpenGL/gl.h>
13 #include <OpenCL/cl_gl.h>
14 #else
15 #include <GL/gl.h>
16 #include <CL/cl_gl.h>
17 #endif
18#endif 9#endif
19 10
20typedef cl_platform_id OpenCL__Platform; 11typedef cl_platform_id OpenCL__Platform;
21typedef cl_device_id OpenCL__Device; 12typedef cl_device_id OpenCL__Device;
22typedef cl_context OpenCL__Context; 13typedef cl_context OpenCL__Context;
153 return 0; 144 return 0;
154 145
155 if (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVAV) 146 if (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVAV)
156 { 147 {
157 AV *av = (AV *)SvRV (sv); 148 AV *av = (AV *)SvRV (sv);
158 int i, len = av_len (av); 149 int i, len = av_len (av) + 1;
159 cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1)); 150 cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1));
160 cl_context_properties *l = p; 151 cl_context_properties *l = p;
161 152
162 if (len & 1) 153 if (len & 1)
163 croak ("%s: %s is not a property list (must be even number of elements)", func, svname); 154 croak ("%s: %s is not a property list (must be even number of elements)", func, svname);
165 while (extracount--) 156 while (extracount--)
166 *l++ = *extra++; 157 *l++ = *extra++;
167 158
168 for (i = 0; i < len; i += 2) 159 for (i = 0; i < len; i += 2)
169 { 160 {
170 cl_context_properties t = SvIV (*av_fetch (av, i, 0)); 161 cl_context_properties t = SvIV (*av_fetch (av, i , 0));
162 SV *p_sv = *av_fetch (av, i + 1, 0);
171 cl_context_properties v; 163 cl_context_properties v;
172 164
173 switch (t) 165 switch (t)
174 { 166 {
175 default: 167 default:
176 /* unknown property, treat as int */ 168 /* unknown property, treat as int */
177 v = SvIV (*av_fetch (av, i, 0)); 169 v = SvIV (p_sv);
178 break; 170 break;
179 } 171 }
180 172
181 *l++ = t; 173 *l++ = t;
182 *l++ = v; 174 *l++ = v;
247 { sizeof (cl_long ), "SIZEOF_LONG" }, 239 { sizeof (cl_long ), "SIZEOF_LONG" },
248 { sizeof (cl_ulong ), "SIZEOF_ULONG" }, 240 { sizeof (cl_ulong ), "SIZEOF_ULONG" },
249 { sizeof (cl_half ), "SIZEOF_HALF" }, 241 { sizeof (cl_half ), "SIZEOF_HALF" },
250 { sizeof (cl_float ), "SIZEOF_FLOAT" }, 242 { sizeof (cl_float ), "SIZEOF_FLOAT" },
251 { sizeof (cl_double), "SIZEOF_DOUBLE" }, 243 { sizeof (cl_double), "SIZEOF_DOUBLE" },
252 { HAVE_OPENGL , "HAVE_OPENGL" },
253#include "constiv.h" 244#include "constiv.h"
254 }; 245 };
255 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 246 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
256 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 247 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
257} 248}
346 337
347void 338void
348context (OpenCL::Platform self, cl_context_properties *properties = 0, SV *devices, FUTURE notify = 0) 339context (OpenCL::Platform self, cl_context_properties *properties = 0, SV *devices, FUTURE notify = 0)
349 PPCODE: 340 PPCODE:
350 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) 341 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV)
351 croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call"); 342 croak ("OpenCL::Platform::context argument 'device' must be an arrayref with device objects, in call");
352 343
353 AV *av = (AV *)SvRV (devices); 344 AV *av = (AV *)SvRV (devices);
354 cl_uint num_devices = av_len (av) + 1; 345 cl_uint num_devices = av_len (av) + 1;
355 cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); 346 cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices);
356 int i; 347 int i;
626 617
627void 618void
628buffer (OpenCL::Context self, cl_mem_flags flags, size_t len) 619buffer (OpenCL::Context self, cl_mem_flags flags, size_t len)
629 PPCODE: 620 PPCODE:
630 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) 621 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
631 croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); 622 croak ("OpenCL::Context::buffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?");
632 623
633 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res)); 624 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res));
634 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 625 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
635 626
636void 627void
637buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data) 628buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data)
638 PPCODE: 629 PPCODE:
639 STRLEN len; 630 STRLEN len;
640 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 631 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
641 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) 632 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
642 croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); 633 croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
643 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res)); 634 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res));
644 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 635 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
645 636
646void 637void
647image2d (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) 638image2d (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)
658 STRLEN len; 649 STRLEN len;
659 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 650 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
660 const cl_image_format format = { channel_order, channel_type }; 651 const cl_image_format format = { channel_order, channel_type };
661 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); 652 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
662 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 653 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
654
655#if cl_apple_gl_sharing || cl_khr_gl_sharing
656
657void
658gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj)
659 PPCODE:
660 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res));
661 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
662
663void
664gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
665 PPCODE:
666 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
667 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
668
669void
670gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
671 PPCODE:
672 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res));
673 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
674
675void
676gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer)
677 PPCODE:
678 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res));
679 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
680
681#endif
663 682
664void 683void
665supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) 684supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type)
666 PPCODE: 685 PPCODE:
667{ 686{
1019 NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1038 NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1020 1039
1021 if (ev) 1040 if (ev)
1022 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1041 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1023 1042
1043#if cl_apple_gl_sharing || cl_khr_gl_sharing
1044
1045void
1046enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...)
1047 ALIAS:
1048 enqueue_release_gl_objects = 1
1049 CODE:
1050 if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV)
1051 croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call");
1052
1053 cl_event ev = 0;
1054 EVENT_LIST (2, items - 2);
1055 AV *av = (AV *)SvRV (objects);
1056 cl_uint num_objects = av_len (av) + 1;
1057 cl_mem *object_list = tmpbuf (sizeof (cl_mem) * num_objects);
1058 int i;
1059
1060 for (i = num_objects; i--; )
1061 object_list [i] = SvPTROBJ ("OpenCL::Queue::enqueue_acquire/release_gl_objects", "objects", *av_fetch (av, i, 0), "OpenCL::Memory");
1062
1063 if (ix)
1064 NEED_SUCCESS (EnqueueReleaseGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1065 else
1066 NEED_SUCCESS (EnqueueAcquireGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1067
1068 if (ev)
1069 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1070
1071#endif
1072
1024void 1073void
1025enqueue_marker (OpenCL::Queue self) 1074enqueue_marker (OpenCL::Queue self)
1026 PPCODE: 1075 PPCODE:
1027 cl_event ev; 1076 cl_event ev;
1028 NEED_SUCCESS (EnqueueMarker, (self, &ev)); 1077 NEED_SUCCESS (EnqueueMarker, (self, &ev));
1187 NEED_SUCCESS (RetainMemObject, (value [i])); 1236 NEED_SUCCESS (RetainMemObject, (value [i]));
1188 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i])); 1237 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i]));
1189 } 1238 }
1190 1239
1191#END:mem 1240#END:mem
1241
1242#if cl_apple_gl_sharing || cl_khr_gl_sharing
1243
1244void
1245gl_object_info (OpenCL::Memory self)
1246 PPCODE:
1247 cl_gl_object_type type;
1248 cl_GLuint name;
1249 NEED_SUCCESS (clGetGLObjectInfo, (self, &type, &name));
1250 EXTEND (SP, 2);
1251 PUSHs (sv_2mortal (newSVuv (type)));
1252 PUSHs (sv_2mortal (newSVuv (name)));
1253
1254#endif
1192 1255
1193MODULE = OpenCL PACKAGE = OpenCL::BufferObj 1256MODULE = OpenCL PACKAGE = OpenCL::BufferObj
1194 1257
1195void 1258void
1196sub_buffer_region (OpenCL::BufferObj self, cl_mem_flags flags, size_t origin, size_t size) 1259sub_buffer_region (OpenCL::BufferObj self, cl_mem_flags flags, size_t origin, size_t size)
1227 EXTEND (SP, 1); 1290 EXTEND (SP, 1);
1228 const int i = 0; 1291 const int i = 0;
1229 PUSHs (sv_2mortal (newSVuv (value [i]))); 1292 PUSHs (sv_2mortal (newSVuv (value [i])));
1230 1293
1231#END:image 1294#END:image
1295
1296#if cl_apple_gl_sharing || cl_khr_gl_sharing
1297
1298#BEGIN:gl_texture
1299
1300void
1301target (OpenCL::Image self)
1302 PPCODE:
1303 cl_GLenum value [1];
1304 NEED_SUCCESS (GetGlTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0));
1305 EXTEND (SP, 1);
1306 const int i = 0;
1307 PUSHs (sv_2mortal (newSVuv (value [i])));
1308
1309void
1310gl_mipmap_level (OpenCL::Image self)
1311 PPCODE:
1312 cl_GLint value [1];
1313 NEED_SUCCESS (GetGlTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0));
1314 EXTEND (SP, 1);
1315 const int i = 0;
1316 PUSHs (sv_2mortal (newSViv (value [i])));
1317
1318#END:gl_texture
1319
1320#endif
1232 1321
1233MODULE = OpenCL PACKAGE = OpenCL::Sampler 1322MODULE = OpenCL PACKAGE = OpenCL::Sampler
1234 1323
1235void 1324void
1236DESTROY (OpenCL::Sampler self) 1325DESTROY (OpenCL::Sampler self)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines