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

Comparing OpenCL/OpenCL.pm (file contents):
Revision 1.40 by root, Thu Apr 19 22:33:27 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); 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) {
336=item * Structures are often specified by flattening out their components 329=item * Structures are often specified by flattening out their components
337as with short vectors, and returned as arrayrefs. 330as with short vectors, and returned as arrayrefs.
338 331
339=item * When enqueuing commands, the wait list is specified by adding 332=item * When enqueuing commands, the wait list is specified by adding
340extra arguments to the function - anywhere a C<$wait_events...> argument 333extra arguments to the function - anywhere a C<$wait_events...> argument
341is documented this can be any number of event objects. 334is documented this can be any number of event objects. As an extsnion
335implemented by this module, C<undef> values will be ignored in the event
336list.
342 337
343=item * When enqueuing commands, if the enqueue method is called in void 338=item * When enqueuing commands, if the enqueue method is called in void
344context, no event is created. In all other contexts an event is returned 339context, no event is created. In all other contexts an event is returned
345by the method. 340by the method.
346 341
454It'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
455wrappers. 450wrappers.
456 451
457L<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>
458 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
459=for gengetinfo begin platform 461=for gengetinfo begin platform
460 462
461=item $string = $platform->profile 463=item $string = $platform->profile
462 464
463Calls C<clGetPlatformInfo> with C<CL_PLATFORM_PROFILE> and returns the result. 465Calls C<clGetPlatformInfo> with C<CL_PLATFORM_PROFILE> and returns the result.
748 750
749=item @device_partition_property_exts = $device->affinity_domains_ext 751=item @device_partition_property_exts = $device->affinity_domains_ext
750 752
751Calls 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.
752 754
753=item $uint = $device->reference_count_ext 755=item $uint = $device->reference_count_ext
754 756
755Calls 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.
756 758
757=item @device_partition_property_exts = $device->partition_style_ext 759=item @device_partition_property_exts = $device->partition_style_ext
758 760
759Calls 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.
760 762
764 766
765=head2 THE OpenCL::Context CLASS 767=head2 THE OpenCL::Context CLASS
766 768
767=over 4 769=over 4
768 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
769=item $queue = $ctx->queue ($device, $properties) 798=item $queue = $ctx->queue ($device, $properties)
770 799
771Create 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.
772 801
773L<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);
774 807
775=item $ev = $ctx->user_event 808=item $ev = $ctx->user_event
776 809
777Creates a new OpenCL::UserEvent object. 810Creates a new OpenCL::UserEvent object.
778 811
788=item $buf = $ctx->buffer_sv ($flags, $data) 821=item $buf = $ctx->buffer_sv ($flags, $data)
789 822
790Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and 823Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and
791initialise it with the given data values. 824initialise it with the given data values.
792 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
793=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)
794 834
795Creates a new OpenCL::Image2D object and optionally initialises it with 835Creates a new OpenCL::Image2D object and optionally initialises it with
796the given data values. 836the given data values.
797 837
809Creates 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
810OpenGL buffer object. 850OpenGL buffer object.
811 851
812http://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
813 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
814=item $ctx->gl_texture2d ($flags, $target, $miplevel, $texture) 861=item $img = $ctx->gl_texture2d ($flags, $target, $miplevel, $texture)
815 862
816Creates a new OpenCL::Image2D object that refers to the given OpenGL 863Creates a new OpenCL::Image2D object that refers to the given OpenGL
8172D texture object. 8642D texture object.
818 865
819http://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
820 867
821=item $ctx->gl_texture3d ($flags, $target, $miplevel, $texture) 868=item $img = $ctx->gl_texture3d ($flags, $target, $miplevel, $texture)
822 869
823Creates a new OpenCL::Image3D object that refers to the given OpenGL 870Creates a new OpenCL::Image3D object that refers to the given OpenGL
8243D texture object. 8713D texture object.
825 872
826http://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
889for 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
890no event object is created. 937no event object is created.
891 938
892They 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
893request 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
894event 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);
895 947
896Queues execute in-order by default, without any parallelism, so in most 948Queues execute in-order by default, without any parallelism, so in most
897cases (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
898create event objects. 950create event objects, althoguh an our of order queue is often a bit
951faster.
899 952
900=over 4 953=over 4
901 954
902=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...)
903 956
969reference 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
970elements as @$global_work_size. 1023elements as @$global_work_size.
971 1024
972L<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>
973 1026
974=item $ev = $queue->enqueue_marker ($wait_events...)
975
976L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueMarker.html>
977
978=item $ev = $queue->enqueue_acquire_gl_objects ([object, ...], $wait_events...) 1027=item $ev = $queue->enqueue_acquire_gl_objects ([object, ...], $wait_events...)
979 1028
980Enqueues 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
981for subsequent OpenCL usage. 1030for subsequent OpenCL usage.
982 1031
991 1040
992=item $ev = $queue->enqueue_wait_for_events ($wait_events...) 1041=item $ev = $queue->enqueue_wait_for_events ($wait_events...)
993 1042
994L<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>
995 1044
996=item $queue->enqueue_barrier 1045=item $ev = $queue->enqueue_marker ($wait_events...)
997 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
998L<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>
999 1052
1000=item $queue->flush 1053=item $queue->flush
1001 1054
1002L<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>
1003 1056
1118 1171
1119=back 1172=back
1120 1173
1121=head2 THE OpenCL::Image CLASS 1174=head2 THE OpenCL::Image CLASS
1122 1175
1123This 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.
1124 1179
1125=over 4 1180=over 4
1126 1181
1127=item $packed_value = $ev->image_info ($name) 1182=item $packed_value = $ev->image_info ($name)
1128 1183
1215 1270
1216=over 4 1271=over 4
1217 1272
1218=item $program->build ($device, $options = "") 1273=item $program->build ($device, $options = "")
1219 1274
1220Tries 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.
1221 1277
1222L<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>
1223 1279
1224=item $packed_value = $program->build_info ($device, $name) 1280=item $packed_value = $program->build_info ($device, $name)
1225 1281
1232 1288
1233Creates 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
1234the program. 1290the program.
1235 1291
1236L<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
1237 1299
1238=for gengetinfo begin program_build 1300=for gengetinfo begin program_build
1239 1301
1240=item $build_status = $program->build_status ($device) 1302=item $build_status = $program->build_status ($device)
1241 1303
1369 1431
1370This is a family of methods to set the kernel argument with the number C<$index> to the give C<$value>. 1432This is a family of methods to set the kernel argument with the number C<$index> to the give C<$value>.
1371 1433
1372TYPE is one of C<char>, C<uchar>, C<short>, C<ushort>, C<int>, C<uint>, 1434TYPE is one of C<char>, C<uchar>, C<short>, C<ushort>, C<int>, C<uint>,
1373C<long>, C<ulong>, C<half>, C<float>, C<double>, C<memory>, C<buffer>, 1435C<long>, C<ulong>, C<half>, C<float>, C<double>, C<memory>, C<buffer>,
1374C<image2d>, C<image3d>, C<sampler> or C<event>. 1436C<image2d>, C<image3d>, C<sampler>, C<local> or C<event>.
1375 1437
1376Chars and integers (including the half type) are specified as integers, 1438Chars and integers (including the half type) are specified as integers,
1377float and double as floating point values, memory/buffer/image2d/image3d 1439float and double as floating point values, memory/buffer/image2d/image3d
1378must be an object of that type or C<undef>, and sampler and event must be 1440must be an object of that type or C<undef>, local-memory arguments are
1379objects of that type. 1441set by specifying the size, and sampler and event must be objects of that
1442type.
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.
1380 1447
1381L<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>
1382 1449
1383=back 1450=back
1384 1451
1473package OpenCL; 1540package OpenCL;
1474 1541
1475use common::sense; 1542use common::sense;
1476 1543
1477BEGIN { 1544BEGIN {
1478 our $VERSION = '0.95'; 1545 our $VERSION = '0.96';
1479 1546
1480 require XSLoader; 1547 require XSLoader;
1481 XSLoader::load (__PACKAGE__, $VERSION); 1548 XSLoader::load (__PACKAGE__, $VERSION);
1482 1549
1483 @OpenCL::Buffer::ISA = 1550 @OpenCL::Buffer::ISA =
1484 @OpenCL::Image::ISA = OpenCL::Memory::; 1551 @OpenCL::Image::ISA = OpenCL::Memory::;
1485 1552
1486 @OpenCL::BufferObj::ISA = OpenCL::Buffer::; 1553 @OpenCL::BufferObj::ISA = OpenCL::Buffer::;
1487 1554
1488 @OpenCL::Image2D::ISA = 1555 @OpenCL::Image2D::ISA =
1556 @OpenCL::Image3D::ISA =
1557 @OpenCL::Image2DArray::ISA =
1558 @OpenCL::Image1D::ISA =
1559 @OpenCL::Image1DArray::ISA =
1489 @OpenCL::Image3D::ISA = OpenCL::Image::; 1560 @OpenCL::Image1DBuffer::ISA = OpenCL::Image::;
1490 1561
1491 @OpenCL::UserEvent::ISA = OpenCL::Event::; 1562 @OpenCL::UserEvent::ISA = OpenCL::Event::;
1492} 1563}
1493 1564
14941; 15651;
1495 1566
1496=head1 AUTHOR 1567=head1 AUTHOR

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines