MLIR
20.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 & | 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... | |
size_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 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.
|
default |
|
inline |
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 353 of file SparseTensorType.h.
References getEncoding().
Referenced by createAllocFields(), mlir::sparse_tensor::SparseTensorDescriptorImpl< ValueArrayRef >::getAOSMemRef(), inferSparseBufferType(), and verifyPackUnPack().
|
inline |
Returns the batched level-rank.
Definition at line 254 of file SparseTensorType.h.
References getEncoding().
Referenced by getBatchLvlShape().
|
inline |
Returns the batched level-shape.
Definition at line 257 of file SparseTensorType.h.
References getBatchLvlRank(), getDimShape(), and getEncoding().
Referenced by inferSparseBufferType().
|
inline |
Definition at line 168 of file SparseTensorType.h.
Referenced by getExpandedDimToLvl(), and inferSparseBufferType().
|
inline |
Returns a list of COO segments in the sparse tensor types.
Definition at line 359 of file SparseTensorType.h.
References getEncoding().
RankedTensorType mlir::sparse_tensor::SparseTensorType::getCOOType | ( | bool | ordered | ) | const |
Returns [un]ordered COO type for this sparse tensor type.
Definition at line 1011 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 338 of file SparseTensorType.h.
Referenced by mlir::sparse_tensor::foreachFieldAndTypeInSparseTensor(), getFieldElemType(), and inferSparseBufferType().
|
inline |
Returns the coordinate-overhead bitwidth, defaulting to zero.
Definition at line 322 of file SparseTensorType.h.
|
inline |
Returns the type with an identity mapping.
Definition at line 265 of file SparseTensorType.h.
References mlir::get(), getElementType(), and getLvlShape().
|
inline |
Returns the dimension-rank.
Definition at line 239 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 245 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 212 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 273 of file SparseTensorType.h.
References getDimRank(), and getDimShape().
Referenced by isDynamicDim().
|
inline |
Definition at line 170 of file SparseTensorType.h.
Referenced by allocSchemeForRank(), mlir::sparse_tensor::foreachFieldAndTypeInSparseTensor(), mlir::sparse_tensor::genReader(), getDemappedType(), getFieldElemType(), and inferSparseBufferType().
|
inline |
Definition at line 172 of file SparseTensorType.h.
Referenced by mlir::sparse_tensor::foreachFieldAndTypeInSparseTensor(), getAoSCOOStart(), getBatchLvlRank(), getBatchLvlShape(), getCOOSegments(), mlir::sparse_tensor::SparseTensorSpecifier::getInitValue(), getLvlShape(), verifyPackUnPack(), 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 221 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 328 of file SparseTensorType.h.
|
inline |
Returns the implicit value, defaulting to null Attribute for 0.
Definition at line 333 of file SparseTensorType.h.
|
inline |
Returns the level-rank.
Definition at line 242 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 verifyPackUnPack().
|
inline |
Returns the level-shape.
Definition at line 248 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 215 of file SparseTensorType.h.
Referenced by mlir::sparse_tensor::genMapBuffers().
Definition at line 299 of file SparseTensorType.h.
Referenced by allocSchemeForRank(), createAllocFields(), genEndInsert(), getNumNonTrivialIdxExpOnSparseLvls(), isCompressedLvl(), isDenseLvl(), isLooseCompressedLvl(), isNOutOfMLvl(), isOrderedLvl(), isSingletonLvl(), isUniqueLvl(), isWithCrd(), isWithPos(), and verifyPackUnPack().
Definition at line 298 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 296 of file SparseTensorType.h.
|
inline |
Returns the position-overhead MLIR type, defaulting to IndexType
.
Definition at line 341 of file SparseTensorType.h.
Referenced by allocSchemeForRank(), createAllocFields(), mlir::sparse_tensor::foreachFieldAndTypeInSparseTensor(), genEndInsert(), getFieldElemType(), and inferSparseBufferType().
|
inline |
Returns the position-overhead bitwidth, defaulting to zero.
Definition at line 325 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 156 of file SparseTensorType.h.
Referenced by getBufferType().
|
inline |
Returns true if any dimension has dynamic size.
Definition at line 282 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 181 of file SparseTensorType.h.
Referenced by convertSparseTensorType(), mlir::sparse_tensor::foreachFieldAndTypeInSparseTensor(), relinkBranch(), and verifyPackUnPack().
|
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 230 of file SparseTensorType.h.
References isIdentity().
|
inline |
Returns true if no dimension has dynamic size.
Definition at line 279 of file SparseTensorType.h.
Referenced by hasDynamicDimShape(), and verifyPackUnPack().
|
inline |
Returns true for tensors where every level is dense.
(This is always true for dense-tensors.)
Definition at line 185 of file SparseTensorType.h.
Referenced by createAllocFields(), hasNonTrivialAffineOnSparseOut(), 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 189 of file SparseTensorType.h.
|
inline |
Definition at line 310 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 995 of file SparseTensorDialect.cpp.
References isUnique().
|
inline |
Definition at line 309 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 287 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 203 of file SparseTensorType.h.
Referenced by mlir::sparse_tensor::genMapBuffers(), mlir::sparse_tensor::hasAnyNonIdentityOperandsOrResults(), hasSameDimToLvl(), and SparseTensorType().
|
inline |
Definition at line 311 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isLooseCompressedLT().
|
inline |
Definition at line 315 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isNOutOfMLT().
|
inline |
Definition at line 316 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 199 of file SparseTensorType.h.
|
inline |
Definition at line 314 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isSingletonLT().
|
inline |
Definition at line 317 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isUniqueLT().
Referenced by genCompressed().
|
inline |
Definition at line 319 of file SparseTensorType.h.
References getLvlType(), and mlir::sparse_tensor::isWithCrdLT().
|
inline |
Definition at line 318 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 149 of file SparseTensorType.h.
|
inline |
Definition at line 164 of file SparseTensorType.h.
|
delete |
|
inline |
Definition at line 158 of file SparseTensorType.h.
|
inline |
Translates between level / dimension coordinate space.
Definition at line 192 of file SparseTensorType.h.
|
inline |
Definition at line 91 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 116 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 75 of file SparseTensorType.h.
References withEncoding().
Referenced by withDimToLvl().
|
inline |
Definition at line 83 of file SparseTensorType.h.
References getEncoding(), and withDimToLvl().
|
inline |
Definition at line 79 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 71 of file SparseTensorType.h.
References SparseTensorType().
Referenced by withBitWidths(), withDimSlices(), withDimToLvl(), withExplicitVal(), withImplicitVal(), withoutBitWidths(), withoutDimSlices(), withoutDimToLvl(), withoutExplicitVal(), and withoutImplicitVal().
|
inline |
Definition at line 99 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 107 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 95 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 120 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 87 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 103 of file SparseTensorType.h.
References withEncoding().
|
inline |
Definition at line 111 of file SparseTensorType.h.
References withEncoding().