NAME
OpenCL - Open Computing Language Bindings
SYNOPSIS
use OpenCL;
DESCRIPTION
This is an early release which might be useful, but hasn't seen much testing.
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.
HELPFUL RESOURCES
The OpenCL specs used to develop this module:
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
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.
EXAMPLES
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) {
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
}
}
Get a useful context and a command queue.
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
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) {
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];
}
}
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->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"
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)
{
$id = get_global_id (0);
output [id] = input [id] * input [id];
}
';
my $prog = $ctx->build_program ($src);
my $kernel = $prog->kernel ("squareit");
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);
# 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;
The same enqueue operations as before, but assuming an out-of-order queue, showing off barriers.
# 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;
The same enqueue operations as before, but assuming an out-of-order queue, showing off event objects and wait lists.
# 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;
Use the OpenGL module to share a texture between OpenCL and OpenGL and draw some julia set tunnel effect.
This is quite a long example to get you going - you can 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;
}
How to modify the previous example to not rely on GL sharing.
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 darw 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.
DOCUMENTATION
BASIC CONVENTIONS
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.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).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.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,undefvalues will be ignored in the event list.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
CL_SUCCESS. If any other status is returned the function will throw an exception, so you don't normally have to to any error checking.
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
GLX SUPPORT
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.
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.
EVENT SYSTEM
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).
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 this module is a bit hard to understand, here are some case examples:
Don't use callbacks.
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.
Use AnyEvent
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>.
Let yourself be interrupted at any time
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:
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).
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.
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.
That is then awfully close to using the built-in AnyEvent support above, though, so consider that one instead.
Be creative
OpenCL exports the Async::Interrupt object it uses in the global variable $OpenCL::INTERRUPT. You can configure it in any way you like.
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 OpenCL PACKAGE
- $int = OpenCL::errno
-
The last error returned by a function - it's only valid after an error occured and before calling another OpenCL function.
- $str = OpenCL::err2str [$errval]
-
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).
- $str = OpenCL::enum2str $enum
-
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.
- @platforms = OpenCL::platforms
-
Returns all available OpenCL::Platform objects.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformIDs.html
- $ctx = OpenCL::context_from_type $properties, $type = OpenCL::DEVICE_TYPE_DEFAULT, $callback->($err, $pvt) = $print_stderr
-
Tries to create a context from a default device and platform type - never worked for me.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html
- $ctx = OpenCL::context $properties, \@devices, $callback->($err, $pvt) = $print_stderr)
-
Create a new OpenCL::Context object using the given device object(s). This function isn't implemented yet, use
$platform->contextinstead.http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html
- OpenCL::wait_for_events $wait_events...
-
Waits for all events to complete.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clWaitForEvents.html
- OpenCL::poll
-
Checks if there are any outstanding events (see "EVENT SYSTEM") and invokes their callbacks.
- $OpenCL::INTERRUPT
-
The Async::Interrupt object used to signal asynchronous events (see "EVENT SYSTEM").
- $OpenCL::WATCHER
-
The AnyEvent watcher object used to watch for asynchronous events (see "EVENT SYSTEM"). This variable is
undefuntil AnyEvent has been loaded and initialised (e.g. by callingAnyEvent::detect).
THE OpenCL::Object CLASS
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.
- $iv = $obj->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
IVtype in your code and cast that to the correct type.
THE OpenCL::Platform CLASS
- @devices = $platform->devices ($type = OpenCL::DEVICE_TYPE_ALL)
-
Returns a list of matching OpenCL::Device objects.
- $ctx = $platform->context_from_type ($properties, $type = OpenCL::DEVICE_TYPE_DEFAULT, $callback->($err, $pvt) = $print_stderr)
-
Tries to create a context. Never worked for me, and you need devices explicitly anyway.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html
- $ctx = $platform->context ($properties, \@devices, $callback->($err, $pvt) = $print_stderr)
-
Create a new OpenCL::Context object using the given device object(s)- a CL_CONTEXT_PLATFORM property is supplied automatically.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html
- $packed_value = $platform->info ($name)
-
Calls
clGetPlatformInfoand 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 correctunpack.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
- $platform->unload_compiler
-
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
- $string = $platform->profile
-
Calls
clGetPlatformInfowithCL_PLATFORM_PROFILEand returns the result. - $string = $platform->version
-
Calls
clGetPlatformInfowithCL_PLATFORM_VERSIONand returns the result. - $string = $platform->name
-
Calls
clGetPlatformInfowithCL_PLATFORM_NAMEand returns the result. - $string = $platform->vendor
-
Calls
clGetPlatformInfowithCL_PLATFORM_VENDORand returns the result. - $string = $platform->extensions
-
Calls
clGetPlatformInfowithCL_PLATFORM_EXTENSIONSand returns the result.
THE OpenCL::Device CLASS
- $packed_value = $device->info ($name)
-
See
$platform->infofor details.http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetDeviceInfo.html
- $device_type = $device->type
-
Calls
clGetDeviceInfowithCL_DEVICE_TYPEand returns the result. - $uint = $device->vendor_id
-
Calls
clGetDeviceInfowithCL_DEVICE_VENDOR_IDand returns the result. - $uint = $device->max_compute_units
-
Calls
clGetDeviceInfowithCL_DEVICE_MAX_COMPUTE_UNITSand returns the result. - $uint = $device->max_work_item_dimensions
-
Calls
clGetDeviceInfowithCL_DEVICE_MAX_WORK_ITEM_DIMENSIONSand returns the result. - $int = $device->max_work_group_size
-
Calls
clGetDeviceInfowithCL_DEVICE_MAX_WORK_GROUP_SIZEand returns the result. - @ints = $device->max_work_item_sizes
-
Calls
clGetDeviceInfowithCL_DEVICE_MAX_WORK_ITEM_SIZESand returns the result. - $uint = $device->preferred_vector_width_char
-
Calls
clGetDeviceInfowithCL_DEVICE_PREFERRED_VECTOR_WIDTH_CHARand returns the result. - $uint = $device->preferred_vector_width_short
-
Calls
clGetDeviceInfowithCL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORTand returns the result. - $uint = $device->preferred_vector_width_int
-
Calls
clGetDeviceInfowithCL_DEVICE_PREFERRED_VECTOR_WIDTH_INTand returns the result. - $uint = $device->preferred_vector_width_long
-
Calls
clGetDeviceInfowithCL_DEVICE_PREFERRED_VECTOR_WIDTH_LONGand returns the result. - $uint = $device->preferred_vector_width_float
-
Calls
clGetDeviceInfowithCL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOATand returns the result. - $uint = $device->preferred_vector_width_double
-
Calls
clGetDeviceInfowithCL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLEand returns the result. - $uint = $device->max_clock_frequency
-
Calls
clGetDeviceInfowithCL_DEVICE_MAX_CLOCK_FREQUENCYand returns the result. - $bitfield = $device->address_bits
-
Calls
clGetDeviceInfowithCL_DEVICE_ADDRESS_BITSand returns the result. - $uint = $device->max_read_image_args
-
Calls
clGetDeviceInfowithCL_DEVICE_MAX_READ_IMAGE_ARGSand returns the result. - $uint = $device->max_write_image_args
-
Calls
clGetDeviceInfowithCL_DEVICE_MAX_WRITE_IMAGE_ARGSand returns the result. - $ulong = $device->max_mem_alloc_size
-
Calls
clGetDeviceInfowithCL_DEVICE_MAX_MEM_ALLOC_SIZEand returns the result. - $int = $device->image2d_max_width
-
Calls
clGetDeviceInfowithCL_DEVICE_IMAGE2D_MAX_WIDTHand returns the result. - $int = $device->image2d_max_height
-
Calls
clGetDeviceInfowithCL_DEVICE_IMAGE2D_MAX_HEIGHTand returns the result. - $int = $device->image3d_max_width
-
Calls
clGetDeviceInfowithCL_DEVICE_IMAGE3D_MAX_WIDTHand returns the result. - $int = $device->image3d_max_height
-
Calls
clGetDeviceInfowithCL_DEVICE_IMAGE3D_MAX_HEIGHTand returns the result. - $int = $device->image3d_max_depth
-
Calls
clGetDeviceInfowithCL_DEVICE_IMAGE3D_MAX_DEPTHand returns the result. - $uint = $device->image_support
-
Calls
clGetDeviceInfowithCL_DEVICE_IMAGE_SUPPORTand returns the result. - $int = $device->max_parameter_size
-
Calls
clGetDeviceInfowithCL_DEVICE_MAX_PARAMETER_SIZEand returns the result. - $uint = $device->max_samplers
-
Calls
clGetDeviceInfowithCL_DEVICE_MAX_SAMPLERSand returns the result. - $uint = $device->mem_base_addr_align
-
Calls
clGetDeviceInfowithCL_DEVICE_MEM_BASE_ADDR_ALIGNand returns the result. - $uint = $device->min_data_type_align_size
-
Calls
clGetDeviceInfowithCL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZEand returns the result. - $device_fp_config = $device->single_fp_config
-
Calls
clGetDeviceInfowithCL_DEVICE_SINGLE_FP_CONFIGand returns the result. - $device_mem_cache_type = $device->global_mem_cache_type
-
Calls
clGetDeviceInfowithCL_DEVICE_GLOBAL_MEM_CACHE_TYPEand returns the result. - $uint = $device->global_mem_cacheline_size
-
Calls
clGetDeviceInfowithCL_DEVICE_GLOBAL_MEM_CACHELINE_SIZEand returns the result. - $ulong = $device->global_mem_cache_size
-
Calls
clGetDeviceInfowithCL_DEVICE_GLOBAL_MEM_CACHE_SIZEand returns the result. - $ulong = $device->global_mem_size
-
Calls
clGetDeviceInfowithCL_DEVICE_GLOBAL_MEM_SIZEand returns the result. - $ulong = $device->max_constant_buffer_size
-
Calls
clGetDeviceInfowithCL_DEVICE_MAX_CONSTANT_BUFFER_SIZEand returns the result. - $uint = $device->max_constant_args
-
Calls
clGetDeviceInfowithCL_DEVICE_MAX_CONSTANT_ARGSand returns the result. - $device_local_mem_type = $device->local_mem_type
-
Calls
clGetDeviceInfowithCL_DEVICE_LOCAL_MEM_TYPEand returns the result. - $ulong = $device->local_mem_size
-
Calls
clGetDeviceInfowithCL_DEVICE_LOCAL_MEM_SIZEand returns the result. - $boolean = $device->error_correction_support
-
Calls
clGetDeviceInfowithCL_DEVICE_ERROR_CORRECTION_SUPPORTand returns the result. - $int = $device->profiling_timer_resolution
-
Calls
clGetDeviceInfowithCL_DEVICE_PROFILING_TIMER_RESOLUTIONand returns the result. - $boolean = $device->endian_little
-
Calls
clGetDeviceInfowithCL_DEVICE_ENDIAN_LITTLEand returns the result. - $boolean = $device->available
-
Calls
clGetDeviceInfowithCL_DEVICE_AVAILABLEand returns the result. - $boolean = $device->compiler_available
-
Calls
clGetDeviceInfowithCL_DEVICE_COMPILER_AVAILABLEand returns the result. - $device_exec_capabilities = $device->execution_capabilities
-
Calls
clGetDeviceInfowithCL_DEVICE_EXECUTION_CAPABILITIESand returns the result. - $command_queue_properties = $device->properties
-
Calls
clGetDeviceInfowithCL_DEVICE_QUEUE_PROPERTIESand returns the result. - $ = $device->platform
-
Calls
clGetDeviceInfowithCL_DEVICE_PLATFORMand returns the result. - $string = $device->name
-
Calls
clGetDeviceInfowithCL_DEVICE_NAMEand returns the result. - $string = $device->vendor
-
Calls
clGetDeviceInfowithCL_DEVICE_VENDORand returns the result. - $string = $device->driver_version
-
Calls
clGetDeviceInfowithCL_DRIVER_VERSIONand returns the result. - $string = $device->profile
-
Calls
clGetDeviceInfowithCL_DEVICE_PROFILEand returns the result. - $string = $device->version
-
Calls
clGetDeviceInfowithCL_DEVICE_VERSIONand returns the result. - $string = $device->extensions
-
Calls
clGetDeviceInfowithCL_DEVICE_EXTENSIONSand returns the result. - $uint = $device->preferred_vector_width_half
-
Calls
clGetDeviceInfowithCL_DEVICE_PREFERRED_VECTOR_WIDTH_HALFand returns the result. - $uint = $device->native_vector_width_char
-
Calls
clGetDeviceInfowithCL_DEVICE_NATIVE_VECTOR_WIDTH_CHARand returns the result. - $uint = $device->native_vector_width_short
-
Calls
clGetDeviceInfowithCL_DEVICE_NATIVE_VECTOR_WIDTH_SHORTand returns the result. - $uint = $device->native_vector_width_int
-
Calls
clGetDeviceInfowithCL_DEVICE_NATIVE_VECTOR_WIDTH_INTand returns the result. - $uint = $device->native_vector_width_long
-
Calls
clGetDeviceInfowithCL_DEVICE_NATIVE_VECTOR_WIDTH_LONGand returns the result. - $uint = $device->native_vector_width_float
-
Calls
clGetDeviceInfowithCL_DEVICE_NATIVE_VECTOR_WIDTH_FLOATand returns the result. - $uint = $device->native_vector_width_double
-
Calls
clGetDeviceInfowithCL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLEand returns the result. - $uint = $device->native_vector_width_half
-
Calls
clGetDeviceInfowithCL_DEVICE_NATIVE_VECTOR_WIDTH_HALFand returns the result. - $device_fp_config = $device->double_fp_config
-
Calls
clGetDeviceInfowithCL_DEVICE_DOUBLE_FP_CONFIGand returns the result. - $device_fp_config = $device->half_fp_config
-
Calls
clGetDeviceInfowithCL_DEVICE_HALF_FP_CONFIGand returns the result. - $boolean = $device->host_unified_memory
-
Calls
clGetDeviceInfowithCL_DEVICE_HOST_UNIFIED_MEMORYand returns the result. - $device = $device->parent_device_ext
-
Calls
clGetDeviceInfowithCL_DEVICE_PARENT_DEVICE_EXTand returns the result. - @device_partition_property_exts = $device->partition_types_ext
-
Calls
clGetDeviceInfowithCL_DEVICE_PARTITION_TYPES_EXTand returns the result. - @device_partition_property_exts = $device->affinity_domains_ext
-
Calls
clGetDeviceInfowithCL_DEVICE_AFFINITY_DOMAINS_EXTand returns the result. - $uint = $device->reference_count_ext
-
Calls
clGetDeviceInfowithCL_DEVICE_REFERENCE_COUNT_EXTand returns the result. - @device_partition_property_exts = $device->partition_style_ext
-
Calls
clGetDeviceInfowithCL_DEVICE_PARTITION_STYLE_EXTand returns the result.
THE OpenCL::Context CLASS
- $prog = $ctx->build_program ($program, $options = "")
-
This convenience function tries to build the program on all devices in the context. If the build fails, then the function will
croakwith the build log. Otherwise ti returns the program object.The
$programcan either be aOpenCL::Programobject or a string containing the program. In the latter case, a program objetc will be created automatically. - $queue = $ctx->queue ($device, $properties)
-
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); - $ev = $ctx->user_event
-
Creates a new OpenCL::UserEvent object.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateUserEvent.html
- $buf = $ctx->buffer ($flags, $len)
-
Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object with the given flags and octet-size.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html
- $buf = $ctx->buffer_sv ($flags, $data)
-
Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and initialise it with the given data values.
- $img = $ctx->image ($self, $flags, $channel_order, $channel_type, $type, $width, $height, $depth = 0, $array_size = 0, $row_pitch = 0, $slice_pitch = 0, $num_mip_level = 0, $num_samples = 0, $*data = &PL_sv_undef)
-
Creates a new OpenCL::Image object and optionally initialises it with the given data values.
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateImage.html
- $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.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage2D.html
- $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.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage3D.html
- $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
- $img = $ctx->gl_texture ($flags, $target, $miplevel, $texture)
-
Creates a new OpenCL::Image object that refers to the given OpenGL texture object or buffer.
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateFromGLTexture.html
- $img = $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
- $img = $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
- $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
- @formats = $ctx->supported_image_formats ($flags, $image_type)
-
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
- $sampler = $ctx->sampler ($normalized_coords, $addressing_mode, $filter_mode)
-
Creates a new OpenCL::Sampler object.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateSampler.html
- $program = $ctx->program_with_source ($string)
-
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
- ($program, \@status) = $ctx->program_with_binary (\@devices, \@binaries)
-
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]); - $packed_value = $ctx->info ($name)
-
See
$platform->infofor details.http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetContextInfo.html
- $uint = $context->reference_count
-
Calls
clGetContextInfowithCL_CONTEXT_REFERENCE_COUNTand returns the result. - @devices = $context->devices
-
Calls
clGetContextInfowithCL_CONTEXT_DEVICESand returns the result. - @property_ints = $context->properties
-
Calls
clGetContextInfowithCL_CONTEXT_PROPERTIESand returns the result. - $uint = $context->num_devices
-
Calls
clGetContextInfowithCL_CONTEXT_NUM_DEVICESand returns the result.
THE OpenCL::Queue CLASS
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 = $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.
- $ev = $queue->read_buffer ($buffer, $blocking, $offset, $len, $data, $wait_events...)
-
Reads data from buffer into the given string.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBuffer.html
- $ev = $queue->write_buffer ($buffer, $blocking, $offset, $data, $wait_events...)
-
Writes data to buffer from the given string.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBuffer.html
- $ev = $queue->copy_buffer ($src, $dst, $src_offset, $dst_offset, $len, $wait_events...)
-
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBuffer.html
- $ev = $queue->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...)
-
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBufferRect.html
- $ev = $queue->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...)
-
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html
- $ev = $queue->copy_buffer_to_image ($src_buffer, $dst_image, $src_offset, $dst_x, $dst_y, $dst_z, $width, $height, $depth, $wait_events...)
-
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html
- $ev = $queue->read_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...)
-
$row_pitch(and$slice_pitch) can be0, 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/clEnqueueReadImage.html
- $ev = $queue->write_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...)
-
$row_pitch(and$slice_pitch) can be0, 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 - $ev = $queue->copy_image ($src_image, $dst_image, $src_x, $src_y, $src_z, $dst_x, $dst_y, $dst_z, $width, $height, $depth, $wait_events...)
-
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImage.html
- $ev = $queue->copy_image_to_buffer ($src_image, $dst_image, $src_x, $src_y, $src_z, $width, $height, $depth, $dst_offset, $wait_events...)
-
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImageToBuffer.html
- $ev = $queue->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.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html.
- $ev = $queue->fill_buffer ($mem, $pattern, $offset, $size, ...)
-
Fills the given buffer object with repeated applications of
$pattern, starting at$offsetfor$sizeoctets.http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueFillBuffer.html
- $ev = $queue->fill_image ($img, $r, $g, $b, $a, $x, $y, $z, $width, $height, $depth, ...)
-
Fills the given image area with the given rgba colour components. The components are normally floating point values between
0and1, except when the image channel data type is a signe dor unsigned unnormalised format, in which case the range is determined by the format.http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueFillImage.html
- $ev = $queue->task ($kernel, $wait_events...)
-
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueTask.html
- $ev = $queue->nd_range_kernel ($kernel, \@global_work_offset, \@global_work_size, \@local_work_size, $wait_events...)
-
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 are0), 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
- $ev = $queue->acquire_gl_objects ([object, ...], $wait_events...)
-
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
- $ev = $queue->release_gl_objects ([object, ...], $wait_events...)
-
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
- $ev = $queue->wait_for_events ($wait_events...)
-
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWaitForEvents.html
- $ev = $queue->marker ($wait_events...)
-
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueMarkerWithWaitList.html
- $ev = $queue->barrier ($wait_events...)
-
http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueBarrierWithWaitList.html
- $queue->flush
-
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clFlush.html
- $queue->finish
-
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clFinish.html
- $packed_value = $queue->info ($name)
-
See
$platform->infofor details.http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetCommandQueueInfo.html
- $ctx = $command_queue->context
-
Calls
clGetCommandQueueInfowithCL_QUEUE_CONTEXTand returns the result. - $device = $command_queue->device
-
Calls
clGetCommandQueueInfowithCL_QUEUE_DEVICEand returns the result. - $uint = $command_queue->reference_count
-
Calls
clGetCommandQueueInfowithCL_QUEUE_REFERENCE_COUNTand returns the result. - $command_queue_properties = $command_queue->properties
-
Calls
clGetCommandQueueInfowithCL_QUEUE_PROPERTIESand returns the result.
MEMORY MAPPED BUFFERS
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.
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.
- $mapped_buffer = $queue->map_buffer ($buf, $blocking=1, $map_flags=OpenCL::MAP_READ|OpenCL::MAP_WRITE, $offset=0, $size=undef, $wait_events...)
-
Maps the given buffer into host memory and returns an
OpenCL::MappedBufferobject. If$sizeis specified as undef, then the map will extend to the end of the buffer.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 - $mapped_image = $queue->map_image ($img, $blocking=1, $map_flags=OpenCL::MAP_READ|OpenCL::MAP_WRITE, $x=0, $y=0, $z=0, $width=undef, $height=undef, $depth=undef, $wait_events...)
-
Maps the given image area into host memory and return an
OpenCL::MappedImageobject.If any of
$width,$heightand/or$depthareundefthen they will be replaced by the maximum possible value.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->set ($_ * $mapped->row_pitch, pack "C", 5) for 0..$image->height; $mapped->unmap;. $mapped->wait; # only needed for out of order queues normally - $ev = $queue->unmap ($mapped, $wait_events...)
-
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.
THE OpenCL::Memory CLASS
This the superclass of all memory objects - OpenCL::Buffer, OpenCL::Image, OpenCL::Image2D and OpenCL::Image3D.
- $packed_value = $memory->info ($name)
-
See
$platform->infofor details.http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetMemObjectInfo.html
- $mem_object_type = $mem->type
-
Calls
clGetMemObjectInfowithCL_MEM_TYPEand returns the result. - $mem_flags = $mem->flags
-
Calls
clGetMemObjectInfowithCL_MEM_FLAGSand returns the result. - $int = $mem->size
-
Calls
clGetMemObjectInfowithCL_MEM_SIZEand returns the result. - $ptr_value = $mem->host_ptr
-
Calls
clGetMemObjectInfowithCL_MEM_HOST_PTRand returns the result. - $uint = $mem->map_count
-
Calls
clGetMemObjectInfowithCL_MEM_MAP_COUNTand returns the result. - $uint = $mem->reference_count
-
Calls
clGetMemObjectInfowithCL_MEM_REFERENCE_COUNTand returns the result. - $ctx = $mem->context
-
Calls
clGetMemObjectInfowithCL_MEM_CONTEXTand returns the result. - $mem = $mem->associated_memobject
-
Calls
clGetMemObjectInfowithCL_MEM_ASSOCIATED_MEMOBJECTand returns the result. - $int = $mem->offset
-
Calls
clGetMemObjectInfowithCL_MEM_OFFSETand returns the result. - ($type, $name) = $mem->gl_object_info
-
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
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.
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.
- $subbuf = $buf_obj->sub_buffer_region ($flags, $origin, $size)
-
Creates an OpenCL::Buffer objects from this buffer and returns it. The
buffer_create_typeis assumed to beCL_BUFFER_CREATE_TYPE_REGION.http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateSubBuffer.html
THE OpenCL::Image CLASS
This is the superclass of all image objects - OpenCL::Image1D, OpenCL::Image1DArray, OpenCL::Image1DBuffer, OpenCL::Image2D, OpenCL::Image2DArray and OpenCL::Image3D.
- $packed_value = $image->image_info ($name)
-
See
$platform->infofor details.The reason this method is not called
infois that there already is an->infomethod inherited fromOpenCL::Memory.http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetImageInfo.html
- ($channel_order, $channel_data_type) = $image->format
-
Returns the channel order and type used to create the image by calling
clGetImageInfowithCL_IMAGE_FORMAT. - $int = $image->element_size
-
Calls
clGetImageInfowithCL_IMAGE_ELEMENT_SIZEand returns the result. - $int = $image->row_pitch
-
Calls
clGetImageInfowithCL_IMAGE_ROW_PITCHand returns the result. - $int = $image->slice_pitch
-
Calls
clGetImageInfowithCL_IMAGE_SLICE_PITCHand returns the result. - $int = $image->width
-
Calls
clGetImageInfowithCL_IMAGE_WIDTHand returns the result. - $int = $image->height
-
Calls
clGetImageInfowithCL_IMAGE_HEIGHTand returns the result. - $int = $image->depth
-
Calls
clGetImageInfowithCL_IMAGE_DEPTHand returns the result. - $GLenum = $gl_texture->target
-
Calls
clGetGLTextureInfowithCL_GL_TEXTURE_TARGETand returns the result. - $GLint = $gl_texture->gl_mipmap_level
-
Calls
clGetGLTextureInfowithCL_GL_MIPMAP_LEVELand returns the result.
THE OpenCL::Sampler CLASS
- $packed_value = $sampler->info ($name)
-
See
$platform->infofor details.http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetSamplerInfo.html
- $uint = $sampler->reference_count
-
Calls
clGetSamplerInfowithCL_SAMPLER_REFERENCE_COUNTand returns the result. - $ctx = $sampler->context
-
Calls
clGetSamplerInfowithCL_SAMPLER_CONTEXTand returns the result. - $addressing_mode = $sampler->normalized_coords
-
Calls
clGetSamplerInfowithCL_SAMPLER_NORMALIZED_COORDSand returns the result. - $filter_mode = $sampler->addressing_mode
-
Calls
clGetSamplerInfowithCL_SAMPLER_ADDRESSING_MODEand returns the result. - $boolean = $sampler->filter_mode
-
Calls
clGetSamplerInfowithCL_SAMPLER_FILTER_MODEand returns the result.
THE OpenCL::Program CLASS
- $program->build (\@devices = undef, $options = "", $cb->($program) = undef)
-
Tries to build the program with the given options. See also the
$ctx-build> convenience function.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_asyncif you want to make sure the build is done in the background.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_BINARYwhen the compilation state is successful but some later stage fails.http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clBuildProgram.html
- $program->build_async (\@devices = undef, $options = "", $cb->($program) = undef)
-
Similar to
->build, except it starts a thread, and never fails (you need to check the compilation status form the callback, or by polling). - $packed_value = $program->build_info ($device, $name)
-
Similar to
$platform->info, but returns build info for a previous build attempt for the given device.http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetBuildInfo.html
- $kernel = $program->kernel ($function_name)
-
Creates an OpenCL::Kernel object out of the named
__kernelfunction in the program.http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateKernel.html
- @kernels = $program->kernels_in_program
-
Returns all kernels successfully compiled for all devices in program.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateKernelsInProgram.html
- $build_status = $program->build_status ($device)
-
Calls
clGetProgramBuildInfowithCL_PROGRAM_BUILD_STATUSand returns the result. - $string = $program->build_options ($device)
-
Calls
clGetProgramBuildInfowithCL_PROGRAM_BUILD_OPTIONSand returns the result. - $string = $program->build_log ($device)
-
Calls
clGetProgramBuildInfowithCL_PROGRAM_BUILD_LOGand returns the result. - $packed_value = $program->info ($name)
-
See
$platform->infofor details.http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetProgramInfo.html
- $uint = $program->reference_count
-
Calls
clGetProgramInfowithCL_PROGRAM_REFERENCE_COUNTand returns the result. - $ctx = $program->context
-
Calls
clGetProgramInfowithCL_PROGRAM_CONTEXTand returns the result. - $uint = $program->num_devices
-
Calls
clGetProgramInfowithCL_PROGRAM_NUM_DEVICESand returns the result. - @devices = $program->devices
-
Calls
clGetProgramInfowithCL_PROGRAM_DEVICESand returns the result. - $string = $program->source
-
Calls
clGetProgramInfowithCL_PROGRAM_SOURCEand returns the result. - @ints = $program->binary_sizes
-
Calls
clGetProgramInfowithCL_PROGRAM_BINARY_SIZESand returns the result. - @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.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetProgramInfo.html
THE OpenCL::Kernel CLASS
- $packed_value = $kernel->info ($name)
-
See
$platform->infofor details.http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetKernelInfo.html
- $string = $kernel->function_name
-
Calls
clGetKernelInfowithCL_KERNEL_FUNCTION_NAMEand returns the result. - $uint = $kernel->num_args
-
Calls
clGetKernelInfowithCL_KERNEL_NUM_ARGSand returns the result. - $uint = $kernel->reference_count
-
Calls
clGetKernelInfowithCL_KERNEL_REFERENCE_COUNTand returns the result. - $ctx = $kernel->context
-
Calls
clGetKernelInfowithCL_KERNEL_CONTEXTand returns the result. - $program = $kernel->program
-
Calls
clGetKernelInfowithCL_KERNEL_PROGRAMand returns the result. - $packed_value = $kernel->work_group_info ($device, $name)
-
See
$platform->infofor details.The reason this method is not called
infois that there already is an->infomethod.http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetKernelWorkGroupInfo.html
- $int = $kernel->work_group_size ($device)
-
Calls
clGetKernelWorkGroupInfowithCL_KERNEL_WORK_GROUP_SIZEand returns the result. - @ints = $kernel->compile_work_group_size ($device)
-
Calls
clGetKernelWorkGroupInfowithCL_KERNEL_COMPILE_WORK_GROUP_SIZEand returns the result. - $ulong = $kernel->local_mem_size ($device)
-
Calls
clGetKernelWorkGroupInfowithCL_KERNEL_LOCAL_MEM_SIZEand returns the result. - $int = $kernel->preferred_work_group_size_multiple ($device)
-
Calls
clGetKernelWorkGroupInfowithCL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLEand returns the result. - $ulong = $kernel->private_mem_size ($device)
-
Calls
clGetKernelWorkGroupInfowithCL_KERNEL_PRIVATE_MEM_SIZEand returns the result. - $kernel->setf ($format, ...)
-
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.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 eventSpace 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); - $kernel->set_TYPE ($index, $value)
- $kernel->set_char ($index, $value)
- $kernel->set_uchar ($index, $value)
- $kernel->set_short ($index, $value)
- $kernel->set_ushort ($index, $value)
- $kernel->set_int ($index, $value)
- $kernel->set_uint ($index, $value)
- $kernel->set_long ($index, $value)
- $kernel->set_ulong ($index, $value)
- $kernel->set_half ($index, $value)
- $kernel->set_float ($index, $value)
- $kernel->set_double ($index, $value)
- $kernel->set_memory ($index, $value)
- $kernel->set_buffer ($index, $value)
- $kernel->set_image ($index, $value)
- $kernel->set_sampler ($index, $value)
- $kernel->set_local ($index, $value)
- $kernel->set_event ($index, $value)
-
This is a family of methods to set the kernel argument with the number
$indexto the give$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_memoryworks for all memory objects (all types of buffers and images) - the main purpose of the more specificset_TYPEfunctions is type checking.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
THE OpenCL::Event CLASS
This is the superclass for all event objects (including OpenCL::UserEvent objects).
- $ev->wait
-
Waits for the event to complete.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clWaitForEvents.html
- $ev->cb ($exec_callback_type, $callback->($event, $event_command_exec_status))
-
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
- $packed_value = $ev->info ($name)
-
See
$platform->infofor details.http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetEventInfo.html
- $queue = $event->command_queue
-
Calls
clGetEventInfowithCL_EVENT_COMMAND_QUEUEand returns the result. - $command_type = $event->command_type
-
Calls
clGetEventInfowithCL_EVENT_COMMAND_TYPEand returns the result. - $uint = $event->reference_count
-
Calls
clGetEventInfowithCL_EVENT_REFERENCE_COUNTand returns the result. - $uint = $event->command_execution_status
-
Calls
clGetEventInfowithCL_EVENT_COMMAND_EXECUTION_STATUSand returns the result. - $ctx = $event->context
-
Calls
clGetEventInfowithCL_EVENT_CONTEXTand returns the result. - $packed_value = $ev->profiling_info ($name)
-
See
$platform->infofor details.The reason this method is not called
infois that there already is an->infomethod.http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetProfilingInfo.html
- $ulong = $event->profiling_command_queued
-
Calls
clGetEventProfilingInfowithCL_PROFILING_COMMAND_QUEUEDand returns the result. - $ulong = $event->profiling_command_submit
-
Calls
clGetEventProfilingInfowithCL_PROFILING_COMMAND_SUBMITand returns the result. - $ulong = $event->profiling_command_start
-
Calls
clGetEventProfilingInfowithCL_PROFILING_COMMAND_STARTand returns the result. - $ulong = $event->profiling_command_end
-
Calls
clGetEventProfilingInfowithCL_PROFILING_COMMAND_ENDand returns the result.
THE OpenCL::UserEvent CLASS
This is a subclass of OpenCL::Event.
- $ev->set_status ($execution_status)
-
Sets the execution status of the user event. Can only be called once, either with OpenCL::COMPLETE or a negative number as status.
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clSetUserEventStatus.html
THE OpenCL::Mapped CLASS
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.
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;
- $ev = $mapped->unmap ($wait_events...)
-
Unmaps the mapped memory object, using the queue originally used to create it, quite similarly to
$queue->unmap ($mapped, ...). - $bool = $mapped->mapped
-
Returns whether the object is still mapped - true before an
unmapis enqueued, false afterwards. - $ev = $mapped->event
-
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.
- $mapped->wait
-
Same as
$mapped->event->wait- makes sure no operations on this mapped object are outstanding. - $bytes = $mapped->size
-
Returns the size of the mapped area, in bytes. Same as
length $$mapped. - $ptr = $mapped->ptr
-
Returns the raw memory address of the mapped area.
- $mapped->set ($offset, $data)
-
Replaces the data at the given
$offsetin the memory area by the new$data. This method is safer than direct manipulation of$mappedbecause it does bounds-checking, but also slower. - $data = $mapped->get ($offset, $length)
-
Returns (without copying) a scalar representing the data at the given
$offsetand$lengthin the mapped memory area. This is the same as the following substr, except much slower;$data = substr $$mapped, $offset, $length
THE OpenCL::MappedBuffer CLASS
This is a subclass of OpenCL::Mapped, representing mapped buffers.
THE OpenCL::MappedImage CLASS
This is a subclass of OpenCL::Mapped, representing mapped images.
- $bytes = $mapped->row_pitch
- $bytes = $mapped->slice_pitch
-
Return the row or slice pitch of the image that has been mapped.
AUTHOR
Marc Lehmann <schmorp@schmorp.de>
http://home.schmorp.de/