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

Comparing OpenCL/OpenCL.pm (file contents):
Revision 1.24 by root, Sun Nov 20 22:31:48 2011 UTC vs.
Revision 1.37 by root, Thu Apr 19 14:36:46 2012 UTC

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
151functions. 151functions.
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
278Due to the sad state that OpenGL support is in in Perl (mostly the OpenGL
279module, which has little to no documentation and has little to no support
280for glx), this module, as a special extension, treats context creation
281properties C<OpenCL::GLX_DISPLAY_KHR> and C<OpenCL::GL_CONTEXT_KHR>
282specially: If either or both of these are C<undef>, then the OpenCL
283module tries to dynamically resolve C<glxGetCurrentDisplay> and
284C<glxGetCurrentContext>, call these functions and use their return values
285instead.
286
287For this to work, the OpenGL library must be loaded, a GLX context must
288have been created and be made current, and C<dlsym> must be available and
289capable 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
287Comverts an error value into a human readable string. 302Comverts an error value into a human readable string.
288 303
289=item $str = OpenCL::enum2str $enum 304=item $str = OpenCL::enum2str $enum
290 305
291Converts most enum values (inof parameter names, image format constants, 306Converts most enum values (of parameter names, image format constants,
292object types, addressing and filter modes, command types etc.) into a 307object types, addressing and filter modes, command types etc.) into a
293human readbale string. When confronted with some random integer it can be 308human readable string. When confronted with some random integer it can be
294very helpful to pass it through this function to maybe get some readable 309very helpful to pass it through this function to maybe get some readable
295string out of it. 310string out of it.
296 311
297=item @platforms = OpenCL::platforms 312=item @platforms = OpenCL::platforms
298 313
326 341
327Tries to create a context. Never worked for me, and you need devices explicitly anyway. 342Tries to create a context. Never worked for me, and you need devices explicitly anyway.
328 343
329L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html> 344L<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
333Create a new OpenCL::Context object using the given device object(s)- a 348Create a new OpenCL::Context object using the given device object(s)- a
334CL_CONTEXT_PLATFORM property is supplied automatically. 349CL_CONTEXT_PLATFORM property is supplied automatically.
335 350
336L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html> 351L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html>
668 683
669L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateUserEvent.html> 684L<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
673Creates a new OpenCL::Buffer object with the given flags and octet-size. 688Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object with the
689given flags and octet-size.
674 690
675L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html> 691L<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
679Creates a new OpenCL::Buffer object and initialise it with the given data values. 695Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and
696initialise 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
683Creates a new OpenCL::Image2D object and optionally initialises it with the given data values. 700Creates a new OpenCL::Image2D object and optionally initialises it with
701the given data values.
684 702
685L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage2D.html> 703L<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
689Creates a new OpenCL::Image3D object and optionally initialises it with the given data values. 707Creates a new OpenCL::Image3D object and optionally initialises it with
708the given data values.
690 709
691L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage3D.html> 710L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateImage3D.html>
711
712=item $buffer = $ctx->gl_buffer ($flags, $bufobj)
713
714Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object that refers to the given
715OpenGL buffer object.
716
717http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLBuffer.html
718
719=item $ctx->gl_texture2d ($flags, $target, $miplevel, $texture)
720
721Creates a new OpenCL::Image2D object that refers to the given OpenGL
7222D texture object.
723
724http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLTexture2D.html
725
726=item $ctx->gl_texture3d ($flags, $target, $miplevel, $texture)
727
728Creates a new OpenCL::Image3D object that refers to the given OpenGL
7293D texture object.
730
731http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLTexture3D.html
732
733=item $ctx->gl_renderbuffer ($flags, $renderbuffer)
734
735Creates a new OpenCL::Image2D object that refers to the given OpenGL
736render buffer.
737
738http://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
695Returns a list of matching image formats - each format is an arrayref with 742Returns a list of matching image formats - each format is an arrayref with
696two values, $channel_order and $channel_type, in it. 743two values, $channel_order and $channel_type, in it.
771 818
772=item $ev = $queue->enqueue_copy_buffer ($src, $dst, $src_offset, $dst_offset, $len, $wait_events...) 819=item $ev = $queue->enqueue_copy_buffer ($src, $dst, $src_offset, $dst_offset, $len, $wait_events...)
773 820
774L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBuffer.html> 821L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBuffer.html>
775 822
823=item $ev = $queue->enqueue_read_buffer_rect (OpenCL::Memory buf, cl_bool blocking, $buf_x, $buf_y, $buf_z, $host_x, $host_y, $host_z, $width, $height, $depth, $buf_row_pitch, $buf_slice_pitch, $host_row_pitch, $host_slice_pitch, $data, $wait_events...)
824
825http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBufferRect.html
826
827=item $ev = $queue->enqueue_write_buffer_rect (OpenCL::Memory buf, cl_bool blocking, $buf_x, $buf_y, $buf_z, $host_x, $host_y, $host_z, $width, $height, $depth, $buf_row_pitch, $buf_slice_pitch, $host_row_pitch, $host_slice_pitch, $data, $wait_events...)
828
829http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html
830
776=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...)
777 832
833L<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
778L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadImage.html> 837L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadImage.html>
779 838
780=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...)
781 840
782L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteImage.html> 841L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteImage.html>
783 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
845L<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
849L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImageToBuffer.html>
850
784=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...)
785 852
786Yeah. 853Yeah.
787 854
788L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferRect.html>
789
790=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...)
791
792L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html>. 855L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBufferToImage.html>.
793
794=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...)
795
796L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImage.html>
797
798=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...)
799
800L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyImageToBuffer.html>
801 856
802=item $ev = $queue->enqueue_task ($kernel, $wait_events...) 857=item $ev = $queue->enqueue_task ($kernel, $wait_events...)
803 858
804L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueTask.html> 859L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueTask.html>
805 860
819reference to an array of local work sizes, with the same number of 874reference to an array of local work sizes, with the same number of
820elements as @$global_work_size. 875elements as @$global_work_size.
821 876
822L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueNDRangeKernel.html> 877L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueNDRangeKernel.html>
823 878
824=item $ev = $queue->enqueue_marker 879=item $ev = $queue->enqueue_marker ($wait_events...)
825 880
826L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueMarker.html> 881L<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
885Enqueues a list (an array-ref of OpenCL::Memory objects) to be acquired
886for subsequent OpenCL usage.
887
888L<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
892Enqueues a list (an array-ref of OpenCL::Memory objects) to be released
893for subsequent OpenGL usage.
894
895L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReleaseGLObjects.html>
827 896
828=item $ev = $queue->enqueue_wait_for_events ($wait_events...) 897=item $ev = $queue->enqueue_wait_for_events ($wait_events...)
829 898
830L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWaitForEvents.html> 899L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWaitForEvents.html>
831 900
920 989
921Calls C<clGetMemObjectInfo> with C<CL_MEM_OFFSET> and returns the result. 990Calls C<clGetMemObjectInfo> with C<CL_MEM_OFFSET> and returns the result.
922 991
923=for gengetinfo end mem 992=for gengetinfo end mem
924 993
994=item ($type, $name) = $mem->gl_object_info
995
996Returns the OpenGL object type (e.g. OpenCL::GL_OBJECT_TEXTURE2D) and the
997object "name" (e.g. the texture name) used to create this memory object.
998
999L<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
1005This is a subclass of OpenCL::Memory, and the superclass of
1006OpenCL::BufferObj. Its purpose is simply to distinguish between buffers
1007and sub-buffers.
1008
1009=head2 THE OpenCL::BufferObj CLASS
1010
1011This is a subclass of OpenCL::Buffer and thus OpenCL::Memory. It exists
1012because one cna create sub buffers of OpenLC::BufferObj objects, but not
1013sub buffers from these sub buffers.
1014
1015=over 4
1016
1017=item $subbuf = $buf_obj->sub_buffer_region ($flags, $origin, $size)
1018
1019Creates an OpenCL::Buffer objects from this buffer and returns it. The
1020C<buffer_create_type> is assumed to be C<CL_BUFFER_CREATE_TYPE_REGION>.
1021
1022L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateSubBuffer.html>
1023
925=back 1024=back
926 1025
927=head2 THE OpenCL::Image CLASS 1026=head2 THE OpenCL::Image CLASS
928 1027
929This is the superclass of all image objects - OpenCL::Image2D and OpenCL::Image3D. 1028This is the superclass of all image objects - OpenCL::Image2D and OpenCL::Image3D.
964=item $int = $image->depth 1063=item $int = $image->depth
965 1064
966Calls C<clGetImageInfo> with C<CL_IMAGE_DEPTH> and returns the result. 1065Calls C<clGetImageInfo> with C<CL_IMAGE_DEPTH> and returns the result.
967 1066
968=for gengetinfo end image 1067=for gengetinfo end image
1068
1069=for gengetinfo begin gl_texture
1070
1071=item $GLenum = $gl_texture->target
1072
1073Calls C<clGetGLTextureInfo> with C<CL_GL_TEXTURE_TARGET> and returns the result.
1074
1075=item $GLint = $gl_texture->gl_mipmap_level
1076
1077Calls C<clGetGLTextureInfo> with C<CL_GL_MIPMAP_LEVEL> and returns the result.
1078
1079=for gengetinfo end gl_texture
969 1080
970=back 1081=back
971 1082
972=head2 THE OpenCL::Sampler CLASS 1083=head2 THE OpenCL::Sampler CLASS
973 1084
1267package OpenCL; 1378package OpenCL;
1268 1379
1269use common::sense; 1380use common::sense;
1270 1381
1271BEGIN { 1382BEGIN {
1272 our $VERSION = '0.55'; 1383 our $VERSION = '0.92';
1273 1384
1274 require XSLoader; 1385 require XSLoader;
1275 XSLoader::load (__PACKAGE__, $VERSION); 1386 XSLoader::load (__PACKAGE__, $VERSION);
1276 1387
1277 @OpenCL::Buffer::ISA = 1388 @OpenCL::Buffer::ISA =
1278 @OpenCL::Image::ISA = OpenCL::Memory::; 1389 @OpenCL::Image::ISA = OpenCL::Memory::;
1279 1390
1391 @OpenCL::BufferObj::ISA = OpenCL::Buffer::;
1392
1280 @OpenCL::Image2D::ISA = 1393 @OpenCL::Image2D::ISA =
1281 @OpenCL::Image3D::ISA = OpenCL::Image::; 1394 @OpenCL::Image3D::ISA = OpenCL::Image::;
1282 1395
1283 @OpenCL::UserEvent::ISA = OpenCL::Event::; 1396 @OpenCL::UserEvent::ISA = OpenCL::Event::;
1284} 1397}
1285 1398
12861; 13991;
1287 1400
1288=head1 AUTHOR 1401=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines