MLIR  18.0.0git
Public Member Functions | List of all members
mlir::sparse_tensor::SparseTensorType Class Reference

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)
 
SparseTensorTypeoperator= (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
 
MLIRContextgetContext () 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< SizegetDimShape () const
 Returns the dimension-shape. More...
 
SmallVector< SizegetLvlShape () 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< LevelTypegetLvlTypes () 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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SparseTensorType() [1/4]

mlir::sparse_tensor::SparseTensorType::SparseTensorType ( RankedTensorType  rtp)
inline

Definition at line 50 of file SparseTensorType.h.

References getDimRank(), and isIdentity().

Referenced by withEncoding().

◆ SparseTensorType() [2/4]

mlir::sparse_tensor::SparseTensorType::SparseTensorType ( ShapedType  stp,
SparseTensorEncodingAttr  enc 
)
inline

Definition at line 59 of file SparseTensorType.h.

◆ SparseTensorType() [3/4]

mlir::sparse_tensor::SparseTensorType::SparseTensorType ( SparseTensorEncodingAttr  enc)
inline

Definition at line 64 of file SparseTensorType.h.

◆ SparseTensorType() [4/4]

mlir::sparse_tensor::SparseTensorType::SparseTensorType ( const SparseTensorType )
default

Member Function Documentation

◆ getContext()

MLIRContext* mlir::sparse_tensor::SparseTensorType::getContext ( ) const
inline

Definition at line 158 of file SparseTensorType.h.

Referenced by getCrdType(), getExpandedDimToLvl(), and getPosType().

◆ getCOOStart()

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().

◆ getCOOType()

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().

◆ getCrdType()

Type mlir::sparse_tensor::SparseTensorType::getCrdType ( ) const
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().

◆ getCrdWidth()

unsigned mlir::sparse_tensor::SparseTensorType::getCrdWidth ( ) const
inline

Returns the coordinate-overhead bitwidth, defaulting to zero.

Definition at line 301 of file SparseTensorType.h.

Referenced by getCrdType().

◆ getDemappedType()

RankedTensorType mlir::sparse_tensor::SparseTensorType::getDemappedType ( ) const
inline

Returns the type with an identity mapping.

Definition at line 244 of file SparseTensorType.h.

References mlir::get(), getElementType(), and getLvlShape().

◆ getDimRank()

Dimension mlir::sparse_tensor::SparseTensorType::getDimRank ( ) const
inline

◆ getDimShape()

ArrayRef<Size> mlir::sparse_tensor::SparseTensorType::getDimShape ( ) const
inline

Returns the dimension-shape.

Definition at line 235 of file SparseTensorType.h.

Referenced by createDimSizes(), mlir::sparse_tensor::genReader(), getDynamicDimSize(), and getLvlShape().

◆ getDimToLvl()

AffineMap mlir::sparse_tensor::SparseTensorType::getDimToLvl ( ) const
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().

◆ getDynamicDimSize()

Size mlir::sparse_tensor::SparseTensorType::getDynamicDimSize ( Dimension  d) const
inline

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().

◆ getElementType()

Type mlir::sparse_tensor::SparseTensorType::getElementType ( ) const
inline

◆ getEncoding()

SparseTensorEncodingAttr mlir::sparse_tensor::SparseTensorType::getEncoding ( ) const
inline

◆ getExpandedDimToLvl()

AffineMap mlir::sparse_tensor::SparseTensorType::getExpandedDimToLvl ( ) const
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().

◆ getLvlRank()

Level mlir::sparse_tensor::SparseTensorType::getLvlRank ( ) const
inline

◆ getLvlShape()

SmallVector<Size> mlir::sparse_tensor::SparseTensorType::getLvlShape ( ) const
inline

Returns the Level-shape.

Definition at line 238 of file SparseTensorType.h.

References getDimShape(), and getEncoding().

Referenced by getDemappedType().

◆ getLvlToDim()

AffineMap mlir::sparse_tensor::SparseTensorType::getLvlToDim ( ) const
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().

◆ getLvlType()

LevelType mlir::sparse_tensor::SparseTensorType::getLvlType ( Level  l) const
inline

◆ getLvlTypes()

ArrayRef<LevelType> mlir::sparse_tensor::SparseTensorType::getLvlTypes ( ) const
inline

Definition at line 277 of file SparseTensorType.h.

◆ getNumDynamicDims()

int64_t mlir::sparse_tensor::SparseTensorType::getNumDynamicDims ( ) const
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.

◆ getPosType()

Type mlir::sparse_tensor::SparseTensorType::getPosType ( ) const
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().

◆ getPosWidth()

unsigned mlir::sparse_tensor::SparseTensorType::getPosWidth ( ) const
inline

Returns the position-overhead bitwidth, defaulting to zero.

Definition at line 304 of file SparseTensorType.h.

Referenced by getPosType().

◆ getRankedTensorType()

RankedTensorType mlir::sparse_tensor::SparseTensorType::getRankedTensorType ( ) const
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().

◆ hasDynamicDimShape()

bool mlir::sparse_tensor::SparseTensorType::hasDynamicDimShape ( ) const
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().

◆ hasEncoding()

bool mlir::sparse_tensor::SparseTensorType::hasEncoding ( ) const
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().

◆ hasSameDimToLvl()

bool mlir::sparse_tensor::SparseTensorType::hasSameDimToLvl ( const SparseTensorType other) const
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().

◆ hasStaticDimShape()

bool mlir::sparse_tensor::SparseTensorType::hasStaticDimShape ( ) const
inline

Returns true if no dimension has dynamic size.

Definition at line 258 of file SparseTensorType.h.

Referenced by hasDynamicDimShape().

◆ is2OutOf4Lvl()

bool mlir::sparse_tensor::SparseTensorType::is2OutOf4Lvl ( Level  l) const
inline

Definition at line 294 of file SparseTensorType.h.

References getLvlType(), and mlir::sparse_tensor::is2OutOf4LT().

◆ isAllDense()

bool mlir::sparse_tensor::SparseTensorType::isAllDense ( ) const
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().

◆ isAllOrdered()

bool mlir::sparse_tensor::SparseTensorType::isAllOrdered ( ) const
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.

◆ isCompressedLvl()

bool mlir::sparse_tensor::SparseTensorType::isCompressedLvl ( Level  l) const
inline

Definition at line 289 of file SparseTensorType.h.

References getLvlType(), and mlir::sparse_tensor::isCompressedLT().

Referenced by createAllocFields().

◆ isCOOType()

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().

◆ isDenseLvl()

bool mlir::sparse_tensor::SparseTensorType::isDenseLvl ( Level  l) const
inline

◆ isDynamicDim()

bool mlir::sparse_tensor::SparseTensorType::isDynamicDim ( Dimension  d) const
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().

◆ isIdentity()

bool mlir::sparse_tensor::SparseTensorType::isIdentity ( ) const
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().

◆ isLooseCompressedLvl()

bool mlir::sparse_tensor::SparseTensorType::isLooseCompressedLvl ( Level  l) const
inline

Definition at line 290 of file SparseTensorType.h.

References getLvlType(), and mlir::sparse_tensor::isLooseCompressedLT().

◆ isOrderedLvl()

bool mlir::sparse_tensor::SparseTensorType::isOrderedLvl ( Level  l) const
inline

Definition at line 295 of file SparseTensorType.h.

References getLvlType(), and mlir::sparse_tensor::isOrderedLT().

◆ isPermutation()

bool mlir::sparse_tensor::SparseTensorType::isPermutation ( ) const
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.

◆ isSingletonLvl()

bool mlir::sparse_tensor::SparseTensorType::isSingletonLvl ( Level  l) const
inline

Definition at line 293 of file SparseTensorType.h.

References getLvlType(), and mlir::sparse_tensor::isSingletonLT().

◆ isUniqueLvl()

bool mlir::sparse_tensor::SparseTensorType::isUniqueLvl ( Level  l) const
inline

Definition at line 296 of file SparseTensorType.h.

References getLvlType(), and mlir::sparse_tensor::isUniqueLT().

Referenced by genCompressed().

◆ isWithCrd()

bool mlir::sparse_tensor::SparseTensorType::isWithCrd ( Level  l) const
inline

Definition at line 298 of file SparseTensorType.h.

References getLvlType(), and mlir::sparse_tensor::isWithCrdLT().

◆ isWithPos()

bool mlir::sparse_tensor::SparseTensorType::isWithPos ( Level  l) const
inline

Definition at line 297 of file SparseTensorType.h.

References getLvlType(), and mlir::sparse_tensor::isWithPosLT().

◆ operator T()

template<typename T , typename = std::enable_if_t< std::is_convertible_v<RankedTensorType, T>>>
mlir::sparse_tensor::SparseTensorType::operator T ( ) const
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.

◆ operator!=()

bool mlir::sparse_tensor::SparseTensorType::operator!= ( const SparseTensorType other) const
inline

Definition at line 154 of file SparseTensorType.h.

◆ operator=()

SparseTensorType& mlir::sparse_tensor::SparseTensorType::operator= ( const SparseTensorType )
delete

◆ operator==()

bool mlir::sparse_tensor::SparseTensorType::operator== ( const SparseTensorType other) const
inline

Definition at line 148 of file SparseTensorType.h.

◆ translateCrds()

ValueRange mlir::sparse_tensor::SparseTensorType::translateCrds ( OpBuilder builder,
Location  loc,
ValueRange  crds,
CrdTransDirectionKind  dir 
) const
inline

Translates between level / dimension coordinate space.

Definition at line 182 of file SparseTensorType.h.

◆ withBitWidths()

SparseTensorType mlir::sparse_tensor::SparseTensorType::withBitWidths ( unsigned  posWidth,
unsigned  crdWidth 
) const
inline

Definition at line 97 of file SparseTensorType.h.

References withEncoding().

◆ withDimSlices()

SparseTensorType mlir::sparse_tensor::SparseTensorType::withDimSlices ( ArrayRef< SparseTensorDimSliceAttr >  dimSlices) const
inline

Definition at line 106 of file SparseTensorType.h.

References withEncoding().

◆ withDimToLvl() [1/3]

SparseTensorType mlir::sparse_tensor::SparseTensorType::withDimToLvl ( AffineMap  dimToLvl) const
inline

Definition at line 81 of file SparseTensorType.h.

References withEncoding().

Referenced by withDimToLvl().

◆ withDimToLvl() [2/3]

SparseTensorType mlir::sparse_tensor::SparseTensorType::withDimToLvl ( const SparseTensorType dimToLvlSTT) const
inline

Definition at line 89 of file SparseTensorType.h.

References getEncoding(), and withDimToLvl().

◆ withDimToLvl() [3/3]

SparseTensorType mlir::sparse_tensor::SparseTensorType::withDimToLvl ( SparseTensorEncodingAttr  dimToLvlEnc) const
inline

Definition at line 85 of file SparseTensorType.h.

References withEncoding().

◆ withEncoding()

SparseTensorType mlir::sparse_tensor::SparseTensorType::withEncoding ( SparseTensorEncodingAttr  newEnc) const
inline

◆ withoutBitWidths()

SparseTensorType mlir::sparse_tensor::SparseTensorType::withoutBitWidths ( ) const
inline

Definition at line 101 of file SparseTensorType.h.

References withEncoding().

◆ withoutDimSlices()

SparseTensorType mlir::sparse_tensor::SparseTensorType::withoutDimSlices ( ) const
inline

Definition at line 110 of file SparseTensorType.h.

References withEncoding().

◆ withoutDimToLvl()

SparseTensorType mlir::sparse_tensor::SparseTensorType::withoutDimToLvl ( ) const
inline

Definition at line 93 of file SparseTensorType.h.

References withEncoding().


The documentation for this class was generated from the following files: