1 #ifndef TEST_PROD_OPENCL_HH 2 #define TEST_PROD_OPENCL_HH 3 #include "test_opencl.hpp" 4 5 6 template <class T, int number_of_tests, int max_dimension> 7 class bench_outer_prod 8 { 9 public: 10 11 typedef test_opencl<T> test; 12 run()13 void run() 14 { 15 opencl::library lib; 16 int passedOperations = 0; 17 // get default device and setup context 18 compute::device device = compute::system::default_device(); 19 compute::context context(device); 20 compute::command_queue queue(context, device); 21 22 std::srand(time(0)); 23 24 ublas::vector<T> va; 25 ublas::vector<T> vb; 26 ublas::matrix<T> resultUBLAS; 27 ublas::matrix<T> resultOPENCL; 28 29 30 for (int i = 0; i<number_of_tests; i++) 31 { 32 int rows = std::rand() % max_dimension + 1; 33 int cols = std::rand() % max_dimension + 1; 34 35 va.resize(rows); 36 vb.resize(cols); 37 38 test::init_vector(va, 200); 39 test::init_vector(vb, 200); 40 41 //matrix_matrix 42 resultUBLAS = ublas::outer_prod(va, vb); 43 resultOPENCL = opencl::outer_prod(va, vb, queue); 44 45 46 if (!test::compare(resultUBLAS, resultOPENCL)) 47 { 48 std::cout << "Error in calculations" << std::endl; 49 50 std::cout << "passed: " << passedOperations << std::endl; 51 return; 52 } 53 54 passedOperations++; 55 56 } 57 std::cout << "All is well (matrix opencl outer prod) of " << typeid(T).name() << std::endl; 58 59 60 61 } 62 63 }; 64 65 #endif