ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/OpenCL/OpenCL.pm
(Generate patch)

Comparing OpenCL/OpenCL.pm (file contents):
Revision 1.2 by root, Tue Nov 15 09:24:40 2011 UTC vs.
Revision 1.3 by root, Tue Nov 15 20:38:07 2011 UTC

7 use OpenCL; 7 use OpenCL;
8 8
9=head1 DESCRIPTION 9=head1 DESCRIPTION
10 10
11This is an early release which is not useful yet. 11This is an early release which is not useful yet.
12
13=head1 HELPFUL RESOURCES
14
15The OpenCL spec used to dveelop this module (1.2 spec was available, but
16no implementation was available to me :).
17
18 http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf
19
20OpenCL manpages:
21
22 http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/
23
24=head1 EXAMPLES
12 25
13Enumerate all devices and get contexts for them; 26Enumerate all devices and get contexts for them;
14 27
15 for my $platform (OpenCL::platforms) { 28 for my $platform (OpenCL::platforms) {
16 warn $platform->info (OpenCL::PLATFORM_NAME); 29 warn $platform->info (OpenCL::PLATFORM_NAME);
26 39
27 my $dev = ((OpenCL::platforms)[0]->devices)[0]; 40 my $dev = ((OpenCL::platforms)[0]->devices)[0];
28 my $ctx = $dev->context_simple; 41 my $ctx = $dev->context_simple;
29 my $queue = $ctx->command_queue_simple ($dev); 42 my $queue = $ctx->command_queue_simple ($dev);
30 43
44Create a buffer with some predefined data, read it back synchronously,
45then 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
56Print 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
66Create and build a program, then create a kernel out of one of its
67functions:
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
31=over 4 85=over 4
32 86
33=cut 87=cut
34 88
35package OpenCL; 89package OpenCL;
39BEGIN { 93BEGIN {
40 our $VERSION = '0.01'; 94 our $VERSION = '0.01';
41 95
42 require XSLoader; 96 require XSLoader;
43 XSLoader::load (__PACKAGE__, $VERSION); 97 XSLoader::load (__PACKAGE__, $VERSION);
98
99 @OpenCL::Buffer::ISA =
100 @OpenCL::Image::ISA = OpenCL::Memory::;
101
102 @OpenCL::Image2D::ISA =
103 @OpenCL::Image3D::ISA = OpenCL::Image::;
44} 104}
45 105
461; 1061;
47 107
48=back 108=back

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines