ascendc-direct-invoke

Defines the AscendC direct-invoke project contract for building NPU operators with CMake and torch.ops.npu.

6|1|Updated Apr 19, 2026
One-click install
npx skills add https://github.com/xchang1121/op-autoresearch --skill ascendc-direct-invoke-xchang1121
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: ascendc-direct-invoke
Source: https://github.com/xchang1121/op-autoresearch/tree/main/skills/ascendc/fundamentals/ascendc-direct-invoke
Command: npx skills add https://github.com/xchang1121/op-autoresearch --skill ascendc-direct-invoke-xchang1121

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? When generating or migrating AscendC operators for Ascend NPU hardware, agents often produce ad-hoc artifacts like Python-embedded C++ source strings or one-off run.sh scripts that cannot be rebuilt or verified. This Skill defines a standard, repeatable project contract so every dsl=ascendc task delivers a CMake-buildable AscendC project plus a thin Python wrapper that the verification pipeline can load and evaluate. ## Core Features & Use Cases - Standard project layout: Enforces a task directory with kernel.py exposing a single ModelNew class and an ascendc_op/ CMake project containing op_kernel, op_host, and op_extension sources. - Lazy extension loading: Specifies that compiled .so files are loaded via torch.ops.load_library inside ModelNew._load() or forward(), avoiding import-time compilation and device selection. - CMake and registration conventions: Documents NPU_ARCH/ASCEND_HOME_PATH variables, TORCH_LIBRARY_FRAGMENT registration under torch.ops.npu, host-side tiling derivation, and Meta function requirements for correct output shapes. - Use Case: When asked to implement an elementwise or broadcast operator for Atlas A2/A3 hardware, follow the Vector template path: create the tiling header, KernelXxx class with Init/CopyIn/Compute/CopyOut/Process, the PyTorch bridge, and register.cpp so the verifier can build and validate the operator. ## Quick Start Ask the agent to generate an AscendC direct-invoke operator project for your target op following this contract, with kernel.py wrapping torch.ops.npu calls and a CMake-buildable ascendc_op directory.

Frequently Asked Questions about ascendc-direct-invoke

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure an AscendC operator project for NPU verification?▼

Create a task directory with kernel.py exposing a single ModelNew class and an ascendc_op/ CMake project containing op_kernel, op_host, and op_extension sources. ModelNew.forward() calls the compiled extension through torch.ops.npu.<op> after lazy-loading the built .so.

How to register a custom AscendC kernel with torch.ops.npu?▼

Use TORCH_LIBRARY_FRAGMENT to define the op schema under the npu namespace and TORCH_LIBRARY_IMPL with PrivateUse1 to bind the implementation. The host bridge allocates outputs, derives tiling, gets the current NPU stream via c10_npu::getCurrentNPUStream(), and launches the kernel.

Which Ascend hardware does the AscendC direct-invoke contract support?▼

The contract targets Ascend backend hardware including Atlas A2, Atlas A3, and Atlas A5. The build adapter passes NPU_ARCH and ASCEND_HOME_PATH to CMake, so new projects should use ${NPU_ARCH} instead of hardcoded values like dav-2201.

Why does my AscendC operator fail verification with wrong output shape?▼

The Meta function registered for the op must return the exact output shape and dtype. An incorrect Meta causes the verifier to read wrong shapes and misjudge a correct kernel as failed, so check the Meta implementation first.

What patterns are forbidden in AscendC direct-invoke tasks?▼

Do not generate Python-embedded C++/AscendC source strings, run.sh-only one-shot workflows, import-time compilation or device selection, or hardcoded local device ids. Deliverables must be reproducibly buildable CMake projects that the verification pipeline can take over.