Skip to content

Commit

Permalink
[MLIR] Fix triple mismatch warning for embedded libdevice (llvm#121447)
Browse files Browse the repository at this point in the history
IRLinker emits warning when linking two modules of different target
triples. The warning is disabled if the source module is libdevice. When
using libdevice embedded in LLVM library via MLIR_NVVM_EMBED_LIBDEVICE,
IRLinker can no longer tell whether the source module is libdevice via
module identifier.

Since `nvptx64-nvidia-gpulibs` is a magic triple that identifies the
libdevice module already, the libdevice filename check is redundant.
This patch fixes the triple mismatch warning by just removing the
filename check.
  • Loading branch information
arthurqiu authored Jan 6, 2025
1 parent 14ba3f9 commit 05bd7d2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
8 changes: 2 additions & 6 deletions llvm/lib/Linker/IRMover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1562,10 +1562,6 @@ Error IRLinker::run() {
bool EnableDLWarning = true;
bool EnableTripleWarning = true;
if (SrcTriple.isNVPTX() && DstTriple.isNVPTX()) {
std::string ModuleId = SrcM->getModuleIdentifier();
StringRef FileName = llvm::sys::path::filename(ModuleId);
bool SrcIsLibDevice =
FileName.starts_with("libdevice") && FileName.ends_with(".10.bc");
bool SrcHasLibDeviceDL =
(SrcM->getDataLayoutStr().empty() ||
SrcM->getDataLayoutStr() == "e-i64:64-v16:16-v32:32-n16:32:64");
Expand All @@ -1576,8 +1572,8 @@ Error IRLinker::run() {
SrcTriple.getOSName() == "gpulibs") ||
(SrcTriple.getVendorName() == "unknown" &&
SrcTriple.getOSName() == "unknown");
EnableTripleWarning = !(SrcIsLibDevice && SrcHasLibDeviceTriple);
EnableDLWarning = !(SrcIsLibDevice && SrcHasLibDeviceDL);
EnableTripleWarning = !SrcHasLibDeviceTriple;
EnableDLWarning = !(SrcHasLibDeviceTriple && SrcHasLibDeviceDL);
}

if (EnableDLWarning && (SrcM->getDataLayout() != DstM.getDataLayout())) {
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/Linker/Inputs/libdevice-with-wrong-dl.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target triple = "nvptx64-nvidia-gpulibs"
target datalayout = "e-i64:64-i128:128-v32:32-n16:32:64"
10 changes: 5 additions & 5 deletions llvm/test/Linker/cuda-libdevice.ll
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
; RUN: llvm-as %p/Inputs/libdevice-cuda-9.ll -o %t/libdevice.compute_35.10.bc
; RUN: llvm-as %p/Inputs/libdevice-cuda-10.ll -o %t/libdevice.10.bc
; RUN: llvm-as %p/Inputs/libdevice-cuda-11.ll -o %t/libdevice.11.10.bc
; RUN: llvm-as %p/Inputs/libdevice-cuda-9.ll -o %t/correct-libdevice-wrong-filename.bc
; RUN: llvm-as %p/Inputs/not-a-libdevice.ll -o %t/libdevice-with-wrong-info.bc
; RUN: llvm-as %p/Inputs/libdevice-with-wrong-dl.ll -o %t/libdevice-with-wrong-dl.bc

; No warnings expected when we link with libdevice variants
; RUN: llvm-link %t/main.bc %t/libdevice.compute_35.10.bc -S 2>&1 \
Expand All @@ -15,12 +15,12 @@
; RUN: llvm-link %t/main.bc %t/libdevice.11.10.bc -S 2>&1 \
; RUN: | FileCheck --check-prefixes COMMON,NOWARN %s

; But make sure we still issue warnings if we see unexpected filename, or
; unexpected triple or datalayout within a libdevice filename.
; RUN: llvm-link %t/main.bc %t/correct-libdevice-wrong-filename.bc -S 2>&1 \
; RUN: | FileCheck --check-prefixes COMMON,WARN-TRIPLE %s
; But make sure we still issue warnings if we see unexpected triple or
; datalayout within a libdevice module.
; RUN: llvm-link %t/main.bc %t/libdevice-with-wrong-info.bc -S 2>&1 \
; RUN: | FileCheck --check-prefixes COMMON,WARN-TRIPLE,WARN-DL %s
; RUN: llvm-link %t/main.bc %t/libdevice-with-wrong-dl.bc -S 2>&1 \
; RUN: | FileCheck --check-prefixes COMMON,NOWARN,WARN-DL %s


target triple = "nvptx64-nvidia-cuda"
Expand Down

0 comments on commit 05bd7d2

Please sign in to comment.