mirror of
https://github.com/Comfy-Org/comfy-aimdo.git
synced 2026-11-04 23:37:21 +00:00
[PR #93] [MERGED] Implement a Memory Compiler #112
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#112
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/93
Author: @rattus128
Created: 8/24/2026
Status: ✅ Merged
Merged: 8/31/2026
Merged by: @rattus128
Base:
master← Head:prs/memory-compiler📝 Commits (10+)
994bf8aAdd native CUDA malloc graph compilerec46366Expose malloc graph Python API2fb6bf8Test malloc graph allocation and nesting258a4feTest malloc graph replay contractf8c3342Test malloc graph ownership errors25ae8cdAllow VBAR eviction during CUDA capturec56e1b2Evict VBARs for malloc graph pagesfa9ece9Compile small CUDA allocationsbec233bAdd malloc graph iteration API43f21d7Pause malloc graph recording📊 Changes
55 files changed (+3323 additions, -12 deletions)
View changed files
📝
comfy_aimdo/control.py(+26 -0)➕
comfy_aimdo/malloc_graph.py(+80 -0)📝
src/control.h(+4 -0)➕
src/malloc-graph.c(+1239 -0)➕
src/malloc-rogue.c(+189 -0)➕
src/malloc-rogue.h(+19 -0)📝
src/model-vbar.c(+8 -2)📝
src/plat.h(+6 -0)📝
src/pyt-cu-plug-alloc-async.c(+39 -10)➕
src/vmm-ref.c(+127 -0)➕
src/vmm-ref.h(+39 -0)➕
tests/malloc-graph-aliasing-cuda.py(+52 -0)➕
tests/malloc-graph-assert-break-cuda.py(+24 -0)➕
tests/malloc-graph-branch-join-cuda.py(+49 -0)➕
tests/malloc-graph-branch-reuse-cuda.py(+26 -0)➕
tests/malloc-graph-changed-size-cuda.py(+30 -0)➕
tests/malloc-graph-cuda.py(+51 -0)➕
tests/malloc-graph-deep-nesting-cuda.py(+36 -0)➕
tests/malloc-graph-destructor-cuda.py(+26 -0)➕
tests/malloc-graph-different-stream-cuda.py(+24 -0)...and 35 more files
📄 Description
Implement a memory compiler.
The TLDR wins:
This adds a compacting memory compiler for repeated execution of a model. When initialized and recording, it reserves a virtual address range, then allocates from that range and backs them with 8 MiB physical pages as needed. Freeing an allocation logically releases its physical pages for reuse but leaves the virtual allocation fully intact and still pointing to the physical pages. The allocator is then free to map those pages into other subsequent virtual segments of any size for other mismatched allocations, while the original range remains intact. At the end of recording, the virtual range remains fully mapped with its ranges aliasing physical memory. This means no GPU virtual address management is needed on replay. The replay is simply validation of the pattern and recall of the addresses as allocated (subject to graph break rules - see below).
When an allocation trace diverges on later replay, the compiler reports a "graph break", reconstructs state from the scope snapshot, and records the new path as an alternate branch. Later executions matching that path replay normally; strict mode can instead reject breaks for validation for developers who wish to minimize memory layour churn, however graph breaks on execution are functional and performant. Graph breaks do not invalidate the whole graph (like the torch compiler) and only need to recompile the divergent section. The graph then becomes branching and both branches remain compiled concurrently, allowing flip-flop coding patterns etc.
More to come in the ComfyUI PR
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.