Advertisement
Guest User

Untitled

a guest
May 26th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #include <arrayfire.h>
  2. #include <iostream>
  3. #include <chrono>
  4.  
  5. using namespace std::chrono;
  6.  
  7. int main(int argc, char ** argv)
  8. {
  9. af::setBackend(AF_BACKEND_CUDA);
  10. af::info();
  11.  
  12. int iters = 1000;
  13. int n = 512;
  14.  
  15. // init
  16. af::array A = af::randu(n, n);
  17. af::array B = af::randu(n, n);
  18.  
  19. // warm up
  20. af::array C = af::matmul(A, B);
  21. C.eval();
  22.  
  23. af::sync();
  24. high_resolution_clock::time_point t1 = high_resolution_clock::now();
  25. for (int t = 0; t < iters; ++t) {
  26. C = af::matmul(A, B);
  27. C.eval();
  28. }
  29. af::sync();
  30. high_resolution_clock::time_point t2 = high_resolution_clock::now();
  31. duration<double> time_span = duration_cast<duration<double>>(t2 - t1);
  32. std::cout << "arrayfire - matmul: " << time_span.count() << std::endl;
  33.  
  34. af::sync();
  35. t1 = high_resolution_clock::now();
  36. for (int t = 0; t < iters; ++t) {
  37. for (int i = 0; i < B.dims(1); ++i) {
  38. C = af::matmul(A, B(af::span, i));
  39. C.eval();
  40. }
  41. }
  42. af::sync();
  43. t2 = high_resolution_clock::now();
  44. time_span = duration_cast<duration<double>>(t2 - t1);
  45. std::cout << "arrayfire - sliced matmul - column major: " << time_span.count() << std::endl;
  46.  
  47. af::sync();
  48. t1 = high_resolution_clock::now();
  49. for (int t = 0; t < iters; ++t) {
  50. for (int i = 0; i < B.dims(0); ++i) {
  51. C = af::matmul(B(i, af::span), A);
  52. C.eval();
  53. }
  54. }
  55. af::sync();
  56. t2 = high_resolution_clock::now();
  57. time_span = duration_cast<duration<double>>(t2 - t1);
  58. std::cout << "arrayfire - sliced matmul - row major: " << time_span.count() << std::endl;
  59.  
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement