Skip to content

Support: persist scene-test kernel compilation cache - #1675

Open
doraemonmj wants to merge 1 commit into
hw-native-sys:mainfrom
doraemonmj:issue-1604-scene-test-cache
Open

Support: persist scene-test kernel compilation cache#1675
doraemonmj wants to merge 1 commit into
hw-native-sys:mainfrom
doraemonmj:issue-1604-scene-test-cache

Conversation

@doraemonmj

@doraemonmj doraemonmj commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • persist content-addressed ChipCallable artifacts under build/cache/kernels, with source/include-closure, compiler identity/flags/schema, and ABI invalidation, plus integrity validation, atomic publication, and per-key locking
  • add a collection-only scene-test compile command that defaults to serial compilation; simpler CI explicitly uses --compile-workers 8 before task-submit without acquiring an NPU
  • restore and save kernel artifacts with actions/cache, while keeping the existing batch-level device acquisition and separate SDMA execution
  • honor active pytest skip conditions and cover cache reuse, invalidation, corruption, concurrency, and configurable warm-up parallelism

Lock-boundary measurement

qwen3_14b_decode::StressBatch16Seq3500 on a2a3, with both device jobs acquiring immediately:

Path Lock-free warm-up task-submit wall Total wall
baseline: full pytest under lock 131.62 s 131.62 s
current: cold cache 80.16 s 54.20 s 134.36 s
current: warm cache 17.23 s 54.20 s 71.43 s

The cold-cache path moves compilation out of the device allocation rather than shortening first-run wall time. Device-lock wall falls by 77.42 s (58.8%); restored caches also reduce total wall time.

Fixture construction and golden computation remain inside the locked pytest invocation and are intentionally outside this PR's scope.

Testing

  • full Python UT: 1076 passed, 19 skipped, 1 xfailed
  • focused cache/warm-up UT after rebase: 15 passed
  • local a2a3sim cold-cache warm-up repeated successfully; a full eight-class run observed eight concurrent compiler child processes
  • real CLI validation covered --compile-workers 8 and rejection of zero workers
  • all commit hooks passed: headers, English-only, YAML, Markdown, Ruff, and Pyright
  • a2a3 onboard qwen3_14b_decode::StressBatch16Seq3500: baseline, cold warm-up, cached device run, and hot warm-up all passed

Refs #1604

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8430f699-f7c4-45b9-9f7d-c50f65fbd132

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR adds persistent, content-sensitive caching for compiled scene-test ChipCallable objects. It integrates cache-aware compilation, adds a pytest collection warm-up tool, and runs warm-up commands with cache restoration in hardware CI.

Changes

Scene-Test Compilation Cache

Layer / File(s) Summary
Cache keys, validation, and locking
simpler_setup/scene_test_cache.py, tests/ut/py/test_scene_test_cache.py
The cache fingerprints ABI data, metadata, source contents, and include dependencies. It validates artifacts, publishes them atomically, and prevents duplicate concurrent compilation.
Compiler input and ChipCallable integration
simpler_setup/kernel_compiler.py, simpler_setup/scene_test.py
Compilation now collects orchestration and in-core inputs and retrieves compiled artifacts through the persistent cache.
Collection tool, CI wiring, and documentation
simpler_setup/tools/scene_test_compile.py, simpler_setup/tools/README.md, .github/workflows/_st-npu.yml, docs/ci.md, docs/testing.md, docs/investigations/..., tests/ut/py/test_scene_test_compile.py
The new tool compiles selected collected classes without device initialization. CI restores the kernel cache and warms selected scene-test batches before pytest. Documentation describes the workflow and lock boundary.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CI as Hardware CI
  participant Pytest as pytest
  participant Warmup as scene_test_compile
  participant Cache as scene_test_cache
  participant Compiler as scene_test.py
  CI->>CI: Restore build/cache/kernels
  CI->>Warmup: Run selected tests with --collect-only
  Warmup->>Pytest: Collect scene-test items
  Pytest-->>Warmup: Return collected classes
  Warmup->>Compiler: Compile selected classes
  Compiler->>Cache: Load or compile ChipCallable
  Cache-->>Compiler: Return cached artifact
  CI->>Pytest: Execute hardware tests
  Pytest->>Cache: Reuse compiled artifacts
Loading

Possibly related issues

Possibly related PRs

Poem

A rabbit warms kernels before the run,
Cache keys bloom beneath the sun.
Headers change, stale blobs flee,
Locks guard one compile efficiently.
pytest hops on, artifacts stay—
Faster trails through tests today.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely identifies the main change: persistent scene-test kernel compilation caching.
Description check ✅ Passed The description directly explains the cache, CI warm-up, lock boundaries, testing, and performance objectives covered by the changeset.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@simpler_setup/scene_test.py`:
- Around line 1032-1055: The artifact metadata built in the compile_artifact_key
call must include a compiler cache token covering the selected compiler version,
relevant compile/link flags, and a schema token for KernelCompiler behavior.
Update the surrounding artifact-key generation to use this token, and add a
regression test proving that changing the schema token invalidates the artifact
key.

In `@simpler_setup/tools/scene_test_compile.py`:
- Around line 24-25: Update the warm-up filtering around item.iter_markers() to
evaluate active pytest skipif conditions, not only markers named "skip", and
skip compilation whenever pytest would skip the collected item. Add a regression
test covering a truthy pytest.mark.skipif condition while preserving compilation
for inactive conditions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bdf8b3c9-b100-41e8-8b49-59279b55f34a

📥 Commits

Reviewing files that changed from the base of the PR and between a032884 and ae6e02a.

📒 Files selected for processing (11)
  • .github/workflows/_st-npu.yml
  • docs/ci.md
  • docs/investigations/2026-07-qwen-scene-test-406s-decomposition.md
  • docs/testing.md
  • simpler_setup/kernel_compiler.py
  • simpler_setup/scene_test.py
  • simpler_setup/scene_test_cache.py
  • simpler_setup/tools/README.md
  • simpler_setup/tools/scene_test_compile.py
  • tests/ut/py/test_scene_test_cache.py
  • tests/ut/py/test_scene_test_compile.py

Comment on lines +1032 to 1055
artifact_key = compile_artifact_key(
{
"cache_key": cache_key,
"platform": platform,
"runtime": runtime,
"host_platform": sys.platform,
"host_machine": host_platform.machine(),
"sanitizers": KernelCompiler._sanitizers,
"orchestration": {
"function_name": orch["function_name"],
"config_name": orch.get("config_name", ""),
"signature": orch.get("signature", []),
},
"incores": [
{
"func_id": k["func_id"],
"core_type": k["core_type"],
"signature": k.get("signature", []),
}
for k in incores
],
},
compilation_units,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Include compiler identity in the artifact key.

The key omits the effective compiler identity and compilation flags. The workflow restore prefix can restore artifacts from an earlier ref. If KernelCompiler behavior, the CANN toolchain, or compiler flags change without a source change, this code can reuse an incompatible compiled binary.

Add a compiler cache token to the metadata. Include the selected compiler version, relevant compile/link flags, and a schema token that changes with compiler behavior. Add a regression test for invalidation after that token changes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@simpler_setup/scene_test.py` around lines 1032 - 1055, The artifact metadata
built in the compile_artifact_key call must include a compiler cache token
covering the selected compiler version, relevant compile/link flags, and a
schema token for KernelCompiler behavior. Update the surrounding artifact-key
generation to use this token, and add a regression test proving that changing
the schema token invalidates the artifact key.

Comment thread simpler_setup/tools/scene_test_compile.py Outdated
@doraemonmj
doraemonmj force-pushed the issue-1604-scene-test-cache branch 2 times, most recently from eacc55c to 98b2456 Compare August 4, 2026 10:32
@doraemonmj
doraemonmj force-pushed the issue-1604-scene-test-cache branch from 98b2456 to 6d10af8 Compare August 4, 2026 13:29
Store content-addressed ChipCallable artifacts with transitive include,
compiler identity, flag, schema, ABI, and integrity invalidation.

Warm selected callables before task-submit without acquiring an NPU.
Compilation is serial by default; simpler CI opts into eight host
workers and preserves artifacts through actions/cache.

Tests cover reuse, invalidation, corruption, concurrency, skip
selection, and configurable warm-up parallelism.

Refs hw-native-sys#1604
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