PARALUTION  1.0.0
PARALUTION
ocl_vector.hpp
Go to the documentation of this file.
1 #ifndef PARALUTION_OCL_VECTOR_HPP_
2 #define PARALUTION_OCL_VECTOR_HPP_
3 
4 #include "../base_vector.hpp"
5 #include "../base_matrix.hpp"
6 #include "../backend_manager.hpp"
7 #include "../../utils/log.hpp"
8 
9 #if defined(__APPLE__) && defined(__MACH__)
10 #include <OpenCL/cl.h>
11 #else
12 #include <CL/cl.h>
13 #endif
14 
15 namespace paralution {
16 
17 template <class ValueType>
18 class OCLAcceleratorVector : public AcceleratorVector<ValueType> {
19 
20 public:
21 
23  OCLAcceleratorVector(const Paralution_Backend_Descriptor local_backend);
24  virtual ~OCLAcceleratorVector();
25 
26  virtual void info(void) const;
27 
28  virtual void Allocate(const int n);
29  virtual void SetDataPtr(ValueType **ptr, const int size);
30  virtual void LeaveDataPtr(ValueType **ptr);
31  virtual void Clear(void);
32  virtual void Zeros(void);
33  virtual void Ones(void);
34  virtual void SetValues(const ValueType val);
35 
36  virtual void CopyFrom(const BaseVector<ValueType> &src) ;
37  virtual void CopyFrom(const BaseVector<ValueType> &src,
38  const int src_offset,
39  const int dst_offset,
40  const int size);
41  virtual void CopyFromFloat(const BaseVector<float> &src);
42  virtual void CopyFromDouble(const BaseVector<double> &src);
43 
44  virtual void CopyTo(BaseVector<ValueType> *dst) const;
45 
46  virtual void CopyFromHost(const HostVector<ValueType> &src);
47  virtual void CopyToHost(HostVector<ValueType> *dst) const;
48 
49  virtual void CopyFromPermute(const BaseVector<ValueType> &src,
50  const BaseVector<int> &permutation);
51  virtual void CopyFromPermuteBackward(const BaseVector<ValueType> &src,
52  const BaseVector<int> &permutation);
53 
54  virtual void Permute(const BaseVector<int> &permutation);
55  virtual void PermuteBackward(const BaseVector<int> &permutation);
56 
57 
58  // this = this + alpha*x
59  virtual void AddScale(const BaseVector<ValueType> &x, const ValueType alpha);
60  // this = alpha*this + x
61  virtual void ScaleAdd(const ValueType alpha, const BaseVector<ValueType> &x);
62  // this = alpha*this + x*beta
63  virtual void ScaleAddScale(const ValueType alpha, const BaseVector<ValueType> &x, const ValueType beta);
64  virtual void ScaleAddScale(const ValueType alpha, const BaseVector<ValueType> &x, const ValueType beta,
65  const int src_offset, const int dst_offset,const int size);
66  // this = alpha*this + x*beta + y*gamma
67  virtual void ScaleAdd2(const ValueType alpha, const BaseVector<ValueType> &x, const ValueType beta, const BaseVector<ValueType> &y, const ValueType gamma) ;
68  // this = alpha*this
69  virtual void Scale(const ValueType alpha);
71  virtual void PartialSum(const BaseVector<ValueType> &x);
72  // this^T x
73  virtual ValueType Dot(const BaseVector<ValueType> &x) const;
74  // this^T x
75  virtual ValueType DotNonConj(const BaseVector<ValueType> &x) const;
76  // srqt(this^T this)
77  virtual ValueType Norm(void) const;
78  // reduce
79  virtual ValueType Reduce(void) const;
80  // Compute sum of absolute values of this
81  virtual ValueType Asum(void) const;
82  // Compute absolute max value of this
83  virtual int Amax(ValueType &value) const;
84  // point-wise multiplication
85  virtual void PointWiseMult(const BaseVector<ValueType> &x);
86  virtual void PointWiseMult(const BaseVector<ValueType> &x, const BaseVector<ValueType> &y);
87  virtual void Power(const double power);
88 
89 private:
90 
91  cl_mem *vec_;
92 
93  friend class OCLAcceleratorVector<double>;
94  friend class OCLAcceleratorVector<float>;
95  friend class OCLAcceleratorVector<int>;
96 
97  friend class HostVector<ValueType>;
98  friend class AcceleratorMatrix<ValueType>;
99 
100  friend class OCLAcceleratorMatrixCSR<ValueType>;
101  friend class OCLAcceleratorMatrixMCSR<ValueType>;
102  friend class OCLAcceleratorMatrixBCSR<ValueType>;
103  friend class OCLAcceleratorMatrixCOO<ValueType>;
104  friend class OCLAcceleratorMatrixDIA<ValueType>;
105  friend class OCLAcceleratorMatrixELL<ValueType>;
106  friend class OCLAcceleratorMatrixDENSE<ValueType>;
107  friend class OCLAcceleratorMatrixHYB<ValueType>;
108 
109  friend class OCLAcceleratorMatrixCOO<double>;
110  friend class OCLAcceleratorMatrixCOO<float>;
111 
112  friend class OCLAcceleratorMatrixCSR<double>;
113  friend class OCLAcceleratorMatrixCSR<float>;
114 
115 };
116 
117 
118 }
119 
120 #endif // PARALUTION_OCL_VECTOR_HPP_
virtual void Power(const double power)
Definition: ocl_vector.cpp:1588
virtual void LeaveDataPtr(ValueType **ptr)
Get a pointer from the vector data and free the vector object.
Definition: ocl_vector.cpp:102
virtual void CopyFromFloat(const BaseVector< float > &src)
Copy values from another (float) vector.
Definition: ocl_vector.cpp:341
virtual void AddScale(const BaseVector< ValueType > &x, const ValueType alpha)
Perform vector update of type this = this + alpha*x.
Definition: ocl_vector.cpp:523
virtual void Clear(void)
Clear (free) the vector.
Definition: ocl_vector.cpp:118
virtual void PointWiseMult(const BaseVector< ValueType > &x)
Perform point-wise multiplication (element-wise) of type this = this * x.
Definition: ocl_vector.cpp:1280
virtual void CopyFromDouble(const BaseVector< double > &src)
Copy values from another (double) vector.
Definition: ocl_vector.cpp:398
Definition: base_matrix.hpp:59
Definition: base_matrix.hpp:67
virtual void CopyTo(BaseVector< ValueType > *dst) const
Copy values to another vector.
Definition: ocl_vector.cpp:294
virtual ValueType Dot(const BaseVector< ValueType > &x) const
Compute dot (scalar) product, return this^T y.
Definition: ocl_vector.cpp:823
virtual void ScaleAdd2(const ValueType alpha, const BaseVector< ValueType > &x, const ValueType beta, const BaseVector< ValueType > &y, const ValueType gamma)
Perform vector update of type this = alpha*this + x*beta + y*gamma.
Definition: ocl_vector.cpp:720
Definition: base_matrix.hpp:65
virtual void ScaleAddScale(const ValueType alpha, const BaseVector< ValueType > &x, const ValueType beta)
Perform vector update of type this = alpha*this + x*beta.
Definition: ocl_vector.cpp:617
virtual void Permute(const BaseVector< int > &permutation)
Perform inplace permutation (forward) of the vector.
Definition: ocl_vector.cpp:1376
virtual void info(void) const
Shows info about the object.
Definition: ocl_vector.cpp:48
virtual void PermuteBackward(const BaseVector< int > &permutation)
Perform inplace permutation (backward) of the vector.
Definition: ocl_vector.cpp:1428
cl_mem * vec_
Definition: ocl_vector.hpp:91
virtual void Allocate(const int n)
Allocate a local vector with name and size.
Definition: ocl_vector.cpp:55
OCLAcceleratorVector()
Definition: ocl_vector.cpp:18
const IndexType const IndexType const IndexType const ValueType const ValueType const ValueType ValueType * y
Definition: cuda_kernels_coo.hpp:91
Definition: base_vector.hpp:10
virtual void Zeros(void)
Set the values of the vector to zero.
Definition: ocl_vector.cpp:454
virtual void PartialSum(const BaseVector< ValueType > &x)
Compute partial sum.
Definition: ocl_vector.cpp:815
virtual void CopyFromPermute(const BaseVector< ValueType > &src, const BaseVector< int > &permutation)
Copy a vector under specified permutation (forward permutation)
Definition: ocl_vector.cpp:1480
virtual int Amax(ValueType &value) const
Compute the absolute max value of the vector, return = max(|this|)
Definition: ocl_vector.cpp:1196
Definition: base_matrix.hpp:61
virtual ValueType DotNonConj(const BaseVector< ValueType > &x) const
Compute non-conjugated dot (scalar) product, return this^T y.
Definition: ocl_vector.cpp:901
void power(const int mic_dev, const int size, const double val, ValueType *vec)
Definition: mic_vector_kernel.cpp:241
virtual ValueType Norm(void) const
Compute L2 norm of the vector, return = srqt(this^T this)
Definition: ocl_vector.cpp:979
virtual void CopyFromHost(const HostVector< ValueType > &src)
Copy (accelerator vector) from host vector.
Definition: ocl_vector.cpp:131
virtual void Scale(const ValueType alpha)
Perform vector scaling this = alpha*this.
Definition: ocl_vector.cpp:775
virtual void ScaleAdd(const ValueType alpha, const BaseVector< ValueType > &x)
Perform vector update of type this = alpha*this + x.
Definition: ocl_vector.cpp:570
virtual ValueType Reduce(void) const
Reduce vector.
Definition: ocl_vector.cpp:1060
virtual void CopyFrom(const BaseVector< ValueType > &src)
Copy values from another vector.
Definition: ocl_vector.cpp:194
Definition: backend_manager.hpp:12
virtual void SetDataPtr(ValueType **ptr, const int size)
Initialize a vector with externally allocated data.
Definition: ocl_vector.cpp:87
virtual void CopyToHost(HostVector< ValueType > *dst) const
Copy (host vector) from accelerator vector.
Definition: ocl_vector.cpp:163
Definition: backend_manager.cpp:43
Definition: base_matrix.hpp:55
Definition: base_matrix.hpp:63
const IndexType const IndexType const IndexType const ValueType const ValueType const ValueType * x
Definition: cuda_kernels_coo.hpp:91
Definition: base_matrix.hpp:57
Definition: base_matrix.hpp:69
virtual void SetValues(const ValueType val)
Set the values of the vector to given argument.
Definition: ocl_vector.cpp:500
friend class HostVector< ValueType >
Definition: ocl_vector.hpp:97
virtual void Ones(void)
Set the values of the vector to one.
Definition: ocl_vector.cpp:477
Definition: base_vector.hpp:19
virtual ValueType Asum(void) const
Compute sum of absolute values of the vector (L1 norm), return = sum(|this|)
Definition: ocl_vector.cpp:1128
virtual void CopyFromPermuteBackward(const BaseVector< ValueType > &src, const BaseVector< int > &permutation)
Copy a vector under specified permutation (backward permutation)
Definition: ocl_vector.cpp:1534
virtual ~OCLAcceleratorVector()
Definition: ocl_vector.cpp:38