MLIR
18.0.0git
|
A wrapper around RankedTensorType
, which has three goals:
More...
#include "mlir/Dialect/SparseTensor/IR/SparseTensorType.h"
Public Member Functions | |
SparseTensorType (RankedTensorType rtp) | |
SparseTensorType (ShapedType stp, SparseTensorEncodingAttr enc) | |
SparseTensorType (SparseTensorEncodingAttr enc) | |
SparseTensorType & | operator= (const SparseTensorType &)=delete |
SparseTensorType (const SparseTensorType &)=default | |
SparseTensorType | withEncoding (SparseTensorEncodingAttr newEnc) const |
SparseTensorType | withDimToLvl (AffineMap dimToLvl) const |
SparseTensorType | withDimToLvl (SparseTensorEncodingAttr dimToLvlEnc) const |
SparseTensorType | withDimToLvl (const SparseTensorType &dimToLvlSTT) const |
SparseTensorType | withoutDimToLvl () const |
SparseTensorType | withBitWidths (unsigned posWidth, unsigned crdWidth) const |
SparseTensorType | withoutBitWidths () const |
SparseTensorType | withDimSlices (ArrayRef< SparseTensorDimSliceAttr > dimSlices) const |
SparseTensorType | withoutDimSlices () const |
template<typename T , typename = std::enable_if_t< std::is_convertible_v<RankedTensorType, T>>> | |
operator T () const | |
Allow implicit conversion to RankedTensorType , ShapedType , and Type . More... | |
RankedTensorType | getRankedTensorType () const |
Explicitly convert to RankedTensorType . More... | |
bool | operator== (const SparseTensorType &other) const |
bool | operator!= (const SparseTensorType &other) const |
MLIRContext * | getContext () const |
Type | getElementType () const |
SparseTensorEncodingAttr | getEncoding () const |
bool | hasEncoding () const |
Returns true for tensors which have an encoding, and false for those which do not. More... | |
bool | isAllDense () const |
Returns true for tensors where every level is dense. More... | |
bool | isAllOrdered () const |
Returns true for tensors where every level is ordered. More... | |
ValueRange | translateCrds (OpBuilder &builder, Location loc, ValueRange crds, CrdTransDirectionKind dir) const |
Translates between level / dimension coordinate space. More... | |
bool | isPermutation () const |
Returns true if the dimToLvl mapping is a permutation. More... | |
bool | isIdentity () const |
Returns true if the dimToLvl mapping is the identity. More... | |
AffineMap | getDimToLvl () const |
Returns the dimToLvl mapping (or the null-map for the identity). More... | |
AffineMap | getLvlToDim () const |
Returns the lvlToDiml mapping (or the null-map for the identity). More... | |
AffineMap | getExpandedDimToLvl () const |
Returns the dimToLvl mapping, where the identity map is expanded out into a full AffineMap . More... | |
bool | hasSameDimToLvl (const SparseTensorType &other) const |
Returns true iff the two types have the same mapping. More... | |
Dimension | getDimRank () const |
Returns the dimension-rank. More... | |
Level | getLvlRank () const |
Returns the level-rank. More... | |
ArrayRef< Size > | getDimShape () const |
Returns the dimension-shape. More... | |
SmallVector< Size > | getLvlShape () const |
Returns the Level-shape. More... | |
RankedTensorType | getDemappedType () const |
Returns the type with an identity mapping. More... | |
Size | getDynamicDimSize (Dimension d) const |
Safely looks up the requested dimension-DynSize. More... | |
bool | hasStaticDimShape () const |
Returns true if no dimension has dynamic size. More... | |
bool | hasDynamicDimShape () const |
Returns true if any dimension has dynamic size. More... | |
bool | isDynamicDim (Dimension d) const |
Returns true if the given dimension has dynamic size. More... | |
int64_t | getNumDynamicDims () const |
Returns the number of dimensions which have dynamic sizes. More... | |
ArrayRef< LevelType > | getLvlTypes () const |
LevelType | getLvlType (Level l) const |
bool | isDenseLvl (Level l) const |
bool | isCompressedLvl (Level l) const |
bool | isLooseCompressedLvl (Level l) const |
bool | isSingletonLvl (Level l) const |
bool | is2OutOf4Lvl (Level l) const |
bool | isOrderedLvl (Level l) const |
bool | isUniqueLvl (Level l) const |
bool | isWithPos (Level l) const |
bool | isWithCrd (Level l) const |
unsigned | getCrdWidth () const |
Returns the coordinate-overhead bitwidth, defaulting to zero. More... | |
unsigned | getPosWidth () const |
Returns the position-overhead bitwidth, defaulting to zero. More... | |
Type | getCrdType () const |
Returns the coordinate-overhead MLIR type, defaulting to IndexType . More... | |
Type | getPosType () const |
Returns the position-overhead MLIR type, defaulting to IndexType . More... | |
bool | isCOOType (Level startLvl=0, bool isUnique=true) const |
Returns true iff this sparse tensor type has a trailing COO region starting at the given level. More... | |
Level | getCOOStart () const |
Returns the starting level of this sparse tensor type for a trailing COO region that spans at least two levels. More... | |
RankedTensorType | getCOOType (bool ordered) const |
Returns [un]ordered COO type for this sparse tensor type. More... | |
A wrapper around RankedTensorType
, which has three goals:
(1) To provide a uniform API for querying aspects of sparse-tensor types; in particular, to make the "dimension" vs "level" distinction overt (i.e., explicit everywhere). Thus, throughout the sparsifier this class should be preferred over using RankedTensorType
or ShapedType
directly, since the methods of the latter do not make the "dimension" vs "level" distinction overt.
(2) To provide a uniform abstraction over both sparse-tensor types (i.e., RankedTensorType
with SparseTensorEncodingAttr
) and dense-tensor types (i.e., RankedTensorType
without an encoding). That is, we want to manipulate dense-tensor types using the same API that we use for manipulating sparse-tensor types; both to keep the "dimension" vs "level" distinction overt, and to avoid needing to handle certain cases specially in the sparsifier.
(3) To provide uniform handling of "defaults". In particular this means that dense-tensors should always return the same answers as sparse-tensors with a default encoding. But it additionally means that the answers should be normalized, so that there's no way to distinguish between non-provided data (which is filled in by default) vs explicitly-provided data which equals the defaults.
Definition at line 46 of file SparseTensorType.h.
|
inline |
Definition at line 50 of file SparseTensorType.h.
References getDimRank(), and isIdentity().
Referenced by withEncoding().
|
inline |
Definition at line 59 of file SparseTensorType.h.
|
inline |
Definition at line 64 of file SparseTensorType.h.
|
default |
|
inline |
Definition at line 158 of file SparseTensorType.h.
Referenced by getCrdType(), getExpandedDimToLvl(), and getPosType().
Level mlir::sparse_tensor::SparseTensorType::getCOOStart | ( | ) | const |
Returns the starting level of this sparse tensor type for a trailing COO region that spans at least two levels.
If no such COO region is found, then returns the level-rank.
Definition at line 728 of file SparseTensorDialect.cpp.
Referenced by createAllocFields(), mlir::sparse_tensor::StorageLayout::foreachField(), and mlir::sparse_tensor::SparseTensorDescriptorImpl< ValueArrayRef >::getAOSMemRef().
RankedTensorType mlir::sparse_tensor::SparseTensorType::getCOOType | ( | bool | ordered | ) | const |
Returns [un]ordered COO type for this sparse tensor type.
Definition at line 737 of file SparseTensorDialect.cpp.
References mlir::sparse_tensor::buildLevelType(), mlir::sparse_tensor::Compressed, mlir::get(), getContext(), getElementType(), and mlir::sparse_tensor::Singleton.
Referenced by getBufferType().
|
inline |
Returns the coordinate-overhead MLIR type, defaulting to IndexType
.
Definition at line 307 of file SparseTensorType.h.
References mlir::get(), getContext(), and getCrdWidth().
Referenced by mlir::sparse_tensor::foreachFieldAndTypeInSparseTensor().
|
inline |
Returns the coordinate-overhead bitwidth, defaulting to zero.
Definition at line 301 of file SparseTensorType.h.
Referenced by getCrdType().
|
inline |
Returns the type with an identity mapping.
Definition at line 244 of file SparseTensorType.h.
References mlir::get(), getElementType(), and getLvlShape().
|
inline |
Returns the dimension-rank.
Definition at line 229 of file SparseTensorType.h.
Referenced by createDimSizes(), mlir::sparse_tensor::genMapBuffers(), mlir::sparse_tensor::genReader(), getDynamicDimSize(), getExpandedDimToLvl(), mlir::sparse_tensor::sizesFromSrc(), and SparseTensorType().
Returns the dimension-shape.
Definition at line 235 of file SparseTensorType.h.
Referenced by createDimSizes(), mlir::sparse_tensor::genReader(), getDynamicDimSize(), and getLvlShape().
|
inline |
Returns the dimToLvl mapping (or the null-map for the identity).
If you intend to compare the results of this method for equality, see hasSameDimToLvl
instead.
Definition at line 202 of file SparseTensorType.h.
Referenced by mlir::sparse_tensor::genMapBuffers().
Safely looks up the requested dimension-DynSize.
If you intend to check the result with ShapedType::isDynamic
, then see the getStaticDimSize
method instead.
Definition at line 252 of file SparseTensorType.h.
References getDimRank(), and getDimShape().
Referenced by isDynamicDim().
|
inline |
Definition at line 160 of file SparseTensorType.h.
Referenced by allocSchemeForRank(), mlir::sparse_tensor::foreachFieldAndTypeInSparseTensor(), mlir::sparse_tensor::genReader(), and getDemappedType().
|
inline |
Definition at line 162 of file SparseTensorType.h.
Referenced by mlir::sparse_tensor::foreachFieldAndTypeInSparseTensor(), mlir::sparse_tensor::SparseTensorSpecifier::getInitValue(), getLvlShape(), mlir::sparse_tensor::LoopEmitter::initialize(), and withDimToLvl().
|
inline |
Returns the dimToLvl mapping, where the identity map is expanded out into a full AffineMap
.
This method is provided as a convenience, but for most purposes other methods (isIdentity
, getDimToLvl
, etc) will be more helpful.
Definition at line 211 of file SparseTensorType.h.
References getContext(), getDimRank(), and mlir::AffineMap::getMultiDimIdentityMap().
|
inline |
Returns the level-rank.
Definition at line 232 of file SparseTensorType.h.
Referenced by allocSchemeForRank(), createAllocFields(), genCompressed(), genEndInsert(), mlir::sparse_tensor::genMapBuffers(), mlir::sparse_tensor::SparseTensorDescriptorImpl< ValueArrayRef >::getAOSMemRef(), getNumNonTrivialIdxExpOnSparseLvls(), mlir::sparse_tensor::LoopEmitter::initialize(), and mlir::sparse_tensor::LoopEmitter::initializeLoopEmit().
|
inline |
Returns the Level-shape.
Definition at line 238 of file SparseTensorType.h.
References getDimShape(), and getEncoding().
Referenced by getDemappedType().
|
inline |
Returns the lvlToDiml mapping (or the null-map for the identity).
Definition at line 205 of file SparseTensorType.h.
Referenced by mlir::sparse_tensor::genMapBuffers().
Definition at line 278 of file SparseTensorType.h.
Referenced by allocSchemeForRank(), createAllocFields(), genEndInsert(), is2OutOf4Lvl(), isCompressedLvl(), isDenseLvl(), isLooseCompressedLvl(), isOrderedLvl(), isSingletonLvl(), isUniqueLvl(), isWithCrd(), and isWithPos().
Definition at line 277 of file SparseTensorType.h.
|
inline |
Returns the number of dimensions which have dynamic sizes.
The return type is int64_t
to maintain consistency with ShapedType::Trait<T>::getNumDynamicDims
.
Definition at line 275 of file SparseTensorType.h.
|
inline |
Returns the position-overhead MLIR type, defaulting to IndexType
.
Definition at line 314 of file SparseTensorType.h.
References mlir::get(), getContext(), and getPosWidth().
Referenced by allocSchemeForRank(), createAllocFields(), mlir::sparse_tensor::foreachFieldAndTypeInSparseTensor(), and genEndInsert().
|
inline |
Returns the position-overhead bitwidth, defaulting to zero.
Definition at line 304 of file SparseTensorType.h.
Referenced by getPosType().
|
inline |
Explicitly convert to RankedTensorType
.
This method is a convenience for resolving overload-ambiguity issues with implicit conversion.
Definition at line 146 of file SparseTensorType.h.
Referenced by getBufferType().
|
inline |
Returns true if any dimension has dynamic size.
Definition at line 261 of file SparseTensorType.h.
References hasStaticDimShape().
Referenced by mlir::sparse_tensor::genReader().
|
inline |
Returns true for tensors which have an encoding, and false for those which do not.
Therefore tensors with an all-dense encoding return true.
Definition at line 171 of file SparseTensorType.h.
Referenced by convertSparseTensorType(), mlir::sparse_tensor::foreachFieldAndTypeInSparseTensor(), and mlir::sparse_tensor::LoopEmitter::initialize().
|
inline |
Returns true iff the two types have the same mapping.
This method takes care to handle identity maps properly, so it should be preferred over using getDimToLvl
followed by AffineMap::operator==
.
Definition at line 220 of file SparseTensorType.h.
References isIdentity().
|
inline |
Returns true if no dimension has dynamic size.
Definition at line 258 of file SparseTensorType.h.
Referenced by hasDynamicDimShape().
|
inline |
Definition at line 294 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::is2OutOf4LT().
|
inline |
Returns true for tensors where every level is dense.
(This is always true for dense-tensors.)
Definition at line 175 of file SparseTensorType.h.
Referenced by createAllocFields(), and mlir::sparse_tensor::CodegenEnv::isAdmissibleTensorExp().
|
inline |
Returns true for tensors where every level is ordered.
(This is always true for dense-tensors.)
Definition at line 179 of file SparseTensorType.h.
|
inline |
Definition at line 289 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isCompressedLT().
Referenced by createAllocFields().
bool mlir::sparse_tensor::SparseTensorType::isCOOType | ( | Level | startLvl = 0 , |
bool | isUnique = true |
||
) | const |
Returns true iff this sparse tensor type has a trailing COO region starting at the given level.
By default, it tests for a unique COO type at top level.
Definition at line 713 of file SparseTensorDialect.cpp.
References isUnique().
|
inline |
Definition at line 288 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isDenseLT().
Referenced by createAllocFields(), and getNumNonTrivialIdxExpOnSparseLvls().
|
inline |
Returns true if the given dimension has dynamic size.
If you intend to call getDynamicDimSize
based on the result, then see the getStaticDimSize
method instead.
Definition at line 266 of file SparseTensorType.h.
References getDynamicDimSize().
Referenced by mlir::sparse_tensor::genReader().
|
inline |
Returns true if the dimToLvl mapping is the identity.
(This is always true for dense-tensors.)
Definition at line 193 of file SparseTensorType.h.
Referenced by mlir::sparse_tensor::genMapBuffers(), hasSameDimToLvl(), and SparseTensorType().
|
inline |
Definition at line 290 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isLooseCompressedLT().
|
inline |
Definition at line 295 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isOrderedLT().
|
inline |
Returns true if the dimToLvl mapping is a permutation.
(This is always true for dense-tensors.)
Definition at line 189 of file SparseTensorType.h.
|
inline |
Definition at line 293 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isSingletonLT().
|
inline |
Definition at line 296 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isUniqueLT().
Referenced by genCompressed().
|
inline |
Definition at line 298 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isWithCrdLT().
|
inline |
Definition at line 297 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isWithPosLT().
|
inline |
Allow implicit conversion to RankedTensorType
, ShapedType
, and Type
.
These are implicit to help alleviate the impedance mismatch for code that has not been converted to use SparseTensorType
directly. Once more uses have been converted to SparseTensorType
, we may want to make these explicit instead.
WARNING: This user-defined-conversion method causes overload ambiguity whenever passing a SparseTensorType
directly to a function which is overloaded to accept either Type
or TypeRange
. In particular, this includes RewriterBase::replaceOpWithNewOp<OpTy>
and OpBuilder::create<OpTy>
whenever the OpTy::build
is overloaded thus. This happens because the TypeRange<T>(T&&)
ctor is implicit as well, and there's no SFINAE we can add to this method that would block subsequent application of that ctor. The only way to fix the overload ambiguity is to avoid implicit conversion at the callsite: e.g., by using static_cast
to make the conversion explicit, by assigning the SparseTensorType
to a temporary variable of the desired type, etc.
Definition at line 139 of file SparseTensorType.h.
|
inline |
Definition at line 154 of file SparseTensorType.h.
|
delete |
|
inline |
Definition at line 148 of file SparseTensorType.h.
|
inline |
Translates between level / dimension coordinate space.
Definition at line 182 of file SparseTensorType.h.
|
inline |
Definition at line 97 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 106 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 81 of file SparseTensorType.h.
References withEncoding().
Referenced by withDimToLvl().
|
inline |
Definition at line 89 of file SparseTensorType.h.
References getEncoding(), and withDimToLvl().
|
inline |
Definition at line 85 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 77 of file SparseTensorType.h.
References SparseTensorType().
Referenced by withBitWidths(), withDimSlices(), withDimToLvl(), withoutBitWidths(), withoutDimSlices(), and withoutDimToLvl().
|
inline |
Definition at line 101 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 110 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 93 of file SparseTensorType.h.
References withEncoding().