Skip to content

Conversation

@jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Aug 4, 2025

Summary:
This tool tries to print the offloading architectures. If the user
doesn't have the HIP libraries or the CUDA libraries it will print and error.
This isn't super helpful since we're just querying things. So, for
example, if we're on an AMD machine with no CUDA you'll get the AMD GPUs
and then an error message saying that CUDA wasn't found. This silences
the error just on failing to find the library unless verbose is on.

Summary:
This tool tries to print the offloading architectures. If the user
doesn't have the HIP libraries or the CUDA libraries it will print this.
This isn't super helpful since we're just querying things. So, for
example, if we're on an AMD machine with no CUDA you'll get the AMD GPUs
and then an error message saying that CUDA wasn't found. This silences
the error just on failing to find the library unless verbose is on.
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:AMDGPU labels Aug 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 4, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Joseph Huber (jhuber6)

Changes

Summary:
This tool tries to print the offloading architectures. If the user
doesn't have the HIP libraries or the CUDA libraries it will print this.
This isn't super helpful since we're just querying things. So, for
example, if we're on an AMD machine with no CUDA you'll get the AMD GPUs
and then an error message saying that CUDA wasn't found. This silences
the error just on failing to find the library unless verbose is on.


Full diff: https://github.com/llvm/llvm-project/pull/151964.diff

2 Files Affected:

  • (modified) clang/tools/offload-arch/AMDGPUArchByHIP.cpp (+3-2)
  • (modified) clang/tools/offload-arch/NVPTXArch.cpp (+6-1)
diff --git a/clang/tools/offload-arch/AMDGPUArchByHIP.cpp b/clang/tools/offload-arch/AMDGPUArchByHIP.cpp
index 02431bf909d6d..11cff4f5ecdbe 100644
--- a/clang/tools/offload-arch/AMDGPUArchByHIP.cpp
+++ b/clang/tools/offload-arch/AMDGPUArchByHIP.cpp
@@ -165,8 +165,9 @@ int printGPUsByHIP() {
       llvm::sys::DynamicLibrary::getPermanentLibrary(DynamicHIPPath.c_str(),
                                                      &ErrMsg));
   if (!DynlibHandle->isValid()) {
-    llvm::errs() << "Failed to load " << DynamicHIPPath << ": " << ErrMsg
-                 << '\n';
+    if (Verbose)
+      llvm::errs() << "Failed to load " << DynamicHIPPath << ": " << ErrMsg
+                   << '\n';
     return 1;
   }
 
diff --git a/clang/tools/offload-arch/NVPTXArch.cpp b/clang/tools/offload-arch/NVPTXArch.cpp
index c7b7fcdf80500..11ea2e79cd279 100644
--- a/clang/tools/offload-arch/NVPTXArch.cpp
+++ b/clang/tools/offload-arch/NVPTXArch.cpp
@@ -21,6 +21,8 @@
 
 using namespace llvm;
 
+extern cl::opt<bool> Verbose;
+
 typedef enum cudaError_enum {
   CUDA_SUCCESS = 0,
   CUDA_ERROR_NO_DEVICE = 100,
@@ -78,7 +80,10 @@ static int handleError(CUresult Err) {
 int printGPUsByCUDA() {
   // Attempt to load the NVPTX driver runtime.
   if (llvm::Error Err = loadCUDA()) {
-    logAllUnhandledErrors(std::move(Err), llvm::errs());
+    if (Verbose)
+      logAllUnhandledErrors(std::move(Err), llvm::errs());
+    else
+      consumeError(std::move(Err));
     return 1;
   }
 

@llvmbot
Copy link
Member

llvmbot commented Aug 4, 2025

@llvm/pr-subscribers-clang

Author: Joseph Huber (jhuber6)

Changes

Summary:
This tool tries to print the offloading architectures. If the user
doesn't have the HIP libraries or the CUDA libraries it will print this.
This isn't super helpful since we're just querying things. So, for
example, if we're on an AMD machine with no CUDA you'll get the AMD GPUs
and then an error message saying that CUDA wasn't found. This silences
the error just on failing to find the library unless verbose is on.


Full diff: https://github.com/llvm/llvm-project/pull/151964.diff

2 Files Affected:

  • (modified) clang/tools/offload-arch/AMDGPUArchByHIP.cpp (+3-2)
  • (modified) clang/tools/offload-arch/NVPTXArch.cpp (+6-1)
diff --git a/clang/tools/offload-arch/AMDGPUArchByHIP.cpp b/clang/tools/offload-arch/AMDGPUArchByHIP.cpp
index 02431bf909d6d..11cff4f5ecdbe 100644
--- a/clang/tools/offload-arch/AMDGPUArchByHIP.cpp
+++ b/clang/tools/offload-arch/AMDGPUArchByHIP.cpp
@@ -165,8 +165,9 @@ int printGPUsByHIP() {
       llvm::sys::DynamicLibrary::getPermanentLibrary(DynamicHIPPath.c_str(),
                                                      &ErrMsg));
   if (!DynlibHandle->isValid()) {
-    llvm::errs() << "Failed to load " << DynamicHIPPath << ": " << ErrMsg
-                 << '\n';
+    if (Verbose)
+      llvm::errs() << "Failed to load " << DynamicHIPPath << ": " << ErrMsg
+                   << '\n';
     return 1;
   }
 
diff --git a/clang/tools/offload-arch/NVPTXArch.cpp b/clang/tools/offload-arch/NVPTXArch.cpp
index c7b7fcdf80500..11ea2e79cd279 100644
--- a/clang/tools/offload-arch/NVPTXArch.cpp
+++ b/clang/tools/offload-arch/NVPTXArch.cpp
@@ -21,6 +21,8 @@
 
 using namespace llvm;
 
+extern cl::opt<bool> Verbose;
+
 typedef enum cudaError_enum {
   CUDA_SUCCESS = 0,
   CUDA_ERROR_NO_DEVICE = 100,
@@ -78,7 +80,10 @@ static int handleError(CUresult Err) {
 int printGPUsByCUDA() {
   // Attempt to load the NVPTX driver runtime.
   if (llvm::Error Err = loadCUDA()) {
-    logAllUnhandledErrors(std::move(Err), llvm::errs());
+    if (Verbose)
+      logAllUnhandledErrors(std::move(Err), llvm::errs());
+    else
+      consumeError(std::move(Err));
     return 1;
   }
 

@arsenm arsenm changed the title [Clang] Hide offload-arch initialization erros behind verbose flag [Clang] Hide offload-arch initialization errors behind verbose flag Aug 4, 2025
llvm::errs() << "Failed to load " << DynamicHIPPath << ": " << ErrMsg
<< '\n';
if (Verbose)
llvm::errs() << "Failed to load " << DynamicHIPPath << ": " << ErrMsg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors should start with lowercase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably do a big monolithic NFC that updates a lot of cases like this.

@jhuber6 jhuber6 merged commit 25c02fb into llvm:main Aug 4, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:AMDGPU clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants