1 | #include "EXTERN.h" |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
3 | #include "XSUB.h" |
|
|
4 | |
|
|
5 | #ifdef I_DLFCN |
|
|
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_1_APIS |
|
|
17 | #define CL_USE_DEPRECATED_OPENCL_1_2_APIS /* just guessing, you stupid idiots */ |
4 | |
18 | |
5 | #ifdef __APPLE__ |
19 | #ifdef __APPLE__ |
6 | #include <OpenCL/opencl.h> |
20 | #include <OpenCL/opencl.h> |
7 | #else |
21 | #else |
8 | #include <CL/opencl.h> |
22 | #include <CL/opencl.h> |
9 | #endif |
23 | #endif |
10 | #if HAVE_OPENGL |
24 | |
11 | #ifdef __APPLE__ |
25 | #if 0 // testing |
12 | #include <OpenGL/gl.h> |
26 | #undef CL_USE_DEPRECATED_OPENCL_1_1_APIS |
13 | #include <OpenCL/cl_gl.h> |
27 | #undef CL_VERSION_1_2 |
14 | #else |
|
|
15 | #include <GL/gl.h> |
|
|
16 | #include <CL/cl_gl.h> |
|
|
17 | #endif |
|
|
18 | #endif |
28 | #endif |
19 | |
29 | |
20 | typedef cl_platform_id OpenCL__Platform; |
30 | typedef cl_platform_id OpenCL__Platform; |
21 | typedef cl_device_id OpenCL__Device; |
31 | typedef cl_device_id OpenCL__Device; |
22 | typedef cl_context OpenCL__Context; |
32 | typedef cl_context OpenCL__Context; |
… | |
… | |
40 | |
50 | |
41 | typedef SV *FUTURE; |
51 | typedef SV *FUTURE; |
42 | |
52 | |
43 | /*****************************************************************************/ |
53 | /*****************************************************************************/ |
44 | |
54 | |
|
|
55 | // name must include a leading underscore |
|
|
56 | // all of this horrors would be unneceesary if somebody wrote a proper OpenGL module |
|
|
57 | // for perl. doh. |
|
|
58 | static void * |
|
|
59 | glsym (const char *name) |
|
|
60 | { |
|
|
61 | void *fun = 0; |
|
|
62 | |
|
|
63 | #if defined I_DLFCN && defined RTLD_DEFAULT |
|
|
64 | fun = dlsym (RTLD_DEFAULT, name + 1); |
|
|
65 | if (!fun) fun = dlsym (RTLD_DEFAULT, name); |
|
|
66 | |
|
|
67 | if (!fun) |
|
|
68 | { |
|
|
69 | static void *libgl; |
|
|
70 | static const char *glso[] = { |
|
|
71 | "libGL.so.1", |
|
|
72 | "libGL.so.3", |
|
|
73 | "libGL.so.4.0", |
|
|
74 | "libGL.so", |
|
|
75 | "/usr/lib/libGL.so", |
|
|
76 | "/usr/X11R6/lib/libGL.1.dylib" |
|
|
77 | }; |
|
|
78 | int i; |
|
|
79 | |
|
|
80 | for (i = 0; !libgl && i < sizeof (glso) / sizeof (glso [0]); ++i) |
|
|
81 | { |
|
|
82 | libgl = dlopen (glso [i], RTLD_LAZY); |
|
|
83 | if (libgl) |
|
|
84 | break; |
|
|
85 | } |
|
|
86 | |
|
|
87 | if (libgl) |
|
|
88 | { |
|
|
89 | fun = dlsym (libgl, name + 1); |
|
|
90 | if (!fun) fun = dlsym (libgl, name); |
|
|
91 | } |
|
|
92 | } |
|
|
93 | #endif |
|
|
94 | |
|
|
95 | return fun; |
|
|
96 | } |
|
|
97 | |
|
|
98 | /*****************************************************************************/ |
|
|
99 | |
45 | /* up to two temporary buffers */ |
100 | /* up to two temporary buffers */ |
46 | static void * |
101 | static void * |
47 | tmpbuf (size_t size) |
102 | tmpbuf (size_t size) |
48 | { |
103 | { |
49 | enum { buffers = 3 }; |
104 | enum { buffers = 3 }; |
50 | static int idx; |
105 | static int idx; |
51 | static void *buf [buffers]; |
106 | static void *buf [buffers]; |
52 | static size_t len [buffers]; |
107 | static size_t len [buffers]; |
53 | |
108 | |
54 | idx = ++idx % buffers; |
109 | idx = (idx + 1) % buffers; |
55 | |
110 | |
56 | if (len [idx] < size) |
111 | if (len [idx] < size) |
57 | { |
112 | { |
58 | free (buf [idx]); |
113 | free (buf [idx]); |
59 | len [idx] = ((size + 31) & ~4095) + 4096 - 32; |
114 | len [idx] = ((size + 31) & ~4095) + 4096 - 32; |
… | |
… | |
153 | return 0; |
208 | return 0; |
154 | |
209 | |
155 | if (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVAV) |
210 | if (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVAV) |
156 | { |
211 | { |
157 | AV *av = (AV *)SvRV (sv); |
212 | AV *av = (AV *)SvRV (sv); |
158 | int i, len = av_len (av); |
213 | int i, len = av_len (av) + 1; |
159 | cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1)); |
214 | cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1)); |
160 | cl_context_properties *l = p; |
215 | cl_context_properties *l = p; |
161 | |
216 | |
162 | if (len & 1) |
217 | if (len & 1) |
163 | croak ("%s: %s is not a property list (must be even number of elements)", func, svname); |
218 | croak ("%s: %s is not a property list (must be even number of elements)", func, svname); |
… | |
… | |
165 | while (extracount--) |
220 | while (extracount--) |
166 | *l++ = *extra++; |
221 | *l++ = *extra++; |
167 | |
222 | |
168 | for (i = 0; i < len; i += 2) |
223 | for (i = 0; i < len; i += 2) |
169 | { |
224 | { |
170 | cl_context_properties t = SvIV (*av_fetch (av, i, 0)); |
225 | cl_context_properties t = SvIV (*av_fetch (av, i , 0)); |
171 | cl_context_properties v; |
226 | SV *p_sv = *av_fetch (av, i + 1, 0); |
|
|
227 | cl_context_properties v = SvIV (p_sv); // code below can override |
172 | |
228 | |
173 | switch (t) |
229 | switch (t) |
174 | { |
230 | { |
|
|
231 | case CL_GLX_DISPLAY_KHR: |
|
|
232 | if (!SvOK (p_sv)) |
|
|
233 | { |
|
|
234 | void *func = glsym ("_glXGetCurrentDisplay"); |
|
|
235 | if (func) |
|
|
236 | v = (cl_context_properties)((void *(*)(void))func)(); |
|
|
237 | } |
|
|
238 | break; |
|
|
239 | |
|
|
240 | case CL_GL_CONTEXT_KHR: |
|
|
241 | if (!SvOK (p_sv)) |
|
|
242 | { |
|
|
243 | void *func = glsym ("_glXGetCurrentContext"); |
|
|
244 | if (func) |
|
|
245 | v = (cl_context_properties)((void *(*)(void))func)(); |
|
|
246 | } |
|
|
247 | break; |
|
|
248 | |
175 | default: |
249 | default: |
176 | /* unknown property, treat as int */ |
250 | /* unknown property, treat as int */ |
177 | v = SvIV (*av_fetch (av, i, 0)); |
|
|
178 | break; |
251 | break; |
179 | } |
252 | } |
180 | |
253 | |
181 | *l++ = t; |
254 | *l++ = t; |
182 | *l++ = v; |
255 | *l++ = v; |
… | |
… | |
199 | clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); |
272 | clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); |
200 | return res; |
273 | return res; |
201 | } |
274 | } |
202 | |
275 | |
203 | static cl_event * |
276 | static cl_event * |
204 | event_list (SV **items, int count) |
277 | event_list (SV **items, cl_uint *rcount) |
205 | { |
278 | { |
|
|
279 | cl_uint count = *rcount; |
|
|
280 | |
206 | if (!count) |
281 | if (!count) |
207 | return 0; |
282 | return 0; |
208 | |
283 | |
209 | cl_event *list = tmpbuf (sizeof (cl_event) * count); |
284 | cl_event *list = tmpbuf (sizeof (cl_event) * count); |
|
|
285 | int i = 0; |
210 | |
286 | |
211 | while (count--) |
287 | do |
|
|
288 | { |
|
|
289 | --count; |
|
|
290 | if (SvOK (items [count])) |
212 | list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); |
291 | list [i++] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); |
|
|
292 | } |
|
|
293 | while (count); |
213 | |
294 | |
|
|
295 | *rcount = i; |
|
|
296 | |
214 | return list; |
297 | return i ? list : 0; |
215 | } |
298 | } |
216 | |
299 | |
217 | #define EVENT_LIST(items,count) \ |
300 | #define EVENT_LIST(items,count) \ |
218 | cl_uint event_list_count = (count); \ |
301 | cl_uint event_list_count = (count); \ |
219 | cl_event *event_list_ptr = event_list (&ST (items), event_list_count) |
302 | cl_event *event_list_ptr = event_list (&ST (items), &event_list_count) |
220 | |
303 | |
221 | #define INFO(class) \ |
304 | #define INFO(class) \ |
222 | { \ |
305 | { \ |
223 | size_t size; \ |
306 | size_t size; \ |
224 | NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ |
307 | NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ |
… | |
… | |
247 | { sizeof (cl_long ), "SIZEOF_LONG" }, |
330 | { sizeof (cl_long ), "SIZEOF_LONG" }, |
248 | { sizeof (cl_ulong ), "SIZEOF_ULONG" }, |
331 | { sizeof (cl_ulong ), "SIZEOF_ULONG" }, |
249 | { sizeof (cl_half ), "SIZEOF_HALF" }, |
332 | { sizeof (cl_half ), "SIZEOF_HALF" }, |
250 | { sizeof (cl_float ), "SIZEOF_FLOAT" }, |
333 | { sizeof (cl_float ), "SIZEOF_FLOAT" }, |
251 | { sizeof (cl_double), "SIZEOF_DOUBLE" }, |
334 | { sizeof (cl_double), "SIZEOF_DOUBLE" }, |
252 | { HAVE_OPENGL , "HAVE_OPENGL" }, |
|
|
253 | #include "constiv.h" |
335 | #include "constiv.h" |
254 | }; |
336 | }; |
255 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
337 | 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)); |
338 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
257 | } |
339 | } |
258 | |
340 | |
259 | cl_int |
341 | cl_int |
260 | errno () |
342 | errno () |
261 | CODE: |
343 | CODE: |
262 | errno = res; |
344 | RETVAL = res; |
|
|
345 | OUTPUT: |
|
|
346 | RETVAL |
263 | |
347 | |
264 | const char * |
348 | const char * |
265 | err2str (cl_int err) |
349 | err2str (cl_int err) |
266 | |
350 | |
267 | const char * |
351 | const char * |
… | |
… | |
286 | context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
370 | context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
287 | PPCODE: |
371 | PPCODE: |
288 | 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)); |
289 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
373 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
290 | |
374 | |
|
|
375 | #if 0 |
|
|
376 | |
291 | void |
377 | void |
292 | context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) |
378 | context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) |
293 | PPCODE: |
379 | PPCODE: |
294 | /* der Gipfel der Kunst */ |
380 | /* der Gipfel der Kunst */ |
|
|
381 | |
|
|
382 | #endif |
295 | |
383 | |
296 | void |
384 | void |
297 | wait_for_events (...) |
385 | wait_for_events (...) |
298 | CODE: |
386 | CODE: |
299 | EVENT_LIST (0, items); |
387 | EVENT_LIST (0, items); |
… | |
… | |
346 | |
434 | |
347 | void |
435 | void |
348 | context (OpenCL::Platform self, cl_context_properties *properties = 0, SV *devices, FUTURE notify = 0) |
436 | context (OpenCL::Platform self, cl_context_properties *properties = 0, SV *devices, FUTURE notify = 0) |
349 | PPCODE: |
437 | PPCODE: |
350 | if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) |
438 | if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) |
351 | croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call"); |
439 | croak ("OpenCL::Platform::context argument 'device' must be an arrayref with device objects, in call"); |
352 | |
440 | |
353 | AV *av = (AV *)SvRV (devices); |
441 | AV *av = (AV *)SvRV (devices); |
354 | cl_uint num_devices = av_len (av) + 1; |
442 | cl_uint num_devices = av_len (av) + 1; |
355 | cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); |
443 | cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); |
356 | int i; |
444 | int i; |
… | |
… | |
626 | |
714 | |
627 | void |
715 | void |
628 | buffer (OpenCL::Context self, cl_mem_flags flags, size_t len) |
716 | buffer (OpenCL::Context self, cl_mem_flags flags, size_t len) |
629 | PPCODE: |
717 | PPCODE: |
630 | if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) |
718 | 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?"); |
719 | croak ("OpenCL::Context::buffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); |
632 | |
720 | |
633 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res)); |
721 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res)); |
634 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
722 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
635 | |
723 | |
636 | void |
724 | void |
637 | buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data) |
725 | buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data) |
638 | PPCODE: |
726 | PPCODE: |
639 | STRLEN len; |
727 | STRLEN len; |
640 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
728 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
641 | 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))) |
642 | croak ("clCreateBuffer: 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?"); |
643 | 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)); |
644 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
732 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
|
|
733 | |
|
|
734 | #if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS |
645 | |
735 | |
646 | void |
736 | void |
647 | image2d (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) |
737 | image2d (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) |
648 | PPCODE: |
738 | PPCODE: |
649 | STRLEN len; |
739 | STRLEN len; |
… | |
… | |
658 | STRLEN len; |
748 | STRLEN len; |
659 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
749 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
660 | const cl_image_format format = { channel_order, channel_type }; |
750 | 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)); |
751 | 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); |
752 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
|
|
753 | |
|
|
754 | #endif |
|
|
755 | |
|
|
756 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
|
|
757 | |
|
|
758 | void |
|
|
759 | gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj) |
|
|
760 | PPCODE: |
|
|
761 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res)); |
|
|
762 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
|
|
763 | |
|
|
764 | #if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS |
|
|
765 | |
|
|
766 | void |
|
|
767 | gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
|
|
768 | PPCODE: |
|
|
769 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res)); |
|
|
770 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
|
|
771 | |
|
|
772 | void |
|
|
773 | gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
|
|
774 | PPCODE: |
|
|
775 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res)); |
|
|
776 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
|
|
777 | |
|
|
778 | #endif |
|
|
779 | |
|
|
780 | void |
|
|
781 | gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer) |
|
|
782 | PPCODE: |
|
|
783 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res)); |
|
|
784 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
|
|
785 | |
|
|
786 | #endif |
663 | |
787 | |
664 | void |
788 | void |
665 | supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) |
789 | supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) |
666 | PPCODE: |
790 | PPCODE: |
667 | { |
791 | { |
… | |
… | |
770 | cl_event ev = 0; |
894 | cl_event ev = 0; |
771 | STRLEN len; |
895 | STRLEN len; |
772 | char *ptr = SvPVbyte (data, len); |
896 | char *ptr = SvPVbyte (data, len); |
773 | EVENT_LIST (5, items - 5); |
897 | EVENT_LIST (5, items - 5); |
774 | |
898 | |
775 | NEED_SUCCESS (EnqueueReadBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
899 | NEED_SUCCESS (EnqueueWriteBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
776 | |
900 | |
777 | if (ev) |
901 | if (ev) |
778 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
902 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
779 | |
903 | |
780 | void |
904 | void |
… | |
… | |
846 | size_t min_len = host_row_pitch * host_slice_pitch * region [2]; |
970 | size_t min_len = host_row_pitch * host_slice_pitch * region [2]; |
847 | |
971 | |
848 | if (len < min_len) |
972 | if (len < min_len) |
849 | croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
973 | croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
850 | |
974 | |
851 | 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)); |
975 | 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)); |
852 | |
976 | |
853 | if (ev) |
977 | if (ev) |
854 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
978 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
855 | |
979 | |
856 | void |
980 | void |
… | |
… | |
911 | size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height; |
1035 | size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height; |
912 | |
1036 | |
913 | if (len < min_len) |
1037 | if (len < min_len) |
914 | croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
1038 | croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
915 | |
1039 | |
916 | 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)); |
1040 | 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)); |
917 | |
1041 | |
918 | if (ev) |
1042 | if (ev) |
919 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1043 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
920 | |
1044 | |
921 | void |
1045 | void |
… | |
… | |
1003 | gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); |
1127 | gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); |
1004 | } |
1128 | } |
1005 | |
1129 | |
1006 | if (SvOK (local_work_size)) |
1130 | if (SvOK (local_work_size)) |
1007 | { |
1131 | { |
1008 | if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV) |
1132 | if ((SvOK (local_work_size) && !SvROK (local_work_size)) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV) |
1009 | croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference"); |
1133 | croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference"); |
1010 | |
1134 | |
1011 | if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) |
1135 | if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) |
1012 | croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size"); |
1136 | croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size"); |
1013 | |
1137 | |
… | |
… | |
1019 | NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1143 | NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1020 | |
1144 | |
1021 | if (ev) |
1145 | if (ev) |
1022 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1146 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1023 | |
1147 | |
|
|
1148 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
|
|
1149 | |
1024 | void |
1150 | void |
1025 | enqueue_marker (OpenCL::Queue self) |
1151 | enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...) |
|
|
1152 | ALIAS: |
|
|
1153 | enqueue_release_gl_objects = 1 |
1026 | PPCODE: |
1154 | PPCODE: |
|
|
1155 | if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV) |
|
|
1156 | croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call"); |
|
|
1157 | |
1027 | cl_event ev; |
1158 | cl_event ev = 0; |
1028 | NEED_SUCCESS (EnqueueMarker, (self, &ev)); |
1159 | EVENT_LIST (2, items - 2); |
|
|
1160 | AV *av = (AV *)SvRV (objects); |
|
|
1161 | cl_uint num_objects = av_len (av) + 1; |
|
|
1162 | cl_mem *object_list = tmpbuf (sizeof (cl_mem) * num_objects); |
|
|
1163 | int i; |
|
|
1164 | |
|
|
1165 | for (i = num_objects; i--; ) |
|
|
1166 | object_list [i] = SvPTROBJ ("OpenCL::Queue::enqueue_acquire/release_gl_objects", "objects", *av_fetch (av, i, 0), "OpenCL::Memory"); |
|
|
1167 | |
|
|
1168 | if (ix) |
|
|
1169 | NEED_SUCCESS (EnqueueReleaseGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1170 | else |
|
|
1171 | NEED_SUCCESS (EnqueueAcquireGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1172 | |
|
|
1173 | if (ev) |
1029 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1174 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
|
|
1175 | |
|
|
1176 | #endif |
|
|
1177 | |
|
|
1178 | #if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS |
1030 | |
1179 | |
1031 | void |
1180 | void |
1032 | enqueue_wait_for_events (OpenCL::Queue self, ...) |
1181 | enqueue_wait_for_events (OpenCL::Queue self, ...) |
1033 | CODE: |
1182 | CODE: |
1034 | EVENT_LIST (1, items - 1); |
1183 | EVENT_LIST (1, items - 1); |
1035 | NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); |
1184 | NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); |
1036 | |
1185 | |
|
|
1186 | #endif |
|
|
1187 | |
1037 | void |
1188 | void |
|
|
1189 | enqueue_marker (OpenCL::Queue self, ...) |
|
|
1190 | PPCODE: |
|
|
1191 | cl_event ev = 0; |
|
|
1192 | EVENT_LIST (1, items - 1); |
|
|
1193 | #if CL_VERSION_1_2 |
|
|
1194 | NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1195 | #else |
|
|
1196 | if (event_list_count) |
|
|
1197 | croak ("OpenCL::Queue->enqueue_marker does not support a wait list in OpenCL 1.1 - upgrade to 1.2"); |
|
|
1198 | NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1199 | #endif |
|
|
1200 | if (ev) |
|
|
1201 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
|
|
1202 | |
|
|
1203 | void |
1038 | enqueue_barrier (OpenCL::Queue self) |
1204 | enqueue_barrier (OpenCL::Queue self, ...) |
1039 | CODE: |
1205 | PPCODE: |
|
|
1206 | cl_event ev = 0; |
|
|
1207 | EVENT_LIST (1, items - 1); |
|
|
1208 | #if CL_VERSION_1_2 |
|
|
1209 | NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, &ev)); |
|
|
1210 | #else |
|
|
1211 | if (event_list_count) |
|
|
1212 | croak ("OpenCL::Queue->enqueue_barrier does not support a wait list in OpenCL 1.1 - upgrade to 1.2"); |
|
|
1213 | if (GIMME_V != G_VOID) |
|
|
1214 | croak ("OpenCL::Queue->enqueue_barrier does not return an event object in OpenCL 1.1 - upgrade to 1.2"); |
1040 | NEED_SUCCESS (EnqueueBarrier, (self)); |
1215 | NEED_SUCCESS (EnqueueBarrier, (self)); |
|
|
1216 | #endif |
|
|
1217 | if (ev) |
|
|
1218 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1041 | |
1219 | |
1042 | void |
1220 | void |
1043 | flush (OpenCL::Queue self) |
1221 | flush (OpenCL::Queue self) |
1044 | CODE: |
1222 | CODE: |
1045 | NEED_SUCCESS (Flush, (self)); |
1223 | NEED_SUCCESS (Flush, (self)); |
… | |
… | |
1187 | NEED_SUCCESS (RetainMemObject, (value [i])); |
1365 | NEED_SUCCESS (RetainMemObject, (value [i])); |
1188 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i])); |
1366 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i])); |
1189 | } |
1367 | } |
1190 | |
1368 | |
1191 | #END:mem |
1369 | #END:mem |
|
|
1370 | |
|
|
1371 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
|
|
1372 | |
|
|
1373 | void |
|
|
1374 | gl_object_info (OpenCL::Memory self) |
|
|
1375 | PPCODE: |
|
|
1376 | cl_gl_object_type type; |
|
|
1377 | cl_GLuint name; |
|
|
1378 | NEED_SUCCESS (GetGLObjectInfo, (self, &type, &name)); |
|
|
1379 | EXTEND (SP, 2); |
|
|
1380 | PUSHs (sv_2mortal (newSVuv (type))); |
|
|
1381 | PUSHs (sv_2mortal (newSVuv (name))); |
|
|
1382 | |
|
|
1383 | #endif |
1192 | |
1384 | |
1193 | MODULE = OpenCL PACKAGE = OpenCL::BufferObj |
1385 | MODULE = OpenCL PACKAGE = OpenCL::BufferObj |
1194 | |
1386 | |
1195 | void |
1387 | void |
1196 | sub_buffer_region (OpenCL::BufferObj self, cl_mem_flags flags, size_t origin, size_t size) |
1388 | sub_buffer_region (OpenCL::BufferObj self, cl_mem_flags flags, size_t origin, size_t size) |
… | |
… | |
1228 | const int i = 0; |
1420 | const int i = 0; |
1229 | PUSHs (sv_2mortal (newSVuv (value [i]))); |
1421 | PUSHs (sv_2mortal (newSVuv (value [i]))); |
1230 | |
1422 | |
1231 | #END:image |
1423 | #END:image |
1232 | |
1424 | |
|
|
1425 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
|
|
1426 | |
|
|
1427 | #BEGIN:gl_texture |
|
|
1428 | |
|
|
1429 | void |
|
|
1430 | target (OpenCL::Image self) |
|
|
1431 | PPCODE: |
|
|
1432 | cl_GLenum value [1]; |
|
|
1433 | NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0)); |
|
|
1434 | EXTEND (SP, 1); |
|
|
1435 | const int i = 0; |
|
|
1436 | PUSHs (sv_2mortal (newSVuv (value [i]))); |
|
|
1437 | |
|
|
1438 | void |
|
|
1439 | gl_mipmap_level (OpenCL::Image self) |
|
|
1440 | PPCODE: |
|
|
1441 | cl_GLint value [1]; |
|
|
1442 | NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0)); |
|
|
1443 | EXTEND (SP, 1); |
|
|
1444 | const int i = 0; |
|
|
1445 | PUSHs (sv_2mortal (newSViv (value [i]))); |
|
|
1446 | |
|
|
1447 | #END:gl_texture |
|
|
1448 | |
|
|
1449 | #endif |
|
|
1450 | |
1233 | MODULE = OpenCL PACKAGE = OpenCL::Sampler |
1451 | MODULE = OpenCL PACKAGE = OpenCL::Sampler |
1234 | |
1452 | |
1235 | void |
1453 | void |
1236 | DESTROY (OpenCL::Sampler self) |
1454 | DESTROY (OpenCL::Sampler self) |
1237 | CODE: |
1455 | CODE: |
… | |
… | |
1375 | { |
1593 | { |
1376 | SV *sv = sv_2mortal (newSV (sizes [i])); |
1594 | SV *sv = sv_2mortal (newSV (sizes [i])); |
1377 | SvUPGRADE (sv, SVt_PV); |
1595 | SvUPGRADE (sv, SVt_PV); |
1378 | SvPOK_only (sv); |
1596 | SvPOK_only (sv); |
1379 | SvCUR_set (sv, sizes [i]); |
1597 | SvCUR_set (sv, sizes [i]); |
1380 | ptrs [i] = SvPVX (sv); |
1598 | ptrs [i] = (void *)SvPVX (sv); |
1381 | PUSHs (sv); |
1599 | PUSHs (sv); |
1382 | } |
1600 | } |
1383 | |
1601 | |
1384 | NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size)); |
1602 | NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size)); |
1385 | if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; |
1603 | if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; |
… | |
… | |
1535 | set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) |
1753 | set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) |
1536 | CODE: |
1754 | CODE: |
1537 | clSetKernelArg (self, idx, sizeof (value), &value); |
1755 | clSetKernelArg (self, idx, sizeof (value), &value); |
1538 | |
1756 | |
1539 | void |
1757 | void |
|
|
1758 | set_local (OpenCL::Kernel self, cl_uint idx, size_t size) |
|
|
1759 | CODE: |
|
|
1760 | clSetKernelArg (self, idx, size, 0); |
|
|
1761 | |
|
|
1762 | void |
1540 | set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value) |
1763 | set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value) |
1541 | CODE: |
1764 | CODE: |
1542 | clSetKernelArg (self, idx, sizeof (value), &value); |
1765 | clSetKernelArg (self, idx, sizeof (value), &value); |
1543 | |
1766 | |
1544 | void |
1767 | void |