]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/perf/perf_count.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 //---------------------------------------------------------------------------//
15 #include <boost/compute/system.hpp>
16 #include <boost/compute/algorithm/count.hpp>
17 #include <boost/compute/container/vector.hpp>
23 return static_cast<int>((rand() / double(RAND_MAX
)) * 25.0);
26 int main(int argc
, char *argv
[])
28 perf_parse_args(argc
, argv
);
29 std::cout
<< "size: " << PERF_N
<< std::endl
;
31 // setup context and queue for the default device
32 boost::compute::device device
= boost::compute::system::default_device();
33 boost::compute::context
context(device
);
34 boost::compute::command_queue
queue(context
, device
);
35 std::cout
<< "device: " << device
.name() << std::endl
;
37 // create vector of random numbers on the host
38 std::vector
<int> host_vector(PERF_N
);
39 std::generate(host_vector
.begin(), host_vector
.end(), rand_int
);
41 // create vector on the device and copy the data
42 boost::compute::vector
<int> device_vector(PERF_N
, context
);
46 device_vector
.begin(),
52 for(size_t trial
= 0; trial
< PERF_TRIALS
; trial
++){
54 count
= boost::compute::count(
55 device_vector
.begin(), device_vector
.end(), 4, queue
60 std::cout
<< "time: " << t
.min_time() / 1e6
<< " ms" << std::endl
;
61 std::cout
<< "count: " << count
<< std::endl
;
63 // verify count is correct
64 size_t host_count
= std::count(host_vector
.begin(),
67 if(count
!= host_count
){
68 std::cout
<< "ERROR: "
69 << "device_count (" << count
<< ") "
71 << "host_count (" << host_count
<< ")"