]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/example/mapped_view.cpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
14 #include <boost/compute/system.hpp>
15 #include <boost/compute/algorithm/reduce.hpp>
16 #include <boost/compute/container/mapped_view.hpp>
18 namespace compute
= boost::compute
;
20 // this example demonstrates how to use the mapped_view class to map
21 // an array of numbers to device memory and use the reduce() algorithm
22 // to calculate the sum.
25 // get default device and setup context
26 compute::device gpu
= compute::system::default_device();
27 compute::context
context(gpu
);
28 compute::command_queue
queue(context
, gpu
);
29 std::cout
<< "device: " << gpu
.name() << std::endl
;
31 // create data on host
32 int data
[] = { 4, 2, 3, 7, 8, 9, 1, 6 };
34 // create mapped view on device
35 compute::mapped_view
<int> view(data
, 8, context
);
37 // use reduce() to calculate sum on the device
39 compute::reduce(view
.begin(), view
.end(), &sum
, queue
);
41 // print the sum on the host
42 std::cout
<< "sum: " << sum
<< std::endl
;