ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/OpenCL/OpenCL.xs
Revision: 1.19
Committed: Thu Nov 24 03:02:57 2011 UTC (12 years, 5 months ago) by root
Branch: MAIN
Changes since 1.18: +5 -1 lines
Log Message:
*** empty log message ***

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