Do not build the CUBIN conversion pass when NVPTX Backend isn't configured

This pass would currently build, but fail to run when this backend isn't
linked in. On the other hand, we'd like it to initialize only the NVPTX
backend, which isn't possible if we continue to build it without the
backend available. Instead of building a broken configuration, let's
skip building the pass entirely.

Differential Revision: https://reviews.llvm.org/D74592
This commit is contained in:
Mehdi Amini 2020-02-14 09:12:41 +00:00
parent 07211d951d
commit 850cb135a3
4 changed files with 18 additions and 4 deletions

View file

@ -44,6 +44,8 @@ if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
else()
set(MLIR_CUDA_CONVERSIONS_ENABLED 0)
endif()
# TODO: we should use a config.h file like LLVM does
add_definitions(-DMLIR_CUDA_CONVERSIONS_ENABLED=${MLIR_CUDA_CONVERSIONS_ENABLED})
set(MLIR_CUDA_RUNNER_ENABLED 0 CACHE BOOL "Enable building the mlir CUDA runner")

View file

@ -90,8 +90,10 @@ inline void registerAllPasses() {
// CUDA
createConvertGpuLaunchFuncToCudaCallsPass();
#if MLIR_CUDA_CONVERSIONS_ENABLED
createConvertGPUKernelToCubinPass(
[](const std::string &, Location, StringRef) { return nullptr; });
#endif
createLowerGpuOpsToNVVMOpsPass();
// Linalg

View file

@ -1,7 +1,16 @@
add_llvm_library(MLIRGPUtoCUDATransforms
set(LLVM_OPTIONAL_SOURCES
ConvertKernelFuncToCubin.cpp
)
set(SOURCES
ConvertLaunchFuncToCudaCalls.cpp
)
if (MLIR_CUDA_CONVERSIONS_ENABLED)
list(APPEND SOURCES "ConvertKernelFuncToCubin.cpp")
endif()
add_llvm_library(MLIRGPUtoCUDATransforms ${SOURCES})
target_link_libraries(MLIRGPUtoCUDATransforms
MLIRGPU
MLIRLLVMIR

View file

@ -57,9 +57,10 @@ public:
gpu::GPUModuleOp module = getOperation();
// Make sure the NVPTX target is initialized.
llvm::InitializeAllTargets();
llvm::InitializeAllTargetMCs();
llvm::InitializeAllAsmPrinters();
LLVMInitializeNVPTXTarget();
LLVMInitializeNVPTXTargetInfo();
LLVMInitializeNVPTXTargetMC();
LLVMInitializeNVPTXAsmPrinter();
auto llvmModule = translateModuleToNVVMIR(module);
if (!llvmModule)