Fold TestLinalgTilePermutePatterns into TestLinalgTransformPatterns - NFC

Centralize all patterns that test Linalg transforms in a single pass.

PiperOrigin-RevId: 284835938
This commit is contained in:
Nicolas Vasilache 2019-12-10 13:25:41 -08:00 committed by A. Unique TensorFlower
parent 9ed22ae5b8
commit 995048d7b7
7 changed files with 95 additions and 200 deletions

View File

@ -1,70 +0,0 @@
// RUN: mlir-opt %s -test-linalg-tile-and-permute-patterns | FileCheck %s
// CHECK-DAG: #[[STRIDED_1D:.*]] = (d0)[s0] -> (d0 + s0)
// CHECK-DAG: #[[STRIDED_2D:.*]] = (d0, d1)[s0, s1] -> (d0 * s1 + s0 + d1)
func @dot(%x: memref<?xf32, offset: ?, strides: [1]>,
%y: memref<?xf32, offset: ?, strides: [1]>,
%v: memref<f32>) {
linalg.dot(%x, %y, %v) : memref<?xf32, offset: ?, strides: [1]>,
memref<?xf32, offset: ?, strides: [1]>,
memref<f32>
return
}
// CHECK-LABEL: func @dot
// CHECK-DAG : %[[c0:.*]] = constant 0 : index
// CHECK-DAG : %[[c8:.*]] = constant 8 : index
// CHECK-DAG : %[[c8000:.*]] = constant 8000 : index
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c8000]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c8]] {
// CHECK : linalg.dot({{.*}}, {{.*}}, {{.*}}) : memref<?xf32, #[[STRIDED_1D]]>, memref<?xf32, #[[STRIDED_1D]]>, memref<f32>
func @matvec(%A: memref<?x?xf32, offset: ?, strides: [?, 1]>,
%x: memref<?xf32, offset: ?, strides: [1]>,
%y: memref<?xf32, offset: ?, strides: [1]>) {
linalg.matvec(%A, %x, %y) : memref<?x?xf32, offset: ?, strides: [?, 1]>,
memref<?xf32, offset: ?, strides: [1]>,
memref<?xf32, offset: ?, strides: [1]>
return
}
// CHECK-LABEL: func @matvec
// CHECK-DAG : %[[c0:.*]] = constant 0 : index
// CHECK-DAG : %[[c5:.*]] = constant 5 : index
// CHECK-DAG : %[[c6:.*]] = constant 6 : index
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c6]]
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c5]]
// CHECK : linalg.matvec({{.*}}, {{.*}}, {{.*}}) : memref<?x?xf32, #[[STRIDED_2D]]>, memref<?xf32, #[[STRIDED_1D]]>, memref<?xf32, #[[STRIDED_1D]]>
func @matmul(%A: memref<?x?xf32, offset: ?, strides: [?, 1]>,
%B: memref<?x?xf32, offset: ?, strides: [?, 1]>,
%C: memref<?x?xf32, offset: ?, strides: [?, 1]>) {
linalg.matmul(%A, %B, %C) : memref<?x?xf32, offset: ?, strides: [?, 1]>,
memref<?x?xf32, offset: ?, strides: [?, 1]>,
memref<?x?xf32, offset: ?, strides: [?, 1]>
return
}
// CHECK-LABEL: func @matmul
// CHECK-DAG : %[[c0:.*]] = constant 0 : index
// CHECK-DAG : %[[c2:.*]] = constant 2 : index
// CHECK-DAG : %[[c3:.*]] = constant 3 : index
// CHECK-DAG : %[[c4:.*]] = constant 4 : index
// CHECK-DAG : %[[c20:.*]] = constant 20 : index
// CHECK-DAG : %[[c30:.*]] = constant 30 : index
// CHECK-DAG : %[[c40:.*]] = constant 40 : index
// CHECK-DAG : %[[c200:.*]] = constant 200 : index
// CHECK-DAG : %[[c300:.*]] = constant 300 : index
// CHECK-DAG : %[[c400:.*]] = constant 400 : index
// CHECK-DAG : %[[c2000:.*]] = constant 2000 : index
// CHECK-DAG : %[[c3000:.*]] = constant 3000 : index
// CHECK-DAG : %[[c4000:.*]] = constant 4000 : index
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c3000]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c4000]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c2000]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c300]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c200]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c400]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c20]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c30]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c40]] {
// CHECK : linalg.matmul({{.*}}, {{.*}}, {{.*}}) : memref<?x?xf32, #[[STRIDED_2D]]>, memref<?x?xf32, #[[STRIDED_2D]]>, memref<?x?xf32, #[[STRIDED_2D]]>

View File

@ -243,3 +243,71 @@ func @permute_generic_indexed(%A: memref<?x?xf32, offset: ?, strides: [?, 1]>,
// CHECK-LABEL : func @fma_indexed
// CHECK-LABEL : func @permute_generic_indexed
// CHECK : linalg.indexed_generic {fun = @fma, indexing_maps = [#[[kn]], #[[nm]], #[[km]]], iterator_types = ["parallel", "reduction", "parallel"], library_call = "linalg_matmul_indexed", n_views = [2, 1]} %{{.*}}, %{{.*}}, %{{.*}} : memref<?x?xf32, #[[STRIDED_2D]]>, memref<?x?xf32, #[[STRIDED_2D]]>, memref<?x?xf32, #[[STRIDED_2D]]>
func @dot_perm(%x: memref<?xf32, offset: ?, strides: [1]>,
%y: memref<?xf32, offset: ?, strides: [1]>,
%v: memref<f32>) {
linalg.dot(%x, %y, %v) {__internal_linalg_transform__ = "__with_perm__"} :
memref<?xf32, offset: ?, strides: [1]>,
memref<?xf32, offset: ?, strides: [1]>,
memref<f32>
return
}
// CHECK-LABEL: func @dot_perm
// CHECK-DAG : %[[c0:.*]] = constant 0 : index
// CHECK-DAG : %[[c8:.*]] = constant 8 : index
// CHECK-DAG : %[[c8000:.*]] = constant 8000 : index
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c8000]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c8]] {
// CHECK : linalg.dot({{.*}}, {{.*}}, {{.*}}) : memref<?xf32, #[[STRIDED_1D]]>, memref<?xf32, #[[STRIDED_1D]]>, memref<f32>
func @matvec_perm(%A: memref<?x?xf32, offset: ?, strides: [?, 1]>,
%x: memref<?xf32, offset: ?, strides: [1]>,
%y: memref<?xf32, offset: ?, strides: [1]>) {
linalg.matvec(%A, %x, %y) {__internal_linalg_transform__ = "__with_perm__"} :
memref<?x?xf32, offset: ?, strides: [?, 1]>,
memref<?xf32, offset: ?, strides: [1]>,
memref<?xf32, offset: ?, strides: [1]>
return
}
// CHECK-LABEL: func @matvec_perm
// CHECK-DAG : %[[c0:.*]] = constant 0 : index
// CHECK-DAG : %[[c5:.*]] = constant 5 : index
// CHECK-DAG : %[[c6:.*]] = constant 6 : index
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c6]]
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c5]]
// CHECK : linalg.matvec({{.*}}, {{.*}}, {{.*}}) : memref<?x?xf32, #[[STRIDED_2D]]>, memref<?xf32, #[[STRIDED_1D]]>, memref<?xf32, #[[STRIDED_1D]]>
func @matmul_perm(%A: memref<?x?xf32, offset: ?, strides: [?, 1]>,
%B: memref<?x?xf32, offset: ?, strides: [?, 1]>,
%C: memref<?x?xf32, offset: ?, strides: [?, 1]>) {
linalg.matmul(%A, %B, %C) {__internal_linalg_transform__ = "__with_perm__"} :
memref<?x?xf32, offset: ?, strides: [?, 1]>,
memref<?x?xf32, offset: ?, strides: [?, 1]>,
memref<?x?xf32, offset: ?, strides: [?, 1]>
return
}
// CHECK-LABEL: func @matmul_perm
// CHECK-DAG : %[[c0:.*]] = constant 0 : index
// CHECK-DAG : %[[c2:.*]] = constant 2 : index
// CHECK-DAG : %[[c3:.*]] = constant 3 : index
// CHECK-DAG : %[[c4:.*]] = constant 4 : index
// CHECK-DAG : %[[c20:.*]] = constant 20 : index
// CHECK-DAG : %[[c30:.*]] = constant 30 : index
// CHECK-DAG : %[[c40:.*]] = constant 40 : index
// CHECK-DAG : %[[c200:.*]] = constant 200 : index
// CHECK-DAG : %[[c300:.*]] = constant 300 : index
// CHECK-DAG : %[[c400:.*]] = constant 400 : index
// CHECK-DAG : %[[c2000:.*]] = constant 2000 : index
// CHECK-DAG : %[[c3000:.*]] = constant 3000 : index
// CHECK-DAG : %[[c4000:.*]] = constant 4000 : index
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c3000]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c4000]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c2000]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c300]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c200]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c400]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c20]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c30]] {
// CHECK : loop.for {{.*}} = %[[c0]] to {{.*}} step %[[c40]] {
// CHECK : linalg.matmul({{.*}}, {{.*}}, {{.*}}) : memref<?x?xf32, #[[STRIDED_2D]]>, memref<?x?xf32, #[[STRIDED_2D]]>, memref<?x?xf32, #[[STRIDED_2D]]>

View File

@ -2,11 +2,6 @@ set(LLVM_TARGET_DEFINITIONS TestLinalgTransformPatterns.td)
mlir_tablegen(TestLinalgTransformPatterns.h.inc -gen-rewriters)
add_public_tablegen_target(MLIRTestLinalgTransformPatternsIncGen)
set(LLVM_TARGET_DEFINITIONS TestLinalgTilePermutePatterns.td)
mlir_tablegen(TestLinalgTilePermutePatterns.h.inc -gen-rewriters)
add_public_tablegen_target(MLIRTestLinalgTilePermutePatternsIncGen)
set(LLVM_TARGET_DEFINITIONS TestVectorPatterns.td)
mlir_tablegen(TestVectorPatterns.h.inc -gen-rewriters)
set(LLVM_TARGET_DEFINITIONS TestVectorTransformPatterns.td)
mlir_tablegen(TestVectorTransformPatterns.h.inc -gen-rewriters)
add_public_tablegen_target(MLIRTestVectorTransformPatternsIncGen)

View File

@ -1,57 +0,0 @@
//===- TestLinalgTilePermutePatterns.td - Test patterns --*- tablegen ----*-===//
//
// Copyright 2019 The MLIR Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
//
// This is the pattern definition file for declarative Linalg transformations
// tests.
//
//===----------------------------------------------------------------------===//
#ifndef TEST_LINALG_TILEPERMUTE_PATTERNS
#define TEST_LINALG_TILEPERMUTE_PATTERNS
include "mlir/Dialect/Linalg/Transforms/LinalgTransformPatterns.td"
//===----------------------------------------------------------------------===//
// Linalg tiling and permutation patterns.
//===----------------------------------------------------------------------===//
def : Pat<(MatmulOp:$op $A, $B, $C),
(TileLinalgOp<[2000, 3000, 4000], "L2", [1,2,0]> $op),
[(Constraint<Or<[HasNoLinalgTransformMarker,
HasLinalgTransformMarker<"MEM">]>> $op)]>;
def : Pat<(MatmulOp:$op $A, $B, $C),
(TileLinalgOp<[200, 300, 400], "L1", [1,0,2]> $op),
[(Constraint<HasLinalgTransformMarker<"L2">> $op)]>;
def : Pat<(MatmulOp:$op $A, $B, $C),
(TileLinalgOp<[20, 30, 40], "REG"> $op),
[(Constraint<HasLinalgTransformMarker<"L1">> $op)]>;
def : Pattern<(MatvecOp:$op $A, $b, $c),
[(TileLinalgOp<[5, 6], "L1", [1,0]> $op)],
[(Constraint<HasNoLinalgTransformMarker> $op)]>;
def : Pattern<(DotOp:$op $a, $b, $c),
[(TileLinalgOp<[8000], "L1"> $op)],
[(Constraint<Or<[HasNoLinalgTransformMarker,
HasLinalgTransformMarker<"MEM">,
HasLinalgTransformMarker<"L3">,
HasLinalgTransformMarker<"L2">]>> $op)]>;
def : Pattern<(DotOp:$op $a, $b, $c),
[(TileLinalgOp<[8], "REG"> $op)],
[(Constraint<HasLinalgTransformMarker<"L1">> $op)]>;
#endif // TEST_LINALG_TILEPERMUTE_PATTERNS

View File

@ -73,6 +73,31 @@ def : Pattern<(DotOp:$op $a, $b, $c),
[(TileLinalgOp<[8], "REG"> $op)],
[(Constraint<HasLinalgTransformMarker<"L1">> $op)]>;
//===----------------------------------------------------------------------===//
// Linalg tiling and permutation patterns.
//===----------------------------------------------------------------------===//
def : Pat<(MatmulOp:$op $A, $B, $C),
(TileLinalgOp<[2000, 3000, 4000], "L2__with_perm__", [1,2,0]> $op),
[(Constraint<HasLinalgTransformMarker<"__with_perm__">> $op)]>;
def : Pat<(MatmulOp:$op $A, $B, $C),
(TileLinalgOp<[200, 300, 400], "L1__with_perm__", [1,0,2]> $op),
[(Constraint<HasLinalgTransformMarker<"L2__with_perm__">> $op)]>;
def : Pat<(MatmulOp:$op $A, $B, $C),
(TileLinalgOp<[20, 30, 40], "REG__with_perm__"> $op),
[(Constraint<HasLinalgTransformMarker<"L1__with_perm__">> $op)]>;
def : Pattern<(MatvecOp:$op $A, $b, $c),
[(TileLinalgOp<[5, 6], "L1__with_perm__", [1,0]> $op)],
[(Constraint<HasLinalgTransformMarker<"__with_perm__">> $op)]>;
def : Pattern<(DotOp:$op $a, $b, $c),
[(TileLinalgOp<[8000], "L1__with_perm__"> $op)],
[(Constraint<HasLinalgTransformMarker<"__with_perm__">> $op)]>;
def : Pattern<(DotOp:$op $a, $b, $c),
[(TileLinalgOp<[8], "REG__with_perm__"> $op)],
[(Constraint<HasLinalgTransformMarker<"L1__with_perm__">> $op)]>;
//===----------------------------------------------------------------------===//
// Linalg to loops patterns.
//===----------------------------------------------------------------------===//

View File

@ -4,7 +4,6 @@ add_llvm_library(MLIRTestTransforms
TestLoopFusion.cpp
TestInlining.cpp
TestLinalgTransforms.cpp
TestLinalgTilePermuteTransforms.cpp
TestLoopMapping.cpp
TestLoopParametricTiling.cpp
TestOpaqueLoc.cpp
@ -22,7 +21,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../DeclarativeTransforms)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../DeclarativeTransforms)
add_dependencies(MLIRTestTransforms MLIRStandardOpsIncGen)
add_dependencies(MLIRTestTransforms MLIRTestLinalgTransformPatternsIncGen)
add_dependencies(MLIRTestTransforms MLIRTestLinalgTilePermutePatternsIncGen)
add_dependencies(MLIRTestTransforms MLIRTestVectorTransformPatternsIncGen)
target_link_libraries(MLIRTestTransforms
MLIRAffineOps

View File

@ -1,64 +0,0 @@
//===- TestLinalgTilePermuteTransforms.cpp - Test Linalg tile + permute ---===//
//
// Copyright 2019 The MLIR Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
//
// This file implements logic for testing Linalg transformations.
//
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/Linalg/IR/LinalgOps.h"
#include "mlir/Dialect/Linalg/Transforms/LinalgTransforms.h"
#include "mlir/Dialect/Linalg/Utils/Utils.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Pass/Pass.h"
using namespace mlir;
using namespace mlir::linalg;
namespace mlir {
namespace linalg {
namespace {
#include "TestLinalgTilePermutePatterns.h.inc"
} // end namespace
} // end namespace linalg
} // end namespace mlir
namespace {
struct TestLinalgTilePermuteTransforms
: public FunctionPass<TestLinalgTilePermuteTransforms> {
void runOnFunction() override;
};
} // end anonymous namespace
/// Apply transformations specified as patterns.
void TestLinalgTilePermuteTransforms::runOnFunction() {
OwningRewritePatternList patterns;
auto funcOp = getFunction();
// Add the generated patterns to the list.
linalg::populateWithGenerated(&getContext(), &patterns);
applyPatternsGreedily(funcOp, patterns);
// Drop the marker.
funcOp.walk([](LinalgOp op) {
op.removeAttr(LinalgTransforms::kLinalgTransformMarker);
});
}
static PassRegistration<TestLinalgTilePermuteTransforms>
pass("test-linalg-tile-and-permute-patterns",
"Test Linalg transformation with permutation patterns by applying "
"them greedily.");