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/host_vector.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> h_vec = generate_random_vector<int>(PERF_N);
27
28 // transfer data to the device
29 thrust::device_vector<int> d_vec;
30
31 size_t rotate_distance = PERF_N / 2;
32
33 perf_timer t;
34 for(size_t trial = 0; trial < PERF_TRIALS; trial++){
35 d_vec = h_vec;
36
37 t.start();
38 // there is no thrust::rotate() so we implement it manually with copy()
39 thrust::device_vector<int> tmp(d_vec.begin(), d_vec.begin() + rotate_distance);
40 thrust::copy(d_vec.begin() + rotate_distance, d_vec.end(), d_vec.begin());
41 thrust::copy(tmp.begin(), tmp.end(), d_vec.begin() + rotate_distance);
42 cudaDeviceSynchronize();
43 t.stop();
44 }
45 std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
46
47 // transfer data back to host
48 thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());
49
50 return 0;
51 }
52