From 5fcf020cfba1366792ba40859419763ab15b12fe Mon Sep 17 00:00:00 2001 From: Lizonghang <870644199@qq.com> Date: Thu, 23 Jan 2025 23:04:40 +0400 Subject: [PATCH] use the recommended working set size as metal mem bound, rather than the total physical mem --- common/common.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/common.cpp b/common/common.cpp index 89901af5..a21bbd71 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -943,7 +943,7 @@ static void assign_device( if ((is_macos && !dev.gpu_support.metal) || is_linux) { mem_budget[m] = dev.memory.available_physical; } else if (is_macos && dev.gpu_support.metal) { - mem_budget[m] = dev.memory.total_physical; + mem_budget[m] = dev.gpu_props.memory_free; } else if (is_android) { mem_budget[m] = dev.memory.available_physical + dev.memory.used_can_swap; } else { @@ -1146,14 +1146,14 @@ static void assign_device( if (in_set(m, M1)) { vec_z[m] = (double)(dev.memory.available_physical * GIGABYTE - b_cio) / (double)(n_layer * b_prime); } else if (in_set(m, M2)) { - vec_z[m] = (double)(dev.memory.total_physical * GIGABYTE - b_cio - c_gpu[m]) / (double)(n_layer * b_prime); + vec_z[m] = (double)(dev.gpu_props.memory_free * GIGABYTE - b_cio - c_gpu[m]) / (double)(n_layer * b_prime); } else if (in_set(m, M3)) { vec_z[m] = (double)(dev.memory.available_physical * GIGABYTE + dev.memory.used_can_swap * GIGABYTE * int(is_android) - b_cio) / (double)(n_layer * b_prime); } else { if (is_macos && !dev.gpu_support.metal) { vec_z[m] = - (double)(dev.memory.available_physical * GIGABYTE - b_cio) / (double)(n_layer * b_prime); } else if (is_macos && dev.gpu_support.metal) { - vec_z[m] = - (double)(dev.memory.total_physical * GIGABYTE - b_cio - c_gpu[m]) / (double)(n_layer * b_prime); + vec_z[m] = - (double)(dev.gpu_props.memory_free * GIGABYTE - b_cio - c_gpu[m]) / (double)(n_layer * b_prime); } else { vec_z[m] = - (double)(dev.memory.available_physical * GIGABYTE + dev.memory.used_can_swap * GIGABYTE * int(is_android) - b_cio) / (double)(n_layer * b_prime); }