TTConvConfig#
Currently, this API is unsupported in Python
-
class TTConvConfig : public helayers::SaveableBasic#
A configuration class for TTConvolutionInterleaved.
It is provided with meta-data only: the input shape and other configuration options. It performs validations and computes some derived meta data.
Semantics of dimensions: In all cases corresponding input, filters, and biases dims should be compatible.
imageRowsDim, imageColsDim: Input: two interleaved dims describing the image. Filters: fully duplicated (possibly masked) Output: interleaved dims describing the output image (possibly smaller due to padding options or to strides. We currently block if the sizes increase) bias: originalSize=1
filtersDim: (optional) Input: original size 1 Filters: original size according to number of filters, not duplicated Output: Same as in filters, or as in input if no filters. bias: If sumOverChannels=true, no duplication, if sumOverChannels=false then originalSize=1
channelDims: (zero or more) Input: not duplicated, may be summed over. Filters: same original size Output: If sumOverChannels is true, then reduced to 1 by summing over (duplicate if first) Otherwise same as in input bias: If sumOverChannels=false, no duplication, if sumOverChannels=true then originalSize=1
All other dims are either degenerated or are considered batch: Input: anything Filters: original_size=1 Output: same as input bias: originalSize=1
Public Functions
-
inline TTConvConfig(const HeContext &he)#
Construct empty configuration for loading from stream.
- Parameters:
he – HeContext object.
-
inline TTConvConfig(const HeContext &he, const TTShape &inputShapeSkeleton, int filterRows, int filterCols, int numFilters = 0, bool hasBias = false)#
Setup details for interleaved convolution / sum pooling.
- Parameters:
he – The HE context
inputShapeSkeleton – Input tile tensor shape skeleton. Can be incomplete, but channels dimensions must be complete. Used only for tile sizes, number of dimensions, and channel dimensions
filterRows – size of filter along the row dimension
filterCols – size of filter along the col dimension
numFilters – size of filter along the col dimension
hasBias – Whether bias exists
-
TTConvConfig &setStrides(int strideRows, int strideCols)#
Set the strides.
- Parameters:
strideRows – Stride rows
strideCols – Stride cols
-
TTConvConfig &setInternalStrides(int strideRows, int strideCols)#
Set the internal strides.
- Parameters:
strideRows – Stride rows
strideCols – Stride cols
-
TTConvConfig &setChainIndices(int filtersChainIndex, int biasChainIndex = -1)#
Sets the chain indices of filters and (optionally) bias.
- Parameters:
filtersChainIndex – Chain index of filters
biasChainIndex – Chain index of bias, default -1
-
TTConvConfig &setSumOverChannels(bool val)#
Sets whether to sum over channels.
- Parameters:
val – New value
-
TTConvConfig &setPadding(const Padding2d &padding)#
Sets padding.
- Parameters:
padding – padding
-
TTConvConfig &setDims(DimInt imageRows, DimInt imageCols, DimInt filters, const std::vector<DimInt> &channels)#
Set the semantics of the dimensions.
- Parameters:
imageRows – image rows
imageCols – image cols
filters – filters Can be -1 for no filters dim
channels – channels. Can be any list of dims, including empty list.
-
TTConvConfig &setDefaultDims(bool cxyfb)#
Sets the semantics of the dimensions based on defaults.
- Parameters:
cxyfb – If true, then CXYFB, otherwise FXYCB
-
TTConvConfig &setAllInterleaved(bool val)#
When set to true, filters and biases will be entirely with interleaved dimensions.
Otherwise only image dimensions.
- Parameters:
val – New value.
-
TTConvConfig &setEncrypted(bool val)#
Whether the filters and biases should be encrypted.
- Parameters:
val – New value.
-
TTConvConfig &setLazyMode(LazyMode val, const std::string &lazyLoadFiltersFileName = "", const std::string &lazyLoadBiasesFileName = "")#
Sets lazy mode for filters and biases.
- Parameters:
val – New value.
lazyLoadFiltersFileName – File name to save filters content in disk when using lazy loading (optional).
lazyLoadBiasesFileName – File name to save biases content in disk when using lazy loading (optional).
-
TTConvConfig &setEncodeOnTheFly(bool val)#
Set the encode-on-the-fly mode for the filters.
When on, the filters will be encoded one tile at a time to save memory
- Parameters:
val – New Value.
-
virtual std::streamoff save(std::ostream &stream) const override#
Saves this object to a stream in binary form.
Returns the number of bytes written to the output stream.
- Parameters:
stream – [in] output stream to write to
-
virtual std::streamoff load(std::istream &stream) override#
Loads this object from the given stream.
Returns the number of bytes read from the input stream.
- Parameters:
stream – [in] input stream to read from
-
void validateInputShape(const TTShape &inShape) const#
Verifies the given input shape matches the configuration.
- Parameters:
inShape – Input shape
-
TTShape computeOutputDimensions(const TTShape &inShape) const#
Return the output shape for the given input shape.
- Parameters:
inShape – Input shape
-
bool needMasks(const TTShape &inShape) const#
Computes whether masks are necessary for the given input shape.
- Parameters:
inShape – Input shape
-
inline const ImageDimInfo &getImageDimInfo(int dim) const#
Returns image dim information.
- Parameters:
dim – Dimension index
-
inline const Padding2d &getPadding() const#
Returns padding.
-
std::map<DimInt, DimInt> splitShapeDueToInternalStrides(TTShape &shape) const#
Splits the input shape image dimensions to two dimension each, The second one reflecting the internal strides.
- Parameters:
shape – input/output shape
- Returns:
Returns a map between input dims and output dims
-
inline bool hasInternalStrides() const#
Returns true if internal strides were specified.
-
bool isImageDim(int i) const#
Returns true if dim is an image dim.
- Parameters:
i – DImension index
Public Static Functions
-
static bool dimMatchesStride(const TTDim &dim, int stride)#
Check whether a convolution with certain stride can be applied on a dimension.
- Parameters:
dim – Dimension (row or col) to apply convolution on
stride – The stride in question
-
static bool supportsPhysicalPadding(const TTShape &inputShape, const Padding2d &padding, int imageRowsDim, int imageColsDim, bool addDiagnosis, std::string &diagnosis)#
Quick test if given shapes support the physical padding mode.
Returns true if physical padding is supported.
- Parameters:
inputShape – Input shape
padding – The requested amount of padding
imageRowsDim – Dimension index of row dim
imageColsDim – Dimension index of col dim
addDiagnosis – Whether to include a human readable explanation to a false results (slows runtime)
diagnosis – Human readable explanation, when flag is on.
-
static bool supportsPhysicalPadding(const TTShape &inputShape, const Padding2d &padding, int imageRowsDim, int imageColsDim)#
Quick test if given shapes support the physical padding mode.
Returns true if physical padding is supported.
- Parameters:
inputShape – Input shape
padding – The requested amount of padding
imageRowsDim – Dimension index of row dim
imageColsDim – Dimension index of col dim
-
struct ImageDimInfo#
Info on one of the two image dimensions.
Public Functions
-
void save(std::ostream &stream) const#
Saves content of this structure.
- Parameters:
stream – Output stream
-
void load(std::istream &stream)#
Loads content of this structure.
- Parameters:
stream – Input stream
Public Members
-
int stride = 1#
Strides along this dim.
-
int internalStride = 1#
Internal strides.
-
int inputRotateOffset = -1#
Offset when rotating this dim.
-
int filterSize = -1#
Size of filter along this dim.
-
int originalOutputSize = -1#
Final output size including all strides.
-
int originalOutputSizeAfterExternalStrides = -1#
Final output size including external strides only.
-
void save(std::ostream &stream) const#
-
inline TTConvConfig(const HeContext &he)#