norm_test.hpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef TEST_NORM_OPENCL_HH
  2. #define TEST_NORM_OPENCL_HH
  3. #include "test_opencl.hpp"
  4. template <class T, int number_of_tests, int max_dimension>
  5. class bench_norm
  6. {
  7. public:
  8. typedef test_opencl<T, ublas::basic_row_major<>> 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> v;
  19. for (int i = 0; i<number_of_tests; i++)
  20. {
  21. int size = std::rand() % max_dimension + 1;
  22. v.resize(size);
  23. test::init_vector(v, 200);
  24. T norm_cpu = ublas::norm_1(v);
  25. T norm_opencl = opencl::norm_1(v, queue);
  26. if (norm_cpu != norm_opencl) //precision of float
  27. {
  28. std::cout << "Error in calculations" << std::endl;
  29. std::cout << "passed: " << passedOperations << std::endl;
  30. return;
  31. }
  32. passedOperations++;
  33. }
  34. std::cout << "All is well (vector opencl a_sum) of " << typeid(T).name() << std::endl;
  35. }
  36. };
  37. #endif