The class CuBlockMatrix holds a vector of objects of type CuMatrix, say, M_1, M_2, . More...
#include <cu-block-matrix.h>
Classes | |
struct | BlockMatrixData |
Public Member Functions | |
CuBlockMatrix () | |
CuBlockMatrix (const std::vector< CuMatrix< Real > > &data) | |
~CuBlockMatrix () | |
CuBlockMatrix (const CuBlockMatrix &other) | |
Copy constructor. More... | |
CuBlockMatrix & | operator= (const CuBlockMatrix &other) |
Assignment operator. More... | |
void | Write (std::ostream &os, bool binary) const |
void | Read (std::istream &is, bool binary) |
MatrixIndexT | NumRows () const |
MatrixIndexT | NumCols () const |
MatrixIndexT | NumBlocks () const |
MatrixIndexT | MaxBlockCols () const |
MatrixIndexT | MaxBlockRows () const |
const CuSubMatrix< Real > | Block (MatrixIndexT b) const |
CuSubMatrix< Real > | Block (MatrixIndexT b) |
void | AddMatMat (BaseFloat alpha, const CuMatrix< Real > &A, MatrixTransposeType transA, const CuMatrix< Real > &B, MatrixTransposeType transB, BaseFloat beta) |
Does *this = alpha A B + beta * *this, discarding elements of the product outside the block structure of the *this matrix. More... | |
void | CopyFromMat (const CuMatrix< Real > &M) |
Copies elements within the block structure from matrix M, discarding others. More... | |
void | NormalizeColumns () |
Normalizes the columns of *this so that each one sums to one. More... | |
void | Swap (CuBlockMatrix *other) |
Protected Attributes | |
CuMatrix< Real > | data_ |
Private Member Functions | |
void | FreeCudaData () |
If using GPU and cu_data_ != NULL, free cu_data_ and set it to NULL. More... | |
void | SetCudaData () |
If using GPU, allocate and set cu_data_ on the GPU to reflect "data_". More... | |
void | Destroy () |
Frees and deinitializes everything. More... | |
Private Attributes | |
std::vector< BlockMatrixData > | block_data_ |
MatrixIndexT | num_rows_ |
Friends | |
class | CuMatrixBase< Real > |
The class CuBlockMatrix holds a vector of objects of type CuMatrix, say, M_1, M_2, .
. M_N and it represents the matrix diag(M_1, M_2, ... M_N). Note: the individual matrices do not have to be square. The reason the class is needed is mostly so that we can efficiently multiply by this block-diagonal structure in a parallel way.
If we have a GPU available, CuBlockMatrix will store a copy of the individual CuMatrix quantities M_1 .. M_N on the GPU, but their 'primary' home remains on the CPU.. what we mean by this is that while the data remains on the GPU, the "primary" version of the Matrix object that holds the pointers will remain on the CPU. We just copy it over to the GPU whenever it is changed.
Definition at line 51 of file cu-block-matrix.h.
CuBlockMatrix | ( | ) |
Definition at line 35 of file cu-block-matrix.cc.
Referenced by CuBlockMatrix< Real >::Block(), and CuBlockMatrix< Real >::~CuBlockMatrix().
CuBlockMatrix | ( | const std::vector< CuMatrix< Real > > & | data | ) |
Definition at line 42 of file cu-block-matrix.cc.
References CuBlockMatrix< Real >::BlockMatrixData::col_offset, data_, KALDI_ASSERT, CuBlockMatrix< Real >::BlockMatrixData::num_cols, CuBlockMatrix< Real >::BlockMatrixData::num_rows, and CuBlockMatrix< Real >::BlockMatrixData::row_offset.
|
inline |
Definition at line 59 of file cu-block-matrix.h.
References CuBlockMatrix< Real >::CuBlockMatrix(), CuBlockMatrix< Real >::Destroy(), CuBlockMatrix< Real >::operator=(), CuBlockMatrix< Real >::Read(), and CuBlockMatrix< Real >::Write().
CuBlockMatrix | ( | const CuBlockMatrix< Real > & | other | ) |
Copy constructor.
void AddMatMat | ( | BaseFloat | alpha, |
const CuMatrix< Real > & | A, | ||
MatrixTransposeType | transA, | ||
const CuMatrix< Real > & | B, | ||
MatrixTransposeType | transB, | ||
BaseFloat | beta | ||
) |
Does *this = alpha A B + beta * *this, discarding elements of the product outside the block structure of the *this matrix.
The transA and transB parameters can be used to substitute A^T for A and B^T for B, respectively.
Definition at line 213 of file cu-block-matrix.cc.
References CuMatrixBase< Real >::AddMatMat(), CU1DBLOCK, CU2DBLOCK, CuMatrixBase< Real >::Data(), KALDI_ASSERT, kaldi::kNoTrans, kaldi::kTrans, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), CuMatrixBase< Real >::Range(), CuMatrixBase< Real >::Stride(), and kaldi::swap().
Referenced by CuBlockMatrix< Real >::NumBlocks(), and kaldi::UnitTestCuBlockMatrixAddMatMat().
const CuSubMatrix< Real > Block | ( | MatrixIndexT | b | ) | const |
Definition at line 70 of file cu-block-matrix.cc.
References data_, and KALDI_ASSERT.
Referenced by CuMatrixBase< float >::AddMatBlock(), CuMatrixBase< float >::CopyFromBlock(), and CuBlockMatrix< Real >::NumBlocks().
CuSubMatrix< Real > Block | ( | MatrixIndexT | b | ) |
Definition at line 78 of file cu-block-matrix.cc.
References CuBlockMatrix< Real >::block_data_, CuBlockMatrix< Real >::CuBlockMatrix(), data_, CuBlockMatrix< Real >::data_, KALDI_ASSERT, and CuBlockMatrix< Real >::num_rows_.
void CopyFromMat | ( | const CuMatrix< Real > & | M | ) |
Copies elements within the block structure from matrix M, discarding others.
Note: this has not been implemented in a very efficient way, it's used only for testing.
Definition at line 298 of file cu-block-matrix.cc.
References CuMatrixBase< Real >::CopyFromMat(), KALDI_ASSERT, CuMatrixBase< Real >::NumCols(), and CuMatrixBase< Real >::NumRows().
Referenced by CuBlockMatrix< Real >::NumBlocks(), and kaldi::UnitTestCuBlockMatrixAddMatMat().
|
private |
Frees and deinitializes everything.
Definition at line 203 of file cu-block-matrix.cc.
References data_.
Referenced by CuBlockMatrix< Real >::~CuBlockMatrix().
|
private |
If using GPU and cu_data_ != NULL, free cu_data_ and set it to NULL.
Definition at line 106 of file cu-block-matrix.cc.
References KALDI_ERR.
MatrixIndexT MaxBlockCols | ( | ) | const |
Definition at line 285 of file cu-block-matrix.cc.
References rnnlm::i.
Referenced by CuBlockMatrix< Real >::NumBlocks().
MatrixIndexT MaxBlockRows | ( | ) | const |
Definition at line 293 of file cu-block-matrix.cc.
References data_.
Referenced by CuBlockMatrix< Real >::NumBlocks().
void NormalizeColumns | ( | ) |
Normalizes the columns of *this so that each one sums to one.
On error (e.g. inf's), will set the column to a constant value that sums to one.
Referenced by CuBlockMatrix< Real >::NumBlocks().
|
inline |
Definition at line 75 of file cu-block-matrix.h.
References CuBlockMatrix< Real >::AddMatMat(), CuBlockMatrix< Real >::Block(), CuBlockMatrix< Real >::block_data_, CuBlockMatrix< Real >::CopyFromMat(), CuBlockMatrix< Real >::MaxBlockCols(), CuBlockMatrix< Real >::MaxBlockRows(), CuBlockMatrix< Real >::NormalizeColumns(), and CuBlockMatrix< Real >::Swap().
Referenced by CuMatrixBase< float >::AddMatBlock(), and CuMatrixBase< float >::CopyFromBlock().
|
inline |
Definition at line 73 of file cu-block-matrix.h.
References CuBlockMatrix< Real >::data_.
Referenced by CuMatrixBase< float >::AddMatBlock(), CuMatrixBase< float >::CopyFromBlock(), CuMatrix< float >::CuMatrix(), kaldi::UnitTestCuBlockMatrixAddMatBlock(), and kaldi::UnitTestCuBlockMatrixAddMatMat().
|
inline |
Definition at line 71 of file cu-block-matrix.h.
References CuBlockMatrix< Real >::num_rows_.
Referenced by CuMatrixBase< float >::AddMatBlock(), CuMatrixBase< float >::CopyFromBlock(), CuMatrix< float >::CuMatrix(), kaldi::UnitTestCuBlockMatrixAddMatBlock(), and kaldi::UnitTestCuBlockMatrixAddMatMat().
CuBlockMatrix< Real > & operator= | ( | const CuBlockMatrix< Real > & | other | ) |
Assignment operator.
Definition at line 96 of file cu-block-matrix.cc.
References CuBlockMatrix< Real >::block_data_, data_, CuBlockMatrix< Real >::data_, and CuBlockMatrix< Real >::num_rows_.
Referenced by CuBlockMatrix< Real >::~CuBlockMatrix().
void Read | ( | std::istream & | is, |
bool | binary | ||
) |
Definition at line 173 of file cu-block-matrix.cc.
References kaldi::ExpectToken(), rnnlm::i, KALDI_ASSERT, kaldi::Peek(), and kaldi::ReadBasicType().
Referenced by kaldi::UnitTestCuBlockMatrixIO(), and CuBlockMatrix< Real >::~CuBlockMatrix().
|
private |
If using GPU, allocate and set cu_data_ on the GPU to reflect "data_".
Definition at line 122 of file cu-block-matrix.cc.
References CuBlockMatrixData_::col_offset, CuMatrixBase< Real >::Data(), CuMatrixBase< Real >::Dim(), KALDI_ASSERT, CuBlockMatrixData_::matrix_data, CuBlockMatrixData_::matrix_dim, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), and CuBlockMatrixData_::row_offset.
void Swap | ( | CuBlockMatrix< Real > * | other | ) |
Definition at line 152 of file cu-block-matrix.cc.
References CuBlockMatrix< Real >::block_data_, data_, CuBlockMatrix< Real >::data_, CuBlockMatrix< Real >::num_rows_, and kaldi::swap().
Referenced by CuBlockMatrix< Real >::NumBlocks().
void Write | ( | std::ostream & | os, |
bool | binary | ||
) | const |
Definition at line 162 of file cu-block-matrix.cc.
References kaldi::WriteBasicType(), and kaldi::WriteToken().
Referenced by kaldi::UnitTestCuBlockMatrixIO(), and CuBlockMatrix< Real >::~CuBlockMatrix().
|
friend |
Definition at line 53 of file cu-block-matrix.h.
|
private |
Definition at line 135 of file cu-block-matrix.h.
Referenced by CuBlockMatrix< Real >::Block(), CuBlockMatrix< Real >::NumBlocks(), CuBlockMatrix< Real >::operator=(), and CuBlockMatrix< Real >::Swap().
|
protected |
Definition at line 110 of file cu-block-matrix.h.
Referenced by CuBlockMatrix< Real >::Block(), CuBlockMatrix< Real >::NumCols(), CuBlockMatrix< Real >::operator=(), and CuBlockMatrix< Real >::Swap().
|
private |
Definition at line 137 of file cu-block-matrix.h.
Referenced by CuBlockMatrix< Real >::Block(), CuBlockMatrix< Real >::NumRows(), CuBlockMatrix< Real >::operator=(), and CuBlockMatrix< Real >::Swap().