1 |
=head1 NAME |
2 |
|
3 |
OpenCL - Open Computing Language Bindings |
4 |
|
5 |
=head1 SYNOPSIS |
6 |
|
7 |
use OpenCL; |
8 |
|
9 |
=head1 DESCRIPTION |
10 |
|
11 |
This is an early release which might be useful, but hasn't seen much testing. |
12 |
|
13 |
=head2 OpenCL FROM 10000 FEET HEIGHT |
14 |
|
15 |
Here is a high level overview of OpenCL: |
16 |
|
17 |
First you need to find one or more OpenCL::Platforms (kind of like |
18 |
vendors) - usually there is only one. |
19 |
|
20 |
Each platform gives you access to a number of OpenCL::Device objects, e.g. |
21 |
your graphics card. |
22 |
|
23 |
From a platform and some device(s), you create an OpenCL::Context, which is |
24 |
a very central object in OpenCL: Once you have a context you can create |
25 |
most other objects: |
26 |
|
27 |
OpenCL::Program objects, which store source code and, after building for a |
28 |
specific device ("compiling and linking"), also binary programs. For each |
29 |
kernel function in a program you can then create an OpenCL::Kernel object |
30 |
which represents basically a function call with argument values. |
31 |
|
32 |
OpenCL::Memory objects of various flavours: OpenCL::Buffers objects (flat |
33 |
memory areas, think array) and OpenCL::Image objects (think 2d or 3d |
34 |
array) for bulk data and input and output for kernels. |
35 |
|
36 |
OpenCL::Sampler objects, which are kind of like texture filter modes in |
37 |
OpenGL. |
38 |
|
39 |
OpenCL::Queue objects - command queues, which allow you to submit memory |
40 |
reads, writes and copies, as well as kernel calls to your devices. They |
41 |
also offer a variety of methods to synchronise request execution, for |
42 |
example with barriers or OpenCL::Event objects. |
43 |
|
44 |
OpenCL::Event objects are used to signal when something is complete. |
45 |
|
46 |
=head2 HELPFUL RESOURCES |
47 |
|
48 |
The OpenCL spec used to develop this module (1.2 spec was available, but |
49 |
no implementation was available to me :). |
50 |
|
51 |
http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf |
52 |
|
53 |
OpenCL manpages: |
54 |
|
55 |
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/ |
56 |
|
57 |
=head1 BASIC WORKFLOW |
58 |
|
59 |
To get something done, you basically have to do this once (refer to the |
60 |
examples below for actual code, this is just a high-level description): |
61 |
|
62 |
Find some platform (e.g. the first one) and some device(s) (e.g. the first |
63 |
device of the platform), and create a context from those. |
64 |
|
65 |
Create program objects from your OpenCL source code, then build (compile) |
66 |
the programs for each device you want to run them on. |
67 |
|
68 |
Create kernel objects for all kernels you want to use (surprisingly, these |
69 |
are not device-specific). |
70 |
|
71 |
Then, to execute stuff, you repeat these steps, possibly resuing or |
72 |
sharing some buffers: |
73 |
|
74 |
Create some input and output buffers from your context. Set these as |
75 |
arguments to your kernel. |
76 |
|
77 |
Enqueue buffer writes to initialise your input buffers (when not |
78 |
initialised at creation time). |
79 |
|
80 |
Enqueue the kernel execution. |
81 |
|
82 |
Enqueue buffer reads for your output buffer to read results. |
83 |
|
84 |
=head1 EXAMPLES |
85 |
|
86 |
=head2 Enumerate all devices and get contexts for them. |
87 |
|
88 |
Best run this once to get a feel for the platforms and devices in your |
89 |
system. |
90 |
|
91 |
for my $platform (OpenCL::platforms) { |
92 |
printf "platform: %s\n", $platform->info (OpenCL::PLATFORM_NAME); |
93 |
printf "extensions: %s\n", $platform->info (OpenCL::PLATFORM_EXTENSIONS); |
94 |
for my $device ($platform->devices) { |
95 |
printf "+ device: %s\n", $device->info (OpenCL::DEVICE_NAME); |
96 |
my $ctx = $device->context; |
97 |
# do stuff |
98 |
} |
99 |
} |
100 |
|
101 |
=head2 Get a useful context and a command queue. |
102 |
|
103 |
This is a useful boilerplate for any OpenCL program that only wants to use |
104 |
one device, |
105 |
|
106 |
my ($platform) = OpenCL::platforms; # find first platform |
107 |
my ($dev) = $platform->devices; # find first device of platform |
108 |
my $ctx = $platform->context (undef, [$dev]); # create context out of those |
109 |
my $queue = $ctx->queue ($dev); # create a command queue for the device |
110 |
|
111 |
=head2 Print all supported image formats of a context. |
112 |
|
113 |
Best run this once for your context, to see whats available and how to |
114 |
gather information. |
115 |
|
116 |
for my $type (OpenCL::MEM_OBJECT_IMAGE2D, OpenCL::MEM_OBJECT_IMAGE3D) { |
117 |
print "supported image formats for ", OpenCL::enum2str $type, "\n"; |
118 |
|
119 |
for my $f ($ctx->supported_image_formats (0, $type)) { |
120 |
printf " %-10s %-20s\n", OpenCL::enum2str $f->[0], OpenCL::enum2str $f->[1]; |
121 |
} |
122 |
} |
123 |
|
124 |
=head2 Create a buffer with some predefined data, read it back synchronously, |
125 |
then asynchronously. |
126 |
|
127 |
my $buf = $ctx->buffer_sv (OpenCL::MEM_COPY_HOST_PTR, "helmut"); |
128 |
|
129 |
$queue->enqueue_read_buffer ($buf, 1, 1, 3, my $data); |
130 |
print "$data\n"; |
131 |
|
132 |
my $ev = $queue->enqueue_read_buffer ($buf, 0, 1, 3, my $data); |
133 |
$ev->wait; |
134 |
print "$data\n"; # prints "elm" |
135 |
|
136 |
=head2 Create and build a program, then create a kernel out of one of its |
137 |
functions. |
138 |
|
139 |
my $src = ' |
140 |
__kernel void |
141 |
squareit (__global float *input, __global float *output) |
142 |
{ |
143 |
size_t id = get_global_id (0); |
144 |
output [id] = input [id] * input [id]; |
145 |
} |
146 |
'; |
147 |
|
148 |
my $prog = $ctx->program_with_source ($src); |
149 |
|
150 |
# build croaks on compile errors, so catch it and print the compile errors |
151 |
eval { $prog->build ($dev); 1 } |
152 |
or die $prog->build_info ($dev, OpenCL::PROGRAM_BUILD_LOG); |
153 |
|
154 |
my $kernel = $prog->kernel ("squareit"); |
155 |
|
156 |
=head2 Create some input and output float buffers, then call the |
157 |
'squareit' kernel on them. |
158 |
|
159 |
my $input = $ctx->buffer_sv (OpenCL::MEM_COPY_HOST_PTR, pack "f*", 1, 2, 3, 4.5); |
160 |
my $output = $ctx->buffer (0, OpenCL::SIZEOF_FLOAT * 5); |
161 |
|
162 |
# set buffer |
163 |
$kernel->set_buffer (0, $input); |
164 |
$kernel->set_buffer (1, $output); |
165 |
|
166 |
# execute it for all 4 numbers |
167 |
$queue->enqueue_nd_range_kernel ($kernel, undef, [4], undef); |
168 |
|
169 |
# enqueue a synchronous read |
170 |
$queue->enqueue_read_buffer ($output, 1, 0, OpenCL::SIZEOF_FLOAT * 4, my $data); |
171 |
|
172 |
# print the results: |
173 |
printf "%s\n", join ", ", unpack "f*", $data; |
174 |
|
175 |
=head2 The same enqueue operations as before, but assuming an out-of-order queue, |
176 |
showing off barriers. |
177 |
|
178 |
# execute it for all 4 numbers |
179 |
$queue->enqueue_nd_range_kernel ($kernel, undef, [4], undef); |
180 |
|
181 |
# enqueue a barrier to ensure in-order execution |
182 |
$queue->enqueue_barrier; |
183 |
|
184 |
# enqueue an async read |
185 |
$queue->enqueue_read_buffer ($output, 0, 0, OpenCL::SIZEOF_FLOAT * 4, my $data); |
186 |
|
187 |
# wait for all requests to finish |
188 |
$queue->finish; |
189 |
|
190 |
=head2 The same enqueue operations as before, but assuming an out-of-order queue, |
191 |
showing off event objects and wait lists. |
192 |
|
193 |
# execute it for all 4 numbers |
194 |
my $ev = $queue->enqueue_nd_range_kernel ($kernel, undef, [4], undef); |
195 |
|
196 |
# enqueue an async read |
197 |
$ev = $queue->enqueue_read_buffer ($output, 0, 0, OpenCL::SIZEOF_FLOAT * 4, my $data, $ev); |
198 |
|
199 |
# wait for the last event to complete |
200 |
$ev->wait; |
201 |
|
202 |
=head1 DOCUMENTATION |
203 |
|
204 |
=head2 BASIC CONVENTIONS |
205 |
|
206 |
This is not a 1:1 C-style translation of OpenCL to Perl - instead I |
207 |
attempted to make the interface as type-safe as possible and introducing |
208 |
object syntax where it makes sense. There are a number of important |
209 |
differences between the OpenCL C API and this module: |
210 |
|
211 |
=over 4 |
212 |
|
213 |
=item * Object lifetime managament is automatic - there is no need |
214 |
to free objects explicitly (C<clReleaseXXX>), the release function |
215 |
is called automatically once all Perl references to it go away. |
216 |
|
217 |
=item * OpenCL uses CamelCase for function names (C<clGetPlatformInfo>), |
218 |
while this module uses underscores as word separator and often leaves out |
219 |
prefixes (C<< $platform->info >>). |
220 |
|
221 |
=item * OpenCL often specifies fixed vector function arguments as short |
222 |
arrays (C<size_t origin[3]>), while this module explicitly expects the |
223 |
components as separate arguments- |
224 |
|
225 |
=item * Where possible, one of the pitch values is calculated from the |
226 |
perl scalar length and need not be specified. |
227 |
|
228 |
=item * When enqueuing commands, the wait list is specified by adding |
229 |
extra arguments to the function - anywhere a C<$wait_events...> argument |
230 |
is documented this can be any number of event objects. |
231 |
|
232 |
=item * When enqueuing commands, if the enqueue method is called in void |
233 |
context, no event is created. In all other contexts an event is returned |
234 |
by the method. |
235 |
|
236 |
=item * This module expects all functions to return C<CL_SUCCESS>. If any |
237 |
other status is returned the function will throw an exception, so you |
238 |
don't normally have to to any error checking. |
239 |
|
240 |
=back |
241 |
|
242 |
=head2 PERL AND OPENCL TYPES |
243 |
|
244 |
This handy(?) table lists OpenCL types and their perl, PDL and pack/unpack |
245 |
format equivalents: |
246 |
|
247 |
OpenCL perl PDL pack/unpack |
248 |
char IV - c |
249 |
uchar IV byte C |
250 |
short IV short s |
251 |
ushort IV ushort S |
252 |
int IV long? l |
253 |
uint IV - L |
254 |
long IV longlong q |
255 |
ulong IV - Q |
256 |
float NV float f |
257 |
half IV ushort S |
258 |
double NV double d |
259 |
|
260 |
=head2 THE OpenCL PACKAGE |
261 |
|
262 |
=over 4 |
263 |
|
264 |
=item $int = OpenCL::errno |
265 |
|
266 |
The last error returned by a function - it's only valid after an error occured |
267 |
and before calling another OpenCL function. |
268 |
|
269 |
=item $str = OpenCL::err2str $errval |
270 |
|
271 |
Comverts an error value into a human readable string. |
272 |
|
273 |
=item $str = OpenCL::enum2str $enum |
274 |
|
275 |
Converts most enum values (inof parameter names, image format constants, |
276 |
object types, addressing and filter modes, command types etc.) into a |
277 |
human readbale string. When confronted with some random integer it can be |
278 |
very helpful to pass it through this function to maybe get some readable |
279 |
string out of it. |
280 |
|
281 |
=item @platforms = OpenCL::platforms |
282 |
|
283 |
Returns all available OpenCL::Platform objects. |
284 |
|
285 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformIDs.html> |
286 |
|
287 |
=item $ctx = OpenCL::context_from_type $properties, $type = OpenCL::DEVICE_TYPE_DEFAULT, $notify = undef |
288 |
|
289 |
Tries to create a context from a default device and platform - never worked for me. |
290 |
|
291 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html> |
292 |
|
293 |
=item OpenCL::wait_for_events $wait_events... |
294 |
|
295 |
Waits for all events to complete. |
296 |
|
297 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clWaitForEvents.html> |
298 |
|
299 |
=back |
300 |
|
301 |
=head2 THE OpenCL::Platform CLASS |
302 |
|
303 |
=over 4 |
304 |
|
305 |
=item $packed_value = $platform->info ($name) |
306 |
|
307 |
Calls C<clGetPlatformInfo> and returns the packed, raw value - for |
308 |
strings, this will be the string, for other values you probably need to |
309 |
use the correct C<unpack>. This might get improved in the future. Hopefully. |
310 |
|
311 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformInfo.html> |
312 |
|
313 |
=item @devices = $platform->devices ($type = OpenCL::DEVICE_TYPE_ALL) |
314 |
|
315 |
Returns a list of matching OpenCL::Device objects. |
316 |
|
317 |
=item $ctx = $platform->context_from_type ($properties, $type = OpenCL::DEVICE_TYPE_DEFAULT, $notify = undef) |
318 |
|
319 |
Tries to create a context. Never worked for me, and you need devices explitly anyway. |
320 |
|
321 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html> |
322 |
|
323 |
=item $ctx = $device->context ($properties = undef, @$devices, $notify = undef) |
324 |
|
325 |
Create a new OpenCL::Context object using the given device object(s)- a |
326 |
CL_CONTEXT_PLATFORM property is supplied automatically. |
327 |
|
328 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html> |
329 |
|
330 |
=back |
331 |
|
332 |
=head2 THE OpenCL::Device CLASS |
333 |
|
334 |
=over 4 |
335 |
|
336 |
=item $packed_value = $device->info ($name) |
337 |
|
338 |
See C<< $platform->info >> for details. |
339 |
|
340 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetDeviceInfo.html> |
341 |
|
342 |
=back |
343 |
|
344 |
=head2 THE OpenCL::Context CLASS |
345 |
|
346 |
=over 4 |
347 |
|
348 |
=item $packed_value = $ctx->info ($name) |
349 |
|
350 |
See C<< $platform->info >> for details. |
351 |
|
352 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetContextInfo.html> |
353 |
|
354 |
=item $queue = $ctx->queue ($device, $properties) |
355 |
|
356 |
Create a new OpenCL::Queue object from the context and the given device. |
357 |
|
358 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateCommandQueue.html> |
359 |
|
360 |
=item $ev = $ctx->user_event |
361 |
|
362 |
Creates a new OpenCL::UserEvent object. |
363 |
|
364 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateUserEvent.html> |
365 |
|
366 |
=item $buf = $ctx->buffer ($flags, $len) |
367 |
|
368 |
Creates a new OpenCL::Buffer object with the given flags and octet-size. |
369 |
|
370 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html> |
371 |
|
372 |
=item $buf = $ctx->buffer_sv ($flags, $data) |
373 |
|
374 |
Creates a new OpenCL::Buffer object and initialise it with the given data values. |
375 |
|
376 |
=item $img = $ctx->image2d ($flags, $channel_order, $channel_type, $width, $height, $data) |
377 |
|
378 |
Creates a new OpenCL::Image2D object and optionally initialises it with the given data values. |
379 |
|
380 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage2D.html> |
381 |
|
382 |
=item $img = $ctx->image3d ($flags, $channel_order, $channel_type, $width, $height, $depth, $slice_pitch, $data) |
383 |
|
384 |
Creates a new OpenCL::Image3D object and optionally initialises it with the given data values. |
385 |
|
386 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage3D.html> |
387 |
|
388 |
=item @formats = $ctx->supported_image_formats ($flags, $image_type) |
389 |
|
390 |
Returns a list of matching image formats - each format is an arrayref with |
391 |
two values, $channel_order and $channel_type, in it. |
392 |
|
393 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetSupportedImageFormats.html> |
394 |
|
395 |
=item $sampler = $ctx->sampler ($normalized_coords, $addressing_mode, $filter_mode) |
396 |
|
397 |
Creates a new OpenCL::Sampler object. |
398 |
|
399 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateSampler.html> |
400 |
|
401 |
=item $program = $ctx->program_with_source ($string) |
402 |
|
403 |
Creates a new OpenCL::Program object from the given source code. |
404 |
|
405 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateProgramWithSource.html> |
406 |
|
407 |
=back |
408 |
|
409 |
=head2 THE OpenCL::Queue CLASS |
410 |
|
411 |
An OpenCL::Queue represents an execution queue for OpenCL. You execute |
412 |
requests by calling their respective C<enqueue_xxx> method and waitinf for |
413 |
it to complete in some way. |
414 |
|
415 |
All the enqueue methods return an event object that can be used to wait |
416 |
for completion, unless the method is called in void context, in which case |
417 |
no event object is created. |
418 |
|
419 |
They also allow you to specify any number of other event objects that this |
420 |
request has to wait for before it starts executing, by simply passing the |
421 |
event objects as extra parameters to the enqueue methods. |
422 |
|
423 |
Queues execute in-order by default, without any parallelism, so in most |
424 |
cases (i.e. you use only one queue) it's not necessary to wait for or |
425 |
create event objects. |
426 |
|
427 |
=over 4 |
428 |
|
429 |
=item $packed_value = $ctx->info ($name) |
430 |
|
431 |
See C<< $platform->info >> for details. |
432 |
|
433 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetCommandQueueInfo.html> |
434 |
|
435 |
=item $ev = $queue->enqueue_read_buffer ($buffer, $blocking, $offset, $len, $data, $wait_events...) |
436 |
|
437 |
Reads data from buffer into the given string. |
438 |
|
439 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBuffer.html> |
440 |
|
441 |
=item $ev = $queue->enqueue_write_buffer ($buffer, $blocking, $offset, $data, $wait_events...) |
442 |
|
443 |
Writes data to buffer from the given string. |
444 |
|
445 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBuffer.html> |
446 |
|
447 |
=item $ev = $queue->enqueue_copy_buffer ($src, $dst, $src_offset, $dst_offset, $len, $wait_events...) |
448 |
|
449 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBuffer.html> |
450 |
|
451 |
=item $ev = $queue->enqueue_read_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...) |
452 |
|
453 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadImage.html> |
454 |
|
455 |
=item $ev = $queue->enqueue_write_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $data, $wait_events...) |
456 |
|
457 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteImage.html> |
458 |
|
459 |
=item $ev = $queue->enqueue_copy_buffer_rect ($src, $dst, $src_x, $src_y, $src_z, $dst_x, $dst_y, $dst_z, $width, $height, $depth, $src_row_pitch, $src_slice_pitch, 4dst_row_pitch, $dst_slice_pitch, $ait_event...) |
460 |
|
461 |
Yeah. |
462 |
|
463 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferRect.html> |
464 |
|
465 |
=item $ev = $queue->enqueue_copy_buffer_to_image (OpenCL::Buffer src, OpenCL::Image dst, size_t src_offset, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...) |
466 |
|
467 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html>. |
468 |
|
469 |
=item $ev = $queue->enqueue_copy_image (OpenCL::Image src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t dst_x, size_t dst_y, size_t dst_z, size_t width, size_t height, size_t depth, ...) |
470 |
|
471 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImage.html> |
472 |
|
473 |
=item $ev = $queue->enqueue_copy_image_to_buffer (OpenCL::Image src, OpenCL::Buffer dst, size_t src_x, size_t src_y, size_t src_z, size_t width, size_t height, size_t depth, size_t dst_offset, ...) |
474 |
|
475 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImageToBuffer.html> |
476 |
|
477 |
=item $ev = $queue->enqueue_task ($kernel, $wait_events...) |
478 |
|
479 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueTask.html> |
480 |
|
481 |
=item $ev = $queue->enqueue_nd_range_kernel ($kernel, @$global_work_offset, @$global_work_size, @$local_work_size, $wait_events...) |
482 |
|
483 |
Enqueues a kernel execution. |
484 |
|
485 |
@$global_work_size must be specified as a reference to an array of |
486 |
integers specifying the work sizes (element counts). |
487 |
|
488 |
@$global_work_offset must be either C<undef> (in which case all offsets |
489 |
are C<0>), or a reference to an array of work offsets, with the same number |
490 |
of elements as @$global_work_size. |
491 |
|
492 |
@$local_work_size must be either C<undef> (in which case the |
493 |
implementation is supposed to choose good local work sizes), or a |
494 |
reference to an array of local work sizes, with the same number of |
495 |
elements as @$global_work_size. |
496 |
|
497 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueNDRangeKernel.html> |
498 |
|
499 |
=item $ev = $queue->enqueue_marker |
500 |
|
501 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueMarker.html> |
502 |
|
503 |
=item $ev = $queue->enqueue_wait_for_events ($wait_events...) |
504 |
|
505 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWaitForEvents.html> |
506 |
|
507 |
=item $queue->enqueue_barrier |
508 |
|
509 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueBarrier.html> |
510 |
|
511 |
=item $queue->flush |
512 |
|
513 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clFlush.html> |
514 |
|
515 |
=item $queue->finish |
516 |
|
517 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clFinish.html> |
518 |
|
519 |
=back |
520 |
|
521 |
=head2 THE OpenCL::Memory CLASS |
522 |
|
523 |
This the superclass of all memory objects - OpenCL::Buffer, OpenCL::Image, |
524 |
OpenCL::Image2D and OpenCL::Image3D. The subclasses of this class |
525 |
currently only exist to allow type-checking. |
526 |
|
527 |
=over 4 |
528 |
|
529 |
=item $packed_value = $memory->info ($name) |
530 |
|
531 |
See C<< $platform->info >> for details. |
532 |
|
533 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetMemObjectInfo.html> |
534 |
|
535 |
=back |
536 |
|
537 |
=head2 THE OpenCL::Sampler CLASS |
538 |
|
539 |
=over 4 |
540 |
|
541 |
=item $packed_value = $sampler->info ($name) |
542 |
|
543 |
See C<< $platform->info >> for details. |
544 |
|
545 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetSamplerInfo.html> |
546 |
|
547 |
=back |
548 |
|
549 |
=head2 THE OpenCL::Program CLASS |
550 |
|
551 |
=over 4 |
552 |
|
553 |
=item $packed_value = $program->info ($name) |
554 |
|
555 |
See C<< $platform->info >> for details. |
556 |
|
557 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetProgramInfo.html> |
558 |
|
559 |
=item $program->build ($device, $options = "") |
560 |
|
561 |
Tries to build the program with the givne options. |
562 |
|
563 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clBuildProgram.html> |
564 |
|
565 |
=item $packed_value = $program->build_info ($device, $name) |
566 |
|
567 |
Similar to C<< $platform->info >>, but returns build info for a previous |
568 |
build attempt for the given device. |
569 |
|
570 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetBuildInfo.html> |
571 |
|
572 |
=item $kernel = $program->kernel ($function_name) |
573 |
|
574 |
Creates an OpenCL::Kernel object out of the named C<__kernel> function in |
575 |
the program. |
576 |
|
577 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateKernel.html> |
578 |
|
579 |
=back |
580 |
|
581 |
=head2 THE OpenCL::Kernel CLASS |
582 |
|
583 |
=over 4 |
584 |
|
585 |
=item $packed_value = $kernel->info ($name) |
586 |
|
587 |
See C<< $platform->info >> for details. |
588 |
|
589 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetKernelInfo.html> |
590 |
|
591 |
=item $kernel->set_TYPE ($index, $value) |
592 |
|
593 |
This is a family of methods to set the kernel argument with the number C<$index> to the give C<$value>. |
594 |
|
595 |
TYPE is one of C<char>, C<uchar>, C<short>, C<ushort>, C<int>, C<uint>, |
596 |
C<long>, C<ulong>, C<half>, C<float>, C<double>, C<memory>, C<buffer>, |
597 |
C<image2d>, C<image3d>, C<sampler> or C<event>. |
598 |
|
599 |
Chars and integers (including the half type) are specified as integers, |
600 |
float and double as floating point values, memory/buffer/image2d/image3d |
601 |
must be an object of that type or C<undef>, and sampler and event must be |
602 |
objects of that type. |
603 |
|
604 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clSetKernelArg.html> |
605 |
|
606 |
=back |
607 |
|
608 |
=head2 THE OpenCL::Event CLASS |
609 |
|
610 |
This is the superclass for all event objects (including OpenCL::UserEvent |
611 |
objects). |
612 |
|
613 |
=over 4 |
614 |
|
615 |
=item $packed_value = $ev->info ($name) |
616 |
|
617 |
See C<< $platform->info >> for details. |
618 |
|
619 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetEventInfo.html> |
620 |
|
621 |
=item $ev->wait |
622 |
|
623 |
Waits for the event to complete. |
624 |
|
625 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clWaitForEvents.html> |
626 |
|
627 |
=back |
628 |
|
629 |
=head2 THE OpenCL::UserEvent CLASS |
630 |
|
631 |
This is a subclass of OpenCL::Event. |
632 |
|
633 |
=over 4 |
634 |
|
635 |
=item $ev->set_status ($execution_status) |
636 |
|
637 |
L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clSetUserEventStatus.html> |
638 |
|
639 |
=back |
640 |
|
641 |
=cut |
642 |
|
643 |
package OpenCL; |
644 |
|
645 |
use common::sense; |
646 |
|
647 |
BEGIN { |
648 |
our $VERSION = '0.03'; |
649 |
|
650 |
require XSLoader; |
651 |
XSLoader::load (__PACKAGE__, $VERSION); |
652 |
|
653 |
@OpenCL::Buffer::ISA = |
654 |
@OpenCL::Image::ISA = OpenCL::Memory::; |
655 |
|
656 |
@OpenCL::Image2D::ISA = |
657 |
@OpenCL::Image3D::ISA = OpenCL::Image::; |
658 |
|
659 |
@OpenCL::UserEvent::ISA = OpenCL::Event::; |
660 |
} |
661 |
|
662 |
1; |
663 |
|
664 |
=head1 AUTHOR |
665 |
|
666 |
Marc Lehmann <schmorp@schmorp.de> |
667 |
http://home.schmorp.de/ |
668 |
|
669 |
=cut |
670 |
|