Skip to content

Add: integrate kernel-mode PRs with an end-to-end launch test - #2216

Merged
YunjiQin merged 2 commits into
hw-native-sys:feat/kernel-mode-integration-testfrom
sunkaixuan2018:skx/kernel-mode-integration-test
Sep 14, 2026
Merged

Add: integrate kernel-mode PRs with an end-to-end launch test#2216
YunjiQin merged 2 commits into
hw-native-sys:feat/kernel-mode-integration-testfrom
sunkaixuan2018:skx/kernel-mode-integration-test

Conversation

@sunkaixuan2018

@sunkaixuan2018 sunkaixuan2018 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Integrates the in-flight kernel-mode PRs into one line on the current mainline, and proves it with a public-entry, caller-owned launch that computes real results on a2a3 hardware.

Contract decisions

Every decision is recorded with its reasoning in INTEGRATION-LOG.md, entries D0 to D14.

Topic Decision
Host error codes Merged K1 numbering: INVALID_ARGUMENT is BASE - 4; CALLABLE_COUNT_EXCEEDED, CALLABLE_BYTES_EXCEEDED, CALLABLE_NOT_RESIDENT, CALLABLE_STALE, CAPACITY_EXCEEDED are BASE - 5 to BASE - 9
prepare_callable Five parameters, keeping caller_stream
launch Callable id, not a handle; generation is checked against the residency on host and device; an out-of-range id returns INVALID_ARGUMENT
Launch events Fork from the caller's Start, AICore submitted before AICPU; KernelEventKind names the fifth event PrepareTail
AICPU transport In-repo rtsLaunchCpuKernel path; the WithHostArgs native binder stays available for a later switch
Symbol resolution Every runtime exports all four entries; ChipWorker resolves init, prepare and launch only when supported is nonzero
Kernel capacity K3's shared static arena bank for onboard and simulation; the inline arena guard added to the onboard runner on main is not carried

Effect on the original PRs

Testing

Hardware: a2a3, through onboard-arch-precheck and task-submit --device auto.

Suite Result
C++ unit tests, no hardware 166/166 passed
C++ unit tests with SIMPLER_ENABLE_HARDWARE_TESTS=ON, no hardware 168/168 passed
C++ hardware tests, ^requires_hardware(_a2a3)?$ 2/2 passed (test_comm_lifecycle, test_kernel_mode_entry)
Python unit tests, tests/ut -m "not requires_hardware" 2335 passed
Python hardware unit tests, tests/ut -m requires_hardware --platform a2a3 30 passed
a2a3 hardware: kernel C API and capture probe 13/13 passed
Invocation transport probe, tools/cann-examples/tmr-invocation-snapshot 24 gated asynchronous snapshots passed
a2a3 onboard scenes, -m "not sdma" --exclude-level 4 167 passed, 1 skipped
a2a3 SDMA scenes 3 passed
a2a3sim scenes 82 passed, 8 skipped
a5sim scenes 78 passed
clang-tidy 18 on changed C++ files passed, zero diagnostics
Other pre-commit hooks on changed files passed
mkdocs build --strict passed

The 13 hardware cases are the eager numerical launch, seven lifecycle retry scenarios, two device-query rejections, kernel init on a borrowed device for both runtimes, and the K2 capture probe with 100 replays.

The full Python hardware run found tests/ut/py/test_worker/test_kernel_mode_entry.py still asserting that every runtime refuses kernel init, which failed three jobs against TMR. The second commit points its refusal cases at host_build_graph and adds init_claims_borrowed_stream, matching the C++ twin; the 30-passed result is from the fixed file. Details are in docs/kernel-integration-validation.md, sections "Mainline merge revalidation" and "Full sweeps on the merged tree".

ctest --test-dir tests/ut/cpp/build -LE requires_hardware
pytest tests/ut -m "not requires_hardware"
task-submit --device auto --device-num 2 --run "pytest tests/ut -m requires_hardware --platform a2a3 --device \$TASK_DEVICE"
task-submit --device auto --device-num 4 --run "pytest examples tests/st -m 'not sdma' --platform a2a3 --exclude-level 4 --device \$TASK_DEVICE --require-pto-isa --pto-session-timeout 1200"
task-submit --device auto --device-num 2 --run "pytest examples tests/st -m sdma --platform a2a3 --device \$TASK_DEVICE --require-pto-isa --pto-session-timeout 600"
pytest examples tests/st --platform a2a3sim --device 0-15 --require-pto-isa --pto-session-timeout 600
pytest examples tests/st --platform a5sim --device 0-15 --require-pto-isa --pto-session-timeout 600
mkdocs build --strict

Not covered

  • Public host_build_graph kernel execution: H4 has no submitted PR, so HBG reports no kernel capability.
  • A5 hardware: only builds, unit tests and simulation.
  • A public launch inside an ACLGraph capture window: the capture probe replays the three-stream primitives 100 times, and the public launch is verified eagerly, but the two have not run together.
  • Shapes, multi-operator graphs and concurrent launches beyond the single fixed-shape operator above.

Bring the in-flight kernel-mode PRs onto one line on the current
mainline, where a context borrowed from the caller runs a real
operator through the four public kernel entries on a2a3.

- simpler_kernel_mode_launch reaches device execution on onboard
  tensormap_and_ringbuffer: a host owner validates the context and
  callable, encodes the invocation, and submits it through the
  three-stream binder; the AICPU dispatch entry hands the payload to
  the TMR executor. The kernel path commits the pooled arena before
  the runtime image is uploaded. host_build_graph and simulation
  report no kernel capability.
- host_build_graph gains host build separated from upload, resource
  planning with prepare and freeze, immutable graph packets and
  sealed execution slots.
- The kernel resource model borrows the caller's ACL state, device
  and stream, keeps a failed close retryable, admits one live kernel
  context per device and runtime in a loaded host runtime, and holds
  kernel capacity through the shared static arena bank.
- prepare_callable takes the caller stream; launch is id-based and
  checks the callable's generation on host and device; launch events
  fork from the caller's Start to AICore first, then AICPU.
- Host error codes follow the merged K1 numbering. INVALID_ARGUMENT
  is BASE - 4 and the callable and capacity codes take BASE - 5
  through BASE - 9. An out-of-range launch id is an argument error.
- tests/ut/py/test_kernel_mode_c_api.py owns its ACL, device, stream
  and tensors, drives the four entries, and compares all 16384
  elements of two launches against x + scalar with fresh addresses
  and scalars, while committed memory stays constant and returns to
  zero after finalize.
- docs/zh-cn/kernel-mode-integration-test.md explains the test, the
  launch sequence and what graph mode has and has not covered; the
  kernel docs join the mkdocs nav.
- INTEGRATION-LOG.md records each contract decision and why.

Co-authored-by: Leaf-Salix <2503954024@qq.com>
Co-authored-by: YunjiQin <a1339924773@gmail.com>
Co-authored-by: TaoZQY <zhangtaolqy@mail.ustc.edu.cn>
@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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: Advanced

Run ID: e00f8456-077c-4987-a239-21b883fe35a3

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

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.

tests/ut/py/test_worker/test_kernel_mode_entry.py asserted that every
runtime refuses kernel init. On the integrated tree the onboard
tensormap_and_ringbuffer runtime claims the borrowed device, so three
hardware jobs failed: both init_refused jobs and program_init_still_works.

The refusal cases now load host_build_graph, which reports no kernel
capability, so they still prove the call reaches the C ABI and that a
refused init leaves the caller's stream usable. A new
init_claims_borrowed_stream case matches the C++ twin: TMR init succeeds,
reports kernel support, and refuses a second worker on the same device
while the first stays initialized.

The validation record gains the full sweeps run on the merged tree:
Python hardware unit tests, the full Python unit suite, the invocation
transport probe, a2a3 onboard and SDMA scenes, and both simulation sweeps.
@YunjiQin
YunjiQin merged commit 5b2a5a5 into hw-native-sys:feat/kernel-mode-integration-test Sep 14, 2026
3 checks passed
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.

2 participants