perf_thrust_reverse_copy.cu 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 <algorithm>
  11. #include <cstdlib>
  12. #include <iostream>
  13. #include <thrust/copy.h>
  14. #include <thrust/device_vector.h>
  15. #include <thrust/generate.h>
  16. #include <thrust/host_vector.h>
  17. #include <thrust/reverse.h>
  18. #include "perf.hpp"
  19. int main(int argc, char *argv[])
  20. {
  21. perf_parse_args(argc, argv);
  22. std::cout << "size: " << PERF_N << std::endl;
  23. thrust::host_vector<int> h_vec = generate_random_vector<int>(PERF_N);
  24. // transfer data to the device
  25. thrust::device_vector<int> d_vec;
  26. d_vec = h_vec;
  27. // device vector for reversed data
  28. thrust::device_vector<int> d_reversed_vec(PERF_N);
  29. perf_timer t;
  30. for(size_t trial = 0; trial < PERF_TRIALS; trial++){
  31. t.start();
  32. thrust::reverse_copy(d_vec.begin(), d_vec.end(), d_reversed_vec.begin());
  33. cudaDeviceSynchronize();
  34. t.stop();
  35. }
  36. std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
  37. return 0;
  38. }