… | |
… | |
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, "-cl-fast-relaxed-math"); 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) { |
… | |
… | |
456 | It's best to avoid this method and use one of the following convenience |
449 | It's best to avoid this method and use one of the following convenience |
457 | wrappers. |
450 | wrappers. |
458 | |
451 | |
459 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformInfo.html> |
452 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetPlatformInfo.html> |
460 | |
453 | |
|
|
454 | =item $platform->unload_compiler |
|
|
455 | |
|
|
456 | Attempts to unload the compiler for this platform, for endless |
|
|
457 | profit. Does nothing on OpenCL 1.1. |
|
|
458 | |
|
|
459 | L<http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clUnloadPlatformCompiler.html> |
|
|
460 | |
461 | =for gengetinfo begin platform |
461 | =for gengetinfo begin platform |
462 | |
462 | |
463 | =item $string = $platform->profile |
463 | =item $string = $platform->profile |
464 | |
464 | |
465 | Calls C<clGetPlatformInfo> with C<CL_PLATFORM_PROFILE> and returns the result. |
465 | Calls C<clGetPlatformInfo> with C<CL_PLATFORM_PROFILE> and returns the result. |
… | |
… | |
752 | |
752 | |
753 | Calls C<clGetDeviceInfo> with C<CL_DEVICE_AFFINITY_DOMAINS_EXT> and returns the result. |
753 | Calls C<clGetDeviceInfo> with C<CL_DEVICE_AFFINITY_DOMAINS_EXT> and returns the result. |
754 | |
754 | |
755 | =item $uint = $device->reference_count_ext |
755 | =item $uint = $device->reference_count_ext |
756 | |
756 | |
757 | Calls C<clGetDeviceInfo> with C<CL_DEVICE_REFERENCE_COUNT_EXT > and returns the result. |
757 | Calls C<clGetDeviceInfo> with C<CL_DEVICE_REFERENCE_COUNT_EXT> and returns the result. |
758 | |
758 | |
759 | =item @device_partition_property_exts = $device->partition_style_ext |
759 | =item @device_partition_property_exts = $device->partition_style_ext |
760 | |
760 | |
761 | Calls C<clGetDeviceInfo> with C<CL_DEVICE_PARTITION_STYLE_EXT> and returns the result. |
761 | Calls C<clGetDeviceInfo> with C<CL_DEVICE_PARTITION_STYLE_EXT> and returns the result. |
762 | |
762 | |
… | |
… | |
765 | =back |
765 | =back |
766 | |
766 | |
767 | =head2 THE OpenCL::Context CLASS |
767 | =head2 THE OpenCL::Context CLASS |
768 | |
768 | |
769 | =over 4 |
769 | =over 4 |
|
|
770 | |
|
|
771 | =item $prog = $ctx->build_program ($program, $options = "") |
|
|
772 | |
|
|
773 | This convenience function tries to build the program on all devices in |
|
|
774 | the context. If the build fails, then the function will C<croak> with the |
|
|
775 | build log. Otherwise ti returns the program object. |
|
|
776 | |
|
|
777 | The C<$program> can either be a C<OpenCL::Program> object or a string |
|
|
778 | containing the program. In the latter case, a program objetc will be |
|
|
779 | created automatically. |
|
|
780 | |
|
|
781 | =cut |
|
|
782 | |
|
|
783 | sub 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 | } |
770 | |
797 | |
771 | =item $queue = $ctx->queue ($device, $properties) |
798 | =item $queue = $ctx->queue ($device, $properties) |
772 | |
799 | |
773 | Create a new OpenCL::Queue object from the context and the given device. |
800 | Create a new OpenCL::Queue object from the context and the given device. |
774 | |
801 | |
… | |
… | |
794 | =item $buf = $ctx->buffer_sv ($flags, $data) |
821 | =item $buf = $ctx->buffer_sv ($flags, $data) |
795 | |
822 | |
796 | Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and |
823 | Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and |
797 | initialise it with the given data values. |
824 | initialise it with the given data values. |
798 | |
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 | |
|
|
828 | Creates a new OpenCL::Image object and optionally initialises it with |
|
|
829 | the given data values. |
|
|
830 | |
|
|
831 | L<http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateImage.html> |
|
|
832 | |
799 | =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) |
800 | |
834 | |
801 | Creates a new OpenCL::Image2D object and optionally initialises it with |
835 | Creates a new OpenCL::Image2D object and optionally initialises it with |
802 | the given data values. |
836 | the given data values. |
803 | |
837 | |
… | |
… | |
815 | Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object that refers to the given |
849 | Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object that refers to the given |
816 | OpenGL buffer object. |
850 | OpenGL buffer object. |
817 | |
851 | |
818 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLBuffer.html |
852 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLBuffer.html |
819 | |
853 | |
|
|
854 | =item $img = $ctx->gl_texture ($flags, $target, $miplevel, $texture) |
|
|
855 | |
|
|
856 | Creates a new OpenCL::Image object that refers to the given OpenGL |
|
|
857 | texture object or buffer. |
|
|
858 | |
|
|
859 | http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateFromGLTexture.html |
|
|
860 | |
820 | =item $ctx->gl_texture2d ($flags, $target, $miplevel, $texture) |
861 | =item $img = $ctx->gl_texture2d ($flags, $target, $miplevel, $texture) |
821 | |
862 | |
822 | Creates a new OpenCL::Image2D object that refers to the given OpenGL |
863 | Creates a new OpenCL::Image2D object that refers to the given OpenGL |
823 | 2D texture object. |
864 | 2D texture object. |
824 | |
865 | |
825 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLTexture2D.html |
866 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLTexture2D.html |
826 | |
867 | |
827 | =item $ctx->gl_texture3d ($flags, $target, $miplevel, $texture) |
868 | =item $img = $ctx->gl_texture3d ($flags, $target, $miplevel, $texture) |
828 | |
869 | |
829 | Creates a new OpenCL::Image3D object that refers to the given OpenGL |
870 | Creates a new OpenCL::Image3D object that refers to the given OpenGL |
830 | 3D texture object. |
871 | 3D texture object. |
831 | |
872 | |
832 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLTexture3D.html |
873 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLTexture3D.html |
… | |
… | |
1130 | |
1171 | |
1131 | =back |
1172 | =back |
1132 | |
1173 | |
1133 | =head2 THE OpenCL::Image CLASS |
1174 | =head2 THE OpenCL::Image CLASS |
1134 | |
1175 | |
1135 | This is the superclass of all image objects - OpenCL::Image2D and OpenCL::Image3D. |
1176 | This is the superclass of all image objects - OpenCL::Image1D, |
|
|
1177 | OpenCL::Image1DArray, OpenCL::Image1DBuffer, OpenCL::Image2D, |
|
|
1178 | OpenCL::Image2DArray and OpenCL::Image3D. |
1136 | |
1179 | |
1137 | =over 4 |
1180 | =over 4 |
1138 | |
1181 | |
1139 | =item $packed_value = $ev->image_info ($name) |
1182 | =item $packed_value = $ev->image_info ($name) |
1140 | |
1183 | |
… | |
… | |
1227 | |
1270 | |
1228 | =over 4 |
1271 | =over 4 |
1229 | |
1272 | |
1230 | =item $program->build ($device, $options = "") |
1273 | =item $program->build ($device, $options = "") |
1231 | |
1274 | |
1232 | Tries to build the program with the givne options. |
1275 | Tries to build the program with the given options. See also the |
|
|
1276 | C<$ctx->build> convenience function. |
1233 | |
1277 | |
1234 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clBuildProgram.html> |
1278 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clBuildProgram.html> |
1235 | |
1279 | |
1236 | =item $packed_value = $program->build_info ($device, $name) |
1280 | =item $packed_value = $program->build_info ($device, $name) |
1237 | |
1281 | |
… | |
… | |
1244 | |
1288 | |
1245 | Creates an OpenCL::Kernel object out of the named C<__kernel> function in |
1289 | Creates an OpenCL::Kernel object out of the named C<__kernel> function in |
1246 | the program. |
1290 | the program. |
1247 | |
1291 | |
1248 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateKernel.html> |
1292 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateKernel.html> |
|
|
1293 | |
|
|
1294 | =item @kernels = $program->kernels_in_program |
|
|
1295 | |
|
|
1296 | Returns all kernels successfully compiled for all devices in program. |
|
|
1297 | |
|
|
1298 | http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateKernelsInProgram.html |
1249 | |
1299 | |
1250 | =for gengetinfo begin program_build |
1300 | =for gengetinfo begin program_build |
1251 | |
1301 | |
1252 | =item $build_status = $program->build_status ($device) |
1302 | =item $build_status = $program->build_status ($device) |
1253 | |
1303 | |
… | |
… | |
1389 | float and double as floating point values, memory/buffer/image2d/image3d |
1439 | float and double as floating point values, memory/buffer/image2d/image3d |
1390 | must be an object of that type or C<undef>, local-memory arguments are |
1440 | must be an object of that type or C<undef>, local-memory arguments are |
1391 | set by specifying the size, and sampler and event must be objects of that |
1441 | set by specifying the size, and sampler and event must be objects of that |
1392 | type. |
1442 | type. |
1393 | |
1443 | |
|
|
1444 | Setting an argument for a kernel does NOT keep a reference to the object - |
|
|
1445 | for example, if you set an argument to some image object, free the image, |
|
|
1446 | and call the kernel, you will run into undefined behaviour. |
|
|
1447 | |
1394 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clSetKernelArg.html> |
1448 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clSetKernelArg.html> |
1395 | |
1449 | |
1396 | =back |
1450 | =back |
1397 | |
1451 | |
1398 | =head2 THE OpenCL::Event CLASS |
1452 | =head2 THE OpenCL::Event CLASS |
… | |
… | |
1491 | our $VERSION = '0.96'; |
1545 | our $VERSION = '0.96'; |
1492 | |
1546 | |
1493 | require XSLoader; |
1547 | require XSLoader; |
1494 | XSLoader::load (__PACKAGE__, $VERSION); |
1548 | XSLoader::load (__PACKAGE__, $VERSION); |
1495 | |
1549 | |
1496 | @OpenCL::Buffer::ISA = |
1550 | @OpenCL::Buffer::ISA = |
1497 | @OpenCL::Image::ISA = OpenCL::Memory::; |
1551 | @OpenCL::Image::ISA = OpenCL::Memory::; |
1498 | |
1552 | |
1499 | @OpenCL::BufferObj::ISA = OpenCL::Buffer::; |
1553 | @OpenCL::BufferObj::ISA = OpenCL::Buffer::; |
1500 | |
1554 | |
1501 | @OpenCL::Image2D::ISA = |
1555 | @OpenCL::Image2D::ISA = |
|
|
1556 | @OpenCL::Image3D::ISA = |
|
|
1557 | @OpenCL::Image2DArray::ISA = |
|
|
1558 | @OpenCL::Image1D::ISA = |
|
|
1559 | @OpenCL::Image1DArray::ISA = |
1502 | @OpenCL::Image3D::ISA = OpenCL::Image::; |
1560 | @OpenCL::Image1DBuffer::ISA = OpenCL::Image::; |
1503 | |
1561 | |
1504 | @OpenCL::UserEvent::ISA = OpenCL::Event::; |
1562 | @OpenCL::UserEvent::ISA = OpenCL::Event::; |
1505 | } |
1563 | } |
1506 | |
1564 | |
1507 | 1; |
1565 | 1; |
1508 | |
1566 | |
1509 | =head1 AUTHOR |
1567 | =head1 AUTHOR |