[mlir][bufferization] Make `TensorCopyInsertionPass` a test pass

TensorCopyInsertion should not have been exposed as a pass. This was a flaw in the original design. It is a preparation step for bufferization and certain transforms (that would otherwise be legal) are illegal between TensorCopyInsertion and actual rewrite to MemRef ops. Therefore, even if broken down as two separate steps internally, they should be exposed as a single pass.

This change affects the sparse compiler, which uses `TensorCopyInsertionPass`. A new `SparsificationAndBufferizationPass` is added to replace all passes in the sparse tensor pipeline from `TensorCopyInsertionPass` until the actual bufferization (rewrite to memref/non-tensor). It is generally unsafe to run arbitrary passes in-between, in particular passes that hoist tensor ops out of loops or change SSA use-def chains along tensor ops.

Differential Revision: https://reviews.llvm.org/D138915
This commit is contained in:
Matthias Springer 2022-12-02 11:46:14 +01:00
parent 5fc071f2b4
commit c1fef4e88a
22 changed files with 286 additions and 184 deletions

View File

@ -97,11 +97,6 @@ std::unique_ptr<Pass> createEmptyTensorEliminationPass();
/// Create a pass that bufferizes ops from the bufferization dialect.
std::unique_ptr<Pass> createBufferizationBufferizePass();
/// Create a pass that resolves out-of-place tensor OpOperands with copies.
std::unique_ptr<Pass> createTensorCopyInsertionPass();
std::unique_ptr<Pass>
createTensorCopyInsertionPass(const OneShotBufferizationOptions &options);
//===----------------------------------------------------------------------===//
// Registration
//===----------------------------------------------------------------------===//

View File

@ -340,37 +340,6 @@ def PromoteBuffersToStack : Pass<"promote-buffers-to-stack", "func::FuncOp"> {
];
}
def TensorCopyInsertion : Pass<"tensor-copy-insertion"> {
let summary = "Make all tensor IR inplaceable by inserting copies";
let description = [{
This pass runs One-Shot Analysis and inserts copies for all OpOperands that
were decided to bufferize out-of-place. After running this pass, a
bufferization can write to buffers directly (without making copies) and no
longer has to care about potential read-after-write conflicts.
Note: By default, all newly inserted tensor copies/allocs (i.e., newly
created `bufferization.alloc_tensor` ops) that do not escape block are
annotated with `escape = false`. If `create-allocs` is unset, all newly
inserted tensor copies/allocs are annotated with `escape = true`. In that
case, they are not getting deallocated when bufferizing the IR.
}];
let options = [
Option<"allowReturnAllocs", "allow-return-allocs", "bool",
/*default=*/"false",
"Allows returning/yielding new allocations from a block.">,
Option<"bufferizeFunctionBoundaries", "bufferize-function-boundaries",
"bool", /*default=*/"0",
"Bufferize function boundaries (experimental).">,
Option<"createDeallocs", "create-deallocs", "bool", /*default=*/"true",
"Specify if new allocations should be deallocated.">,
Option<"mustInferMemorySpace", "must-infer-memory-space", "bool",
/*default=*/"false",
"The memory space of an memref types must always be inferred. If "
"unset, a default memory space of 0 is used otherwise.">,
];
let constructor = "mlir::bufferization::createTensorCopyInsertionPass()";
}
def EmptyTensorElimination : Pass<"eliminate-empty-tensors"> {
let summary = "Try to eliminate all tensor.empty ops.";
let description = [{

View File

@ -162,8 +162,11 @@ createPostSparsificationRewritePass(bool enableRT, bool enableForeach = true,
// Other rewriting rules and passes.
//===----------------------------------------------------------------------===//
std::unique_ptr<Pass> createDenseBufferizationPass(
const bufferization::OneShotBufferizationOptions &options);
std::unique_ptr<Pass> createSparsificationAndBufferizationPass(
const bufferization::OneShotBufferizationOptions &bufferizationOptions,
const SparsificationOptions &sparsificationOptions,
const SparseTensorConversionOptions &sparseTensorConversionOptions,
bool enableRuntimeLibrary, bool enableBufferInitialization);
void populateSparseBufferRewriting(RewritePatternSet &patterns,
bool enableBufferInitialization);

View File

@ -161,45 +161,3 @@ mlir::bufferization::insertTensorCopies(Operation *op,
return failure(result.wasInterrupted());
}
namespace {
struct TensorCopyInsertionPass
: public bufferization::impl::TensorCopyInsertionBase<
TensorCopyInsertionPass> {
TensorCopyInsertionPass() : options(llvm::None) {}
TensorCopyInsertionPass(const OneShotBufferizationOptions &options)
: options(options) {}
void getDependentDialects(DialectRegistry &registry) const override {
registry.insert<bufferization::BufferizationDialect>();
}
void runOnOperation() override {
if (options) {
if (failed(insertTensorCopies(getOperation(), *options)))
signalPassFailure();
} else {
OneShotBufferizationOptions options;
options.allowReturnAllocs = allowReturnAllocs;
options.bufferizeFunctionBoundaries = bufferizeFunctionBoundaries;
options.createDeallocs = createDeallocs;
if (mustInferMemorySpace)
options.defaultMemorySpace = None;
if (failed(insertTensorCopies(getOperation(), options)))
signalPassFailure();
}
}
private:
Optional<OneShotBufferizationOptions> options;
};
} // namespace
std::unique_ptr<Pass> mlir::bufferization::createTensorCopyInsertionPass() {
return std::make_unique<TensorCopyInsertionPass>();
}
std::unique_ptr<Pass> mlir::bufferization::createTensorCopyInsertionPass(
const OneShotBufferizationOptions &options) {
return std::make_unique<TensorCopyInsertionPass>(options);
}

View File

@ -52,25 +52,12 @@ getBufferizationOptions(bool analysisOnly) {
void mlir::sparse_tensor::buildSparseCompiler(
OpPassManager &pm, const SparseCompilerOptions &options) {
pm.addNestedPass<func::FuncOp>(createLinalgGeneralizationPass());
pm.addPass(
bufferization::createTensorCopyInsertionPass(getBufferizationOptions(
/*analysisOnly=*/options.testBufferizationAnalysisOnly)));
pm.addPass(createSparsificationAndBufferizationPass(
getBufferizationOptions(options.testBufferizationAnalysisOnly),
options.sparsificationOptions(), options.sparseTensorConversionOptions(),
options.enableRuntimeLibrary, options.enableBufferInitialization));
if (options.testBufferizationAnalysisOnly)
return;
pm.addPass(createPreSparsificationRewritePass());
pm.addPass(createSparsificationPass(options.sparsificationOptions()));
pm.addPass(createPostSparsificationRewritePass(options.enableRuntimeLibrary));
if (options.enableRuntimeLibrary) {
pm.addPass(createSparseTensorConversionPass(
options.sparseTensorConversionOptions()));
} else {
pm.addPass(
createSparseTensorCodegenPass(options.enableBufferInitialization));
pm.addPass(
createSparseBufferRewritePass(options.enableBufferInitialization));
}
pm.addPass(createDenseBufferizationPass(
getBufferizationOptions(/*analysisOnly=*/false)));
pm.addNestedPass<func::FuncOp>(createCanonicalizerPass());
pm.addNestedPass<func::FuncOp>(
mlir::bufferization::createFinalizingBufferizePass());

View File

@ -1,14 +1,14 @@
add_mlir_dialect_library(MLIRSparseTensorTransforms
BufferizableOpInterfaceImpl.cpp
CodegenUtils.cpp
DenseBufferizationPass.cpp
Sparsification.cpp
SparseBufferRewriting.cpp
SparseTensorCodegen.cpp
SparseTensorConversion.cpp
SparseTensorPasses.cpp
SparseTensorRewriting.cpp
SparseVectorization.cpp
Sparsification.cpp
SparsificationAndBufferizationPass.cpp
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/SparseTensor

View File

@ -1,73 +0,0 @@
//===- DenseBufferizationPass.cpp - Dense bufferization pass --------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/SparseTensor/Transforms/Passes.h"
#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
#include "mlir/Dialect/Bufferization/Transforms/Bufferize.h"
#include "mlir/Dialect/Bufferization/Transforms/OneShotAnalysis.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/SparseTensor/IR/SparseTensor.h"
using namespace mlir;
using namespace mlir::func;
namespace mlir {
namespace sparse_tensor {
/// Return `true` if one of the given types is a sparse tensor type.
static bool containsSparseTensor(TypeRange types) {
for (Type t : types)
if (getSparseTensorEncoding(t))
return true;
return false;
}
/// A pass that bufferizes only dense tensor ops and ignores all sparse tensor
/// ops. No buffer copies are inserted. All tensor OpOperands must be
/// inplacable.
class BufferizeDenseOpsPass
: public PassWrapper<BufferizeDenseOpsPass, OperationPass<ModuleOp>> {
public:
BufferizeDenseOpsPass(
const bufferization::OneShotBufferizationOptions &options)
: options(options) {}
void runOnOperation() override {
// Disallow all sparse tensor ops, so that only dense tensor ops are
// bufferized.
bufferization::OpFilter opFilter;
opFilter.allowOperation([&](Operation *op) {
if (containsSparseTensor(TypeRange(op->getResults())) ||
containsSparseTensor(TypeRange(op->getOperands())))
return false;
if (auto funcOp = dyn_cast<func::FuncOp>(op)) {
FunctionType funcType = funcOp.getFunctionType();
if (containsSparseTensor(funcType.getInputs()) ||
containsSparseTensor(funcType.getResults()))
return false;
}
return true;
});
if (failed(bufferization::bufferizeOp(getOperation(), options,
/*copyBeforeWrite=*/false,
&opFilter)))
signalPassFailure();
}
private:
bufferization::OneShotBufferizationOptions options;
};
} // namespace sparse_tensor
} // namespace mlir
std::unique_ptr<Pass> mlir::createDenseBufferizationPass(
const bufferization::OneShotBufferizationOptions &options) {
return std::make_unique<mlir::sparse_tensor::BufferizeDenseOpsPass>(options);
}

View File

@ -0,0 +1,155 @@
//===- SparsificationAndBufferizationPass.cpp - Tensor to Memref Lowering -===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/SparseTensor/Transforms/Passes.h"
#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
#include "mlir/Dialect/Bufferization/Transforms/Bufferize.h"
#include "mlir/Dialect/Bufferization/Transforms/OneShotAnalysis.h"
#include "mlir/Dialect/Bufferization/Transforms/Transforms.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/SparseTensor/IR/SparseTensor.h"
#include "mlir/Dialect/SparseTensor/Transforms/Passes.h"
#include "mlir/Pass/PassManager.h"
using namespace mlir;
using namespace mlir::func;
namespace mlir {
namespace sparse_tensor {
/// Return `true` if one of the given types is a sparse tensor type.
static bool containsSparseTensor(TypeRange types) {
for (Type t : types)
if (getSparseTensorEncoding(t))
return true;
return false;
}
/// A pass that lowers tensor ops to memref ops, regardless of whether they are
/// dense or sparse.
///
/// One-Shot Analysis is used to detect RaW conflicts and to insert buffer
/// copies of the tensor level (`insertTensorCopies`). Afterwards, the lowering
/// of tensor ops to memref ops follows a different code path depending on
/// whether the op is sparse or dense:
///
/// * Sparse tensor ops are lowered through Sparsification and follow-up pass
/// that lowers sparse_tensor dialect ops.
/// * Dense tensor ops are lowered through BufferizableOpInterface
/// implementations.
class SparsificationAndBufferizationPass
: public PassWrapper<SparsificationAndBufferizationPass,
OperationPass<ModuleOp>> {
public:
SparsificationAndBufferizationPass(
const bufferization::OneShotBufferizationOptions &bufferizationOptions,
const SparsificationOptions &sparsificationOptions,
const SparseTensorConversionOptions &sparseTensorConversionOptions,
bool enableRuntimeLibrary, bool enableBufferInitialization)
: bufferizationOptions(bufferizationOptions),
sparsificationOptions(sparsificationOptions),
sparseTensorConversionOptions(sparseTensorConversionOptions),
enableRuntimeLibrary(enableRuntimeLibrary),
enableBufferInitialization(enableBufferInitialization) {}
/// Bufferize all dense ops. This assumes that no further analysis is needed
/// and that all required buffer copies were already inserted by
/// `insertTensorCopies` in the form of `bufferization.alloc_tensor` ops.
LogicalResult runDenseBufferization() {
bufferization::OpFilter denseOpFilter;
denseOpFilter.allowOperation([&](Operation *op) {
if (containsSparseTensor(TypeRange(op->getResults())) ||
containsSparseTensor(TypeRange(op->getOperands())))
return false;
if (auto funcOp = dyn_cast<func::FuncOp>(op)) {
FunctionType funcType = funcOp.getFunctionType();
if (containsSparseTensor(funcType.getInputs()) ||
containsSparseTensor(funcType.getResults()))
return false;
}
return true;
});
return bufferization::bufferizeOp(getOperation(), bufferizationOptions,
/*copyBeforeWrite=*/false,
&denseOpFilter);
}
void runOnOperation() override {
{
// Run enabling transformations.
OpPassManager pm("builtin.module");
pm.addPass(createPreSparsificationRewritePass());
if (failed(runPipeline(pm, getOperation())))
return signalPassFailure();
}
// Insert tensor copies. This step runs One-Shot Analysis (which analyzes
// SSA use-def chains of tensor IR) and decides where buffer copies are
// needed and where buffers can be written to in-place. These decisions are
// materialized in the IR in the form of `bufferization.alloc_tensor` ops.
//
// Note: All following steps in this pass must be careful not to modify the
// structure of the IR (i.e., tensor use-def chains), as that could
// invalidate the results of the analysis. From now on, only small and
// localized rewrites are allowed, such as replacing a tensor op with its
// memref equivalent.
if (failed(bufferization::insertTensorCopies(getOperation(),
bufferizationOptions)))
return signalPassFailure();
// `testAnalysisOnly` is a debug/testing flag. If set, the results of
// OneShotAnalysis are added to the IR via attributes. In that case, do not
// continue with the remaining pipeline.
if (bufferizationOptions.testAnalysisOnly)
return;
// Bufferize all sparse ops. No further analysis is needed. All required
// buffer copies were already inserted by `insertTensorCopies` in the form
// of `bufferization.alloc_tensor` ops.
{
OpPassManager pm("builtin.module");
pm.addPass(createSparsificationPass(sparsificationOptions));
pm.addPass(createPostSparsificationRewritePass(enableRuntimeLibrary));
if (enableRuntimeLibrary) {
pm.addPass(
createSparseTensorConversionPass(sparseTensorConversionOptions));
} else {
pm.addPass(createSparseTensorCodegenPass(enableBufferInitialization));
pm.addPass(createSparseBufferRewritePass(enableBufferInitialization));
}
if (failed(runPipeline(pm, getOperation())))
return signalPassFailure();
}
// Bufferize all dense ops.
if (failed(runDenseBufferization()))
signalPassFailure();
}
private:
bufferization::OneShotBufferizationOptions bufferizationOptions;
SparsificationOptions sparsificationOptions;
SparseTensorConversionOptions sparseTensorConversionOptions;
bool enableRuntimeLibrary;
bool enableBufferInitialization;
};
} // namespace sparse_tensor
} // namespace mlir
std::unique_ptr<Pass> mlir::createSparsificationAndBufferizationPass(
const bufferization::OneShotBufferizationOptions &bufferizationOptions,
const SparsificationOptions &sparsificationOptions,
const SparseTensorConversionOptions &sparseTensorConversionOptions,
bool enableRuntimeLibrary, bool enableBufferInitialization) {
return std::make_unique<
mlir::sparse_tensor::SparsificationAndBufferizationPass>(
bufferizationOptions, sparsificationOptions,
sparseTensorConversionOptions, enableRuntimeLibrary,
enableBufferInitialization);
}

View File

@ -1,4 +1,4 @@
// RUN: mlir-opt %s -tensor-copy-insertion="must-infer-memory-space" -split-input-file -verify-diagnostics
// RUN: mlir-opt %s -test-tensor-copy-insertion="must-infer-memory-space" -split-input-file -verify-diagnostics
// An alloc is inserted but the copy is emitted. Therefore, the memory space
// should be specified on the alloc_tensor op.

View File

@ -1,4 +1,4 @@
// RUN: mlir-opt %s -tensor-copy-insertion="must-infer-memory-space" -split-input-file | FileCheck %s
// RUN: mlir-opt %s -test-tensor-copy-insertion="must-infer-memory-space" -split-input-file | FileCheck %s
// CHECK-LABEL: func @unknown_op_copy
func.func @unknown_op_copy() -> (tensor<10xf32>, tensor<10xf32>) {

View File

@ -1,6 +1,6 @@
// RUN: mlir-opt %s -tensor-copy-insertion -split-input-file | FileCheck %s
// RUN: mlir-opt %s -tensor-copy-insertion="bufferize-function-boundaries allow-return-allocs" -split-input-file | FileCheck %s --check-prefix=CHECK-FUNC
// RUN: mlir-opt %s -tensor-copy-insertion="create-deallocs=0" -split-input-file | FileCheck %s --check-prefix=CHECK-NO-DEALLOC
// RUN: mlir-opt %s -test-tensor-copy-insertion -split-input-file | FileCheck %s
// RUN: mlir-opt %s -test-tensor-copy-insertion="bufferize-function-boundaries allow-return-allocs" -split-input-file | FileCheck %s --check-prefix=CHECK-FUNC
// RUN: mlir-opt %s -test-tensor-copy-insertion="create-deallocs=0" -split-input-file | FileCheck %s --check-prefix=CHECK-NO-DEALLOC
// CHECK-LABEL: func @read_after_write_conflict(
// CHECK-SAME: %[[t:.*]]: tensor<?xf32>

View File

@ -1,5 +1,5 @@
// RUN: mlir-opt %s -tensor-copy-insertion="allow-return-allocs" -allow-unregistered-dialect -split-input-file | FileCheck %s
// RUN: mlir-opt %s -tensor-copy-insertion="bufferize-function-boundaries allow-return-allocs" -split-input-file | FileCheck %s --check-prefix=CHECK-FUNC
// RUN: mlir-opt %s -test-tensor-copy-insertion="allow-return-allocs" -allow-unregistered-dialect -split-input-file | FileCheck %s
// RUN: mlir-opt %s -test-tensor-copy-insertion="bufferize-function-boundaries allow-return-allocs" -split-input-file | FileCheck %s --check-prefix=CHECK-FUNC
// CHECK-LABEL: func @scf_for(
// CHECK-SAME: %[[A:.*]]: tensor<?xf32>, %[[B:.*]]: tensor<?xf32>

View File

@ -1,5 +1,5 @@
// RUN: mlir-opt %s -tensor-copy-insertion="allow-return-allocs" | FileCheck %s
// RUN: mlir-opt %s -tensor-copy-insertion="bufferize-function-boundaries allow-return-allocs" | FileCheck %s --check-prefix=CHECK-FUNC
// RUN: mlir-opt %s -test-tensor-copy-insertion="allow-return-allocs" | FileCheck %s
// RUN: mlir-opt %s -test-tensor-copy-insertion="bufferize-function-boundaries allow-return-allocs" | FileCheck %s --check-prefix=CHECK-FUNC
#DCSR = #sparse_tensor.encoding<{
dimLevelType = [ "compressed", "compressed" ],

View File

@ -1,4 +1,4 @@
// RUN: mlir-opt %s --tensor-copy-insertion --pre-sparsification-rewrite --sparsification --cse | FileCheck %s
// RUN: mlir-opt %s --test-tensor-copy-insertion --pre-sparsification-rewrite --sparsification --cse | FileCheck %s
#SM = #sparse_tensor.encoding<{ dimLevelType = [ "compressed", "compressed" ] }>

View File

@ -1,5 +1,5 @@
// RUN: mlir-opt %s -tensor-copy-insertion -split-input-file | FileCheck %s
// RUN: mlir-opt %s -tensor-copy-insertion="bufferize-function-boundaries allow-return-allocs" -split-input-file | FileCheck %s --check-prefix=CHECK-FUNC
// RUN: mlir-opt %s -test-tensor-copy-insertion -split-input-file | FileCheck %s
// RUN: mlir-opt %s -test-tensor-copy-insertion="bufferize-function-boundaries allow-return-allocs" -split-input-file | FileCheck %s --check-prefix=CHECK-FUNC
// CHECK-LABEL: func @extract_slice(
// CHECK-SAME: %[[t:.*]]: tensor<?xf32>

View File

@ -0,0 +1,12 @@
# Exclude tests from libMLIR.so
add_mlir_library(MLIRBufferizationTestPasses
TestTensorCopyInsertion.cpp
EXCLUDE_FROM_LIBMLIR
LINK_LIBS PUBLIC
MLIRBufferizationDialect
MLIRBufferizationTransforms
MLIRIR
MLIRPass
)

View File

@ -0,0 +1,78 @@
//===- TestTensorCopyInsertion.cpp - Bufferization Analysis -----*- 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
//
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/Bufferization/IR/Bufferization.h"
#include "mlir/Dialect/Bufferization/Transforms/OneShotAnalysis.h"
#include "mlir/Dialect/Bufferization/Transforms/Transforms.h"
#include "mlir/Pass/Pass.h"
using namespace mlir;
namespace {
/// This pass runs One-Shot Analysis and inserts copies for all OpOperands that
/// were decided to bufferize out-of-place. After running this pass, a
/// bufferization can write to buffers directly (without making copies) and no
/// longer has to care about potential read-after-write conflicts.
///
/// Note: By default, all newly inserted tensor copies/allocs (i.e., newly
/// created `bufferization.alloc_tensor` ops) that do not escape block are
/// annotated with `escape = false`. If `create-allocs` is unset, all newly
/// inserted tensor copies/allocs are annotated with `escape = true`. In that
/// case, they are not getting deallocated when bufferizing the IR.
struct TestTensorCopyInsertionPass
: public PassWrapper<TestTensorCopyInsertionPass, OperationPass<ModuleOp>> {
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestTensorCopyInsertionPass)
TestTensorCopyInsertionPass() = default;
TestTensorCopyInsertionPass(const TestTensorCopyInsertionPass &pass)
: PassWrapper(pass) {}
void getDependentDialects(DialectRegistry &registry) const override {
registry.insert<bufferization::BufferizationDialect>();
}
StringRef getArgument() const final { return "test-tensor-copy-insertion"; }
StringRef getDescription() const final {
return "Module pass to test Tensor Copy Insertion";
}
void runOnOperation() override {
bufferization::OneShotBufferizationOptions options;
options.allowReturnAllocs = allowReturnAllocs;
options.bufferizeFunctionBoundaries = bufferizeFunctionBoundaries;
options.createDeallocs = createDeallocs;
if (mustInferMemorySpace)
options.defaultMemorySpace = None;
if (failed(bufferization::insertTensorCopies(getOperation(), options)))
signalPassFailure();
}
Option<bool> allowReturnAllocs{
*this, "allow-return-allocs",
llvm::cl::desc("Allows returning/yielding new allocations from a block."),
llvm::cl::init(false)};
Option<bool> bufferizeFunctionBoundaries{
*this, "bufferize-function-boundaries",
llvm::cl::desc("Bufferize function boundaries."), llvm::cl::init(false)};
Option<bool> createDeallocs{
*this, "create-deallocs",
llvm::cl::desc("Specify if new allocations should be deallocated."),
llvm::cl::init(true)};
Option<bool> mustInferMemorySpace{
*this, "must-infer-memory-space",
llvm::cl::desc(
"The memory space of an memref types must always be inferred. If "
"unset, a default memory space of 0 is used otherwise."),
llvm::cl::init(false)};
};
} // namespace
namespace mlir::test {
void registerTestTensorCopyInsertionPass() {
PassRegistration<TestTensorCopyInsertionPass>();
}
} // namespace mlir::test

View File

@ -1,5 +1,6 @@
add_subdirectory(Affine)
add_subdirectory(Arith)
add_subdirectory(Bufferization)
add_subdirectory(DLTI)
add_subdirectory(Func)
add_subdirectory(GPU)

View File

@ -15,6 +15,7 @@ if(MLIR_INCLUDE_TESTS)
MLIRTestFuncToLLVM
MLIRAffineTransformsTestPasses
MLIRArithTestPasses
MLIRBufferizationTestPasses
MLIRDLTITestPasses
MLIRFuncTestPasses
MLIRGPUTestPasses

View File

@ -113,6 +113,7 @@ void registerTestRecursiveTypesPass();
void registerTestSCFUtilsPass();
void registerTestShapeMappingPass();
void registerTestSliceAnalysisPass();
void registerTestTensorCopyInsertionPass();
void registerTestTensorTransforms();
void registerTestTilingInterface();
void registerTestTopologicalSortAnalysisPass();
@ -216,6 +217,7 @@ void registerTestPasses() {
mlir::test::registerTestSCFUtilsPass();
mlir::test::registerTestShapeMappingPass();
mlir::test::registerTestSliceAnalysisPass();
mlir::test::registerTestTensorCopyInsertionPass();
mlir::test::registerTestTensorTransforms();
mlir::test::registerTestTilingInterface();
mlir::test::registerTestTopologicalSortAnalysisPass();

View File

@ -6865,6 +6865,7 @@ cc_binary(
"//mlir/test:TestAffine",
"//mlir/test:TestAnalysis",
"//mlir/test:TestArith",
"//mlir/test:TestBufferization",
"//mlir/test:TestDLTI",
"//mlir/test:TestDialect",
"//mlir/test:TestFunc",

View File

@ -701,6 +701,19 @@ cc_library(
],
)
cc_library(
name = "TestBufferization",
srcs = glob(["lib/Dialect/Bufferization/*.cpp"]),
defines = ["MLIR_CUDA_CONVERSIONS_ENABLED"],
includes = ["lib/Dialect/Test"],
deps = [
"//mlir:BufferizationDialect",
"//mlir:BufferizationTransforms",
"//mlir:IR",
"//mlir:Pass",
],
)
cc_library(
name = "TestShapeDialect",
srcs = [