• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2015 Jakub Szuppe <j.szuppe@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 <algorithm>
13 #include <vector>
14 
15 #include <bolt/cl/merge.h>
16 #include <bolt/cl/copy.h>
17 #include <bolt/cl/device_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 
27     bolt::cl::control ctrl = bolt::cl::control::getDefault();
28     ::cl::Device device = ctrl.getDevice();
29     std::cout << "device: " << device.getInfo<CL_DEVICE_NAME>() << std::endl;
30 
31     // create vector of random numbers on the host
32     std::vector<int> host_vec1 = generate_random_vector<int>(std::floor(PERF_N / 2.0));
33     std::vector<int> host_vec2 = generate_random_vector<int>(std::ceil(PERF_N / 2.0));
34     // sort them
35     std::sort(host_vec1.begin(), host_vec1.end());
36     std::sort(host_vec2.begin(), host_vec2.end());
37 
38     // create device vectors
39     bolt::cl::device_vector<int> device_vec1(PERF_N);
40     bolt::cl::device_vector<int> device_vec2(PERF_N);
41     bolt::cl::device_vector<int> device_vec3(PERF_N);
42 
43     // transfer data to the device
44     bolt::cl::copy(host_vec1.begin(), host_vec1.end(), device_vec1.begin());
45     bolt::cl::copy(host_vec2.begin(), host_vec2.end(), device_vec2.begin());
46 
47     perf_timer t;
48     for(size_t trial = 0; trial < PERF_TRIALS; trial++){
49         t.start();
50         bolt::cl::merge(
51             device_vec1.begin(), device_vec1.end(),
52             device_vec2.begin(), device_vec2.end(),
53             device_vec3.begin()
54         );
55         t.stop();
56     }
57     std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
58 
59     return 0;
60 }
61