transposition_test.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef TEST_TRANS_OPENCL_HH
  2. #define TEST_TRANS_OPENCL_HH
  3. #include "test_opencl.hpp"
  4. template <class T, class F, int number_of_tests, int max_dimension>
  5. class bench_trans
  6. {
  7. public:
  8. typedef test_opencl<T, F> test;
  9. void run()
  10. {
  11. opencl::library lib;
  12. int passedOperations = 0;
  13. // get default device and setup context
  14. compute::device device = compute::system::default_device();
  15. compute::context context(device);
  16. compute::command_queue queue(context, device);
  17. std::srand(time(0));
  18. ublas::matrix<T, F> a;
  19. ublas::matrix<T, F> resultUBLAS;
  20. ublas::matrix<T, F> resultOPENCL;
  21. for (int i = 0; i<number_of_tests; i++)
  22. {
  23. int rowsA = std::rand() % max_dimension + 1;
  24. int colsA = std::rand() % max_dimension + 1;
  25. a.resize(rowsA, colsA);
  26. test::init_matrix(a, 200);
  27. resultUBLAS = ublas::trans(a);
  28. resultOPENCL = opencl::trans(a, queue);
  29. if (!test::compare(resultUBLAS, resultOPENCL))
  30. {
  31. std::cout << "Error in calculations" << std::endl;
  32. std::cout << "passed: " << passedOperations << std::endl;
  33. return;
  34. }
  35. passedOperations++;
  36. }
  37. std::cout << "All is well (matrix opencl prod) of " << typeid(T).name() << std::endl;
  38. }
  39. };
  40. #endif