perf_fill.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 <iostream>
  11. #include <boost/compute/system.hpp>
  12. #include <boost/compute/algorithm/fill.hpp>
  13. #include <boost/compute/container/vector.hpp>
  14. #include "perf.hpp"
  15. int main(int argc, char *argv[])
  16. {
  17. perf_parse_args(argc, argv);
  18. std::cout << "size: " << PERF_N << std::endl;
  19. // setup context and queue for the default device
  20. boost::compute::device device = boost::compute::system::default_device();
  21. boost::compute::context context(device);
  22. boost::compute::command_queue queue(context, device);
  23. std::cout << "device: " << device.name() << std::endl;
  24. // create vector on the device (filled with zeros)
  25. boost::compute::vector<int> vec(PERF_N, 0, queue);
  26. perf_timer t;
  27. for(size_t trial = 0; trial < PERF_TRIALS; trial++){
  28. t.start();
  29. boost::compute::fill(vec.begin(), vec.end(), int(trial), queue);
  30. queue.finish();
  31. t.stop();
  32. }
  33. std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
  34. return 0;
  35. }