20 mlir::sparse_tensor::SparseTensorDialect)
25 static_cast<int>(LevelFormat::Dense) &&
27 static_cast<int>(LevelFormat::Compressed) &&
29 static_cast<int>(LevelFormat::Singleton) &&
31 static_cast<int>(LevelFormat::LooseCompressed) &&
33 static_cast<int>(LevelFormat::NOutOfM),
34 "MlirSparseTensorLevelFormat (C-API) and LevelFormat (C++) mismatch");
37 static_cast<int>(LevelPropNonDefault::Nonordered) &&
39 static_cast<int>(LevelPropNonDefault::Nonunique),
40 "MlirSparseTensorLevelProperty (C-API) and "
41 "LevelPropertyNondefault (C++) mismatch");
44 return isa<SparseTensorEncodingAttr>(
unwrap(attr));
50 MlirAffineMap dimToLvl, MlirAffineMap lvlToDim,
51 int posWidth,
int crdWidth) {
53 cppLvlTypes.reserve(lvlRank);
54 for (intptr_t l = 0; l < lvlRank; ++l)
55 cppLvlTypes.push_back(
static_cast<LevelType>(lvlTypes[l]));
62 return wrap(cast<SparseTensorEncodingAttr>(
unwrap(attr)).getDimToLvl());
66 return wrap(cast<SparseTensorEncodingAttr>(
unwrap(attr)).getLvlToDim());
70 return cast<SparseTensorEncodingAttr>(
unwrap(attr)).getLvlRank();
76 cast<SparseTensorEncodingAttr>(
unwrap(attr)).getLvlType(lvl));
87 return cast<SparseTensorEncodingAttr>(
unwrap(attr)).getPosWidth();
91 return cast<SparseTensorEncodingAttr>(
unwrap(attr)).getCrdWidth();
97 unsigned size,
unsigned n,
unsigned m) {
99 std::vector<LevelPropNonDefault> props;
100 for (
unsigned i = 0; i < size; i++)
intptr_t mlirSparseTensorEncodingGetLvlRank(MlirAttribute attr)
Returns the level-rank of the sparse_tensor.encoding attribute.
MlirAffineMap mlirSparseTensorEncodingAttrGetLvlToDim(MlirAttribute attr)
Returns the level-to-dimension mapping of the sparse_tensor.encoding attribute.
int mlirSparseTensorEncodingAttrGetCrdWidth(MlirAttribute attr)
Returns the coordinate bitwidth of the sparse_tensor.encoding attribute.
MlirSparseTensorLevelType mlirSparseTensorEncodingAttrBuildLvlType(enum MlirSparseTensorLevelFormat lvlFmt, const enum MlirSparseTensorLevelPropertyNondefault *properties, unsigned size, unsigned n, unsigned m)
bool mlirAttributeIsASparseTensorEncodingAttr(MlirAttribute attr)
Checks whether the given attribute is a sparse_tensor.encoding attribute.
MlirAffineMap mlirSparseTensorEncodingAttrGetDimToLvl(MlirAttribute attr)
Returns the dimension-to-level mapping of the sparse_tensor.encoding attribute.
int mlirSparseTensorEncodingAttrGetPosWidth(MlirAttribute attr)
Returns the position bitwidth of the sparse_tensor.encoding attribute.
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(SparseTensor, sparse_tensor, mlir::sparse_tensor::SparseTensorDialect) static_assert(static_cast< int >(MLIR_SPARSE_TENSOR_LEVEL_DENSE)
unsigned mlirSparseTensorEncodingAttrGetStructuredN(MlirSparseTensorLevelType lvlType)
unsigned mlirSparseTensorEncodingAttrGetStructuredM(MlirSparseTensorLevelType lvlType)
MlirAttribute mlirSparseTensorEncodingAttrGet(MlirContext ctx, intptr_t lvlRank, MlirSparseTensorLevelType const *lvlTypes, MlirAffineMap dimToLvl, MlirAffineMap lvlToDim, int posWidth, int crdWidth)
Creates a sparse_tensor.encoding attribute with the given parameters.
enum MlirSparseTensorLevelFormat mlirSparseTensorEncodingAttrGetLvlFmt(MlirAttribute attr, intptr_t lvl)
Returns a specified level-format of the sparse_tensor.encoding attribute.
MlirSparseTensorLevelType mlirSparseTensorEncodingAttrGetLvlType(MlirAttribute attr, intptr_t lvl)
Returns a specified level-type of the sparse_tensor.encoding attribute.
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
uint64_t MlirSparseTensorLevelType
Dimension level types (and properties) that define sparse tensors.
MlirSparseTensorLevelFormat
@ MLIR_SPARSE_TENSOR_LEVEL_N_OUT_OF_M
@ MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED
@ MLIR_SPARSE_TENSOR_LEVEL_DENSE
@ MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED
@ MLIR_SPARSE_TENSOR_LEVEL_SINGLETON
MlirSparseTensorLevelPropertyNondefault
@ MLIR_SPARSE_PROPERTY_NON_UNIQUE
@ MLIR_SPARSE_PROPERTY_NON_ORDERED
Include the generated interface declarations.
LevelFormat
This enum defines all supported storage format without the level properties.
uint64_t getN(LevelType lt)
uint64_t getM(LevelType lt)
LevelPropNonDefault
This enum defines all the nondefault properties for storage formats.
std::optional< LevelType > buildLevelType(LevelFormat lf, const std::vector< LevelPropNonDefault > &properties, uint64_t n=0, uint64_t m=0)
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
This enum defines all the sparse representations supportable by the SparseTensor dialect.
constexpr LevelFormat getLvlFmt() const
Get the LevelFormat of the LevelType.