1 |
root |
1.1 |
#include "EXTERN.h" |
2 |
|
|
#include "perl.h" |
3 |
|
|
#include "XSUB.h" |
4 |
|
|
|
5 |
root |
1.64 |
#include "ecb.h"//D |
6 |
|
|
|
7 |
root |
1.51 |
#define X_STACKSIZE sizeof (void *) * 512 * 1024 // 2-4mb should be enough, really |
8 |
|
|
#include "xthread.h" |
9 |
|
|
#include "schmorp.h" |
10 |
|
|
|
11 |
root |
1.30 |
#ifdef I_DLFCN |
12 |
|
|
#include <dlfcn.h> |
13 |
|
|
#endif |
14 |
|
|
|
15 |
root |
1.37 |
// how stupid is that, the 1.2 header files define CL_VERSION_1_1, |
16 |
|
|
// but then fail to define the api functions unless you ALSO define |
17 |
|
|
// this. This breaks 100% of the opencl 1.1 apps, for what reason? |
18 |
|
|
// after all, the functions are deprecated, not removed. |
19 |
|
|
// in addition, you cannot test for this in any future-proof way. |
20 |
|
|
// each time a new opencl version comes out, you need to make a new |
21 |
|
|
// release. |
22 |
|
|
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS /* just guessing, you stupid idiots */ |
23 |
|
|
|
24 |
root |
1.45 |
#ifndef PREFER_1_1 |
25 |
root |
1.44 |
#define PREFER_1_1 1 |
26 |
|
|
#endif |
27 |
|
|
|
28 |
|
|
#if PREFER_1_1 |
29 |
|
|
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS |
30 |
|
|
#endif |
31 |
|
|
|
32 |
root |
1.19 |
#ifdef __APPLE__ |
33 |
root |
1.74 |
#define CLHDR(name) <OpenCL/name> |
34 |
root |
1.19 |
#else |
35 |
root |
1.74 |
#define CLHDR(name) <CL/name> |
36 |
|
|
#endif |
37 |
|
|
|
38 |
|
|
#include CLHDR(opencl.h) |
39 |
|
|
|
40 |
|
|
#ifndef CL_VERSION_1_2 |
41 |
|
|
#include CLHDR(cl_d3d9.h) |
42 |
|
|
#endif |
43 |
|
|
|
44 |
|
|
#if _WIN32 |
45 |
|
|
#include CLHDR(cl_d3d10.h) |
46 |
|
|
#if CL_VERSION_1_2 |
47 |
|
|
#include CLHDR<cl_d3d11.h> |
48 |
|
|
#endif |
49 |
|
|
#include CLHDR<cl_dx9_media_sharing.h.h> |
50 |
root |
1.19 |
#endif |
51 |
root |
1.1 |
|
52 |
root |
1.44 |
#ifndef CL_VERSION_1_2 |
53 |
|
|
#undef PREFER_1_1 |
54 |
|
|
#define PREFER_1_1 1 |
55 |
root |
1.38 |
#endif |
56 |
|
|
|
57 |
root |
1.74 |
// make sure all constants we might use are actually defined |
58 |
|
|
#include "default.h" |
59 |
|
|
|
60 |
root |
1.16 |
typedef cl_platform_id OpenCL__Platform; |
61 |
|
|
typedef cl_device_id OpenCL__Device; |
62 |
root |
1.65 |
typedef cl_device_id OpenCL__SubDevice; |
63 |
root |
1.16 |
typedef cl_context OpenCL__Context; |
64 |
|
|
typedef cl_command_queue OpenCL__Queue; |
65 |
|
|
typedef cl_mem OpenCL__Memory; |
66 |
|
|
typedef cl_mem OpenCL__Buffer; |
67 |
root |
1.18 |
typedef cl_mem OpenCL__BufferObj; |
68 |
root |
1.16 |
typedef cl_mem OpenCL__Image; |
69 |
|
|
typedef cl_mem OpenCL__Memory_ornull; |
70 |
|
|
typedef cl_mem OpenCL__Buffer_ornull; |
71 |
|
|
typedef cl_mem OpenCL__Image_ornull; |
72 |
|
|
typedef cl_sampler OpenCL__Sampler; |
73 |
|
|
typedef cl_program OpenCL__Program; |
74 |
|
|
typedef cl_kernel OpenCL__Kernel; |
75 |
|
|
typedef cl_event OpenCL__Event; |
76 |
|
|
typedef cl_event OpenCL__UserEvent; |
77 |
root |
1.5 |
|
78 |
root |
1.61 |
typedef struct mapped * OpenCL__Mapped; |
79 |
|
|
|
80 |
|
|
static HV |
81 |
|
|
*stash_platform, |
82 |
|
|
*stash_device, |
83 |
root |
1.65 |
*stash_subdevice, |
84 |
root |
1.61 |
*stash_context, |
85 |
|
|
*stash_queue, |
86 |
|
|
*stash_program, |
87 |
|
|
*stash_kernel, |
88 |
|
|
*stash_sampler, |
89 |
|
|
*stash_event, |
90 |
|
|
*stash_userevent, |
91 |
|
|
*stash_memory, |
92 |
|
|
*stash_buffer, |
93 |
|
|
*stash_bufferobj, |
94 |
|
|
*stash_image, |
95 |
|
|
*stash_image1d, |
96 |
|
|
*stash_image1darray, |
97 |
|
|
*stash_image1dbuffer, |
98 |
|
|
*stash_image2d, |
99 |
|
|
*stash_image2darray, |
100 |
|
|
*stash_image3d, |
101 |
|
|
*stash_mapped, |
102 |
|
|
*stash_mappedbuffer, |
103 |
|
|
*stash_mappedimage; |
104 |
|
|
|
105 |
root |
1.5 |
/*****************************************************************************/ |
106 |
|
|
|
107 |
root |
1.30 |
// name must include a leading underscore |
108 |
root |
1.32 |
// all of this horrors would be unneceesary if somebody wrote a proper OpenGL module |
109 |
|
|
// for perl. doh. |
110 |
root |
1.30 |
static void * |
111 |
root |
1.32 |
glsym (const char *name) |
112 |
root |
1.30 |
{ |
113 |
root |
1.32 |
void *fun = 0; |
114 |
|
|
|
115 |
root |
1.30 |
#if defined I_DLFCN && defined RTLD_DEFAULT |
116 |
root |
1.32 |
fun = dlsym (RTLD_DEFAULT, name + 1); |
117 |
|
|
if (!fun) fun = dlsym (RTLD_DEFAULT, name); |
118 |
|
|
|
119 |
|
|
if (!fun) |
120 |
|
|
{ |
121 |
|
|
static void *libgl; |
122 |
|
|
static const char *glso[] = { |
123 |
|
|
"libGL.so.1", |
124 |
|
|
"libGL.so.3", |
125 |
|
|
"libGL.so.4.0", |
126 |
|
|
"libGL.so", |
127 |
|
|
"/usr/lib/libGL.so", |
128 |
|
|
"/usr/X11R6/lib/libGL.1.dylib" |
129 |
|
|
}; |
130 |
|
|
int i; |
131 |
|
|
|
132 |
|
|
for (i = 0; !libgl && i < sizeof (glso) / sizeof (glso [0]); ++i) |
133 |
|
|
{ |
134 |
|
|
libgl = dlopen (glso [i], RTLD_LAZY); |
135 |
|
|
if (libgl) |
136 |
|
|
break; |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
if (libgl) |
140 |
|
|
{ |
141 |
|
|
fun = dlsym (libgl, name + 1); |
142 |
|
|
if (!fun) fun = dlsym (libgl, name); |
143 |
|
|
} |
144 |
|
|
} |
145 |
root |
1.30 |
#endif |
146 |
root |
1.32 |
|
147 |
|
|
return fun; |
148 |
root |
1.30 |
} |
149 |
|
|
|
150 |
|
|
/*****************************************************************************/ |
151 |
|
|
|
152 |
root |
1.5 |
/* up to two temporary buffers */ |
153 |
root |
1.64 |
static void * ecb_noinline |
154 |
root |
1.5 |
tmpbuf (size_t size) |
155 |
|
|
{ |
156 |
root |
1.64 |
enum { buffers = 4 }; |
157 |
root |
1.5 |
static int idx; |
158 |
root |
1.24 |
static void *buf [buffers]; |
159 |
|
|
static size_t len [buffers]; |
160 |
root |
1.5 |
|
161 |
root |
1.37 |
idx = (idx + 1) % buffers; |
162 |
root |
1.5 |
|
163 |
|
|
if (len [idx] < size) |
164 |
|
|
{ |
165 |
|
|
free (buf [idx]); |
166 |
|
|
len [idx] = ((size + 31) & ~4095) + 4096 - 32; |
167 |
|
|
buf [idx] = malloc (len [idx]); |
168 |
|
|
} |
169 |
|
|
|
170 |
|
|
return buf [idx]; |
171 |
|
|
} |
172 |
|
|
|
173 |
root |
1.69 |
static const char * ecb_noinline |
174 |
|
|
cv_get_name (CV *cv) |
175 |
|
|
{ |
176 |
|
|
static char fullname [256]; |
177 |
|
|
|
178 |
|
|
GV *gv = CvGV (cv); // gv better be nonzero |
179 |
|
|
|
180 |
|
|
HV *stash = GvSTASH (gv); |
181 |
|
|
const char *hvname = HvNAME_get (stash); // stash also better be nonzero |
182 |
|
|
const char *gvname = GvNAME (gv); |
183 |
|
|
|
184 |
|
|
snprintf (fullname, sizeof (fullname), "%s::%s", hvname, gvname); |
185 |
|
|
return fullname; |
186 |
|
|
} |
187 |
|
|
|
188 |
root |
1.5 |
/*****************************************************************************/ |
189 |
root |
1.1 |
|
190 |
root |
1.3 |
typedef struct |
191 |
|
|
{ |
192 |
root |
1.1 |
IV iv; |
193 |
|
|
const char *name; |
194 |
root |
1.3 |
#define const_iv(name) { (IV)CL_ ## name, # name }, |
195 |
|
|
} ivstr; |
196 |
root |
1.1 |
|
197 |
|
|
static const char * |
198 |
root |
1.3 |
iv2str (IV value, const ivstr *base, int count, const char *fallback) |
199 |
root |
1.1 |
{ |
200 |
|
|
int i; |
201 |
root |
1.3 |
static char strbuf [32]; |
202 |
|
|
|
203 |
|
|
for (i = count; i--; ) |
204 |
|
|
if (base [i].iv == value) |
205 |
|
|
return base [i].name; |
206 |
|
|
|
207 |
|
|
snprintf (strbuf, sizeof (strbuf), fallback, (int)value); |
208 |
|
|
|
209 |
|
|
return strbuf; |
210 |
|
|
} |
211 |
|
|
|
212 |
|
|
static const char * |
213 |
|
|
enum2str (cl_uint value) |
214 |
|
|
{ |
215 |
|
|
static const ivstr enumstr[] = { |
216 |
|
|
#include "enumstr.h" |
217 |
|
|
}; |
218 |
root |
1.1 |
|
219 |
root |
1.3 |
return iv2str (value, enumstr, sizeof (enumstr) / sizeof (enumstr [0]), "ENUM(0x%04x)"); |
220 |
|
|
} |
221 |
root |
1.1 |
|
222 |
root |
1.3 |
static const char * |
223 |
|
|
err2str (cl_int err) |
224 |
|
|
{ |
225 |
|
|
static const ivstr errstr[] = { |
226 |
|
|
#include "errstr.h" |
227 |
|
|
}; |
228 |
root |
1.1 |
|
229 |
root |
1.3 |
return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)"); |
230 |
root |
1.1 |
} |
231 |
|
|
|
232 |
root |
1.5 |
/*****************************************************************************/ |
233 |
|
|
|
234 |
root |
1.8 |
static cl_int res; |
235 |
root |
1.5 |
|
236 |
root |
1.8 |
#define FAIL(name) \ |
237 |
|
|
croak ("cl" # name ": %s", err2str (res)); |
238 |
root |
1.1 |
|
239 |
|
|
#define NEED_SUCCESS(name,args) \ |
240 |
|
|
do { \ |
241 |
root |
1.8 |
res = cl ## name args; \ |
242 |
root |
1.1 |
\ |
243 |
|
|
if (res) \ |
244 |
root |
1.8 |
FAIL (name); \ |
245 |
root |
1.1 |
} while (0) |
246 |
|
|
|
247 |
root |
1.8 |
#define NEED_SUCCESS_ARG(retdecl, name, args) \ |
248 |
|
|
retdecl = cl ## name args; \ |
249 |
|
|
if (res) \ |
250 |
|
|
FAIL (name); |
251 |
|
|
|
252 |
root |
1.5 |
/*****************************************************************************/ |
253 |
|
|
|
254 |
root |
1.65 |
static SV * |
255 |
|
|
new_clobj (HV *stash, IV id) |
256 |
|
|
{ |
257 |
|
|
return sv_2mortal (sv_bless (newRV_noinc (newSViv (id)), stash)); |
258 |
|
|
} |
259 |
|
|
|
260 |
|
|
#define PUSH_CLOBJ(stash,id) PUSHs (new_clobj ((stash), (IV)(id))) |
261 |
|
|
#define XPUSH_CLOBJ(stash,id) XPUSHs (new_clobj ((stash), (IV)(id))) |
262 |
|
|
|
263 |
|
|
/* cl objects are either \$iv, or [$iv, ...] */ |
264 |
|
|
/* they can be upgraded at runtime to the array form */ |
265 |
|
|
static void * ecb_noinline |
266 |
root |
1.71 |
SvCLOBJ (CV *cv, const char *svname, SV *sv, const char *pkg) |
267 |
root |
1.65 |
{ |
268 |
|
|
// sv_derived_from is quite slow :( |
269 |
|
|
if (SvROK (sv) && sv_derived_from (sv, pkg)) |
270 |
|
|
return (void *)SvIV (SvRV (sv)); |
271 |
|
|
|
272 |
root |
1.71 |
croak ("%s: %s is not of type %s", cv_get_name (cv), svname, pkg); |
273 |
root |
1.65 |
} |
274 |
|
|
|
275 |
|
|
// the "no-inherit" version of the above |
276 |
|
|
static void * ecb_noinline |
277 |
root |
1.71 |
SvCLOBJ_ni (CV *cv, const char *svname, SV *sv, HV *stash) |
278 |
root |
1.65 |
{ |
279 |
|
|
if (SvROK (sv) && SvSTASH (SvRV (sv)) == stash) |
280 |
|
|
return (void *)SvIV (SvRV (sv)); |
281 |
|
|
|
282 |
root |
1.71 |
croak ("%s: %s is not of type %s", cv_get_name (cv), svname, HvNAME (stash)); |
283 |
root |
1.65 |
} |
284 |
|
|
|
285 |
|
|
/*****************************************************************************/ |
286 |
|
|
|
287 |
root |
1.64 |
static cl_context_properties * ecb_noinline |
288 |
root |
1.71 |
SvCONTEXTPROPERTIES (CV *cv, const char *svname, SV *sv, cl_context_properties *extra, int extracount) |
289 |
root |
1.24 |
{ |
290 |
|
|
if (!sv || !SvOK (sv)) |
291 |
|
|
if (extra) |
292 |
|
|
sv = sv_2mortal (newRV_noinc ((SV *)newAV ())); // slow, but rarely used hopefully |
293 |
|
|
else |
294 |
|
|
return 0; |
295 |
|
|
|
296 |
|
|
if (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVAV) |
297 |
|
|
{ |
298 |
|
|
AV *av = (AV *)SvRV (sv); |
299 |
root |
1.28 |
int i, len = av_len (av) + 1; |
300 |
root |
1.24 |
cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1)); |
301 |
|
|
cl_context_properties *l = p; |
302 |
|
|
|
303 |
|
|
if (len & 1) |
304 |
root |
1.71 |
croak ("%s: %s is not a property list (must contain an even number of elements)", cv_get_name (cv), svname); |
305 |
root |
1.24 |
|
306 |
|
|
while (extracount--) |
307 |
|
|
*l++ = *extra++; |
308 |
|
|
|
309 |
root |
1.29 |
for (i = 0; i < len; i += 2) |
310 |
root |
1.24 |
{ |
311 |
root |
1.29 |
cl_context_properties t = SvIV (*av_fetch (av, i , 0)); |
312 |
|
|
SV *p_sv = *av_fetch (av, i + 1, 0); |
313 |
root |
1.32 |
cl_context_properties v = SvIV (p_sv); // code below can override |
314 |
root |
1.24 |
|
315 |
|
|
switch (t) |
316 |
|
|
{ |
317 |
root |
1.65 |
case CL_CONTEXT_PLATFORM: |
318 |
|
|
if (SvROK (p_sv)) |
319 |
root |
1.71 |
v = (cl_context_properties)SvCLOBJ (cv, svname, p_sv, "OpenCL::Platform"); |
320 |
root |
1.65 |
break; |
321 |
|
|
|
322 |
root |
1.32 |
case CL_GLX_DISPLAY_KHR: |
323 |
|
|
if (!SvOK (p_sv)) |
324 |
|
|
{ |
325 |
|
|
void *func = glsym ("_glXGetCurrentDisplay"); |
326 |
|
|
if (func) |
327 |
|
|
v = (cl_context_properties)((void *(*)(void))func)(); |
328 |
|
|
} |
329 |
|
|
break; |
330 |
|
|
|
331 |
|
|
case CL_GL_CONTEXT_KHR: |
332 |
|
|
if (!SvOK (p_sv)) |
333 |
|
|
{ |
334 |
|
|
void *func = glsym ("_glXGetCurrentContext"); |
335 |
|
|
if (func) |
336 |
|
|
v = (cl_context_properties)((void *(*)(void))func)(); |
337 |
|
|
} |
338 |
|
|
break; |
339 |
|
|
|
340 |
root |
1.24 |
default: |
341 |
|
|
/* unknown property, treat as int */ |
342 |
|
|
break; |
343 |
|
|
} |
344 |
|
|
|
345 |
|
|
*l++ = t; |
346 |
|
|
*l++ = v; |
347 |
|
|
} |
348 |
|
|
|
349 |
|
|
*l = 0; |
350 |
|
|
|
351 |
|
|
return p; |
352 |
|
|
} |
353 |
|
|
|
354 |
root |
1.71 |
croak ("%s: %s is not a property list (either undef or [type => value, ...])", cv_get_name (cv), svname); |
355 |
root |
1.24 |
} |
356 |
|
|
|
357 |
root |
1.71 |
// parse an array of CLOBJ into a void ** array in C - works only for CLOBJs whose representation |
358 |
|
|
// is a pointer (and only on well-behaved systems). |
359 |
root |
1.69 |
static void * ecb_noinline |
360 |
|
|
object_list (CV *cv, int or_undef, const char *argname, SV *arg, const char *klass, cl_uint *rcount) |
361 |
|
|
{ |
362 |
|
|
if (!SvROK (arg) || SvTYPE (SvRV (arg)) != SVt_PVAV) |
363 |
|
|
croak ("%s: '%s' parameter must be %sa reference to an array of %s objects", |
364 |
root |
1.71 |
cv_get_name (cv), argname, or_undef ? "undef or " : "", klass); |
365 |
root |
1.69 |
|
366 |
|
|
AV *av = (AV *)SvRV (arg); |
367 |
|
|
void **list = 0; |
368 |
|
|
cl_uint count = av_len (av) + 1; |
369 |
|
|
|
370 |
|
|
if (count) |
371 |
|
|
{ |
372 |
|
|
list = tmpbuf (sizeof (*list) * count); |
373 |
|
|
int i; |
374 |
|
|
for (i = 0; i < count; ++i) |
375 |
root |
1.71 |
list [i] = SvCLOBJ (cv, argname, *av_fetch (av, i, 1), klass); |
376 |
root |
1.69 |
} |
377 |
|
|
|
378 |
|
|
if (!count && !or_undef) |
379 |
|
|
croak ("%s: '%s' must contain at least one %s object", |
380 |
root |
1.71 |
cv_get_name (cv), argname, klass); |
381 |
root |
1.69 |
|
382 |
|
|
*rcount = count; |
383 |
|
|
return (void *)list; |
384 |
|
|
} |
385 |
|
|
|
386 |
root |
1.24 |
/*****************************************************************************/ |
387 |
root |
1.51 |
/* callback stuff */ |
388 |
|
|
|
389 |
|
|
/* default context callback, log to stderr */ |
390 |
|
|
static void CL_CALLBACK |
391 |
|
|
context_default_notify (const char *msg, const void *info, size_t cb, void *data) |
392 |
|
|
{ |
393 |
|
|
fprintf (stderr, "OpenCL Context Notify: %s\n", msg); |
394 |
|
|
} |
395 |
|
|
|
396 |
|
|
typedef struct |
397 |
|
|
{ |
398 |
|
|
int free_cb; |
399 |
|
|
void (*push)(void *data1, void *data2, void *data3); |
400 |
|
|
} eq_vtbl; |
401 |
|
|
|
402 |
|
|
typedef struct eq_item |
403 |
|
|
{ |
404 |
|
|
struct eq_item *next; |
405 |
|
|
eq_vtbl *vtbl; |
406 |
|
|
SV *cb; |
407 |
|
|
void *data1, *data2, *data3; |
408 |
|
|
} eq_item; |
409 |
|
|
|
410 |
|
|
static void (*eq_signal_func)(void *signal_arg, int value); |
411 |
|
|
static void *eq_signal_arg; |
412 |
|
|
static xmutex_t eq_lock = X_MUTEX_INIT; |
413 |
|
|
static eq_item *eq_head, *eq_tail; |
414 |
|
|
|
415 |
root |
1.64 |
static void ecb_noinline |
416 |
root |
1.51 |
eq_enq (eq_vtbl *vtbl, SV *cb, void *data1, void *data2, void *data3) |
417 |
|
|
{ |
418 |
|
|
eq_item *item = malloc (sizeof (eq_item)); |
419 |
|
|
|
420 |
|
|
item->next = 0; |
421 |
|
|
item->vtbl = vtbl; |
422 |
|
|
item->cb = cb; |
423 |
|
|
item->data1 = data1; |
424 |
|
|
item->data2 = data2; |
425 |
|
|
item->data3 = data3; |
426 |
|
|
|
427 |
|
|
X_LOCK (eq_lock); |
428 |
|
|
|
429 |
|
|
*(eq_head ? &eq_tail->next : &eq_head) = item; |
430 |
|
|
eq_tail = item; |
431 |
|
|
|
432 |
|
|
X_UNLOCK (eq_lock); |
433 |
|
|
|
434 |
|
|
eq_signal_func (eq_signal_arg, 0); |
435 |
|
|
} |
436 |
|
|
|
437 |
|
|
static eq_item * |
438 |
|
|
eq_dec (void) |
439 |
|
|
{ |
440 |
|
|
eq_item *res; |
441 |
|
|
|
442 |
|
|
X_LOCK (eq_lock); |
443 |
|
|
|
444 |
|
|
res = eq_head; |
445 |
|
|
if (res) |
446 |
|
|
eq_head = res->next; |
447 |
|
|
|
448 |
|
|
X_UNLOCK (eq_lock); |
449 |
|
|
|
450 |
|
|
return res; |
451 |
|
|
} |
452 |
|
|
|
453 |
|
|
static void |
454 |
|
|
eq_poll (void) |
455 |
|
|
{ |
456 |
|
|
eq_item *item; |
457 |
|
|
|
458 |
|
|
while ((item = eq_dec ())) |
459 |
|
|
{ |
460 |
|
|
ENTER; |
461 |
|
|
SAVETMPS; |
462 |
|
|
|
463 |
|
|
dSP; |
464 |
|
|
PUSHMARK (SP); |
465 |
|
|
EXTEND (SP, 2); |
466 |
|
|
|
467 |
|
|
if (item->vtbl->free_cb) |
468 |
|
|
sv_2mortal (item->cb); |
469 |
|
|
|
470 |
|
|
PUTBACK; |
471 |
|
|
item->vtbl->push (item->data1, item->data2, item->data3); |
472 |
|
|
|
473 |
|
|
SV *cb = item->cb; |
474 |
|
|
free (item); |
475 |
|
|
|
476 |
|
|
call_sv (cb, G_DISCARD | G_VOID); |
477 |
|
|
|
478 |
|
|
FREETMPS; |
479 |
|
|
LEAVE; |
480 |
|
|
} |
481 |
|
|
} |
482 |
|
|
|
483 |
|
|
static void |
484 |
|
|
eq_poll_interrupt (pTHX_ void *c_arg, int value) |
485 |
|
|
{ |
486 |
|
|
eq_poll (); |
487 |
|
|
} |
488 |
|
|
|
489 |
root |
1.52 |
/*****************************************************************************/ |
490 |
root |
1.51 |
/* context notify */ |
491 |
|
|
|
492 |
root |
1.64 |
static void ecb_noinline |
493 |
root |
1.51 |
eq_context_push (void *data1, void *data2, void *data3) |
494 |
|
|
{ |
495 |
|
|
dSP; |
496 |
|
|
PUSHs (sv_2mortal (newSVpv (data1, 0))); |
497 |
|
|
PUSHs (sv_2mortal (newSVpvn (data2, (STRLEN)data3))); |
498 |
|
|
PUTBACK; |
499 |
root |
1.52 |
|
500 |
|
|
free (data1); |
501 |
|
|
free (data2); |
502 |
root |
1.51 |
} |
503 |
|
|
|
504 |
|
|
static eq_vtbl eq_context_vtbl = { 0, eq_context_push }; |
505 |
|
|
|
506 |
root |
1.52 |
static void CL_CALLBACK |
507 |
|
|
eq_context_notify (const char *msg, const void *pvt, size_t cb, void *user_data) |
508 |
|
|
{ |
509 |
|
|
void *pvt_copy = malloc (cb); |
510 |
|
|
memcpy (pvt_copy, pvt, cb); |
511 |
|
|
eq_enq (&eq_context_vtbl, user_data, strdup (msg), pvt_copy, (void *)cb); |
512 |
|
|
} |
513 |
|
|
|
514 |
|
|
#define CONTEXT_NOTIFY_CALLBACK \ |
515 |
|
|
void (CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *) = context_default_notify; \ |
516 |
|
|
void *user_data = 0; \ |
517 |
|
|
\ |
518 |
|
|
if (SvOK (notify)) \ |
519 |
|
|
{ \ |
520 |
|
|
pfn_notify = eq_context_notify; \ |
521 |
|
|
user_data = s_get_cv (notify); \ |
522 |
|
|
} |
523 |
|
|
|
524 |
root |
1.64 |
static SV * ecb_noinline |
525 |
root |
1.52 |
new_clobj_context (cl_context ctx, void *user_data) |
526 |
|
|
{ |
527 |
root |
1.61 |
SV *sv = new_clobj (stash_context, (IV)ctx); |
528 |
root |
1.52 |
|
529 |
|
|
if (user_data) |
530 |
|
|
sv_magicext (SvRV (sv), user_data, PERL_MAGIC_ext, 0, 0, 0); |
531 |
|
|
|
532 |
|
|
return sv; |
533 |
|
|
} |
534 |
|
|
|
535 |
|
|
#define XPUSH_CLOBJ_CONTEXT XPUSHs (new_clobj_context (ctx, user_data)); |
536 |
|
|
|
537 |
|
|
/*****************************************************************************/ |
538 |
root |
1.51 |
/* build/compile/link notify */ |
539 |
|
|
|
540 |
|
|
static void |
541 |
|
|
eq_program_push (void *data1, void *data2, void *data3) |
542 |
|
|
{ |
543 |
|
|
dSP; |
544 |
root |
1.61 |
PUSH_CLOBJ (stash_program, data1); |
545 |
root |
1.51 |
PUTBACK; |
546 |
|
|
} |
547 |
|
|
|
548 |
|
|
static eq_vtbl eq_program_vtbl = { 1, eq_program_push }; |
549 |
|
|
|
550 |
|
|
static void CL_CALLBACK |
551 |
|
|
eq_program_notify (cl_program program, void *user_data) |
552 |
|
|
{ |
553 |
root |
1.69 |
clRetainProgram (program); |
554 |
|
|
|
555 |
root |
1.51 |
eq_enq (&eq_program_vtbl, user_data, (void *)program, 0, 0); |
556 |
|
|
} |
557 |
|
|
|
558 |
root |
1.69 |
typedef void (CL_CALLBACK *program_callback)(cl_program program, void *user_data); |
559 |
|
|
|
560 |
|
|
static program_callback ecb_noinline |
561 |
|
|
make_program_callback (SV *notify, void **ruser_data) |
562 |
|
|
{ |
563 |
|
|
if (SvOK (notify)) |
564 |
|
|
{ |
565 |
|
|
*ruser_data = SvREFCNT_inc (s_get_cv (notify)); |
566 |
|
|
return eq_program_notify; |
567 |
|
|
} |
568 |
|
|
else |
569 |
|
|
{ |
570 |
|
|
*ruser_data = 0; |
571 |
|
|
return 0; |
572 |
|
|
} |
573 |
|
|
} |
574 |
|
|
|
575 |
root |
1.51 |
struct build_args |
576 |
|
|
{ |
577 |
|
|
cl_program program; |
578 |
|
|
char *options; |
579 |
|
|
void *user_data; |
580 |
|
|
cl_uint num_devices; |
581 |
|
|
}; |
582 |
|
|
|
583 |
|
|
X_THREAD_PROC (build_program_thread) |
584 |
|
|
{ |
585 |
|
|
struct build_args *arg = thr_arg; |
586 |
|
|
|
587 |
|
|
clBuildProgram (arg->program, arg->num_devices, arg->num_devices ? (void *)(arg + 1) : 0, arg->options, 0, 0); |
588 |
|
|
|
589 |
|
|
if (arg->user_data) |
590 |
|
|
eq_program_notify (arg->program, arg->user_data); |
591 |
|
|
else |
592 |
|
|
clReleaseProgram (arg->program); |
593 |
|
|
|
594 |
|
|
free (arg->options); |
595 |
|
|
free (arg); |
596 |
root |
1.64 |
|
597 |
|
|
return 0; |
598 |
root |
1.51 |
} |
599 |
|
|
|
600 |
|
|
static void |
601 |
|
|
build_program_async (cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, void *user_data) |
602 |
|
|
{ |
603 |
|
|
struct build_args *arg = malloc (sizeof (struct build_args) + sizeof (*device_list) * num_devices); |
604 |
|
|
|
605 |
|
|
arg->program = program; |
606 |
|
|
arg->options = strdup (options); |
607 |
|
|
arg->user_data = user_data; |
608 |
|
|
arg->num_devices = num_devices; |
609 |
|
|
memcpy (arg + 1, device_list, sizeof (*device_list) * num_devices); |
610 |
|
|
|
611 |
|
|
xthread_t id; |
612 |
|
|
thread_create (&id, build_program_thread, arg); |
613 |
|
|
} |
614 |
|
|
|
615 |
root |
1.52 |
/*****************************************************************************/ |
616 |
root |
1.51 |
/* event objects */ |
617 |
|
|
|
618 |
|
|
static void |
619 |
|
|
eq_event_push (void *data1, void *data2, void *data3) |
620 |
|
|
{ |
621 |
|
|
dSP; |
622 |
root |
1.61 |
PUSH_CLOBJ (stash_event, data1); |
623 |
root |
1.51 |
PUSHs (sv_2mortal (newSViv ((IV)data2))); |
624 |
|
|
PUTBACK; |
625 |
|
|
} |
626 |
|
|
|
627 |
|
|
static eq_vtbl eq_event_vtbl = { 1, eq_event_push }; |
628 |
|
|
|
629 |
|
|
static void CL_CALLBACK |
630 |
|
|
eq_event_notify (cl_event event, cl_int event_command_exec_status, void *user_data) |
631 |
|
|
{ |
632 |
|
|
clRetainEvent (event); |
633 |
root |
1.52 |
eq_enq (&eq_event_vtbl, user_data, (void *)event, (void *)(IV)event_command_exec_status, 0); |
634 |
root |
1.51 |
} |
635 |
|
|
|
636 |
|
|
/*****************************************************************************/ |
637 |
root |
1.62 |
/* utilities for XS code */ |
638 |
|
|
|
639 |
|
|
static size_t |
640 |
|
|
img_row_pitch (cl_mem img) |
641 |
|
|
{ |
642 |
|
|
size_t res; |
643 |
|
|
clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); |
644 |
|
|
return res; |
645 |
|
|
} |
646 |
|
|
|
647 |
root |
1.64 |
static cl_event * ecb_noinline |
648 |
root |
1.71 |
event_list (CV *cv, SV **items, cl_uint *rcount, cl_event extra) |
649 |
root |
1.62 |
{ |
650 |
|
|
cl_uint count = *rcount; |
651 |
|
|
|
652 |
root |
1.64 |
if (count > 0x7fffffffU) // yeah, it's a hack - the caller might have underflowed |
653 |
|
|
*rcount = count = 0; |
654 |
root |
1.62 |
|
655 |
|
|
if (!count && !extra) |
656 |
|
|
return 0; |
657 |
|
|
|
658 |
|
|
cl_event *list = tmpbuf (sizeof (cl_event) * (count + 1)); |
659 |
|
|
int i = 0; |
660 |
|
|
|
661 |
|
|
while (count--) |
662 |
|
|
if (SvOK (items [count])) |
663 |
root |
1.71 |
list [i++] = SvCLOBJ (cv, "wait_events", items [count], "OpenCL::Event"); |
664 |
root |
1.62 |
|
665 |
|
|
if (extra) |
666 |
|
|
list [i++] = extra; |
667 |
|
|
|
668 |
|
|
*rcount = i; |
669 |
|
|
|
670 |
|
|
return i ? list : 0; |
671 |
|
|
} |
672 |
|
|
|
673 |
|
|
#define EVENT_LIST(skip) \ |
674 |
|
|
cl_uint event_list_count = items - (skip); \ |
675 |
root |
1.71 |
cl_event *event_list_ptr = event_list (cv, &ST (skip), &event_list_count, 0) |
676 |
root |
1.62 |
|
677 |
|
|
#define INFO(class) \ |
678 |
|
|
{ \ |
679 |
|
|
size_t size; \ |
680 |
|
|
NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ |
681 |
|
|
SV *sv = sv_2mortal (newSV (size)); \ |
682 |
|
|
SvUPGRADE (sv, SVt_PV); \ |
683 |
|
|
SvPOK_only (sv); \ |
684 |
|
|
SvCUR_set (sv, size); \ |
685 |
|
|
NEED_SUCCESS (Get ## class ## Info, (self, name, size, SvPVX (sv), 0)); \ |
686 |
|
|
XPUSHs (sv); \ |
687 |
|
|
} |
688 |
|
|
|
689 |
|
|
/*****************************************************************************/ |
690 |
root |
1.61 |
/* mapped_xxx */ |
691 |
|
|
|
692 |
|
|
static OpenCL__Mapped |
693 |
|
|
SvMAPPED (SV *sv) |
694 |
|
|
{ |
695 |
|
|
// no typechecking atm., keep your fingers crossed |
696 |
|
|
return (OpenCL__Mapped)SvMAGIC (SvRV (sv))->mg_ptr; |
697 |
|
|
} |
698 |
|
|
|
699 |
|
|
struct mapped |
700 |
|
|
{ |
701 |
|
|
cl_command_queue queue; |
702 |
|
|
cl_mem memobj; |
703 |
|
|
void *ptr; |
704 |
|
|
size_t cb; |
705 |
|
|
cl_event event; |
706 |
|
|
size_t row_pitch; |
707 |
|
|
size_t slice_pitch; |
708 |
|
|
}; |
709 |
|
|
|
710 |
|
|
static SV * |
711 |
|
|
mapped_new (HV *stash, cl_command_queue queue, cl_mem memobj, cl_map_flags flags, void *ptr, size_t cb, cl_event ev, size_t row_pitch, size_t slice_pitch) |
712 |
|
|
{ |
713 |
|
|
SV *data = newSV (0); |
714 |
|
|
SvUPGRADE (data, SVt_PVMG); |
715 |
|
|
|
716 |
|
|
OpenCL__Mapped mapped; |
717 |
|
|
New (0, mapped, 1, struct mapped); |
718 |
|
|
|
719 |
|
|
clRetainCommandQueue (queue); |
720 |
|
|
|
721 |
|
|
mapped->queue = queue; |
722 |
|
|
mapped->memobj = memobj; |
723 |
|
|
mapped->ptr = ptr; |
724 |
|
|
mapped->cb = cb; |
725 |
|
|
mapped->event = ev; |
726 |
|
|
mapped->row_pitch = row_pitch; |
727 |
|
|
mapped->slice_pitch = slice_pitch; |
728 |
|
|
|
729 |
|
|
sv_magicext (data, 0, PERL_MAGIC_ext, 0, (char *)mapped, 0); |
730 |
|
|
|
731 |
|
|
if (SvLEN (data)) |
732 |
|
|
Safefree (data); |
733 |
|
|
|
734 |
|
|
SvPVX (data) = (char *)ptr; |
735 |
|
|
SvCUR_set (data, cb); |
736 |
|
|
SvLEN_set (data, 0); |
737 |
|
|
SvPOK_only (data); |
738 |
|
|
|
739 |
root |
1.62 |
SV *obj = sv_2mortal (sv_bless (newRV_noinc (data), stash)); |
740 |
|
|
|
741 |
|
|
if (!(flags & CL_MAP_WRITE)) |
742 |
|
|
SvREADONLY_on (data); |
743 |
|
|
|
744 |
|
|
return obj; |
745 |
root |
1.61 |
} |
746 |
|
|
|
747 |
|
|
static void |
748 |
|
|
mapped_detach (SV *sv, OpenCL__Mapped mapped) |
749 |
|
|
{ |
750 |
|
|
SV *data = SvRV (sv); |
751 |
|
|
|
752 |
root |
1.62 |
// the next check checks both before AND after detach, where SvPVX should STILL be 0 |
753 |
root |
1.61 |
if (SvPVX (data) != (char *)mapped->ptr) |
754 |
|
|
warn ("FATAL: OpenCL memory mapped scalar changed location, detected"); |
755 |
|
|
else |
756 |
|
|
{ |
757 |
|
|
SvREADONLY_off (data); |
758 |
|
|
SvCUR_set (data, 0); |
759 |
|
|
SvPVX (data) = 0; |
760 |
|
|
SvOK_off (data); |
761 |
|
|
} |
762 |
|
|
|
763 |
|
|
mapped->ptr = 0; |
764 |
|
|
} |
765 |
|
|
|
766 |
root |
1.62 |
static void |
767 |
root |
1.71 |
mapped_unmap (CV *cv, SV *self, OpenCL__Mapped mapped, cl_command_queue queue, SV **wait_list, cl_uint event_list_count) |
768 |
root |
1.11 |
{ |
769 |
root |
1.71 |
cl_event *event_list_ptr = event_list (cv, wait_list, &event_list_count, mapped->event); |
770 |
root |
1.62 |
cl_event ev; |
771 |
root |
1.11 |
|
772 |
root |
1.62 |
NEED_SUCCESS (EnqueueUnmapMemObject, (queue, mapped->memobj, mapped->ptr, event_list_count, event_list_ptr, &ev)); |
773 |
root |
1.35 |
|
774 |
root |
1.62 |
clReleaseEvent (mapped->event); |
775 |
|
|
mapped->event = ev; |
776 |
root |
1.61 |
|
777 |
root |
1.62 |
mapped_detach (self, mapped); |
778 |
root |
1.5 |
} |
779 |
|
|
|
780 |
root |
1.62 |
/*****************************************************************************/ |
781 |
root |
1.2 |
|
782 |
root |
1.1 |
MODULE = OpenCL PACKAGE = OpenCL |
783 |
|
|
|
784 |
root |
1.2 |
PROTOTYPES: ENABLE |
785 |
|
|
|
786 |
root |
1.51 |
void |
787 |
|
|
poll () |
788 |
|
|
CODE: |
789 |
|
|
eq_poll (); |
790 |
|
|
|
791 |
|
|
void |
792 |
|
|
_eq_initialise (IV func, IV arg) |
793 |
|
|
CODE: |
794 |
|
|
eq_signal_func = (void (*)(void *, int))func; |
795 |
|
|
eq_signal_arg = (void*)arg; |
796 |
|
|
|
797 |
root |
1.1 |
BOOT: |
798 |
|
|
{ |
799 |
root |
1.24 |
HV *stash = gv_stashpv ("OpenCL", 1); |
800 |
|
|
static const ivstr *civ, const_iv[] = { |
801 |
|
|
{ sizeof (cl_char ), "SIZEOF_CHAR" }, |
802 |
|
|
{ sizeof (cl_uchar ), "SIZEOF_UCHAR" }, |
803 |
|
|
{ sizeof (cl_short ), "SIZEOF_SHORT" }, |
804 |
|
|
{ sizeof (cl_ushort), "SIZEOF_USHORT" }, |
805 |
|
|
{ sizeof (cl_int ), "SIZEOF_INT" }, |
806 |
|
|
{ sizeof (cl_uint ), "SIZEOF_UINT" }, |
807 |
|
|
{ sizeof (cl_long ), "SIZEOF_LONG" }, |
808 |
|
|
{ sizeof (cl_ulong ), "SIZEOF_ULONG" }, |
809 |
|
|
{ sizeof (cl_half ), "SIZEOF_HALF" }, |
810 |
|
|
{ sizeof (cl_float ), "SIZEOF_FLOAT" }, |
811 |
|
|
{ sizeof (cl_double), "SIZEOF_DOUBLE" }, |
812 |
root |
1.72 |
{ PREFER_1_1 , "PREFER_1_1" }, |
813 |
root |
1.1 |
#include "constiv.h" |
814 |
root |
1.24 |
}; |
815 |
root |
1.51 |
|
816 |
root |
1.24 |
for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
817 |
|
|
newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
818 |
root |
1.51 |
|
819 |
root |
1.61 |
stash_platform = gv_stashpv ("OpenCL::Platform", GV_ADD); |
820 |
|
|
stash_device = gv_stashpv ("OpenCL::Device", GV_ADD); |
821 |
root |
1.65 |
stash_subdevice = gv_stashpv ("OpenCL::SubDevice", GV_ADD); |
822 |
root |
1.61 |
stash_context = gv_stashpv ("OpenCL::Context", GV_ADD); |
823 |
|
|
stash_queue = gv_stashpv ("OpenCL::Queue", GV_ADD); |
824 |
|
|
stash_program = gv_stashpv ("OpenCL::Program", GV_ADD); |
825 |
|
|
stash_kernel = gv_stashpv ("OpenCL::Kernel", GV_ADD); |
826 |
|
|
stash_sampler = gv_stashpv ("OpenCL::Sampler", GV_ADD); |
827 |
|
|
stash_event = gv_stashpv ("OpenCL::Event", GV_ADD); |
828 |
|
|
stash_userevent = gv_stashpv ("OpenCL::UserEvent", GV_ADD); |
829 |
|
|
stash_memory = gv_stashpv ("OpenCL::Memory", GV_ADD); |
830 |
|
|
stash_buffer = gv_stashpv ("OpenCL::Buffer", GV_ADD); |
831 |
|
|
stash_bufferobj = gv_stashpv ("OpenCL::BufferObj", GV_ADD); |
832 |
|
|
stash_image = gv_stashpv ("OpenCL::Image", GV_ADD); |
833 |
|
|
stash_image1d = gv_stashpv ("OpenCL::Image1D", GV_ADD); |
834 |
|
|
stash_image1darray = gv_stashpv ("OpenCL::Image1DArray", GV_ADD); |
835 |
|
|
stash_image1dbuffer = gv_stashpv ("OpenCL::Image1DBuffer", GV_ADD); |
836 |
|
|
stash_image2d = gv_stashpv ("OpenCL::Image2D", GV_ADD); |
837 |
|
|
stash_image2darray = gv_stashpv ("OpenCL::Image2DArray", GV_ADD); |
838 |
|
|
stash_image3d = gv_stashpv ("OpenCL::Image3D", GV_ADD); |
839 |
|
|
stash_mapped = gv_stashpv ("OpenCL::Mapped", GV_ADD); |
840 |
|
|
stash_mappedbuffer = gv_stashpv ("OpenCL::MappedBuffer", GV_ADD); |
841 |
|
|
stash_mappedimage = gv_stashpv ("OpenCL::MappedImage", GV_ADD); |
842 |
|
|
|
843 |
root |
1.51 |
sv_setiv (perl_get_sv ("OpenCL::POLL_FUNC", TRUE), (IV)eq_poll_interrupt); |
844 |
root |
1.1 |
} |
845 |
|
|
|
846 |
root |
1.5 |
cl_int |
847 |
|
|
errno () |
848 |
|
|
CODE: |
849 |
root |
1.37 |
RETVAL = res; |
850 |
|
|
OUTPUT: |
851 |
|
|
RETVAL |
852 |
root |
1.5 |
|
853 |
root |
1.3 |
const char * |
854 |
root |
1.57 |
err2str (cl_int err = res) |
855 |
root |
1.3 |
|
856 |
|
|
const char * |
857 |
|
|
enum2str (cl_uint value) |
858 |
|
|
|
859 |
root |
1.1 |
void |
860 |
|
|
platforms () |
861 |
|
|
PPCODE: |
862 |
|
|
cl_platform_id *list; |
863 |
|
|
cl_uint count; |
864 |
|
|
int i; |
865 |
|
|
|
866 |
root |
1.2 |
NEED_SUCCESS (GetPlatformIDs, (0, 0, &count)); |
867 |
root |
1.4 |
list = tmpbuf (sizeof (*list) * count); |
868 |
root |
1.2 |
NEED_SUCCESS (GetPlatformIDs, (count, list, 0)); |
869 |
root |
1.1 |
|
870 |
|
|
EXTEND (SP, count); |
871 |
|
|
for (i = 0; i < count; ++i) |
872 |
root |
1.65 |
PUSH_CLOBJ (stash_platform, list [i]); |
873 |
root |
1.1 |
|
874 |
|
|
void |
875 |
root |
1.52 |
context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef) |
876 |
root |
1.1 |
PPCODE: |
877 |
root |
1.52 |
CONTEXT_NOTIFY_CALLBACK; |
878 |
root |
1.64 |
NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, pfn_notify, user_data, &res)); |
879 |
root |
1.52 |
XPUSH_CLOBJ_CONTEXT; |
880 |
root |
1.37 |
|
881 |
root |
1.8 |
void |
882 |
root |
1.71 |
context (cl_context_properties *properties, SV *devices, SV *notify = &PL_sv_undef) |
883 |
root |
1.8 |
PPCODE: |
884 |
root |
1.71 |
cl_uint device_count; |
885 |
|
|
cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); |
886 |
|
|
|
887 |
|
|
CONTEXT_NOTIFY_CALLBACK; |
888 |
|
|
NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (properties, device_count, device_list, pfn_notify, user_data, &res)); |
889 |
|
|
XPUSH_CLOBJ_CONTEXT; |
890 |
root |
1.1 |
|
891 |
root |
1.2 |
void |
892 |
|
|
wait_for_events (...) |
893 |
|
|
CODE: |
894 |
root |
1.61 |
EVENT_LIST (0); |
895 |
root |
1.2 |
NEED_SUCCESS (WaitForEvents, (event_list_count, event_list_ptr)); |
896 |
|
|
|
897 |
|
|
PROTOTYPES: DISABLE |
898 |
|
|
|
899 |
root |
1.1 |
MODULE = OpenCL PACKAGE = OpenCL::Platform |
900 |
|
|
|
901 |
|
|
void |
902 |
root |
1.22 |
info (OpenCL::Platform self, cl_platform_info name) |
903 |
root |
1.1 |
PPCODE: |
904 |
root |
1.2 |
INFO (Platform) |
905 |
root |
1.1 |
|
906 |
root |
1.47 |
void |
907 |
|
|
unload_compiler (OpenCL::Platform self) |
908 |
|
|
CODE: |
909 |
|
|
#if CL_VERSION_1_2 |
910 |
|
|
clUnloadPlatformCompiler (self); |
911 |
|
|
#endif |
912 |
|
|
|
913 |
root |
1.13 |
#BEGIN:platform |
914 |
|
|
|
915 |
|
|
void |
916 |
root |
1.22 |
profile (OpenCL::Platform self) |
917 |
root |
1.16 |
ALIAS: |
918 |
|
|
profile = CL_PLATFORM_PROFILE |
919 |
|
|
version = CL_PLATFORM_VERSION |
920 |
|
|
name = CL_PLATFORM_NAME |
921 |
|
|
vendor = CL_PLATFORM_VENDOR |
922 |
|
|
extensions = CL_PLATFORM_EXTENSIONS |
923 |
root |
1.14 |
PPCODE: |
924 |
|
|
size_t size; |
925 |
root |
1.22 |
NEED_SUCCESS (GetPlatformInfo, (self, ix, 0, 0, &size)); |
926 |
root |
1.14 |
char *value = tmpbuf (size); |
927 |
root |
1.22 |
NEED_SUCCESS (GetPlatformInfo, (self, ix, size, value, 0)); |
928 |
root |
1.16 |
EXTEND (SP, 1); |
929 |
|
|
const int i = 0; |
930 |
root |
1.14 |
PUSHs (sv_2mortal (newSVpv (value, 0))); |
931 |
root |
1.13 |
|
932 |
|
|
#END:platform |
933 |
|
|
|
934 |
root |
1.1 |
void |
935 |
root |
1.22 |
devices (OpenCL::Platform self, cl_device_type type = CL_DEVICE_TYPE_ALL) |
936 |
root |
1.1 |
PPCODE: |
937 |
|
|
cl_device_id *list; |
938 |
|
|
cl_uint count; |
939 |
|
|
int i; |
940 |
|
|
|
941 |
root |
1.22 |
NEED_SUCCESS (GetDeviceIDs, (self, type, 0, 0, &count)); |
942 |
root |
1.4 |
list = tmpbuf (sizeof (*list) * count); |
943 |
root |
1.22 |
NEED_SUCCESS (GetDeviceIDs, (self, type, count, list, 0)); |
944 |
root |
1.1 |
|
945 |
|
|
EXTEND (SP, count); |
946 |
|
|
for (i = 0; i < count; ++i) |
947 |
root |
1.61 |
PUSH_CLOBJ (stash_device, list [i]); |
948 |
root |
1.1 |
|
949 |
|
|
void |
950 |
root |
1.71 |
context (OpenCL::Platform self, SV *properties, SV *devices, SV *notify = &PL_sv_undef) |
951 |
root |
1.8 |
PPCODE: |
952 |
root |
1.64 |
cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self }; |
953 |
root |
1.71 |
cl_context_properties *props = SvCONTEXTPROPERTIES (cv, "properties", properties, extra, 2); |
954 |
root |
1.64 |
|
955 |
root |
1.71 |
cl_uint device_count; |
956 |
|
|
cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); |
957 |
root |
1.8 |
|
958 |
root |
1.52 |
CONTEXT_NOTIFY_CALLBACK; |
959 |
root |
1.69 |
NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (props, device_count, device_list, pfn_notify, user_data, &res)); |
960 |
root |
1.52 |
XPUSH_CLOBJ_CONTEXT; |
961 |
root |
1.8 |
|
962 |
|
|
void |
963 |
root |
1.52 |
context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, SV *notify = &PL_sv_undef) |
964 |
root |
1.1 |
PPCODE: |
965 |
root |
1.24 |
cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self }; |
966 |
root |
1.71 |
cl_context_properties *props = SvCONTEXTPROPERTIES (cv, "properties", properties, extra, 2); |
967 |
root |
1.52 |
|
968 |
|
|
CONTEXT_NOTIFY_CALLBACK; |
969 |
root |
1.64 |
NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, pfn_notify, user_data, &res)); |
970 |
root |
1.52 |
XPUSH_CLOBJ_CONTEXT; |
971 |
root |
1.1 |
|
972 |
root |
1.16 |
MODULE = OpenCL PACKAGE = OpenCL::Device |
973 |
root |
1.14 |
|
974 |
|
|
void |
975 |
root |
1.22 |
info (OpenCL::Device self, cl_device_info name) |
976 |
root |
1.16 |
PPCODE: |
977 |
|
|
INFO (Device) |
978 |
root |
1.14 |
|
979 |
root |
1.65 |
#if CL_VERSION_1_2 |
980 |
|
|
|
981 |
|
|
void |
982 |
|
|
sub_devices (OpenCL::Device self, SV *properties) |
983 |
|
|
PPCODE: |
984 |
|
|
if (!SvROK (properties) || SvTYPE (SvRV (properties)) != SVt_PVAV) |
985 |
|
|
croak ("OpenCL::Device::sub_devices: properties must be specified as reference to an array of property-value pairs"); |
986 |
|
|
|
987 |
|
|
properties = SvRV (properties); |
988 |
|
|
|
989 |
|
|
cl_uint count = av_len ((AV *)properties) + 1; |
990 |
|
|
cl_device_partition_property *props = tmpbuf (sizeof (*props) * count + 1); |
991 |
|
|
|
992 |
|
|
int i; |
993 |
|
|
for (i = 0; i < count; ++i) |
994 |
|
|
props [i] = (cl_device_partition_property)SvIV (*av_fetch ((AV *)properties, i, 0)); |
995 |
|
|
|
996 |
|
|
props [count] = 0; |
997 |
|
|
|
998 |
|
|
cl_uint num_devices; |
999 |
|
|
NEED_SUCCESS (CreateSubDevices, (self, props, 0, 0, &num_devices)); |
1000 |
|
|
cl_device_id *list = tmpbuf (sizeof (*list) * num_devices); |
1001 |
|
|
NEED_SUCCESS (CreateSubDevices, (self, props, num_devices, list, 0)); |
1002 |
|
|
|
1003 |
|
|
EXTEND (SP, num_devices); |
1004 |
|
|
for (i = 0; i < count; ++i) |
1005 |
|
|
PUSH_CLOBJ (stash_subdevice, list [i]); |
1006 |
|
|
|
1007 |
|
|
#endif |
1008 |
|
|
|
1009 |
root |
1.16 |
#BEGIN:device |
1010 |
root |
1.14 |
|
1011 |
|
|
void |
1012 |
root |
1.22 |
type (OpenCL::Device self) |
1013 |
root |
1.14 |
PPCODE: |
1014 |
root |
1.16 |
cl_device_type value [1]; |
1015 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_TYPE, sizeof (value), value, 0)); |
1016 |
root |
1.16 |
EXTEND (SP, 1); |
1017 |
|
|
const int i = 0; |
1018 |
root |
1.61 |
PUSHs (sv_2mortal (newSVuv (value [i]))); |
1019 |
root |
1.14 |
|
1020 |
|
|
void |
1021 |
root |
1.22 |
vendor_id (OpenCL::Device self) |
1022 |
root |
1.16 |
ALIAS: |
1023 |
|
|
vendor_id = CL_DEVICE_VENDOR_ID |
1024 |
|
|
max_compute_units = CL_DEVICE_MAX_COMPUTE_UNITS |
1025 |
|
|
max_work_item_dimensions = CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS |
1026 |
|
|
preferred_vector_width_char = CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR |
1027 |
|
|
preferred_vector_width_short = CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT |
1028 |
|
|
preferred_vector_width_int = CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT |
1029 |
|
|
preferred_vector_width_long = CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG |
1030 |
|
|
preferred_vector_width_float = CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT |
1031 |
|
|
preferred_vector_width_double = CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE |
1032 |
|
|
max_clock_frequency = CL_DEVICE_MAX_CLOCK_FREQUENCY |
1033 |
|
|
max_read_image_args = CL_DEVICE_MAX_READ_IMAGE_ARGS |
1034 |
|
|
max_write_image_args = CL_DEVICE_MAX_WRITE_IMAGE_ARGS |
1035 |
|
|
image_support = CL_DEVICE_IMAGE_SUPPORT |
1036 |
|
|
max_samplers = CL_DEVICE_MAX_SAMPLERS |
1037 |
|
|
mem_base_addr_align = CL_DEVICE_MEM_BASE_ADDR_ALIGN |
1038 |
|
|
min_data_type_align_size = CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE |
1039 |
|
|
global_mem_cacheline_size = CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE |
1040 |
|
|
max_constant_args = CL_DEVICE_MAX_CONSTANT_ARGS |
1041 |
|
|
preferred_vector_width_half = CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF |
1042 |
|
|
native_vector_width_char = CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR |
1043 |
|
|
native_vector_width_short = CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT |
1044 |
|
|
native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT |
1045 |
|
|
native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG |
1046 |
|
|
native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT |
1047 |
|
|
native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE |
1048 |
|
|
native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF |
1049 |
root |
1.41 |
reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT |
1050 |
root |
1.14 |
PPCODE: |
1051 |
|
|
cl_uint value [1]; |
1052 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0)); |
1053 |
root |
1.14 |
EXTEND (SP, 1); |
1054 |
|
|
const int i = 0; |
1055 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
1056 |
|
|
|
1057 |
|
|
void |
1058 |
root |
1.22 |
max_work_group_size (OpenCL::Device self) |
1059 |
root |
1.16 |
ALIAS: |
1060 |
|
|
max_work_group_size = CL_DEVICE_MAX_WORK_GROUP_SIZE |
1061 |
|
|
image2d_max_width = CL_DEVICE_IMAGE2D_MAX_WIDTH |
1062 |
|
|
image2d_max_height = CL_DEVICE_IMAGE2D_MAX_HEIGHT |
1063 |
|
|
image3d_max_width = CL_DEVICE_IMAGE3D_MAX_WIDTH |
1064 |
|
|
image3d_max_height = CL_DEVICE_IMAGE3D_MAX_HEIGHT |
1065 |
|
|
image3d_max_depth = CL_DEVICE_IMAGE3D_MAX_DEPTH |
1066 |
|
|
max_parameter_size = CL_DEVICE_MAX_PARAMETER_SIZE |
1067 |
|
|
profiling_timer_resolution = CL_DEVICE_PROFILING_TIMER_RESOLUTION |
1068 |
root |
1.14 |
PPCODE: |
1069 |
root |
1.16 |
size_t value [1]; |
1070 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0)); |
1071 |
root |
1.14 |
EXTEND (SP, 1); |
1072 |
|
|
const int i = 0; |
1073 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
1074 |
|
|
|
1075 |
|
|
void |
1076 |
root |
1.22 |
max_work_item_sizes (OpenCL::Device self) |
1077 |
root |
1.14 |
PPCODE: |
1078 |
root |
1.16 |
size_t size; |
1079 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_MAX_WORK_ITEM_SIZES, 0, 0, &size)); |
1080 |
root |
1.16 |
size_t *value = tmpbuf (size); |
1081 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_MAX_WORK_ITEM_SIZES, size, value, 0)); |
1082 |
root |
1.16 |
int i, n = size / sizeof (*value); |
1083 |
|
|
EXTEND (SP, n); |
1084 |
|
|
for (i = 0; i < n; ++i) |
1085 |
root |
1.14 |
PUSHs (sv_2mortal (newSVuv (value [i]))); |
1086 |
|
|
|
1087 |
|
|
void |
1088 |
root |
1.22 |
address_bits (OpenCL::Device self) |
1089 |
root |
1.14 |
PPCODE: |
1090 |
root |
1.16 |
cl_bitfield value [1]; |
1091 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_ADDRESS_BITS, sizeof (value), value, 0)); |
1092 |
root |
1.14 |
EXTEND (SP, 1); |
1093 |
|
|
const int i = 0; |
1094 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
1095 |
|
|
|
1096 |
|
|
void |
1097 |
root |
1.22 |
max_mem_alloc_size (OpenCL::Device self) |
1098 |
root |
1.16 |
ALIAS: |
1099 |
|
|
max_mem_alloc_size = CL_DEVICE_MAX_MEM_ALLOC_SIZE |
1100 |
|
|
global_mem_cache_size = CL_DEVICE_GLOBAL_MEM_CACHE_SIZE |
1101 |
|
|
global_mem_size = CL_DEVICE_GLOBAL_MEM_SIZE |
1102 |
|
|
max_constant_buffer_size = CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE |
1103 |
|
|
local_mem_size = CL_DEVICE_LOCAL_MEM_SIZE |
1104 |
root |
1.14 |
PPCODE: |
1105 |
root |
1.16 |
cl_ulong value [1]; |
1106 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0)); |
1107 |
root |
1.14 |
EXTEND (SP, 1); |
1108 |
|
|
const int i = 0; |
1109 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
1110 |
|
|
|
1111 |
|
|
void |
1112 |
root |
1.22 |
single_fp_config (OpenCL::Device self) |
1113 |
root |
1.16 |
ALIAS: |
1114 |
|
|
single_fp_config = CL_DEVICE_SINGLE_FP_CONFIG |
1115 |
|
|
double_fp_config = CL_DEVICE_DOUBLE_FP_CONFIG |
1116 |
|
|
half_fp_config = CL_DEVICE_HALF_FP_CONFIG |
1117 |
root |
1.14 |
PPCODE: |
1118 |
root |
1.16 |
cl_device_fp_config value [1]; |
1119 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0)); |
1120 |
root |
1.14 |
EXTEND (SP, 1); |
1121 |
|
|
const int i = 0; |
1122 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
1123 |
|
|
|
1124 |
|
|
void |
1125 |
root |
1.22 |
global_mem_cache_type (OpenCL::Device self) |
1126 |
root |
1.14 |
PPCODE: |
1127 |
root |
1.16 |
cl_device_mem_cache_type value [1]; |
1128 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, sizeof (value), value, 0)); |
1129 |
root |
1.14 |
EXTEND (SP, 1); |
1130 |
|
|
const int i = 0; |
1131 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
1132 |
|
|
|
1133 |
|
|
void |
1134 |
root |
1.22 |
local_mem_type (OpenCL::Device self) |
1135 |
root |
1.14 |
PPCODE: |
1136 |
root |
1.16 |
cl_device_local_mem_type value [1]; |
1137 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_LOCAL_MEM_TYPE, sizeof (value), value, 0)); |
1138 |
root |
1.14 |
EXTEND (SP, 1); |
1139 |
|
|
const int i = 0; |
1140 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
1141 |
|
|
|
1142 |
|
|
void |
1143 |
root |
1.22 |
error_correction_support (OpenCL::Device self) |
1144 |
root |
1.16 |
ALIAS: |
1145 |
|
|
error_correction_support = CL_DEVICE_ERROR_CORRECTION_SUPPORT |
1146 |
|
|
endian_little = CL_DEVICE_ENDIAN_LITTLE |
1147 |
|
|
available = CL_DEVICE_AVAILABLE |
1148 |
|
|
compiler_available = CL_DEVICE_COMPILER_AVAILABLE |
1149 |
|
|
host_unified_memory = CL_DEVICE_HOST_UNIFIED_MEMORY |
1150 |
root |
1.14 |
PPCODE: |
1151 |
root |
1.16 |
cl_bool value [1]; |
1152 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, ix, sizeof (value), value, 0)); |
1153 |
root |
1.14 |
EXTEND (SP, 1); |
1154 |
|
|
const int i = 0; |
1155 |
root |
1.16 |
PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no)); |
1156 |
root |
1.14 |
|
1157 |
|
|
void |
1158 |
root |
1.22 |
execution_capabilities (OpenCL::Device self) |
1159 |
root |
1.14 |
PPCODE: |
1160 |
root |
1.16 |
cl_device_exec_capabilities value [1]; |
1161 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_EXECUTION_CAPABILITIES, sizeof (value), value, 0)); |
1162 |
root |
1.14 |
EXTEND (SP, 1); |
1163 |
|
|
const int i = 0; |
1164 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
1165 |
|
|
|
1166 |
|
|
void |
1167 |
root |
1.22 |
properties (OpenCL::Device self) |
1168 |
root |
1.14 |
PPCODE: |
1169 |
root |
1.16 |
cl_command_queue_properties value [1]; |
1170 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_QUEUE_PROPERTIES, sizeof (value), value, 0)); |
1171 |
root |
1.14 |
EXTEND (SP, 1); |
1172 |
|
|
const int i = 0; |
1173 |
root |
1.61 |
PUSHs (sv_2mortal (newSVuv (value [i]))); |
1174 |
root |
1.14 |
|
1175 |
|
|
void |
1176 |
root |
1.22 |
platform (OpenCL::Device self) |
1177 |
root |
1.14 |
PPCODE: |
1178 |
root |
1.16 |
cl_platform_id value [1]; |
1179 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_PLATFORM, sizeof (value), value, 0)); |
1180 |
root |
1.14 |
EXTEND (SP, 1); |
1181 |
|
|
const int i = 0; |
1182 |
|
|
{ |
1183 |
root |
1.61 |
PUSH_CLOBJ (stash_platform, value [i]); |
1184 |
root |
1.14 |
} |
1185 |
|
|
|
1186 |
|
|
void |
1187 |
root |
1.22 |
name (OpenCL::Device self) |
1188 |
root |
1.16 |
ALIAS: |
1189 |
|
|
name = CL_DEVICE_NAME |
1190 |
|
|
vendor = CL_DEVICE_VENDOR |
1191 |
|
|
driver_version = CL_DRIVER_VERSION |
1192 |
|
|
profile = CL_DEVICE_PROFILE |
1193 |
|
|
version = CL_DEVICE_VERSION |
1194 |
|
|
extensions = CL_DEVICE_EXTENSIONS |
1195 |
root |
1.14 |
PPCODE: |
1196 |
|
|
size_t size; |
1197 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, ix, 0, 0, &size)); |
1198 |
root |
1.16 |
char *value = tmpbuf (size); |
1199 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, ix, size, value, 0)); |
1200 |
root |
1.16 |
EXTEND (SP, 1); |
1201 |
|
|
const int i = 0; |
1202 |
|
|
PUSHs (sv_2mortal (newSVpv (value, 0))); |
1203 |
root |
1.14 |
|
1204 |
|
|
void |
1205 |
root |
1.22 |
parent_device_ext (OpenCL::Device self) |
1206 |
root |
1.14 |
PPCODE: |
1207 |
root |
1.16 |
cl_device_id value [1]; |
1208 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, CL_DEVICE_PARENT_DEVICE_EXT, sizeof (value), value, 0)); |
1209 |
root |
1.14 |
EXTEND (SP, 1); |
1210 |
|
|
const int i = 0; |
1211 |
root |
1.16 |
{ |
1212 |
root |
1.61 |
PUSH_CLOBJ (stash_device, value [i]); |
1213 |
root |
1.16 |
} |
1214 |
root |
1.14 |
|
1215 |
|
|
void |
1216 |
root |
1.22 |
partition_types_ext (OpenCL::Device self) |
1217 |
root |
1.16 |
ALIAS: |
1218 |
|
|
partition_types_ext = CL_DEVICE_PARTITION_TYPES_EXT |
1219 |
|
|
affinity_domains_ext = CL_DEVICE_AFFINITY_DOMAINS_EXT |
1220 |
|
|
partition_style_ext = CL_DEVICE_PARTITION_STYLE_EXT |
1221 |
root |
1.14 |
PPCODE: |
1222 |
|
|
size_t size; |
1223 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, ix, 0, 0, &size)); |
1224 |
root |
1.14 |
cl_device_partition_property_ext *value = tmpbuf (size); |
1225 |
root |
1.22 |
NEED_SUCCESS (GetDeviceInfo, (self, ix, size, value, 0)); |
1226 |
root |
1.15 |
int i, n = size / sizeof (*value); |
1227 |
root |
1.14 |
EXTEND (SP, n); |
1228 |
|
|
for (i = 0; i < n; ++i) |
1229 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
1230 |
|
|
|
1231 |
|
|
#END:device |
1232 |
|
|
|
1233 |
root |
1.65 |
MODULE = OpenCL PACKAGE = OpenCL::SubDevice |
1234 |
|
|
|
1235 |
|
|
#if CL_VERSION_1_2 |
1236 |
|
|
|
1237 |
|
|
void |
1238 |
|
|
DESTROY (OpenCL::SubDevice self) |
1239 |
|
|
CODE: |
1240 |
|
|
clReleaseDevice (self); |
1241 |
|
|
|
1242 |
|
|
#endif |
1243 |
|
|
|
1244 |
root |
1.1 |
MODULE = OpenCL PACKAGE = OpenCL::Context |
1245 |
|
|
|
1246 |
|
|
void |
1247 |
root |
1.65 |
DESTROY (OpenCL::Context self) |
1248 |
root |
1.1 |
CODE: |
1249 |
root |
1.65 |
clReleaseContext (self); |
1250 |
root |
1.1 |
|
1251 |
|
|
void |
1252 |
root |
1.22 |
info (OpenCL::Context self, cl_context_info name) |
1253 |
root |
1.1 |
PPCODE: |
1254 |
root |
1.2 |
INFO (Context) |
1255 |
|
|
|
1256 |
|
|
void |
1257 |
root |
1.22 |
queue (OpenCL::Context self, OpenCL::Device device, cl_command_queue_properties properties = 0) |
1258 |
root |
1.2 |
PPCODE: |
1259 |
root |
1.23 |
NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (self, device, properties, &res)); |
1260 |
root |
1.61 |
XPUSH_CLOBJ (stash_queue, queue); |
1261 |
root |
1.2 |
|
1262 |
|
|
void |
1263 |
root |
1.22 |
user_event (OpenCL::Context self) |
1264 |
root |
1.5 |
PPCODE: |
1265 |
root |
1.23 |
NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (self, &res)); |
1266 |
root |
1.61 |
XPUSH_CLOBJ (stash_userevent, ev); |
1267 |
root |
1.5 |
|
1268 |
|
|
void |
1269 |
root |
1.22 |
buffer (OpenCL::Context self, cl_mem_flags flags, size_t len) |
1270 |
root |
1.2 |
PPCODE: |
1271 |
root |
1.3 |
if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) |
1272 |
root |
1.27 |
croak ("OpenCL::Context::buffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); |
1273 |
root |
1.3 |
|
1274 |
root |
1.22 |
NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res)); |
1275 |
root |
1.61 |
XPUSH_CLOBJ (stash_bufferobj, mem); |
1276 |
root |
1.2 |
|
1277 |
|
|
void |
1278 |
root |
1.22 |
buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data) |
1279 |
root |
1.2 |
PPCODE: |
1280 |
|
|
STRLEN len; |
1281 |
root |
1.21 |
char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
1282 |
root |
1.3 |
if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) |
1283 |
root |
1.27 |
croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); |
1284 |
root |
1.22 |
NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res)); |
1285 |
root |
1.61 |
XPUSH_CLOBJ (stash_bufferobj, mem); |
1286 |
root |
1.3 |
|
1287 |
root |
1.42 |
#if CL_VERSION_1_2 |
1288 |
|
|
|
1289 |
|
|
void |
1290 |
root |
1.55 |
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 = 0, 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) |
1291 |
root |
1.42 |
PPCODE: |
1292 |
|
|
STRLEN len; |
1293 |
|
|
char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
1294 |
|
|
const cl_image_format format = { channel_order, channel_type }; |
1295 |
|
|
const cl_image_desc desc = { |
1296 |
|
|
type, |
1297 |
|
|
width, height, depth, |
1298 |
|
|
array_size, row_pitch, slice_pitch, |
1299 |
|
|
num_mip_level, num_samples, |
1300 |
root |
1.71 |
type == CL_MEM_OBJECT_IMAGE1D_BUFFER ? (cl_mem)SvCLOBJ (cv, "data", data, "OpenCL::Buffer") : 0 |
1301 |
root |
1.42 |
}; |
1302 |
|
|
NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res)); |
1303 |
root |
1.61 |
HV *stash = stash_image; |
1304 |
root |
1.42 |
switch (type) |
1305 |
|
|
{ |
1306 |
root |
1.61 |
case CL_MEM_OBJECT_IMAGE1D_BUFFER: stash = stash_image1dbuffer; break; |
1307 |
|
|
case CL_MEM_OBJECT_IMAGE1D: stash = stash_image1d; break; |
1308 |
|
|
case CL_MEM_OBJECT_IMAGE1D_ARRAY: stash = stash_image2darray; break; |
1309 |
|
|
case CL_MEM_OBJECT_IMAGE2D: stash = stash_image2d; break; |
1310 |
|
|
case CL_MEM_OBJECT_IMAGE2D_ARRAY: stash = stash_image2darray; break; |
1311 |
|
|
case CL_MEM_OBJECT_IMAGE3D: stash = stash_image3d; break; |
1312 |
root |
1.42 |
} |
1313 |
root |
1.61 |
XPUSH_CLOBJ (stash, mem); |
1314 |
root |
1.42 |
|
1315 |
|
|
#endif |
1316 |
|
|
|
1317 |
root |
1.3 |
void |
1318 |
root |
1.22 |
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) |
1319 |
root |
1.3 |
PPCODE: |
1320 |
|
|
STRLEN len; |
1321 |
root |
1.21 |
char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
1322 |
root |
1.3 |
const cl_image_format format = { channel_order, channel_type }; |
1323 |
root |
1.44 |
#if PREFER_1_1 |
1324 |
|
|
NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res)); |
1325 |
|
|
#else |
1326 |
root |
1.42 |
const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE2D, width, height, 0, 0, row_pitch, 0, 0, 0, 0 }; |
1327 |
|
|
NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res)); |
1328 |
|
|
#endif |
1329 |
root |
1.61 |
XPUSH_CLOBJ (stash_image2d, mem); |
1330 |
root |
1.3 |
|
1331 |
|
|
void |
1332 |
root |
1.22 |
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) |
1333 |
root |
1.3 |
PPCODE: |
1334 |
|
|
STRLEN len; |
1335 |
root |
1.21 |
char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
1336 |
root |
1.3 |
const cl_image_format format = { channel_order, channel_type }; |
1337 |
root |
1.44 |
#if PREFER_1_1 |
1338 |
|
|
NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); |
1339 |
|
|
#else |
1340 |
root |
1.42 |
const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE3D, width, height, depth, 0, row_pitch, slice_pitch, 0, 0, 0 }; |
1341 |
|
|
NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res)); |
1342 |
|
|
#endif |
1343 |
root |
1.61 |
XPUSH_CLOBJ (stash_image3d, mem); |
1344 |
root |
1.3 |
|
1345 |
root |
1.25 |
#if cl_apple_gl_sharing || cl_khr_gl_sharing |
1346 |
|
|
|
1347 |
|
|
void |
1348 |
|
|
gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj) |
1349 |
|
|
PPCODE: |
1350 |
|
|
NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res)); |
1351 |
root |
1.61 |
XPUSH_CLOBJ (stash_bufferobj, mem); |
1352 |
root |
1.25 |
|
1353 |
|
|
void |
1354 |
root |
1.40 |
gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer) |
1355 |
root |
1.25 |
PPCODE: |
1356 |
root |
1.40 |
NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res)); |
1357 |
root |
1.61 |
XPUSH_CLOBJ (stash_image2d, mem); |
1358 |
root |
1.25 |
|
1359 |
root |
1.39 |
#if CL_VERSION_1_2 |
1360 |
|
|
|
1361 |
|
|
void |
1362 |
|
|
gl_texture (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
1363 |
root |
1.43 |
ALIAS: |
1364 |
root |
1.39 |
PPCODE: |
1365 |
root |
1.43 |
NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture, (self, flags, target, miplevel, texture, &res)); |
1366 |
|
|
cl_gl_object_type type; |
1367 |
|
|
NEED_SUCCESS (GetGLObjectInfo, (mem, &type, 0)); // TODO: use target instead? |
1368 |
root |
1.61 |
HV *stash = stash_memory; |
1369 |
root |
1.42 |
switch (type) |
1370 |
root |
1.39 |
{ |
1371 |
root |
1.61 |
case CL_GL_OBJECT_TEXTURE_BUFFER: stash = stash_image1dbuffer; break; |
1372 |
|
|
case CL_GL_OBJECT_TEXTURE1D: stash = stash_image1d; break; |
1373 |
|
|
case CL_GL_OBJECT_TEXTURE1D_ARRAY: stash = stash_image2darray; break; |
1374 |
|
|
case CL_GL_OBJECT_TEXTURE2D: stash = stash_image2d; break; |
1375 |
|
|
case CL_GL_OBJECT_TEXTURE2D_ARRAY: stash = stash_image2darray; break; |
1376 |
|
|
case CL_GL_OBJECT_TEXTURE3D: stash = stash_image3d; break; |
1377 |
root |
1.39 |
} |
1378 |
root |
1.61 |
XPUSH_CLOBJ (stash, mem); |
1379 |
root |
1.39 |
|
1380 |
root |
1.44 |
#endif |
1381 |
root |
1.40 |
|
1382 |
root |
1.25 |
void |
1383 |
root |
1.40 |
gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
1384 |
root |
1.25 |
PPCODE: |
1385 |
root |
1.44 |
#if PREFER_1_1 |
1386 |
root |
1.40 |
NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res)); |
1387 |
root |
1.44 |
#else |
1388 |
|
|
NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture , (self, flags, target, miplevel, texture, &res)); |
1389 |
|
|
#endif |
1390 |
root |
1.61 |
XPUSH_CLOBJ (stash_image2d, mem); |
1391 |
root |
1.25 |
|
1392 |
root |
1.40 |
void |
1393 |
|
|
gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
1394 |
|
|
PPCODE: |
1395 |
root |
1.44 |
#if PREFER_1_1 |
1396 |
root |
1.40 |
NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res)); |
1397 |
root |
1.44 |
#else |
1398 |
|
|
NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture , (self, flags, target, miplevel, texture, &res)); |
1399 |
|
|
#endif |
1400 |
root |
1.61 |
XPUSH_CLOBJ (stash_image3d, mem); |
1401 |
root |
1.40 |
|
1402 |
|
|
#endif |
1403 |
|
|
|
1404 |
root |
1.3 |
void |
1405 |
root |
1.22 |
supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) |
1406 |
root |
1.3 |
PPCODE: |
1407 |
|
|
{ |
1408 |
|
|
cl_uint count; |
1409 |
|
|
cl_image_format *list; |
1410 |
|
|
int i; |
1411 |
|
|
|
1412 |
root |
1.23 |
NEED_SUCCESS (GetSupportedImageFormats, (self, flags, image_type, 0, 0, &count)); |
1413 |
root |
1.3 |
Newx (list, count, cl_image_format); |
1414 |
root |
1.23 |
NEED_SUCCESS (GetSupportedImageFormats, (self, flags, image_type, count, list, 0)); |
1415 |
root |
1.3 |
|
1416 |
|
|
EXTEND (SP, count); |
1417 |
|
|
for (i = 0; i < count; ++i) |
1418 |
|
|
{ |
1419 |
|
|
AV *av = newAV (); |
1420 |
|
|
av_store (av, 1, newSVuv (list [i].image_channel_data_type)); |
1421 |
|
|
av_store (av, 0, newSVuv (list [i].image_channel_order)); |
1422 |
|
|
PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
1423 |
|
|
} |
1424 |
root |
1.2 |
} |
1425 |
|
|
|
1426 |
|
|
void |
1427 |
root |
1.22 |
sampler (OpenCL::Context self, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode) |
1428 |
root |
1.2 |
PPCODE: |
1429 |
root |
1.23 |
NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (self, normalized_coords, addressing_mode, filter_mode, &res)); |
1430 |
root |
1.61 |
XPUSH_CLOBJ (stash_sampler, sampler); |
1431 |
root |
1.1 |
|
1432 |
|
|
void |
1433 |
root |
1.22 |
program_with_source (OpenCL::Context self, SV *program) |
1434 |
root |
1.1 |
PPCODE: |
1435 |
root |
1.2 |
STRLEN len; |
1436 |
|
|
size_t len2; |
1437 |
|
|
const char *ptr = SvPVbyte (program, len); |
1438 |
|
|
|
1439 |
|
|
len2 = len; |
1440 |
root |
1.23 |
NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (self, 1, &ptr, &len2, &res)); |
1441 |
root |
1.61 |
XPUSH_CLOBJ (stash_program, prog); |
1442 |
root |
1.1 |
|
1443 |
root |
1.64 |
void |
1444 |
|
|
program_with_binary (OpenCL::Context self, SV *devices, SV *binaries) |
1445 |
|
|
PPCODE: |
1446 |
root |
1.70 |
cl_uint device_count; |
1447 |
|
|
cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); |
1448 |
root |
1.64 |
|
1449 |
|
|
if (!SvROK (binaries) || SvTYPE (SvRV (binaries)) != SVt_PVAV) |
1450 |
|
|
croak ("OpenCL::Context::program_with_binary: binaries must be specified as reference to an array of strings"); |
1451 |
|
|
|
1452 |
|
|
binaries = SvRV (binaries); |
1453 |
|
|
|
1454 |
root |
1.70 |
if (device_count != av_len ((AV *)binaries) + 1) |
1455 |
root |
1.64 |
croak ("OpenCL::Context::program_with_binary: differing numbers of devices and binaries are not allowed"); |
1456 |
|
|
|
1457 |
root |
1.70 |
size_t *length_list = tmpbuf (sizeof (*length_list) * device_count); |
1458 |
|
|
const unsigned char **binary_list = tmpbuf (sizeof (*binary_list) * device_count); |
1459 |
|
|
cl_int *status_list = tmpbuf (sizeof (*status_list) * device_count); |
1460 |
root |
1.64 |
|
1461 |
|
|
int i; |
1462 |
root |
1.70 |
for (i = 0; i < device_count; ++i) |
1463 |
root |
1.64 |
{ |
1464 |
|
|
STRLEN len; |
1465 |
|
|
binary_list [i] = (const unsigned char *)SvPVbyte (*av_fetch ((AV *)binaries, i, 0), len); |
1466 |
|
|
length_list [i] = len; |
1467 |
|
|
} |
1468 |
|
|
|
1469 |
root |
1.70 |
NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBinary, (self, device_count, device_list, |
1470 |
|
|
length_list, binary_list, |
1471 |
|
|
GIMME_V == G_ARRAY ? status_list : 0, &res)); |
1472 |
root |
1.64 |
|
1473 |
|
|
EXTEND (SP, 2); |
1474 |
|
|
PUSH_CLOBJ (stash_program, prog); |
1475 |
|
|
|
1476 |
|
|
if (GIMME_V == G_ARRAY) |
1477 |
|
|
{ |
1478 |
|
|
AV *av = newAV (); |
1479 |
|
|
PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
1480 |
|
|
|
1481 |
root |
1.70 |
for (i = device_count; i--; ) |
1482 |
root |
1.64 |
av_store (av, i, newSViv (status_list [i])); |
1483 |
|
|
} |
1484 |
|
|
|
1485 |
root |
1.65 |
#if CL_VERSION_1_2 |
1486 |
|
|
|
1487 |
|
|
void |
1488 |
|
|
program_with_built_in_kernels (OpenCL::Context self, SV *devices, SV *kernel_names) |
1489 |
|
|
PPCODE: |
1490 |
root |
1.71 |
cl_uint device_count; |
1491 |
|
|
cl_device_id *device_list = object_list (cv, 0, "devices", devices, "OpenCL::Device", &device_count); |
1492 |
root |
1.69 |
|
1493 |
|
|
NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithBuiltInKernels, (self, device_count, device_list, SvPVbyte_nolen (kernel_names), &res)); |
1494 |
|
|
|
1495 |
|
|
XPUSH_CLOBJ (stash_program, prog); |
1496 |
|
|
|
1497 |
|
|
void |
1498 |
|
|
link_program (OpenCL::Context self, SV *devices, SV *options, SV *programs, SV *notify = &PL_sv_undef) |
1499 |
|
|
CODE: |
1500 |
|
|
cl_uint device_count = 0; |
1501 |
|
|
cl_device_id *device_list = 0; |
1502 |
root |
1.65 |
|
1503 |
root |
1.69 |
if (SvOK (devices)) |
1504 |
|
|
device_list = object_list (cv, 1, "devices", devices, "OpenCL::Device", &device_count); |
1505 |
root |
1.65 |
|
1506 |
root |
1.69 |
cl_uint program_count; |
1507 |
|
|
cl_program *program_list = object_list (cv, 0, "programs", programs, "OpenCL::Program", &program_count); |
1508 |
root |
1.65 |
|
1509 |
root |
1.69 |
void *user_data; |
1510 |
|
|
program_callback pfn_notify = make_program_callback (notify, &user_data); |
1511 |
root |
1.65 |
|
1512 |
root |
1.69 |
NEED_SUCCESS_ARG (cl_program prog, LinkProgram, (self, device_count, device_list, SvPVbyte_nolen (options), |
1513 |
|
|
program_count, program_list, pfn_notify, user_data, &res)); |
1514 |
root |
1.65 |
|
1515 |
|
|
XPUSH_CLOBJ (stash_program, prog); |
1516 |
|
|
|
1517 |
|
|
#endif |
1518 |
|
|
|
1519 |
root |
1.13 |
#BEGIN:context |
1520 |
|
|
|
1521 |
root |
1.14 |
void |
1522 |
root |
1.22 |
reference_count (OpenCL::Context self) |
1523 |
root |
1.16 |
ALIAS: |
1524 |
|
|
reference_count = CL_CONTEXT_REFERENCE_COUNT |
1525 |
|
|
num_devices = CL_CONTEXT_NUM_DEVICES |
1526 |
root |
1.14 |
PPCODE: |
1527 |
|
|
cl_uint value [1]; |
1528 |
root |
1.22 |
NEED_SUCCESS (GetContextInfo, (self, ix, sizeof (value), value, 0)); |
1529 |
root |
1.14 |
EXTEND (SP, 1); |
1530 |
|
|
const int i = 0; |
1531 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
1532 |
|
|
|
1533 |
|
|
void |
1534 |
root |
1.22 |
devices (OpenCL::Context self) |
1535 |
root |
1.14 |
PPCODE: |
1536 |
|
|
size_t size; |
1537 |
root |
1.22 |
NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_DEVICES, 0, 0, &size)); |
1538 |
root |
1.14 |
cl_device_id *value = tmpbuf (size); |
1539 |
root |
1.22 |
NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_DEVICES, size, value, 0)); |
1540 |
root |
1.15 |
int i, n = size / sizeof (*value); |
1541 |
root |
1.14 |
EXTEND (SP, n); |
1542 |
|
|
for (i = 0; i < n; ++i) |
1543 |
|
|
{ |
1544 |
root |
1.61 |
PUSH_CLOBJ (stash_device, value [i]); |
1545 |
root |
1.14 |
} |
1546 |
|
|
|
1547 |
|
|
void |
1548 |
root |
1.22 |
properties (OpenCL::Context self) |
1549 |
root |
1.14 |
PPCODE: |
1550 |
|
|
size_t size; |
1551 |
root |
1.22 |
NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_PROPERTIES, 0, 0, &size)); |
1552 |
root |
1.14 |
cl_context_properties *value = tmpbuf (size); |
1553 |
root |
1.22 |
NEED_SUCCESS (GetContextInfo, (self, CL_CONTEXT_PROPERTIES, size, value, 0)); |
1554 |
root |
1.15 |
int i, n = size / sizeof (*value); |
1555 |
root |
1.14 |
EXTEND (SP, n); |
1556 |
|
|
for (i = 0; i < n; ++i) |
1557 |
|
|
PUSHs (sv_2mortal (newSVuv ((UV)value [i]))); |
1558 |
|
|
|
1559 |
root |
1.13 |
#END:context |
1560 |
|
|
|
1561 |
root |
1.1 |
MODULE = OpenCL PACKAGE = OpenCL::Queue |
1562 |
|
|
|
1563 |
|
|
void |
1564 |
root |
1.22 |
DESTROY (OpenCL::Queue self) |
1565 |
root |
1.1 |
CODE: |
1566 |
root |
1.22 |
clReleaseCommandQueue (self); |
1567 |
root |
1.1 |
|
1568 |
|
|
void |
1569 |
root |
1.55 |
read_buffer (OpenCL::Queue self, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...) |
1570 |
|
|
ALIAS: |
1571 |
|
|
enqueue_read_buffer = 0 |
1572 |
root |
1.2 |
PPCODE: |
1573 |
root |
1.61 |
EVENT_LIST (6); |
1574 |
root |
1.2 |
|
1575 |
|
|
SvUPGRADE (data, SVt_PV); |
1576 |
|
|
SvGROW (data, len); |
1577 |
|
|
SvPOK_only (data); |
1578 |
|
|
SvCUR_set (data, len); |
1579 |
root |
1.69 |
|
1580 |
|
|
cl_event ev = 0; |
1581 |
root |
1.22 |
NEED_SUCCESS (EnqueueReadBuffer, (self, mem, blocking, offset, len, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1582 |
root |
1.2 |
|
1583 |
|
|
if (ev) |
1584 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
1585 |
root |
1.2 |
|
1586 |
|
|
void |
1587 |
root |
1.55 |
write_buffer (OpenCL::Queue self, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...) |
1588 |
|
|
ALIAS: |
1589 |
|
|
enqueue_write_buffer = 0 |
1590 |
root |
1.2 |
PPCODE: |
1591 |
root |
1.69 |
EVENT_LIST (5); |
1592 |
|
|
|
1593 |
root |
1.2 |
STRLEN len; |
1594 |
|
|
char *ptr = SvPVbyte (data, len); |
1595 |
|
|
|
1596 |
root |
1.69 |
cl_event ev = 0; |
1597 |
root |
1.34 |
NEED_SUCCESS (EnqueueWriteBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1598 |
root |
1.2 |
|
1599 |
|
|
if (ev) |
1600 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
1601 |
root |
1.2 |
|
1602 |
root |
1.48 |
#if CL_VERSION_1_2 |
1603 |
|
|
|
1604 |
|
|
void |
1605 |
root |
1.55 |
fill_buffer (OpenCL::Queue self, OpenCL::Buffer mem, SV *data, size_t offset, size_t size, ...) |
1606 |
|
|
ALIAS: |
1607 |
|
|
enqueue_fill_buffer = 0 |
1608 |
root |
1.48 |
PPCODE: |
1609 |
root |
1.69 |
EVENT_LIST (5); |
1610 |
|
|
|
1611 |
root |
1.48 |
STRLEN len; |
1612 |
|
|
char *ptr = SvPVbyte (data, len); |
1613 |
|
|
|
1614 |
root |
1.69 |
cl_event ev = 0; |
1615 |
root |
1.48 |
NEED_SUCCESS (EnqueueFillBuffer, (self, mem, ptr, len, offset, size, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1616 |
|
|
|
1617 |
|
|
if (ev) |
1618 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
1619 |
root |
1.48 |
|
1620 |
|
|
void |
1621 |
root |
1.55 |
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, ...) |
1622 |
|
|
ALIAS: |
1623 |
|
|
enqueue_fill_image = 0 |
1624 |
root |
1.48 |
PPCODE: |
1625 |
root |
1.69 |
EVENT_LIST (12); |
1626 |
|
|
|
1627 |
root |
1.48 |
const size_t origin [3] = { x, y, z }; |
1628 |
|
|
const size_t region [3] = { width, height, depth }; |
1629 |
|
|
|
1630 |
|
|
const cl_float c_f [4] = { r, g, b, a }; |
1631 |
|
|
const cl_uint c_u [4] = { r, g, b, a }; |
1632 |
|
|
const cl_int c_s [4] = { r, g, b, a }; |
1633 |
|
|
const void *c_fus [3] = { &c_f, &c_u, &c_s }; |
1634 |
|
|
static const char fus [] = { 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 1, 1, 1, 0, 0 }; |
1635 |
|
|
cl_image_format format; |
1636 |
root |
1.50 |
NEED_SUCCESS (GetImageInfo, (img, CL_IMAGE_FORMAT, sizeof (format), &format, 0)); |
1637 |
root |
1.48 |
assert (sizeof (fus) == CL_FLOAT + 1 - CL_SNORM_INT8); |
1638 |
|
|
if (format.image_channel_data_type < CL_SNORM_INT8 || CL_FLOAT < format.image_channel_data_type) |
1639 |
|
|
croak ("enqueue_fill_image: image has unsupported channel type, only opencl 1.2 channel types supported."); |
1640 |
|
|
|
1641 |
root |
1.69 |
cl_event ev = 0; |
1642 |
root |
1.55 |
NEED_SUCCESS (EnqueueFillImage, (self, img, c_fus [fus [format.image_channel_data_type - CL_SNORM_INT8]], |
1643 |
root |
1.48 |
origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1644 |
|
|
|
1645 |
|
|
if (ev) |
1646 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
1647 |
root |
1.48 |
|
1648 |
|
|
#endif |
1649 |
|
|
|
1650 |
root |
1.2 |
void |
1651 |
root |
1.55 |
copy_buffer (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...) |
1652 |
|
|
ALIAS: |
1653 |
|
|
enqueue_copy_buffer = 0 |
1654 |
root |
1.2 |
PPCODE: |
1655 |
root |
1.61 |
EVENT_LIST (6); |
1656 |
root |
1.2 |
|
1657 |
root |
1.69 |
cl_event ev = 0; |
1658 |
root |
1.22 |
NEED_SUCCESS (EnqueueCopyBuffer, (self, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1659 |
root |
1.2 |
|
1660 |
|
|
if (ev) |
1661 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
1662 |
root |
1.2 |
|
1663 |
root |
1.3 |
void |
1664 |
root |
1.55 |
read_buffer_rect (OpenCL::Queue self, OpenCL::Memory buf, cl_bool blocking, size_t buf_x, size_t buf_y, size_t buf_z, size_t host_x, size_t host_y, size_t host_z, size_t width, size_t height, size_t depth, size_t buf_row_pitch, size_t buf_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, SV *data, ...) |
1665 |
|
|
ALIAS: |
1666 |
|
|
enqueue_read_buffer_rect = 0 |
1667 |
root |
1.17 |
PPCODE: |
1668 |
root |
1.69 |
EVENT_LIST (17); |
1669 |
|
|
|
1670 |
root |
1.17 |
const size_t buf_origin [3] = { buf_x , buf_y , buf_z }; |
1671 |
|
|
const size_t host_origin[3] = { host_x, host_y, host_z }; |
1672 |
|
|
const size_t region[3] = { width, height, depth }; |
1673 |
|
|
|
1674 |
|
|
if (!buf_row_pitch) |
1675 |
|
|
buf_row_pitch = region [0]; |
1676 |
|
|
|
1677 |
|
|
if (!buf_slice_pitch) |
1678 |
|
|
buf_slice_pitch = region [1] * buf_row_pitch; |
1679 |
|
|
|
1680 |
|
|
if (!host_row_pitch) |
1681 |
|
|
host_row_pitch = region [0]; |
1682 |
|
|
|
1683 |
|
|
if (!host_slice_pitch) |
1684 |
|
|
host_slice_pitch = region [1] * host_row_pitch; |
1685 |
|
|
|
1686 |
|
|
size_t len = host_row_pitch * host_slice_pitch * region [2]; |
1687 |
|
|
|
1688 |
|
|
SvUPGRADE (data, SVt_PV); |
1689 |
|
|
SvGROW (data, len); |
1690 |
|
|
SvPOK_only (data); |
1691 |
|
|
SvCUR_set (data, len); |
1692 |
root |
1.69 |
|
1693 |
|
|
cl_event ev = 0; |
1694 |
root |
1.22 |
NEED_SUCCESS (EnqueueReadBufferRect, (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)); |
1695 |
root |
1.17 |
|
1696 |
|
|
if (ev) |
1697 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
1698 |
root |
1.17 |
|
1699 |
|
|
void |
1700 |
root |
1.55 |
write_buffer_rect (OpenCL::Queue self, OpenCL::Memory buf, cl_bool blocking, size_t buf_x, size_t buf_y, size_t buf_z, size_t host_x, size_t host_y, size_t host_z, size_t width, size_t height, size_t depth, size_t buf_row_pitch, size_t buf_slice_pitch, size_t host_row_pitch, size_t host_slice_pitch, SV *data, ...) |
1701 |
|
|
ALIAS: |
1702 |
|
|
enqueue_write_buffer_rect = 0 |
1703 |
root |
1.17 |
PPCODE: |
1704 |
root |
1.69 |
EVENT_LIST (17); |
1705 |
|
|
|
1706 |
root |
1.17 |
const size_t buf_origin [3] = { buf_x , buf_y , buf_z }; |
1707 |
|
|
const size_t host_origin[3] = { host_x, host_y, host_z }; |
1708 |
|
|
const size_t region[3] = { width, height, depth }; |
1709 |
|
|
STRLEN len; |
1710 |
|
|
char *ptr = SvPVbyte (data, len); |
1711 |
|
|
|
1712 |
|
|
if (!buf_row_pitch) |
1713 |
|
|
buf_row_pitch = region [0]; |
1714 |
|
|
|
1715 |
|
|
if (!buf_slice_pitch) |
1716 |
|
|
buf_slice_pitch = region [1] * buf_row_pitch; |
1717 |
|
|
|
1718 |
|
|
if (!host_row_pitch) |
1719 |
|
|
host_row_pitch = region [0]; |
1720 |
|
|
|
1721 |
|
|
if (!host_slice_pitch) |
1722 |
|
|
host_slice_pitch = region [1] * host_row_pitch; |
1723 |
|
|
|
1724 |
|
|
size_t min_len = host_row_pitch * host_slice_pitch * region [2]; |
1725 |
|
|
|
1726 |
|
|
if (len < min_len) |
1727 |
|
|
croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
1728 |
|
|
|
1729 |
root |
1.69 |
cl_event ev = 0; |
1730 |
root |
1.37 |
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)); |
1731 |
root |
1.17 |
|
1732 |
|
|
if (ev) |
1733 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
1734 |
root |
1.17 |
|
1735 |
|
|
void |
1736 |
root |
1.55 |
copy_buffer_rect (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t src_row_pitch, size_t src_slice_pitch, size_t dst_row_pitch, size_t dst_slice_pitch, ...) |
1737 |
|
|
ALIAS: |
1738 |
|
|
enqueue_copy_buffer_rect = 0 |
1739 |
root |
1.18 |
PPCODE: |
1740 |
root |
1.69 |
EVENT_LIST (16); |
1741 |
|
|
|
1742 |
root |
1.18 |
const size_t src_origin[3] = { src_x, src_y, src_z }; |
1743 |
|
|
const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; |
1744 |
|
|
const size_t region[3] = { width, height, depth }; |
1745 |
|
|
|
1746 |
root |
1.69 |
cl_event ev = 0; |
1747 |
root |
1.22 |
NEED_SUCCESS (EnqueueCopyBufferRect, (self, src, dst, src_origin, dst_origin, region, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1748 |
root |
1.18 |
|
1749 |
|
|
if (ev) |
1750 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
1751 |
root |
1.18 |
|
1752 |
|
|
void |
1753 |
root |
1.55 |
read_image (OpenCL::Queue self, OpenCL::Image src, cl_bool blocking, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...) |
1754 |
|
|
ALIAS: |
1755 |
|
|
enqueue_read_image = 0 |
1756 |
root |
1.3 |
PPCODE: |
1757 |
root |
1.69 |
EVENT_LIST (12); |
1758 |
|
|
|
1759 |
root |
1.3 |
const size_t src_origin[3] = { src_x, src_y, src_z }; |
1760 |
|
|
const size_t region[3] = { width, height, depth }; |
1761 |
root |
1.10 |
|
1762 |
root |
1.11 |
if (!row_pitch) |
1763 |
|
|
row_pitch = img_row_pitch (src); |
1764 |
|
|
|
1765 |
|
|
if (depth > 1 && !slice_pitch) |
1766 |
|
|
slice_pitch = row_pitch * height; |
1767 |
|
|
|
1768 |
|
|
size_t len = slice_pitch ? slice_pitch * depth : row_pitch * height; |
1769 |
root |
1.3 |
|
1770 |
|
|
SvUPGRADE (data, SVt_PV); |
1771 |
|
|
SvGROW (data, len); |
1772 |
|
|
SvPOK_only (data); |
1773 |
|
|
SvCUR_set (data, len); |
1774 |
root |
1.69 |
|
1775 |
|
|
cl_event ev = 0; |
1776 |
root |
1.22 |
NEED_SUCCESS (EnqueueReadImage, (self, src, blocking, src_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1777 |
root |
1.3 |
|
1778 |
|
|
if (ev) |
1779 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
1780 |
root |
1.3 |
|
1781 |
|
|
void |
1782 |
root |
1.55 |
write_image (OpenCL::Queue self, OpenCL::Image dst, cl_bool blocking, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, size_t row_pitch, size_t slice_pitch, SV *data, ...) |
1783 |
|
|
ALIAS: |
1784 |
|
|
enqueue_write_image = 0 |
1785 |
root |
1.3 |
PPCODE: |
1786 |
root |
1.69 |
EVENT_LIST (12); |
1787 |
|
|
|
1788 |
root |
1.3 |
const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; |
1789 |
|
|
const size_t region[3] = { width, height, depth }; |
1790 |
|
|
STRLEN len; |
1791 |
|
|
char *ptr = SvPVbyte (data, len); |
1792 |
|
|
|
1793 |
root |
1.11 |
if (!row_pitch) |
1794 |
|
|
row_pitch = img_row_pitch (dst); |
1795 |
|
|
|
1796 |
|
|
if (depth > 1 && !slice_pitch) |
1797 |
|
|
slice_pitch = row_pitch * height; |
1798 |
|
|
|
1799 |
|
|
size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height; |
1800 |
|
|
|
1801 |
|
|
if (len < min_len) |
1802 |
|
|
croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
1803 |
|
|
|
1804 |
root |
1.69 |
cl_event ev = 0; |
1805 |
root |
1.37 |
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)); |
1806 |
root |
1.3 |
|
1807 |
|
|
if (ev) |
1808 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
1809 |
root |
1.3 |
|
1810 |
|
|
void |
1811 |
root |
1.55 |
copy_image (OpenCL::Queue self, OpenCL::Image src, OpenCL::Image dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...) |
1812 |
|
|
ALIAS: |
1813 |
|
|
enqueue_copy_image = 0 |
1814 |
root |
1.3 |
PPCODE: |
1815 |
root |
1.69 |
EVENT_LIST (12); |
1816 |
|
|
|
1817 |
root |
1.3 |
const size_t src_origin[3] = { src_x, src_y, src_z }; |
1818 |
|
|
const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; |
1819 |
|
|
const size_t region[3] = { width, height, depth }; |
1820 |
|
|
|
1821 |
root |
1.69 |
cl_event ev = 0; |
1822 |
root |
1.22 |
NEED_SUCCESS (EnqueueCopyImage, (self, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1823 |
root |
1.3 |
|
1824 |
|
|
if (ev) |
1825 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
1826 |
root |
1.3 |
|
1827 |
|
|
void |
1828 |
root |
1.55 |
copy_image_to_buffer (OpenCL::Queue self, OpenCL::Image src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t dst_offset, ...) |
1829 |
|
|
ALIAS: |
1830 |
|
|
enqueue_copy_image_to_buffer = 0 |
1831 |
root |
1.3 |
PPCODE: |
1832 |
root |
1.69 |
EVENT_LIST (10); |
1833 |
|
|
|
1834 |
root |
1.61 |
const size_t src_origin[3] = { src_x, src_y, src_z }; |
1835 |
|
|
const size_t region [3] = { width, height, depth }; |
1836 |
root |
1.3 |
|
1837 |
root |
1.69 |
cl_event ev = 0; |
1838 |
root |
1.22 |
NEED_SUCCESS (EnqueueCopyImageToBuffer, (self, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1839 |
root |
1.3 |
|
1840 |
|
|
if (ev) |
1841 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
1842 |
root |
1.3 |
|
1843 |
|
|
void |
1844 |
root |
1.55 |
copy_buffer_to_image (OpenCL::Queue self, OpenCL::Buffer src, OpenCL::Image dst, size_t src_offset, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...) |
1845 |
|
|
ALIAS: |
1846 |
|
|
enqueue_copy_buffer_to_image = 0 |
1847 |
root |
1.3 |
PPCODE: |
1848 |
root |
1.69 |
EVENT_LIST (10); |
1849 |
|
|
|
1850 |
root |
1.61 |
const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; |
1851 |
|
|
const size_t region [3] = { width, height, depth }; |
1852 |
root |
1.3 |
|
1853 |
root |
1.69 |
cl_event ev = 0; |
1854 |
root |
1.22 |
NEED_SUCCESS (EnqueueCopyBufferToImage, (self, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1855 |
root |
1.3 |
|
1856 |
|
|
if (ev) |
1857 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
1858 |
|
|
|
1859 |
|
|
void |
1860 |
root |
1.64 |
map_buffer (OpenCL::Queue self, OpenCL::Buffer buf, cl_bool blocking = 1, cl_map_flags map_flags = CL_MAP_READ | CL_MAP_WRITE, size_t offset = 0, SV *cb_ = &PL_sv_undef, ...) |
1861 |
root |
1.61 |
ALIAS: |
1862 |
|
|
enqueue_map_buffer = 0 |
1863 |
|
|
PPCODE: |
1864 |
root |
1.62 |
EVENT_LIST (6); |
1865 |
root |
1.69 |
|
1866 |
root |
1.64 |
size_t cb = SvIV (cb_); |
1867 |
|
|
|
1868 |
|
|
if (!SvOK (cb_)) |
1869 |
|
|
{ |
1870 |
|
|
NEED_SUCCESS (GetMemObjectInfo, (buf, CL_MEM_SIZE, sizeof (cb), &cb, 0)); |
1871 |
|
|
cb -= offset; |
1872 |
|
|
} |
1873 |
root |
1.61 |
|
1874 |
root |
1.69 |
cl_event ev; |
1875 |
root |
1.61 |
NEED_SUCCESS_ARG (void *ptr, EnqueueMapBuffer, (self, buf, blocking, map_flags, offset, cb, event_list_count, event_list_ptr, &ev, &res)); |
1876 |
|
|
XPUSHs (mapped_new (stash_mappedbuffer, self, buf, map_flags, ptr, cb, ev, 0, 0)); |
1877 |
|
|
|
1878 |
|
|
void |
1879 |
root |
1.64 |
map_image (OpenCL::Queue self, OpenCL::Image img, cl_bool blocking = 1, cl_map_flags map_flags = CL_MAP_READ | CL_MAP_WRITE, size_t x = 0, size_t y = 0, size_t z = 0, SV *width_ = &PL_sv_undef, SV *height_ = &PL_sv_undef, SV *depth_ = &PL_sv_undef, ...) |
1880 |
root |
1.61 |
ALIAS: |
1881 |
|
|
enqueue_map_image = 0 |
1882 |
|
|
PPCODE: |
1883 |
root |
1.64 |
size_t width = SvIV (width_); |
1884 |
|
|
if (!SvOK (width_)) |
1885 |
|
|
{ |
1886 |
|
|
NEED_SUCCESS (GetImageInfo, (img, CL_IMAGE_WIDTH, sizeof (width), &width, 0)); |
1887 |
|
|
width -= x; |
1888 |
|
|
} |
1889 |
|
|
|
1890 |
|
|
size_t height = SvIV (width_); |
1891 |
|
|
if (!SvOK (height_)) |
1892 |
|
|
{ |
1893 |
|
|
NEED_SUCCESS (GetImageInfo, (img, CL_IMAGE_HEIGHT, sizeof (height), &height, 0)); |
1894 |
|
|
height -= y; |
1895 |
|
|
} |
1896 |
|
|
|
1897 |
|
|
size_t depth = SvIV (width_); |
1898 |
|
|
if (!SvOK (depth_)) |
1899 |
|
|
{ |
1900 |
|
|
NEED_SUCCESS (GetImageInfo, (img, CL_IMAGE_DEPTH, sizeof (depth), &depth, 0)); |
1901 |
|
|
depth -= z; |
1902 |
|
|
|
1903 |
|
|
// stupid opencl returns 0 for depth, but requires 1 for 2d images |
1904 |
|
|
if (!depth) |
1905 |
|
|
depth = 1; |
1906 |
|
|
} |
1907 |
|
|
|
1908 |
root |
1.61 |
const size_t origin[3] = { x, y, z }; |
1909 |
|
|
const size_t region[3] = { width, height, depth }; |
1910 |
|
|
size_t row_pitch, slice_pitch; |
1911 |
root |
1.62 |
EVENT_LIST (10); |
1912 |
root |
1.61 |
|
1913 |
root |
1.64 |
cl_event ev; |
1914 |
root |
1.61 |
NEED_SUCCESS_ARG (void *ptr, EnqueueMapImage, (self, img, blocking, map_flags, origin, region, &row_pitch, &slice_pitch, event_list_count, event_list_ptr, &ev, &res)); |
1915 |
|
|
|
1916 |
|
|
size_t cb = slice_pitch ? slice_pitch * region [2] |
1917 |
|
|
: row_pitch ? row_pitch * region [1] |
1918 |
|
|
: region [0]; |
1919 |
|
|
|
1920 |
|
|
XPUSHs (mapped_new (stash_mappedimage, self, img, map_flags, ptr, cb, ev, row_pitch, slice_pitch)); |
1921 |
|
|
|
1922 |
|
|
void |
1923 |
|
|
unmap (OpenCL::Queue self, OpenCL::Mapped mapped, ...) |
1924 |
|
|
PPCODE: |
1925 |
root |
1.71 |
mapped_unmap (cv, ST (1), mapped, self, &ST (2), items - 2); |
1926 |
root |
1.61 |
if (GIMME_V != G_VOID) |
1927 |
root |
1.62 |
{ |
1928 |
|
|
clRetainEvent (mapped->event); |
1929 |
|
|
XPUSH_CLOBJ (stash_event, mapped->event); |
1930 |
|
|
} |
1931 |
root |
1.3 |
|
1932 |
|
|
void |
1933 |
root |
1.55 |
task (OpenCL::Queue self, OpenCL::Kernel kernel, ...) |
1934 |
|
|
ALIAS: |
1935 |
|
|
enqueue_task = 0 |
1936 |
root |
1.3 |
PPCODE: |
1937 |
root |
1.61 |
EVENT_LIST (2); |
1938 |
root |
1.3 |
|
1939 |
root |
1.69 |
cl_event ev = 0; |
1940 |
root |
1.22 |
NEED_SUCCESS (EnqueueTask, (self, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1941 |
root |
1.3 |
|
1942 |
|
|
if (ev) |
1943 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
1944 |
root |
1.3 |
|
1945 |
root |
1.4 |
void |
1946 |
root |
1.55 |
nd_range_kernel (OpenCL::Queue self, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...) |
1947 |
|
|
ALIAS: |
1948 |
|
|
enqueue_nd_range_kernel = 0 |
1949 |
root |
1.4 |
PPCODE: |
1950 |
root |
1.69 |
EVENT_LIST (5); |
1951 |
|
|
|
1952 |
root |
1.4 |
size_t *gwo = 0, *gws, *lws = 0; |
1953 |
|
|
int gws_len; |
1954 |
|
|
size_t *lists; |
1955 |
|
|
int i; |
1956 |
|
|
|
1957 |
|
|
if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV) |
1958 |
|
|
croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference"); |
1959 |
|
|
|
1960 |
|
|
gws_len = AvFILLp (SvRV (global_work_size)) + 1; |
1961 |
|
|
|
1962 |
|
|
lists = tmpbuf (sizeof (size_t) * 3 * gws_len); |
1963 |
|
|
|
1964 |
|
|
gws = lists + gws_len * 0; |
1965 |
|
|
for (i = 0; i < gws_len; ++i) |
1966 |
root |
1.58 |
{ |
1967 |
|
|
gws [i] = SvIV (AvARRAY (SvRV (global_work_size))[i]); |
1968 |
|
|
// at least nvidia crashes for 0-sized work group sizes, work around |
1969 |
|
|
if (!gws [i]) |
1970 |
|
|
croak ("clEnqueueNDRangeKernel: global_work_size[%d] is zero, must be non-zero", i); |
1971 |
|
|
} |
1972 |
root |
1.4 |
|
1973 |
|
|
if (SvOK (global_work_offset)) |
1974 |
|
|
{ |
1975 |
|
|
if (!SvROK (global_work_offset) || SvTYPE (SvRV (global_work_offset)) != SVt_PVAV) |
1976 |
|
|
croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array reference"); |
1977 |
|
|
|
1978 |
|
|
if (AvFILLp (SvRV (global_work_size)) + 1 != gws_len) |
1979 |
|
|
croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array of same size as global_work_size"); |
1980 |
|
|
|
1981 |
|
|
gwo = lists + gws_len * 1; |
1982 |
|
|
for (i = 0; i < gws_len; ++i) |
1983 |
|
|
gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); |
1984 |
|
|
} |
1985 |
|
|
|
1986 |
|
|
if (SvOK (local_work_size)) |
1987 |
|
|
{ |
1988 |
root |
1.37 |
if ((SvOK (local_work_size) && !SvROK (local_work_size)) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV) |
1989 |
root |
1.58 |
croak ("clEnqueueNDRangeKernel: local_work_size must be undef or an array reference"); |
1990 |
root |
1.4 |
|
1991 |
|
|
if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) |
1992 |
|
|
croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size"); |
1993 |
|
|
|
1994 |
|
|
lws = lists + gws_len * 2; |
1995 |
|
|
for (i = 0; i < gws_len; ++i) |
1996 |
root |
1.58 |
{ |
1997 |
|
|
lws [i] = SvIV (AvARRAY (SvRV (local_work_size))[i]); |
1998 |
|
|
// at least nvidia crashes for 0-sized work group sizes, work around |
1999 |
|
|
if (!lws [i]) |
2000 |
|
|
croak ("clEnqueueNDRangeKernel: local_work_size[%d] is zero, must be non-zero", i); |
2001 |
|
|
} |
2002 |
root |
1.4 |
} |
2003 |
|
|
|
2004 |
root |
1.69 |
cl_event ev = 0; |
2005 |
root |
1.22 |
NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
2006 |
root |
1.4 |
|
2007 |
|
|
if (ev) |
2008 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
2009 |
root |
1.3 |
|
2010 |
root |
1.65 |
#if CL_VERSION_1_2 |
2011 |
|
|
|
2012 |
|
|
void |
2013 |
|
|
migrate_mem_objects (OpenCL::Queue self, SV *objects, cl_mem_migration_flags flags, ...) |
2014 |
|
|
ALIAS: |
2015 |
|
|
enqueue_migrate_mem_objects = 0 |
2016 |
|
|
PPCODE: |
2017 |
|
|
EVENT_LIST (3); |
2018 |
|
|
|
2019 |
root |
1.69 |
cl_uint obj_count; |
2020 |
|
|
cl_mem *obj_list = object_list (cv, 0, "objects", objects, "OpenCL::Memory", &obj_count); |
2021 |
root |
1.65 |
|
2022 |
|
|
cl_event ev = 0; |
2023 |
root |
1.69 |
NEED_SUCCESS (EnqueueMigrateMemObjects, (self, obj_count, obj_list, flags, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
2024 |
root |
1.65 |
|
2025 |
|
|
if (ev) |
2026 |
|
|
XPUSH_CLOBJ (stash_event, ev); |
2027 |
|
|
|
2028 |
|
|
#endif |
2029 |
|
|
|
2030 |
root |
1.25 |
#if cl_apple_gl_sharing || cl_khr_gl_sharing |
2031 |
|
|
|
2032 |
|
|
void |
2033 |
root |
1.55 |
acquire_gl_objects (OpenCL::Queue self, SV *objects, ...) |
2034 |
|
|
ALIAS: |
2035 |
root |
1.60 |
release_gl_objects = 1 |
2036 |
root |
1.55 |
enqueue_acquire_gl_objects = 0 |
2037 |
root |
1.27 |
enqueue_release_gl_objects = 1 |
2038 |
root |
1.36 |
PPCODE: |
2039 |
root |
1.69 |
EVENT_LIST (2); |
2040 |
|
|
|
2041 |
|
|
cl_uint obj_count; |
2042 |
|
|
cl_mem *obj_list = object_list (cv, 0, "objects", objects, "OpenCL::Memory", &obj_count); |
2043 |
root |
1.27 |
|
2044 |
root |
1.25 |
cl_event ev = 0; |
2045 |
|
|
|
2046 |
root |
1.27 |
if (ix) |
2047 |
root |
1.69 |
NEED_SUCCESS (EnqueueReleaseGLObjects, (self, obj_count, obj_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
2048 |
root |
1.27 |
else |
2049 |
root |
1.69 |
NEED_SUCCESS (EnqueueAcquireGLObjects, (self, obj_count, obj_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
2050 |
root |
1.25 |
|
2051 |
|
|
if (ev) |
2052 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
2053 |
root |
1.25 |
|
2054 |
|
|
#endif |
2055 |
|
|
|
2056 |
root |
1.2 |
void |
2057 |
root |
1.55 |
wait_for_events (OpenCL::Queue self, ...) |
2058 |
|
|
ALIAS: |
2059 |
|
|
enqueue_wait_for_events = 0 |
2060 |
root |
1.2 |
CODE: |
2061 |
root |
1.61 |
EVENT_LIST (1); |
2062 |
root |
1.47 |
#if PREFER_1_1 |
2063 |
root |
1.22 |
NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); |
2064 |
root |
1.47 |
#else |
2065 |
|
|
NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, 0)); |
2066 |
root |
1.38 |
#endif |
2067 |
|
|
|
2068 |
|
|
void |
2069 |
root |
1.55 |
marker (OpenCL::Queue self, ...) |
2070 |
|
|
ALIAS: |
2071 |
|
|
enqueue_marker = 0 |
2072 |
root |
1.38 |
PPCODE: |
2073 |
root |
1.69 |
EVENT_LIST (1); |
2074 |
root |
1.38 |
cl_event ev = 0; |
2075 |
root |
1.45 |
#if PREFER_1_1 |
2076 |
root |
1.47 |
if (!event_list_count) |
2077 |
|
|
NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0)); |
2078 |
|
|
else |
2079 |
root |
1.46 |
#if CL_VERSION_1_2 |
2080 |
|
|
NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
2081 |
|
|
#else |
2082 |
root |
1.50 |
{ |
2083 |
|
|
NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); // also a barrier |
2084 |
|
|
NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0)); |
2085 |
|
|
} |
2086 |
root |
1.46 |
#endif |
2087 |
root |
1.45 |
#else |
2088 |
|
|
NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
2089 |
root |
1.38 |
#endif |
2090 |
|
|
if (ev) |
2091 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
2092 |
root |
1.38 |
|
2093 |
root |
1.2 |
void |
2094 |
root |
1.55 |
barrier (OpenCL::Queue self, ...) |
2095 |
|
|
ALIAS: |
2096 |
|
|
enqueue_barrier = 0 |
2097 |
root |
1.38 |
PPCODE: |
2098 |
root |
1.69 |
EVENT_LIST (1); |
2099 |
root |
1.38 |
cl_event ev = 0; |
2100 |
root |
1.45 |
#if PREFER_1_1 |
2101 |
root |
1.47 |
if (!event_list_count && GIMME_V == G_VOID) |
2102 |
|
|
NEED_SUCCESS (EnqueueBarrier, (self)); |
2103 |
|
|
else |
2104 |
root |
1.46 |
#if CL_VERSION_1_2 |
2105 |
|
|
NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
2106 |
|
|
#else |
2107 |
root |
1.47 |
{ |
2108 |
|
|
if (event_list_count) |
2109 |
root |
1.50 |
NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); |
2110 |
root |
1.47 |
|
2111 |
|
|
if (GIMME_V != G_VOID) |
2112 |
|
|
NEED_SUCCESS (EnqueueMarker, (self, &ev)); |
2113 |
|
|
} |
2114 |
root |
1.46 |
#endif |
2115 |
root |
1.45 |
#else |
2116 |
root |
1.46 |
NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
2117 |
root |
1.37 |
#endif |
2118 |
root |
1.38 |
if (ev) |
2119 |
root |
1.61 |
XPUSH_CLOBJ (stash_event, ev); |
2120 |
root |
1.37 |
|
2121 |
root |
1.3 |
void |
2122 |
root |
1.22 |
flush (OpenCL::Queue self) |
2123 |
root |
1.3 |
CODE: |
2124 |
root |
1.22 |
NEED_SUCCESS (Flush, (self)); |
2125 |
root |
1.3 |
|
2126 |
|
|
void |
2127 |
root |
1.22 |
finish (OpenCL::Queue self) |
2128 |
root |
1.3 |
CODE: |
2129 |
root |
1.22 |
NEED_SUCCESS (Finish, (self)); |
2130 |
root |
1.3 |
|
2131 |
root |
1.14 |
void |
2132 |
root |
1.22 |
info (OpenCL::Queue self, cl_command_queue_info name) |
2133 |
root |
1.14 |
PPCODE: |
2134 |
|
|
INFO (CommandQueue) |
2135 |
|
|
|
2136 |
|
|
#BEGIN:command_queue |
2137 |
|
|
|
2138 |
|
|
void |
2139 |
root |
1.22 |
context (OpenCL::Queue self) |
2140 |
root |
1.14 |
PPCODE: |
2141 |
|
|
cl_context value [1]; |
2142 |
root |
1.22 |
NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_CONTEXT, sizeof (value), value, 0)); |
2143 |
root |
1.14 |
EXTEND (SP, 1); |
2144 |
|
|
const int i = 0; |
2145 |
|
|
{ |
2146 |
|
|
NEED_SUCCESS (RetainContext, (value [i])); |
2147 |
root |
1.61 |
PUSH_CLOBJ (stash_context, value [i]); |
2148 |
root |
1.14 |
} |
2149 |
|
|
|
2150 |
|
|
void |
2151 |
root |
1.22 |
device (OpenCL::Queue self) |
2152 |
root |
1.14 |
PPCODE: |
2153 |
|
|
cl_device_id value [1]; |
2154 |
root |
1.22 |
NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_DEVICE, sizeof (value), value, 0)); |
2155 |
root |
1.14 |
EXTEND (SP, 1); |
2156 |
|
|
const int i = 0; |
2157 |
|
|
{ |
2158 |
root |
1.61 |
PUSH_CLOBJ (stash_device, value [i]); |
2159 |
root |
1.14 |
} |
2160 |
|
|
|
2161 |
|
|
void |
2162 |
root |
1.22 |
reference_count (OpenCL::Queue self) |
2163 |
root |
1.14 |
PPCODE: |
2164 |
|
|
cl_uint value [1]; |
2165 |
root |
1.22 |
NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_REFERENCE_COUNT, sizeof (value), value, 0)); |
2166 |
root |
1.14 |
EXTEND (SP, 1); |
2167 |
|
|
const int i = 0; |
2168 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2169 |
|
|
|
2170 |
|
|
void |
2171 |
root |
1.22 |
properties (OpenCL::Queue self) |
2172 |
root |
1.14 |
PPCODE: |
2173 |
|
|
cl_command_queue_properties value [1]; |
2174 |
root |
1.22 |
NEED_SUCCESS (GetCommandQueueInfo, (self, CL_QUEUE_PROPERTIES, sizeof (value), value, 0)); |
2175 |
root |
1.14 |
EXTEND (SP, 1); |
2176 |
|
|
const int i = 0; |
2177 |
root |
1.61 |
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2178 |
root |
1.14 |
|
2179 |
|
|
#END:command_queue |
2180 |
|
|
|
2181 |
root |
1.2 |
MODULE = OpenCL PACKAGE = OpenCL::Memory |
2182 |
|
|
|
2183 |
|
|
void |
2184 |
root |
1.22 |
DESTROY (OpenCL::Memory self) |
2185 |
root |
1.2 |
CODE: |
2186 |
root |
1.22 |
clReleaseMemObject (self); |
2187 |
root |
1.2 |
|
2188 |
|
|
void |
2189 |
root |
1.22 |
info (OpenCL::Memory self, cl_mem_info name) |
2190 |
root |
1.2 |
PPCODE: |
2191 |
|
|
INFO (MemObject) |
2192 |
|
|
|
2193 |
root |
1.14 |
#BEGIN:mem |
2194 |
|
|
|
2195 |
|
|
void |
2196 |
root |
1.22 |
type (OpenCL::Memory self) |
2197 |
root |
1.14 |
PPCODE: |
2198 |
|
|
cl_mem_object_type value [1]; |
2199 |
root |
1.22 |
NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_TYPE, sizeof (value), value, 0)); |
2200 |
root |
1.14 |
EXTEND (SP, 1); |
2201 |
|
|
const int i = 0; |
2202 |
root |
1.61 |
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2203 |
root |
1.14 |
|
2204 |
|
|
void |
2205 |
root |
1.22 |
flags (OpenCL::Memory self) |
2206 |
root |
1.14 |
PPCODE: |
2207 |
|
|
cl_mem_flags value [1]; |
2208 |
root |
1.22 |
NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_FLAGS, sizeof (value), value, 0)); |
2209 |
root |
1.14 |
EXTEND (SP, 1); |
2210 |
|
|
const int i = 0; |
2211 |
root |
1.61 |
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2212 |
root |
1.14 |
|
2213 |
|
|
void |
2214 |
root |
1.22 |
size (OpenCL::Memory self) |
2215 |
root |
1.16 |
ALIAS: |
2216 |
|
|
size = CL_MEM_SIZE |
2217 |
|
|
offset = CL_MEM_OFFSET |
2218 |
root |
1.14 |
PPCODE: |
2219 |
|
|
size_t value [1]; |
2220 |
root |
1.22 |
NEED_SUCCESS (GetMemObjectInfo, (self, ix, sizeof (value), value, 0)); |
2221 |
root |
1.14 |
EXTEND (SP, 1); |
2222 |
|
|
const int i = 0; |
2223 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2224 |
|
|
|
2225 |
|
|
void |
2226 |
root |
1.22 |
host_ptr (OpenCL::Memory self) |
2227 |
root |
1.14 |
PPCODE: |
2228 |
|
|
void * value [1]; |
2229 |
root |
1.22 |
NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_HOST_PTR, sizeof (value), value, 0)); |
2230 |
root |
1.14 |
EXTEND (SP, 1); |
2231 |
|
|
const int i = 0; |
2232 |
|
|
PUSHs (sv_2mortal (newSVuv ((IV)(intptr_t)value [i]))); |
2233 |
|
|
|
2234 |
|
|
void |
2235 |
root |
1.22 |
map_count (OpenCL::Memory self) |
2236 |
root |
1.16 |
ALIAS: |
2237 |
|
|
map_count = CL_MEM_MAP_COUNT |
2238 |
|
|
reference_count = CL_MEM_REFERENCE_COUNT |
2239 |
root |
1.14 |
PPCODE: |
2240 |
|
|
cl_uint value [1]; |
2241 |
root |
1.22 |
NEED_SUCCESS (GetMemObjectInfo, (self, ix, sizeof (value), value, 0)); |
2242 |
root |
1.14 |
EXTEND (SP, 1); |
2243 |
|
|
const int i = 0; |
2244 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2245 |
|
|
|
2246 |
|
|
void |
2247 |
root |
1.22 |
context (OpenCL::Memory self) |
2248 |
root |
1.14 |
PPCODE: |
2249 |
|
|
cl_context value [1]; |
2250 |
root |
1.22 |
NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_CONTEXT, sizeof (value), value, 0)); |
2251 |
root |
1.14 |
EXTEND (SP, 1); |
2252 |
|
|
const int i = 0; |
2253 |
|
|
{ |
2254 |
|
|
NEED_SUCCESS (RetainContext, (value [i])); |
2255 |
root |
1.61 |
PUSH_CLOBJ (stash_context, value [i]); |
2256 |
root |
1.14 |
} |
2257 |
|
|
|
2258 |
|
|
void |
2259 |
root |
1.22 |
associated_memobject (OpenCL::Memory self) |
2260 |
root |
1.14 |
PPCODE: |
2261 |
|
|
cl_mem value [1]; |
2262 |
root |
1.22 |
NEED_SUCCESS (GetMemObjectInfo, (self, CL_MEM_ASSOCIATED_MEMOBJECT, sizeof (value), value, 0)); |
2263 |
root |
1.14 |
EXTEND (SP, 1); |
2264 |
|
|
const int i = 0; |
2265 |
|
|
{ |
2266 |
|
|
NEED_SUCCESS (RetainMemObject, (value [i])); |
2267 |
root |
1.61 |
PUSH_CLOBJ (stash_memory, value [i]); |
2268 |
root |
1.14 |
} |
2269 |
|
|
|
2270 |
|
|
#END:mem |
2271 |
|
|
|
2272 |
root |
1.26 |
#if cl_apple_gl_sharing || cl_khr_gl_sharing |
2273 |
|
|
|
2274 |
|
|
void |
2275 |
|
|
gl_object_info (OpenCL::Memory self) |
2276 |
|
|
PPCODE: |
2277 |
|
|
cl_gl_object_type type; |
2278 |
|
|
cl_GLuint name; |
2279 |
root |
1.31 |
NEED_SUCCESS (GetGLObjectInfo, (self, &type, &name)); |
2280 |
root |
1.26 |
EXTEND (SP, 2); |
2281 |
|
|
PUSHs (sv_2mortal (newSVuv (type))); |
2282 |
|
|
PUSHs (sv_2mortal (newSVuv (name))); |
2283 |
|
|
|
2284 |
|
|
#endif |
2285 |
|
|
|
2286 |
root |
1.18 |
MODULE = OpenCL PACKAGE = OpenCL::BufferObj |
2287 |
|
|
|
2288 |
|
|
void |
2289 |
root |
1.22 |
sub_buffer_region (OpenCL::BufferObj self, cl_mem_flags flags, size_t origin, size_t size) |
2290 |
root |
1.18 |
PPCODE: |
2291 |
|
|
if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_ALLOC_HOST_PTR)) |
2292 |
|
|
croak ("clCreateSubBuffer: cannot use/copy/alloc host ptr, doesn't make sense, check your flags!"); |
2293 |
|
|
|
2294 |
|
|
cl_buffer_region crdata = { origin, size }; |
2295 |
|
|
|
2296 |
root |
1.22 |
NEED_SUCCESS_ARG (cl_mem mem, CreateSubBuffer, (self, flags, CL_BUFFER_CREATE_TYPE_REGION, &crdata, &res)); |
2297 |
root |
1.61 |
XPUSH_CLOBJ (stash_buffer, mem); |
2298 |
root |
1.18 |
|
2299 |
root |
1.13 |
MODULE = OpenCL PACKAGE = OpenCL::Image |
2300 |
|
|
|
2301 |
|
|
void |
2302 |
root |
1.22 |
image_info (OpenCL::Image self, cl_image_info name) |
2303 |
root |
1.13 |
PPCODE: |
2304 |
|
|
INFO (Image) |
2305 |
|
|
|
2306 |
root |
1.49 |
void |
2307 |
|
|
format (OpenCL::Image self) |
2308 |
|
|
PPCODE: |
2309 |
|
|
cl_image_format format; |
2310 |
|
|
NEED_SUCCESS (GetImageInfo, (self, CL_IMAGE_FORMAT, sizeof (format), &format, 0)); |
2311 |
|
|
EXTEND (SP, 2); |
2312 |
|
|
PUSHs (sv_2mortal (newSVuv (format.image_channel_order))); |
2313 |
|
|
PUSHs (sv_2mortal (newSVuv (format.image_channel_data_type))); |
2314 |
|
|
|
2315 |
root |
1.14 |
#BEGIN:image |
2316 |
|
|
|
2317 |
|
|
void |
2318 |
root |
1.22 |
element_size (OpenCL::Image self) |
2319 |
root |
1.16 |
ALIAS: |
2320 |
|
|
element_size = CL_IMAGE_ELEMENT_SIZE |
2321 |
|
|
row_pitch = CL_IMAGE_ROW_PITCH |
2322 |
|
|
slice_pitch = CL_IMAGE_SLICE_PITCH |
2323 |
|
|
width = CL_IMAGE_WIDTH |
2324 |
|
|
height = CL_IMAGE_HEIGHT |
2325 |
|
|
depth = CL_IMAGE_DEPTH |
2326 |
root |
1.14 |
PPCODE: |
2327 |
|
|
size_t value [1]; |
2328 |
root |
1.22 |
NEED_SUCCESS (GetImageInfo, (self, ix, sizeof (value), value, 0)); |
2329 |
root |
1.14 |
EXTEND (SP, 1); |
2330 |
|
|
const int i = 0; |
2331 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2332 |
|
|
|
2333 |
|
|
#END:image |
2334 |
|
|
|
2335 |
root |
1.26 |
#if cl_apple_gl_sharing || cl_khr_gl_sharing |
2336 |
|
|
|
2337 |
|
|
#BEGIN:gl_texture |
2338 |
|
|
|
2339 |
|
|
void |
2340 |
|
|
target (OpenCL::Image self) |
2341 |
|
|
PPCODE: |
2342 |
|
|
cl_GLenum value [1]; |
2343 |
root |
1.31 |
NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0)); |
2344 |
root |
1.26 |
EXTEND (SP, 1); |
2345 |
|
|
const int i = 0; |
2346 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2347 |
|
|
|
2348 |
|
|
void |
2349 |
|
|
gl_mipmap_level (OpenCL::Image self) |
2350 |
|
|
PPCODE: |
2351 |
|
|
cl_GLint value [1]; |
2352 |
root |
1.31 |
NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0)); |
2353 |
root |
1.26 |
EXTEND (SP, 1); |
2354 |
|
|
const int i = 0; |
2355 |
|
|
PUSHs (sv_2mortal (newSViv (value [i]))); |
2356 |
|
|
|
2357 |
|
|
#END:gl_texture |
2358 |
|
|
|
2359 |
|
|
#endif |
2360 |
|
|
|
2361 |
root |
1.2 |
MODULE = OpenCL PACKAGE = OpenCL::Sampler |
2362 |
|
|
|
2363 |
|
|
void |
2364 |
root |
1.22 |
DESTROY (OpenCL::Sampler self) |
2365 |
root |
1.2 |
CODE: |
2366 |
root |
1.22 |
clReleaseSampler (self); |
2367 |
root |
1.2 |
|
2368 |
|
|
void |
2369 |
root |
1.22 |
info (OpenCL::Sampler self, cl_sampler_info name) |
2370 |
root |
1.2 |
PPCODE: |
2371 |
|
|
INFO (Sampler) |
2372 |
|
|
|
2373 |
root |
1.14 |
#BEGIN:sampler |
2374 |
|
|
|
2375 |
|
|
void |
2376 |
root |
1.22 |
reference_count (OpenCL::Sampler self) |
2377 |
root |
1.14 |
PPCODE: |
2378 |
|
|
cl_uint value [1]; |
2379 |
root |
1.22 |
NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_REFERENCE_COUNT, sizeof (value), value, 0)); |
2380 |
root |
1.14 |
EXTEND (SP, 1); |
2381 |
|
|
const int i = 0; |
2382 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2383 |
|
|
|
2384 |
|
|
void |
2385 |
root |
1.22 |
context (OpenCL::Sampler self) |
2386 |
root |
1.14 |
PPCODE: |
2387 |
|
|
cl_context value [1]; |
2388 |
root |
1.22 |
NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_CONTEXT, sizeof (value), value, 0)); |
2389 |
root |
1.14 |
EXTEND (SP, 1); |
2390 |
|
|
const int i = 0; |
2391 |
|
|
{ |
2392 |
|
|
NEED_SUCCESS (RetainContext, (value [i])); |
2393 |
root |
1.61 |
PUSH_CLOBJ (stash_context, value [i]); |
2394 |
root |
1.14 |
} |
2395 |
|
|
|
2396 |
|
|
void |
2397 |
root |
1.22 |
normalized_coords (OpenCL::Sampler self) |
2398 |
root |
1.14 |
PPCODE: |
2399 |
|
|
cl_addressing_mode value [1]; |
2400 |
root |
1.22 |
NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_NORMALIZED_COORDS, sizeof (value), value, 0)); |
2401 |
root |
1.14 |
EXTEND (SP, 1); |
2402 |
|
|
const int i = 0; |
2403 |
root |
1.61 |
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2404 |
root |
1.14 |
|
2405 |
|
|
void |
2406 |
root |
1.22 |
addressing_mode (OpenCL::Sampler self) |
2407 |
root |
1.14 |
PPCODE: |
2408 |
|
|
cl_filter_mode value [1]; |
2409 |
root |
1.22 |
NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_ADDRESSING_MODE, sizeof (value), value, 0)); |
2410 |
root |
1.14 |
EXTEND (SP, 1); |
2411 |
|
|
const int i = 0; |
2412 |
root |
1.61 |
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2413 |
root |
1.14 |
|
2414 |
|
|
void |
2415 |
root |
1.22 |
filter_mode (OpenCL::Sampler self) |
2416 |
root |
1.14 |
PPCODE: |
2417 |
|
|
cl_bool value [1]; |
2418 |
root |
1.22 |
NEED_SUCCESS (GetSamplerInfo, (self, CL_SAMPLER_FILTER_MODE, sizeof (value), value, 0)); |
2419 |
root |
1.14 |
EXTEND (SP, 1); |
2420 |
|
|
const int i = 0; |
2421 |
|
|
PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no)); |
2422 |
|
|
|
2423 |
|
|
#END:sampler |
2424 |
|
|
|
2425 |
root |
1.2 |
MODULE = OpenCL PACKAGE = OpenCL::Program |
2426 |
|
|
|
2427 |
|
|
void |
2428 |
root |
1.22 |
DESTROY (OpenCL::Program self) |
2429 |
root |
1.2 |
CODE: |
2430 |
root |
1.22 |
clReleaseProgram (self); |
2431 |
root |
1.2 |
|
2432 |
|
|
void |
2433 |
root |
1.51 |
build (OpenCL::Program self, SV *devices = &PL_sv_undef, SV *options = &PL_sv_undef, SV *notify = &PL_sv_undef) |
2434 |
|
|
ALIAS: |
2435 |
|
|
build_async = 1 |
2436 |
root |
1.2 |
CODE: |
2437 |
root |
1.69 |
cl_uint device_count = 0; |
2438 |
|
|
cl_device_id *device_list = 0; |
2439 |
root |
1.51 |
|
2440 |
|
|
if (SvOK (devices)) |
2441 |
root |
1.69 |
device_list = object_list (cv, 1, "devices", devices, "OpenCL::Device", &device_count); |
2442 |
|
|
|
2443 |
|
|
void *user_data; |
2444 |
|
|
program_callback pfn_notify = make_program_callback (notify, &user_data); |
2445 |
|
|
|
2446 |
|
|
if (ix) |
2447 |
|
|
build_program_async (self, device_count, device_list, SvPVbyte_nolen (options), user_data); |
2448 |
|
|
else |
2449 |
|
|
NEED_SUCCESS (BuildProgram, (self, device_count, device_list, SvPVbyte_nolen (options), pfn_notify, user_data)); |
2450 |
|
|
|
2451 |
|
|
#if CL_VERSION_1_2 |
2452 |
|
|
|
2453 |
|
|
void |
2454 |
|
|
compile (OpenCL::Program self, SV *devices, SV *options = &PL_sv_undef, SV *headers = &PL_sv_undef, SV *notify = &PL_sv_undef) |
2455 |
|
|
CODE: |
2456 |
|
|
cl_uint device_count = 0; |
2457 |
|
|
cl_device_id *device_list = 0; |
2458 |
|
|
|
2459 |
|
|
if (SvOK (devices)) |
2460 |
|
|
device_list = object_list (cv, 1, "devices", devices, "OpenCL::Device", &device_count); |
2461 |
|
|
|
2462 |
|
|
cl_uint header_count = 0; |
2463 |
|
|
cl_program *header_list = 0; |
2464 |
|
|
const char **header_name = 0; |
2465 |
|
|
|
2466 |
|
|
if (SvOK (headers)) |
2467 |
|
|
{ |
2468 |
|
|
if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVHV) |
2469 |
|
|
croak ("clCompileProgram: headers must be undef or a hashref of name => OpenCL::Program pairs"); |
2470 |
root |
1.51 |
|
2471 |
root |
1.69 |
HV *hv = (HV *)SvRV (devices); |
2472 |
root |
1.51 |
|
2473 |
root |
1.69 |
header_count = hv_iterinit (hv); |
2474 |
|
|
header_list = tmpbuf (sizeof (*header_list) * header_count); |
2475 |
|
|
header_name = tmpbuf (sizeof (*header_name) * header_count); |
2476 |
|
|
|
2477 |
|
|
HE *he; |
2478 |
|
|
int i = 0; |
2479 |
|
|
while (he = hv_iternext (hv)) |
2480 |
root |
1.51 |
{ |
2481 |
root |
1.69 |
header_name [i] = SvPVbyte_nolen (HeSVKEY_force (he)); |
2482 |
root |
1.71 |
header_list [i] = SvCLOBJ (cv, "headers", HeVAL (he), "OpenCL::Program"); |
2483 |
root |
1.69 |
++i; |
2484 |
root |
1.51 |
} |
2485 |
|
|
} |
2486 |
|
|
|
2487 |
root |
1.69 |
void *user_data; |
2488 |
|
|
program_callback pfn_notify = make_program_callback (notify, &user_data); |
2489 |
|
|
|
2490 |
|
|
NEED_SUCCESS (CompileProgram, (self, device_count, device_list, SvPVbyte_nolen (options), |
2491 |
|
|
header_count, header_list, header_name, pfn_notify, user_data)); |
2492 |
root |
1.51 |
|
2493 |
root |
1.69 |
#endif |
2494 |
root |
1.2 |
|
2495 |
|
|
void |
2496 |
root |
1.22 |
build_info (OpenCL::Program self, OpenCL::Device device, cl_program_build_info name) |
2497 |
root |
1.2 |
PPCODE: |
2498 |
root |
1.23 |
size_t size; |
2499 |
|
|
NEED_SUCCESS (GetProgramBuildInfo, (self, device, name, 0, 0, &size)); |
2500 |
root |
1.10 |
SV *sv = sv_2mortal (newSV (size)); |
2501 |
root |
1.1 |
SvUPGRADE (sv, SVt_PV); |
2502 |
|
|
SvPOK_only (sv); |
2503 |
|
|
SvCUR_set (sv, size); |
2504 |
root |
1.23 |
NEED_SUCCESS (GetProgramBuildInfo, (self, device, name, size, SvPVX (sv), 0)); |
2505 |
root |
1.1 |
XPUSHs (sv); |
2506 |
|
|
|
2507 |
root |
1.14 |
#BEGIN:program_build |
2508 |
|
|
|
2509 |
|
|
void |
2510 |
root |
1.22 |
build_status (OpenCL::Program self, OpenCL::Device device) |
2511 |
root |
1.14 |
PPCODE: |
2512 |
|
|
cl_build_status value [1]; |
2513 |
root |
1.22 |
NEED_SUCCESS (GetProgramBuildInfo, (self, device, CL_PROGRAM_BUILD_STATUS, sizeof (value), value, 0)); |
2514 |
root |
1.14 |
EXTEND (SP, 1); |
2515 |
|
|
const int i = 0; |
2516 |
|
|
PUSHs (sv_2mortal (newSViv (value [i]))); |
2517 |
|
|
|
2518 |
|
|
void |
2519 |
root |
1.22 |
build_options (OpenCL::Program self, OpenCL::Device device) |
2520 |
root |
1.16 |
ALIAS: |
2521 |
|
|
build_options = CL_PROGRAM_BUILD_OPTIONS |
2522 |
|
|
build_log = CL_PROGRAM_BUILD_LOG |
2523 |
root |
1.14 |
PPCODE: |
2524 |
|
|
size_t size; |
2525 |
root |
1.22 |
NEED_SUCCESS (GetProgramBuildInfo, (self, device, ix, 0, 0, &size)); |
2526 |
root |
1.14 |
char *value = tmpbuf (size); |
2527 |
root |
1.22 |
NEED_SUCCESS (GetProgramBuildInfo, (self, device, ix, size, value, 0)); |
2528 |
root |
1.16 |
EXTEND (SP, 1); |
2529 |
|
|
const int i = 0; |
2530 |
root |
1.14 |
PUSHs (sv_2mortal (newSVpv (value, 0))); |
2531 |
|
|
|
2532 |
root |
1.73 |
void |
2533 |
|
|
binary_type (OpenCL::Program self, OpenCL::Device device) |
2534 |
|
|
PPCODE: |
2535 |
|
|
cl_program_binary_type value [1]; |
2536 |
|
|
NEED_SUCCESS (GetProgramBuildInfo, (self, device, CL_PROGRAM_BINARY_TYPE, sizeof (value), value, 0)); |
2537 |
|
|
EXTEND (SP, 1); |
2538 |
|
|
const int i = 0; |
2539 |
root |
1.74 |
PUSHs (sv_2mortal (newSVuv ((UV)value [i]))); |
2540 |
root |
1.73 |
|
2541 |
root |
1.14 |
#END:program_build |
2542 |
|
|
|
2543 |
root |
1.2 |
void |
2544 |
|
|
kernel (OpenCL::Program program, SV *function) |
2545 |
|
|
PPCODE: |
2546 |
root |
1.23 |
NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res)); |
2547 |
root |
1.61 |
XPUSH_CLOBJ (stash_kernel, kernel); |
2548 |
root |
1.2 |
|
2549 |
root |
1.14 |
void |
2550 |
root |
1.47 |
kernels_in_program (OpenCL::Program program) |
2551 |
|
|
PPCODE: |
2552 |
|
|
cl_uint num_kernels; |
2553 |
|
|
NEED_SUCCESS (CreateKernelsInProgram, (program, 0, 0, &num_kernels)); |
2554 |
|
|
cl_kernel *kernels = tmpbuf (sizeof (cl_kernel) * num_kernels); |
2555 |
|
|
NEED_SUCCESS (CreateKernelsInProgram, (program, num_kernels, kernels, 0)); |
2556 |
|
|
|
2557 |
|
|
int i; |
2558 |
|
|
EXTEND (SP, num_kernels); |
2559 |
|
|
for (i = 0; i < num_kernels; ++i) |
2560 |
root |
1.61 |
PUSH_CLOBJ (stash_kernel, kernels [i]); |
2561 |
root |
1.47 |
|
2562 |
|
|
void |
2563 |
root |
1.22 |
info (OpenCL::Program self, cl_program_info name) |
2564 |
root |
1.14 |
PPCODE: |
2565 |
|
|
INFO (Program) |
2566 |
|
|
|
2567 |
root |
1.15 |
void |
2568 |
root |
1.22 |
binaries (OpenCL::Program self) |
2569 |
root |
1.15 |
PPCODE: |
2570 |
|
|
cl_uint n, i; |
2571 |
|
|
size_t size; |
2572 |
|
|
|
2573 |
root |
1.22 |
NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_NUM_DEVICES , sizeof (n) , &n , 0)); |
2574 |
root |
1.15 |
if (!n) XSRETURN_EMPTY; |
2575 |
|
|
|
2576 |
|
|
size_t *sizes = tmpbuf (sizeof (*sizes) * n); |
2577 |
root |
1.22 |
NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARY_SIZES, sizeof (*sizes) * n, sizes, &size)); |
2578 |
root |
1.15 |
if (size != sizeof (*sizes) * n) XSRETURN_EMPTY; |
2579 |
|
|
unsigned char **ptrs = tmpbuf (sizeof (*ptrs) * n); |
2580 |
|
|
|
2581 |
|
|
EXTEND (SP, n); |
2582 |
|
|
for (i = 0; i < n; ++i) |
2583 |
|
|
{ |
2584 |
|
|
SV *sv = sv_2mortal (newSV (sizes [i])); |
2585 |
|
|
SvUPGRADE (sv, SVt_PV); |
2586 |
|
|
SvPOK_only (sv); |
2587 |
|
|
SvCUR_set (sv, sizes [i]); |
2588 |
root |
1.37 |
ptrs [i] = (void *)SvPVX (sv); |
2589 |
root |
1.15 |
PUSHs (sv); |
2590 |
|
|
} |
2591 |
|
|
|
2592 |
root |
1.22 |
NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size)); |
2593 |
root |
1.15 |
if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; |
2594 |
|
|
|
2595 |
root |
1.14 |
#BEGIN:program |
2596 |
|
|
|
2597 |
|
|
void |
2598 |
root |
1.22 |
reference_count (OpenCL::Program self) |
2599 |
root |
1.16 |
ALIAS: |
2600 |
|
|
reference_count = CL_PROGRAM_REFERENCE_COUNT |
2601 |
|
|
num_devices = CL_PROGRAM_NUM_DEVICES |
2602 |
root |
1.14 |
PPCODE: |
2603 |
|
|
cl_uint value [1]; |
2604 |
root |
1.22 |
NEED_SUCCESS (GetProgramInfo, (self, ix, sizeof (value), value, 0)); |
2605 |
root |
1.14 |
EXTEND (SP, 1); |
2606 |
|
|
const int i = 0; |
2607 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2608 |
|
|
|
2609 |
|
|
void |
2610 |
root |
1.22 |
context (OpenCL::Program self) |
2611 |
root |
1.14 |
PPCODE: |
2612 |
|
|
cl_context value [1]; |
2613 |
root |
1.22 |
NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_CONTEXT, sizeof (value), value, 0)); |
2614 |
root |
1.14 |
EXTEND (SP, 1); |
2615 |
|
|
const int i = 0; |
2616 |
|
|
{ |
2617 |
|
|
NEED_SUCCESS (RetainContext, (value [i])); |
2618 |
root |
1.61 |
PUSH_CLOBJ (stash_context, value [i]); |
2619 |
root |
1.14 |
} |
2620 |
|
|
|
2621 |
|
|
void |
2622 |
root |
1.22 |
devices (OpenCL::Program self) |
2623 |
root |
1.14 |
PPCODE: |
2624 |
|
|
size_t size; |
2625 |
root |
1.22 |
NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_DEVICES, 0, 0, &size)); |
2626 |
root |
1.14 |
cl_device_id *value = tmpbuf (size); |
2627 |
root |
1.22 |
NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_DEVICES, size, value, 0)); |
2628 |
root |
1.15 |
int i, n = size / sizeof (*value); |
2629 |
root |
1.14 |
EXTEND (SP, n); |
2630 |
|
|
for (i = 0; i < n; ++i) |
2631 |
|
|
{ |
2632 |
root |
1.61 |
PUSH_CLOBJ (stash_device, value [i]); |
2633 |
root |
1.14 |
} |
2634 |
|
|
|
2635 |
|
|
void |
2636 |
root |
1.22 |
source (OpenCL::Program self) |
2637 |
root |
1.14 |
PPCODE: |
2638 |
|
|
size_t size; |
2639 |
root |
1.22 |
NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_SOURCE, 0, 0, &size)); |
2640 |
root |
1.14 |
char *value = tmpbuf (size); |
2641 |
root |
1.22 |
NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_SOURCE, size, value, 0)); |
2642 |
root |
1.16 |
EXTEND (SP, 1); |
2643 |
|
|
const int i = 0; |
2644 |
root |
1.14 |
PUSHs (sv_2mortal (newSVpv (value, 0))); |
2645 |
|
|
|
2646 |
|
|
void |
2647 |
root |
1.22 |
binary_sizes (OpenCL::Program self) |
2648 |
root |
1.14 |
PPCODE: |
2649 |
|
|
size_t size; |
2650 |
root |
1.22 |
NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARY_SIZES, 0, 0, &size)); |
2651 |
root |
1.14 |
size_t *value = tmpbuf (size); |
2652 |
root |
1.22 |
NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARY_SIZES, size, value, 0)); |
2653 |
root |
1.15 |
int i, n = size / sizeof (*value); |
2654 |
root |
1.14 |
EXTEND (SP, n); |
2655 |
|
|
for (i = 0; i < n; ++i) |
2656 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2657 |
|
|
|
2658 |
|
|
#END:program |
2659 |
|
|
|
2660 |
root |
1.2 |
MODULE = OpenCL PACKAGE = OpenCL::Kernel |
2661 |
|
|
|
2662 |
|
|
void |
2663 |
root |
1.22 |
DESTROY (OpenCL::Kernel self) |
2664 |
root |
1.2 |
CODE: |
2665 |
root |
1.22 |
clReleaseKernel (self); |
2666 |
root |
1.2 |
|
2667 |
|
|
void |
2668 |
root |
1.56 |
setf (OpenCL::Kernel self, const char *format, ...) |
2669 |
|
|
CODE: |
2670 |
|
|
int i; |
2671 |
|
|
for (i = 2; ; ++i) |
2672 |
|
|
{ |
2673 |
|
|
while (*format == ' ') |
2674 |
|
|
++format; |
2675 |
|
|
|
2676 |
|
|
char type = *format++; |
2677 |
|
|
|
2678 |
|
|
if (!type) |
2679 |
|
|
break; |
2680 |
|
|
|
2681 |
|
|
if (i >= items) |
2682 |
|
|
croak ("OpenCL::Kernel::setf format string too long (not enough arguments)"); |
2683 |
|
|
|
2684 |
|
|
SV *sv = ST (i); |
2685 |
|
|
|
2686 |
|
|
union |
2687 |
|
|
{ |
2688 |
|
|
cl_char cc; cl_uchar cC; cl_short cs; cl_ushort cS; |
2689 |
|
|
cl_int ci; cl_uint cI; cl_long cl; cl_ulong cL; |
2690 |
|
|
cl_half ch; cl_float cf; cl_double cd; |
2691 |
|
|
cl_mem cm; |
2692 |
|
|
cl_sampler ca; |
2693 |
|
|
size_t cz; |
2694 |
|
|
cl_event ce; |
2695 |
|
|
} arg; |
2696 |
|
|
size_t size; |
2697 |
root |
1.59 |
int nullarg = 0; |
2698 |
root |
1.56 |
|
2699 |
|
|
switch (type) |
2700 |
|
|
{ |
2701 |
|
|
case 'c': arg.cc = SvIV (sv); size = sizeof (arg.cc); break; |
2702 |
|
|
case 'C': arg.cC = SvUV (sv); size = sizeof (arg.cC); break; |
2703 |
|
|
case 's': arg.cs = SvIV (sv); size = sizeof (arg.cs); break; |
2704 |
|
|
case 'S': arg.cS = SvUV (sv); size = sizeof (arg.cS); break; |
2705 |
|
|
case 'i': arg.ci = SvIV (sv); size = sizeof (arg.ci); break; |
2706 |
|
|
case 'I': arg.cI = SvUV (sv); size = sizeof (arg.cI); break; |
2707 |
|
|
case 'l': arg.cl = SvIV (sv); size = sizeof (arg.cl); break; |
2708 |
|
|
case 'L': arg.cL = SvUV (sv); size = sizeof (arg.cL); break; |
2709 |
|
|
|
2710 |
|
|
case 'h': arg.ch = SvUV (sv); size = sizeof (arg.ch); break; |
2711 |
|
|
case 'f': arg.cf = SvNV (sv); size = sizeof (arg.cf); break; |
2712 |
|
|
case 'd': arg.cd = SvNV (sv); size = sizeof (arg.cd); break; |
2713 |
|
|
|
2714 |
root |
1.59 |
case 'z': nullarg = 1; size = SvIV (sv); break; |
2715 |
|
|
|
2716 |
root |
1.71 |
case 'm': nullarg = !SvOK (sv); arg.cm = SvCLOBJ (cv, "m", sv, "OpenCL::Memory" ); size = sizeof (arg.cm); break; |
2717 |
|
|
case 'a': nullarg = !SvOK (sv); arg.ca = SvCLOBJ (cv, "a", sv, "OpenCL::Sampler"); size = sizeof (arg.ca); break; |
2718 |
|
|
case 'e': nullarg = !SvOK (sv); arg.ca = SvCLOBJ (cv, "e", sv, "OpenCL::Event" ); size = sizeof (arg.ce); break; |
2719 |
root |
1.56 |
|
2720 |
|
|
default: |
2721 |
|
|
croak ("OpenCL::Kernel::setf format character '%c' not supported", type); |
2722 |
|
|
} |
2723 |
|
|
|
2724 |
root |
1.59 |
res = clSetKernelArg (self, i - 2, size, nullarg ? 0 : &arg); |
2725 |
|
|
if (res) |
2726 |
|
|
croak ("OpenCL::Kernel::setf kernel parameter '%c' (#%d): %s", type, i - 2, err2str (res)); |
2727 |
root |
1.56 |
} |
2728 |
|
|
|
2729 |
|
|
if (i != items) |
2730 |
|
|
croak ("OpenCL::Kernel::setf format string too short (too many arguments)"); |
2731 |
|
|
|
2732 |
|
|
void |
2733 |
root |
1.22 |
set_char (OpenCL::Kernel self, cl_uint idx, cl_char value) |
2734 |
root |
1.3 |
CODE: |
2735 |
root |
1.22 |
clSetKernelArg (self, idx, sizeof (value), &value); |
2736 |
root |
1.3 |
|
2737 |
|
|
void |
2738 |
root |
1.22 |
set_uchar (OpenCL::Kernel self, cl_uint idx, cl_uchar value) |
2739 |
root |
1.3 |
CODE: |
2740 |
root |
1.22 |
clSetKernelArg (self, idx, sizeof (value), &value); |
2741 |
root |
1.3 |
|
2742 |
|
|
void |
2743 |
root |
1.22 |
set_short (OpenCL::Kernel self, cl_uint idx, cl_short value) |
2744 |
root |
1.3 |
CODE: |
2745 |
root |
1.22 |
clSetKernelArg (self, idx, sizeof (value), &value); |
2746 |
root |
1.3 |
|
2747 |
|
|
void |
2748 |
root |
1.22 |
set_ushort (OpenCL::Kernel self, cl_uint idx, cl_ushort value) |
2749 |
root |
1.3 |
CODE: |
2750 |
root |
1.22 |
clSetKernelArg (self, idx, sizeof (value), &value); |
2751 |
root |
1.3 |
|
2752 |
|
|
void |
2753 |
root |
1.22 |
set_int (OpenCL::Kernel self, cl_uint idx, cl_int value) |
2754 |
root |
1.3 |
CODE: |
2755 |
root |
1.22 |
clSetKernelArg (self, idx, sizeof (value), &value); |
2756 |
root |
1.3 |
|
2757 |
|
|
void |
2758 |
root |
1.22 |
set_uint (OpenCL::Kernel self, cl_uint idx, cl_uint value) |
2759 |
root |
1.3 |
CODE: |
2760 |
root |
1.22 |
clSetKernelArg (self, idx, sizeof (value), &value); |
2761 |
root |
1.3 |
|
2762 |
|
|
void |
2763 |
root |
1.22 |
set_long (OpenCL::Kernel self, cl_uint idx, cl_long value) |
2764 |
root |
1.3 |
CODE: |
2765 |
root |
1.22 |
clSetKernelArg (self, idx, sizeof (value), &value); |
2766 |
root |
1.3 |
|
2767 |
|
|
void |
2768 |
root |
1.22 |
set_ulong (OpenCL::Kernel self, cl_uint idx, cl_ulong value) |
2769 |
root |
1.3 |
CODE: |
2770 |
root |
1.22 |
clSetKernelArg (self, idx, sizeof (value), &value); |
2771 |
root |
1.3 |
|
2772 |
|
|
void |
2773 |
root |
1.22 |
set_half (OpenCL::Kernel self, cl_uint idx, cl_half value) |
2774 |
root |
1.3 |
CODE: |
2775 |
root |
1.22 |
clSetKernelArg (self, idx, sizeof (value), &value); |
2776 |
root |
1.3 |
|
2777 |
|
|
void |
2778 |
root |
1.22 |
set_float (OpenCL::Kernel self, cl_uint idx, cl_float value) |
2779 |
root |
1.3 |
CODE: |
2780 |
root |
1.22 |
clSetKernelArg (self, idx, sizeof (value), &value); |
2781 |
root |
1.3 |
|
2782 |
|
|
void |
2783 |
root |
1.22 |
set_double (OpenCL::Kernel self, cl_uint idx, cl_double value) |
2784 |
root |
1.5 |
CODE: |
2785 |
root |
1.22 |
clSetKernelArg (self, idx, sizeof (value), &value); |
2786 |
root |
1.5 |
|
2787 |
|
|
void |
2788 |
root |
1.22 |
set_memory (OpenCL::Kernel self, cl_uint idx, OpenCL::Memory_ornull value) |
2789 |
root |
1.3 |
CODE: |
2790 |
root |
1.59 |
clSetKernelArg (self, idx, sizeof (value), value ? &value : 0); |
2791 |
root |
1.3 |
|
2792 |
|
|
void |
2793 |
root |
1.22 |
set_buffer (OpenCL::Kernel self, cl_uint idx, OpenCL::Buffer_ornull value) |
2794 |
root |
1.3 |
CODE: |
2795 |
root |
1.59 |
clSetKernelArg (self, idx, sizeof (value), value ? &value : 0); |
2796 |
root |
1.3 |
|
2797 |
|
|
void |
2798 |
root |
1.54 |
set_image (OpenCL::Kernel self, cl_uint idx, OpenCL::Image_ornull value) |
2799 |
|
|
ALIAS: |
2800 |
|
|
set_image2d = 0 |
2801 |
|
|
set_image3d = 0 |
2802 |
root |
1.3 |
CODE: |
2803 |
root |
1.59 |
clSetKernelArg (self, idx, sizeof (value), value ? &value : 0); |
2804 |
root |
1.3 |
|
2805 |
|
|
void |
2806 |
root |
1.22 |
set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) |
2807 |
root |
1.3 |
CODE: |
2808 |
root |
1.22 |
clSetKernelArg (self, idx, sizeof (value), &value); |
2809 |
root |
1.3 |
|
2810 |
|
|
void |
2811 |
root |
1.33 |
set_local (OpenCL::Kernel self, cl_uint idx, size_t size) |
2812 |
|
|
CODE: |
2813 |
|
|
clSetKernelArg (self, idx, size, 0); |
2814 |
|
|
|
2815 |
|
|
void |
2816 |
root |
1.22 |
set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value) |
2817 |
root |
1.2 |
CODE: |
2818 |
root |
1.22 |
clSetKernelArg (self, idx, sizeof (value), &value); |
2819 |
root |
1.2 |
|
2820 |
root |
1.14 |
void |
2821 |
root |
1.22 |
info (OpenCL::Kernel self, cl_kernel_info name) |
2822 |
root |
1.14 |
PPCODE: |
2823 |
|
|
INFO (Kernel) |
2824 |
|
|
|
2825 |
|
|
#BEGIN:kernel |
2826 |
|
|
|
2827 |
|
|
void |
2828 |
root |
1.22 |
function_name (OpenCL::Kernel self) |
2829 |
root |
1.14 |
PPCODE: |
2830 |
|
|
size_t size; |
2831 |
root |
1.22 |
NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_FUNCTION_NAME, 0, 0, &size)); |
2832 |
root |
1.14 |
char *value = tmpbuf (size); |
2833 |
root |
1.22 |
NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_FUNCTION_NAME, size, value, 0)); |
2834 |
root |
1.16 |
EXTEND (SP, 1); |
2835 |
|
|
const int i = 0; |
2836 |
root |
1.14 |
PUSHs (sv_2mortal (newSVpv (value, 0))); |
2837 |
|
|
|
2838 |
|
|
void |
2839 |
root |
1.22 |
num_args (OpenCL::Kernel self) |
2840 |
root |
1.16 |
ALIAS: |
2841 |
|
|
num_args = CL_KERNEL_NUM_ARGS |
2842 |
|
|
reference_count = CL_KERNEL_REFERENCE_COUNT |
2843 |
root |
1.14 |
PPCODE: |
2844 |
|
|
cl_uint value [1]; |
2845 |
root |
1.22 |
NEED_SUCCESS (GetKernelInfo, (self, ix, sizeof (value), value, 0)); |
2846 |
root |
1.14 |
EXTEND (SP, 1); |
2847 |
|
|
const int i = 0; |
2848 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2849 |
|
|
|
2850 |
|
|
void |
2851 |
root |
1.22 |
context (OpenCL::Kernel self) |
2852 |
root |
1.14 |
PPCODE: |
2853 |
|
|
cl_context value [1]; |
2854 |
root |
1.22 |
NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_CONTEXT, sizeof (value), value, 0)); |
2855 |
root |
1.14 |
EXTEND (SP, 1); |
2856 |
|
|
const int i = 0; |
2857 |
|
|
{ |
2858 |
|
|
NEED_SUCCESS (RetainContext, (value [i])); |
2859 |
root |
1.61 |
PUSH_CLOBJ (stash_context, value [i]); |
2860 |
root |
1.14 |
} |
2861 |
|
|
|
2862 |
|
|
void |
2863 |
root |
1.22 |
program (OpenCL::Kernel self) |
2864 |
root |
1.14 |
PPCODE: |
2865 |
|
|
cl_program value [1]; |
2866 |
root |
1.22 |
NEED_SUCCESS (GetKernelInfo, (self, CL_KERNEL_PROGRAM, sizeof (value), value, 0)); |
2867 |
root |
1.14 |
EXTEND (SP, 1); |
2868 |
|
|
const int i = 0; |
2869 |
|
|
{ |
2870 |
|
|
NEED_SUCCESS (RetainProgram, (value [i])); |
2871 |
root |
1.61 |
PUSH_CLOBJ (stash_program, value [i]); |
2872 |
root |
1.14 |
} |
2873 |
|
|
|
2874 |
|
|
#END:kernel |
2875 |
|
|
|
2876 |
|
|
void |
2877 |
root |
1.22 |
work_group_info (OpenCL::Kernel self, OpenCL::Device device, cl_kernel_work_group_info name) |
2878 |
root |
1.14 |
PPCODE: |
2879 |
root |
1.22 |
size_t size; |
2880 |
|
|
NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, name, 0, 0, &size)); |
2881 |
root |
1.14 |
SV *sv = sv_2mortal (newSV (size)); |
2882 |
|
|
SvUPGRADE (sv, SVt_PV); |
2883 |
|
|
SvPOK_only (sv); |
2884 |
|
|
SvCUR_set (sv, size); |
2885 |
root |
1.22 |
NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, name, size, SvPVX (sv), 0)); |
2886 |
root |
1.14 |
XPUSHs (sv); |
2887 |
|
|
|
2888 |
|
|
#BEGIN:kernel_work_group |
2889 |
|
|
|
2890 |
|
|
void |
2891 |
root |
1.22 |
work_group_size (OpenCL::Kernel self, OpenCL::Device device) |
2892 |
root |
1.16 |
ALIAS: |
2893 |
|
|
work_group_size = CL_KERNEL_WORK_GROUP_SIZE |
2894 |
|
|
preferred_work_group_size_multiple = CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE |
2895 |
root |
1.14 |
PPCODE: |
2896 |
|
|
size_t value [1]; |
2897 |
root |
1.22 |
NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, ix, sizeof (value), value, 0)); |
2898 |
root |
1.14 |
EXTEND (SP, 1); |
2899 |
|
|
const int i = 0; |
2900 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2901 |
|
|
|
2902 |
|
|
void |
2903 |
root |
1.22 |
compile_work_group_size (OpenCL::Kernel self, OpenCL::Device device) |
2904 |
root |
1.14 |
PPCODE: |
2905 |
|
|
size_t size; |
2906 |
root |
1.22 |
NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, 0, 0, &size)); |
2907 |
root |
1.14 |
size_t *value = tmpbuf (size); |
2908 |
root |
1.22 |
NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, size, value, 0)); |
2909 |
root |
1.15 |
int i, n = size / sizeof (*value); |
2910 |
root |
1.14 |
EXTEND (SP, n); |
2911 |
|
|
for (i = 0; i < n; ++i) |
2912 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2913 |
|
|
|
2914 |
|
|
void |
2915 |
root |
1.22 |
local_mem_size (OpenCL::Kernel self, OpenCL::Device device) |
2916 |
root |
1.16 |
ALIAS: |
2917 |
|
|
local_mem_size = CL_KERNEL_LOCAL_MEM_SIZE |
2918 |
|
|
private_mem_size = CL_KERNEL_PRIVATE_MEM_SIZE |
2919 |
root |
1.14 |
PPCODE: |
2920 |
|
|
cl_ulong value [1]; |
2921 |
root |
1.22 |
NEED_SUCCESS (GetKernelWorkGroupInfo, (self, device, ix, sizeof (value), value, 0)); |
2922 |
root |
1.14 |
EXTEND (SP, 1); |
2923 |
|
|
const int i = 0; |
2924 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2925 |
|
|
|
2926 |
|
|
#END:kernel_work_group |
2927 |
|
|
|
2928 |
root |
1.66 |
#if CL_VERSION_1_2 |
2929 |
|
|
|
2930 |
|
|
void |
2931 |
|
|
arg_info (OpenCL::Kernel self, cl_uint idx, cl_kernel_arg_info name) |
2932 |
|
|
PPCODE: |
2933 |
|
|
size_t size; |
2934 |
root |
1.67 |
NEED_SUCCESS (GetKernelArgInfo, (self, idx, name, 0, 0, &size)); |
2935 |
root |
1.66 |
SV *sv = sv_2mortal (newSV (size)); |
2936 |
|
|
SvUPGRADE (sv, SVt_PV); |
2937 |
|
|
SvPOK_only (sv); |
2938 |
|
|
SvCUR_set (sv, size); |
2939 |
root |
1.67 |
NEED_SUCCESS (GetKernelArgInfo, (self, idx, name, size, SvPVX (sv), 0)); |
2940 |
root |
1.66 |
XPUSHs (sv); |
2941 |
|
|
|
2942 |
|
|
#BEGIN:kernel_arg |
2943 |
|
|
|
2944 |
root |
1.68 |
void |
2945 |
|
|
arg_address_qualifier (OpenCL::Kernel self, cl_uint idx) |
2946 |
|
|
PPCODE: |
2947 |
|
|
cl_kernel_arg_address_qualifier value [1]; |
2948 |
|
|
NEED_SUCCESS (GetKernelArgInfo, (self, idx, CL_KERNEL_ARG_ADDRESS_QUALIFIER, sizeof (value), value, 0)); |
2949 |
|
|
EXTEND (SP, 1); |
2950 |
|
|
const int i = 0; |
2951 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2952 |
|
|
|
2953 |
|
|
void |
2954 |
|
|
arg_access_qualifier (OpenCL::Kernel self, cl_uint idx) |
2955 |
|
|
PPCODE: |
2956 |
|
|
cl_kernel_arg_access_qualifier value [1]; |
2957 |
|
|
NEED_SUCCESS (GetKernelArgInfo, (self, idx, CL_KERNEL_ARG_ACCESS_QUALIFIER, sizeof (value), value, 0)); |
2958 |
|
|
EXTEND (SP, 1); |
2959 |
|
|
const int i = 0; |
2960 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2961 |
|
|
|
2962 |
|
|
void |
2963 |
|
|
arg_type_name (OpenCL::Kernel self, cl_uint idx) |
2964 |
|
|
ALIAS: |
2965 |
|
|
arg_type_name = CL_KERNEL_ARG_TYPE_NAME |
2966 |
|
|
arg_name = CL_KERNEL_ARG_NAME |
2967 |
|
|
PPCODE: |
2968 |
|
|
size_t size; |
2969 |
|
|
NEED_SUCCESS (GetKernelArgInfo, (self, idx, ix, 0, 0, &size)); |
2970 |
|
|
char *value = tmpbuf (size); |
2971 |
|
|
NEED_SUCCESS (GetKernelArgInfo, (self, idx, ix, size, value, 0)); |
2972 |
|
|
EXTEND (SP, 1); |
2973 |
|
|
const int i = 0; |
2974 |
|
|
PUSHs (sv_2mortal (newSVpv (value, 0))); |
2975 |
|
|
|
2976 |
|
|
void |
2977 |
|
|
arg_type_qualifier (OpenCL::Kernel self, cl_uint idx) |
2978 |
|
|
PPCODE: |
2979 |
|
|
cl_kernel_arg_type_qualifier value [1]; |
2980 |
|
|
NEED_SUCCESS (GetKernelArgInfo, (self, idx, CL_KERNEL_ARG_TYPE_QUALIFIER, sizeof (value), value, 0)); |
2981 |
|
|
EXTEND (SP, 1); |
2982 |
|
|
const int i = 0; |
2983 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
2984 |
|
|
|
2985 |
root |
1.66 |
#END:kernel_arg |
2986 |
|
|
|
2987 |
|
|
#endif |
2988 |
|
|
|
2989 |
root |
1.2 |
MODULE = OpenCL PACKAGE = OpenCL::Event |
2990 |
|
|
|
2991 |
|
|
void |
2992 |
root |
1.22 |
DESTROY (OpenCL::Event self) |
2993 |
root |
1.2 |
CODE: |
2994 |
root |
1.22 |
clReleaseEvent (self); |
2995 |
root |
1.2 |
|
2996 |
|
|
void |
2997 |
root |
1.22 |
wait (OpenCL::Event self) |
2998 |
root |
1.14 |
CODE: |
2999 |
root |
1.22 |
clWaitForEvents (1, &self); |
3000 |
root |
1.14 |
|
3001 |
|
|
void |
3002 |
root |
1.51 |
cb (OpenCL::Event self, cl_int command_exec_callback_type, SV *cb) |
3003 |
|
|
CODE: |
3004 |
|
|
clSetEventCallback (self, command_exec_callback_type, eq_event_notify, SvREFCNT_inc (s_get_cv (cb))); |
3005 |
|
|
|
3006 |
|
|
void |
3007 |
root |
1.22 |
info (OpenCL::Event self, cl_event_info name) |
3008 |
root |
1.2 |
PPCODE: |
3009 |
|
|
INFO (Event) |
3010 |
|
|
|
3011 |
root |
1.14 |
#BEGIN:event |
3012 |
|
|
|
3013 |
|
|
void |
3014 |
root |
1.22 |
command_queue (OpenCL::Event self) |
3015 |
root |
1.14 |
PPCODE: |
3016 |
|
|
cl_command_queue value [1]; |
3017 |
root |
1.22 |
NEED_SUCCESS (GetEventInfo, (self, CL_EVENT_COMMAND_QUEUE, sizeof (value), value, 0)); |
3018 |
root |
1.14 |
EXTEND (SP, 1); |
3019 |
|
|
const int i = 0; |
3020 |
|
|
{ |
3021 |
|
|
NEED_SUCCESS (RetainCommandQueue, (value [i])); |
3022 |
root |
1.61 |
PUSH_CLOBJ (stash_queue, value [i]); |
3023 |
root |
1.14 |
} |
3024 |
|
|
|
3025 |
|
|
void |
3026 |
root |
1.22 |
command_type (OpenCL::Event self) |
3027 |
root |
1.14 |
PPCODE: |
3028 |
|
|
cl_command_type value [1]; |
3029 |
root |
1.22 |
NEED_SUCCESS (GetEventInfo, (self, CL_EVENT_COMMAND_TYPE, sizeof (value), value, 0)); |
3030 |
root |
1.14 |
EXTEND (SP, 1); |
3031 |
|
|
const int i = 0; |
3032 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
3033 |
|
|
|
3034 |
|
|
void |
3035 |
root |
1.22 |
reference_count (OpenCL::Event self) |
3036 |
root |
1.16 |
ALIAS: |
3037 |
|
|
reference_count = CL_EVENT_REFERENCE_COUNT |
3038 |
|
|
command_execution_status = CL_EVENT_COMMAND_EXECUTION_STATUS |
3039 |
root |
1.14 |
PPCODE: |
3040 |
|
|
cl_uint value [1]; |
3041 |
root |
1.22 |
NEED_SUCCESS (GetEventInfo, (self, ix, sizeof (value), value, 0)); |
3042 |
root |
1.14 |
EXTEND (SP, 1); |
3043 |
|
|
const int i = 0; |
3044 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
3045 |
|
|
|
3046 |
|
|
void |
3047 |
root |
1.22 |
context (OpenCL::Event self) |
3048 |
root |
1.14 |
PPCODE: |
3049 |
|
|
cl_context value [1]; |
3050 |
root |
1.22 |
NEED_SUCCESS (GetEventInfo, (self, CL_EVENT_CONTEXT, sizeof (value), value, 0)); |
3051 |
root |
1.14 |
EXTEND (SP, 1); |
3052 |
|
|
const int i = 0; |
3053 |
|
|
{ |
3054 |
|
|
NEED_SUCCESS (RetainContext, (value [i])); |
3055 |
root |
1.61 |
PUSH_CLOBJ (stash_context, value [i]); |
3056 |
root |
1.14 |
} |
3057 |
|
|
|
3058 |
|
|
#END:event |
3059 |
|
|
|
3060 |
root |
1.2 |
void |
3061 |
root |
1.22 |
profiling_info (OpenCL::Event self, cl_profiling_info name) |
3062 |
root |
1.13 |
PPCODE: |
3063 |
|
|
INFO (EventProfiling) |
3064 |
|
|
|
3065 |
root |
1.14 |
#BEGIN:profiling |
3066 |
|
|
|
3067 |
root |
1.13 |
void |
3068 |
root |
1.22 |
profiling_command_queued (OpenCL::Event self) |
3069 |
root |
1.16 |
ALIAS: |
3070 |
|
|
profiling_command_queued = CL_PROFILING_COMMAND_QUEUED |
3071 |
|
|
profiling_command_submit = CL_PROFILING_COMMAND_SUBMIT |
3072 |
|
|
profiling_command_start = CL_PROFILING_COMMAND_START |
3073 |
|
|
profiling_command_end = CL_PROFILING_COMMAND_END |
3074 |
root |
1.14 |
PPCODE: |
3075 |
|
|
cl_ulong value [1]; |
3076 |
root |
1.22 |
NEED_SUCCESS (GetEventProfilingInfo, (self, ix, sizeof (value), value, 0)); |
3077 |
root |
1.14 |
EXTEND (SP, 1); |
3078 |
|
|
const int i = 0; |
3079 |
|
|
PUSHs (sv_2mortal (newSVuv (value [i]))); |
3080 |
|
|
|
3081 |
|
|
#END:profiling |
3082 |
root |
1.2 |
|
3083 |
root |
1.5 |
MODULE = OpenCL PACKAGE = OpenCL::UserEvent |
3084 |
|
|
|
3085 |
|
|
void |
3086 |
root |
1.22 |
set_status (OpenCL::UserEvent self, cl_int execution_status) |
3087 |
root |
1.5 |
CODE: |
3088 |
root |
1.22 |
clSetUserEventStatus (self, execution_status); |
3089 |
root |
1.5 |
|
3090 |
root |
1.61 |
MODULE = OpenCL PACKAGE = OpenCL::Mapped |
3091 |
|
|
|
3092 |
|
|
void |
3093 |
|
|
DESTROY (SV *self) |
3094 |
|
|
CODE: |
3095 |
|
|
OpenCL__Mapped mapped = SvMAPPED (self); |
3096 |
|
|
|
3097 |
|
|
clEnqueueUnmapMemObject (mapped->queue, mapped->memobj, mapped->ptr, 1, &mapped->event, 0); |
3098 |
|
|
mapped_detach (self, mapped); |
3099 |
|
|
|
3100 |
|
|
clReleaseCommandQueue (mapped->queue); |
3101 |
root |
1.62 |
clReleaseEvent (mapped->event); |
3102 |
root |
1.61 |
Safefree (mapped); |
3103 |
|
|
|
3104 |
root |
1.62 |
void |
3105 |
|
|
unmap (OpenCL::Mapped self, ...) |
3106 |
|
|
CODE: |
3107 |
root |
1.71 |
mapped_unmap (cv, ST (0), self, self->queue, &ST (1), items - 1); |
3108 |
root |
1.62 |
|
3109 |
root |
1.61 |
bool |
3110 |
|
|
mapped (OpenCL::Mapped self) |
3111 |
|
|
CODE: |
3112 |
|
|
RETVAL = !!self->ptr; |
3113 |
|
|
OUTPUT: |
3114 |
|
|
RETVAL |
3115 |
|
|
|
3116 |
|
|
void |
3117 |
|
|
wait (OpenCL::Mapped self) |
3118 |
|
|
PPCODE: |
3119 |
|
|
if (self->event) |
3120 |
|
|
NEED_SUCCESS (WaitForEvents, (1, &self->event)); |
3121 |
|
|
|
3122 |
|
|
void |
3123 |
|
|
event (OpenCL::Mapped self) |
3124 |
|
|
PPCODE: |
3125 |
|
|
if (!self->event) |
3126 |
|
|
XSRETURN_UNDEF; |
3127 |
|
|
|
3128 |
|
|
clRetainEvent (self->event); |
3129 |
|
|
XPUSH_CLOBJ (stash_event, self->event); |
3130 |
|
|
|
3131 |
|
|
size_t |
3132 |
|
|
size (OpenCL::Mapped self) |
3133 |
|
|
CODE: |
3134 |
|
|
RETVAL = self->cb; |
3135 |
|
|
OUTPUT: |
3136 |
|
|
RETVAL |
3137 |
|
|
|
3138 |
|
|
IV |
3139 |
|
|
ptr (OpenCL::Mapped self) |
3140 |
|
|
CODE: |
3141 |
|
|
RETVAL = PTR2IV (self->ptr); |
3142 |
|
|
OUTPUT: |
3143 |
|
|
RETVAL |
3144 |
|
|
|
3145 |
root |
1.63 |
void |
3146 |
|
|
set (OpenCL::Mapped self, size_t offset, SV *data) |
3147 |
|
|
CODE: |
3148 |
|
|
STRLEN len; |
3149 |
|
|
const char *ptr = SvPVbyte (data, len); |
3150 |
|
|
|
3151 |
root |
1.64 |
if (offset + len > self->cb) |
3152 |
root |
1.63 |
croak ("OpenCL::Mapped::set out of bound condition detected"); |
3153 |
|
|
|
3154 |
|
|
memcpy (offset + (char *)self->ptr, ptr, len); |
3155 |
|
|
|
3156 |
root |
1.61 |
MODULE = OpenCL PACKAGE = OpenCL::MappedBuffer |
3157 |
|
|
|
3158 |
|
|
MODULE = OpenCL PACKAGE = OpenCL::MappedImage |
3159 |
|
|
|
3160 |
|
|
IV |
3161 |
|
|
row_pitch (OpenCL::Mapped self) |
3162 |
|
|
ALIAS: |
3163 |
|
|
slice_pitch = 1 |
3164 |
|
|
CODE: |
3165 |
|
|
RETVAL = ix ? self->slice_pitch : self->row_pitch; |
3166 |
|
|
OUTPUT: |
3167 |
|
|
RETVAL |
3168 |
|
|
|
3169 |
|
|
|
3170 |
|
|
|