ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/OpenCL/OpenCL.xs
Revision: 1.21
Committed: Mon Apr 16 06:39:54 2012 UTC (12 years, 1 month ago) by root
Branch: MAIN
CVS Tags: rel-0_92
Changes since 1.20: +3 -5 lines
Log Message:
0.92

File Contents

# User Rev Content
1 root 1.1 #include "EXTERN.h"
2     #include "perl.h"
3     #include "XSUB.h"
4    
5 root 1.19 #ifdef __APPLE__
6     #include <OpenCL/opencl.h>
7     #else
8     #include <CL/opencl.h>
9     #endif
10 root 1.1
11 root 1.16 typedef cl_platform_id OpenCL__Platform;
12     typedef cl_device_id OpenCL__Device;
13     typedef cl_context OpenCL__Context;
14     typedef cl_command_queue OpenCL__Queue;
15     typedef cl_mem OpenCL__Memory;
16     typedef cl_mem OpenCL__Buffer;
17 root 1.18 typedef cl_mem OpenCL__BufferObj;
18 root 1.16 typedef cl_mem OpenCL__Image;
19     typedef cl_mem OpenCL__Image2D;
20     typedef cl_mem OpenCL__Image3D;
21     typedef cl_mem OpenCL__Memory_ornull;
22     typedef cl_mem OpenCL__Buffer_ornull;
23     typedef cl_mem OpenCL__Image_ornull;
24     typedef cl_mem OpenCL__Image2D_ornull;
25     typedef cl_mem OpenCL__Image3D_ornull;
26     typedef cl_sampler OpenCL__Sampler;
27     typedef cl_program OpenCL__Program;
28     typedef cl_kernel OpenCL__Kernel;
29     typedef cl_event OpenCL__Event;
30     typedef cl_event OpenCL__UserEvent;
31 root 1.5
32 root 1.7 typedef SV *FUTURE;
33    
34 root 1.5 /*****************************************************************************/
35    
36     /* up to two temporary buffers */
37     static void *
38     tmpbuf (size_t size)
39     {
40     static int idx;
41     static void *buf [2];
42     static size_t len [2];
43    
44     idx ^= 1;
45    
46     if (len [idx] < size)
47     {
48     free (buf [idx]);
49     len [idx] = ((size + 31) & ~4095) + 4096 - 32;
50     buf [idx] = malloc (len [idx]);
51     }
52    
53     return buf [idx];
54     }
55    
56     /*****************************************************************************/
57 root 1.1
58 root 1.3 typedef struct
59     {
60 root 1.1 IV iv;
61     const char *name;
62 root 1.3 #define const_iv(name) { (IV)CL_ ## name, # name },
63     } ivstr;
64 root 1.1
65     static const char *
66 root 1.3 iv2str (IV value, const ivstr *base, int count, const char *fallback)
67 root 1.1 {
68     int i;
69 root 1.3 static char strbuf [32];
70    
71     for (i = count; i--; )
72     if (base [i].iv == value)
73     return base [i].name;
74    
75     snprintf (strbuf, sizeof (strbuf), fallback, (int)value);
76    
77     return strbuf;
78     }
79    
80     static const char *
81     enum2str (cl_uint value)
82     {
83     static const ivstr enumstr[] = {
84     #include "enumstr.h"
85     };
86 root 1.1
87 root 1.3 return iv2str (value, enumstr, sizeof (enumstr) / sizeof (enumstr [0]), "ENUM(0x%04x)");
88     }
89 root 1.1
90 root 1.3 static const char *
91     err2str (cl_int err)
92     {
93     static const ivstr errstr[] = {
94     #include "errstr.h"
95     };
96 root 1.1
97 root 1.3 return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)");
98 root 1.1 }
99    
100 root 1.5 /*****************************************************************************/
101    
102 root 1.8 static cl_int res;
103 root 1.5
104 root 1.8 #define FAIL(name) \
105     croak ("cl" # name ": %s", err2str (res));
106 root 1.1
107     #define NEED_SUCCESS(name,args) \
108     do { \
109 root 1.8 res = cl ## name args; \
110 root 1.1 \
111     if (res) \
112 root 1.8 FAIL (name); \
113 root 1.1 } while (0)
114    
115 root 1.8 #define NEED_SUCCESS_ARG(retdecl, name, args) \
116     retdecl = cl ## name args; \
117     if (res) \
118     FAIL (name);
119    
120 root 1.5 /*****************************************************************************/
121    
122 root 1.2 #define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr)
123     #define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr))
124    
125 root 1.5 static void *
126     SvPTROBJ (const char *func, const char *svname, SV *sv, const char *pkg)
127     {
128     if (SvROK (sv) && sv_derived_from (sv, pkg))
129     return (void *)SvIV (SvRV (sv));
130    
131     croak ("%s: %s is not of type %s", func, svname, pkg);
132     }
133    
134     /*****************************************************************************/
135    
136 root 1.11 static size_t
137     img_row_pitch (cl_mem img)
138     {
139     size_t res;
140     clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0);
141     return res;
142     }
143    
144 root 1.5 static cl_event *
145     event_list (SV **items, int count)
146     {
147 root 1.20 if (!count)
148     return 0;
149    
150 root 1.5 cl_event *list = tmpbuf (sizeof (cl_event) * count);
151    
152     while (count--)
153     list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event");
154    
155     return list;
156     }
157    
158     #define EVENT_LIST(items,count) \
159     cl_uint event_list_count = (count); \
160     cl_event *event_list_ptr = event_list (&ST (items), event_list_count)
161 root 1.2
162     #define INFO(class) \
163     { \
164     size_t size; \
165     NEED_SUCCESS (Get ## class ## Info, (this, name, 0, 0, &size)); \
166 root 1.10 SV *sv = sv_2mortal (newSV (size)); \
167 root 1.2 SvUPGRADE (sv, SVt_PV); \
168     SvPOK_only (sv); \
169     SvCUR_set (sv, size); \
170     NEED_SUCCESS (Get ## class ## Info, (this, name, size, SvPVX (sv), 0)); \
171     XPUSHs (sv); \
172     }
173    
174 root 1.1 MODULE = OpenCL PACKAGE = OpenCL
175    
176 root 1.2 PROTOTYPES: ENABLE
177    
178 root 1.1 BOOT:
179     {
180     HV *stash = gv_stashpv ("OpenCL", 1);
181 root 1.3 static const ivstr *civ, const_iv[] = {
182 root 1.5 { sizeof (cl_char ), "SIZEOF_CHAR" },
183     { sizeof (cl_uchar ), "SIZEOF_UCHAR" },
184     { sizeof (cl_short ), "SIZEOF_SHORT" },
185     { sizeof (cl_ushort), "SIZEOF_USHORT" },
186     { sizeof (cl_int ), "SIZEOF_INT" },
187     { sizeof (cl_uint ), "SIZEOF_UINT" },
188     { sizeof (cl_long ), "SIZEOF_LONG" },
189     { sizeof (cl_ulong ), "SIZEOF_ULONG" },
190     { sizeof (cl_half ), "SIZEOF_HALF" },
191     { sizeof (cl_float ), "SIZEOF_FLOAT" },
192     { sizeof (cl_double), "SIZEOF_DOUBLE" },
193 root 1.1 #include "constiv.h"
194     };
195     for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
196     newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
197     }
198    
199 root 1.5 cl_int
200     errno ()
201     CODE:
202 root 1.8 errno = res;
203 root 1.5
204 root 1.3 const char *
205     err2str (cl_int err)
206    
207     const char *
208     enum2str (cl_uint value)
209    
210 root 1.1 void
211     platforms ()
212     PPCODE:
213     cl_platform_id *list;
214     cl_uint count;
215     int i;
216    
217 root 1.2 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count));
218 root 1.4 list = tmpbuf (sizeof (*list) * count);
219 root 1.2 NEED_SUCCESS (GetPlatformIDs, (count, list, 0));
220 root 1.1
221     EXTEND (SP, count);
222     for (i = 0; i < count; ++i)
223 root 1.2 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i]));
224 root 1.1
225     void
226 root 1.7 context_from_type (FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
227 root 1.1 PPCODE:
228 root 1.8 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (0, type, 0, 0, &res));
229     XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
230 root 1.1
231 root 1.8 void
232     context (FUTURE properties, FUTURE devices, FUTURE notify = 0)
233     PPCODE:
234     /* der Gipfel der Kunst */
235 root 1.1
236 root 1.2 void
237     wait_for_events (...)
238     CODE:
239     EVENT_LIST (0, items);
240     NEED_SUCCESS (WaitForEvents, (event_list_count, event_list_ptr));
241    
242     PROTOTYPES: DISABLE
243    
244 root 1.1 MODULE = OpenCL PACKAGE = OpenCL::Platform
245    
246     void
247     info (OpenCL::Platform this, cl_platform_info name)
248     PPCODE:
249 root 1.2 INFO (Platform)
250 root 1.1
251 root 1.13 #BEGIN:platform
252    
253     void
254     profile (OpenCL::Platform this)
255 root 1.16 ALIAS:
256     profile = CL_PLATFORM_PROFILE
257     version = CL_PLATFORM_VERSION
258     name = CL_PLATFORM_NAME
259     vendor = CL_PLATFORM_VENDOR
260     extensions = CL_PLATFORM_EXTENSIONS
261 root 1.14 PPCODE:
262     size_t size;
263 root 1.16 NEED_SUCCESS (GetPlatformInfo, (this, ix, 0, 0, &size));
264 root 1.14 char *value = tmpbuf (size);
265 root 1.16 NEED_SUCCESS (GetPlatformInfo, (this, ix, size, value, 0));
266     EXTEND (SP, 1);
267     const int i = 0;
268 root 1.14 PUSHs (sv_2mortal (newSVpv (value, 0)));
269 root 1.13
270     #END:platform
271    
272 root 1.1 void
273     devices (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_ALL)
274     PPCODE:
275     cl_device_id *list;
276     cl_uint count;
277     int i;
278    
279 root 1.2 NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count));
280 root 1.4 list = tmpbuf (sizeof (*list) * count);
281 root 1.2 NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0));
282 root 1.1
283     EXTEND (SP, count);
284     for (i = 0; i < count; ++i)
285     PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i]));
286    
287     void
288 root 1.8 context (OpenCL::Platform this, FUTURE properties, SV *devices, FUTURE notify = 0)
289     PPCODE:
290     if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV)
291     croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call");
292    
293 root 1.11 AV *av = (AV *)SvRV (devices);
294 root 1.8 cl_uint num_devices = av_len (av) + 1;
295     cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices);
296     int i;
297    
298     for (i = num_devices; i--; )
299     device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device");
300    
301     NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (0, num_devices, device_list, 0, 0, &res));
302     XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
303    
304     void
305 root 1.7 context_from_type (OpenCL::Platform this, FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
306 root 1.1 PPCODE:
307     cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)this, 0 };
308 root 1.8 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res));
309 root 1.2 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
310 root 1.1
311 root 1.16 MODULE = OpenCL PACKAGE = OpenCL::Device
312 root 1.14
313     void
314 root 1.16 info (OpenCL::Device this, cl_device_info name)
315     PPCODE:
316     INFO (Device)
317 root 1.14
318 root 1.16 #BEGIN:device
319 root 1.14
320     void
321 root 1.16 type (OpenCL::Device this)
322 root 1.14 PPCODE:
323 root 1.16 cl_device_type value [1];
324     NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_TYPE, sizeof (value), value, 0));
325     EXTEND (SP, 1);
326     const int i = 0;
327     PUSHs (sv_2mortal (newSViv (value [i])));
328 root 1.14
329     void
330 root 1.16 vendor_id (OpenCL::Device this)
331     ALIAS:
332     vendor_id = CL_DEVICE_VENDOR_ID
333     max_compute_units = CL_DEVICE_MAX_COMPUTE_UNITS
334     max_work_item_dimensions = CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
335     preferred_vector_width_char = CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR
336     preferred_vector_width_short = CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT
337     preferred_vector_width_int = CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT
338     preferred_vector_width_long = CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG
339     preferred_vector_width_float = CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT
340     preferred_vector_width_double = CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE
341     max_clock_frequency = CL_DEVICE_MAX_CLOCK_FREQUENCY
342     max_read_image_args = CL_DEVICE_MAX_READ_IMAGE_ARGS
343     max_write_image_args = CL_DEVICE_MAX_WRITE_IMAGE_ARGS
344     image_support = CL_DEVICE_IMAGE_SUPPORT
345     max_samplers = CL_DEVICE_MAX_SAMPLERS
346     mem_base_addr_align = CL_DEVICE_MEM_BASE_ADDR_ALIGN
347     min_data_type_align_size = CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE
348     global_mem_cacheline_size = CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE
349     max_constant_args = CL_DEVICE_MAX_CONSTANT_ARGS
350     preferred_vector_width_half = CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF
351     native_vector_width_char = CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR
352     native_vector_width_short = CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT
353     native_vector_width_int = CL_DEVICE_NATIVE_VECTOR_WIDTH_INT
354     native_vector_width_long = CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG
355     native_vector_width_float = CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT
356     native_vector_width_double = CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE
357     native_vector_width_half = CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF
358     reference_count_ext = CL_DEVICE_REFERENCE_COUNT_EXT
359 root 1.14 PPCODE:
360     cl_uint value [1];
361 root 1.16 NEED_SUCCESS (GetDeviceInfo, (this, ix, sizeof (value), value, 0));
362 root 1.14 EXTEND (SP, 1);
363     const int i = 0;
364     PUSHs (sv_2mortal (newSVuv (value [i])));
365    
366     void
367 root 1.16 max_work_group_size (OpenCL::Device this)
368     ALIAS:
369     max_work_group_size = CL_DEVICE_MAX_WORK_GROUP_SIZE
370     image2d_max_width = CL_DEVICE_IMAGE2D_MAX_WIDTH
371     image2d_max_height = CL_DEVICE_IMAGE2D_MAX_HEIGHT
372     image3d_max_width = CL_DEVICE_IMAGE3D_MAX_WIDTH
373     image3d_max_height = CL_DEVICE_IMAGE3D_MAX_HEIGHT
374     image3d_max_depth = CL_DEVICE_IMAGE3D_MAX_DEPTH
375     max_parameter_size = CL_DEVICE_MAX_PARAMETER_SIZE
376     profiling_timer_resolution = CL_DEVICE_PROFILING_TIMER_RESOLUTION
377 root 1.14 PPCODE:
378 root 1.16 size_t value [1];
379     NEED_SUCCESS (GetDeviceInfo, (this, ix, sizeof (value), value, 0));
380 root 1.14 EXTEND (SP, 1);
381     const int i = 0;
382     PUSHs (sv_2mortal (newSVuv (value [i])));
383    
384     void
385 root 1.16 max_work_item_sizes (OpenCL::Device this)
386 root 1.14 PPCODE:
387 root 1.16 size_t size;
388     NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_WORK_ITEM_SIZES, 0, 0, &size));
389     size_t *value = tmpbuf (size);
390     NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_MAX_WORK_ITEM_SIZES, size, value, 0));
391     int i, n = size / sizeof (*value);
392     EXTEND (SP, n);
393     for (i = 0; i < n; ++i)
394 root 1.14 PUSHs (sv_2mortal (newSVuv (value [i])));
395    
396     void
397 root 1.16 address_bits (OpenCL::Device this)
398 root 1.14 PPCODE:
399 root 1.16 cl_bitfield value [1];
400     NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_ADDRESS_BITS, sizeof (value), value, 0));
401 root 1.14 EXTEND (SP, 1);
402     const int i = 0;
403     PUSHs (sv_2mortal (newSVuv (value [i])));
404    
405     void
406 root 1.16 max_mem_alloc_size (OpenCL::Device this)
407     ALIAS:
408     max_mem_alloc_size = CL_DEVICE_MAX_MEM_ALLOC_SIZE
409     global_mem_cache_size = CL_DEVICE_GLOBAL_MEM_CACHE_SIZE
410     global_mem_size = CL_DEVICE_GLOBAL_MEM_SIZE
411     max_constant_buffer_size = CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE
412     local_mem_size = CL_DEVICE_LOCAL_MEM_SIZE
413 root 1.14 PPCODE:
414 root 1.16 cl_ulong value [1];
415     NEED_SUCCESS (GetDeviceInfo, (this, ix, sizeof (value), value, 0));
416 root 1.14 EXTEND (SP, 1);
417     const int i = 0;
418     PUSHs (sv_2mortal (newSVuv (value [i])));
419    
420     void
421 root 1.16 single_fp_config (OpenCL::Device this)
422     ALIAS:
423     single_fp_config = CL_DEVICE_SINGLE_FP_CONFIG
424     double_fp_config = CL_DEVICE_DOUBLE_FP_CONFIG
425     half_fp_config = CL_DEVICE_HALF_FP_CONFIG
426 root 1.14 PPCODE:
427 root 1.16 cl_device_fp_config value [1];
428     NEED_SUCCESS (GetDeviceInfo, (this, ix, sizeof (value), value, 0));
429 root 1.14 EXTEND (SP, 1);
430     const int i = 0;
431     PUSHs (sv_2mortal (newSVuv (value [i])));
432    
433     void
434 root 1.16 global_mem_cache_type (OpenCL::Device this)
435 root 1.14 PPCODE:
436 root 1.16 cl_device_mem_cache_type value [1];
437     NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, sizeof (value), value, 0));
438 root 1.14 EXTEND (SP, 1);
439     const int i = 0;
440     PUSHs (sv_2mortal (newSVuv (value [i])));
441    
442     void
443 root 1.16 local_mem_type (OpenCL::Device this)
444 root 1.14 PPCODE:
445 root 1.16 cl_device_local_mem_type value [1];
446     NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_LOCAL_MEM_TYPE, sizeof (value), value, 0));
447 root 1.14 EXTEND (SP, 1);
448     const int i = 0;
449     PUSHs (sv_2mortal (newSVuv (value [i])));
450    
451     void
452 root 1.16 error_correction_support (OpenCL::Device this)
453     ALIAS:
454     error_correction_support = CL_DEVICE_ERROR_CORRECTION_SUPPORT
455     endian_little = CL_DEVICE_ENDIAN_LITTLE
456     available = CL_DEVICE_AVAILABLE
457     compiler_available = CL_DEVICE_COMPILER_AVAILABLE
458     host_unified_memory = CL_DEVICE_HOST_UNIFIED_MEMORY
459 root 1.14 PPCODE:
460 root 1.16 cl_bool value [1];
461     NEED_SUCCESS (GetDeviceInfo, (this, ix, sizeof (value), value, 0));
462 root 1.14 EXTEND (SP, 1);
463     const int i = 0;
464 root 1.16 PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no));
465 root 1.14
466     void
467 root 1.16 execution_capabilities (OpenCL::Device this)
468 root 1.14 PPCODE:
469 root 1.16 cl_device_exec_capabilities value [1];
470     NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_EXECUTION_CAPABILITIES, sizeof (value), value, 0));
471 root 1.14 EXTEND (SP, 1);
472     const int i = 0;
473     PUSHs (sv_2mortal (newSVuv (value [i])));
474    
475     void
476 root 1.16 properties (OpenCL::Device this)
477 root 1.14 PPCODE:
478 root 1.16 cl_command_queue_properties value [1];
479     NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_QUEUE_PROPERTIES, sizeof (value), value, 0));
480 root 1.14 EXTEND (SP, 1);
481     const int i = 0;
482 root 1.16 PUSHs (sv_2mortal (newSViv (value [i])));
483 root 1.14
484     void
485 root 1.16 platform (OpenCL::Device this)
486 root 1.14 PPCODE:
487 root 1.16 cl_platform_id value [1];
488     NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PLATFORM, sizeof (value), value, 0));
489 root 1.14 EXTEND (SP, 1);
490     const int i = 0;
491     {
492 root 1.16 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", value [i]));
493 root 1.14 }
494    
495     void
496 root 1.16 name (OpenCL::Device this)
497     ALIAS:
498     name = CL_DEVICE_NAME
499     vendor = CL_DEVICE_VENDOR
500     driver_version = CL_DRIVER_VERSION
501     profile = CL_DEVICE_PROFILE
502     version = CL_DEVICE_VERSION
503     extensions = CL_DEVICE_EXTENSIONS
504 root 1.14 PPCODE:
505     size_t size;
506 root 1.16 NEED_SUCCESS (GetDeviceInfo, (this, ix, 0, 0, &size));
507     char *value = tmpbuf (size);
508     NEED_SUCCESS (GetDeviceInfo, (this, ix, size, value, 0));
509     EXTEND (SP, 1);
510     const int i = 0;
511     PUSHs (sv_2mortal (newSVpv (value, 0)));
512 root 1.14
513     void
514 root 1.16 parent_device_ext (OpenCL::Device this)
515 root 1.14 PPCODE:
516 root 1.16 cl_device_id value [1];
517     NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_PARENT_DEVICE_EXT, sizeof (value), value, 0));
518 root 1.14 EXTEND (SP, 1);
519     const int i = 0;
520 root 1.16 {
521     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i]));
522     }
523 root 1.14
524     void
525 root 1.16 partition_types_ext (OpenCL::Device this)
526     ALIAS:
527     partition_types_ext = CL_DEVICE_PARTITION_TYPES_EXT
528     affinity_domains_ext = CL_DEVICE_AFFINITY_DOMAINS_EXT
529     partition_style_ext = CL_DEVICE_PARTITION_STYLE_EXT
530 root 1.14 PPCODE:
531     size_t size;
532 root 1.16 NEED_SUCCESS (GetDeviceInfo, (this, ix, 0, 0, &size));
533 root 1.14 cl_device_partition_property_ext *value = tmpbuf (size);
534 root 1.16 NEED_SUCCESS (GetDeviceInfo, (this, ix, size, value, 0));
535 root 1.15 int i, n = size / sizeof (*value);
536 root 1.14 EXTEND (SP, n);
537     for (i = 0; i < n; ++i)
538     PUSHs (sv_2mortal (newSVuv (value [i])));
539    
540     #END:device
541    
542 root 1.1 MODULE = OpenCL PACKAGE = OpenCL::Context
543    
544     void
545     DESTROY (OpenCL::Context context)
546     CODE:
547     clReleaseContext (context);
548    
549     void
550     info (OpenCL::Context this, cl_context_info name)
551     PPCODE:
552 root 1.2 INFO (Context)
553    
554     void
555 root 1.7 queue (OpenCL::Context this, OpenCL::Device device, cl_command_queue_properties properties = 0)
556 root 1.2 PPCODE:
557 root 1.8 NEED_SUCCESS_ARG (cl_command_queue queue, CreateCommandQueue, (this, device, properties, &res));
558 root 1.2 XPUSH_NEW_OBJ ("OpenCL::Queue", queue);
559    
560     void
561 root 1.5 user_event (OpenCL::Context this)
562     PPCODE:
563 root 1.8 NEED_SUCCESS_ARG (cl_event ev, CreateUserEvent, (this, &res));
564 root 1.5 XPUSH_NEW_OBJ ("OpenCL::UserEvent", ev);
565    
566     void
567 root 1.2 buffer (OpenCL::Context this, cl_mem_flags flags, size_t len)
568     PPCODE:
569 root 1.3 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
570     croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?");
571    
572 root 1.8 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, 0, &res));
573 root 1.18 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
574 root 1.2
575     void
576     buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data)
577     PPCODE:
578     STRLEN len;
579 root 1.21 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
580 root 1.3 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
581     croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
582 root 1.8 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, ptr, &res));
583 root 1.18 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
584 root 1.3
585     void
586 root 1.12 image2d (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)
587 root 1.3 PPCODE:
588     STRLEN len;
589 root 1.21 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
590 root 1.3 const cl_image_format format = { channel_order, channel_type };
591 root 1.10 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (this, flags, &format, width, height, row_pitch, ptr, &res));
592 root 1.3 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
593    
594     void
595 root 1.12 image3d (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)
596 root 1.3 PPCODE:
597     STRLEN len;
598 root 1.21 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
599 root 1.3 const cl_image_format format = { channel_order, channel_type };
600 root 1.10 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (this, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
601 root 1.3 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
602    
603     void
604     supported_image_formats (OpenCL::Context this, cl_mem_flags flags, cl_mem_object_type image_type)
605     PPCODE:
606     {
607     cl_uint count;
608     cl_image_format *list;
609     int i;
610    
611     NEED_SUCCESS (GetSupportedImageFormats, (this, flags, image_type, 0, 0, &count));
612     Newx (list, count, cl_image_format);
613     NEED_SUCCESS (GetSupportedImageFormats, (this, flags, image_type, count, list, 0));
614    
615     EXTEND (SP, count);
616     for (i = 0; i < count; ++i)
617     {
618     AV *av = newAV ();
619     av_store (av, 1, newSVuv (list [i].image_channel_data_type));
620     av_store (av, 0, newSVuv (list [i].image_channel_order));
621     PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
622     }
623 root 1.2 }
624    
625     void
626     sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode)
627     PPCODE:
628 root 1.8 NEED_SUCCESS_ARG (cl_sampler sampler, CreateSampler, (this, normalized_coords, addressing_mode, filter_mode, &res));
629 root 1.2 XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler);
630 root 1.1
631     void
632 root 1.2 program_with_source (OpenCL::Context this, SV *program)
633 root 1.1 PPCODE:
634 root 1.2 STRLEN len;
635     size_t len2;
636     const char *ptr = SvPVbyte (program, len);
637    
638     len2 = len;
639 root 1.8 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (this, 1, &ptr, &len2, &res));
640 root 1.2 XPUSH_NEW_OBJ ("OpenCL::Program", prog);
641 root 1.1
642 root 1.13 #BEGIN:context
643    
644 root 1.14 void
645     reference_count (OpenCL::Context this)
646 root 1.16 ALIAS:
647     reference_count = CL_CONTEXT_REFERENCE_COUNT
648     num_devices = CL_CONTEXT_NUM_DEVICES
649 root 1.14 PPCODE:
650     cl_uint value [1];
651 root 1.16 NEED_SUCCESS (GetContextInfo, (this, ix, sizeof (value), value, 0));
652 root 1.14 EXTEND (SP, 1);
653     const int i = 0;
654     PUSHs (sv_2mortal (newSVuv (value [i])));
655    
656     void
657     devices (OpenCL::Context this)
658     PPCODE:
659     size_t size;
660     NEED_SUCCESS (GetContextInfo, (this, CL_CONTEXT_DEVICES, 0, 0, &size));
661     cl_device_id *value = tmpbuf (size);
662     NEED_SUCCESS (GetContextInfo, (this, CL_CONTEXT_DEVICES, size, value, 0));
663 root 1.15 int i, n = size / sizeof (*value);
664 root 1.14 EXTEND (SP, n);
665     for (i = 0; i < n; ++i)
666     {
667     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i]));
668     }
669    
670     void
671     properties (OpenCL::Context this)
672     PPCODE:
673     size_t size;
674     NEED_SUCCESS (GetContextInfo, (this, CL_CONTEXT_PROPERTIES, 0, 0, &size));
675     cl_context_properties *value = tmpbuf (size);
676     NEED_SUCCESS (GetContextInfo, (this, CL_CONTEXT_PROPERTIES, size, value, 0));
677 root 1.15 int i, n = size / sizeof (*value);
678 root 1.14 EXTEND (SP, n);
679     for (i = 0; i < n; ++i)
680     PUSHs (sv_2mortal (newSVuv ((UV)value [i])));
681    
682 root 1.13 #END:context
683    
684 root 1.1 MODULE = OpenCL PACKAGE = OpenCL::Queue
685    
686     void
687     DESTROY (OpenCL::Queue this)
688     CODE:
689     clReleaseCommandQueue (this);
690    
691     void
692 root 1.3 enqueue_read_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...)
693 root 1.2 PPCODE:
694     cl_event ev = 0;
695     EVENT_LIST (6, items - 6);
696    
697     SvUPGRADE (data, SVt_PV);
698     SvGROW (data, len);
699     SvPOK_only (data);
700     SvCUR_set (data, len);
701     NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
702    
703     if (ev)
704     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
705    
706     void
707 root 1.3 enqueue_write_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...)
708 root 1.2 PPCODE:
709     cl_event ev = 0;
710     STRLEN len;
711     char *ptr = SvPVbyte (data, len);
712     EVENT_LIST (5, items - 5);
713    
714     NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
715    
716     if (ev)
717     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
718    
719     void
720 root 1.3 enqueue_copy_buffer (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...)
721 root 1.2 PPCODE:
722     cl_event ev = 0;
723     EVENT_LIST (6, items - 6);
724    
725     NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
726    
727     if (ev)
728     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
729    
730 root 1.3 void
731 root 1.17 enqueue_read_buffer_rect (OpenCL::Queue this, 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, ...)
732     PPCODE:
733     cl_event ev = 0;
734     const size_t buf_origin [3] = { buf_x , buf_y , buf_z };
735     const size_t host_origin[3] = { host_x, host_y, host_z };
736     const size_t region[3] = { width, height, depth };
737     EVENT_LIST (17, items - 17);
738    
739     if (!buf_row_pitch)
740     buf_row_pitch = region [0];
741    
742     if (!buf_slice_pitch)
743     buf_slice_pitch = region [1] * buf_row_pitch;
744    
745     if (!host_row_pitch)
746     host_row_pitch = region [0];
747    
748     if (!host_slice_pitch)
749     host_slice_pitch = region [1] * host_row_pitch;
750    
751     size_t len = host_row_pitch * host_slice_pitch * region [2];
752    
753     SvUPGRADE (data, SVt_PV);
754     SvGROW (data, len);
755     SvPOK_only (data);
756     SvCUR_set (data, len);
757     NEED_SUCCESS (EnqueueReadBufferRect, (this, 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));
758    
759     if (ev)
760     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
761    
762     void
763     enqueue_write_buffer_rect (OpenCL::Queue this, 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, ...)
764     PPCODE:
765     cl_event ev = 0;
766     const size_t buf_origin [3] = { buf_x , buf_y , buf_z };
767     const size_t host_origin[3] = { host_x, host_y, host_z };
768     const size_t region[3] = { width, height, depth };
769     STRLEN len;
770     char *ptr = SvPVbyte (data, len);
771     EVENT_LIST (17, items - 17);
772    
773     if (!buf_row_pitch)
774     buf_row_pitch = region [0];
775    
776     if (!buf_slice_pitch)
777     buf_slice_pitch = region [1] * buf_row_pitch;
778    
779     if (!host_row_pitch)
780     host_row_pitch = region [0];
781    
782     if (!host_slice_pitch)
783     host_slice_pitch = region [1] * host_row_pitch;
784    
785     size_t min_len = host_row_pitch * host_slice_pitch * region [2];
786    
787     if (len < min_len)
788     croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
789    
790     NEED_SUCCESS (EnqueueWriteBufferRect, (this, 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));
791    
792     if (ev)
793     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
794    
795     void
796 root 1.18 enqueue_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, ...)
797     PPCODE:
798     cl_event ev = 0;
799     const size_t src_origin[3] = { src_x, src_y, src_z };
800     const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
801     const size_t region[3] = { width, height, depth };
802     EVENT_LIST (16, items - 16);
803    
804     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));
805    
806     if (ev)
807     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
808    
809     void
810 root 1.3 enqueue_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, ...)
811     PPCODE:
812     cl_event ev = 0;
813     const size_t src_origin[3] = { src_x, src_y, src_z };
814     const size_t region[3] = { width, height, depth };
815 root 1.10 EVENT_LIST (12, items - 12);
816    
817 root 1.11 if (!row_pitch)
818     row_pitch = img_row_pitch (src);
819    
820     if (depth > 1 && !slice_pitch)
821     slice_pitch = row_pitch * height;
822    
823     size_t len = slice_pitch ? slice_pitch * depth : row_pitch * height;
824 root 1.3
825     SvUPGRADE (data, SVt_PV);
826     SvGROW (data, len);
827     SvPOK_only (data);
828     SvCUR_set (data, len);
829     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));
830    
831     if (ev)
832     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
833    
834     void
835 root 1.10 enqueue_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, ...)
836 root 1.3 PPCODE:
837     cl_event ev = 0;
838     const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
839     const size_t region[3] = { width, height, depth };
840     STRLEN len;
841     char *ptr = SvPVbyte (data, len);
842 root 1.10 EVENT_LIST (12, items - 12);
843 root 1.3
844 root 1.11 if (!row_pitch)
845     row_pitch = img_row_pitch (dst);
846    
847     if (depth > 1 && !slice_pitch)
848     slice_pitch = row_pitch * height;
849    
850     size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height;
851    
852     if (len < min_len)
853     croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
854    
855 root 1.3 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));
856    
857     if (ev)
858     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
859    
860     void
861 root 1.18 enqueue_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, ...)
862 root 1.3 PPCODE:
863     cl_event ev = 0;
864     const size_t src_origin[3] = { src_x, src_y, src_z };
865     const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
866     const size_t region[3] = { width, height, depth };
867 root 1.18 EVENT_LIST (12, items - 12);
868 root 1.3
869 root 1.18 NEED_SUCCESS (EnqueueCopyImage, (this, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
870 root 1.3
871     if (ev)
872     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
873    
874     void
875 root 1.18 enqueue_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, ...)
876 root 1.3 PPCODE:
877     cl_event ev = 0;
878 root 1.18 const size_t src_origin[3] = { src_x, src_y, src_z };
879 root 1.3 const size_t region[3] = { width, height, depth };
880     EVENT_LIST (10, items - 10);
881    
882 root 1.18 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
883 root 1.3
884     if (ev)
885     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
886    
887     void
888 root 1.18 enqueue_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, ...)
889 root 1.3 PPCODE:
890     cl_event ev = 0;
891     const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
892     const size_t region[3] = { width, height, depth };
893     EVENT_LIST (10, items - 10);
894    
895 root 1.18 NEED_SUCCESS (EnqueueCopyBufferToImage, (this, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
896 root 1.3
897     if (ev)
898     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
899    
900     void
901     enqueue_task (OpenCL::Queue this, OpenCL::Kernel kernel, ...)
902     PPCODE:
903     cl_event ev = 0;
904     EVENT_LIST (2, items - 2);
905    
906     NEED_SUCCESS (EnqueueTask, (this, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
907    
908     if (ev)
909     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
910    
911 root 1.4 void
912     enqueue_nd_range_kernel (OpenCL::Queue this, OpenCL::Kernel kernel, SV *global_work_offset, SV *global_work_size, SV *local_work_size = &PL_sv_undef, ...)
913     PPCODE:
914     cl_event ev = 0;
915     size_t *gwo = 0, *gws, *lws = 0;
916     int gws_len;
917     size_t *lists;
918     int i;
919 root 1.5 EVENT_LIST (5, items - 5);
920 root 1.4
921     if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV)
922     croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference");
923    
924     gws_len = AvFILLp (SvRV (global_work_size)) + 1;
925    
926     lists = tmpbuf (sizeof (size_t) * 3 * gws_len);
927    
928     gws = lists + gws_len * 0;
929     for (i = 0; i < gws_len; ++i)
930     gws [i] = SvIV (AvARRAY (SvRV (global_work_size))[i]);
931    
932     if (SvOK (global_work_offset))
933     {
934     if (!SvROK (global_work_offset) || SvTYPE (SvRV (global_work_offset)) != SVt_PVAV)
935     croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array reference");
936    
937     if (AvFILLp (SvRV (global_work_size)) + 1 != gws_len)
938     croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array of same size as global_work_size");
939    
940     gwo = lists + gws_len * 1;
941     for (i = 0; i < gws_len; ++i)
942     gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
943     }
944    
945     if (SvOK (local_work_size))
946     {
947     if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV)
948     croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference");
949    
950     if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len)
951     croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
952    
953     lws = lists + gws_len * 2;
954     for (i = 0; i < gws_len; ++i)
955     lws [i] = SvIV (AvARRAY (SvRV (local_work_size))[i]);
956     }
957    
958     NEED_SUCCESS (EnqueueNDRangeKernel, (this, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
959    
960     if (ev)
961     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
962 root 1.3
963 root 1.2 void
964     enqueue_marker (OpenCL::Queue this)
965     PPCODE:
966     cl_event ev;
967     NEED_SUCCESS (EnqueueMarker, (this, &ev));
968     XPUSH_NEW_OBJ ("OpenCL::Event", ev);
969    
970     void
971     enqueue_wait_for_events (OpenCL::Queue this, ...)
972     CODE:
973     EVENT_LIST (1, items - 1);
974     NEED_SUCCESS (EnqueueWaitForEvents, (this, event_list_count, event_list_ptr));
975    
976     void
977     enqueue_barrier (OpenCL::Queue this)
978     CODE:
979     NEED_SUCCESS (EnqueueBarrier, (this));
980    
981 root 1.3 void
982     flush (OpenCL::Queue this)
983     CODE:
984     NEED_SUCCESS (Flush, (this));
985    
986     void
987     finish (OpenCL::Queue this)
988     CODE:
989     NEED_SUCCESS (Finish, (this));
990    
991 root 1.14 void
992     info (OpenCL::Queue this, cl_command_queue_info name)
993     PPCODE:
994     INFO (CommandQueue)
995    
996     #BEGIN:command_queue
997    
998     void
999     context (OpenCL::Queue this)
1000     PPCODE:
1001     cl_context value [1];
1002     NEED_SUCCESS (GetCommandQueueInfo, (this, CL_QUEUE_CONTEXT, sizeof (value), value, 0));
1003     EXTEND (SP, 1);
1004     const int i = 0;
1005     {
1006     NEED_SUCCESS (RetainContext, (value [i]));
1007     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
1008     }
1009    
1010     void
1011     device (OpenCL::Queue this)
1012     PPCODE:
1013     cl_device_id value [1];
1014     NEED_SUCCESS (GetCommandQueueInfo, (this, CL_QUEUE_DEVICE, sizeof (value), value, 0));
1015     EXTEND (SP, 1);
1016     const int i = 0;
1017     {
1018     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i]));
1019     }
1020    
1021     void
1022     reference_count (OpenCL::Queue this)
1023     PPCODE:
1024     cl_uint value [1];
1025     NEED_SUCCESS (GetCommandQueueInfo, (this, CL_QUEUE_REFERENCE_COUNT, sizeof (value), value, 0));
1026     EXTEND (SP, 1);
1027     const int i = 0;
1028     PUSHs (sv_2mortal (newSVuv (value [i])));
1029    
1030     void
1031     properties (OpenCL::Queue this)
1032     PPCODE:
1033     cl_command_queue_properties value [1];
1034     NEED_SUCCESS (GetCommandQueueInfo, (this, CL_QUEUE_PROPERTIES, sizeof (value), value, 0));
1035     EXTEND (SP, 1);
1036     const int i = 0;
1037     PUSHs (sv_2mortal (newSViv (value [i])));
1038    
1039     #END:command_queue
1040    
1041 root 1.2 MODULE = OpenCL PACKAGE = OpenCL::Memory
1042    
1043     void
1044     DESTROY (OpenCL::Memory this)
1045     CODE:
1046     clReleaseMemObject (this);
1047    
1048     void
1049     info (OpenCL::Memory this, cl_mem_info name)
1050     PPCODE:
1051     INFO (MemObject)
1052    
1053 root 1.14 #BEGIN:mem
1054    
1055     void
1056     type (OpenCL::Memory this)
1057     PPCODE:
1058     cl_mem_object_type value [1];
1059     NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_TYPE, sizeof (value), value, 0));
1060     EXTEND (SP, 1);
1061     const int i = 0;
1062     PUSHs (sv_2mortal (newSViv (value [i])));
1063    
1064     void
1065     flags (OpenCL::Memory this)
1066     PPCODE:
1067     cl_mem_flags value [1];
1068     NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_FLAGS, sizeof (value), value, 0));
1069     EXTEND (SP, 1);
1070     const int i = 0;
1071     PUSHs (sv_2mortal (newSViv (value [i])));
1072    
1073     void
1074     size (OpenCL::Memory this)
1075 root 1.16 ALIAS:
1076     size = CL_MEM_SIZE
1077     offset = CL_MEM_OFFSET
1078 root 1.14 PPCODE:
1079     size_t value [1];
1080 root 1.16 NEED_SUCCESS (GetMemObjectInfo, (this, ix, sizeof (value), value, 0));
1081 root 1.14 EXTEND (SP, 1);
1082     const int i = 0;
1083     PUSHs (sv_2mortal (newSVuv (value [i])));
1084    
1085     void
1086     host_ptr (OpenCL::Memory this)
1087     PPCODE:
1088     void * value [1];
1089     NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_HOST_PTR, sizeof (value), value, 0));
1090     EXTEND (SP, 1);
1091     const int i = 0;
1092     PUSHs (sv_2mortal (newSVuv ((IV)(intptr_t)value [i])));
1093    
1094     void
1095     map_count (OpenCL::Memory this)
1096 root 1.16 ALIAS:
1097     map_count = CL_MEM_MAP_COUNT
1098     reference_count = CL_MEM_REFERENCE_COUNT
1099 root 1.14 PPCODE:
1100     cl_uint value [1];
1101 root 1.16 NEED_SUCCESS (GetMemObjectInfo, (this, ix, sizeof (value), value, 0));
1102 root 1.14 EXTEND (SP, 1);
1103     const int i = 0;
1104     PUSHs (sv_2mortal (newSVuv (value [i])));
1105    
1106     void
1107     context (OpenCL::Memory this)
1108     PPCODE:
1109     cl_context value [1];
1110     NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_CONTEXT, sizeof (value), value, 0));
1111     EXTEND (SP, 1);
1112     const int i = 0;
1113     {
1114     NEED_SUCCESS (RetainContext, (value [i]));
1115     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
1116     }
1117    
1118     void
1119     associated_memobject (OpenCL::Memory this)
1120     PPCODE:
1121     cl_mem value [1];
1122     NEED_SUCCESS (GetMemObjectInfo, (this, CL_MEM_ASSOCIATED_MEMOBJECT, sizeof (value), value, 0));
1123     EXTEND (SP, 1);
1124     const int i = 0;
1125     {
1126     NEED_SUCCESS (RetainMemObject, (value [i]));
1127     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i]));
1128     }
1129    
1130     #END:mem
1131    
1132 root 1.18 MODULE = OpenCL PACKAGE = OpenCL::BufferObj
1133    
1134     void
1135     sub_buffer_region (OpenCL::BufferObj this, cl_mem_flags flags, size_t origin, size_t size)
1136     PPCODE:
1137     if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_ALLOC_HOST_PTR))
1138     croak ("clCreateSubBuffer: cannot use/copy/alloc host ptr, doesn't make sense, check your flags!");
1139    
1140     cl_buffer_region crdata = { origin, size };
1141    
1142     NEED_SUCCESS_ARG (cl_mem mem, CreateSubBuffer, (this, flags, CL_BUFFER_CREATE_TYPE_REGION, &crdata, &res));
1143     XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
1144    
1145 root 1.13 MODULE = OpenCL PACKAGE = OpenCL::Image
1146    
1147     void
1148     image_info (OpenCL::Image this, cl_image_info name)
1149     PPCODE:
1150     INFO (Image)
1151    
1152 root 1.14 #BEGIN:image
1153    
1154     void
1155     element_size (OpenCL::Image this)
1156 root 1.16 ALIAS:
1157     element_size = CL_IMAGE_ELEMENT_SIZE
1158     row_pitch = CL_IMAGE_ROW_PITCH
1159     slice_pitch = CL_IMAGE_SLICE_PITCH
1160     width = CL_IMAGE_WIDTH
1161     height = CL_IMAGE_HEIGHT
1162     depth = CL_IMAGE_DEPTH
1163 root 1.14 PPCODE:
1164     size_t value [1];
1165 root 1.16 NEED_SUCCESS (GetImageInfo, (this, ix, sizeof (value), value, 0));
1166 root 1.14 EXTEND (SP, 1);
1167     const int i = 0;
1168     PUSHs (sv_2mortal (newSVuv (value [i])));
1169    
1170     #END:image
1171    
1172 root 1.2 MODULE = OpenCL PACKAGE = OpenCL::Sampler
1173    
1174     void
1175     DESTROY (OpenCL::Sampler this)
1176     CODE:
1177     clReleaseSampler (this);
1178    
1179     void
1180     info (OpenCL::Sampler this, cl_sampler_info name)
1181     PPCODE:
1182     INFO (Sampler)
1183    
1184 root 1.14 #BEGIN:sampler
1185    
1186     void
1187     reference_count (OpenCL::Sampler this)
1188     PPCODE:
1189     cl_uint value [1];
1190     NEED_SUCCESS (GetSamplerInfo, (this, CL_SAMPLER_REFERENCE_COUNT, sizeof (value), value, 0));
1191     EXTEND (SP, 1);
1192     const int i = 0;
1193     PUSHs (sv_2mortal (newSVuv (value [i])));
1194    
1195     void
1196     context (OpenCL::Sampler this)
1197     PPCODE:
1198     cl_context value [1];
1199     NEED_SUCCESS (GetSamplerInfo, (this, CL_SAMPLER_CONTEXT, sizeof (value), value, 0));
1200     EXTEND (SP, 1);
1201     const int i = 0;
1202     {
1203     NEED_SUCCESS (RetainContext, (value [i]));
1204     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
1205     }
1206    
1207     void
1208     normalized_coords (OpenCL::Sampler this)
1209     PPCODE:
1210     cl_addressing_mode value [1];
1211     NEED_SUCCESS (GetSamplerInfo, (this, CL_SAMPLER_NORMALIZED_COORDS, sizeof (value), value, 0));
1212     EXTEND (SP, 1);
1213     const int i = 0;
1214     PUSHs (sv_2mortal (newSViv (value [i])));
1215    
1216     void
1217     addressing_mode (OpenCL::Sampler this)
1218     PPCODE:
1219     cl_filter_mode value [1];
1220     NEED_SUCCESS (GetSamplerInfo, (this, CL_SAMPLER_ADDRESSING_MODE, sizeof (value), value, 0));
1221     EXTEND (SP, 1);
1222     const int i = 0;
1223     PUSHs (sv_2mortal (newSViv (value [i])));
1224    
1225     void
1226     filter_mode (OpenCL::Sampler this)
1227     PPCODE:
1228     cl_bool value [1];
1229     NEED_SUCCESS (GetSamplerInfo, (this, CL_SAMPLER_FILTER_MODE, sizeof (value), value, 0));
1230     EXTEND (SP, 1);
1231     const int i = 0;
1232     PUSHs (sv_2mortal (value [i] ? &PL_sv_yes : &PL_sv_no));
1233    
1234     #END:sampler
1235    
1236 root 1.2 MODULE = OpenCL PACKAGE = OpenCL::Program
1237    
1238     void
1239     DESTROY (OpenCL::Program this)
1240     CODE:
1241     clReleaseProgram (this);
1242    
1243     void
1244     build (OpenCL::Program this, OpenCL::Device device, SV *options = &PL_sv_undef)
1245     CODE:
1246     NEED_SUCCESS (BuildProgram, (this, 1, &device, SvPVbyte_nolen (options), 0, 0));
1247    
1248     void
1249     build_info (OpenCL::Program this, OpenCL::Device device, cl_program_build_info name)
1250     PPCODE:
1251 root 1.1 size_t size;
1252 root 1.2 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, 0, 0, &size));
1253 root 1.10 SV *sv = sv_2mortal (newSV (size));
1254 root 1.1 SvUPGRADE (sv, SVt_PV);
1255     SvPOK_only (sv);
1256     SvCUR_set (sv, size);
1257 root 1.2 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, size, SvPVX (sv), 0));
1258 root 1.1 XPUSHs (sv);
1259    
1260 root 1.14 #BEGIN:program_build
1261    
1262     void
1263     build_status (OpenCL::Program this, OpenCL::Device device)
1264     PPCODE:
1265     cl_build_status value [1];
1266     NEED_SUCCESS (GetProgramBuildInfo, (this, device, CL_PROGRAM_BUILD_STATUS, sizeof (value), value, 0));
1267     EXTEND (SP, 1);
1268     const int i = 0;
1269     PUSHs (sv_2mortal (newSViv (value [i])));
1270    
1271     void
1272     build_options (OpenCL::Program this, OpenCL::Device device)
1273 root 1.16 ALIAS:
1274     build_options = CL_PROGRAM_BUILD_OPTIONS
1275     build_log = CL_PROGRAM_BUILD_LOG
1276 root 1.14 PPCODE:
1277     size_t size;
1278 root 1.16 NEED_SUCCESS (GetProgramBuildInfo, (this, device, ix, 0, 0, &size));
1279 root 1.14 char *value = tmpbuf (size);
1280 root 1.16 NEED_SUCCESS (GetProgramBuildInfo, (this, device, ix, size, value, 0));
1281     EXTEND (SP, 1);
1282     const int i = 0;
1283 root 1.14 PUSHs (sv_2mortal (newSVpv (value, 0)));
1284    
1285     #END:program_build
1286    
1287 root 1.2 void
1288     kernel (OpenCL::Program program, SV *function)
1289     PPCODE:
1290 root 1.8 NEED_SUCCESS_ARG (cl_kernel kernel, CreateKernel, (program, SvPVbyte_nolen (function), &res));
1291 root 1.2 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel);
1292    
1293 root 1.14 void
1294     info (OpenCL::Program this, cl_program_info name)
1295     PPCODE:
1296     INFO (Program)
1297    
1298 root 1.15 void
1299     binaries (OpenCL::Program this)
1300     PPCODE:
1301     cl_uint n, i;
1302     size_t size;
1303    
1304     NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_NUM_DEVICES , sizeof (n) , &n , 0));
1305     if (!n) XSRETURN_EMPTY;
1306    
1307     size_t *sizes = tmpbuf (sizeof (*sizes) * n);
1308     NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_BINARY_SIZES, sizeof (*sizes) * n, sizes, &size));
1309     if (size != sizeof (*sizes) * n) XSRETURN_EMPTY;
1310     unsigned char **ptrs = tmpbuf (sizeof (*ptrs) * n);
1311    
1312     EXTEND (SP, n);
1313     for (i = 0; i < n; ++i)
1314     {
1315     SV *sv = sv_2mortal (newSV (sizes [i]));
1316     SvUPGRADE (sv, SVt_PV);
1317     SvPOK_only (sv);
1318     SvCUR_set (sv, sizes [i]);
1319     ptrs [i] = SvPVX (sv);
1320     PUSHs (sv);
1321     }
1322    
1323     NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size));
1324     if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY;
1325    
1326 root 1.14 #BEGIN:program
1327    
1328     void
1329     reference_count (OpenCL::Program this)
1330 root 1.16 ALIAS:
1331     reference_count = CL_PROGRAM_REFERENCE_COUNT
1332     num_devices = CL_PROGRAM_NUM_DEVICES
1333 root 1.14 PPCODE:
1334     cl_uint value [1];
1335 root 1.16 NEED_SUCCESS (GetProgramInfo, (this, ix, sizeof (value), value, 0));
1336 root 1.14 EXTEND (SP, 1);
1337     const int i = 0;
1338     PUSHs (sv_2mortal (newSVuv (value [i])));
1339    
1340     void
1341     context (OpenCL::Program this)
1342     PPCODE:
1343     cl_context value [1];
1344     NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_CONTEXT, sizeof (value), value, 0));
1345     EXTEND (SP, 1);
1346     const int i = 0;
1347     {
1348     NEED_SUCCESS (RetainContext, (value [i]));
1349     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
1350     }
1351    
1352     void
1353     devices (OpenCL::Program this)
1354     PPCODE:
1355     size_t size;
1356     NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_DEVICES, 0, 0, &size));
1357     cl_device_id *value = tmpbuf (size);
1358     NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_DEVICES, size, value, 0));
1359 root 1.15 int i, n = size / sizeof (*value);
1360 root 1.14 EXTEND (SP, n);
1361     for (i = 0; i < n; ++i)
1362     {
1363     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Device", value [i]));
1364     }
1365    
1366     void
1367     source (OpenCL::Program this)
1368     PPCODE:
1369     size_t size;
1370     NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_SOURCE, 0, 0, &size));
1371     char *value = tmpbuf (size);
1372     NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_SOURCE, size, value, 0));
1373 root 1.16 EXTEND (SP, 1);
1374     const int i = 0;
1375 root 1.14 PUSHs (sv_2mortal (newSVpv (value, 0)));
1376    
1377     void
1378     binary_sizes (OpenCL::Program this)
1379     PPCODE:
1380     size_t size;
1381     NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_BINARY_SIZES, 0, 0, &size));
1382     size_t *value = tmpbuf (size);
1383     NEED_SUCCESS (GetProgramInfo, (this, CL_PROGRAM_BINARY_SIZES, size, value, 0));
1384 root 1.15 int i, n = size / sizeof (*value);
1385 root 1.14 EXTEND (SP, n);
1386     for (i = 0; i < n; ++i)
1387     PUSHs (sv_2mortal (newSVuv (value [i])));
1388    
1389     #END:program
1390    
1391 root 1.2 MODULE = OpenCL PACKAGE = OpenCL::Kernel
1392    
1393     void
1394     DESTROY (OpenCL::Kernel this)
1395     CODE:
1396     clReleaseKernel (this);
1397    
1398     void
1399 root 1.3 set_char (OpenCL::Kernel this, cl_uint idx, cl_char value)
1400     CODE:
1401     clSetKernelArg (this, idx, sizeof (value), &value);
1402    
1403     void
1404     set_uchar (OpenCL::Kernel this, cl_uint idx, cl_uchar value)
1405     CODE:
1406     clSetKernelArg (this, idx, sizeof (value), &value);
1407    
1408     void
1409     set_short (OpenCL::Kernel this, cl_uint idx, cl_short value)
1410     CODE:
1411     clSetKernelArg (this, idx, sizeof (value), &value);
1412    
1413     void
1414     set_ushort (OpenCL::Kernel this, cl_uint idx, cl_ushort value)
1415     CODE:
1416     clSetKernelArg (this, idx, sizeof (value), &value);
1417    
1418     void
1419     set_int (OpenCL::Kernel this, cl_uint idx, cl_int value)
1420     CODE:
1421     clSetKernelArg (this, idx, sizeof (value), &value);
1422    
1423     void
1424     set_uint (OpenCL::Kernel this, cl_uint idx, cl_uint value)
1425     CODE:
1426     clSetKernelArg (this, idx, sizeof (value), &value);
1427    
1428     void
1429     set_long (OpenCL::Kernel this, cl_uint idx, cl_long value)
1430     CODE:
1431     clSetKernelArg (this, idx, sizeof (value), &value);
1432    
1433     void
1434     set_ulong (OpenCL::Kernel this, cl_uint idx, cl_ulong value)
1435     CODE:
1436     clSetKernelArg (this, idx, sizeof (value), &value);
1437    
1438     void
1439     set_half (OpenCL::Kernel this, cl_uint idx, cl_half value)
1440     CODE:
1441     clSetKernelArg (this, idx, sizeof (value), &value);
1442    
1443     void
1444     set_float (OpenCL::Kernel this, cl_uint idx, cl_float value)
1445     CODE:
1446     clSetKernelArg (this, idx, sizeof (value), &value);
1447    
1448     void
1449 root 1.5 set_double (OpenCL::Kernel this, cl_uint idx, cl_double value)
1450     CODE:
1451     clSetKernelArg (this, idx, sizeof (value), &value);
1452    
1453     void
1454 root 1.3 set_memory (OpenCL::Kernel this, cl_uint idx, OpenCL::Memory_ornull value)
1455     CODE:
1456     clSetKernelArg (this, idx, sizeof (value), &value);
1457    
1458     void
1459     set_buffer (OpenCL::Kernel this, cl_uint idx, OpenCL::Buffer_ornull value)
1460     CODE:
1461     clSetKernelArg (this, idx, sizeof (value), &value);
1462    
1463     void
1464     set_image2d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image2D_ornull value)
1465     CODE:
1466     clSetKernelArg (this, idx, sizeof (value), &value);
1467    
1468     void
1469     set_image3d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image3D_ornull value)
1470     CODE:
1471     clSetKernelArg (this, idx, sizeof (value), &value);
1472    
1473     void
1474     set_sampler (OpenCL::Kernel this, cl_uint idx, OpenCL::Sampler value)
1475     CODE:
1476     clSetKernelArg (this, idx, sizeof (value), &value);
1477    
1478     void
1479     set_event (OpenCL::Kernel this, cl_uint idx, OpenCL::Event value)
1480 root 1.2 CODE:
1481 root 1.3 clSetKernelArg (this, idx, sizeof (value), &value);
1482 root 1.2
1483 root 1.14 void
1484     info (OpenCL::Kernel this, cl_kernel_info name)
1485     PPCODE:
1486     INFO (Kernel)
1487    
1488     #BEGIN:kernel
1489    
1490     void
1491     function_name (OpenCL::Kernel this)
1492     PPCODE:
1493     size_t size;
1494     NEED_SUCCESS (GetKernelInfo, (this, CL_KERNEL_FUNCTION_NAME, 0, 0, &size));
1495     char *value = tmpbuf (size);
1496     NEED_SUCCESS (GetKernelInfo, (this, CL_KERNEL_FUNCTION_NAME, size, value, 0));
1497 root 1.16 EXTEND (SP, 1);
1498     const int i = 0;
1499 root 1.14 PUSHs (sv_2mortal (newSVpv (value, 0)));
1500    
1501     void
1502     num_args (OpenCL::Kernel this)
1503 root 1.16 ALIAS:
1504     num_args = CL_KERNEL_NUM_ARGS
1505     reference_count = CL_KERNEL_REFERENCE_COUNT
1506 root 1.14 PPCODE:
1507     cl_uint value [1];
1508 root 1.16 NEED_SUCCESS (GetKernelInfo, (this, ix, sizeof (value), value, 0));
1509 root 1.14 EXTEND (SP, 1);
1510     const int i = 0;
1511     PUSHs (sv_2mortal (newSVuv (value [i])));
1512    
1513     void
1514     context (OpenCL::Kernel this)
1515     PPCODE:
1516     cl_context value [1];
1517     NEED_SUCCESS (GetKernelInfo, (this, CL_KERNEL_CONTEXT, sizeof (value), value, 0));
1518     EXTEND (SP, 1);
1519     const int i = 0;
1520     {
1521     NEED_SUCCESS (RetainContext, (value [i]));
1522     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
1523     }
1524    
1525     void
1526     program (OpenCL::Kernel this)
1527     PPCODE:
1528     cl_program value [1];
1529     NEED_SUCCESS (GetKernelInfo, (this, CL_KERNEL_PROGRAM, sizeof (value), value, 0));
1530     EXTEND (SP, 1);
1531     const int i = 0;
1532     {
1533     NEED_SUCCESS (RetainProgram, (value [i]));
1534     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Program", value [i]));
1535     }
1536    
1537     #END:kernel
1538    
1539     void
1540     work_group_info (OpenCL::Kernel this, OpenCL::Device device, cl_kernel_work_group_info name)
1541     PPCODE:
1542     size_t size;
1543     NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, name, 0, 0, &size));
1544     SV *sv = sv_2mortal (newSV (size));
1545     SvUPGRADE (sv, SVt_PV);
1546     SvPOK_only (sv);
1547     SvCUR_set (sv, size);
1548     NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, name, size, SvPVX (sv), 0));
1549     XPUSHs (sv);
1550    
1551     #BEGIN:kernel_work_group
1552    
1553     void
1554     work_group_size (OpenCL::Kernel this, OpenCL::Device device)
1555 root 1.16 ALIAS:
1556     work_group_size = CL_KERNEL_WORK_GROUP_SIZE
1557     preferred_work_group_size_multiple = CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE
1558 root 1.14 PPCODE:
1559     size_t value [1];
1560 root 1.16 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, ix, sizeof (value), value, 0));
1561 root 1.14 EXTEND (SP, 1);
1562     const int i = 0;
1563     PUSHs (sv_2mortal (newSVuv (value [i])));
1564    
1565     void
1566     compile_work_group_size (OpenCL::Kernel this, OpenCL::Device device)
1567     PPCODE:
1568     size_t size;
1569     NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, 0, 0, &size));
1570     size_t *value = tmpbuf (size);
1571     NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, size, value, 0));
1572 root 1.15 int i, n = size / sizeof (*value);
1573 root 1.14 EXTEND (SP, n);
1574     for (i = 0; i < n; ++i)
1575     PUSHs (sv_2mortal (newSVuv (value [i])));
1576    
1577     void
1578     local_mem_size (OpenCL::Kernel this, OpenCL::Device device)
1579 root 1.16 ALIAS:
1580     local_mem_size = CL_KERNEL_LOCAL_MEM_SIZE
1581     private_mem_size = CL_KERNEL_PRIVATE_MEM_SIZE
1582 root 1.14 PPCODE:
1583     cl_ulong value [1];
1584 root 1.16 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, ix, sizeof (value), value, 0));
1585 root 1.14 EXTEND (SP, 1);
1586     const int i = 0;
1587     PUSHs (sv_2mortal (newSVuv (value [i])));
1588    
1589     #END:kernel_work_group
1590    
1591 root 1.2 MODULE = OpenCL PACKAGE = OpenCL::Event
1592    
1593     void
1594     DESTROY (OpenCL::Event this)
1595     CODE:
1596     clReleaseEvent (this);
1597    
1598     void
1599 root 1.14 wait (OpenCL::Event this)
1600     CODE:
1601     clWaitForEvents (1, &this);
1602    
1603     void
1604 root 1.2 info (OpenCL::Event this, cl_event_info name)
1605     PPCODE:
1606     INFO (Event)
1607    
1608 root 1.14 #BEGIN:event
1609    
1610     void
1611     command_queue (OpenCL::Event this)
1612     PPCODE:
1613     cl_command_queue value [1];
1614     NEED_SUCCESS (GetEventInfo, (this, CL_EVENT_COMMAND_QUEUE, sizeof (value), value, 0));
1615     EXTEND (SP, 1);
1616     const int i = 0;
1617     {
1618     NEED_SUCCESS (RetainCommandQueue, (value [i]));
1619     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Queue", value [i]));
1620     }
1621    
1622     void
1623     command_type (OpenCL::Event this)
1624     PPCODE:
1625     cl_command_type value [1];
1626     NEED_SUCCESS (GetEventInfo, (this, CL_EVENT_COMMAND_TYPE, sizeof (value), value, 0));
1627     EXTEND (SP, 1);
1628     const int i = 0;
1629     PUSHs (sv_2mortal (newSVuv (value [i])));
1630    
1631     void
1632     reference_count (OpenCL::Event this)
1633 root 1.16 ALIAS:
1634     reference_count = CL_EVENT_REFERENCE_COUNT
1635     command_execution_status = CL_EVENT_COMMAND_EXECUTION_STATUS
1636 root 1.14 PPCODE:
1637     cl_uint value [1];
1638 root 1.16 NEED_SUCCESS (GetEventInfo, (this, ix, sizeof (value), value, 0));
1639 root 1.14 EXTEND (SP, 1);
1640     const int i = 0;
1641     PUSHs (sv_2mortal (newSVuv (value [i])));
1642    
1643     void
1644     context (OpenCL::Event this)
1645     PPCODE:
1646     cl_context value [1];
1647     NEED_SUCCESS (GetEventInfo, (this, CL_EVENT_CONTEXT, sizeof (value), value, 0));
1648     EXTEND (SP, 1);
1649     const int i = 0;
1650     {
1651     NEED_SUCCESS (RetainContext, (value [i]));
1652     PUSHs (NEW_MORTAL_OBJ ("OpenCL::Context", value [i]));
1653     }
1654    
1655     #END:event
1656    
1657 root 1.2 void
1658 root 1.13 profiling_info (OpenCL::Event this, cl_profiling_info name)
1659     PPCODE:
1660     INFO (EventProfiling)
1661    
1662 root 1.14 #BEGIN:profiling
1663    
1664 root 1.13 void
1665 root 1.14 profiling_command_queued (OpenCL::Event this)
1666 root 1.16 ALIAS:
1667     profiling_command_queued = CL_PROFILING_COMMAND_QUEUED
1668     profiling_command_submit = CL_PROFILING_COMMAND_SUBMIT
1669     profiling_command_start = CL_PROFILING_COMMAND_START
1670     profiling_command_end = CL_PROFILING_COMMAND_END
1671 root 1.14 PPCODE:
1672     cl_ulong value [1];
1673 root 1.16 NEED_SUCCESS (GetEventProfilingInfo, (this, ix, sizeof (value), value, 0));
1674 root 1.14 EXTEND (SP, 1);
1675     const int i = 0;
1676     PUSHs (sv_2mortal (newSVuv (value [i])));
1677    
1678     #END:profiling
1679 root 1.2
1680 root 1.5 MODULE = OpenCL PACKAGE = OpenCL::UserEvent
1681    
1682     void
1683     set_status (OpenCL::UserEvent this, cl_int execution_status)
1684     CODE:
1685     clSetUserEventStatus (this, execution_status);
1686