CANN合同摄入参考指南
Contract Intake Reference【免费下载链接】cannbot-skillsCANNBot 是面向 CANN 开发的用于提升开发效率的系列智能体本仓库为其提供可复用的 Skills 模块。项目地址: https://gitcode.com/cann/cannbot-skillsUse this file whenagent/playbooks/clarify-first.mdneeds help extracting the contract from a reference instead of a direct user spec. This page owns the intake rules, device-default rules, and contract anti-patterns.Input formsForm A: structured spec in the user messageIf the user already states formula, shapes, dtypes, device, or topology intent directly in text:go straight back toclarify-first.mdfill the Contract TemplateForm B: pointer to a PyTorch function fileExamples:实现 /path/to/ref.py 里的 fn基于 a5 实现 xxx.py 的函数Intake rule:Read the reference file end-to-end. Do not skim the__main__block.Extract what the file actually fixes: formula, shapes, dtypes, scalar values, and any device hints.Verify PyTorch type promotion when Python scalars are involved. For example,half_tensor * 0.5may promote tofloat32whilehalf_tensor * half_tensorstayshalf.Fill the Contract Template.ASK on fields the file does not fix, especially device, broadcast intent, topology for multi-stage flows, and tail behavior.Form C: pointer to an existing kernel fileExamples:参考 kernels/a5/foo.py 帮我写个 kernel根据 xxx.py 写一个wherexxx.pyalready containskernelInterpretation rule:The default meaning is reproduce the reference in a new file.Never invent a new computation the user did not describe.If the user described an explicit change, apply exactly that change on top of the reference contract.Treat the reference kernels device, topology, and tile shape as evidence of what is legal, not as mandatory copy targets.Form D: verbal description onlyUse the Contract Template directly and ASK on every unresolved field.Device when unspecifiedWhen the user did not name a device and no direct text fixes one:if the referenced kernel lives underagent/example/kernels/a2/, target a2if it lives underagent/example/kernels/a5/, target a5if the reference is a PyTorch file with no NPU hint, ASKDo not silently default to a5.Reference-derived rules that are easy to missExample shapes in__main__are part of the contract evidence.A shape that happens to be aligned does not prove the kernel may ignore tails.If the formula has 2 matmuls, softmax, or online reduction, topology is part of the contract, not a late implementation detail.If the value path intentionally casts before a later cube stage, that cast boundary is semantic and must be confirmed.Anti-patternsfilling the Contract Template silently and moving oninventing a new formula when the user only said 参考 xxx.pyassuming output dtype equals input dtype without checking Python-scalar promotiontreating an aligned example shape as permission to skip tail reasoningsilently defaulting to a5 when the reference file does not fix the device【免费下载链接】cannbot-skillsCANNBot 是面向 CANN 开发的用于提升开发效率的系列智能体本仓库为其提供可复用的 Skills 模块。项目地址: https://gitcode.com/cann/cannbot-skills创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考