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

Comparing OpenCL/OpenCL.pm (file contents):
Revision 1.9 by root, Thu Nov 17 01:36:52 2011 UTC vs.
Revision 1.10 by root, Thu Nov 17 02:10:39 2011 UTC

80=head1 EXAMPLES 80=head1 EXAMPLES
81 81
82=head2 Enumerate all devices and get contexts for them. 82=head2 Enumerate all devices and get contexts for them.
83 83
84 for my $platform (OpenCL::platforms) { 84 for my $platform (OpenCL::platforms) {
85 warn $platform->info (OpenCL::PLATFORM_NAME); 85 printf "platform: %s\n", $platform->info (OpenCL::PLATFORM_NAME);
86 warn $platform->info (OpenCL::PLATFORM_EXTENSIONS); 86 printf "extensions: %s\n", $platform->info (OpenCL::PLATFORM_EXTENSIONS);
87 for my $device ($platform->devices) { 87 for my $device ($platform->devices) {
88 warn $device->info (OpenCL::DEVICE_NAME); 88 printf "+ device: %s\n", $device->info (OpenCL::DEVICE_NAME);
89 my $ctx = $device->context_simple; 89 my $ctx = $device->context;
90 # do stuff 90 # do stuff
91 } 91 }
92 } 92 }
93 93
94=head2 Get a useful context and a command queue. 94=head2 Get a useful context and a command queue.
95 95
96 my $dev = ((OpenCL::platforms)[0]->devices)[0]; 96 my $dev = ((OpenCL::platforms)[0]->devices)[0];
97 my $ctx = $dev->context_simple; 97 my $ctx = $dev->context;
98 my $queue = $ctx->queue ($dev); 98 my $queue = $ctx->queue ($dev);
99 99
100=head2 Print all supported image formats of a context. 100=head2 Print all supported image formats of a context.
101 101
102 for my $type (OpenCL::MEM_OBJECT_IMAGE2D, OpenCL::MEM_OBJECT_IMAGE3D) { 102 for my $type (OpenCL::MEM_OBJECT_IMAGE2D, OpenCL::MEM_OBJECT_IMAGE3D) {
103 say "supported image formats for ", OpenCL::enum2str $type; 103 print "supported image formats for ", OpenCL::enum2str $type, "\n";
104 104
105 for my $f ($ctx->supported_image_formats (0, $type)) { 105 for my $f ($ctx->supported_image_formats (0, $type)) {
106 printf " %-10s %-20s\n", OpenCL::enum2str $f->[0], OpenCL::enum2str $f->[1]; 106 printf " %-10s %-20s\n", OpenCL::enum2str $f->[0], OpenCL::enum2str $f->[1];
107 } 107 }
108 } 108 }
111then asynchronously. 111then asynchronously.
112 112
113 my $buf = $ctx->buffer_sv (OpenCL::MEM_COPY_HOST_PTR, "helmut"); 113 my $buf = $ctx->buffer_sv (OpenCL::MEM_COPY_HOST_PTR, "helmut");
114 114
115 $queue->enqueue_read_buffer ($buf, 1, 1, 3, my $data); 115 $queue->enqueue_read_buffer ($buf, 1, 1, 3, my $data);
116 warn $data; 116 print "$data\n";
117 117
118 my $ev = $queue->enqueue_read_buffer ($buf, 0, 1, 3, my $data); 118 my $ev = $queue->enqueue_read_buffer ($buf, 0, 1, 3, my $data);
119 $ev->wait; 119 $ev->wait;
120 warn $data; 120 print "$data\n"; # prints "elm"
121 121
122=head2 Create and build a program, then create a kernel out of one of its 122=head2 Create and build a program, then create a kernel out of one of its
123functions. 123functions.
124 124
125 my $src = ' 125 my $src = '
152 152
153 # enqueue a synchronous read 153 # enqueue a synchronous read
154 $queue->enqueue_read_buffer ($output, 1, 0, OpenCL::SIZEOF_FLOAT * 4, my $data); 154 $queue->enqueue_read_buffer ($output, 1, 0, OpenCL::SIZEOF_FLOAT * 4, my $data);
155 155
156 # print the results: 156 # print the results:
157 say join ", ", unpack "f*", $data; 157 printf "%s\n", join ", ", unpack "f*", $data;
158 158
159=head2 The same enqueue operations as before, but assuming an out-of-order queue, 159=head2 The same enqueue operations as before, but assuming an out-of-order queue,
160showing off barriers. 160showing off barriers.
161 161
162 # execute it for all 4 numbers 162 # execute it for all 4 numbers
265 265
266Returns all available OpenCL::Platform objects. 266Returns all available OpenCL::Platform objects.
267 267
268L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformIDs.html> 268L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformIDs.html>
269 269
270=item $ctx = OpenCL::context_from_type_simple $type = OpenCL::DEVICE_TYPE_DEFAULT 270=item $ctx = OpenCL::context_from_type $properties, $type = OpenCL::DEVICE_TYPE_DEFAULT, $notify = undef
271 271
272Tries to create a context from a default device and platform - never worked for me. 272Tries to create a context from a default device and platform - never worked for me.
273 273
274L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html> 274L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html>
275 275
295 295
296=item @devices = $platform->devices ($type = OpenCL::DEVICE_TYPE_ALL) 296=item @devices = $platform->devices ($type = OpenCL::DEVICE_TYPE_ALL)
297 297
298Returns a list of matching OpenCL::Device objects. 298Returns a list of matching OpenCL::Device objects.
299 299
300=item $ctx = $platform->context_from_type_simple ($type = OpenCL::DEVICE_TYPE_DEFAULT) 300=item $ctx = $platform->context_from_type ($properties, $type = OpenCL::DEVICE_TYPE_DEFAULT, $notify = undef)
301 301
302Tries to create a context. Never worked for me. 302Tries to create a context. Never worked for me.
303 303
304L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html> 304L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html>
305 305
313 313
314See C<< $platform->info >> for details. 314See C<< $platform->info >> for details.
315 315
316L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetDeviceInfo.html> 316L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetDeviceInfo.html>
317 317
318=item $ctx = $device->context_simple 318=item $ctx = $device->context ($properties = undef, $notify = undef)
319 319
320Convenience function to create a new OpenCL::Context object. 320Create a new OpenCL::Context object.
321 321
322L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html> 322L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html>
323 323
324=back 324=back
325 325

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines