diff --git a/CMakeLists.txt b/CMakeLists.txt index 440ac55..7f4c5fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,8 +15,7 @@ set(ONNF_SRC_ROOT "${CMAKE_CURRENT_SOURCE_DIR}") set(ONNF_BIN_ROOT "${CMAKE_CURRENT_BINARY_DIR}") set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -#TODO(eventually enable the following) -#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) include(MLIR.cmake) @@ -24,25 +23,7 @@ add_subdirectory(third_party/onnx) add_subdirectory(third_party/benchmark) add_subdirectory(third_party/pybind11) -# Set cxx standard only for onnf project files. set(CMAKE_CXX_STANDARD 14) - -# Boost 1.61.0 required for boost::dll:program_location() -find_package(Boost 1.61.0 - COMPONENTS graph - program_options - log_setup - log - system - filesystem - REQUIRED) - -if(Boost_FOUND) - message("Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}") - message("Boost_LIBRARY_DIRS = ${Boost_LIBRARY_DIRS}") - include_directories(${Boost_INCLUDE_DIRS}) -endif() - add_subdirectory(src/builder) add_subdirectory(src/compiler) add_subdirectory(src) diff --git a/MLIR.cmake b/MLIR.cmake index 39cb0c9..68b4447 100644 --- a/MLIR.cmake +++ b/MLIR.cmake @@ -62,6 +62,7 @@ find_mlir_lib(MLIRExecutionEngine) find_mlir_lib(MLIRIR) find_mlir_lib(MLIRLLVMIR) find_mlir_lib(MLIRLoopToStandard) +find_mlir_lib(MLIRLoopOps) find_mlir_lib(MLIRParser) find_mlir_lib(MLIRPass) find_mlir_lib(MLIRStandardOps) @@ -96,42 +97,42 @@ find_mlir_lib(LLVMDemangle) set(MLIRLibsOnce - LLVMAnalysis - LLVMAsmParser - LLVMBinaryFormat - LLVMBitReader - LLVMBitstreamReader - LLVMBitWriter - LLVMCore - LLVMIRReader - LLVMMC - LLVMMCParser - LLVMObject - LLVMRemarks - LLVMSupport - LLVMTransformUtils - LLVMProfileData - LLVMDemangle - MLIRAffineOps - MLIRAffineToStandard - MLIRAnalysis - MLIRDialect - MLIRExecutionEngine - MLIRIR - MLIRLLVMIR - MLIRLoopOps - MLIRLoopToStandard - MLIROptMain - MLIRParser - MLIRPass - MLIRStandardOps - MLIRStandardToLLVM - MLIRSupport - MLIRTargetLLVMIR - MLIRTargetLLVMIRModuleTranslation - MLIRTransforms - MLIRTransformUtils - MLIRTranslation) + ${LLVMAnalysis} + ${LLVMAsmParser} + ${LLVMBinaryFormat} + ${LLVMBitReader} + ${LLVMBitstreamReader} + ${LLVMBitWriter} + ${LLVMCore} + ${LLVMIRReader} + ${LLVMMC} + ${LLVMMCParser} + ${LLVMObject} + ${LLVMRemarks} + ${LLVMSupport} + ${LLVMTransformUtils} + ${LLVMProfileData} + ${LLVMDemangle} + ${MLIRAffineOps} + ${MLIRAffineToStandard} + ${MLIRAnalysis} + ${MLIRDialect} + ${MLIRExecutionEngine} + ${MLIRIR} + ${MLIRLLVMIR} + ${MLIRLoopToStandard} + ${MLIRLoopOps} + ${MLIROptMain} + ${MLIRParser} + ${MLIRPass} + ${MLIRStandardOps} + ${MLIRStandardToLLVM} + ${MLIRSupport} + ${MLIRTargetLLVMIR} + ${MLIRTargetLLVMIRModuleTranslation} + ${MLIRTransforms} + ${MLIRTransformUtils} + ${MLIRTranslation}) set(MLIRLibs ${MLIRLibsOnce} @@ -146,7 +147,8 @@ set(MLIRWholeArchiveLibs MLIRStandardToLLVM MLIRTransforms MLIRLoopToStandard - MLIRVectorOps) + MLIRVectorOps + MLIRLoopOps) function(whole_archive_link target lib_dir) get_property(link_flags TARGET ${target} PROPERTY LINK_FLAGS) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3fe6903..df95708 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,11 +1,8 @@ add_executable(onnf main.cpp) -target_link_libraries(onnf builder compiler ${MLIRLibs} ${Boost_LIBRARIES}) -set_target_properties(onnf PROPERTIES LINK_FLAGS "-lz") - +target_link_libraries(onnf builder compiler ${MLIRLibs} onnf_transform) whole_archive_link_mlir(onnf ${MLIRWholeArchiveLibs}) -whole_archive_link_onnf(onnf onnf_transform) - +set_target_properties(onnf PROPERTIES LINK_FLAGS "-lz") target_include_directories(onnf PRIVATE ${CMAKE_SOURCE_DIR}) target_include_directories(onnf PRIVATE ${CMAKE_BINARY_DIR}) diff --git a/src/compiler/CMakeLists.txt b/src/compiler/CMakeLists.txt index 46a3ce6..5d16100 100644 --- a/src/compiler/CMakeLists.txt +++ b/src/compiler/CMakeLists.txt @@ -28,18 +28,7 @@ target_include_directories(compiler PRIVATE ${ONNF_SRC_ROOT}/third_party/fmt/inc # Include tablegen generated header files. target_include_directories(compiler PRIVATE ${ONNF_BIN_ROOT}) -find_package(Boost 1.54.0 - COMPONENTS - graph - program_options - log_setup - log - system - filesystem - REQUIRED) - target_link_libraries(compiler - ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS} ${MLIRLibs} diff --git a/src/compiler/tool/onnf_opt/onnf_opt.cpp b/src/compiler/tool/onnf_opt/onnf_opt.cpp index 722eb60..2bb4ed7 100644 --- a/src/compiler/tool/onnf_opt/onnf_opt.cpp +++ b/src/compiler/tool/onnf_opt/onnf_opt.cpp @@ -8,14 +8,11 @@ #include #include -#include #include -#include #include #include #include #include -#include "llvm/Support/SourceMgr.h" #include "src/compiler/dialect/krnl/krnl_ops.hpp" #include "src/compiler/dialect/onnx/onnx_ops.hpp" @@ -23,28 +20,32 @@ using namespace onnf; -static llvm::cl::opt input_filename( - llvm::cl::Positional, llvm::cl::desc(""), llvm::cl::init("-")); +static llvm::cl::opt input_filename(llvm::cl::Positional, + llvm::cl::desc(""), + llvm::cl::init("-")); -static llvm::cl::opt output_filename("o", - llvm::cl::desc("Output filename"), llvm::cl::value_desc("filename"), - llvm::cl::init("-")); +static llvm::cl::opt + output_filename("o", llvm::cl::desc("Output filename"), + llvm::cl::value_desc("filename"), llvm::cl::init("-")); -static llvm::cl::opt split_input_file("split-input-file", +static llvm::cl::opt split_input_file( + "split-input-file", llvm::cl::desc("Split the input file into pieces and process each " "chunk independently"), llvm::cl::init(false)); -static llvm::cl::opt verify_diagnostics("verify-diagnostics", +static llvm::cl::opt verify_diagnostics( + "verify-diagnostics", llvm::cl::desc("Check that emitted diagnostics match " "expected-* lines on the corresponding line"), llvm::cl::init(false)); -static llvm::cl::opt verify_passes("verify-each", +static llvm::cl::opt verify_passes( + "verify-each", llvm::cl::desc("Run the verifier after each transformation pass"), llvm::cl::init(true)); -int main(int argc, char** argv) { +int main(int argc, char **argv) { llvm::InitLLVM y(argc, argv); mlir::registerDialect(); @@ -53,8 +54,8 @@ int main(int argc, char** argv) { // Register any pass manager command line options. mlir::registerPassManagerCLOptions(); mlir::PassPipelineCLParser passPipeline("", "Compiler passes to run"); - llvm::cl::ParseCommandLineOptions( - argc, argv, "onnf MLIR modular optimizer driver\n"); + llvm::cl::ParseCommandLineOptions(argc, argv, + "ONNF MLIR modular optimizer driver\n"); // Set up the input file. std::string error_message; @@ -65,5 +66,6 @@ int main(int argc, char** argv) { assert(output); return failed(mlir::MlirOptMain(output->os(), std::move(file), passPipeline, - split_input_file, verify_diagnostics, verify_passes)); + split_input_file, verify_diagnostics, + verify_passes)); } diff --git a/src/main.cpp b/src/main.cpp index 4f1e946..e3896ba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,24 +12,10 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - #include "llvm/Bitcode/BitcodeWriter.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/FileUtilities.h" +#include "llvm/Support/InitLLVM.h" #include "llvm/Support/Regex.h" #include "llvm/Support/SourceMgr.h" @@ -54,8 +40,8 @@ using namespace std; using namespace onnf; -void LoadMLIR(string inputFilename, mlir::MLIRContext& context, - mlir::OwningModuleRef& module) { +void LoadMLIR(string inputFilename, mlir::MLIRContext &context, + mlir::OwningModuleRef &module) { // Handle '.mlir' input to the ONNF frontend. // The mlir format indicates that one or more of the supported // representations are used in the file. @@ -76,50 +62,33 @@ void LoadMLIR(string inputFilename, mlir::MLIRContext& context, } } -int main(int ac, char *av[]) { - namespace po = boost::program_options; - - po::options_description desc("ONNF available options"); - // clang-format off - desc.add_options()("help", "produce help message")( - "onnx-model", po::value()->required(), - "onnx model file"); - // clang-format on - - // Handle command line argument with option names and positional - // command line arguments. - po::positional_options_description p; - p.add("onnx-model", -1); - po::variables_map vm; - po::store(po::command_line_parser(ac, av).options(desc).positional(p).run(), - vm); - - // TODO: allow multiple input files - assert(vm.count("onnx-model") < 2 && "At most one input file can be provided!"); - - if (vm.count("help")) { - cout << desc << endl; - return 0; - } - +int main(int argc, char *argv[]) { mlir::registerDialect(); mlir::registerDialect(); + llvm::cl::OptionCategory OnnfOptions("ONNF Options", + "These are frontend options."); + llvm::cl::opt InputFilename( + llvm::cl::Positional, llvm::cl::desc(""), llvm::cl::init("-"), + llvm::cl::cat(OnnfOptions)); + llvm::cl::HideUnrelatedOptions(OnnfOptions); + llvm::cl::ParseCommandLineOptions(argc, argv, + "ONNF MLIR modular optimizer driver\n"); + mlir::MLIRContext context; mlir::OwningModuleRef module; // Decide if the input file is an ONNX model or a model specified // in MLIR. The extension of the file is the decider. - string model_filename = vm["onnx-model"].as(); string extension = - model_filename.substr(model_filename.find_last_of(".") + 1); + InputFilename.substr(InputFilename.find_last_of(".") + 1); bool onnx_model_provided = (extension == "onnx"); bool mlir_model_provided = (extension == "mlir"); if (onnx_model_provided) { - ImportFrontendModelFile(model_filename, context, module); + ImportFrontendModelFile(InputFilename, context, module); } else if (mlir_model_provided) { - LoadMLIR(model_filename, context, module); + LoadMLIR(InputFilename, context, module); } else { assert(false && "No ONNX or MLIR models provided!"); }