… | |
… | |
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> |
… | |
… | |
668 | |
683 | |
669 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateUserEvent.html> |
684 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateUserEvent.html> |
670 | |
685 | |
671 | =item $buf = $ctx->buffer ($flags, $len) |
686 | =item $buf = $ctx->buffer ($flags, $len) |
672 | |
687 | |
673 | Creates a new OpenCL::Buffer object with the given flags and octet-size. |
688 | Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object with the |
|
|
689 | given flags and octet-size. |
674 | |
690 | |
675 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html> |
691 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html> |
676 | |
692 | |
677 | =item $buf = $ctx->buffer_sv ($flags, $data) |
693 | =item $buf = $ctx->buffer_sv ($flags, $data) |
678 | |
694 | |
679 | Creates a new OpenCL::Buffer object and initialise it with the given data values. |
695 | Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and |
|
|
696 | initialise it with the given data values. |
680 | |
697 | |
681 | =item $img = $ctx->image2d ($flags, $channel_order, $channel_type, $width, $height, $row_pitch = 0, $data = undef) |
698 | =item $img = $ctx->image2d ($flags, $channel_order, $channel_type, $width, $height, $row_pitch = 0, $data = undef) |
682 | |
699 | |
683 | Creates a new OpenCL::Image2D object and optionally initialises it with the given data values. |
700 | Creates a new OpenCL::Image2D object and optionally initialises it with |
|
|
701 | the given data values. |
684 | |
702 | |
685 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage2D.html> |
703 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage2D.html> |
686 | |
704 | |
687 | =item $img = $ctx->image3d ($flags, $channel_order, $channel_type, $width, $height, $depth, $row_pitch = 0, $slice_pitch = 0, $data = undef) |
705 | =item $img = $ctx->image3d ($flags, $channel_order, $channel_type, $width, $height, $depth, $row_pitch = 0, $slice_pitch = 0, $data = undef) |
688 | |
706 | |
689 | Creates a new OpenCL::Image3D object and optionally initialises it with the given data values. |
707 | Creates a new OpenCL::Image3D object and optionally initialises it with |
|
|
708 | the given data values. |
690 | |
709 | |
691 | 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 |
692 | |
739 | |
693 | =item @formats = $ctx->supported_image_formats ($flags, $image_type) |
740 | =item @formats = $ctx->supported_image_formats ($flags, $image_type) |
694 | |
741 | |
695 | 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 |
696 | two values, $channel_order and $channel_type, in it. |
743 | two values, $channel_order and $channel_type, in it. |
… | |
… | |
781 | |
828 | |
782 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html |
829 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html |
783 | |
830 | |
784 | =item $ev = $queue->enqueue_read_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...) |
831 | =item $ev = $queue->enqueue_read_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...) |
785 | |
832 | |
|
|
833 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferRect.html> |
|
|
834 | |
|
|
835 | =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...) |
|
|
836 | |
786 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadImage.html> |
837 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadImage.html> |
787 | |
838 | |
788 | =item $ev = $queue->enqueue_write_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...) |
839 | =item $ev = $queue->enqueue_write_image ($src, $blocking, $x, $y, $z, $width, $height, $depth, $row_pitch, $slice_pitch, $data, $wait_events...) |
789 | |
840 | |
790 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteImage.html> |
841 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteImage.html> |
791 | |
842 | |
|
|
843 | =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...) |
|
|
844 | |
|
|
845 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImage.html> |
|
|
846 | |
|
|
847 | =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...) |
|
|
848 | |
|
|
849 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImageToBuffer.html> |
|
|
850 | |
792 | =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...) |
851 | =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...) |
793 | |
852 | |
794 | Yeah. |
853 | Yeah. |
795 | |
854 | |
796 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferRect.html> |
|
|
797 | |
|
|
798 | =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...) |
|
|
799 | |
|
|
800 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html>. |
855 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html>. |
801 | |
|
|
802 | =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...) |
|
|
803 | |
|
|
804 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImage.html> |
|
|
805 | |
|
|
806 | =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...) |
|
|
807 | |
|
|
808 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImageToBuffer.html> |
|
|
809 | |
856 | |
810 | =item $ev = $queue->enqueue_task ($kernel, $wait_events...) |
857 | =item $ev = $queue->enqueue_task ($kernel, $wait_events...) |
811 | |
858 | |
812 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueTask.html> |
859 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueTask.html> |
813 | |
860 | |
… | |
… | |
827 | 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 |
828 | elements as @$global_work_size. |
875 | elements as @$global_work_size. |
829 | |
876 | |
830 | 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> |
831 | |
878 | |
832 | =item $ev = $queue->enqueue_marker |
879 | =item $ev = $queue->enqueue_marker ($wait_events...) |
833 | |
880 | |
834 | 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> |
835 | |
896 | |
836 | =item $ev = $queue->enqueue_wait_for_events ($wait_events...) |
897 | =item $ev = $queue->enqueue_wait_for_events ($wait_events...) |
837 | |
898 | |
838 | 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> |
839 | |
900 | |
… | |
… | |
928 | |
989 | |
929 | 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. |
930 | |
991 | |
931 | =for gengetinfo end mem |
992 | =for gengetinfo end mem |
932 | |
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> |
|
|
1000 | |
|
|
1001 | =back |
|
|
1002 | |
|
|
1003 | =head2 THE OpenCL::Buffer CLASS |
|
|
1004 | |
|
|
1005 | This is a subclass of OpenCL::Memory, and the superclass of |
|
|
1006 | OpenCL::BufferObj. Its purpose is simply to distinguish between buffers |
|
|
1007 | and sub-buffers. |
|
|
1008 | |
|
|
1009 | =head2 THE OpenCL::BufferObj CLASS |
|
|
1010 | |
|
|
1011 | This is a subclass of OpenCL::Buffer and thus OpenCL::Memory. It exists |
|
|
1012 | because one cna create sub buffers of OpenLC::BufferObj objects, but not |
|
|
1013 | sub buffers from these sub buffers. |
|
|
1014 | |
|
|
1015 | =over 4 |
|
|
1016 | |
|
|
1017 | =item $subbuf = $buf_obj->sub_buffer_region ($flags, $origin, $size) |
|
|
1018 | |
|
|
1019 | Creates an OpenCL::Buffer objects from this buffer and returns it. The |
|
|
1020 | C<buffer_create_type> is assumed to be C<CL_BUFFER_CREATE_TYPE_REGION>. |
|
|
1021 | |
|
|
1022 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateSubBuffer.html> |
|
|
1023 | |
933 | =back |
1024 | =back |
934 | |
1025 | |
935 | =head2 THE OpenCL::Image CLASS |
1026 | =head2 THE OpenCL::Image CLASS |
936 | |
1027 | |
937 | This is the superclass of all image objects - OpenCL::Image2D and OpenCL::Image3D. |
1028 | This is the superclass of all image objects - OpenCL::Image2D and OpenCL::Image3D. |
… | |
… | |
972 | =item $int = $image->depth |
1063 | =item $int = $image->depth |
973 | |
1064 | |
974 | 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. |
975 | |
1066 | |
976 | =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 |
977 | |
1080 | |
978 | =back |
1081 | =back |
979 | |
1082 | |
980 | =head2 THE OpenCL::Sampler CLASS |
1083 | =head2 THE OpenCL::Sampler CLASS |
981 | |
1084 | |
… | |
… | |
1275 | package OpenCL; |
1378 | package OpenCL; |
1276 | |
1379 | |
1277 | use common::sense; |
1380 | use common::sense; |
1278 | |
1381 | |
1279 | BEGIN { |
1382 | BEGIN { |
1280 | our $VERSION = '0.59'; |
1383 | our $VERSION = '0.92'; |
1281 | |
1384 | |
1282 | require XSLoader; |
1385 | require XSLoader; |
1283 | XSLoader::load (__PACKAGE__, $VERSION); |
1386 | XSLoader::load (__PACKAGE__, $VERSION); |
1284 | |
1387 | |
1285 | @OpenCL::Buffer::ISA = |
1388 | @OpenCL::Buffer::ISA = |
1286 | @OpenCL::Image::ISA = OpenCL::Memory::; |
1389 | @OpenCL::Image::ISA = OpenCL::Memory::; |
1287 | |
1390 | |
|
|
1391 | @OpenCL::BufferObj::ISA = OpenCL::Buffer::; |
|
|
1392 | |
1288 | @OpenCL::Image2D::ISA = |
1393 | @OpenCL::Image2D::ISA = |
1289 | @OpenCL::Image3D::ISA = OpenCL::Image::; |
1394 | @OpenCL::Image3D::ISA = OpenCL::Image::; |
1290 | |
1395 | |
1291 | @OpenCL::UserEvent::ISA = OpenCL::Event::; |
1396 | @OpenCL::UserEvent::ISA = OpenCL::Event::; |
1292 | } |
1397 | } |
1293 | |
1398 | |
1294 | 1; |
1399 | 1; |
1295 | |
1400 | |
1296 | =head1 AUTHOR |
1401 | =head1 AUTHOR |