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.20 by root, Sat Dec 10 23:07:38 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines