ascendc-operator-project-init
Original:🇨🇳 Chinese
Translated
5 scripts
Initialize AscendC operator project and create compilable operator skeleton. Trigger scenarios: (1) User requests to create a new operator; (2) Keywords: ascendc operator, new operator, operator directory, operator initialization; (3) Need to quickly implement based on ascend-kernel template. This skill not only creates directories, but also outputs standard files and checklists for "continuous development".
3installs
Sourceascend/agent-skills
Added on
NPX Install
npx skill4agent add ascend/agent-skills ascendc-operator-project-initTags
Translated version includes tags in frontmatterSKILL.md Content (Chinese)
View Translation Comparison →AscendC Operator Project Initialization
Skill Type: Process-oriented (multi-stage workflow with stage checkpoints)
Quickly create an Ascend-Kernel operator project, where all operators are uniformly generated under the directory, ensuring that subsequent design/coding/compilation testing stages can be directly entered.
csrc/opsCore Principles
- Single Directory: All operators are uniformly generated under the directory
csrc/ops - Security First: Automatically check if the directory exists to avoid overwriting existing files
- Naming Convention: Strictly require snake_case naming format
- Project Detection: Prioritize using existing ascend-kernel projects; copy the template if it does not exist
- Verifiable Results: Output directory structure, registration change points, and build/test commands
- Built-in Pitfall Prevention: Explicitly prompt for three CMake updates, left-value requirements for , and environment dependencies
EXEC_KERNEL_CMD
Workflow
dot
digraph project_init {
rankdir=TB;
node [shape=box];
start [label="用户请求创建算子" shape=ellipse];
detect_ascend_kernel [label="检测ascend-kernel项目是否存在" shape=diamond];
detect_ops [label="检测csrc/ops/目录是否存在" shape=diamond];
copy_template [label="复制ascend-kernel项目模板到当前目录"];
create_ops_dir [label="创建csrc/ops目录"];
collect [label="收集算子信息"];
check_path [label="检查目标算子路径是否存在" shape=diamond];
show_exists [label="提示路径已存在,询问是否更换"];
show_result [label="展示目录结构和下一步指引"];
start -> detect_ascend_kernel;
detect_ascend_kernel -> detect_ops [label="存在"];
detect_ascend_kernel -> copy_template [label="不存在"];
copy_template -> collect;
detect_ops -> collect [label="存在ops/"];
detect_ops -> create_ops_dir [label="不存在ops/"];
create_ops_dir -> collect;
collect -> check_path;
check_path -> show_exists [label="存在"];
show_exists -> collect [label="更换名称"];
check_path -> show_result [label="不存在"];
}Anti-Pattern Checklist (NEVER DO THESE)
- ❌ Do not generate operators outside the csrc/ops directory
- ❌ Do not overwrite existing operator directories
- ❌ Do not use naming formats other than snake_case
- ❌ Do not skip directory existence checks
- ❌ Do not only create operator directories without creating and
op_host/op_kernel/ - ❌ Do not forget to update ,
ops.h, andregister.cpp(three places)csrc/CMakeLists.txt - ❌ Do not directly pass right-value temporary variables in
EXEC_KERNEL_CMD - ❌ Do not use ACLNN as the implementation path for new operators
Step 1: Detect and Initialize Ascend-Kernel Project
1.1 Detect Ascend-Kernel Project Location
Detection Strategy:
- Check if the current directory is an ascend-kernel project (contains build.sh, CMakeLists.txt, csrc/)
- Check the ascend-kernel subdirectory under the current directory
- Check ascend-kernel projects in first-level subdirectories
Execution Command:
bash
bash <skill_dir>/scripts/detect_ascend_kernel_project.sh1.2 Process Detection Results
| Detection Result | Processing Method |
|---|---|
| Use the existing project and proceed to Step 2 |
| Create the csrc/ops/ directory in the project and proceed to Step 2 |
| Copy the ascend-kernel template to the current directory and proceed to Step 2 |
| List all projects and let the user select |
1.3 Copy Project Template (if needed)
Execution Command:
bash
cp -r "<skill_dir>/templates/ascend-kernel" ./ascend-kernel
chmod +x ./ascend-kernel/build.shImportant: Must run after copying, otherwise a error will occur during compilation.
chmod +x build.shPermission deniedVerification: Confirm that the ascend-kernel directory contains:
- build.sh (with execution permission)
- CMakeLists.txt
- csrc/ directory
Step 2: Collect Operator Information (Minimum Required)
Mandatory Information to Confirm:
| Information | Format Requirement | Description |
|---|---|---|
| Operator Name | snake_case | e.g., |
Confirmation Message:
=== Ascend-Kernel Operator Information ===
Operator Name: <op_name>
Generation Path: <ascend_kernel_path>/csrc/ops/<op_name>
Confirm creation? [Y/n]Step 3: Check Preconditions
- Confirm being in the root directory of the ascend-kernel project (build.sh exists and has execution permission)
- Confirm that the csrc/ops/ directory exists (create it with if it does not exist)
mkdir -p csrc/ops - Confirm that the target directory does not exist
csrc/ops/<op_name>
Step 4: Create Operator Skeleton
Create Directories:
bash
mkdir -p csrc/ops/<op_name>/op_host csrc/ops/<op_name>/op_kernelCreate the following files under :
csrc/ops/<op_name>/csrc/ops/<op_name>/
├── CMakeLists.txt
├── design.md # Design document placeholder (to be filled by design skill)
├── op_host/
│ └── <op_name>.cpp # Host placeholder (to be replaced by code-gen skill)
└── op_kernel/
└── <op_name>.cpp # Kernel placeholder (to be replaced by code-gen skill)4.1 Minimum File Templates
CMakeLists.txt
cmake
ascendc_add_operator(OP_NAME <op_name>)op_host/<op_name>.cpp
- Includes BSD 3-Clause header
- Includes
torch_kernel_helper.h - Includes
aclrtlaunch_<op_name>.h - Provides placeholder for
namespace ascend_kernel { at::Tensor <op_name>(...) { ... } }
op_kernel/<op_name>.cpp
- Includes BSD 3-Clause header
- Includes
kernel_operator.h - Provides placeholder for
extern "C" __global__ __aicore__ void <op_name>(...)
Step 5: Registration Reminders (Must be Executed but Not Automatically Modified in This Skill)
After initialization, explicitly prompt the user/subsequent skills to update the following three places:
- : Add function declarations
csrc/ops.h - : Add
csrc/register.cppandm.defm.impl - :
csrc/CMakeLists.txt- Add host files to
OP_SRCS - Add kernel files to
ascendc_library(...) - If there is a duplicate ACLNN wrapper in the template, the corresponding must be removed
aclnn/<op>.cpp
- Add host files to
Note: This is the most frequently missed point in practice, so it must be prompted in advance during the initialization phase.
Step 6: Display Project Structure and Next Steps
Prompt User:
Ascend-Kernel project initialization succeeded!
Project Structure:
<ascend_kernel_path>/
├── build.sh # Build script
├── CMakeLists.txt # CMake configuration
├── csrc/
│ ├── ops/ # Operator directory
│ ├── aclnn/ # ACLNN operator wrapper
│ ├── utils/ # Utility classes
│ ├── ops.h # Operator declarations
│ └── register.cpp # Operator registration
├── python/ # Python package
└── tests/ # Test cases
Next Steps:
Call ascendc-operator-design skill to complete the design documentNotes
- Operator names can only contain letters, numbers, and underscores
- The system will automatically check if the directory exists to avoid overwriting
- If there is no ascend-kernel project in the current directory, the system will automatically copy the template
- New operators must use the AscendC path; ACLNN implementation path is prohibited
- parameters must be left-values; e.g., convert
EXEC_KERNEL_CMDto a local float variable before passingdouble - It is recommended to use PyTorch reference implementation as the test baseline; for dtypes not supported by CPU (such as some fp16 pooling), convert to float32 for comparison
Definition of Done (DoD)
After completing this skill, at least the following requirements should be met:
- Located or created the project
ascend-kernel - Created the standard skeleton for
csrc/ops/<op_name>/ - Identified three registration update points (/
ops.h/register.cpp)csrc/CMakeLists.txt - Provided executable build, installation, and test commands
- Prompted key pitfall prevention items (environment, left-value parameters, three CMake updates)