• 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/copy.h>
16 #include <bolt/cl/device_vector.h>
17 #include <bolt/cl/reduce.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 host vector
32     std::vector<int> host_vec = generate_random_vector<int>(PERF_N);
33 
34     // create device vectors
35     bolt::cl::device_vector<int> device_vec(PERF_N);
36 
37     // transfer data to the device
38     bolt::cl::copy(host_vec.begin(), host_vec.end(), device_vec.begin());
39 
40     int sum = 0;
41     perf_timer t;
42     for(size_t trial = 0; trial < PERF_TRIALS; trial++){
43         t.start();
44         sum = bolt::cl::reduce(device_vec.begin(), device_vec.end());
45         t.stop();
46     }
47     std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
48     std::cout << "sum: " << sum << std::endl;
49 
50     return 0;
51 }
52