--- OpenCL/OpenCL.pm 2011/11/15 06:50:30 1.1 +++ OpenCL/OpenCL.pm 2011/11/15 20:38:07 1.3 @@ -10,6 +10,19 @@ This is an early release which is not useful yet. +=head1 HELPFUL RESOURCES + +The OpenCL spec used to dveelop this module (1.2 spec was available, but +no implementation was available to me :). + + http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf + +OpenCL manpages: + + http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/ + +=head1 EXAMPLES + Enumerate all devices and get contexts for them; for my $platform (OpenCL::platforms) { @@ -28,17 +41,66 @@ my $ctx = $dev->context_simple; my $queue = $ctx->command_queue_simple ($dev); +Create a buffer with some predefined data, read it back synchronously, +then asynchronously: + + my $buf = $ctx->buffer_sv (OpenCL::MEM_COPY_HOST_PTR, "helmut"); + + $queue->enqueue_read_buffer ($buf, 1, 1, 3, my $data); + warn $data; + + my $ev = $queue->enqueue_read_buffer ($buf, 0, 1, 3, my $data); + $ev->wait; + warn $data; + +Print all supported image formats: + + for my $type (OpenCL::MEM_OBJECT_IMAGE2D, OpenCL::MEM_OBJECT_IMAGE3D) { + say "supported image formats for ", OpenCL::enum2str $type; + + for my $f ($ctx->supported_image_formats (0, $type)) { + printf " %-10s %-20s\n", OpenCL::enum2str $f->[0], OpenCL::enum2str $f->[1]; + } + } + +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) + { + size_t id = get_global_id (0); + output [id] = input [id] * input [id]; + } + '; + + my $prog = $ctx->program_with_source ($src); + + eval { $prog->build ($dev); 1 } + or die $prog->build_info ($dev, OpenCL::PROGRAM_BUILD_LOG); + + my $kernel = $prog->kernel ("squareit"); + =over 4 =cut package OpenCL; +use common::sense; + BEGIN { - $VERSION = '0.01'; + our $VERSION = '0.01'; require XSLoader; XSLoader::load (__PACKAGE__, $VERSION); + + @OpenCL::Buffer::ISA = + @OpenCL::Image::ISA = OpenCL::Memory::; + + @OpenCL::Image2D::ISA = + @OpenCL::Image3D::ISA = OpenCL::Image::; } 1;