Skip to content

vulkan: allow multiple devices to access gpu-visible host memory - #29741

Merged
0cc4m merged 5 commits into
masterfrom
0cc4m/vulkan-multi-device-host-memory
Oct 13, 2026
Merged

0cc4m merged 5 commits into
masterfrom
0cc4m/vulkan-multi-device-host-memory

Conversation

@0cc4m

@0cc4m 0cc4m commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Overview

This has been on my todo list for a while: Overhaul the Vulkan backend host-visible memory management to allow multiple devices to access host memory. On master only the first device can directly read from host memory, which increases load times in multi-gpu systems and may make transfers slower.

This branch changes it to use VK_EXT_external_memory_host to use a regular aligned CPU allocation and access it from all devices. In my tests it reduces non-mmap multi-GPU load times by around 20%. No effect on inference performance.

Single-GPU systems should be unaffected.

Requirements

@0cc4m
0cc4m requested a review from a team as a code owner September 30, 2026 11:59
@github-actions github-actions Bot added Vulkan Issues specific to the Vulkan backend ggml changes relating to the ggml tensor library for machine learning labels Sep 30, 2026
@0cc4m

0cc4m commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

@jeffbolznv Can you review this when you have time?

@jeffbolznv

Copy link
Copy Markdown
Contributor

Overall it looks fine to me. Codex had a few good finds that I didn't notice:

• P1: Allocation failure becomes an invalid buffer. ggml/src/ggml-vulkan/ggml-vulkan.cpp:13078: aligned allocation can return nullptr, but the caller only handles exceptions. It
creates a non-null buffer whose get_base() subsequently asserts. Handle the null return explicitly.

• P2: Explicit device selection disables the feature. ggml/src/ggml-vulkan/ggml-vulkan.cpp:5392: multi_device is assigned only in the default-selection branch. With
GGML_VK_VISIBLE_DEVICES=0,1, it stays false and device 1 continues staging. Move the assignment outside the selection branches.

• P2: Insufficient alignment without host-import support. ggml/src/ggml-vulkan/ggml-vulkan-buffers.cpp:283: when no selected device advertises the extension, alignment falls to
8 bytes. The CPU buffer wrapper requires 32-byte alignment and can assert. The minimum must also satisfy ggml’s alignment requirements.

On the first one, IMO we should throw rather than codex's suggestion of returning null and handling null in the caller. On the third one, maybe we should check for any device advertising the extension before enabling this path.

@0cc4m

0cc4m commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Good points, should be fixed now. I went with the nullptr handling that can catch both the Vulkan error and the alloc nullptr result.

@0cc4m 0cc4m added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Oct 12, 2026

@CISC CISC left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0cc4m

0cc4m commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Seems to be some kind of Nvidia cleanup crash again, not caused by this PR.

@0cc4m
0cc4m merged commit e0bcacc into master Oct 13, 2026
27 of 28 checks passed
@0cc4m
0cc4m deleted the 0cc4m/vulkan-multi-device-host-memory branch October 13, 2026 13:05
@jeffbolznv

Copy link
Copy Markdown
Contributor

If somebody can capture a crash dump or call stack for one of these intermittent crashes, I can share it internally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. Vulkan Issues specific to the Vulkan backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants