… | |
… | |
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 | Here's a tutorial from AMD (very AMD-centric, too), not sure how useful it |
|
|
58 | is, but at least it's free of charge: |
|
|
59 | |
|
|
60 | http://developer.amd.com/zones/OpenCLZone/courses/Documents/Introduction_to_OpenCL_Programming%20Training_Guide%20%28201005%29.pdf |
|
|
61 | |
|
|
62 | If you are into UML class diagrams, the following diagram might help - if |
|
|
63 | not, it will be mildly cofusing: |
|
|
64 | |
|
|
65 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/classDiagram.html |
56 | |
66 | |
57 | =head1 BASIC WORKFLOW |
67 | =head1 BASIC WORKFLOW |
58 | |
68 | |
59 | To get something done, you basically have to do this once (refer to the |
69 | 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): |
70 | examples below for actual code, this is just a high-level description): |
… | |
… | |
138 | |
148 | |
139 | my $src = ' |
149 | my $src = ' |
140 | __kernel void |
150 | __kernel void |
141 | squareit (__global float *input, __global float *output) |
151 | squareit (__global float *input, __global float *output) |
142 | { |
152 | { |
143 | size_t id = get_global_id (0); |
153 | $id = get_global_id (0); |
144 | output [id] = input [id] * input [id]; |
154 | output [id] = input [id] * input [id]; |
145 | } |
155 | } |
146 | '; |
156 | '; |
147 | |
157 | |
148 | my $prog = $ctx->program_with_source ($src); |
158 | my $prog = $ctx->program_with_source ($src); |
… | |
… | |
201 | |
211 | |
202 | =head1 DOCUMENTATION |
212 | =head1 DOCUMENTATION |
203 | |
213 | |
204 | =head2 BASIC CONVENTIONS |
214 | =head2 BASIC CONVENTIONS |
205 | |
215 | |
206 | This is not a 1:1 C-style translation of OpenCL to Perl - instead I |
216 | This is not a one-to-one C-style translation of OpenCL to Perl - instead |
207 | attempted to make the interface as type-safe as possible and introducing |
217 | I attempted to make the interface as type-safe as possible by introducing |
208 | object syntax where it makes sense. There are a number of important |
218 | object syntax where it makes sense. There are a number of important |
209 | differences between the OpenCL C API and this module: |
219 | differences between the OpenCL C API and this module: |
210 | |
220 | |
211 | =over 4 |
221 | =over 4 |
212 | |
222 | |
… | |
… | |
217 | =item * OpenCL uses CamelCase for function names (C<clGetPlatformInfo>), |
227 | =item * OpenCL uses CamelCase for function names (C<clGetPlatformInfo>), |
218 | while this module uses underscores as word separator and often leaves out |
228 | while this module uses underscores as word separator and often leaves out |
219 | prefixes (C<< $platform->info >>). |
229 | prefixes (C<< $platform->info >>). |
220 | |
230 | |
221 | =item * OpenCL often specifies fixed vector function arguments as short |
231 | =item * OpenCL often specifies fixed vector function arguments as short |
222 | arrays (C<size_t origin[3]>), while this module explicitly expects the |
232 | arrays (C<$origin[3]>), while this module explicitly expects the |
223 | components as separate arguments- |
233 | components as separate arguments- |
|
|
234 | |
|
|
235 | =item * Structures are often specified with their components, and returned |
|
|
236 | as arrayrefs. |
224 | |
237 | |
225 | =item * Where possible, one of the pitch values is calculated from the |
238 | =item * Where possible, one of the pitch values is calculated from the |
226 | perl scalar length and need not be specified. |
239 | perl scalar length and need not be specified. |
227 | |
240 | |
228 | =item * When enqueuing commands, the wait list is specified by adding |
241 | =item * When enqueuing commands, the wait list is specified by adding |
… | |
… | |
454 | |
467 | |
455 | =item $ev = $queue->enqueue_write_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $data, $wait_events...) |
468 | =item $ev = $queue->enqueue_write_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $data, $wait_events...) |
456 | |
469 | |
457 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteImage.html> |
470 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteImage.html> |
458 | |
471 | |
459 | =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...) |
472 | =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, $wait_event...) |
460 | |
473 | |
461 | Yeah. |
474 | Yeah. |
462 | |
475 | |
463 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferRect.html> |
476 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferRect.html> |
464 | |
477 | |
465 | =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, ...) |
478 | =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...) |
466 | |
479 | |
467 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html>. |
480 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html>. |
468 | |
481 | |
469 | =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, ...) |
482 | =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...) |
470 | |
483 | |
471 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImage.html> |
484 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImage.html> |
472 | |
485 | |
473 | =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, ...) |
486 | =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...) |
474 | |
487 | |
475 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImageToBuffer.html> |
488 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImageToBuffer.html> |
476 | |
489 | |
477 | =item $ev = $queue->enqueue_task ($kernel, $wait_events...) |
490 | =item $ev = $queue->enqueue_task ($kernel, $wait_events...) |
478 | |
491 | |