perf_bolt_accumulate.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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/copy.h>
  14. #include <bolt/cl/device_vector.h>
  15. #include <bolt/cl/reduce.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 host vector
  25. std::vector<int> host_vec = generate_random_vector<int>(PERF_N);
  26. // create device vectors
  27. bolt::cl::device_vector<int> device_vec(PERF_N);
  28. // transfer data to the device
  29. bolt::cl::copy(host_vec.begin(), host_vec.end(), device_vec.begin());
  30. int sum = 0;
  31. perf_timer t;
  32. for(size_t trial = 0; trial < PERF_TRIALS; trial++){
  33. t.start();
  34. sum = bolt::cl::reduce(device_vec.begin(), device_vec.end());
  35. t.stop();
  36. }
  37. std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
  38. std::cout << "sum: " << sum << std::endl;
  39. return 0;
  40. }