[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
This commit is contained in:
Christian Sigg 2021-01-28 15:29:27 +01:00
parent 469096d18e
commit 5bdc771fc9
4 changed files with 14 additions and 13 deletions

View 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}
)

View 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.

View 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}
)

View 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.