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_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 |
|
|
24 | #endif |
4 | |
25 | |
5 | #ifdef __APPLE__ |
26 | #ifdef __APPLE__ |
6 | #include <OpenCL/opencl.h> |
27 | #include <OpenCL/opencl.h> |
7 | #else |
28 | #else |
8 | #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 |
9 | #endif |
35 | #endif |
10 | |
36 | |
11 | typedef cl_platform_id OpenCL__Platform; |
37 | typedef cl_platform_id OpenCL__Platform; |
12 | typedef cl_device_id OpenCL__Device; |
38 | typedef cl_device_id OpenCL__Device; |
13 | typedef cl_context OpenCL__Context; |
39 | typedef cl_context OpenCL__Context; |
… | |
… | |
31 | |
57 | |
32 | typedef SV *FUTURE; |
58 | typedef SV *FUTURE; |
33 | |
59 | |
34 | /*****************************************************************************/ |
60 | /*****************************************************************************/ |
35 | |
61 | |
|
|
62 | // name must include a leading underscore |
|
|
63 | // all of this horrors would be unneceesary if somebody wrote a proper OpenGL module |
|
|
64 | // for perl. doh. |
|
|
65 | static void * |
|
|
66 | glsym (const char *name) |
|
|
67 | { |
|
|
68 | void *fun = 0; |
|
|
69 | |
|
|
70 | #if defined I_DLFCN && defined RTLD_DEFAULT |
|
|
71 | fun = dlsym (RTLD_DEFAULT, name + 1); |
|
|
72 | if (!fun) fun = dlsym (RTLD_DEFAULT, name); |
|
|
73 | |
|
|
74 | if (!fun) |
|
|
75 | { |
|
|
76 | static void *libgl; |
|
|
77 | static const char *glso[] = { |
|
|
78 | "libGL.so.1", |
|
|
79 | "libGL.so.3", |
|
|
80 | "libGL.so.4.0", |
|
|
81 | "libGL.so", |
|
|
82 | "/usr/lib/libGL.so", |
|
|
83 | "/usr/X11R6/lib/libGL.1.dylib" |
|
|
84 | }; |
|
|
85 | int i; |
|
|
86 | |
|
|
87 | for (i = 0; !libgl && i < sizeof (glso) / sizeof (glso [0]); ++i) |
|
|
88 | { |
|
|
89 | libgl = dlopen (glso [i], RTLD_LAZY); |
|
|
90 | if (libgl) |
|
|
91 | break; |
|
|
92 | } |
|
|
93 | |
|
|
94 | if (libgl) |
|
|
95 | { |
|
|
96 | fun = dlsym (libgl, name + 1); |
|
|
97 | if (!fun) fun = dlsym (libgl, name); |
|
|
98 | } |
|
|
99 | } |
|
|
100 | #endif |
|
|
101 | |
|
|
102 | return fun; |
|
|
103 | } |
|
|
104 | |
|
|
105 | /*****************************************************************************/ |
|
|
106 | |
36 | /* up to two temporary buffers */ |
107 | /* up to two temporary buffers */ |
37 | static void * |
108 | static void * |
38 | tmpbuf (size_t size) |
109 | tmpbuf (size_t size) |
39 | { |
110 | { |
|
|
111 | enum { buffers = 3 }; |
40 | static int idx; |
112 | static int idx; |
41 | static void *buf [2]; |
113 | static void *buf [buffers]; |
42 | static size_t len [2]; |
114 | static size_t len [buffers]; |
43 | |
115 | |
44 | idx ^= 1; |
116 | idx = (idx + 1) % buffers; |
45 | |
117 | |
46 | if (len [idx] < size) |
118 | if (len [idx] < size) |
47 | { |
119 | { |
48 | free (buf [idx]); |
120 | free (buf [idx]); |
49 | len [idx] = ((size + 31) & ~4095) + 4096 - 32; |
121 | len [idx] = ((size + 31) & ~4095) + 4096 - 32; |
… | |
… | |
131 | croak ("%s: %s is not of type %s", func, svname, pkg); |
203 | croak ("%s: %s is not of type %s", func, svname, pkg); |
132 | } |
204 | } |
133 | |
205 | |
134 | /*****************************************************************************/ |
206 | /*****************************************************************************/ |
135 | |
207 | |
|
|
208 | static cl_context_properties * |
|
|
209 | SvCONTEXTPROPERTIES (const char *func, const char *svname, SV *sv, cl_context_properties *extra, int extracount) |
|
|
210 | { |
|
|
211 | if (!sv || !SvOK (sv)) |
|
|
212 | if (extra) |
|
|
213 | sv = sv_2mortal (newRV_noinc ((SV *)newAV ())); // slow, but rarely used hopefully |
|
|
214 | else |
|
|
215 | return 0; |
|
|
216 | |
|
|
217 | if (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVAV) |
|
|
218 | { |
|
|
219 | AV *av = (AV *)SvRV (sv); |
|
|
220 | int i, len = av_len (av) + 1; |
|
|
221 | cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1)); |
|
|
222 | cl_context_properties *l = p; |
|
|
223 | |
|
|
224 | if (len & 1) |
|
|
225 | croak ("%s: %s is not a property list (must be even number of elements)", func, svname); |
|
|
226 | |
|
|
227 | while (extracount--) |
|
|
228 | *l++ = *extra++; |
|
|
229 | |
|
|
230 | for (i = 0; i < len; i += 2) |
|
|
231 | { |
|
|
232 | cl_context_properties t = SvIV (*av_fetch (av, i , 0)); |
|
|
233 | SV *p_sv = *av_fetch (av, i + 1, 0); |
|
|
234 | cl_context_properties v = SvIV (p_sv); // code below can override |
|
|
235 | |
|
|
236 | switch (t) |
|
|
237 | { |
|
|
238 | case CL_GLX_DISPLAY_KHR: |
|
|
239 | if (!SvOK (p_sv)) |
|
|
240 | { |
|
|
241 | void *func = glsym ("_glXGetCurrentDisplay"); |
|
|
242 | if (func) |
|
|
243 | v = (cl_context_properties)((void *(*)(void))func)(); |
|
|
244 | } |
|
|
245 | break; |
|
|
246 | |
|
|
247 | case CL_GL_CONTEXT_KHR: |
|
|
248 | if (!SvOK (p_sv)) |
|
|
249 | { |
|
|
250 | void *func = glsym ("_glXGetCurrentContext"); |
|
|
251 | if (func) |
|
|
252 | v = (cl_context_properties)((void *(*)(void))func)(); |
|
|
253 | } |
|
|
254 | break; |
|
|
255 | |
|
|
256 | default: |
|
|
257 | /* unknown property, treat as int */ |
|
|
258 | break; |
|
|
259 | } |
|
|
260 | |
|
|
261 | *l++ = t; |
|
|
262 | *l++ = v; |
|
|
263 | } |
|
|
264 | |
|
|
265 | *l = 0; |
|
|
266 | |
|
|
267 | return p; |
|
|
268 | } |
|
|
269 | |
|
|
270 | croak ("%s: %s is not a property list (either undef or [type => value, ...])", func, svname); |
|
|
271 | } |
|
|
272 | |
|
|
273 | /*****************************************************************************/ |
|
|
274 | |
136 | static size_t |
275 | static size_t |
137 | img_row_pitch (cl_mem img) |
276 | img_row_pitch (cl_mem img) |
138 | { |
277 | { |
139 | size_t res; |
278 | size_t res; |
140 | clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); |
279 | clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); |
141 | return res; |
280 | return res; |
142 | } |
281 | } |
143 | |
282 | |
144 | static cl_event * |
283 | static cl_event * |
145 | event_list (SV **items, int count) |
284 | event_list (SV **items, cl_uint *rcount) |
146 | { |
285 | { |
|
|
286 | cl_uint count = *rcount; |
|
|
287 | |
147 | if (!count) |
288 | if (!count) |
148 | return 0; |
289 | return 0; |
149 | |
290 | |
150 | cl_event *list = tmpbuf (sizeof (cl_event) * count); |
291 | cl_event *list = tmpbuf (sizeof (cl_event) * count); |
|
|
292 | int i = 0; |
151 | |
293 | |
152 | while (count--) |
294 | do |
|
|
295 | { |
|
|
296 | --count; |
|
|
297 | if (SvOK (items [count])) |
153 | list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); |
298 | list [i++] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); |
|
|
299 | } |
|
|
300 | while (count); |
154 | |
301 | |
|
|
302 | *rcount = i; |
|
|
303 | |
155 | return list; |
304 | return i ? list : 0; |
156 | } |
305 | } |
157 | |
306 | |
158 | #define EVENT_LIST(items,count) \ |
307 | #define EVENT_LIST(items,count) \ |
159 | cl_uint event_list_count = (count); \ |
308 | cl_uint event_list_count = (count); \ |
160 | cl_event *event_list_ptr = event_list (&ST (items), event_list_count) |
309 | cl_event *event_list_ptr = event_list (&ST (items), &event_list_count) |
161 | |
310 | |
162 | #define INFO(class) \ |
311 | #define INFO(class) \ |
163 | { \ |
312 | { \ |
164 | size_t size; \ |
313 | size_t size; \ |
165 | NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ |
314 | NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ |
… | |
… | |
175 | |
324 | |
176 | PROTOTYPES: ENABLE |
325 | PROTOTYPES: ENABLE |
177 | |
326 | |
178 | BOOT: |
327 | BOOT: |
179 | { |
328 | { |
180 | HV *stash = gv_stashpv ("OpenCL", 1); |
329 | HV *stash = gv_stashpv ("OpenCL", 1); |
181 | static const ivstr *civ, const_iv[] = { |
330 | static const ivstr *civ, const_iv[] = { |
182 | { sizeof (cl_char ), "SIZEOF_CHAR" }, |
331 | { sizeof (cl_char ), "SIZEOF_CHAR" }, |
183 | { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, |
332 | { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, |
184 | { sizeof (cl_short ), "SIZEOF_SHORT" }, |
333 | { sizeof (cl_short ), "SIZEOF_SHORT" }, |
185 | { sizeof (cl_ushort), "SIZEOF_USHORT" }, |
334 | { sizeof (cl_ushort), "SIZEOF_USHORT" }, |
186 | { sizeof (cl_int ), "SIZEOF_INT" }, |
335 | { sizeof (cl_int ), "SIZEOF_INT" }, |
187 | { sizeof (cl_uint ), "SIZEOF_UINT" }, |
336 | { sizeof (cl_uint ), "SIZEOF_UINT" }, |
188 | { sizeof (cl_long ), "SIZEOF_LONG" }, |
337 | { sizeof (cl_long ), "SIZEOF_LONG" }, |
189 | { sizeof (cl_ulong ), "SIZEOF_ULONG" }, |
338 | { sizeof (cl_ulong ), "SIZEOF_ULONG" }, |
190 | { sizeof (cl_half ), "SIZEOF_HALF" }, |
339 | { sizeof (cl_half ), "SIZEOF_HALF" }, |
191 | { sizeof (cl_float ), "SIZEOF_FLOAT" }, |
340 | { sizeof (cl_float ), "SIZEOF_FLOAT" }, |
192 | { sizeof (cl_double), "SIZEOF_DOUBLE" }, |
341 | { sizeof (cl_double), "SIZEOF_DOUBLE" }, |
193 | #include "constiv.h" |
342 | #include "constiv.h" |
194 | }; |
343 | }; |
195 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
344 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
196 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
345 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
197 | } |
346 | } |
198 | |
347 | |
199 | cl_int |
348 | cl_int |
200 | errno () |
349 | errno () |
201 | CODE: |
350 | CODE: |
202 | errno = res; |
351 | RETVAL = res; |
|
|
352 | OUTPUT: |
|
|
353 | RETVAL |
203 | |
354 | |
204 | const char * |
355 | const char * |
205 | err2str (cl_int err) |
356 | err2str (cl_int err) |
206 | |
357 | |
207 | const char * |
358 | const char * |
… | |
… | |
221 | EXTEND (SP, count); |
372 | EXTEND (SP, count); |
222 | for (i = 0; i < count; ++i) |
373 | for (i = 0; i < count; ++i) |
223 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); |
374 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); |
224 | |
375 | |
225 | void |
376 | void |
226 | context_from_type (FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
377 | context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
227 | PPCODE: |
378 | PPCODE: |
228 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (0, type, 0, 0, &res)); |
379 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res)); |
229 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
380 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
230 | |
381 | |
|
|
382 | #if 0 |
|
|
383 | |
231 | void |
384 | void |
232 | context (FUTURE properties, FUTURE devices, FUTURE notify = 0) |
385 | context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) |
233 | PPCODE: |
386 | PPCODE: |
234 | /* der Gipfel der Kunst */ |
387 | /* der Gipfel der Kunst */ |
|
|
388 | |
|
|
389 | #endif |
235 | |
390 | |
236 | void |
391 | void |
237 | wait_for_events (...) |
392 | wait_for_events (...) |
238 | CODE: |
393 | CODE: |
239 | EVENT_LIST (0, items); |
394 | EVENT_LIST (0, items); |
… | |
… | |
245 | |
400 | |
246 | void |
401 | void |
247 | info (OpenCL::Platform self, cl_platform_info name) |
402 | info (OpenCL::Platform self, cl_platform_info name) |
248 | PPCODE: |
403 | PPCODE: |
249 | INFO (Platform) |
404 | INFO (Platform) |
|
|
405 | |
|
|
406 | void |
|
|
407 | unload_compiler (OpenCL::Platform self) |
|
|
408 | CODE: |
|
|
409 | #if CL_VERSION_1_2 |
|
|
410 | clUnloadPlatformCompiler (self); |
|
|
411 | #endif |
250 | |
412 | |
251 | #BEGIN:platform |
413 | #BEGIN:platform |
252 | |
414 | |
253 | void |
415 | void |
254 | profile (OpenCL::Platform self) |
416 | profile (OpenCL::Platform self) |
… | |
… | |
283 | EXTEND (SP, count); |
445 | EXTEND (SP, count); |
284 | for (i = 0; i < count; ++i) |
446 | for (i = 0; i < count; ++i) |
285 | PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); |
447 | PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); |
286 | |
448 | |
287 | void |
449 | void |
288 | context (OpenCL::Platform self, FUTURE properties, SV *devices, FUTURE notify = 0) |
450 | context (OpenCL::Platform self, cl_context_properties *properties = 0, SV *devices, FUTURE notify = 0) |
289 | PPCODE: |
451 | PPCODE: |
290 | if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) |
452 | if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) |
291 | croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call"); |
453 | croak ("OpenCL::Platform::context argument 'device' must be an arrayref with device objects, in call"); |
292 | |
454 | |
293 | AV *av = (AV *)SvRV (devices); |
455 | AV *av = (AV *)SvRV (devices); |
294 | cl_uint num_devices = av_len (av) + 1; |
456 | cl_uint num_devices = av_len (av) + 1; |
295 | cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); |
457 | cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); |
296 | int i; |
458 | int i; |
297 | |
459 | |
298 | for (i = num_devices; i--; ) |
460 | for (i = num_devices; i--; ) |
299 | device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device"); |
461 | device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device"); |
300 | |
462 | |
301 | NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (0, num_devices, device_list, 0, 0, &res)); |
463 | NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (properties, num_devices, device_list, 0, 0, &res)); |
302 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
464 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
303 | |
465 | |
304 | void |
466 | void |
305 | context_from_type (OpenCL::Platform self, FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
467 | context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
306 | PPCODE: |
468 | PPCODE: |
307 | cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self, 0 }; |
469 | cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self }; |
|
|
470 | cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context_from_type", "properties", properties, extra, 2); |
308 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res)); |
471 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res)); |
309 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
472 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
310 | |
473 | |
311 | MODULE = OpenCL PACKAGE = OpenCL::Device |
474 | MODULE = OpenCL PACKAGE = OpenCL::Device |
312 | |
475 | |
… | |
… | |
353 | native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT |
516 | native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT |
354 | native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG |
517 | native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG |
355 | native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT |
518 | native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT |
356 | native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE |
519 | native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE |
357 | native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF |
520 | native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF |
358 | reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT |
521 | reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT |
359 | PPCODE: |
522 | PPCODE: |
360 | cl_uint value [1]; |
523 | cl_uint value [1]; |
361 | NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0)); |
524 | NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0)); |
362 | EXTEND (SP, 1); |
525 | EXTEND (SP, 1); |
363 | const int i = 0; |
526 | const int i = 0; |
… | |
… | |
565 | |
728 | |
566 | void |
729 | void |
567 | buffer (OpenCL::Context self, cl_mem_flags flags, size_t len) |
730 | buffer (OpenCL::Context self, cl_mem_flags flags, size_t len) |
568 | PPCODE: |
731 | PPCODE: |
569 | if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) |
732 | if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) |
570 | croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); |
733 | croak ("OpenCL::Context::buffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); |
571 | |
734 | |
572 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res)); |
735 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res)); |
573 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
736 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
574 | |
737 | |
575 | void |
738 | void |
576 | buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data) |
739 | buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data) |
577 | PPCODE: |
740 | PPCODE: |
578 | STRLEN len; |
741 | STRLEN len; |
579 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
742 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
580 | 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))) |
581 | croak ("clCreateBuffer: 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?"); |
582 | 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)); |
583 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
746 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
584 | |
747 | |
|
|
748 | #if CL_VERSION_1_2 |
|
|
749 | |
585 | void |
750 | void |
586 | 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) |
751 | image (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) |
587 | PPCODE: |
752 | PPCODE: |
588 | STRLEN len; |
753 | STRLEN len; |
589 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
754 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
590 | 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 | }; |
591 | 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 | } |
592 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
774 | XPUSH_NEW_OBJ (klass, mem); |
593 | |
775 | |
|
|
776 | #endif |
|
|
777 | |
594 | void |
778 | void |
595 | image3d (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) |
779 | 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) |
596 | PPCODE: |
780 | PPCODE: |
597 | STRLEN len; |
781 | STRLEN len; |
598 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
782 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
599 | 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 | |
|
|
792 | void |
|
|
793 | image3d (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 |
600 | 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 |
601 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
804 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
|
|
805 | |
|
|
806 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
|
|
807 | |
|
|
808 | void |
|
|
809 | gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj) |
|
|
810 | PPCODE: |
|
|
811 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res)); |
|
|
812 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
|
|
813 | |
|
|
814 | void |
|
|
815 | gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer) |
|
|
816 | PPCODE: |
|
|
817 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res)); |
|
|
818 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
|
|
819 | |
|
|
820 | #if CL_VERSION_1_2 |
|
|
821 | |
|
|
822 | void |
|
|
823 | gl_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 | |
|
|
843 | void |
|
|
844 | gl_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 | |
|
|
853 | void |
|
|
854 | gl_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); |
|
|
862 | |
|
|
863 | #endif |
602 | |
864 | |
603 | void |
865 | void |
604 | supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) |
866 | supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) |
605 | PPCODE: |
867 | PPCODE: |
606 | { |
868 | { |
… | |
… | |
709 | cl_event ev = 0; |
971 | cl_event ev = 0; |
710 | STRLEN len; |
972 | STRLEN len; |
711 | char *ptr = SvPVbyte (data, len); |
973 | char *ptr = SvPVbyte (data, len); |
712 | EVENT_LIST (5, items - 5); |
974 | EVENT_LIST (5, items - 5); |
713 | |
975 | |
714 | NEED_SUCCESS (EnqueueReadBuffer, (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)); |
715 | |
977 | |
716 | if (ev) |
978 | if (ev) |
717 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
979 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
|
|
980 | |
|
|
981 | #if CL_VERSION_1_2 |
|
|
982 | |
|
|
983 | void |
|
|
984 | enqueue_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 | |
|
|
996 | void |
|
|
997 | enqueue_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 (GetImageInfo, (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 |
718 | |
1023 | |
719 | void |
1024 | void |
720 | enqueue_copy_buffer (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...) |
1025 | enqueue_copy_buffer (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...) |
721 | PPCODE: |
1026 | PPCODE: |
722 | cl_event ev = 0; |
1027 | cl_event ev = 0; |
… | |
… | |
785 | 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]; |
786 | |
1091 | |
787 | if (len < min_len) |
1092 | if (len < min_len) |
788 | croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
1093 | croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
789 | |
1094 | |
790 | 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)); |
791 | |
1096 | |
792 | if (ev) |
1097 | if (ev) |
793 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1098 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
794 | |
1099 | |
795 | void |
1100 | void |
… | |
… | |
850 | 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; |
851 | |
1156 | |
852 | if (len < min_len) |
1157 | if (len < min_len) |
853 | croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
1158 | croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
854 | |
1159 | |
855 | 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)); |
856 | |
1161 | |
857 | if (ev) |
1162 | if (ev) |
858 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1163 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
859 | |
1164 | |
860 | void |
1165 | void |
… | |
… | |
942 | gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); |
1247 | gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); |
943 | } |
1248 | } |
944 | |
1249 | |
945 | if (SvOK (local_work_size)) |
1250 | if (SvOK (local_work_size)) |
946 | { |
1251 | { |
947 | 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) |
948 | 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"); |
949 | |
1254 | |
950 | if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) |
1255 | if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) |
951 | 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"); |
952 | |
1257 | |
… | |
… | |
958 | NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1263 | NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
959 | |
1264 | |
960 | if (ev) |
1265 | if (ev) |
961 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1266 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
962 | |
1267 | |
|
|
1268 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
|
|
1269 | |
963 | void |
1270 | void |
964 | enqueue_marker (OpenCL::Queue self) |
1271 | enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...) |
|
|
1272 | ALIAS: |
|
|
1273 | enqueue_release_gl_objects = 1 |
965 | PPCODE: |
1274 | PPCODE: |
|
|
1275 | if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV) |
|
|
1276 | croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call"); |
|
|
1277 | |
966 | cl_event ev; |
1278 | cl_event ev = 0; |
967 | NEED_SUCCESS (EnqueueMarker, (self, &ev)); |
1279 | EVENT_LIST (2, items - 2); |
|
|
1280 | AV *av = (AV *)SvRV (objects); |
|
|
1281 | cl_uint num_objects = av_len (av) + 1; |
|
|
1282 | cl_mem *object_list = tmpbuf (sizeof (cl_mem) * num_objects); |
|
|
1283 | int i; |
|
|
1284 | |
|
|
1285 | for (i = num_objects; i--; ) |
|
|
1286 | object_list [i] = SvPTROBJ ("OpenCL::Queue::enqueue_acquire/release_gl_objects", "objects", *av_fetch (av, i, 0), "OpenCL::Memory"); |
|
|
1287 | |
|
|
1288 | if (ix) |
|
|
1289 | NEED_SUCCESS (EnqueueReleaseGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1290 | else |
|
|
1291 | NEED_SUCCESS (EnqueueAcquireGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1292 | |
|
|
1293 | if (ev) |
968 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1294 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
|
|
1295 | |
|
|
1296 | #endif |
969 | |
1297 | |
970 | void |
1298 | void |
971 | enqueue_wait_for_events (OpenCL::Queue self, ...) |
1299 | enqueue_wait_for_events (OpenCL::Queue self, ...) |
972 | CODE: |
1300 | CODE: |
973 | EVENT_LIST (1, items - 1); |
1301 | EVENT_LIST (1, items - 1); |
|
|
1302 | #if PREFER_1_1 |
974 | 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 |
975 | |
1307 | |
976 | void |
1308 | void |
|
|
1309 | enqueue_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 | { |
|
|
1321 | NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); // also a barrier |
|
|
1322 | NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1323 | } |
|
|
1324 | #endif |
|
|
1325 | #else |
|
|
1326 | NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1327 | #endif |
|
|
1328 | if (ev) |
|
|
1329 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
|
|
1330 | |
|
|
1331 | void |
977 | enqueue_barrier (OpenCL::Queue self) |
1332 | enqueue_barrier (OpenCL::Queue self, ...) |
978 | CODE: |
1333 | PPCODE: |
|
|
1334 | cl_event ev = 0; |
|
|
1335 | EVENT_LIST (1, items - 1); |
|
|
1336 | #if PREFER_1_1 |
|
|
1337 | if (!event_list_count && GIMME_V == G_VOID) |
979 | NEED_SUCCESS (EnqueueBarrier, (self)); |
1338 | NEED_SUCCESS (EnqueueBarrier, (self)); |
|
|
1339 | else |
|
|
1340 | #if CL_VERSION_1_2 |
|
|
1341 | NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1342 | #else |
|
|
1343 | { |
|
|
1344 | if (event_list_count) |
|
|
1345 | NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); |
|
|
1346 | |
|
|
1347 | if (GIMME_V != G_VOID) |
|
|
1348 | NEED_SUCCESS (EnqueueMarker, (self, &ev)); |
|
|
1349 | } |
|
|
1350 | #endif |
|
|
1351 | #else |
|
|
1352 | NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1353 | #endif |
|
|
1354 | if (ev) |
|
|
1355 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
980 | |
1356 | |
981 | void |
1357 | void |
982 | flush (OpenCL::Queue self) |
1358 | flush (OpenCL::Queue self) |
983 | CODE: |
1359 | CODE: |
984 | NEED_SUCCESS (Flush, (self)); |
1360 | NEED_SUCCESS (Flush, (self)); |
… | |
… | |
1127 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i])); |
1503 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i])); |
1128 | } |
1504 | } |
1129 | |
1505 | |
1130 | #END:mem |
1506 | #END:mem |
1131 | |
1507 | |
|
|
1508 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
|
|
1509 | |
|
|
1510 | void |
|
|
1511 | gl_object_info (OpenCL::Memory self) |
|
|
1512 | PPCODE: |
|
|
1513 | cl_gl_object_type type; |
|
|
1514 | cl_GLuint name; |
|
|
1515 | NEED_SUCCESS (GetGLObjectInfo, (self, &type, &name)); |
|
|
1516 | EXTEND (SP, 2); |
|
|
1517 | PUSHs (sv_2mortal (newSVuv (type))); |
|
|
1518 | PUSHs (sv_2mortal (newSVuv (name))); |
|
|
1519 | |
|
|
1520 | #endif |
|
|
1521 | |
1132 | MODULE = OpenCL PACKAGE = OpenCL::BufferObj |
1522 | MODULE = OpenCL PACKAGE = OpenCL::BufferObj |
1133 | |
1523 | |
1134 | void |
1524 | void |
1135 | sub_buffer_region (OpenCL::BufferObj self, cl_mem_flags flags, size_t origin, size_t size) |
1525 | sub_buffer_region (OpenCL::BufferObj self, cl_mem_flags flags, size_t origin, size_t size) |
1136 | PPCODE: |
1526 | PPCODE: |
… | |
… | |
1146 | |
1536 | |
1147 | void |
1537 | void |
1148 | image_info (OpenCL::Image self, cl_image_info name) |
1538 | image_info (OpenCL::Image self, cl_image_info name) |
1149 | PPCODE: |
1539 | PPCODE: |
1150 | INFO (Image) |
1540 | INFO (Image) |
|
|
1541 | |
|
|
1542 | void |
|
|
1543 | format (OpenCL::Image self) |
|
|
1544 | PPCODE: |
|
|
1545 | cl_image_format format; |
|
|
1546 | NEED_SUCCESS (GetImageInfo, (self, CL_IMAGE_FORMAT, sizeof (format), &format, 0)); |
|
|
1547 | EXTEND (SP, 2); |
|
|
1548 | PUSHs (sv_2mortal (newSVuv (format.image_channel_order))); |
|
|
1549 | PUSHs (sv_2mortal (newSVuv (format.image_channel_data_type))); |
1151 | |
1550 | |
1152 | #BEGIN:image |
1551 | #BEGIN:image |
1153 | |
1552 | |
1154 | void |
1553 | void |
1155 | element_size (OpenCL::Image self) |
1554 | element_size (OpenCL::Image self) |
… | |
… | |
1167 | const int i = 0; |
1566 | const int i = 0; |
1168 | PUSHs (sv_2mortal (newSVuv (value [i]))); |
1567 | PUSHs (sv_2mortal (newSVuv (value [i]))); |
1169 | |
1568 | |
1170 | #END:image |
1569 | #END:image |
1171 | |
1570 | |
|
|
1571 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
|
|
1572 | |
|
|
1573 | #BEGIN:gl_texture |
|
|
1574 | |
|
|
1575 | void |
|
|
1576 | target (OpenCL::Image self) |
|
|
1577 | PPCODE: |
|
|
1578 | cl_GLenum value [1]; |
|
|
1579 | NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0)); |
|
|
1580 | EXTEND (SP, 1); |
|
|
1581 | const int i = 0; |
|
|
1582 | PUSHs (sv_2mortal (newSVuv (value [i]))); |
|
|
1583 | |
|
|
1584 | void |
|
|
1585 | gl_mipmap_level (OpenCL::Image self) |
|
|
1586 | PPCODE: |
|
|
1587 | cl_GLint value [1]; |
|
|
1588 | NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0)); |
|
|
1589 | EXTEND (SP, 1); |
|
|
1590 | const int i = 0; |
|
|
1591 | PUSHs (sv_2mortal (newSViv (value [i]))); |
|
|
1592 | |
|
|
1593 | #END:gl_texture |
|
|
1594 | |
|
|
1595 | #endif |
|
|
1596 | |
1172 | MODULE = OpenCL PACKAGE = OpenCL::Sampler |
1597 | MODULE = OpenCL PACKAGE = OpenCL::Sampler |
1173 | |
1598 | |
1174 | void |
1599 | void |
1175 | DESTROY (OpenCL::Sampler self) |
1600 | DESTROY (OpenCL::Sampler self) |
1176 | CODE: |
1601 | CODE: |
… | |
… | |
1289 | PPCODE: |
1714 | PPCODE: |
1290 | NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res)); |
1715 | NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res)); |
1291 | XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel); |
1716 | XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel); |
1292 | |
1717 | |
1293 | void |
1718 | void |
|
|
1719 | kernels_in_program (OpenCL::Program program) |
|
|
1720 | PPCODE: |
|
|
1721 | cl_uint num_kernels; |
|
|
1722 | NEED_SUCCESS (CreateKernelsInProgram, (program, 0, 0, &num_kernels)); |
|
|
1723 | cl_kernel *kernels = tmpbuf (sizeof (cl_kernel) * num_kernels); |
|
|
1724 | NEED_SUCCESS (CreateKernelsInProgram, (program, num_kernels, kernels, 0)); |
|
|
1725 | |
|
|
1726 | int i; |
|
|
1727 | EXTEND (SP, num_kernels); |
|
|
1728 | for (i = 0; i < num_kernels; ++i) |
|
|
1729 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Kernel", kernels [i])); |
|
|
1730 | |
|
|
1731 | void |
1294 | info (OpenCL::Program self, cl_program_info name) |
1732 | info (OpenCL::Program self, cl_program_info name) |
1295 | PPCODE: |
1733 | PPCODE: |
1296 | INFO (Program) |
1734 | INFO (Program) |
1297 | |
1735 | |
1298 | void |
1736 | void |
… | |
… | |
1314 | { |
1752 | { |
1315 | SV *sv = sv_2mortal (newSV (sizes [i])); |
1753 | SV *sv = sv_2mortal (newSV (sizes [i])); |
1316 | SvUPGRADE (sv, SVt_PV); |
1754 | SvUPGRADE (sv, SVt_PV); |
1317 | SvPOK_only (sv); |
1755 | SvPOK_only (sv); |
1318 | SvCUR_set (sv, sizes [i]); |
1756 | SvCUR_set (sv, sizes [i]); |
1319 | ptrs [i] = SvPVX (sv); |
1757 | ptrs [i] = (void *)SvPVX (sv); |
1320 | PUSHs (sv); |
1758 | PUSHs (sv); |
1321 | } |
1759 | } |
1322 | |
1760 | |
1323 | NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size)); |
1761 | NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size)); |
1324 | if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; |
1762 | if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; |
… | |
… | |
1474 | set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) |
1912 | set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) |
1475 | CODE: |
1913 | CODE: |
1476 | clSetKernelArg (self, idx, sizeof (value), &value); |
1914 | clSetKernelArg (self, idx, sizeof (value), &value); |
1477 | |
1915 | |
1478 | void |
1916 | void |
|
|
1917 | set_local (OpenCL::Kernel self, cl_uint idx, size_t size) |
|
|
1918 | CODE: |
|
|
1919 | clSetKernelArg (self, idx, size, 0); |
|
|
1920 | |
|
|
1921 | void |
1479 | set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value) |
1922 | set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value) |
1480 | CODE: |
1923 | CODE: |
1481 | clSetKernelArg (self, idx, sizeof (value), &value); |
1924 | clSetKernelArg (self, idx, sizeof (value), &value); |
1482 | |
1925 | |
1483 | void |
1926 | void |