--- OpenCL/OpenCL.pm 2012/04/25 20:49:13 1.59 +++ OpenCL/OpenCL.pm 2012/04/29 18:24:35 1.63 @@ -495,12 +495,13 @@ package OpenCL; use common::sense; +use Carp (); use Async::Interrupt (); our $POLL_FUNC; # set by XS BEGIN { - our $VERSION = '0.97'; + our $VERSION = '0.98'; require XSLoader; XSLoader::load (__PACKAGE__, $VERSION); @@ -539,9 +540,10 @@ The last error returned by a function - it's only valid after an error occured and before calling another OpenCL function. -=item $str = OpenCL::err2str $errval +=item $str = OpenCL::err2str [$errval] -Comverts an error value into a human readable string. +Converts an error value into a human readable string. IF no error value is +given, then the last error will be used (as returned by OpenCL::errno). =item $str = OpenCL::enum2str $enum @@ -1004,16 +1006,19 @@ sub OpenCL::Context::build_program { my ($self, $prog, $options) = @_; - require Carp; - $prog = $self->program_with_source ($prog) unless ref $prog; - # we build separately per device so we instantly know which one failed + eval { $prog->build (undef, $options); 1 } + or errno == BUILD_PROGRAM_FAILURE + or errno == INVALID_BINARY # workaround nvidia bug + or Carp::croak "OpenCL::Context->build_program: " . err2str; + + # we check status for all devices for my $dev ($self->devices) { - eval { $prog->build ([$dev], $options); 1 } - or Carp::croak ("Building OpenCL program for device '" . $dev->name . "' failed:\n" - . $prog->build_log ($dev)); + $prog->build_status ($dev) == BUILD_SUCCESS + or Carp::croak "Building OpenCL program for device '" . $dev->name . "' failed:\n" + . $prog->build_log ($dev); } $prog @@ -1526,11 +1531,14 @@ compiling whether you use a callback or not. See C if you want to make sure the build is done in the background. -Note that some OpenCL implementations atc up badly, and don't call the +Note that some OpenCL implementations act up badly, and don't call the callback in some error cases (but call it in others). This implementation assumes the callback will always be called, and leaks memory if this is not so. So best make sure you don't pass in invalid values. +Some implementations fail with C when the +compilation state is successful but some later stage fails. + L =item $program->build_async (\@devices = undef, $options = "", $cb->($program) = undef) @@ -1688,6 +1696,40 @@ =for gengetinfo end kernel_work_group +=item $kernel->setf ($format, ...) + +Sets the arguments of a kernel. Since OpenCL 1.1 doesn't have a generic +way to set arguments (and with OpenCL 1.2 it might be rather slow), you +need to specify a format argument, much as with C, to tell OpenCL +what type of argument it is. + +The format arguments are single letters: + + c char + C unsigned char + s short + S unsigned short + i int + I unsigned int + l long + L unsigned long + + h half float (0..65535) + f float + d double + + z local (octet size) + + m memory object (buffer or image) + a sampler + e event + +Space characters in the format string are ignored. + +Example: set the arguments for a kernel that expects an int, two floats, a buffer and an image. + + $kernel->setf ("i ff mm", 5, 0.5, 3, $buffer, $image); + =item $kernel->set_TYPE ($index, $value) =item $kernel->set_char ($index, $value)