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::DimLevelType in the C++ API. 26 /// If updating, keep them in sync and update the static_assert in the impl 27 /// file. 28 enum MlirSparseTensorDimLevelType { 29 MLIR_SPARSE_TENSOR_DIM_LEVEL_DENSE, 30 MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED, 31 MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED_NU, 32 MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED_NO, 33 MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED_NU_NO, 34 MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON, 35 MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON_NU, 36 MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON_NO, 37 MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON_NU_NO, 38 }; 39 40 //===----------------------------------------------------------------------===// 41 // SparseTensorEncodingAttr 42 //===----------------------------------------------------------------------===// 43 44 /// Checks whether the given attribute is a sparse_tensor.encoding attribute. 45 MLIR_CAPI_EXPORTED bool 46 mlirAttributeIsASparseTensorEncodingAttr(MlirAttribute attr); 47 48 /// Creates a sparse_tensor.encoding attribute with the given parameters. 49 MLIR_CAPI_EXPORTED MlirAttribute mlirSparseTensorEncodingAttrGet( 50 MlirContext ctx, intptr_t numDimLevelTypes, 51 enum MlirSparseTensorDimLevelType const *dimLevelTypes, 52 MlirAffineMap dimOrdering, MlirAffineMap higherOrdering, 53 int pointerBitWidth, int indexBitWidth); 54 55 /// Returns the number of dim level types in a sparse_tensor.encoding attribute. 56 MLIR_CAPI_EXPORTED intptr_t 57 mlirSparseTensorEncodingGetNumDimLevelTypes(MlirAttribute attr); 58 59 /// Returns a specified dim level type in a sparse_tensor.encoding attribute. 60 MLIR_CAPI_EXPORTED enum MlirSparseTensorDimLevelType 61 mlirSparseTensorEncodingAttrGetDimLevelType(MlirAttribute attr, intptr_t pos); 62 63 /// Returns the dimension ordering in a sparse_tensor.encoding attribute. 64 MLIR_CAPI_EXPORTED MlirAffineMap 65 mlirSparseTensorEncodingAttrGetDimOrdering(MlirAttribute attr); 66 67 /// Returns the higher ordering in a sparse_tensor.encoding attribute. 68 MLIR_CAPI_EXPORTED MlirAffineMap 69 mlirSparseTensorEncodingAttrGetHigherOrdering(MlirAttribute attr); 70 71 /// Returns the pointer bit width in a sparse_tensor.encoding attribute. 72 MLIR_CAPI_EXPORTED int 73 mlirSparseTensorEncodingAttrGetPointerBitWidth(MlirAttribute attr); 74 75 /// Returns the index bit width in a sparse_tensor.encoding attribute. 76 MLIR_CAPI_EXPORTED int 77 mlirSparseTensorEncodingAttrGetIndexBitWidth(MlirAttribute attr); 78 79 #ifdef __cplusplus 80 } 81 #endif 82 83 #include "mlir/Dialect/SparseTensor/Transforms/Passes.capi.h.inc" 84 85 #endif // MLIR_C_DIALECT_SPARSETENSOR_H 86