ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/OpenCL/OpenCL.xs
Revision: 1.16
Committed: Tue Nov 22 10:29:18 2011 UTC (12 years, 5 months ago) by root
Branch: MAIN
Changes since 1.15: +220 -791 lines
Log Message:
coalesce

File Contents

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