VerifyBackendContract -> VerifyLinalgOnTensorsBackendContract

This moves it into TorchConversion since it is only needed there.

This removes the Backend/ directory.
pull/323/head
Sean Silva 2021-09-24 02:18:56 +00:00
parent 06559efe94
commit 2213584c4f
19 changed files with 21 additions and 147 deletions

View File

@ -1 +0,0 @@
add_subdirectory(Common)

View File

@ -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)

View File

@ -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<OperationPass<ModuleOp>> createVerifyBackendContractPass();
} // namespace CommonBackend
} // namespace NPCOMP
} // namespace mlir
#endif // NPCOMP_BACKEND_COMMON_PASSES_H

View File

@ -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

View File

@ -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.

View File

@ -1,3 +1,2 @@
add_subdirectory(Backend)
add_subdirectory(Conversion)
add_subdirectory(Dialect)

View File

@ -32,6 +32,8 @@ std::unique_ptr<OperationPass<ModuleOp>> createFuncBackendTypeConversionPass();
std::unique_ptr<OperationPass<FuncOp>>
createFinalizingBackendTypeConversionPass();
std::unique_ptr<OperationPass<ModuleOp>> createVerifyLinalgOnTensorsBackendContractPass();
} // namespace TorchConversion
/// Registers all Torch transformation passes.

View File

@ -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

View File

@ -1 +0,0 @@
add_subdirectory(Common)

View File

@ -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)

View File

@ -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

View File

@ -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();
}

View File

@ -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

View File

@ -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

View File

@ -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<FuncOp>(
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());
}

View File

@ -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<VerifyBackendContractPass> {
class VerifyLinalgOnTensorsBackendContractPass
: public VerifyLinalgOnTensorsBackendContractBase<
VerifyLinalgOnTensorsBackendContractPass> {
void runOnOperation() override {
MLIRContext *context = &getContext();
auto module = getOperation();
@ -79,6 +81,6 @@ class VerifyBackendContractPass
} // namespace
std::unique_ptr<OperationPass<ModuleOp>>
mlir::NPCOMP::CommonBackend::createVerifyBackendContractPass() {
return std::make_unique<VerifyBackendContractPass>();
mlir::NPCOMP::TorchConversion::createVerifyLinalgOnTensorsBackendContractPass() {
return std::make_unique<VerifyLinalgOnTensorsBackendContractPass>();
}

View File

@ -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 &registry) {
void mlir::NPCOMP::registerAllPasses() {
mlir::NPCOMP::registerConversionPasses();
mlir::NPCOMP::registerTorchConversionPasses();
mlir::NPCOMP::CommonBackend::registerCommonBackendPasses();
}

View File

@ -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.

View File

@ -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<?x?xf32>, %arg1: tensor<?x?xf32>) -> tensor<?x?xf32> {