OpenCL - Open Computing Language Bindings
use OpenCL;
This is an early release which might be useful, but hasn't seen much testing.
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.
The OpenCL specs used to develop this module - download these and keept hema round, they are required reference material:
http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf http://www.khronos.org/registry/cl/specs/opencl-1.2.pdf http://www.khronos.org/registry/cl/specs/opencl-1.2-extensions.pdf
OpenCL manpages:
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/ http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/
If you are into UML class diagrams, the following diagram might help - if not, it will be mildly confusing (also, the class hierarchy of this module is much more fine-grained):
http://www.khronos.org/registry/cl/sdk/1.2/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
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.
Best run this once to get a feel for the platforms and devices in your system.
for my $platform (OpenCL::platforms) { printf "platform: %s\n", $platform->name; printf "extensions: %s\n", $platform->extensions; for my $device ($platform->devices) { printf "+ device: %s\n", $device->name; my $ctx = $platform->context (undef, [$device]); # do stuff } }
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
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) { 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]; } }
my $buf = $ctx->buffer_sv (OpenCL::MEM_COPY_HOST_PTR, "helmut"); $queue->read_buffer ($buf, 1, 1, 3, my $data); print "$data\n"; my $ev = $queue->read_buffer ($buf, 0, 1, 3, my $data); $ev->wait; print "$data\n"; # prints "elm"
my $src = ' kernel void squareit (global float *input, global float *output) { $id = get_global_id (0); output [id] = input [id] * input [id]; } '; my $prog = $ctx->build_program ($src); my $kernel = $prog->kernel ("squareit");
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); # set buffer $kernel->set_buffer (0, $input); $kernel->set_buffer (1, $output); # execute it for all 4 numbers $queue->nd_range_kernel ($kernel, undef, [4], undef); # enqueue a synchronous read $queue->read_buffer ($output, 1, 0, OpenCL::SIZEOF_FLOAT * 4, my $data); # print the results: printf "%s\n", join ", ", unpack "f*", $data;
# execute it for all 4 numbers $queue->nd_range_kernel ($kernel, undef, [4], undef); # enqueue a barrier to ensure in-order execution $queue->barrier; # enqueue an async read $queue->read_buffer ($output, 0, 0, OpenCL::SIZEOF_FLOAT * 4, my $data); # wait for all requests to finish $queue->finish;
# execute it for all 4 numbers my $ev = $queue->nd_range_kernel ($kernel, undef, [4], undef); # enqueue an async read $ev = $queue->read_buffer ($output, 0, 0, OpenCL::SIZEOF_FLOAT * 4, my $data, $ev); # wait for the last event to complete $ev->wait;
This is quite a long example to get you going - you can also download it from http://cvs.schmorp.de/OpenCL/examples/juliaflight.
use OpenGL ":all"; use OpenCL; my $S = $ARGV[0] || 256; # window/texture size, smaller is faster # open a window and create a gl texture OpenGL::glpOpenWindow width => $S, height => $S; my $texid = glGenTextures_p 1; glBindTexture GL_TEXTURE_2D, $texid; glTexImage2D_c GL_TEXTURE_2D, 0, GL_RGBA8, $S, $S, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0; # find and use the first opencl device that let's us get a shared opengl context my $platform; my $dev; my $ctx; for (OpenCL::platforms) { $platform = $_; for ($platform->devices) { $dev = $_; $ctx = $platform->context ([OpenCL::GLX_DISPLAY_KHR, undef, OpenCL::GL_CONTEXT_KHR, undef], [$dev]) and last; } } $ctx or die "cannot find suitable OpenCL device\n"; my $queue = $ctx->queue ($dev); # now attach an opencl image2d object to the opengl texture my $tex = $ctx->gl_texture2d (OpenCL::MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, $texid); # now the boring opencl code my $src = <<EOF; kernel void juliatunnel (write_only image2d_t img, float time) { int2 xy = (int2)(get_global_id (0), get_global_id (1)); float2 p = convert_float2 (xy) / $S.f * 2.f - 1.f; float2 m = (float2)(1.f, p.y) / fabs (p.x); // tunnel m.x = fabs (fmod (m.x + time * 0.05f, 4.f) - 2.f); float2 z = m; float2 c = (float2)(sin (time * 0.01133f), cos (time * 0.02521f)); for (int i = 0; i < 25 && dot (z, z) < 4.f; ++i) // standard julia z = (float2)(z.x * z.x - z.y * z.y, 2.f * z.x * z.y) + c; float3 colour = (float3)(z.x, z.y, atan2 (z.y, z.x)); write_imagef (img, xy, (float4)(colour * p.x * p.x, 1.)); } EOF my $prog = $ctx->build_program ($src); my $kernel = $prog->kernel ("juliatunnel"); # program compiled, kernel ready, now draw and loop for (my $time; ; ++$time) { # acquire objects from opengl $queue->acquire_gl_objects ([$tex]); # configure and run our kernel $kernel->setf ("mf", $tex, $time*2); # mf = memory object, float $queue->nd_range_kernel ($kernel, undef, [$S, $S], undef); # release objects to opengl again $queue->release_gl_objects ([$tex]); # wait $queue->finish; # now draw the texture, the defaults should be all right glTexParameterf GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST; glEnable GL_TEXTURE_2D; glBegin GL_QUADS; glTexCoord2f 0, 1; glVertex3i -1, -1, -1; glTexCoord2f 0, 0; glVertex3i 1, -1, -1; glTexCoord2f 1, 0; glVertex3i 1, 1, -1; glTexCoord2f 1, 1; glVertex3i -1, 1, -1; glEnd; glXSwapBuffers; select undef, undef, undef, 1/60; }
For those poor souls with only a sucky CPU OpenCL implementation, you currently have to read the image into some perl scalar, and then modify a texture or use glDrawPixels or so).
First, when you don't need gl sharing, you can create the context much simpler:
$ctx = $platform->context (undef, [$dev])
To use a texture, you would modify the above example by creating an OpenCL::Image manually instead of deriving it from a texture:
my $tex = $ctx->image2d (OpenCL::MEM_WRITE_ONLY, OpenCL::RGBA, OpenCL::UNORM_INT8, $S, $S);
And in the draw loop, intead of acquire_gl_objects/release_gl_objects, you would read the image2d after the kernel has written it:
$queue->read_image ($tex, 0, 0, 0, 0, $S, $S, 1, 0, 0, my $data);
And then you would upload the pixel data to the texture (or use glDrawPixels):
glTexSubImage2D_s GL_TEXTURE_2D, 0, 0, 0, $S, $S, GL_RGBA, GL_UNSIGNED_BYTE, $data;
The fully modified example can be found at http://cvs.schmorp.de/OpenCL/examples/juliaflight-nosharing.
Then colour them differently, e.g. using orbit traps! Replace the loop and colour calculation from the previous examples by this:
float2 dm = (float2)(1.f, 1.f); for (int i = 0; i < 25; ++i) { z = (float2)(z.x * z.x - z.y * z.y, 2.f * z.x * z.y) + c; dm = fmin (dm, (float2)(fabs (dot (z, z) - 1.f), fabs (z.x - 1.f))); } float3 colour = (float3)(dm.x * dm.y, dm.x * dm.y, dm.x);
Also try -10.f instead of -1.f.
-10.f
-1.f
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:
Object lifetime managament is automatic - there is no need to free objects explicitly (clReleaseXXX), the release function is called automatically once all Perl references to it go away.
clReleaseXXX
OpenCL uses CamelCase for function names (e.g. clGetPlatformIDs, clGetPlatformInfo), while this module uses underscores as word separator and often leaves out prefixes (OpenCL::platforms, $platform->info).
clGetPlatformIDs
clGetPlatformInfo
OpenCL::platforms
$platform->info
OpenCL often specifies fixed vector function arguments as short arrays (size_t origin[3]), while this module explicitly expects the components as separate arguments ($orig_x, $orig_y, $orig_z) in function calls.
size_t origin[3]
$orig_x, $orig_y, $orig_z
Structures are often specified by flattening out their components as with short vectors, and returned as arrayrefs.
When enqueuing commands, the wait list is specified by adding extra arguments to the function - anywhere a $wait_events... argument is documented this can be any number of event objects. As an extsnion implemented by this module, undef values will be ignored in the event list.
$wait_events...
undef
When enqueuing commands, if the enqueue method is called in void context, no event is created. In all other contexts an event is returned by the method.
This module expects all functions to return OpenCL::SUCCESS. If any other status is returned the function will throw an exception, so you don't normally have to to any error checking.
OpenCL::SUCCESS
All CL_xxx constants that this module supports are always available in the OpenCL namespace as OpenCL::xxx (i.e. without the CL_ prefix). Constants which are not defined in the header files used during compilation, or otherwise are not available, will have the value 0 (in some cases, this will make them indistinguishable from real constants, sorry).
CL_xxx
OpenCL
OpenCL::xxx
CL_
0
The latest version of this module knows and exports the constants listed in http://cvs.schmorp.de/OpenCL/constiv.h.
This module supports both OpenCL version 1.1 and 1.2, although the OpenCL 1.2 interface hasn't been tested much for lack of availability of an actual implementation.
Every function or method in this manual page that interfaces to a particular OpenCL function has a link to the its C manual page.
If the link contains a 1.1, then this function is an OpenCL 1.1 function. Most but not all also exist in OpenCL 1.2, and this module tries to emulate the missing ones for you, when told to do so at compiletime. You can check whether a function was removed in OpenCL 1.2 by replacing the 1.1 component in the URL by 1.2.
If the link contains a 1.2, then this is a OpenCL 1.2-only function. Even if the module was compiled with OpenCL 1.2 header files and has an 1.2 OpenCL library, calling such a function on a platform that doesn't implement 1.2 causes undefined behaviour, usually a crash (But this is not guaranteed).
You can find out whether this module was compiled to prefer 1.1 functionality by ooking at OpenCL::PREFER_1_1 - if it is true, then 1.1 functions generally are implemented using 1.1 OpenCL functions. If it is false, then 1.1 functions missing from 1.2 are emulated by calling 1.2 fucntions.
OpenCL::PREFER_1_1
This is a somewhat sorry state of affairs, but the Khronos group choose to make every release of OpenCL source and binary incompatible with previous releases.
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
Due to the sad state that OpenGL support is in in Perl (mostly the OpenGL module, which has little to no documentation and has little to no support for glX), this module, as a special extension, treats context creation properties OpenCL::GLX_DISPLAY_KHR and OpenCL::GL_CONTEXT_KHR specially: If either or both of these are undef, then the OpenCL module tries to dynamically resolve glXGetCurrentDisplay and glXGetCurrentContext, call these functions and use their return values instead.
OpenCL::GLX_DISPLAY_KHR
OpenCL::GL_CONTEXT_KHR
glXGetCurrentDisplay
glXGetCurrentContext
For this to work, the OpenGL library must be loaded, a GLX context must have been created and be made current, and dlsym must be available and capable of finding the function via RTLD_DEFAULT.
dlsym
RTLD_DEFAULT
OpenCL can generate a number of (potentially) asynchronous events, for example, after compiling a program, to signal a context-related error or, perhaps most important, to signal completion of queued jobs (by setting callbacks on OpenCL::Event objects).
The OpenCL module converts all these callbacks into events - you can still register callbacks, but they are not executed when your OpenCL implementation calls the actual callback, but only later. Therefore, none of the limitations of OpenCL callbacks apply to the perl implementation: it is perfectly safe to make blocking operations from event callbacks, and enqueued operations don't need to be flushed.
To facilitate this, this module maintains an event queue - each time an asynchronous event happens, it is queued, and perl will be interrupted. This is implemented via the Async::Interrupt module. In addition, this module has AnyEvent support, so it can seamlessly integrate itself into many event loops.
Since Async::Interrupt is a bit hard to understand, here are some case examples:
When your program never uses any callbacks, then there will never be any notifications you need to take care of, and therefore no need to worry about all this.
You can achieve a great deal by explicitly waiting for events, or using barriers and flush calls. In many programs, there is no need at all to tinker with asynchronous events.
This module automatically registers a watcher that invokes all outstanding event callbacks when AnyEvent is initialised (and block asynchronous interruptions). Using this mode of operations is the safest and most recommended one.
To use this, simply use AnyEvent and this module normally, make sure you have an event loop running:
use Gtk2 -init; use AnyEvent; # initialise AnyEvent, by creating a watcher, or: AnyEvent::detect; my $e = $queue->marker; $e->cb (sub { warn "opencl is finished\n"; }) main Gtk2;
Note that this module will not initialise AnyEvent for you. Before AnyEvent is initialised, the module will asynchronously interrupt perl instead. To avoid any surprises, it's best to explicitly initialise AnyEvent.
You can temporarily enable asynchronous interruptions (see next paragraph) by calling $OpenCL::INTERRUPT-unblock> and disable them again by calling $OpenCL::INTERRUPT-block>.
$OpenCL::INTERRUPT-
This mode is the default unless AnyEvent is loaded and initialised. In this mode, OpenCL asynchronously interrupts a running perl program. The emphasis is on both asynchronously and running here.
Asynchronously means that perl might execute your callbacks at any time. For example, in the following code (THAT YOU SHOULD NOT COPY), the until loop following the marker call will be interrupted by the callback:
until
my $e = $queue->marker; my $flag; $e->cb (sub { $flag = 1 }); 1 until $flag; # $flag is now 1
The reason why you shouldn't blindly copy the above code is that busy waiting is a really really bad thing, and really really bad for performance.
While at first this asynchronous business might look exciting, it can be really hard, because you need to be prepared for the callback code to be executed at any time, which limits the amount of things the callback code can do safely.
This can be mitigated somewhat by using $OpenCL::INTERRUPT->scope_block (see the Async::Interrupt documentation for details).
$OpenCL::INTERRUPT->scope_block
The other problem is that your program must be actively running to be interrupted. When you calculate stuff, your program is running. When you hang in some C functions or other block execution (by calling sleep, select, running an event loop and so on), your program is waiting, not running.
sleep
select
One way around that would be to attach a read watcher to your event loop, listening for events on $OpenCL::INTERRUPT->pipe_fileno, using a dummy callback (sub { }) to temporarily execute some perl code.
$OpenCL::INTERRUPT->pipe_fileno
sub { }
That is then awfully close to using the built-in AnyEvent support above, though, so consider that one instead.
OpenCL exports the Async::Interrupt object it uses in the global variable $OpenCL::INTERRUPT. You can configure it in any way you like.
$OpenCL::INTERRUPT
So if you want to feel like a real pro, err, wait, if you feel no risk menas no fun, you can experiment by implementing your own mode of operations.
The last error returned by a function - it's only valid after an error occured and before calling another OpenCL function.
Converts an error value into a human readable string. If no error value is given, then the last error will be used (as returned by OpenCL::errno).
The latest version of this module knows the error constants listed in http://cvs.schmorp.de/OpenCL/errstr.h.
Converts most enum values (of parameter names, image format constants, object types, addressing and filter modes, command types etc.) into a 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.
The latest version of this module knows the enumaration constants listed in http://cvs.schmorp.de/OpenCL/enumstr.h.
Returns all available OpenCL::Platform objects.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformIDs.html
Tries to create a context from a default device and platform type - never worked for me. Consider using $platform->context_from_type instead.
$platform->context_from_type
type: OpenCL::DEVICE_TYPE_DEFAULT, OpenCL::DEVICE_TYPE_CPU, OpenCL::DEVICE_TYPE_GPU, OpenCL::DEVICE_TYPE_ACCELERATOR, OpenCL::DEVICE_TYPE_CUSTOM, OpenCL::DEVICE_TYPE_ALL.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html
Create a new OpenCL::Context object using the given device object(s). Consider using $platform->context instead.
$platform->context
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html
Waits for all events to complete.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clWaitForEvents.html
Checks if there are any outstanding events (see "EVENT SYSTEM") and invokes their callbacks.
The Async::Interrupt object used to signal asynchronous events (see "EVENT SYSTEM").
The AnyEvent watcher object used to watch for asynchronous events (see "EVENT SYSTEM"). This variable is undef until AnyEvent has been loaded and initialised (e.g. by calling AnyEvent::detect).
AnyEvent::detect
This is the base class for all objects in the OpenCL module. The only method it implements is the id method, which is only useful if you want to interface to OpenCL on the C level.
id
OpenCL objects are represented by pointers or integers on the C level. If you want to interface to an OpenCL object directly on the C level, then you need this value, which is returned by this method. You should use an IV type in your code and cast that to the correct type.
IV
Returns a list of matching OpenCL::Device objects.
Tries to create a context. Never worked for me, and you need devices explicitly anyway.
Create a new OpenCL::Context object using the given device object(s)- a OpenCL::CONTEXT_PLATFORM property is supplied automatically.
Calls clGetPlatformInfo and returns the packed, raw value - for strings, this will be the string (possibly including terminating \0), for other values you probably need to use the correct unpack.
unpack
It's best to avoid this method and use one of the following convenience wrappers.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformInfo.html
Attempts to unload the compiler for this platform, for endless profit. Does nothing on OpenCL 1.1.
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clUnloadPlatformCompiler.html
Calls clGetPlatformInfo with OpenCL::PLATFORM_PROFILE and returns the result.
OpenCL::PLATFORM_PROFILE
Calls clGetPlatformInfo with OpenCL::PLATFORM_VERSION and returns the result.
OpenCL::PLATFORM_VERSION
Calls clGetPlatformInfo with OpenCL::PLATFORM_NAME and returns the result.
OpenCL::PLATFORM_NAME
Calls clGetPlatformInfo with OpenCL::PLATFORM_VENDOR and returns the result.
OpenCL::PLATFORM_VENDOR
Calls clGetPlatformInfo with OpenCL::PLATFORM_EXTENSIONS and returns the result.
OpenCL::PLATFORM_EXTENSIONS
See $platform->info for details.
fp_config: OpenCL::FP_DENORM, OpenCL::FP_INF_NAN, OpenCL::FP_ROUND_TO_NEAREST, OpenCL::FP_ROUND_TO_ZERO, OpenCL::FP_ROUND_TO_INF, OpenCL::FP_FMA, OpenCL::FP_SOFT_FLOAT, OpenCL::FP_CORRECTLY_ROUNDED_DIVIDE_SQRT.
mem_cache_type: OpenCL::NONE, OpenCL::READ_ONLY_CACHE, OpenCL::READ_WRITE_CACHE.
local_mem_type: OpenCL::LOCAL, OpenCL::GLOBAL.
exec_capabilities: OpenCL::EXEC_KERNEL, OpenCL::EXEC_NATIVE_KERNEL.
command_queue_properties: OpenCL::QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, OpenCL::QUEUE_PROFILING_ENABLE.
partition_properties: OpenCL::DEVICE_PARTITION_EQUALLY, OpenCL::DEVICE_PARTITION_BY_COUNTS, OpenCL::DEVICE_PARTITION_BY_COUNTS_LIST_END, OpenCL::DEVICE_PARTITION_BY_AFFINITY_DOMAIN.
affinity_domain: OpenCL::DEVICE_AFFINITY_DOMAIN_NUMA, OpenCL::DEVICE_AFFINITY_DOMAIN_L4_CACHE, OpenCL::DEVICE_AFFINITY_DOMAIN_L3_CACHE, OpenCL::DEVICE_AFFINITY_DOMAIN_L2_CACHE, OpenCL::DEVICE_AFFINITY_DOMAIN_L1_CACHE, OpenCL::DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetDeviceInfo.html
Creates OpencL::SubDevice objects by partitioning an existing device.
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateSubDevices.html
Calls clGetDeviceInfo with OpenCL::DEVICE_TYPE and returns the result.
clGetDeviceInfo
OpenCL::DEVICE_TYPE
Calls clGetDeviceInfo with OpenCL::DEVICE_VENDOR_ID and returns the result.
OpenCL::DEVICE_VENDOR_ID
Calls clGetDeviceInfo with OpenCL::DEVICE_MAX_COMPUTE_UNITS and returns the result.
OpenCL::DEVICE_MAX_COMPUTE_UNITS
Calls clGetDeviceInfo with OpenCL::DEVICE_MAX_WORK_ITEM_DIMENSIONS and returns the result.
OpenCL::DEVICE_MAX_WORK_ITEM_DIMENSIONS
Calls clGetDeviceInfo with OpenCL::DEVICE_MAX_WORK_GROUP_SIZE and returns the result.
OpenCL::DEVICE_MAX_WORK_GROUP_SIZE
Calls clGetDeviceInfo with OpenCL::DEVICE_MAX_WORK_ITEM_SIZES and returns the result.
OpenCL::DEVICE_MAX_WORK_ITEM_SIZES
Calls clGetDeviceInfo with OpenCL::DEVICE_PREFERRED_VECTOR_WIDTH_CHAR and returns the result.
OpenCL::DEVICE_PREFERRED_VECTOR_WIDTH_CHAR
Calls clGetDeviceInfo with OpenCL::DEVICE_PREFERRED_VECTOR_WIDTH_SHORT and returns the result.
OpenCL::DEVICE_PREFERRED_VECTOR_WIDTH_SHORT
Calls clGetDeviceInfo with OpenCL::DEVICE_PREFERRED_VECTOR_WIDTH_INT and returns the result.
OpenCL::DEVICE_PREFERRED_VECTOR_WIDTH_INT
Calls clGetDeviceInfo with OpenCL::DEVICE_PREFERRED_VECTOR_WIDTH_LONG and returns the result.
OpenCL::DEVICE_PREFERRED_VECTOR_WIDTH_LONG
Calls clGetDeviceInfo with OpenCL::DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT and returns the result.
OpenCL::DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT
Calls clGetDeviceInfo with OpenCL::DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE and returns the result.
OpenCL::DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE
Calls clGetDeviceInfo with OpenCL::DEVICE_MAX_CLOCK_FREQUENCY and returns the result.
OpenCL::DEVICE_MAX_CLOCK_FREQUENCY
Calls clGetDeviceInfo with OpenCL::DEVICE_ADDRESS_BITS and returns the result.
OpenCL::DEVICE_ADDRESS_BITS
Calls clGetDeviceInfo with OpenCL::DEVICE_MAX_READ_IMAGE_ARGS and returns the result.
OpenCL::DEVICE_MAX_READ_IMAGE_ARGS
Calls clGetDeviceInfo with OpenCL::DEVICE_MAX_WRITE_IMAGE_ARGS and returns the result.
OpenCL::DEVICE_MAX_WRITE_IMAGE_ARGS
Calls clGetDeviceInfo with OpenCL::DEVICE_MAX_MEM_ALLOC_SIZE and returns the result.
OpenCL::DEVICE_MAX_MEM_ALLOC_SIZE
Calls clGetDeviceInfo with OpenCL::DEVICE_IMAGE2D_MAX_WIDTH and returns the result.
OpenCL::DEVICE_IMAGE2D_MAX_WIDTH
Calls clGetDeviceInfo with OpenCL::DEVICE_IMAGE2D_MAX_HEIGHT and returns the result.
OpenCL::DEVICE_IMAGE2D_MAX_HEIGHT
Calls clGetDeviceInfo with OpenCL::DEVICE_IMAGE3D_MAX_WIDTH and returns the result.
OpenCL::DEVICE_IMAGE3D_MAX_WIDTH
Calls clGetDeviceInfo with OpenCL::DEVICE_IMAGE3D_MAX_HEIGHT and returns the result.
OpenCL::DEVICE_IMAGE3D_MAX_HEIGHT
Calls clGetDeviceInfo with OpenCL::DEVICE_IMAGE3D_MAX_DEPTH and returns the result.
OpenCL::DEVICE_IMAGE3D_MAX_DEPTH
Calls clGetDeviceInfo with OpenCL::DEVICE_IMAGE_SUPPORT and returns the result.
OpenCL::DEVICE_IMAGE_SUPPORT
Calls clGetDeviceInfo with OpenCL::DEVICE_MAX_PARAMETER_SIZE and returns the result.
OpenCL::DEVICE_MAX_PARAMETER_SIZE
Calls clGetDeviceInfo with OpenCL::DEVICE_MAX_SAMPLERS and returns the result.
OpenCL::DEVICE_MAX_SAMPLERS
Calls clGetDeviceInfo with OpenCL::DEVICE_MEM_BASE_ADDR_ALIGN and returns the result.
OpenCL::DEVICE_MEM_BASE_ADDR_ALIGN
Calls clGetDeviceInfo with OpenCL::DEVICE_MIN_DATA_TYPE_ALIGN_SIZE and returns the result.
OpenCL::DEVICE_MIN_DATA_TYPE_ALIGN_SIZE
Calls clGetDeviceInfo with OpenCL::DEVICE_SINGLE_FP_CONFIG and returns the result.
OpenCL::DEVICE_SINGLE_FP_CONFIG
Calls clGetDeviceInfo with OpenCL::DEVICE_GLOBAL_MEM_CACHE_TYPE and returns the result.
OpenCL::DEVICE_GLOBAL_MEM_CACHE_TYPE
Calls clGetDeviceInfo with OpenCL::DEVICE_GLOBAL_MEM_CACHELINE_SIZE and returns the result.
OpenCL::DEVICE_GLOBAL_MEM_CACHELINE_SIZE
Calls clGetDeviceInfo with OpenCL::DEVICE_GLOBAL_MEM_CACHE_SIZE and returns the result.
OpenCL::DEVICE_GLOBAL_MEM_CACHE_SIZE
Calls clGetDeviceInfo with OpenCL::DEVICE_GLOBAL_MEM_SIZE and returns the result.
OpenCL::DEVICE_GLOBAL_MEM_SIZE
Calls clGetDeviceInfo with OpenCL::DEVICE_MAX_CONSTANT_BUFFER_SIZE and returns the result.
OpenCL::DEVICE_MAX_CONSTANT_BUFFER_SIZE
Calls clGetDeviceInfo with OpenCL::DEVICE_MAX_CONSTANT_ARGS and returns the result.
OpenCL::DEVICE_MAX_CONSTANT_ARGS
Calls clGetDeviceInfo with OpenCL::DEVICE_LOCAL_MEM_TYPE and returns the result.
OpenCL::DEVICE_LOCAL_MEM_TYPE
Calls clGetDeviceInfo with OpenCL::DEVICE_LOCAL_MEM_SIZE and returns the result.
OpenCL::DEVICE_LOCAL_MEM_SIZE
Calls clGetDeviceInfo with OpenCL::DEVICE_ERROR_CORRECTION_SUPPORT and returns the result.
OpenCL::DEVICE_ERROR_CORRECTION_SUPPORT
Calls clGetDeviceInfo with OpenCL::DEVICE_PROFILING_TIMER_RESOLUTION and returns the result.
OpenCL::DEVICE_PROFILING_TIMER_RESOLUTION
Calls clGetDeviceInfo with OpenCL::DEVICE_ENDIAN_LITTLE and returns the result.
OpenCL::DEVICE_ENDIAN_LITTLE
Calls clGetDeviceInfo with OpenCL::DEVICE_AVAILABLE and returns the result.
OpenCL::DEVICE_AVAILABLE
Calls clGetDeviceInfo with OpenCL::DEVICE_COMPILER_AVAILABLE and returns the result.
OpenCL::DEVICE_COMPILER_AVAILABLE
Calls clGetDeviceInfo with OpenCL::DEVICE_EXECUTION_CAPABILITIES and returns the result.
OpenCL::DEVICE_EXECUTION_CAPABILITIES
Calls clGetDeviceInfo with OpenCL::DEVICE_QUEUE_PROPERTIES and returns the result.
OpenCL::DEVICE_QUEUE_PROPERTIES
Calls clGetDeviceInfo with OpenCL::DEVICE_PLATFORM and returns the result.
OpenCL::DEVICE_PLATFORM
Calls clGetDeviceInfo with OpenCL::DEVICE_NAME and returns the result.
OpenCL::DEVICE_NAME
Calls clGetDeviceInfo with OpenCL::DEVICE_VENDOR and returns the result.
OpenCL::DEVICE_VENDOR
Calls clGetDeviceInfo with OpenCL::DRIVER_VERSION and returns the result.
OpenCL::DRIVER_VERSION
Calls clGetDeviceInfo with OpenCL::DEVICE_PROFILE and returns the result.
OpenCL::DEVICE_PROFILE
Calls clGetDeviceInfo with OpenCL::DEVICE_VERSION and returns the result.
OpenCL::DEVICE_VERSION
Calls clGetDeviceInfo with OpenCL::DEVICE_EXTENSIONS and returns the result.
OpenCL::DEVICE_EXTENSIONS
Calls clGetDeviceInfo with OpenCL::DEVICE_PREFERRED_VECTOR_WIDTH_HALF and returns the result.
OpenCL::DEVICE_PREFERRED_VECTOR_WIDTH_HALF
Calls clGetDeviceInfo with OpenCL::DEVICE_NATIVE_VECTOR_WIDTH_CHAR and returns the result.
OpenCL::DEVICE_NATIVE_VECTOR_WIDTH_CHAR
Calls clGetDeviceInfo with OpenCL::DEVICE_NATIVE_VECTOR_WIDTH_SHORT and returns the result.
OpenCL::DEVICE_NATIVE_VECTOR_WIDTH_SHORT
Calls clGetDeviceInfo with OpenCL::DEVICE_NATIVE_VECTOR_WIDTH_INT and returns the result.
OpenCL::DEVICE_NATIVE_VECTOR_WIDTH_INT
Calls clGetDeviceInfo with OpenCL::DEVICE_NATIVE_VECTOR_WIDTH_LONG and returns the result.
OpenCL::DEVICE_NATIVE_VECTOR_WIDTH_LONG
Calls clGetDeviceInfo with OpenCL::DEVICE_NATIVE_VECTOR_WIDTH_FLOAT and returns the result.
OpenCL::DEVICE_NATIVE_VECTOR_WIDTH_FLOAT
Calls clGetDeviceInfo with OpenCL::DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE and returns the result.
OpenCL::DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE
Calls clGetDeviceInfo with OpenCL::DEVICE_NATIVE_VECTOR_WIDTH_HALF and returns the result.
OpenCL::DEVICE_NATIVE_VECTOR_WIDTH_HALF
Calls clGetDeviceInfo with OpenCL::DEVICE_DOUBLE_FP_CONFIG and returns the result.
OpenCL::DEVICE_DOUBLE_FP_CONFIG
Calls clGetDeviceInfo with OpenCL::DEVICE_HALF_FP_CONFIG and returns the result.
OpenCL::DEVICE_HALF_FP_CONFIG
Calls clGetDeviceInfo with OpenCL::DEVICE_HOST_UNIFIED_MEMORY and returns the result.
OpenCL::DEVICE_HOST_UNIFIED_MEMORY
Calls clGetDeviceInfo with OpenCL::DEVICE_PARENT_DEVICE_EXT and returns the result.
OpenCL::DEVICE_PARENT_DEVICE_EXT
Calls clGetDeviceInfo with OpenCL::DEVICE_PARTITION_TYPES_EXT and returns the result.
OpenCL::DEVICE_PARTITION_TYPES_EXT
Calls clGetDeviceInfo with OpenCL::DEVICE_AFFINITY_DOMAINS_EXT and returns the result.
OpenCL::DEVICE_AFFINITY_DOMAINS_EXT
Calls clGetDeviceInfo with OpenCL::DEVICE_REFERENCE_COUNT_EXT and returns the result.
OpenCL::DEVICE_REFERENCE_COUNT_EXT
Calls clGetDeviceInfo with OpenCL::DEVICE_PARTITION_STYLE_EXT and returns the result.
OpenCL::DEVICE_PARTITION_STYLE_EXT
An OpenCL::Context is basically a container, or manager, for a number of devices of a platform. It is used to create all sorts of secondary objects such as buffers, queues, programs and so on.
All context creation functions and methods take a list of properties (type-value pairs). All property values can be specified as integers - some additionally support other types:
Also accepts OpenCL::Platform objects.
Also accepts undef, in which case a deep and troubling hack is engaged to find the current glx display (see "GLX SUPPORT").
Also accepts undef, in which case a deep and troubling hack is engaged to find the current glx context (see "GLX SUPPORT").
This convenience function tries to build the program on all devices in the context. If the build fails, then the function will croak with the build log. Otherwise ti returns the program object.
croak
The $program can either be a OpenCL::Program object or a string containing the program. In the latter case, a program objetc will be created automatically.
$program
OpenCL::Program
Create a new OpenCL::Queue object from the context and the given device.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateCommandQueue.html
Example: create an out-of-order queue.
$queue = $ctx->queue ($device, OpenCL::QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE);
Creates a new OpenCL::UserEvent object.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateUserEvent.html
Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object with the given flags and octet-size.
flags: OpenCL::MEM_READ_WRITE, OpenCL::MEM_WRITE_ONLY, OpenCL::MEM_READ_ONLY, OpenCL::MEM_USE_HOST_PTR, OpenCL::MEM_ALLOC_HOST_PTR, OpenCL::MEM_COPY_HOST_PTR, OpenCL::MEM_HOST_WRITE_ONLY, OpenCL::MEM_HOST_READ_ONLY, OpenCL::MEM_HOST_NO_ACCESS.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html
Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and initialise it with the given data values.
Creates a new OpenCL::Image object and optionally initialises it with the given data values.
channel_order: OpenCL::R, OpenCL::A, OpenCL::RG, OpenCL::RA, OpenCL::RGB, OpenCL::RGBA, OpenCL::BGRA, OpenCL::ARGB, OpenCL::INTENSITY, OpenCL::LUMINANCE, OpenCL::Rx, OpenCL::RGx, OpenCL::RGBx.
channel_type: OpenCL::SNORM_INT8, OpenCL::SNORM_INT16, OpenCL::UNORM_INT8, OpenCL::UNORM_INT16, OpenCL::UNORM_SHORT_565, OpenCL::UNORM_SHORT_555, OpenCL::UNORM_INT_101010, OpenCL::SIGNED_INT8, OpenCL::SIGNED_INT16, OpenCL::SIGNED_INT32, OpenCL::UNSIGNED_INT8, OpenCL::UNSIGNED_INT16, OpenCL::UNSIGNED_INT32, OpenCL::HALF_FLOAT, OpenCL::FLOAT.
type: OpenCL::MEM_OBJECT_BUFFER, OpenCL::MEM_OBJECT_IMAGE2D, OpenCL::MEM_OBJECT_IMAGE3D, OpenCL::MEM_OBJECT_IMAGE2D_ARRAY, OpenCL::MEM_OBJECT_IMAGE1D, OpenCL::MEM_OBJECT_IMAGE1D_ARRAY, OpenCL::MEM_OBJECT_IMAGE1D_BUFFER.
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateImage.html
Creates a new OpenCL::Image2D object and optionally initialises it with the given data values.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage2D.html
Creates a new OpenCL::Image3D object and optionally initialises it with the given data values.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage3D.html
Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object that refers to the given OpenGL buffer object.
flags: OpenCL::MEM_READ_WRITE, OpenCL::MEM_READ_ONLY, OpenCL::MEM_WRITE_ONLY.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLBuffer.html
Creates a new OpenCL::Image object that refers to the given OpenGL texture object or buffer.
target: GL_TEXTURE_1D, GL_TEXTURE_1D_ARRAY, GL_TEXTURE_BUFFER, GL_TEXTURE_2D, GL_TEXTURE_2D_ARRAY, GL_TEXTURE_3D, GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, GL_TEXTURE_RECTANGLE/GL_TEXTURE_RECTANGLE_ARB.
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateFromGLTexture.html
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
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
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
Returns a list of matching image formats - each format is an arrayref with two values, $channel_order and $channel_type, in it.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetSupportedImageFormats.html
Creates a new OpenCL::Sampler object.
addressing_mode: OpenCL::ADDRESS_NONE, OpenCL::ADDRESS_CLAMP_TO_EDGE, OpenCL::ADDRESS_CLAMP, OpenCL::ADDRESS_REPEAT, OpenCL::ADDRESS_MIRRORED_REPEAT.
filter_mode: OpenCL::FILTER_NEAREST, OpenCL::FILTER_LINEAR.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateSampler.html
Creates a new OpenCL::Program object from the given source code.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateProgramWithSource.html
Creates a new OpenCL::Program object from the given binaries.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateProgramWithBinary.html
Example: clone an existing program object that contains a successfully compiled program, no matter how useless this is.
my $clone = $ctx->program_with_binary ([$prog->devices], [$prog->binaries]);
Creates a new OpenCL::Program object from the given built-in kernel names.
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateProgramWithBuiltInKernels.html
Links all (already compiled) program objects specified in @programs together and returns a new OpenCL::Program object with the result.
@programs
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clLinkProgram.html
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetContextInfo.html
Calls clGetContextInfo with OpenCL::CONTEXT_REFERENCE_COUNT and returns the result.
clGetContextInfo
OpenCL::CONTEXT_REFERENCE_COUNT
Calls clGetContextInfo with OpenCL::CONTEXT_DEVICES and returns the result.
OpenCL::CONTEXT_DEVICES
Calls clGetContextInfo with OpenCL::CONTEXT_PROPERTIES and returns the result.
OpenCL::CONTEXT_PROPERTIES
Calls clGetContextInfo with OpenCL::CONTEXT_NUM_DEVICES and returns the result.
OpenCL::CONTEXT_NUM_DEVICES
An OpenCL::Queue represents an execution queue for OpenCL. You execute requests by calling their respective method and waiting for it to complete in some way.
Most methods that enqueue some request return an event object that can be used to wait for completion (optionally using a callback), unless the method is called in void context, in which case no event object is created.
They also allow you to specify any number of other event objects that this request has to wait for before it starts executing, by simply passing the event objects as extra parameters to the enqueue methods. To simplify program design, this module ignores any undef values in the list of events. This makes it possible to code operations such as this, without having to put a valid event object into $event first:
$event
$event = $queue->xxx (..., $event);
Queues execute in-order by default, without any parallelism, so in most cases (i.e. you use only one queue) it's not necessary to wait for or create event objects, althoguh an our of order queue is often a bit faster.
Reads data from buffer into the given string.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBuffer.html
Writes data to buffer from the given string.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBuffer.html
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBuffer.html
$eue->read_buffer_rect ($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...)
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBufferRect.html
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html
$row_pitch (and $slice_pitch) can be 0, in which case the OpenCL module uses the image width (and height) to supply default values.
$row_pitch
$slice_pitch
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadImage.html
$row_pitch (and $slice_pitch) can be 0, in which case the OpenCL module uses the image width (and height) to supply default values. http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteImage.html
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImage.html
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImageToBuffer.html
Yeah.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html.
Fills the given buffer object with repeated applications of $pattern, starting at $offset for $size octets.
$pattern
$offset
$size
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueFillBuffer.html
Fills the given image area with the given rgba colour components. The components are normally floating point values between 0 and 1, except when the image channel data type is a signe dor unsigned unnormalised format, in which case the range is determined by the format.
1
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueFillImage.html
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueTask.html
Enqueues a kernel execution.
\@global_work_size must be specified as a reference to an array of integers specifying the work sizes (element counts).
\@global_work_offset must be either undef (in which case all offsets are 0), or a reference to an array of work offsets, with the same number of elements as \@global_work_size.
\@local_work_size must be either undef (in which case the implementation is supposed to choose good local work sizes), or a reference to an array of local work sizes, with the same number of elements as \@global_work_size.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueNDRangeKernel.html
Migrates a number of OpenCL::Memory objects to or from the device.
flags: OpenCL::MIGRATE_MEM_OBJECT_HOST, OpenCL::MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueMigrateMemObjects.html
Enqueues a list (an array-ref of OpenCL::Memory objects) to be acquired for subsequent OpenCL usage.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueAcquireGLObjects.html
Enqueues a list (an array-ref of OpenCL::Memory objects) to be released for subsequent OpenGL usage.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReleaseGLObjects.html
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWaitForEvents.html
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueMarkerWithWaitList.html
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueBarrierWithWaitList.html
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clFlush.html
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clFinish.html
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetCommandQueueInfo.html
Calls clGetCommandQueueInfo with OpenCL::QUEUE_CONTEXT and returns the result.
clGetCommandQueueInfo
OpenCL::QUEUE_CONTEXT
Calls clGetCommandQueueInfo with OpenCL::QUEUE_DEVICE and returns the result.
OpenCL::QUEUE_DEVICE
Calls clGetCommandQueueInfo with OpenCL::QUEUE_REFERENCE_COUNT and returns the result.
OpenCL::QUEUE_REFERENCE_COUNT
Calls clGetCommandQueueInfo with OpenCL::QUEUE_PROPERTIES and returns the result.
OpenCL::QUEUE_PROPERTIES
OpenCL allows you to map buffers and images to host memory (read: perl scalars). This is done much like reading or copying a buffer, by enqueuing a map or unmap operation on the command queue.
The map operations return an OpenCL::Mapped object - see "THE OpenCL::Mapped CLASS" section for details on what to do with these objects.
OpenCL::Mapped
The object will be unmapped automatically when the mapped object is destroyed (you can use a barrier to make sure the unmap has finished, before using the buffer in a kernel), but you can also enqueue an unmap operation manually.
Maps the given buffer into host memory and returns an OpenCL::MappedBuffer object. If $size is specified as undef, then the map will extend to the end of the buffer.
OpenCL::MappedBuffer
map_flags: OpenCL::MAP_READ, OpenCL::MAP_WRITE, OpenCL::MAP_WRITE_INVALIDATE_REGION.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueMapBuffer.html
Example: map the buffer $buf fully and replace the first 4 bytes by "abcd", then unmap.
{ my $mapped = $queue->map_buffer ($buf, 1, OpenCL::MAP_WRITE); substr $$mapped, 0, 4, "abcd"; } # asynchronously unmap because $mapped is destroyed
Maps the given image area into host memory and return an OpenCL::MappedImage object.
OpenCL::MappedImage
If any of $width, $height and/or $depth are undef then they will be replaced by the maximum possible value.
$width
$height
$depth
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueMapImage.html
Example: map an image (with OpenCL::UNSIGNED_INT8 channel type) and set the first channel of the leftmost column to 5, then explicitly unmap it. You are not necessarily meant to do it this way, this example just shows you the accessors to use :)
my $mapped = $queue->map_image ($image, 1, OpenCL::MAP_WRITE); $mapped->write ($_ * $mapped->row_pitch, pack "C", 5) for 0 .. $mapped->height - 1; $mapped->unmap;. $mapped->wait; # only needed for out of order queues normally
Unmaps the data from host memory. You must not call any methods that modify the data, or modify the data scalar directly, after calling this method.
The mapped event object will always be passed as part of the $wait_events. The mapped event object will be replaced by the new event object that this request creates.
This the superclass of all memory objects - OpenCL::Buffer, OpenCL::Image, OpenCL::Image2D and OpenCL::Image3D.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetMemObjectInfo.html
Sets a callback that will be invoked after the memory object is destructed.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clSetMemObjectDestructorCallback.html
Calls clGetMemObjectInfo with OpenCL::MEM_TYPE and returns the result.
clGetMemObjectInfo
OpenCL::MEM_TYPE
Calls clGetMemObjectInfo with OpenCL::MEM_FLAGS and returns the result.
OpenCL::MEM_FLAGS
Calls clGetMemObjectInfo with OpenCL::MEM_SIZE and returns the result.
OpenCL::MEM_SIZE
Calls clGetMemObjectInfo with OpenCL::MEM_HOST_PTR and returns the result.
OpenCL::MEM_HOST_PTR
Calls clGetMemObjectInfo with OpenCL::MEM_MAP_COUNT and returns the result.
OpenCL::MEM_MAP_COUNT
Calls clGetMemObjectInfo with OpenCL::MEM_REFERENCE_COUNT and returns the result.
OpenCL::MEM_REFERENCE_COUNT
Calls clGetMemObjectInfo with OpenCL::MEM_CONTEXT and returns the result.
OpenCL::MEM_CONTEXT
Calls clGetMemObjectInfo with OpenCL::MEM_ASSOCIATED_MEMOBJECT and returns the result.
OpenCL::MEM_ASSOCIATED_MEMOBJECT
Calls clGetMemObjectInfo with OpenCL::MEM_OFFSET and returns the result.
OpenCL::MEM_OFFSET
Returns the OpenGL object type (e.g. OpenCL::GL_OBJECT_TEXTURE2D) and the object "name" (e.g. the texture name) used to create this memory object.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetGLObjectInfo.html
This is a subclass of OpenCL::Memory, and the superclass of OpenCL::BufferObj. Its purpose is simply to distinguish between buffers and sub-buffers.
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.
Creates an OpenCL::Buffer objects from this buffer and returns it. The buffer_create_type is assumed to be OpenCL::BUFFER_CREATE_TYPE_REGION.
buffer_create_type
OpenCL::BUFFER_CREATE_TYPE_REGION
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateSubBuffer.html
This is the superclass of all image objects - OpenCL::Image1D, OpenCL::Image1DArray, OpenCL::Image1DBuffer, OpenCL::Image2D, OpenCL::Image2DArray and OpenCL::Image3D.
The reason this method is not called info is that there already is an ->info method inherited from OpenCL::Memory.
info
->info
OpenCL::Memory
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetImageInfo.html
Returns the channel order and type used to create the image by calling clGetImageInfo with OpenCL::IMAGE_FORMAT.
clGetImageInfo
OpenCL::IMAGE_FORMAT
Calls clGetImageInfo with OpenCL::IMAGE_ELEMENT_SIZE and returns the result.
OpenCL::IMAGE_ELEMENT_SIZE
Calls clGetImageInfo with OpenCL::IMAGE_ROW_PITCH and returns the result.
OpenCL::IMAGE_ROW_PITCH
Calls clGetImageInfo with OpenCL::IMAGE_SLICE_PITCH and returns the result.
OpenCL::IMAGE_SLICE_PITCH
Calls clGetImageInfo with OpenCL::IMAGE_WIDTH and returns the result.
OpenCL::IMAGE_WIDTH
Calls clGetImageInfo with OpenCL::IMAGE_HEIGHT and returns the result.
OpenCL::IMAGE_HEIGHT
Calls clGetImageInfo with OpenCL::IMAGE_DEPTH and returns the result.
OpenCL::IMAGE_DEPTH
Calls clGetGLTextureInfo with OpenCL::GL_TEXTURE_TARGET and returns the result.
clGetGLTextureInfo
OpenCL::GL_TEXTURE_TARGET
Calls clGetGLTextureInfo with OpenCL::GL_MIPMAP_LEVEL and returns the result.
OpenCL::GL_MIPMAP_LEVEL
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetSamplerInfo.html
Calls clGetSamplerInfo with OpenCL::SAMPLER_REFERENCE_COUNT and returns the result.
clGetSamplerInfo
OpenCL::SAMPLER_REFERENCE_COUNT
Calls clGetSamplerInfo with OpenCL::SAMPLER_CONTEXT and returns the result.
OpenCL::SAMPLER_CONTEXT
Calls clGetSamplerInfo with OpenCL::SAMPLER_NORMALIZED_COORDS and returns the result.
OpenCL::SAMPLER_NORMALIZED_COORDS
Calls clGetSamplerInfo with OpenCL::SAMPLER_ADDRESSING_MODE and returns the result.
OpenCL::SAMPLER_ADDRESSING_MODE
Calls clGetSamplerInfo with OpenCL::SAMPLER_FILTER_MODE and returns the result.
OpenCL::SAMPLER_FILTER_MODE
Tries to build the program with the given options. See also the $ctx-build> convenience function.
$ctx-
If a callback is specified, then it will be called when compilation is finished. Note that many OpenCL implementations block your program while compiling whether you use a callback or not. See build_async if you want to make sure the build is done in the background.
build_async
Note that some OpenCL implementations act up badly, and don't call the callback in some error cases (but call it in others). This implementation assumes the callback will always be called, and leaks memory if this is not so. So best make sure you don't pass in invalid values.
Some implementations fail with OpenCL::INVALID_BINARY when the compilation state is successful but some later stage fails.
OpenCL::INVALID_BINARY
options: -D name, -D name=definition, -I dir, -cl-single-precision-constant, -cl-denorms-are-zero, -cl-fp32-correctly-rounded-divide-sqrt, -cl-opt-disable, -cl-mad-enable, -cl-no-signed-zeros, -cl-unsafe-math-optimizations, -cl-finite-math-only, -cl-fast-relaxed-math, -w, -Werror, -cl-std=CL1.1/CL1.2, -cl-kernel-arg-info, -create-library, -enable-link-options.
-D name
-D name=definition
-I dir
-cl-single-precision-constant
-cl-denorms-are-zero
-cl-fp32-correctly-rounded-divide-sqrt
-cl-opt-disable
-cl-mad-enable
-cl-no-signed-zeros
-cl-unsafe-math-optimizations
-cl-finite-math-only
-cl-fast-relaxed-math
-w
-Werror
-cl-std=CL1.1/CL1.2
-cl-kernel-arg-info
-create-library
-enable-link-options
build_status: OpenCL::BUILD_SUCCESS, OpenCL::BUILD_NONE, OpenCL::BUILD_ERROR, OpenCL::BUILD_IN_PROGRESS.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clBuildProgram.html
Similar to ->build, except it starts a thread, and never fails (you need to check the compilation status form the callback, or by polling).
->build
Compiles the given program for the given devices (or all devices if undef). If $headers is given, it must be a hashref with include name => OpenCL::Program pairs.
$headers
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCompileProgram.html
Similar to $platform->info, but returns build info for a previous build attempt for the given device.
binary_type: OpenCL::PROGRAM_BINARY_TYPE_NONE, OpenCL::PROGRAM_BINARY_TYPE_COMPILED_OBJECT, OpenCL::PROGRAM_BINARY_TYPE_LIBRARY, OpenCL::PROGRAM_BINARY_TYPE_EXECUTABLE.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetBuildInfo.html
Creates an OpenCL::Kernel object out of the named __kernel function in the program.
__kernel
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateKernel.html
Returns all kernels successfully compiled for all devices in program.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateKernelsInProgram.html
Calls clGetProgramBuildInfo with OpenCL::PROGRAM_BUILD_STATUS and returns the result.
clGetProgramBuildInfo
OpenCL::PROGRAM_BUILD_STATUS
Calls clGetProgramBuildInfo with OpenCL::PROGRAM_BUILD_OPTIONS and returns the result.
OpenCL::PROGRAM_BUILD_OPTIONS
Calls clGetProgramBuildInfo with OpenCL::PROGRAM_BUILD_LOG and returns the result.
OpenCL::PROGRAM_BUILD_LOG
Calls clGetProgramBuildInfo with OpenCL::PROGRAM_BINARY_TYPE and returns the result.
OpenCL::PROGRAM_BINARY_TYPE
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetProgramInfo.html
Calls clGetProgramInfo with OpenCL::PROGRAM_REFERENCE_COUNT and returns the result.
clGetProgramInfo
OpenCL::PROGRAM_REFERENCE_COUNT
Calls clGetProgramInfo with OpenCL::PROGRAM_CONTEXT and returns the result.
OpenCL::PROGRAM_CONTEXT
Calls clGetProgramInfo with OpenCL::PROGRAM_NUM_DEVICES and returns the result.
OpenCL::PROGRAM_NUM_DEVICES
Calls clGetProgramInfo with OpenCL::PROGRAM_DEVICES and returns the result.
OpenCL::PROGRAM_DEVICES
Calls clGetProgramInfo with OpenCL::PROGRAM_SOURCE and returns the result.
OpenCL::PROGRAM_SOURCE
Calls clGetProgramInfo with OpenCL::PROGRAM_BINARY_SIZES and returns the result.
OpenCL::PROGRAM_BINARY_SIZES
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.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetKernelInfo.html
Calls clGetKernelInfo with OpenCL::KERNEL_FUNCTION_NAME and returns the result.
clGetKernelInfo
OpenCL::KERNEL_FUNCTION_NAME
Calls clGetKernelInfo with OpenCL::KERNEL_NUM_ARGS and returns the result.
OpenCL::KERNEL_NUM_ARGS
Calls clGetKernelInfo with OpenCL::KERNEL_REFERENCE_COUNT and returns the result.
OpenCL::KERNEL_REFERENCE_COUNT
Calls clGetKernelInfo with OpenCL::KERNEL_CONTEXT and returns the result.
OpenCL::KERNEL_CONTEXT
Calls clGetKernelInfo with OpenCL::KERNEL_PROGRAM and returns the result.
OpenCL::KERNEL_PROGRAM
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetKernelWorkGroupInfo.html
Calls clGetKernelWorkGroupInfo with OpenCL::KERNEL_WORK_GROUP_SIZE and returns the result.
clGetKernelWorkGroupInfo
OpenCL::KERNEL_WORK_GROUP_SIZE
Calls clGetKernelWorkGroupInfo with OpenCL::KERNEL_COMPILE_WORK_GROUP_SIZE and returns the result.
OpenCL::KERNEL_COMPILE_WORK_GROUP_SIZE
Calls clGetKernelWorkGroupInfo with OpenCL::KERNEL_LOCAL_MEM_SIZE and returns the result.
OpenCL::KERNEL_LOCAL_MEM_SIZE
Calls clGetKernelWorkGroupInfo with OpenCL::KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE and returns the result.
OpenCL::KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE
Calls clGetKernelWorkGroupInfo with OpenCL::KERNEL_PRIVATE_MEM_SIZE and returns the result.
OpenCL::KERNEL_PRIVATE_MEM_SIZE
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clGetKernelArgInfo.html
Calls clGetKernelArgInfo with OpenCL::KERNEL_ARG_ADDRESS_QUALIFIER and returns the result.
clGetKernelArgInfo
OpenCL::KERNEL_ARG_ADDRESS_QUALIFIER
Calls clGetKernelArgInfo with OpenCL::KERNEL_ARG_ACCESS_QUALIFIER and returns the result.
OpenCL::KERNEL_ARG_ACCESS_QUALIFIER
Calls clGetKernelArgInfo with OpenCL::KERNEL_ARG_TYPE_NAME and returns the result.
OpenCL::KERNEL_ARG_TYPE_NAME
Calls clGetKernelArgInfo with OpenCL::KERNEL_ARG_TYPE_QUALIFIER and returns the result.
OpenCL::KERNEL_ARG_TYPE_QUALIFIER
Calls clGetKernelArgInfo with OpenCL::KERNEL_ARG_NAME and returns the result.
OpenCL::KERNEL_ARG_NAME
Sets the arguments of a kernel. Since OpenCL 1.1 doesn't have a generic way to set arguments (and with OpenCL 1.2 it might be rather slow), you need to specify a format argument, much as with printf, to tell OpenCL what type of argument it is.
printf
The format arguments are single letters:
c char C unsigned char s short S unsigned short i int I unsigned int l long L unsigned long h half float (0..65535) f float d double z local (octet size) m memory object (buffer or image) a sampler e event
Space characters in the format string are ignored.
Example: set the arguments for a kernel that expects an int, two floats, a buffer and an image.
$kernel->setf ("i ff mm", 5, 0.5, 3, $buffer, $image);
This is a family of methods to set the kernel argument with the number $index to the give $value.
$index
$value
Chars and integers (including the half type) are specified as integers, float and double as floating point values, memory/buffer/image must be an object of that type or undef, local-memory arguments are set by specifying the size, and sampler and event must be objects of that type.
Note that set_memory works for all memory objects (all types of buffers and images) - the main purpose of the more specific set_TYPE functions is type checking.
set_memory
set_TYPE
Setting an argument for a kernel does NOT keep a reference to the object - for example, if you set an argument to some image object, free the image, and call the kernel, you will run into undefined behaviour.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clSetKernelArg.html
This is the superclass for all event objects (including OpenCL::UserEvent objects).
Waits for the event to complete.
Adds a callback to the callback stack for the given event type. There is no way to remove a callback again.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clSetEventCallback.html
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetEventInfo.html
Calls clGetEventInfo with OpenCL::EVENT_COMMAND_QUEUE and returns the result.
clGetEventInfo
OpenCL::EVENT_COMMAND_QUEUE
Calls clGetEventInfo with OpenCL::EVENT_COMMAND_TYPE and returns the result.
OpenCL::EVENT_COMMAND_TYPE
Calls clGetEventInfo with OpenCL::EVENT_REFERENCE_COUNT and returns the result.
OpenCL::EVENT_REFERENCE_COUNT
Calls clGetEventInfo with OpenCL::EVENT_COMMAND_EXECUTION_STATUS and returns the result.
OpenCL::EVENT_COMMAND_EXECUTION_STATUS
Calls clGetEventInfo with OpenCL::EVENT_CONTEXT and returns the result.
OpenCL::EVENT_CONTEXT
The reason this method is not called info is that there already is an ->info method.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetProfilingInfo.html
Calls clGetEventProfilingInfo with OpenCL::PROFILING_COMMAND_QUEUED and returns the result.
clGetEventProfilingInfo
OpenCL::PROFILING_COMMAND_QUEUED
Calls clGetEventProfilingInfo with OpenCL::PROFILING_COMMAND_SUBMIT and returns the result.
OpenCL::PROFILING_COMMAND_SUBMIT
Calls clGetEventProfilingInfo with OpenCL::PROFILING_COMMAND_START and returns the result.
OpenCL::PROFILING_COMMAND_START
Calls clGetEventProfilingInfo with OpenCL::PROFILING_COMMAND_END and returns the result.
OpenCL::PROFILING_COMMAND_END
This is a subclass of OpenCL::Event.
Sets the execution status of the user event. Can only be called once, either with OpenCL::COMPLETE or a negative number as status.
execution_status: OpenCL::COMPLETE or a negative integer.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clSetUserEventStatus.html
This class represents objects mapped into host memory. They are represented by a blessed string scalar. The string data is the mapped memory area, that is, if you read or write it, then the mapped object is accessed directly.
You must only ever use operations that modify the string in-place - for example, a substr that doesn't change the length, or maybe a regex that doesn't change the length. Any other operation might cause the data to be copied.
substr
When the object is destroyed it will enqueue an implicit unmap operation on the queue that was used to create it.
Keep in mind that you need to unmap (or destroy) mapped objects before OpenCL sees the changes, even if some implementations don't need this sometimes.
Example, replace the first two floats in the mapped buffer by 1 and 2.
my $mapped = $queue->map_buffer ($buf, ... $mapped->event->wait; # make sure it's there # now replace first 8 bytes by new data, which is exactly 8 bytes long # we blindly assume device endianness to equal host endianness # (and of course, we assume iee 754 single precision floats :) substr $$mapped, 0, 8, pack "f*", 1, 2;
Unmaps the mapped memory object, using the queue originally used to create it, quite similarly to $queue->unmap ($mapped, ...).
$queue->unmap ($mapped, ...)
Returns whether the object is still mapped - true before an unmap is enqueued, false afterwards.
unmap
Return the event object associated with the mapped object. Initially, this will be the event object created when mapping the object, and after an unmap, this will be the event object that the unmap operation created.
Same as $mapped->event->wait - makes sure no operations on this mapped object are outstanding.
$mapped->event->wait
Returns the size of the mapped area, in bytes. Same as length $$mapped.
length $$mapped
Returns the raw memory address of the mapped area.
Replaces the data at the given $offset in the memory area by the new $data. This method is safer than direct manipulation of $mapped because it does bounds-checking, but also slower.
$data
$mapped
Returns (without copying) a scalar representing the data at the given $offset and $length in the mapped memory area. This is the same as the following substr, except much slower;
$length
$data = substr $$mapped, $offset, $length
This is a subclass of OpenCL::Mapped, representing mapped buffers.
This is a subclass of OpenCL::Mapped, representing mapped images.
Return the width/height/depth of the mapped image region, in pixels.
Return the row or slice pitch of the image that has been mapped.
Return the size of a single pixel.
Return $count pixels from the given coordinates. The pixel data must be completely contained within a single row.
$count
If $count is undef, then all the remaining pixels in that row are returned.
Write the given pixel data at the given coordinate. The pixel data must be completely contained within a single row.
Marc Lehmann <schmorp@schmorp.de> http://home.schmorp.de/
To install OpenCL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm OpenCL
CPAN shell
perl -MCPAN -e shell install OpenCL
For more information on module installation, please visit the detailed CPAN module installation guide.