[mlir] Make cuda/rocm-runtime-wrappers not depend on LLVMSupport.
authorChristian Sigg <csigg@google.com>
Thu, 28 Jan 2021 14:29:27 +0000 (15:29 +0100)
committerChristian Sigg <csigg@google.com>
Thu, 28 Jan 2021 16:25:01 +0000 (17:25 +0100)
Depending on the headers only is fine, but we do not want to use any symbols from LLVMSupport. If we do, static registration of cl options is linked in as well, and loading multiple such libraries in the cuda/rocm-runner fails because the same cl options are registered multiple times.

The cuda/rocm-runners also depend on LLVMSupport, so one could think that already loading a single such library would fail. It does not because the map of cl options is not shared between the runner and the loaded libraries (but it is shared across all loaded libraries, presumably because it has external linkage, in contrast to the static registration which has internal linkage).

This change is a preparation step for dynamically loading the mlir_async_runtime.so and cuda-runtime-wrappers.so in the same test. The async runtime depends on LLVMSupport in a more fundamental way (llvm::ThreadPool), and as explained above there can only be one.

This change also switches to add_mlir_library to make it consistent with the other runner_utils libraries.

Reviewed By: herhut

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

mlir/tools/mlir-cuda-runner/CMakeLists.txt
mlir/tools/mlir-cuda-runner/cuda-runtime-wrappers.cpp
mlir/tools/mlir-rocm-runner/CMakeLists.txt
mlir/tools/mlir-rocm-runner/rocm-runtime-wrappers.cpp

index 8a99418..f9c5bc0 100644 (file)
@@ -27,16 +27,18 @@ if(MLIR_CUDA_RUNNER_ENABLED)
   # We need the libcuda.so library.
   find_library(CUDA_RUNTIME_LIBRARY cuda)
 
-  add_llvm_library(cuda-runtime-wrappers SHARED
+  add_mlir_library(cuda-runtime-wrappers
+    SHARED
     cuda-runtime-wrappers.cpp
+
+    EXCLUDE_FROM_LIBMLIR
   )
   target_include_directories(cuda-runtime-wrappers
-    PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
-    LLVMSupport
+    PRIVATE
+    ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
   )
   target_link_libraries(cuda-runtime-wrappers
-    PUBLIC
-    LLVMSupport
+    PRIVATE
     ${CUDA_RUNTIME_LIBRARY}
   )
 
index 306ca51..d4360de 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "mlir/ExecutionEngine/CRunnerUtils.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/Support/raw_ostream.h"
 
 #include "cuda.h"
 
@@ -29,7 +28,7 @@
     cuGetErrorName(result, &name);                                             \
     if (!name)                                                                 \
       name = "<unknown>";                                                      \
-    llvm::errs() << "'" << #expr << "' failed with '" << name << "'\n";        \
+    fprintf(stderr, "'%s' failed with '%s'\n", #expr, name);                   \
   }(expr)
 
 // Static reference to CUDA primary context for device ordinal 0.
index a4da496..effcbaf 100644 (file)
@@ -49,18 +49,19 @@ if(MLIR_ROCM_RUNNER_ENABLED)
   # Set HIP compile-time flags.
   add_definitions(-D__HIP_PLATFORM_HCC__)
 
-  add_llvm_library(rocm-runtime-wrappers SHARED
+  add_mlir_library(rocm-runtime-wrappers
+    SHARED
     rocm-runtime-wrappers.cpp
+
+    EXCLUDE_FROM_LIBMLIR
   )
   target_include_directories(rocm-runtime-wrappers
     PRIVATE
     "${HIP_PATH}/../include"
     "${HIP_PATH}/include"
-    LLVMSupport
   )
   target_link_libraries(rocm-runtime-wrappers
-    PUBLIC
-    LLVMSupport
+    PRIVATE
     ${ROCM_RUNTIME_LIBRARY}
   )
 
index 5f693c3..cf3c757 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "mlir/ExecutionEngine/CRunnerUtils.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/Support/raw_ostream.h"
 
 #include "hip/hip_runtime.h"
 
@@ -28,7 +27,7 @@
     const char *name = hipGetErrorName(result);                                \
     if (!name)                                                                 \
       name = "<unknown>";                                                      \
-    llvm::errs() << "'" << #expr << "' failed with '" << name << "'\n";        \
+    fprintf(stderr, "'%s' failed with '%s'\n", #expr, name);                   \
   }(expr)
 
 // Static reference to HIP primary context for device ordinal 0.