Skip to content

Commit

Permalink
Introduce a new target for high-level op generation: mlir-miopen-driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
whchung committed Jun 6, 2020
1 parent 02d8aba commit c9808d0
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions mlir/lib/Dialect/MIOpenOps/CMakeLists.txt
Expand Up @@ -9,3 +9,4 @@ add_dependencies(MLIRMIOpenOps MLIRMIOpenOpsIncGen MLIRStandardOps LLVMSupport)
target_link_libraries(MLIRMIOpenOps LLVMSupport)

add_subdirectory(CppOutput)
add_subdirectory(Driver)
16 changes: 16 additions & 0 deletions mlir/lib/Dialect/MIOpenOps/Driver/CMakeLists.txt
@@ -0,0 +1,16 @@
set(LIBS
MLIRAnalysis
MLIRMIOpenOps
MLIRParser
MLIRPass
MLIRStandardOps
MLIRTransforms
MLIRSupport
)

add_llvm_tool(mlir-miopen-driver
mlir-miopen-driver.cpp
)
llvm_update_compile_flags(mlir-miopen-driver)
whole_archive_link(mlir-miopen-driver ${LIBS})
target_link_libraries(mlir-miopen-driver PRIVATE MLIRIR ${LIBS} LLVMSupport)
65 changes: 65 additions & 0 deletions mlir/lib/Dialect/MIOpenOps/Driver/mlir-miopen-driver.cpp
@@ -0,0 +1,65 @@
//===- mlir-miopen-driver.cpp - MLIR MIOpen Dialect Driver ----------------===//
//
// Part of the MLIR Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Main entry function for mlir-miopen-driver.
//
//===----------------------------------------------------------------------===//

#include "mlir/Analysis/Passes.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Support/FileUtilities.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/ToolOutputFile.h"

using namespace llvm;
using namespace mlir;

static cl::opt<std::string>
inputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"));

static cl::opt<std::string> outputFilename("o", cl::desc("Output filename"),
cl::value_desc("filename"),
cl::init("-"));

static cl::opt<std::string> filterLayout("f", cl::desc("Filter layout"),
cl::value_desc("layout string"),
cl::init("kcyx"));

static cl::opt<std::string> inputLayout("i", cl::desc("Input layout"),
cl::value_desc("layout string"),
cl::init("nchw"));

static cl::opt<std::string> outputLayout("d", cl::desc("Output layout"),
cl::value_desc("layout string"),
cl::init("nkhw"));

int main(int argc, char **argv) {
InitLLVM y(argc, argv);

// Parse pass names in main to ensure static initialization completed.
cl::ParseCommandLineOptions(argc, argv, "MLIR MIOpen Dialect driver\n");

// Set up the input file.
std::string errorMessage;
auto file = openInputFile(inputFilename, &errorMessage);
if (!file) {
llvm::errs() << errorMessage << "\n";
return 1;
}

auto output = openOutputFile(outputFilename, &errorMessage);
if (!output) {
llvm::errs() << errorMessage << "\n";
exit(1);
}

return 0;
}

0 comments on commit c9808d0

Please sign in to comment.