Skip to content

Commit

Permalink
GPU: use driver reported adapter name if available
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Sep 27, 2024
1 parent 5058a93 commit 4eac17f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
3 changes: 3 additions & 0 deletions src/detection/gpu/gpu_amd.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,8 @@ const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResu
if (result.index)
*result.type = (uint32_t) device->adlAdapterIndex;

if (result.name)
ffStrbufSetS(result->name, device->adapterString);

return NULL;
}
26 changes: 13 additions & 13 deletions src/detection/gpu/gpu_bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
gpu->deviceId = (pc->pc_sel.pc_domain * 100000ull) + (pc->pc_sel.pc_bus * 1000ull) + (pc->pc_sel.pc_dev * 10ull) + pc->pc_sel.pc_func;
gpu->frequency = FF_GPU_FREQUENCY_UNSET;

if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD)
{
char query[32];
snprintf(query, sizeof(query), "%X,\t%X,", (unsigned) pc->pc_device, (unsigned) pc->pc_revid);
ffParsePropFileData("libdrm/amdgpu.ids", query, &gpu->name);
}

if (gpu->name.length == 0)
{
ffGPUFillVendorAndName(pc->pc_subclass, pc->pc_vendor, pc->pc_device, gpu);
}

if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || options->driverSpecific))
{
ffDetectNvidiaGpuInfo(&(FFGpuDriverCondition) {
Expand All @@ -79,10 +67,22 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
.type = &gpu->type,
.frequency = &gpu->frequency,
.coreUsage = &gpu->coreUsage,
.name = options->driverSpecific ? &gpu->name : NULL,
.name = &gpu->name,
}, "libnvidia-ml.so");
}

if (gpu->name.length == 0)
{
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD)
{
char query[32];
snprintf(query, sizeof(query), "%X,\t%X,", (unsigned) pc->pc_device, (unsigned) pc->pc_revid);
ffParsePropFileData("libdrm/amdgpu.ids", query, &gpu->name);
}
if (gpu->name.length == 0)
ffGPUFillVendorAndName(pc->pc_subclass, pc->pc_vendor, pc->pc_device, gpu);
}

if (gpu->type == FF_GPU_TYPE_UNKNOWN)
{
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA)
Expand Down
10 changes: 4 additions & 6 deletions src/detection/gpu/gpu_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,6 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf

if (drmKey) ffStrbufSetF(&gpu->platformApi, "DRM (%s)", drmKey);

if (gpu->name.length == 0)
{
ffGPUFillVendorAndName(subclassId, (uint16_t) vendorId, (uint16_t) deviceId, gpu);
}

pciDetectDriver(&gpu->driver, deviceDir, buffer, drmKey);
ffStrbufSubstrBefore(deviceDir, drmDirPathLength);

Expand Down Expand Up @@ -367,7 +362,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf
.coreUsage = options->driverSpecific ? &gpu->coreUsage : NULL,
.type = &gpu->type,
.frequency = options->driverSpecific ? &gpu->frequency : NULL,
.name = options->driverSpecific ? &gpu->name : NULL,
.name = &gpu->name,
}, soName);
}

Expand All @@ -388,6 +383,9 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf
}
}

if (gpu->name.length == 0)
ffGPUFillVendorAndName(subclassId, (uint16_t) vendorId, (uint16_t) deviceId, gpu);

return NULL;
}

Expand Down
9 changes: 7 additions & 2 deletions src/detection/gpu/gpu_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
}

wchar_t buffer[256];
if (SetupDiGetDeviceRegistryPropertyW(hdev, &did, SPDRP_DEVICEDESC, NULL, (PBYTE) buffer, sizeof(buffer), NULL))
ffStrbufSetWS(&gpu->name, buffer);

uint64_t adapterLuid = 0;

Expand Down Expand Up @@ -175,11 +173,18 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
.coreCount = options->driverSpecific ? (uint32_t*) &gpu->coreCount : NULL,
.coreUsage = options->driverSpecific ? &gpu->coreUsage : NULL,
.type = &gpu->type,
.name = &gpu->name,
.frequency = options->driverSpecific ? &gpu->frequency : NULL,
},
dllName
);
}

if (!gpu->name.length)
{
if (SetupDiGetDeviceRegistryPropertyW(hdev, &did, SPDRP_DEVICEDESC, NULL, (PBYTE) buffer, sizeof(buffer), NULL))
ffStrbufSetWS(&gpu->name, buffer);
}
}

return NULL;
Expand Down

0 comments on commit 4eac17f

Please sign in to comment.