//===- SparseTensorDescriptor.h ---------------------------------*- 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 // //===----------------------------------------------------------------------===// // // This header file defines utilities for the sparse memory layout. // //===----------------------------------------------------------------------===// #ifndef MLIR_DIALECT_SPARSETENSOR_TRANSFORMS_UTILS_SPARSETENSORDESCRIPTOR_H_ #define MLIR_DIALECT_SPARSETENSOR_TRANSFORMS_UTILS_SPARSETENSORDESCRIPTOR_H_ #include "mlir/Dialect/SparseTensor/IR/SparseTensor.h" #include "mlir/Dialect/SparseTensor/IR/SparseTensorStorageLayout.h" #include "mlir/Dialect/SparseTensor/IR/SparseTensorType.h" #include "mlir/Dialect/SparseTensor/Transforms/Passes.h" namespace mlir { namespace sparse_tensor { class SparseTensorSpecifier { … }; /// A helper class around an array of values that corresponds to a sparse /// tensor. This class provides a set of meaningful APIs to query and update /// a particular field in a consistent way. Users should not make assumptions /// on how a sparse tensor is laid out but instead rely on this class to access /// the right value for the right field. template <typename ValueArrayRef> class SparseTensorDescriptorImpl { … }; /// Uses ValueRange for immutable descriptors. class SparseTensorDescriptor : public SparseTensorDescriptorImpl<ValueRange> { … }; /// Using SmallVector for mutable descriptor allows users to reuse it as a /// tmp buffers to append value for some special cases, though users should /// be responsible to restore the buffer to legal states after their use. It /// is probably not a clean way, but it is the most efficient way to avoid /// copying the fields into another SmallVector. If a more clear way is /// wanted, we should change it to MutableArrayRef instead. class MutSparseTensorDescriptor : public SparseTensorDescriptorImpl<SmallVectorImpl<Value> &> { … }; /// Returns the "tuple" value of the adapted tensor. inline UnrealizedConversionCastOp getTuple(Value tensor) { … } /// Packs the given values as a "tuple" value. inline Value genTuple(OpBuilder &builder, Location loc, Type tp, ValueRange values) { … } inline Value genTuple(OpBuilder &builder, Location loc, SparseTensorDescriptor desc) { … } inline SparseTensorDescriptor getDescriptorFromTensorTuple(Value tensor) { … } inline MutSparseTensorDescriptor getMutDescriptorFromTensorTuple(Value tensor, SmallVectorImpl<Value> &fields) { … } } // namespace sparse_tensor } // namespace mlir #endif // MLIR_DIALECT_SPARSETENSOR_TRANSFORMS_UTILS_SPARSETENSODESCRIPTOR_H_