Class CuCompressedMatrix, templated on an integer type (expected to be one of: int8, uint8, int16, uint16), this provides a way to approximate a CuMatrix in a more memory-efficient format. More...
#include <cu-compressed-matrix.h>
Public Member Functions | |
CuCompressedMatrix (BaseFloat range, bool truncate=true) | |
Constructor which sets 'scale_' according to scale_ = range / std::numeric_limits<I>::max(). More... | |
virtual void | CopyFromMat (const CuMatrixBase< BaseFloat > &mat) |
Sets *this to an appropriately compressed copy of 'mat', which includes resizing *this. More... | |
virtual void | CopyToMat (CuMatrixBase< BaseFloat > *mat) const |
Copies the contents of *this to 'mat', which should be correctly sized beforehand. More... | |
virtual MatrixIndexT | NumRows () const |
virtual MatrixIndexT | NumCols () const |
virtual | ~CuCompressedMatrix () |
Public Member Functions inherited from CuCompressedMatrixBase | |
virtual | ~CuCompressedMatrixBase () |
Private Member Functions | |
void | Destroy () |
Private Attributes | |
I * | data_ |
BaseFloat | scale_ |
bool | truncate_ |
MatrixIndexT | num_rows_ |
MatrixIndexT | num_cols_ |
MatrixIndexT | stride_ |
Class CuCompressedMatrix, templated on an integer type (expected to be one of: int8, uint8, int16, uint16), this provides a way to approximate a CuMatrix in a more memory-efficient format.
It's used in nnet3 to reduce memory use for large networks.
It is *not* a CUDA equivalent for class CompressedMatrix (of ../matrix/compressed-matrix.h). Note: this class is only to be used when you are using a GPU. If you didn't compile for CUDA or you are not using a GPU, you are not supposed to create an instance of this class, and doing so will cause a runtime error.
Definition at line 72 of file cu-compressed-matrix.h.
CuCompressedMatrix | ( | BaseFloat | range, |
bool | truncate = true |
||
) |
Constructor which sets 'scale_' according to scale_ = range / std::numeric_limits<I>::max().
range = 0 (only supported for I == int8) is a special case in which only the sign of the input is retained; and when we reconstruct, the output will be -1, 0 or 1.
truncate (only relevant if range != 0) should be true if it's possible that the input could exceed the allowed input range, i.e. [0, range] if I is unsigned, and [-range, range] if I is signed; and it may be false if you know that the input (the matrix given to CopyFromMat) will have elements only in the allowed range. Setting 'truncate' to false allows the compression code to avoid the bounds check.
Definition at line 38 of file cu-compressed-matrix.cc.
References KALDI_ASSERT, and KALDI_ERR.
|
inlinevirtual |
Definition at line 99 of file cu-compressed-matrix.h.
|
virtual |
Sets *this to an appropriately compressed copy of 'mat', which includes resizing *this.
The details of how this is done will be different in different child classes.
Implements CuCompressedMatrixBase.
Definition at line 65 of file cu-compressed-matrix.cc.
References CuMatrixBase< Real >::Data(), CuCompressedMatrix< I >::data_, CuCompressedMatrix< I >::Destroy(), CuMatrixBase< Real >::Dim(), KALDI_ASSERT, CuCompressedMatrix< I >::num_cols_, CuCompressedMatrix< I >::num_rows_, CuCompressedMatrix< I >::NumCols(), CuMatrixBase< Real >::NumCols(), CuCompressedMatrix< I >::NumRows(), CuMatrixBase< Real >::NumRows(), CuCompressedMatrix< I >::scale_, CuCompressedMatrix< I >::stride_, and CuCompressedMatrix< I >::truncate_.
|
virtual |
Copies the contents of *this to 'mat', which should be correctly sized beforehand.
Implements CuCompressedMatrixBase.
Definition at line 102 of file cu-compressed-matrix.cc.
References CuMatrixBase< Real >::Data(), CuCompressedMatrix< I >::data_, CuMatrixBase< Real >::Dim(), KALDI_ASSERT, CuCompressedMatrix< I >::num_cols_, CuCompressedMatrix< I >::num_rows_, CuCompressedMatrix< I >::NumCols(), CuMatrixBase< Real >::NumCols(), CuCompressedMatrix< I >::NumRows(), CuMatrixBase< Real >::NumRows(), CuCompressedMatrix< I >::scale_, and CuCompressedMatrix< I >::stride_.
|
private |
Definition at line 50 of file cu-compressed-matrix.cc.
References CuCompressedMatrix< I >::data_, CuCompressedMatrix< I >::num_cols_, CuCompressedMatrix< I >::num_rows_, and CuCompressedMatrix< I >::stride_.
Referenced by CuCompressedMatrix< I >::CopyFromMat().
|
inlinevirtual |
Implements CuCompressedMatrixBase.
Definition at line 96 of file cu-compressed-matrix.h.
Referenced by CuCompressedMatrix< I >::CopyFromMat(), and CuCompressedMatrix< I >::CopyToMat().
|
inlinevirtual |
Implements CuCompressedMatrixBase.
Definition at line 94 of file cu-compressed-matrix.h.
Referenced by CuCompressedMatrix< I >::CopyFromMat(), and CuCompressedMatrix< I >::CopyToMat().
|
private |
Definition at line 106 of file cu-compressed-matrix.h.
Referenced by CuCompressedMatrix< I >::CopyFromMat(), CuCompressedMatrix< I >::CopyToMat(), and CuCompressedMatrix< I >::Destroy().
|
private |
Definition at line 129 of file cu-compressed-matrix.h.
Referenced by CuCompressedMatrix< I >::CopyFromMat(), CuCompressedMatrix< I >::CopyToMat(), and CuCompressedMatrix< I >::Destroy().
|
private |
Definition at line 128 of file cu-compressed-matrix.h.
Referenced by CuCompressedMatrix< I >::CopyFromMat(), CuCompressedMatrix< I >::CopyToMat(), and CuCompressedMatrix< I >::Destroy().
|
private |
Definition at line 117 of file cu-compressed-matrix.h.
Referenced by CuCompressedMatrix< I >::CopyFromMat(), and CuCompressedMatrix< I >::CopyToMat().
|
private |
Definition at line 132 of file cu-compressed-matrix.h.
Referenced by CuCompressedMatrix< I >::CopyFromMat(), CuCompressedMatrix< I >::CopyToMat(), and CuCompressedMatrix< I >::Destroy().
|
private |
Definition at line 126 of file cu-compressed-matrix.h.
Referenced by CuCompressedMatrix< I >::CopyFromMat().