1 |
root |
1.1 |
=head1 NAME |
2 |
|
|
|
3 |
|
|
OpenCL - bindings to, well, OpenCL |
4 |
|
|
|
5 |
|
|
=head1 SYNOPSIS |
6 |
|
|
|
7 |
|
|
use OpenCL; |
8 |
|
|
|
9 |
|
|
=head1 DESCRIPTION |
10 |
|
|
|
11 |
|
|
This is an early release which is not useful yet. |
12 |
|
|
|
13 |
root |
1.3 |
=head1 HELPFUL RESOURCES |
14 |
|
|
|
15 |
|
|
The OpenCL spec used to dveelop this module (1.2 spec was available, but |
16 |
|
|
no implementation was available to me :). |
17 |
|
|
|
18 |
|
|
http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf |
19 |
|
|
|
20 |
|
|
OpenCL manpages: |
21 |
|
|
|
22 |
|
|
http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/ |
23 |
|
|
|
24 |
|
|
=head1 EXAMPLES |
25 |
|
|
|
26 |
root |
1.1 |
Enumerate all devices and get contexts for them; |
27 |
|
|
|
28 |
|
|
for my $platform (OpenCL::platforms) { |
29 |
|
|
warn $platform->info (OpenCL::PLATFORM_NAME); |
30 |
|
|
warn $platform->info (OpenCL::PLATFORM_EXTENSIONS); |
31 |
|
|
for my $device ($platform->devices) { |
32 |
|
|
warn $device->info (OpenCL::DEVICE_NAME); |
33 |
|
|
my $ctx = $device->context_simple; |
34 |
|
|
# do stuff |
35 |
|
|
} |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
Get a useful context and a command queue: |
39 |
|
|
|
40 |
|
|
my $dev = ((OpenCL::platforms)[0]->devices)[0]; |
41 |
|
|
my $ctx = $dev->context_simple; |
42 |
|
|
my $queue = $ctx->command_queue_simple ($dev); |
43 |
|
|
|
44 |
root |
1.3 |
Create a buffer with some predefined data, read it back synchronously, |
45 |
|
|
then asynchronously: |
46 |
|
|
|
47 |
|
|
my $buf = $ctx->buffer_sv (OpenCL::MEM_COPY_HOST_PTR, "helmut"); |
48 |
|
|
|
49 |
|
|
$queue->enqueue_read_buffer ($buf, 1, 1, 3, my $data); |
50 |
|
|
warn $data; |
51 |
|
|
|
52 |
|
|
my $ev = $queue->enqueue_read_buffer ($buf, 0, 1, 3, my $data); |
53 |
|
|
$ev->wait; |
54 |
|
|
warn $data; |
55 |
|
|
|
56 |
|
|
Print all supported image formats: |
57 |
|
|
|
58 |
|
|
for my $type (OpenCL::MEM_OBJECT_IMAGE2D, OpenCL::MEM_OBJECT_IMAGE3D) { |
59 |
|
|
say "supported image formats for ", OpenCL::enum2str $type; |
60 |
|
|
|
61 |
|
|
for my $f ($ctx->supported_image_formats (0, $type)) { |
62 |
|
|
printf " %-10s %-20s\n", OpenCL::enum2str $f->[0], OpenCL::enum2str $f->[1]; |
63 |
|
|
} |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
Create and build a program, then create a kernel out of one of its |
67 |
|
|
functions: |
68 |
|
|
|
69 |
|
|
my $src = ' |
70 |
|
|
__kernel void |
71 |
|
|
squareit (__global float *input, __global float *output) |
72 |
|
|
{ |
73 |
|
|
size_t id = get_global_id (0); |
74 |
|
|
output [id] = input [id] * input [id]; |
75 |
|
|
} |
76 |
|
|
'; |
77 |
|
|
|
78 |
|
|
my $prog = $ctx->program_with_source ($src); |
79 |
|
|
|
80 |
|
|
eval { $prog->build ($dev); 1 } |
81 |
|
|
or die $prog->build_info ($dev, OpenCL::PROGRAM_BUILD_LOG); |
82 |
|
|
|
83 |
|
|
my $kernel = $prog->kernel ("squareit"); |
84 |
|
|
|
85 |
root |
1.1 |
=over 4 |
86 |
|
|
|
87 |
|
|
=cut |
88 |
|
|
|
89 |
|
|
package OpenCL; |
90 |
|
|
|
91 |
root |
1.2 |
use common::sense; |
92 |
|
|
|
93 |
root |
1.1 |
BEGIN { |
94 |
root |
1.2 |
our $VERSION = '0.01'; |
95 |
root |
1.1 |
|
96 |
|
|
require XSLoader; |
97 |
|
|
XSLoader::load (__PACKAGE__, $VERSION); |
98 |
root |
1.3 |
|
99 |
|
|
@OpenCL::Buffer::ISA = |
100 |
|
|
@OpenCL::Image::ISA = OpenCL::Memory::; |
101 |
|
|
|
102 |
|
|
@OpenCL::Image2D::ISA = |
103 |
|
|
@OpenCL::Image3D::ISA = OpenCL::Image::; |
104 |
root |
1.1 |
} |
105 |
|
|
|
106 |
|
|
1; |
107 |
|
|
|
108 |
|
|
=back |
109 |
|
|
|
110 |
|
|
=head1 AUTHOR |
111 |
|
|
|
112 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
113 |
|
|
http://home.schmorp.de/ |
114 |
|
|
|
115 |
|
|
=cut |
116 |
|
|
|