[PR #65] rdna2spirv: translate FLAT loads and stores as global accesses #116

Open
opened 2026-11-26 20:16:51 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/65
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/9790


📝 Commits (2)

  • f797e73 rdna2spirv: translate FLAT loads and stores as global accesses
  • fbe718a ab_control_flow: leave flat_atomic out of the A/B sweep too

📊 Changes

4 files changed (+214 additions, -3 deletions)

View changed files

📝 docs/design.md (+1 -0)
➕ tests/semantic/test_flat_mem.py (+168 -0)
📝 tools/ab_control_flow.py (+1 -1)
📝 tools/rdna2spirv.py (+44 -2)

📄 Description

Carried over from old PR 9790 by tiagonogueiraa-bit in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9790, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
tiagonogueiraa-bit: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Resubmission of #8823, unchanged (head fbe718a46). #8823 was closed at 22:39 UTC during the move to ProjectLeonida, with no comment and no triage: line, and the API refuses to reopen it. It had about ten independent passes (CPU and GPU on Linux, Windows and macOS; see #8823's comments). On today's main 2d53a8055 the branch merges without conflicts, and its 12 test_flat_mem tests pass. Originally claimed in #8683: https://github.com/ProjectLeonida/Leonida/issues/8683#issuecomment-7111644742

What

flat_load_* and flat_store_* used to reach the translator's final Unsupported(op). tools/isa_coverage.py listed all 54 FLAT opcodes as unknown, and no open PR translates them. Gen.flat_mem now emits the same code as the GLOBAL access with off, through Gen.global_mem / Gen.global_sub. That covers:

  • every dword width (dword, x2, x3, x4);
  • the 8/16-bit loads and stores;
  • the d16 / d16_hi forms.

Inactive lanes don't access memory, as with global_*.

Why global

  • RDNA2 rule: a FLAT address outside the LDS and private apertures reads and writes global memory, and that is the GLOBAL access with off.
  • Aperture addresses: a program reads the aperture bases as src_shared_base / src_private_base. The translator refuses those operands, so a program that builds an aperture address from them is refused as a whole. A test covers this.
  • Unchecked case: an aperture address loaded from memory or a constant would be treated as global memory. I haven't seen one, and the translator can't detect it. The docs/design.md row says so.

Refused (Unsupported)

  • A non-zero instruction offset. Its behaviour on the console GPU isn't measured. LLVM marks GFX10.1 with FeatureFlatSegmentOffsetBug ("inst_offset is ignored when flat instructions access global memory") and folds no offset into a FLAT access there.
  • flat_atomic_*.
  • A 32-bit address.

Also changed

  • First-read analysis (read_before_write_vgprs): it counts the vdst of a FLAT d16 load as read, the same as for global_load_*_d16.
  • Interp copy analysis: it skips flat_store like the other stores.
  • tools/ab_control_flow.py: it lists flat_store among the memory writes the harness can't set up, next to global_store.
  • Contract row: a new "Flat memory" row in docs/design.md.

Tests

tests/semantic/test_flat_mem.py is new. Each program is translated, run with spirv_mini_interp, checked against words worked out by hand, and checked to leave the same memory as its global_* ..., off spelling. It covers:

  • loads and stores of every width;
  • byte offsets 0 to 11, including a 16-bit access that crosses a dword;
  • d16 loads keeping the other half;
  • a non-zero high address dword;
  • 32 lanes with 8 active through v_cmpx;
  • the refused forms (offset, atomics, 32-bit address) and both aperture operands;
  • the first-read analysis.

What I ran, on macOS 26 with an Apple M4 (CPU only) and Python 3.12.13:

  • python -I scripts/run_semantic_tests.py -j 4 tests/semantic: 448 files, 5,969 tests; 446 files pass. The two that fail, test_image_atomics_guard (47) and test_image_store_d16 (1), fail the same way on main 867d922f.
  • tests/test_isa_coverage.py, tests/test_semantic_translator_use.py, tests/test_ab_control_flow.py, tests/test_design_contract_rows.py, tests/test_docs_repo_paths.py: all pass.
  • tests/test_docs_design_rows.py and tests/test_docs_links.py fail the same way on main (on docs/README.md and docs/dev-tools.md, which this PR doesn't touch).
  • scripts/check_no_game_data.py passes on the changed files.

Not GPU-verified. No game files were used.

AI-assisted (Claude Code, Claude Opus 5.5).

🤖 Generated with Claude Code


🔄 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/65 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/9790` --- ### 📝 Commits (2) - [`f797e73`](https://github.com/ubiquitarianism/leonida/commit/f797e73085bbed99c06e9732f61e68f9e3efe5c4) rdna2spirv: translate FLAT loads and stores as global accesses - [`fbe718a`](https://github.com/ubiquitarianism/leonida/commit/fbe718a46077501038b4a0c3b11c45f57b4dec3b) ab_control_flow: leave flat_atomic out of the A/B sweep too ### 📊 Changes **4 files changed** (+214 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -0) ➕ `tests/semantic/test_flat_mem.py` (+168 -0) 📝 `tools/ab_control_flow.py` (+1 -1) 📝 `tools/rdna2spirv.py` (+44 -2) </details> ### 📄 Description > Carried over from **old PR 9790** by `tiagonogueiraa-bit` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9790`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `tiagonogueiraa-bit`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): **Resubmission of `#8823`**, unchanged (head `fbe718a46`). `#8823` was closed at 22:39 UTC during the move to ProjectLeonida, with no comment and no `triage:` line, and the API refuses to reopen it. It had about ten independent passes (CPU and GPU on Linux, Windows and macOS; see `#8823`'s comments). On today's `main` `2d53a8055` the branch merges without conflicts, and its 12 `test_flat_mem` tests pass. Originally claimed in `#8683`: https://github.com/ProjectLeonida/Leonida/issues/8683#issuecomment-7111644742 ## What `flat_load_*` and `flat_store_*` used to reach the translator's final `Unsupported(op)`. `tools/isa_coverage.py` listed all 54 FLAT opcodes as unknown, and no open PR translates them. `Gen.flat_mem` now emits the same code as the GLOBAL access with `off`, through `Gen.global_mem` / `Gen.global_sub`. That covers: - every dword width (`dword`, `x2`, `x3`, `x4`); - the 8/16-bit loads and stores; - the d16 / d16_hi forms. Inactive lanes don't access memory, as with `global_*`. ## Why global - **RDNA2 rule:** a FLAT address outside the LDS and private apertures reads and writes global memory, and that is the GLOBAL access with `off`. - **Aperture addresses:** a program reads the aperture bases as `src_shared_base` / `src_private_base`. The translator refuses those operands, so a program that builds an aperture address from them is refused as a whole. A test covers this. - **Unchecked case:** an aperture address loaded from memory or a constant would be treated as global memory. I haven't seen one, and the translator can't detect it. The `docs/design.md` row says so. ## Refused (`Unsupported`) - **A non-zero instruction offset.** Its behaviour on the console GPU isn't measured. LLVM marks GFX10.1 with `FeatureFlatSegmentOffsetBug` ("inst_offset is ignored when flat instructions access global memory") and folds no offset into a FLAT access there. - **`flat_atomic_*`.** - **A 32-bit address.** ## Also changed - **First-read analysis** (`read_before_write_vgprs`): it counts the `vdst` of a FLAT d16 load as read, the same as for `global_load_*_d16`. - **Interp copy analysis:** it skips `flat_store` like the other stores. - **`tools/ab_control_flow.py`:** it lists `flat_store` among the memory writes the harness can't set up, next to `global_store`. - **Contract row:** a new "Flat memory" row in `docs/design.md`. ## Tests `tests/semantic/test_flat_mem.py` is new. Each program is translated, run with `spirv_mini_interp`, checked against words worked out by hand, and checked to leave the same memory as its `global_* ..., off` spelling. It covers: - loads and stores of every width; - byte offsets 0 to 11, including a 16-bit access that crosses a dword; - d16 loads keeping the other half; - a non-zero high address dword; - 32 lanes with 8 active through `v_cmpx`; - the refused forms (offset, atomics, 32-bit address) and both aperture operands; - the first-read analysis. What I ran, on macOS 26 with an Apple M4 (CPU only) and Python 3.12.13: - `python -I scripts/run_semantic_tests.py -j 4 tests/semantic`: 448 files, 5,969 tests; 446 files pass. The two that fail, `test_image_atomics_guard` (47) and `test_image_store_d16` (1), fail the same way on `main` `867d922f`. - `tests/test_isa_coverage.py`, `tests/test_semantic_translator_use.py`, `tests/test_ab_control_flow.py`, `tests/test_design_contract_rows.py`, `tests/test_docs_repo_paths.py`: all pass. - `tests/test_docs_design_rows.py` and `tests/test_docs_links.py` fail the same way on `main` (on `docs/README.md` and `docs/dev-tools.md`, which this PR doesn't touch). - `scripts/check_no_game_data.py` passes on the changed files. **Not GPU-verified.** No game files were used. AI-assisted (Claude Code, Claude Opus 5.5). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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#116
No description provided.