test_opencl.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef TEST_OPENCL_HEADER_HH
  2. #define TEST_OPENCL_HEADER_HH
  3. #include <stdio.h>
  4. #define BOOST_UBLAS_ENABLE_OPENCL
  5. #include <boost/numeric/ublas/opencl.hpp>
  6. #include <boost/numeric/ublas/matrix.hpp>
  7. #include <time.h>
  8. #include <math.h>
  9. namespace ublas = boost::numeric::ublas;
  10. namespace opencl = boost::numeric::ublas::opencl;
  11. namespace compute = boost::compute;
  12. template <class T, class F = ublas::basic_row_major<>>
  13. class test_opencl
  14. {
  15. public:
  16. static bool compare(ublas::matrix<T, F>& a, ublas::matrix<T, F>& b)
  17. {
  18. typedef typename ublas::matrix<T, F>::size_type size_type;
  19. if ((a.size1() != b.size1()) || (a.size2() != b.size2()))
  20. return false;
  21. for (size_type i = 0; i<a.size1(); i++)
  22. for (size_type j = 0; j<a.size2(); j++)
  23. if (a(i, j) != b(i, j))
  24. {
  25. return false;
  26. }
  27. return true;
  28. }
  29. static bool compare(ublas::vector<T>& a, ublas::vector<T>& b)
  30. {
  31. typedef typename ublas::vector<T>::size_type size_type;
  32. if (a.size() != b.size())
  33. return false;
  34. for (size_type i = 0; i<a.size(); i++)
  35. if ((a[i] != b[i]))
  36. {
  37. return false;
  38. }
  39. return true;
  40. }
  41. static void init_matrix(ublas::matrix<T, F>& m, int max_value)
  42. {
  43. typedef typename ublas::matrix<T, F>::size_type size_type;
  44. for (size_type i = 0; i < m.size1(); i++)
  45. {
  46. for (size_type j = 0; j<m.size2(); j++)
  47. m(i, j) = (std::rand() % max_value) + 1;
  48. }
  49. }
  50. static void init_vector(ublas::vector<T>& v, int max_value)
  51. {
  52. typedef typename ublas::vector<T>::size_type size_type;
  53. for (size_type i = 0; i <v.size(); i++)
  54. {
  55. v[i] = (std::rand() % max_value) + 1;
  56. }
  57. }
  58. virtual void run()
  59. {
  60. }
  61. };
  62. #endif