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.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; 12typedef cl_mem OpenCL__Buffer;
13typedef cl_mem OpenCL__BufferObj;
13typedef cl_mem OpenCL__Image; 14typedef cl_mem OpenCL__Image;
14typedef cl_mem OpenCL__Image2D; 15typedef cl_mem OpenCL__Image2D;
15typedef cl_mem OpenCL__Image3D; 16typedef cl_mem OpenCL__Image3D;
16typedef cl_mem OpenCL__Memory_ornull; 17typedef cl_mem OpenCL__Memory_ornull;
17typedef cl_mem OpenCL__Buffer_ornull; 18typedef cl_mem OpenCL__Buffer_ornull;
18typedef cl_mem OpenCL__Image_ornull; 19typedef cl_mem OpenCL__Image_ornull;
19typedef cl_mem OpenCL__Image2D_ornull; 20typedef cl_mem OpenCL__Image2D_ornull;
20typedef cl_mem OpenCL__Image3D_ornull; 21typedef cl_mem OpenCL__Image3D_ornull;
21typedef cl_sampler OpenCL__Sampler; 22typedef cl_sampler OpenCL__Sampler;
22typedef cl_program OpenCL__Program; 23typedef cl_program OpenCL__Program;
23typedef cl_kernel OpenCL__Kernel; 24typedef cl_kernel OpenCL__Kernel;
24typedef cl_event OpenCL__Event; 25typedef cl_event OpenCL__Event;
25typedef cl_event OpenCL__UserEvent; 26typedef cl_event OpenCL__UserEvent;
27
28typedef SV *FUTURE;
26 29
27/*****************************************************************************/ 30/*****************************************************************************/
28 31
29/* up to two temporary buffers */ 32/* up to two temporary buffers */
30static void * 33static void *
90 return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)"); 93 return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)");
91} 94}
92 95
93/*****************************************************************************/ 96/*****************************************************************************/
94 97
95static cl_int last_error; 98static cl_int res;
96 99
97#define FAIL(name,err) \ 100#define FAIL(name) \
98 croak ("cl" # name ": %s", err2str (last_error = err)); 101 croak ("cl" # name ": %s", err2str (res));
99 102
100#define NEED_SUCCESS(name,args) \ 103#define NEED_SUCCESS(name,args) \
101 do { \ 104 do { \
102 cl_int res = cl ## name args; \ 105 res = cl ## name args; \
103 \ 106 \
104 if (res) \ 107 if (res) \
105 FAIL (name, res); \ 108 FAIL (name); \
106 } 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);
107 115
108/*****************************************************************************/ 116/*****************************************************************************/
109 117
110#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)
111#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))
119 croak ("%s: %s is not of type %s", func, svname, pkg); 127 croak ("%s: %s is not of type %s", func, svname, pkg);
120} 128}
121 129
122/*****************************************************************************/ 130/*****************************************************************************/
123 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
124static cl_event * 140static cl_event *
125event_list (SV **items, int count) 141event_list (SV **items, int count)
126{ 142{
127 cl_event *list = tmpbuf (sizeof (cl_event) * count); 143 cl_event *list = tmpbuf (sizeof (cl_event) * count);
128 144
137 cl_event *event_list_ptr = event_list (&ST (items), event_list_count) 153 cl_event *event_list_ptr = event_list (&ST (items), event_list_count)
138 154
139#define INFO(class) \ 155#define INFO(class) \
140{ \ 156{ \
141 size_t size; \ 157 size_t size; \
142 SV *sv; \
143 \
144 NEED_SUCCESS (Get ## class ## Info, (this, name, 0, 0, &size)); \ 158 NEED_SUCCESS (Get ## class ## Info, (this, name, 0, 0, &size)); \
145 sv = sv_2mortal (newSV (size)); \ 159 SV *sv = sv_2mortal (newSV (size)); \
146 SvUPGRADE (sv, SVt_PV); \ 160 SvUPGRADE (sv, SVt_PV); \
147 SvPOK_only (sv); \ 161 SvPOK_only (sv); \
148 SvCUR_set (sv, size); \ 162 SvCUR_set (sv, size); \
149 NEED_SUCCESS (Get ## class ## Info, (this, name, size, SvPVX (sv), 0)); \ 163 NEED_SUCCESS (Get ## class ## Info, (this, name, size, SvPVX (sv), 0)); \
150 XPUSHs (sv); \ 164 XPUSHs (sv); \
176} 190}
177 191
178cl_int 192cl_int
179errno () 193errno ()
180 CODE: 194 CODE:
181 errno = last_error; 195 errno = res;
182 196
183const char * 197const char *
184err2str (cl_int err) 198err2str (cl_int err)
185 199
186const char * 200const char *
187enum2str (cl_uint value) 201enum2str (cl_uint value)
188 202
189void 203void
190platforms () 204platforms ()
191 PPCODE: 205 PPCODE:
192{
193 cl_platform_id *list; 206 cl_platform_id *list;
194 cl_uint count; 207 cl_uint count;
195 int i; 208 int i;
196 209
197 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count)); 210 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count));
199 NEED_SUCCESS (GetPlatformIDs, (count, list, 0)); 212 NEED_SUCCESS (GetPlatformIDs, (count, list, 0));
200 213
201 EXTEND (SP, count); 214 EXTEND (SP, count);
202 for (i = 0; i < count; ++i) 215 for (i = 0; i < count; ++i)
203 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); 216 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i]));
204}
205 217
206void 218void
207context_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)
208 PPCODE: 220 PPCODE:
209{
210 cl_int res;
211 cl_context ctx = clCreateContextFromType (0, type, 0, 0, &res); 221 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); 222 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
217} 223
224void
225context (FUTURE properties, FUTURE devices, FUTURE notify = 0)
226 PPCODE:
227 /* der Gipfel der Kunst */
218 228
219void 229void
220wait_for_events (...) 230wait_for_events (...)
221 CODE: 231 CODE:
222{
223 EVENT_LIST (0, items); 232 EVENT_LIST (0, items);
224 NEED_SUCCESS (WaitForEvents, (event_list_count, event_list_ptr)); 233 NEED_SUCCESS (WaitForEvents, (event_list_count, event_list_ptr));
225}
226 234
227PROTOTYPES: DISABLE 235PROTOTYPES: DISABLE
228 236
229MODULE = OpenCL PACKAGE = OpenCL::Platform 237MODULE = OpenCL PACKAGE = OpenCL::Platform
230 238
231void 239void
232info (OpenCL::Platform this, cl_platform_info name) 240info (OpenCL::Platform this, cl_platform_info name)
233 PPCODE: 241 PPCODE:
234 INFO (Platform) 242 INFO (Platform)
235 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
236void 265void
237devices (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_ALL) 266devices (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_ALL)
238 PPCODE: 267 PPCODE:
239{
240 cl_device_id *list; 268 cl_device_id *list;
241 cl_uint count; 269 cl_uint count;
242 int i; 270 int i;
243 271
244 NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count)); 272 NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count));
246 NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0)); 274 NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0));
247 275
248 EXTEND (SP, count); 276 EXTEND (SP, count);
249 for (i = 0; i < count; ++i) 277 for (i = 0; i < count; ++i)
250 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); 278 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i]));
251}
252 279
253void 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
254context_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)
255 PPCODE: 299 PPCODE:
256{
257 cl_int res;
258 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 };
259 cl_context ctx = clCreateContextFromType (props, type, 0, 0, &res); 301 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); 302 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
265}
266 303
267MODULE = OpenCL PACKAGE = OpenCL::Device 304MODULE = OpenCL PACKAGE = OpenCL::Device
268 305
269void 306void
270info (OpenCL::Device this, cl_device_info name) 307info (OpenCL::Device this, cl_device_info name)
271 PPCODE: 308 PPCODE:
272 INFO (Device) 309 INFO (Device)
273 310
311#BEGIN:device
312
274void 313void
275context_simple (OpenCL::Device this) 314type (OpenCL::Device this)
276 PPCODE: 315 PPCODE:
277{ 316 cl_device_type value [1];
278 cl_int res; 317 NEED_SUCCESS (GetDeviceInfo, (this, CL_DEVICE_TYPE, sizeof (value), value, 0));
279 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])));
280 321
281 if (res) 322void
282 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])));
283 358
284 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 359void
285} 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
286 534
287MODULE = OpenCL PACKAGE = OpenCL::Context 535MODULE = OpenCL PACKAGE = OpenCL::Context
288 536
289void 537void
290DESTROY (OpenCL::Context context) 538DESTROY (OpenCL::Context context)
295info (OpenCL::Context this, cl_context_info name) 543info (OpenCL::Context this, cl_context_info name)
296 PPCODE: 544 PPCODE:
297 INFO (Context) 545 INFO (Context)
298 546
299void 547void
300command_queue_simple (OpenCL::Context this, OpenCL::Device device) 548queue (OpenCL::Context this, OpenCL::Device device, cl_command_queue_properties properties = 0)
301 PPCODE: 549 PPCODE:
302{
303 cl_int res;
304 cl_command_queue queue = clCreateCommandQueue (this, device, 0, &res); 550 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); 551 XPUSH_NEW_OBJ ("OpenCL::Queue", queue);
310}
311 552
312void 553void
313user_event (OpenCL::Context this) 554user_event (OpenCL::Context this)
314 PPCODE: 555 PPCODE:
315{
316 cl_int res;
317 cl_event ev = clCreateUserEvent (this, &res); 556 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); 557 XPUSH_NEW_OBJ ("OpenCL::UserEvent", ev);
323}
324 558
325void 559void
326buffer (OpenCL::Context this, cl_mem_flags flags, size_t len) 560buffer (OpenCL::Context this, cl_mem_flags flags, size_t len)
327 PPCODE: 561 PPCODE:
328{
329 cl_int res;
330 cl_mem mem;
331
332 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) 562 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?"); 563 croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?");
334 564
335 mem = clCreateBuffer (this, flags, len, 0, &res); 565 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); 566 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
341}
342 567
343void 568void
344buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data) 569buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data)
345 PPCODE: 570 PPCODE:
346{
347 STRLEN len; 571 STRLEN len;
348 char *ptr = SvPVbyte (data, len); 572 char *ptr = SvPVbyte (data, len);
349 cl_int res;
350 cl_mem mem;
351 573
352 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) 574 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?"); 575 croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
354 576
355 mem = clCreateBuffer (this, flags, len, ptr, &res); 577 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); 578 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
361}
362 579
363void 580void
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) 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)
365 PPCODE: 582 PPCODE:
366{
367 STRLEN len; 583 STRLEN len;
368 char *ptr = SvPVbyte (data, len); 584 char *ptr = SvPVbyte (data, len);
369 const cl_image_format format = { channel_order, channel_type }; 585 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); 586 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); 587 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
377}
378 588
379void 589void
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) 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)
381 PPCODE: 591 PPCODE:
382{
383 STRLEN len; 592 STRLEN len;
384 char *ptr = SvPVbyte (data, len); 593 char *ptr = SvPVbyte (data, len);
385 const cl_image_format format = { channel_order, channel_type }; 594 const cl_image_format format = { channel_order, channel_type };
386 cl_int res; 595 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); 596 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
394}
395 597
396void 598void
397supported_image_formats (OpenCL::Context this, cl_mem_flags flags, cl_mem_object_type image_type) 599supported_image_formats (OpenCL::Context this, cl_mem_flags flags, cl_mem_object_type image_type)
398 PPCODE: 600 PPCODE:
399{ 601{
416} 618}
417 619
418void 620void
419sampler (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)
420 PPCODE: 622 PPCODE:
421{
422 cl_int res;
423 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));
424
425 if (res)
426 FAIL (CreateSampler, res);
427
428 XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler); 624 XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler);
429}
430 625
431void 626void
432program_with_source (OpenCL::Context this, SV *program) 627program_with_source (OpenCL::Context this, SV *program)
433 PPCODE: 628 PPCODE:
434{
435 STRLEN len; 629 STRLEN len;
436 size_t len2; 630 size_t len2;
437 const char *ptr = SvPVbyte (program, len); 631 const char *ptr = SvPVbyte (program, len);
438 cl_int res;
439 cl_program prog;
440 632
441 len2 = len; 633 len2 = len;
442 prog = clCreateProgramWithSource (this, 1, &ptr, &len2, &res); 634 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); 635 XPUSH_NEW_OBJ ("OpenCL::Program", prog);
448} 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
449 678
450MODULE = OpenCL PACKAGE = OpenCL::Queue 679MODULE = OpenCL PACKAGE = OpenCL::Queue
451 680
452void 681void
453DESTROY (OpenCL::Queue this) 682DESTROY (OpenCL::Queue this)
454 CODE: 683 CODE:
455 clReleaseCommandQueue (this); 684 clReleaseCommandQueue (this);
456 685
457void 686void
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, ...) 687enqueue_read_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...)
464 PPCODE: 688 PPCODE:
465{
466 cl_event ev = 0; 689 cl_event ev = 0;
467 EVENT_LIST (6, items - 6); 690 EVENT_LIST (6, items - 6);
468 691
469 SvUPGRADE (data, SVt_PV); 692 SvUPGRADE (data, SVt_PV);
470 SvGROW (data, len); 693 SvGROW (data, len);
472 SvCUR_set (data, len); 695 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)); 696 NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
474 697
475 if (ev) 698 if (ev)
476 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 699 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
477}
478 700
479void 701void
480enqueue_write_buffer (OpenCL::Queue this, OpenCL::Buffer 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, ...)
481 PPCODE: 703 PPCODE:
482{
483 cl_event ev = 0; 704 cl_event ev = 0;
484 STRLEN len; 705 STRLEN len;
485 char *ptr = SvPVbyte (data, len); 706 char *ptr = SvPVbyte (data, len);
486 EVENT_LIST (5, items - 5); 707 EVENT_LIST (5, items - 5);
487 708
488 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));
489 710
490 if (ev) 711 if (ev)
491 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 712 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
492}
493 713
494void 714void
495enqueue_copy_buffer (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer 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, ...)
496 PPCODE: 716 PPCODE:
497{
498 cl_event ev = 0; 717 cl_event ev = 0;
499 EVENT_LIST (6, items - 6); 718 EVENT_LIST (6, items - 6);
500 719
501 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));
502 721
503 if (ev) 722 if (ev)
504 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 723 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
505}
506 724
507 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBufferRect.html */ 725void
508 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html */ 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);
509 803
510void 804void
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, ...) 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, ...)
512 PPCODE: 806 PPCODE:
513{
514 cl_event ev = 0; 807 cl_event ev = 0;
515 const size_t src_origin[3] = { src_x, src_y, src_z }; 808 const size_t src_origin[3] = { src_x, src_y, src_z };
516 const size_t region[3] = { width, height, depth }; 809 const size_t region[3] = { width, height, depth };
517 size_t len = row_pitch * slice_pitch * depth;
518 EVENT_LIST (11, items - 11); 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;
519 819
520 SvUPGRADE (data, SVt_PV); 820 SvUPGRADE (data, SVt_PV);
521 SvGROW (data, len); 821 SvGROW (data, len);
522 SvPOK_only (data); 822 SvPOK_only (data);
523 SvCUR_set (data, len); 823 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)); 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));
525 825
526 if (ev) 826 if (ev)
527 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 827 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
528}
529 828
530void 829void
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, ...) 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, ...)
532 PPCODE: 831 PPCODE:
533{
534 cl_event ev = 0; 832 cl_event ev = 0;
535 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 833 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
536 const size_t region[3] = { width, height, depth }; 834 const size_t region[3] = { width, height, depth };
537 STRLEN len; 835 STRLEN len;
538 char *ptr = SvPVbyte (data, len); 836 char *ptr = SvPVbyte (data, len);
539 size_t slice_pitch = len / (row_pitch * height);
540 EVENT_LIST (11, items - 11); 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");
541 849
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)); 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));
543 851
544 if (ev) 852 if (ev)
545 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 853 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
546}
547 854
548void 855void
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, ...)
550 PPCODE:
551{
552 cl_event ev = 0;
553 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 };
555 const size_t region[3] = { width, height, depth };
556 EVENT_LIST (16, items - 16);
557
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));
559
560 if (ev)
561 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
562}
563
564void
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, ...)
566 PPCODE:
567{
568 cl_event ev = 0;
569 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
570 const size_t region[3] = { width, height, depth };
571 EVENT_LIST (10, items - 10);
572
573 NEED_SUCCESS (EnqueueCopyBufferToImage, (this, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
574
575 if (ev)
576 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
577}
578
579void
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, ...) 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, ...)
581 PPCODE: 857 PPCODE:
582{
583 cl_event ev = 0; 858 cl_event ev = 0;
584 const size_t src_origin[3] = { src_x, src_y, src_z }; 859 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 }; 860 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
586 const size_t region[3] = { width, height, depth }; 861 const size_t region[3] = { width, height, depth };
587 EVENT_LIST (12, items - 12); 862 EVENT_LIST (12, items - 12);
588 863
589 NEED_SUCCESS (EnqueueCopyImage, (this, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 864 NEED_SUCCESS (EnqueueCopyImage, (this, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
590 865
591 if (ev) 866 if (ev)
592 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 867 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
593}
594 868
595void 869void
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, ...) 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, ...)
597 PPCODE: 871 PPCODE:
598{
599 cl_event ev = 0; 872 cl_event ev = 0;
600 const size_t src_origin[3] = { src_x, src_y, src_z }; 873 const size_t src_origin[3] = { src_x, src_y, src_z };
601 const size_t region[3] = { width, height, depth }; 874 const size_t region[3] = { width, height, depth };
602 EVENT_LIST (10, items - 10); 875 EVENT_LIST (10, items - 10);
603 876
604 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 877 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
605 878
606 if (ev) 879 if (ev)
607 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 880 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
608} 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);
609 894
610void 895void
611enqueue_task (OpenCL::Queue this, OpenCL::Kernel kernel, ...) 896enqueue_task (OpenCL::Queue this, OpenCL::Kernel kernel, ...)
612 PPCODE: 897 PPCODE:
613{
614 cl_event ev = 0; 898 cl_event ev = 0;
615 EVENT_LIST (2, items - 2); 899 EVENT_LIST (2, items - 2);
616 900
617 NEED_SUCCESS (EnqueueTask, (this, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 901 NEED_SUCCESS (EnqueueTask, (this, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
618 902
619 if (ev) 903 if (ev)
620 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 904 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
621}
622 905
623void 906void
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, ...) 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, ...)
625 PPCODE: 908 PPCODE:
626{
627 cl_event ev = 0; 909 cl_event ev = 0;
628 size_t *gwo = 0, *gws, *lws = 0; 910 size_t *gwo = 0, *gws, *lws = 0;
629 int gws_len; 911 int gws_len;
630 size_t *lists; 912 size_t *lists;
631 int i; 913 int i;
670 952
671 NEED_SUCCESS (EnqueueNDRangeKernel, (this, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 953 NEED_SUCCESS (EnqueueNDRangeKernel, (this, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
672 954
673 if (ev) 955 if (ev)
674 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 956 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
675}
676 957
677void 958void
678enqueue_marker (OpenCL::Queue this) 959enqueue_marker (OpenCL::Queue this)
679 PPCODE: 960 PPCODE:
680{
681 cl_event ev; 961 cl_event ev;
682 NEED_SUCCESS (EnqueueMarker, (this, &ev)); 962 NEED_SUCCESS (EnqueueMarker, (this, &ev));
683 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 963 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
684}
685 964
686void 965void
687enqueue_wait_for_events (OpenCL::Queue this, ...) 966enqueue_wait_for_events (OpenCL::Queue this, ...)
688 CODE: 967 CODE:
689{
690 EVENT_LIST (1, items - 1); 968 EVENT_LIST (1, items - 1);
691 NEED_SUCCESS (EnqueueWaitForEvents, (this, event_list_count, event_list_ptr)); 969 NEED_SUCCESS (EnqueueWaitForEvents, (this, event_list_count, event_list_ptr));
692}
693 970
694void 971void
695enqueue_barrier (OpenCL::Queue this) 972enqueue_barrier (OpenCL::Queue this)
696 CODE: 973 CODE:
697 NEED_SUCCESS (EnqueueBarrier, (this)); 974 NEED_SUCCESS (EnqueueBarrier, (this));
704void 981void
705finish (OpenCL::Queue this) 982finish (OpenCL::Queue this)
706 CODE: 983 CODE:
707 NEED_SUCCESS (Finish, (this)); 984 NEED_SUCCESS (Finish, (this));
708 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
709MODULE = OpenCL PACKAGE = OpenCL::Memory 1036MODULE = OpenCL PACKAGE = OpenCL::Memory
710 1037
711void 1038void
712DESTROY (OpenCL::Memory this) 1039DESTROY (OpenCL::Memory this)
713 CODE: 1040 CODE:
716void 1043void
717info (OpenCL::Memory this, cl_mem_info name) 1044info (OpenCL::Memory this, cl_mem_info name)
718 PPCODE: 1045 PPCODE:
719 INFO (MemObject) 1046 INFO (MemObject)
720 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
721MODULE = OpenCL PACKAGE = OpenCL::Sampler 1167MODULE = OpenCL PACKAGE = OpenCL::Sampler
722 1168
723void 1169void
724DESTROY (OpenCL::Sampler this) 1170DESTROY (OpenCL::Sampler this)
725 CODE: 1171 CODE:
728void 1174void
729info (OpenCL::Sampler this, cl_sampler_info name) 1175info (OpenCL::Sampler this, cl_sampler_info name)
730 PPCODE: 1176 PPCODE:
731 INFO (Sampler) 1177 INFO (Sampler)
732 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
733MODULE = OpenCL PACKAGE = OpenCL::Program 1231MODULE = OpenCL PACKAGE = OpenCL::Program
734 1232
735void 1233void
736DESTROY (OpenCL::Program this) 1234DESTROY (OpenCL::Program this)
737 CODE: 1235 CODE:
738 clReleaseProgram (this); 1236 clReleaseProgram (this);
739 1237
740void 1238void
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) 1239build (OpenCL::Program this, OpenCL::Device device, SV *options = &PL_sv_undef)
747 CODE: 1240 CODE:
748 NEED_SUCCESS (BuildProgram, (this, 1, &device, SvPVbyte_nolen (options), 0, 0)); 1241 NEED_SUCCESS (BuildProgram, (this, 1, &device, SvPVbyte_nolen (options), 0, 0));
749 1242
750void 1243void
751build_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)
752 PPCODE: 1245 PPCODE:
753{
754 size_t size; 1246 size_t size;
755 SV *sv;
756
757 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, 0, 0, &size)); 1247 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, 0, 0, &size));
758 sv = sv_2mortal (newSV (size)); 1248 SV *sv = sv_2mortal (newSV (size));
759 SvUPGRADE (sv, SVt_PV); 1249 SvUPGRADE (sv, SVt_PV);
760 SvPOK_only (sv); 1250 SvPOK_only (sv);
761 SvCUR_set (sv, size); 1251 SvCUR_set (sv, size);
762 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, size, SvPVX (sv), 0)); 1252 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, size, SvPVX (sv), 0));
763 XPUSHs (sv); 1253 XPUSHs (sv);
764} 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
765 1281
766void 1282void
767kernel (OpenCL::Program program, SV *function) 1283kernel (OpenCL::Program program, SV *function)
768 PPCODE: 1284 PPCODE:
769{
770 cl_int res;
771 cl_kernel kernel = clCreateKernel (program, SvPVbyte_nolen (function), &res); 1285 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); 1286 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel);
777} 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
778 1385
779MODULE = OpenCL PACKAGE = OpenCL::Kernel 1386MODULE = OpenCL PACKAGE = OpenCL::Kernel
780 1387
781void 1388void
782DESTROY (OpenCL::Kernel this) 1389DESTROY (OpenCL::Kernel this)
783 CODE: 1390 CODE:
784 clReleaseKernel (this); 1391 clReleaseKernel (this);
785 1392
786void 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
787info (OpenCL::Kernel this, cl_kernel_info name) 1479info (OpenCL::Kernel this, cl_kernel_info name)
788 PPCODE: 1480 PPCODE:
789 INFO (Kernel) 1481 INFO (Kernel)
790 1482
1483#BEGIN:kernel
1484
791void 1485void
792set_char (OpenCL::Kernel this, cl_uint idx, cl_char 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)
793 CODE: 1536 PPCODE:
794 clSetKernelArg (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);
795 1545
796void 1546#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 1547
801void 1548void
802set_short (OpenCL::Kernel this, cl_uint idx, cl_short value) 1549work_group_size (OpenCL::Kernel this, OpenCL::Device device)
803 CODE: 1550 ALIAS:
804 clSetKernelArg (this, idx, sizeof (value), &value); 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])));
805 1559
806void 1560void
807set_ushort (OpenCL::Kernel this, cl_uint idx, cl_ushort value) 1561compile_work_group_size (OpenCL::Kernel this, OpenCL::Device device)
808 CODE: 1562 PPCODE:
809 clSetKernelArg (this, idx, sizeof (value), &value); 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])));
810 1571
811void 1572void
812set_int (OpenCL::Kernel this, cl_uint idx, cl_int value) 1573local_mem_size (OpenCL::Kernel this, OpenCL::Device device)
813 CODE: 1574 ALIAS:
814 clSetKernelArg (this, idx, sizeof (value), &value); 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])));
815 1583
816void 1584#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 1585
876MODULE = OpenCL PACKAGE = OpenCL::Event 1586MODULE = OpenCL PACKAGE = OpenCL::Event
877 1587
878void 1588void
879DESTROY (OpenCL::Event this) 1589DESTROY (OpenCL::Event this)
880 CODE: 1590 CODE:
881 clReleaseEvent (this); 1591 clReleaseEvent (this);
882 1592
883void 1593void
1594wait (OpenCL::Event this)
1595 CODE:
1596 clWaitForEvents (1, &this);
1597
1598void
884info (OpenCL::Event this, cl_event_info name) 1599info (OpenCL::Event this, cl_event_info name)
885 PPCODE: 1600 PPCODE:
886 INFO (Event) 1601 INFO (Event)
887 1602
1603#BEGIN:event
1604
888void 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
889wait (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)
890 CODE: 1654 PPCODE:
891 clWaitForEvents (1, &this); 1655 INFO (EventProfiling)
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
892 1674
893MODULE = OpenCL PACKAGE = OpenCL::UserEvent 1675MODULE = OpenCL PACKAGE = OpenCL::UserEvent
894 1676
895void 1677void
896set_status (OpenCL::UserEvent this, cl_int execution_status) 1678set_status (OpenCL::UserEvent this, cl_int execution_status)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines