• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cstdlib>
13 #include <iostream>
14 
15 #include <thrust/copy.h>
16 #include <thrust/device_vector.h>
17 #include <thrust/generate.h>
18 #include <thrust/host_vector.h>
19 #include <thrust/partition.h>
20 
21 #include "perf.hpp"
22 
rand_int()23 int rand_int()
24 {
25     return static_cast<int>((rand() / double(RAND_MAX)) * 25.0);
26 }
27 
28 struct less_than_ten : public thrust::unary_function<bool, int>
29 {
operator ()less_than_ten30     __device__ bool operator()(int x) const
31     {
32         return x < 10;
33     }
34 };
35 
main(int argc,char * argv[])36 int main(int argc, char *argv[])
37 {
38     perf_parse_args(argc, argv);
39 
40     std::cout << "size: " << PERF_N << std::endl;
41     thrust::host_vector<int> h_vec(PERF_N);
42     std::generate(h_vec.begin(), h_vec.end(), rand_int);
43 
44     thrust::device_vector<int> d_vec(PERF_N);
45 
46     perf_timer t;
47     for(size_t trial = 0; trial < PERF_TRIALS; trial++){
48         d_vec = h_vec;
49 
50         t.start();
51         thrust::partition(
52             d_vec.begin(), d_vec.end(), less_than_ten()
53         );
54         cudaDeviceSynchronize();
55         t.stop();
56     }
57     std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
58 
59     return 0;
60 }
61