perf_bolt_inner_product.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/inner_product.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 host vectors
  25. std::vector<int> host_x = generate_random_vector<int>(PERF_N);
  26. std::vector<int> host_y = generate_random_vector<int>(PERF_N);
  27. // create device vectors
  28. bolt::cl::device_vector<int> device_x(PERF_N);
  29. bolt::cl::device_vector<int> device_y(PERF_N);
  30. // transfer data to the device
  31. bolt::cl::copy(host_x.begin(), host_x.end(), device_x.begin());
  32. bolt::cl::copy(host_y.begin(), host_y.end(), device_y.begin());
  33. int product = 0;
  34. perf_timer t;
  35. for(size_t trial = 0; trial < PERF_TRIALS; trial++){
  36. t.start();
  37. product = bolt::cl::inner_product(
  38. device_x.begin(), device_x.end(), device_y.begin(), 0
  39. );
  40. t.stop();
  41. }
  42. std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
  43. std::cout << "product: " << product << std::endl;
  44. return 0;
  45. }