[PR #1788] runtime: preserve in-flight GPU label targets when expanding a non-heap region (RT-GPU-LABEL-MEMORY-EXPAND) #1803

Open
opened 2026-11-26 21:19:00 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1788
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/rt-gpu-label-memory-expand


📝 Commits (1)

  • 0267290 runtime: preserve in-flight GPU label targets when expanding a non-heap region

📊 Changes

3 files changed (+207 additions, -2 deletions)

View changed files

📝 runtime/CMakeLists.txt (+5 -0)
📝 runtime/src/gpu_label_memory.h (+8 -2)
➕ runtime/test/gpu_label_memory_test.cpp (+194 -0)

📄 Description

Summary

Fixes leonida::label::Memory::track() in runtime/src/gpu_label_memory.h so growing a tracked non-heap region at the same base and allocation_base updates Region::end in place instead of overwriting regions_[base] and dropping in-flight GPU completion value writes.

Root cause

In Memory::track(base, bytes, allocation_base, heap):

  • Previously, if a non-heap region at base with the same allocation_base already existed and a new track() call covered a larger range (end > r.end), the early-return check end <= r.end failed and line 41 executed regions_[base] = std::make_shared<Region>(...).
  • Replacing regions_[base] destroyed the previous Region shared_ptr (and caused it->second != region in publish()), silently dropping any in-flight label::Target GPU completion writes captured from [base, old_end) before the expansion.

Changes

  • runtime/src/gpu_label_memory.h:
    • When !heap and an existing non-heap region at the same base and allocation_base is expanded (base == r.begin && end > r.end), update r.end = end in place under mutex_.
    • Preserves existing Region identity and generation (so stale pre-decommit targets remain rejected, live post-decommit targets survive further expansion, adjacent pages stay isolated from each other's partial decommits, and heap regions or distinct allocation_base reservations still allocate a fresh Region).
  • runtime/test/gpu_label_memory_test.cpp & runtime/CMakeLists.txt:
    • Add portable gpu_label_memory CTest covering in-place expansion, post-partial-release generation retention, subrange and adjacent-page isolation, heap and new-reservation invalidation, base-0 GPU arena tracking, alignment/overflow bounds, and concurrent expand/capture/publish under TSan.

Verification

  • AI-assisted: yes
  • GPUs tested: none (portable standard-library C++20 header + test, verified locally on macOS Apple Silicon ARM64 with Clang; Windows MSVC build and Windows-only gpu_label_store / xbox_gpu_label tests rely on Windows CI).
  • Commands run:
    • clang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=address,undefined -O1 runtime/test/gpu_label_memory_test.cpp — pass
    • clang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=thread -O1 runtime/test/gpu_label_memory_test.cpp — pass (zero data races)
    • clang++ -std=c++20 -Wall -Wextra -Werror -O2 runtime/test/gpu_label_memory_test.cpp — pass
    • Mutation test compiling gpu_label_memory_test.cpp against unpatched main:runtime/src/gpu_label_memory.h — fails on test_expand_preserves_inflight_targets, confirming regression coverage
    • python3 -I scripts/check_no_game_data.py runtime/src/gpu_label_memory.h runtime/test/gpu_label_memory_test.cpp runtime/CMakeLists.txt — pass
    • python3 -I tests/test_text_write_line_endings.py — 3/3 pass

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1788 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/rt-gpu-label-memory-expand` --- ### 📝 Commits (1) - [`0267290`](https://github.com/ubiquitarianism/leonida/commit/0267290f9c7ec35bece4e0b81a132f7d8310e4e6) runtime: preserve in-flight GPU label targets when expanding a non-heap region ### 📊 Changes **3 files changed** (+207 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+5 -0) 📝 `runtime/src/gpu_label_memory.h` (+8 -2) ➕ `runtime/test/gpu_label_memory_test.cpp` (+194 -0) </details> ### 📄 Description ## Summary Fixes `leonida::label::Memory::track()` in `runtime/src/gpu_label_memory.h` so growing a tracked non-heap region at the same `base` and `allocation_base` updates `Region::end` in place instead of overwriting `regions_[base]` and dropping in-flight GPU completion value writes. - **Coordination item**: `RT-GPU-LABEL-MEMORY-EXPAND` - **Claim**: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162005947 ### Root cause In `Memory::track(base, bytes, allocation_base, heap)`: - Previously, if a non-heap region at `base` with the same `allocation_base` already existed and a new `track()` call covered a larger range (`end > r.end`), the early-return check `end <= r.end` failed and line 41 executed `regions_[base] = std::make_shared<Region>(...)`. - Replacing `regions_[base]` destroyed the previous `Region` `shared_ptr` (and caused `it->second != region` in `publish()`), silently dropping any in-flight `label::Target` GPU completion writes captured from `[base, old_end)` before the expansion. ### Changes - [`runtime/src/gpu_label_memory.h`](runtime/src/gpu_label_memory.h): - When `!heap` and an existing non-heap region at the same `base` and `allocation_base` is expanded (`base == r.begin && end > r.end`), update `r.end = end` in place under `mutex_`. - Preserves existing `Region` identity and `generation` (so stale pre-decommit targets remain rejected, live post-decommit targets survive further expansion, adjacent pages stay isolated from each other's partial decommits, and heap regions or distinct `allocation_base` reservations still allocate a fresh `Region`). - [`runtime/test/gpu_label_memory_test.cpp`](runtime/test/gpu_label_memory_test.cpp) & [`runtime/CMakeLists.txt`](runtime/CMakeLists.txt): - Add portable `gpu_label_memory` CTest covering in-place expansion, post-partial-release generation retention, subrange and adjacent-page isolation, heap and new-reservation invalidation, base-0 GPU arena tracking, alignment/overflow bounds, and concurrent expand/capture/publish under TSan. ## Verification - **AI-assisted**: yes - **GPUs tested**: none (portable standard-library C++20 header + test, verified locally on macOS Apple Silicon ARM64 with Clang; Windows MSVC build and Windows-only `gpu_label_store` / `xbox_gpu_label` tests rely on Windows CI). - Commands run: - `clang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=address,undefined -O1 runtime/test/gpu_label_memory_test.cpp` — pass - `clang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=thread -O1 runtime/test/gpu_label_memory_test.cpp` — pass (zero data races) - `clang++ -std=c++20 -Wall -Wextra -Werror -O2 runtime/test/gpu_label_memory_test.cpp` — pass - Mutation test compiling `gpu_label_memory_test.cpp` against unpatched `main:runtime/src/gpu_label_memory.h` — fails on `test_expand_preserves_inflight_targets`, confirming regression coverage - `python3 -I scripts/check_no_game_data.py runtime/src/gpu_label_memory.h runtime/test/gpu_label_memory_test.cpp runtime/CMakeLists.txt` — pass - `python3 -I tests/test_text_write_line_endings.py` — 3/3 pass --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1803
No description provided.