[mlir][CRunnerUtils] Use explicit execution engine symbol registration.
As a follow up of https://reviews.llvm.org/D153250, this path uses the explicit symbol registration mechanism of the execution engine in the CRunnerUtils library. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D153354
This commit is contained in:
@@ -48,5 +48,4 @@ MLIR_FLOAT16_EXPORT std::ostream &operator<<(std::ostream &os, const f16 &f);
|
||||
// Outputs a bfloat value.
|
||||
MLIR_FLOAT16_EXPORT std::ostream &operator<<(std::ostream &os, const bf16 &d);
|
||||
|
||||
#undef MLIR_FLOAT16_EXPORT
|
||||
#endif // MLIR_EXECUTIONENGINE_FLOAT16BITS_H_
|
||||
|
||||
@@ -147,8 +147,15 @@ if(LLVM_ENABLE_PIC)
|
||||
MLIRSparseTensorEnums
|
||||
MLIRSparseTensorRuntime
|
||||
)
|
||||
set_property(TARGET mlir_c_runner_utils PROPERTY CXX_VISIBILITY_PRESET hidden)
|
||||
set_property(TARGET mlir_c_runner_utils PROPERTY CXX_STANDARD 17)
|
||||
target_compile_definitions(mlir_c_runner_utils PRIVATE mlir_c_runner_utils_EXPORTS)
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
# Don't export symbols from link-time dependencies, these are internal
|
||||
# implementation details.
|
||||
# FIXME: Add a similar fix for Windows.
|
||||
target_link_options(mlir_c_runner_utils PRIVATE "-Wl,-exclude-libs,ALL")
|
||||
endif()
|
||||
|
||||
add_mlir_library(mlir_runner_utils
|
||||
SHARED
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "mlir/ExecutionEngine/CRunnerUtils.h"
|
||||
#include "mlir/ExecutionEngine/Msan.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
||||
@@ -187,4 +188,45 @@ IMPL_STDSORT(F64, double)
|
||||
IMPL_STDSORT(F32, float)
|
||||
#undef IMPL_STDSORT
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// MLIR ExecutionEngine dynamic library integration.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Visual Studio had a bug that fails to compile nested generic lambdas
|
||||
// inside an `extern "C"` function.
|
||||
// https://developercommunity.visualstudio.com/content/problem/475494/clexe-error-with-lambda-inside-function-templates.html
|
||||
// The bug is fixed in VS2019 16.1. Separating the declaration and definition is
|
||||
// a work around for older versions of Visual Studio.
|
||||
extern "C" MLIR_CRUNNERUTILS_EXPORT void
|
||||
__mlir_execution_engine_init(llvm::StringMap<void *> &exportSymbols);
|
||||
|
||||
void __mlir_execution_engine_init(llvm::StringMap<void *> &exportSymbols) {
|
||||
auto exportSymbol = [&](llvm::StringRef name, auto ptr) {
|
||||
assert(exportSymbols.count(name) == 0 && "symbol already exists");
|
||||
exportSymbols[name] = reinterpret_cast<void *>(ptr);
|
||||
};
|
||||
|
||||
exportSymbol("memrefCopy", &memrefCopy);
|
||||
exportSymbol("printI64", &printI64);
|
||||
exportSymbol("printU64", &printU64);
|
||||
exportSymbol("printF32", &printF32);
|
||||
exportSymbol("printF64", &printF64);
|
||||
exportSymbol("printOpen", &printOpen);
|
||||
exportSymbol("printClose", &printClose);
|
||||
exportSymbol("printComma", &printComma);
|
||||
exportSymbol("printNewline", &printNewline);
|
||||
exportSymbol("printF16", &printF16);
|
||||
exportSymbol("printBF16", &printBF16);
|
||||
exportSymbol("printFlops", &printFlops);
|
||||
exportSymbol("rtclock", &rtclock);
|
||||
exportSymbol("*rtsrand", &*rtsrand);
|
||||
exportSymbol("rtrand", &rtrand);
|
||||
exportSymbol("rtdrand", &rtdrand);
|
||||
exportSymbol("_mlir_ciface_stdSortI64", &_mlir_ciface_stdSortI64);
|
||||
exportSymbol("_mlir_ciface_stdSortF64", &_mlir_ciface_stdSortF64);
|
||||
exportSymbol("_mlir_ciface_stdSortF32", &_mlir_ciface_stdSortF32);
|
||||
}
|
||||
|
||||
extern "C" MLIR_CRUNNERUTILS_EXPORT void __mlir_execution_engine_destroy() {}
|
||||
|
||||
#endif // MLIR_CRUNNERUTILS_DEFINE_FUNCTIONS
|
||||
|
||||
@@ -193,12 +193,12 @@ extern "C" BF16ABIType ATTR_WEAK __truncdfbf2(double d) {
|
||||
}
|
||||
|
||||
// Provide these to the CRunner with the local float16 knowledge.
|
||||
extern "C" void printF16(uint16_t bits) {
|
||||
extern "C" MLIR_FLOAT16_EXPORT void printF16(uint16_t bits) {
|
||||
f16 f;
|
||||
std::memcpy(&f, &bits, sizeof(f16));
|
||||
std::cout << f;
|
||||
}
|
||||
extern "C" void printBF16(uint16_t bits) {
|
||||
extern "C" MLIR_FLOAT16_EXPORT void printBF16(uint16_t bits) {
|
||||
bf16 f;
|
||||
std::memcpy(&f, &bits, sizeof(bf16));
|
||||
std::cout << f;
|
||||
|
||||
Reference in New Issue
Block a user