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

Comparing OpenCL/OpenCL.pm (file contents):
Revision 1.11 by root, Thu Nov 17 02:54:14 2011 UTC vs.
Revision 1.19 by root, Sat Nov 19 19:54:04 2011 UTC

28specific device ("compiling and linking"), also binary programs. For each 28specific device ("compiling and linking"), also binary programs. For each
29kernel function in a program you can then create an OpenCL::Kernel object 29kernel function in a program you can then create an OpenCL::Kernel object
30which represents basically a function call with argument values. 30which represents basically a function call with argument values.
31 31
32OpenCL::Memory objects of various flavours: OpenCL::Buffers objects (flat 32OpenCL::Memory objects of various flavours: OpenCL::Buffers objects (flat
33memory areas, think array) and OpenCL::Image objects (think 2d or 3d 33memory areas, think arrays or structs) and OpenCL::Image objects (think 2d
34array) for bulk data and input and output for kernels. 34or 3d array) for bulk data and input and output for kernels.
35 35
36OpenCL::Sampler objects, which are kind of like texture filter modes in 36OpenCL::Sampler objects, which are kind of like texture filter modes in
37OpenGL. 37OpenGL.
38 38
39OpenCL::Queue objects - command queues, which allow you to submit memory 39OpenCL::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
53OpenCL manpages: 53OpenCL 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
57If you are into UML class diagrams, the following diagram might help - if
58not, it will be mildly cobfusing:
59
60 http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/classDiagram.html
61
62Here's a tutorial from AMD (very AMD-centric, too), not sure how useful it
63is, 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
67And 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
59To get something done, you basically have to do this once (refer to the 73To get something done, you basically have to do this once (refer to the
60examples below for actual code, this is just a high-level description): 74examples 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);
201 215
202=head1 DOCUMENTATION 216=head1 DOCUMENTATION
203 217
204=head2 BASIC CONVENTIONS 218=head2 BASIC CONVENTIONS
205 219
206This is not a 1:1 C-style translation of OpenCL to Perl - instead I 220This is not a one-to-one C-style translation of OpenCL to Perl - instead
207attempted to make the interface as type-safe as possible and introducing 221I attempted to make the interface as type-safe as possible by introducing
208object syntax where it makes sense. There are a number of important 222object syntax where it makes sense. There are a number of important
209differences between the OpenCL C API and this module: 223differences between the OpenCL C API and this module:
210 224
211=over 4 225=over 4
212 226
213=item * Object lifetime managament is automatic - there is no need 227=item * Object lifetime managament is automatic - there is no need
214to free objects explicitly (C<clReleaseXXX>), the release function 228to free objects explicitly (C<clReleaseXXX>), the release function
215is called automatically once all Perl references to it go away. 229is called automatically once all Perl references to it go away.
216 230
217=item * OpenCL uses CamelCase for function names (C<clGetPlatformInfo>), 231=item * OpenCL uses CamelCase for function names (e.g. C<clGetPlatformIDs>, C<clGetPlatformInfo>),
218while this module uses underscores as word separator and often leaves out 232while this module uses underscores as word separator and often leaves out
219prefixes (C<< $platform->info >>). 233prefixes (C<OpenCL::platforms>, 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
222arrays (C<size_t origin[3]>), while this module explicitly expects the 236arrays (C<size_t origin[3]>), while this module explicitly expects the
223components as separate arguments- 237components as separate arguments (C<$orig_x, $orig_y, $orig_z>) in
238function calls.
224 239
225=item * Where possible, one of the pitch values is calculated from the 240=item * Structures are often specified by flattening out their components
226perl scalar length and need not be specified. 241as with short vectors, and returned as arrayrefs.
227 242
228=item * When enqueuing commands, the wait list is specified by adding 243=item * When enqueuing commands, the wait list is specified by adding
229extra arguments to the function - anywhere a C<$wait_events...> argument 244extra arguments to the function - anywhere a C<$wait_events...> argument
230is documented this can be any number of event objects. 245is documented this can be any number of event objects.
231 246
371 386
372=item $buf = $ctx->buffer_sv ($flags, $data) 387=item $buf = $ctx->buffer_sv ($flags, $data)
373 388
374Creates a new OpenCL::Buffer object and initialise it with the given data values. 389Creates a new OpenCL::Buffer object and initialise it with the given data values.
375 390
376=item $img = $ctx->image2d ($flags, $channel_order, $channel_type, $width, $height, $data) 391=item $img = $ctx->image2d ($flags, $channel_order, $channel_type, $width, $height, $row_pitch = 0, $data = undef)
377 392
378Creates a new OpenCL::Image2D object and optionally initialises it with the given data values. 393Creates a new OpenCL::Image2D object and optionally initialises it with the given data values.
379 394
380L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage2D.html> 395L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage2D.html>
381 396
382=item $img = $ctx->image3d ($flags, $channel_order, $channel_type, $width, $height, $depth, $slice_pitch, $data) 397=item $img = $ctx->image3d ($flags, $channel_order, $channel_type, $width, $height, $depth, $row_pitch = 0, $slice_pitch = 0, $data = undef)
383 398
384Creates a new OpenCL::Image3D object and optionally initialises it with the given data values. 399Creates a new OpenCL::Image3D object and optionally initialises it with the given data values.
385 400
386L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage3D.html> 401L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage3D.html>
387 402
450 465
451=item $ev = $queue->enqueue_read_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...) 466=item $ev = $queue->enqueue_read_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...)
452 467
453L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadImage.html> 468L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadImage.html>
454 469
455=item $ev = $queue->enqueue_write_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $data, $wait_events...) 470=item $ev = $queue->enqueue_write_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...)
456 471
457L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteImage.html> 472L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteImage.html>
458 473
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...) 474=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...)
460 475
461Yeah. 476Yeah.
462 477
463L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferRect.html> 478L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferRect.html>
464 479
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, ...) 480=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 481
467L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html>. 482L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html>.
468 483
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, ...) 484=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 485
471L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImage.html> 486L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImage.html>
472 487
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, ...) 488=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 489
475L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImageToBuffer.html> 490L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImageToBuffer.html>
476 491
477=item $ev = $queue->enqueue_task ($kernel, $wait_events...) 492=item $ev = $queue->enqueue_task ($kernel, $wait_events...)
478 493
643package OpenCL; 658package OpenCL;
644 659
645use common::sense; 660use common::sense;
646 661
647BEGIN { 662BEGIN {
648 our $VERSION = '0.03'; 663 our $VERSION = '0.15';
649 664
650 require XSLoader; 665 require XSLoader;
651 XSLoader::load (__PACKAGE__, $VERSION); 666 XSLoader::load (__PACKAGE__, $VERSION);
652 667
653 @OpenCL::Buffer::ISA = 668 @OpenCL::Buffer::ISA =

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines