MLIR  20.0.0git
SparseTensor.h
Go to the documentation of this file.
1 //===-- mlir-c/Dialect/SparseTensor.h - C API for SparseTensor ----*- C -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM
4 // Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef MLIR_C_DIALECT_SPARSETENSOR_H
11 #define MLIR_C_DIALECT_SPARSETENSOR_H
12 
13 #include "mlir-c/AffineMap.h"
14 #include "mlir-c/IR.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(SparseTensor, sparse_tensor);
21 
22 /// Dimension level types (and properties) that define sparse tensors.
23 /// See the documentation in SparseTensorAttrDefs.td for their meaning.
24 ///
25 /// These correspond to SparseTensorEncodingAttr::LevelType in the C++ API.
26 /// If updating, keep them in sync and update the static_assert in the impl
27 /// file.
28 typedef uint64_t MlirSparseTensorLevelType;
29 
37 };
38 
43 };
44 
45 //===----------------------------------------------------------------------===//
46 // SparseTensorEncodingAttr
47 //===----------------------------------------------------------------------===//
48 
49 /// Checks whether the given attribute is a `sparse_tensor.encoding` attribute.
52 
53 /// Creates a `sparse_tensor.encoding` attribute with the given parameters.
55  MlirContext ctx, intptr_t lvlRank,
56  MlirSparseTensorLevelType const *lvlTypes, MlirAffineMap dimToLvl,
57  MlirAffineMap lvlTodim, int posWidth, int crdWidth,
58  MlirAttribute explicitVal, MlirAttribute implicitVal);
59 
60 /// Returns the level-rank of the `sparse_tensor.encoding` attribute.
61 MLIR_CAPI_EXPORTED intptr_t
62 mlirSparseTensorEncodingGetLvlRank(MlirAttribute attr);
63 
64 /// Returns a specified level-type of the `sparse_tensor.encoding` attribute.
66 mlirSparseTensorEncodingAttrGetLvlType(MlirAttribute attr, intptr_t lvl);
67 
68 /// Returns a specified level-format of the `sparse_tensor.encoding` attribute.
70 mlirSparseTensorEncodingAttrGetLvlFmt(MlirAttribute attr, intptr_t lvl);
71 
72 /// Returns the dimension-to-level mapping of the `sparse_tensor.encoding`
73 /// attribute.
74 MLIR_CAPI_EXPORTED MlirAffineMap
75 mlirSparseTensorEncodingAttrGetDimToLvl(MlirAttribute attr);
76 
77 /// Returns the level-to-dimension mapping of the `sparse_tensor.encoding`
78 /// attribute.
79 MLIR_CAPI_EXPORTED MlirAffineMap
80 mlirSparseTensorEncodingAttrGetLvlToDim(MlirAttribute attr);
81 
82 /// Returns the position bitwidth of the `sparse_tensor.encoding` attribute.
84 mlirSparseTensorEncodingAttrGetPosWidth(MlirAttribute attr);
85 
86 /// Returns the coordinate bitwidth of the `sparse_tensor.encoding` attribute.
88 mlirSparseTensorEncodingAttrGetCrdWidth(MlirAttribute attr);
89 
90 /// Returns the explicit value of the `sparse_tensor.encoding` attribute.
91 MLIR_CAPI_EXPORTED MlirAttribute
93 
94 /// Returns the implicit value of the `sparse_tensor.encoding` attribute.
95 MLIR_CAPI_EXPORTED MlirAttribute
97 
98 MLIR_CAPI_EXPORTED unsigned
100 
101 MLIR_CAPI_EXPORTED unsigned
103 
106  enum MlirSparseTensorLevelFormat lvlFmt,
107  const enum MlirSparseTensorLevelPropertyNondefault *properties,
108  unsigned propSize, unsigned n, unsigned m);
109 
110 #ifdef __cplusplus
111 }
112 #endif
113 
114 #include "mlir/Dialect/SparseTensor/Transforms/Passes.capi.h.inc"
115 
116 #endif // MLIR_C_DIALECT_SPARSETENSOR_H
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.
uint64_t MlirSparseTensorLevelType
Dimension level types (and properties) that define sparse tensors.
Definition: SparseTensor.h:28
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
Definition: SparseTensor.h:30
@ MLIR_SPARSE_TENSOR_LEVEL_N_OUT_OF_M
Definition: SparseTensor.h:36
@ MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED
Definition: SparseTensor.h:33
@ MLIR_SPARSE_TENSOR_LEVEL_DENSE
Definition: SparseTensor.h:31
@ MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED
Definition: SparseTensor.h:35
@ MLIR_SPARSE_TENSOR_LEVEL_SINGLETON
Definition: SparseTensor.h:34
@ MLIR_SPARSE_TENSOR_LEVEL_BATCH
Definition: SparseTensor.h:32
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_DECLARE_CAPI_DIALECT_REGISTRATION(SparseTensor, sparse_tensor)
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.
MlirSparseTensorLevelPropertyNondefault
Definition: SparseTensor.h:39
@ MLIR_SPARSE_PROPERTY_NON_UNIQUE
Definition: SparseTensor.h:40
@ MLIR_SPARSE_PROPERTY_NON_ORDERED
Definition: SparseTensor.h:41
@ MLIR_SPARSE_PROPERTY_SOA
Definition: SparseTensor.h:42
#define MLIR_CAPI_EXPORTED
Definition: Support.h:46