1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
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
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10 
11 #include <algorithm>
12 #include <iostream>
13 #include <vector>
14 
15 #include <thrust/count.h>
16 #include <thrust/host_vector.h>
17 #include <thrust/device_vector.h>
18 
19 #include "perf.hpp"
20 
rand_int()21 int rand_int()
22 {
23     return static_cast<int>((rand() / double(RAND_MAX)) * 25.0);
24 }
25 
main(int argc,char * argv[])26 int main(int argc, char *argv[])
27 {
28     perf_parse_args(argc, argv);
29     std::cout << "size: " << PERF_N << std::endl;
30 
31     // create vector of random numbers on the host
32     thrust::host_vector<int> host_vector(PERF_N);
33     thrust::generate(host_vector.begin(), host_vector.end(), rand_int);
34 
35     thrust::device_vector<int> v = host_vector;
36 
37     size_t count = 0;
38     perf_timer t;
39     for(size_t trial = 0; trial < PERF_TRIALS; trial++){
40         t.start();
41         count = thrust::count(v.begin(), v.end(), 4);
42         cudaDeviceSynchronize();
43         t.stop();
44     }
45     std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
46     std::cout << "count: " << count << std::endl;
47 
48     return 0;
49 }
50