The old "pointer/index" names often cause confusion since these names clash with names of unrelated things in MLIR; so this change rectifies this by changing everything to use "position/coordinate" terminology instead.
In addition to the basic terminology, there have also been various conventions for making certain distinctions like: (1) the overall storage for coordinates in the sparse-tensor, vs the particular collection of coordinates of a given element; and (2) particular coordinates given as a `Value` or `TypedValue<MemRefType>`, vs particular coordinates given as `ValueRange` or similar. I have striven to maintain these distinctions
as follows:
* "p/c" are used for individual position/coordinate values, when there is no risk of confusion. (Just like we use "d/l" to abbreviate "dim/lvl".)
* "pos/crd" are used for individual position/coordinate values, when a longer name is helpful to avoid ambiguity or to form compound names (e.g., "parentPos"). (Just like we use "dim/lvl" when we need a longer form of "d/l".)
I have also used these forms for a handful of compound names where the old name had been using a three-letter form previously, even though a longer form would be more appropriate. I've avoided renaming these to use a longer form purely for expediency sake, since changing them would require a cascade of other renamings. They should be updated to follow the new naming scheme, but that can be done in future patches.
* "coords" is used for the complete collection of crd values associated with a single element. In the runtime library this includes both `std::vector` and raw pointer representations. In the compiler, this is used specifically for buffer variables with C++ type `Value`, `TypedValue<MemRefType>`, etc.
The bare form "coords" is discouraged, since it fails to make the dim/lvl distinction; so the compound names "dimCoords/lvlCoords" should be used instead. (Though there may exist a rare few cases where is is appropriate to be intentionally ambiguous about what coordinate-space the coords live in; in which case the bare "coords" is appropriate.)
There is seldom the need for the pos variant of this notion. In most circumstances we use the term "cursor", since the same buffer is reused for a 'moving' pos-collection.
* "dcvs/lcvs" is used in the compiler as the `ValueRange` analogue of "dimCoords/lvlCoords". (The "vs" stands for "`Value`s".) I haven't found the need for it, but "pvs" would be the obvious name for a pos-`ValueRange`.
The old "ind"-vs-"ivs" naming scheme does not seem to have been sustained in more recent code, which instead prefers other mnemonics (e.g., adding "Buf" to the end of the names for `TypeValue<MemRefType>`). I have cleaned up a lot of these to follow the "coords"-vs-"cvs" naming scheme, though haven't done an exhaustive cleanup.
* "positions/coordinates" are used for larger collections of pos/crd values; in particular, these are used when referring to the complete sparse-tensor storage components.
I also prefer to use these unabbreviated names in the documentation, unless there is some specific reason why using the abbreviated forms helps resolve ambiguity.
In addition to making this terminology change, this change also does some cleanup along the way:
* correcting the dim/lvl terminology in certain places.
* adding `const` when it requires no other code changes.
* miscellaneous cleanup that was entailed in order to make the proper distinctions. Most of these are in CodegenUtils.{h,cpp}
Reviewed By: aartbik
Differential Revision: https://reviews.llvm.org/D144773
86 lines
3.4 KiB
C
86 lines
3.4 KiB
C
//===-- mlir-c/Dialect/SparseTensor.h - C API for SparseTensor ----*- C -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM
|
|
// Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef MLIR_C_DIALECT_SPARSETENSOR_H
|
|
#define MLIR_C_DIALECT_SPARSETENSOR_H
|
|
|
|
#include "mlir-c/AffineMap.h"
|
|
#include "mlir-c/IR.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(SparseTensor, sparse_tensor);
|
|
|
|
/// Dimension level types (and properties) that define sparse tensors.
|
|
/// See the documentation in SparseTensorAttrDefs.td for their meaning.
|
|
///
|
|
/// These correspond to SparseTensorEncodingAttr::DimLevelType in the C++ API.
|
|
/// If updating, keep them in sync and update the static_assert in the impl
|
|
/// file.
|
|
enum MlirSparseTensorDimLevelType {
|
|
MLIR_SPARSE_TENSOR_DIM_LEVEL_DENSE = 4, // 0b001_00
|
|
MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED = 8, // 0b010_00
|
|
MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED_NU = 9, // 0b010_01
|
|
MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED_NO = 10, // 0b010_10
|
|
MLIR_SPARSE_TENSOR_DIM_LEVEL_COMPRESSED_NU_NO = 11, // 0b010_11
|
|
MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON = 16, // 0b100_00
|
|
MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON_NU = 17, // 0b100_01
|
|
MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON_NO = 18, // 0b100_10
|
|
MLIR_SPARSE_TENSOR_DIM_LEVEL_SINGLETON_NU_NO = 19, // 0b100_11
|
|
};
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// SparseTensorEncodingAttr
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// Checks whether the given attribute is a `sparse_tensor.encoding` attribute.
|
|
MLIR_CAPI_EXPORTED bool
|
|
mlirAttributeIsASparseTensorEncodingAttr(MlirAttribute attr);
|
|
|
|
/// Creates a `sparse_tensor.encoding` attribute with the given parameters.
|
|
MLIR_CAPI_EXPORTED MlirAttribute mlirSparseTensorEncodingAttrGet(
|
|
MlirContext ctx, intptr_t lvlRank,
|
|
enum MlirSparseTensorDimLevelType const *dimLevelTypes,
|
|
MlirAffineMap dimOrdering, MlirAffineMap higherOrdering, int posWidth,
|
|
int crdWidth);
|
|
|
|
/// Returns the level-rank of the `sparse_tensor.encoding` attribute.
|
|
MLIR_CAPI_EXPORTED intptr_t
|
|
mlirSparseTensorEncodingGetLvlRank(MlirAttribute attr);
|
|
|
|
/// Returns a specified level-type of the `sparse_tensor.encoding` attribute.
|
|
MLIR_CAPI_EXPORTED enum MlirSparseTensorDimLevelType
|
|
mlirSparseTensorEncodingAttrGetDimLevelType(MlirAttribute attr, intptr_t lvl);
|
|
|
|
/// Returns the dimension-ordering of the `sparse_tensor.encoding` attribute.
|
|
MLIR_CAPI_EXPORTED MlirAffineMap
|
|
mlirSparseTensorEncodingAttrGetDimOrdering(MlirAttribute attr);
|
|
|
|
/// Returns the higher-ordering of the `sparse_tensor.encoding` attribute.
|
|
MLIR_CAPI_EXPORTED MlirAffineMap
|
|
mlirSparseTensorEncodingAttrGetHigherOrdering(MlirAttribute attr);
|
|
|
|
/// Returns the position bitwidth of the `sparse_tensor.encoding` attribute.
|
|
MLIR_CAPI_EXPORTED int
|
|
mlirSparseTensorEncodingAttrGetPosWidth(MlirAttribute attr);
|
|
|
|
/// Returns the coordinate bitwidth of the `sparse_tensor.encoding` attribute.
|
|
MLIR_CAPI_EXPORTED int
|
|
mlirSparseTensorEncodingAttrGetCrdWidth(MlirAttribute attr);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#include "mlir/Dialect/SparseTensor/Transforms/Passes.capi.h.inc"
|
|
|
|
#endif // MLIR_C_DIALECT_SPARSETENSOR_H
|