SuperAPI AI Directory

external-gitcode-ascend-catlass-operator-code-gen

Coding & development

View repository

Updated 10-15 15:15

About this skill

Catlass operator code generation

Core workflow

设计文档解析 → Catlass 实现参考选型 → op_host 生成 → op_kernel 生成 → test_aclnn 生成 → 质量验证

Design document compliance specification (CRITICAL)

The design document is the sole basis for code generation and must be 100% complied with.

Section Required content Verification method
Operator name Contains catlass substring, snake_case directory name matches CamelCase class name Directory, OpDef, test_aclnn naming consistent
I/O and dtype Input/output shape, dtype, format OpDef and test_aclnn tensor consistent
Core components ArchTag, BlockMmad, BlockEpilogue, BlockScheduler, Kernel types op_kernel and custom-epilogue.md consistent
Reference example Specified catlass example path and selection rationale Implementation consistent with selection (not pasted in full)
TilingKey Each branch corresponds to dtype/transpose, etc. Host SetTilingKey and TILING_KEY_IS in one-to-one correspondence
Workspace Fixed formulation See kernel-rules.md

Prerequisites

Check item Description
Design document Contains operator name, I/O, dtype, transpose, reference example, Kernel/Block/Epilogue
Project OPS_PROJECT_ROOT determined, contains build.sh、ops/
Catlass <OPS_PROJECT_ROOT>/catlass/ contains include/、examples/; if missing, clone at the project root

When conditions are unclearAskthe user.


Catlass implementation reference selection

In catlass/examples/ select according to the design documentimplementation reference(read the structure, copy the component combination approach,nottreat the example as a ops/ migration source):

  1. Find the example closest to the operator form
  2. Determine the reusable Kernel/Block/Epilogue;the operator project op_kernel must be Device-called
  3. Align tiling constants, Workspace,TILING_KEY_IS branches with the Host side

End-to-end steps

Step 0: Generate skeleton (mandatory)

In OPS_PROJECT_ROOT:bash build.sh --genop=ops/<op_name>

Step 1: Clean up template, configure compilation options

Delete unused templates; configure compile-options.md according to ascendc_config.json

Step 2: List checklist against the design document

Operator name, I/O, dtype, transpose, reference path, Kernel/Block/Epilogue, Workspace, TilingKey branches

Step 3: Lock the implementation reference

Same as "Catlass implementation reference selection" above

Step 4: Write op_host

Generate 3 categories, 4 files:

Step 5: Write op_kernel

According to kernel-rules.md:GET_TILING_DATA、TILING_KEY_IS, Device call,#define K_MAX_SHAPE_DIM 0, do not #include tiling.h

Step 6: Write test_aclnn

According to example-rules.md cover examples/test_aclnn_<op_name>.cpp

Step 7: Verify

  • Structure self-check:code-structure.md
  • Compile and run:ascendc-operator-compile-debug

Common pitfalls

NEVER: skip --genop; merge tiling/infershape into def; miss IMPL_OP_* registration; in def SetTiling/SetInferShape; no directory name catlass; use within Kernel if instead of TilingKey; op_kernel uses DeviceGemm;op_kernel #include tiling.h; for Gemm only use shape to infer transpose; forgetting to set in ascendc_config.json the Catlass compile options

ALWAYS: opgen first then overwrite; three files registered separately; strictly follow the design document for component selection; in ascendc_config.json configure the Catlass compile options; after changing the operator --pkg install then run the example


references index

file content
compile-options.md compile option configuration
code-structure.md directory tree, file responsibility index
example-rules.md test_aclnn usage
tiling-rules.md tiling.h / tiling.cpp
def-rules.md def.cpp
infershape-rules.md infershape.cpp
kernel-rules.md Catlass dependencies and Device invocation
custom-epilogue.md custom Tile Epilogue

reference materials

document/directory purpose
catlass/examples/advanced/basic_matmul_aclnn engineered op_host / op_kernel / test organization comparison
catlass/examples/03_matmul_add MatmulEpilogue + BlockEpilogue combination reference
ascendc-operator-compile-debug compile, install, run example
catlass-operator-design design document