Matrix for CUDA computing. More...
#include <matrix-common.h>
Public Member Functions | |
CuPackedMatrix () | |
CuPackedMatrix (MatrixIndexT r, MatrixResizeType resize_type=kSetZero) | |
CuPackedMatrix (const PackedMatrix< Real > &orig) | |
CuPackedMatrix (const CuPackedMatrix< Real > &orig) | |
void | SetZero () |
void | SetUnit () |
< Set to zero More... | |
void | SetRandn () |
< Set to unit matrix. More... | |
void | SetDiag (Real alpha) |
< Set to random values of a normal distribution More... | |
void | AddToDiag (Real r) |
< Set the diagonal value to alpha More... | |
void | Scale (Real alpha) |
void | ScaleDiag (Real alpha) |
Real | Trace () const |
~CuPackedMatrix () | |
void | Resize (MatrixIndexT nRows, MatrixResizeType resize_type=kSetZero) |
Set packed matrix to a specified size (can be zero). More... | |
void | CopyFromPacked (const CuPackedMatrix< Real > &src) |
void | CopyFromPacked (const PackedMatrix< Real > &src) |
void | CopyToPacked (PackedMatrix< Real > *dst) const |
void | Read (std::istream &in, bool binary) |
void | Write (std::ostream &out, bool binary) const |
void | Destroy () |
void | Swap (CuPackedMatrix< Real > *other) |
Swaps the contents of *this and *other. Shallow swap. More... | |
void | Swap (PackedMatrix< Real > *other) |
Swaps the contents of *this and *other. More... | |
Real * | Data () |
const Real * | Data () const |
Real | operator() (MatrixIndexT r, MatrixIndexT c) const |
MatrixIndexT | NumRows () const |
MatrixIndexT | NumCols () const |
size_t | SizeInBytes () const |
Returns size in bytes of the data held by the matrix. More... | |
Protected Member Functions | |
const PackedMatrix< Real > & | Mat () const |
PackedMatrix< Real > & | Mat () |
void | AddPacked (const Real alpha, const CuPackedMatrix< Real > &M) |
Protected Attributes | |
Real * | data_ |
MatrixIndexT | num_rows_ |
Private Member Functions | |
PackedMatrix< Real > & | operator= (const PackedMatrix< Real > &other) |
Friends | |
class | CuMatrixBase< Real > |
class | CuVectorBase< Real > |
class | CuSubMatrix< Real > |
class | CuRand< Real > |
Matrix for CUDA computing.
This is a base class for packed triangular and symmetric matrices. Does the computation on the CUDA card when CUDA is compiled in and we have a suitable GPU (CuDevice::Instantiate().Enabled() == true); otherwise, does it on the CPU.Packed CUDA matrix: base class for triangular and symmetric matrices on a GPU card.
Definition at line 75 of file matrix-common.h.
|
inline |
Definition at line 60 of file cu-packed-matrix.h.
|
inlineexplicit |
Definition at line 62 of file cu-packed-matrix.h.
References CuPackedMatrix< Real >::Resize().
|
inlineexplicit |
Definition at line 66 of file cu-packed-matrix.h.
References CuPackedMatrix< Real >::CopyFromPacked(), kaldi::kUndefined, PackedMatrix< Real >::num_rows_, and CuPackedMatrix< Real >::Resize().
|
inlineexplicit |
Definition at line 71 of file cu-packed-matrix.h.
References CuPackedMatrix< Real >::AddToDiag(), CuPackedMatrix< Real >::CopyFromPacked(), kaldi::kUndefined, CuPackedMatrix< Real >::Resize(), CuPackedMatrix< Real >::Scale(), CuPackedMatrix< Real >::ScaleDiag(), CuPackedMatrix< Real >::SetDiag(), CuPackedMatrix< Real >::SetRandn(), CuPackedMatrix< Real >::SetUnit(), CuPackedMatrix< Real >::SetZero(), and CuPackedMatrix< Real >::Trace().
|
inline |
Definition at line 86 of file cu-packed-matrix.h.
References CuPackedMatrix< Real >::CopyFromPacked(), CuPackedMatrix< Real >::CopyToPacked(), CuPackedMatrix< Real >::Destroy(), kaldi::kSetZero, CuPackedMatrix< Real >::Read(), CuPackedMatrix< Real >::Resize(), CuPackedMatrix< Real >::Swap(), and CuPackedMatrix< Real >::Write().
|
protected |
Definition at line 333 of file cu-packed-matrix.cc.
References CuPackedMatrix< Real >::Data(), data_, KALDI_ASSERT, CuPackedMatrix< Real >::Mat(), and CuPackedMatrix< Real >::NumRows().
Referenced by CuSpMatrix< Real >::AddSp().
void AddToDiag | ( | Real | r | ) |
< Set the diagonal value to alpha
Add this quantity to the diagonal of the matrix.
Definition at line 351 of file cu-packed-matrix.cc.
References CU1DBLOCK, and data_.
Referenced by CuPackedMatrix< Real >::CuPackedMatrix(), kaldi::UnitTestCuPackedMatrixAddToDiag(), kaldi::UnitTestCuSpMatrixAddToDiag(), kaldi::UnitTestCuSpMatrixInvert(), and kaldi::UnitTestCuSpMatrixSetUnit().
void CopyFromPacked | ( | const CuPackedMatrix< Real > & | src | ) |
Definition at line 137 of file cu-packed-matrix.cc.
References data_, CuPackedMatrix< Real >::data_, KALDI_ASSERT, CuPackedMatrix< Real >::Mat(), and CuPackedMatrix< Real >::NumRows().
Referenced by CuSpMatrix< Real >::CopyFromSp(), CuTpMatrix< Real >::CopyFromTp(), CuPackedMatrix< Real >::CuPackedMatrix(), CuTpMatrix< Real >::operator=(), kaldi::UnitTestCuPackedMatrixCopy(), and CuPackedMatrix< Real >::~CuPackedMatrix().
void CopyFromPacked | ( | const PackedMatrix< Real > & | src | ) |
Definition at line 159 of file cu-packed-matrix.cc.
References data_, PackedMatrix< Real >::data_, KALDI_ASSERT, PackedMatrix< Real >::NumRows(), and PackedMatrix< Real >::SizeInBytes().
void CopyToPacked | ( | PackedMatrix< Real > * | dst | ) | const |
Definition at line 178 of file cu-packed-matrix.cc.
References PackedMatrix< Real >::CopyFromPacked(), data_, PackedMatrix< Real >::data_, KALDI_ASSERT, and PackedMatrix< Real >::NumRows().
Referenced by TpMatrix< float >::CopyFromMat(), CuSpMatrix< Real >::CopyToSp(), kaldi::UnitTestCuPackedMatrixCopy(), and CuPackedMatrix< Real >::~CuPackedMatrix().
|
inline |
Definition at line 113 of file cu-packed-matrix.h.
References CuPackedMatrix< Real >::data_.
Referenced by CuPackedMatrix< Real >::AddPacked(), CuVectorBase< float >::AddSpVec(), CuVectorBase< float >::CopyDiagFromPacked(), CuMatrixBase< float >::CopyFromSp(), CuMatrixBase< float >::CopyFromTp(), CuVectorBase< float >::MulTp(), and kaldi::TraceSpSp().
|
inline |
void Destroy | ( | ) |
Definition at line 85 of file cu-packed-matrix.cc.
References data_, and KALDI_MEMALIGN_FREE.
Referenced by CuPackedMatrix< Real >::~CuPackedMatrix().
|
inlineprotected |
Definition at line 150 of file cu-packed-matrix.h.
Referenced by CuPackedMatrix< Real >::AddPacked(), CuVectorBase< float >::CopyDiagFromPacked(), and CuPackedMatrix< Real >::CopyFromPacked().
|
inlineprotected |
Definition at line 153 of file cu-packed-matrix.h.
|
inline |
Definition at line 136 of file cu-packed-matrix.h.
References CuPackedMatrix< Real >::num_rows_.
Referenced by CuVectorBase< float >::AddSpVec(), and CuMatrix< float >::CuMatrix().
|
inline |
Definition at line 135 of file cu-packed-matrix.h.
References CuPackedMatrix< Real >::num_rows_.
Referenced by CuPackedMatrix< Real >::AddPacked(), CuVectorBase< float >::AddSpVec(), CuVectorBase< float >::AddTpVec(), CuSpMatrix< Real >::ApproxEqual(), kaldi::AssertEqual(), CuVectorBase< float >::CopyDiagFromPacked(), CuPackedMatrix< Real >::CopyFromPacked(), CuMatrixBase< float >::CopyFromSp(), CuMatrixBase< float >::CopyFromTp(), CuMatrix< float >::CuMatrix(), CuTpMatrix< Real >::Invert(), CuVectorBase< float >::MulTp(), CuSpMatrix< Real >::operator=(), CuTpMatrix< Real >::operator=(), TpMatrix< float >::TpMatrix(), kaldi::TraceSpSp(), and kaldi::UnitTestCuPackedMatrixSetUnit().
|
inline |
Definition at line 116 of file cu-packed-matrix.h.
References CuPackedMatrix< Real >::data_, KALDI_ASSERT, CuPackedMatrix< Real >::num_rows_, and kaldi::swap().
|
private |
void Read | ( | std::istream & | in, |
bool | binary | ||
) |
Definition at line 231 of file cu-packed-matrix.cc.
References PackedMatrix< Real >::Read().
Referenced by kaldi::UnitTestCuSpMatrixIO(), kaldi::UnitTestCuTpMatrixIO(), and CuPackedMatrix< Real >::~CuPackedMatrix().
void Resize | ( | MatrixIndexT | nRows, |
MatrixResizeType | resize_type = kSetZero |
||
) |
Set packed matrix to a specified size (can be zero).
The value of the new data depends on resize_type: -if kSetZero, the new data will be zero -if kUndefined, the new data will be undefined -if kCopyData, the new data will be the same as the old data in any shared positions, and zero elsewhere. This function takes time proportional to the number of data elements.
Definition at line 40 of file cu-packed-matrix.cc.
References data_, KALDI_ASSERT, kaldi::kSetZero, and kaldi::kUndefined.
Referenced by CuPackedMatrix< Real >::CuPackedMatrix(), CuTpMatrix< Real >::operator=(), CuSpMatrix< Real >::Resize(), TpMatrix< float >::TpMatrix(), and CuPackedMatrix< Real >::~CuPackedMatrix().
void Scale | ( | Real | alpha | ) |
Definition at line 299 of file cu-packed-matrix.cc.
References data_.
Referenced by CuPackedMatrix< Real >::CuPackedMatrix(), and kaldi::UnitTestCuPackedMatrixScale().
void ScaleDiag | ( | Real | alpha | ) |
Definition at line 316 of file cu-packed-matrix.cc.
References CU1DBLOCK, and data_.
Referenced by CuPackedMatrix< Real >::CuPackedMatrix(), kaldi::UnitTestCuPackedMatrixScaleDiag(), and kaldi::nnet2::UnitTestPreconditionDirections().
void SetDiag | ( | Real | alpha | ) |
< Set to random values of a normal distribution
Definition at line 281 of file cu-packed-matrix.cc.
References CU1DBLOCK, and data_.
Referenced by CuPackedMatrix< Real >::CuPackedMatrix().
void SetRandn | ( | ) |
< Set to unit matrix.
Definition at line 75 of file cu-packed-matrix.cc.
References data_, and CuRand< Real >::RandGaussian().
Referenced by CuPackedMatrix< Real >::CuPackedMatrix(), kaldi::CuVectorUnitTestAddSpVec(), kaldi::CuVectorUnitTestCopyDiagFromPacked(), kaldi::TestCuMatrixCopyFromSp(), kaldi::TestCuMatrixCopyFromTp(), kaldi::UnitTestCuSpMatrixInvert(), kaldi::UnitTestCuSpMatrixIO(), kaldi::UnitTestCuSpMatrixSetUnit(), and kaldi::UnitTestCuTpMatrixIO().
void SetUnit | ( | ) |
< Set to zero
Definition at line 370 of file cu-packed-matrix.cc.
Referenced by CuPackedMatrix< Real >::CuPackedMatrix(), kaldi::UnitTestCuPackedMatrixSetUnit(), and kaldi::nnet2::UnitTestPreconditionDirections().
void SetZero | ( | ) |
Definition at line 246 of file cu-packed-matrix.cc.
References data_.
Referenced by CuPackedMatrix< Real >::CuPackedMatrix(), and kaldi::UnitTestCuSpMatrixSetUnit().
|
inline |
Returns size in bytes of the data held by the matrix.
Definition at line 139 of file cu-packed-matrix.h.
References CuPackedMatrix< Real >::num_rows_.
void Swap | ( | CuPackedMatrix< Real > * | other | ) |
Swaps the contents of *this and *other. Shallow swap.
Referenced by CuPackedMatrix< Real >::~CuPackedMatrix().
void Swap | ( | PackedMatrix< Real > * | other | ) |
Swaps the contents of *this and *other.
Definition at line 101 of file cu-packed-matrix.cc.
References PackedMatrix< Real >::data_, kaldi::kUndefined, PackedMatrix< Real >::num_rows_, PackedMatrix< Real >::Resize(), PackedMatrix< Real >::Swap(), and kaldi::swap().
Real Trace | ( | ) | const |
Definition at line 264 of file cu-packed-matrix.cc.
References CuVectorBase< Real >::CopyDiagFromPacked(), kaldi::kUndefined, and CuVectorBase< Real >::Sum().
Referenced by CuPackedMatrix< Real >::CuPackedMatrix(), kaldi::UnitTestCuPackedMatrixTrace(), kaldi::UnitTestCuSpMatrixInvert(), and kaldi::UnitTestTrace().
void Write | ( | std::ostream & | out, |
bool | binary | ||
) | const |
Definition at line 239 of file cu-packed-matrix.cc.
References kaldi::kUndefined, and PackedMatrix< Real >::Write().
Referenced by kaldi::UnitTestCuSpMatrixIO(), kaldi::UnitTestCuTpMatrixIO(), and CuPackedMatrix< Real >::~CuPackedMatrix().
|
friend |
Definition at line 55 of file cu-packed-matrix.h.
|
friend |
Definition at line 58 of file cu-packed-matrix.h.
|
friend |
Definition at line 57 of file cu-packed-matrix.h.
|
friend |
Definition at line 56 of file cu-packed-matrix.h.
|
protected |
Definition at line 160 of file cu-packed-matrix.h.
Referenced by CuTpMatrix< Real >::CopyFromMat(), CuPackedMatrix< Real >::CopyFromPacked(), CuPackedMatrix< Real >::Data(), CuSpMatrix< Real >::operator()(), and CuPackedMatrix< Real >::operator()().
|
protected |
Definition at line 161 of file cu-packed-matrix.h.
Referenced by CuTpMatrix< Real >::CopyFromMat(), CuTpMatrix< Real >::Invert(), CuPackedMatrix< Real >::NumCols(), CuPackedMatrix< Real >::NumRows(), CuSpMatrix< Real >::operator()(), CuPackedMatrix< Real >::operator()(), and CuPackedMatrix< Real >::SizeInBytes().