• 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 <iostream>
12 #include <iterator>
13 #include <algorithm>
14 
15 #include <thrust/device_vector.h>
16 #include <thrust/host_vector.h>
17 #include <thrust/inner_product.h>
18 
19 #include "perf.hpp"
20 
main(int argc,char * argv[])21 int main(int argc, char *argv[])
22 {
23     perf_parse_args(argc, argv);
24 
25     std::cout << "size: " << PERF_N << std::endl;
26     thrust::host_vector<int> host_x(PERF_N);
27     thrust::host_vector<int> host_y(PERF_N);
28     std::generate(host_x.begin(), host_x.end(), rand);
29     std::generate(host_y.begin(), host_y.end(), rand);
30 
31     // transfer data to the device
32     thrust::device_vector<int> device_x = host_x;
33     thrust::device_vector<int> device_y = host_y;
34 
35     int product = 0;
36     perf_timer t;
37     for(size_t trial = 0; trial < PERF_TRIALS; trial++){
38         t.start();
39         product = thrust::inner_product(
40             device_x.begin(), device_x.end(), device_y.begin(), 0
41         );
42         cudaDeviceSynchronize();
43         t.stop();
44     }
45     std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
46     std::cout << "product: " << product << std::endl;
47 
48     return 0;
49 }
50