metal : fix memory query under low-memory conditions (#27701)
* metal: Fix memory query under low-memory conditions * Simply variable name Co-authored-by: Georgi Gerganov <ggerganov@gmail.com> * Write it even shorter Co-authored-by: Niklas Wenzel <dev@nikwen.de> --------- Co-authored-by: Georgi Gerganov <ggerganov@gmail.com> Co-authored-by: Niklas Wenzel <dev@nikwen.de>
This commit is contained in:
co-authored by
Georgi Gerganov
Niklas Wenzel
parent
03dbcc53e1
commit
8c0b9cd04a
@@ -1471,8 +1471,10 @@ void ggml_metal_device_event_synchronize(ggml_metal_device_t dev, ggml_metal_eve
|
|||||||
|
|
||||||
void ggml_metal_device_get_memory(ggml_metal_device_t dev, size_t * free, size_t * total) {
|
void ggml_metal_device_get_memory(ggml_metal_device_t dev, size_t * free, size_t * total) {
|
||||||
if (@available(macOS 10.12, iOS 16.0, *)) {
|
if (@available(macOS 10.12, iOS 16.0, *)) {
|
||||||
*total = dev->mtl_device.recommendedMaxWorkingSetSize;
|
*total = dev->mtl_device.recommendedMaxWorkingSetSize;
|
||||||
*free = *total - dev->mtl_device.currentAllocatedSize;
|
size_t cur = dev->mtl_device.currentAllocatedSize;
|
||||||
|
// it's possible to allocate more than `recommendedMaxWorkingSetSize`
|
||||||
|
*free = *total > cur ? *total - cur : 0;
|
||||||
} else {
|
} else {
|
||||||
*free = 0;
|
*free = 0;
|
||||||
*total = 0;
|
*total = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user