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.11 by root, Thu Nov 17 04:17:43 2011 UTC

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 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}
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);
135 143
251context (OpenCL::Platform this, FUTURE properties, SV *devices, FUTURE notify = 0) 259context (OpenCL::Platform this, FUTURE properties, SV *devices, FUTURE notify = 0)
252 PPCODE: 260 PPCODE:
253 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) 261 if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV)
254 croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call"); 262 croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call");
255 263
256 AV *av = (SV *)SvRV (devices); 264 AV *av = (AV *)SvRV (devices);
257 cl_uint num_devices = av_len (av) + 1; 265 cl_uint num_devices = av_len (av) + 1;
258 cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); 266 cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices);
259 int i; 267 int i;
260 268
261 for (i = num_devices; i--; ) 269 for (i = num_devices; i--; )
429 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 437 NEED_SUCCESS (EnqueueCopyBuffer, (this, src, dst, src_offset, dst_offset, len, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
430 438
431 if (ev) 439 if (ev)
432 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 440 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
433 441
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 442void
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, ...) 443enqueue_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: 444 PPCODE:
440 cl_event ev = 0; 445 cl_event ev = 0;
441 const size_t src_origin[3] = { src_x, src_y, src_z }; 446 const size_t src_origin[3] = { src_x, src_y, src_z };
442 const size_t region[3] = { width, height, depth }; 447 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); 448 EVENT_LIST (12, items - 12);
445 449
446 if (!len) 450 if (!row_pitch)
447 croak ("enqueue_read_image: currently, row_pitch must be specified to be non-zero"); 451 row_pitch = img_row_pitch (src);
452
453 if (depth > 1 && !slice_pitch)
454 slice_pitch = row_pitch * height;
455
456 size_t len = slice_pitch ? slice_pitch * depth : row_pitch * height;
448 457
449 SvUPGRADE (data, SVt_PV); 458 SvUPGRADE (data, SVt_PV);
450 SvGROW (data, len); 459 SvGROW (data, len);
451 SvPOK_only (data); 460 SvPOK_only (data);
452 SvCUR_set (data, len); 461 SvCUR_set (data, len);
462 const size_t dst_origin[3] = { dst_x, dst_y, dst_z }; 471 const size_t dst_origin[3] = { dst_x, dst_y, dst_z };
463 const size_t region[3] = { width, height, depth }; 472 const size_t region[3] = { width, height, depth };
464 STRLEN len; 473 STRLEN len;
465 char *ptr = SvPVbyte (data, len); 474 char *ptr = SvPVbyte (data, len);
466 EVENT_LIST (12, items - 12); 475 EVENT_LIST (12, items - 12);
476
477 if (!row_pitch)
478 row_pitch = img_row_pitch (dst);
479
480 if (depth > 1 && !slice_pitch)
481 slice_pitch = row_pitch * height;
482
483 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height;
484
485 if (len < min_len)
486 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
467 487
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)); 488 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 489
470 if (ev) 490 if (ev)
471 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 491 XPUSH_NEW_OBJ ("OpenCL::Event", ev);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines