1bcfa7baeSStella Laurenzo //===-- mlir-c/Dialect/SparseTensor.h - C API for SparseTensor ----*- C -*-===// 2bcfa7baeSStella Laurenzo // 3bcfa7baeSStella Laurenzo // Part of the LLVM Project, under the Apache License v2.0 with LLVM 4bcfa7baeSStella Laurenzo // Exceptions. 5bcfa7baeSStella Laurenzo // See https://llvm.org/LICENSE.txt for license information. 6bcfa7baeSStella Laurenzo // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7bcfa7baeSStella Laurenzo // 8bcfa7baeSStella Laurenzo //===----------------------------------------------------------------------===// 9bcfa7baeSStella Laurenzo 108f23296bSMehdi Amini #ifndef MLIR_C_DIALECT_SPARSETENSOR_H 118f23296bSMehdi Amini #define MLIR_C_DIALECT_SPARSETENSOR_H 12bcfa7baeSStella Laurenzo 13bcfa7baeSStella Laurenzo #include "mlir-c/AffineMap.h" 145e83a5b4SStella Laurenzo #include "mlir-c/IR.h" 15bcfa7baeSStella Laurenzo 16bcfa7baeSStella Laurenzo #ifdef __cplusplus 17bcfa7baeSStella Laurenzo extern "C" { 18bcfa7baeSStella Laurenzo #endif 19bcfa7baeSStella Laurenzo 20bcfa7baeSStella Laurenzo MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(SparseTensor, sparse_tensor); 21bcfa7baeSStella Laurenzo 221b434652SAart Bik /// Dimension level types (and properties) that define sparse tensors. 231b434652SAart Bik /// See the documentation in SparseTensorAttrDefs.td for their meaning. 24bcfa7baeSStella Laurenzo /// 251944c4f7SAart Bik /// These correspond to SparseTensorEncodingAttr::LevelType in the C++ API. 26bcfa7baeSStella Laurenzo /// If updating, keep them in sync and update the static_assert in the impl 27bcfa7baeSStella Laurenzo /// file. 28cd481fa8SYinying Li typedef uint64_t MlirSparseTensorLevelType; 29cd481fa8SYinying Li 30429919e3SPeiming Liu enum MlirSparseTensorLevelFormat { 31e5924d64SYinying Li MLIR_SPARSE_TENSOR_LEVEL_DENSE = 0x000000010000, 3256d58295SPeiming Liu MLIR_SPARSE_TENSOR_LEVEL_BATCH = 0x000000020000, 3356d58295SPeiming Liu MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED = 0x000000040000, 3456d58295SPeiming Liu MLIR_SPARSE_TENSOR_LEVEL_SINGLETON = 0x000000080000, 3556d58295SPeiming Liu MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED = 0x000000100000, 3656d58295SPeiming Liu MLIR_SPARSE_TENSOR_LEVEL_N_OUT_OF_M = 0x000000200000, 37bcfa7baeSStella Laurenzo }; 38bcfa7baeSStella Laurenzo 39429919e3SPeiming Liu enum MlirSparseTensorLevelPropertyNondefault { 40429919e3SPeiming Liu MLIR_SPARSE_PROPERTY_NON_UNIQUE = 0x0001, 41429919e3SPeiming Liu MLIR_SPARSE_PROPERTY_NON_ORDERED = 0x0002, 42*b50ce4c8SMateusz Sokół MLIR_SPARSE_PROPERTY_SOA = 0x0004, 43429919e3SPeiming Liu }; 44429919e3SPeiming Liu 45bcfa7baeSStella Laurenzo //===----------------------------------------------------------------------===// 46bcfa7baeSStella Laurenzo // SparseTensorEncodingAttr 47bcfa7baeSStella Laurenzo //===----------------------------------------------------------------------===// 48bcfa7baeSStella Laurenzo 4984cd51bbSwren romano /// Checks whether the given attribute is a `sparse_tensor.encoding` attribute. 50bcfa7baeSStella Laurenzo MLIR_CAPI_EXPORTED bool 51bcfa7baeSStella Laurenzo mlirAttributeIsASparseTensorEncodingAttr(MlirAttribute attr); 52bcfa7baeSStella Laurenzo 5384cd51bbSwren romano /// Creates a `sparse_tensor.encoding` attribute with the given parameters. 54bcfa7baeSStella Laurenzo MLIR_CAPI_EXPORTED MlirAttribute mlirSparseTensorEncodingAttrGet( 5584cd51bbSwren romano MlirContext ctx, intptr_t lvlRank, 56cd481fa8SYinying Li MlirSparseTensorLevelType const *lvlTypes, MlirAffineMap dimToLvl, 57a10d67f9SYinying Li MlirAffineMap lvlTodim, int posWidth, int crdWidth, 58a10d67f9SYinying Li MlirAttribute explicitVal, MlirAttribute implicitVal); 59bcfa7baeSStella Laurenzo 6084cd51bbSwren romano /// Returns the level-rank of the `sparse_tensor.encoding` attribute. 61bcfa7baeSStella Laurenzo MLIR_CAPI_EXPORTED intptr_t 6284cd51bbSwren romano mlirSparseTensorEncodingGetLvlRank(MlirAttribute attr); 63bcfa7baeSStella Laurenzo 6484cd51bbSwren romano /// Returns a specified level-type of the `sparse_tensor.encoding` attribute. 65cd481fa8SYinying Li MLIR_CAPI_EXPORTED MlirSparseTensorLevelType 66a0615d02Swren romano mlirSparseTensorEncodingAttrGetLvlType(MlirAttribute attr, intptr_t lvl); 67bcfa7baeSStella Laurenzo 68429919e3SPeiming Liu /// Returns a specified level-format of the `sparse_tensor.encoding` attribute. 69429919e3SPeiming Liu MLIR_CAPI_EXPORTED enum MlirSparseTensorLevelFormat 70429919e3SPeiming Liu mlirSparseTensorEncodingAttrGetLvlFmt(MlirAttribute attr, intptr_t lvl); 71429919e3SPeiming Liu 7276647fceSwren romano /// Returns the dimension-to-level mapping of the `sparse_tensor.encoding` 7376647fceSwren romano /// attribute. 74bcfa7baeSStella Laurenzo MLIR_CAPI_EXPORTED MlirAffineMap 7576647fceSwren romano mlirSparseTensorEncodingAttrGetDimToLvl(MlirAttribute attr); 76c48e9087SAart Bik 77836411b9SAart Bik /// Returns the level-to-dimension mapping of the `sparse_tensor.encoding` 78836411b9SAart Bik /// attribute. 79836411b9SAart Bik MLIR_CAPI_EXPORTED MlirAffineMap 80836411b9SAart Bik mlirSparseTensorEncodingAttrGetLvlToDim(MlirAttribute attr); 81836411b9SAart Bik 8284cd51bbSwren romano /// Returns the position bitwidth of the `sparse_tensor.encoding` attribute. 83bcfa7baeSStella Laurenzo MLIR_CAPI_EXPORTED int 8484cd51bbSwren romano mlirSparseTensorEncodingAttrGetPosWidth(MlirAttribute attr); 85bcfa7baeSStella Laurenzo 8684cd51bbSwren romano /// Returns the coordinate bitwidth of the `sparse_tensor.encoding` attribute. 87bcfa7baeSStella Laurenzo MLIR_CAPI_EXPORTED int 8884cd51bbSwren romano mlirSparseTensorEncodingAttrGetCrdWidth(MlirAttribute attr); 89bcfa7baeSStella Laurenzo 90a10d67f9SYinying Li /// Returns the explicit value of the `sparse_tensor.encoding` attribute. 91a10d67f9SYinying Li MLIR_CAPI_EXPORTED MlirAttribute 92a10d67f9SYinying Li mlirSparseTensorEncodingAttrGetExplicitVal(MlirAttribute attr); 93a10d67f9SYinying Li 94a10d67f9SYinying Li /// Returns the implicit value of the `sparse_tensor.encoding` attribute. 95a10d67f9SYinying Li MLIR_CAPI_EXPORTED MlirAttribute 96a10d67f9SYinying Li mlirSparseTensorEncodingAttrGetImplicitVal(MlirAttribute attr); 97a10d67f9SYinying Li 982a6b521bSYinying Li MLIR_CAPI_EXPORTED unsigned 992a6b521bSYinying Li mlirSparseTensorEncodingAttrGetStructuredN(MlirSparseTensorLevelType lvlType); 1002a6b521bSYinying Li 1012a6b521bSYinying Li MLIR_CAPI_EXPORTED unsigned 1022a6b521bSYinying Li mlirSparseTensorEncodingAttrGetStructuredM(MlirSparseTensorLevelType lvlType); 1032a6b521bSYinying Li 1042a6b521bSYinying Li MLIR_CAPI_EXPORTED MlirSparseTensorLevelType 1052a6b521bSYinying Li mlirSparseTensorEncodingAttrBuildLvlType( 106429919e3SPeiming Liu enum MlirSparseTensorLevelFormat lvlFmt, 107429919e3SPeiming Liu const enum MlirSparseTensorLevelPropertyNondefault *properties, 108429919e3SPeiming Liu unsigned propSize, unsigned n, unsigned m); 1092a6b521bSYinying Li 110bcfa7baeSStella Laurenzo #ifdef __cplusplus 111bcfa7baeSStella Laurenzo } 112bcfa7baeSStella Laurenzo #endif 113bcfa7baeSStella Laurenzo 11458d12332SAart Bik #include "mlir/Dialect/SparseTensor/Transforms/Passes.capi.h.inc" 11558d12332SAart Bik 1168f23296bSMehdi Amini #endif // MLIR_C_DIALECT_SPARSETENSOR_H 117