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

Comparing OpenCL/OpenCL.pm (file contents):
Revision 1.3 by root, Tue Nov 15 20:38:07 2011 UTC vs.
Revision 1.4 by root, Tue Nov 15 21:16:19 2011 UTC

80 eval { $prog->build ($dev); 1 } 80 eval { $prog->build ($dev); 1 }
81 or die $prog->build_info ($dev, OpenCL::PROGRAM_BUILD_LOG); 81 or die $prog->build_info ($dev, OpenCL::PROGRAM_BUILD_LOG);
82 82
83 my $kernel = $prog->kernel ("squareit"); 83 my $kernel = $prog->kernel ("squareit");
84 84
85Create some input and output float buffers, then call squareit on them:
86
87 my $input = $ctx->buffer_sv (OpenCL::MEM_COPY_HOST_PTR, pack "f*", 1, 2, 3, 4.5);
88 my $output = $ctx->buffer (0, OpenCL::SIZEOF_FLOAT * 5);
89
90 # set buffer
91 $kernel->set_buffer (0, $input);
92 $kernel->set_buffer (1, $output);
93
94 # execute it for all 4 numbers
95 $queue->enqueue_nd_range_kernel ($kernel, undef, [4], undef);
96
97 # enqueue a barrier ot ensure in-order execution (not really needed in this case)
98 $queue->enqueue_barrier;
99
100 # enqueue an async read (could easily be blocking here though), then wait for it:
101 my $ev = $queue->enqueue_read_buffer ($output, 0, 0, OpenCL::SIZEOF_FLOAT * 4, my $data);
102 $ev->wait;
103
104 # print the results:
105 say join ", ", unpack "f*", $data;
106
85=over 4 107=over 4
86 108
87=cut 109=cut
88 110
89package OpenCL; 111package OpenCL;
90 112
91use common::sense; 113use common::sense;
92 114
93BEGIN { 115BEGIN {
94 our $VERSION = '0.01'; 116 our $VERSION = '0.02';
95 117
96 require XSLoader; 118 require XSLoader;
97 XSLoader::load (__PACKAGE__, $VERSION); 119 XSLoader::load (__PACKAGE__, $VERSION);
98 120
99 @OpenCL::Buffer::ISA = 121 @OpenCL::Buffer::ISA =

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines