• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef TEST_NORM_OPENCL_HH
2 #define TEST_NORM_OPENCL_HH
3 #include "test_opencl.hpp"
4 
5 
6 template <class T, int number_of_tests, int max_dimension>
7 class bench_norm
8 {
9 public:
10 
11   typedef test_opencl<T, ublas::basic_row_major<>> test;
12 
13 
run()14   void run()
15   {
16 	opencl::library lib;
17 	int passedOperations = 0;
18 	// get default device and setup context
19 	compute::device device = compute::system::default_device();
20 	compute::context context(device);
21 	compute::command_queue queue(context, device);
22 
23 	std::srand(time(0));
24 
25 	ublas::vector<T> v;
26 
27 
28 	for (int i = 0; i<number_of_tests; i++)
29 	{
30 	  int size = std::rand() % max_dimension + 1;
31 
32 	  v.resize(size);
33 	  test::init_vector(v, 200);
34 
35 
36 	  T norm_cpu = ublas::norm_1(v);
37 	  T norm_opencl = opencl::norm_1(v, queue);
38 
39 
40 	  if (norm_cpu != norm_opencl) //precision of float
41 	  {
42 		std::cout << "Error in calculations" << std::endl;
43 
44 		std::cout << "passed: " << passedOperations << std::endl;
45 		return;
46 	  }
47 
48 	  passedOperations++;
49 
50 	}
51 	std::cout << "All is well (vector opencl a_sum) of " << typeid(T).name() << std::endl;
52 
53 
54 
55   }
56 
57 };
58 
59 #endif