14 #include <pybind11/cast.h>
15 #include <pybind11/detail/common.h>
16 #include <pybind11/pybind11.h>
17 #include <pybind11/pytypes.h>
26 py::enum_<MlirSparseTensorLevelFormat>(m,
"LevelFormat", py::module_local())
33 py::enum_<MlirSparseTensorLevelPropertyNondefault>(m,
"LevelProperty",
43 [](py::object cls, std::vector<MlirSparseTensorLevelType> lvlTypes,
44 std::optional<MlirAffineMap> dimToLvl,
45 std::optional<MlirAffineMap> lvlToDim,
int posWidth,
int crdWidth,
46 std::optional<MlirAttribute> explicitVal,
47 std::optional<MlirAttribute> implicitVal, MlirContext context) {
49 context, lvlTypes.size(), lvlTypes.data(),
50 dimToLvl ? *dimToLvl : MlirAffineMap{nullptr},
51 lvlToDim ? *lvlToDim : MlirAffineMap{nullptr}, posWidth,
52 crdWidth, explicitVal ? *explicitVal : MlirAttribute{nullptr},
53 implicitVal ? *implicitVal : MlirAttribute{nullptr}));
55 py::arg(
"cls"), py::arg(
"lvl_types"), py::arg(
"dim_to_lvl"),
56 py::arg(
"lvl_to_dim"), py::arg(
"pos_width"), py::arg(
"crd_width"),
57 py::arg(
"explicit_val") = py::none(),
58 py::arg(
"implicit_val") = py::none(), py::arg(
"context") = py::none(),
59 "Gets a sparse_tensor.encoding from parameters.")
63 const std::vector<MlirSparseTensorLevelPropertyNondefault>
65 unsigned n,
unsigned m) {
67 lvlFmt, properties.data(), properties.size(), n, m);
69 py::arg(
"cls"), py::arg(
"lvl_fmt"),
70 py::arg(
"properties") =
71 std::vector<MlirSparseTensorLevelPropertyNondefault>(),
72 py::arg(
"n") = 0, py::arg(
"m") = 0,
73 "Builds a sparse_tensor.encoding.level_type from parameters.")
74 .def_property_readonly(
76 [](MlirAttribute
self) {
78 std::vector<MlirSparseTensorLevelType> ret;
80 for (
int l = 0; l < lvlRank; ++l)
84 .def_property_readonly(
86 [](MlirAttribute
self) -> std::optional<MlirAffineMap> {
92 .def_property_readonly(
94 [](MlirAttribute
self) -> std::optional<MlirAffineMap> {
100 .def_property_readonly(
"pos_width",
106 [](MlirAttribute
self) -> std::optional<MlirAttribute> {
113 .def_property_readonly(
115 [](MlirAttribute
self) -> std::optional<MlirAttribute> {
122 .def_property_readonly(
124 [](MlirAttribute
self) ->
unsigned {
129 .def_property_readonly(
131 [](MlirAttribute
self) ->
unsigned {
136 .def_property_readonly(
"lvl_formats_enum", [](MlirAttribute
self) {
138 std::vector<MlirSparseTensorLevelFormat> ret;
139 ret.reserve(lvlRank);
140 for (
int l = 0; l < lvlRank; l++)
147 m.doc() =
"MLIR SparseTensor dialect.";
PYBIND11_MODULE(_mlirDialectsSparseTensor, m)
static void populateDialectSparseTensorSubmodule(const py::module &m)
Creates a custom subclass of mlir.ir.Attribute, implementing a casting constructor and type checking ...
pure_subclass & def_classmethod(const char *name, Func &&f, const Extra &...extra)
pure_subclass & def_property_readonly(const char *name, Func &&f, const Extra &...extra)
static bool mlirAffineMapIsNull(MlirAffineMap affineMap)
Checks whether an affine map is null.
MLIR_CAPI_EXPORTED MlirAffineMap mlirSparseTensorEncodingAttrGetDimToLvl(MlirAttribute attr)
Returns the dimension-to-level mapping of the sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirSparseTensorEncodingAttrGetImplicitVal(MlirAttribute attr)
Returns the implicit value of the sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED intptr_t mlirSparseTensorEncodingGetLvlRank(MlirAttribute attr)
Returns the level-rank of the sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirSparseTensorEncodingAttrGet(MlirContext ctx, intptr_t lvlRank, MlirSparseTensorLevelType const *lvlTypes, MlirAffineMap dimToLvl, MlirAffineMap lvlTodim, int posWidth, int crdWidth, MlirAttribute explicitVal, MlirAttribute implicitVal)
Creates a sparse_tensor.encoding attribute with the given parameters.
MLIR_CAPI_EXPORTED enum MlirSparseTensorLevelFormat mlirSparseTensorEncodingAttrGetLvlFmt(MlirAttribute attr, intptr_t lvl)
Returns a specified level-format of the sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED int mlirSparseTensorEncodingAttrGetCrdWidth(MlirAttribute attr)
Returns the coordinate bitwidth of the sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED MlirAffineMap mlirSparseTensorEncodingAttrGetLvlToDim(MlirAttribute attr)
Returns the level-to-dimension mapping of the sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirSparseTensorEncodingAttrGetExplicitVal(MlirAttribute attr)
Returns the explicit value of the sparse_tensor.encoding attribute.
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
MLIR_CAPI_EXPORTED unsigned mlirSparseTensorEncodingAttrGetStructuredN(MlirSparseTensorLevelType lvlType)
MLIR_CAPI_EXPORTED MlirSparseTensorLevelType mlirSparseTensorEncodingAttrBuildLvlType(enum MlirSparseTensorLevelFormat lvlFmt, const enum MlirSparseTensorLevelPropertyNondefault *properties, unsigned propSize, unsigned n, unsigned m)
MLIR_CAPI_EXPORTED unsigned mlirSparseTensorEncodingAttrGetStructuredM(MlirSparseTensorLevelType lvlType)
MLIR_CAPI_EXPORTED bool mlirAttributeIsASparseTensorEncodingAttr(MlirAttribute attr)
Checks whether the given attribute is a sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED MlirSparseTensorLevelType mlirSparseTensorEncodingAttrGetLvlType(MlirAttribute attr, intptr_t lvl)
Returns a specified level-type of the sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED int mlirSparseTensorEncodingAttrGetPosWidth(MlirAttribute attr)
Returns the position bitwidth of the sparse_tensor.encoding attribute.
@ MLIR_SPARSE_PROPERTY_NON_UNIQUE
@ MLIR_SPARSE_PROPERTY_NON_ORDERED
@ MLIR_SPARSE_PROPERTY_SOA
static bool mlirAttributeIsNull(MlirAttribute attr)
Checks whether an attribute is null.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Include the generated interface declarations.