--- OpenCL/OpenCL.pm 2011/11/16 00:36:40 1.6 +++ OpenCL/OpenCL.pm 2012/04/19 12:55:30 1.33 @@ -8,9 +8,42 @@ =head1 DESCRIPTION -This is an early release which might be useful, but hasn't seen any testing. +This is an early release which might be useful, but hasn't seen much testing. -=head1 HELPFUL RESOURCES +=head2 OpenCL FROM 10000 FEET HEIGHT + +Here is a high level overview of OpenCL: + +First you need to find one or more OpenCL::Platforms (kind of like +vendors) - usually there is only one. + +Each platform gives you access to a number of OpenCL::Device objects, e.g. +your graphics card. + +From a platform and some device(s), you create an OpenCL::Context, which is +a very central object in OpenCL: Once you have a context you can create +most other objects: + +OpenCL::Program objects, which store source code and, after building for a +specific device ("compiling and linking"), also binary programs. For each +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::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. + +OpenCL::Queue objects - command queues, which allow you to submit memory +reads, writes and copies, as well as kernel calls to your devices. They +also offer a variety of methods to synchronise request execution, for +example with barriers or OpenCL::Event objects. + +OpenCL::Event objects are used to signal when something is complete. + +=head2 HELPFUL RESOURCES The OpenCL spec used to develop this module (1.2 spec was available, but no implementation was available to me :). @@ -21,30 +54,81 @@ 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 +examples below for actual code, this is just a high-level description): + +Find some platform (e.g. the first one) and some device(s) (e.g. the first +device of the platform), and create a context from those. + +Create program objects from your OpenCL source code, then build (compile) +the programs for each device you want to run them on. + +Create kernel objects for all kernels you want to use (surprisingly, these +are not device-specific). + +Then, to execute stuff, you repeat these steps, possibly resuing or +sharing some buffers: + +Create some input and output buffers from your context. Set these as +arguments to your kernel. + +Enqueue buffer writes to initialise your input buffers (when not +initialised at creation time). + +Enqueue the kernel execution. + +Enqueue buffer reads for your output buffer to read results. + =head1 EXAMPLES =head2 Enumerate all devices and get contexts for them. +Best run this once to get a feel for the platforms and devices in your +system. + for my $platform (OpenCL::platforms) { - warn $platform->info (OpenCL::PLATFORM_NAME); - warn $platform->info (OpenCL::PLATFORM_EXTENSIONS); + printf "platform: %s\n", $platform->name; + printf "extensions: %s\n", $platform->extensions; for my $device ($platform->devices) { - warn $device->info (OpenCL::DEVICE_NAME); - my $ctx = $device->context_simple; + printf "+ device: %s\n", $device->name; + my $ctx = $platform->context (undef, [$device]); # do stuff } } =head2 Get a useful context and a command queue. - my $dev = ((OpenCL::platforms)[0]->devices)[0]; - my $ctx = $dev->context_simple; - my $queue = $ctx->command_queue_simple ($dev); +This is a useful boilerplate for any OpenCL program that only wants to use +one device, + + my ($platform) = OpenCL::platforms; # find first platform + my ($dev) = $platform->devices; # find first device of platform + my $ctx = $platform->context (undef, [$dev]); # create context out of those + my $queue = $ctx->queue ($dev); # create a command queue for the device =head2 Print all supported image formats of a context. +Best run this once for your context, to see whats available and how to +gather information. + for my $type (OpenCL::MEM_OBJECT_IMAGE2D, OpenCL::MEM_OBJECT_IMAGE3D) { - say "supported image formats for ", OpenCL::enum2str $type; + print "supported image formats for ", OpenCL::enum2str $type, "\n"; for my $f ($ctx->supported_image_formats (0, $type)) { printf " %-10s %-20s\n", OpenCL::enum2str $f->[0], OpenCL::enum2str $f->[1]; @@ -57,32 +141,34 @@ my $buf = $ctx->buffer_sv (OpenCL::MEM_COPY_HOST_PTR, "helmut"); $queue->enqueue_read_buffer ($buf, 1, 1, 3, my $data); - warn $data; + print "$data\n"; my $ev = $queue->enqueue_read_buffer ($buf, 0, 1, 3, my $data); $ev->wait; - warn $data; + print "$data\n"; # prints "elm" =head2 Create and build a program, then create a kernel out of one of its functions. my $src = ' - __kernel void - squareit (__global float *input, __global float *output) + 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]; } '; my $prog = $ctx->program_with_source ($src); + # build croaks on compile errors, so catch it and print the compile errors eval { $prog->build ($dev); 1 } - or die $prog->build_info ($dev, OpenCL::PROGRAM_BUILD_LOG); + or die $prog->build_log; my $kernel = $prog->kernel ("squareit"); -=head2 Create some input and output float buffers, then call squareit on them. +=head2 Create some input and output float buffers, then call the +'squareit' kernel on them. my $input = $ctx->buffer_sv (OpenCL::MEM_COPY_HOST_PTR, pack "f*", 1, 2, 3, 4.5); my $output = $ctx->buffer (0, OpenCL::SIZEOF_FLOAT * 5); @@ -98,7 +184,7 @@ $queue->enqueue_read_buffer ($output, 1, 0, OpenCL::SIZEOF_FLOAT * 4, my $data); # print the results: - say join ", ", unpack "f*", $data; + printf "%s\n", join ", ", unpack "f*", $data; =head2 The same enqueue operations as before, but assuming an out-of-order queue, showing off barriers. @@ -131,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: @@ -142,19 +228,21 @@ 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- +components as separate arguments (C<$orig_x, $orig_y, $orig_z>) in +function calls. -=item * Where possible, the row_pitch value 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 - everywhere a C<$wait_events...> argument +extra arguments to the function - anywhere a C<$wait_events...> argument is documented this can be any number of event objects. =item * When enqueuing commands, if the enqueue method is called in void @@ -167,23 +255,42 @@ =back +=head2 PERL AND OPENCL TYPES + +This handy(?) table lists OpenCL types and their perl, PDL and pack/unpack +format equivalents: + + OpenCL perl PDL pack/unpack + char IV - c + uchar IV byte C + short IV short s + ushort IV ushort S + int IV long? l + uint IV - L + long IV longlong q + ulong IV - Q + float NV float f + half IV ushort S + double NV double d + =head2 THE OpenCL PACKAGE =over 4 =item $int = OpenCL::errno -The last error returned by a function - it's only changed on errors. +The last error returned by a function - it's only valid after an error occured +and before calling another OpenCL function. =item $str = OpenCL::err2str $errval Comverts an error value into a human readable string. -=item $str = OpenCL::err2str $enum +=item $str = OpenCL::enum2str $enum -Converts most enum values (inof parameter names, image format constants, +Converts most enum values (of parameter names, image format constants, object types, addressing and filter modes, command types etc.) into a -human readbale string. When confronted with some random integer it can be +human readable string. When confronted with some random integer it can be very helpful to pass it through this function to maybe get some readable string out of it. @@ -193,7 +300,7 @@ L -=item $ctx = OpenCL::context_from_type_simple $type = OpenCL::DEVICE_TYPE_DEFAULT +=item $ctx = OpenCL::context_from_type $properties, $type = OpenCL::DEVICE_TYPE_DEFAULT, $notify = undef Tries to create a context from a default device and platform - never worked for me. @@ -211,23 +318,57 @@ =over 4 +=item @devices = $platform->devices ($type = OpenCL::DEVICE_TYPE_ALL) + +Returns a list of matching OpenCL::Device objects. + +=item $ctx = $platform->context_from_type ($properties, $type = OpenCL::DEVICE_TYPE_DEFAULT, $notify = undef) + +Tries to create a context. Never worked for me, and you need devices explicitly anyway. + +L + +=item $ctx = $platform->context ($properties = undef, @$devices, $notify = undef) + +Create a new OpenCL::Context object using the given device object(s)- a +CL_CONTEXT_PLATFORM property is supplied automatically. + +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. This might get improved in the future. Hopefully. +strings, this will be the string (possibly including terminating \0), for +other values you probably need to use the correct C. + +It's best to avoid this method and use one of the following convenience +wrappers. L -=item @devices = $platform->devices ($type = OpenCL::DEVICE_TYPE_ALL) +=for gengetinfo begin platform -Returns a list of matching OpenCL::Device objects. +=item $string = $platform->profile -=item $ctx = $platform->context_from_type_simple ($type = OpenCL::DEVICE_TYPE_DEFAULT) +Calls C with C and returns the result. -Tries to create a context. Never worked for me. +=item $string = $platform->version -L +Calls C with C and returns the result. + +=item $string = $platform->name + +Calls C with C and returns the result. + +=item $string = $platform->vendor + +Calls C with C and returns the result. + +=item $string = $platform->extensions + +Calls C with C and returns the result. + +=for gengetinfo end platform =back @@ -241,27 +382,283 @@ L -=item $ctx = $device->context_simple +=for gengetinfo begin device -Convenience function to create a new OpenCL::Context object. +=item $device_type = $device->type -L +Calls C with C and returns the result. -=back +=item $uint = $device->vendor_id -=head2 THE OpenCL::Context CLASS +Calls C with C and returns the result. -=over 4 +=item $uint = $device->max_compute_units -=item $packed_value = $ctx->info ($name) +Calls C with C and returns the result. -See C<< $platform->info >> for details. +=item $uint = $device->max_work_item_dimensions -L +Calls C with C and returns the result. + +=item $int = $device->max_work_group_size + +Calls C with C and returns the result. + +=item @ints = $device->max_work_item_sizes + +Calls C with C and returns the result. + +=item $uint = $device->preferred_vector_width_char + +Calls C with C and returns the result. + +=item $uint = $device->preferred_vector_width_short + +Calls C with C and returns the result. + +=item $uint = $device->preferred_vector_width_int + +Calls C with C and returns the result. + +=item $uint = $device->preferred_vector_width_long + +Calls C with C and returns the result. + +=item $uint = $device->preferred_vector_width_float + +Calls C with C and returns the result. + +=item $uint = $device->preferred_vector_width_double + +Calls C with C and returns the result. + +=item $uint = $device->max_clock_frequency + +Calls C with C and returns the result. + +=item $bitfield = $device->address_bits + +Calls C with C and returns the result. + +=item $uint = $device->max_read_image_args + +Calls C with C and returns the result. + +=item $uint = $device->max_write_image_args + +Calls C with C and returns the result. + +=item $ulong = $device->max_mem_alloc_size + +Calls C with C and returns the result. + +=item $int = $device->image2d_max_width + +Calls C with C and returns the result. + +=item $int = $device->image2d_max_height + +Calls C with C and returns the result. + +=item $int = $device->image3d_max_width + +Calls C with C and returns the result. + +=item $int = $device->image3d_max_height + +Calls C with C and returns the result. + +=item $int = $device->image3d_max_depth + +Calls C with C and returns the result. + +=item $uint = $device->image_support + +Calls C with C and returns the result. + +=item $int = $device->max_parameter_size + +Calls C with C and returns the result. + +=item $uint = $device->max_samplers + +Calls C with C and returns the result. + +=item $uint = $device->mem_base_addr_align + +Calls C with C and returns the result. + +=item $uint = $device->min_data_type_align_size -=item $queue = $ctx->command_queue_simple ($device) +Calls C with C and returns the result. -Convenience function to create a new OpenCL::Queue object from the context and the given device. +=item $device_fp_config = $device->single_fp_config + +Calls C with C and returns the result. + +=item $device_mem_cache_type = $device->global_mem_cache_type + +Calls C with C and returns the result. + +=item $uint = $device->global_mem_cacheline_size + +Calls C with C and returns the result. + +=item $ulong = $device->global_mem_cache_size + +Calls C with C and returns the result. + +=item $ulong = $device->global_mem_size + +Calls C with C and returns the result. + +=item $ulong = $device->max_constant_buffer_size + +Calls C with C and returns the result. + +=item $uint = $device->max_constant_args + +Calls C with C and returns the result. + +=item $device_local_mem_type = $device->local_mem_type + +Calls C with C and returns the result. + +=item $ulong = $device->local_mem_size + +Calls C with C and returns the result. + +=item $boolean = $device->error_correction_support + +Calls C with C and returns the result. + +=item $int = $device->profiling_timer_resolution + +Calls C with C and returns the result. + +=item $boolean = $device->endian_little + +Calls C with C and returns the result. + +=item $boolean = $device->available + +Calls C with C and returns the result. + +=item $boolean = $device->compiler_available + +Calls C with C and returns the result. + +=item $device_exec_capabilities = $device->execution_capabilities + +Calls C with C and returns the result. + +=item $command_queue_properties = $device->properties + +Calls C with C and returns the result. + +=item $ = $device->platform + +Calls C with C and returns the result. + +=item $string = $device->name + +Calls C with C and returns the result. + +=item $string = $device->vendor + +Calls C with C and returns the result. + +=item $string = $device->driver_version + +Calls C with C and returns the result. + +=item $string = $device->profile + +Calls C with C and returns the result. + +=item $string = $device->version + +Calls C with C and returns the result. + +=item $string = $device->extensions + +Calls C with C and returns the result. + +=item $uint = $device->preferred_vector_width_half + +Calls C with C and returns the result. + +=item $uint = $device->native_vector_width_char + +Calls C with C and returns the result. + +=item $uint = $device->native_vector_width_short + +Calls C with C and returns the result. + +=item $uint = $device->native_vector_width_int + +Calls C with C and returns the result. + +=item $uint = $device->native_vector_width_long + +Calls C with C and returns the result. + +=item $uint = $device->native_vector_width_float + +Calls C with C and returns the result. + +=item $uint = $device->native_vector_width_double + +Calls C with C and returns the result. + +=item $uint = $device->native_vector_width_half + +Calls C with C and returns the result. + +=item $device_fp_config = $device->double_fp_config + +Calls C with C and returns the result. + +=item $device_fp_config = $device->half_fp_config + +Calls C with C and returns the result. + +=item $boolean = $device->host_unified_memory + +Calls C with C and returns the result. + +=item $device = $device->parent_device_ext + +Calls C with C and returns the result. + +=item @device_partition_property_exts = $device->partition_types_ext + +Calls C with C and returns the result. + +=item @device_partition_property_exts = $device->affinity_domains_ext + +Calls C with C and returns the result. + +=item $uint = $device->reference_count_ext + +Calls C with C and returns the result. + +=item @device_partition_property_exts = $device->partition_style_ext + +Calls C with C and returns the result. + +=for gengetinfo end device + +=back + +=head2 THE OpenCL::Context CLASS + +=over 4 + +=item $queue = $ctx->queue ($device, $properties) + +Create a new OpenCL::Queue object from the context and the given device. L @@ -273,26 +670,58 @@ =item $buf = $ctx->buffer ($flags, $len) -Creates a new OpenCL::Buffer object with the given flags and octet-size. +Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object with the +given flags and octet-size. L =item $buf = $ctx->buffer_sv ($flags, $data) -Creates a new OpenCL::Buffer object and initialise it with the given data values. +Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) 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. +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. +Creates a new OpenCL::Image3D object and optionally initialises it with +the given data values. L +=item $buffer = $ctx->gl_buffer ($flags, $bufobj) + +Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object that refers to the given +OpenGL buffer object. + +http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLBuffer.html + +=item $ctx->gl_texture2d ($flags, $target, $miplevel, $texture) + +Creates a new OpenCL::Image2D object that refers to the given OpenGL +2D texture object. + +http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLTexture2D.html + +=item $ctx->gl_texture3d ($flags, $target, $miplevel, $texture) + +Creates a new OpenCL::Image3D object that refers to the given OpenGL +3D texture object. + +http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLTexture3D.html + +=item $ctx->gl_renderbuffer ($flags, $renderbuffer) + +Creates a new OpenCL::Image2D object that refers to the given OpenGL +render buffer. + +http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLRenderbuffer.html + =item @formats = $ctx->supported_image_formats ($flags, $image_type) Returns a list of matching image formats - each format is an arrayref with @@ -312,6 +741,32 @@ L +=item $packed_value = $ctx->info ($name) + +See C<< $platform->info >> for details. + +L + +=for gengetinfo begin context + +=item $uint = $context->reference_count + +Calls C with C and returns the result. + +=item @devices = $context->devices + +Calls C with C and returns the result. + +=item @property_ints = $context->properties + +Calls C with C and returns the result. + +=item $uint = $context->num_devices + +Calls C with C and returns the result. + +=for gengetinfo end context + =back =head2 THE OpenCL::Queue CLASS @@ -334,12 +789,6 @@ =over 4 -=item $packed_value = $ctx->info ($name) - -See C<< $platform->info >> for details. - -L - =item $ev = $queue->enqueue_read_buffer ($buffer, $blocking, $offset, $len, $data, $wait_events...) Reads data from buffer into the given string. @@ -356,32 +805,40 @@ L -=item $ev = $queue->enqueue_read_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...) +=item $ev = $queue->enqueue_read_buffer_rect (OpenCL::Memory buf, cl_bool blocking, $buf_x, $buf_y, $buf_z, $host_x, $host_y, $host_z, $width, $height, $depth, $buf_row_pitch, $buf_slice_pitch, $host_row_pitch, $host_slice_pitch, $data, $wait_events...) -L - -=item $ev = $queue->enqueue_write_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $data, $wait_events...) +http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBufferRect.html -L +=item $ev = $queue->enqueue_write_buffer_rect (OpenCL::Memory buf, cl_bool blocking, $buf_x, $buf_y, $buf_z, $host_x, $host_y, $host_z, $width, $height, $depth, $buf_row_pitch, $buf_slice_pitch, $host_row_pitch, $host_slice_pitch, $data, $wait_events...) -=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...) +http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html -Yeah. +=item $ev = $queue->enqueue_read_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...) 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. +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_write_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...) + +L + +=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 +=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_task ($kernel, $wait_events...) L @@ -424,13 +881,38 @@ L +=item $packed_value = $queue->info ($name) + +See C<< $platform->info >> for details. + +L + +=for gengetinfo begin command_queue + +=item $ctx = $command_queue->context + +Calls C with C and returns the result. + +=item $device = $command_queue->device + +Calls C with C and returns the result. + +=item $uint = $command_queue->reference_count + +Calls C with C and returns the result. + +=item $command_queue_properties = $command_queue->properties + +Calls C with C and returns the result. + +=for gengetinfo end command_queue + =back =head2 THE OpenCL::Memory CLASS This the superclass of all memory objects - OpenCL::Buffer, OpenCL::Image, -OpenCL::Image2D and OpenCL::Image3D. The subclasses of this class -currently only exist to allow type-checking. +OpenCL::Image2D and OpenCL::Image3D. =over 4 @@ -440,29 +922,155 @@ L +=for gengetinfo begin mem + +=item $mem_object_type = $mem->type + +Calls C with C and returns the result. + +=item $mem_flags = $mem->flags + +Calls C with C and returns the result. + +=item $int = $mem->size + +Calls C with C and returns the result. + +=item $ptr_value = $mem->host_ptr + +Calls C with C and returns the result. + +=item $uint = $mem->map_count + +Calls C with C and returns the result. + +=item $uint = $mem->reference_count + +Calls C with C and returns the result. + +=item $ctx = $mem->context + +Calls C with C and returns the result. + +=item $mem = $mem->associated_memobject + +Calls C with C and returns the result. + +=item $int = $mem->offset + +Calls C with C and returns the result. + +=for gengetinfo end mem + =back -=head2 THE OpenCL::Sampler CLASS +=head2 THE OpenCL::Buffer CLASS + +This is a subclass of OpenCL::Memory, and the superclass of +OpenCL::BufferObj. Its purpose is simply to distinguish between buffers +and sub-buffers. + +=head2 THE OpenCL::BufferObj CLASS + +This is a subclass of OpenCL::Buffer and thus OpenCL::Memory. It exists +because one cna create sub buffers of OpenLC::BufferObj objects, but not +sub buffers from these sub buffers. =over 4 -=item $packed_value = $sampler->info ($name) +=item $subbuf = $buf_obj->sub_buffer_region ($flags, $origin, $size) + +Creates an OpenCL::Buffer objects from this buffer and returns it. The +C is assumed to be C. + +L + +=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. -L +The reason this method is not called C is that there already is an +C<< ->info >> method inherited from C. + +L + +=for gengetinfo begin image + +=item $int = $image->element_size + +Calls C with C and returns the result. + +=item $int = $image->row_pitch + +Calls C with C and returns the result. + +=item $int = $image->slice_pitch + +Calls C with C and returns the result. + +=item $int = $image->width + +Calls C with C and returns the result. + +=item $int = $image->height + +Calls C with C and returns the result. + +=item $int = $image->depth + +Calls C with C and returns the result. + +=for gengetinfo end image =back -=head2 THE OpenCL::Program CLASS +=head2 THE OpenCL::Sampler CLASS =over 4 -=item $packed_value = $program->info ($name) +=item $packed_value = $sampler->info ($name) See C<< $platform->info >> for details. -L +L + +=for gengetinfo begin sampler + +=item $uint = $sampler->reference_count + +Calls C with C and returns the result. + +=item $ctx = $sampler->context + +Calls C with C and returns the result. + +=item $addressing_mode = $sampler->normalized_coords + +Calls C with C and returns the result. + +=item $filter_mode = $sampler->addressing_mode + +Calls C with C and returns the result. + +=item $boolean = $sampler->filter_mode + +Calls C with C and returns the result. + +=for gengetinfo end sampler + +=back + +=head2 THE OpenCL::Program CLASS + +=over 4 =item $program->build ($device, $options = "") @@ -484,6 +1092,67 @@ L +=for gengetinfo begin program_build + +=item $build_status = $program->build_status ($device) + +Calls C with C and returns the result. + +=item $string = $program->build_options ($device) + +Calls C with C and returns the result. + +=item $string = $program->build_log ($device) + +Calls C with C and returns the result. + +=for gengetinfo end program_build + +=item $packed_value = $program->info ($name) + +See C<< $platform->info >> for details. + +L + +=for gengetinfo begin program + +=item $uint = $program->reference_count + +Calls C with C and returns the result. + +=item $ctx = $program->context + +Calls C with C and returns the result. + +=item $uint = $program->num_devices + +Calls C with C and returns the result. + +=item @devices = $program->devices + +Calls C with C and returns the result. + +=item $string = $program->source + +Calls C with C and returns the result. + +=item @ints = $program->binary_sizes + +Calls C with C and returns the result. + +=for gengetinfo end program + +=item @blobs = $program->binaries + +Returns a string for the compiled binary for every device associated with +the program, empty strings indicate missing programs, and an empty result +means no program binaries are available. + +These "binaries" are often, in fact, informative low-level assembly +sources. + +L + =back =head2 THE OpenCL::Kernel CLASS @@ -496,6 +1165,63 @@ L +=for gengetinfo begin kernel + +=item $string = $kernel->function_name + +Calls C with C and returns the result. + +=item $uint = $kernel->num_args + +Calls C with C and returns the result. + +=item $uint = $kernel->reference_count + +Calls C with C and returns the result. + +=item $ctx = $kernel->context + +Calls C with C and returns the result. + +=item $program = $kernel->program + +Calls C with C and returns the result. + +=for gengetinfo end kernel + +=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 + +=for gengetinfo begin kernel_work_group + +=item $int = $kernel->work_group_size ($device) + +Calls C with C and returns the result. + +=item @ints = $kernel->compile_work_group_size ($device) + +Calls C with C and returns the result. + +=item $ulong = $kernel->local_mem_size ($device) + +Calls C with C and returns the result. + +=item $int = $kernel->preferred_work_group_size_multiple ($device) + +Calls C with C and returns the result. + +=item $ulong = $kernel->private_mem_size ($device) + +Calls C with C and returns the result. + +=for gengetinfo end kernel_work_group + =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>. @@ -520,17 +1246,70 @@ =over 4 +=item $ev->wait + +Waits for the event to complete. + +L + =item $packed_value = $ev->info ($name) See C<< $platform->info >> for details. L -=item $ev->wait +=for gengetinfo begin event -Waits for the event to complete. +=item $queue = $event->command_queue -L +Calls C with C and returns the result. + +=item $command_type = $event->command_type + +Calls C with C and returns the result. + +=item $uint = $event->reference_count + +Calls C with C and returns the result. + +=item $uint = $event->command_execution_status + +Calls C with C and returns the result. + +=item $ctx = $event->context + +Calls C with C and returns the result. + +=for gengetinfo end event + +=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 + +=for gengetinfo begin profiling + +=item $ulong = $event->profiling_command_queued + +Calls C with C and returns the result. + +=item $ulong = $event->profiling_command_submit + +Calls C with C and returns the result. + +=item $ulong = $event->profiling_command_start + +Calls C with C and returns the result. + +=item $ulong = $event->profiling_command_end + +Calls C with C and returns the result. + +=for gengetinfo end profiling =back @@ -553,18 +1332,20 @@ use common::sense; BEGIN { - our $VERSION = '0.03'; + our $VERSION = '0.92'; require XSLoader; XSLoader::load (__PACKAGE__, $VERSION); - @OpenCL::Buffer::ISA = - @OpenCL::Image::ISA = OpenCL::Memory::; + @OpenCL::Buffer::ISA = + @OpenCL::Image::ISA = OpenCL::Memory::; + + @OpenCL::BufferObj::ISA = OpenCL::Buffer::; - @OpenCL::Image2D::ISA = - @OpenCL::Image3D::ISA = OpenCL::Image::; + @OpenCL::Image2D::ISA = + @OpenCL::Image3D::ISA = OpenCL::Image::; - @OpenCL::UserEvent::ISA = OpenCL::Event::; + @OpenCL::UserEvent::ISA = OpenCL::Event::; } 1;