CuTpMatrix< Real > Class Template Reference

#include <matrix-common.h>

Inheritance diagram for CuTpMatrix< Real >:
Collaboration diagram for CuTpMatrix< Real >:

Public Member Functions

 CuTpMatrix ()
 
 CuTpMatrix (MatrixIndexT r, MatrixResizeType resize_type=kSetZero)
 
 CuTpMatrix (const TpMatrix< Real > &orig)
 
 CuTpMatrix (const CuTpMatrix< Real > &orig)
 
 CuTpMatrix (const CuMatrixBase< Real > &orig, MatrixTransposeType trans=kNoTrans)
 
 ~CuTpMatrix ()
 
void CopyFromMat (const CuMatrixBase< Real > &M, MatrixTransposeType Trans=kNoTrans)
 
void CopyFromTp (const CuTpMatrix< Real > &other)
 
void CopyFromTp (const TpMatrix< Real > &other)
 
void Cholesky (const CuSpMatrix< Real > &Orig)
 
void Invert ()
 
CuTpMatrix< Real > & operator= (const CuTpMatrix< Real > &in)
 
- Public Member Functions inherited from CuPackedMatrix< Real >
 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 TpMatrix< Real > & Mat () const
 
TpMatrix< Real > & Mat ()
 
- Protected Member Functions inherited from CuPackedMatrix< Real >
const PackedMatrix< Real > & Mat () const
 
PackedMatrix< Real > & Mat ()
 
void AddPacked (const Real alpha, const CuPackedMatrix< Real > &M)
 

Friends

class CuMatrixBase< float >
 
class CuMatrixBase< double >
 
class CuVectorBase< Real >
 
class CuSubMatrix< Real >
 
class CuRand< Real >
 
class CuTpMatrix< float >
 
class CuTpMatrix< double >
 

Additional Inherited Members

- Protected Attributes inherited from CuPackedMatrix< Real >
Real * data_
 
MatrixIndexT num_rows_
 

Detailed Description

template<typename Real>
class kaldi::CuTpMatrix< Real >

Definition at line 77 of file matrix-common.h.

Constructor & Destructor Documentation

◆ CuTpMatrix() [1/5]

CuTpMatrix ( )
inline

Definition at line 48 of file cu-tp-matrix.h.

48 : CuPackedMatrix<Real>() {}

◆ CuTpMatrix() [2/5]

CuTpMatrix ( MatrixIndexT  r,
MatrixResizeType  resize_type = kSetZero 
)
inlineexplicit

Definition at line 49 of file cu-tp-matrix.h.

50  : CuPackedMatrix<Real>(r, resize_type) {}

◆ CuTpMatrix() [3/5]

CuTpMatrix ( const TpMatrix< Real > &  orig)
inlineexplicit

Definition at line 52 of file cu-tp-matrix.h.

53  : CuPackedMatrix<Real>(orig) {}

◆ CuTpMatrix() [4/5]

CuTpMatrix ( const CuTpMatrix< Real > &  orig)
inline

Definition at line 56 of file cu-tp-matrix.h.

References kaldi::kNoTrans.

57  : CuPackedMatrix<Real>(orig) {}

◆ CuTpMatrix() [5/5]

CuTpMatrix ( const CuMatrixBase< Real > &  orig,
MatrixTransposeType  trans = kNoTrans 
)
explicit

Definition at line 40 of file cu-tp-matrix.cc.

References CuTpMatrix< Real >::CopyFromMat(), KALDI_ASSERT, CuMatrixBase< Real >::NumCols(), and CuMatrixBase< Real >::NumRows().

40  :
41  CuPackedMatrix<Real>(orig.NumRows(), kUndefined) {
42  KALDI_ASSERT(orig.NumRows() == orig.NumCols());
43  this->CopyFromMat(orig, trans);
44 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void CopyFromMat(const CuMatrixBase< Real > &M, MatrixTransposeType Trans=kNoTrans)
Definition: cu-tp-matrix.cc:89

◆ ~CuTpMatrix()

~CuTpMatrix ( )
inline

Definition at line 63 of file cu-tp-matrix.h.

References CuTpMatrix< Real >::CopyFromMat(), and kaldi::kNoTrans.

63 {}

Member Function Documentation

◆ Cholesky()

void Cholesky ( const CuSpMatrix< Real > &  Orig)

Definition at line 48 of file cu-tp-matrix.cc.

References CuMatrixBase< Real >::Cholesky(), CuTpMatrix< Real >::CopyFromMat(), kaldi::kNoTrans, CuTpMatrix< Real >::Mat(), and CuSpMatrix< Real >::Mat().

Referenced by CuTpMatrix< Real >::CopyFromTp(), and kaldi::UnitTestCuTpMatrixCholesky().

48  {
49 #if HAVE_CUDA==1
50  if (CuDevice::Instantiate().Enabled()) {
51  CuMatrix<Real> tmp(orig);
52  tmp.Cholesky();
53  this->CopyFromMat(tmp, kNoTrans);
54  } else
55 #endif
56  {
57  this->Mat().Cholesky(orig.Mat());
58  }
59 }
void CopyFromMat(const CuMatrixBase< Real > &M, MatrixTransposeType Trans=kNoTrans)
Definition: cu-tp-matrix.cc:89
const TpMatrix< Real > & Mat() const
Definition: cu-tp-matrix.h:80

◆ CopyFromMat()

void CopyFromMat ( const CuMatrixBase< Real > &  M,
MatrixTransposeType  Trans = kNoTrans 
)

Definition at line 89 of file cu-tp-matrix.cc.

References CU2DBLOCK, CuMatrixBase< Real >::Data(), CuPackedMatrix< Real >::data_, CuMatrixBase< Real >::Dim(), KALDI_ASSERT, kaldi::kNoTrans, CuTpMatrix< Real >::Mat(), CuMatrixBase< Real >::Mat(), CuPackedMatrix< Real >::num_rows_, CuMatrixBase< Real >::NumCols(), and CuMatrixBase< Real >::NumRows().

Referenced by CuTpMatrix< Real >::Cholesky(), CuTpMatrix< Real >::CuTpMatrix(), CuTpMatrix< Real >::Invert(), TpMatrix< float >::TpMatrix(), kaldi::UnitTestCuTpMatrixCopyFromMat(), and CuTpMatrix< Real >::~CuTpMatrix().

90  {
91 #if HAVE_CUDA==1
92  if (CuDevice::Instantiate().Enabled()) {
93  MatrixIndexT num_rows = this->num_rows_;
94  KALDI_ASSERT(num_rows == M.NumRows() && this->num_rows_ == M.NumCols());
95  if (num_rows == 0) return;
96  CuTimer tim;
97  dim3 dimBlock(CU2DBLOCK, CU2DBLOCK);
98  dim3 dimGrid(n_blocks(num_rows, CU2DBLOCK), n_blocks(num_rows, CU2DBLOCK));
99  if (Trans == kNoTrans) {
100  cuda_take_lower(dimGrid, dimBlock, M.Data(), this->data_, M.Dim());
101  } else {
102  cuda_take_upper(dimGrid, dimBlock, M.Data(), this->data_, M.Dim());
103  }
104  CU_SAFE_CALL(cudaGetLastError());
105  CuDevice::Instantiate().AccuProfile(__func__, tim);
106  } else
107 #endif
108  {
109  Mat().CopyFromMat(M.Mat(), Trans);
110  }
111 }
int32 MatrixIndexT
Definition: matrix-common.h:98
#define CU2DBLOCK
Definition: cu-matrixdim.h:61
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
const TpMatrix< Real > & Mat() const
Definition: cu-tp-matrix.h:80

◆ CopyFromTp() [1/2]

void CopyFromTp ( const CuTpMatrix< Real > &  other)
inline

Definition at line 68 of file cu-tp-matrix.h.

References CuPackedMatrix< Real >::CopyFromPacked().

Referenced by CuMatrixBase< float >::Cholesky(), and kaldi::UnitTestCuTpMatrixCopyFromTp().

68  {
70  }
void CopyFromPacked(const CuPackedMatrix< Real > &src)

◆ CopyFromTp() [2/2]

void CopyFromTp ( const TpMatrix< Real > &  other)
inline

◆ Invert()

void Invert ( )

Definition at line 63 of file cu-tp-matrix.cc.

References CuTpMatrix< Real >::CopyFromMat(), CuMatrixBase< Real >::CopyFromTp(), CU2DBLOCK, CuMatrixBase< Real >::Data(), CuMatrixBase< Real >::Dim(), kaldi::kNoTrans, CuTpMatrix< Real >::Mat(), CuPackedMatrix< Real >::num_rows_, CuPackedMatrix< Real >::NumRows(), and MatrixDim_::stride.

Referenced by CuTpMatrix< Real >::CopyFromTp().

63  {
64 #if HAVE_CUDA==1
65  if (CuDevice::Instantiate().Enabled()) {
66  if (this->num_rows_ == 0) return;
67  CuTimer tim;
68  int dimBlock(CU2DBLOCK);
69  int dimGrid(n_blocks(this->NumRows(), CU2DBLOCK));
70  CuMatrix<Real> tmp(this->NumRows(), this->NumRows());
71  int dim = this->NumRows();
72  Real alpha = 1.0;
73  cuda_set_diag(dimGrid, dimBlock, tmp.Data(), alpha, tmp.Dim());
74  CU_SAFE_CALL(cudaGetLastError());
75  CuMatrix<Real> tmp2(dim, dim);
76  tmp2.CopyFromTp(*this);
77  CUBLAS_SAFE_CALL(cublas_trsm(GetCublasHandle(), dim, dim, alpha, tmp2.Data(), tmp2.Dim().stride,
78  tmp.Data(), tmp.Dim().stride));
79  this->CopyFromMat(tmp, kNoTrans);
80  CuDevice::Instantiate().AccuProfile(__func__, tim);
81  } else
82 #endif
83  {
84  Mat().Invert();
85  }
86 }
MatrixIndexT NumRows() const
#define CU2DBLOCK
Definition: cu-matrixdim.h:61
void CopyFromMat(const CuMatrixBase< Real > &M, MatrixTransposeType Trans=kNoTrans)
Definition: cu-tp-matrix.cc:89
const TpMatrix< Real > & Mat() const
Definition: cu-tp-matrix.h:80

◆ Mat() [1/2]

const TpMatrix<Real>& Mat ( ) const
inlineprotected

Definition at line 80 of file cu-tp-matrix.h.

Referenced by CuVectorBase< float >::AddTpVec(), CuTpMatrix< Real >::Cholesky(), CuTpMatrix< Real >::CopyFromMat(), CuMatrixBase< float >::CopyFromTp(), CuTpMatrix< Real >::Invert(), and CuVectorBase< float >::MulTp().

80  {
81  return *(reinterpret_cast<const TpMatrix<Real>* >(this));
82  }

◆ Mat() [2/2]

TpMatrix<Real>& Mat ( )
inlineprotected

Definition at line 83 of file cu-tp-matrix.h.

83  {
84  return *(reinterpret_cast<TpMatrix<Real>* >(this));
85  }

◆ operator=()

CuTpMatrix< Real > & operator= ( const CuTpMatrix< Real > &  in)

Definition at line 130 of file cu-tp-matrix.cc.

References CuPackedMatrix< Real >::CopyFromPacked(), kaldi::kUndefined, CuPackedMatrix< Real >::NumRows(), and CuPackedMatrix< Real >::Resize().

Referenced by CuTpMatrix< Real >::CopyFromTp().

130  {
131  this->Resize(in.NumRows(), kUndefined);
132  this->CopyFromPacked(in);
133  return *this;
134 }
void Resize(MatrixIndexT nRows, MatrixResizeType resize_type=kSetZero)
Set packed matrix to a specified size (can be zero).
void CopyFromPacked(const CuPackedMatrix< Real > &src)

Friends And Related Function Documentation

◆ CuMatrixBase< double >

friend class CuMatrixBase< double >
friend

Definition at line 41 of file cu-tp-matrix.h.

◆ CuMatrixBase< float >

friend class CuMatrixBase< float >
friend

Definition at line 40 of file cu-tp-matrix.h.

◆ CuRand< Real >

friend class CuRand< Real >
friend

Definition at line 44 of file cu-tp-matrix.h.

◆ CuSubMatrix< Real >

friend class CuSubMatrix< Real >
friend

Definition at line 43 of file cu-tp-matrix.h.

◆ CuTpMatrix< double >

friend class CuTpMatrix< double >
friend

Definition at line 46 of file cu-tp-matrix.h.

◆ CuTpMatrix< float >

friend class CuTpMatrix< float >
friend

Definition at line 45 of file cu-tp-matrix.h.

◆ CuVectorBase< Real >

friend class CuVectorBase< Real >
friend

Definition at line 42 of file cu-tp-matrix.h.


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