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/count.h>
16 #include <bolt/cl/copy.h>
17 #include <bolt/cl/device_vector.h>
18 
19 #include "perf.hpp"
20 
rand_int()21 int rand_int()
22 {
23     return static_cast<int>((rand() / double(RAND_MAX)) * 25.0);
24 }
25 
main(int argc,char * argv[])26 int main(int argc, char *argv[])
27 {
28     perf_parse_args(argc, argv);
29 
30     std::cout << "size: " << PERF_N << std::endl;
31 
32     bolt::cl::control ctrl = bolt::cl::control::getDefault();
33     ::cl::Device device = ctrl.getDevice();
34     std::cout << "device: " << device.getInfo<CL_DEVICE_NAME>() << std::endl;
35 
36     // create vector of random numbers on the host
37     std::vector<int> h_vec(PERF_N);
38     std::generate(h_vec.begin(), h_vec.end(), rand_int);
39 
40     // create device vector
41     bolt::cl::device_vector<int> d_vec(PERF_N);
42 
43     // transfer data to the device
44     bolt::cl::copy(h_vec.begin(), h_vec.end(), d_vec.begin());
45 
46     size_t count = 0;
47     perf_timer t;
48     for(size_t trial = 0; trial < PERF_TRIALS; trial++){
49         t.start();
50         count = bolt::cl::count(ctrl, d_vec.begin(), d_vec.end(), 4);
51         t.stop();
52     }
53     std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
54     std::cout << "count: " << count << std::endl;
55 
56     return 0;
57 }
58