CuSubArray< T > Class Template Reference

#include <cu-array.h>

Inheritance diagram for CuSubArray< T >:
Collaboration diagram for CuSubArray< T >:

Public Member Functions

 CuSubArray (const CuArrayBase< T > &src, MatrixIndexT offset, MatrixIndexT dim)
 Constructor as a range of an existing CuArray or CuSubArray. More...
 
 CuSubArray (const T *data, MatrixIndexT length)
 Construct from raw pointers. More...
 
- 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...
 
Min () const
 Get minimum value (for now implemented on CPU, reimplement if slow). More...
 
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...
 

Detailed Description

template<typename T>
class kaldi::CuSubArray< T >

Definition at line 33 of file cu-array.h.

Constructor & Destructor Documentation

◆ CuSubArray() [1/2]

CuSubArray ( const CuArrayBase< T > &  src,
MatrixIndexT  offset,
MatrixIndexT  dim 
)
explicit

Constructor as a range of an existing CuArray or CuSubArray.

Note: like similar constructors in class CuVector and others, it can be used to evade 'const' constraints; don't do that.

Definition at line 315 of file cu-array-inl.h.

References data_, CuArrayBase< T >::data_, CuArrayBase< T >::Dim(), and KALDI_ASSERT.

317  {
318  KALDI_ASSERT(offset >= 0 && dim >= 0 &&
319  offset + dim <= src.Dim());
320  this->data_ = src.data_ + offset;
321  this->dim_ = dim;
322 }
T * data_
GPU data pointer (if GPU not available, will point to CPU memory).
Definition: cu-array.h:111
MatrixIndexT dim_
dimension of the vector
Definition: cu-array.h:113
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ CuSubArray() [2/2]

CuSubArray ( const T *  data,
MatrixIndexT  length 
)
inline

Construct from raw pointers.

Definition at line 189 of file cu-array.h.

References CuArrayBase< T >::data_, and CuArrayBase< T >::dim_.

189  {
190  // Yes, we're evading C's restrictions on const here, and yes, it can be used
191  // to do wrong stuff; unfortunately the workaround would be very difficult.
192  this->data_ = const_cast<T*>(data);
193  this->dim_ = length;
194  }
T * data_
GPU data pointer (if GPU not available, will point to CPU memory).
Definition: cu-array.h:111
MatrixIndexT dim_
dimension of the vector
Definition: cu-array.h:113

The documentation for this class was generated from the following files: