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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.3 by root, Tue Nov 15 20:38:07 2011 UTC vs.
Revision 1.14 by root, Sun Nov 20 10:21:27 2011 UTC

20typedef cl_mem OpenCL__Image3D_ornull; 20typedef cl_mem OpenCL__Image3D_ornull;
21typedef cl_sampler OpenCL__Sampler; 21typedef cl_sampler OpenCL__Sampler;
22typedef cl_program OpenCL__Program; 22typedef cl_program OpenCL__Program;
23typedef cl_kernel OpenCL__Kernel; 23typedef cl_kernel OpenCL__Kernel;
24typedef cl_event OpenCL__Event; 24typedef cl_event OpenCL__Event;
25typedef cl_event OpenCL__UserEvent;
26
27typedef SV *FUTURE;
28
29/*****************************************************************************/
30
31/* up to two temporary buffers */
32static void *
33tmpbuf (size_t size)
34{
35 static int idx;
36 static void *buf [2];
37 static size_t len [2];
38
39 idx ^= 1;
40
41 if (len [idx] < size)
42 {
43 free (buf [idx]);
44 len [idx] = ((size + 31) & ~4095) + 4096 - 32;
45 buf [idx] = malloc (len [idx]);
46 }
47
48 return buf [idx];
49}
50
51/*****************************************************************************/
25 52
26typedef struct 53typedef struct
27{ 54{
28 IV iv; 55 IV iv;
29 const char *name; 56 const char *name;
63 }; 90 };
64 91
65 return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)"); 92 return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)");
66} 93}
67 94
95/*****************************************************************************/
96
97static cl_int res;
98
68#define FAIL(name,res) \ 99#define FAIL(name) \
69 croak ("cl" # name ": %s", err2str (res)); 100 croak ("cl" # name ": %s", err2str (res));
70 101
71#define NEED_SUCCESS(name,args) \ 102#define NEED_SUCCESS(name,args) \
72 do { \ 103 do { \
73 cl_int res = cl ## name args; \ 104 res = cl ## name args; \
74 \ 105 \
75 if (res) \ 106 if (res) \
76 FAIL (name, res); \ 107 FAIL (name); \
77 } while (0) 108 } while (0)
109
110#define NEED_SUCCESS_ARG(retdecl, name, args) \
111 retdecl = cl ## name args; \
112 if (res) \
113 FAIL (name);
114
115/*****************************************************************************/
78 116
79#define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr) 117#define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr)
80#define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr)) 118#define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr))
81 119
82/*TODO*/ 120static void *
83#define EVENT_LIST(items,count) cl_uint event_list_count = 0; cl_event *event_list_ptr = 0 121SvPTROBJ (const char *func, const char *svname, SV *sv, const char *pkg)
122{
123 if (SvROK (sv) && sv_derived_from (sv, pkg))
124 return (void *)SvIV (SvRV (sv));
125
126 croak ("%s: %s is not of type %s", func, svname, pkg);
127}
128
129/*****************************************************************************/
130
131static size_t
132img_row_pitch (cl_mem img)
133{
134 size_t res;
135 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0);
136 return res;
137}
138
139static cl_event *
140event_list (SV **items, int count)
141{
142 cl_event *list = tmpbuf (sizeof (cl_event) * count);
143
144 while (count--)
145 list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event");
146
147 return list;
148}
149
150#define EVENT_LIST(items,count) \
151 cl_uint event_list_count = (count); \
152 cl_event *event_list_ptr = event_list (&ST (items), event_list_count)
84 153
85#define INFO(class) \ 154#define INFO(class) \
86{ \ 155{ \
87 size_t size; \ 156 size_t size; \
88 SV *sv; \
89 \
90 NEED_SUCCESS (Get ## class ## Info, (this, name, 0, 0, &size)); \ 157 NEED_SUCCESS (Get ## class ## Info, (this, name, 0, 0, &size)); \
91 sv = sv_2mortal (newSV (size)); \ 158 SV *sv = sv_2mortal (newSV (size)); \
92 SvUPGRADE (sv, SVt_PV); \ 159 SvUPGRADE (sv, SVt_PV); \
93 SvPOK_only (sv); \ 160 SvPOK_only (sv); \
94 SvCUR_set (sv, size); \ 161 SvCUR_set (sv, size); \
95 NEED_SUCCESS (Get ## class ## Info, (this, name, size, SvPVX (sv), 0)); \ 162 NEED_SUCCESS (Get ## class ## Info, (this, name, size, SvPVX (sv), 0)); \
96 XPUSHs (sv); \ 163 XPUSHs (sv); \
97} 164}
98 165
99static void *
100SvPTROBJ (const char *func, const char *svname, SV *sv, const char *pkg)
101{
102 if (SvROK (sv) && sv_derived_from (sv, pkg))
103 return (void *)SvIV (SvRV (sv));
104
105 croak ("%s: %s is not of type %s", func, svname, pkg);
106}
107
108MODULE = OpenCL PACKAGE = OpenCL 166MODULE = OpenCL PACKAGE = OpenCL
109 167
110PROTOTYPES: ENABLE 168PROTOTYPES: ENABLE
111 169
112BOOT: 170BOOT:
113{ 171{
114 HV *stash = gv_stashpv ("OpenCL", 1); 172 HV *stash = gv_stashpv ("OpenCL", 1);
115 static const ivstr *civ, const_iv[] = { 173 static const ivstr *civ, const_iv[] = {
116 { sizeof (cl_char ), "SIZEOF_CHAR" }, 174 { sizeof (cl_char ), "SIZEOF_CHAR" },
117 { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, 175 { sizeof (cl_uchar ), "SIZEOF_UCHAR" },
118 { sizeof (cl_short ), "SIZEOF_SHORT" }, 176 { sizeof (cl_short ), "SIZEOF_SHORT" },
119 { sizeof (cl_ushort), "SIZEOF_USHORT"}, 177 { sizeof (cl_ushort), "SIZEOF_USHORT" },
120 { sizeof (cl_int ), "SIZEOF_INT" }, 178 { sizeof (cl_int ), "SIZEOF_INT" },
121 { sizeof (cl_uint ), "SIZEOF_UINT" }, 179 { sizeof (cl_uint ), "SIZEOF_UINT" },
122 { sizeof (cl_long ), "SIZEOF_LONG" }, 180 { sizeof (cl_long ), "SIZEOF_LONG" },
123 { sizeof (cl_ulong ), "SIZEOF_ULONG" }, 181 { sizeof (cl_ulong ), "SIZEOF_ULONG" },
124 { sizeof (cl_half ), "SIZEOF_HALF" }, 182 { sizeof (cl_half ), "SIZEOF_HALF" },
125 { sizeof (cl_float ), "SIZEOF_FLOAT" }, 183 { sizeof (cl_float ), "SIZEOF_FLOAT" },
184 { sizeof (cl_double), "SIZEOF_DOUBLE" },
126#include "constiv.h" 185#include "constiv.h"
127 }; 186 };
128 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 187 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
129 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 188 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
130} 189}
131 190
191cl_int
192errno ()
193 CODE:
194 errno = res;
195
132const char * 196const char *
133err2str (cl_int err) 197err2str (cl_int err)
134 198
135const char * 199const char *
136enum2str (cl_uint value) 200enum2str (cl_uint value)
137 201
138void 202void
139platforms () 203platforms ()
140 PPCODE: 204 PPCODE:
141{
142 cl_platform_id *list; 205 cl_platform_id *list;
143 cl_uint count; 206 cl_uint count;
144 int i; 207 int i;
145 208
146 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count)); 209 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count));
147 Newx (list, count, cl_platform_id); 210 list = tmpbuf (sizeof (*list) * count);
148 NEED_SUCCESS (GetPlatformIDs, (count, list, 0)); 211 NEED_SUCCESS (GetPlatformIDs, (count, list, 0));
149 212
150 EXTEND (SP, count); 213 EXTEND (SP, count);
151 for (i = 0; i < count; ++i) 214 for (i = 0; i < count; ++i)
152 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); 215 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i]));
153 216
154 Safefree (list);
155}
156
157void 217void
158context_from_type_simple (cl_device_type type = CL_DEVICE_TYPE_DEFAULT) 218context_from_type (FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
159 PPCODE: 219 PPCODE:
160{
161 cl_int res;
162 cl_context ctx = clCreateContextFromType (0, type, 0, 0, &res); 220 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (0, type, 0, 0, &res));
163
164 if (res)
165 FAIL (CreateContextFromType, res);
166
167 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 221 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
168} 222
223void
224context (FUTURE properties, FUTURE devices, FUTURE notify = 0)
225 PPCODE:
226 /* der Gipfel der Kunst */
169 227
170void 228void
171wait_for_events (...) 229wait_for_events (...)
172 CODE: 230 CODE:
173{
174 EVENT_LIST (0, items); 231 EVENT_LIST (0, items);
175 NEED_SUCCESS (WaitForEvents, (event_list_count, event_list_ptr)); 232 NEED_SUCCESS (WaitForEvents, (event_list_count, event_list_ptr));
176}
177 233
178PROTOTYPES: DISABLE 234PROTOTYPES: DISABLE
179 235
180MODULE = OpenCL PACKAGE = OpenCL::Platform 236MODULE = OpenCL PACKAGE = OpenCL::Platform
181 237
182void 238void
183info (OpenCL::Platform this, cl_platform_info name) 239info (OpenCL::Platform this, cl_platform_info name)
184 PPCODE: 240 PPCODE:
185 INFO (Platform) 241 INFO (Platform)
186 242
243#BEGIN:platform
244
245void
246profile (OpenCL::Platform this)
247 PPCODE:
248 size_t size;
249 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_PROFILE, 0, 0, &size));
250 char *value = tmpbuf (size);
251 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_PROFILE, size, value, 0));
252 int i, n = 1;
253 EXTEND (SP, n);
254 for (i = 0; i < n; ++i)
255 PUSHs (sv_2mortal (newSVpv (value, 0)));
256
257void
258version (OpenCL::Platform this)
259 PPCODE:
260 size_t size;
261 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_VERSION, 0, 0, &size));
262 char *value = tmpbuf (size);
263 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_VERSION, size, value, 0));
264 int i, n = 1;
265 EXTEND (SP, n);
266 for (i = 0; i < n; ++i)
267 PUSHs (sv_2mortal (newSVpv (value, 0)));
268
269void
270name (OpenCL::Platform this)
271 PPCODE:
272 size_t size;
273 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_NAME, 0, 0, &size));
274 char *value = tmpbuf (size);
275 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_NAME, size, value, 0));
276 int i, n = 1;
277 EXTEND (SP, n);
278 for (i = 0; i < n; ++i)
279 PUSHs (sv_2mortal (newSVpv (value, 0)));
280
281void
282vendor (OpenCL::Platform this)
283 PPCODE:
284 size_t size;
285 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_VENDOR, 0, 0, &size));
286 char *value = tmpbuf (size);
287 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_VENDOR, size, value, 0));
288 int i, n = 1;
289 EXTEND (SP, n);
290 for (i = 0; i < n; ++i)
291 PUSHs (sv_2mortal (newSVpv (value, 0)));
292
293void
294extensions (OpenCL::Platform this)
295 PPCODE:
296 size_t size;
297 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_EXTENSIONS, 0, 0, &size));
298 char *value = tmpbuf (size);
299 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_EXTENSIONS, size, value, 0));
300 int i, n = 1;
301 EXTEND (SP, n);
302 for (i = 0; i < n; ++i)
303 PUSHs (sv_2mortal (newSVpv (value, 0)));
304
305#END:platform
306
187void 307void
188devices (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_ALL) 308devices (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_ALL)
189 PPCODE: 309 PPCODE:
190{
191 cl_device_id *list; 310 cl_device_id *list;
192 cl_uint count; 311 cl_uint count;
193 int i; 312 int i;
194 313
195 NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count)); 314 NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count));
196 Newx (list, count, cl_device_id); 315 list = tmpbuf (sizeof (*list) * count);
197 NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0)); 316 NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0));
198 317
199 EXTEND (SP, count); 318 EXTEND (SP, count);
200 for (i = 0; i < count; ++i) 319 for (i = 0; i < count; ++i)
201 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); 320 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i]));
202 321
203 Safefree (list);
204}
205
206void 322void
323context (OpenCL::Platform this, FUTURE properties, SV *devices, FUTURE notify = 0)
324 PPCODE:
325 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV)
326 croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call");
327
328 AV *av = (AV *)SvRV (devices);
329 cl_uint num_devices = av_len (av) + 1;
330 cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices);
331 int i;
332
333 for (i = num_devices; i--; )
334 device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device");
335
336 NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (0, num_devices, device_list, 0, 0, &res));
337 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
338
339void
207context_from_type_simple (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_DEFAULT) 340context_from_type (OpenCL::Platform this, FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
208 PPCODE: 341 PPCODE:
209{
210 cl_int res;
211 cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)this, 0 }; 342 cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)this, 0 };
212 cl_context ctx = clCreateContextFromType (props, type, 0, 0, &res); 343 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res));
213
214 if (res)
215 FAIL (CreateContextFromType, res);
216
217 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 344 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
218}
219 345
220MODULE = OpenCL PACKAGE = OpenCL::Device 346MODULE = OpenCL PACKAGE = OpenCL::Device
221 347
222void 348void
223info (OpenCL::Device this, cl_device_info name) 349info (OpenCL::Device this, cl_device_info name)
224 PPCODE: 350 PPCODE:
225 INFO (Device) 351 INFO (Device)
226 352
353#BEGIN:device
354
227void 355void
228context_simple (OpenCL::Device this) 356type (OpenCL::Device this)
229 PPCODE: 357 PPCODE:
230{ 358 cl_device_type value [1];
231 cl_int res; 359 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_TYPE, sizeof (value), value, 0));
232 cl_context ctx = clCreateContext (0, 1, &this, 0, 0, &res); 360 EXTEND (SP, 1);
361 const int i = 0;
362 PUSHs (sv_2mortal (newSViv (value [i])));
233 363
234 if (res) 364void
235 FAIL (CreateContext, res); 365vendor_id (OpenCL::Device this)
366 PPCODE:
367 cl_uint value [1];
368 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_VENDOR_ID, sizeof (value), value, 0));
369 EXTEND (SP, 1);
370 const int i = 0;
371 PUSHs (sv_2mortal (newSVuv (value [i])));
236 372
237 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 373void
238} 374max_compute_units (OpenCL::Device this)
375 PPCODE:
376 cl_uint value [1];
377 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof (value), value, 0));
378 EXTEND (SP, 1);
379 const int i = 0;
380 PUSHs (sv_2mortal (newSVuv (value [i])));
381
382void
383max_work_item_dimensions (OpenCL::Device this)
384 PPCODE:
385 cl_uint value [1];
386 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof (value), value, 0));
387 EXTEND (SP, 1);
388 const int i = 0;
389 PUSHs (sv_2mortal (newSVuv (value [i])));
390
391void
392max_work_group_size (OpenCL::Device this)
393 PPCODE:
394 size_t value [1];
395 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof (value), value, 0));
396 EXTEND (SP, 1);
397 const int i = 0;
398 PUSHs (sv_2mortal (newSVuv (value [i])));
399
400void
401max_work_item_sizes (OpenCL::Device this)
402 PPCODE:
403 size_t size;
404 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_WORK_ITEM_SIZES, 0, 0, &size));
405 size_t *value = tmpbuf (size);
406 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_WORK_ITEM_SIZES, size, value, 0));
407 int i, n = size / sizeof (value [0]);
408 EXTEND (SP, n);
409 for (i = 0; i < n; ++i)
410 PUSHs (sv_2mortal (newSVuv (value [i])));
411
412void
413preferred_vector_width_char (OpenCL::Device this)
414 PPCODE:
415 cl_uint value [1];
416 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, sizeof (value), value, 0));
417 EXTEND (SP, 1);
418 const int i = 0;
419 PUSHs (sv_2mortal (newSVuv (value [i])));
420
421void
422preferred_vector_width_short (OpenCL::Device this)
423 PPCODE:
424 cl_uint value [1];
425 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, sizeof (value), value, 0));
426 EXTEND (SP, 1);
427 const int i = 0;
428 PUSHs (sv_2mortal (newSVuv (value [i])));
429
430void
431preferred_vector_width_int (OpenCL::Device this)
432 PPCODE:
433 cl_uint value [1];
434 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, sizeof (value), value, 0));
435 EXTEND (SP, 1);
436 const int i = 0;
437 PUSHs (sv_2mortal (newSVuv (value [i])));
438
439void
440preferred_vector_width_long (OpenCL::Device this)
441 PPCODE:
442 cl_uint value [1];
443 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, sizeof (value), value, 0));
444 EXTEND (SP, 1);
445 const int i = 0;
446 PUSHs (sv_2mortal (newSVuv (value [i])));
447
448void
449preferred_vector_width_float (OpenCL::Device this)
450 PPCODE:
451 cl_uint value [1];
452 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, sizeof (value), value, 0));
453 EXTEND (SP, 1);
454 const int i = 0;
455 PUSHs (sv_2mortal (newSVuv (value [i])));
456
457void
458preferred_vector_width_double (OpenCL::Device this)
459 PPCODE:
460 cl_uint value [1];
461 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, sizeof (value), value, 0));
462 EXTEND (SP, 1);
463 const int i = 0;
464 PUSHs (sv_2mortal (newSVuv (value [i])));
465
466void
467max_clock_frequency (OpenCL::Device this)
468 PPCODE:
469 cl_uint value [1];
470 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof (value), value, 0));
471 EXTEND (SP, 1);
472 const int i = 0;
473 PUSHs (sv_2mortal (newSVuv (value [i])));
474
475void
476address_bits (OpenCL::Device this)
477 PPCODE:
478 cl_bitfield value [1];
479 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_ADDRESS_BITS, sizeof (value), value, 0));
480 EXTEND (SP, 1);
481 const int i = 0;
482 PUSHs (sv_2mortal (newSVuv (value [i])));
483
484void
485max_read_image_args (OpenCL::Device this)
486 PPCODE:
487 cl_uint value [1];
488 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_READ_IMAGE_ARGS, sizeof (value), value, 0));
489 EXTEND (SP, 1);
490 const int i = 0;
491 PUSHs (sv_2mortal (newSVuv (value [i])));
492
493void
494max_write_image_args (OpenCL::Device this)
495 PPCODE:
496 cl_uint value [1];
497 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, sizeof (value), value, 0));
498 EXTEND (SP, 1);
499 const int i = 0;
500 PUSHs (sv_2mortal (newSVuv (value [i])));
501
502void
503max_mem_alloc_size (OpenCL::Device this)
504 PPCODE:
505 cl_ulong value [1];
506 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof (value), value, 0));
507 EXTEND (SP, 1);
508 const int i = 0;
509 PUSHs (sv_2mortal (newSVuv (value [i])));
510
511void
512image2d_max_width (OpenCL::Device this)
513 PPCODE:
514 size_t value [1];
515 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof (value), value, 0));
516 EXTEND (SP, 1);
517 const int i = 0;
518 PUSHs (sv_2mortal (newSVuv (value [i])));
519
520void
521image2d_max_height (OpenCL::Device this)
522 PPCODE:
523 size_t value [1];
524 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_IMAGE2D_MAX_HEIGHT, sizeof (value), value, 0));
525 EXTEND (SP, 1);
526 const int i = 0;
527 PUSHs (sv_2mortal (newSVuv (value [i])));
528
529void
530image3d_max_width (OpenCL::Device this)
531 PPCODE:
532 size_t value [1];
533 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_IMAGE3D_MAX_WIDTH, sizeof (value), value, 0));
534 EXTEND (SP, 1);
535 const int i = 0;
536 PUSHs (sv_2mortal (newSVuv (value [i])));
537
538void
539image3d_max_height (OpenCL::Device this)
540 PPCODE:
541 size_t value [1];
542 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_IMAGE3D_MAX_HEIGHT, sizeof (value), value, 0));
543 EXTEND (SP, 1);
544 const int i = 0;
545 PUSHs (sv_2mortal (newSVuv (value [i])));
546
547void
548image3d_max_depth (OpenCL::Device this)
549 PPCODE:
550 size_t value [1];
551 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof (value), value, 0));
552 EXTEND (SP, 1);
553 const int i = 0;
554 PUSHs (sv_2mortal (newSVuv (value [i])));
555
556void
557image_support (OpenCL::Device this)
558 PPCODE:
559 cl_uint value [1];
560 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_IMAGE_SUPPORT, sizeof (value), value, 0));
561 EXTEND (SP, 1);
562 const int i = 0;
563 PUSHs (sv_2mortal (newSVuv (value [i])));
564
565void
566max_parameter_size (OpenCL::Device this)
567 PPCODE:
568 size_t value [1];
569 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_PARAMETER_SIZE, sizeof (value), value, 0));
570 EXTEND (SP, 1);
571 const int i = 0;
572 PUSHs (sv_2mortal (newSVuv (value [i])));
573
574void
575max_samplers (OpenCL::Device this)
576 PPCODE:
577 cl_uint value [1];
578 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_SAMPLERS, sizeof (value), value, 0));
579 EXTEND (SP, 1);
580 const int i = 0;
581 PUSHs (sv_2mortal (newSVuv (value [i])));
582
583void
584mem_base_addr_align (OpenCL::Device this)
585 PPCODE:
586 cl_uint value [1];
587 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MEM_BASE_ADDR_ALIGN, sizeof (value), value, 0));
588 EXTEND (SP, 1);
589 const int i = 0;
590 PUSHs (sv_2mortal (newSVuv (value [i])));
591
592void
593min_data_type_align_size (OpenCL::Device this)
594 PPCODE:
595 cl_uint value [1];
596 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, sizeof (value), value, 0));
597 EXTEND (SP, 1);
598 const int i = 0;
599 PUSHs (sv_2mortal (newSVuv (value [i])));
600
601void
602single_fp_config (OpenCL::Device this)
603 PPCODE:
604 cl_device_fp_config value [1];
605 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_SINGLE_FP_CONFIG, sizeof (value), value, 0));
606 EXTEND (SP, 1);
607 const int i = 0;
608 PUSHs (sv_2mortal (newSVuv (value [i])));
609
610void
611global_mem_cache_type (OpenCL::Device this)
612 PPCODE:
613 cl_device_mem_cache_type value [1];
614 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, sizeof (value), value, 0));
615 EXTEND (SP, 1);
616 const int i = 0;
617 PUSHs (sv_2mortal (newSVuv (value [i])));
618
619void
620global_mem_cacheline_size (OpenCL::Device this)
621 PPCODE:
622 cl_uint value [1];
623 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, sizeof (value), value, 0));
624 EXTEND (SP, 1);
625 const int i = 0;
626 PUSHs (sv_2mortal (newSVuv (value [i])));
627
628void
629global_mem_cache_size (OpenCL::Device this)
630 PPCODE:
631 cl_ulong value [1];
632 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, sizeof (value), value, 0));
633 EXTEND (SP, 1);
634 const int i = 0;
635 PUSHs (sv_2mortal (newSVuv (value [i])));
636
637void
638global_mem_size (OpenCL::Device this)
639 PPCODE:
640 cl_ulong value [1];
641 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof (value), value, 0));
642 EXTEND (SP, 1);
643 const int i = 0;
644 PUSHs (sv_2mortal (newSVuv (value [i])));
645
646void
647max_constant_buffer_size (OpenCL::Device this)
648 PPCODE:
649 cl_ulong value [1];
650 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, sizeof (value), value, 0));
651 EXTEND (SP, 1);
652 const int i = 0;
653 PUSHs (sv_2mortal (newSVuv (value [i])));
654
655void
656max_constant_args (OpenCL::Device this)
657 PPCODE:
658 cl_uint value [1];
659 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_CONSTANT_ARGS, sizeof (value), value, 0));
660 EXTEND (SP, 1);
661 const int i = 0;
662 PUSHs (sv_2mortal (newSVuv (value [i])));
663
664void
665local_mem_type (OpenCL::Device this)
666 PPCODE:
667 cl_device_local_mem_type value [1];
668 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_LOCAL_MEM_TYPE, sizeof (value), value, 0));
669 EXTEND (SP, 1);
670 const int i = 0;
671 PUSHs (sv_2mortal (newSVuv (value [i])));
672
673void
674local_mem_size (OpenCL::Device this)
675 PPCODE:
676 cl_ulong value [1];
677 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_LOCAL_MEM_SIZE, sizeof (value), value, 0));
678 EXTEND (SP, 1);
679 const int i = 0;
680 PUSHs (sv_2mortal (newSVuv (value [i])));
681
682void
683error_correction_support (OpenCL::Device this)
684 PPCODE:
685 cl_bool value [1];
686 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_ERROR_CORRECTION_SUPPORT, sizeof (value), value, 0));
687 EXTEND (SP, 1);
688 const int i = 0;
689 PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no));
690
691void
692profiling_timer_resolution (OpenCL::Device this)
693 PPCODE:
694 size_t value [1];
695 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PROFILING_TIMER_RESOLUTION, sizeof (value), value, 0));
696 EXTEND (SP, 1);
697 const int i = 0;
698 PUSHs (sv_2mortal (newSVuv (value [i])));
699
700void
701endian_little (OpenCL::Device this)
702 PPCODE:
703 cl_bool value [1];
704 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_ENDIAN_LITTLE, sizeof (value), value, 0));
705 EXTEND (SP, 1);
706 const int i = 0;
707 PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no));
708
709void
710available (OpenCL::Device this)
711 PPCODE:
712 cl_bool value [1];
713 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_AVAILABLE, sizeof (value), value, 0));
714 EXTEND (SP, 1);
715 const int i = 0;
716 PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no));
717
718void
719compiler_available (OpenCL::Device this)
720 PPCODE:
721 cl_bool value [1];
722 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_COMPILER_AVAILABLE, sizeof (value), value, 0));
723 EXTEND (SP, 1);
724 const int i = 0;
725 PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no));
726
727void
728execution_capabilities (OpenCL::Device this)
729 PPCODE:
730 cl_device_exec_capabilities value [1];
731 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_EXECUTION_CAPABILITIES, sizeof (value), value, 0));
732 EXTEND (SP, 1);
733 const int i = 0;
734 PUSHs (sv_2mortal (newSVuv (value [i])));
735
736void
737properties (OpenCL::Device this)
738 PPCODE:
739 cl_command_queue_properties value [1];
740 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_QUEUE_PROPERTIES, sizeof (value), value, 0));
741 EXTEND (SP, 1);
742 const int i = 0;
743 PUSHs (sv_2mortal (newSViv (value [i])));
744
745void
746platform (OpenCL::Device this)
747 PPCODE:
748 cl_platform_id value [1];
749 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PLATFORM, sizeof (value), value, 0));
750 EXTEND (SP, 1);
751 const int i = 0;
752 {
753 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", value [i]));
754 }
755
756void
757name (OpenCL::Device this)
758 PPCODE:
759 size_t size;
760 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_NAME, 0, 0, &size));
761 char *value = tmpbuf (size);
762 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_NAME, size, value, 0));
763 int i, n = 1;
764 EXTEND (SP, n);
765 for (i = 0; i < n; ++i)
766 PUSHs (sv_2mortal (newSVpv (value, 0)));
767
768void
769vendor (OpenCL::Device this)
770 PPCODE:
771 size_t size;
772 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_VENDOR, 0, 0, &size));
773 char *value = tmpbuf (size);
774 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_VENDOR, size, value, 0));
775 int i, n = 1;
776 EXTEND (SP, n);
777 for (i = 0; i < n; ++i)
778 PUSHs (sv_2mortal (newSVpv (value, 0)));
779
780void
781driver_version (OpenCL::Device this)
782 PPCODE:
783 size_t size;
784 NEED_SUCCESS (GetDeviceInfo, (this, CL_DRIVER_VERSION, 0, 0, &size));
785 char *value = tmpbuf (size);
786 NEED_SUCCESS (GetDeviceInfo, (this, CL_DRIVER_VERSION, size, value, 0));
787 int i, n = 1;
788 EXTEND (SP, n);
789 for (i = 0; i < n; ++i)
790 PUSHs (sv_2mortal (newSVpv (value, 0)));
791
792void
793profile (OpenCL::Device this)
794 PPCODE:
795 size_t size;
796 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PROFILE, 0, 0, &size));
797 char *value = tmpbuf (size);
798 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PROFILE, size, value, 0));
799 int i, n = 1;
800 EXTEND (SP, n);
801 for (i = 0; i < n; ++i)
802 PUSHs (sv_2mortal (newSVpv (value, 0)));
803
804void
805version (OpenCL::Device this)
806 PPCODE:
807 size_t size;
808 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_VERSION, 0, 0, &size));
809 char *value = tmpbuf (size);
810 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_VERSION, size, value, 0));
811 int i, n = 1;
812 EXTEND (SP, n);
813 for (i = 0; i < n; ++i)
814 PUSHs (sv_2mortal (newSVpv (value, 0)));
815
816void
817extensions (OpenCL::Device this)
818 PPCODE:
819 size_t size;
820 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_EXTENSIONS, 0, 0, &size));
821 char *value = tmpbuf (size);
822 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_EXTENSIONS, size, value, 0));
823 int i, n = 1;
824 EXTEND (SP, n);
825 for (i = 0; i < n; ++i)
826 PUSHs (sv_2mortal (newSVpv (value, 0)));
827
828void
829preferred_vector_width_half (OpenCL::Device this)
830 PPCODE:
831 cl_uint value [1];
832 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, sizeof (value), value, 0));
833 EXTEND (SP, 1);
834 const int i = 0;
835 PUSHs (sv_2mortal (newSVuv (value [i])));
836
837void
838native_vector_width_char (OpenCL::Device this)
839 PPCODE:
840 cl_uint value [1];
841 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, sizeof (value), value, 0));
842 EXTEND (SP, 1);
843 const int i = 0;
844 PUSHs (sv_2mortal (newSVuv (value [i])));
845
846void
847native_vector_width_short (OpenCL::Device this)
848 PPCODE:
849 cl_uint value [1];
850 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, sizeof (value), value, 0));
851 EXTEND (SP, 1);
852 const int i = 0;
853 PUSHs (sv_2mortal (newSVuv (value [i])));
854
855void
856native_vector_width_int (OpenCL::Device this)
857 PPCODE:
858 cl_uint value [1];
859 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, sizeof (value), value, 0));
860 EXTEND (SP, 1);
861 const int i = 0;
862 PUSHs (sv_2mortal (newSVuv (value [i])));
863
864void
865native_vector_width_long (OpenCL::Device this)
866 PPCODE:
867 cl_uint value [1];
868 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, sizeof (value), value, 0));
869 EXTEND (SP, 1);
870 const int i = 0;
871 PUSHs (sv_2mortal (newSVuv (value [i])));
872
873void
874native_vector_width_float (OpenCL::Device this)
875 PPCODE:
876 cl_uint value [1];
877 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, sizeof (value), value, 0));
878 EXTEND (SP, 1);
879 const int i = 0;
880 PUSHs (sv_2mortal (newSVuv (value [i])));
881
882void
883native_vector_width_double (OpenCL::Device this)
884 PPCODE:
885 cl_uint value [1];
886 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, sizeof (value), value, 0));
887 EXTEND (SP, 1);
888 const int i = 0;
889 PUSHs (sv_2mortal (newSVuv (value [i])));
890
891void
892native_vector_width_half (OpenCL::Device this)
893 PPCODE:
894 cl_uint value [1];
895 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, sizeof (value), value, 0));
896 EXTEND (SP, 1);
897 const int i = 0;
898 PUSHs (sv_2mortal (newSVuv (value [i])));
899
900void
901double_fp_config (OpenCL::Device this)
902 PPCODE:
903 cl_device_fp_config value [1];
904 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_DOUBLE_FP_CONFIG, sizeof (value), value, 0));
905 EXTEND (SP, 1);
906 const int i = 0;
907 PUSHs (sv_2mortal (newSVuv (value [i])));
908
909void
910half_fp_config (OpenCL::Device this)
911 PPCODE:
912 cl_device_fp_config value [1];
913 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_HALF_FP_CONFIG, sizeof (value), value, 0));
914 EXTEND (SP, 1);
915 const int i = 0;
916 PUSHs (sv_2mortal (newSVuv (value [i])));
917
918void
919host_unified_memory (OpenCL::Device this)
920 PPCODE:
921 cl_bool value [1];
922 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_HOST_UNIFIED_MEMORY, sizeof (value), value, 0));
923 EXTEND (SP, 1);
924 const int i = 0;
925 PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no));
926
927void
928parent_device_ext (OpenCL::Device this)
929 PPCODE:
930 cl_device_id value [1];
931 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PARENT_DEVICE_EXT, sizeof (value), value, 0));
932 EXTEND (SP, 1);
933 const int i = 0;
934 {
935 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i]));
936 }
937
938void
939partition_types_ext (OpenCL::Device this)
940 PPCODE:
941 size_t size;
942 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PARTITION_TYPES_EXT, 0, 0, &size));
943 cl_device_partition_property_ext *value = tmpbuf (size);
944 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PARTITION_TYPES_EXT, size, value, 0));
945 int i, n = size / sizeof (value [0]);
946 EXTEND (SP, n);
947 for (i = 0; i < n; ++i)
948 PUSHs (sv_2mortal (newSVuv (value [i])));
949
950void
951affinity_domains_ext (OpenCL::Device this)
952 PPCODE:
953 size_t size;
954 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_AFFINITY_DOMAINS_EXT, 0, 0, &size));
955 cl_device_partition_property_ext *value = tmpbuf (size);
956 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_AFFINITY_DOMAINS_EXT, size, value, 0));
957 int i, n = size / sizeof (value [0]);
958 EXTEND (SP, n);
959 for (i = 0; i < n; ++i)
960 PUSHs (sv_2mortal (newSVuv (value [i])));
961
962void
963reference_count_ext (OpenCL::Device this)
964 PPCODE:
965 cl_uint value [1];
966 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_REFERENCE_COUNT_EXT , sizeof (value), value, 0));
967 EXTEND (SP, 1);
968 const int i = 0;
969 PUSHs (sv_2mortal (newSVuv (value [i])));
970
971void
972partition_style_ext (OpenCL::Device this)
973 PPCODE:
974 size_t size;
975 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PARTITION_STYLE_EXT, 0, 0, &size));
976 cl_device_partition_property_ext *value = tmpbuf (size);
977 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PARTITION_STYLE_EXT, size, value, 0));
978 int i, n = size / sizeof (value [0]);
979 EXTEND (SP, n);
980 for (i = 0; i < n; ++i)
981 PUSHs (sv_2mortal (newSVuv (value [i])));
982
983#END:device
239 984
240MODULE = OpenCL PACKAGE = OpenCL::Context 985MODULE = OpenCL PACKAGE = OpenCL::Context
241 986
242void 987void
243DESTROY (OpenCL::Context context) 988DESTROY (OpenCL::Context context)
248info (OpenCL::Context this, cl_context_info name) 993info (OpenCL::Context this, cl_context_info name)
249 PPCODE: 994 PPCODE:
250 INFO (Context) 995 INFO (Context)
251 996
252void 997void
253command_queue_simple (OpenCL::Context this, OpenCL::Device device) 998queue (OpenCL::Context this, OpenCL::Device device, cl_command_queue_properties properties = 0)
254 PPCODE: 999 PPCODE:
255{
256 cl_int res;
257 cl_command_queue queue = clCreateCommandQueue (this, device, 0, &res); 1000 NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (this, device, properties, &res));
258
259 if (res)
260 FAIL (CreateCommandQueue, res);
261
262 XPUSH_NEW_OBJ ("OpenCL::Queue", queue); 1001 XPUSH_NEW_OBJ ("OpenCL::Queue", queue);
263} 1002
1003void
1004user_event (OpenCL::Context this)
1005 PPCODE:
1006 NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (this, &res));
1007 XPUSH_NEW_OBJ ("OpenCL::UserEvent", ev);
264 1008
265void 1009void
266buffer (OpenCL::Context this, cl_mem_flags flags, size_t len) 1010buffer (OpenCL::Context this, cl_mem_flags flags, size_t len)
267 PPCODE: 1011 PPCODE:
268{
269 cl_int res;
270 cl_mem mem;
271
272 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) 1012 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
273 croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); 1013 croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?");
274 1014
275 mem = clCreateBuffer (this, flags, len, 0, &res); 1015 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, 0, &res));
276
277 if (res)
278 FAIL (CreateBuffer, res);
279
280 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); 1016 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
281}
282 1017
283void 1018void
284buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data) 1019buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data)
285 PPCODE: 1020 PPCODE:
286{
287 STRLEN len; 1021 STRLEN len;
288 char *ptr = SvPVbyte (data, len); 1022 char *ptr = SvPVbyte (data, len);
289 cl_int res;
290 cl_mem mem;
291 1023
292 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) 1024 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
293 croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); 1025 croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
294 1026
295 mem = clCreateBuffer (this, flags, len, ptr, &res); 1027 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, ptr, &res));
296
297 if (res)
298 FAIL (CreateBuffer, res);
299
300 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); 1028 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
301}
302 1029
303void 1030void
304image2d (OpenCL::Context this, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, SV *data) 1031image2d (OpenCL::Context this, 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)
305 PPCODE: 1032 PPCODE:
306{
307 STRLEN len; 1033 STRLEN len;
308 char *ptr = SvPVbyte (data, len); 1034 char *ptr = SvPVbyte (data, len);
309 const cl_image_format format = { channel_order, channel_type }; 1035 const cl_image_format format = { channel_order, channel_type };
310 cl_int res;
311 cl_mem mem = clCreateImage2D (this, flags, &format, width, height, len / height, ptr, &res); 1036 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (this, flags, &format, width, height, row_pitch, ptr, &res));
312
313 if (res)
314 FAIL (CreateImage2D, res);
315
316 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 1037 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
317}
318 1038
319void 1039void
320image3d (OpenCL::Context this, 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 slice_pitch, SV *data) 1040image3d (OpenCL::Context this, 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)
321 PPCODE: 1041 PPCODE:
322{
323 STRLEN len; 1042 STRLEN len;
324 char *ptr = SvPVbyte (data, len); 1043 char *ptr = SvPVbyte (data, len);
325 const cl_image_format format = { channel_order, channel_type }; 1044 const cl_image_format format = { channel_order, channel_type };
326 cl_int res; 1045 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (this, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
327 cl_mem mem = clCreateImage3D (this, flags, &format, width, height,
328 depth, len / (height * slice_pitch), slice_pitch, ptr, &res);
329
330 if (res)
331 FAIL (CreateImage3D, res);
332
333 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 1046 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
334}
335 1047
336void 1048void
337supported_image_formats (OpenCL::Context this, cl_mem_flags flags, cl_mem_object_type image_type) 1049supported_image_formats (OpenCL::Context this, cl_mem_flags flags, cl_mem_object_type image_type)
338 PPCODE: 1050 PPCODE:
339{ 1051{
356} 1068}
357 1069
358void 1070void
359sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode) 1071sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode)
360 PPCODE: 1072 PPCODE:
361{
362 cl_int res;
363 cl_sampler sampler = clCreateSampler (this, normalized_coords, addressing_mode, filter_mode, &res); 1073 NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (this, normalized_coords, addressing_mode, filter_mode, &res));
364
365 if (res)
366 FAIL (CreateSampler, res);
367
368 XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler); 1074 XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler);
369}
370 1075
371void 1076void
372program_with_source (OpenCL::Context this, SV *program) 1077program_with_source (OpenCL::Context this, SV *program)
373 PPCODE: 1078 PPCODE:
374{
375 STRLEN len; 1079 STRLEN len;
376 size_t len2; 1080 size_t len2;
377 const char *ptr = SvPVbyte (program, len); 1081 const char *ptr = SvPVbyte (program, len);
378 cl_int res;
379 cl_program prog;
380 1082
381 len2 = len; 1083 len2 = len;
382 prog = clCreateProgramWithSource (this, 1, &ptr, &len2, &res); 1084 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (this, 1, &ptr, &len2, &res));
383
384 if (res)
385 FAIL (CreateProgramWithSource, res);
386
387 XPUSH_NEW_OBJ ("OpenCL::Program", prog); 1085 XPUSH_NEW_OBJ ("OpenCL::Program", prog);
388} 1086
1087#BEGIN:context
1088
1089void
1090reference_count (OpenCL::Context this)
1091 PPCODE:
1092 cl_uint value [1];
1093 NEED_SUCCESS (GetContextInfo, (this, CL_CONTEXT_REFERENCE_COUNT, sizeof (value), value, 0));
1094 EXTEND (SP, 1);
1095 const int i = 0;
1096 PUSHs (sv_2mortal (newSVuv (value [i])));
1097
1098void
1099devices (OpenCL::Context this)
1100 PPCODE:
1101 size_t size;
1102 NEED_SUCCESS (GetContextInfo, (this, CL_CONTEXT_DEVICES, 0, 0, &size));
1103 cl_device_id *value = tmpbuf (size);
1104 NEED_SUCCESS (GetContextInfo, (this, CL_CONTEXT_DEVICES, size, value, 0));
1105 int i, n = size / sizeof (value [0]);
1106 EXTEND (SP, n);
1107 for (i = 0; i < n; ++i)
1108 {
1109 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i]));
1110 }
1111
1112void
1113properties (OpenCL::Context this)
1114 PPCODE:
1115 size_t size;
1116 NEED_SUCCESS (GetContextInfo, (this, CL_CONTEXT_PROPERTIES, 0, 0, &size));
1117 cl_context_properties *value = tmpbuf (size);
1118 NEED_SUCCESS (GetContextInfo, (this, CL_CONTEXT_PROPERTIES, size, value, 0));
1119 int i, n = size / sizeof (value [0]);
1120 EXTEND (SP, n);
1121 for (i = 0; i < n; ++i)
1122 PUSHs (sv_2mortal (newSVuv ((UV)value [i])));
1123
1124void
1125num_devices (OpenCL::Context this)
1126 PPCODE:
1127 cl_uint value [1];
1128 NEED_SUCCESS (GetContextInfo, (this, CL_CONTEXT_NUM_DEVICES, sizeof (value), value, 0));
1129 EXTEND (SP, 1);
1130 const int i = 0;
1131 PUSHs (sv_2mortal (newSVuv (value [i])));
1132
1133#END:context
389 1134
390MODULE = OpenCL PACKAGE = OpenCL::Queue 1135MODULE = OpenCL PACKAGE = OpenCL::Queue
391 1136
392void 1137void
393DESTROY (OpenCL::Queue this) 1138DESTROY (OpenCL::Queue this)
394 CODE: 1139 CODE:
395 clReleaseCommandQueue (this); 1140 clReleaseCommandQueue (this);
396 1141
397void 1142void
398info (OpenCL::Queue this, cl_command_queue_info name)
399 PPCODE:
400 INFO (CommandQueue)
401
402void
403enqueue_read_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...) 1143enqueue_read_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...)
404 PPCODE: 1144 PPCODE:
405{
406 cl_event ev = 0; 1145 cl_event ev = 0;
407 EVENT_LIST (6, items - 6); 1146 EVENT_LIST (6, items - 6);
408 1147
409 SvUPGRADE (data, SVt_PV); 1148 SvUPGRADE (data, SVt_PV);
410 SvGROW (data, len); 1149 SvGROW (data, len);
412 SvCUR_set (data, len); 1151 SvCUR_set (data, len);
413 NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1152 NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
414 1153
415 if (ev) 1154 if (ev)
416 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1155 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
417}
418 1156
419void 1157void
420enqueue_write_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...) 1158enqueue_write_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...)
421 PPCODE: 1159 PPCODE:
422{
423 cl_event ev = 0; 1160 cl_event ev = 0;
424 STRLEN len; 1161 STRLEN len;
425 char *ptr = SvPVbyte (data, len); 1162 char *ptr = SvPVbyte (data, len);
426 EVENT_LIST (5, items - 5); 1163 EVENT_LIST (5, items - 5);
427 1164
428 NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1165 NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
429 1166
430 if (ev) 1167 if (ev)
431 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1168 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
432}
433 1169
434void 1170void
435enqueue_copy_buffer (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...) 1171enqueue_copy_buffer (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...)
436 PPCODE: 1172 PPCODE:
437{
438 cl_event ev = 0; 1173 cl_event ev = 0;
439 EVENT_LIST (6, items - 6); 1174 EVENT_LIST (6, items - 6);
440 1175
441 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1176 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
442 1177
443 if (ev) 1178 if (ev)
444 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1179 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
445}
446
447 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBufferRect.html */
448 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html */
449 1180
450void 1181void
451enqueue_read_image (OpenCL::Queue this, 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, ...) 1182enqueue_read_image (OpenCL::Queue this, 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, ...)
452 PPCODE: 1183 PPCODE:
453{
454 cl_event ev = 0; 1184 cl_event ev = 0;
455 const size_t src_origin[3] = { src_x, src_y, src_z }; 1185 const size_t src_origin[3] = { src_x, src_y, src_z };
456 const size_t region[3] = { width, height, depth }; 1186 const size_t region[3] = { width, height, depth };
457 size_t len = row_pitch * slice_pitch * depth;
458 EVENT_LIST (11, items - 11); 1187 EVENT_LIST (12, items - 12);
1188
1189 if (!row_pitch)
1190 row_pitch = img_row_pitch (src);
1191
1192 if (depth > 1 && !slice_pitch)
1193 slice_pitch = row_pitch * height;
1194
1195 size_t len = slice_pitch ? slice_pitch * depth : row_pitch * height;
459 1196
460 SvUPGRADE (data, SVt_PV); 1197 SvUPGRADE (data, SVt_PV);
461 SvGROW (data, len); 1198 SvGROW (data, len);
462 SvPOK_only (data); 1199 SvPOK_only (data);
463 SvCUR_set (data, len); 1200 SvCUR_set (data, len);
464 NEED_SUCCESS (EnqueueReadImage, (this, src, blocking, src_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1201 NEED_SUCCESS (EnqueueReadImage, (this, src, blocking, src_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
465 1202
466 if (ev) 1203 if (ev)
467 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1204 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
468}
469 1205
470void 1206void
471enqueue_write_image (OpenCL::Queue this, 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, SV *data, ...) 1207enqueue_write_image (OpenCL::Queue this, 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, ...)
472 PPCODE: 1208 PPCODE:
473{
474 cl_event ev = 0; 1209 cl_event ev = 0;
475 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 1210 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
476 const size_t region[3] = { width, height, depth }; 1211 const size_t region[3] = { width, height, depth };
477 STRLEN len; 1212 STRLEN len;
478 char *ptr = SvPVbyte (data, len); 1213 char *ptr = SvPVbyte (data, len);
479 size_t slice_pitch = len / (row_pitch * height);
480 EVENT_LIST (11, items - 11); 1214 EVENT_LIST (12, items - 12);
1215
1216 if (!row_pitch)
1217 row_pitch = img_row_pitch (dst);
1218
1219 if (depth > 1 && !slice_pitch)
1220 slice_pitch = row_pitch * height;
1221
1222 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height;
1223
1224 if (len < min_len)
1225 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
481 1226
482 NEED_SUCCESS (EnqueueWriteImage, (this, dst, blocking, dst_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1227 NEED_SUCCESS (EnqueueWriteImage, (this, dst, blocking, dst_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
483 1228
484 if (ev) 1229 if (ev)
485 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1230 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
486}
487 1231
488void 1232void
489enqueue_copy_buffer_rect (OpenCL::Queue this, 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, ...) 1233enqueue_copy_buffer_rect (OpenCL::Queue this, 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, ...)
490 PPCODE: 1234 PPCODE:
491{
492 cl_event ev = 0; 1235 cl_event ev = 0;
493 const size_t src_origin[3] = { src_x, src_y, src_z }; 1236 const size_t src_origin[3] = { src_x, src_y, src_z };
494 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 1237 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
495 const size_t region[3] = { width, height, depth }; 1238 const size_t region[3] = { width, height, depth };
496 EVENT_LIST (16, items - 16); 1239 EVENT_LIST (16, items - 16);
497 1240
498 NEED_SUCCESS (EnqueueCopyBufferRect, (this, 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)); 1241 NEED_SUCCESS (EnqueueCopyBufferRect, (this, 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));
499 1242
500 if (ev) 1243 if (ev)
501 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1244 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
502}
503 1245
504void 1246void
505enqueue_copy_buffer_to_image (OpenCL::Queue this, 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, ...) 1247enqueue_copy_buffer_to_image (OpenCL::Queue this, 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, ...)
506 PPCODE: 1248 PPCODE:
507{
508 cl_event ev = 0; 1249 cl_event ev = 0;
509 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 1250 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
510 const size_t region[3] = { width, height, depth }; 1251 const size_t region[3] = { width, height, depth };
511 EVENT_LIST (10, items - 10); 1252 EVENT_LIST (10, items - 10);
512 1253
513 NEED_SUCCESS (EnqueueCopyBufferToImage, (this, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1254 NEED_SUCCESS (EnqueueCopyBufferToImage, (this, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
514 1255
515 if (ev) 1256 if (ev)
516 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1257 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
517}
518 1258
519void 1259void
520enqueue_copy_image (OpenCL::Queue this, OpenCL::Image 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, ...) 1260enqueue_copy_image (OpenCL::Queue this, 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, ...)
521 PPCODE: 1261 PPCODE:
522{
523 cl_event ev = 0; 1262 cl_event ev = 0;
524 const size_t src_origin[3] = { src_x, src_y, src_z }; 1263 const size_t src_origin[3] = { src_x, src_y, src_z };
525 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 1264 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
526 const size_t region[3] = { width, height, depth }; 1265 const size_t region[3] = { width, height, depth };
527 EVENT_LIST (12, items - 12); 1266 EVENT_LIST (12, items - 12);
528 1267
529 NEED_SUCCESS (EnqueueCopyImage, (this, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1268 NEED_SUCCESS (EnqueueCopyImage, (this, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
530 1269
531 if (ev) 1270 if (ev)
532 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1271 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
533}
534 1272
535void 1273void
536enqueue_copy_image_to_buffer (OpenCL::Queue this, 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, ...) 1274enqueue_copy_image_to_buffer (OpenCL::Queue this, 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, ...)
537 PPCODE: 1275 PPCODE:
538{
539 cl_event ev = 0; 1276 cl_event ev = 0;
540 const size_t src_origin[3] = { src_x, src_y, src_z }; 1277 const size_t src_origin[3] = { src_x, src_y, src_z };
541 const size_t region[3] = { width, height, depth }; 1278 const size_t region[3] = { width, height, depth };
542 EVENT_LIST (10, items - 10); 1279 EVENT_LIST (10, items - 10);
543 1280
544 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1281 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
545 1282
546 if (ev) 1283 if (ev)
547 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1284 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
548}
549 1285
550void 1286void
551enqueue_task (OpenCL::Queue this, OpenCL::Kernel kernel, ...) 1287enqueue_task (OpenCL::Queue this, OpenCL::Kernel kernel, ...)
552 PPCODE: 1288 PPCODE:
553{
554 cl_event ev = 0; 1289 cl_event ev = 0;
555 EVENT_LIST (2, items - 2); 1290 EVENT_LIST (2, items - 2);
556 1291
557 NEED_SUCCESS (EnqueueTask, (this, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1292 NEED_SUCCESS (EnqueueTask, (this, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
558 1293
559 if (ev) 1294 if (ev)
560 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1295 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
561}
562 1296
563 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueNDRangeKernel.html */ 1297void
1298enqueue_nd_range_kernel (OpenCL::Queue this, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...)
1299 PPCODE:
1300 cl_event ev = 0;
1301 size_t *gwo = 0, *gws, *lws = 0;
1302 int gws_len;
1303 size_t *lists;
1304 int i;
1305 EVENT_LIST (5, items - 5);
1306
1307 if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV)
1308 croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference");
1309
1310 gws_len = AvFILLp (SvRV (global_work_size)) + 1;
1311
1312 lists = tmpbuf (sizeof (size_t) * 3 * gws_len);
1313
1314 gws = lists + gws_len * 0;
1315 for (i = 0; i < gws_len; ++i)
1316 gws [i] = SvIV (AvARRAY (SvRV (global_work_size))[i]);
1317
1318 if (SvOK (global_work_offset))
1319 {
1320 if (!SvROK (global_work_offset) || SvTYPE (SvRV (global_work_offset)) != SVt_PVAV)
1321 croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array reference");
1322
1323 if (AvFILLp (SvRV (global_work_size)) + 1 != gws_len)
1324 croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array of same size as global_work_size");
1325
1326 gwo = lists + gws_len * 1;
1327 for (i = 0; i < gws_len; ++i)
1328 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
1329 }
1330
1331 if (SvOK (local_work_size))
1332 {
1333 if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV)
1334 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference");
1335
1336 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len)
1337 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
1338
1339 lws = lists + gws_len * 2;
1340 for (i = 0; i < gws_len; ++i)
1341 lws [i] = SvIV (AvARRAY (SvRV (local_work_size))[i]);
1342 }
1343
1344 NEED_SUCCESS (EnqueueNDRangeKernel, (this, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1345
1346 if (ev)
1347 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
564 1348
565void 1349void
566enqueue_marker (OpenCL::Queue this) 1350enqueue_marker (OpenCL::Queue this)
567 PPCODE: 1351 PPCODE:
568{
569 cl_event ev; 1352 cl_event ev;
570 NEED_SUCCESS (EnqueueMarker, (this, &ev)); 1353 NEED_SUCCESS (EnqueueMarker, (this, &ev));
571 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1354 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
572}
573 1355
574void 1356void
575enqueue_wait_for_events (OpenCL::Queue this, ...) 1357enqueue_wait_for_events (OpenCL::Queue this, ...)
576 CODE: 1358 CODE:
577{
578 EVENT_LIST (1, items - 1); 1359 EVENT_LIST (1, items - 1);
579 NEED_SUCCESS (EnqueueWaitForEvents, (this, event_list_count, event_list_ptr)); 1360 NEED_SUCCESS (EnqueueWaitForEvents, (this, event_list_count, event_list_ptr));
580}
581 1361
582void 1362void
583enqueue_barrier (OpenCL::Queue this) 1363enqueue_barrier (OpenCL::Queue this)
584 CODE: 1364 CODE:
585 NEED_SUCCESS (EnqueueBarrier, (this)); 1365 NEED_SUCCESS (EnqueueBarrier, (this));
592void 1372void
593finish (OpenCL::Queue this) 1373finish (OpenCL::Queue this)
594 CODE: 1374 CODE:
595 NEED_SUCCESS (Finish, (this)); 1375 NEED_SUCCESS (Finish, (this));
596 1376
1377void
1378info (OpenCL::Queue this, cl_command_queue_info name)
1379 PPCODE:
1380 INFO (CommandQueue)
1381
1382#BEGIN:command_queue
1383
1384void
1385context (OpenCL::Queue this)
1386 PPCODE:
1387 cl_context value [1];
1388 NEED_SUCCESS (GetCommandQueueInfo, (this, CL_QUEUE_CONTEXT, sizeof (value), value, 0));
1389 EXTEND (SP, 1);
1390 const int i = 0;
1391 {
1392 NEED_SUCCESS (RetainContext, (value [i]));
1393 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
1394 }
1395
1396void
1397device (OpenCL::Queue this)
1398 PPCODE:
1399 cl_device_id value [1];
1400 NEED_SUCCESS (GetCommandQueueInfo, (this, CL_QUEUE_DEVICE, sizeof (value), value, 0));
1401 EXTEND (SP, 1);
1402 const int i = 0;
1403 {
1404 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i]));
1405 }
1406
1407void
1408reference_count (OpenCL::Queue this)
1409 PPCODE:
1410 cl_uint value [1];
1411 NEED_SUCCESS (GetCommandQueueInfo, (this, CL_QUEUE_REFERENCE_COUNT, sizeof (value), value, 0));
1412 EXTEND (SP, 1);
1413 const int i = 0;
1414 PUSHs (sv_2mortal (newSVuv (value [i])));
1415
1416void
1417properties (OpenCL::Queue this)
1418 PPCODE:
1419 cl_command_queue_properties value [1];
1420 NEED_SUCCESS (GetCommandQueueInfo, (this, CL_QUEUE_PROPERTIES, sizeof (value), value, 0));
1421 EXTEND (SP, 1);
1422 const int i = 0;
1423 PUSHs (sv_2mortal (newSViv (value [i])));
1424
1425#END:command_queue
1426
597MODULE = OpenCL PACKAGE = OpenCL::Memory 1427MODULE = OpenCL PACKAGE = OpenCL::Memory
598 1428
599void 1429void
600DESTROY (OpenCL::Memory this) 1430DESTROY (OpenCL::Memory this)
601 CODE: 1431 CODE:
604void 1434void
605info (OpenCL::Memory this, cl_mem_info name) 1435info (OpenCL::Memory this, cl_mem_info name)
606 PPCODE: 1436 PPCODE:
607 INFO (MemObject) 1437 INFO (MemObject)
608 1438
1439#BEGIN:mem
1440
1441void
1442type (OpenCL::Memory this)
1443 PPCODE:
1444 cl_mem_object_type value [1];
1445 NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_TYPE, sizeof (value), value, 0));
1446 EXTEND (SP, 1);
1447 const int i = 0;
1448 PUSHs (sv_2mortal (newSViv (value [i])));
1449
1450void
1451flags (OpenCL::Memory this)
1452 PPCODE:
1453 cl_mem_flags value [1];
1454 NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_FLAGS, sizeof (value), value, 0));
1455 EXTEND (SP, 1);
1456 const int i = 0;
1457 PUSHs (sv_2mortal (newSViv (value [i])));
1458
1459void
1460size (OpenCL::Memory this)
1461 PPCODE:
1462 size_t value [1];
1463 NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_SIZE, sizeof (value), value, 0));
1464 EXTEND (SP, 1);
1465 const int i = 0;
1466 PUSHs (sv_2mortal (newSVuv (value [i])));
1467
1468void
1469host_ptr (OpenCL::Memory this)
1470 PPCODE:
1471 void * value [1];
1472 NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_HOST_PTR, sizeof (value), value, 0));
1473 EXTEND (SP, 1);
1474 const int i = 0;
1475 PUSHs (sv_2mortal (newSVuv ((IV)(intptr_t)value [i])));
1476
1477void
1478map_count (OpenCL::Memory this)
1479 PPCODE:
1480 cl_uint value [1];
1481 NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_MAP_COUNT, sizeof (value), value, 0));
1482 EXTEND (SP, 1);
1483 const int i = 0;
1484 PUSHs (sv_2mortal (newSVuv (value [i])));
1485
1486void
1487reference_count (OpenCL::Memory this)
1488 PPCODE:
1489 cl_uint value [1];
1490 NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_REFERENCE_COUNT, sizeof (value), value, 0));
1491 EXTEND (SP, 1);
1492 const int i = 0;
1493 PUSHs (sv_2mortal (newSVuv (value [i])));
1494
1495void
1496context (OpenCL::Memory this)
1497 PPCODE:
1498 cl_context value [1];
1499 NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_CONTEXT, sizeof (value), value, 0));
1500 EXTEND (SP, 1);
1501 const int i = 0;
1502 {
1503 NEED_SUCCESS (RetainContext, (value [i]));
1504 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
1505 }
1506
1507void
1508associated_memobject (OpenCL::Memory this)
1509 PPCODE:
1510 cl_mem value [1];
1511 NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_ASSOCIATED_MEMOBJECT, sizeof (value), value, 0));
1512 EXTEND (SP, 1);
1513 const int i = 0;
1514 {
1515 NEED_SUCCESS (RetainMemObject, (value [i]));
1516 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i]));
1517 }
1518
1519void
1520offset (OpenCL::Memory this)
1521 PPCODE:
1522 size_t value [1];
1523 NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_OFFSET, sizeof (value), value, 0));
1524 EXTEND (SP, 1);
1525 const int i = 0;
1526 PUSHs (sv_2mortal (newSVuv (value [i])));
1527
1528#END:mem
1529
1530MODULE = OpenCL PACKAGE = OpenCL::Image
1531
1532void
1533image_info (OpenCL::Image this, cl_image_info name)
1534 PPCODE:
1535 INFO (Image)
1536
1537#BEGIN:image
1538
1539void
1540element_size (OpenCL::Image this)
1541 PPCODE:
1542 size_t value [1];
1543 NEED_SUCCESS (GetImageInfo, (this, CL_IMAGE_ELEMENT_SIZE, sizeof (value), value, 0));
1544 EXTEND (SP, 1);
1545 const int i = 0;
1546 PUSHs (sv_2mortal (newSVuv (value [i])));
1547
1548void
1549row_pitch (OpenCL::Image this)
1550 PPCODE:
1551 size_t value [1];
1552 NEED_SUCCESS (GetImageInfo, (this, CL_IMAGE_ROW_PITCH, sizeof (value), value, 0));
1553 EXTEND (SP, 1);
1554 const int i = 0;
1555 PUSHs (sv_2mortal (newSVuv (value [i])));
1556
1557void
1558slice_pitch (OpenCL::Image this)
1559 PPCODE:
1560 size_t value [1];
1561 NEED_SUCCESS (GetImageInfo, (this, CL_IMAGE_SLICE_PITCH, sizeof (value), value, 0));
1562 EXTEND (SP, 1);
1563 const int i = 0;
1564 PUSHs (sv_2mortal (newSVuv (value [i])));
1565
1566void
1567width (OpenCL::Image this)
1568 PPCODE:
1569 size_t value [1];
1570 NEED_SUCCESS (GetImageInfo, (this, CL_IMAGE_WIDTH, sizeof (value), value, 0));
1571 EXTEND (SP, 1);
1572 const int i = 0;
1573 PUSHs (sv_2mortal (newSVuv (value [i])));
1574
1575void
1576height (OpenCL::Image this)
1577 PPCODE:
1578 size_t value [1];
1579 NEED_SUCCESS (GetImageInfo, (this, CL_IMAGE_HEIGHT, sizeof (value), value, 0));
1580 EXTEND (SP, 1);
1581 const int i = 0;
1582 PUSHs (sv_2mortal (newSVuv (value [i])));
1583
1584void
1585depth (OpenCL::Image this)
1586 PPCODE:
1587 size_t value [1];
1588 NEED_SUCCESS (GetImageInfo, (this, CL_IMAGE_DEPTH, sizeof (value), value, 0));
1589 EXTEND (SP, 1);
1590 const int i = 0;
1591 PUSHs (sv_2mortal (newSVuv (value [i])));
1592
1593#END:image
1594
609MODULE = OpenCL PACKAGE = OpenCL::Sampler 1595MODULE = OpenCL PACKAGE = OpenCL::Sampler
610 1596
611void 1597void
612DESTROY (OpenCL::Sampler this) 1598DESTROY (OpenCL::Sampler this)
613 CODE: 1599 CODE:
616void 1602void
617info (OpenCL::Sampler this, cl_sampler_info name) 1603info (OpenCL::Sampler this, cl_sampler_info name)
618 PPCODE: 1604 PPCODE:
619 INFO (Sampler) 1605 INFO (Sampler)
620 1606
1607#BEGIN:sampler
1608
1609void
1610reference_count (OpenCL::Sampler this)
1611 PPCODE:
1612 cl_uint value [1];
1613 NEED_SUCCESS (GetSamplerInfo, (this, CL_SAMPLER_REFERENCE_COUNT, sizeof (value), value, 0));
1614 EXTEND (SP, 1);
1615 const int i = 0;
1616 PUSHs (sv_2mortal (newSVuv (value [i])));
1617
1618void
1619context (OpenCL::Sampler this)
1620 PPCODE:
1621 cl_context value [1];
1622 NEED_SUCCESS (GetSamplerInfo, (this, CL_SAMPLER_CONTEXT, sizeof (value), value, 0));
1623 EXTEND (SP, 1);
1624 const int i = 0;
1625 {
1626 NEED_SUCCESS (RetainContext, (value [i]));
1627 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
1628 }
1629
1630void
1631normalized_coords (OpenCL::Sampler this)
1632 PPCODE:
1633 cl_addressing_mode value [1];
1634 NEED_SUCCESS (GetSamplerInfo, (this, CL_SAMPLER_NORMALIZED_COORDS, sizeof (value), value, 0));
1635 EXTEND (SP, 1);
1636 const int i = 0;
1637 PUSHs (sv_2mortal (newSViv (value [i])));
1638
1639void
1640addressing_mode (OpenCL::Sampler this)
1641 PPCODE:
1642 cl_filter_mode value [1];
1643 NEED_SUCCESS (GetSamplerInfo, (this, CL_SAMPLER_ADDRESSING_MODE, sizeof (value), value, 0));
1644 EXTEND (SP, 1);
1645 const int i = 0;
1646 PUSHs (sv_2mortal (newSViv (value [i])));
1647
1648void
1649filter_mode (OpenCL::Sampler this)
1650 PPCODE:
1651 cl_bool value [1];
1652 NEED_SUCCESS (GetSamplerInfo, (this, CL_SAMPLER_FILTER_MODE, sizeof (value), value, 0));
1653 EXTEND (SP, 1);
1654 const int i = 0;
1655 PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no));
1656
1657#END:sampler
1658
621MODULE = OpenCL PACKAGE = OpenCL::Program 1659MODULE = OpenCL PACKAGE = OpenCL::Program
622 1660
623void 1661void
624DESTROY (OpenCL::Program this) 1662DESTROY (OpenCL::Program this)
625 CODE: 1663 CODE:
626 clReleaseProgram (this); 1664 clReleaseProgram (this);
627 1665
628void 1666void
629info (OpenCL::Program this, cl_program_info name)
630 PPCODE:
631 INFO (Program)
632
633void
634build (OpenCL::Program this, OpenCL::Device device, SV *options = &PL_sv_undef) 1667build (OpenCL::Program this, OpenCL::Device device, SV *options = &PL_sv_undef)
635 CODE: 1668 CODE:
636 NEED_SUCCESS (BuildProgram, (this, 1, &device, SvPVbyte_nolen (options), 0, 0)); 1669 NEED_SUCCESS (BuildProgram, (this, 1, &device, SvPVbyte_nolen (options), 0, 0));
637 1670
638void 1671void
639build_info (OpenCL::Program this, OpenCL::Device device, cl_program_build_info name) 1672build_info (OpenCL::Program this, OpenCL::Device device, cl_program_build_info name)
640 PPCODE: 1673 PPCODE:
641{
642 size_t size; 1674 size_t size;
643 SV *sv;
644
645 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, 0, 0, &size)); 1675 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, 0, 0, &size));
646 sv = sv_2mortal (newSV (size)); 1676 SV *sv = sv_2mortal (newSV (size));
647 SvUPGRADE (sv, SVt_PV); 1677 SvUPGRADE (sv, SVt_PV);
648 SvPOK_only (sv); 1678 SvPOK_only (sv);
649 SvCUR_set (sv, size); 1679 SvCUR_set (sv, size);
650 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, size, SvPVX (sv), 0)); 1680 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, size, SvPVX (sv), 0));
651 XPUSHs (sv); 1681 XPUSHs (sv);
652} 1682
1683#BEGIN:program_build
1684
1685void
1686build_status (OpenCL::Program this, OpenCL::Device device)
1687 PPCODE:
1688 cl_build_status value [1];
1689 NEED_SUCCESS (GetProgramBuildInfo, (this, device, CL_PROGRAM_BUILD_STATUS, sizeof (value), value, 0));
1690 EXTEND (SP, 1);
1691 const int i = 0;
1692 PUSHs (sv_2mortal (newSViv (value [i])));
1693
1694void
1695build_options (OpenCL::Program this, OpenCL::Device device)
1696 PPCODE:
1697 size_t size;
1698 NEED_SUCCESS (GetProgramBuildInfo, (this, device, CL_PROGRAM_BUILD_OPTIONS, 0, 0, &size));
1699 char *value = tmpbuf (size);
1700 NEED_SUCCESS (GetProgramBuildInfo, (this, device, CL_PROGRAM_BUILD_OPTIONS, size, value, 0));
1701 int i, n = 1;
1702 EXTEND (SP, n);
1703 for (i = 0; i < n; ++i)
1704 PUSHs (sv_2mortal (newSVpv (value, 0)));
1705
1706void
1707build_log (OpenCL::Program this, OpenCL::Device device)
1708 PPCODE:
1709 size_t size;
1710 NEED_SUCCESS (GetProgramBuildInfo, (this, device, CL_PROGRAM_BUILD_LOG, 0, 0, &size));
1711 char *value = tmpbuf (size);
1712 NEED_SUCCESS (GetProgramBuildInfo, (this, device, CL_PROGRAM_BUILD_LOG, size, value, 0));
1713 int i, n = 1;
1714 EXTEND (SP, n);
1715 for (i = 0; i < n; ++i)
1716 PUSHs (sv_2mortal (newSVpv (value, 0)));
1717
1718#END:program_build
653 1719
654void 1720void
655kernel (OpenCL::Program program, SV *function) 1721kernel (OpenCL::Program program, SV *function)
656 PPCODE: 1722 PPCODE:
657{
658 cl_int res;
659 cl_kernel kernel = clCreateKernel (program, SvPVbyte_nolen (function), &res); 1723 NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res));
660
661 if (res)
662 FAIL (CreateKernel, res);
663
664 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel); 1724 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel);
665} 1725
1726void
1727info (OpenCL::Program this, cl_program_info name)
1728 PPCODE:
1729 INFO (Program)
1730
1731#BEGIN:program
1732
1733void
1734reference_count (OpenCL::Program this)
1735 PPCODE:
1736 cl_uint value [1];
1737 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_REFERENCE_COUNT, sizeof (value), value, 0));
1738 EXTEND (SP, 1);
1739 const int i = 0;
1740 PUSHs (sv_2mortal (newSVuv (value [i])));
1741
1742void
1743context (OpenCL::Program this)
1744 PPCODE:
1745 cl_context value [1];
1746 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_CONTEXT, sizeof (value), value, 0));
1747 EXTEND (SP, 1);
1748 const int i = 0;
1749 {
1750 NEED_SUCCESS (RetainContext, (value [i]));
1751 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
1752 }
1753
1754void
1755num_devices (OpenCL::Program this)
1756 PPCODE:
1757 cl_uint value [1];
1758 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_NUM_DEVICES, sizeof (value), value, 0));
1759 EXTEND (SP, 1);
1760 const int i = 0;
1761 PUSHs (sv_2mortal (newSVuv (value [i])));
1762
1763void
1764devices (OpenCL::Program this)
1765 PPCODE:
1766 size_t size;
1767 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_DEVICES, 0, 0, &size));
1768 cl_device_id *value = tmpbuf (size);
1769 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_DEVICES, size, value, 0));
1770 int i, n = size / sizeof (value [0]);
1771 EXTEND (SP, n);
1772 for (i = 0; i < n; ++i)
1773 {
1774 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i]));
1775 }
1776
1777void
1778source (OpenCL::Program this)
1779 PPCODE:
1780 size_t size;
1781 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_SOURCE, 0, 0, &size));
1782 char *value = tmpbuf (size);
1783 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_SOURCE, size, value, 0));
1784 int i, n = 1;
1785 EXTEND (SP, n);
1786 for (i = 0; i < n; ++i)
1787 PUSHs (sv_2mortal (newSVpv (value, 0)));
1788
1789void
1790binary_sizes (OpenCL::Program this)
1791 PPCODE:
1792 size_t size;
1793 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_BINARY_SIZES, 0, 0, &size));
1794 size_t *value = tmpbuf (size);
1795 NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_BINARY_SIZES, size, value, 0));
1796 int i, n = size / sizeof (value [0]);
1797 EXTEND (SP, n);
1798 for (i = 0; i < n; ++i)
1799 PUSHs (sv_2mortal (newSVuv (value [i])));
1800
1801#END:program
666 1802
667MODULE = OpenCL PACKAGE = OpenCL::Kernel 1803MODULE = OpenCL PACKAGE = OpenCL::Kernel
668 1804
669void 1805void
670DESTROY (OpenCL::Kernel this) 1806DESTROY (OpenCL::Kernel this)
671 CODE: 1807 CODE:
672 clReleaseKernel (this); 1808 clReleaseKernel (this);
673 1809
674void 1810void
1811set_char (OpenCL::Kernel this, cl_uint idx, cl_char value)
1812 CODE:
1813 clSetKernelArg (this, idx, sizeof (value), &value);
1814
1815void
1816set_uchar (OpenCL::Kernel this, cl_uint idx, cl_uchar value)
1817 CODE:
1818 clSetKernelArg (this, idx, sizeof (value), &value);
1819
1820void
1821set_short (OpenCL::Kernel this, cl_uint idx, cl_short value)
1822 CODE:
1823 clSetKernelArg (this, idx, sizeof (value), &value);
1824
1825void
1826set_ushort (OpenCL::Kernel this, cl_uint idx, cl_ushort value)
1827 CODE:
1828 clSetKernelArg (this, idx, sizeof (value), &value);
1829
1830void
1831set_int (OpenCL::Kernel this, cl_uint idx, cl_int value)
1832 CODE:
1833 clSetKernelArg (this, idx, sizeof (value), &value);
1834
1835void
1836set_uint (OpenCL::Kernel this, cl_uint idx, cl_uint value)
1837 CODE:
1838 clSetKernelArg (this, idx, sizeof (value), &value);
1839
1840void
1841set_long (OpenCL::Kernel this, cl_uint idx, cl_long value)
1842 CODE:
1843 clSetKernelArg (this, idx, sizeof (value), &value);
1844
1845void
1846set_ulong (OpenCL::Kernel this, cl_uint idx, cl_ulong value)
1847 CODE:
1848 clSetKernelArg (this, idx, sizeof (value), &value);
1849
1850void
1851set_half (OpenCL::Kernel this, cl_uint idx, cl_half value)
1852 CODE:
1853 clSetKernelArg (this, idx, sizeof (value), &value);
1854
1855void
1856set_float (OpenCL::Kernel this, cl_uint idx, cl_float value)
1857 CODE:
1858 clSetKernelArg (this, idx, sizeof (value), &value);
1859
1860void
1861set_double (OpenCL::Kernel this, cl_uint idx, cl_double value)
1862 CODE:
1863 clSetKernelArg (this, idx, sizeof (value), &value);
1864
1865void
1866set_memory (OpenCL::Kernel this, cl_uint idx, OpenCL::Memory_ornull value)
1867 CODE:
1868 clSetKernelArg (this, idx, sizeof (value), &value);
1869
1870void
1871set_buffer (OpenCL::Kernel this, cl_uint idx, OpenCL::Buffer_ornull value)
1872 CODE:
1873 clSetKernelArg (this, idx, sizeof (value), &value);
1874
1875void
1876set_image2d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image2D_ornull value)
1877 CODE:
1878 clSetKernelArg (this, idx, sizeof (value), &value);
1879
1880void
1881set_image3d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image3D_ornull value)
1882 CODE:
1883 clSetKernelArg (this, idx, sizeof (value), &value);
1884
1885void
1886set_sampler (OpenCL::Kernel this, cl_uint idx, OpenCL::Sampler value)
1887 CODE:
1888 clSetKernelArg (this, idx, sizeof (value), &value);
1889
1890void
1891set_event (OpenCL::Kernel this, cl_uint idx, OpenCL::Event value)
1892 CODE:
1893 clSetKernelArg (this, idx, sizeof (value), &value);
1894
1895void
675info (OpenCL::Kernel this, cl_kernel_info name) 1896info (OpenCL::Kernel this, cl_kernel_info name)
676 PPCODE: 1897 PPCODE:
677 INFO (Kernel) 1898 INFO (Kernel)
678 1899
1900#BEGIN:kernel
1901
679void 1902void
680set_char (OpenCL::Kernel this, cl_uint idx, cl_char value) 1903function_name (OpenCL::Kernel this)
1904 PPCODE:
1905 size_t size;
1906 NEED_SUCCESS (GetKernelInfo, (this, CL_KERNEL_FUNCTION_NAME, 0, 0, &size));
1907 char *value = tmpbuf (size);
1908 NEED_SUCCESS (GetKernelInfo, (this, CL_KERNEL_FUNCTION_NAME, size, value, 0));
1909 int i, n = 1;
1910 EXTEND (SP, n);
1911 for (i = 0; i < n; ++i)
1912 PUSHs (sv_2mortal (newSVpv (value, 0)));
1913
1914void
1915num_args (OpenCL::Kernel this)
1916 PPCODE:
1917 cl_uint value [1];
1918 NEED_SUCCESS (GetKernelInfo, (this, CL_KERNEL_NUM_ARGS, sizeof (value), value, 0));
1919 EXTEND (SP, 1);
1920 const int i = 0;
1921 PUSHs (sv_2mortal (newSVuv (value [i])));
1922
1923void
1924reference_count (OpenCL::Kernel this)
1925 PPCODE:
1926 cl_uint value [1];
1927 NEED_SUCCESS (GetKernelInfo, (this, CL_KERNEL_REFERENCE_COUNT, sizeof (value), value, 0));
1928 EXTEND (SP, 1);
1929 const int i = 0;
1930 PUSHs (sv_2mortal (newSVuv (value [i])));
1931
1932void
1933context (OpenCL::Kernel this)
1934 PPCODE:
1935 cl_context value [1];
1936 NEED_SUCCESS (GetKernelInfo, (this, CL_KERNEL_CONTEXT, sizeof (value), value, 0));
1937 EXTEND (SP, 1);
1938 const int i = 0;
1939 {
1940 NEED_SUCCESS (RetainContext, (value [i]));
1941 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
1942 }
1943
1944void
1945program (OpenCL::Kernel this)
1946 PPCODE:
1947 cl_program value [1];
1948 NEED_SUCCESS (GetKernelInfo, (this, CL_KERNEL_PROGRAM, sizeof (value), value, 0));
1949 EXTEND (SP, 1);
1950 const int i = 0;
1951 {
1952 NEED_SUCCESS (RetainProgram, (value [i]));
1953 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Program", value [i]));
1954 }
1955
1956#END:kernel
1957
1958void
1959work_group_info (OpenCL::Kernel this, OpenCL::Device device, cl_kernel_work_group_info name)
681 CODE: 1960 PPCODE:
682 clSetKernelArg (this, idx, sizeof (value), &value); 1961 size_t size;
1962 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, name, 0, 0, &size));
1963 SV *sv = sv_2mortal (newSV (size));
1964 SvUPGRADE (sv, SVt_PV);
1965 SvPOK_only (sv);
1966 SvCUR_set (sv, size);
1967 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, name, size, SvPVX (sv), 0));
1968 XPUSHs (sv);
683 1969
684void 1970#BEGIN:kernel_work_group
685set_uchar (OpenCL::Kernel this, cl_uint idx, cl_uchar value)
686 CODE:
687 clSetKernelArg (this, idx, sizeof (value), &value);
688 1971
689void 1972void
690set_short (OpenCL::Kernel this, cl_uint idx, cl_short value) 1973work_group_size (OpenCL::Kernel this, OpenCL::Device device)
691 CODE: 1974 PPCODE:
692 clSetKernelArg (this, idx, sizeof (value), &value); 1975 size_t value [1];
1976 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (value), value, 0));
1977 EXTEND (SP, 1);
1978 const int i = 0;
1979 PUSHs (sv_2mortal (newSVuv (value [i])));
693 1980
694void 1981void
695set_ushort (OpenCL::Kernel this, cl_uint idx, cl_ushort value) 1982compile_work_group_size (OpenCL::Kernel this, OpenCL::Device device)
696 CODE: 1983 PPCODE:
697 clSetKernelArg (this, idx, sizeof (value), &value); 1984 size_t size;
1985 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, 0, 0, &size));
1986 size_t *value = tmpbuf (size);
1987 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, size, value, 0));
1988 int i, n = size / sizeof (value [0]);
1989 EXTEND (SP, n);
1990 for (i = 0; i < n; ++i)
1991 PUSHs (sv_2mortal (newSVuv (value [i])));
698 1992
699void 1993void
700set_int (OpenCL::Kernel this, cl_uint idx, cl_int value) 1994local_mem_size (OpenCL::Kernel this, OpenCL::Device device)
701 CODE: 1995 PPCODE:
702 clSetKernelArg (this, idx, sizeof (value), &value); 1996 cl_ulong value [1];
1997 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, CL_KERNEL_LOCAL_MEM_SIZE, sizeof (value), value, 0));
1998 EXTEND (SP, 1);
1999 const int i = 0;
2000 PUSHs (sv_2mortal (newSVuv (value [i])));
703 2001
704void 2002void
705set_uint (OpenCL::Kernel this, cl_uint idx, cl_uint value) 2003preferred_work_group_size_multiple (OpenCL::Kernel this, OpenCL::Device device)
706 CODE: 2004 PPCODE:
707 clSetKernelArg (this, idx, sizeof (value), &value); 2005 size_t value [1];
2006 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, sizeof (value), value, 0));
2007 EXTEND (SP, 1);
2008 const int i = 0;
2009 PUSHs (sv_2mortal (newSVuv (value [i])));
708 2010
709void 2011void
710set_long (OpenCL::Kernel this, cl_uint idx, cl_long value) 2012private_mem_size (OpenCL::Kernel this, OpenCL::Device device)
711 CODE: 2013 PPCODE:
712 clSetKernelArg (this, idx, sizeof (value), &value); 2014 cl_ulong value [1];
2015 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, CL_KERNEL_PRIVATE_MEM_SIZE, sizeof (value), value, 0));
2016 EXTEND (SP, 1);
2017 const int i = 0;
2018 PUSHs (sv_2mortal (newSVuv (value [i])));
713 2019
714void 2020#END:kernel_work_group
715set_ulong (OpenCL::Kernel this, cl_uint idx, cl_ulong value)
716 CODE:
717 clSetKernelArg (this, idx, sizeof (value), &value);
718
719void
720set_half (OpenCL::Kernel this, cl_uint idx, cl_half value)
721 CODE:
722 clSetKernelArg (this, idx, sizeof (value), &value);
723
724void
725set_float (OpenCL::Kernel this, cl_uint idx, cl_float value)
726 CODE:
727 clSetKernelArg (this, idx, sizeof (value), &value);
728
729void
730set_memory (OpenCL::Kernel this, cl_uint idx, OpenCL::Memory_ornull value)
731 CODE:
732 clSetKernelArg (this, idx, sizeof (value), &value);
733
734void
735set_buffer (OpenCL::Kernel this, cl_uint idx, OpenCL::Buffer_ornull value)
736 CODE:
737 clSetKernelArg (this, idx, sizeof (value), &value);
738
739void
740set_image2d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image2D_ornull value)
741 CODE:
742 clSetKernelArg (this, idx, sizeof (value), &value);
743
744void
745set_image3d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image3D_ornull value)
746 CODE:
747 clSetKernelArg (this, idx, sizeof (value), &value);
748
749void
750set_sampler (OpenCL::Kernel this, cl_uint idx, OpenCL::Sampler value)
751 CODE:
752 clSetKernelArg (this, idx, sizeof (value), &value);
753
754void
755set_event (OpenCL::Kernel this, cl_uint idx, OpenCL::Event value)
756 CODE:
757 clSetKernelArg (this, idx, sizeof (value), &value);
758 2021
759MODULE = OpenCL PACKAGE = OpenCL::Event 2022MODULE = OpenCL PACKAGE = OpenCL::Event
760 2023
761void 2024void
762DESTROY (OpenCL::Event this) 2025DESTROY (OpenCL::Event this)
763 CODE: 2026 CODE:
764 clReleaseEvent (this); 2027 clReleaseEvent (this);
765 2028
766void 2029void
2030wait (OpenCL::Event this)
2031 CODE:
2032 clWaitForEvents (1, &this);
2033
2034void
767info (OpenCL::Event this, cl_event_info name) 2035info (OpenCL::Event this, cl_event_info name)
768 PPCODE: 2036 PPCODE:
769 INFO (Event) 2037 INFO (Event)
770 2038
2039#BEGIN:event
2040
771void 2041void
2042command_queue (OpenCL::Event this)
2043 PPCODE:
2044 cl_command_queue value [1];
2045 NEED_SUCCESS (GetEventInfo, (this, CL_EVENT_COMMAND_QUEUE, sizeof (value), value, 0));
2046 EXTEND (SP, 1);
2047 const int i = 0;
2048 {
2049 NEED_SUCCESS (RetainCommandQueue, (value [i]));
2050 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Queue", value [i]));
2051 }
2052
2053void
2054command_type (OpenCL::Event this)
2055 PPCODE:
2056 cl_command_type value [1];
2057 NEED_SUCCESS (GetEventInfo, (this, CL_EVENT_COMMAND_TYPE, sizeof (value), value, 0));
2058 EXTEND (SP, 1);
2059 const int i = 0;
2060 PUSHs (sv_2mortal (newSVuv (value [i])));
2061
2062void
2063reference_count (OpenCL::Event this)
2064 PPCODE:
2065 cl_uint value [1];
2066 NEED_SUCCESS (GetEventInfo, (this, CL_EVENT_REFERENCE_COUNT, sizeof (value), value, 0));
2067 EXTEND (SP, 1);
2068 const int i = 0;
2069 PUSHs (sv_2mortal (newSVuv (value [i])));
2070
2071void
2072command_execution_status (OpenCL::Event this)
2073 PPCODE:
2074 cl_uint value [1];
2075 NEED_SUCCESS (GetEventInfo, (this, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof (value), value, 0));
2076 EXTEND (SP, 1);
2077 const int i = 0;
2078 PUSHs (sv_2mortal (newSVuv (value [i])));
2079
2080void
772wait (OpenCL::Event this) 2081context (OpenCL::Event this)
2082 PPCODE:
2083 cl_context value [1];
2084 NEED_SUCCESS (GetEventInfo, (this, CL_EVENT_CONTEXT, sizeof (value), value, 0));
2085 EXTEND (SP, 1);
2086 const int i = 0;
2087 {
2088 NEED_SUCCESS (RetainContext, (value [i]));
2089 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
2090 }
2091
2092#END:event
2093
2094void
2095profiling_info (OpenCL::Event this, cl_profiling_info name)
773 CODE: 2096 PPCODE:
774 clWaitForEvents (1, &this); 2097 INFO (EventProfiling)
775 2098
2099#BEGIN:profiling
2100
2101void
2102profiling_command_queued (OpenCL::Event this)
2103 PPCODE:
2104 cl_ulong value [1];
2105 NEED_SUCCESS (GetEventProfilingInfo, (this, CL_PROFILING_COMMAND_QUEUED, sizeof (value), value, 0));
2106 EXTEND (SP, 1);
2107 const int i = 0;
2108 PUSHs (sv_2mortal (newSVuv (value [i])));
2109
2110void
2111profiling_command_submit (OpenCL::Event this)
2112 PPCODE:
2113 cl_ulong value [1];
2114 NEED_SUCCESS (GetEventProfilingInfo, (this, CL_PROFILING_COMMAND_SUBMIT, sizeof (value), value, 0));
2115 EXTEND (SP, 1);
2116 const int i = 0;
2117 PUSHs (sv_2mortal (newSVuv (value [i])));
2118
2119void
2120profiling_command_start (OpenCL::Event this)
2121 PPCODE:
2122 cl_ulong value [1];
2123 NEED_SUCCESS (GetEventProfilingInfo, (this, CL_PROFILING_COMMAND_START, sizeof (value), value, 0));
2124 EXTEND (SP, 1);
2125 const int i = 0;
2126 PUSHs (sv_2mortal (newSVuv (value [i])));
2127
2128void
2129profiling_command_end (OpenCL::Event this)
2130 PPCODE:
2131 cl_ulong value [1];
2132 NEED_SUCCESS (GetEventProfilingInfo, (this, CL_PROFILING_COMMAND_END, sizeof (value), value, 0));
2133 EXTEND (SP, 1);
2134 const int i = 0;
2135 PUSHs (sv_2mortal (newSVuv (value [i])));
2136
2137#END:profiling
2138
2139MODULE = OpenCL PACKAGE = OpenCL::UserEvent
2140
2141void
2142set_status (OpenCL::UserEvent this, cl_int execution_status)
2143 CODE:
2144 clSetUserEventStatus (this, execution_status);
2145

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines