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 <algorithm>
12 #include <cstdlib>
13 #include <vector>
14 
15 #include <bolt/cl/sort.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     ::cl::Device device = bolt::cl::control::getDefault().getDevice();
28     std::cout << "device: " << device.getInfo<CL_DEVICE_NAME>() << std::endl;
29 
30     // create host vector
31     std::vector<int> h_vec = generate_random_vector<int>(PERF_N);
32     // create device vector
33     bolt::cl::device_vector<int> d_vec(PERF_N);
34 
35     perf_timer t;
36     for(size_t trial = 0; trial < PERF_TRIALS; trial++){
37         // transfer data to the device
38         bolt::cl::copy(h_vec.begin(), h_vec.end(), d_vec.begin());
39 
40         t.start();
41         bolt::cl::sort(d_vec.begin(), d_vec.end());
42         t.stop();
43     }
44     std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
45 
46     // transfer data back to host
47     bolt::cl::copy(d_vec.begin(), d_vec.end(), h_vec.begin());
48 
49     return 0;
50 }
51