Skip to content

Commit

Permalink
refactor: gpustack update mac gpu memory
Browse files Browse the repository at this point in the history
  • Loading branch information
aiwantaozi committed Jul 17, 2024
1 parent 3dd3150 commit 0690f51
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/detection/gpu/gpu_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,35 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
if (!ffCfDictGetDict(properties, CFSTR("PerformanceStatistics"), &performanceDict))
{
ffCfDictGetDouble(performanceDict, CFSTR("Device Utilization %"), &gpu->coreUtilizationRate);

bool isVram = false;
int64_t freeMemory = 0;
int64_t usedMemory = 0;
int64_t totalMemory = 0;

CFStringRef keys[] = {CFSTR("In use system memory"), CFSTR("In use system memory (driver)"), CFSTR("gartUsedBytes"), CFSTR("vramUsedBytes")};
for (size_t i = 0; i < sizeof(keys) / sizeof(keys[0]); i++) {

if (ffCfDictGetInt64(performanceDict, keys[i], &usedMemory) == NULL) {
if (keys[i] == CFSTR("vramUsedBytes"))
{
isVram = true;
}
break;
}
}

if(ffCfDictGetInt64(performanceDict, CFSTR("gartSizeBytes"), &totalMemory))
{
if (isVram)
{
ffCfDictGetInt64(performanceDict, CFSTR("vramFreeBytes"), &freeMemory);
totalMemory = usedMemory + freeMemory;
}
}

gpu->dedicated.total = (uint64_t)totalMemory;
gpu->dedicated.used = (uint64_t)usedMemory;
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/detection/gpu/gpu_apple.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@
if (gpu->type == FF_GPU_TYPE_INTEGRATED)
{
gpu->shared.total = device.recommendedMaxWorkingSetSize;
gpu->shared.used = device.currentAllocatedSize;
gpu->shared.used = gpu->dedicated.used;

gpu->dedicated.total = FF_GPU_VMEM_SIZE_UNSET;
gpu->dedicated.used = FF_GPU_VMEM_SIZE_UNSET;
}
else
{
Expand Down

0 comments on commit 0690f51

Please sign in to comment.