perf_thrust_unique.cu 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/unique.h>
  18. #include "perf.hpp"
  19. int rand_int()
  20. {
  21. return static_cast<int>((rand() / double(RAND_MAX)) * 25.0);
  22. }
  23. int main(int argc, char *argv[])
  24. {
  25. perf_parse_args(argc, argv);
  26. std::cout << "size: " << PERF_N << std::endl;
  27. thrust::host_vector<int> h_vec(PERF_N);
  28. std::generate(h_vec.begin(), h_vec.end(), rand_int);
  29. thrust::device_vector<int> d_vec(PERF_N);
  30. perf_timer t;
  31. for(size_t trial = 0; trial < PERF_TRIALS; trial++){
  32. d_vec = h_vec;
  33. t.start();
  34. thrust::unique(d_vec.begin(), d_vec.end());
  35. cudaDeviceSynchronize();
  36. t.stop();
  37. }
  38. std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
  39. return 0;
  40. }