perf_thrust_partial_sum.cu 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 <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/scan.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 = h_vec;
  26. perf_timer t;
  27. for(size_t trial = 0; trial < PERF_TRIALS; trial++){
  28. d_vec = h_vec;
  29. t.start();
  30. thrust::inclusive_scan(d_vec.begin(), d_vec.end(), d_vec.begin());
  31. cudaDeviceSynchronize();
  32. t.stop();
  33. }
  34. std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
  35. // transfer data back to host
  36. thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());
  37. return 0;
  38. }