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

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.10 by root, Thu Nov 17 03:56:07 2011 UTC vs.
Revision 1.13 by root, Sun Nov 20 01:09:48 2011 UTC

125 125
126 croak ("%s: %s is not of type %s", func, svname, pkg); 126 croak ("%s: %s is not of type %s", func, svname, pkg);
127} 127}
128 128
129/*****************************************************************************/ 129/*****************************************************************************/
130
131static size_t
132img_row_pitch (cl_mem img)
133{
134 size_t res;
135 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0);
136 return res;
137}
130 138
131static cl_event * 139static cl_event *
132event_list (SV **items, int count) 140event_list (SV **items, int count)
133{ 141{
134 cl_event *list = tmpbuf (sizeof (cl_event) * count); 142 cl_event *list = tmpbuf (sizeof (cl_event) * count);
230void 238void
231info (OpenCL::Platform this, cl_platform_info name) 239info (OpenCL::Platform this, cl_platform_info name)
232 PPCODE: 240 PPCODE:
233 INFO (Platform) 241 INFO (Platform)
234 242
243#BEGIN:platform
244
245void
246profile (OpenCL::Platform this)
247 PPCODE:
248 size_t size;
249 int i, n;
250 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_PROFILE, 0, 0, &size));
251 char *value = tmpbuf (size);
252 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_PROFILE, size, value, 0));
253 n = 1;
254 EXTEND (SP, n);
255 for (i = 0; i < n; ++i)
256 PUSHs (sv_2mortal (newSVpvn (value, size)));
257
258void
259version (OpenCL::Platform this)
260 PPCODE:
261 size_t size;
262 int i, n;
263 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_VERSION, 0, 0, &size));
264 char *value = tmpbuf (size);
265 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_VERSION, size, value, 0));
266 n = 1;
267 EXTEND (SP, n);
268 for (i = 0; i < n; ++i)
269 PUSHs (sv_2mortal (newSVpvn (value, size)));
270
271void
272name (OpenCL::Platform this)
273 PPCODE:
274 size_t size;
275 int i, n;
276 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_NAME, 0, 0, &size));
277 char *value = tmpbuf (size);
278 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_NAME, size, value, 0));
279 n = 1;
280 EXTEND (SP, n);
281 for (i = 0; i < n; ++i)
282 PUSHs (sv_2mortal (newSVpvn (value, size)));
283
284void
285vendor (OpenCL::Platform this)
286 PPCODE:
287 size_t size;
288 int i, n;
289 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_VENDOR, 0, 0, &size));
290 char *value = tmpbuf (size);
291 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_VENDOR, size, value, 0));
292 n = 1;
293 EXTEND (SP, n);
294 for (i = 0; i < n; ++i)
295 PUSHs (sv_2mortal (newSVpvn (value, size)));
296
297void
298extensions (OpenCL::Platform this)
299 PPCODE:
300 size_t size;
301 int i, n;
302 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_EXTENSIONS, 0, 0, &size));
303 char *value = tmpbuf (size);
304 NEED_SUCCESS (GetPlatformInfo, (this, CL_PLATFORM_EXTENSIONS, size, value, 0));
305 n = 1;
306 EXTEND (SP, n);
307 for (i = 0; i < n; ++i)
308 PUSHs (sv_2mortal (newSVpvn (value, size)));
309
310#END:platform
311
235void 312void
236devices (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_ALL) 313devices (OpenCL::Platform this, cl_device_type type = CL_DEVICE_TYPE_ALL)
237 PPCODE: 314 PPCODE:
238 cl_device_id *list; 315 cl_device_id *list;
239 cl_uint count; 316 cl_uint count;
251context (OpenCL::Platform this, FUTURE properties, SV *devices, FUTURE notify = 0) 328context (OpenCL::Platform this, FUTURE properties, SV *devices, FUTURE notify = 0)
252 PPCODE: 329 PPCODE:
253 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) 330 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV)
254 croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call"); 331 croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call");
255 332
256 AV *av = (SV *)SvRV (devices); 333 AV *av = (AV *)SvRV (devices);
257 cl_uint num_devices = av_len (av) + 1; 334 cl_uint num_devices = av_len (av) + 1;
258 cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); 335 cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices);
259 int i; 336 int i;
260 337
261 for (i = num_devices; i--; ) 338 for (i = num_devices; i--; )
322 399
323 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, ptr, &res)); 400 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (this, flags, len, ptr, &res));
324 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem); 401 XPUSH_NEW_OBJ ("OpenCL::Buffer", mem);
325 402
326void 403void
327image2d (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, SV *data) 404image2d (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)
328 PPCODE: 405 PPCODE:
329 STRLEN len; 406 STRLEN len;
330 char *ptr = SvPVbyte (data, len); 407 char *ptr = SvPVbyte (data, len);
331 const cl_image_format format = { channel_order, channel_type }; 408 const cl_image_format format = { channel_order, channel_type };
332 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (this, flags, &format, width, height, row_pitch, ptr, &res)); 409 NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (this, flags, &format, width, height, row_pitch, ptr, &res));
333 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 410 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
334 411
335void 412void
336image3d (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, size_t slice_pitch, SV *data) 413image3d (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)
337 PPCODE: 414 PPCODE:
338 STRLEN len; 415 STRLEN len;
339 char *ptr = SvPVbyte (data, len); 416 char *ptr = SvPVbyte (data, len);
340 const cl_image_format format = { channel_order, channel_type }; 417 const cl_image_format format = { channel_order, channel_type };
341 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (this, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); 418 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (this, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
378 455
379 len2 = len; 456 len2 = len;
380 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (this, 1, &ptr, &len2, &res)); 457 NEED_SUCCESS_ARG (cl_program prog, CreateProgramWithSource, (this, 1, &ptr, &len2, &res));
381 XPUSH_NEW_OBJ ("OpenCL::Program", prog); 458 XPUSH_NEW_OBJ ("OpenCL::Program", prog);
382 459
460#BEGIN:context
461
462#END:context
463
383MODULE = OpenCL PACKAGE = OpenCL::Queue 464MODULE = OpenCL PACKAGE = OpenCL::Queue
384 465
385void 466void
386DESTROY (OpenCL::Queue this) 467DESTROY (OpenCL::Queue this)
387 CODE: 468 CODE:
429 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 510 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
430 511
431 if (ev) 512 if (ev)
432 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 513 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
433 514
434 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBufferRect.html */
435 /*TODO http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html */
436
437void 515void
438enqueue_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, ...) 516enqueue_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, ...)
439 PPCODE: 517 PPCODE:
440 cl_event ev = 0; 518 cl_event ev = 0;
441 const size_t src_origin[3] = { src_x, src_y, src_z }; 519 const size_t src_origin[3] = { src_x, src_y, src_z };
442 const size_t region[3] = { width, height, depth }; 520 const size_t region[3] = { width, height, depth };
443 size_t len = row_pitch * (slice_pitch ? slice_pitch : 1) * depth;
444 EVENT_LIST (12, items - 12); 521 EVENT_LIST (12, items - 12);
445 522
446 if (!len) 523 if (!row_pitch)
447 croak ("enqueue_read_image: currently, row_pitch must be specified to be non-zero"); 524 row_pitch = img_row_pitch (src);
525
526 if (depth > 1 && !slice_pitch)
527 slice_pitch = row_pitch * height;
528
529 size_t len = slice_pitch ? slice_pitch * depth : row_pitch * height;
448 530
449 SvUPGRADE (data, SVt_PV); 531 SvUPGRADE (data, SVt_PV);
450 SvGROW (data, len); 532 SvGROW (data, len);
451 SvPOK_only (data); 533 SvPOK_only (data);
452 SvCUR_set (data, len); 534 SvCUR_set (data, len);
463 const size_t region[3] = { width, height, depth }; 545 const size_t region[3] = { width, height, depth };
464 STRLEN len; 546 STRLEN len;
465 char *ptr = SvPVbyte (data, len); 547 char *ptr = SvPVbyte (data, len);
466 EVENT_LIST (12, items - 12); 548 EVENT_LIST (12, items - 12);
467 549
550 if (!row_pitch)
551 row_pitch = img_row_pitch (dst);
552
553 if (depth > 1 && !slice_pitch)
554 slice_pitch = row_pitch * height;
555
556 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height;
557
558 if (len < min_len)
559 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
560
468 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)); 561 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));
469 562
470 if (ev) 563 if (ev)
471 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 564 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
472 565
624 717
625void 718void
626info (OpenCL::Memory this, cl_mem_info name) 719info (OpenCL::Memory this, cl_mem_info name)
627 PPCODE: 720 PPCODE:
628 INFO (MemObject) 721 INFO (MemObject)
722
723MODULE = OpenCL PACKAGE = OpenCL::Image
724
725void
726image_info (OpenCL::Image this, cl_image_info name)
727 PPCODE:
728 INFO (Image)
629 729
630MODULE = OpenCL PACKAGE = OpenCL::Sampler 730MODULE = OpenCL PACKAGE = OpenCL::Sampler
631 731
632void 732void
633DESTROY (OpenCL::Sampler this) 733DESTROY (OpenCL::Sampler this)
685info (OpenCL::Kernel this, cl_kernel_info name) 785info (OpenCL::Kernel this, cl_kernel_info name)
686 PPCODE: 786 PPCODE:
687 INFO (Kernel) 787 INFO (Kernel)
688 788
689void 789void
790work_group_info (OpenCL::Kernel this, OpenCL::Device device, cl_kernel_work_group_info name)
791 PPCODE:
792 size_t size;
793 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, name, 0, 0, &size));
794 SV *sv = sv_2mortal (newSV (size));
795 SvUPGRADE (sv, SVt_PV);
796 SvPOK_only (sv);
797 SvCUR_set (sv, size);
798 NEED_SUCCESS (GetKernelWorkGroupInfo, (this, device, name, size, SvPVX (sv), 0));
799 XPUSHs (sv);
800
801void
690set_char (OpenCL::Kernel this, cl_uint idx, cl_char value) 802set_char (OpenCL::Kernel this, cl_uint idx, cl_char value)
691 CODE: 803 CODE:
692 clSetKernelArg (this, idx, sizeof (value), &value); 804 clSetKernelArg (this, idx, sizeof (value), &value);
693 805
694void 806void
782info (OpenCL::Event this, cl_event_info name) 894info (OpenCL::Event this, cl_event_info name)
783 PPCODE: 895 PPCODE:
784 INFO (Event) 896 INFO (Event)
785 897
786void 898void
899profiling_info (OpenCL::Event this, cl_profiling_info name)
900 PPCODE:
901 INFO (EventProfiling)
902
903void
787wait (OpenCL::Event this) 904wait (OpenCL::Event this)
788 CODE: 905 CODE:
789 clWaitForEvents (1, &this); 906 clWaitForEvents (1, &this);
790 907
791MODULE = OpenCL PACKAGE = OpenCL::UserEvent 908MODULE = OpenCL PACKAGE = OpenCL::UserEvent

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines