diff --git a/mlir/include/mlir/ExecutionEngine/SparseTensor/Enums.h b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h rename from mlir/include/mlir/ExecutionEngine/SparseTensor/Enums.h rename to mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h --- a/mlir/include/mlir/ExecutionEngine/SparseTensor/Enums.h +++ b/mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h @@ -6,25 +6,27 @@ // //===----------------------------------------------------------------------===// // -// Typedefs and enums for the lightweight runtime support library for -// sparse tensor manipulations. These are required to be public so that -// they can be shared with `Transforms/SparseTensorConversion.cpp`, since -// they define the arguments to the public functions declared later on. +// Typedefs and enums shared between MLIR code for manipulating the +// IR, and the lightweight runtime support library for sparse tensor +// manipulations. That is, all the enums are used to define the API +// of the runtime library and hence are also needed when generating +// calls into the runtime library. Moveover, the `DimLevelType` enum +// is also used as the internal IR encoding of dimension level types, +// to avoid code duplication (e.g., for the predicates). // // This file also defines x-macros // so that we can generate variations of the public functions for each // supported primary- and/or overhead-type. // -// This file is part of the lightweight runtime support library for sparse -// tensor manipulations. The functionality of the support library is meant -// to simplify benchmarking, testing, and debugging MLIR code operating on -// sparse tensors. However, the provided functionality is **not** part of -// core MLIR itself. +// Because this file defines a library which is a dependency of the +// runtime library itself, this file must not depend on any MLIR internals +// (e.g., operators, attributes, ArrayRefs, etc) lest the runtime library +// inherit those dependencies. // //===----------------------------------------------------------------------===// -#ifndef MLIR_EXECUTIONENGINE_SPARSETENSOR_ENUMS_H -#define MLIR_EXECUTIONENGINE_SPARSETENSOR_ENUMS_H +#ifndef MLIR_DIALECT_SPARSETENSOR_IR_ENUMS_H +#define MLIR_DIALECT_SPARSETENSOR_IR_ENUMS_H #include "mlir/ExecutionEngine/Float16bits.h" @@ -127,9 +129,14 @@ kToIterator = 6, }; -/// This enum mimics `SparseTensorEncodingAttr::DimLevelType` for -/// breaking dependency cycles. `SparseTensorEncodingAttr::DimLevelType` -/// is the source of truth and this enum should be kept consistent with it. +/// This enum defines all the sparse representations supportable by +/// the SparseTensor dialect. We use a lightweight encoding to encode +/// both the "format" per se (dense, compressed, singleton) as well as +/// the "properties" (ordered, unique). The encoding is chosen for +/// performance of the runtime library, and thus may change in future +/// versions; consequently, client code should use the predicate functions +/// defined below, rather than relying on knowledge about the particular +/// binary encoding. enum class DimLevelType : uint8_t { Dense = 4, // 0b001_00 Compressed = 8, // 0b010_00 @@ -217,4 +224,4 @@ } // namespace sparse_tensor } // namespace mlir -#endif // MLIR_EXECUTIONENGINE_SPARSETENSOR_ENUMS_H +#endif // MLIR_DIALECT_SPARSETENSOR_IR_ENUMS_H diff --git a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensor.h b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensor.h --- a/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensor.h +++ b/mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensor.h @@ -9,7 +9,7 @@ #ifndef MLIR_DIALECT_SPARSETENSOR_IR_SPARSETENSOR_H_ #define MLIR_DIALECT_SPARSETENSOR_IR_SPARSETENSOR_H_ -#include "mlir/ExecutionEngine/SparseTensor/Enums.h" +#include "mlir/Dialect/SparseTensor/IR/Enums.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Dialect.h" #include "mlir/IR/OpDefinition.h" diff --git a/mlir/include/mlir/ExecutionEngine/SparseTensor/Storage.h b/mlir/include/mlir/ExecutionEngine/SparseTensor/Storage.h --- a/mlir/include/mlir/ExecutionEngine/SparseTensor/Storage.h +++ b/mlir/include/mlir/ExecutionEngine/SparseTensor/Storage.h @@ -35,7 +35,7 @@ #include "mlir/ExecutionEngine/SparseTensor/COO.h" #include "mlir/ExecutionEngine/SparseTensor/CheckedMul.h" -#include "mlir/ExecutionEngine/SparseTensor/Enums.h" +#include "mlir/Dialect/SparseTensor/IR/Enums.h" #include "mlir/ExecutionEngine/SparseTensor/ErrorHandling.h" namespace mlir { diff --git a/mlir/include/mlir/ExecutionEngine/SparseTensorRuntime.h b/mlir/include/mlir/ExecutionEngine/SparseTensorRuntime.h --- a/mlir/include/mlir/ExecutionEngine/SparseTensorRuntime.h +++ b/mlir/include/mlir/ExecutionEngine/SparseTensorRuntime.h @@ -16,7 +16,7 @@ #define MLIR_EXECUTIONENGINE_SPARSETENSORRUNTIME_H #include "mlir/ExecutionEngine/CRunnerUtils.h" -#include "mlir/ExecutionEngine/SparseTensor/Enums.h" +#include "mlir/Dialect/SparseTensor/IR/Enums.h" #include #include diff --git a/mlir/lib/Dialect/SparseTensor/IR/CMakeLists.txt b/mlir/lib/Dialect/SparseTensor/IR/CMakeLists.txt --- a/mlir/lib/Dialect/SparseTensor/IR/CMakeLists.txt +++ b/mlir/lib/Dialect/SparseTensor/IR/CMakeLists.txt @@ -1,3 +1,17 @@ +# This library is shared by both MLIRSparseTensorDialect and +# MLIRSparseTensorRuntime, so it must not depend on any of the MLIR/LLVM +# internals or else mlir_c_runner_utils will inherit that dependency. +add_mlir_library(MLIRSparseTensorEnums + # TODO: how to list the single header in this library? + ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/SparseTensor/IR/Enums.h + + EXCLUDE_FROM_LIBMLIR + + LINK_LIBS PUBLIC + mlir_float16_utils + ) +set_property(TARGET MLIRSparseTensorRuntime PROPERTY CXX_STANDARD 17) + add_mlir_dialect_library(MLIRSparseTensorDialect SparseTensorDialect.cpp diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h --- a/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h +++ b/mlir/lib/Dialect/SparseTensor/Transforms/CodegenUtils.h @@ -19,7 +19,7 @@ #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/SparseTensor/IR/SparseTensor.h" #include "mlir/Dialect/Utils/ReshapeOpsUtils.h" -#include "mlir/ExecutionEngine/SparseTensor/Enums.h" +#include "mlir/Dialect/SparseTensor/IR/Enums.h" #include "mlir/IR/Builders.h" namespace mlir { diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp --- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp +++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorConversion.cpp @@ -26,7 +26,7 @@ #include "mlir/Dialect/SparseTensor/IR/SparseTensor.h" #include "mlir/Dialect/SparseTensor/Transforms/Passes.h" #include "mlir/Dialect/Tensor/IR/Tensor.h" -#include "mlir/ExecutionEngine/SparseTensor/Enums.h" +#include "mlir/Dialect/SparseTensor/IR/Enums.h" #include "mlir/Transforms/DialectConversion.h" using namespace mlir; diff --git a/mlir/lib/ExecutionEngine/SparseTensor/CMakeLists.txt b/mlir/lib/ExecutionEngine/SparseTensor/CMakeLists.txt --- a/mlir/lib/ExecutionEngine/SparseTensor/CMakeLists.txt +++ b/mlir/lib/ExecutionEngine/SparseTensor/CMakeLists.txt @@ -1,17 +1,3 @@ -# This library is shared by both SparseTensorDialect and -# SparseTensorRuntime, so it must not depend on any of the MLIR/LLVM -# internals or else mlir_c_runner_utils will inherit that dependency. -add_mlir_library(MLIRSparseTensorEnums - # TODO: how to list the single header in this library? - ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine/SparseTensor/Enums.h - - EXCLUDE_FROM_LIBMLIR - - LINK_LIBS PUBLIC - mlir_float16_utils - ) -set_property(TARGET MLIRSparseTensorRuntime PROPERTY CXX_STANDARD 17) - # Unlike mlir_float16_utils, mlir_c_runner_utils, etc, we do *not* make # this a shared library: because doing so causes issues when building # on Windows. In particular, various functions take/return `std::vector` diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel @@ -2073,7 +2073,7 @@ cc_library( name = "SparseTensorEnums", srcs = [], - hdrs = ["include/mlir/ExecutionEngine/SparseTensor/Enums.h"], + hdrs = ["include/mlir/Dialect/SparseTensor/IR/Enums.h"], includes = ["include"], deps = [":mlir_float16_utils"], )