Skip to content

Commit

Permalink
Pass XSMM runner lib to MLIR execution engine (#147)
Browse files Browse the repository at this point in the history
Manually finds and passes XSMM runner library to the MLIR JIT engine
to resolve missing TPP xsmm_* symbols when executing from Python.

Works only for Linux currently.
  • Loading branch information
adam-smnk authored Jul 25, 2024
1 parent a7f652e commit a510e01
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
6 changes: 5 additions & 1 deletion cmake/tpp-mlir.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ if (TPP_MLIR_DIR)
tpp_xsmm_runner_utils
)
function(add_tpp_mlir_includes target)
target_include_directories(${target} PRIVATE ${TPP_MLIR_DIR}/../include ${TPP_MLIR_DIR}/include)
target_include_directories(${target}
PRIVATE
${TPP_MLIR_DIR}/../include
${TPP_MLIR_DIR}/include
${TPP_MLIR_DIR}/../runtime)
endfunction()
function(add_tpp_mlir_libs target)
target_link_directories(${target} PRIVATE ${TPP_MLIR_DIR}/lib)
Expand Down
30 changes: 27 additions & 3 deletions src/common/transformations/src/transformations/mlir/mlir_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

#include "mlir_op.hpp"

#include <vector>
#include <algorithm>
#include <functional>
#include <memory>
#include <string>
#include <vector>

#include "mlir/Dialect/Bufferization/Transforms/Passes.h"
#include "mlir/Pass/PassManager.h"

// TODO: Prune unused headers -- it's hard to understand needed ones
#include "llvm/ADT/SmallVector.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/InitLLVM.h"
Expand Down Expand Up @@ -54,8 +55,16 @@
#include "mlir/Target/LLVMIR/ModuleTranslation.h"

#ifdef TPP_MLIR // If TPP is available
#include "TPP/PassBundles.h"
#include "TPP/Passes.h"
# if defined(__APPLE__) || defined(__linux__) || defined(__EMSCRIPTEN__)
# include <dlfcn.h>
# else
# error "Unsupported OS"
# endif

# include "PerfRunnerUtils.h"
# include "TPP/PassBundles.h"
# include "TPP/Passes.h"
# include "openvino/util/file_util.hpp"
#endif

namespace {
Expand Down Expand Up @@ -255,6 +264,19 @@ namespace mlir {

using namespace ::mlir;

static std::string get_xsmm_runner_path() {
#if defined(__APPLE__) || defined(__linux__) || defined(__EMSCRIPTEN__)
// TODO: Add multiplatform shared library search support.
Dl_info info;
if (dladdr(reinterpret_cast<void*>(perf_start_timer), &info) == 0) {
llvm::errs() << "failed to find XSMM Runner library\n";
abort();
}
return ov::util::get_absolute_file_path(info.dli_fname);
#else
# error "Unsupported OS"
#endif
}

MLIREvaluate::MLIREvaluate(OwningOpRef<mlir::ModuleOp> _module) : module(std::move(_module)) {
if (true) {
Expand All @@ -281,6 +303,8 @@ MLIREvaluate::MLIREvaluate(OwningOpRef<mlir::ModuleOp> _module) : module(std::mo
engineOptions.transformer = optPipeline; // opt level looks to be overriden in lowerToLLVMIR, but is still used
// in `create` independently
engineOptions.llvmModuleBuilder = lowerToLLVMIR;
std::string xsmmLibPath = get_xsmm_runner_path();
engineOptions.sharedLibPaths = SmallVector<StringRef>{xsmmLibPath};
auto maybeEngine = mlir::ExecutionEngine::create(module.get(), engineOptions);
if (maybeEngine) {
engine = std::move(maybeEngine.get());
Expand Down

0 comments on commit a510e01

Please sign in to comment.