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

Comparing OpenCL/OpenCL.pm (file contents):
Revision 1.44 by root, Sat Apr 21 17:47:23 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.
750 750
751=item @device_partition_property_exts = $device->affinity_domains_ext 751=item @device_partition_property_exts = $device->affinity_domains_ext
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
766 766
767=head2 THE OpenCL::Context CLASS 767=head2 THE OpenCL::Context CLASS
768 768
769=over 4 769=over 4
770 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}
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
775L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateCommandQueue.html> 802L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateCommandQueue.html>
803
804Example: create an out-of-order queue.
805
806 $queue = $ctx->queue ($device, OpenCL::QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE);
776 807
777=item $ev = $ctx->user_event 808=item $ev = $ctx->user_event
778 809
779Creates a new OpenCL::UserEvent object. 810Creates a new OpenCL::UserEvent object.
780 811
790=item $buf = $ctx->buffer_sv ($flags, $data) 821=item $buf = $ctx->buffer_sv ($flags, $data)
791 822
792Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and 823Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and
793initialise it with the given data values. 824initialise it with the given data values.
794 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
795=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)
796 834
797Creates a new OpenCL::Image2D object and optionally initialises it with 835Creates a new OpenCL::Image2D object and optionally initialises it with
798the given data values. 836the given data values.
799 837
811Creates 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
812OpenGL buffer object. 850OpenGL buffer object.
813 851
814http://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
815 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
816=item $ctx->gl_texture2d ($flags, $target, $miplevel, $texture) 861=item $img = $ctx->gl_texture2d ($flags, $target, $miplevel, $texture)
817 862
818Creates a new OpenCL::Image2D object that refers to the given OpenGL 863Creates a new OpenCL::Image2D object that refers to the given OpenGL
8192D texture object. 8642D texture object.
820 865
821http://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
822 867
823=item $ctx->gl_texture3d ($flags, $target, $miplevel, $texture) 868=item $img = $ctx->gl_texture3d ($flags, $target, $miplevel, $texture)
824 869
825Creates a new OpenCL::Image3D object that refers to the given OpenGL 870Creates a new OpenCL::Image3D object that refers to the given OpenGL
8263D texture object. 8713D texture object.
827 872
828http://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
891for completion, unless the method is called in void context, in which case 936for completion, unless the method is called in void context, in which case
892no event object is created. 937no event object is created.
893 938
894They also allow you to specify any number of other event objects that this 939They also allow you to specify any number of other event objects that this
895request has to wait for before it starts executing, by simply passing the 940request has to wait for before it starts executing, by simply passing the
896event objects as extra parameters to the enqueue methods. 941event objects as extra parameters to the enqueue methods. To simplify
942program design, this module ignores any C<undef> values in the list of
943events. This makes it possible to code operations such as this, without
944having to put a valid event object into C<$event> first:
945
946 $event = $queue->enqueue_xxx (..., $event);
897 947
898Queues execute in-order by default, without any parallelism, so in most 948Queues execute in-order by default, without any parallelism, so in most
899cases (i.e. you use only one queue) it's not necessary to wait for or 949cases (i.e. you use only one queue) it's not necessary to wait for or
900create event objects. 950create event objects, althoguh an our of order queue is often a bit
951faster.
901 952
902=over 4 953=over 4
903 954
904=item $ev = $queue->enqueue_read_buffer ($buffer, $blocking, $offset, $len, $data, $wait_events...) 955=item $ev = $queue->enqueue_read_buffer ($buffer, $blocking, $offset, $len, $data, $wait_events...)
905 956
971reference to an array of local work sizes, with the same number of 1022reference to an array of local work sizes, with the same number of
972elements as @$global_work_size. 1023elements as @$global_work_size.
973 1024
974L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueNDRangeKernel.html> 1025L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueNDRangeKernel.html>
975 1026
976=item $ev = $queue->enqueue_marker ($wait_events...)
977
978L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueMarker.html>
979
980=item $ev = $queue->enqueue_acquire_gl_objects ([object, ...], $wait_events...) 1027=item $ev = $queue->enqueue_acquire_gl_objects ([object, ...], $wait_events...)
981 1028
982Enqueues a list (an array-ref of OpenCL::Memory objects) to be acquired 1029Enqueues a list (an array-ref of OpenCL::Memory objects) to be acquired
983for subsequent OpenCL usage. 1030for subsequent OpenCL usage.
984 1031
993 1040
994=item $ev = $queue->enqueue_wait_for_events ($wait_events...) 1041=item $ev = $queue->enqueue_wait_for_events ($wait_events...)
995 1042
996L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWaitForEvents.html> 1043L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWaitForEvents.html>
997 1044
998=item $queue->enqueue_barrier 1045=item $ev = $queue->enqueue_marker ($wait_events...)
999 1046
1047L<http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueMarkerWithWaitList.html>
1048
1049=item $ev = $queue->enqueue_barrier ($wait_events...)
1050
1000L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueBarrier.html> 1051L<http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueBarrierWithWaitList.html>
1001 1052
1002=item $queue->flush 1053=item $queue->flush
1003 1054
1004L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clFlush.html> 1055L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clFlush.html>
1005 1056
1120 1171
1121=back 1172=back
1122 1173
1123=head2 THE OpenCL::Image CLASS 1174=head2 THE OpenCL::Image CLASS
1124 1175
1125This 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.
1126 1179
1127=over 4 1180=over 4
1128 1181
1129=item $packed_value = $ev->image_info ($name) 1182=item $packed_value = $ev->image_info ($name)
1130 1183
1217 1270
1218=over 4 1271=over 4
1219 1272
1220=item $program->build ($device, $options = "") 1273=item $program->build ($device, $options = "")
1221 1274
1222Tries 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.
1223 1277
1224L<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>
1225 1279
1226=item $packed_value = $program->build_info ($device, $name) 1280=item $packed_value = $program->build_info ($device, $name)
1227 1281
1234 1288
1235Creates 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
1236the program. 1290the program.
1237 1291
1238L<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
1239 1299
1240=for gengetinfo begin program_build 1300=for gengetinfo begin program_build
1241 1301
1242=item $build_status = $program->build_status ($device) 1302=item $build_status = $program->build_status ($device)
1243 1303
1379float and double as floating point values, memory/buffer/image2d/image3d 1439float and double as floating point values, memory/buffer/image2d/image3d
1380must 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
1381set 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
1382type. 1442type.
1383 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
1384L<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>
1385 1449
1386=back 1450=back
1387 1451
1388=head2 THE OpenCL::Event CLASS 1452=head2 THE OpenCL::Event CLASS
1481 our $VERSION = '0.96'; 1545 our $VERSION = '0.96';
1482 1546
1483 require XSLoader; 1547 require XSLoader;
1484 XSLoader::load (__PACKAGE__, $VERSION); 1548 XSLoader::load (__PACKAGE__, $VERSION);
1485 1549
1486 @OpenCL::Buffer::ISA = 1550 @OpenCL::Buffer::ISA =
1487 @OpenCL::Image::ISA = OpenCL::Memory::; 1551 @OpenCL::Image::ISA = OpenCL::Memory::;
1488 1552
1489 @OpenCL::BufferObj::ISA = OpenCL::Buffer::; 1553 @OpenCL::BufferObj::ISA = OpenCL::Buffer::;
1490 1554
1491 @OpenCL::Image2D::ISA = 1555 @OpenCL::Image2D::ISA =
1556 @OpenCL::Image3D::ISA =
1557 @OpenCL::Image2DArray::ISA =
1558 @OpenCL::Image1D::ISA =
1559 @OpenCL::Image1DArray::ISA =
1492 @OpenCL::Image3D::ISA = OpenCL::Image::; 1560 @OpenCL::Image1DBuffer::ISA = OpenCL::Image::;
1493 1561
1494 @OpenCL::UserEvent::ISA = OpenCL::Event::; 1562 @OpenCL::UserEvent::ISA = OpenCL::Event::;
1495} 1563}
1496 1564
14971; 15651;
1498 1566
1499=head1 AUTHOR 1567=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines