Skip to content

Commit

Permalink
Revert "python: trim registration and loading of dialects and passes" (
Browse files Browse the repository at this point in the history
…llvm#1093)

This reverts commit ad283c1, since it's
causing nightly build failures for all platforms.
  • Loading branch information
ashay authored and gpetters94 committed Jul 27, 2022
1 parent fe4596b commit c9fddf9
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 73 deletions.
3 changes: 0 additions & 3 deletions include/torch-mlir-c/Registration.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ extern "C" {
*/
MLIR_CAPI_EXPORTED void torchMlirRegisterAllDialects(MlirContext context);

/** Registers upstream (MLIR) dialects used in Torch-MLIR IRs. */
MLIR_CAPI_EXPORTED void torchMlirRegisterRequiredDialects(MlirContext context);

/** Registers all passes for symbolic access with the global registry. */
MLIR_CAPI_EXPORTED void torchMlirRegisterAllPasses();

Expand Down
17 changes: 0 additions & 17 deletions lib/CAPI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,6 @@ add_mlir_public_c_api_library(TorchMLIRCAPI

LINK_LIBS PUBLIC
MLIRIR
MLIRAffineToStandard
MLIRArithmeticToLLVM
MLIRArithmeticTransforms
MLIRBufferizationTransforms
MLIRControlFlowToLLVM
MLIRFuncToLLVM
MLIRFuncTransforms
MLIRLinalgToLLVM
MLIRLinalgTransforms
MLIRMathToLLVM
MLIRMemRefToLLVM
MLIRReconcileUnrealizedCasts
MLIRSCFToControlFlow
MLIRSCFTransforms
MLIRTensorTransforms
MLIRTosaToArith
MLIRTosaToLinalg
MLIRSupport
TorchMLIRTorchDialect
TorchMLIRInitAll
Expand Down
44 changes: 4 additions & 40 deletions lib/CAPI/Registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,11 @@
#include "torch-mlir-c/Registration.h"

#include "mlir/CAPI/IR.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
#include "mlir/Dialect/Bufferization/IR/Bufferization.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/Linalg/IR/Linalg.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
#include "mlir/Dialect/Tosa/IR/TosaOps.h"
#include "mlir/InitAllPasses.h"
#include "mlir/Conversion/Passes.h"
#include "mlir/Dialect/Linalg/Passes.h"
#include "mlir/Transforms/Passes.h"
#include "torch-mlir/InitAll.h"

void torchMlirRegisterRequiredDialects(MlirContext context) {
mlir::DialectRegistry registry;
registry.insert<mlir::AffineDialect, mlir::arith::ArithmeticDialect,
mlir::bufferization::BufferizationDialect,
mlir::func::FuncDialect, mlir::linalg::LinalgDialect,
mlir::scf::SCFDialect, mlir::tensor::TensorDialect,
mlir::tosa::TosaDialect>();
unwrap(context)->appendDialectRegistry(registry);
}

void torchMlirRegisterAllDialects(MlirContext context) {
mlir::DialectRegistry registry;
mlir::torch::registerAllDialects(registry);
Expand All @@ -39,24 +23,4 @@ void torchMlirRegisterAllDialects(MlirContext context) {
unwrap(context)->loadAllAvailableDialects();
}

void torchMlirRegisterAllPasses() {
mlir::arith::registerArithmeticPasses();
mlir::bufferization::registerBufferizationPasses();
mlir::func::registerFuncPasses();
mlir::registerConvertAffineToStandardPass();
mlir::registerConvertArithmeticToLLVMPass();
mlir::registerConvertControlFlowToLLVMPass();
mlir::registerConvertFuncToLLVMPass();
mlir::registerConvertLinalgToLLVMPass();
mlir::registerConvertMathToLLVMPass();
mlir::registerConvertMemRefToLLVMPass();
mlir::registerLinalgPasses();
mlir::registerReconcileUnrealizedCastsPass();
mlir::registerSCFPasses();
mlir::registerSCFToControlFlowPass();
mlir::registerTosaToArithPass();
mlir::registerTosaToLinalgNamedPass();
mlir::registerTosaToLinalgPass();
mlir::tensor::registerTensorPasses();
mlir::torch::registerAllPasses();
}
void torchMlirRegisterAllPasses() { mlir::torch::registerAllPasses(); }
13 changes: 9 additions & 4 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ declare_mlir_python_sources(TorchMLIRPythonSources.TopLevel
SOURCES
__init__.py
compiler_utils.py
_mlir_libs/_site_initialize_0.py
)

declare_mlir_python_sources(TorchMLIRPythonSources.Dialects
Expand Down Expand Up @@ -103,10 +102,16 @@ add_subdirectory(torch_mlir/eager_mode)
################################################################################

set(_source_components
MLIRPythonSources.Core
MLIRPythonSources.Dialects.func
MLIRPythonSources.ExecutionEngine
# TODO: Core is now implicitly building/registering all dialects, increasing
# build burden by ~5x. Make it stop.
# TODO: Reduce dependencies. We need ExecutionEngine and a bunch of passes
# for the reference backend, but logically they can be separate. But seemingly
# the only way to handle that is to create a separate mlir python package
# tree, which seems excessive.
MLIRPythonSources
MLIRPythonExtension.Core
MLIRPythonExtension.RegisterEverything
MLIRPythonExtension.ExecutionEngine
TorchMLIRPythonSources
TorchMLIRPythonExtensions
)
Expand Down
13 changes: 10 additions & 3 deletions python/TorchMLIRModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "mlir-c/Bindings/Python/Interop.h"
#include "mlir/Bindings/Python/PybindAdaptors.h"
#include "mlir/CAPI/IR.h"
#include "torch-mlir-c/Dialects.h"
#include "torch-mlir-c/Registration.h"

Expand All @@ -20,6 +19,14 @@ PYBIND11_MODULE(_torchMlir, m) {

m.doc() = "torch-mlir main python extension";

m.def("register_required_dialects", torchMlirRegisterRequiredDialects,
py::arg("context"));
m.def(
"register_dialect",
[](MlirContext context, bool load) {
MlirDialectHandle handle = mlirGetDialectHandle__torch__();
mlirDialectHandleRegisterDialect(handle, context);
if (load) {
mlirDialectHandleLoadDialect(handle, context);
}
},
py::arg("context"), py::arg("load") = true);
}
4 changes: 0 additions & 4 deletions python/torch_mlir/_mlir_libs/_site_initialize_0.py

This file was deleted.

2 changes: 1 addition & 1 deletion python/torch_mlir/dialects/torch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# Also available under a BSD-style license. See LICENSE.

from .._torch_ops_gen import *
from ..._mlir_libs._torchMlir import register_required_dialects
from ..._mlir_libs._torchMlir import register_dialect
2 changes: 1 addition & 1 deletion test/python/smoketest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from torch_mlir.dialects import torch

with torch_mlir.ir.Context() as ctx:
torch.register_required_dialects(ctx)
torch.register_dialect(ctx)

0 comments on commit c9fddf9

Please sign in to comment.