summaryrefslogtreecommitdiff
path: root/src/CuBaseLib/cuvector.h~
diff options
context:
space:
mode:
Diffstat (limited to 'src/CuBaseLib/cuvector.h~')
-rw-r--r--src/CuBaseLib/cuvector.h~104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/CuBaseLib/cuvector.h~ b/src/CuBaseLib/cuvector.h~
new file mode 100644
index 0000000..d118ec4
--- /dev/null
+++ b/src/CuBaseLib/cuvector.h~
@@ -0,0 +1,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