]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/example/host_sort.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/spirit/include/karma.hpp>
16 #include <boost/compute/system.hpp>
17 #include <boost/compute/algorithm/sort.hpp>
19 namespace compute
= boost::compute
;
20 namespace karma
= boost::spirit::karma
;
27 // this example demonstrates how to sort a std::vector of ints on the GPU
30 // get default device and setup context
31 compute::device gpu
= compute::system::default_device();
32 compute::context
context(gpu
);
33 compute::command_queue
queue(context
, gpu
);
34 std::cout
<< "device: " << gpu
.name() << std::endl
;
36 // create vector of random values on the host
37 std::vector
<int> vector(8);
38 std::generate(vector
.begin(), vector
.end(), rand_int
);
41 std::cout
<< "input: [ "
42 << karma::format(karma::int_
% ", ", vector
)
47 compute::sort(vector
.begin(), vector
.end(), queue
);
49 // print sorted vector
50 std::cout
<< "output: [ "
51 << karma::format(karma::int_
% ", ", vector
)