[OFFLOAD] Update CUDA and AMD plugins to new debug format (#175787)

This commit is contained in:
Alex Duran 2026-01-13 17:53:59 +01:00 committed by GitHub
parent e6cdfb75ac
commit efad3563ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 27 additions and 15 deletions

View File

@ -20,6 +20,8 @@
#include "hsa_ext_amd.h"
#include <memory>
using namespace llvm::offload::debug;
DLWRAP_INITIALIZE()
DLWRAP_INTERNAL(hsa_init, 0)
@ -93,7 +95,7 @@ static bool checkForHSA() {
auto DynlibHandle = std::make_unique<llvm::sys::DynamicLibrary>(
llvm::sys::DynamicLibrary::getPermanentLibrary(HsaLib, &ErrMsg));
if (!DynlibHandle->isValid()) {
DP("Unable to load library '%s': %s!\n", HsaLib, ErrMsg.c_str());
ODBG(OLDT_Init) << "Unable to load library '" << HsaLib << "': " << ErrMsg;
return false;
}
@ -102,10 +104,12 @@ static bool checkForHSA() {
void *P = DynlibHandle->getAddressOfSymbol(Sym);
if (P == nullptr) {
DP("Unable to find '%s' in '%s'!\n", Sym, HsaLib);
ODBG(OLDT_Init) << "Unable to find '" << Sym << "' in '" << HsaLib
<< "'!";
return false;
}
DP("Implementing %s with dlsym(%s) -> %p\n", Sym, Sym, P);
ODBG(OLDT_Init) << "Implementing " << Sym << " with dlsym(" << Sym
<< ") -> " << P;
*dlwrap::pointer(I) = P;
}

View File

@ -75,6 +75,7 @@
#include "hsa/hsa_ext_amd.h"
#endif
using namespace llvm::offload::debug;
using namespace error;
namespace llvm {
@ -558,7 +559,7 @@ struct AMDGPUKernelTy : public GenericKernelTy {
ImplicitArgsSize =
hsa_utils::getImplicitArgsSize(AMDImage.getELFABIVersion());
DP("ELFABIVersion: %d\n", AMDImage.getELFABIVersion());
ODBG(OLDT_Module) << "ELFABIVersion: " << AMDImage.getELFABIVersion();
// Get additional kernel info read from image
KernelInfo = AMDImage.getKernelInfo(getName());
@ -3488,7 +3489,7 @@ struct AMDGPUPluginTy final : public GenericPluginTy {
hsa_status_t Status = hsa_init();
if (Status != HSA_STATUS_SUCCESS) {
// Cannot call hsa_success_string.
DP("Failed to initialize AMDGPU's HSA library\n");
ODBG(OLDT_Init) << "Failed to initialize AMDGPU's HSA library";
return 0;
}
@ -3533,7 +3534,7 @@ struct AMDGPUPluginTy final : public GenericPluginTy {
int32_t NumDevices = KernelAgents.size();
if (NumDevices == 0) {
// Do not initialize if there are no devices.
DP("There are no devices supporting AMDGPU.\n");
ODBG(OLDT_Init) << "There are no devices supporting AMDGPU.";
return 0;
}

View File

@ -57,7 +57,7 @@ inline Error readAMDGPUMetaDataFromImage(
MemBuffer, KernelInfoMap, ELFABIVersion);
if (!Err)
return Err;
DP("ELFABIVERSION Version: %u\n", ELFABIVersion);
ODBG(OLDT_Module) << "ELFABIVERSION Version: " << ELFABIVersion;
return Err;
}

View File

@ -22,6 +22,8 @@
#include <string>
#include <unordered_map>
using namespace llvm::offload::debug;
DLWRAP_INITIALIZE()
DLWRAP_INTERNAL(cuInit, 1)
@ -143,7 +145,8 @@ static bool checkForCUDA() {
auto DynlibHandle = std::make_unique<llvm::sys::DynamicLibrary>(
llvm::sys::DynamicLibrary::getPermanentLibrary(CudaLib, &ErrMsg));
if (!DynlibHandle->isValid()) {
DP("Unable to load library '%s': %s!\n", CudaLib, ErrMsg.c_str());
ODBG(OLDT_Init) << "Unable to load library ' " << CudaLib << "': " << ErrMsg
<< "!";
return false;
}
@ -155,7 +158,8 @@ static bool checkForCUDA() {
const char *First = It->second;
void *P = DynlibHandle->getAddressOfSymbol(First);
if (P) {
DP("Implementing %s with dlsym(%s) -> %p\n", Sym, First, P);
ODBG(OLDT_Init) << "Implementing " << Sym << " with dlsym(" << First
<< ") -> " << P;
*dlwrap::pointer(I) = P;
continue;
}
@ -163,10 +167,12 @@ static bool checkForCUDA() {
void *P = DynlibHandle->getAddressOfSymbol(Sym);
if (P == nullptr) {
DP("Unable to find '%s' in '%s'!\n", Sym, CudaLib);
ODBG(OLDT_Init) << "Unable to find '" << Sym << "' in '" << CudaLib
<< "'!";
return false;
}
DP("Implementing %s with dlsym(%s) -> %p\n", Sym, Sym, P);
ODBG(OLDT_Init) << "Implementing " << Sym << " with dlsym(" << Sym
<< ") -> " << P;
*dlwrap::pointer(I) = P;
}

View File

@ -34,6 +34,7 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Program.h"
using namespace llvm::offload::debug;
using namespace error;
namespace llvm {
@ -1552,13 +1553,13 @@ struct CUDAPluginTy final : public GenericPluginTy {
CUresult Res = cuInit(0);
if (Res == CUDA_ERROR_INVALID_HANDLE) {
// Cannot call cuGetErrorString if dlsym failed.
DP("Failed to load CUDA shared library\n");
ODBG(OLDT_Init) << "Failed to load CUDA shared library";
return 0;
}
if (Res == CUDA_ERROR_NO_DEVICE) {
// Do not initialize if there are no devices.
DP("There are no devices supporting CUDA.\n");
ODBG(OLDT_Init) << "There are no devices supporting CUDA.";
return 0;
}
@ -1573,7 +1574,7 @@ struct CUDAPluginTy final : public GenericPluginTy {
// Do not initialize if there are no devices.
if (NumDevices == 0)
DP("There are no devices supporting CUDA.\n");
ODBG(OLDT_Init) << "There are no devices supporting CUDA.";
return NumDevices;
}
@ -1681,7 +1682,7 @@ Error CUDADeviceTy::dataExchangeImpl(const void *SrcPtr,
if (Res == CUDA_ERROR_TOO_MANY_PEERS) {
// Resources may be exhausted due to many P2P links.
CanAccessPeer = 0;
DP("Too many P2P so fall back to D2D memcpy");
ODBG(OLDT_DataTransfer) << "Too many P2P so fall back to D2D memcpy";
} else if (auto Err =
Plugin::check(Res, "error in cuCtxEnablePeerAccess: %s"))
return Err;