ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/OpenCL/OpenCL.pm
(Generate patch)

Comparing OpenCL/OpenCL.pm (file contents):
Revision 1.50 by root, Tue Apr 24 13:30:49 2012 UTC vs.
Revision 1.51 by root, Tue Apr 24 13:45:58 2012 UTC

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) {
773 766
774=head2 THE OpenCL::Context CLASS 767=head2 THE OpenCL::Context CLASS
775 768
776=over 4 769=over 4
777 770
771=item $prog = $ctx->build_program ($program, $options = "")
772
773This convenience function tries to build the program on all devices in
774the context. If the build fails, then the function will C<croak> with the
775build log. Otherwise ti returns the program object.
776
777The C<$program> can either be a C<OpenCL::Program> object or a string
778containing the program. In the latter case, a program objetc will be
779created automatically.
780
781=cut
782
783sub 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}
797
778=item $queue = $ctx->queue ($device, $properties) 798=item $queue = $ctx->queue ($device, $properties)
779 799
780Create a new OpenCL::Queue object from the context and the given device. 800Create a new OpenCL::Queue object from the context and the given device.
781 801
782L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateCommandQueue.html> 802L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateCommandQueue.html>
1250 1270
1251=over 4 1271=over 4
1252 1272
1253=item $program->build ($device, $options = "") 1273=item $program->build ($device, $options = "")
1254 1274
1255Tries to build the program with the givne options. 1275Tries to build the program with the given options. See also the
1276C<$ctx->build> convenience function.
1256 1277
1257L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clBuildProgram.html> 1278L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clBuildProgram.html>
1258 1279
1259=item $packed_value = $program->build_info ($device, $name) 1280=item $packed_value = $program->build_info ($device, $name)
1260 1281

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines