Caffe2 - C++ API
A deep learning, cross platform ML framework
Public Member Functions | Protected Attributes
caffe2::QTensor< Context > Class Template Reference

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.
 

Protected Attributes

std::vector< int > dims_
 
size_t size_ = 0
 
unsigned char precision_ = CHAR_BIT
 
unsigned char alignment_ = CHAR_BIT
 
std::shared_ptr< unsigned char > data_
 
double scale_
 
double bias_
 
bool signed_ = false
 
size_t capacity_ = 0
 

Detailed Description

template<class Context>
class caffe2::QTensor< Context >

Definition at line 33 of file qtensor.h.

Constructor & Destructor Documentation

template<class Context>
caffe2::QTensor< Context >::QTensor ( const std::vector< int > &  dims,
const unsigned char  precision,
const bool  signbit = false 
)
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

Definition at line 65 of file qtensor.h.

Member Function Documentation

template<class Context>
int caffe2::QTensor< Context >::canonical_axis_index ( int  axis_index) const
inline

Returns the 'canonical' version of a (usually) user-specified axis, allowing for negative indexing (e.g., -1 for the last axis).

Parameters
axis_indexthe axis index. If 0 <= index < ndim(), return index. If -ndim <= index <= -1, return (ndim() - (-index)), e.g., the last axis index (ndim() - 1) if index == -1, the second to last if index == -2, etc. Dies on out of range index.

Definition at line 219 of file qtensor.h.


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