GPU (Linux): try detecting vmem with gpu kernel module

This commit is contained in:
Carter Li
2024-04-17 14:21:30 +08:00
committed by 李通洲
parent f098cdbf69
commit 6d36ec55c5
+30 -1
View File
@@ -20,8 +20,9 @@ FF_MAYBE_UNUSED static void pciDetectTemp(FFGPUResult* gpu, uint32_t deviceClass
FF_LIST_FOR_EACH(FFTempValue, tempValue, *tempsResult)
{
// https://www.kernel.org/doc/html/v5.10/gpu/amdgpu.html#hwmon-interfaces
// FIXME: this code doesn't take multiGPUs into count
//The kernel exposes the device class multiplied by 256 for some reason
// The kernel exposes the device class multiplied by 256 for some reason
if(tempValue->deviceClass == deviceClass * 256)
{
gpu->temperature = tempValue->value;
@@ -54,6 +55,31 @@ static void pciDetectDriver(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer
}
}
static void pciDetectVmem(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer)
{
// https://www.kernel.org/doc/html/v5.10/gpu/amdgpu.html#mem-info-vis-vram-total
ffStrbufAppendS(pciDir, "/mem_info_vis_vram_total");
uint64_t size = 0;
if (ffReadFileBuffer(pciDir->chars, buffer) && (size = ffStrbufToUInt(buffer, 0)))
{
gpu->type = size > 1024UL * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED;
if (gpu->type == FF_GPU_TYPE_DISCRETE)
gpu->dedicated.total = size;
else
gpu->shared.total = size;
ffStrbufSubstrBefore(pciDir, pciDir->length - (uint32_t) strlen("/mem_info_vis_vram_total"));
ffStrbufAppendS(pciDir, "/mem_info_vram_used");
if (ffReadFileBuffer(pciDir->chars, buffer) && (size = ffStrbufToUInt(buffer, 0)))
{
if (gpu->type == FF_GPU_TYPE_DISCRETE)
gpu->dedicated.used = size;
else
gpu->shared.used = size;
}
}
}
static bool loadPciIds(FFstrbuf* pciids)
{
#ifdef FF_CUSTOM_PCI_IDS_PATH
@@ -154,6 +180,9 @@ static const char* pciDetectGPUs(const FFGPUOptions* options, FFlist* gpus)
ffGPUParsePciIds(&pciids, subclassId, (uint16_t) vendorId, (uint16_t) deviceId, gpu);
}
pciDetectVmem(gpu, &pciDir, &buffer);
ffStrbufSubstrBefore(&pciDir, pciDevDirLength);
pciDetectDriver(gpu, &pciDir, &buffer);
ffStrbufSubstrBefore(&pciDir, pciDevDirLength);