summaryrefslogtreecommitdiff
path: root/src/CuBaseLib/cuvector.h~
blob: d118ec4370eae6f90529de17e4b2c00e2673f428 (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#ifndef _CUVECTOR_H_
#define _CUVECTOR_H_

#include "Vector.h"

namespace TNet {

  template<typename _ElemT> class CuMatrix;

  /**
   * \brief Vector for CUDA computing
   */
  template<typename _ElemT>
  class CuVector 
  {
    typedef CuVector<_ElemT> ThisType;

    public:

      /// Default Constructor
      CuVector<_ElemT>()
       : mDim(0), mpCUData(NULL)
      { }
      /// Constructor with memory initialisation
      CuVector<_ElemT>(size_t dim)
       : mDim(0), mpCUData(NULL)
      { Init(dim); }

      /// Destructor
      ~CuVector()
      { Destroy(); }

      /// Dimensions
      size_t Dim() const
      { return mDim; }

      /*
      ::MatrixDim Dim() const
      { ::MatrixDim d = { mDim, 1, 1 }; return d; }
      */

      /// Get raw pointer
      const _ElemT* pCUData() const
      { return mpCUData; }
      _ElemT* pCUData()
      { return mpCUData; }

      /// Allocate the memory
      ThisType& Init(size_t dim);

      /// Deallocate the memory
      void Destroy();

      /// Copy functions (reallocates when needed)
      ThisType&        CopyFrom(const CuVector<_ElemT>& rSrc);
      ThisType&        CopyFrom(const Vector<_ElemT>& rSrc);
      Vector<_ElemT>&  CopyTo(Vector<_ElemT>& rDst) const;


      
      // Math operations
      //
      void SetZero();

      void SetConst(_ElemT value)
      { Error("__func__ Not implemented"); }

      void AddScaled(_ElemT alpha, const CuVector<_ElemT>& vec, _ElemT beta)
      { Error("__func__ Not implemented"); }

      void AddColSum(_ElemT alpha, const CuMatrix<_ElemT>& mat, _ElemT beta)
      { Error("__func__ Not implemented"); }

      void Print() const
      { 
        Vector<_ElemT> vec(Dim());
        CopyTo(vec);
        std::cout << vec << "\n";
      }


    private:
      size_t mDim;
      _ElemT* mpCUData;
  };


  /// Prints the matrix dimensions and pointer to stream
  template<typename _ElemT>
  inline std::ostream& operator << (std::ostream& out, const CuVector<_ElemT>& vec)
  { 
    size_t d = vec.Dim(); 
    out << "[CuVector D" << d
        << " PTR" << vec.pCUData() << "]" << std::flush;
    return out;
  }
  
  
}


#include "cuvector.tcc"

#endif