[Mlir-commits] [mlir] bba2b65 - [mlir][RunnerUtils] Make symbols private + implement loading mechanism.

Ingo Müller llvmlistbot at llvm.org
Tue Jun 20 12:28:37 PDT 2023


Author: Ingo Müller
Date: 2023-06-20T19:28:33Z
New Revision: bba2b656110209a3d9863b92c060082479b06ab1

URL: https://github.com/llvm/llvm-project/commit/bba2b656110209a3d9863b92c060082479b06ab1
DIFF: https://github.com/llvm/llvm-project/commit/bba2b656110209a3d9863b92c060082479b06ab1.diff

LOG: [mlir][RunnerUtils] Make symbols private + implement loading mechanism.

There are two ways to make symbols from a shared library visible in the
execution engine: exporting the symbols with public visibility or
implementing a loading/unloading mechansim that registers the exported
symbols explicitly. The latter has only been available in the JIT runner
until recently, but https://reviews.llvm.org/D153029 makes it available
in any usage of the execution engine (including the Python bindings).

This patch makes the runner utils library use the latter mechanism
instead of the former, i.e., it makes all of its symbols private and
implements the init/destroy functions of the loading mechanism to
control explicitly which symbols it registers.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D153250

Added: 
    

Modified: 
    mlir/lib/ExecutionEngine/CMakeLists.txt
    mlir/lib/ExecutionEngine/RunnerUtils.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/ExecutionEngine/CMakeLists.txt b/mlir/lib/ExecutionEngine/CMakeLists.txt
index 39cc9c060db78..ab33fb5b430fb 100644
--- a/mlir/lib/ExecutionEngine/CMakeLists.txt
+++ b/mlir/lib/ExecutionEngine/CMakeLists.txt
@@ -156,7 +156,14 @@ if(LLVM_ENABLE_PIC)
 
     EXCLUDE_FROM_LIBMLIR
   )
+  set_property(TARGET mlir_runner_utils PROPERTY CXX_VISIBILITY_PRESET hidden)
   target_compile_definitions(mlir_runner_utils PRIVATE mlir_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_runner_utils PRIVATE "-Wl,-exclude-libs,ALL")
+  endif()
 
   add_mlir_library(mlir_async_runtime
     SHARED

diff  --git a/mlir/lib/ExecutionEngine/RunnerUtils.cpp b/mlir/lib/ExecutionEngine/RunnerUtils.cpp
index ccf5309487637..b1fc190ea63d5 100644
--- a/mlir/lib/ExecutionEngine/RunnerUtils.cpp
+++ b/mlir/lib/ExecutionEngine/RunnerUtils.cpp
@@ -14,6 +14,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "mlir/ExecutionEngine/RunnerUtils.h"
+#include "llvm/ADT/StringMap.h"
 #include <chrono>
 
 // NOLINTBEGIN(*-identifier-naming)
@@ -287,4 +288,85 @@ extern "C" int64_t verifyMemRefC64(int64_t rank, void *actualPtr,
   return _mlir_ciface_verifyMemRefC64(&actualDesc, &expectedDesc);
 }
 
+//===----------------------------------------------------------------------===//
+// 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_RUNNERUTILS_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("_mlir_ciface_printMemrefShapeI8",
+               &_mlir_ciface_printMemrefShapeI8);
+  exportSymbol("_mlir_ciface_printMemrefShapeI32",
+               &_mlir_ciface_printMemrefShapeI32);
+  exportSymbol("_mlir_ciface_printMemrefShapeI64",
+               &_mlir_ciface_printMemrefShapeI64);
+  exportSymbol("_mlir_ciface_printMemrefShapeF32",
+               &_mlir_ciface_printMemrefShapeF32);
+  exportSymbol("_mlir_ciface_printMemrefShapeF64",
+               &_mlir_ciface_printMemrefShapeF64);
+  exportSymbol("_mlir_ciface_printMemrefShapeInd",
+               &_mlir_ciface_printMemrefShapeInd);
+  exportSymbol("_mlir_ciface_printMemrefShapeC32",
+               &_mlir_ciface_printMemrefShapeC32);
+  exportSymbol("_mlir_ciface_printMemrefShapeC64",
+               &_mlir_ciface_printMemrefShapeC64);
+  exportSymbol("_mlir_ciface_printMemrefI8", &_mlir_ciface_printMemrefI8);
+  exportSymbol("_mlir_ciface_printMemrefI32", &_mlir_ciface_printMemrefI32);
+  exportSymbol("_mlir_ciface_printMemrefI64", &_mlir_ciface_printMemrefI64);
+  exportSymbol("_mlir_ciface_printMemrefF32", &_mlir_ciface_printMemrefF32);
+  exportSymbol("_mlir_ciface_printMemrefF64", &_mlir_ciface_printMemrefF64);
+  exportSymbol("_mlir_ciface_printMemrefInd", &_mlir_ciface_printMemrefInd);
+  exportSymbol("_mlir_ciface_printMemrefC32", &_mlir_ciface_printMemrefC32);
+  exportSymbol("_mlir_ciface_printMemrefC64", &_mlir_ciface_printMemrefC64);
+  exportSymbol("_mlir_ciface_nanoTime", &_mlir_ciface_nanoTime);
+  exportSymbol("printMemrefI32", &printMemrefI32);
+  exportSymbol("printMemrefI64", &printMemrefI64);
+  exportSymbol("printMemrefF32", &printMemrefF32);
+  exportSymbol("printMemrefF64", &printMemrefF64);
+  exportSymbol("printMemrefInd", &printMemrefInd);
+  exportSymbol("printMemrefC32", &printMemrefC32);
+  exportSymbol("printMemrefC64", &printMemrefC64);
+  exportSymbol("printCString", &printCString);
+  exportSymbol("_mlir_ciface_printMemref0dF32", &_mlir_ciface_printMemref0dF32);
+  exportSymbol("_mlir_ciface_printMemref1dF32", &_mlir_ciface_printMemref1dF32);
+  exportSymbol("_mlir_ciface_printMemref2dF32", &_mlir_ciface_printMemref2dF32);
+  exportSymbol("_mlir_ciface_printMemref3dF32", &_mlir_ciface_printMemref3dF32);
+  exportSymbol("_mlir_ciface_printMemref4dF32", &_mlir_ciface_printMemref4dF32);
+  exportSymbol("_mlir_ciface_printMemref1dI8", &_mlir_ciface_printMemref1dI8);
+  exportSymbol("_mlir_ciface_printMemref1dI32", &_mlir_ciface_printMemref1dI32);
+  exportSymbol("_mlir_ciface_printMemref1dI64", &_mlir_ciface_printMemref1dI64);
+  exportSymbol("_mlir_ciface_printMemref1dF64", &_mlir_ciface_printMemref1dF64);
+  exportSymbol("_mlir_ciface_printMemref1dInd", &_mlir_ciface_printMemref1dInd);
+  exportSymbol("_mlir_ciface_printMemref1dC32", &_mlir_ciface_printMemref1dC32);
+  exportSymbol("_mlir_ciface_printMemref1dC64", &_mlir_ciface_printMemref1dC64);
+  exportSymbol("_mlir_ciface_printMemrefVector4x4xf32",
+               &_mlir_ciface_printMemrefVector4x4xf32);
+  exportSymbol("_mlir_ciface_verifyMemRefI32", &_mlir_ciface_verifyMemRefI32);
+  exportSymbol("_mlir_ciface_verifyMemRefF32", &_mlir_ciface_verifyMemRefF32);
+  exportSymbol("_mlir_ciface_verifyMemRefF64", &_mlir_ciface_verifyMemRefF64);
+  exportSymbol("_mlir_ciface_verifyMemRefInd", &_mlir_ciface_verifyMemRefInd);
+  exportSymbol("_mlir_ciface_verifyMemRefC32", &_mlir_ciface_verifyMemRefC32);
+  exportSymbol("_mlir_ciface_verifyMemRefC64", &_mlir_ciface_verifyMemRefC64);
+  exportSymbol("verifyMemRefI32", &verifyMemRefI32);
+  exportSymbol("verifyMemRefF32", &verifyMemRefF32);
+  exportSymbol("verifyMemRefF64", &verifyMemRefF64);
+  exportSymbol("verifyMemRefInd", &verifyMemRefInd);
+  exportSymbol("verifyMemRefC32", &verifyMemRefC32);
+  exportSymbol("verifyMemRefC64", &verifyMemRefC64);
+}
+
+extern "C" MLIR_RUNNERUTILS_EXPORT void __mlir_execution_engine_destroy() {}
+
 // NOLINTEND(*-identifier-naming)


        


More information about the Mlir-commits mailing list