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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.1 by root, Tue Nov 15 06:50:30 2011 UTC vs.
Revision 1.3 by root, Tue Nov 15 20:38:07 2011 UTC

6 6
7typedef cl_platform_id OpenCL__Platform; 7typedef cl_platform_id OpenCL__Platform;
8typedef cl_device_id OpenCL__Device; 8typedef cl_device_id OpenCL__Device;
9typedef cl_context OpenCL__Context; 9typedef cl_context OpenCL__Context;
10typedef cl_command_queue OpenCL__Queue; 10typedef cl_command_queue OpenCL__Queue;
11typedef cl_mem OpenCL__Memory;
12typedef cl_mem OpenCL__Buffer;
13typedef cl_mem OpenCL__Image;
14typedef cl_mem OpenCL__Image2D;
15typedef cl_mem OpenCL__Image3D;
16typedef cl_mem OpenCL__Memory_ornull;
17typedef cl_mem OpenCL__Buffer_ornull;
18typedef cl_mem OpenCL__Image_ornull;
19typedef cl_mem OpenCL__Image2D_ornull;
20typedef cl_mem OpenCL__Image3D_ornull;
21typedef cl_sampler OpenCL__Sampler;
22typedef cl_program OpenCL__Program;
23typedef cl_kernel OpenCL__Kernel;
24typedef cl_event OpenCL__Event;
11 25
12static const struct { 26typedef struct
27{
13 IV iv; 28 IV iv;
14 const char *name; 29 const char *name;
15} cl_error[] = {
16#define def_error(name) { (IV)CL_ ## name, # name }, 30 #define const_iv(name) { (IV)CL_ ## name, # name },
17#include "invalid.h" 31} ivstr;
18};
19 32
20static const char * 33static const char *
21clstrerror (cl_int res) 34iv2str (IV value, const ivstr *base, int count, const char *fallback)
22{ 35{
23 int i; 36 int i;
24 static char numbuf [32]; 37 static char strbuf [32];
25 38
26 for (i = sizeof (cl_error) / sizeof (cl_error [0]); i--; ) 39 for (i = count; i--; )
27 if (cl_error [i].iv == res) 40 if (base [i].iv == value)
28 return cl_error [i].name; 41 return base [i].name;
29 42
30 snprintf (numbuf, sizeof (numbuf), "ERROR(%d)", res); 43 snprintf (strbuf, sizeof (strbuf), fallback, (int)value);
31 44
32 return numbuf; 45 return strbuf;
46}
47
48static const char *
49enum2str (cl_uint value)
50{
51 static const ivstr enumstr[] = {
52 #include "enumstr.h"
53 };
54
55 return iv2str (value, enumstr, sizeof (enumstr) / sizeof (enumstr [0]), "ENUM(0x%04x)");
56}
57
58static const char *
59err2str (cl_int err)
60{
61 static const ivstr errstr[] = {
62 #include "errstr.h"
63 };
64
65 return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)");
33} 66}
34 67
35#define FAIL(name,res) \ 68#define FAIL(name,res) \
36 croak (# name ": %s", clstrerror (res)); 69 croak ("cl" # name ": %s", err2str (res));
37 70
38#define NEED_SUCCESS(name,args) \ 71#define NEED_SUCCESS(name,args) \
39 do { \ 72 do { \
40 cl_int res = name args; \ 73 cl_int res = cl ## name args; \
41 \ 74 \
42 if (res) \ 75 if (res) \
43 FAIL (name, res); \ 76 FAIL (name, res); \
44 } while (0) 77 } while (0)
45 78
79#define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr)
80#define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr))
81
82/*TODO*/
83#define EVENT_LIST(items,count) cl_uint event_list_count = 0; cl_event *event_list_ptr = 0
84
85#define INFO(class) \
86{ \
87 size_t size; \
88 SV *sv; \
89 \
90 NEED_SUCCESS (Get ## class ## Info, (this, name, 0, 0, &size)); \
91 sv = sv_2mortal (newSV (size)); \
92 SvUPGRADE (sv, SVt_PV); \
93 SvPOK_only (sv); \
94 SvCUR_set (sv, size); \
95 NEED_SUCCESS (Get ## class ## Info, (this, name, size, SvPVX (sv), 0)); \
96 XPUSHs (sv); \
97}
98
99static void *
100SvPTROBJ (const char *func, const char *svname, SV *sv, const char *pkg)
101{
102 if (SvROK (sv) && sv_derived_from (sv, pkg))
103 return (void *)SvIV (SvRV (sv));
104
105 croak ("%s: %s is not of type %s", func, svname, pkg);
106}
107
46MODULE = OpenCL PACKAGE = OpenCL 108MODULE = OpenCL PACKAGE = OpenCL
47 109
110PROTOTYPES: ENABLE
111
48BOOT: 112BOOT:
49{ 113{
50 HV *stash = gv_stashpv ("OpenCL", 1); 114 HV *stash = gv_stashpv ("OpenCL", 1);
51 static const struct {
52 const char *name;
53 IV iv;
54 } *civ, const_iv[] = { 115 static const ivstr *civ, const_iv[] = {
55#define const_iv(name) { # name, (IV)CL_ ## name }, 116 { sizeof (cl_char ), "SIZEOF_CHAR" },
117 { sizeof (cl_uchar ), "SIZEOF_UCHAR" },
118 { sizeof (cl_short ), "SIZEOF_SHORT" },
119 { sizeof (cl_ushort), "SIZEOF_USHORT"},
120 { sizeof (cl_int ), "SIZEOF_INT" },
121 { sizeof (cl_uint ), "SIZEOF_UINT" },
122 { sizeof (cl_long ), "SIZEOF_LONG" },
123 { sizeof (cl_ulong ), "SIZEOF_ULONG" },
124 { sizeof (cl_half ), "SIZEOF_HALF" },
125 { sizeof (cl_float ), "SIZEOF_FLOAT" },
56#include "constiv.h" 126#include "constiv.h"
57 }; 127 };
58 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 128 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
59 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 129 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
60} 130}
61 131
132const char *
133err2str (cl_int err)
134
135const char *
136enum2str (cl_uint value)
137
62void 138void
63platforms () 139platforms ()
64 PPCODE: 140 PPCODE:
65{ 141{
66 cl_platform_id *list; 142 cl_platform_id *list;
67 cl_uint count; 143 cl_uint count;
68 int i; 144 int i;
69 145
70 NEED_SUCCESS (clGetPlatformIDs, (0, 0, &count)); 146 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count));
71 Newx (list, count, cl_platform_id); 147 Newx (list, count, cl_platform_id);
72 NEED_SUCCESS (clGetPlatformIDs, (count, list, 0)); 148 NEED_SUCCESS (GetPlatformIDs, (count, list, 0));
73 149
74 EXTEND (SP, count); 150 EXTEND (SP, count);
75 for (i = 0; i < count; ++i) 151 for (i = 0; i < count; ++i)
76 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Platform", list [i])); 152 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i]));
77 153
78 Safefree (list); 154 Safefree (list);
79} 155}
80 156
81void 157void
84{ 160{
85 cl_int res; 161 cl_int res;
86 cl_context ctx = clCreateContextFromType (0, type, 0, 0, &res); 162 cl_context ctx = clCreateContextFromType (0, type, 0, 0, &res);
87 163
88 if (res) 164 if (res)
89 FAIL (clCreateContextFromType, res); 165 FAIL (CreateContextFromType, res);
90 166
91 XPUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Context", ctx)); 167 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
92} 168}
169
170void
171wait_for_events (...)
172 CODE:
173{
174 EVENT_LIST (0, items);
175 NEED_SUCCESS (WaitForEvents, (event_list_count, event_list_ptr));
176}
177
178PROTOTYPES: DISABLE
93 179
94MODULE = OpenCL PACKAGE = OpenCL::Platform 180MODULE = OpenCL PACKAGE = OpenCL::Platform
95 181
96void 182void
97info (OpenCL::Platform this, cl_platform_info name) 183info (OpenCL::Platform this, cl_platform_info name)
184 PPCODE:
185 INFO (Platform)
186
187void
188devices (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_ALL)
189 PPCODE:
190{
191 cl_device_id *list;
192 cl_uint count;
193 int i;
194
195 NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count));
196 Newx (list, count, cl_device_id);
197 NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0));
198
199 EXTEND (SP, count);
200 for (i = 0; i < count; ++i)
201 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i]));
202
203 Safefree (list);
204}
205
206void
207context_from_type_simple (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_DEFAULT)
208 PPCODE:
209{
210 cl_int res;
211 cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)this, 0 };
212 cl_context ctx = clCreateContextFromType (props, type, 0, 0, &res);
213
214 if (res)
215 FAIL (CreateContextFromType, res);
216
217 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
218}
219
220MODULE = OpenCL PACKAGE = OpenCL::Device
221
222void
223info (OpenCL::Device this, cl_device_info name)
224 PPCODE:
225 INFO (Device)
226
227void
228context_simple (OpenCL::Device this)
229 PPCODE:
230{
231 cl_int res;
232 cl_context ctx = clCreateContext (0, 1, &this, 0, 0, &res);
233
234 if (res)
235 FAIL (CreateContext, res);
236
237 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
238}
239
240MODULE = OpenCL PACKAGE = OpenCL::Context
241
242void
243DESTROY (OpenCL::Context context)
244 CODE:
245 clReleaseContext (context);
246
247void
248info (OpenCL::Context this, cl_context_info name)
249 PPCODE:
250 INFO (Context)
251
252void
253command_queue_simple (OpenCL::Context this, OpenCL::Device device)
254 PPCODE:
255{
256 cl_int res;
257 cl_command_queue queue = clCreateCommandQueue (this, device, 0, &res);
258
259 if (res)
260 FAIL (CreateCommandQueue, res);
261
262 XPUSH_NEW_OBJ ("OpenCL::Queue", queue);
263}
264
265void
266buffer (OpenCL::Context this, cl_mem_flags flags, size_t len)
267 PPCODE:
268{
269 cl_int res;
270 cl_mem mem;
271
272 if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
273 croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?");
274
275 mem = clCreateBuffer (this, flags, len, 0, &res);
276
277 if (res)
278 FAIL (CreateBuffer, res);
279
280 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
281}
282
283void
284buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data)
285 PPCODE:
286{
287 STRLEN len;
288 char *ptr = SvPVbyte (data, len);
289 cl_int res;
290 cl_mem mem;
291
292 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
293 croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
294
295 mem = clCreateBuffer (this, flags, len, ptr, &res);
296
297 if (res)
298 FAIL (CreateBuffer, res);
299
300 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
301}
302
303void
304image2d (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)
305 PPCODE:
306{
307 STRLEN len;
308 char *ptr = SvPVbyte (data, len);
309 const cl_image_format format = { channel_order, channel_type };
310 cl_int res;
311 cl_mem mem = clCreateImage2D (this, flags, &format, width, height, len / height, ptr, &res);
312
313 if (res)
314 FAIL (CreateImage2D, res);
315
316 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
317}
318
319void
320image3d (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)
321 PPCODE:
322{
323 STRLEN len;
324 char *ptr = SvPVbyte (data, len);
325 const cl_image_format format = { channel_order, channel_type };
326 cl_int res;
327 cl_mem mem = clCreateImage3D (this, flags, &format, width, height,
328 depth, len / (height * slice_pitch), slice_pitch, ptr, &res);
329
330 if (res)
331 FAIL (CreateImage3D, res);
332
333 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
334}
335
336void
337supported_image_formats (OpenCL::Context this, cl_mem_flags flags, cl_mem_object_type image_type)
338 PPCODE:
339{
340 cl_uint count;
341 cl_image_format *list;
342 int i;
343
344 NEED_SUCCESS (GetSupportedImageFormats, (this, flags, image_type, 0, 0, &count));
345 Newx (list, count, cl_image_format);
346 NEED_SUCCESS (GetSupportedImageFormats, (this, flags, image_type, count, list, 0));
347
348 EXTEND (SP, count);
349 for (i = 0; i < count; ++i)
350 {
351 AV *av = newAV ();
352 av_store (av, 1, newSVuv (list [i].image_channel_data_type));
353 av_store (av, 0, newSVuv (list [i].image_channel_order));
354 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
355 }
356}
357
358void
359sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode)
360 PPCODE:
361{
362 cl_int res;
363 cl_sampler sampler = clCreateSampler (this, normalized_coords, addressing_mode, filter_mode, &res);
364
365 if (res)
366 FAIL (CreateSampler, res);
367
368 XPUSH_NEW_OBJ ("OpenCL::Sampler", sampler);
369}
370
371void
372program_with_source (OpenCL::Context this, SV *program)
373 PPCODE:
374{
375 STRLEN len;
376 size_t len2;
377 const char *ptr = SvPVbyte (program, len);
378 cl_int res;
379 cl_program prog;
380
381 len2 = len;
382 prog = clCreateProgramWithSource (this, 1, &ptr, &len2, &res);
383
384 if (res)
385 FAIL (CreateProgramWithSource, res);
386
387 XPUSH_NEW_OBJ ("OpenCL::Program", prog);
388}
389
390MODULE = OpenCL PACKAGE = OpenCL::Queue
391
392void
393DESTROY (OpenCL::Queue this)
394 CODE:
395 clReleaseCommandQueue (this);
396
397void
398info (OpenCL::Queue this, cl_command_queue_info name)
399 PPCODE:
400 INFO (CommandQueue)
401
402void
403enqueue_read_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...)
404 PPCODE:
405{
406 cl_event ev = 0;
407 EVENT_LIST (6, items - 6);
408
409 SvUPGRADE (data, SVt_PV);
410 SvGROW (data, len);
411 SvPOK_only (data);
412 SvCUR_set (data, len);
413 NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
414
415 if (ev)
416 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
417}
418
419void
420enqueue_write_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...)
421 PPCODE:
422{
423 cl_event ev = 0;
424 STRLEN len;
425 char *ptr = SvPVbyte (data, len);
426 EVENT_LIST (5, items - 5);
427
428 NEED_SUCCESS (EnqueueReadBuffer, (this, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
429
430 if (ev)
431 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
432}
433
434void
435enqueue_copy_buffer (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...)
436 PPCODE:
437{
438 cl_event ev = 0;
439 EVENT_LIST (6, items - 6);
440
441 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
442
443 if (ev)
444 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
445}
446
447 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBufferRect.html */
448 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html */
449
450void
451enqueue_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, ...)
452 PPCODE:
453{
454 cl_event ev = 0;
455 const size_t src_origin[3] = { src_x, src_y, src_z };
456 const size_t region[3] = { width, height, depth };
457 size_t len = row_pitch * slice_pitch * depth;
458 EVENT_LIST (11, items - 11);
459
460 SvUPGRADE (data, SVt_PV);
461 SvGROW (data, len);
462 SvPOK_only (data);
463 SvCUR_set (data, len);
464 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));
465
466 if (ev)
467 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
468}
469
470void
471enqueue_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, ...)
472 PPCODE:
473{
474 cl_event ev = 0;
475 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
476 const size_t region[3] = { width, height, depth };
477 STRLEN len;
478 char *ptr = SvPVbyte (data, len);
479 size_t slice_pitch = len / (row_pitch * height);
480 EVENT_LIST (11, items - 11);
481
482 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));
483
484 if (ev)
485 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
486}
487
488void
489enqueue_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, ...)
490 PPCODE:
491{
492 cl_event ev = 0;
493 const size_t src_origin[3] = { src_x, src_y, src_z };
494 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
495 const size_t region[3] = { width, height, depth };
496 EVENT_LIST (16, items - 16);
497
498 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));
499
500 if (ev)
501 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
502}
503
504void
505enqueue_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, ...)
506 PPCODE:
507{
508 cl_event ev = 0;
509 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
510 const size_t region[3] = { width, height, depth };
511 EVENT_LIST (10, items - 10);
512
513 NEED_SUCCESS (EnqueueCopyBufferToImage, (this, src, dst, src_offset, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
514
515 if (ev)
516 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
517}
518
519void
520enqueue_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, ...)
521 PPCODE:
522{
523 cl_event ev = 0;
524 const size_t src_origin[3] = { src_x, src_y, src_z };
525 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
526 const size_t region[3] = { width, height, depth };
527 EVENT_LIST (12, items - 12);
528
529 NEED_SUCCESS (EnqueueCopyImage, (this, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
530
531 if (ev)
532 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
533}
534
535void
536enqueue_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, ...)
537 PPCODE:
538{
539 cl_event ev = 0;
540 const size_t src_origin[3] = { src_x, src_y, src_z };
541 const size_t region[3] = { width, height, depth };
542 EVENT_LIST (10, items - 10);
543
544 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
545
546 if (ev)
547 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
548}
549
550void
551enqueue_task (OpenCL::Queue this, OpenCL::Kernel kernel, ...)
552 PPCODE:
553{
554 cl_event ev = 0;
555 EVENT_LIST (2, items - 2);
556
557 NEED_SUCCESS (EnqueueTask, (this, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
558
559 if (ev)
560 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
561}
562
563 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueNDRangeKernel.html */
564
565void
566enqueue_marker (OpenCL::Queue this)
567 PPCODE:
568{
569 cl_event ev;
570 NEED_SUCCESS (EnqueueMarker, (this, &ev));
571 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
572}
573
574void
575enqueue_wait_for_events (OpenCL::Queue this, ...)
576 CODE:
577{
578 EVENT_LIST (1, items - 1);
579 NEED_SUCCESS (EnqueueWaitForEvents, (this, event_list_count, event_list_ptr));
580}
581
582void
583enqueue_barrier (OpenCL::Queue this)
584 CODE:
585 NEED_SUCCESS (EnqueueBarrier, (this));
586
587void
588flush (OpenCL::Queue this)
589 CODE:
590 NEED_SUCCESS (Flush, (this));
591
592void
593finish (OpenCL::Queue this)
594 CODE:
595 NEED_SUCCESS (Finish, (this));
596
597MODULE = OpenCL PACKAGE = OpenCL::Memory
598
599void
600DESTROY (OpenCL::Memory this)
601 CODE:
602 clReleaseMemObject (this);
603
604void
605info (OpenCL::Memory this, cl_mem_info name)
606 PPCODE:
607 INFO (MemObject)
608
609MODULE = OpenCL PACKAGE = OpenCL::Sampler
610
611void
612DESTROY (OpenCL::Sampler this)
613 CODE:
614 clReleaseSampler (this);
615
616void
617info (OpenCL::Sampler this, cl_sampler_info name)
618 PPCODE:
619 INFO (Sampler)
620
621MODULE = OpenCL PACKAGE = OpenCL::Program
622
623void
624DESTROY (OpenCL::Program this)
625 CODE:
626 clReleaseProgram (this);
627
628void
629info (OpenCL::Program this, cl_program_info name)
630 PPCODE:
631 INFO (Program)
632
633void
634build (OpenCL::Program this, OpenCL::Device device, SV *options = &PL_sv_undef)
635 CODE:
636 NEED_SUCCESS (BuildProgram, (this, 1, &device, SvPVbyte_nolen (options), 0, 0));
637
638void
639build_info (OpenCL::Program this, OpenCL::Device device, cl_program_build_info name)
98 PPCODE: 640 PPCODE:
99{ 641{
100 size_t size; 642 size_t size;
101 SV *sv; 643 SV *sv;
102 644
103 NEED_SUCCESS (clGetPlatformInfo, (this, name, 0, 0, &size)); 645 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, 0, 0, &size));
104 sv = sv_2mortal (newSV (size)); 646 sv = sv_2mortal (newSV (size));
105 SvUPGRADE (sv, SVt_PV); 647 SvUPGRADE (sv, SVt_PV);
106 SvPOK_only (sv); 648 SvPOK_only (sv);
107 SvCUR_set (sv, size); 649 SvCUR_set (sv, size);
108 NEED_SUCCESS (clGetPlatformInfo, (this, name, size, SvPVX (sv), 0)); 650 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, size, SvPVX (sv), 0));
109 XPUSHs (sv); 651 XPUSHs (sv);
110} 652}
111 653
112void 654void
113devices (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_ALL) 655kernel (OpenCL::Program program, SV *function)
114 PPCODE:
115{
116 cl_device_id *list;
117 cl_uint count;
118 int i;
119
120 NEED_SUCCESS (clGetDeviceIDs, (this, type, 0, 0, &count));
121 Newx (list, count, cl_device_id);
122 NEED_SUCCESS (clGetDeviceIDs, (this, type, count, list, 0));
123
124 EXTEND (SP, count);
125 for (i = 0; i < count; ++i)
126 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i]));
127
128 Safefree (list);
129}
130
131void
132context_from_type_simple (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_DEFAULT)
133 PPCODE:
134{
135 cl_int res;
136 cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)this, 0 };
137 cl_context ctx = clCreateContextFromType (props, type, 0, 0, &res);
138
139 if (res)
140 FAIL (clCreateContextFromType, res);
141
142 XPUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Context", ctx));
143}
144
145MODULE = OpenCL PACKAGE = OpenCL::Device
146
147void
148info (OpenCL::Device this, cl_device_info name)
149 PPCODE:
150{
151 size_t size;
152 SV *sv;
153
154 NEED_SUCCESS (clGetDeviceInfo, (this, name, 0, 0, &size));
155 sv = sv_2mortal (newSV (size));
156 SvUPGRADE (sv, SVt_PV);
157 SvPOK_only (sv);
158 SvCUR_set (sv, size);
159 NEED_SUCCESS (clGetDeviceInfo, (this, name, size, SvPVX (sv), 0));
160 XPUSHs (sv);
161}
162
163void
164context_simple (OpenCL::Device this)
165 PPCODE:
166{
167 cl_int res;
168 cl_context ctx = clCreateContext (0, 1, &this, 0, 0, &res);
169
170 if (res)
171 FAIL (clCreateContext, res);
172
173 XPUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Context", ctx));
174}
175
176MODULE = OpenCL PACKAGE = OpenCL::Context
177
178void
179DESTROY (OpenCL::Context context)
180 CODE: 656 PPCODE:
181 clReleaseContext (context);
182
183void
184info (OpenCL::Context this, cl_context_info name)
185 PPCODE:
186{ 657{
187 size_t size;
188 SV *sv;
189
190 NEED_SUCCESS (clGetContextInfo, (this, name, 0, 0, &size));
191 sv = sv_2mortal (newSV (size));
192 SvUPGRADE (sv, SVt_PV);
193 SvPOK_only (sv);
194 SvCUR_set (sv, size);
195 NEED_SUCCESS (clGetContextInfo, (this, name, size, SvPVX (sv), 0));
196 XPUSHs (sv);
197}
198
199void
200command_queue_simple (OpenCL::Context this, OpenCL::Device device)
201 PPCODE:
202{
203 cl_int res; 658 cl_int res;
204 cl_command_queue queue = clCreateCommandQueue (this, device, 0, &res); 659 cl_kernel kernel = clCreateKernel (program, SvPVbyte_nolen (function), &res);
205 660
206 if (res) 661 if (res)
207 FAIL (clCreateCommandQueue, res); 662 FAIL (CreateKernel, res);
208 663
209 XPUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Queue", queue)); 664 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel);
210} 665}
211 666
212MODULE = OpenCL PACKAGE = OpenCL::Queue 667MODULE = OpenCL PACKAGE = OpenCL::Kernel
213 668
214void 669void
215DESTROY (OpenCL::Queue this) 670DESTROY (OpenCL::Kernel this)
216 CODE:
217 clReleaseCommandQueue (this);
218
219void
220info (OpenCL::Queue this, cl_command_queue_info name)
221 PPCODE: 671 CODE:
222{ 672 clReleaseKernel (this);
223 size_t size;
224 SV *sv;
225 673
226 NEED_SUCCESS (clGetCommandQueueInfo, (this, name, 0, 0, &size)); 674void
227 sv = sv_2mortal (newSV (size)); 675info (OpenCL::Kernel this, cl_kernel_info name)
228 SvUPGRADE (sv, SVt_PV); 676 PPCODE:
229 SvPOK_only (sv); 677 INFO (Kernel)
230 SvCUR_set (sv, size);
231 NEED_SUCCESS (clGetCommandQueueInfo, (this, name, size, SvPVX (sv), 0));
232 XPUSHs (sv);
233}
234 678
679void
680set_char (OpenCL::Kernel this, cl_uint idx, cl_char value)
681 CODE:
682 clSetKernelArg (this, idx, sizeof (value), &value);
683
684void
685set_uchar (OpenCL::Kernel this, cl_uint idx, cl_uchar value)
686 CODE:
687 clSetKernelArg (this, idx, sizeof (value), &value);
688
689void
690set_short (OpenCL::Kernel this, cl_uint idx, cl_short value)
691 CODE:
692 clSetKernelArg (this, idx, sizeof (value), &value);
693
694void
695set_ushort (OpenCL::Kernel this, cl_uint idx, cl_ushort value)
696 CODE:
697 clSetKernelArg (this, idx, sizeof (value), &value);
698
699void
700set_int (OpenCL::Kernel this, cl_uint idx, cl_int value)
701 CODE:
702 clSetKernelArg (this, idx, sizeof (value), &value);
703
704void
705set_uint (OpenCL::Kernel this, cl_uint idx, cl_uint value)
706 CODE:
707 clSetKernelArg (this, idx, sizeof (value), &value);
708
709void
710set_long (OpenCL::Kernel this, cl_uint idx, cl_long value)
711 CODE:
712 clSetKernelArg (this, idx, sizeof (value), &value);
713
714void
715set_ulong (OpenCL::Kernel this, cl_uint idx, cl_ulong value)
716 CODE:
717 clSetKernelArg (this, idx, sizeof (value), &value);
718
719void
720set_half (OpenCL::Kernel this, cl_uint idx, cl_half value)
721 CODE:
722 clSetKernelArg (this, idx, sizeof (value), &value);
723
724void
725set_float (OpenCL::Kernel this, cl_uint idx, cl_float value)
726 CODE:
727 clSetKernelArg (this, idx, sizeof (value), &value);
728
729void
730set_memory (OpenCL::Kernel this, cl_uint idx, OpenCL::Memory_ornull value)
731 CODE:
732 clSetKernelArg (this, idx, sizeof (value), &value);
733
734void
735set_buffer (OpenCL::Kernel this, cl_uint idx, OpenCL::Buffer_ornull value)
736 CODE:
737 clSetKernelArg (this, idx, sizeof (value), &value);
738
739void
740set_image2d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image2D_ornull value)
741 CODE:
742 clSetKernelArg (this, idx, sizeof (value), &value);
743
744void
745set_image3d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image3D_ornull value)
746 CODE:
747 clSetKernelArg (this, idx, sizeof (value), &value);
748
749void
750set_sampler (OpenCL::Kernel this, cl_uint idx, OpenCL::Sampler value)
751 CODE:
752 clSetKernelArg (this, idx, sizeof (value), &value);
753
754void
755set_event (OpenCL::Kernel this, cl_uint idx, OpenCL::Event value)
756 CODE:
757 clSetKernelArg (this, idx, sizeof (value), &value);
758
759MODULE = OpenCL PACKAGE = OpenCL::Event
760
761void
762DESTROY (OpenCL::Event this)
763 CODE:
764 clReleaseEvent (this);
765
766void
767info (OpenCL::Event this, cl_event_info name)
768 PPCODE:
769 INFO (Event)
770
771void
772wait (OpenCL::Event this)
773 CODE:
774 clWaitForEvents (1, &this);
775

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines