clean up, remove dependency for boost
This commit is contained in:
parent
a6a40cf989
commit
5573cb39fe
|
@ -15,8 +15,7 @@ set(ONNF_SRC_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
set(ONNF_BIN_ROOT "${CMAKE_CURRENT_BINARY_DIR}")
|
set(ONNF_BIN_ROOT "${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||||
set(CMAKE_LIBRARY_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)
|
include(MLIR.cmake)
|
||||||
|
|
||||||
|
@ -24,25 +23,7 @@ add_subdirectory(third_party/onnx)
|
||||||
add_subdirectory(third_party/benchmark)
|
add_subdirectory(third_party/benchmark)
|
||||||
add_subdirectory(third_party/pybind11)
|
add_subdirectory(third_party/pybind11)
|
||||||
|
|
||||||
# Set cxx standard only for onnf project files.
|
|
||||||
set(CMAKE_CXX_STANDARD 14)
|
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/builder)
|
||||||
add_subdirectory(src/compiler)
|
add_subdirectory(src/compiler)
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
76
MLIR.cmake
76
MLIR.cmake
|
@ -62,6 +62,7 @@ find_mlir_lib(MLIRExecutionEngine)
|
||||||
find_mlir_lib(MLIRIR)
|
find_mlir_lib(MLIRIR)
|
||||||
find_mlir_lib(MLIRLLVMIR)
|
find_mlir_lib(MLIRLLVMIR)
|
||||||
find_mlir_lib(MLIRLoopToStandard)
|
find_mlir_lib(MLIRLoopToStandard)
|
||||||
|
find_mlir_lib(MLIRLoopOps)
|
||||||
find_mlir_lib(MLIRParser)
|
find_mlir_lib(MLIRParser)
|
||||||
find_mlir_lib(MLIRPass)
|
find_mlir_lib(MLIRPass)
|
||||||
find_mlir_lib(MLIRStandardOps)
|
find_mlir_lib(MLIRStandardOps)
|
||||||
|
@ -96,42 +97,42 @@ find_mlir_lib(LLVMDemangle)
|
||||||
|
|
||||||
|
|
||||||
set(MLIRLibsOnce
|
set(MLIRLibsOnce
|
||||||
LLVMAnalysis
|
${LLVMAnalysis}
|
||||||
LLVMAsmParser
|
${LLVMAsmParser}
|
||||||
LLVMBinaryFormat
|
${LLVMBinaryFormat}
|
||||||
LLVMBitReader
|
${LLVMBitReader}
|
||||||
LLVMBitstreamReader
|
${LLVMBitstreamReader}
|
||||||
LLVMBitWriter
|
${LLVMBitWriter}
|
||||||
LLVMCore
|
${LLVMCore}
|
||||||
LLVMIRReader
|
${LLVMIRReader}
|
||||||
LLVMMC
|
${LLVMMC}
|
||||||
LLVMMCParser
|
${LLVMMCParser}
|
||||||
LLVMObject
|
${LLVMObject}
|
||||||
LLVMRemarks
|
${LLVMRemarks}
|
||||||
LLVMSupport
|
${LLVMSupport}
|
||||||
LLVMTransformUtils
|
${LLVMTransformUtils}
|
||||||
LLVMProfileData
|
${LLVMProfileData}
|
||||||
LLVMDemangle
|
${LLVMDemangle}
|
||||||
MLIRAffineOps
|
${MLIRAffineOps}
|
||||||
MLIRAffineToStandard
|
${MLIRAffineToStandard}
|
||||||
MLIRAnalysis
|
${MLIRAnalysis}
|
||||||
MLIRDialect
|
${MLIRDialect}
|
||||||
MLIRExecutionEngine
|
${MLIRExecutionEngine}
|
||||||
MLIRIR
|
${MLIRIR}
|
||||||
MLIRLLVMIR
|
${MLIRLLVMIR}
|
||||||
MLIRLoopOps
|
${MLIRLoopToStandard}
|
||||||
MLIRLoopToStandard
|
${MLIRLoopOps}
|
||||||
MLIROptMain
|
${MLIROptMain}
|
||||||
MLIRParser
|
${MLIRParser}
|
||||||
MLIRPass
|
${MLIRPass}
|
||||||
MLIRStandardOps
|
${MLIRStandardOps}
|
||||||
MLIRStandardToLLVM
|
${MLIRStandardToLLVM}
|
||||||
MLIRSupport
|
${MLIRSupport}
|
||||||
MLIRTargetLLVMIR
|
${MLIRTargetLLVMIR}
|
||||||
MLIRTargetLLVMIRModuleTranslation
|
${MLIRTargetLLVMIRModuleTranslation}
|
||||||
MLIRTransforms
|
${MLIRTransforms}
|
||||||
MLIRTransformUtils
|
${MLIRTransformUtils}
|
||||||
MLIRTranslation)
|
${MLIRTranslation})
|
||||||
|
|
||||||
set(MLIRLibs
|
set(MLIRLibs
|
||||||
${MLIRLibsOnce}
|
${MLIRLibsOnce}
|
||||||
|
@ -146,7 +147,8 @@ set(MLIRWholeArchiveLibs
|
||||||
MLIRStandardToLLVM
|
MLIRStandardToLLVM
|
||||||
MLIRTransforms
|
MLIRTransforms
|
||||||
MLIRLoopToStandard
|
MLIRLoopToStandard
|
||||||
MLIRVectorOps)
|
MLIRVectorOps
|
||||||
|
MLIRLoopOps)
|
||||||
|
|
||||||
function(whole_archive_link target lib_dir)
|
function(whole_archive_link target lib_dir)
|
||||||
get_property(link_flags TARGET ${target} PROPERTY LINK_FLAGS)
|
get_property(link_flags TARGET ${target} PROPERTY LINK_FLAGS)
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
add_executable(onnf main.cpp)
|
add_executable(onnf main.cpp)
|
||||||
|
|
||||||
target_link_libraries(onnf builder compiler ${MLIRLibs} ${Boost_LIBRARIES})
|
target_link_libraries(onnf builder compiler ${MLIRLibs} onnf_transform)
|
||||||
set_target_properties(onnf PROPERTIES LINK_FLAGS "-lz")
|
|
||||||
|
|
||||||
whole_archive_link_mlir(onnf ${MLIRWholeArchiveLibs})
|
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_SOURCE_DIR})
|
||||||
target_include_directories(onnf PRIVATE ${CMAKE_BINARY_DIR})
|
target_include_directories(onnf PRIVATE ${CMAKE_BINARY_DIR})
|
||||||
|
|
|
@ -28,18 +28,7 @@ target_include_directories(compiler PRIVATE ${ONNF_SRC_ROOT}/third_party/fmt/inc
|
||||||
# Include tablegen generated header files.
|
# Include tablegen generated header files.
|
||||||
target_include_directories(compiler PRIVATE ${ONNF_BIN_ROOT})
|
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
|
target_link_libraries(compiler
|
||||||
${Boost_LIBRARIES}
|
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
${CMAKE_DL_LIBS}
|
${CMAKE_DL_LIBS}
|
||||||
${MLIRLibs}
|
${MLIRLibs}
|
||||||
|
|
|
@ -8,14 +8,11 @@
|
||||||
|
|
||||||
#include <llvm/Support/CommandLine.h>
|
#include <llvm/Support/CommandLine.h>
|
||||||
#include <llvm/Support/InitLLVM.h>
|
#include <llvm/Support/InitLLVM.h>
|
||||||
#include <llvm/Support/MemoryBuffer.h>
|
|
||||||
#include <llvm/Support/ToolOutputFile.h>
|
#include <llvm/Support/ToolOutputFile.h>
|
||||||
#include <mlir/Dialect/StandardOps/Ops.h>
|
|
||||||
#include <mlir/Pass/Pass.h>
|
#include <mlir/Pass/Pass.h>
|
||||||
#include <mlir/Pass/PassManager.h>
|
#include <mlir/Pass/PassManager.h>
|
||||||
#include <mlir/Support/FileUtilities.h>
|
#include <mlir/Support/FileUtilities.h>
|
||||||
#include <mlir/Support/MlirOptMain.h>
|
#include <mlir/Support/MlirOptMain.h>
|
||||||
#include "llvm/Support/SourceMgr.h"
|
|
||||||
|
|
||||||
#include "src/compiler/dialect/krnl/krnl_ops.hpp"
|
#include "src/compiler/dialect/krnl/krnl_ops.hpp"
|
||||||
#include "src/compiler/dialect/onnx/onnx_ops.hpp"
|
#include "src/compiler/dialect/onnx/onnx_ops.hpp"
|
||||||
|
@ -23,24 +20,28 @@
|
||||||
|
|
||||||
using namespace onnf;
|
using namespace onnf;
|
||||||
|
|
||||||
static llvm::cl::opt<std::string> input_filename(
|
static llvm::cl::opt<std::string> input_filename(llvm::cl::Positional,
|
||||||
llvm::cl::Positional, llvm::cl::desc("<input file>"), llvm::cl::init("-"));
|
llvm::cl::desc("<input file>"),
|
||||||
|
|
||||||
static llvm::cl::opt<std::string> output_filename("o",
|
|
||||||
llvm::cl::desc("Output filename"), llvm::cl::value_desc("filename"),
|
|
||||||
llvm::cl::init("-"));
|
llvm::cl::init("-"));
|
||||||
|
|
||||||
static llvm::cl::opt<bool> split_input_file("split-input-file",
|
static llvm::cl::opt<std::string>
|
||||||
|
output_filename("o", llvm::cl::desc("Output filename"),
|
||||||
|
llvm::cl::value_desc("filename"), llvm::cl::init("-"));
|
||||||
|
|
||||||
|
static llvm::cl::opt<bool> split_input_file(
|
||||||
|
"split-input-file",
|
||||||
llvm::cl::desc("Split the input file into pieces and process each "
|
llvm::cl::desc("Split the input file into pieces and process each "
|
||||||
"chunk independently"),
|
"chunk independently"),
|
||||||
llvm::cl::init(false));
|
llvm::cl::init(false));
|
||||||
|
|
||||||
static llvm::cl::opt<bool> verify_diagnostics("verify-diagnostics",
|
static llvm::cl::opt<bool> verify_diagnostics(
|
||||||
|
"verify-diagnostics",
|
||||||
llvm::cl::desc("Check that emitted diagnostics match "
|
llvm::cl::desc("Check that emitted diagnostics match "
|
||||||
"expected-* lines on the corresponding line"),
|
"expected-* lines on the corresponding line"),
|
||||||
llvm::cl::init(false));
|
llvm::cl::init(false));
|
||||||
|
|
||||||
static llvm::cl::opt<bool> verify_passes("verify-each",
|
static llvm::cl::opt<bool> verify_passes(
|
||||||
|
"verify-each",
|
||||||
llvm::cl::desc("Run the verifier after each transformation pass"),
|
llvm::cl::desc("Run the verifier after each transformation pass"),
|
||||||
llvm::cl::init(true));
|
llvm::cl::init(true));
|
||||||
|
|
||||||
|
@ -53,8 +54,8 @@ int main(int argc, char** argv) {
|
||||||
// Register any pass manager command line options.
|
// Register any pass manager command line options.
|
||||||
mlir::registerPassManagerCLOptions();
|
mlir::registerPassManagerCLOptions();
|
||||||
mlir::PassPipelineCLParser passPipeline("", "Compiler passes to run");
|
mlir::PassPipelineCLParser passPipeline("", "Compiler passes to run");
|
||||||
llvm::cl::ParseCommandLineOptions(
|
llvm::cl::ParseCommandLineOptions(argc, argv,
|
||||||
argc, argv, "onnf MLIR modular optimizer driver\n");
|
"ONNF MLIR modular optimizer driver\n");
|
||||||
|
|
||||||
// Set up the input file.
|
// Set up the input file.
|
||||||
std::string error_message;
|
std::string error_message;
|
||||||
|
@ -65,5 +66,6 @@ int main(int argc, char** argv) {
|
||||||
assert(output);
|
assert(output);
|
||||||
|
|
||||||
return failed(mlir::MlirOptMain(output->os(), std::move(file), passPipeline,
|
return failed(mlir::MlirOptMain(output->os(), std::move(file), passPipeline,
|
||||||
split_input_file, verify_diagnostics, verify_passes));
|
split_input_file, verify_diagnostics,
|
||||||
|
verify_passes));
|
||||||
}
|
}
|
||||||
|
|
61
src/main.cpp
61
src/main.cpp
|
@ -12,24 +12,10 @@
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
|
||||||
#include <boost/log/attributes/named_scope.hpp>
|
|
||||||
#include <boost/log/core.hpp>
|
|
||||||
#include <boost/log/expressions.hpp>
|
|
||||||
#include <boost/log/sinks/sync_frontend.hpp>
|
|
||||||
#include <boost/log/sinks/text_file_backend.hpp>
|
|
||||||
#include <boost/log/sinks/text_ostream_backend.hpp>
|
|
||||||
#include <boost/log/sources/logger.hpp>
|
|
||||||
#include <boost/log/support/date_time.hpp>
|
|
||||||
#include <boost/log/trivial.hpp>
|
|
||||||
#include <boost/log/utility/setup/common_attributes.hpp>
|
|
||||||
#include <boost/log/utility/setup/console.hpp>
|
|
||||||
#include <boost/log/utility/setup/file.hpp>
|
|
||||||
|
|
||||||
#include <boost/program_options.hpp>
|
|
||||||
|
|
||||||
#include "llvm/Bitcode/BitcodeWriter.h"
|
#include "llvm/Bitcode/BitcodeWriter.h"
|
||||||
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/FileUtilities.h"
|
#include "llvm/Support/FileUtilities.h"
|
||||||
|
#include "llvm/Support/InitLLVM.h"
|
||||||
#include "llvm/Support/Regex.h"
|
#include "llvm/Support/Regex.h"
|
||||||
#include "llvm/Support/SourceMgr.h"
|
#include "llvm/Support/SourceMgr.h"
|
||||||
|
|
||||||
|
@ -76,50 +62,33 @@ void LoadMLIR(string inputFilename, mlir::MLIRContext& context,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int ac, char *av[]) {
|
int main(int argc, char *argv[]) {
|
||||||
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<string>()->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;
|
|
||||||
}
|
|
||||||
|
|
||||||
mlir::registerDialect<mlir::ONNXOpsDialect>();
|
mlir::registerDialect<mlir::ONNXOpsDialect>();
|
||||||
mlir::registerDialect<mlir::KrnlOpsDialect>();
|
mlir::registerDialect<mlir::KrnlOpsDialect>();
|
||||||
|
|
||||||
|
llvm::cl::OptionCategory OnnfOptions("ONNF Options",
|
||||||
|
"These are frontend options.");
|
||||||
|
llvm::cl::opt<string> InputFilename(
|
||||||
|
llvm::cl::Positional, llvm::cl::desc("<input file>"), 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::MLIRContext context;
|
||||||
mlir::OwningModuleRef module;
|
mlir::OwningModuleRef module;
|
||||||
|
|
||||||
// Decide if the input file is an ONNX model or a model specified
|
// Decide if the input file is an ONNX model or a model specified
|
||||||
// in MLIR. The extension of the file is the decider.
|
// in MLIR. The extension of the file is the decider.
|
||||||
string model_filename = vm["onnx-model"].as<string>();
|
|
||||||
string extension =
|
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 onnx_model_provided = (extension == "onnx");
|
||||||
bool mlir_model_provided = (extension == "mlir");
|
bool mlir_model_provided = (extension == "mlir");
|
||||||
|
|
||||||
if (onnx_model_provided) {
|
if (onnx_model_provided) {
|
||||||
ImportFrontendModelFile(model_filename, context, module);
|
ImportFrontendModelFile(InputFilename, context, module);
|
||||||
} else if (mlir_model_provided) {
|
} else if (mlir_model_provided) {
|
||||||
LoadMLIR(model_filename, context, module);
|
LoadMLIR(InputFilename, context, module);
|
||||||
} else {
|
} else {
|
||||||
assert(false && "No ONNX or MLIR models provided!");
|
assert(false && "No ONNX or MLIR models provided!");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue