TTDim#
- class TTDim#
Specification of a single dimension in a tile tensor shape. See more in TTShape.
- apply_compatibility_adjustments(self: pyhelayers.TTDim, other: pyhelayers.TTDim, actionType: pyhelayers.ActionType) None #
Change this TTDim to be the result of applying a tile tensor operator on this object and other object.
- Parameters:
other (TTDim) – TTDim on which an operator is applied.
at (ActionType) – Action type to apply compatibility for
- duplicate(self: pyhelayers.TTDim, dup: int = -1) None #
Sets dim to be duplicated. Assumes this dim is either incomplete or originalSize==1. and currently not duplicated.
- Parameters:
dup – duplication count. Defaults to -1, which means duplicate to the entire tile size.
- Raises:
ValueError – If the specified dimension has originalSize>1, or is already duplicated
- get_are_unused_slots_unknown(self: pyhelayers.TTDim) bool #
- get_external_size(self: pyhelayers.TTDim) int #
- get_is_complex_packed(self: pyhelayers.TTDim) bool #
Returns whether this dimension is complex packed.
- get_max_used_slots_in_tile(self: pyhelayers.TTDim) int #
Returns a bound on the number of used slots along this dimension in a single tile.
- get_num_duplicated(self: pyhelayers.TTDim) int #
Returns number of duplications.
- get_num_duplicated_slots(self: pyhelayers.TTDim) int #
Returns the number of slots that contain duplicated values.
- get_num_unused_slots(self: pyhelayers.TTDim) int #
- get_num_used_slots(self: pyhelayers.TTDim) int #
- get_original_size(self: pyhelayers.TTDim) int #
Returns original size.
- get_original_size_slots(self: pyhelayers.TTDim) int #
Returns the minimal number of slots required to store the original size numbers.
- get_tile_size(self: pyhelayers.TTDim) int #
- is_compatible(self: pyhelayers.TTDim, other: pyhelayers.TTDim, action_type: pyhelayers.ActionType = <ActionType.OTHER_ACTION_TYPE: 2>) bool #
Returns whether other TTDim is compatible for tile tensor
- Parameters:
other (TTDim) – TTDim to check compatibility with.
at (ActionType) – Action type to check compatibility with.
- is_degenerate_tile(self: pyhelayers.TTDim) bool #
- is_equal_on_original_slots(self: pyhelayers.TTDim, other: pyhelayers.TTDim, enforceInterleavedExternalSize: bool = True) bool #
- is_fully_duplicated(self: pyhelayers.TTDim) bool #
- is_incomplete(self: pyhelayers.TTDim) bool #
- is_interleaved(self: pyhelayers.TTDim) bool #
- reduce_original_size(self: pyhelayers.TTDim, new_original_size: int, new_interleaved_external_size: int = False) pyhelayers.TTDim #
- set_are_unused_slots_unknown(self: pyhelayers.TTDim, are_unknown: bool) pyhelayers.TTDim #
Sets the value of the unknown flag for this dimension. fully duplicated along tile size.
- Parameters:
are_unknown (bool) – Value to set.
- Raises:
ValueError – If areUnknown is true and this dimension has no unused slots.
- set_incomplete(self: pyhelayers.TTDim) None #
- set_interleaved(self: pyhelayers.TTDim, is_interleaved: bool, external_size_divisor: int = 1) pyhelayers.TTDim #
Turns interleave flag on or off.
- Parameters:
is_interleaved (bool) – Whether this dimension is interleaved.
external_size_divisor (int) – If isInterleaved, you can forc the external size to be divisible by this value. Defaults to 1.
- set_interleaved_external_size(self: pyhelayers.TTDim, new_size: int) pyhelayers.TTDim #
Set the interleaved external size of this dimension. Can be called only for dimensions marked with setInterleaved(true). Given size must be at least getMinExternalSize()
- Parameters:
new_size (int) – new interleaved size.
- set_is_complex_packed(self: pyhelayers.TTDim, val: bool) pyhelayers.TTDim #
Sets this dimension’s complex packed flag
- Parameters:
val (bool) – new value to set.
- set_num_duplicated(self: pyhelayers.TTDim, num: int) pyhelayers.TTDim #
- set_original_size(self: pyhelayers.TTDim, size: int, keep_interleaved_external_size: bool = False) pyhelayers.TTDim #
- set_tile_size(self: pyhelayers.TTDim, size: int) pyhelayers.TTDim #
- set_unused_slots_unknown(self: pyhelayers.TTDim) pyhelayers.TTDim #
Indicates that unused slots if they exist are unknown. This turns on the unknown flag for this dimension if it has unused slots.
-
class TTDim : public helayers::SaveableBasic#
Specification of a single dimension in a tile tensor shape.
See more in TTShape.
You can query this object to get attributes such as originalSize, tileSize, numDuplicates, etc…
Notes for complex packed dims:
Complex packing can be either for duplicated data, or for regular data. Currently not for interleaved dimensions.
For regular data (not-duplicated): The data (a,b,c,d) is packed in two slots: (a+ib),(c+id) getOriginalSize() returns the total number of values and is required to be even. getOriginalSizeSlots() returns their packed size, which is half the total number getNumDuplicated(),getNumDuplicatedSlots() returns 1.
For duplicated data: The data (a,a,a,a) is packed in two slots: (a+ia),(a+ia) getOriginalSize(), getOriginalSizeSlots() returns 1. getNumDuplicated() returns the total number of duplicates and is required to be even. getNumDuplicatedSlots() returns half the total number
If a dimension is not complex packed, then: getOriginalSize() == getOriginalSizeSlots() getNumDuplicated() == getNumDuplicatedSlots()
Public Functions
-
TTDim(DimInt originalSize, DimInt tileSize, DimInt numDuplicated = 1, bool areUnusedSlotsUnknown = false, bool isInterleaved = false, bool isComplexPacked = false)#
Construct a new TTDim object.
- Parameters:
originalSize – Original size, or -1 if not specified.
tileSize – Tile size.
numDuplicated – Number of duplications.
areUnusedSlotsUnknown – Indication whether unused slots are unknown.
isInterleaved – Indication whether the interleaved mode is used.
isComplexPacked – Indication whether this dimension is complex packed.
-
inline virtual ~TTDim()#
-
bool isIncomplete() const#
Returns true if no original size is specified.
-
bool isCompatible(const TTDim &other, ActionType at = OTHER_ACTION_TYPE) const#
Returns whether other TTDim is compatible for tile tensor operations.
- Parameters:
other – Other TTDim to check compatibility with.
at – Action type to check compatibility for. Affects complex packed dimensions. Default is set to most restrictive setting.
-
void applyCompatibilityAdjustments(const TTDim &other, ActionType at)#
Change this TTDim to be the result of applying a tile tensor operator on this object and other object.
- Parameters:
other – Other TTDim on which an operator is applied.
at – Action type to apply compatibility for
-
TTDim &reduceOriginalSize(DimInt newOriginalSize, DimInt newInterleavedExternalSize = -1)#
Reduces original size to a new value.
This method performs validity checks, and allows overriding the interleaved external size. Returns a reference to this object for further manipulation.
- Parameters:
newOriginalSize – New value to set.
newInterleavedExternalSize – New interleaved external size (optional).
-
TTDim &setOriginalSize(DimInt size, bool keepInterleavedExternalSize = false)#
Set the original size.
In interleaved mode, the interleaved external size is set to the new minimum. Returns a reference to this object for further manipulation.
- Parameters:
size – New value to set.
keepInterleavedExternalSize – if in interleaved mode and this param set to true, the external size will be set to the minimal value between the current external size and the new original size.
-
TTDim &setTileSize(DimInt size)#
Set the tile size.
Returns a reference to this object for further manipulation.
- Parameters:
size – New value to set.
-
TTDim &setNumDuplicated(DimInt num)#
Set the number of duplications.
Returns a reference to this object for further manipulation.
- Parameters:
num – New value to set.
-
TTDim &setFullyDuplicated()#
Sets this TTDim to be fully duplicated.
That is, the number of its duplicated tiles becomes equal to the tile size.
Returns a reference to this object for further manipulation.
-
TTDim &setAreUnusedSlotsUnknown(bool areUnknown)#
Sets the value of the unknown flag for this dimension.
- Parameters:
areUnknown – Value to set
- Throws:
invalid_argument – if areUnknown is true and this dimension has no unused slots.
-
TTDim &setUnusedSlotsUnknown()#
Indicates that unused slots if they exist are unknown.
This turns on the unknown flag for this dimension if it has unused slots.
-
TTDim &setInterleaved(bool isInterleaved, DimInt externalSizeDivisor = 1)#
Turns interleave flag on or off.
- Parameters:
isInterleaved – Whether this dimension is interleaved
externalSizeDivisor – If isInterleaved, you can force the external size to be divisible by this value
-
TTDim &setInterleavedExternalSize(DimInt newSize)#
Set the interleaved external size of this dimension.
Can be called only for dimensions marked with setInterleaved(true). Given size must be at least getMinExternalSize()
- Parameters:
newSize – new interleaved size
-
void setIncomplete()#
Erases original size information, sets number of duplicates to 1, and unknown values to false.
-
TTDim getAsIncompleteTileSizeAndInterleaved() const#
Returns a TTDim object containing just the tile size of this object, as well as the interleaved flag and the interleaved external size in case of non-default size.
The returned TTDim has an incomplete original size.
-
void duplicate(DimInt dup = -1)#
Sets dim to be duplicated.
Assumes this dim is either incomplete or originalSize==1 and currently not duplicated.
- Parameters:
dup – [in] duplication count. The default value of -1 means duplicate to the entire tile size
- Throws:
invalid_argument – If the specified dimension has originalSize>1, or is already duplicated
-
DimInt getOriginalSizeSlots() const#
Returns the minimal number of slots required to store the original size numbers.
Three options:
(1) This dim is not complex packed: the return value is equal to getOriginalSize().
(2) This dim is complex packed and getNumDuplicated()==1: getOriginalSize() must be even, and the return value is half of it.
(3) This dim is complex packed and getNumDuplicated()>1: the return value is 1.
-
DimInt getNumDuplicatedSlots() const#
Returns the number of slots that contain duplicated values.
Three options:
(1) This dim is not complex packed: the return value is equal to getNumDuplicated().
(2) This dim is complex packed and getNumDuplicated()==1: returns 1. getOriginalSize() must be even in this case.
(3) This dim is complex packed and getNumDuplicated()>1: getNumDuplicated() must be even, and the return value is half of it.
-
inline bool getAreUnusedSlotsUnknown() const#
Returns whether unused slots are unknown.
If false, it means they are set to zero.
-
inline bool getIsComplexPacked() const#
Returns whether this dimension is complex packed.
-
bool isFullyDuplicated() const#
Returns true if data is fully duplicated along this dimension.
Equivalent to getNumDuplicated()==getTileSize()
-
bool isDegenerateTile() const#
Returns true if the tile size is 1.
-
bool isInterleaved() const#
Returns whether the interleaved mode is used.
-
DimInt getMaxUsedSlotsInTile() const#
Returns a bound on the number of used slots along this dimension.
-
bool isEqualOnOriginalSlots(const TTDim &other, bool enforceInterleavedExternalSize = true) const#
Returns whether tile sizes, original sizes, interleaved modes and optionally interleaved external sizes are equal.
- Parameters:
other – Other object to compare.
enforceInterleavedExternalSize – Whether to enforce the same interleaved external size in case of interleaved mode.
-
bool canBecomeFullyDuplicated(bool clearUnknownsAllowed) const#
Returns whether this object can be made fully duplicated.
To be made fully duplicated, it must either already be fully duplicated, or have original size equal 1 and no duplicated values at all.
- Parameters:
clearUnknownsAllowed – Whether clear unknown unused slots is allowed in order to become fully duplicated.
-
void reinterpretOriginalSize(DimInt newSize)#
Reinterpret this dimension by increasing or decreasing its original size.
Cannot change the external size. Eliminates any duplicated slots if exist, turning them to original or to unused slot. Newly-created unused slots will be marked as unknown.
- Parameters:
newSize – The new desired original size.
-
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
-
virtual void debugPrint(const std::string &title = "", Verbosity verbosity = VERBOSITY_REGULAR, std::ostream &out = std::cout) const override#
Prints the content of this object.
- Parameters:
title – Text to add to the print
verbosity – Verbosity level
out – Output stream
-
inline const bool isDiagonalized() const#
Returns true if this dimension is diagonalized.
To set diagonalized dims, use setDiagonalized of TTShape.
-
inline const DimInt getDiagonalizedDimIndex() const#
If isDiagonalized() returns true, this method returns the diagonalized dim index of the dimension (0 or 1).
Otherwise returns -1.
-
void allowPacking(const std::vector<TTDimTilingMethod> &allowedMethods, const std::vector<TTDimFlag> &allowedFlags, const std::string &opName) const#
Verifies the tiling methods and flags used by this object are included in the given lists.
- Parameters:
allowedMethods – List of allowed tiling methods.
allowedFlags – List of allowed flags.
opName – Name of operator requesting this check, for error messages.