MLIR
19.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 | withExplicitVal (Attribute explicitVal) const |
SparseTensorType | withoutExplicitVal () const |
SparseTensorType | withImplicitVal (Attribute implicitVal) const |
SparseTensorType | withoutImplicitVal () 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... | |
unsigned | getBatchLvlRank () const |
Returns the batched level-rank. More... | |
SmallVector< Size > | getBatchLvlShape () const |
Returns the batched 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 | isNOutOfMLvl (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... | |
Attribute | getExplicitVal () const |
Returns the explicit value, defaulting to null Attribute for unset. More... | |
Attribute | getImplicitVal () const |
Returns the implicit value, defaulting to null Attribute for 0. 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 | getAoSCOOStart () 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... | |
SmallVector< COOSegment > | getCOOSegments () const |
Returns a list of COO segments in the sparse tensor types. 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 59 of file SparseTensorType.h.
|
inline |
Definition at line 63 of file SparseTensorType.h.
References getDimRank(), and isIdentity().
Referenced by withEncoding().
|
inline |
Definition at line 72 of file SparseTensorType.h.
|
inline |
Definition at line 77 of file SparseTensorType.h.
|
default |
Level mlir::sparse_tensor::SparseTensorType::getAoSCOOStart | ( | ) | 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.
DEPRECATED: use getCOOSegment instead;
Definition at line 932 of file SparseTensorDialect.cpp.
Referenced by createAllocFields(), mlir::sparse_tensor::SparseTensorDescriptorImpl< ValueArrayRef >::getAOSMemRef(), and inferSparseBufferType().
|
inline |
Returns the batched level-rank.
Definition at line 273 of file SparseTensorType.h.
References getEncoding().
Referenced by getBatchLvlShape().
|
inline |
Returns the batched level-shape.
Definition at line 276 of file SparseTensorType.h.
References getBatchLvlRank(), getDimShape(), and getEncoding().
Referenced by inferSparseBufferType().
|
inline |
Definition at line 187 of file SparseTensorType.h.
Referenced by getExpandedDimToLvl(), and inferSparseBufferType().
SmallVector< COOSegment > mlir::sparse_tensor::SparseTensorType::getCOOSegments | ( | ) | const |
Returns a list of COO segments in the sparse tensor types.
Definition at line 942 of file SparseTensorDialect.cpp.
References mlir::sparse_tensor::Compressed, mlir::sparse_tensor::LevelType::isa(), mlir::sparse_tensor::LooseCompressed, and mlir::sparse_tensor::SoA.
Referenced by mlir::sparse_tensor::StorageLayout::foreachField().
RankedTensorType mlir::sparse_tensor::SparseTensorType::getCOOType | ( | bool | ordered | ) | const |
Returns [un]ordered COO type for this sparse tensor type.
Definition at line 974 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 353 of file SparseTensorType.h.
Referenced by mlir::sparse_tensor::foreachFieldAndTypeInSparseTensor(), and inferSparseBufferType().
|
inline |
Returns the coordinate-overhead bitwidth, defaulting to zero.
Definition at line 341 of file SparseTensorType.h.
|
inline |
Returns the type with an identity mapping.
Definition at line 284 of file SparseTensorType.h.
References mlir::get(), getElementType(), and getLvlShape().
|
inline |
Returns the dimension-rank.
Definition at line 258 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 264 of file SparseTensorType.h.
Referenced by createDimSizes(), mlir::sparse_tensor::foreachFieldAndTypeInSparseTensor(), mlir::sparse_tensor::genReader(), getBatchLvlShape(), 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 231 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 292 of file SparseTensorType.h.
References getDimRank(), and getDimShape().
Referenced by isDynamicDim().
|
inline |
Definition at line 189 of file SparseTensorType.h.
Referenced by allocSchemeForRank(), mlir::sparse_tensor::foreachFieldAndTypeInSparseTensor(), mlir::sparse_tensor::genReader(), getDemappedType(), and inferSparseBufferType().
|
inline |
Definition at line 191 of file SparseTensorType.h.
Referenced by mlir::sparse_tensor::foreachFieldAndTypeInSparseTensor(), getBatchLvlRank(), getBatchLvlShape(), mlir::sparse_tensor::SparseTensorSpecifier::getInitValue(), getLvlShape(), 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 240 of file SparseTensorType.h.
References getContext(), getDimRank(), and mlir::AffineMap::getMultiDimIdentityMap().
|
inline |
Returns the explicit value, defaulting to null Attribute for unset.
Definition at line 347 of file SparseTensorType.h.
|
inline |
Returns the implicit value, defaulting to null Attribute for 0.
Definition at line 350 of file SparseTensorType.h.
|
inline |
Returns the level-rank.
Definition at line 261 of file SparseTensorType.h.
Referenced by allocSchemeForRank(), createAllocFields(), genCompressed(), genEndInsert(), mlir::sparse_tensor::genMapBuffers(), mlir::sparse_tensor::SparseTensorDescriptorImpl< ValueArrayRef >::getAOSMemRef(), getNumNonTrivialIdxExpOnSparseLvls(), and mlir::sparse_tensor::LoopEmitter::initialize().
|
inline |
Returns the level-shape.
Definition at line 267 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 234 of file SparseTensorType.h.
Referenced by mlir::sparse_tensor::genMapBuffers().
Definition at line 318 of file SparseTensorType.h.
Referenced by allocSchemeForRank(), createAllocFields(), genEndInsert(), getNumNonTrivialIdxExpOnSparseLvls(), isCompressedLvl(), isDenseLvl(), isLooseCompressedLvl(), isNOutOfMLvl(), isOrderedLvl(), isSingletonLvl(), isUniqueLvl(), isWithCrd(), and isWithPos().
Definition at line 317 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 315 of file SparseTensorType.h.
|
inline |
Returns the position-overhead MLIR type, defaulting to IndexType
.
Definition at line 356 of file SparseTensorType.h.
Referenced by allocSchemeForRank(), createAllocFields(), mlir::sparse_tensor::foreachFieldAndTypeInSparseTensor(), genEndInsert(), and inferSparseBufferType().
|
inline |
Returns the position-overhead bitwidth, defaulting to zero.
Definition at line 344 of file SparseTensorType.h.
|
inline |
Explicitly convert to RankedTensorType
.
This method is a convenience for resolving overload-ambiguity issues with implicit conversion.
Definition at line 175 of file SparseTensorType.h.
Referenced by getBufferType().
|
inline |
Returns true if any dimension has dynamic size.
Definition at line 301 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 200 of file SparseTensorType.h.
Referenced by convertSparseTensorType(), and mlir::sparse_tensor::foreachFieldAndTypeInSparseTensor().
|
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 249 of file SparseTensorType.h.
References isIdentity().
|
inline |
Returns true if no dimension has dynamic size.
Definition at line 298 of file SparseTensorType.h.
Referenced by hasDynamicDimShape().
|
inline |
Returns true for tensors where every level is dense.
(This is always true for dense-tensors.)
Definition at line 204 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 208 of file SparseTensorType.h.
|
inline |
Definition at line 329 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 917 of file SparseTensorDialect.cpp.
References isUnique().
|
inline |
Definition at line 328 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isDenseLT().
Referenced by createAllocFields().
|
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 306 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 222 of file SparseTensorType.h.
Referenced by mlir::sparse_tensor::genMapBuffers(), hasSameDimToLvl(), and SparseTensorType().
|
inline |
Definition at line 330 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isLooseCompressedLT().
|
inline |
Definition at line 334 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isNOutOfMLT().
|
inline |
Definition at line 335 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 218 of file SparseTensorType.h.
|
inline |
Definition at line 333 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isSingletonLT().
|
inline |
Definition at line 336 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isUniqueLT().
Referenced by genCompressed().
|
inline |
Definition at line 338 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isWithCrdLT().
|
inline |
Definition at line 337 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 168 of file SparseTensorType.h.
|
inline |
Definition at line 183 of file SparseTensorType.h.
|
delete |
|
inline |
Definition at line 177 of file SparseTensorType.h.
|
inline |
Translates between level / dimension coordinate space.
Definition at line 211 of file SparseTensorType.h.
|
inline |
Definition at line 110 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 135 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 94 of file SparseTensorType.h.
References withEncoding().
Referenced by withDimToLvl().
|
inline |
Definition at line 102 of file SparseTensorType.h.
References getEncoding(), and withDimToLvl().
|
inline |
Definition at line 98 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 90 of file SparseTensorType.h.
References SparseTensorType().
Referenced by withBitWidths(), withDimSlices(), withDimToLvl(), withExplicitVal(), withImplicitVal(), withoutBitWidths(), withoutDimSlices(), withoutDimToLvl(), withoutExplicitVal(), and withoutImplicitVal().
|
inline |
Definition at line 118 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 126 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 114 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 139 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 106 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 122 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 130 of file SparseTensorType.h.
References withEncoding().