clean up, remove dependency for boost

This commit is contained in:
Tian Jin 2019-12-22 20:33:33 -05:00
parent a6a40cf989
commit 5573cb39fe
6 changed files with 76 additions and 136 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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})

View File

@ -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}

View File

@ -8,14 +8,11 @@
#include <llvm/Support/CommandLine.h>
#include <llvm/Support/InitLLVM.h>
#include <llvm/Support/MemoryBuffer.h>
#include <llvm/Support/ToolOutputFile.h>
#include <mlir/Dialect/StandardOps/Ops.h>
#include <mlir/Pass/Pass.h>
#include <mlir/Pass/PassManager.h>
#include <mlir/Support/FileUtilities.h>
#include <mlir/Support/MlirOptMain.h>
#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<std::string> input_filename(
llvm::cl::Positional, llvm::cl::desc("<input file>"), llvm::cl::init("-"));
static llvm::cl::opt<std::string> input_filename(llvm::cl::Positional,
llvm::cl::desc("<input file>"),
llvm::cl::init("-"));
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<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",
static llvm::cl::opt<bool> 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<bool> verify_diagnostics("verify-diagnostics",
static llvm::cl::opt<bool> 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<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::init(true));
int main(int argc, char** argv) {
int main(int argc, char **argv) {
llvm::InitLLVM y(argc, argv);
mlir::registerDialect<mlir::ONNXOpsDialect>();
@ -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));
}

View File

@ -12,24 +12,10 @@
#include <random>
#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/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<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;
}
int main(int argc, char *argv[]) {
mlir::registerDialect<mlir::ONNXOpsDialect>();
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::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>();
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!");
}