[Mlir-commits] [mlir] f9bce19 - [mlir][async] Mark exported symbols of runtime lib as visible.

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


Author: Ingo Müller
Date: 2023-06-20T19:27:47Z
New Revision: f9bce19e2e2be09768260d2a297d933f46bc3efd

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

LOG: [mlir][async] Mark exported symbols of runtime lib as visible.

The async runtime library explicitly registers the symbols it exports
with the loading mechanism of the execution engine. This even works even
though these symbols were marked as hidden in the library. However, if
used outside the execution engine, such as with `lli --dlopen` or if AOT
compiled, these hidden symbols would not be found. This patch thus marks
all symbols that are part of the API as visible.

Reviewed By: mehdi_amini

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

Added: 
    

Modified: 
    mlir/include/mlir/ExecutionEngine/AsyncRuntime.h
    mlir/lib/ExecutionEngine/AsyncRuntime.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/ExecutionEngine/AsyncRuntime.h b/mlir/include/mlir/ExecutionEngine/AsyncRuntime.h
index 3f65ec47841ef..063381ba5d67c 100644
--- a/mlir/include/mlir/ExecutionEngine/AsyncRuntime.h
+++ b/mlir/include/mlir/ExecutionEngine/AsyncRuntime.h
@@ -17,10 +17,20 @@
 #include <cstddef>
 #include <stdint.h>
 
+#ifdef _WIN32
+#ifndef MLIR_ASYNC_RUNTIME_EXPORT
 #ifdef mlir_async_runtime_EXPORTS
 // We are building this library
-#define MLIR_ASYNCRUNTIME_DEFINE_FUNCTIONS
+#define MLIR_ASYNC_RUNTIME_EXPORT __declspec(dllexport)
+#else
+// We are using this library
+#define MLIR_ASYNC_RUNTIME_EXPORT __declspec(dllimport)
 #endif // mlir_async_runtime_EXPORTS
+#endif // MLIR_ASYNC_RUNTIME_EXPORT
+#else
+// Non-windows: use visibility attributes.
+#define MLIR_ASYNC_RUNTIME_EXPORT __attribute__((visibility("default")))
+#endif // _WIN32
 
 namespace mlir {
 namespace runtime {
@@ -52,86 +62,105 @@ using CoroResume = void (*)(void *); // coroutine resume function
 using RefCountedObjPtr = void *;
 
 // Adds references to reference counted runtime object.
-extern "C" void mlirAsyncRuntimeAddRef(RefCountedObjPtr, int64_t);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT void
+    mlirAsyncRuntimeAddRef(RefCountedObjPtr, int64_t);
 
 // Drops references from reference counted runtime object.
-extern "C" void mlirAsyncRuntimeDropRef(RefCountedObjPtr, int64_t);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT void
+    mlirAsyncRuntimeDropRef(RefCountedObjPtr, int64_t);
 
 // Create a new `async.token` in not-ready state.
-extern "C" AsyncToken *mlirAsyncRuntimeCreateToken();
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT AsyncToken *mlirAsyncRuntimeCreateToken();
 
 // Create a new `async.value` in not-ready state. Size parameter specifies the
 // number of bytes that will be allocated for the async value storage. Storage
 // is owned by the `async.value` and deallocated when the async value is
 // destructed (reference count drops to zero).
-extern "C" AsyncValue *mlirAsyncRuntimeCreateValue(int64_t);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT AsyncValue *
+    mlirAsyncRuntimeCreateValue(int64_t);
 
 // Create a new `async.group` in empty state.
-extern "C" AsyncGroup *mlirAsyncRuntimeCreateGroup(int64_t size);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT AsyncGroup *
+mlirAsyncRuntimeCreateGroup(int64_t size);
 
-extern "C" int64_t mlirAsyncRuntimeAddTokenToGroup(AsyncToken *, AsyncGroup *);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT int64_t
+mlirAsyncRuntimeAddTokenToGroup(AsyncToken *, AsyncGroup *);
 
 // Switches `async.token` to ready state and runs all awaiters.
-extern "C" void mlirAsyncRuntimeEmplaceToken(AsyncToken *);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT void
+mlirAsyncRuntimeEmplaceToken(AsyncToken *);
 
 // Switches `async.value` to ready state and runs all awaiters.
-extern "C" void mlirAsyncRuntimeEmplaceValue(AsyncValue *);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT void
+mlirAsyncRuntimeEmplaceValue(AsyncValue *);
 
 // Switches `async.token` to error state and runs all awaiters.
-extern "C" void mlirAsyncRuntimeSetTokenError(AsyncToken *);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT void
+mlirAsyncRuntimeSetTokenError(AsyncToken *);
 
 // Switches `async.value` to error state and runs all awaiters.
-extern "C" void mlirAsyncRuntimeSetValueError(AsyncValue *);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT void
+mlirAsyncRuntimeSetValueError(AsyncValue *);
 
 // Returns true if token is in the error state.
-extern "C" bool mlirAsyncRuntimeIsTokenError(AsyncToken *);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT bool
+mlirAsyncRuntimeIsTokenError(AsyncToken *);
 
 // Returns true if value is in the error state.
-extern "C" bool mlirAsyncRuntimeIsValueError(AsyncValue *);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT bool
+mlirAsyncRuntimeIsValueError(AsyncValue *);
 
 // Returns true if group is in the error state (any of the tokens or values
 // added to the group are in the error state).
-extern "C" bool mlirAsyncRuntimeIsGroupError(AsyncGroup *);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT bool
+mlirAsyncRuntimeIsGroupError(AsyncGroup *);
 
 // Blocks the caller thread until the token becomes ready.
-extern "C" void mlirAsyncRuntimeAwaitToken(AsyncToken *);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT void
+mlirAsyncRuntimeAwaitToken(AsyncToken *);
 
 // Blocks the caller thread until the value becomes ready.
-extern "C" void mlirAsyncRuntimeAwaitValue(AsyncValue *);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT void
+mlirAsyncRuntimeAwaitValue(AsyncValue *);
 
 // Blocks the caller thread until the elements in the group become ready.
-extern "C" void mlirAsyncRuntimeAwaitAllInGroup(AsyncGroup *);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT void
+mlirAsyncRuntimeAwaitAllInGroup(AsyncGroup *);
 
 // Returns a pointer to the storage owned by the async value.
-extern "C" ValueStorage mlirAsyncRuntimeGetValueStorage(AsyncValue *);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT ValueStorage
+mlirAsyncRuntimeGetValueStorage(AsyncValue *);
 
 // Executes the task (coro handle + resume function) in one of the threads
 // managed by the runtime.
-extern "C" void mlirAsyncRuntimeExecute(CoroHandle, CoroResume);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT void mlirAsyncRuntimeExecute(CoroHandle,
+                                                                  CoroResume);
 
 // Executes the task (coro handle + resume function) in one of the threads
 // managed by the runtime after the token becomes ready.
-extern "C" void mlirAsyncRuntimeAwaitTokenAndExecute(AsyncToken *, CoroHandle,
-                                                     CoroResume);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT void
+mlirAsyncRuntimeAwaitTokenAndExecute(AsyncToken *, CoroHandle, CoroResume);
 
 // Executes the task (coro handle + resume function) in one of the threads
 // managed by the runtime after the value becomes ready.
-extern "C" void mlirAsyncRuntimeAwaitValueAndExecute(AsyncValue *, CoroHandle,
-                                                     CoroResume);
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT void
+mlirAsyncRuntimeAwaitValueAndExecute(AsyncValue *, CoroHandle, CoroResume);
 
 // Executes the task (coro handle + resume function) in one of the threads
 // managed by the runtime after the all members of the group become ready.
-extern "C" void
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT void
 mlirAsyncRuntimeAwaitAllInGroupAndExecute(AsyncGroup *, CoroHandle, CoroResume);
 
 // Returns the current number of available worker threads in the threadpool.
-extern "C" int64_t mlirAsyncRuntimGetNumWorkerThreads();
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT int64_t
+mlirAsyncRuntimGetNumWorkerThreads();
 
 //===----------------------------------------------------------------------===//
 // Small async runtime support library for testing.
 //===----------------------------------------------------------------------===//
 
-extern "C" void mlirAsyncRuntimePrintCurrentThreadId();
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT void
+mlirAsyncRuntimePrintCurrentThreadId();
 
 } // namespace runtime
 } // namespace mlir

diff  --git a/mlir/lib/ExecutionEngine/AsyncRuntime.cpp b/mlir/lib/ExecutionEngine/AsyncRuntime.cpp
index 878f85995e5d7..9d7e4000fe3be 100644
--- a/mlir/lib/ExecutionEngine/AsyncRuntime.cpp
+++ b/mlir/lib/ExecutionEngine/AsyncRuntime.cpp
@@ -13,8 +13,6 @@
 
 #include "mlir/ExecutionEngine/AsyncRuntime.h"
 
-#ifdef MLIR_ASYNCRUNTIME_DEFINE_FUNCTIONS
-
 #include <atomic>
 #include <cassert>
 #include <condition_variable>
@@ -455,21 +453,13 @@ extern "C" void mlirAsyncRuntimePrintCurrentThreadId() {
 // MLIR ExecutionEngine dynamic library integration.
 //===----------------------------------------------------------------------===//
 
-// Export symbols for the MLIR ExecutionEngine integration. All other symbols
-// are hidden.
-#ifdef _WIN32
-#define API __declspec(dllexport)
-#else
-#define API __attribute__((visibility("default")))
-#endif
-
 // 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.
 // NOLINTNEXTLINE(*-identifier-naming): externally called.
-extern "C" API void
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT void
 __mlir_execution_engine_init(llvm::StringMap<void *> &exportSymbols);
 
 // NOLINTNEXTLINE(*-identifier-naming): externally called.
@@ -528,11 +518,9 @@ void __mlir_execution_engine_init(llvm::StringMap<void *> &exportSymbols) {
 }
 
 // NOLINTNEXTLINE(*-identifier-naming): externally called.
-extern "C" API void __mlir_execution_engine_destroy() {
+extern "C" MLIR_ASYNC_RUNTIME_EXPORT void __mlir_execution_engine_destroy() {
   resetDefaultAsyncRuntime();
 }
 
 } // namespace runtime
 } // namespace mlir
-
-#endif // MLIR_ASYNCRUNTIME_DEFINE_FUNCTIONS


        


More information about the Mlir-commits mailing list