… | |
… | |
434 | OpenCL can generate a number of (potentially) asynchronous events, for |
434 | OpenCL can generate a number of (potentially) asynchronous events, for |
435 | example, after compiling a program, to signal a context-related error or, |
435 | example, after compiling a program, to signal a context-related error or, |
436 | perhaps most important, to signal completion of queued jobs (by setting |
436 | perhaps most important, to signal completion of queued jobs (by setting |
437 | callbacks on OpenCL::Event objects). |
437 | callbacks on OpenCL::Event objects). |
438 | |
438 | |
|
|
439 | The OpenCL module converts all these callbacks into events - you can |
|
|
440 | still register callbacks, but they are not executed when your OpenCL |
|
|
441 | implementation calls the actual callback, but only later. Therefore, none |
|
|
442 | of the limitations of OpenCL callbacks apply to the perl implementation: |
|
|
443 | it is perfectly safe to make blocking operations from event callbacks, and |
|
|
444 | enqueued operations don't need to be flushed. |
|
|
445 | |
439 | To facilitate this, this module maintains an event queue - each |
446 | To facilitate this, this module maintains an event queue - each |
440 | time an asynchronous event happens, it is queued, and perl will be |
447 | time an asynchronous event happens, it is queued, and perl will be |
441 | interrupted. This is implemented via the L<Async::Interrupt> module. In |
448 | interrupted. This is implemented via the L<Async::Interrupt> module. In |
442 | addition, this module has L<AnyEvent> support, so it can seamlessly |
449 | addition, this module has L<AnyEvent> support, so it can seamlessly |
443 | integrate itself into many event loops. |
450 | integrate itself into many event loops. |
444 | |
451 | |
445 | Since this module is a bit hard to understand, here are some case examples: |
452 | Since L<Async::Interrupt> is a bit hard to understand, here are some case examples: |
446 | |
453 | |
447 | =head3 Don't use callbacks. |
454 | =head3 Don't use callbacks. |
448 | |
455 | |
449 | When your program never uses any callbacks, then there will never be any |
456 | When your program never uses any callbacks, then there will never be any |
450 | notifications you need to take care of, and therefore no need to worry |
457 | notifications you need to take care of, and therefore no need to worry |
… | |
… | |
613 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformIDs.html> |
620 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformIDs.html> |
614 | |
621 | |
615 | =item $ctx = OpenCL::context_from_type $properties, $type = OpenCL::DEVICE_TYPE_DEFAULT, $callback->($err, $pvt) = $print_stderr |
622 | =item $ctx = OpenCL::context_from_type $properties, $type = OpenCL::DEVICE_TYPE_DEFAULT, $callback->($err, $pvt) = $print_stderr |
616 | |
623 | |
617 | Tries to create a context from a default device and platform type - never worked for me. |
624 | Tries to create a context from a default device and platform type - never worked for me. |
|
|
625 | Consider using C<< $platform->context_from_type >> instead. |
618 | |
626 | |
619 | type: OpenCL::DEVICE_TYPE_DEFAULT, OpenCL::DEVICE_TYPE_CPU, OpenCL::DEVICE_TYPE_GPU, |
627 | type: OpenCL::DEVICE_TYPE_DEFAULT, OpenCL::DEVICE_TYPE_CPU, OpenCL::DEVICE_TYPE_GPU, |
620 | OpenCL::DEVICE_TYPE_ACCELERATOR, OpenCL::DEVICE_TYPE_CUSTOM, OpenCL::DEVICE_TYPE_ALL. |
628 | OpenCL::DEVICE_TYPE_ACCELERATOR, OpenCL::DEVICE_TYPE_CUSTOM, OpenCL::DEVICE_TYPE_ALL. |
621 | |
629 | |
622 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html> |
630 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContextFromType.html> |
623 | |
631 | |
624 | =item $ctx = OpenCL::context $properties, \@devices, $callback->($err, $pvt) = $print_stderr) |
632 | =item $ctx = OpenCL::context $properties, \@devices, $callback->($err, $pvt) = $print_stderr) |
625 | |
633 | |
626 | Create a new OpenCL::Context object using the given device object(s). This |
634 | Create a new OpenCL::Context object using the given device object(s). |
627 | function isn't implemented yet, use C<< $platform->context >> instead. |
635 | Consider using C<< $platform->context >> instead. |
628 | |
636 | |
629 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html> |
637 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateContext.html> |
630 | |
638 | |
631 | =item OpenCL::wait_for_events $wait_events... |
639 | =item OpenCL::wait_for_events $wait_events... |
632 | |
640 | |
… | |
… | |
1263 | =item $program = $ctx->program_with_built_in_kernels (\@devices, $kernel_names) |
1271 | =item $program = $ctx->program_with_built_in_kernels (\@devices, $kernel_names) |
1264 | |
1272 | |
1265 | Creates a new OpenCL::Program object from the given built-in kernel names. |
1273 | Creates a new OpenCL::Program object from the given built-in kernel names. |
1266 | |
1274 | |
1267 | L<http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateProgramWithBuiltInKernels.html> |
1275 | L<http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateProgramWithBuiltInKernels.html> |
|
|
1276 | |
|
|
1277 | =item $program = $ctx->link_program (\@devices, $options, \@programs, $cb->($program) = undef) |
|
|
1278 | |
|
|
1279 | Links all (already compiled) program objects specified in C<@programs> |
|
|
1280 | together and returns a new OpenCL::Program object with the result. |
|
|
1281 | |
|
|
1282 | L<http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clLinkProgram.html> |
1268 | |
1283 | |
1269 | =item $packed_value = $ctx->info ($name) |
1284 | =item $packed_value = $ctx->info ($name) |
1270 | |
1285 | |
1271 | See C<< $platform->info >> for details. |
1286 | See C<< $platform->info >> for details. |
1272 | |
1287 | |
… | |
… | |
1766 | C<-cl-mad-enable>, C<-cl-no-signed-zeros>, C<-cl-unsafe-math-optimizations>, |
1781 | C<-cl-mad-enable>, C<-cl-no-signed-zeros>, C<-cl-unsafe-math-optimizations>, |
1767 | C<-cl-finite-math-only>, C<-cl-fast-relaxed-math>, |
1782 | C<-cl-finite-math-only>, C<-cl-fast-relaxed-math>, |
1768 | C<-w>, C<-Werror>, C<-cl-std=CL1.1/CL1.2>, C<-cl-kernel-arg-info>, |
1783 | C<-w>, C<-Werror>, C<-cl-std=CL1.1/CL1.2>, C<-cl-kernel-arg-info>, |
1769 | C<-create-library>, C<-enable-link-options>. |
1784 | C<-create-library>, C<-enable-link-options>. |
1770 | |
1785 | |
|
|
1786 | build_status: OpenCL::BUILD_SUCCESS, OpenCL::BUILD_NONE, |
|
|
1787 | OpenCL::BUILD_ERROR, OpenCL::BUILD_IN_PROGRESS. |
|
|
1788 | |
1771 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clBuildProgram.html> |
1789 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clBuildProgram.html> |
1772 | |
1790 | |
1773 | =item $program->build_async (\@devices = undef, $options = "", $cb->($program) = undef) |
1791 | =item $program->build_async (\@devices = undef, $options = "", $cb->($program) = undef) |
1774 | |
1792 | |
1775 | Similar to C<< ->build >>, except it starts a thread, and never fails (you |
1793 | Similar to C<< ->build >>, except it starts a thread, and never fails (you |
1776 | need to check the compilation status form the callback, or by polling). |
1794 | need to check the compilation status form the callback, or by polling). |
1777 | |
1795 | |
|
|
1796 | =item $program->compile (\@devices = undef, $options = "", \%headers = undef, $cb->($program) = undef) |
|
|
1797 | |
|
|
1798 | Compiles the given program for the given devices (or all devices if |
|
|
1799 | undef). If C<$headers> is given, it must be a hashref with include name => |
|
|
1800 | OpenCL::Program pairs. |
|
|
1801 | |
|
|
1802 | L<http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCompileProgram.html> |
|
|
1803 | |
1778 | =item $packed_value = $program->build_info ($device, $name) |
1804 | =item $packed_value = $program->build_info ($device, $name) |
1779 | |
1805 | |
1780 | Similar to C<< $platform->info >>, but returns build info for a previous |
1806 | Similar to C<< $platform->info >>, but returns build info for a previous |
1781 | build attempt for the given device. |
1807 | build attempt for the given device. |
1782 | |
1808 | |
… | |
… | |
1798 | =for gengetinfo begin program_build |
1824 | =for gengetinfo begin program_build |
1799 | |
1825 | |
1800 | =item $build_status = $program->build_status ($device) |
1826 | =item $build_status = $program->build_status ($device) |
1801 | |
1827 | |
1802 | Calls C<clGetProgramBuildInfo> with C<OpenCL::PROGRAM_BUILD_STATUS> and returns the result. |
1828 | Calls C<clGetProgramBuildInfo> with C<OpenCL::PROGRAM_BUILD_STATUS> and returns the result. |
1803 | |
|
|
1804 | build_status: OpenCL::BUILD_SUCCESS, OpenCL::BUILD_NONE, |
|
|
1805 | OpenCL::BUILD_ERROR, OpenCL::BUILD_IN_PROGRESS. |
|
|
1806 | |
1829 | |
1807 | =item $string = $program->build_options ($device) |
1830 | =item $string = $program->build_options ($device) |
1808 | |
1831 | |
1809 | Calls C<clGetProgramBuildInfo> with C<OpenCL::PROGRAM_BUILD_OPTIONS> and returns the result. |
1832 | Calls C<clGetProgramBuildInfo> with C<OpenCL::PROGRAM_BUILD_OPTIONS> and returns the result. |
1810 | |
1833 | |
… | |
… | |
1897 | |
1920 | |
1898 | =item $packed_value = $kernel->work_group_info ($device, $name) |
1921 | =item $packed_value = $kernel->work_group_info ($device, $name) |
1899 | |
1922 | |
1900 | See C<< $platform->info >> for details. |
1923 | See C<< $platform->info >> for details. |
1901 | |
1924 | |
1902 | The reason this method is not called C<info> is that there already is an |
|
|
1903 | C<< ->info >> method. |
|
|
1904 | |
|
|
1905 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetKernelWorkGroupInfo.html> |
1925 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetKernelWorkGroupInfo.html> |
1906 | |
1926 | |
1907 | =for gengetinfo begin kernel_work_group |
1927 | =for gengetinfo begin kernel_work_group |
1908 | |
1928 | |
1909 | =item $int = $kernel->work_group_size ($device) |
1929 | =item $int = $kernel->work_group_size ($device) |
… | |
… | |
1925 | =item $ulong = $kernel->private_mem_size ($device) |
1945 | =item $ulong = $kernel->private_mem_size ($device) |
1926 | |
1946 | |
1927 | Calls C<clGetKernelWorkGroupInfo> with C<OpenCL::KERNEL_PRIVATE_MEM_SIZE> and returns the result. |
1947 | Calls C<clGetKernelWorkGroupInfo> with C<OpenCL::KERNEL_PRIVATE_MEM_SIZE> and returns the result. |
1928 | |
1948 | |
1929 | =for gengetinfo end kernel_work_group |
1949 | =for gengetinfo end kernel_work_group |
|
|
1950 | |
|
|
1951 | =item $packed_value = $kernel->arg_info ($idx, $name) |
|
|
1952 | |
|
|
1953 | See C<< $platform->info >> for details. |
|
|
1954 | |
|
|
1955 | L<http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clGetKernelArgInfo.html> |
|
|
1956 | |
|
|
1957 | =for gengetinfo begin kernel_arg |
|
|
1958 | |
|
|
1959 | =item $kernel_arg_address_qualifier = $kernel->arg_address_qualifier ($idx) |
|
|
1960 | |
|
|
1961 | Calls C<clGetKernelArgInfo> with C<OpenCL::KERNEL_ARG_ADDRESS_QUALIFIER> and returns the result. |
|
|
1962 | |
|
|
1963 | =item $kernel_arg_access_qualifier = $kernel->arg_access_qualifier ($idx) |
|
|
1964 | |
|
|
1965 | Calls C<clGetKernelArgInfo> with C<OpenCL::KERNEL_ARG_ACCESS_QUALIFIER> and returns the result. |
|
|
1966 | |
|
|
1967 | =item $string = $kernel->arg_type_name ($idx) |
|
|
1968 | |
|
|
1969 | Calls C<clGetKernelArgInfo> with C<OpenCL::KERNEL_ARG_TYPE_NAME> and returns the result. |
|
|
1970 | |
|
|
1971 | =item $kernel_arg_type_qualifier = $kernel->arg_type_qualifier ($idx) |
|
|
1972 | |
|
|
1973 | Calls C<clGetKernelArgInfo> with C<OpenCL::KERNEL_ARG_TYPE_QUALIFIER> and returns the result. |
|
|
1974 | |
|
|
1975 | =item $string = $kernel->arg_name ($idx) |
|
|
1976 | |
|
|
1977 | Calls C<clGetKernelArgInfo> with C<OpenCL::KERNEL_ARG_NAME> and returns the result. |
|
|
1978 | |
|
|
1979 | =for gengetinfo end kernel_arg |
1930 | |
1980 | |
1931 | =item $kernel->setf ($format, ...) |
1981 | =item $kernel->setf ($format, ...) |
1932 | |
1982 | |
1933 | Sets the arguments of a kernel. Since OpenCL 1.1 doesn't have a generic |
1983 | Sets the arguments of a kernel. Since OpenCL 1.1 doesn't have a generic |
1934 | way to set arguments (and with OpenCL 1.2 it might be rather slow), you |
1984 | way to set arguments (and with OpenCL 1.2 it might be rather slow), you |