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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.2 by root, Tue Nov 15 09:24:40 2011 UTC vs.
Revision 1.7 by root, Thu Nov 17 02:10:39 2011 UTC

7typedef cl_platform_id OpenCL__Platform; 7typedef cl_platform_id OpenCL__Platform;
8typedef cl_device_id OpenCL__Device; 8typedef cl_device_id OpenCL__Device;
9typedef cl_context OpenCL__Context; 9typedef cl_context OpenCL__Context;
10typedef cl_command_queue OpenCL__Queue; 10typedef cl_command_queue OpenCL__Queue;
11typedef cl_mem OpenCL__Memory; 11typedef cl_mem OpenCL__Memory;
12typedef cl_mem OpenCL__Buffer;
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;
12typedef cl_sampler OpenCL__Sampler; 21typedef cl_sampler OpenCL__Sampler;
13typedef cl_program OpenCL__Program; 22typedef cl_program OpenCL__Program;
14typedef cl_kernel OpenCL__Kernel; 23typedef cl_kernel OpenCL__Kernel;
15typedef cl_event OpenCL__Event; 24typedef cl_event OpenCL__Event;
25typedef cl_event OpenCL__UserEvent;
16 26
17static const struct { 27typedef SV *FUTURE;
28
29/*****************************************************************************/
30
31/* up to two temporary buffers */
32static void *
33tmpbuf (size_t size)
34{
35 static int idx;
36 static void *buf [2];
37 static size_t len [2];
38
39 idx ^= 1;
40
41 if (len [idx] < size)
42 {
43 free (buf [idx]);
44 len [idx] = ((size + 31) & ~4095) + 4096 - 32;
45 buf [idx] = malloc (len [idx]);
46 }
47
48 return buf [idx];
49}
50
51/*****************************************************************************/
52
53typedef struct
54{
18 IV iv; 55 IV iv;
19 const char *name; 56 const char *name;
20} cl_error[] = {
21#define def_error(name) { (IV)CL_ ## name, # name }, 57 #define const_iv(name) { (IV)CL_ ## name, # name },
22#include "invalid.h" 58} ivstr;
23};
24 59
25static const char * 60static const char *
26clstrerror (cl_int res) 61iv2str (IV value, const ivstr *base, int count, const char *fallback)
27{ 62{
28 int i; 63 int i;
29 static char numbuf [32]; 64 static char strbuf [32];
30 65
31 for (i = sizeof (cl_error) / sizeof (cl_error [0]); i--; ) 66 for (i = count; i--; )
32 if (cl_error [i].iv == res) 67 if (base [i].iv == value)
33 return cl_error [i].name; 68 return base [i].name;
34 69
35 snprintf (numbuf, sizeof (numbuf), "ERROR(%d)", res); 70 snprintf (strbuf, sizeof (strbuf), fallback, (int)value);
36 71
37 return numbuf; 72 return strbuf;
38} 73}
39 74
75static const char *
76enum2str (cl_uint value)
77{
78 static const ivstr enumstr[] = {
79 #include "enumstr.h"
80 };
81
82 return iv2str (value, enumstr, sizeof (enumstr) / sizeof (enumstr [0]), "ENUM(0x%04x)");
83}
84
85static const char *
86err2str (cl_int err)
87{
88 static const ivstr errstr[] = {
89 #include "errstr.h"
90 };
91
92 return iv2str (err, errstr, sizeof (errstr) / sizeof (errstr [0]), "ERROR(%d)");
93}
94
95/*****************************************************************************/
96
97static cl_int last_error;
98
40#define FAIL(name,res) \ 99#define FAIL(name,err) \
41 croak ("cl" # name ": %s", clstrerror (res)); 100 croak ("cl" # name ": %s", err2str (last_error = err));
42 101
43#define NEED_SUCCESS(name,args) \ 102#define NEED_SUCCESS(name,args) \
44 do { \ 103 do { \
45 cl_int res = cl ## name args; \ 104 cl_int res = cl ## name args; \
46 \ 105 \
47 if (res) \ 106 if (res) \
48 FAIL (name, res); \ 107 FAIL (name, res); \
49 } while (0) 108 } while (0)
50 109
110/*****************************************************************************/
111
51#define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr) 112#define NEW_MORTAL_OBJ(class,ptr) sv_setref_pv (sv_newmortal (), class, ptr)
52#define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr)) 113#define XPUSH_NEW_OBJ(class,ptr) XPUSHs (NEW_MORTAL_OBJ (class, ptr))
53 114
54/*TODO*/ 115static void *
55#define EVENT_LIST(items,count) cl_uint event_list_count = 0; cl_event *event_list_ptr = 0 116SvPTROBJ (const char *func, const char *svname, SV *sv, const char *pkg)
117{
118 if (SvROK (sv) && sv_derived_from (sv, pkg))
119 return (void *)SvIV (SvRV (sv));
120
121 croak ("%s: %s is not of type %s", func, svname, pkg);
122}
123
124/*****************************************************************************/
125
126static cl_event *
127event_list (SV **items, int count)
128{
129 cl_event *list = tmpbuf (sizeof (cl_event) * count);
130
131 while (count--)
132 list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event");
133
134 return list;
135}
136
137#define EVENT_LIST(items,count) \
138 cl_uint event_list_count = (count); \
139 cl_event *event_list_ptr = event_list (&ST (items), event_list_count)
56 140
57#define INFO(class) \ 141#define INFO(class) \
58{ \ 142{ \
59 size_t size; \ 143 size_t size; \
60 SV *sv; \ 144 SV *sv; \
73PROTOTYPES: ENABLE 157PROTOTYPES: ENABLE
74 158
75BOOT: 159BOOT:
76{ 160{
77 HV *stash = gv_stashpv ("OpenCL", 1); 161 HV *stash = gv_stashpv ("OpenCL", 1);
78 static const struct {
79 const char *name;
80 IV iv;
81 } *civ, const_iv[] = { 162 static const ivstr *civ, const_iv[] = {
82#define const_iv(name) { # name, (IV)CL_ ## name }, 163 { sizeof (cl_char ), "SIZEOF_CHAR" },
164 { sizeof (cl_uchar ), "SIZEOF_UCHAR" },
165 { sizeof (cl_short ), "SIZEOF_SHORT" },
166 { sizeof (cl_ushort), "SIZEOF_USHORT" },
167 { sizeof (cl_int ), "SIZEOF_INT" },
168 { sizeof (cl_uint ), "SIZEOF_UINT" },
169 { sizeof (cl_long ), "SIZEOF_LONG" },
170 { sizeof (cl_ulong ), "SIZEOF_ULONG" },
171 { sizeof (cl_half ), "SIZEOF_HALF" },
172 { sizeof (cl_float ), "SIZEOF_FLOAT" },
173 { sizeof (cl_double), "SIZEOF_DOUBLE" },
83#include "constiv.h" 174#include "constiv.h"
84 }; 175 };
85 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 176 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
86 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 177 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
87} 178}
88 179
180cl_int
181errno ()
182 CODE:
183 errno = last_error;
184
185const char *
186err2str (cl_int err)
187
188const char *
189enum2str (cl_uint value)
190
89void 191void
90platforms () 192platforms ()
91 PPCODE: 193 PPCODE:
92{ 194{
93 cl_platform_id *list; 195 cl_platform_id *list;
94 cl_uint count; 196 cl_uint count;
95 int i; 197 int i;
96 198
97 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count)); 199 NEED_SUCCESS (GetPlatformIDs, (0, 0, &count));
98 Newx (list, count, cl_platform_id); 200 list = tmpbuf (sizeof (*list) * count);
99 NEED_SUCCESS (GetPlatformIDs, (count, list, 0)); 201 NEED_SUCCESS (GetPlatformIDs, (count, list, 0));
100 202
101 EXTEND (SP, count); 203 EXTEND (SP, count);
102 for (i = 0; i < count; ++i) 204 for (i = 0; i < count; ++i)
103 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); 205 PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i]));
104
105 Safefree (list);
106} 206}
107 207
108void 208void
109context_from_type_simple (cl_device_type type = CL_DEVICE_TYPE_DEFAULT) 209context_from_type (FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
110 PPCODE: 210 PPCODE:
111{ 211{
112 cl_int res; 212 cl_int res;
113 cl_context ctx = clCreateContextFromType (0, type, 0, 0, &res); 213 cl_context ctx = clCreateContextFromType (0, type, 0, 0, &res);
114 214
142 cl_device_id *list; 242 cl_device_id *list;
143 cl_uint count; 243 cl_uint count;
144 int i; 244 int i;
145 245
146 NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count)); 246 NEED_SUCCESS (GetDeviceIDs, (this, type, 0, 0, &count));
147 Newx (list, count, cl_device_id); 247 list = tmpbuf (sizeof (*list) * count);
148 NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0)); 248 NEED_SUCCESS (GetDeviceIDs, (this, type, count, list, 0));
149 249
150 EXTEND (SP, count); 250 EXTEND (SP, count);
151 for (i = 0; i < count; ++i) 251 for (i = 0; i < count; ++i)
152 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); 252 PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i]));
153
154 Safefree (list);
155} 253}
156 254
157void 255void
158context_from_type_simple (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_DEFAULT) 256context_from_type (OpenCL::Platform this, FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
159 PPCODE: 257 PPCODE:
160{ 258{
161 cl_int res; 259 cl_int res;
162 cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)this, 0 }; 260 cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)this, 0 };
163 cl_context ctx = clCreateContextFromType (props, type, 0, 0, &res); 261 cl_context ctx = clCreateContextFromType (props, type, 0, 0, &res);
166 FAIL (CreateContextFromType, res); 264 FAIL (CreateContextFromType, res);
167 265
168 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 266 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
169} 267}
170 268
171void
172unload_compiler ()
173 CODE:
174 NEED_SUCCESS (UnloadCompiler, ());
175
176MODULE = OpenCL PACKAGE = OpenCL::Device 269MODULE = OpenCL PACKAGE = OpenCL::Device
177 270
178void 271void
179info (OpenCL::Device this, cl_device_info name) 272info (OpenCL::Device this, cl_device_info name)
180 PPCODE: 273 PPCODE:
181 INFO (Device) 274 INFO (Device)
182 275
183void 276void
184context_simple (OpenCL::Device this) 277context (OpenCL::Device this, FUTURE properties = 0, FUTURE notify = 0)
185 PPCODE: 278 PPCODE:
186{ 279{
187 cl_int res; 280 cl_int res;
188 cl_context ctx = clCreateContext (0, 1, &this, 0, 0, &res); 281 cl_context ctx = clCreateContext (0, 1, &this, 0, 0, &res);
189 282
204info (OpenCL::Context this, cl_context_info name) 297info (OpenCL::Context this, cl_context_info name)
205 PPCODE: 298 PPCODE:
206 INFO (Context) 299 INFO (Context)
207 300
208void 301void
209command_queue_simple (OpenCL::Context this, OpenCL::Device device) 302queue (OpenCL::Context this, OpenCL::Device device, cl_command_queue_properties properties = 0)
210 PPCODE: 303 PPCODE:
211{ 304{
212 cl_int res; 305 cl_int res;
213 cl_command_queue queue = clCreateCommandQueue (this, device, 0, &res); 306 cl_command_queue queue = clCreateCommandQueue (this, device, properties, &res);
214 307
215 if (res) 308 if (res)
216 FAIL (CreateCommandQueue, res); 309 FAIL (CreateCommandQueue, res);
217 310
218 XPUSH_NEW_OBJ ("OpenCL::Queue", queue); 311 XPUSH_NEW_OBJ ("OpenCL::Queue", queue);
219} 312}
220 313
221void 314void
315user_event (OpenCL::Context this)
316 PPCODE:
317{
318 cl_int res;
319 cl_event ev = clCreateUserEvent (this, &res);
320
321 if (res)
322 FAIL (CreateUserevent, res);
323
324 XPUSH_NEW_OBJ ("OpenCL::UserEvent", ev);
325}
326
327void
222buffer (OpenCL::Context this, cl_mem_flags flags, size_t len) 328buffer (OpenCL::Context this, cl_mem_flags flags, size_t len)
223 PPCODE: 329 PPCODE:
224{ 330{
225 cl_int res; 331 cl_int res;
332 cl_mem mem;
333
334 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?");
336
226 cl_mem mem = clCreateBuffer (this, flags, len, 0, &res); 337 mem = clCreateBuffer (this, flags, len, 0, &res);
227 338
228 if (res) 339 if (res)
229 FAIL (CreateBuffer, res); 340 FAIL (CreateBuffer, res);
230 341
231 XPUSH_NEW_OBJ ("OpenCL::Memory", mem); 342 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
232} 343}
233 344
234void 345void
235buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data) 346buffer_sv (OpenCL::Context this, cl_mem_flags flags, SV *data)
236 PPCODE: 347 PPCODE:
237{ 348{
238 STRLEN len; 349 STRLEN len;
239 char *ptr = SvPVbyte (data, len); 350 char *ptr = SvPVbyte (data, len);
240 cl_int res; 351 cl_int res;
352 cl_mem mem;
353
354 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?");
356
241 cl_mem mem = clCreateBuffer (this, flags, len, ptr, &res); 357 mem = clCreateBuffer (this, flags, len, ptr, &res);
242 358
243 if (res) 359 if (res)
244 FAIL (CreateBuffer, res); 360 FAIL (CreateBuffer, res);
245 361
246 XPUSH_NEW_OBJ ("OpenCL::Memory", mem); 362 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
363}
364
365void
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)
367 PPCODE:
368{
369 STRLEN len;
370 char *ptr = SvPVbyte (data, len);
371 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);
374
375 if (res)
376 FAIL (CreateImage2D, res);
377
378 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
379}
380
381void
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)
383 PPCODE:
384{
385 STRLEN len;
386 char *ptr = SvPVbyte (data, len);
387 const cl_image_format format = { channel_order, channel_type };
388 cl_int 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);
396}
397
398void
399supported_image_formats (OpenCL::Context this, cl_mem_flags flags, cl_mem_object_type image_type)
400 PPCODE:
401{
402 cl_uint count;
403 cl_image_format *list;
404 int i;
405
406 NEED_SUCCESS (GetSupportedImageFormats, (this, flags, image_type, 0, 0, &count));
407 Newx (list, count, cl_image_format);
408 NEED_SUCCESS (GetSupportedImageFormats, (this, flags, image_type, count, list, 0));
409
410 EXTEND (SP, count);
411 for (i = 0; i < count; ++i)
412 {
413 AV *av = newAV ();
414 av_store (av, 1, newSVuv (list [i].image_channel_data_type));
415 av_store (av, 0, newSVuv (list [i].image_channel_order));
416 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
417 }
247} 418}
248 419
249void 420void
250sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode) 421sampler (OpenCL::Context this, cl_bool normalized_coords, cl_addressing_mode addressing_mode, cl_filter_mode filter_mode)
251 PPCODE: 422 PPCODE:
289info (OpenCL::Queue this, cl_command_queue_info name) 460info (OpenCL::Queue this, cl_command_queue_info name)
290 PPCODE: 461 PPCODE:
291 INFO (CommandQueue) 462 INFO (CommandQueue)
292 463
293void 464void
294enqueue_read_buffer (OpenCL::Queue this, OpenCL::Memory mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...) 465enqueue_read_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, size_t len, SV *data, ...)
295 PPCODE: 466 PPCODE:
296{ 467{
297 cl_event ev = 0; 468 cl_event ev = 0;
298 EVENT_LIST (6, items - 6); 469 EVENT_LIST (6, items - 6);
299 470
306 if (ev) 477 if (ev)
307 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 478 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
308} 479}
309 480
310void 481void
311enqueue_write_buffer (OpenCL::Queue this, OpenCL::Memory mem, cl_bool blocking, size_t offset, SV *data, ...) 482enqueue_write_buffer (OpenCL::Queue this, OpenCL::Buffer mem, cl_bool blocking, size_t offset, SV *data, ...)
312 PPCODE: 483 PPCODE:
313{ 484{
314 cl_event ev = 0; 485 cl_event ev = 0;
315 STRLEN len; 486 STRLEN len;
316 char *ptr = SvPVbyte (data, len); 487 char *ptr = SvPVbyte (data, len);
321 if (ev) 492 if (ev)
322 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 493 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
323} 494}
324 495
325void 496void
326enqueue_copy_buffer (OpenCL::Queue this, OpenCL::Memory src, OpenCL::Memory dst, size_t src_offset, size_t dst_offset, size_t len, ...) 497enqueue_copy_buffer (OpenCL::Queue this, OpenCL::Buffer src, OpenCL::Buffer dst, size_t src_offset, size_t dst_offset, size_t len, ...)
327 PPCODE: 498 PPCODE:
328{ 499{
329 cl_event ev = 0; 500 cl_event ev = 0;
330 EVENT_LIST (6, items - 6); 501 EVENT_LIST (6, items - 6);
331 502
332 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 503 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
504
505 if (ev)
506 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
507}
508
509 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBufferRect.html */
510 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html */
511
512void
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, ...)
514 PPCODE:
515{
516 cl_event ev = 0;
517 const size_t src_origin[3] = { src_x, src_y, src_z };
518 const size_t region[3] = { width, height, depth };
519 size_t len = row_pitch * slice_pitch * depth;
520 EVENT_LIST (11, items - 11);
521
522 SvUPGRADE (data, SVt_PV);
523 SvGROW (data, len);
524 SvPOK_only (data);
525 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));
527
528 if (ev)
529 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
530}
531
532void
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, ...)
534 PPCODE:
535{
536 cl_event ev = 0;
537 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
538 const size_t region[3] = { width, height, depth };
539 STRLEN len;
540 char *ptr = SvPVbyte (data, len);
541 size_t slice_pitch = len / (row_pitch * height);
542 EVENT_LIST (11, items - 11);
543
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));
545
546 if (ev)
547 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
548}
549
550void
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, ...)
583 PPCODE:
584{
585 cl_event ev = 0;
586 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 };
588 const size_t region[3] = { width, height, depth };
589 EVENT_LIST (12, items - 12);
590
591 NEED_SUCCESS (EnqueueCopyImage, (this, src, dst, src_origin, dst_origin, region, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
592
593 if (ev)
594 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
595}
596
597void
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, ...)
599 PPCODE:
600{
601 cl_event ev = 0;
602 const size_t src_origin[3] = { src_x, src_y, src_z };
603 const size_t region[3] = { width, height, depth };
604 EVENT_LIST (10, items - 10);
605
606 NEED_SUCCESS (EnqueueCopyImageToBuffer, (this, src, dst, src_origin, region, dst_offset, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
607
608 if (ev)
609 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
610}
611
612void
613enqueue_task (OpenCL::Queue this, OpenCL::Kernel kernel, ...)
614 PPCODE:
615{
616 cl_event ev = 0;
617 EVENT_LIST (2, items - 2);
618
619 NEED_SUCCESS (EnqueueTask, (this, kernel, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
620
621 if (ev)
622 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
623}
624
625void
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, ...)
627 PPCODE:
628{
629 cl_event ev = 0;
630 size_t *gwo = 0, *gws, *lws = 0;
631 int gws_len;
632 size_t *lists;
633 int i;
634 EVENT_LIST (5, items - 5);
635
636 if (!SvROK (global_work_size) || SvTYPE (SvRV (global_work_size)) != SVt_PVAV)
637 croak ("clEnqueueNDRangeKernel: global_work_size must be an array reference");
638
639 gws_len = AvFILLp (SvRV (global_work_size)) + 1;
640
641 lists = tmpbuf (sizeof (size_t) * 3 * gws_len);
642
643 gws = lists + gws_len * 0;
644 for (i = 0; i < gws_len; ++i)
645 gws [i] = SvIV (AvARRAY (SvRV (global_work_size))[i]);
646
647 if (SvOK (global_work_offset))
648 {
649 if (!SvROK (global_work_offset) || SvTYPE (SvRV (global_work_offset)) != SVt_PVAV)
650 croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array reference");
651
652 if (AvFILLp (SvRV (global_work_size)) + 1 != gws_len)
653 croak ("clEnqueueNDRangeKernel: global_work_offset must be undef or an array of same size as global_work_size");
654
655 gwo = lists + gws_len * 1;
656 for (i = 0; i < gws_len; ++i)
657 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
658 }
659
660 if (SvOK (local_work_size))
661 {
662 if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV)
663 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference");
664
665 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len)
666 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
667
668 lws = lists + gws_len * 2;
669 for (i = 0; i < gws_len; ++i)
670 lws [i] = SvIV (AvARRAY (SvRV (local_work_size))[i]);
671 }
672
673 NEED_SUCCESS (EnqueueNDRangeKernel, (this, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
333 674
334 if (ev) 675 if (ev)
335 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 676 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
336} 677}
337 678
354 695
355void 696void
356enqueue_barrier (OpenCL::Queue this) 697enqueue_barrier (OpenCL::Queue this)
357 CODE: 698 CODE:
358 NEED_SUCCESS (EnqueueBarrier, (this)); 699 NEED_SUCCESS (EnqueueBarrier, (this));
700
701void
702flush (OpenCL::Queue this)
703 CODE:
704 NEED_SUCCESS (Flush, (this));
705
706void
707finish (OpenCL::Queue this)
708 CODE:
709 NEED_SUCCESS (Finish, (this));
359 710
360MODULE = OpenCL PACKAGE = OpenCL::Memory 711MODULE = OpenCL PACKAGE = OpenCL::Memory
361 712
362void 713void
363DESTROY (OpenCL::Memory this) 714DESTROY (OpenCL::Memory this)
438info (OpenCL::Kernel this, cl_kernel_info name) 789info (OpenCL::Kernel this, cl_kernel_info name)
439 PPCODE: 790 PPCODE:
440 INFO (Kernel) 791 INFO (Kernel)
441 792
442void 793void
443set_bool (OpenCL::Kernel this, cl_uint idx, cl_bool value) 794set_char (OpenCL::Kernel this, cl_uint idx, cl_char value)
444 CODE: 795 CODE:
445 clKernelSetArg (this, idx, sizeof (value), &value); 796 clSetKernelArg (this, idx, sizeof (value), &value);
797
798void
799set_uchar (OpenCL::Kernel this, cl_uint idx, cl_uchar value)
800 CODE:
801 clSetKernelArg (this, idx, sizeof (value), &value);
802
803void
804set_short (OpenCL::Kernel this, cl_uint idx, cl_short value)
805 CODE:
806 clSetKernelArg (this, idx, sizeof (value), &value);
807
808void
809set_ushort (OpenCL::Kernel this, cl_uint idx, cl_ushort value)
810 CODE:
811 clSetKernelArg (this, idx, sizeof (value), &value);
812
813void
814set_int (OpenCL::Kernel this, cl_uint idx, cl_int value)
815 CODE:
816 clSetKernelArg (this, idx, sizeof (value), &value);
817
818void
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);
446 877
447MODULE = OpenCL PACKAGE = OpenCL::Event 878MODULE = OpenCL PACKAGE = OpenCL::Event
448 879
449void 880void
450DESTROY (OpenCL::Event this) 881DESTROY (OpenCL::Event this)
459void 890void
460wait (OpenCL::Event this) 891wait (OpenCL::Event this)
461 CODE: 892 CODE:
462 clWaitForEvents (1, &this); 893 clWaitForEvents (1, &this);
463 894
895MODULE = OpenCL PACKAGE = OpenCL::UserEvent
896
897void
898set_status (OpenCL::UserEvent this, cl_int execution_status)
899 CODE:
900 clSetUserEventStatus (this, execution_status);
901

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines