1 #ifndef TEST_INNER_PROD_HH 2 #define TEST_INNER_PROD_HH 3 #include "test_opencl.hpp" 4 5 6 template <class T, int number_of_tests, int max_dimension> 7 class bench_inner_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 T result_inner_prod_ublas; 27 T result_inner_prod_opencl; 28 29 30 for (int i = 0; i<number_of_tests; i++) 31 { 32 int size = std::rand() % max_dimension + 1; 33 34 va.resize(size); 35 vb.resize(size); 36 37 test::init_vector(va, 200); 38 test::init_vector(vb, 200); 39 40 result_inner_prod_ublas = ublas::inner_prod(va, vb); 41 42 result_inner_prod_opencl = opencl::inner_prod(va, vb, queue); 43 44 45 if (( result_inner_prod_ublas != result_inner_prod_opencl )) 46 { 47 std::cout << "Error in calculations" << std::endl; 48 49 std::cout << "passed: " << passedOperations << std::endl; 50 return; 51 } 52 53 passedOperations++; 54 55 } 56 std::cout << "All is well (matrix opencl inner prod) of " << typeid(T).name() << std::endl; 57 58 59 60 } 61 62 }; 63 64 #endif 65