Skip to content

Commit

Permalink
Move shared cpu runner library to Support/JitRunner.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 258347825
  • Loading branch information
Stephan Herhut authored and joker-eph committed Jul 16, 2019
1 parent f3c1113 commit 6bb21b0
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 40 deletions.
47 changes: 47 additions & 0 deletions include/mlir/Support/JitRunner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//===- JitRunner.h - MLIR CPU Execution Driver Library ----------*- C++ -*-===//
//
// Copyright 2019 The MLIR Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// =============================================================================
//
// This is a library that provides a shared implementation for command line
// utilities that execute an MLIR file on the CPU by translating MLIR to LLVM
// IR before JIT-compiling and executing the latter.
//
// The translation can be customized by providing an MLIR to MLIR
// transformation.
//
//===----------------------------------------------------------------------===//

#ifndef MLIR_SUPPORT_JITRUNNER_H_
#define MLIR_SUPPORT_JITRUNNER_H_

#include "llvm/ADT/STLExtras.h"

namespace mlir {

class ModuleOp;
struct LogicalResult;

// Entry point for all CPU runners. Expects the common argc/argv arguments for
// standard C++ main functions and an mlirTransformer.
// The latter is applied after parsing the input into MLIR IR and before passing
// the MLIR module to the ExecutionEngine.
int JitRunnerMain(
int argc, char **argv,
llvm::function_ref<LogicalResult(mlir::ModuleOp)> mlirTransformer);

} // namespace mlir

#endif // MLIR_SUPPORT_JITRUNNER_H_
17 changes: 17 additions & 0 deletions lib/Support/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(LLVM_OPTIONAL_SOURCES
FileUtilities.cpp
JitRunner.cpp
MlirOptMain.cpp
StorageUniquer.cpp
TranslateClParser.cpp
Expand Down Expand Up @@ -38,3 +39,19 @@ add_llvm_library(MLIRTranslateClParser
${MLIR_MAIN_INCLUDE_DIR}/mlir/Support
)
target_link_libraries(MLIRTranslateClParser LLVMSupport)

add_llvm_library(MLIRJitRunner
JitRunner.cpp
)
target_link_libraries(MLIRJitRunner PRIVATE
MLIRExecutionEngine
MLIRIR
MLIRParser
MLIRStandardOps
MLIRTargetLLVMIR
MLIRTransforms
MLIRStandardToLLVM
MLIRSupport
LLVMCore
LLVMSupport
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===- mlir-cpu-runner-lib.cpp - MLIR CPU Execution Driver Library --------===//
//===- jit-runner.cpp - MLIR CPU Execution Driver Library -----------------===//
//
// Copyright 2019 The MLIR Authors.
//
Expand All @@ -15,11 +15,16 @@
// limitations under the License.
// =============================================================================
//
// This is a command line utility that executes an MLIR file on the CPU by
// translating MLIR to LLVM IR before JIT-compiling and executing the latter.
// This is a library that provides a shared implementation for command line
// utilities that execute an MLIR file on the CPU by translating MLIR to LLVM
// IR before JIT-compiling and executing the latter.
//
// The translation can be customized by providing an MLIR to MLIR
// transformation.
//===----------------------------------------------------------------------===//

#include "mlir/Support/JitRunner.h"

#include "mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h"
#include "mlir/ExecutionEngine/ExecutionEngine.h"
#include "mlir/ExecutionEngine/MemRefUtils.h"
Expand Down Expand Up @@ -254,8 +259,9 @@ static Error compileAndExecuteSingleFloatReturnFunction(
// standard C++ main functions and an mlirTransformer.
// The latter is applied after parsing the input into MLIR IR and before passing
// the MLIR module to the ExecutionEngine.
int run(int argc, char **argv,
llvm::function_ref<LogicalResult(mlir::ModuleOp)> mlirTransformer) {
int mlir::JitRunnerMain(
int argc, char **argv,
llvm::function_ref<LogicalResult(mlir::ModuleOp)> mlirTransformer) {
llvm::PrettyStackTraceProgram x(argc, argv);
llvm::InitLLVM y(argc, argv);

Expand Down
29 changes: 12 additions & 17 deletions tools/mlir-cpu-runner/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
set(LLVM_OPTIONAL_SOURCES
mlir-cpu-runner-lib.cpp
add_llvm_executable(mlir-cpu-runner
mlir-cpu-runner.cpp
)

set(LIBS
)
llvm_update_compile_flags(mlir-cpu-runner)
whole_archive_link(mlir-cpu-runner
MLIRLLVMIR
MLIRStandardOps
MLIRTargetLLVMIR
MLIRTransforms
MLIRTranslation
)
target_link_libraries(mlir-cpu-runner PRIVATE
MLIRAffineOps
MLIRAnalysis
MLIRControlFlowToCFG
MLIREDSC
MLIRExecutionEngine
MLIRIR
MLIRJitRunner
MLIRLLVMIR
MLIRParser
MLIRTargetLLVMIR
Expand All @@ -19,15 +26,3 @@ set(LIBS
LLVMCore
LLVMSupport
)

add_llvm_library(MLIRCPURunnerLib
mlir-cpu-runner-lib.cpp
)
target_link_libraries(MLIRCPURunnerLib ${LIBS})

add_llvm_executable(mlir-cpu-runner
mlir-cpu-runner.cpp
)
llvm_update_compile_flags(mlir-cpu-runner)
whole_archive_link(mlir-cpu-runner MLIRLLVMIR MLIRStandardOps MLIRTargetLLVMIR MLIRTransforms MLIRTranslation)
target_link_libraries(mlir-cpu-runner PRIVATE MLIRIR ${LIBS} MLIRCPURunnerLib)
15 changes: 4 additions & 11 deletions tools/mlir-cpu-runner/mlir-cpu-runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,8 @@
//
//===----------------------------------------------------------------------===//

#include "llvm/ADT/STLExtras.h"
#include "mlir/Support/JitRunner.h"

namespace mlir {
class ModuleOp;
struct LogicalResult;
} // namespace mlir

// TODO(herhut) Factor out into an include file and proper library.
extern int run(int argc, char **argv,
llvm::function_ref<mlir::LogicalResult(mlir::ModuleOp)>);

int main(int argc, char **argv) { return run(argc, argv, nullptr); }
int main(int argc, char **argv) {
return mlir::JitRunnerMain(argc, argv, nullptr);
}
3 changes: 1 addition & 2 deletions tools/mlir-cuda-runner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ if(MLIR_CUDA_RUNNER_ENABLED)
MLIRParser
MLIREDSC
MLIRAnalysis
MLIRCPURunnerLib
MLIRExecutionEngine
MLIRJitRunner
MLIRSupport
LLVMCore
LLVMSupport
Expand All @@ -71,5 +71,4 @@ if(MLIR_CUDA_RUNNER_ENABLED)
whole_archive_link(mlir-cuda-runner ${FULL_LINK_LIBS})
target_link_libraries(mlir-cuda-runner PRIVATE ${FULL_LINK_LIBS} ${LIBS})


endif()
9 changes: 4 additions & 5 deletions tools/mlir-cuda-runner/mlir-cuda-runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@
#include "mlir/LLVMIR/LLVMDialect.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Support/JitRunner.h"
#include "mlir/Transforms/DialectConversion.h"

#include "cuda.h"

using namespace mlir;

// TODO(herhut) Factor out into an include file and proper library.
extern int run(int argc, char **argv,
llvm::function_ref<LogicalResult(ModuleOp)>);

inline void emit_cuda_error(const llvm::Twine &message, const char *buffer,
CUresult error, FuncOp &function) {
function.emitError(message.concat(" failed with error code ")
Expand Down Expand Up @@ -151,4 +148,6 @@ static LogicalResult runMLIRPasses(ModuleOp m) {
return success();
}

int main(int argc, char **argv) { return run(argc, argv, &runMLIRPasses); }
int main(int argc, char **argv) {
return mlir::JitRunnerMain(argc, argv, &runMLIRPasses);
}

0 comments on commit 6bb21b0

Please sign in to comment.