Skip to content

[Caching] Fix per-construct split false fallback on ndarray-vs-non-ndarray mixed pointers - #905

Open
hughperkins wants to merge 2 commits into
mainfrom
hp/po-split-whole-element-precise
Open

[Caching] Fix per-construct split false fallback on ndarray-vs-non-ndarray mixed pointers#905
hughperkins wants to merge 2 commits into
mainfrom
hp/po-split-whole-element-precise

Conversation

@hughperkins

Copy link
Copy Markdown
Collaborator

Problem

After #900 merged, qipc's giant graph_do_while _step_kernel stopped using the per-construct split: warm + single-edit time-to-first-step regressed from ~11s back to ~27s (a whole-kernel recompile), defeating the point of the split for the flagship kernel.

Root cause is the whole-element/component recompute-safety guard added in #900's final review round (whole_element_read_may_overlap_component_write). It correctly closes a real alias_analysis blind spot (a whole-element ndarray read a[i] vs a component write a[j][c]=... to the same ndarray, which alias_analysis wrongly treats as disjoint). But its conservative catch-all rejected any mixed ExternalPtr/MatrixPtr pair whose matrix side did not normalize to an external pointer:

if (ea == nullptr || eb == nullptr)
  return true;  // <- wrong: treats field/alloca/global-temp writes as "may overlap"

Hard evidence from an instrumented build on a Blackwell node — the pair flagged for _step_kernel:

read  = extptr (ndarray arg 25, scalar)
write = matrixptr(origin=alloca)   <- a thread-local stack tensor, NOT an ndarray

A MatrixPtr over a local alloca / global temp / field is a different memory space than an ndarray read; alias_analysis already reports the pair different (checked before this guard runs). Overriding that to "may overlap" is a false positive.

Fix

  • as_ndarray_ptr now follows the matrix-ptr chain down to the underlying ndarray ExternalPtrStmt (handles higher-rank elements), returning null only when the base genuinely isn't an ndarray.
  • The guard overrides alias_analysis only when both sides are ndarray-backed; otherwise it defers to alias_analysis's verdict. The genuine whole-element-vs-component ndarray hazard still falls back.

Validation (Blackwell node)

  • New TDD regression test ..._whole_element_vs_non_ndarray_component_ok fails before / passes after; the true-positive ..._whole_element_vs_component_recompute_unsafe still falls back.
  • tests/python/test_per_offload_cache.py: 78 passed, 3 skipped (cpu+cuda).
  • qipc _step_kernel warm + single-edit time-to-first-step: 26.8s -> 11.6s (compile_kernel 21.7s -> 5.2s); cold 32.5s -> 19.8s.
  • qipc test_abd_freefall.py: 4 passed (split output correct).

Made with Cursor

…array mixed ptrs

The whole-element/component recompute-safety guard (added to close a real
alias_analysis blind spot) had a conservative catch-all that rejected ANY mixed
ExternalPtr/MatrixPtr pair whose matrix side did not normalize to an external
pointer. But a MatrixPtr over a local alloca, a global temp, or a field is a
different memory space than an ndarray read, and alias_analysis already reports
such a pair `different` (checked before this guard runs). Overriding that to
"may overlap" disabled the split for any kernel that recomputes a whole-element
ndarray read past a component write to a local/temp/field -- including qipc's
giant graph_do_while `_step_kernel`, which regressed warm+1-edit time-to-first-
step from ~11s back to ~27s (whole-kernel recompile).

Fix: `as_ndarray_ptr` now follows the matrix-ptr chain to the underlying ndarray
external pointer (handling higher-rank elements), and the guard only overrides
alias_analysis when BOTH sides are ndarray-backed; otherwise it defers to
alias_analysis's verdict. The genuine whole-element-vs-component ndarray hazard
(same ndarray, mixed access) still falls back.

Validated on a Blackwell node: new regression test fails before / passes after;
the true-positive test still falls back; full test_per_offload_cache.py suite
78 passed / 3 skipped (cpu+cuda); qipc warm+1-edit 26.8s -> 11.6s; qipc
test_abd_freefall.py 4 passed (split output correct).
@hughperkins

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: d37093f87e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

@hughperkins

hughperkins commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author
  • code reivew ok
  • checked fixes qipc main split
  • ci green
  • check doc
  • check ratio comments/code
  • gen tests
  • gen benchmarks

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant