[Mlir-commits] [mlir] 9119325 - [mlir][CRunnerUtils] Use explicit execution engine symbol registration.
Ingo Müller
llvmlistbot at llvm.org
Wed Jun 21 02:44:15 PDT 2023
Author: Ingo Müller
Date: 2023-06-21T09:44:10Z
New Revision: 9119325a5666e557a19f38a05525578b556c215b
URL: https://github.com/llvm/llvm-project/commit/9119325a5666e557a19f38a05525578b556c215b
DIFF: https://github.com/llvm/llvm-project/commit/9119325a5666e557a19f38a05525578b556c215b.diff
LOG: [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
Added:
Modified:
mlir/include/mlir/ExecutionEngine/Float16bits.h
mlir/lib/ExecutionEngine/CMakeLists.txt
mlir/lib/ExecutionEngine/CRunnerUtils.cpp
mlir/lib/ExecutionEngine/Float16bits.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/ExecutionEngine/Float16bits.h b/mlir/include/mlir/ExecutionEngine/Float16bits.h
index 6bf1589aa13a2..be9c77b99d74f 100644
--- a/mlir/include/mlir/ExecutionEngine/Float16bits.h
+++ b/mlir/include/mlir/ExecutionEngine/Float16bits.h
@@ -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_
diff --git a/mlir/lib/ExecutionEngine/CMakeLists.txt b/mlir/lib/ExecutionEngine/CMakeLists.txt
index ab33fb5b430fb..6377a9d1793ae 100644
--- a/mlir/lib/ExecutionEngine/CMakeLists.txt
+++ b/mlir/lib/ExecutionEngine/CMakeLists.txt
@@ -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
diff --git a/mlir/lib/ExecutionEngine/CRunnerUtils.cpp b/mlir/lib/ExecutionEngine/CRunnerUtils.cpp
index 7f800e8ea96ff..1be41c9d6df12 100644
--- a/mlir/lib/ExecutionEngine/CRunnerUtils.cpp
+++ b/mlir/lib/ExecutionEngine/CRunnerUtils.cpp
@@ -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
diff --git a/mlir/lib/ExecutionEngine/Float16bits.cpp b/mlir/lib/ExecutionEngine/Float16bits.cpp
index 38a05fe86bbdd..fa86b776f7fd1 100644
--- a/mlir/lib/ExecutionEngine/Float16bits.cpp
+++ b/mlir/lib/ExecutionEngine/Float16bits.cpp
@@ -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;
More information about the Mlir-commits
mailing list