From 2213584c4f153e37ab062e32f8dcf724a999dada Mon Sep 17 00:00:00 2001 From: Sean Silva Date: Fri, 24 Sep 2021 02:18:56 +0000 Subject: [PATCH] VerifyBackendContract -> VerifyLinalgOnTensorsBackendContract This moves it into TorchConversion since it is only needed there. This removes the Backend/ directory. --- include/npcomp/Backend/CMakeLists.txt | 1 - include/npcomp/Backend/Common/CMakeLists.txt | 5 ---- include/npcomp/Backend/Common/Passes.h | 27 ------------------- include/npcomp/Backend/Common/Passes.td | 19 ------------- include/npcomp/Backend/Common/README.md | 5 ---- include/npcomp/CMakeLists.txt | 1 - .../TorchConversion/Transforms/Passes.h | 2 ++ .../TorchConversion/Transforms/Passes.td | 5 ++++ lib/Backend/CMakeLists.txt | 1 - lib/Backend/Common/CMakeLists.txt | 22 --------------- lib/Backend/Common/PassDetail.h | 25 ----------------- lib/Backend/Common/Passes.cpp | 25 ----------------- lib/CMakeLists.txt | 2 -- .../TorchConversion/Transforms/CMakeLists.txt | 1 + .../TorchConversion/Transforms/Passes.cpp | 7 +++-- .../VerifyLinalgOnTensorsBackendContract.cpp} | 14 +++++----- lib/InitAll.cpp | 2 -- python/npcomp/compiler/pytorch/backend/abc.py | 2 +- ...y-linalg-on-tensors-backend-contract.mlir} | 2 +- 19 files changed, 21 insertions(+), 147 deletions(-) delete mode 100644 include/npcomp/Backend/CMakeLists.txt delete mode 100644 include/npcomp/Backend/Common/CMakeLists.txt delete mode 100644 include/npcomp/Backend/Common/Passes.h delete mode 100644 include/npcomp/Backend/Common/Passes.td delete mode 100644 include/npcomp/Backend/Common/README.md delete mode 100644 lib/Backend/CMakeLists.txt delete mode 100644 lib/Backend/Common/CMakeLists.txt delete mode 100644 lib/Backend/Common/PassDetail.h delete mode 100644 lib/Backend/Common/Passes.cpp rename lib/{Backend/Common/VerifyBackendContract.cpp => Dialect/TorchConversion/Transforms/VerifyLinalgOnTensorsBackendContract.cpp} (87%) rename test/{Backend/Common/verify-backend-contract.mlir => Dialect/TorchConversion/verify-linalg-on-tensors-backend-contract.mlir} (92%) diff --git a/include/npcomp/Backend/CMakeLists.txt b/include/npcomp/Backend/CMakeLists.txt deleted file mode 100644 index 224629e31..000000000 --- a/include/npcomp/Backend/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(Common) diff --git a/include/npcomp/Backend/Common/CMakeLists.txt b/include/npcomp/Backend/Common/CMakeLists.txt deleted file mode 100644 index e56fa169a..000000000 --- a/include/npcomp/Backend/Common/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -set(LLVM_TARGET_DEFINITIONS Passes.td) -mlir_tablegen(Passes.h.inc -gen-pass-decls) -add_public_tablegen_target(NPCOMPCommonBackendPassIncGen) - -add_mlir_doc(Passes CommonBackendPasses ./ -gen-pass-doc) diff --git a/include/npcomp/Backend/Common/Passes.h b/include/npcomp/Backend/Common/Passes.h deleted file mode 100644 index 07e71c611..000000000 --- a/include/npcomp/Backend/Common/Passes.h +++ /dev/null @@ -1,27 +0,0 @@ -//===------------------------------------------------------------*- C++ -*-===// -// -// This file is licensed 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 -// -//===----------------------------------------------------------------------===// - -#ifndef NPCOMP_BACKEND_COMMON_PASSES_H -#define NPCOMP_BACKEND_COMMON_PASSES_H - -#include "mlir/Pass/Pass.h" -#include "mlir/Pass/PassManager.h" - -namespace mlir { -namespace NPCOMP { -namespace CommonBackend { -/// Registers all CommonBackend passes. -void registerCommonBackendPasses(); - -std::unique_ptr> createVerifyBackendContractPass(); - -} // namespace CommonBackend -} // namespace NPCOMP -} // namespace mlir - -#endif // NPCOMP_BACKEND_COMMON_PASSES_H diff --git a/include/npcomp/Backend/Common/Passes.td b/include/npcomp/Backend/Common/Passes.td deleted file mode 100644 index 6829d68fc..000000000 --- a/include/npcomp/Backend/Common/Passes.td +++ /dev/null @@ -1,19 +0,0 @@ -//===-- Passes.td - Pass definition file -------------------*- tablegen -*-===// -// -// 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 -// -//===----------------------------------------------------------------------===// - -#ifndef NPCOMP_BACKEND_COMMON_PASSES -#define NPCOMP_BACKEND_COMMON_PASSES - -include "mlir/Pass/PassBase.td" - -def VerifyBackendContract : Pass<"npcomp-verify-backend-contract", "ModuleOp"> { - let summary = "Verifies conformity to the backend contract that npcomp targets"; - let constructor = "mlir::NPCOMP::CommonBackend::createVerifyBackendContractPass()"; -} - -#endif // NPCOMP_BACKEND_COMMON_PASSES diff --git a/include/npcomp/Backend/Common/README.md b/include/npcomp/Backend/Common/README.md deleted file mode 100644 index c95f2acb8..000000000 --- a/include/npcomp/Backend/Common/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Common backend utilities - -This directory contains passes/transformations/analyses/etc. that are relevant -to the backend contract that npcomp targets, but otherwise independent of any -particular backend. diff --git a/include/npcomp/CMakeLists.txt b/include/npcomp/CMakeLists.txt index 02b0c5740..629c08af6 100644 --- a/include/npcomp/CMakeLists.txt +++ b/include/npcomp/CMakeLists.txt @@ -1,3 +1,2 @@ -add_subdirectory(Backend) add_subdirectory(Conversion) add_subdirectory(Dialect) diff --git a/include/npcomp/Dialect/TorchConversion/Transforms/Passes.h b/include/npcomp/Dialect/TorchConversion/Transforms/Passes.h index 6c83c5408..3a5126dae 100644 --- a/include/npcomp/Dialect/TorchConversion/Transforms/Passes.h +++ b/include/npcomp/Dialect/TorchConversion/Transforms/Passes.h @@ -32,6 +32,8 @@ std::unique_ptr> createFuncBackendTypeConversionPass(); std::unique_ptr> createFinalizingBackendTypeConversionPass(); +std::unique_ptr> createVerifyLinalgOnTensorsBackendContractPass(); + } // namespace TorchConversion /// Registers all Torch transformation passes. diff --git a/include/npcomp/Dialect/TorchConversion/Transforms/Passes.td b/include/npcomp/Dialect/TorchConversion/Transforms/Passes.td index 14db5eb8e..d9f19bc26 100644 --- a/include/npcomp/Dialect/TorchConversion/Transforms/Passes.td +++ b/include/npcomp/Dialect/TorchConversion/Transforms/Passes.td @@ -52,4 +52,9 @@ def FinalizingBackendTypeConversion }]; } +def VerifyLinalgOnTensorsBackendContract : Pass<"npcomp-verify-linalg-on-tensors-backend-contract", "ModuleOp"> { + let summary = "Verifies conformity to the linalg-on-tensors backend contract"; + let constructor = "mlir::NPCOMP::TorchConversion::createVerifyLinalgOnTensorsBackendContractPass()"; +} + #endif // NPCOMP_TORCHCONVERSION_PASSES diff --git a/lib/Backend/CMakeLists.txt b/lib/Backend/CMakeLists.txt deleted file mode 100644 index 224629e31..000000000 --- a/lib/Backend/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(Common) diff --git a/lib/Backend/Common/CMakeLists.txt b/lib/Backend/Common/CMakeLists.txt deleted file mode 100644 index c4bce4cc7..000000000 --- a/lib/Backend/Common/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -add_npcomp_library(NPCOMPCommonBackend - VerifyBackendContract.cpp - Passes.cpp - - ADDITIONAL_HEADER_DIRS - ${PROJECT_SRC_DIR}/include/npcomp/Backend/Common - - DEPENDS - NPCOMPCommonBackendPassIncGen - - LINK_COMPONENTS - Core - - LINK_LIBS PUBLIC - MLIRIR - MLIRLinalg - MLIRTensor - MLIRStandard - MLIRMath - ) - -mlir_check_all_link_libraries(NPCOMPCommonBackend) diff --git a/lib/Backend/Common/PassDetail.h b/lib/Backend/Common/PassDetail.h deleted file mode 100644 index 5ff3fe947..000000000 --- a/lib/Backend/Common/PassDetail.h +++ /dev/null @@ -1,25 +0,0 @@ -//===- PassDetail.h - Pass class details ------------------------*- 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 -// -//===----------------------------------------------------------------------===// - -#ifndef BACKEND_COMMON_PASSDETAIL_H -#define BACKEND_COMMON_PASSDETAIL_H - -#include "mlir/Pass/Pass.h" - -namespace mlir { -namespace NPCOMP { -namespace CommonBackend { - -#define GEN_PASS_CLASSES -#include "npcomp/Backend/Common/Passes.h.inc" - -} // namespace CommonBackend -} // namespace NPCOMP -} // end namespace mlir - -#endif // BACKEND_COMMON_PASSDETAIL_H diff --git a/lib/Backend/Common/Passes.cpp b/lib/Backend/Common/Passes.cpp deleted file mode 100644 index ca787d039..000000000 --- a/lib/Backend/Common/Passes.cpp +++ /dev/null @@ -1,25 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 "PassDetail.h" -#include "npcomp/Backend/Common/Passes.h" - -#include "mlir/IR/BuiltinOps.h" - -using namespace mlir; -using namespace mlir::NPCOMP; -using namespace mlir::NPCOMP::CommonBackend; - -namespace { -#define GEN_PASS_REGISTRATION -#include "npcomp/Backend/Common/Passes.h.inc" -} // end namespace - -void mlir::NPCOMP::CommonBackend::registerCommonBackendPasses() { - ::registerPasses(); -} diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 6f97f6f88..a89580ffb 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,4 +1,3 @@ -add_subdirectory(Backend) add_subdirectory(CAPI) add_subdirectory(Conversion) add_subdirectory(Dialect) @@ -25,7 +24,6 @@ add_npcomp_library(NPCOMPInitAll PUBLIC # Local depends - NPCOMPCommonBackend TorchMLIRTorchDialect NPCOMPTorchConversionDialect NPCOMPConversionPasses diff --git a/lib/Dialect/TorchConversion/Transforms/CMakeLists.txt b/lib/Dialect/TorchConversion/Transforms/CMakeLists.txt index ab44908b3..402572748 100644 --- a/lib/Dialect/TorchConversion/Transforms/CMakeLists.txt +++ b/lib/Dialect/TorchConversion/Transforms/CMakeLists.txt @@ -2,6 +2,7 @@ add_npcomp_conversion_library(NPCOMPTorchConversionPasses BackendTypeConversion.cpp Passes.cpp VerifyInvariantsBeforeBackendLowering.cpp + VerifyLinalgOnTensorsBackendContract.cpp ADDITIONAL_HEADER_DIRS ${PROJECT_SOURCE_DIR}/include/npcomp/Dialect/TorchConversion/Transforms diff --git a/lib/Dialect/TorchConversion/Transforms/Passes.cpp b/lib/Dialect/TorchConversion/Transforms/Passes.cpp index 504ff3807..08179befe 100644 --- a/lib/Dialect/TorchConversion/Transforms/Passes.cpp +++ b/lib/Dialect/TorchConversion/Transforms/Passes.cpp @@ -12,7 +12,6 @@ #include "mlir/Dialect/StandardOps/Transforms/Passes.h" #include "mlir/Pass/PassManager.h" #include "mlir/Transforms/Passes.h" -#include "npcomp/Backend/Common/Passes.h" #include "npcomp/Conversion/TorchToLinalg/TorchToLinalg.h" #include "npcomp/Conversion/TorchToSCF/TorchToSCF.h" #include "npcomp/Conversion/TorchToStd/TorchToStd.h" @@ -75,8 +74,8 @@ void mlir::NPCOMP::TorchConversion::createTorchScriptToNpcompBackendPipeline( pm.addNestedPass( TorchConversion::createFinalizingBackendTypeConversionPass()); - // Verify that we have lowered to the form that npcomp backends expect. - // This fails compilation (signalPassFailure) if the IR is not in the + // Verify that we have lowered to the form that linalg on tensors backends + // expect. This fails compilation (signalPassFailure) if the IR is not in the // correct form. - pm.addPass(CommonBackend::createVerifyBackendContractPass()); + pm.addPass(TorchConversion::createVerifyLinalgOnTensorsBackendContractPass()); } diff --git a/lib/Backend/Common/VerifyBackendContract.cpp b/lib/Dialect/TorchConversion/Transforms/VerifyLinalgOnTensorsBackendContract.cpp similarity index 87% rename from lib/Backend/Common/VerifyBackendContract.cpp rename to lib/Dialect/TorchConversion/Transforms/VerifyLinalgOnTensorsBackendContract.cpp index f83b8b418..91f06612f 100644 --- a/lib/Backend/Common/VerifyBackendContract.cpp +++ b/lib/Dialect/TorchConversion/Transforms/VerifyLinalgOnTensorsBackendContract.cpp @@ -7,22 +7,24 @@ //===----------------------------------------------------------------------===// #include "PassDetail.h" + #include "mlir/Dialect/Linalg/IR/LinalgOps.h" #include "mlir/Dialect/Math/IR/Math.h" #include "mlir/Dialect/Tensor/IR/Tensor.h" #include "mlir/IR/OpDefinition.h" #include "mlir/Transforms/DialectConversion.h" -#include "npcomp/Backend/Common/Passes.h" +#include "npcomp/Dialect/TorchConversion/Transforms/Passes.h" #include "mlir/IR/BuiltinOps.h" using namespace mlir; using namespace mlir::NPCOMP; -using namespace mlir::NPCOMP::CommonBackend; +using namespace mlir::NPCOMP::TorchConversion; namespace { -class VerifyBackendContractPass - : public VerifyBackendContractBase { +class VerifyLinalgOnTensorsBackendContractPass + : public VerifyLinalgOnTensorsBackendContractBase< + VerifyLinalgOnTensorsBackendContractPass> { void runOnOperation() override { MLIRContext *context = &getContext(); auto module = getOperation(); @@ -79,6 +81,6 @@ class VerifyBackendContractPass } // namespace std::unique_ptr> -mlir::NPCOMP::CommonBackend::createVerifyBackendContractPass() { - return std::make_unique(); +mlir::NPCOMP::TorchConversion::createVerifyLinalgOnTensorsBackendContractPass() { + return std::make_unique(); } diff --git a/lib/InitAll.cpp b/lib/InitAll.cpp index 370ab6315..f2fa8e3af 100644 --- a/lib/InitAll.cpp +++ b/lib/InitAll.cpp @@ -9,7 +9,6 @@ #include "npcomp/InitAll.h" #include "mlir/IR/Dialect.h" -#include "npcomp/Backend/Common/Passes.h" #include "npcomp/Conversion/Passes.h" #include "npcomp/Dialect/TorchConversion/IR/TorchConversionDialect.h" #include "npcomp/Dialect/TorchConversion/Transforms/Passes.h" @@ -21,5 +20,4 @@ void mlir::NPCOMP::registerAllDialects(mlir::DialectRegistry ®istry) { void mlir::NPCOMP::registerAllPasses() { mlir::NPCOMP::registerConversionPasses(); mlir::NPCOMP::registerTorchConversionPasses(); - mlir::NPCOMP::CommonBackend::registerCommonBackendPasses(); } diff --git a/python/npcomp/compiler/pytorch/backend/abc.py b/python/npcomp/compiler/pytorch/backend/abc.py index a70127657..3efce1f74 100644 --- a/python/npcomp/compiler/pytorch/backend/abc.py +++ b/python/npcomp/compiler/pytorch/backend/abc.py @@ -28,7 +28,7 @@ class NpcompBackend(abc.ABC): """Compile the provided MLIR module into a compiled artifact. The module adheres to the npcomp backend contract - (see the VerifyBackendContract pass). + (see the VerifyLinalgOnTensorsBackendContract pass). The compiled artifact can be any type, but must be correctly interpreted by the `load` method. diff --git a/test/Backend/Common/verify-backend-contract.mlir b/test/Dialect/TorchConversion/verify-linalg-on-tensors-backend-contract.mlir similarity index 92% rename from test/Backend/Common/verify-backend-contract.mlir rename to test/Dialect/TorchConversion/verify-linalg-on-tensors-backend-contract.mlir index 14929b5cf..126f0a741 100644 --- a/test/Backend/Common/verify-backend-contract.mlir +++ b/test/Dialect/TorchConversion/verify-linalg-on-tensors-backend-contract.mlir @@ -1,4 +1,4 @@ -// RUN: npcomp-opt -npcomp-verify-backend-contract -split-input-file -verify-diagnostics -allow-unregistered-dialect %s | FileCheck %s +// RUN: npcomp-opt -npcomp-verify-linalg-on-tensors-backend-contract -split-input-file -verify-diagnostics -allow-unregistered-dialect %s | FileCheck %s // CHECK: func @mm func @mm(%arg0: tensor, %arg1: tensor) -> tensor {