perf_bolt_exclusive_scan.cpp 1.6 KB

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