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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines