perf_reverse.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@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 <algorithm>
  11. #include <iostream>
  12. #include <numeric>
  13. #include <vector>
  14. #include <boost/compute/system.hpp>
  15. #include <boost/compute/algorithm/reverse.hpp>
  16. #include <boost/compute/container/vector.hpp>
  17. #include "perf.hpp"
  18. int rand_int()
  19. {
  20. return static_cast<int>((rand() / double(RAND_MAX)) * 25.0);
  21. }
  22. int main(int argc, char *argv[])
  23. {
  24. perf_parse_args(argc, argv);
  25. std::cout << "size: " << PERF_N << std::endl;
  26. // setup context and queue for the default device
  27. boost::compute::device device = boost::compute::system::default_device();
  28. boost::compute::context context(device);
  29. boost::compute::command_queue queue(context, device);
  30. std::cout << "device: " << device.name() << std::endl;
  31. // create vector of random numbers on the host
  32. std::vector<int> host_vector(PERF_N);
  33. std::generate(host_vector.begin(), host_vector.end(), rand_int);
  34. // create vector on the device and copy the data
  35. boost::compute::vector<int> device_vector(PERF_N, context);
  36. boost::compute::copy(
  37. host_vector.begin(), host_vector.end(), device_vector.begin(), queue
  38. );
  39. perf_timer t;
  40. for(size_t trial = 0; trial < PERF_TRIALS; trial++){
  41. t.start();
  42. boost::compute::reverse(
  43. device_vector.begin(), device_vector.end(), queue
  44. );
  45. queue.finish();
  46. t.stop();
  47. }
  48. std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
  49. return 0;
  50. }