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

Comparing OpenCL/OpenCL.pm (file contents):
Revision 1.46 by root, Sat Apr 21 19:17:09 2012 UTC vs.
Revision 1.51 by root, Tue Apr 24 13:45:58 2012 UTC

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 ';
161 161
162 my $prog = $ctx->program_with_source ($src); 162 my $prog = $ctx->build_program ($src);
163
164 # build croaks on compile errors, so catch it and print the compile errors
165 eval { $prog->build ($dev, "-cl-fast-relaxed-math"); 1 }
166 or die $prog->build_log;
167
168 my $kernel = $prog->kernel ("squareit"); 163 my $kernel = $prog->kernel ("squareit");
169 164
170=head2 Create some input and output float buffers, then call the 165=head2 Create some input and output float buffers, then call the
171'squareit' kernel on them. 166'squareit' kernel on them.
172 167
267 262
268 float3 colour = (float3)(z.x, z.y, z.x * z.y); 263 float3 colour = (float3)(z.x, z.y, z.x * z.y);
269 write_imagef (img, (int2)(get_global_id (0), get_global_id (1)), (float4)(colour * p.x * p.x, 1.)); 264 write_imagef (img, (int2)(get_global_id (0), get_global_id (1)), (float4)(colour * p.x * p.x, 1.));
270 } 265 }
271 EOF 266 EOF
267
272 my $prog = $ctx->program_with_source ($src); 268 my $prog = $ctx->build_program ($src);
273 eval { $prog->build ($dev); 1 }
274 or die $prog->build_log ($dev);
275
276 my $kernel = $prog->kernel ("juliatunnel"); 269 my $kernel = $prog->kernel ("juliatunnel");
277 270
278 # program compiled, kernel ready, now draw and loop 271 # program compiled, kernel ready, now draw and loop
279 272
280 for (my $time; ; ++$time) { 273 for (my $time; ; ++$time) {
456It's best to avoid this method and use one of the following convenience 449It's best to avoid this method and use one of the following convenience
457wrappers. 450wrappers.
458 451
459L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformInfo.html> 452L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformInfo.html>
460 453
454=item $platform->unload_compiler
455
456Attempts to unload the compiler for this platform, for endless
457profit. Does nothing on OpenCL 1.1.
458
459L<http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clUnloadPlatformCompiler.html>
460
461=for gengetinfo begin platform 461=for gengetinfo begin platform
462 462
463=item $string = $platform->profile 463=item $string = $platform->profile
464 464
465Calls C<clGetPlatformInfo> with C<CL_PLATFORM_PROFILE> and returns the result. 465Calls C<clGetPlatformInfo> with C<CL_PLATFORM_PROFILE> and returns the result.
752 752
753Calls C<clGetDeviceInfo> with C<CL_DEVICE_AFFINITY_DOMAINS_EXT> and returns the result. 753Calls C<clGetDeviceInfo> with C<CL_DEVICE_AFFINITY_DOMAINS_EXT> and returns the result.
754 754
755=item $uint = $device->reference_count_ext 755=item $uint = $device->reference_count_ext
756 756
757Calls C<clGetDeviceInfo> with C<CL_DEVICE_REFERENCE_COUNT_EXT > and returns the result. 757Calls C<clGetDeviceInfo> with C<CL_DEVICE_REFERENCE_COUNT_EXT> and returns the result.
758 758
759=item @device_partition_property_exts = $device->partition_style_ext 759=item @device_partition_property_exts = $device->partition_style_ext
760 760
761Calls C<clGetDeviceInfo> with C<CL_DEVICE_PARTITION_STYLE_EXT> and returns the result. 761Calls C<clGetDeviceInfo> with C<CL_DEVICE_PARTITION_STYLE_EXT> and returns the result.
762 762
765=back 765=back
766 766
767=head2 THE OpenCL::Context CLASS 767=head2 THE OpenCL::Context CLASS
768 768
769=over 4 769=over 4
770
771=item $prog = $ctx->build_program ($program, $options = "")
772
773This convenience function tries to build the program on all devices in
774the context. If the build fails, then the function will C<croak> with the
775build log. Otherwise ti returns the program object.
776
777The C<$program> can either be a C<OpenCL::Program> object or a string
778containing the program. In the latter case, a program objetc will be
779created automatically.
780
781=cut
782
783sub OpenCL::Context::build_program {
784 my ($self, $prog, $options) = @_;
785
786 $prog = $self->program_with_source ($prog)
787 unless ref $prog;
788
789 for my $dev ($self->devices) {
790 eval { $prog->build ($dev, $options); 1 }
791 or Carp::croak "Building OpenCL program for device '" . $dev->name . "' failed:\n"
792 . $prog->build_log ($dev);
793 }
794
795 $prog
796}
770 797
771=item $queue = $ctx->queue ($device, $properties) 798=item $queue = $ctx->queue ($device, $properties)
772 799
773Create a new OpenCL::Queue object from the context and the given device. 800Create a new OpenCL::Queue object from the context and the given device.
774 801
794=item $buf = $ctx->buffer_sv ($flags, $data) 821=item $buf = $ctx->buffer_sv ($flags, $data)
795 822
796Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and 823Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and
797initialise it with the given data values. 824initialise it with the given data values.
798 825
826=item $img = $ctx->image ($self, $flags, $channel_order, $channel_type, $type, $width, $height, $depth, $array_size = 0, $row_pitch = 0, $slice_pitch = 0, $num_mip_level = 0, $num_samples = 0, $*data = &PL_sv_undef)
827
828Creates a new OpenCL::Image object and optionally initialises it with
829the given data values.
830
831L<http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateImage.html>
832
799=item $img = $ctx->image2d ($flags, $channel_order, $channel_type, $width, $height, $row_pitch = 0, $data = undef) 833=item $img = $ctx->image2d ($flags, $channel_order, $channel_type, $width, $height, $row_pitch = 0, $data = undef)
800 834
801Creates a new OpenCL::Image2D object and optionally initialises it with 835Creates a new OpenCL::Image2D object and optionally initialises it with
802the given data values. 836the given data values.
803 837
815Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object that refers to the given 849Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object that refers to the given
816OpenGL buffer object. 850OpenGL buffer object.
817 851
818http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLBuffer.html 852http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLBuffer.html
819 853
854=item $img = $ctx->gl_texture ($flags, $target, $miplevel, $texture)
855
856Creates a new OpenCL::Image object that refers to the given OpenGL
857texture object or buffer.
858
859http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateFromGLTexture.html
860
820=item $ctx->gl_texture2d ($flags, $target, $miplevel, $texture) 861=item $img = $ctx->gl_texture2d ($flags, $target, $miplevel, $texture)
821 862
822Creates a new OpenCL::Image2D object that refers to the given OpenGL 863Creates a new OpenCL::Image2D object that refers to the given OpenGL
8232D texture object. 8642D texture object.
824 865
825http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLTexture2D.html 866http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLTexture2D.html
826 867
827=item $ctx->gl_texture3d ($flags, $target, $miplevel, $texture) 868=item $img = $ctx->gl_texture3d ($flags, $target, $miplevel, $texture)
828 869
829Creates a new OpenCL::Image3D object that refers to the given OpenGL 870Creates a new OpenCL::Image3D object that refers to the given OpenGL
8303D texture object. 8713D texture object.
831 872
832http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLTexture3D.html 873http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLTexture3D.html
1130 1171
1131=back 1172=back
1132 1173
1133=head2 THE OpenCL::Image CLASS 1174=head2 THE OpenCL::Image CLASS
1134 1175
1135This is the superclass of all image objects - OpenCL::Image2D and OpenCL::Image3D. 1176This is the superclass of all image objects - OpenCL::Image1D,
1177OpenCL::Image1DArray, OpenCL::Image1DBuffer, OpenCL::Image2D,
1178OpenCL::Image2DArray and OpenCL::Image3D.
1136 1179
1137=over 4 1180=over 4
1138 1181
1139=item $packed_value = $ev->image_info ($name) 1182=item $packed_value = $ev->image_info ($name)
1140 1183
1227 1270
1228=over 4 1271=over 4
1229 1272
1230=item $program->build ($device, $options = "") 1273=item $program->build ($device, $options = "")
1231 1274
1232Tries to build the program with the givne options. 1275Tries to build the program with the given options. See also the
1276C<$ctx->build> convenience function.
1233 1277
1234L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clBuildProgram.html> 1278L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clBuildProgram.html>
1235 1279
1236=item $packed_value = $program->build_info ($device, $name) 1280=item $packed_value = $program->build_info ($device, $name)
1237 1281
1244 1288
1245Creates an OpenCL::Kernel object out of the named C<__kernel> function in 1289Creates an OpenCL::Kernel object out of the named C<__kernel> function in
1246the program. 1290the program.
1247 1291
1248L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateKernel.html> 1292L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateKernel.html>
1293
1294=item @kernels = $program->kernels_in_program
1295
1296Returns all kernels successfully compiled for all devices in program.
1297
1298http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateKernelsInProgram.html
1249 1299
1250=for gengetinfo begin program_build 1300=for gengetinfo begin program_build
1251 1301
1252=item $build_status = $program->build_status ($device) 1302=item $build_status = $program->build_status ($device)
1253 1303
1389float and double as floating point values, memory/buffer/image2d/image3d 1439float and double as floating point values, memory/buffer/image2d/image3d
1390must be an object of that type or C<undef>, local-memory arguments are 1440must be an object of that type or C<undef>, local-memory arguments are
1391set by specifying the size, and sampler and event must be objects of that 1441set by specifying the size, and sampler and event must be objects of that
1392type. 1442type.
1393 1443
1444Setting an argument for a kernel does NOT keep a reference to the object -
1445for example, if you set an argument to some image object, free the image,
1446and call the kernel, you will run into undefined behaviour.
1447
1394L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clSetKernelArg.html> 1448L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clSetKernelArg.html>
1395 1449
1396=back 1450=back
1397 1451
1398=head2 THE OpenCL::Event CLASS 1452=head2 THE OpenCL::Event CLASS
1491 our $VERSION = '0.96'; 1545 our $VERSION = '0.96';
1492 1546
1493 require XSLoader; 1547 require XSLoader;
1494 XSLoader::load (__PACKAGE__, $VERSION); 1548 XSLoader::load (__PACKAGE__, $VERSION);
1495 1549
1496 @OpenCL::Buffer::ISA = 1550 @OpenCL::Buffer::ISA =
1497 @OpenCL::Image::ISA = OpenCL::Memory::; 1551 @OpenCL::Image::ISA = OpenCL::Memory::;
1498 1552
1499 @OpenCL::BufferObj::ISA = OpenCL::Buffer::; 1553 @OpenCL::BufferObj::ISA = OpenCL::Buffer::;
1500 1554
1501 @OpenCL::Image2D::ISA = 1555 @OpenCL::Image2D::ISA =
1556 @OpenCL::Image3D::ISA =
1557 @OpenCL::Image2DArray::ISA =
1558 @OpenCL::Image1D::ISA =
1559 @OpenCL::Image1DArray::ISA =
1502 @OpenCL::Image3D::ISA = OpenCL::Image::; 1560 @OpenCL::Image1DBuffer::ISA = OpenCL::Image::;
1503 1561
1504 @OpenCL::UserEvent::ISA = OpenCL::Event::; 1562 @OpenCL::UserEvent::ISA = OpenCL::Event::;
1505} 1563}
1506 1564
15071; 15651;
1508 1566
1509=head1 AUTHOR 1567=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines