perf_bolt_merge.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 <iostream>
  11. #include <algorithm>
  12. #include <vector>
  13. #include <bolt/cl/merge.h>
  14. #include <bolt/cl/copy.h>
  15. #include <bolt/cl/device_vector.h>
  16. #include "perf.hpp"
  17. int main(int argc, char *argv[])
  18. {
  19. perf_parse_args(argc, argv);
  20. std::cout << "size: " << PERF_N << std::endl;
  21. bolt::cl::control ctrl = bolt::cl::control::getDefault();
  22. ::cl::Device device = ctrl.getDevice();
  23. std::cout << "device: " << device.getInfo<CL_DEVICE_NAME>() << std::endl;
  24. // create vector of random numbers on the host
  25. std::vector<int> host_vec1 = generate_random_vector<int>(std::floor(PERF_N / 2.0));
  26. std::vector<int> host_vec2 = generate_random_vector<int>(std::ceil(PERF_N / 2.0));
  27. // sort them
  28. std::sort(host_vec1.begin(), host_vec1.end());
  29. std::sort(host_vec2.begin(), host_vec2.end());
  30. // create device vectors
  31. bolt::cl::device_vector<int> device_vec1(PERF_N);
  32. bolt::cl::device_vector<int> device_vec2(PERF_N);
  33. bolt::cl::device_vector<int> device_vec3(PERF_N);
  34. // transfer data to the device
  35. bolt::cl::copy(host_vec1.begin(), host_vec1.end(), device_vec1.begin());
  36. bolt::cl::copy(host_vec2.begin(), host_vec2.end(), device_vec2.begin());
  37. perf_timer t;
  38. for(size_t trial = 0; trial < PERF_TRIALS; trial++){
  39. t.start();
  40. bolt::cl::merge(
  41. device_vec1.begin(), device_vec1.end(),
  42. device_vec2.begin(), device_vec2.end(),
  43. device_vec3.begin()
  44. );
  45. t.stop();
  46. }
  47. std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
  48. return 0;
  49. }