[Mlir-commits] [mlir] 9ca97cd - [mlir] Linalg refactor for using "bufferize" terminology.
Sean Silva
llvmlistbot at llvm.org
Wed Oct 14 12:41:30 PDT 2020
Author: Sean Silva
Date: 2020-10-14T12:39:15-07:00
New Revision: 9ca97cde8508b92856d22e2164c8b6fb6756696e
URL: https://github.com/llvm/llvm-project/commit/9ca97cde8508b92856d22e2164c8b6fb6756696e
DIFF: https://github.com/llvm/llvm-project/commit/9ca97cde8508b92856d22e2164c8b6fb6756696e.diff
LOG: [mlir] Linalg refactor for using "bufferize" terminology.
Part of the refactor discussed in:
https://llvm.discourse.group/t/what-is-the-strategy-for-tensor-memref-conversion-bufferization/1938/17
Differential Revision: https://reviews.llvm.org/D89261
Added:
mlir/lib/Dialect/Linalg/Transforms/Bufferize.cpp
mlir/test/Dialect/Linalg/bufferize.mlir
Modified:
mlir/include/mlir/Dialect/Linalg/Passes.h
mlir/include/mlir/Dialect/Linalg/Passes.td
mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
mlir/integration_test/Dialect/Linalg/CPU/test-tensor-e2e.mlir
mlir/integration_test/Dialect/Linalg/CPU/test-tensor-matmul.mlir
mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt
Removed:
mlir/lib/Dialect/Linalg/Transforms/TensorsToBuffers.cpp
mlir/test/Dialect/Linalg/tensors-to-buffers.mlir
################################################################################
diff --git a/mlir/include/mlir/Dialect/Linalg/Passes.h b/mlir/include/mlir/Dialect/Linalg/Passes.h
index d74714cdaa56..2d6f6f54649f 100644
--- a/mlir/include/mlir/Dialect/Linalg/Passes.h
+++ b/mlir/include/mlir/Dialect/Linalg/Passes.h
@@ -46,8 +46,7 @@ std::unique_ptr<OperationPass<FuncOp>> createConvertLinalgToAffineLoopsPass();
/// Create a pass to convert Linalg operations which work on tensors to use
/// buffers instead.
-std::unique_ptr<OperationPass<ModuleOp>>
-createConvertLinalgOnTensorsToBuffersPass();
+std::unique_ptr<OperationPass<ModuleOp>> createLinalgBufferizePass();
/// Patterns for fusing linalg operation on tensors.
void populateLinalgTensorOpsFusionPatterns(MLIRContext *context,
diff --git a/mlir/include/mlir/Dialect/Linalg/Passes.td b/mlir/include/mlir/Dialect/Linalg/Passes.td
index 4e25772d5793..7103ee84b7cf 100644
--- a/mlir/include/mlir/Dialect/Linalg/Passes.td
+++ b/mlir/include/mlir/Dialect/Linalg/Passes.td
@@ -48,10 +48,9 @@ def LinalgLowerToLoops : FunctionPass<"convert-linalg-to-loops"> {
let dependentDialects = ["linalg::LinalgDialect", "scf::SCFDialect", "AffineDialect"];
}
-def LinalgOnTensorsToBuffers : Pass<"convert-linalg-on-tensors-to-buffers", "ModuleOp"> {
- let summary = "Convert the Linalg operations which work on tensor-type "
- "operands or results to use buffers instead";
- let constructor = "mlir::createConvertLinalgOnTensorsToBuffersPass()";
+def LinalgBufferize : Pass<"linalg-bufferize", "ModuleOp"> {
+ let summary = "Bufferize the linalg dialect";
+ let constructor = "mlir::createLinalgBufferizePass()";
let dependentDialects = ["linalg::LinalgDialect", "vector::VectorDialect"];
}
diff --git a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
index 948883e89e1e..781a5284e754 100644
--- a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
+++ b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
@@ -49,11 +49,10 @@ void populateConvVectorizationPatterns(
MLIRContext *context, SmallVectorImpl<OwningRewritePatternList> &patterns,
ArrayRef<int64_t> tileSizes);
-/// Populates the given list with patterns to convert Linalg operations on
-/// tensors to buffers.
-void populateConvertLinalgOnTensorsToBuffersPatterns(
- MLIRContext *context, BufferAssignmentTypeConverter &converter,
- OwningRewritePatternList &patterns);
+/// Populates the given list with patterns to bufferize linalg ops.
+void populateLinalgBufferizePatterns(MLIRContext *context,
+ BufferAssignmentTypeConverter &converter,
+ OwningRewritePatternList &patterns);
/// Performs standalone tiling of a single LinalgOp by `tileSizes`.
/// and permute the loop nest according to `interchangeVector`
diff --git a/mlir/integration_test/Dialect/Linalg/CPU/test-tensor-e2e.mlir b/mlir/integration_test/Dialect/Linalg/CPU/test-tensor-e2e.mlir
index a2bd18c7a3b1..b14418e74889 100644
--- a/mlir/integration_test/Dialect/Linalg/CPU/test-tensor-e2e.mlir
+++ b/mlir/integration_test/Dialect/Linalg/CPU/test-tensor-e2e.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -convert-linalg-on-tensors-to-buffers -convert-linalg-to-loops -convert-linalg-to-llvm -convert-std-to-llvm | \
+// RUN: mlir-opt %s -linalg-bufferize -convert-linalg-to-loops -convert-linalg-to-llvm -convert-std-to-llvm | \
// RUN: mlir-cpu-runner -e main -entry-point-result=void \
// RUN: -shared-libs=%mlir_integration_test_dir/libmlir_runner_utils%shlibext \
// RUN: | FileCheck %s
diff --git a/mlir/integration_test/Dialect/Linalg/CPU/test-tensor-matmul.mlir b/mlir/integration_test/Dialect/Linalg/CPU/test-tensor-matmul.mlir
index a06874550f56..548fab3afa6d 100644
--- a/mlir/integration_test/Dialect/Linalg/CPU/test-tensor-matmul.mlir
+++ b/mlir/integration_test/Dialect/Linalg/CPU/test-tensor-matmul.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -convert-linalg-on-tensors-to-buffers -convert-linalg-to-loops -convert-linalg-to-llvm -convert-std-to-llvm | \
+// RUN: mlir-opt %s -linalg-bufferize -convert-linalg-to-loops -convert-linalg-to-llvm -convert-std-to-llvm | \
// RUN: mlir-cpu-runner -e main -entry-point-result=void \
// RUN: -shared-libs=%mlir_integration_test_dir/libmlir_runner_utils%shlibext \
// RUN: | FileCheck %s
diff --git a/mlir/lib/Dialect/Linalg/Transforms/TensorsToBuffers.cpp b/mlir/lib/Dialect/Linalg/Transforms/Bufferize.cpp
similarity index 95%
rename from mlir/lib/Dialect/Linalg/Transforms/TensorsToBuffers.cpp
rename to mlir/lib/Dialect/Linalg/Transforms/Bufferize.cpp
index 303624f2898d..6ddd4e26d3e1 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/TensorsToBuffers.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Bufferize.cpp
@@ -1,16 +1,12 @@
-//===- TensorsToBuffers.cpp - Transformation from tensors to buffers ------===//
+//===- Bufferize.cpp - Bufferization of linalg ops ------------------===//
//
// 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 file implements the conversion from tensors to buffers on Linalg
-// operations.
-//
-//===----------------------------------------------------------------------===//
+#include "mlir/Transforms/Bufferize.h"
#include "PassDetail.h"
#include "mlir/Dialect/Linalg/IR/LinalgOps.h"
#include "mlir/Dialect/Linalg/Passes.h"
@@ -20,7 +16,6 @@
#include "mlir/IR/Function.h"
#include "mlir/IR/Operation.h"
#include "mlir/Pass/Pass.h"
-#include "mlir/Transforms/Bufferize.h"
using namespace ::mlir;
using namespace ::mlir::linalg;
@@ -295,8 +290,7 @@ namespace {
/// Converts Linalg operations that work on tensor-type operands or results to
/// work on buffers.
-struct ConvertLinalgOnTensorsToBuffers
- : public LinalgOnTensorsToBuffersBase<ConvertLinalgOnTensorsToBuffers> {
+struct LinalgBufferizePass : public LinalgBufferizeBase<LinalgBufferizePass> {
void runOnOperation() override {
MLIRContext &context = getContext();
ConversionTarget target(context);
@@ -353,8 +347,7 @@ struct ConvertLinalgOnTensorsToBuffers
BufferAssignmentTypeConverter::AppendToArgumentsList);
OwningRewritePatternList patterns;
- populateConvertLinalgOnTensorsToBuffersPatterns(&context, converter,
- patterns);
+ populateLinalgBufferizePatterns(&context, converter, patterns);
populateWithBufferAssignmentOpConversionPatterns<
mlir::ReturnOp, mlir::ReturnOp, linalg::CopyOp>(&context, converter,
patterns);
@@ -364,12 +357,10 @@ struct ConvertLinalgOnTensorsToBuffers
};
} // end anonymous namespace
-std::unique_ptr<OperationPass<ModuleOp>>
-mlir::createConvertLinalgOnTensorsToBuffersPass() {
- return std::make_unique<ConvertLinalgOnTensorsToBuffers>();
+std::unique_ptr<OperationPass<ModuleOp>> mlir::createLinalgBufferizePass() {
+ return std::make_unique<LinalgBufferizePass>();
}
-void mlir::linalg::populateConvertLinalgOnTensorsToBuffersPatterns(
-
+void mlir::linalg::populateLinalgBufferizePatterns(
MLIRContext *context, BufferAssignmentTypeConverter &converter,
OwningRewritePatternList &patterns) {
patterns.insert<
diff --git a/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt b/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt
index 89b06261bc5b..844972e56c6f 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt
+++ b/mlir/lib/Dialect/Linalg/Transforms/CMakeLists.txt
@@ -1,4 +1,5 @@
add_mlir_dialect_library(MLIRLinalgTransforms
+ Bufferize.cpp
CodegenStrategy.cpp
DropUnitDims.cpp
Fusion.cpp
@@ -7,7 +8,6 @@ add_mlir_dialect_library(MLIRLinalgTransforms
Interchange.cpp
Loops.cpp
Promotion.cpp
- TensorsToBuffers.cpp
Tiling.cpp
Transforms.cpp
Vectorization.cpp
diff --git a/mlir/test/Dialect/Linalg/tensors-to-buffers.mlir b/mlir/test/Dialect/Linalg/bufferize.mlir
similarity index 99%
rename from mlir/test/Dialect/Linalg/tensors-to-buffers.mlir
rename to mlir/test/Dialect/Linalg/bufferize.mlir
index 093732c7f47d..ed78365b1937 100644
--- a/mlir/test/Dialect/Linalg/tensors-to-buffers.mlir
+++ b/mlir/test/Dialect/Linalg/bufferize.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -convert-linalg-on-tensors-to-buffers -buffer-placement -split-input-file %s | FileCheck %s
+// RUN: mlir-opt -linalg-bufferize -buffer-placement -split-input-file %s | FileCheck %s
#map0 = affine_map<(d0) -> (d0)>
More information about the Mlir-commits
mailing list