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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines