Skip to content

Commit 0690f51

Browse files
committed
refactor: gpustack update mac gpu memory
1 parent 3dd3150 commit 0690f51

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/detection/gpu/gpu_apple.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,35 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
8282
if (!ffCfDictGetDict(properties, CFSTR("PerformanceStatistics"), &performanceDict))
8383
{
8484
ffCfDictGetDouble(performanceDict, CFSTR("Device Utilization %"), &gpu->coreUtilizationRate);
85+
86+
bool isVram = false;
87+
int64_t freeMemory = 0;
88+
int64_t usedMemory = 0;
89+
int64_t totalMemory = 0;
90+
91+
CFStringRef keys[] = {CFSTR("In use system memory"), CFSTR("In use system memory (driver)"), CFSTR("gartUsedBytes"), CFSTR("vramUsedBytes")};
92+
for (size_t i = 0; i < sizeof(keys) / sizeof(keys[0]); i++) {
93+
94+
if (ffCfDictGetInt64(performanceDict, keys[i], &usedMemory) == NULL) {
95+
if (keys[i] == CFSTR("vramUsedBytes"))
96+
{
97+
isVram = true;
98+
}
99+
break;
100+
}
101+
}
102+
103+
if(ffCfDictGetInt64(performanceDict, CFSTR("gartSizeBytes"), &totalMemory))
104+
{
105+
if (isVram)
106+
{
107+
ffCfDictGetInt64(performanceDict, CFSTR("vramFreeBytes"), &freeMemory);
108+
totalMemory = usedMemory + freeMemory;
109+
}
110+
}
111+
112+
gpu->dedicated.total = (uint64_t)totalMemory;
113+
gpu->dedicated.used = (uint64_t)usedMemory;
85114
}
86115
}
87116

src/detection/gpu/gpu_apple.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@
5858
if (gpu->type == FF_GPU_TYPE_INTEGRATED)
5959
{
6060
gpu->shared.total = device.recommendedMaxWorkingSetSize;
61-
gpu->shared.used = device.currentAllocatedSize;
61+
gpu->shared.used = gpu->dedicated.used;
62+
63+
gpu->dedicated.total = FF_GPU_VMEM_SIZE_UNSET;
64+
gpu->dedicated.used = FF_GPU_VMEM_SIZE_UNSET;
6265
}
6366
else
6467
{

0 commit comments

Comments
 (0)