… | |
… | |
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 | |
|
|
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 | } |
|
|
797 | |
778 | =item $queue = $ctx->queue ($device, $properties) |
798 | =item $queue = $ctx->queue ($device, $properties) |
779 | |
799 | |
780 | 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. |
781 | |
801 | |
782 | L<http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clCreateCommandQueue.html> |
802 | L<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 | |
1255 | 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. |
1256 | |
1277 | |
1257 | 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> |
1258 | |
1279 | |
1259 | =item $packed_value = $program->build_info ($device, $name) |
1280 | =item $packed_value = $program->build_info ($device, $name) |
1260 | |
1281 | |