File: test_opencl.hpp

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (84 lines) | stat: -rw-r--r-- 1,639 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef TEST_OPENCL_HEADER_HH
#define TEST_OPENCL_HEADER_HH
#include <stdio.h>

#define BOOST_UBLAS_ENABLE_OPENCL
#include <boost/numeric/ublas/opencl.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <time.h>
#include <math.h>




namespace ublas = boost::numeric::ublas;
namespace opencl = boost::numeric::ublas::opencl;
namespace compute = boost::compute;

template <class T, class F = ublas::basic_row_major<>>
class test_opencl
{
public:
  static bool compare(ublas::matrix<T, F>& a, ublas::matrix<T, F>& b)
  {
    typedef typename ublas::matrix<T, F>::size_type size_type;
	if ((a.size1() != b.size1()) || (a.size2() != b.size2()))
	  return false;

	for (size_type i = 0; i<a.size1(); i++)
	  for (size_type j = 0; j<a.size2(); j++)
		if (a(i, j) != b(i, j))
		{
		  return false;
		}
	return true;

  }


  static bool compare(ublas::vector<T>& a, ublas::vector<T>& b)
  {
    typedef typename ublas::vector<T>::size_type size_type;
	if (a.size() != b.size())
	  return false;

	for (size_type i = 0; i<a.size(); i++)
	  if ((a[i] != b[i]))
	  {
		return false;
	  }
	return true;

  }



  static void init_matrix(ublas::matrix<T, F>& m, int max_value)
  {
    typedef typename ublas::matrix<T, F>::size_type size_type;
	for (size_type i = 0; i < m.size1(); i++)
	{
	  for (size_type j = 0; j<m.size2(); j++)
		m(i, j) = (std::rand() % max_value) + 1;

	}
  }


  static void init_vector(ublas::vector<T>& v, int max_value)
  {
    typedef typename ublas::vector<T>::size_type size_type;
	for (size_type i = 0; i <v.size(); i++)
	{
	  v[i] = (std::rand() % max_value) + 1;
	}
  }


  virtual void run()
  {
  }

};

#endif