Skip to content

Commit

Permalink
remove src/Compiler dependencies from src/{Builder,Transform,Conversi…
Browse files Browse the repository at this point in the history
…on} (#2506)

Signed-off-by: Soren Lassen <[email protected]>
  • Loading branch information
sorenlassen authored Sep 15, 2023
1 parent 3b71a60 commit 110437f
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/Builder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ add_onnx_mlir_library(OMBuilder
ModelInputShaper.cpp

LINK_LIBS PUBLIC
OMCompilerOptions
OMHasOnnxSubgraphOpInterface
OMONNXOps
OMResultTypeInferenceOpInterface
Expand Down
3 changes: 1 addition & 2 deletions src/Builder/FrontendDialectTransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "src/Builder/ImportONNXUtils.hpp"
#include "src/Builder/ModelInputShaper.hpp"
#include "src/Builder/SymbolTable.hpp"
#include "src/Compiler/CompilerOptions.hpp"
#include "src/Dialect/ONNX/DialectBuilder.hpp"
#include "src/Dialect/ONNX/ONNXOps.hpp"
#include "src/Dialect/ONNX/ONNXOps/OpHelper.hpp"
Expand Down Expand Up @@ -165,7 +164,7 @@ class FrontendGenImpl {
opset_map_ = GetOpsetImportsFromProto(model); // Which opsets to use.
in_model_functions_ = GetModelLocalFunctions(model);
importGraph(model.graph());
if (VerboseOutput) {
if (options_.verboseOutput) {
llvm::outs()
<< "The ONNX model has " << num_of_parameters_
<< " elements in its initializers. This value would be close to and "
Expand Down
1 change: 1 addition & 0 deletions src/Builder/FrontendDialectTransformer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace onnx_mlir {
* Options to control the translation of an ONNX model to ONNX-MLIR.
*/
struct ImportOptions {
bool verboseOutput = false;
// Use types/shapes in the input-model for translation (for intermediate
// variables)
bool useOnnxModelTypes = false;
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/CompilerPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void addONNXToMLIRPasses(mlir::PassManager &pm, bool targetCPU) {
// Dynamic iterate in ONNXOpTransformPass
pm.addPass(onnx_mlir::createONNXOpTransformPass(onnxOpTransformThreshold,
onnxOpTransformReport, targetCPU,
enableSimdDataLayout && !disableSimdOption));
enableSimdDataLayout && !disableSimdOption, enableConvOptPass));
} else {
// Statically add extra passes
for (int i = 0; i < repeatOnnxTransform; i++) {
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/CompilerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ int processInputFile(StringRef inputFilename, mlir::MLIRContext &context,

if (inputIsSTDIN || inputIsONNX || inputIsONNXText || inputIsJSON) {
ImportOptions options;
options.verboseOutput = VerboseOutput;
options.useOnnxModelTypes = useOnnxModelTypes;
options.invokeOnnxVersionConverter = invokeOnnxVersionConverter;
options.shapeInformation = shapeInformation;
Expand Down
1 change: 0 additions & 1 deletion src/Conversion/KrnlToAffine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ add_onnx_mlir_library(OMKrnlToAffine

LINK_LIBS PUBLIC
OMSpecializedKernelOpInterface
OMCompilerOptions
OMONNXOps
OMSupport
MLIRTransforms
Expand Down
3 changes: 0 additions & 3 deletions src/Conversion/KrnlToAffine/ConvertKrnlToAffine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "mlir/Transforms/LoopInvariantCodeMotionUtils.h"
#include "llvm/Support/Debug.h"

#include "src/Compiler/CompilerOptions.hpp"
#include "src/Conversion/KrnlToAffine/ConvertKrnlToAffine.hpp"
#include "src/Dialect/Krnl/KrnlOps.hpp"
#include "src/Dialect/Mlir/VectorMachineSupport.hpp"
Expand Down Expand Up @@ -712,7 +711,6 @@ void ConvertKrnlToAffinePass::runOnOperation() {

MLIRContext *ctx = &getContext();
OpBuilder builder(ctx);
VectorMachineSupport::setGlobalVectorMachineSupport(march, mcpu, "");

const auto &dataLayoutAnalysis = getAnalysis<DataLayoutAnalysis>();
LowerToLLVMOptions options(
Expand Down Expand Up @@ -821,7 +819,6 @@ void ConvertKrnlToAffinePass::runOnOperation() {
}

delete currUnrollAndJamList;
VectorMachineSupport::clearGlobalVectorMachineSupport();
}

std::unique_ptr<Pass> createConvertKrnlToAffinePass() {
Expand Down
1 change: 0 additions & 1 deletion src/Conversion/ONNXToKrnl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ add_onnx_mlir_library(OMONNXToKrnl

LINK_LIBS PUBLIC
OMAccelerator
OMCompilerOptions
OMONNXOps
OMSupport
MLIRFuncDialect
Expand Down
4 changes: 0 additions & 4 deletions src/Conversion/ONNXToKrnl/ConvertONNXToKrnl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include "src/Accelerators/Accelerator.hpp"
#include "src/Builder/ModelInputShaper.hpp"
#include "src/Compiler/CompilerOptions.hpp"
#include "src/Conversion/ONNXToKrnl/ONNXToKrnlCommon.hpp"
#include "src/Dialect/Mlir/VectorMachineSupport.hpp"

Expand Down Expand Up @@ -335,8 +334,6 @@ struct FrontendToKrnlLoweringPass

void FrontendToKrnlLoweringPass::runOnOperation() {
ModuleOp module = getOperation();
// Define vector machine.
VectorMachineSupport::setGlobalVectorMachineSupport(march, mcpu, "");
// Perform dim analysis (useful for SIMD but also to avoid broadcast
// expressions in index access patterns).
DimAnalysis *dimAnalysis = new DimAnalysis(module);
Expand Down Expand Up @@ -441,7 +438,6 @@ void FrontendToKrnlLoweringPass::runOnOperation() {
if (failed(applyPartialConversion(module, target, std::move(patterns)))) {
signalPassFailure();
}
VectorMachineSupport::clearGlobalVectorMachineSupport();
delete dimAnalysis;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Pass/Passes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ std::unique_ptr<mlir::Pass> createScrubDisposablePass(bool closeAfter = true);

/// Pass for ONNX graph level optimization
std::unique_ptr<mlir::Pass> createONNXOpTransformPass();
std::unique_ptr<mlir::Pass> createONNXOpTransformPass(
int threshold, bool report, bool targetCPU, bool enableSimdDataLayoutOpt);
std::unique_ptr<mlir::Pass> createONNXOpTransformPass(int threshold,
bool report, bool targetCPU, bool enableSimdDataLayoutOpt,
bool enableConvOptPass);

/// Pass for rewriting inside frontend dialect.
std::unique_ptr<mlir::Pass> createDecomposeONNXToONNXPass(
Expand Down
1 change: 0 additions & 1 deletion src/Transform/ONNX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ add_onnx_mlir_library(OMShapeInferencePass
OMShapeInferenceOpInterface
MLIRFuncDialect
MLIRPass
OMCompilerOptions
OMShapeInference
)

Expand Down
16 changes: 10 additions & 6 deletions src/Transform/ONNX/ONNXOpTransformPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "mlir/Pass/PassManager.h"
#include "mlir/Transforms/Passes.h"

#include "src/Compiler/CompilerOptions.hpp"
#include "src/Dialect/ONNX/ONNXOps.hpp"
#include "src/Pass/Passes.hpp"

Expand Down Expand Up @@ -47,17 +46,21 @@ struct ONNXOpTransformPass : public mlir::PassWrapper<ONNXOpTransformPass,
"onnx-op-transform-simd-data-layout",
llvm::cl::desc("Enable SIMD data layout opt in op transform passes."),
llvm::cl::init(false)};
Option<bool> enableConvOptPass{*this, "enable-conv-opt-pass",
llvm::cl::desc("Enable the ConvOptPass. Default is true."),
llvm::cl::init(true)};

ONNXOpTransformPass() = default;
ONNXOpTransformPass(const ONNXOpTransformPass &pass)
: mlir::PassWrapper<ONNXOpTransformPass,
OperationPass<mlir::ModuleOp>>() {}
ONNXOpTransformPass(int threshold, bool report, bool targetCPU,
bool enableSimdDataLayoutOpt) {
bool enableSimdDataLayoutOpt, bool enableConvOptPass) {
this->onnxOpTransformThreshold = threshold;
this->onnxOpTransformReport = report;
this->onnxOpTransformTargetCPU = targetCPU;
this->onnxOpTransformEnableSimdDataLayout = enableSimdDataLayoutOpt;
this->enableConvOptPass = enableConvOptPass;
}

void runOnOperation() final;
Expand All @@ -79,7 +82,7 @@ void ONNXOpTransformPass::runOnOperation() {
dynamicPM.addNestedPass<func::FuncOp>(
onnx_mlir::createShapeInferencePass());
// Convolution Optimization currently only for CPU.
if (onnxOpTransformTargetCPU && onnx_mlir::enableConvOptPass) {
if (onnxOpTransformTargetCPU && enableConvOptPass) {
dynamicPM.addNestedPass<func::FuncOp>(
onnx_mlir::createConvOptONNXToONNXPass(
onnxOpTransformEnableSimdDataLayout));
Expand Down Expand Up @@ -116,8 +119,9 @@ std::unique_ptr<mlir::Pass> onnx_mlir::createONNXOpTransformPass() {
return std::make_unique<ONNXOpTransformPass>();
}

std::unique_ptr<mlir::Pass> onnx_mlir::createONNXOpTransformPass(
int threshold, bool report, bool targetCPU, bool enableSimdDataLayoutOpt) {
std::unique_ptr<mlir::Pass> onnx_mlir::createONNXOpTransformPass(int threshold,
bool report, bool targetCPU, bool enableSimdDataLayoutOpt,
bool enableConvOptPass) {
return std::make_unique<ONNXOpTransformPass>(
threshold, report, targetCPU, enableSimdDataLayoutOpt);
threshold, report, targetCPU, enableSimdDataLayoutOpt, enableConvOptPass);
}

0 comments on commit 110437f

Please sign in to comment.