perf_bolt_count.cpp 1.6 KB

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