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> |
… | |
… | |
31 | |
45 | |
32 | typedef SV *FUTURE; |
46 | typedef SV *FUTURE; |
33 | |
47 | |
34 | /*****************************************************************************/ |
48 | /*****************************************************************************/ |
35 | |
49 | |
|
|
50 | // name must include a leading underscore |
|
|
51 | // all of this horrors would be unneceesary if somebody wrote a proper OpenGL module |
|
|
52 | // for perl. doh. |
|
|
53 | static void * |
|
|
54 | glsym (const char *name) |
|
|
55 | { |
|
|
56 | void *fun = 0; |
|
|
57 | |
|
|
58 | #if defined I_DLFCN && defined RTLD_DEFAULT |
|
|
59 | fun = dlsym (RTLD_DEFAULT, name + 1); |
|
|
60 | if (!fun) fun = dlsym (RTLD_DEFAULT, name); |
|
|
61 | |
|
|
62 | if (!fun) |
|
|
63 | { |
|
|
64 | static void *libgl; |
|
|
65 | static const char *glso[] = { |
|
|
66 | "libGL.so.1", |
|
|
67 | "libGL.so.3", |
|
|
68 | "libGL.so.4.0", |
|
|
69 | "libGL.so", |
|
|
70 | "/usr/lib/libGL.so", |
|
|
71 | "/usr/X11R6/lib/libGL.1.dylib" |
|
|
72 | }; |
|
|
73 | int i; |
|
|
74 | |
|
|
75 | for (i = 0; !libgl && i < sizeof (glso) / sizeof (glso [0]); ++i) |
|
|
76 | { |
|
|
77 | libgl = dlopen (glso [i], RTLD_LAZY); |
|
|
78 | if (libgl) |
|
|
79 | break; |
|
|
80 | } |
|
|
81 | |
|
|
82 | if (libgl) |
|
|
83 | { |
|
|
84 | fun = dlsym (libgl, name + 1); |
|
|
85 | if (!fun) fun = dlsym (libgl, name); |
|
|
86 | } |
|
|
87 | } |
|
|
88 | #endif |
|
|
89 | |
|
|
90 | return fun; |
|
|
91 | } |
|
|
92 | |
|
|
93 | /*****************************************************************************/ |
|
|
94 | |
36 | /* up to two temporary buffers */ |
95 | /* up to two temporary buffers */ |
37 | static void * |
96 | static void * |
38 | tmpbuf (size_t size) |
97 | tmpbuf (size_t size) |
39 | { |
98 | { |
|
|
99 | enum { buffers = 3 }; |
40 | static int idx; |
100 | static int idx; |
41 | static void *buf [2]; |
101 | static void *buf [buffers]; |
42 | static size_t len [2]; |
102 | static size_t len [buffers]; |
43 | |
103 | |
44 | idx ^= 1; |
104 | idx = (idx + 1) % buffers; |
45 | |
105 | |
46 | if (len [idx] < size) |
106 | if (len [idx] < size) |
47 | { |
107 | { |
48 | free (buf [idx]); |
108 | free (buf [idx]); |
49 | len [idx] = ((size + 31) & ~4095) + 4096 - 32; |
109 | len [idx] = ((size + 31) & ~4095) + 4096 - 32; |
… | |
… | |
131 | croak ("%s: %s is not of type %s", func, svname, pkg); |
191 | croak ("%s: %s is not of type %s", func, svname, pkg); |
132 | } |
192 | } |
133 | |
193 | |
134 | /*****************************************************************************/ |
194 | /*****************************************************************************/ |
135 | |
195 | |
|
|
196 | static cl_context_properties * |
|
|
197 | SvCONTEXTPROPERTIES (const char *func, const char *svname, SV *sv, cl_context_properties *extra, int extracount) |
|
|
198 | { |
|
|
199 | if (!sv || !SvOK (sv)) |
|
|
200 | if (extra) |
|
|
201 | sv = sv_2mortal (newRV_noinc ((SV *)newAV ())); // slow, but rarely used hopefully |
|
|
202 | else |
|
|
203 | return 0; |
|
|
204 | |
|
|
205 | if (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVAV) |
|
|
206 | { |
|
|
207 | AV *av = (AV *)SvRV (sv); |
|
|
208 | int i, len = av_len (av) + 1; |
|
|
209 | cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1)); |
|
|
210 | cl_context_properties *l = p; |
|
|
211 | |
|
|
212 | if (len & 1) |
|
|
213 | croak ("%s: %s is not a property list (must be even number of elements)", func, svname); |
|
|
214 | |
|
|
215 | while (extracount--) |
|
|
216 | *l++ = *extra++; |
|
|
217 | |
|
|
218 | for (i = 0; i < len; i += 2) |
|
|
219 | { |
|
|
220 | cl_context_properties t = SvIV (*av_fetch (av, i , 0)); |
|
|
221 | SV *p_sv = *av_fetch (av, i + 1, 0); |
|
|
222 | cl_context_properties v = SvIV (p_sv); // code below can override |
|
|
223 | |
|
|
224 | switch (t) |
|
|
225 | { |
|
|
226 | case CL_GLX_DISPLAY_KHR: |
|
|
227 | if (!SvOK (p_sv)) |
|
|
228 | { |
|
|
229 | void *func = glsym ("_glXGetCurrentDisplay"); |
|
|
230 | if (func) |
|
|
231 | v = (cl_context_properties)((void *(*)(void))func)(); |
|
|
232 | } |
|
|
233 | break; |
|
|
234 | |
|
|
235 | case CL_GL_CONTEXT_KHR: |
|
|
236 | if (!SvOK (p_sv)) |
|
|
237 | { |
|
|
238 | void *func = glsym ("_glXGetCurrentContext"); |
|
|
239 | if (func) |
|
|
240 | v = (cl_context_properties)((void *(*)(void))func)(); |
|
|
241 | } |
|
|
242 | break; |
|
|
243 | |
|
|
244 | default: |
|
|
245 | /* unknown property, treat as int */ |
|
|
246 | break; |
|
|
247 | } |
|
|
248 | |
|
|
249 | *l++ = t; |
|
|
250 | *l++ = v; |
|
|
251 | } |
|
|
252 | |
|
|
253 | *l = 0; |
|
|
254 | |
|
|
255 | return p; |
|
|
256 | } |
|
|
257 | |
|
|
258 | croak ("%s: %s is not a property list (either undef or [type => value, ...])", func, svname); |
|
|
259 | } |
|
|
260 | |
|
|
261 | /*****************************************************************************/ |
|
|
262 | |
136 | static size_t |
263 | static size_t |
137 | img_row_pitch (cl_mem img) |
264 | img_row_pitch (cl_mem img) |
138 | { |
265 | { |
139 | size_t res; |
266 | size_t res; |
140 | clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); |
267 | clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); |
141 | return res; |
268 | return res; |
142 | } |
269 | } |
143 | |
270 | |
144 | static cl_event * |
271 | static cl_event * |
145 | event_list (SV **items, int count) |
272 | event_list (SV **items, cl_uint *rcount) |
146 | { |
273 | { |
|
|
274 | cl_uint count = *rcount; |
|
|
275 | |
147 | if (!count) |
276 | if (!count) |
148 | return 0; |
277 | return 0; |
149 | |
278 | |
150 | cl_event *list = tmpbuf (sizeof (cl_event) * count); |
279 | cl_event *list = tmpbuf (sizeof (cl_event) * count); |
|
|
280 | int i = 0; |
151 | |
281 | |
152 | while (count--) |
282 | do |
|
|
283 | { |
|
|
284 | --count; |
|
|
285 | if (SvOK (items [count])) |
153 | list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); |
286 | list [i++] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); |
|
|
287 | } |
|
|
288 | while (count); |
154 | |
289 | |
|
|
290 | *rcount = i; |
|
|
291 | |
155 | return list; |
292 | return i ? list : 0; |
156 | } |
293 | } |
157 | |
294 | |
158 | #define EVENT_LIST(items,count) \ |
295 | #define EVENT_LIST(items,count) \ |
159 | cl_uint event_list_count = (count); \ |
296 | cl_uint event_list_count = (count); \ |
160 | cl_event *event_list_ptr = event_list (&ST (items), event_list_count) |
297 | cl_event *event_list_ptr = event_list (&ST (items), &event_list_count) |
161 | |
298 | |
162 | #define INFO(class) \ |
299 | #define INFO(class) \ |
163 | { \ |
300 | { \ |
164 | size_t size; \ |
301 | size_t size; \ |
165 | NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ |
302 | NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ |
166 | SV *sv = sv_2mortal (newSV (size)); \ |
303 | SV *sv = sv_2mortal (newSV (size)); \ |
167 | SvUPGRADE (sv, SVt_PV); \ |
304 | SvUPGRADE (sv, SVt_PV); \ |
168 | SvPOK_only (sv); \ |
305 | SvPOK_only (sv); \ |
169 | SvCUR_set (sv, size); \ |
306 | SvCUR_set (sv, size); \ |
170 | NEED_SUCCESS (Get ## class ## Info, (self, name, size, SvPVX (sv), 0)); \ |
307 | NEED_SUCCESS (Get ## class ## Info, (self, name, size, SvPVX (sv), 0)); \ |
171 | XPUSHs (sv); \ |
308 | XPUSHs (sv); \ |
172 | } |
309 | } |
173 | |
310 | |
174 | MODULE = OpenCL PACKAGE = OpenCL |
311 | MODULE = OpenCL PACKAGE = OpenCL |
175 | |
312 | |
176 | PROTOTYPES: ENABLE |
313 | PROTOTYPES: ENABLE |
177 | |
314 | |
178 | BOOT: |
315 | BOOT: |
179 | { |
316 | { |
180 | HV *stash = gv_stashpv ("OpenCL", 1); |
317 | HV *stash = gv_stashpv ("OpenCL", 1); |
181 | static const ivstr *civ, const_iv[] = { |
318 | static const ivstr *civ, const_iv[] = { |
182 | { sizeof (cl_char ), "SIZEOF_CHAR" }, |
319 | { sizeof (cl_char ), "SIZEOF_CHAR" }, |
183 | { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, |
320 | { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, |
184 | { sizeof (cl_short ), "SIZEOF_SHORT" }, |
321 | { sizeof (cl_short ), "SIZEOF_SHORT" }, |
185 | { sizeof (cl_ushort), "SIZEOF_USHORT" }, |
322 | { sizeof (cl_ushort), "SIZEOF_USHORT" }, |
186 | { sizeof (cl_int ), "SIZEOF_INT" }, |
323 | { sizeof (cl_int ), "SIZEOF_INT" }, |
187 | { sizeof (cl_uint ), "SIZEOF_UINT" }, |
324 | { sizeof (cl_uint ), "SIZEOF_UINT" }, |
188 | { sizeof (cl_long ), "SIZEOF_LONG" }, |
325 | { sizeof (cl_long ), "SIZEOF_LONG" }, |
189 | { sizeof (cl_ulong ), "SIZEOF_ULONG" }, |
326 | { sizeof (cl_ulong ), "SIZEOF_ULONG" }, |
190 | { sizeof (cl_half ), "SIZEOF_HALF" }, |
327 | { sizeof (cl_half ), "SIZEOF_HALF" }, |
191 | { sizeof (cl_float ), "SIZEOF_FLOAT" }, |
328 | { sizeof (cl_float ), "SIZEOF_FLOAT" }, |
192 | { sizeof (cl_double), "SIZEOF_DOUBLE" }, |
329 | { sizeof (cl_double), "SIZEOF_DOUBLE" }, |
193 | #include "constiv.h" |
330 | #include "constiv.h" |
194 | }; |
331 | }; |
195 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
332 | 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)); |
333 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
197 | } |
334 | } |
198 | |
335 | |
199 | cl_int |
336 | cl_int |
200 | errno () |
337 | errno () |
201 | CODE: |
338 | CODE: |
202 | errno = res; |
339 | RETVAL = res; |
|
|
340 | OUTPUT: |
|
|
341 | RETVAL |
203 | |
342 | |
204 | const char * |
343 | const char * |
205 | err2str (cl_int err) |
344 | err2str (cl_int err) |
206 | |
345 | |
207 | const char * |
346 | const char * |
… | |
… | |
221 | EXTEND (SP, count); |
360 | EXTEND (SP, count); |
222 | for (i = 0; i < count; ++i) |
361 | for (i = 0; i < count; ++i) |
223 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); |
362 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); |
224 | |
363 | |
225 | void |
364 | void |
226 | context_from_type (FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
365 | context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
227 | PPCODE: |
366 | PPCODE: |
228 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (0, type, 0, 0, &res)); |
367 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res)); |
229 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
368 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
230 | |
369 | |
|
|
370 | #if 0 |
|
|
371 | |
231 | void |
372 | void |
232 | context (FUTURE properties, FUTURE devices, FUTURE notify = 0) |
373 | context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) |
233 | PPCODE: |
374 | PPCODE: |
234 | /* der Gipfel der Kunst */ |
375 | /* der Gipfel der Kunst */ |
|
|
376 | |
|
|
377 | #endif |
235 | |
378 | |
236 | void |
379 | void |
237 | wait_for_events (...) |
380 | wait_for_events (...) |
238 | CODE: |
381 | CODE: |
239 | EVENT_LIST (0, items); |
382 | EVENT_LIST (0, items); |
… | |
… | |
283 | EXTEND (SP, count); |
426 | EXTEND (SP, count); |
284 | for (i = 0; i < count; ++i) |
427 | for (i = 0; i < count; ++i) |
285 | PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); |
428 | PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); |
286 | |
429 | |
287 | void |
430 | void |
288 | context (OpenCL::Platform self, FUTURE properties, SV *devices, FUTURE notify = 0) |
431 | context (OpenCL::Platform self, cl_context_properties *properties = 0, SV *devices, FUTURE notify = 0) |
289 | PPCODE: |
432 | PPCODE: |
290 | if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) |
433 | if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) |
291 | croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call"); |
434 | croak ("OpenCL::Platform::context argument 'device' must be an arrayref with device objects, in call"); |
292 | |
435 | |
293 | AV *av = (AV *)SvRV (devices); |
436 | AV *av = (AV *)SvRV (devices); |
294 | cl_uint num_devices = av_len (av) + 1; |
437 | cl_uint num_devices = av_len (av) + 1; |
295 | cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); |
438 | cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); |
296 | int i; |
439 | int i; |
297 | |
440 | |
298 | for (i = num_devices; i--; ) |
441 | for (i = num_devices; i--; ) |
299 | device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device"); |
442 | device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device"); |
300 | |
443 | |
301 | NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (0, num_devices, device_list, 0, 0, &res)); |
444 | NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (properties, num_devices, device_list, 0, 0, &res)); |
302 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
445 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
303 | |
446 | |
304 | void |
447 | void |
305 | context_from_type (OpenCL::Platform self, FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
448 | context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
306 | PPCODE: |
449 | PPCODE: |
307 | cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self, 0 }; |
450 | cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self }; |
|
|
451 | 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)); |
452 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res)); |
309 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
453 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
310 | |
454 | |
311 | MODULE = OpenCL PACKAGE = OpenCL::Device |
455 | MODULE = OpenCL PACKAGE = OpenCL::Device |
312 | |
456 | |
… | |
… | |
552 | INFO (Context) |
696 | INFO (Context) |
553 | |
697 | |
554 | void |
698 | void |
555 | queue (OpenCL::Context self, OpenCL::Device device, cl_command_queue_properties properties = 0) |
699 | queue (OpenCL::Context self, OpenCL::Device device, cl_command_queue_properties properties = 0) |
556 | PPCODE: |
700 | PPCODE: |
557 | NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (self, device, properties, &res)); |
701 | NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (self, device, properties, &res)); |
558 | XPUSH_NEW_OBJ ("OpenCL::Queue", queue); |
702 | XPUSH_NEW_OBJ ("OpenCL::Queue", queue); |
559 | |
703 | |
560 | void |
704 | void |
561 | user_event (OpenCL::Context self) |
705 | user_event (OpenCL::Context self) |
562 | PPCODE: |
706 | PPCODE: |
563 | NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (self, &res)); |
707 | NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (self, &res)); |
564 | XPUSH_NEW_OBJ ("OpenCL::UserEvent", ev); |
708 | XPUSH_NEW_OBJ ("OpenCL::UserEvent", ev); |
565 | |
709 | |
566 | void |
710 | void |
567 | buffer (OpenCL::Context self, cl_mem_flags flags, size_t len) |
711 | buffer (OpenCL::Context self, cl_mem_flags flags, size_t len) |
568 | PPCODE: |
712 | PPCODE: |
569 | if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) |
713 | 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?"); |
714 | croak ("OpenCL::Context::buffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); |
571 | |
715 | |
572 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res)); |
716 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res)); |
573 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
717 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
574 | |
718 | |
575 | void |
719 | void |
576 | buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data) |
720 | buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data) |
577 | PPCODE: |
721 | PPCODE: |
578 | STRLEN len; |
722 | STRLEN len; |
579 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
723 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
580 | 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))) |
581 | croak ("clCreateBuffer: 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?"); |
582 | 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)); |
583 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
727 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
|
|
728 | |
|
|
729 | #if !defined CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS |
584 | |
730 | |
585 | void |
731 | 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) |
732 | 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) |
587 | PPCODE: |
733 | PPCODE: |
588 | STRLEN len; |
734 | STRLEN len; |
589 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
735 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
590 | const cl_image_format format = { channel_order, channel_type }; |
736 | const cl_image_format format = { channel_order, channel_type }; |
591 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res)); |
737 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res)); |
592 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
738 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
593 | |
739 | |
594 | void |
740 | 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) |
741 | 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) |
596 | PPCODE: |
742 | PPCODE: |
597 | STRLEN len; |
743 | STRLEN len; |
598 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
744 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
599 | const cl_image_format format = { channel_order, channel_type }; |
745 | const cl_image_format format = { channel_order, channel_type }; |
600 | 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)); |
601 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
747 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
|
|
748 | |
|
|
749 | #endif |
|
|
750 | |
|
|
751 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
|
|
752 | |
|
|
753 | void |
|
|
754 | gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj) |
|
|
755 | PPCODE: |
|
|
756 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res)); |
|
|
757 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
|
|
758 | |
|
|
759 | #if !defined CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS |
|
|
760 | |
|
|
761 | void |
|
|
762 | gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
|
|
763 | PPCODE: |
|
|
764 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res)); |
|
|
765 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
|
|
766 | |
|
|
767 | void |
|
|
768 | gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
|
|
769 | PPCODE: |
|
|
770 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res)); |
|
|
771 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
|
|
772 | |
|
|
773 | #endif |
|
|
774 | |
|
|
775 | void |
|
|
776 | gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer) |
|
|
777 | PPCODE: |
|
|
778 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res)); |
|
|
779 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
|
|
780 | |
|
|
781 | #endif |
602 | |
782 | |
603 | void |
783 | void |
604 | supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) |
784 | supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) |
605 | PPCODE: |
785 | PPCODE: |
606 | { |
786 | { |
607 | cl_uint count; |
787 | cl_uint count; |
608 | cl_image_format *list; |
788 | cl_image_format *list; |
609 | int i; |
789 | int i; |
610 | |
790 | |
611 | NEED_SUCCESS (GetSupportedImageFormats, (self, flags, image_type, 0, 0, &count)); |
791 | NEED_SUCCESS (GetSupportedImageFormats, (self, flags, image_type, 0, 0, &count)); |
612 | Newx (list, count, cl_image_format); |
792 | Newx (list, count, cl_image_format); |
613 | NEED_SUCCESS (GetSupportedImageFormats, (self, flags, image_type, count, list, 0)); |
793 | NEED_SUCCESS (GetSupportedImageFormats, (self, flags, image_type, count, list, 0)); |
614 | |
794 | |
615 | EXTEND (SP, count); |
795 | EXTEND (SP, count); |
616 | for (i = 0; i < count; ++i) |
796 | for (i = 0; i < count; ++i) |
617 | { |
797 | { |
618 | AV *av = newAV (); |
798 | AV *av = newAV (); |
… | |
… | |
623 | } |
803 | } |
624 | |
804 | |
625 | void |
805 | void |
626 | sampler (OpenCL::Context self, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode) |
806 | sampler (OpenCL::Context self, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode) |
627 | PPCODE: |
807 | PPCODE: |
628 | NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (self, normalized_coords, addressing_mode, filter_mode, &res)); |
808 | NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (self, normalized_coords, addressing_mode, filter_mode, &res)); |
629 | XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler); |
809 | XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler); |
630 | |
810 | |
631 | void |
811 | void |
632 | program_with_source (OpenCL::Context self, SV *program) |
812 | program_with_source (OpenCL::Context self, SV *program) |
633 | PPCODE: |
813 | PPCODE: |
634 | STRLEN len; |
814 | STRLEN len; |
635 | size_t len2; |
815 | size_t len2; |
636 | const char *ptr = SvPVbyte (program, len); |
816 | const char *ptr = SvPVbyte (program, len); |
637 | |
817 | |
638 | len2 = len; |
818 | len2 = len; |
639 | NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (self, 1, &ptr, &len2, &res)); |
819 | NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (self, 1, &ptr, &len2, &res)); |
640 | XPUSH_NEW_OBJ ("OpenCL::Program", prog); |
820 | XPUSH_NEW_OBJ ("OpenCL::Program", prog); |
641 | |
821 | |
642 | #BEGIN:context |
822 | #BEGIN:context |
643 | |
823 | |
644 | void |
824 | void |
… | |
… | |
709 | cl_event ev = 0; |
889 | cl_event ev = 0; |
710 | STRLEN len; |
890 | STRLEN len; |
711 | char *ptr = SvPVbyte (data, len); |
891 | char *ptr = SvPVbyte (data, len); |
712 | EVENT_LIST (5, items - 5); |
892 | EVENT_LIST (5, items - 5); |
713 | |
893 | |
714 | NEED_SUCCESS (EnqueueReadBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
894 | NEED_SUCCESS (EnqueueWriteBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
715 | |
895 | |
716 | if (ev) |
896 | if (ev) |
717 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
897 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
718 | |
898 | |
719 | void |
899 | void |
… | |
… | |
785 | 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]; |
786 | |
966 | |
787 | if (len < min_len) |
967 | if (len < min_len) |
788 | croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
968 | croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
789 | |
969 | |
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)); |
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)); |
791 | |
971 | |
792 | if (ev) |
972 | if (ev) |
793 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
973 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
794 | |
974 | |
795 | void |
975 | void |
… | |
… | |
850 | 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; |
851 | |
1031 | |
852 | if (len < min_len) |
1032 | if (len < min_len) |
853 | croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
1033 | croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
854 | |
1034 | |
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)); |
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)); |
856 | |
1036 | |
857 | if (ev) |
1037 | if (ev) |
858 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1038 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
859 | |
1039 | |
860 | void |
1040 | void |
… | |
… | |
942 | gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); |
1122 | gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); |
943 | } |
1123 | } |
944 | |
1124 | |
945 | if (SvOK (local_work_size)) |
1125 | if (SvOK (local_work_size)) |
946 | { |
1126 | { |
947 | 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) |
948 | 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"); |
949 | |
1129 | |
950 | if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) |
1130 | 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"); |
1131 | croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size"); |
952 | |
1132 | |
… | |
… | |
958 | NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1138 | NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
959 | |
1139 | |
960 | if (ev) |
1140 | if (ev) |
961 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1141 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
962 | |
1142 | |
|
|
1143 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
|
|
1144 | |
|
|
1145 | void |
|
|
1146 | enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...) |
|
|
1147 | ALIAS: |
|
|
1148 | enqueue_release_gl_objects = 1 |
|
|
1149 | PPCODE: |
|
|
1150 | if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV) |
|
|
1151 | croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call"); |
|
|
1152 | |
|
|
1153 | cl_event ev = 0; |
|
|
1154 | EVENT_LIST (2, items - 2); |
|
|
1155 | AV *av = (AV *)SvRV (objects); |
|
|
1156 | cl_uint num_objects = av_len (av) + 1; |
|
|
1157 | cl_mem *object_list = tmpbuf (sizeof (cl_mem) * num_objects); |
|
|
1158 | int i; |
|
|
1159 | |
|
|
1160 | for (i = num_objects; i--; ) |
|
|
1161 | object_list [i] = SvPTROBJ ("OpenCL::Queue::enqueue_acquire/release_gl_objects", "objects", *av_fetch (av, i, 0), "OpenCL::Memory"); |
|
|
1162 | |
|
|
1163 | if (ix) |
|
|
1164 | NEED_SUCCESS (EnqueueReleaseGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1165 | else |
|
|
1166 | NEED_SUCCESS (EnqueueAcquireGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1167 | |
|
|
1168 | if (ev) |
|
|
1169 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
|
|
1170 | |
|
|
1171 | #endif |
|
|
1172 | |
|
|
1173 | #if !defined CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS |
|
|
1174 | |
963 | void |
1175 | void |
964 | enqueue_marker (OpenCL::Queue self) |
1176 | enqueue_marker (OpenCL::Queue self) |
965 | PPCODE: |
1177 | PPCODE: |
966 | cl_event ev; |
1178 | cl_event ev; |
967 | NEED_SUCCESS (EnqueueMarker, (self, &ev)); |
1179 | NEED_SUCCESS (EnqueueMarker, (self, &ev)); |
… | |
… | |
975 | |
1187 | |
976 | void |
1188 | void |
977 | enqueue_barrier (OpenCL::Queue self) |
1189 | enqueue_barrier (OpenCL::Queue self) |
978 | CODE: |
1190 | CODE: |
979 | NEED_SUCCESS (EnqueueBarrier, (self)); |
1191 | NEED_SUCCESS (EnqueueBarrier, (self)); |
|
|
1192 | |
|
|
1193 | #endif |
980 | |
1194 | |
981 | void |
1195 | void |
982 | flush (OpenCL::Queue self) |
1196 | flush (OpenCL::Queue self) |
983 | CODE: |
1197 | CODE: |
984 | NEED_SUCCESS (Flush, (self)); |
1198 | NEED_SUCCESS (Flush, (self)); |
… | |
… | |
1126 | NEED_SUCCESS (RetainMemObject, (value [i])); |
1340 | NEED_SUCCESS (RetainMemObject, (value [i])); |
1127 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i])); |
1341 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i])); |
1128 | } |
1342 | } |
1129 | |
1343 | |
1130 | #END:mem |
1344 | #END:mem |
|
|
1345 | |
|
|
1346 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
|
|
1347 | |
|
|
1348 | void |
|
|
1349 | gl_object_info (OpenCL::Memory self) |
|
|
1350 | PPCODE: |
|
|
1351 | cl_gl_object_type type; |
|
|
1352 | cl_GLuint name; |
|
|
1353 | NEED_SUCCESS (GetGLObjectInfo, (self, &type, &name)); |
|
|
1354 | EXTEND (SP, 2); |
|
|
1355 | PUSHs (sv_2mortal (newSVuv (type))); |
|
|
1356 | PUSHs (sv_2mortal (newSVuv (name))); |
|
|
1357 | |
|
|
1358 | #endif |
1131 | |
1359 | |
1132 | MODULE = OpenCL PACKAGE = OpenCL::BufferObj |
1360 | MODULE = OpenCL PACKAGE = OpenCL::BufferObj |
1133 | |
1361 | |
1134 | void |
1362 | void |
1135 | sub_buffer_region (OpenCL::BufferObj self, cl_mem_flags flags, size_t origin, size_t size) |
1363 | sub_buffer_region (OpenCL::BufferObj self, cl_mem_flags flags, size_t origin, size_t size) |
… | |
… | |
1167 | const int i = 0; |
1395 | const int i = 0; |
1168 | PUSHs (sv_2mortal (newSVuv (value [i]))); |
1396 | PUSHs (sv_2mortal (newSVuv (value [i]))); |
1169 | |
1397 | |
1170 | #END:image |
1398 | #END:image |
1171 | |
1399 | |
|
|
1400 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
|
|
1401 | |
|
|
1402 | #BEGIN:gl_texture |
|
|
1403 | |
|
|
1404 | void |
|
|
1405 | target (OpenCL::Image self) |
|
|
1406 | PPCODE: |
|
|
1407 | cl_GLenum value [1]; |
|
|
1408 | NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0)); |
|
|
1409 | EXTEND (SP, 1); |
|
|
1410 | const int i = 0; |
|
|
1411 | PUSHs (sv_2mortal (newSVuv (value [i]))); |
|
|
1412 | |
|
|
1413 | void |
|
|
1414 | gl_mipmap_level (OpenCL::Image self) |
|
|
1415 | PPCODE: |
|
|
1416 | cl_GLint value [1]; |
|
|
1417 | NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0)); |
|
|
1418 | EXTEND (SP, 1); |
|
|
1419 | const int i = 0; |
|
|
1420 | PUSHs (sv_2mortal (newSViv (value [i]))); |
|
|
1421 | |
|
|
1422 | #END:gl_texture |
|
|
1423 | |
|
|
1424 | #endif |
|
|
1425 | |
1172 | MODULE = OpenCL PACKAGE = OpenCL::Sampler |
1426 | MODULE = OpenCL PACKAGE = OpenCL::Sampler |
1173 | |
1427 | |
1174 | void |
1428 | void |
1175 | DESTROY (OpenCL::Sampler self) |
1429 | DESTROY (OpenCL::Sampler self) |
1176 | CODE: |
1430 | CODE: |
… | |
… | |
1246 | NEED_SUCCESS (BuildProgram, (self, 1, &device, SvPVbyte_nolen (options), 0, 0)); |
1500 | NEED_SUCCESS (BuildProgram, (self, 1, &device, SvPVbyte_nolen (options), 0, 0)); |
1247 | |
1501 | |
1248 | void |
1502 | void |
1249 | build_info (OpenCL::Program self, OpenCL::Device device, cl_program_build_info name) |
1503 | build_info (OpenCL::Program self, OpenCL::Device device, cl_program_build_info name) |
1250 | PPCODE: |
1504 | PPCODE: |
1251 | size_t size; |
1505 | size_t size; |
1252 | NEED_SUCCESS (GetProgramBuildInfo, (self, device, name, 0, 0, &size)); |
1506 | NEED_SUCCESS (GetProgramBuildInfo, (self, device, name, 0, 0, &size)); |
1253 | SV *sv = sv_2mortal (newSV (size)); |
1507 | SV *sv = sv_2mortal (newSV (size)); |
1254 | SvUPGRADE (sv, SVt_PV); |
1508 | SvUPGRADE (sv, SVt_PV); |
1255 | SvPOK_only (sv); |
1509 | SvPOK_only (sv); |
1256 | SvCUR_set (sv, size); |
1510 | SvCUR_set (sv, size); |
1257 | NEED_SUCCESS (GetProgramBuildInfo, (self, device, name, size, SvPVX (sv), 0)); |
1511 | NEED_SUCCESS (GetProgramBuildInfo, (self, device, name, size, SvPVX (sv), 0)); |
1258 | XPUSHs (sv); |
1512 | XPUSHs (sv); |
1259 | |
1513 | |
1260 | #BEGIN:program_build |
1514 | #BEGIN:program_build |
1261 | |
1515 | |
1262 | void |
1516 | void |
… | |
… | |
1285 | #END:program_build |
1539 | #END:program_build |
1286 | |
1540 | |
1287 | void |
1541 | void |
1288 | kernel (OpenCL::Program program, SV *function) |
1542 | kernel (OpenCL::Program program, SV *function) |
1289 | PPCODE: |
1543 | PPCODE: |
1290 | NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res)); |
1544 | NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res)); |
1291 | XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel); |
1545 | XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel); |
1292 | |
1546 | |
1293 | void |
1547 | void |
1294 | info (OpenCL::Program self, cl_program_info name) |
1548 | info (OpenCL::Program self, cl_program_info name) |
1295 | PPCODE: |
1549 | PPCODE: |
… | |
… | |
1314 | { |
1568 | { |
1315 | SV *sv = sv_2mortal (newSV (sizes [i])); |
1569 | SV *sv = sv_2mortal (newSV (sizes [i])); |
1316 | SvUPGRADE (sv, SVt_PV); |
1570 | SvUPGRADE (sv, SVt_PV); |
1317 | SvPOK_only (sv); |
1571 | SvPOK_only (sv); |
1318 | SvCUR_set (sv, sizes [i]); |
1572 | SvCUR_set (sv, sizes [i]); |
1319 | ptrs [i] = SvPVX (sv); |
1573 | ptrs [i] = (void *)SvPVX (sv); |
1320 | PUSHs (sv); |
1574 | PUSHs (sv); |
1321 | } |
1575 | } |
1322 | |
1576 | |
1323 | 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)); |
1324 | if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; |
1578 | if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; |
… | |
… | |
1474 | set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) |
1728 | set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) |
1475 | CODE: |
1729 | CODE: |
1476 | clSetKernelArg (self, idx, sizeof (value), &value); |
1730 | clSetKernelArg (self, idx, sizeof (value), &value); |
1477 | |
1731 | |
1478 | void |
1732 | void |
|
|
1733 | set_local (OpenCL::Kernel self, cl_uint idx, size_t size) |
|
|
1734 | CODE: |
|
|
1735 | clSetKernelArg (self, idx, size, 0); |
|
|
1736 | |
|
|
1737 | void |
1479 | set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value) |
1738 | set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value) |
1480 | CODE: |
1739 | CODE: |
1481 | clSetKernelArg (self, idx, sizeof (value), &value); |
1740 | clSetKernelArg (self, idx, sizeof (value), &value); |
1482 | |
1741 | |
1483 | void |
1742 | void |