… | |
… | |
18 | vendors) - usually there is only one. |
18 | vendors) - usually there is only one. |
19 | |
19 | |
20 | Each platform gives you access to a number of OpenCL::Device objects, e.g. |
20 | Each platform gives you access to a number of OpenCL::Device objects, e.g. |
21 | your graphics card. |
21 | your graphics card. |
22 | |
22 | |
23 | From a platform and some devices, you create an OpenCL::Context, which is |
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 |
24 | a very central object in OpenCL: Once you have a context you can create |
25 | most other objects: |
25 | most other objects: |
26 | |
26 | |
27 | OpenCL::Program objects, which store source code and, after building |
27 | OpenCL::Program objects, which store source code and, after building for a |
28 | ("compiling and linking"), also binary programs. For each kernel function |
28 | specific device ("compiling and linking"), also binary programs. For each |
29 | in a program you can then create an OpenCL::Kernel object which represents |
29 | kernel function in a program you can then create an OpenCL::Kernel object |
30 | basically a function call with argument values. |
30 | which represents basically a function call with argument values. |
31 | |
31 | |
32 | OpenCL::Memory objects of various flavours: OpenCL::Buffers objects (flat |
32 | OpenCL::Memory objects of various flavours: OpenCL::Buffer objects (flat |
33 | memory areas, think array) and OpenCL::Image objects (think 2d or 3d |
33 | memory areas, think arrays or structs) and OpenCL::Image objects (think 2d |
34 | array) for bulk data and input and output for kernels. |
34 | or 3d array) for bulk data and input and output for kernels. |
35 | |
35 | |
36 | OpenCL::Sampler objects, which are kind of like texture filter modes in |
36 | OpenCL::Sampler objects, which are kind of like texture filter modes in |
37 | OpenGL. |
37 | OpenGL. |
38 | |
38 | |
39 | OpenCL::Queue objects - command queues, which allow you to submit memory |
39 | OpenCL::Queue objects - command queues, which allow you to submit memory |
… | |
… | |
52 | |
52 | |
53 | OpenCL manpages: |
53 | OpenCL manpages: |
54 | |
54 | |
55 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/ |
55 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/ |
56 | |
56 | |
|
|
57 | If you are into UML class diagrams, the following diagram might help - if |
|
|
58 | not, it will be mildly cobfusing: |
|
|
59 | |
|
|
60 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/classDiagram.html |
|
|
61 | |
|
|
62 | Here's a tutorial from AMD (very AMD-centric, too), not sure how useful it |
|
|
63 | is, but at least it's free of charge: |
|
|
64 | |
|
|
65 | http://developer.amd.com/zones/OpenCLZone/courses/Documents/Introduction_to_OpenCL_Programming%20Training_Guide%20%28201005%29.pdf |
|
|
66 | |
|
|
67 | And here's NVIDIA's OpenCL Best Practises Guide: |
|
|
68 | |
|
|
69 | http://developer.download.nvidia.com/compute/cuda/3_2/toolkit/docs/OpenCL_Best_Practices_Guide.pdf |
|
|
70 | |
57 | =head1 BASIC WORKFLOW |
71 | =head1 BASIC WORKFLOW |
58 | |
72 | |
59 | To get something done, you basically have to do this once: |
73 | To get something done, you basically have to do this once (refer to the |
|
|
74 | examples below for actual code, this is just a high-level description): |
60 | |
75 | |
61 | Find some platform (e.g. the first one) and some device (e.g. the first |
76 | Find some platform (e.g. the first one) and some device(s) (e.g. the first |
62 | device you can find), and create a context from those. |
77 | device of the platform), and create a context from those. |
63 | |
78 | |
64 | Create a command queue from your context, and program objects from your |
79 | Create program objects from your OpenCL source code, then build (compile) |
65 | OpenCL source code, build the programs. |
80 | the programs for each device you want to run them on. |
66 | |
81 | |
67 | Create kernel objects for all kernels you want to use. |
82 | Create kernel objects for all kernels you want to use (surprisingly, these |
|
|
83 | are not device-specific). |
68 | |
84 | |
69 | Then, to execute stuff, you repeat this: |
85 | Then, to execute stuff, you repeat these steps, possibly resuing or |
|
|
86 | sharing some buffers: |
70 | |
87 | |
71 | Create some input and output buffers from your context. Initialise the |
88 | Create some input and output buffers from your context. Set these as |
72 | input buffers with data. Set these as arguments to your kernel. |
89 | arguments to your kernel. |
|
|
90 | |
|
|
91 | Enqueue buffer writes to initialise your input buffers (when not |
|
|
92 | initialised at creation time). |
73 | |
93 | |
74 | Enqueue the kernel execution. |
94 | Enqueue the kernel execution. |
75 | |
95 | |
76 | Enqueue buffer reads for your output buffer to read results. |
96 | Enqueue buffer reads for your output buffer to read results. |
77 | |
97 | |
78 | The next section shows how this can be done. |
|
|
79 | |
|
|
80 | =head1 EXAMPLES |
98 | =head1 EXAMPLES |
81 | |
99 | |
82 | =head2 Enumerate all devices and get contexts for them. |
100 | =head2 Enumerate all devices and get contexts for them. |
83 | |
101 | |
|
|
102 | Best run this once to get a feel for the platforms and devices in your |
|
|
103 | system. |
|
|
104 | |
84 | for my $platform (OpenCL::platforms) { |
105 | for my $platform (OpenCL::platforms) { |
85 | warn $platform->info (OpenCL::PLATFORM_NAME); |
106 | printf "platform: %s\n", $platform->info (OpenCL::PLATFORM_NAME); |
86 | warn $platform->info (OpenCL::PLATFORM_EXTENSIONS); |
107 | printf "extensions: %s\n", $platform->info (OpenCL::PLATFORM_EXTENSIONS); |
87 | for my $device ($platform->devices) { |
108 | for my $device ($platform->devices) { |
88 | warn $device->info (OpenCL::DEVICE_NAME); |
109 | printf "+ device: %s\n", $device->info (OpenCL::DEVICE_NAME); |
89 | my $ctx = $device->context_simple; |
110 | my $ctx = $device->context; |
90 | # do stuff |
111 | # do stuff |
91 | } |
112 | } |
92 | } |
113 | } |
93 | |
114 | |
94 | =head2 Get a useful context and a command queue. |
115 | =head2 Get a useful context and a command queue. |
95 | |
116 | |
96 | my $dev = ((OpenCL::platforms)[0]->devices)[0]; |
117 | This is a useful boilerplate for any OpenCL program that only wants to use |
97 | my $ctx = $dev->context_simple; |
118 | one device, |
98 | my $queue = $ctx->queue ($dev); |
119 | |
|
|
120 | my ($platform) = OpenCL::platforms; # find first platform |
|
|
121 | my ($dev) = $platform->devices; # find first device of platform |
|
|
122 | my $ctx = $platform->context (undef, [$dev]); # create context out of those |
|
|
123 | my $queue = $ctx->queue ($dev); # create a command queue for the device |
99 | |
124 | |
100 | =head2 Print all supported image formats of a context. |
125 | =head2 Print all supported image formats of a context. |
101 | |
126 | |
|
|
127 | Best run this once for your context, to see whats available and how to |
|
|
128 | gather information. |
|
|
129 | |
102 | for my $type (OpenCL::MEM_OBJECT_IMAGE2D, OpenCL::MEM_OBJECT_IMAGE3D) { |
130 | for my $type (OpenCL::MEM_OBJECT_IMAGE2D, OpenCL::MEM_OBJECT_IMAGE3D) { |
103 | say "supported image formats for ", OpenCL::enum2str $type; |
131 | print "supported image formats for ", OpenCL::enum2str $type, "\n"; |
104 | |
132 | |
105 | for my $f ($ctx->supported_image_formats (0, $type)) { |
133 | for my $f ($ctx->supported_image_formats (0, $type)) { |
106 | printf " %-10s %-20s\n", OpenCL::enum2str $f->[0], OpenCL::enum2str $f->[1]; |
134 | printf " %-10s %-20s\n", OpenCL::enum2str $f->[0], OpenCL::enum2str $f->[1]; |
107 | } |
135 | } |
108 | } |
136 | } |
… | |
… | |
111 | then asynchronously. |
139 | then asynchronously. |
112 | |
140 | |
113 | my $buf = $ctx->buffer_sv (OpenCL::MEM_COPY_HOST_PTR, "helmut"); |
141 | my $buf = $ctx->buffer_sv (OpenCL::MEM_COPY_HOST_PTR, "helmut"); |
114 | |
142 | |
115 | $queue->enqueue_read_buffer ($buf, 1, 1, 3, my $data); |
143 | $queue->enqueue_read_buffer ($buf, 1, 1, 3, my $data); |
116 | warn $data; |
144 | print "$data\n"; |
117 | |
145 | |
118 | my $ev = $queue->enqueue_read_buffer ($buf, 0, 1, 3, my $data); |
146 | my $ev = $queue->enqueue_read_buffer ($buf, 0, 1, 3, my $data); |
119 | $ev->wait; |
147 | $ev->wait; |
120 | warn $data; |
148 | print "$data\n"; # prints "elm" |
121 | |
149 | |
122 | =head2 Create and build a program, then create a kernel out of one of its |
150 | =head2 Create and build a program, then create a kernel out of one of its |
123 | functions. |
151 | functions. |
124 | |
152 | |
125 | my $src = ' |
153 | my $src = ' |
126 | __kernel void |
154 | __kernel void |
127 | squareit (__global float *input, __global float *output) |
155 | squareit (__global float *input, __global float *output) |
128 | { |
156 | { |
129 | size_t id = get_global_id (0); |
157 | $id = get_global_id (0); |
130 | output [id] = input [id] * input [id]; |
158 | output [id] = input [id] * input [id]; |
131 | } |
159 | } |
132 | '; |
160 | '; |
133 | |
161 | |
134 | my $prog = $ctx->program_with_source ($src); |
162 | my $prog = $ctx->program_with_source ($src); |
135 | |
163 | |
|
|
164 | # build croaks on compile errors, so catch it and print the compile errors |
136 | eval { $prog->build ($dev); 1 } |
165 | eval { $prog->build ($dev); 1 } |
137 | or die $prog->build_info ($dev, OpenCL::PROGRAM_BUILD_LOG); |
166 | or die $prog->build_info ($dev, OpenCL::PROGRAM_BUILD_LOG); |
138 | |
167 | |
139 | my $kernel = $prog->kernel ("squareit"); |
168 | my $kernel = $prog->kernel ("squareit"); |
140 | |
169 | |
141 | =head2 Create some input and output float buffers, then call squareit on them. |
170 | =head2 Create some input and output float buffers, then call the |
|
|
171 | 'squareit' kernel on them. |
142 | |
172 | |
143 | my $input = $ctx->buffer_sv (OpenCL::MEM_COPY_HOST_PTR, pack "f*", 1, 2, 3, 4.5); |
173 | my $input = $ctx->buffer_sv (OpenCL::MEM_COPY_HOST_PTR, pack "f*", 1, 2, 3, 4.5); |
144 | my $output = $ctx->buffer (0, OpenCL::SIZEOF_FLOAT * 5); |
174 | my $output = $ctx->buffer (0, OpenCL::SIZEOF_FLOAT * 5); |
145 | |
175 | |
146 | # set buffer |
176 | # set buffer |
… | |
… | |
152 | |
182 | |
153 | # enqueue a synchronous read |
183 | # enqueue a synchronous read |
154 | $queue->enqueue_read_buffer ($output, 1, 0, OpenCL::SIZEOF_FLOAT * 4, my $data); |
184 | $queue->enqueue_read_buffer ($output, 1, 0, OpenCL::SIZEOF_FLOAT * 4, my $data); |
155 | |
185 | |
156 | # print the results: |
186 | # print the results: |
157 | say join ", ", unpack "f*", $data; |
187 | printf "%s\n", join ", ", unpack "f*", $data; |
158 | |
188 | |
159 | =head2 The same enqueue operations as before, but assuming an out-of-order queue, |
189 | =head2 The same enqueue operations as before, but assuming an out-of-order queue, |
160 | showing off barriers. |
190 | showing off barriers. |
161 | |
191 | |
162 | # execute it for all 4 numbers |
192 | # execute it for all 4 numbers |
… | |
… | |
185 | |
215 | |
186 | =head1 DOCUMENTATION |
216 | =head1 DOCUMENTATION |
187 | |
217 | |
188 | =head2 BASIC CONVENTIONS |
218 | =head2 BASIC CONVENTIONS |
189 | |
219 | |
190 | This is not a 1:1 C-style translation of OpenCL to Perl - instead I |
220 | This is not a one-to-one C-style translation of OpenCL to Perl - instead |
191 | attempted to make the interface as type-safe as possible and introducing |
221 | I attempted to make the interface as type-safe as possible by introducing |
192 | object syntax where it makes sense. There are a number of important |
222 | object syntax where it makes sense. There are a number of important |
193 | differences between the OpenCL C API and this module: |
223 | differences between the OpenCL C API and this module: |
194 | |
224 | |
195 | =over 4 |
225 | =over 4 |
196 | |
226 | |
197 | =item * Object lifetime managament is automatic - there is no need |
227 | =item * Object lifetime managament is automatic - there is no need |
198 | to free objects explicitly (C<clReleaseXXX>), the release function |
228 | to free objects explicitly (C<clReleaseXXX>), the release function |
199 | is called automatically once all Perl references to it go away. |
229 | is called automatically once all Perl references to it go away. |
200 | |
230 | |
201 | =item * OpenCL uses CamelCase for function names (C<clGetPlatformInfo>), |
231 | =item * OpenCL uses CamelCase for function names |
|
|
232 | (e.g. C<clGetPlatformIDs>, C<clGetPlatformInfo>), while this module |
202 | while this module uses underscores as word separator and often leaves out |
233 | uses underscores as word separator and often leaves out prefixes |
203 | prefixes (C<< $platform->info >>). |
234 | (C<OpenCL::platforms>, C<< $platform->info >>). |
204 | |
235 | |
205 | =item * OpenCL often specifies fixed vector function arguments as short |
236 | =item * OpenCL often specifies fixed vector function arguments as short |
206 | arrays (C<size_t origin[3]>), while this module explicitly expects the |
237 | arrays (C<size_t origin[3]>), while this module explicitly expects the |
207 | components as separate arguments- |
238 | components as separate arguments (C<$orig_x, $orig_y, $orig_z>) in |
|
|
239 | function calls. |
208 | |
240 | |
209 | =item * Where possible, one of the pitch values is calculated from the |
241 | =item * Structures are often specified by flattening out their components |
210 | perl scalar length and need not be specified. |
242 | as with short vectors, and returned as arrayrefs. |
211 | |
243 | |
212 | =item * When enqueuing commands, the wait list is specified by adding |
244 | =item * When enqueuing commands, the wait list is specified by adding |
213 | extra arguments to the function - anywhere a C<$wait_events...> argument |
245 | extra arguments to the function - anywhere a C<$wait_events...> argument |
214 | is documented this can be any number of event objects. |
246 | is documented this can be any number of event objects. |
215 | |
247 | |
… | |
… | |
245 | |
277 | |
246 | =over 4 |
278 | =over 4 |
247 | |
279 | |
248 | =item $int = OpenCL::errno |
280 | =item $int = OpenCL::errno |
249 | |
281 | |
250 | The last error returned by a function - it's only changed on errors. |
282 | The last error returned by a function - it's only valid after an error occured |
|
|
283 | and before calling another OpenCL function. |
251 | |
284 | |
252 | =item $str = OpenCL::err2str $errval |
285 | =item $str = OpenCL::err2str $errval |
253 | |
286 | |
254 | Comverts an error value into a human readable string. |
287 | Comverts an error value into a human readable string. |
255 | |
288 | |
… | |
… | |
265 | |
298 | |
266 | Returns all available OpenCL::Platform objects. |
299 | Returns all available OpenCL::Platform objects. |
267 | |
300 | |
268 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformIDs.html> |
301 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformIDs.html> |
269 | |
302 | |
270 | =item $ctx = OpenCL::context_from_type_simple $type = OpenCL::DEVICE_TYPE_DEFAULT |
303 | =item $ctx = OpenCL::context_from_type $properties, $type = OpenCL::DEVICE_TYPE_DEFAULT, $notify = undef |
271 | |
304 | |
272 | Tries to create a context from a default device and platform - never worked for me. |
305 | Tries to create a context from a default device and platform - never worked for me. |
273 | |
306 | |
274 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html> |
307 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html> |
275 | |
308 | |
… | |
… | |
282 | =back |
315 | =back |
283 | |
316 | |
284 | =head2 THE OpenCL::Platform CLASS |
317 | =head2 THE OpenCL::Platform CLASS |
285 | |
318 | |
286 | =over 4 |
319 | =over 4 |
|
|
320 | |
|
|
321 | =item @devices = $platform->devices ($type = OpenCL::DEVICE_TYPE_ALL) |
|
|
322 | |
|
|
323 | Returns a list of matching OpenCL::Device objects. |
|
|
324 | |
|
|
325 | =item $ctx = $platform->context_from_type ($properties, $type = OpenCL::DEVICE_TYPE_DEFAULT, $notify = undef) |
|
|
326 | |
|
|
327 | Tries to create a context. Never worked for me, and you need devices explitly anyway. |
|
|
328 | |
|
|
329 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html> |
|
|
330 | |
|
|
331 | =item $ctx = $device->context ($properties = undef, @$devices, $notify = undef) |
|
|
332 | |
|
|
333 | Create a new OpenCL::Context object using the given device object(s)- a |
|
|
334 | CL_CONTEXT_PLATFORM property is supplied automatically. |
|
|
335 | |
|
|
336 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html> |
287 | |
337 | |
288 | =item $packed_value = $platform->info ($name) |
338 | =item $packed_value = $platform->info ($name) |
289 | |
339 | |
290 | Calls C<clGetPlatformInfo> and returns the packed, raw value - for |
340 | Calls C<clGetPlatformInfo> and returns the packed, raw value - for |
291 | strings, this will be the string, for other values you probably need to |
341 | strings, this will be the string, for other values you probably need to |
292 | use the correct C<unpack>. This might get improved in the future. Hopefully. |
342 | use the correct C<unpack>. |
|
|
343 | |
|
|
344 | It's best to avoid this method and use one of the predefined C<get_*> |
|
|
345 | methods. |
293 | |
346 | |
294 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformInfo.html> |
347 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformInfo.html> |
295 | |
348 | |
296 | =item @devices = $platform->devices ($type = OpenCL::DEVICE_TYPE_ALL) |
349 | =for gengetinfo begin platform |
297 | |
350 | |
298 | Returns a list of matching OpenCL::Device objects. |
|
|
299 | |
351 | |
300 | =item $ctx = $platform->context_from_type_simple ($type = OpenCL::DEVICE_TYPE_DEFAULT) |
352 | =item $string = $platform->profile |
301 | |
353 | |
302 | Tries to create a context. Never worked for me. |
354 | Calls C<clGetPlatformInfo> with C<CL_PLATFORM_PROFILE> and returns the result(s). |
303 | |
355 | |
304 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html> |
356 | =item $string = $platform->version |
|
|
357 | |
|
|
358 | Calls C<clGetPlatformInfo> with C<CL_PLATFORM_VERSION> and returns the result(s). |
|
|
359 | |
|
|
360 | =item $string = $platform->name |
|
|
361 | |
|
|
362 | Calls C<clGetPlatformInfo> with C<CL_PLATFORM_NAME> and returns the result(s). |
|
|
363 | |
|
|
364 | =item $string = $platform->vendor |
|
|
365 | |
|
|
366 | Calls C<clGetPlatformInfo> with C<CL_PLATFORM_VENDOR> and returns the result(s). |
|
|
367 | |
|
|
368 | =item $string = $platform->extensions |
|
|
369 | |
|
|
370 | Calls C<clGetPlatformInfo> with C<CL_PLATFORM_EXTENSIONS> and returns the result(s). |
|
|
371 | =for gengetinfo end platform |
305 | |
372 | |
306 | =back |
373 | =back |
307 | |
374 | |
308 | =head2 THE OpenCL::Device CLASS |
375 | =head2 THE OpenCL::Device CLASS |
309 | |
376 | |
… | |
… | |
313 | |
380 | |
314 | See C<< $platform->info >> for details. |
381 | See C<< $platform->info >> for details. |
315 | |
382 | |
316 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetDeviceInfo.html> |
383 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetDeviceInfo.html> |
317 | |
384 | |
318 | =item $ctx = $device->context_simple |
|
|
319 | |
|
|
320 | Convenience function to create a new OpenCL::Context object. |
|
|
321 | |
|
|
322 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html> |
|
|
323 | |
|
|
324 | =back |
385 | =back |
325 | |
386 | |
326 | =head2 THE OpenCL::Context CLASS |
387 | =head2 THE OpenCL::Context CLASS |
327 | |
388 | |
328 | =over 4 |
389 | =over 4 |
329 | |
390 | |
330 | =item $packed_value = $ctx->info ($name) |
|
|
331 | |
|
|
332 | See C<< $platform->info >> for details. |
|
|
333 | |
|
|
334 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetContextInfo.html> |
|
|
335 | |
|
|
336 | =item $queue = $ctx->queue ($device, $properties) |
391 | =item $queue = $ctx->queue ($device, $properties) |
337 | |
392 | |
338 | Create a new OpenCL::Queue object from the context and the given device. |
393 | Create a new OpenCL::Queue object from the context and the given device. |
339 | |
394 | |
340 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateCommandQueue.html> |
395 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateCommandQueue.html> |
… | |
… | |
353 | |
408 | |
354 | =item $buf = $ctx->buffer_sv ($flags, $data) |
409 | =item $buf = $ctx->buffer_sv ($flags, $data) |
355 | |
410 | |
356 | Creates a new OpenCL::Buffer object and initialise it with the given data values. |
411 | Creates a new OpenCL::Buffer object and initialise it with the given data values. |
357 | |
412 | |
358 | =item $img = $ctx->image2d ($flags, $channel_order, $channel_type, $width, $height, $data) |
413 | =item $img = $ctx->image2d ($flags, $channel_order, $channel_type, $width, $height, $row_pitch = 0, $data = undef) |
359 | |
414 | |
360 | Creates a new OpenCL::Image2D object and optionally initialises it with the given data values. |
415 | Creates a new OpenCL::Image2D object and optionally initialises it with the given data values. |
361 | |
416 | |
362 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage2D.html> |
417 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage2D.html> |
363 | |
418 | |
364 | =item $img = $ctx->image3d ($flags, $channel_order, $channel_type, $width, $height, $depth, $slice_pitch, $data) |
419 | =item $img = $ctx->image3d ($flags, $channel_order, $channel_type, $width, $height, $depth, $row_pitch = 0, $slice_pitch = 0, $data = undef) |
365 | |
420 | |
366 | Creates a new OpenCL::Image3D object and optionally initialises it with the given data values. |
421 | Creates a new OpenCL::Image3D object and optionally initialises it with the given data values. |
367 | |
422 | |
368 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage3D.html> |
423 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage3D.html> |
369 | |
424 | |
… | |
… | |
383 | =item $program = $ctx->program_with_source ($string) |
438 | =item $program = $ctx->program_with_source ($string) |
384 | |
439 | |
385 | Creates a new OpenCL::Program object from the given source code. |
440 | Creates a new OpenCL::Program object from the given source code. |
386 | |
441 | |
387 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateProgramWithSource.html> |
442 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateProgramWithSource.html> |
|
|
443 | |
|
|
444 | =item $packed_value = $ctx->info ($name) |
|
|
445 | |
|
|
446 | See C<< $platform->info >> for details. |
|
|
447 | |
|
|
448 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetContextInfo.html> |
|
|
449 | |
|
|
450 | =for gengetinfo begin context |
|
|
451 | |
|
|
452 | =for gengetinfo end context |
388 | |
453 | |
389 | =back |
454 | =back |
390 | |
455 | |
391 | =head2 THE OpenCL::Queue CLASS |
456 | =head2 THE OpenCL::Queue CLASS |
392 | |
457 | |
… | |
… | |
432 | |
497 | |
433 | =item $ev = $queue->enqueue_read_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...) |
498 | =item $ev = $queue->enqueue_read_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...) |
434 | |
499 | |
435 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadImage.html> |
500 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadImage.html> |
436 | |
501 | |
437 | =item $ev = $queue->enqueue_write_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $data, $wait_events...) |
502 | =item $ev = $queue->enqueue_write_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...) |
438 | |
503 | |
439 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteImage.html> |
504 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteImage.html> |
440 | |
505 | |
441 | =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...) |
506 | =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, $dst_row_pitch, $dst_slice_pitch, $wait_event...) |
442 | |
507 | |
443 | Yeah. |
508 | Yeah. |
444 | |
509 | |
445 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferRect.html> |
510 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferRect.html> |
446 | |
511 | |
447 | =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, ...) |
512 | =item $ev = $queue->enqueue_copy_buffer_to_image ($src_buffer, $dst_image, $src_offset, $dst_x, $dst_y, $dst_z, $width, $height, $depth, $wait_events...) |
448 | |
513 | |
449 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html>. |
514 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html>. |
450 | |
515 | |
451 | =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, ...) |
516 | =item $ev = $queue->enqueue_copy_image ($src_image, $dst_image, $src_x, $src_y, $src_z, $dst_x, $dst_y, $dst_z, $width, $height, $depth, $wait_events...) |
452 | |
517 | |
453 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImage.html> |
518 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImage.html> |
454 | |
519 | |
455 | =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, ...) |
520 | =item $ev = $queue->enqueue_copy_image_to_buffer ($src_image, $dst_image, $src_x, $src_y, $src_z, $width, $height, $depth, $dst_offset, $wait_events...) |
456 | |
521 | |
457 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImageToBuffer.html> |
522 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImageToBuffer.html> |
458 | |
523 | |
459 | =item $ev = $queue->enqueue_task ($kernel, $wait_events...) |
524 | =item $ev = $queue->enqueue_task ($kernel, $wait_events...) |
460 | |
525 | |
… | |
… | |
514 | |
579 | |
515 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetMemObjectInfo.html> |
580 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetMemObjectInfo.html> |
516 | |
581 | |
517 | =back |
582 | =back |
518 | |
583 | |
|
|
584 | =head2 THE OpenCL::Image CLASS |
|
|
585 | |
|
|
586 | This is the superclass of all image objects - OpenCL::Image2D and OpenCL::Image3D. |
|
|
587 | |
|
|
588 | =over 4 |
|
|
589 | |
|
|
590 | =item $packed_value = $ev->image_info ($name) |
|
|
591 | |
|
|
592 | See C<< $platform->info >> for details. |
|
|
593 | |
|
|
594 | The reason this method is not called C<info> is that there already is an |
|
|
595 | C<< ->info >> method inherited from C<OpenCL::Memory>. |
|
|
596 | |
|
|
597 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetImageInfo.html> |
|
|
598 | |
|
|
599 | =back |
|
|
600 | |
519 | =head2 THE OpenCL::Sampler CLASS |
601 | =head2 THE OpenCL::Sampler CLASS |
520 | |
602 | |
521 | =over 4 |
603 | =over 4 |
522 | |
604 | |
523 | =item $packed_value = $sampler->info ($name) |
605 | =item $packed_value = $sampler->info ($name) |
… | |
… | |
567 | =item $packed_value = $kernel->info ($name) |
649 | =item $packed_value = $kernel->info ($name) |
568 | |
650 | |
569 | See C<< $platform->info >> for details. |
651 | See C<< $platform->info >> for details. |
570 | |
652 | |
571 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetKernelInfo.html> |
653 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetKernelInfo.html> |
|
|
654 | |
|
|
655 | =item $packed_value = $kernel->work_group_info ($device, $name) |
|
|
656 | |
|
|
657 | See C<< $platform->info >> for details. |
|
|
658 | |
|
|
659 | The reason this method is not called C<info> is that there already is an |
|
|
660 | C<< ->info >> method. |
|
|
661 | |
|
|
662 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetKernelWorkGroupInfo.html> |
572 | |
663 | |
573 | =item $kernel->set_TYPE ($index, $value) |
664 | =item $kernel->set_TYPE ($index, $value) |
574 | |
665 | |
575 | This is a family of methods to set the kernel argument with the number C<$index> to the give C<$value>. |
666 | This is a family of methods to set the kernel argument with the number C<$index> to the give C<$value>. |
576 | |
667 | |
… | |
… | |
598 | |
689 | |
599 | See C<< $platform->info >> for details. |
690 | See C<< $platform->info >> for details. |
600 | |
691 | |
601 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetEventInfo.html> |
692 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetEventInfo.html> |
602 | |
693 | |
|
|
694 | =item $packed_value = $ev->profiling_info ($name) |
|
|
695 | |
|
|
696 | See C<< $platform->info >> for details. |
|
|
697 | |
|
|
698 | The reason this method is not called C<info> is that there already is an |
|
|
699 | C<< ->info >> method. |
|
|
700 | |
|
|
701 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetProfilingInfo.html> |
|
|
702 | |
603 | =item $ev->wait |
703 | =item $ev->wait |
604 | |
704 | |
605 | Waits for the event to complete. |
705 | Waits for the event to complete. |
606 | |
706 | |
607 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clWaitForEvents.html> |
707 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clWaitForEvents.html> |
… | |
… | |
625 | package OpenCL; |
725 | package OpenCL; |
626 | |
726 | |
627 | use common::sense; |
727 | use common::sense; |
628 | |
728 | |
629 | BEGIN { |
729 | BEGIN { |
630 | our $VERSION = '0.03'; |
730 | our $VERSION = '0.15'; |
631 | |
731 | |
632 | require XSLoader; |
732 | require XSLoader; |
633 | XSLoader::load (__PACKAGE__, $VERSION); |
733 | XSLoader::load (__PACKAGE__, $VERSION); |
634 | |
734 | |
635 | @OpenCL::Buffer::ISA = |
735 | @OpenCL::Buffer::ISA = |