… | |
… | |
493 | =cut |
493 | =cut |
494 | |
494 | |
495 | package OpenCL; |
495 | package OpenCL; |
496 | |
496 | |
497 | use common::sense; |
497 | use common::sense; |
|
|
498 | use Carp (); |
498 | use Async::Interrupt (); |
499 | use Async::Interrupt (); |
499 | |
500 | |
500 | our $POLL_FUNC; # set by XS |
501 | our $POLL_FUNC; # set by XS |
501 | |
502 | |
502 | BEGIN { |
503 | BEGIN { |
503 | our $VERSION = '0.97'; |
504 | our $VERSION = '0.98'; |
504 | |
505 | |
505 | require XSLoader; |
506 | require XSLoader; |
506 | XSLoader::load (__PACKAGE__, $VERSION); |
507 | XSLoader::load (__PACKAGE__, $VERSION); |
507 | |
508 | |
508 | @OpenCL::Platform::ISA = |
509 | @OpenCL::Platform::ISA = |
… | |
… | |
537 | =item $int = OpenCL::errno |
538 | =item $int = OpenCL::errno |
538 | |
539 | |
539 | The last error returned by a function - it's only valid after an error occured |
540 | The last error returned by a function - it's only valid after an error occured |
540 | and before calling another OpenCL function. |
541 | and before calling another OpenCL function. |
541 | |
542 | |
542 | =item $str = OpenCL::err2str $errval |
543 | =item $str = OpenCL::err2str [$errval] |
543 | |
544 | |
544 | Comverts an error value into a human readable string. |
545 | Converts an error value into a human readable string. IF no error value is |
|
|
546 | given, then the last error will be used (as returned by OpenCL::errno). |
545 | |
547 | |
546 | =item $str = OpenCL::enum2str $enum |
548 | =item $str = OpenCL::enum2str $enum |
547 | |
549 | |
548 | Converts most enum values (of parameter names, image format constants, |
550 | Converts most enum values (of parameter names, image format constants, |
549 | object types, addressing and filter modes, command types etc.) into a |
551 | object types, addressing and filter modes, command types etc.) into a |
… | |
… | |
1002 | =cut |
1004 | =cut |
1003 | |
1005 | |
1004 | sub OpenCL::Context::build_program { |
1006 | sub OpenCL::Context::build_program { |
1005 | my ($self, $prog, $options) = @_; |
1007 | my ($self, $prog, $options) = @_; |
1006 | |
1008 | |
1007 | require Carp; |
|
|
1008 | |
|
|
1009 | $prog = $self->program_with_source ($prog) |
1009 | $prog = $self->program_with_source ($prog) |
1010 | unless ref $prog; |
1010 | unless ref $prog; |
1011 | |
1011 | |
1012 | # we build separately per device so we instantly know which one failed |
1012 | eval { $prog->build (undef, $options); 1 } |
|
|
1013 | or errno == BUILD_PROGRAM_FAILURE |
|
|
1014 | or errno == INVALID_BINARY # workaround nvidia bug |
|
|
1015 | or Carp::croak "OpenCL::Context->build_program: " . err2str; |
|
|
1016 | |
|
|
1017 | # we check status for all devices |
1013 | for my $dev ($self->devices) { |
1018 | for my $dev ($self->devices) { |
1014 | eval { $prog->build ([$dev], $options); 1 } |
1019 | $prog->build_status ($dev) == BUILD_SUCCESS |
1015 | or Carp::croak ("Building OpenCL program for device '" . $dev->name . "' failed:\n" |
1020 | or Carp::croak "Building OpenCL program for device '" . $dev->name . "' failed:\n" |
1016 | . $prog->build_log ($dev)); |
1021 | . $prog->build_log ($dev); |
1017 | } |
1022 | } |
1018 | |
1023 | |
1019 | $prog |
1024 | $prog |
1020 | } |
1025 | } |
1021 | |
1026 | |
… | |
… | |
1524 | If a callback is specified, then it will be called when compilation is |
1529 | If a callback is specified, then it will be called when compilation is |
1525 | finished. Note that many OpenCL implementations block your program while |
1530 | finished. Note that many OpenCL implementations block your program while |
1526 | compiling whether you use a callback or not. See C<build_async> if you |
1531 | compiling whether you use a callback or not. See C<build_async> if you |
1527 | want to make sure the build is done in the background. |
1532 | want to make sure the build is done in the background. |
1528 | |
1533 | |
1529 | Note that some OpenCL implementations atc up badly, and don't call the |
1534 | Note that some OpenCL implementations act up badly, and don't call the |
1530 | callback in some error cases (but call it in others). This implementation |
1535 | callback in some error cases (but call it in others). This implementation |
1531 | assumes the callback will always be called, and leaks memory if this is |
1536 | assumes the callback will always be called, and leaks memory if this is |
1532 | not so. So best make sure you don't pass in invalid values. |
1537 | not so. So best make sure you don't pass in invalid values. |
|
|
1538 | |
|
|
1539 | Some implementations fail with C<OpenCL::INVALID_BINARY> when the |
|
|
1540 | compilation state is successful but some later stage fails. |
1533 | |
1541 | |
1534 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clBuildProgram.html> |
1542 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clBuildProgram.html> |
1535 | |
1543 | |
1536 | =item $program->build_async (\@devices = undef, $options = "", $cb->($program) = undef) |
1544 | =item $program->build_async (\@devices = undef, $options = "", $cb->($program) = undef) |
1537 | |
1545 | |