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/set_operations.h>
18 #include <thrust/sort.h>
19
20 #include "perf.hpp"
21
rand_int()22 int rand_int()
23 {
24 return static_cast<int>((rand() / double(RAND_MAX)) * 25.0);
25 }
26
main(int argc,char * argv[])27 int main(int argc, char *argv[])
28 {
29 perf_parse_args(argc, argv);
30
31 std::cout << "size: " << PERF_N << std::endl;
32 thrust::host_vector<int> v1(std::floor(PERF_N / 2.0));
33 thrust::host_vector<int> v2(std::ceil(PERF_N / 2.0));
34 std::generate(v1.begin(), v1.end(), rand_int);
35 std::generate(v2.begin(), v2.end(), rand_int);
36 std::sort(v1.begin(), v1.end());
37 std::sort(v2.begin(), v2.end());
38
39 // transfer data to the device
40 thrust::device_vector<int> gpu_v1 = v1;
41 thrust::device_vector<int> gpu_v2 = v2;
42 thrust::device_vector<int> gpu_v3(PERF_N);
43
44 thrust::device_vector<int>::iterator gpu_v3_end;
45
46 perf_timer t;
47 for(size_t trial = 0; trial < PERF_TRIALS; trial++){
48 t.start();
49 gpu_v3_end = thrust::set_difference(
50 gpu_v1.begin(), gpu_v1.end(),
51 gpu_v2.begin(), gpu_v2.end(),
52 gpu_v3.begin()
53 );
54 cudaDeviceSynchronize();
55 t.stop();
56 }
57 std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
58 std::cout << "size: " << thrust::distance(gpu_v3.begin(), gpu_v3_end) << std::endl;
59
60 return 0;
61 }
62