brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.3 KiB · c816c1b Raw
117 lines · c
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 LLVM4// Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef MLIR_C_DIALECT_SPARSETENSOR_H11#define MLIR_C_DIALECT_SPARSETENSOR_H12 13#include "mlir-c/AffineMap.h"14#include "mlir-c/IR.h"15 16#ifdef __cplusplus17extern "C" {18#endif19 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 impl27/// 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// SparseTensorEncodingAttr47//===----------------------------------------------------------------------===//48 49/// Checks whether the given attribute is a `sparse_tensor.encoding` attribute.50MLIR_CAPI_EXPORTED bool51mlirAttributeIsASparseTensorEncodingAttr(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_t62mlirSparseTensorEncodingGetLvlRank(MlirAttribute attr);63 64/// Returns a specified level-type of the `sparse_tensor.encoding` attribute.65MLIR_CAPI_EXPORTED MlirSparseTensorLevelType66mlirSparseTensorEncodingAttrGetLvlType(MlirAttribute attr, intptr_t lvl);67 68/// Returns a specified level-format of the `sparse_tensor.encoding` attribute.69MLIR_CAPI_EXPORTED enum MlirSparseTensorLevelFormat70mlirSparseTensorEncodingAttrGetLvlFmt(MlirAttribute attr, intptr_t lvl);71 72/// Returns the dimension-to-level mapping of the `sparse_tensor.encoding`73/// attribute.74MLIR_CAPI_EXPORTED MlirAffineMap75mlirSparseTensorEncodingAttrGetDimToLvl(MlirAttribute attr);76 77/// Returns the level-to-dimension mapping of the `sparse_tensor.encoding`78/// attribute.79MLIR_CAPI_EXPORTED MlirAffineMap80mlirSparseTensorEncodingAttrGetLvlToDim(MlirAttribute attr);81 82/// Returns the position bitwidth of the `sparse_tensor.encoding` attribute.83MLIR_CAPI_EXPORTED int84mlirSparseTensorEncodingAttrGetPosWidth(MlirAttribute attr);85 86/// Returns the coordinate bitwidth of the `sparse_tensor.encoding` attribute.87MLIR_CAPI_EXPORTED int88mlirSparseTensorEncodingAttrGetCrdWidth(MlirAttribute attr);89 90/// Returns the explicit value of the `sparse_tensor.encoding` attribute.91MLIR_CAPI_EXPORTED MlirAttribute92mlirSparseTensorEncodingAttrGetExplicitVal(MlirAttribute attr);93 94/// Returns the implicit value of the `sparse_tensor.encoding` attribute.95MLIR_CAPI_EXPORTED MlirAttribute96mlirSparseTensorEncodingAttrGetImplicitVal(MlirAttribute attr);97 98MLIR_CAPI_EXPORTED unsigned99mlirSparseTensorEncodingAttrGetStructuredN(MlirSparseTensorLevelType lvlType);100 101MLIR_CAPI_EXPORTED unsigned102mlirSparseTensorEncodingAttrGetStructuredM(MlirSparseTensorLevelType lvlType);103 104MLIR_CAPI_EXPORTED MlirSparseTensorLevelType105mlirSparseTensorEncodingAttrBuildLvlType(106    enum MlirSparseTensorLevelFormat lvlFmt,107    const enum MlirSparseTensorLevelPropertyNondefault *properties,108    unsigned propSize, unsigned n, unsigned m);109 110#ifdef __cplusplus111}112#endif113 114#include "mlir/Dialect/SparseTensor/Transforms/Passes.capi.h.inc"115 116#endif // MLIR_C_DIALECT_SPARSETENSOR_H117