… | |
… | |
105 | for my $platform (OpenCL::platforms) { |
105 | for my $platform (OpenCL::platforms) { |
106 | printf "platform: %s\n", $platform->name; |
106 | printf "platform: %s\n", $platform->name; |
107 | printf "extensions: %s\n", $platform->extensions; |
107 | printf "extensions: %s\n", $platform->extensions; |
108 | for my $device ($platform->devices) { |
108 | for my $device ($platform->devices) { |
109 | printf "+ device: %s\n", $device->name; |
109 | printf "+ device: %s\n", $device->name; |
110 | my $ctx = $device->context; |
110 | my $ctx = $platform->context (undef, [$device]); |
111 | # do stuff |
111 | # do stuff |
112 | } |
112 | } |
113 | } |
113 | } |
114 | |
114 | |
115 | =head2 Get a useful context and a command queue. |
115 | =head2 Get a useful context and a command queue. |
… | |
… | |
149 | |
149 | |
150 | =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 |
151 | functions. |
151 | functions. |
152 | |
152 | |
153 | my $src = ' |
153 | my $src = ' |
154 | __kernel void |
154 | kernel void |
155 | squareit (__global float *input, __global float *output) |
155 | squareit (global float *input, global float *output) |
156 | { |
156 | { |
157 | $id = get_global_id (0); |
157 | $id = get_global_id (0); |
158 | output [id] = input [id] * input [id]; |
158 | output [id] = input [id] * input [id]; |
159 | } |
159 | } |
160 | '; |
160 | '; |
… | |
… | |
271 | ulong IV - Q |
271 | ulong IV - Q |
272 | float NV float f |
272 | float NV float f |
273 | half IV ushort S |
273 | half IV ushort S |
274 | double NV double d |
274 | double NV double d |
275 | |
275 | |
|
|
276 | =head2 GLX SUPPORT |
|
|
277 | |
|
|
278 | Due to the sad state that OpenGL support is in in Perl (mostly the OpenGL |
|
|
279 | module, which has little to no documentation and has little to no support |
|
|
280 | for glx), this module, as a special extension, treats context creation |
|
|
281 | properties C<OpenCL::GLX_DISPLAY_KHR> and C<OpenCL::GL_CONTEXT_KHR> |
|
|
282 | specially: If either or both of these are C<undef>, then the OpenCL |
|
|
283 | module tries to dynamically resolve C<glxGetCurrentDisplay> and |
|
|
284 | C<glxGetCurrentContext>, call these functions and use their return values |
|
|
285 | instead. |
|
|
286 | |
|
|
287 | For this to work, the OpenGL library must be loaded, a GLX context must |
|
|
288 | have been created and be made current, and C<dlsym> must be available and |
|
|
289 | capable of finding the function via C<RTLD_DEFAULT>. |
|
|
290 | |
276 | =head2 THE OpenCL PACKAGE |
291 | =head2 THE OpenCL PACKAGE |
277 | |
292 | |
278 | =over 4 |
293 | =over 4 |
279 | |
294 | |
280 | =item $int = OpenCL::errno |
295 | =item $int = OpenCL::errno |
… | |
… | |
286 | |
301 | |
287 | Comverts an error value into a human readable string. |
302 | Comverts an error value into a human readable string. |
288 | |
303 | |
289 | =item $str = OpenCL::enum2str $enum |
304 | =item $str = OpenCL::enum2str $enum |
290 | |
305 | |
291 | Converts most enum values (inof parameter names, image format constants, |
306 | Converts most enum values (of parameter names, image format constants, |
292 | object types, addressing and filter modes, command types etc.) into a |
307 | object types, addressing and filter modes, command types etc.) into a |
293 | human readbale string. When confronted with some random integer it can be |
308 | human readable string. When confronted with some random integer it can be |
294 | very helpful to pass it through this function to maybe get some readable |
309 | very helpful to pass it through this function to maybe get some readable |
295 | string out of it. |
310 | string out of it. |
296 | |
311 | |
297 | =item @platforms = OpenCL::platforms |
312 | =item @platforms = OpenCL::platforms |
298 | |
313 | |
… | |
… | |
326 | |
341 | |
327 | Tries to create a context. Never worked for me, and you need devices explicitly anyway. |
342 | Tries to create a context. Never worked for me, and you need devices explicitly anyway. |
328 | |
343 | |
329 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html> |
344 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html> |
330 | |
345 | |
331 | =item $ctx = $device->context ($properties = undef, @$devices, $notify = undef) |
346 | =item $ctx = $platform->context ($properties = undef, @$devices, $notify = undef) |
332 | |
347 | |
333 | Create a new OpenCL::Context object using the given device object(s)- a |
348 | Create a new OpenCL::Context object using the given device object(s)- a |
334 | CL_CONTEXT_PLATFORM property is supplied automatically. |
349 | CL_CONTEXT_PLATFORM property is supplied automatically. |
335 | |
350 | |
336 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html> |
351 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html> |
… | |
… | |
691 | |
706 | |
692 | Creates a new OpenCL::Image3D object and optionally initialises it with |
707 | Creates a new OpenCL::Image3D object and optionally initialises it with |
693 | the given data values. |
708 | the given data values. |
694 | |
709 | |
695 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage3D.html> |
710 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage3D.html> |
|
|
711 | |
|
|
712 | =item $buffer = $ctx->gl_buffer ($flags, $bufobj) |
|
|
713 | |
|
|
714 | Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object that refers to the given |
|
|
715 | OpenGL buffer object. |
|
|
716 | |
|
|
717 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLBuffer.html |
|
|
718 | |
|
|
719 | =item $ctx->gl_texture2d ($flags, $target, $miplevel, $texture) |
|
|
720 | |
|
|
721 | Creates a new OpenCL::Image2D object that refers to the given OpenGL |
|
|
722 | 2D texture object. |
|
|
723 | |
|
|
724 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLTexture2D.html |
|
|
725 | |
|
|
726 | =item $ctx->gl_texture3d ($flags, $target, $miplevel, $texture) |
|
|
727 | |
|
|
728 | Creates a new OpenCL::Image3D object that refers to the given OpenGL |
|
|
729 | 3D texture object. |
|
|
730 | |
|
|
731 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLTexture3D.html |
|
|
732 | |
|
|
733 | =item $ctx->gl_renderbuffer ($flags, $renderbuffer) |
|
|
734 | |
|
|
735 | Creates a new OpenCL::Image2D object that refers to the given OpenGL |
|
|
736 | render buffer. |
|
|
737 | |
|
|
738 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLRenderbuffer.html |
696 | |
739 | |
697 | =item @formats = $ctx->supported_image_formats ($flags, $image_type) |
740 | =item @formats = $ctx->supported_image_formats ($flags, $image_type) |
698 | |
741 | |
699 | Returns a list of matching image formats - each format is an arrayref with |
742 | Returns a list of matching image formats - each format is an arrayref with |
700 | two values, $channel_order and $channel_type, in it. |
743 | two values, $channel_order and $channel_type, in it. |
… | |
… | |
831 | reference to an array of local work sizes, with the same number of |
874 | reference to an array of local work sizes, with the same number of |
832 | elements as @$global_work_size. |
875 | elements as @$global_work_size. |
833 | |
876 | |
834 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueNDRangeKernel.html> |
877 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueNDRangeKernel.html> |
835 | |
878 | |
836 | =item $ev = $queue->enqueue_marker |
879 | =item $ev = $queue->enqueue_marker ($wait_events...) |
837 | |
880 | |
838 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueMarker.html> |
881 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueMarker.html> |
|
|
882 | |
|
|
883 | =item $ev = $queue->enqueue_acquire_gl_objects ([object, ...], $wait_events...) |
|
|
884 | |
|
|
885 | Enqueues a list (an array-ref of OpenCL::Memory objects) to be acquired |
|
|
886 | for subsequent OpenCL usage. |
|
|
887 | |
|
|
888 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueAcquireGLObjects.html> |
|
|
889 | |
|
|
890 | =item $ev = $queue->enqueue_release_gl_objects ([object, ...], $wait_events...) |
|
|
891 | |
|
|
892 | Enqueues a list (an array-ref of OpenCL::Memory objects) to be released |
|
|
893 | for subsequent OpenGL usage. |
|
|
894 | |
|
|
895 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReleaseGLObjects.html> |
839 | |
896 | |
840 | =item $ev = $queue->enqueue_wait_for_events ($wait_events...) |
897 | =item $ev = $queue->enqueue_wait_for_events ($wait_events...) |
841 | |
898 | |
842 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWaitForEvents.html> |
899 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWaitForEvents.html> |
843 | |
900 | |
… | |
… | |
931 | =item $int = $mem->offset |
988 | =item $int = $mem->offset |
932 | |
989 | |
933 | Calls C<clGetMemObjectInfo> with C<CL_MEM_OFFSET> and returns the result. |
990 | Calls C<clGetMemObjectInfo> with C<CL_MEM_OFFSET> and returns the result. |
934 | |
991 | |
935 | =for gengetinfo end mem |
992 | =for gengetinfo end mem |
|
|
993 | |
|
|
994 | =item ($type, $name) = $mem->gl_object_info |
|
|
995 | |
|
|
996 | Returns the OpenGL object type (e.g. OpenCL::GL_OBJECT_TEXTURE2D) and the |
|
|
997 | object "name" (e.g. the texture name) used to create this memory object. |
|
|
998 | |
|
|
999 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetGLObjectInfo.html> |
936 | |
1000 | |
937 | =back |
1001 | =back |
938 | |
1002 | |
939 | =head2 THE OpenCL::Buffer CLASS |
1003 | =head2 THE OpenCL::Buffer CLASS |
940 | |
1004 | |
… | |
… | |
999 | =item $int = $image->depth |
1063 | =item $int = $image->depth |
1000 | |
1064 | |
1001 | Calls C<clGetImageInfo> with C<CL_IMAGE_DEPTH> and returns the result. |
1065 | Calls C<clGetImageInfo> with C<CL_IMAGE_DEPTH> and returns the result. |
1002 | |
1066 | |
1003 | =for gengetinfo end image |
1067 | =for gengetinfo end image |
|
|
1068 | |
|
|
1069 | =for gengetinfo begin gl_texture |
|
|
1070 | |
|
|
1071 | =item $GLenum = $gl_texture->target |
|
|
1072 | |
|
|
1073 | Calls C<clGetGLTextureInfo> with C<CL_GL_TEXTURE_TARGET> and returns the result. |
|
|
1074 | |
|
|
1075 | =item $GLint = $gl_texture->gl_mipmap_level |
|
|
1076 | |
|
|
1077 | Calls C<clGetGLTextureInfo> with C<CL_GL_MIPMAP_LEVEL> and returns the result. |
|
|
1078 | |
|
|
1079 | =for gengetinfo end gl_texture |
1004 | |
1080 | |
1005 | =back |
1081 | =back |
1006 | |
1082 | |
1007 | =head2 THE OpenCL::Sampler CLASS |
1083 | =head2 THE OpenCL::Sampler CLASS |
1008 | |
1084 | |
… | |
… | |
1302 | package OpenCL; |
1378 | package OpenCL; |
1303 | |
1379 | |
1304 | use common::sense; |
1380 | use common::sense; |
1305 | |
1381 | |
1306 | BEGIN { |
1382 | BEGIN { |
1307 | our $VERSION = '0.91'; |
1383 | our $VERSION = '0.92'; |
1308 | |
1384 | |
1309 | require XSLoader; |
1385 | require XSLoader; |
1310 | XSLoader::load (__PACKAGE__, $VERSION); |
1386 | XSLoader::load (__PACKAGE__, $VERSION); |
1311 | |
1387 | |
1312 | @OpenCL::Buffer::ISA = |
1388 | @OpenCL::Buffer::ISA = |