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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.2 by root, Tue Nov 15 09:24:40 2011 UTC vs.
Revision 1.18 by root, Wed Nov 23 03:02:38 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines