mirror of
https://github.com/Comfy-Org/comfy-aimdo.git
synced 2026-11-04 23:37:21 +00:00
[PR #31] Multi-GPU support: per-device VRAM management #71
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/comfy-aimdo#71
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Comfy-Org/comfy-aimdo/pull/31
Author: @Kosinkadink
Created: 4/9/2026
Status: 🔄 Open
Base:
master← Head:multigpu-thread-safety📝 Commits (4)
607f103Add mutex synchronization and device-aware eviction for multi-GPU7593759multi-GPU phases 1-5: per-device state, context safety, hybrid budget, device-aware allocator, atomic counters718e01bfix code review issues: thread-safe init, atomic reads, per-device ctx syncac7f22efix Windows build: include <intrin.h> for Interlocked intrinsics📊 Changes
7 files changed (+543 additions, -31 deletions)
View changed files
➕
MULTIGPU_PLAN.md(+139 -0)📝
build-linux-docker(+1 -0)📝
src/control.c(+125 -0)📝
src/model-vbar.c(+122 -19)📝
src/plat.h(+122 -1)📝
src/pyt-cu-plug-alloc-async.c(+31 -8)📝
src/vrambuf.c(+3 -3)📄 Description
Summary
Makes aimdo work properly with multiple GPUs. Previously, aimdo assumed a single GPU —
budget_deficit()used globaltotal_vram_usage(sum of ALL GPUs) against one GPU'svram_capacity, creating a phantom deficit that triggered constant unnecessary eviction. With 2×RTX 4090, this made 2-GPU slower than 1-GPU.Changes
Commit 1: Mutex + device-aware eviction (foundation)
vbars_free_locked_dev()with device_filter parameterdev_vram_usage[],dev_vram_add/sub,current_cuda_device()Commit 2: Phases 1–5 (core multi-GPU logic)
AimdoDeviceStatestruct with per-devicevram_capacity,ctx,deficit_sync, etc. Lazyensure_device_init()called fromvbar_allocateand allocator hooks.vbar_allocateuses per-device capacity.with_device_ctx()/restore_ctx()helpers.poll_budget_deficit_dev()switches to correct device context forcuMemGetInfo. Fixedensure_ctx()to not force device 0 context on multi-GPU.budget_deficit_dev()uses per-device usage + per-devicecuMemGetInfobackstop (not just simple accounting).vbar_faultuses this instead of globalbudget_deficit(), eliminating phantom cross-GPU deficit.aimdo_cuda_malloc/aimdo_cuda_malloc_asyncdetermine current device, usevbars_free_dev+budget_deficit_dev.vrambuf_growalso device-aware.dev_vram_add/subuse__atomic_add_fetch(Linux) /InterlockedExchangeAdd64(Windows).API Compatibility
Fully backward compatible — no changes to exported function signatures. ComfyUI does not need any modifications.
init(device_id)still works; other devices are initialized lazily.Benchmarks (2×RTX 4090, Qwen-Image 38GB, CFG=7, 20 steps)
Key design decisions
cudaFreeAsyncdecrements counters before memory is actually reusable.init()for device 0. Other devices are initialized on first use viaensure_device_init().budget_deficit_dev()falls back to global when device state isn't initialized.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.