Class CuArray represents a vector of an integer or struct of type T. More...
#include <cu-array.h>
Public Member Functions | |
CuArray () | |
Default constructor, initialized data_ to NULL and dim_ to 0 via constructor of CuArrayBase. More... | |
CuArray (MatrixIndexT dim, MatrixResizeType resize_type=kSetZero) | |
Constructor with memory initialisation. More... | |
CuArray (const std::vector< T > &src) | |
Constructor from CPU-based int vector. More... | |
CuArray (const CuArray< T > &src) | |
Copy constructor. More... | |
~CuArray () | |
Destructor. More... | |
void | Resize (MatrixIndexT dim, MatrixResizeType resize_type=kSetZero) |
Allocate the memory. More... | |
void | Destroy () |
Deallocate the memory and set dim_ and data_ to zero. More... | |
void | CopyFromVec (const std::vector< T > &src) |
This function resizes if needed. More... | |
void | CopyFromArray (const CuArrayBase< T > &src) |
This function resizes if needed. More... | |
CuArray< T > & | operator= (const CuArray< T > &in) |
CuArray< T > & | operator= (const std::vector< T > &in) |
void | Swap (CuArray< T > *other) |
Shallow swap with another CuArray<T>. More... | |
void | Read (std::istream &is, bool binary) |
I/O. More... | |
void | Write (std::ostream &is, bool binary) const |
Public Member Functions inherited from CuArrayBase< T > | |
MatrixIndexT | Dim () const |
Return the vector dimension. More... | |
const T * | Data () const |
Get raw pointer. More... | |
T * | Data () |
void | SetZero () |
Sets the memory for the object to zero, via memset. More... | |
void | CopyFromArray (const CuArrayBase< T > &src) |
The caller is responsible to ensure dim is equal between *this and src. More... | |
void | CopyFromVec (const std::vector< T > &src) |
The caller is responsible to ensure dim is equal between *this and src. More... | |
void | CopyToVec (std::vector< T > *dst) const |
This function resizes *dst if needed. More... | |
void | CopyToHost (T *dst) const |
Version of the above function that copies contents to a host array (i.e. More... | |
void | Set (const T &value) |
Set to a constant value. More... | |
void | Sequence (const T base) |
Fill with the sequence [base ... More... | |
void | Add (const T &value) |
Add a constant value. More... | |
T | Min () const |
Get minimum value (for now implemented on CPU, reimplement if slow). More... | |
T | Max () const |
Get minimum value (for now implemented on CPU, reimplement if slow). More... | |
template<> | |
void | Set (const int32 &value) |
template<> | |
void | Sequence (const int32 base) |
template<> | |
void | Add (const int32 &value) |
template<> | |
void | Sequence (const int32 base) |
template<> | |
void | Set (const int32 &value) |
template<> | |
void | Add (const int32 &value) |
Additional Inherited Members | |
Protected Member Functions inherited from CuArrayBase< T > | |
CuArrayBase () | |
Default constructor: make it protected so the user cannot instantiate this class. More... | |
Protected Attributes inherited from CuArrayBase< T > | |
T * | data_ |
GPU data pointer (if GPU not available, will point to CPU memory). More... | |
MatrixIndexT | dim_ |
dimension of the vector More... | |
Class CuArray represents a vector of an integer or struct of type T.
If we are using a GPU then the memory is on the GPU, otherwise it's on the CPU. This class owns the data that it contains from a memory allocation perspective; see also CuSubArrary which does not own the data it contains.
Definition at line 32 of file cu-array.h.
|
inline |
Default constructor, initialized data_ to NULL and dim_ to 0 via constructor of CuArrayBase.
Definition at line 129 of file cu-array.h.
|
inlineexplicit |
Constructor with memory initialisation.
resize_type may be kSetZero or kUndefined.
Definition at line 133 of file cu-array.h.
|
inlineexplicit |
Constructor from CPU-based int vector.
Definition at line 137 of file cu-array.h.
Copy constructor.
We don't make this explicit because we want to be able to create a std::vector<CuArray>.
Definition at line 141 of file cu-array.h.
|
inline |
Destructor.
Definition at line 144 of file cu-array.h.
void CopyFromArray | ( | const CuArrayBase< T > & | src | ) |
This function resizes if needed.
Definition at line 139 of file cu-array-inl.h.
void CopyFromVec | ( | const std::vector< T > & | src | ) |
This function resizes if needed.
Note: copying to GPU is done via memcpy, and any constructors or assignment operators are not called.
Definition at line 120 of file cu-array-inl.h.
Referenced by ConvolutionComputation::ComputeDerived(), kaldi::nnet3::CopyPairVector(), NnetComputer::GetPointers(), GeneralDropoutComponent::PrecomputeIndexes(), MatrixRandomizer::Randomize(), kaldi::UnitTestCuDiffXent(), kaldi::UnitTestCuMathCopy(), kaldi::UnitTestCuMathRandomize(), and kaldi::UnitTestCuMathSplice().
void Destroy | ( | ) |
Deallocate the memory and set dim_ and data_ to zero.
Does not call any destructors of the objects stored.
Definition at line 82 of file cu-array-inl.h.
Definition at line 161 of file cu-array.h.
|
inline |
Definition at line 165 of file cu-array.h.
void Read | ( | std::istream & | is, |
bool | binary | ||
) |
I/O.
Definition at line 300 of file cu-array-inl.h.
Referenced by Splice::InitData(), and Splice::ReadData().
void Resize | ( | MatrixIndexT | dim, |
MatrixResizeType | resize_type = kSetZero |
||
) |
Allocate the memory.
resize_type may be kSetZero or kUndefined. kCopyData not yet supported (can be implemented if needed).
Definition at line 43 of file cu-array-inl.h.
Referenced by kaldi::UnitTestCuArray().
void Swap | ( | CuArray< T > * | other | ) |
Shallow swap with another CuArray<T>.
Definition at line 341 of file cu-array-inl.h.
void Write | ( | std::ostream & | is, |
bool | binary | ||
) | const |
Definition at line 307 of file cu-array-inl.h.
Referenced by Splice::WriteData(), and CopyComponent::WriteData().