MLIR  16.0.0git
DialectSparseTensor.cpp
Go to the documentation of this file.
1 //===- DialectSparseTensor.cpp - 'sparse_tensor' dialect submodule --------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "mlir-c/IR.h"
12 
13 namespace py = pybind11;
14 using namespace llvm;
15 using namespace mlir;
16 using namespace mlir::python::adaptors;
17 
18 static void populateDialectSparseTensorSubmodule(const py::module &m) {
19  py::enum_<MlirSparseTensorDimLevelType>(m, "DimLevelType", py::module_local())
21  .value("compressed", MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED);
22 
23  mlir_attribute_subclass(m, "EncodingAttr",
26  "get",
27  [](py::object cls,
28  std::vector<MlirSparseTensorDimLevelType> dimLevelTypes,
29  llvm::Optional<MlirAffineMap> dimOrdering, int pointerBitWidth,
30  int indexBitWidth, MlirContext context) {
32  context, dimLevelTypes.size(), dimLevelTypes.data(),
33  dimOrdering ? *dimOrdering : MlirAffineMap{nullptr},
34  pointerBitWidth, indexBitWidth));
35  },
36  py::arg("cls"), py::arg("dim_level_types"), py::arg("dim_ordering"),
37  py::arg("pointer_bit_width"), py::arg("index_bit_width"),
38  py::arg("context") = py::none(),
39  "Gets a sparse_tensor.encoding from parameters.")
40  .def_property_readonly(
41  "dim_level_types",
42  [](MlirAttribute self) {
43  std::vector<MlirSparseTensorDimLevelType> ret;
44  for (int i = 0,
46  i < e; ++i)
47  ret.push_back(
49  return ret;
50  })
51  .def_property_readonly(
52  "dim_ordering",
53  [](MlirAttribute self) -> llvm::Optional<MlirAffineMap> {
54  MlirAffineMap ret =
56  if (mlirAffineMapIsNull(ret))
57  return {};
58  return ret;
59  })
60  .def_property_readonly(
61  "pointer_bit_width",
62  [](MlirAttribute self) {
64  })
65  .def_property_readonly("index_bit_width", [](MlirAttribute self) {
67  });
68 }
69 
70 PYBIND11_MODULE(_mlirDialectsSparseTensor, m) {
71  m.doc() = "MLIR SparseTensor dialect.";
73 }
Include the generated interface declarations.
static bool mlirAffineMapIsNull(MlirAffineMap affineMap)
Checks whether an affine map is null.
Definition: AffineMap.h:47
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition: CallGraph.h:221
Creates a custom subclass of mlir.ir.Attribute, implementing a casting constructor and type checking ...
MLIR_CAPI_EXPORTED MlirAffineMap mlirSparseTensorEncodingAttrGetDimOrdering(MlirAttribute attr)
Returns the dimension ordering in a sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED enum MlirSparseTensorDimLevelType mlirSparseTensorEncodingAttrGetDimLevelType(MlirAttribute attr, intptr_t pos)
Returns a specified dim level type in a sparse_tensor.encoding attribute.
static constexpr const bool value
pure_subclass & def_classmethod(const char *name, Func &&f, const Extra &...extra)
MLIR_CAPI_EXPORTED int mlirSparseTensorEncodingAttrGetPointerBitWidth(MlirAttribute attr)
Returns the pointer bit width in a sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED int mlirSparseTensorEncodingAttrGetIndexBitWidth(MlirAttribute attr)
Returns the index bit width in a sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED intptr_t mlirSparseTensorEncodingGetNumDimLevelTypes(MlirAttribute attr)
Returns the number of dim level types in a sparse_tensor.encoding attribute.
static void populateDialectSparseTensorSubmodule(const py::module &m)
MLIR_CAPI_EXPORTED bool mlirAttributeIsASparseTensorEncodingAttr(MlirAttribute attr)
Checks whether the given attribute is a sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirSparseTensorEncodingAttrGet(MlirContext ctx, intptr_t numDimLevelTypes, enum MlirSparseTensorDimLevelType const *dimLevelTypes, MlirAffineMap dimOrdering, int pointerBitWidth, int indexBitWidth)
Creates a sparse_tensor.encoding attribute with the given parameters.
PYBIND11_MODULE(_mlirDialectsSparseTensor, m)