Onboard arch precheck

From hw-native-sys/simpler · View interactive version

Onboard arch precheck is an AI agent skill from the GitHub repository hw-native-sys/simpler. Detect the host's actual Ascend silicon and refuse mismatched onboard hardware tests. On shared hosts, acquire a task-submit device allocation first and run the precheck and hardware test in that same job. Skip for a2a3sim and a5sim.

How to use this skill

Skill file

Onboard Arch Precheck

Gate to prevent running wrong-arch onboard tests on a dev box. CI already

handles this (each onboard runner is labeled with its arch and only gets

matching jobs). Local hardware work bypasses that protection — this skill

restores it.

Why this exists (DO NOT STRIP — non-obvious failure-mode context)

This repo supports two onboard arches:

Ascend910_93* = Atlas A3 silicon; both build via dav-c220 and share

src/a2a3/)

src/a5/)

A given dev box has ONE of them. **Running tests built for the wrong arch

produces error cascades that look like genuine refactor bugs but aren't.**

Typical signatures:

| Error code | Surface | Meaning when arch-mismatched |

| ---------- | ------- | ---------------------------- |

| 507018 (ACL_ERROR_RT_AICPU_EXCEPTION) | aclrtSynchronizeStreamWithTimeout | AICPU kernel built against the wrong silicon contract faults at runtime; host sees a timeout / aicpu exception. |

| 507899 | rtStreamCreate / rtMalloc | Driver rejects an operation because the resource model doesn't match the silicon. |

Critical: BOTH codes can also be GENUINE bugs (real flaky tests,

real refactor regressions, real AICPU OS issues — see issue #822 for a

historical example). This is precisely what makes the misdiagnosis costly.

People chase a phantom regression for hours when the actual cause was

running the wrong --platform. This skill is cheap insurance against that.

When to invoke

Invoke check.sh BEFORE running ANY of these commands:

Skip the check entirely when the platform string is a sim variant:

Sim variants build and run on host CPU only — they cannot mismatch

silicon by definition. Wasting the precheck on them adds latency.

How to use

# Single check; exit non-zero with a clear message on mismatch.
.claude/skills/onboard-arch-precheck/check.sh a2a3

# Embedded in a workflow:
.claude/skills/onboard-arch-precheck/check.sh "$ARCH" || exit 1
pytest ... --platform "$ARCH" ...

# Shared hosts: query and test within the same device allocation.
task-submit --device auto --device-num 1 --env ARCH --run \
  '.claude/skills/onboard-arch-precheck/check.sh "$ARCH" && \
   pytest ... --platform "$ARCH" --device "$TASK_DEVICE"'

check.sh exits:

Detection method

Same authoritative source as tools/cann-examples/query/ — the CANN

platform_config/<SoC>.ini Short_SoC_version field — but read via

shell so the precheck does not depend on the query binary being built

and never has to bind an ACL device (which would risk contending with

in-flight task-submit device locks).

Pipeline:

  1. Query for Chip Name and, when reported, NPU Name (~600 ms, no ACL

init or binding). A5 queries the first device in TASK_DEVICE (default 0

outside an allocation) via npu-smi info -t board -i <device>; its driver

rejects -c. A2/A3 query card 0 (npu-smi info -t board -i 0 -c 0,

then without -c 0 if that fails): npu-smi -i takes the NPU/card ID

while TASK_DEVICE is the task-submit logic ID, and the two differ on

A2/A3 multi-chip hosts, so card 0 — which always exists and suffices for

arch detection — is queried instead. Outside an allocation, the script

retains the task-submit --run "…" privilege retry where host policy

permits it. Shared hosts must use the allocated-job example above.

A call already inside a task allocation (TASKQUEUE_INSIDE is set) never

submits another task: it tries that platform's queries directly and retains failures.

Retries depend on exit status; only a successful query is parsed. If all

attempts fail, report their commands, exit statuses and output, then exit 1.

A successful but unusable board report is retained in detection errors.

  1. When NPU Name is absent or empty, accept Chip Name only as a full SoC

token matching an exact installed CANN INI filename after adding the

Ascend prefix if absent (e.g. 910B2C → Ascend910B2C.ini). The same

Short_SoC_version validation below still applies. Otherwise construct

the CANN SoC name per family:

otherwise try Ascend950_<NPU>

(e.g. Ascend950DT_9581), without adding another DT/PR suffix

  1. Read Short_SoC_version= from

${ASCEND_HOME_PATH}/{aarch64,x86_64}-linux/data/platform_config/<SoC>.ini.

  1. Map Short_SoC_version → repo arch (must stay in sync with

docs/hardware/chip-architecture.md and query.cpp::arch_from_short_soc):

| Short_SoC_version | Repo arch |

| ------------------- | --------- |

| Ascend910B | a2a3 |

| Ascend910_93 | a2a3 |

| Ascend950 | a5 |

The skill never hardcodes "this box is a2a3" — every check

re-derives the answer from npu-smi + the CANN ini files. The result

is cached at ${TMPDIR:-/tmp}/onboard-arch-precheck-<uid>.cache (format

arch|soc|short_soc) with a 1-hour TTL so repeat invocations stay fast

(~5 ms). Mismatch errors include the specific SoC + Short_SoC_version

so you know exactly what silicon was detected (e.g.

Detected silicon: a2a3 (SoC=Ascend910_9392, Short_SoC_version=Ascend910_93)).

What this does NOT cover

one ever exists, the cache will need to be keyed by npu-smi info -i N

per-device. A5 inspects the first granted device (device 0 outside an

allocation); A2/A3 inspect card 0.

construction (src/{arch}/platform/sim/).

one silicon family; the Ascend910 vs Ascend950 discrimination is

unaffected.

installed for the wrong silicon, separate ASCEND_HOME_PATH /

ASCEND_DRIVER_PATH errors will trip during the actual build / run,

not here.

Related

rule that says all hardware work goes through task-submit. The

precheck and test run within the same device allocation on shared hosts.

the authoritative table for Short_SoC_version → repo arch. The

npu-smi Chip Name can contain a family name or a full SoC. Both paths

require an exact installed CANN INI and validate its Short_SoC_version

before admitting the requested architecture.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.