diff --git a/MLIR.cmake b/MLIR.cmake index ee46e82..4f87d3b 100644 --- a/MLIR.cmake +++ b/MLIR.cmake @@ -200,7 +200,8 @@ function(onnx_mlir_tablegen ofn) tablegen(MLIR ${ARGV} "-I${MLIR_SRC_INCLUDE_PATH}" - "-I${MLIR_BIN_INCLUDE_PATH}") + "-I${MLIR_BIN_INCLUDE_PATH}" + "-I${ONNX_MLIR_SRC_ROOT}") set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn} PARENT_SCOPE) diff --git a/src/Builder/CMakeLists.txt b/src/Builder/CMakeLists.txt index d917d81..147d4fb 100644 --- a/src/Builder/CMakeLists.txt +++ b/src/Builder/CMakeLists.txt @@ -1,15 +1,20 @@ -add_library(builder +add_library(OMBuilder FrontendDialectHelper.cpp FrontendDialectHelper.hpp FrontendDialectTransformer.cpp FrontendDialectTransformer.hpp OpBuildTable.inc) -target_include_directories(builder PRIVATE ${CMAKE_SOURCE_DIR}) -target_include_directories(builder PRIVATE ${CMAKE_BINARY_DIR}) +target_include_directories(OMBuilder PRIVATE ${CMAKE_SOURCE_DIR}) +target_include_directories(OMBuilder PRIVATE ${CMAKE_BINARY_DIR}) -target_link_libraries(builder compiler onnx ${MLIRLibs} curses mpark_variant) -target_include_directories(builder +target_link_libraries(OMBuilder + OMONNXOps + onnx + ${MLIRLibs} + curses + mpark_variant) +target_include_directories(OMBuilder PUBLIC ${CMAKE_SOURCE_DIR}/third_party/onnx ${CMAKE_SOURCE_DIR}/third_party/variant diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 07fc656..1fccb7c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,127 +1,25 @@ -add_library(compiler - Dialect/Krnl/KrnlOps.cpp - Dialect/Krnl/KrnlOps.hpp - Dialect/Krnl/KrnlTypes.cpp - Dialect/Krnl/KrnlTypes.hpp - Dialect/ONNX/ONNXOps.cpp - Dialect/ONNX/ONNXOps.hpp - Dialect/Krnl/KrnlHelper.cpp - Dialect/Krnl/KrnlHelper.hpp - Pass/ShapeInferenceInterface.hpp - Pass/ONNXCombine.cpp - Pass/ONNXRewrite.cpp - Pass/ONNXDecompose.cpp - Pass/Passes.hpp) - -# Include root src directory. -target_include_directories(compiler PRIVATE ${ONNX_MLIR_SRC_ROOT}) - -# Include tablegen generated header files. -target_include_directories(compiler PRIVATE ${ONNX_MLIR_BIN_ROOT}) - -target_link_libraries(compiler - ${CMAKE_THREAD_LIBS_INIT} - ${CMAKE_DL_LIBS} - ${MLIRLibs} - curses) - -set(LLVM_TARGET_DEFINITIONS Pass/ONNXDecompose.td) -onnx_mlir_tablegen(onnx_decompose.inc -gen-rewriters) -add_public_tablegen_target(gen_onnx_decompose) -add_dependencies(compiler gen_onnx_decompose) - -set(LLVM_TARGET_DEFINITIONS Pass/ShapeInferenceInterface.td) -onnx_mlir_tablegen(shape_inference.hpp.inc -gen-op-interface-decls) -onnx_mlir_tablegen(shape_inference.cpp.inc -gen-op-interface-defs) -add_public_tablegen_target(gen_shape_inference) -add_dependencies(compiler gen_shape_inference) - -set(LLVM_TARGET_DEFINITIONS Pass/ONNXCombine.td) -onnx_mlir_tablegen(onnx_combine.inc -gen-rewriters) -add_public_tablegen_target(gen_onnx_combine) -add_dependencies(compiler gen_onnx_combine) - -set(LLVM_TARGET_DEFINITIONS Pass/ONNXRewrite.td) -onnx_mlir_tablegen(onnx_rewrite.inc -gen-rewriters) -add_public_tablegen_target(gen_onnx_rewrite) -add_dependencies(compiler gen_onnx_rewrite) - add_subdirectory(Interface) - -set(LLVM_TARGET_DEFINITIONS Dialect/ONNX/ONNXOps.td) -onnx_mlir_tablegen(onnx.hpp.inc -gen-op-decls "-I${CMAKE_SOURCE_DIR}/compiler/pass") -onnx_mlir_tablegen(onnx.cpp.inc -gen-op-defs "-I${CMAKE_SOURCE_DIR}/compiler/pass") -set(GEN_DOC_FILE ${CMAKE_BINARY_DIR}/docs/Dialects/onnx.md) -add_public_tablegen_target(gen_onnx) - -add_dependencies(gen_onnx gen_shape_inference) -add_dependencies(compiler gen_onnx) - -# TODO: onnx_mlir_gen_promotable_const_operands_op_interface is really a -# dependency of the onnx dialect library, which is currently part of `compiler`. -add_dependencies(compiler onnx_mlir_gen_promotable_const_operands_op_interface) - -add_onnx_mlir_dialect_doc(onnx Dialect/ONNX/ONNXOps.td) - -set(LLVM_TARGET_DEFINITIONS Dialect/Krnl/KrnlOps.td) -onnx_mlir_tablegen(krnl.hpp.inc -gen-op-decls) -onnx_mlir_tablegen(krnl.cpp.inc -gen-op-defs) -add_public_tablegen_target(gen_krnl_ops) -add_dependencies(compiler gen_krnl_ops) - -add_library(onnx_mlir_onnx_decompose Pass/ONNXDecompose.cpp) -target_include_directories(onnx_mlir_onnx_decompose - PRIVATE ${ONNX_MLIR_SRC_ROOT} ${ONNX_MLIR_BIN_ROOT} - ${ONNX_MLIR_SRC_ROOT}) -target_link_libraries(onnx_mlir_onnx_decompose ${MLIRLibs}) -add_dependencies(onnx_mlir_onnx_decompose gen_onnx) - -add_library(onnx_mlir_shape_inference Pass/ShapeInferencePass.cpp) -target_include_directories(onnx_mlir_shape_inference - PRIVATE ${ONNX_MLIR_SRC_ROOT} ${ONNX_MLIR_BIN_ROOT} - ${ONNX_MLIR_SRC_ROOT}) -target_link_libraries(onnx_mlir_shape_inference ${MLIRLibs}) -add_dependencies(onnx_mlir_shape_inference gen_onnx) - -add_library(onnx_mlir_lower_frontend - Conversion/ONNXToKrnl/ONNXToKrnlCommon.cpp - Conversion/ONNXToKrnl/ONNXToKrnlCommon.hpp - Conversion/ONNXToKrnl/Math/Elementwise.cpp - Conversion/ONNXToKrnl/Math/Gemm.cpp - Conversion/ONNXToKrnl/Math/MatMul.cpp - Conversion/ONNXToKrnl/Math/Reduction.cpp - Conversion/ONNXToKrnl/Math/Softmax.cpp - Conversion/ONNXToKrnl/NN/Conv.cpp - Conversion/ONNXToKrnl/NN/Normalization.cpp - Conversion/ONNXToKrnl/NN/Pooling.cpp - Conversion/ONNXToKrnl/Tensor/Identity.cpp - Conversion/ONNXToKrnl/Tensor/Reshape.cpp - Conversion/ONNXToKrnl/Tensor/PadConstantValuePad.cpp - Conversion/ONNXToKrnl/Tensor/Transpose.cpp - Conversion/ONNXToKrnl/Tensor/Unsqueeze.cpp - Conversion/ONNXToKrnl/Tensor/Constant.cpp - Conversion/ONNXToKrnl/ConvertONNXToKrnl.cpp) -target_include_directories(onnx_mlir_lower_frontend - PRIVATE ${ONNX_MLIR_SRC_ROOT} ${ONNX_MLIR_BIN_ROOT} - ${ONNX_MLIR_SRC_ROOT}) -target_link_libraries(onnx_mlir_lower_frontend ${MLIRLibs}) -add_dependencies(onnx_mlir_lower_frontend gen_krnl_ops) - +add_subdirectory(Dialect) +add_subdirectory(Conversion) add_subdirectory(Transform) add_subdirectory(Tool) add_subdirectory(Builder) add_subdirectory(Runtime) add_executable(onnx-mlir main.cpp) - target_link_libraries(onnx-mlir - builder ${MLIRLibs} - onnx_mlir_transform - onnx_mlir_onnx_decompose - onnx_mlir_shape_inference - onnx_mlir_lower_frontend - onnx_mlir_attribute_promotion) + OMBuilder + OMKrnlOps + OMONNXOps + OMKrnlToAffine + OMKrnlToLLVM + OMShapeInference + OMONNXToKrnl + OMONNXRewrite + OMAttributePromotion + ${CMAKE_THREAD_LIBS_INIT} + ${CMAKE_DL_LIBS}) whole_archive_link_mlir(onnx-mlir ${MLIRWholeArchiveLibs}) diff --git a/src/Conversion/CMakeLists.txt b/src/Conversion/CMakeLists.txt new file mode 100644 index 0000000..d9797c0 --- /dev/null +++ b/src/Conversion/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(ONNXToKrnl) \ No newline at end of file diff --git a/src/Conversion/ONNXToKrnl/CMakeLists.txt b/src/Conversion/ONNXToKrnl/CMakeLists.txt new file mode 100644 index 0000000..9f027cd --- /dev/null +++ b/src/Conversion/ONNXToKrnl/CMakeLists.txt @@ -0,0 +1,26 @@ +add_library(OMONNXToKrnl + ONNXToKrnlCommon.cpp + ONNXToKrnlCommon.hpp + Math/Elementwise.cpp + Math/Gemm.cpp + Math/MatMul.cpp + Math/Reduction.cpp + Math/Softmax.cpp + NN/Conv.cpp + NN/Normalization.cpp + NN/Pooling.cpp + Tensor/Identity.cpp + Tensor/Reshape.cpp + Tensor/PadConstantValuePad.cpp + Tensor/Transpose.cpp + Tensor/Unsqueeze.cpp + Tensor/Constant.cpp + ConvertONNXToKrnl.cpp) +target_include_directories(OMONNXToKrnl + PRIVATE + ${ONNX_MLIR_SRC_ROOT} + ${ONNX_MLIR_BIN_ROOT} + ${ONNX_MLIR_SRC_ROOT}) +target_link_libraries(OMONNXToKrnl + ${MLIRLibs} + OMKrnlOps) \ No newline at end of file diff --git a/src/Dialect/CMakeLists.txt b/src/Dialect/CMakeLists.txt new file mode 100644 index 0000000..52599c3 --- /dev/null +++ b/src/Dialect/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(Krnl) +add_subdirectory(ONNX) \ No newline at end of file diff --git a/src/Dialect/Krnl/CMakeLists.txt b/src/Dialect/Krnl/CMakeLists.txt new file mode 100644 index 0000000..b1dd052 --- /dev/null +++ b/src/Dialect/Krnl/CMakeLists.txt @@ -0,0 +1,18 @@ +set(LLVM_TARGET_DEFINITIONS KrnlOps.td) +onnx_mlir_tablegen(KrnlOps.hpp.inc -gen-op-decls) +onnx_mlir_tablegen(KrnlOps.cpp.inc -gen-op-defs) +add_public_tablegen_target(OMKrnlOpsIncGen) + +add_library(OMKrnlOps + KrnlOps.hpp + KrnlOps.cpp + KrnlTypes.hpp + KrnlTypes.cpp + KrnlHelper.hpp + KrnlHelper.cpp) +target_include_directories(OMKrnlOps + PRIVATE + ${ONNX_MLIR_SRC_ROOT} + ${ONNX_MLIR_BIN_ROOT} + ${ONNX_MLIR_SRC_ROOT}) +add_dependencies(OMKrnlOps OMKrnlOpsIncGen) \ No newline at end of file diff --git a/src/Dialect/Krnl/KrnlOps.cpp b/src/Dialect/Krnl/KrnlOps.cpp index 190f5c7..05fc8d6 100644 --- a/src/Dialect/Krnl/KrnlOps.cpp +++ b/src/Dialect/Krnl/KrnlOps.cpp @@ -37,7 +37,7 @@ KrnlOpsDialect::KrnlOpsDialect(MLIRContext *context) : Dialect(getDialectNamespace(), context) { addOperations< #define GET_OP_LIST -#include "src/krnl.cpp.inc" +#include "src/Dialect/Krnl/KrnlOps.cpp.inc" >(); addTypes(); } @@ -375,5 +375,5 @@ void KrnlEntryPointOp::build(mlir::Builder *builder, OperationState &state, } #define GET_OP_CLASSES -#include "src/krnl.cpp.inc" +#include "src/Dialect/Krnl/KrnlOps.cpp.inc" } // namespace mlir diff --git a/src/Dialect/Krnl/KrnlOps.hpp b/src/Dialect/Krnl/KrnlOps.hpp index 435c2fe..351c8ca 100644 --- a/src/Dialect/Krnl/KrnlOps.hpp +++ b/src/Dialect/Krnl/KrnlOps.hpp @@ -45,5 +45,5 @@ public: }; #define GET_OP_CLASSES -#include "src/krnl.hpp.inc" +#include "src/Dialect/Krnl/KrnlOps.hpp.inc" } // namespace mlir diff --git a/src/Dialect/ONNX/CMakeLists.txt b/src/Dialect/ONNX/CMakeLists.txt index e69de29..fbe1948 100644 --- a/src/Dialect/ONNX/CMakeLists.txt +++ b/src/Dialect/ONNX/CMakeLists.txt @@ -0,0 +1,20 @@ +set(LLVM_TARGET_DEFINITIONS ONNXOps.td) +onnx_mlir_tablegen(ONNXOps.hpp.inc -gen-op-decls "-I${CMAKE_SOURCE_DIR}/compiler/pass") +onnx_mlir_tablegen(ONNXOps.cpp.inc -gen-op-defs "-I${CMAKE_SOURCE_DIR}/compiler/pass") +set(GEN_DOC_FILE ${CMAKE_BINARY_DIR}/docs/Dialects/onnx.md) +add_public_tablegen_target(OMONNXOpsIncGen) + +add_library(OMONNXOps + ONNXOps.cpp + ONNXOps.hpp) +target_include_directories(OMONNXOps + PRIVATE + ${ONNX_MLIR_SRC_ROOT} + ${ONNX_MLIR_BIN_ROOT} + ${ONNX_MLIR_SRC_ROOT}) +add_dependencies(OMONNXOps OMONNXOpsIncGen) +target_link_libraries(OMONNXOps + OMPromotableConstOperandsOpInterface + OMShapeInferenceOpInterface) + +add_onnx_mlir_dialect_doc(onnx ONNXOps.td) \ No newline at end of file diff --git a/src/Dialect/ONNX/ONNXOps.cpp b/src/Dialect/ONNX/ONNXOps.cpp index 7911a86..d976e4c 100644 --- a/src/Dialect/ONNX/ONNXOps.cpp +++ b/src/Dialect/ONNX/ONNXOps.cpp @@ -310,7 +310,7 @@ ONNXOpsDialect::ONNXOpsDialect(mlir::MLIRContext *ctx) : mlir::Dialect(getDialectNamespace(), ctx) { addOperations< #define GET_OP_LIST -#include "src/onnx.cpp.inc" +#include "src/Dialect/ONNX/ONNXOps.cpp.inc" >(); } @@ -1325,4 +1325,4 @@ void ONNXConstantOp::inferShapes() { //===----------------------------------------------------------------------===// #define GET_OP_CLASSES -#include "src/onnx.cpp.inc" +#include "src/Dialect/ONNX/ONNXOps.cpp.inc" diff --git a/src/Dialect/ONNX/ONNXOps.hpp b/src/Dialect/ONNX/ONNXOps.hpp index fbf5c54..6b8b413 100644 --- a/src/Dialect/ONNX/ONNXOps.hpp +++ b/src/Dialect/ONNX/ONNXOps.hpp @@ -19,7 +19,7 @@ #include "mlir/IR/OpDefinition.h" #include "mlir/IR/StandardTypes.h" -#include "src/Pass/ShapeInferenceInterface.hpp" +#include "src/Interface/ShapeInferenceInterface.hpp" #include "src/Interface/PromotableConstOperandsOpInterface.hpp" namespace mlir { @@ -36,7 +36,7 @@ class ONNXOpsDialect : public Dialect { /// Include the auto-generated header file containing the declarations of the /// ONNX operations. #define GET_OP_CLASSES -#include "src/onnx.hpp.inc" +#include "src/Dialect/ONNX/ONNXOps.hpp.inc" } // end namespace mlir diff --git a/src/Dialect/ONNX/ONNXOps.td b/src/Dialect/ONNX/ONNXOps.td index e4251f2..e48973b 100644 --- a/src/Dialect/ONNX/ONNXOps.td +++ b/src/Dialect/ONNX/ONNXOps.td @@ -19,12 +19,12 @@ include "mlir/IR/OpBase.td" #ifdef SHAPE_INFERENCE_INTERFACE #else -include "Pass/ShapeInferenceInterface.td" +include "src/Interface/ShapeInferenceInterface.td" #endif // SHAPE_INFERENCE_INTERFACE #ifdef PROMOTABLE_CONST_OPERANDS_OP_INTERFACE #else -include "Interface/PromotableConstOperandsOpInterface.td" +include "src/Interface/PromotableConstOperandsOpInterface.td" #endif // PROMOTABLE_CONST_OPERANDS_OP_INTERFACE def ONNX_Dialect : Dialect { @@ -61,7 +61,7 @@ class ONNX_Op traits = []> : // 4. type of string, complex64 and complex128 for input/output are ignored // 5. unsigned int are treated as signed one -include "Dialect/ONNX/ONNXOps.td.inc" +include "src/Dialect/ONNX/ONNXOps.td.inc" // Indicate entry point functions of ONNX graph. def ONNXEntryPointOp: ONNX_Op<"EntryPoint"> { diff --git a/src/Interface/CMakeLists.txt b/src/Interface/CMakeLists.txt index 4503766..e6ab929 100644 --- a/src/Interface/CMakeLists.txt +++ b/src/Interface/CMakeLists.txt @@ -1,14 +1,27 @@ set(LLVM_TARGET_DEFINITIONS PromotableConstOperandsOpInterface.td) -onnx_mlir_tablegen(promotable_const_operands_op_interface.hpp.inc -gen-op-interface-decls) -onnx_mlir_tablegen(promotable_const_operands_op_interface.cpp.inc -gen-op-interface-defs) -add_public_tablegen_target(onnx_mlir_gen_promotable_const_operands_op_interface) +onnx_mlir_tablegen(PromotableConstOperandsOpInterface.hpp.inc -gen-op-interface-decls) +onnx_mlir_tablegen(PromotableConstOperandsOpInterface.cpp.inc -gen-op-interface-defs) +add_public_tablegen_target(OMPromotableConstOperandsOpInterfaceIncGen) -add_library(onnx_mlir_promotable_const_operands_op_interface +add_library(OMPromotableConstOperandsOpInterface PromotableConstOperandsOpInterface.hpp PromotableConstOperandsOpInterface.cpp) -target_include_directories(onnx_mlir_promotable_const_operands_op_interface +target_include_directories(OMPromotableConstOperandsOpInterface PRIVATE ${ONNX_MLIR_SRC_ROOT} ${ONNX_MLIR_BIN_ROOT} ${ONNX_MLIR_SRC_ROOT}) +add_dependencies(OMPromotableConstOperandsOpInterface + OMPromotableConstOperandsOpInterfaceIncGen) -add_dependencies(onnx_mlir_promotable_const_operands_op_interface - onnx_mlir_gen_promotable_const_operands_op_interface) \ No newline at end of file + +set(LLVM_TARGET_DEFINITIONS ShapeInferenceInterface.td) +onnx_mlir_tablegen(ShapeInference.hpp.inc -gen-op-interface-decls) +onnx_mlir_tablegen(ShapeInference.cpp.inc -gen-op-interface-defs) +add_public_tablegen_target(ShapeInferenceOpInterfaceIncGen) + +add_library(OMShapeInferenceOpInterface + ShapeInferenceInterface.hpp + ShapeInferenceInterface.cpp) +target_include_directories(OMShapeInferenceOpInterface + PRIVATE ${ONNX_MLIR_SRC_ROOT} ${ONNX_MLIR_BIN_ROOT} + ${ONNX_MLIR_SRC_ROOT}) +add_dependencies(OMShapeInferenceOpInterface ShapeInferenceOpInterfaceIncGen) \ No newline at end of file diff --git a/src/Interface/PromotableConstOperandsOpInterface.cpp b/src/Interface/PromotableConstOperandsOpInterface.cpp index ef341a5..92e20e2 100644 --- a/src/Interface/PromotableConstOperandsOpInterface.cpp +++ b/src/Interface/PromotableConstOperandsOpInterface.cpp @@ -1,4 +1,4 @@ -//===------------ promotable_const_operands_op_interface.cpp --------------===// +//===------------ PromotableConstOperandsOpInterface.cpp --------------===// //===-------- Promotable Const Operands Op Interface Definition -----------===// // // Copyright 2020 The IBM Research Authors. @@ -19,5 +19,5 @@ using namespace mlir; // Promotable Const Operands Op Interface //===----------------------------------------------------------------------===// -#include "src/Interface/promotable_const_operands_op_interface.cpp.inc" +#include "src/Interface/PromotableConstOperandsOpInterface.cpp.inc" diff --git a/src/Interface/PromotableConstOperandsOpInterface.hpp b/src/Interface/PromotableConstOperandsOpInterface.hpp index 129dfcc..a105fcb 100644 --- a/src/Interface/PromotableConstOperandsOpInterface.hpp +++ b/src/Interface/PromotableConstOperandsOpInterface.hpp @@ -1,4 +1,4 @@ -//===------------ promotable_const_operands_op_interface.cpp --------------===// +//===------------ PromotableConstOperandsOpInterface.hpp --------------===// //===-------- Promotable Const Operands Op Interface Definition -----------===// // // Copyright 2020 The IBM Research Authors. @@ -20,6 +20,6 @@ namespace mlir { /// Include the auto-generated declarations. -#include "src/Interface/promotable_const_operands_op_interface.hpp.inc" +#include "src/Interface/PromotableConstOperandsOpInterface.hpp.inc" } // end namespace mlir \ No newline at end of file diff --git a/src/Interface/PromotableConstOperandsOpInterface.td b/src/Interface/PromotableConstOperandsOpInterface.td index ccecb09..82e0890 100644 --- a/src/Interface/PromotableConstOperandsOpInterface.td +++ b/src/Interface/PromotableConstOperandsOpInterface.td @@ -1,4 +1,4 @@ -//===------------- promotable_const_operands_op_interface.td --------------===// +//===------------- PromotableConstOperandsOpInterface.td --------------===// //===---- Promotable Const Operands Op Interface TableGen Definition ------===// // // Copyright 2020 The IBM Research Authors. diff --git a/src/Interface/ShapeInferenceInterface.cpp b/src/Interface/ShapeInferenceInterface.cpp new file mode 100644 index 0000000..3b17e1f --- /dev/null +++ b/src/Interface/ShapeInferenceInterface.cpp @@ -0,0 +1,19 @@ +//===---- ShapeInferenceInterface.cpp - Definition for ShapeInference -----===// +// +// Copyright 2019-2020 The IBM Research Authors. +// +// ============================================================================= +// +// This file contains the implementations of the shape inference interfaces +// defined in ShapeInferenceInterface.td. +// +//===----------------------------------------------------------------------===// + +#include "src/Interface/ShapeInferenceInterface.hpp" + +namespace mlir { + +/// Include the auto-generated declarations. +#include "src/Interface/ShapeInference.cpp.inc" + +} // end namespace mlir diff --git a/src/Pass/ShapeInferenceInterface.hpp b/src/Interface/ShapeInferenceInterface.hpp similarity index 92% rename from src/Pass/ShapeInferenceInterface.hpp rename to src/Interface/ShapeInferenceInterface.hpp index e8a68b8..812a7b3 100644 --- a/src/Pass/ShapeInferenceInterface.hpp +++ b/src/Interface/ShapeInferenceInterface.hpp @@ -16,6 +16,6 @@ namespace mlir { /// Include the auto-generated declarations. -#include "src/shape_inference.hpp.inc" +#include "src/Interface/ShapeInference.hpp.inc" } // end namespace mlir diff --git a/src/Pass/ShapeInferenceInterface.td b/src/Interface/ShapeInferenceInterface.td similarity index 100% rename from src/Pass/ShapeInferenceInterface.td rename to src/Interface/ShapeInferenceInterface.td diff --git a/src/Tool/ONNXMLIROpt/CMakeLists.txt b/src/Tool/ONNXMLIROpt/CMakeLists.txt index 45289b9..30e6624 100644 --- a/src/Tool/ONNXMLIROpt/CMakeLists.txt +++ b/src/Tool/ONNXMLIROpt/CMakeLists.txt @@ -1,22 +1,25 @@ add_executable(onnx-mlir-opt ONNXMLIROpt.cpp) -add_dependencies(onnx-mlir-opt gen_krnl_ops) +add_dependencies(onnx-mlir-opt OMKrnlOpsIncGen) target_include_directories(onnx-mlir-opt PRIVATE ${ONNX_MLIR_SRC_ROOT}) target_include_directories(onnx-mlir-opt PRIVATE ${ONNX_MLIR_BIN_ROOT}) target_link_libraries(onnx-mlir-opt - builder ${MLIRLibs} - onnx_mlir_transform - onnx_mlir_shape_inference - onnx_mlir_lower_frontend - onnx_mlir_promotable_const_operands_op_interface + OMBuilder + OMKrnlOps + OMKrnlToAffine + OMKrnlToLLVM + OMShapeInference + OMONNXToKrnl + OMPromotableConstOperandsOpInterface curses) whole_archive_link_mlir(onnx-mlir-opt ${MLIRWholeArchiveLibs}) whole_archive_link_onnx_mlir(onnx-mlir-opt - compiler - onnx_mlir_transform - onnx_mlir_lower_frontend - onnx_mlir_shape_inference - onnx_mlir_attribute_promotion) \ No newline at end of file + OMKrnlToAffine + OMKrnlToLLVM + OMONNXToKrnl + OMONNXRewrite + OMShapeInference + OMAttributePromotion) \ No newline at end of file diff --git a/src/Transform/CMakeLists.txt b/src/Transform/CMakeLists.txt index f766236..728839d 100644 --- a/src/Transform/CMakeLists.txt +++ b/src/Transform/CMakeLists.txt @@ -1,11 +1,25 @@ -add_library(onnx_mlir_transform - LowerKrnl.cpp +add_library(OMKrnlToAffine + LowerKrnl.cpp) +target_include_directories(OMKrnlToAffine + PRIVATE + ${ONNX_MLIR_SRC_ROOT} + ${ONNX_MLIR_BIN_ROOT} + ${ONNX_MLIR_SRC_ROOT}) +target_link_libraries(OMKrnlToAffine + ${MLIRLibs} + OMKrnlOps + OMONNXOps) + +add_library(OMKrnlToLLVM LowerToLLVM.cpp) +target_include_directories(OMKrnlToLLVM + PRIVATE + ${ONNX_MLIR_SRC_ROOT} + ${ONNX_MLIR_BIN_ROOT} + ${ONNX_MLIR_SRC_ROOT}) +target_link_libraries(OMKrnlToLLVM + ${MLIRLibs} + OMKrnlOps + OMONNXOps) -target_include_directories(onnx_mlir_transform - PRIVATE ${ONNX_MLIR_SRC_ROOT} ${ONNX_MLIR_BIN_ROOT} - ${ONNX_MLIR_SRC_ROOT}) -target_link_libraries(onnx_mlir_transform ${MLIRLibs}) -add_dependencies(onnx_mlir_transform gen_krnl_ops) - -add_subdirectory(onnx) \ No newline at end of file +add_subdirectory(ONNX) \ No newline at end of file diff --git a/src/Transform/onnx/attribute_promotion.cpp b/src/Transform/ONNX/AttributePromotion.cpp similarity index 100% rename from src/Transform/onnx/attribute_promotion.cpp rename to src/Transform/ONNX/AttributePromotion.cpp diff --git a/src/Transform/ONNX/CMakeLists.txt b/src/Transform/ONNX/CMakeLists.txt new file mode 100644 index 0000000..7dce830 --- /dev/null +++ b/src/Transform/ONNX/CMakeLists.txt @@ -0,0 +1,42 @@ +add_library(OMAttributePromotion + AttributePromotion.cpp) +target_include_directories(OMAttributePromotion + PRIVATE ${ONNX_MLIR_SRC_ROOT} ${ONNX_MLIR_BIN_ROOT} + ${ONNF_MLIR_SRC_ROOT}) +target_link_libraries(OMAttributePromotion + OMPromotableConstOperandsOpInterface) + +set(LLVM_TARGET_DEFINITIONS ONNXRewrite.td) +onnx_mlir_tablegen(ONNXRewrite.inc -gen-rewriters) +add_public_tablegen_target(OMONNXRewriteIncGen) + +set(LLVM_TARGET_DEFINITIONS ONNXCombine.td) +onnx_mlir_tablegen(ONNXCombine.inc -gen-rewriters) +add_public_tablegen_target(OMONNXCombineIncGen) + +set(LLVM_TARGET_DEFINITIONS ONNXDecompose.td) +onnx_mlir_tablegen(ONNXDecompose.inc -gen-rewriters) +add_public_tablegen_target(OMONNXDecomposeIncGen) + +add_library(OMONNXRewrite + ONNXRewrite.cpp + ONNXCombine.cpp + ONNXDecompose.cpp) +target_include_directories(OMONNXRewrite + PRIVATE ${ONNX_MLIR_SRC_ROOT} ${ONNX_MLIR_BIN_ROOT} + ${ONNF_MLIR_SRC_ROOT}) +target_link_libraries(OMONNXRewrite + OMONNXOps) +add_dependencies(OMONNXRewrite + OMONNXRewriteIncGen + OMONNXDecomposeIncGen + OMONNXCombineIncGen) + +add_library(OMShapeInference ShapeInferencePass.cpp) +target_include_directories(OMShapeInference + PRIVATE ${ONNX_MLIR_SRC_ROOT} ${ONNX_MLIR_BIN_ROOT} + ${ONNX_MLIR_SRC_ROOT}) +target_link_libraries(OMShapeInference + ${MLIRLibs} + OMShapeInferenceOpInterface) +add_dependencies(OMShapeInference ShapeInferenceOpInterfaceIncGen) \ No newline at end of file diff --git a/src/Pass/ONNXCombine.cpp b/src/Transform/ONNX/ONNXCombine.cpp similarity index 97% rename from src/Pass/ONNXCombine.cpp rename to src/Transform/ONNX/ONNXCombine.cpp index 18d8f82..b549f0d 100644 --- a/src/Pass/ONNXCombine.cpp +++ b/src/Transform/ONNX/ONNXCombine.cpp @@ -19,7 +19,7 @@ using namespace mlir; namespace { /// Include the patterns defined in the Declarative Rewrite framework. -#include "src/onnx_combine.inc" +#include "src/Transform/ONNX/ONNXCombine.inc" } // end anonymous namespace /// Register optimization patterns as "canonicalization" patterns diff --git a/src/Pass/ONNXCombine.td b/src/Transform/ONNX/ONNXCombine.td similarity index 98% rename from src/Pass/ONNXCombine.td rename to src/Transform/ONNX/ONNXCombine.td index 0e8829f..610257c 100644 --- a/src/Pass/ONNXCombine.td +++ b/src/Transform/ONNX/ONNXCombine.td @@ -13,7 +13,7 @@ #define ONNX_COMBINE #ifndef OP_BASE -include "Dialect/ONNX/ONNXOps.td" +include "src/Dialect/ONNX/ONNXOps.td" #endif // OP_BASE /// Note: The DRR definition used for defining patterns is shown below: diff --git a/src/Pass/ONNXDecompose.cpp b/src/Transform/ONNX/ONNXDecompose.cpp similarity index 96% rename from src/Pass/ONNXDecompose.cpp rename to src/Transform/ONNX/ONNXDecompose.cpp index e75dc78..1145a73 100644 --- a/src/Pass/ONNXDecompose.cpp +++ b/src/Transform/ONNX/ONNXDecompose.cpp @@ -19,13 +19,13 @@ #include "mlir/Transforms/DialectConversion.h" #include "src/Dialect/ONNX/ONNXOps.hpp" -#include "Passes.hpp" +#include "src/Pass/Passes.hpp" using namespace mlir; namespace { /// Include the patterns defined in the Declarative Rewrite framework. -#include "src/onnx_decompose.inc" +#include "src/Transform/ONNX/ONNXDecompose.inc" struct DecomposeONNXToONNXPass : public FunctionPass { void runOnFunction() final; diff --git a/src/Pass/ONNXDecompose.td b/src/Transform/ONNX/ONNXDecompose.td similarity index 98% rename from src/Pass/ONNXDecompose.td rename to src/Transform/ONNX/ONNXDecompose.td index ae96aaa..3a0f35d 100644 --- a/src/Pass/ONNXDecompose.td +++ b/src/Transform/ONNX/ONNXDecompose.td @@ -13,7 +13,7 @@ #define ONNX_DECOMPOSE #ifndef OP_BASE -include "Dialect/ONNX/ONNXOps.td" +include "src/Dialect/ONNX/ONNXOps.td" #endif // OP_BASE /// Note: The DRR definition used for defining patterns is shown below: diff --git a/src/Pass/ONNXRewrite.cpp b/src/Transform/ONNX/ONNXRewrite.cpp similarity index 99% rename from src/Pass/ONNXRewrite.cpp rename to src/Transform/ONNX/ONNXRewrite.cpp index 3d28319..3985bdf 100644 --- a/src/Pass/ONNXRewrite.cpp +++ b/src/Transform/ONNX/ONNXRewrite.cpp @@ -68,7 +68,7 @@ ArrayAttr insertZerosForNonPaddedDims( } /// Include the patterns defined in the Declarative Rewrite framework. -#include "src/onnx_rewrite.inc" +#include "src/Transform/ONNX/ONNXRewrite.inc" //===----------------------------------------------------------------------===// // Rewrite: diff --git a/src/Pass/ONNXRewrite.td b/src/Transform/ONNX/ONNXRewrite.td similarity index 98% rename from src/Pass/ONNXRewrite.td rename to src/Transform/ONNX/ONNXRewrite.td index 8e6a253..f0684f9 100644 --- a/src/Pass/ONNXRewrite.td +++ b/src/Transform/ONNX/ONNXRewrite.td @@ -13,7 +13,7 @@ #define ONNX_REWRITE #ifndef OP_BASE -include "Dialect/ONNX/ONNXOps.td" +include "src/Dialect/ONNX/ONNXOps.td" #endif // OP_BASE /// Note: The DRR definition used for defining patterns is shown below: diff --git a/src/Pass/ShapeInferencePass.cpp b/src/Transform/ONNX/ShapeInferencePass.cpp similarity index 96% rename from src/Pass/ShapeInferencePass.cpp rename to src/Transform/ONNX/ShapeInferencePass.cpp index d2ad5cd..4c59625 100644 --- a/src/Pass/ShapeInferencePass.cpp +++ b/src/Transform/ONNX/ShapeInferencePass.cpp @@ -14,15 +14,11 @@ #include "llvm/Support/raw_ostream.h" #include "mlir/IR/StandardTypes.h" -#include "ShapeInferenceInterface.hpp" - -#include "Passes.hpp" +#include "src/Interface/ShapeInferenceInterface.hpp" +#include "src/Pass/Passes.hpp" using namespace mlir; -// Include the auto-generated definitions for the shape inference interfaces. -#include "src/shape_inference.cpp.inc" - namespace { /*! * FunctionPass that performs shape inference by iterating over a list of diff --git a/src/Transform/onnx/CMakeLists.txt b/src/Transform/onnx/CMakeLists.txt deleted file mode 100644 index 3874c63..0000000 --- a/src/Transform/onnx/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -add_library(onnx_mlir_attribute_promotion - attribute_promotion.cpp) -target_include_directories(onnx_mlir_attribute_promotion - PRIVATE ${ONNX_MLIR_SRC_ROOT} ${ONNX_MLIR_BIN_ROOT} - ${ONNF_MLIR_SRC_ROOT}) -target_link_libraries(onnx_mlir_attribute_promotion - onnx_mlir_promotable_const_operands_op_interface) \ No newline at end of file