Skip to content

Commit cf50f4f

Browse files
committed
[mlir] Link mlir_runner_utils statically into cuda/rocm-runtime-wrappers.
The runtime-wrappers depend on LLVMSupport, pulling in static initialization code (e.g. command line arguments). Dynamically loading multiple such libraries results in ODR violoations. So far this has not been an issue, but in D94421, I would like to load both the async-runtime and the cuda-runtime-wrappers as part of a cuda-runner integration test. When doing this, code that asserts that an option category is only registered once fails (note that I've only experienced this in Google's bazel where the async-runtime depends on LLVMSupport, but a similar issue would happen in cmake if more than one runtime-wrapper starts to depend on LLVMSupport). The underlying issue is that we have a mix of static and dynamic linking. If all dependencies were loaded as shared objects (i.e. if LLVMSupport was linked dynamically to the runtime wrappers), each dependency would only get loaded once. However, linking dependencies dynamically would require special attention to paths (one could dynamically load the dependencies first given explicit paths). The simpler approach seems to be to link all dependencies statically into a single shared object. This change basically applies the same logic that we have in the c_runner_utils: we have a shared object target that can be loaded dynamically, and we have a static library target that can be linked to other runtime-wrapper shared object targets. Reviewed By: herhut Differential Revision: https://reviews.llvm.org/D94399
1 parent 29aaae2 commit cf50f4f

19 files changed

+83
-17
lines changed

mlir/include/mlir/ExecutionEngine/CRunnerUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define MLIR_CRUNNERUTILS_EXPORT __declspec(dllimport)
2727
#endif // mlir_c_runner_utils_EXPORTS
2828
#endif // MLIR_CRUNNERUTILS_EXPORT
29-
#else
29+
#else // _WIN32
3030
#define MLIR_CRUNNERUTILS_EXPORT
3131
#define MLIR_CRUNNERUTILS_DEFINE_FUNCTIONS
3232
#endif // _WIN32

mlir/lib/ExecutionEngine/CMakeLists.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ add_mlir_library(mlir_c_runner_utils
8080
EXCLUDE_FROM_LIBMLIR
8181
)
8282
set_property(TARGET mlir_c_runner_utils PROPERTY CXX_STANDARD 11)
83+
target_compile_definitions(mlir_c_runner_utils PRIVATE mlir_c_runner_utils_EXPORTS)
8384

8485
add_mlir_library(mlir_c_runner_utils_static
8586
CRunnerUtils.cpp
@@ -88,7 +89,6 @@ add_mlir_library(mlir_c_runner_utils_static
8889
EXCLUDE_FROM_LIBMLIR
8990
)
9091
set_property(TARGET mlir_c_runner_utils_static PROPERTY CXX_STANDARD 11)
91-
target_compile_definitions(mlir_c_runner_utils PRIVATE mlir_c_runner_utils_EXPORTS)
9292

9393
add_mlir_library(mlir_runner_utils
9494
SHARED
@@ -101,6 +101,15 @@ add_mlir_library(mlir_runner_utils
101101
)
102102
target_compile_definitions(mlir_runner_utils PRIVATE mlir_runner_utils_EXPORTS)
103103

104+
add_mlir_library(mlir_runner_utils_static
105+
RunnerUtils.cpp
106+
107+
EXCLUDE_FROM_LIBMLIR
108+
109+
LINK_LIBS PUBLIC
110+
mlir_c_runner_utils_static
111+
)
112+
104113
add_mlir_library(mlir_async_runtime
105114
SHARED
106115
AsyncRuntime.cpp
@@ -113,3 +122,13 @@ add_mlir_library(mlir_async_runtime
113122
)
114123
set_property(TARGET mlir_async_runtime PROPERTY CXX_VISIBILITY_PRESET hidden)
115124
target_compile_definitions(mlir_async_runtime PRIVATE mlir_async_runtime_EXPORTS)
125+
126+
add_mlir_library(mlir_async_runtime_static
127+
AsyncRuntime.cpp
128+
129+
EXCLUDE_FROM_LIBMLIR
130+
131+
LINK_LIBS PUBLIC
132+
mlir_c_runner_utils_static
133+
${LLVM_PTHREAD_LIB}
134+
)

mlir/test/mlir-cuda-runner/all-reduce-and.mlir

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: mlir-cuda-runner %s --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-cuda-runner %s \
2+
// RUN: --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext
3+
// RUN: --entry-point-result=void \
4+
// RUN: | FileCheck %s
25

36
func @main() {
47
%data = alloc() : memref<2x6xi32>

mlir/test/mlir-cuda-runner/all-reduce-max.mlir

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: mlir-cuda-runner %s --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-cuda-runner %s \
2+
// RUN: --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext
3+
// RUN: --entry-point-result=void \
4+
// RUN: | FileCheck %s
25

36
func @main() {
47
%data = alloc() : memref<2x6xi32>

mlir/test/mlir-cuda-runner/all-reduce-min.mlir

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: mlir-cuda-runner %s --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-cuda-runner %s \
2+
// RUN: --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext
3+
// RUN: --entry-point-result=void \
4+
// RUN: | FileCheck %s
25

36
func @main() {
47
%data = alloc() : memref<2x6xi32>

mlir/test/mlir-cuda-runner/all-reduce-op.mlir

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: mlir-cuda-runner %s --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-cuda-runner %s \
2+
// RUN: --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext
3+
// RUN: --entry-point-result=void \
4+
// RUN: | FileCheck %s
25

36
// CHECK-COUNT-8: [{{(5356, ){12}5356}}]
47
func @main() {

mlir/test/mlir-cuda-runner/all-reduce-or.mlir

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: mlir-cuda-runner %s --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-cuda-runner %s \
2+
// RUN: --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext
3+
// RUN: --entry-point-result=void \
4+
// RUN: | FileCheck %s
25

36
func @main() {
47
%data = alloc() : memref<2x6xi32>

mlir/test/mlir-cuda-runner/all-reduce-region.mlir

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: mlir-cuda-runner %s --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-cuda-runner %s \
2+
// RUN: --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext
3+
// RUN: --entry-point-result=void \
4+
// RUN: | FileCheck %s
25

36
// CHECK: [{{(35, ){34}35}}]
47
func @main() {

mlir/test/mlir-cuda-runner/all-reduce-xor.mlir

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: mlir-cuda-runner %s --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-cuda-runner %s \
2+
// RUN: --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext
3+
// RUN: --entry-point-result=void \
4+
// RUN: | FileCheck %s
25

36
func @main() {
47
%data = alloc() : memref<2x6xi32>

mlir/test/mlir-cuda-runner/gpu-to-cubin.mlir

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: mlir-cuda-runner %s --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext --entry-point-result=void | FileCheck %s
1+
// RUN: mlir-cuda-runner %s \
2+
// RUN: --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext
3+
// RUN: --entry-point-result=void \
4+
// RUN: | FileCheck %s
25

36
func @other_func(%arg0 : f32, %arg1 : memref<?xf32>) {
47
%cst = constant 1 : index

0 commit comments

Comments
 (0)