outer_prod_test.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef TEST_PROD_OPENCL_HH
  2. #define TEST_PROD_OPENCL_HH
  3. #include "test_opencl.hpp"
  4. template <class T, int number_of_tests, int max_dimension>
  5. class bench_outer_prod
  6. {
  7. public:
  8. typedef test_opencl<T> 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::vector<T> va;
  19. ublas::vector<T> vb;
  20. ublas::matrix<T> resultUBLAS;
  21. ublas::matrix<T> resultOPENCL;
  22. for (int i = 0; i<number_of_tests; i++)
  23. {
  24. int rows = std::rand() % max_dimension + 1;
  25. int cols = std::rand() % max_dimension + 1;
  26. va.resize(rows);
  27. vb.resize(cols);
  28. test::init_vector(va, 200);
  29. test::init_vector(vb, 200);
  30. //matrix_matrix
  31. resultUBLAS = ublas::outer_prod(va, vb);
  32. resultOPENCL = opencl::outer_prod(va, vb, queue);
  33. if (!test::compare(resultUBLAS, resultOPENCL))
  34. {
  35. std::cout << "Error in calculations" << std::endl;
  36. std::cout << "passed: " << passedOperations << std::endl;
  37. return;
  38. }
  39. passedOperations++;
  40. }
  41. std::cout << "All is well (matrix opencl outer prod) of " << typeid(T).name() << std::endl;
  42. }
  43. };
  44. #endif