[Mlir-commits] [mlir] 5bdc771 - [mlir] Make cuda/rocm-runtime-wrappers not depend on LLVMSupport.

Christian Sigg llvmlistbot at llvm.org
Thu Jan 28 08:25:16 PST 2021


Author: Christian Sigg
Date: 2021-01-28T17:25:01+01:00
New Revision: 5bdc771fc97ed752af42562c33a18c3ea28b098e

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

LOG: [mlir] Make cuda/rocm-runtime-wrappers not depend on LLVMSupport.

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

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/mlir/tools/mlir-cuda-runner/CMakeLists.txt b/mlir/tools/mlir-cuda-runner/CMakeLists.txt
index 8a99418ebf65..f9c5bc0e23e8 100644
--- a/mlir/tools/mlir-cuda-runner/CMakeLists.txt
+++ b/mlir/tools/mlir-cuda-runner/CMakeLists.txt
@@ -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}
   )
 

diff  --git a/mlir/tools/mlir-cuda-runner/cuda-runtime-wrappers.cpp b/mlir/tools/mlir-cuda-runner/cuda-runtime-wrappers.cpp
index 306ca5106fa4..d4360de76ed9 100644
--- a/mlir/tools/mlir-cuda-runner/cuda-runtime-wrappers.cpp
+++ b/mlir/tools/mlir-cuda-runner/cuda-runtime-wrappers.cpp
@@ -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.

diff  --git a/mlir/tools/mlir-rocm-runner/CMakeLists.txt b/mlir/tools/mlir-rocm-runner/CMakeLists.txt
index a4da49673027..effcbaf5af36 100644
--- a/mlir/tools/mlir-rocm-runner/CMakeLists.txt
+++ b/mlir/tools/mlir-rocm-runner/CMakeLists.txt
@@ -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}
   )
 

diff  --git a/mlir/tools/mlir-rocm-runner/rocm-runtime-wrappers.cpp b/mlir/tools/mlir-rocm-runner/rocm-runtime-wrappers.cpp
index 5f693c34a2a7..cf3c75720807 100644
--- a/mlir/tools/mlir-rocm-runner/rocm-runtime-wrappers.cpp
+++ b/mlir/tools/mlir-rocm-runner/rocm-runtime-wrappers.cpp
@@ -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.


        


More information about the Mlir-commits mailing list