inner_prod_test.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef TEST_INNER_PROD_HH
  2. #define TEST_INNER_PROD_HH
  3. #include "test_opencl.hpp"
  4. template <class T, int number_of_tests, int max_dimension>
  5. class bench_inner_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. T result_inner_prod_ublas;
  21. T result_inner_prod_opencl;
  22. for (int i = 0; i<number_of_tests; i++)
  23. {
  24. int size = std::rand() % max_dimension + 1;
  25. va.resize(size);
  26. vb.resize(size);
  27. test::init_vector(va, 200);
  28. test::init_vector(vb, 200);
  29. result_inner_prod_ublas = ublas::inner_prod(va, vb);
  30. result_inner_prod_opencl = opencl::inner_prod(va, vb, queue);
  31. if (( result_inner_prod_ublas != result_inner_prod_opencl ))
  32. {
  33. std::cout << "Error in calculations" << std::endl;
  34. std::cout << "passed: " << passedOperations << std::endl;
  35. return;
  36. }
  37. passedOperations++;
  38. }
  39. std::cout << "All is well (matrix opencl inner prod) of " << typeid(T).name() << std::endl;
  40. }
  41. };
  42. #endif