--- OpenCL/OpenCL.pm 2011/11/17 03:01:35 1.13 +++ OpenCL/OpenCL.pm 2011/11/20 01:09:48 1.20 @@ -29,9 +29,9 @@ kernel function in a program you can then create an OpenCL::Kernel object which represents basically a function call with argument values. -OpenCL::Memory objects of various flavours: OpenCL::Buffers objects (flat -memory areas, think array) and OpenCL::Image objects (think 2d or 3d -array) for bulk data and input and output for kernels. +OpenCL::Memory objects of various flavours: OpenCL::Buffer objects (flat +memory areas, think arrays or structs) and OpenCL::Image objects (think 2d +or 3d array) for bulk data and input and output for kernels. OpenCL::Sampler objects, which are kind of like texture filter modes in OpenGL. @@ -54,6 +54,20 @@ http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/ +If you are into UML class diagrams, the following diagram might help - if +not, it will be mildly cobfusing: + + http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/classDiagram.html + +Here's a tutorial from AMD (very AMD-centric, too), not sure how useful it +is, but at least it's free of charge: + + http://developer.amd.com/zones/OpenCLZone/courses/Documents/Introduction_to_OpenCL_Programming%20Training_Guide%20%28201005%29.pdf + +And here's NVIDIA's OpenCL Best Practises Guide: + + http://developer.download.nvidia.com/compute/cuda/3_2/toolkit/docs/OpenCL_Best_Practices_Guide.pdf + =head1 BASIC WORKFLOW To get something done, you basically have to do this once (refer to the @@ -140,7 +154,7 @@ __kernel void squareit (__global float *input, __global float *output) { - size_t id = get_global_id (0); + $id = get_global_id (0); output [id] = input [id] * input [id]; } '; @@ -203,8 +217,8 @@ =head2 BASIC CONVENTIONS -This is not a 1:1 C-style translation of OpenCL to Perl - instead I -attempted to make the interface as type-safe as possible and introducing +This is not a one-to-one C-style translation of OpenCL to Perl - instead +I attempted to make the interface as type-safe as possible by introducing object syntax where it makes sense. There are a number of important differences between the OpenCL C API and this module: @@ -214,19 +228,18 @@ to free objects explicitly (C), the release function is called automatically once all Perl references to it go away. -=item * OpenCL uses CamelCase for function names (C), -while this module uses underscores as word separator and often leaves out -prefixes (C<< $platform->info >>). +=item * OpenCL uses CamelCase for function names +(e.g. C, C), while this module +uses underscores as word separator and often leaves out prefixes +(C, C<< $platform->info >>). =item * OpenCL often specifies fixed vector function arguments as short arrays (C), while this module explicitly expects the -components as separate arguments- - -=item * Structures are often specified with their components, and returned -as arrayrefs. +components as separate arguments (C<$orig_x, $orig_y, $orig_z>) in +function calls. -=item * Where possible, one of the pitch values is calculated from the -perl scalar length and need not be specified. +=item * Structures are often specified by flattening out their components +as with short vectors, and returned as arrayrefs. =item * When enqueuing commands, the wait list is specified by adding extra arguments to the function - anywhere a C<$wait_events...> argument @@ -305,14 +318,6 @@ =over 4 -=item $packed_value = $platform->info ($name) - -Calls C and returns the packed, raw value - for -strings, this will be the string, for other values you probably need to -use the correct C. This might get improved in the future. Hopefully. - -L - =item @devices = $platform->devices ($type = OpenCL::DEVICE_TYPE_ALL) Returns a list of matching OpenCL::Device objects. @@ -330,6 +335,41 @@ L +=item $packed_value = $platform->info ($name) + +Calls C and returns the packed, raw value - for +strings, this will be the string, for other values you probably need to +use the correct C. + +It's best to avoid this method and use one of the predefined C +methods. + +L + +=for gengetinfo begin platform + + +=item $string = $platform->profile + +Calls C with C and returns the result(s). + +=item $string = $platform->version + +Calls C with C and returns the result(s). + +=item $string = $platform->name + +Calls C with C and returns the result(s). + +=item $string = $platform->vendor + +Calls C with C and returns the result(s). + +=item $string = $platform->extensions + +Calls C with C and returns the result(s). +=for gengetinfo end platform + =back =head2 THE OpenCL::Device CLASS @@ -348,12 +388,6 @@ =over 4 -=item $packed_value = $ctx->info ($name) - -See C<< $platform->info >> for details. - -L - =item $queue = $ctx->queue ($device, $properties) Create a new OpenCL::Queue object from the context and the given device. @@ -376,13 +410,13 @@ Creates a new OpenCL::Buffer object and initialise it with the given data values. -=item $img = $ctx->image2d ($flags, $channel_order, $channel_type, $width, $height, $data) +=item $img = $ctx->image2d ($flags, $channel_order, $channel_type, $width, $height, $row_pitch = 0, $data = undef) Creates a new OpenCL::Image2D object and optionally initialises it with the given data values. L -=item $img = $ctx->image3d ($flags, $channel_order, $channel_type, $width, $height, $depth, $slice_pitch, $data) +=item $img = $ctx->image3d ($flags, $channel_order, $channel_type, $width, $height, $depth, $row_pitch = 0, $slice_pitch = 0, $data = undef) Creates a new OpenCL::Image3D object and optionally initialises it with the given data values. @@ -407,6 +441,16 @@ L +=item $packed_value = $ctx->info ($name) + +See C<< $platform->info >> for details. + +L + +=for gengetinfo begin context + +=for gengetinfo end context + =back =head2 THE OpenCL::Queue CLASS @@ -455,25 +499,25 @@ L -=item $ev = $queue->enqueue_write_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $data, $wait_events...) +=item $ev = $queue->enqueue_write_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...) L -=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...) +=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...) Yeah. L -=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, ...) +=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...) L. -=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, ...) +=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...) L -=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, ...) +=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...) L @@ -537,6 +581,23 @@ =back +=head2 THE OpenCL::Image CLASS + +This is the superclass of all image objects - OpenCL::Image2D and OpenCL::Image3D. + +=over 4 + +=item $packed_value = $ev->image_info ($name) + +See C<< $platform->info >> for details. + +The reason this method is not called C is that there already is an +C<< ->info >> method inherited from C. + +L + +=back + =head2 THE OpenCL::Sampler CLASS =over 4 @@ -591,6 +652,15 @@ L +=item $packed_value = $kernel->work_group_info ($device, $name) + +See C<< $platform->info >> for details. + +The reason this method is not called C is that there already is an +C<< ->info >> method. + +L + =item $kernel->set_TYPE ($index, $value) This is a family of methods to set the kernel argument with the number C<$index> to the give C<$value>. @@ -621,6 +691,15 @@ L +=item $packed_value = $ev->profiling_info ($name) + +See C<< $platform->info >> for details. + +The reason this method is not called C is that there already is an +C<< ->info >> method. + +L + =item $ev->wait Waits for the event to complete. @@ -648,7 +727,7 @@ use common::sense; BEGIN { - our $VERSION = '0.14'; + our $VERSION = '0.15'; require XSLoader; XSLoader::load (__PACKAGE__, $VERSION);