]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
metal: use shared buffers on eGPU (#17866)
authorJeremy Demeule <redacted>
Mon, 15 Dec 2025 14:14:49 +0000 (15:14 +0100)
committerGitHub <redacted>
Mon, 15 Dec 2025 14:14:49 +0000 (16:14 +0200)
* metal: use shared buffers on eGPU

With #15906, I noticed on important regression when using metal backend on eGPU.
This commit restore the previous behavior and add an option to force its activation.

* metal: use shared buffers on eGPU

* metal: use shared buffers on eGPU

ggml/src/ggml-metal/ggml-metal-device.m

index 7b7d1c123354784d8d4f482e6950bae2680e27be..f24270bb1c583262c3e1b11b09b212d18f0b15fd 100644 (file)
@@ -769,9 +769,16 @@ ggml_metal_device_t ggml_metal_device_init(void) {
 #endif
 
             dev->props.use_shared_buffers = dev->props.has_unified_memory;
+#if TARGET_OS_OSX
+            // In case of eGPU, shared memory may be preferable.
+            dev->props.use_shared_buffers |= [dev->mtl_device location] == MTLDeviceLocationExternal;
+#endif
             if (getenv("GGML_METAL_SHARED_BUFFERS_DISABLE") != NULL) {
                 dev->props.use_shared_buffers = false;
             }
+            if (getenv("GGML_METAL_SHARED_BUFFERS_ENABLE") != NULL) {
+                dev->props.use_shared_buffers = true;
+            }
 
             dev->props.supports_gpu_family_apple7 = [dev->mtl_device supportsFamily:MTLGPUFamilyApple7];