ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/OpenCL/OpenCL.xs
Revision: 1.3
Committed: Tue Nov 15 20:38:07 2011 UTC (12 years, 6 months ago) by root
Branch: MAIN
Changes since 1.2: +344 -32 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4
5 #include <CL/opencl.h>
6
7 typedef cl_platform_id OpenCL__Platform;
8 typedef cl_device_id OpenCL__Device;
9 typedef cl_context OpenCL__Context;
10 typedef cl_command_queue OpenCL__Queue;
11 typedef cl_mem OpenCL__Memory;
12 typedef cl_mem OpenCL__Buffer;
13 typedef cl_mem OpenCL__Image;
14 typedef cl_mem OpenCL__Image2D;
15 typedef cl_mem OpenCL__Image3D;
16 typedef cl_mem OpenCL__Memory_ornull;
17 typedef cl_mem OpenCL__Buffer_ornull;
18 typedef cl_mem OpenCL__Image_ornull;
19 typedef cl_mem OpenCL__Image2D_ornull;
20 typedef cl_mem OpenCL__Image3D_ornull;
21 typedef cl_sampler OpenCL__Sampler;
22 typedef cl_program OpenCL__Program;
23 typedef cl_kernel OpenCL__Kernel;
24 typedef cl_event OpenCL__Event;
25
26 typedef struct
27 {
28 IV iv;
29 const char *name;
30 #define const_iv(name) { (IV)CL_ ## name, # name },
31 } ivstr;
32
33 static const char *
34 iv2str (IV value, const ivstr *base, int count, const char *fallback)
35 {
36 int i;
37 static char strbuf [32];
38
39 for (i = count; i--; )
40 if (base [i].iv == value)
41 return base [i].name;
42
43 snprintf (strbuf, sizeof (strbuf), fallback, (int)value);
44
45 return strbuf;
46 }
47
48 static const char *
49 enum2str (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
58 static const char *
59 err2str (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)");
66 }
67
68 #define FAIL(name,res) \
69 croak ("cl" # name ": %s", err2str (res));
70
71 #define NEED_SUCCESS(name,args) \
72 do { \
73 cl_int res = cl ## name args; \
74 \
75 if (res) \
76 FAIL (name, res); \
77 } while (0)
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
99 static void *
100 SvPTROBJ (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
108 MODULE = OpenCL PACKAGE = OpenCL
109
110 PROTOTYPES: ENABLE
111
112 BOOT:
113 {
114 HV *stash = gv_stashpv ("OpenCL", 1);
115 static const ivstr *civ, const_iv[] = {
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" },
126 #include "constiv.h"
127 };
128 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
129 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
130 }
131
132 const char *
133 err2str (cl_int err)
134
135 const char *
136 enum2str (cl_uint value)
137
138 void
139 platforms ()
140 PPCODE:
141 {
142 cl_platform_id *list;
143 cl_uint count;
144 int i;
145
146 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count));
147 Newx (list, count, cl_platform_id);
148 NEED_SUCCESS (GetPlatformIDs, (count, list, 0));
149
150 EXTEND (SP, count);
151 for (i = 0; i < count; ++i)
152 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i]));
153
154 Safefree (list);
155 }
156
157 void
158 context_from_type_simple (cl_device_type type = CL_DEVICE_TYPE_DEFAULT)
159 PPCODE:
160 {
161 cl_int res;
162 cl_context ctx = clCreateContextFromType (0, type, 0, 0, &res);
163
164 if (res)
165 FAIL (CreateContextFromType, res);
166
167 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
168 }
169
170 void
171 wait_for_events (...)
172 CODE:
173 {
174 EVENT_LIST (0, items);
175 NEED_SUCCESS (WaitForEvents, (event_list_count, event_list_ptr));
176 }
177
178 PROTOTYPES: DISABLE
179
180 MODULE = OpenCL PACKAGE = OpenCL::Platform
181
182 void
183 info (OpenCL::Platform this, cl_platform_info name)
184 PPCODE:
185 INFO (Platform)
186
187 void
188 devices (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
206 void
207 context_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
220 MODULE = OpenCL PACKAGE = OpenCL::Device
221
222 void
223 info (OpenCL::Device this, cl_device_info name)
224 PPCODE:
225 INFO (Device)
226
227 void
228 context_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
240 MODULE = OpenCL PACKAGE = OpenCL::Context
241
242 void
243 DESTROY (OpenCL::Context context)
244 CODE:
245 clReleaseContext (context);
246
247 void
248 info (OpenCL::Context this, cl_context_info name)
249 PPCODE:
250 INFO (Context)
251
252 void
253 command_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
265 void
266 buffer (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
283 void
284 buffer_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
303 void
304 image2d (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
319 void
320 image3d (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
336 void
337 supported_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
358 void
359 sampler (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
371 void
372 program_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
390 MODULE = OpenCL PACKAGE = OpenCL::Queue
391
392 void
393 DESTROY (OpenCL::Queue this)
394 CODE:
395 clReleaseCommandQueue (this);
396
397 void
398 info (OpenCL::Queue this, cl_command_queue_info name)
399 PPCODE:
400 INFO (CommandQueue)
401
402 void
403 enqueue_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
419 void
420 enqueue_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
434 void
435 enqueue_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
450 void
451 enqueue_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
470 void
471 enqueue_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
488 void
489 enqueue_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
504 void
505 enqueue_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
519 void
520 enqueue_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
535 void
536 enqueue_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
550 void
551 enqueue_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
565 void
566 enqueue_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
574 void
575 enqueue_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
582 void
583 enqueue_barrier (OpenCL::Queue this)
584 CODE:
585 NEED_SUCCESS (EnqueueBarrier, (this));
586
587 void
588 flush (OpenCL::Queue this)
589 CODE:
590 NEED_SUCCESS (Flush, (this));
591
592 void
593 finish (OpenCL::Queue this)
594 CODE:
595 NEED_SUCCESS (Finish, (this));
596
597 MODULE = OpenCL PACKAGE = OpenCL::Memory
598
599 void
600 DESTROY (OpenCL::Memory this)
601 CODE:
602 clReleaseMemObject (this);
603
604 void
605 info (OpenCL::Memory this, cl_mem_info name)
606 PPCODE:
607 INFO (MemObject)
608
609 MODULE = OpenCL PACKAGE = OpenCL::Sampler
610
611 void
612 DESTROY (OpenCL::Sampler this)
613 CODE:
614 clReleaseSampler (this);
615
616 void
617 info (OpenCL::Sampler this, cl_sampler_info name)
618 PPCODE:
619 INFO (Sampler)
620
621 MODULE = OpenCL PACKAGE = OpenCL::Program
622
623 void
624 DESTROY (OpenCL::Program this)
625 CODE:
626 clReleaseProgram (this);
627
628 void
629 info (OpenCL::Program this, cl_program_info name)
630 PPCODE:
631 INFO (Program)
632
633 void
634 build (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
638 void
639 build_info (OpenCL::Program this, OpenCL::Device device, cl_program_build_info name)
640 PPCODE:
641 {
642 size_t size;
643 SV *sv;
644
645 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, 0, 0, &size));
646 sv = sv_2mortal (newSV (size));
647 SvUPGRADE (sv, SVt_PV);
648 SvPOK_only (sv);
649 SvCUR_set (sv, size);
650 NEED_SUCCESS (GetProgramBuildInfo, (this, device, name, size, SvPVX (sv), 0));
651 XPUSHs (sv);
652 }
653
654 void
655 kernel (OpenCL::Program program, SV *function)
656 PPCODE:
657 {
658 cl_int res;
659 cl_kernel kernel = clCreateKernel (program, SvPVbyte_nolen (function), &res);
660
661 if (res)
662 FAIL (CreateKernel, res);
663
664 XPUSH_NEW_OBJ ("OpenCL::Kernel", kernel);
665 }
666
667 MODULE = OpenCL PACKAGE = OpenCL::Kernel
668
669 void
670 DESTROY (OpenCL::Kernel this)
671 CODE:
672 clReleaseKernel (this);
673
674 void
675 info (OpenCL::Kernel this, cl_kernel_info name)
676 PPCODE:
677 INFO (Kernel)
678
679 void
680 set_char (OpenCL::Kernel this, cl_uint idx, cl_char value)
681 CODE:
682 clSetKernelArg (this, idx, sizeof (value), &value);
683
684 void
685 set_uchar (OpenCL::Kernel this, cl_uint idx, cl_uchar value)
686 CODE:
687 clSetKernelArg (this, idx, sizeof (value), &value);
688
689 void
690 set_short (OpenCL::Kernel this, cl_uint idx, cl_short value)
691 CODE:
692 clSetKernelArg (this, idx, sizeof (value), &value);
693
694 void
695 set_ushort (OpenCL::Kernel this, cl_uint idx, cl_ushort value)
696 CODE:
697 clSetKernelArg (this, idx, sizeof (value), &value);
698
699 void
700 set_int (OpenCL::Kernel this, cl_uint idx, cl_int value)
701 CODE:
702 clSetKernelArg (this, idx, sizeof (value), &value);
703
704 void
705 set_uint (OpenCL::Kernel this, cl_uint idx, cl_uint value)
706 CODE:
707 clSetKernelArg (this, idx, sizeof (value), &value);
708
709 void
710 set_long (OpenCL::Kernel this, cl_uint idx, cl_long value)
711 CODE:
712 clSetKernelArg (this, idx, sizeof (value), &value);
713
714 void
715 set_ulong (OpenCL::Kernel this, cl_uint idx, cl_ulong value)
716 CODE:
717 clSetKernelArg (this, idx, sizeof (value), &value);
718
719 void
720 set_half (OpenCL::Kernel this, cl_uint idx, cl_half value)
721 CODE:
722 clSetKernelArg (this, idx, sizeof (value), &value);
723
724 void
725 set_float (OpenCL::Kernel this, cl_uint idx, cl_float value)
726 CODE:
727 clSetKernelArg (this, idx, sizeof (value), &value);
728
729 void
730 set_memory (OpenCL::Kernel this, cl_uint idx, OpenCL::Memory_ornull value)
731 CODE:
732 clSetKernelArg (this, idx, sizeof (value), &value);
733
734 void
735 set_buffer (OpenCL::Kernel this, cl_uint idx, OpenCL::Buffer_ornull value)
736 CODE:
737 clSetKernelArg (this, idx, sizeof (value), &value);
738
739 void
740 set_image2d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image2D_ornull value)
741 CODE:
742 clSetKernelArg (this, idx, sizeof (value), &value);
743
744 void
745 set_image3d (OpenCL::Kernel this, cl_uint idx, OpenCL::Image3D_ornull value)
746 CODE:
747 clSetKernelArg (this, idx, sizeof (value), &value);
748
749 void
750 set_sampler (OpenCL::Kernel this, cl_uint idx, OpenCL::Sampler value)
751 CODE:
752 clSetKernelArg (this, idx, sizeof (value), &value);
753
754 void
755 set_event (OpenCL::Kernel this, cl_uint idx, OpenCL::Event value)
756 CODE:
757 clSetKernelArg (this, idx, sizeof (value), &value);
758
759 MODULE = OpenCL PACKAGE = OpenCL::Event
760
761 void
762 DESTROY (OpenCL::Event this)
763 CODE:
764 clReleaseEvent (this);
765
766 void
767 info (OpenCL::Event this, cl_event_info name)
768 PPCODE:
769 INFO (Event)
770
771 void
772 wait (OpenCL::Event this)
773 CODE:
774 clWaitForEvents (1, &this);
775