--- OpenCL/OpenCL.pm 2012/04/21 17:50:27 1.45 +++ OpenCL/OpenCL.pm 2012/04/24 13:45:58 1.51 @@ -159,12 +159,7 @@ } '; - my $prog = $ctx->program_with_source ($src); - - # build croaks on compile errors, so catch it and print the compile errors - eval { $prog->build ($dev, "-cl-fast-relaxed-math"); 1 } - or die $prog->build_log; - + my $prog = $ctx->build_program ($src); my $kernel = $prog->kernel ("squareit"); =head2 Create some input and output float buffers, then call the @@ -269,10 +264,8 @@ write_imagef (img, (int2)(get_global_id (0), get_global_id (1)), (float4)(colour * p.x * p.x, 1.)); } EOF - my $prog = $ctx->program_with_source ($src); - eval { $prog->build ($dev); 1 } - or die $prog->build_log ($dev); + my $prog = $ctx->build_program ($src); my $kernel = $prog->kernel ("juliatunnel"); # program compiled, kernel ready, now draw and loop @@ -458,6 +451,13 @@ L +=item $platform->unload_compiler + +Attempts to unload the compiler for this platform, for endless +profit. Does nothing on OpenCL 1.1. + +L + =for gengetinfo begin platform =item $string = $platform->profile @@ -754,7 +754,7 @@ =item $uint = $device->reference_count_ext -Calls C with C and returns the result. +Calls C with C and returns the result. =item @device_partition_property_exts = $device->partition_style_ext @@ -768,6 +768,33 @@ =over 4 +=item $prog = $ctx->build_program ($program, $options = "") + +This convenience function tries to build the program on all devices in +the context. If the build fails, then the function will C with the +build log. Otherwise ti returns the program object. + +The C<$program> can either be a C object or a string +containing the program. In the latter case, a program objetc will be +created automatically. + +=cut + +sub OpenCL::Context::build_program { + my ($self, $prog, $options) = @_; + + $prog = $self->program_with_source ($prog) + unless ref $prog; + + 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 +} + =item $queue = $ctx->queue ($device, $properties) Create a new OpenCL::Queue object from the context and the given device. @@ -796,6 +823,13 @@ Creates a new OpenCL::Buffer (actually OpenCL::BufferObj) object and initialise it with the given data values. +=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) + +Creates a new OpenCL::Image object and optionally initialises it with +the given data values. + +L + =item $img = $ctx->image2d ($flags, $channel_order, $channel_type, $width, $height, $row_pitch = 0, $data = undef) Creates a new OpenCL::Image2D object and optionally initialises it with @@ -817,14 +851,21 @@ http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLBuffer.html -=item $ctx->gl_texture2d ($flags, $target, $miplevel, $texture) +=item $img = $ctx->gl_texture ($flags, $target, $miplevel, $texture) + +Creates a new OpenCL::Image object that refers to the given OpenGL +texture object or buffer. + +http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateFromGLTexture.html + +=item $img = $ctx->gl_texture2d ($flags, $target, $miplevel, $texture) Creates a new OpenCL::Image2D object that refers to the given OpenGL 2D texture object. http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateFromGLTexture2D.html -=item $ctx->gl_texture3d ($flags, $target, $miplevel, $texture) +=item $img = $ctx->gl_texture3d ($flags, $target, $miplevel, $texture) Creates a new OpenCL::Image3D object that refers to the given OpenGL 3D texture object. @@ -983,10 +1024,6 @@ L -=item $ev = $queue->enqueue_marker ($wait_events...) - -L - =item $ev = $queue->enqueue_acquire_gl_objects ([object, ...], $wait_events...) Enqueues a list (an array-ref of OpenCL::Memory objects) to be acquired @@ -1005,9 +1042,13 @@ L -=item $queue->enqueue_barrier +=item $ev = $queue->enqueue_marker ($wait_events...) + +L + +=item $ev = $queue->enqueue_barrier ($wait_events...) -L +L =item $queue->flush @@ -1132,7 +1173,9 @@ =head2 THE OpenCL::Image CLASS -This is the superclass of all image objects - OpenCL::Image2D and OpenCL::Image3D. +This is the superclass of all image objects - OpenCL::Image1D, +OpenCL::Image1DArray, OpenCL::Image1DBuffer, OpenCL::Image2D, +OpenCL::Image2DArray and OpenCL::Image3D. =over 4 @@ -1229,7 +1272,8 @@ =item $program->build ($device, $options = "") -Tries to build the program with the givne options. +Tries to build the program with the given options. See also the +C<$ctx->build> convenience function. L @@ -1247,6 +1291,12 @@ L +=item @kernels = $program->kernels_in_program + +Returns all kernels successfully compiled for all devices in program. + +http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateKernelsInProgram.html + =for gengetinfo begin program_build =item $build_status = $program->build_status ($device) @@ -1391,6 +1441,10 @@ set by specifying the size, and sampler and event must be objects of that type. +Setting an argument for a kernel does NOT keep a reference to the object - +for example, if you set an argument to some image object, free the image, +and call the kernel, you will run into undefined behaviour. + L =back @@ -1493,15 +1547,19 @@ require XSLoader; XSLoader::load (__PACKAGE__, $VERSION); - @OpenCL::Buffer::ISA = - @OpenCL::Image::ISA = OpenCL::Memory::; + @OpenCL::Buffer::ISA = + @OpenCL::Image::ISA = OpenCL::Memory::; - @OpenCL::BufferObj::ISA = OpenCL::Buffer::; + @OpenCL::BufferObj::ISA = OpenCL::Buffer::; - @OpenCL::Image2D::ISA = - @OpenCL::Image3D::ISA = OpenCL::Image::; + @OpenCL::Image2D::ISA = + @OpenCL::Image3D::ISA = + @OpenCL::Image2DArray::ISA = + @OpenCL::Image1D::ISA = + @OpenCL::Image1DArray::ISA = + @OpenCL::Image1DBuffer::ISA = OpenCL::Image::; - @OpenCL::UserEvent::ISA = OpenCL::Event::; + @OpenCL::UserEvent::ISA = OpenCL::Event::; } 1;