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
17extern "C" {
18#endif
19
20MLIR_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.
28typedef uint64_t MlirSparseTensorLevelType;
29
30enum MlirSparseTensorLevelFormat {
31 MLIR_SPARSE_TENSOR_LEVEL_DENSE = 0x000000010000,
32 MLIR_SPARSE_TENSOR_LEVEL_BATCH = 0x000000020000,
33 MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED = 0x000000040000,
34 MLIR_SPARSE_TENSOR_LEVEL_SINGLETON = 0x000000080000,
35 MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED = 0x000000100000,
36 MLIR_SPARSE_TENSOR_LEVEL_N_OUT_OF_M = 0x000000200000,
37};
38
39enum MlirSparseTensorLevelPropertyNondefault {
40 MLIR_SPARSE_PROPERTY_NON_UNIQUE = 0x0001,
41 MLIR_SPARSE_PROPERTY_NON_ORDERED = 0x0002,
42 MLIR_SPARSE_PROPERTY_SOA = 0x0004,
43};
44
45//===----------------------------------------------------------------------===//
46// SparseTensorEncodingAttr
47//===----------------------------------------------------------------------===//
48
49/// Checks whether the given attribute is a `sparse_tensor.encoding` attribute.
50MLIR_CAPI_EXPORTED bool
51mlirAttributeIsASparseTensorEncodingAttr(MlirAttribute attr);
52
53/// Creates a `sparse_tensor.encoding` attribute with the given parameters.
54MLIR_CAPI_EXPORTED MlirAttribute mlirSparseTensorEncodingAttrGet(
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.
61MLIR_CAPI_EXPORTED intptr_t
62mlirSparseTensorEncodingGetLvlRank(MlirAttribute attr);
63
64/// Returns a specified level-type of the `sparse_tensor.encoding` attribute.
65MLIR_CAPI_EXPORTED MlirSparseTensorLevelType
66mlirSparseTensorEncodingAttrGetLvlType(MlirAttribute attr, intptr_t lvl);
67
68/// Returns a specified level-format of the `sparse_tensor.encoding` attribute.
69MLIR_CAPI_EXPORTED enum MlirSparseTensorLevelFormat
70mlirSparseTensorEncodingAttrGetLvlFmt(MlirAttribute attr, intptr_t lvl);
71
72/// Returns the dimension-to-level mapping of the `sparse_tensor.encoding`
73/// attribute.
74MLIR_CAPI_EXPORTED MlirAffineMap
75mlirSparseTensorEncodingAttrGetDimToLvl(MlirAttribute attr);
76
77/// Returns the level-to-dimension mapping of the `sparse_tensor.encoding`
78/// attribute.
79MLIR_CAPI_EXPORTED MlirAffineMap
80mlirSparseTensorEncodingAttrGetLvlToDim(MlirAttribute attr);
81
82/// Returns the position bitwidth of the `sparse_tensor.encoding` attribute.
83MLIR_CAPI_EXPORTED int
84mlirSparseTensorEncodingAttrGetPosWidth(MlirAttribute attr);
85
86/// Returns the coordinate bitwidth of the `sparse_tensor.encoding` attribute.
87MLIR_CAPI_EXPORTED int
88mlirSparseTensorEncodingAttrGetCrdWidth(MlirAttribute attr);
89
90/// Returns the explicit value of the `sparse_tensor.encoding` attribute.
91MLIR_CAPI_EXPORTED MlirAttribute
92mlirSparseTensorEncodingAttrGetExplicitVal(MlirAttribute attr);
93
94/// Returns the implicit value of the `sparse_tensor.encoding` attribute.
95MLIR_CAPI_EXPORTED MlirAttribute
96mlirSparseTensorEncodingAttrGetImplicitVal(MlirAttribute attr);
97
98MLIR_CAPI_EXPORTED unsigned
99mlirSparseTensorEncodingAttrGetStructuredN(MlirSparseTensorLevelType lvlType);
100
101MLIR_CAPI_EXPORTED unsigned
102mlirSparseTensorEncodingAttrGetStructuredM(MlirSparseTensorLevelType lvlType);
103
104MLIR_CAPI_EXPORTED MlirSparseTensorLevelType
105mlirSparseTensorEncodingAttrBuildLvlType(
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
117

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

source code of mlir/include/mlir-c/Dialect/SparseTensor.h