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