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

Comparing OpenCL/OpenCL.pm (file contents):
Revision 1.73 by root, Fri May 4 14:56:50 2012 UTC vs.
Revision 1.88 by root, Tue Oct 22 17:25:38 2013 UTC

28specific device ("compiling and linking"), also binary programs. For each 28specific device ("compiling and linking"), also binary programs. For each
29kernel function in a program you can then create an OpenCL::Kernel object 29kernel function in a program you can then create an OpenCL::Kernel object
30which represents basically a function call with argument values. 30which represents basically a function call with argument values.
31 31
32OpenCL::Memory objects of various flavours: OpenCL::Buffer objects (flat 32OpenCL::Memory objects of various flavours: OpenCL::Buffer objects (flat
33memory areas, think arrays or structs) and OpenCL::Image objects (think 2d 33memory areas, think arrays or structs) and OpenCL::Image objects (think 2D
34or 3d array) for bulk data and input and output for kernels. 34or 3D array) for bulk data and input and output for kernels.
35 35
36OpenCL::Sampler objects, which are kind of like texture filter modes in 36OpenCL::Sampler objects, which are kind of like texture filter modes in
37OpenGL. 37OpenGL.
38 38
39OpenCL::Queue objects - command queues, which allow you to submit memory 39OpenCL::Queue objects - command queues, which allow you to submit memory
213 $ev->wait; 213 $ev->wait;
214 214
215=head2 Use the OpenGL module to share a texture between OpenCL and OpenGL and draw some julia 215=head2 Use the OpenGL module to share a texture between OpenCL and OpenGL and draw some julia
216set flight effect. 216set flight effect.
217 217
218This is quite a long example to get you going - you can download it from 218This is quite a long example to get you going - you can also download it
219L<http://cvs.schmorp.de/OpenCL/examples/juliaflight>. 219from L<http://cvs.schmorp.de/OpenCL/examples/juliaflight>.
220 220
221 use OpenGL ":all"; 221 use OpenGL ":all";
222 use OpenCL; 222 use OpenCL;
223 223
224 my $S = $ARGV[0] || 256; # window/texture size, smaller is faster 224 my $S = $ARGV[0] || 256; # window/texture size, smaller is faster
232 # find and use the first opencl device that let's us get a shared opengl context 232 # find and use the first opencl device that let's us get a shared opengl context
233 my $platform; 233 my $platform;
234 my $dev; 234 my $dev;
235 my $ctx; 235 my $ctx;
236 236
237 sub get_context {
237 for (OpenCL::platforms) { 238 for (OpenCL::platforms) {
238 $platform = $_; 239 $platform = $_;
239 for ($platform->devices) { 240 for ($platform->devices) {
240 $dev = $_; 241 $dev = $_;
241 $ctx = $platform->context ([OpenCL::GLX_DISPLAY_KHR, undef, OpenCL::GL_CONTEXT_KHR, undef], [$dev]) 242 $ctx = eval { $platform->context ([OpenCL::GLX_DISPLAY_KHR, undef, OpenCL::GL_CONTEXT_KHR, undef], [$dev]) }
242 and last; 243 and return;
244 }
243 } 245 }
246
247 die "cannot find suitable OpenCL device\n";
244 } 248 }
245 249
246 $ctx 250 get_context;
247 or die "cannot find suitable OpenCL device\n";
248 251
249 my $queue = $ctx->queue ($dev); 252 my $queue = $ctx->queue ($dev);
250 253
251 # now attach an opencl image2d object to the opengl texture 254 # now attach an opencl image2d object to the opengl texture
252 my $tex = $ctx->gl_texture2d (OpenCL::MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, $texid); 255 my $tex = $ctx->gl_texture2d (OpenCL::MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, $texid);
388 391
389=item * When enqueuing commands, if the enqueue method is called in void 392=item * When enqueuing commands, if the enqueue method is called in void
390context, no event is created. In all other contexts an event is returned 393context, no event is created. In all other contexts an event is returned
391by the method. 394by the method.
392 395
393=item * This module expects all functions to return C<CL_SUCCESS>. If any 396=item * This module expects all functions to return C<OpenCL::SUCCESS>. If any
394other status is returned the function will throw an exception, so you 397other status is returned the function will throw an exception, so you
395don't normally have to to any error checking. 398don't normally have to to any error checking.
396 399
397=back 400=back
401
402=head2 CONSTANTS
403
404All C<CL_xxx> constants that this module supports are always available
405in the C<OpenCL> namespace as C<OpenCL::xxx> (i.e. without the C<CL_>
406prefix). Constants which are not defined in the header files used during
407compilation, or otherwise are not available, will have the value C<0> (in
408some cases, this will make them indistinguishable from real constants,
409sorry).
410
411The latest version of this module knows and exports the constants
412listed in L<http://cvs.schmorp.de/OpenCL/constiv.h>.
413
414=head2 OPENCL 1.1 VS. OPENCL 1.2
415
416This module supports both OpenCL version 1.1 and 1.2, although the OpenCL
4171.2 interface hasn't been tested much for lack of availability of an
418actual implementation.
419
420Every function or method in this manual page that interfaces to a
421particular OpenCL function has a link to the its C manual page.
422
423If the link contains a F<1.1>, then this function is an OpenCL 1.1
424function. Most but not all also exist in OpenCL 1.2, and this module
425tries to emulate the missing ones for you, when told to do so at
426compiletime. You can check whether a function was removed in OpenCL 1.2 by
427replacing the F<1.1> component in the URL by F<1.2>.
428
429If the link contains a F<1.2>, then this is a OpenCL 1.2-only
430function. Even if the module was compiled with OpenCL 1.2 header files
431and has an 1.2 OpenCL library, calling such a function on a platform that
432doesn't implement 1.2 causes undefined behaviour, usually a crash (But
433this is not guaranteed).
434
435You can find out whether this module was compiled to prefer 1.1
436functionality by ooking at C<OpenCL::PREFER_1_1> - if it is true, then
4371.1 functions generally are implemented using 1.1 OpenCL functions. If it
438is false, then 1.1 functions missing from 1.2 are emulated by calling 1.2
439fucntions.
440
441This is a somewhat sorry state of affairs, but the Khronos group choose to
442make every release of OpenCL source and binary incompatible with previous
443releases.
398 444
399=head2 PERL AND OPENCL TYPES 445=head2 PERL AND OPENCL TYPES
400 446
401This handy(?) table lists OpenCL types and their perl, PDL and pack/unpack 447This handy(?) table lists OpenCL types and their perl, PDL and pack/unpack
402format equivalents: 448format equivalents:
434OpenCL can generate a number of (potentially) asynchronous events, for 480OpenCL can generate a number of (potentially) asynchronous events, for
435example, after compiling a program, to signal a context-related error or, 481example, after compiling a program, to signal a context-related error or,
436perhaps most important, to signal completion of queued jobs (by setting 482perhaps most important, to signal completion of queued jobs (by setting
437callbacks on OpenCL::Event objects). 483callbacks on OpenCL::Event objects).
438 484
485The OpenCL module converts all these callbacks into events - you can
486still register callbacks, but they are not executed when your OpenCL
487implementation calls the actual callback, but only later. Therefore, none
488of the limitations of OpenCL callbacks apply to the perl implementation:
489it is perfectly safe to make blocking operations from event callbacks, and
490enqueued operations don't need to be flushed.
491
439To facilitate this, this module maintains an event queue - each 492To facilitate this, this module maintains an event queue - each
440time an asynchronous event happens, it is queued, and perl will be 493time an asynchronous event happens, it is queued, and perl will be
441interrupted. This is implemented via the L<Async::Interrupt> module. In 494interrupted. This is implemented via the L<Async::Interrupt> module. In
442addition, this module has L<AnyEvent> support, so it can seamlessly 495addition, this module has L<AnyEvent> support, so it can seamlessly
443integrate itself into many event loops. 496integrate itself into many event loops.
444 497
445Since this module is a bit hard to understand, here are some case examples: 498Since L<Async::Interrupt> is a bit hard to understand, here are some case examples:
446 499
447=head3 Don't use callbacks. 500=head3 Don't use callbacks.
448 501
449When your program never uses any callbacks, then there will never be any 502When your program never uses any callbacks, then there will never be any
450notifications you need to take care of, and therefore no need to worry 503notifications you need to take care of, and therefore no need to worry
547use Async::Interrupt (); 600use Async::Interrupt ();
548 601
549our $POLL_FUNC; # set by XS 602our $POLL_FUNC; # set by XS
550 603
551BEGIN { 604BEGIN {
552 our $VERSION = '0.99'; 605 our $VERSION = '1.01';
553 606
554 require XSLoader; 607 require XSLoader;
555 XSLoader::load (__PACKAGE__, $VERSION); 608 XSLoader::load (__PACKAGE__, $VERSION);
556 609
557 @OpenCL::Platform::ISA = 610 @OpenCL::Platform::ISA =
593The last error returned by a function - it's only valid after an error occured 646The last error returned by a function - it's only valid after an error occured
594and before calling another OpenCL function. 647and before calling another OpenCL function.
595 648
596=item $str = OpenCL::err2str [$errval] 649=item $str = OpenCL::err2str [$errval]
597 650
598Converts an error value into a human readable string. IF no error value is 651Converts an error value into a human readable string. If no error value is
599given, then the last error will be used (as returned by OpenCL::errno). 652given, then the last error will be used (as returned by OpenCL::errno).
653
654The latest version of this module knows the error constants
655listed in L<http://cvs.schmorp.de/OpenCL/errstr.h>.
600 656
601=item $str = OpenCL::enum2str $enum 657=item $str = OpenCL::enum2str $enum
602 658
603Converts most enum values (of parameter names, image format constants, 659Converts most enum values (of parameter names, image format constants,
604object types, addressing and filter modes, command types etc.) into a 660object types, addressing and filter modes, command types etc.) into a
605human readable string. When confronted with some random integer it can be 661human readable string. When confronted with some random integer it can be
606very helpful to pass it through this function to maybe get some readable 662very helpful to pass it through this function to maybe get some readable
607string out of it. 663string out of it.
608 664
665The latest version of this module knows the enumaration constants
666listed in L<http://cvs.schmorp.de/OpenCL/enumstr.h>.
667
609=item @platforms = OpenCL::platforms 668=item @platforms = OpenCL::platforms
610 669
611Returns all available OpenCL::Platform objects. 670Returns all available OpenCL::Platform objects.
612 671
613L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformIDs.html> 672L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformIDs.html>
614 673
615=item $ctx = OpenCL::context_from_type $properties, $type = OpenCL::DEVICE_TYPE_DEFAULT, $callback->($err, $pvt) = $print_stderr 674=item $ctx = OpenCL::context_from_type $properties, $type = OpenCL::DEVICE_TYPE_DEFAULT, $callback->($err, $pvt) = $print_stderr
616 675
617Tries to create a context from a default device and platform type - never worked for me. 676Tries to create a context from a default device and platform type - never worked for me.
677Consider using C<< $platform->context_from_type >> instead.
618 678
619type: OpenCL::DEVICE_TYPE_DEFAULT, OpenCL::DEVICE_TYPE_CPU, OpenCL::DEVICE_TYPE_GPU, 679type: OpenCL::DEVICE_TYPE_DEFAULT, OpenCL::DEVICE_TYPE_CPU, OpenCL::DEVICE_TYPE_GPU,
620OpenCL::DEVICE_TYPE_ACCELERATOR, OpenCL::DEVICE_TYPE_CUSTOM, OpenCL::DEVICE_TYPE_ALL. 680OpenCL::DEVICE_TYPE_ACCELERATOR, OpenCL::DEVICE_TYPE_CUSTOM, OpenCL::DEVICE_TYPE_ALL.
621 681
622L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html> 682L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html>
623 683
624=item $ctx = OpenCL::context $properties, \@devices, $callback->($err, $pvt) = $print_stderr) 684=item $ctx = OpenCL::context $properties, \@devices, $callback->($err, $pvt) = $print_stderr)
625 685
626Create a new OpenCL::Context object using the given device object(s). This 686Create a new OpenCL::Context object using the given device object(s).
627function isn't implemented yet, use C<< $platform->context >> instead. 687Consider using C<< $platform->context >> instead.
628 688
629L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html> 689L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html>
630 690
631=item OpenCL::wait_for_events $wait_events... 691=item OpenCL::wait_for_events $wait_events...
632 692
713L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html> 773L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html>
714 774
715=item $ctx = $platform->context ($properties, \@devices, $callback->($err, $pvt) = $print_stderr) 775=item $ctx = $platform->context ($properties, \@devices, $callback->($err, $pvt) = $print_stderr)
716 776
717Create a new OpenCL::Context object using the given device object(s)- a 777Create a new OpenCL::Context object using the given device object(s)- a
718CL_CONTEXT_PLATFORM property is supplied automatically. 778OpenCL::CONTEXT_PLATFORM property is supplied automatically.
719 779
720L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html> 780L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html>
721 781
722=item $packed_value = $platform->info ($name) 782=item $packed_value = $platform->info ($name)
723 783
768=over 4 828=over 4
769 829
770=item $packed_value = $device->info ($name) 830=item $packed_value = $device->info ($name)
771 831
772See C<< $platform->info >> for details. 832See C<< $platform->info >> for details.
833
834type: OpenCL::DEVICE_TYPE_DEFAULT, OpenCL::DEVICE_TYPE_CPU,
835OpenCL::DEVICE_TYPE_GPU, OpenCL::DEVICE_TYPE_ACCELERATOR,
836OpenCL::DEVICE_TYPE_CUSTOM, OpenCL::DEVICE_TYPE_ALL.
837
838fp_config: OpenCL::FP_DENORM, OpenCL::FP_INF_NAN, OpenCL::FP_ROUND_TO_NEAREST,
839OpenCL::FP_ROUND_TO_ZERO, OpenCL::FP_ROUND_TO_INF, OpenCL::FP_FMA,
840OpenCL::FP_SOFT_FLOAT, OpenCL::FP_CORRECTLY_ROUNDED_DIVIDE_SQRT.
841
842mem_cache_type: OpenCL::NONE, OpenCL::READ_ONLY_CACHE, OpenCL::READ_WRITE_CACHE.
843
844local_mem_type: OpenCL::LOCAL, OpenCL::GLOBAL.
845
846exec_capabilities: OpenCL::EXEC_KERNEL, OpenCL::EXEC_NATIVE_KERNEL.
847
848command_queue_properties: OpenCL::QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE,
849OpenCL::QUEUE_PROFILING_ENABLE.
850
851partition_properties: OpenCL::DEVICE_PARTITION_EQUALLY,
852OpenCL::DEVICE_PARTITION_BY_COUNTS, OpenCL::DEVICE_PARTITION_BY_COUNTS_LIST_END,
853OpenCL::DEVICE_PARTITION_BY_AFFINITY_DOMAIN.
854
855affinity_domain: OpenCL::DEVICE_AFFINITY_DOMAIN_NUMA,
856OpenCL::DEVICE_AFFINITY_DOMAIN_L4_CACHE, OpenCL::DEVICE_AFFINITY_DOMAIN_L3_CACHE,
857OpenCL::DEVICE_AFFINITY_DOMAIN_L2_CACHE, OpenCL::DEVICE_AFFINITY_DOMAIN_L1_CACHE,
858OpenCL::DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE.
773 859
774L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetDeviceInfo.html> 860L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetDeviceInfo.html>
775 861
776=item @devices = $device->sub_devices (\@properties) 862=item @devices = $device->sub_devices (\@properties)
777 863
1137OpenCL::MEM_USE_HOST_PTR, OpenCL::MEM_ALLOC_HOST_PTR, OpenCL::MEM_COPY_HOST_PTR, 1223OpenCL::MEM_USE_HOST_PTR, OpenCL::MEM_ALLOC_HOST_PTR, OpenCL::MEM_COPY_HOST_PTR,
1138OpenCL::MEM_HOST_WRITE_ONLY, OpenCL::MEM_HOST_READ_ONLY, OpenCL::MEM_HOST_NO_ACCESS. 1224OpenCL::MEM_HOST_WRITE_ONLY, OpenCL::MEM_HOST_READ_ONLY, OpenCL::MEM_HOST_NO_ACCESS.
1139 1225
1140L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html> 1226L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateBuffer.html>
1141 1227
1228A somewhat informative thread on the flags is:
1229
1230L<http://www.khronos.org/message_boards/viewtopic.php?f=28&t=2440>
1231
1142=item $buf = $ctx->buffer_sv ($flags, $data) 1232=item $buf = $ctx->buffer_sv ($flags, $data)
1143 1233
1144Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and 1234Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and
1145initialise it with the given data values. 1235initialise it with the given data values.
1146 1236
1156channel_type: OpenCL::SNORM_INT8, OpenCL::SNORM_INT16, OpenCL::UNORM_INT8, 1246channel_type: OpenCL::SNORM_INT8, OpenCL::SNORM_INT16, OpenCL::UNORM_INT8,
1157OpenCL::UNORM_INT16, OpenCL::UNORM_SHORT_565, OpenCL::UNORM_SHORT_555, 1247OpenCL::UNORM_INT16, OpenCL::UNORM_SHORT_565, OpenCL::UNORM_SHORT_555,
1158OpenCL::UNORM_INT_101010, OpenCL::SIGNED_INT8, OpenCL::SIGNED_INT16, 1248OpenCL::UNORM_INT_101010, OpenCL::SIGNED_INT8, OpenCL::SIGNED_INT16,
1159OpenCL::SIGNED_INT32, OpenCL::UNSIGNED_INT8, OpenCL::UNSIGNED_INT16, 1249OpenCL::SIGNED_INT32, OpenCL::UNSIGNED_INT8, OpenCL::UNSIGNED_INT16,
1160OpenCL::UNSIGNED_INT32, OpenCL::HALF_FLOAT, OpenCL::FLOAT. 1250OpenCL::UNSIGNED_INT32, OpenCL::HALF_FLOAT, OpenCL::FLOAT.
1161
1162 1251
1163type: OpenCL::MEM_OBJECT_BUFFER, OpenCL::MEM_OBJECT_IMAGE2D, 1252type: OpenCL::MEM_OBJECT_BUFFER, OpenCL::MEM_OBJECT_IMAGE2D,
1164OpenCL::MEM_OBJECT_IMAGE3D, OpenCL::MEM_OBJECT_IMAGE2D_ARRAY, 1253OpenCL::MEM_OBJECT_IMAGE3D, OpenCL::MEM_OBJECT_IMAGE2D_ARRAY,
1165OpenCL::MEM_OBJECT_IMAGE1D, OpenCL::MEM_OBJECT_IMAGE1D_ARRAY, 1254OpenCL::MEM_OBJECT_IMAGE1D, OpenCL::MEM_OBJECT_IMAGE1D_ARRAY,
1166OpenCL::MEM_OBJECT_IMAGE1D_BUFFER. 1255OpenCL::MEM_OBJECT_IMAGE1D_BUFFER.
1264 1353
1265Creates a new OpenCL::Program object from the given built-in kernel names. 1354Creates a new OpenCL::Program object from the given built-in kernel names.
1266 1355
1267L<http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateProgramWithBuiltInKernels.html> 1356L<http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateProgramWithBuiltInKernels.html>
1268 1357
1358=item $program = $ctx->link_program (\@devices, $options, \@programs, $cb->($program) = undef)
1359
1360Links all (already compiled) program objects specified in C<@programs>
1361together and returns a new OpenCL::Program object with the result.
1362
1363L<http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clLinkProgram.html>
1364
1269=item $packed_value = $ctx->info ($name) 1365=item $packed_value = $ctx->info ($name)
1270 1366
1271See C<< $platform->info >> for details. 1367See C<< $platform->info >> for details.
1272 1368
1273L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetContextInfo.html> 1369L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetContextInfo.html>
1335 1431
1336=item $ev = $queue->copy_buffer ($src, $dst, $src_offset, $dst_offset, $len, $wait_events...) 1432=item $ev = $queue->copy_buffer ($src, $dst, $src_offset, $dst_offset, $len, $wait_events...)
1337 1433
1338L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBuffer.html> 1434L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueCopyBuffer.html>
1339 1435
1340=item $ev = $queue->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...) 1436$eue->read_buffer_rect ($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...)
1341 1437
1342http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBufferRect.html 1438http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueReadBufferRect.html
1343 1439
1344=item $ev = $queue->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...) 1440=item $ev = $queue->write_buffer_rect ($buf, $blocking, $buf_y, $host_x, $host_z, $height, $buf_row_pitch, $host_row_pitch, $data, $wait_events...)
1345 1441
1346http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html 1442http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueWriteBufferRect.html
1347 1443
1348=item $ev = $queue->copy_buffer_to_image ($src_buffer, $dst_image, $src_offset, $dst_x, $dst_y, $dst_z, $width, $height, $depth, $wait_events...) 1444=item $ev = $queue->copy_buffer_to_image ($src_buffer, $dst_image, $src_offset, $dst_x, $dst_y, $dst_z, $width, $height, $depth, $wait_events...)
1349 1445
1533it. You are not necessarily meant to do it this way, this example just 1629it. You are not necessarily meant to do it this way, this example just
1534shows you the accessors to use :) 1630shows you the accessors to use :)
1535 1631
1536 my $mapped = $queue->map_image ($image, 1, OpenCL::MAP_WRITE); 1632 my $mapped = $queue->map_image ($image, 1, OpenCL::MAP_WRITE);
1537 1633
1538 $mapped->set ($_ * $mapped->row_pitch, pack "C", 5) 1634 $mapped->write ($_ * $mapped->row_pitch, pack "C", 5)
1539 for 0..$image->height; 1635 for 0 .. $mapped->height - 1;
1540 1636
1541 $mapped->unmap;. 1637 $mapped->unmap;.
1542 $mapped->wait; # only needed for out of order queues normally 1638 $mapped->wait; # only needed for out of order queues normally
1543 1639
1544=item $ev = $queue->unmap ($mapped, $wait_events...) 1640=item $ev = $queue->unmap ($mapped, $wait_events...)
1564 1660
1565See C<< $platform->info >> for details. 1661See C<< $platform->info >> for details.
1566 1662
1567L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetMemObjectInfo.html> 1663L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetMemObjectInfo.html>
1568 1664
1665=item $memory->destructor_callback ($cb->())
1666
1667Sets a callback that will be invoked after the memory object is destructed.
1668
1669L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clSetMemObjectDestructorCallback.html>
1670
1569=for gengetinfo begin mem 1671=for gengetinfo begin mem
1570 1672
1571=item $mem_object_type = $mem->type 1673=item $mem_object_type = $mem->type
1572 1674
1573Calls C<clGetMemObjectInfo> with C<OpenCL::MEM_TYPE> and returns the result. 1675Calls C<clGetMemObjectInfo> with C<OpenCL::MEM_TYPE> and returns the result.
1630=over 4 1732=over 4
1631 1733
1632=item $subbuf = $buf_obj->sub_buffer_region ($flags, $origin, $size) 1734=item $subbuf = $buf_obj->sub_buffer_region ($flags, $origin, $size)
1633 1735
1634Creates an OpenCL::Buffer objects from this buffer and returns it. The 1736Creates an OpenCL::Buffer objects from this buffer and returns it. The
1635C<buffer_create_type> is assumed to be C<CL_BUFFER_CREATE_TYPE_REGION>. 1737C<buffer_create_type> is assumed to be C<OpenCL::BUFFER_CREATE_TYPE_REGION>.
1636 1738
1637L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateSubBuffer.html> 1739L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateSubBuffer.html>
1638 1740
1639=back 1741=back
1640 1742
1656L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetImageInfo.html> 1758L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetImageInfo.html>
1657 1759
1658=item ($channel_order, $channel_data_type) = $image->format 1760=item ($channel_order, $channel_data_type) = $image->format
1659 1761
1660Returns the channel order and type used to create the image by calling 1762Returns the channel order and type used to create the image by calling
1661C<clGetImageInfo> with C<CL_IMAGE_FORMAT>. 1763C<clGetImageInfo> with C<OpenCL::IMAGE_FORMAT>.
1662 1764
1663=for gengetinfo begin image 1765=for gengetinfo begin image
1664 1766
1665=item $int = $image->element_size 1767=item $int = $image->element_size
1666 1768
1766C<-cl-mad-enable>, C<-cl-no-signed-zeros>, C<-cl-unsafe-math-optimizations>, 1868C<-cl-mad-enable>, C<-cl-no-signed-zeros>, C<-cl-unsafe-math-optimizations>,
1767C<-cl-finite-math-only>, C<-cl-fast-relaxed-math>, 1869C<-cl-finite-math-only>, C<-cl-fast-relaxed-math>,
1768C<-w>, C<-Werror>, C<-cl-std=CL1.1/CL1.2>, C<-cl-kernel-arg-info>, 1870C<-w>, C<-Werror>, C<-cl-std=CL1.1/CL1.2>, C<-cl-kernel-arg-info>,
1769C<-create-library>, C<-enable-link-options>. 1871C<-create-library>, C<-enable-link-options>.
1770 1872
1873build_status: OpenCL::BUILD_SUCCESS, OpenCL::BUILD_NONE,
1874OpenCL::BUILD_ERROR, OpenCL::BUILD_IN_PROGRESS.
1875
1771L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clBuildProgram.html> 1876L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clBuildProgram.html>
1772 1877
1773=item $program->build_async (\@devices = undef, $options = "", $cb->($program) = undef) 1878=item $program->build_async (\@devices = undef, $options = "", $cb->($program) = undef)
1774 1879
1775Similar to C<< ->build >>, except it starts a thread, and never fails (you 1880Similar to C<< ->build >>, except it starts a thread, and never fails (you
1776need to check the compilation status form the callback, or by polling). 1881need to check the compilation status form the callback, or by polling).
1777 1882
1778build_status: OpenCL::BUILD_SUCCESS, OpenCL::BUILD_NONE, 1883=item $program->compile (\@devices = undef, $options = "", \%headers = undef, $cb->($program) = undef)
1779OpenCL::BUILD_ERROR, OpenCL::BUILD_IN_PROGRESS. 1884
1885Compiles the given program for the given devices (or all devices if
1886undef). If C<$headers> is given, it must be a hashref with include name =>
1887OpenCL::Program pairs.
1888
1889L<http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCompileProgram.html>
1780 1890
1781=item $packed_value = $program->build_info ($device, $name) 1891=item $packed_value = $program->build_info ($device, $name)
1782 1892
1783Similar to C<< $platform->info >>, but returns build info for a previous 1893Similar to C<< $platform->info >>, but returns build info for a previous
1784build attempt for the given device. 1894build attempt for the given device.
1785 1895
1896binary_type: OpenCL::PROGRAM_BINARY_TYPE_NONE,
1897OpenCL::PROGRAM_BINARY_TYPE_COMPILED_OBJECT,
1898OpenCL::PROGRAM_BINARY_TYPE_LIBRARY,
1899OpenCL::PROGRAM_BINARY_TYPE_EXECUTABLE.
1900
1786L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetBuildInfo.html> 1901L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetBuildInfo.html>
1787 1902
1788=item $kernel = $program->kernel ($function_name) 1903=item $kernel = $program->kernel ($function_name)
1789 1904
1790Creates an OpenCL::Kernel object out of the named C<__kernel> function in 1905Creates an OpenCL::Kernel object out of the named C<__kernel> function in
1809Calls C<clGetProgramBuildInfo> with C<OpenCL::PROGRAM_BUILD_OPTIONS> and returns the result. 1924Calls C<clGetProgramBuildInfo> with C<OpenCL::PROGRAM_BUILD_OPTIONS> and returns the result.
1810 1925
1811=item $string = $program->build_log ($device) 1926=item $string = $program->build_log ($device)
1812 1927
1813Calls C<clGetProgramBuildInfo> with C<OpenCL::PROGRAM_BUILD_LOG> and returns the result. 1928Calls C<clGetProgramBuildInfo> with C<OpenCL::PROGRAM_BUILD_LOG> and returns the result.
1929
1930=item $binary_type = $program->binary_type ($device)
1931
1932Calls C<clGetProgramBuildInfo> with C<OpenCL::PROGRAM_BINARY_TYPE> and returns the result.
1814 1933
1815=for gengetinfo end program_build 1934=for gengetinfo end program_build
1816 1935
1817=item $packed_value = $program->info ($name) 1936=item $packed_value = $program->info ($name)
1818 1937
2233 2352
2234This is a subclass of OpenCL::Mapped, representing mapped images. 2353This is a subclass of OpenCL::Mapped, representing mapped images.
2235 2354
2236=over 4 2355=over 4
2237 2356
2357=item $pixels = $mapped->width
2358
2359=item $pixels = $mapped->height
2360
2361=item $pixels = $mapped->depth
2362
2363Return the width/height/depth of the mapped image region, in pixels.
2364
2238=item $bytes = $mapped->row_pitch 2365=item $bytes = $mapped->row_pitch
2239 2366
2240=item $bytes = $mapped->slice_pitch 2367=item $bytes = $mapped->slice_pitch
2241 2368
2242Return the row or slice pitch of the image that has been mapped. 2369Return the row or slice pitch of the image that has been mapped.
2243 2370
2371=item $bytes = $mapped->element_size
2372
2373Return the size of a single pixel.
2374
2375=item $data = $mapped->get_row ($count, $x=0, $y=0, $z=0)
2376
2377Return C<$count> pixels from the given coordinates. The pixel data must
2378be completely contained within a single row.
2379
2380If C<$count> is C<undef>, then all the remaining pixels in that row are
2381returned.
2382
2383=item $mapped->set_row ($data, $x=0, $y=0, $z=0)
2384
2385Write the given pixel data at the given coordinate. The pixel data must
2386be completely contained within a single row.
2387
2244=back 2388=back
2245
2246 2389
2247=cut 2390=cut
2248 2391
22491; 23921;
2250 2393

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines