… | |
… | |
28 | specific device ("compiling and linking"), also binary programs. For each |
28 | specific device ("compiling and linking"), also binary programs. For each |
29 | kernel function in a program you can then create an OpenCL::Kernel object |
29 | kernel function in a program you can then create an OpenCL::Kernel object |
30 | which represents basically a function call with argument values. |
30 | which represents basically a function call with argument values. |
31 | |
31 | |
32 | OpenCL::Memory objects of various flavours: OpenCL::Buffers objects (flat |
32 | OpenCL::Memory objects of various flavours: OpenCL::Buffers objects (flat |
33 | memory areas, think array) and OpenCL::Image objects (think 2d or 3d |
33 | memory areas, think arrays or structs) and OpenCL::Image objects (think 2d |
34 | array) for bulk data and input and output for kernels. |
34 | or 3d array) for bulk data and input and output for kernels. |
35 | |
35 | |
36 | OpenCL::Sampler objects, which are kind of like texture filter modes in |
36 | OpenCL::Sampler objects, which are kind of like texture filter modes in |
37 | OpenGL. |
37 | OpenGL. |
38 | |
38 | |
39 | OpenCL::Queue objects - command queues, which allow you to submit memory |
39 | OpenCL::Queue objects - command queues, which allow you to submit memory |
… | |
… | |
51 | http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf |
51 | http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf |
52 | |
52 | |
53 | OpenCL manpages: |
53 | OpenCL manpages: |
54 | |
54 | |
55 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/ |
55 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/ |
|
|
56 | |
|
|
57 | If you are into UML class diagrams, the following diagram might help - if |
|
|
58 | not, it will be mildly cobfusing: |
|
|
59 | |
|
|
60 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/classDiagram.html |
|
|
61 | |
|
|
62 | Here's a tutorial from AMD (very AMD-centric, too), not sure how useful it |
|
|
63 | is, but at least it's free of charge: |
|
|
64 | |
|
|
65 | http://developer.amd.com/zones/OpenCLZone/courses/Documents/Introduction_to_OpenCL_Programming%20Training_Guide%20%28201005%29.pdf |
|
|
66 | |
|
|
67 | And here's NVIDIA's OpenCL Best Practises Guide: |
|
|
68 | |
|
|
69 | http://developer.download.nvidia.com/compute/cuda/3_2/toolkit/docs/OpenCL_Best_Practices_Guide.pdf |
56 | |
70 | |
57 | =head1 BASIC WORKFLOW |
71 | =head1 BASIC WORKFLOW |
58 | |
72 | |
59 | To get something done, you basically have to do this once (refer to the |
73 | To get something done, you basically have to do this once (refer to the |
60 | examples below for actual code, this is just a high-level description): |
74 | examples below for actual code, this is just a high-level description): |
… | |
… | |
138 | |
152 | |
139 | my $src = ' |
153 | my $src = ' |
140 | __kernel void |
154 | __kernel void |
141 | squareit (__global float *input, __global float *output) |
155 | squareit (__global float *input, __global float *output) |
142 | { |
156 | { |
143 | size_t id = get_global_id (0); |
157 | $id = get_global_id (0); |
144 | output [id] = input [id] * input [id]; |
158 | output [id] = input [id] * input [id]; |
145 | } |
159 | } |
146 | '; |
160 | '; |
147 | |
161 | |
148 | my $prog = $ctx->program_with_source ($src); |
162 | my $prog = $ctx->program_with_source ($src); |
… | |
… | |
217 | =item * OpenCL uses CamelCase for function names (C<clGetPlatformInfo>), |
231 | =item * OpenCL uses CamelCase for function names (C<clGetPlatformInfo>), |
218 | while this module uses underscores as word separator and often leaves out |
232 | while this module uses underscores as word separator and often leaves out |
219 | prefixes (C<< $platform->info >>). |
233 | prefixes (C<< $platform->info >>). |
220 | |
234 | |
221 | =item * OpenCL often specifies fixed vector function arguments as short |
235 | =item * OpenCL often specifies fixed vector function arguments as short |
222 | arrays (C<size_t origin[3]>), while this module explicitly expects the |
236 | arrays (C<$origin[3]>), while this module explicitly expects the |
223 | components as separate arguments- |
237 | components as separate arguments- |
224 | |
238 | |
225 | =item * Structures are often specified with their components, and returned |
239 | =item * Structures are often specified with their components, and returned |
226 | as arrayrefs. |
240 | as arrayrefs. |
227 | |
241 | |
… | |
… | |
374 | |
388 | |
375 | =item $buf = $ctx->buffer_sv ($flags, $data) |
389 | =item $buf = $ctx->buffer_sv ($flags, $data) |
376 | |
390 | |
377 | Creates a new OpenCL::Buffer object and initialise it with the given data values. |
391 | Creates a new OpenCL::Buffer object and initialise it with the given data values. |
378 | |
392 | |
379 | =item $img = $ctx->image2d ($flags, $channel_order, $channel_type, $width, $height, $data) |
393 | =item $img = $ctx->image2d ($flags, $channel_order, $channel_type, $width, $height, $row_pitch = 0, $data = undef) |
380 | |
394 | |
381 | Creates a new OpenCL::Image2D object and optionally initialises it with the given data values. |
395 | Creates a new OpenCL::Image2D object and optionally initialises it with the given data values. |
382 | |
396 | |
383 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage2D.html> |
397 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage2D.html> |
384 | |
398 | |
385 | =item $img = $ctx->image3d ($flags, $channel_order, $channel_type, $width, $height, $depth, $slice_pitch, $data) |
399 | =item $img = $ctx->image3d ($flags, $channel_order, $channel_type, $width, $height, $depth, $row_pitch = 0, $slice_pitch = 0, $data = undef) |
386 | |
400 | |
387 | Creates a new OpenCL::Image3D object and optionally initialises it with the given data values. |
401 | Creates a new OpenCL::Image3D object and optionally initialises it with the given data values. |
388 | |
402 | |
389 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage3D.html> |
403 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage3D.html> |
390 | |
404 | |
… | |
… | |
453 | |
467 | |
454 | =item $ev = $queue->enqueue_read_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...) |
468 | =item $ev = $queue->enqueue_read_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...) |
455 | |
469 | |
456 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadImage.html> |
470 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadImage.html> |
457 | |
471 | |
458 | =item $ev = $queue->enqueue_write_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $data, $wait_events...) |
472 | =item $ev = $queue->enqueue_write_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...) |
459 | |
473 | |
460 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteImage.html> |
474 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteImage.html> |
461 | |
475 | |
462 | =item $ev = $queue->enqueue_copy_buffer_rect ($src, $dst, $src_x, $src_y, $src_z, $dst_x, $dst_y, $dst_z, $width, $height, $depth, $src_row_pitch, $src_slice_pitch, 4dst_row_pitch, $dst_slice_pitch, $ait_event...) |
476 | =item $ev = $queue->enqueue_copy_buffer_rect ($src, $dst, $src_x, $src_y, $src_z, $dst_x, $dst_y, $dst_z, $width, $height, $depth, $src_row_pitch, $src_slice_pitch, $dst_row_pitch, $dst_slice_pitch, $wait_event...) |
463 | |
477 | |
464 | Yeah. |
478 | Yeah. |
465 | |
479 | |
466 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferRect.html> |
480 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferRect.html> |
467 | |
481 | |
468 | =item $ev = $queue->enqueue_copy_buffer_to_image (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, ...) |
482 | =item $ev = $queue->enqueue_copy_buffer_to_image ($src_buffer, $dst_image, $src_offset, $dst_x, $dst_y, $dst_z, $width, $height, $depth, $wait_events...) |
469 | |
483 | |
470 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html>. |
484 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html>. |
471 | |
485 | |
472 | =item $ev = $queue->enqueue_copy_image (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, ...) |
486 | =item $ev = $queue->enqueue_copy_image ($src_image, $dst_image, $src_x, $src_y, $src_z, $dst_x, $dst_y, $dst_z, $width, $height, $depth, $wait_events...) |
473 | |
487 | |
474 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImage.html> |
488 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImage.html> |
475 | |
489 | |
476 | =item $ev = $queue->enqueue_copy_image_to_buffer (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, ...) |
490 | =item $ev = $queue->enqueue_copy_image_to_buffer ($src_image, $dst_image, $src_x, $src_y, $src_z, $width, $height, $depth, $dst_offset, $wait_events...) |
477 | |
491 | |
478 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImageToBuffer.html> |
492 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImageToBuffer.html> |
479 | |
493 | |
480 | =item $ev = $queue->enqueue_task ($kernel, $wait_events...) |
494 | =item $ev = $queue->enqueue_task ($kernel, $wait_events...) |
481 | |
495 | |
… | |
… | |
646 | package OpenCL; |
660 | package OpenCL; |
647 | |
661 | |
648 | use common::sense; |
662 | use common::sense; |
649 | |
663 | |
650 | BEGIN { |
664 | BEGIN { |
651 | our $VERSION = '0.14'; |
665 | our $VERSION = '0.15'; |
652 | |
666 | |
653 | require XSLoader; |
667 | require XSLoader; |
654 | XSLoader::load (__PACKAGE__, $VERSION); |
668 | XSLoader::load (__PACKAGE__, $VERSION); |
655 | |
669 | |
656 | @OpenCL::Buffer::ISA = |
670 | @OpenCL::Buffer::ISA = |