Public Member Functions | |
QTensor (const std::vector< int > &dims, const unsigned char precision, const bool signbit=false) | |
Creates a quantized tensor of the given dimension. More... | |
void | Resize (std::vector< int > dim_source) |
void | SetBitAtIndex (const unsigned char bit, const size_t index, const bool value) |
bool | GetBitAtIndex (const unsigned char bit, const size_t index) const |
void | SetPrecision (const unsigned char precision) |
void | SetSigned (const bool make_signed=true) |
void | SetScale (const double scale) |
void | SetBias (const double bias) |
unsigned char * | mutable_data () |
const unsigned char * | data () const |
size_t | size () const |
unsigned char | alignment () const |
unsigned char | precision () const |
const vector< int > & | dims () const |
bool | is_signed () const |
int | ndim () const |
Returns the number of dimensions of the data. | |
size_t | aligned_size () const |
size_t | nbytes () const |
double | scale () const |
double | bias () const |
int | dim32 (const int i) const |
Returns the i-th dimension of the qtensor in int. | |
int | canonical_axis_index (int axis_index) const |
Returns the 'canonical' version of a (usually) user-specified axis, allowing for negative indexing (e.g., -1 for the last axis). More... | |
TIndex | size_from_dim (int k) const |
Return product of all dimensions starting from K. | |
TIndex | size_to_dim (int k) const |
Product of all dims up to. | |
|
inlineexplicit |
Creates a quantized tensor of the given dimension.
Note that the actual data allocation is not going to be carried out until the first time mutable_data() is called.
The underlying storage of the quantized tensor interleaves elements by bit depth.
Labeled memory for tensor of size 6, precision 3 [ E1[0] E2[0] E3[0] E4[0] E5[0] E6[0] ] // Least significant Bits [ E1[1] E2[1] E3[1] E4[1] E5[1] E6[1] ] [ E1[2] E2[2] E3[2] E4[2] E5[2] E6[2] ]
In the case of sign bits (see enable_sign argument), an extra bit per element is added:
Labeled memory for tensor of size 6, precision 3, sign bit enabled [ E1[0] E2[0] E3[0] E4[0] E5[0] E6[0] ] [ E1[1] E2[1] E3[1] E4[1] E5[1] E6[1] ] [ E1[2] E2[2] E3[2] E4[2] E5[2] E6[2] ] [ E1[s] E2[s] E3[s] E4[s] E5[s] E6[s] ] Where 's' is 1 if E is negative
The reason for this layout is the ability to efficiently multiply many low precision integers as a sum of popcnt(A & B) * 1 << bit. Explained here: https://arxiv.org/abs/1606.06160
|
inline |
Returns the 'canonical' version of a (usually) user-specified axis, allowing for negative indexing (e.g., -1 for the last axis).