Merged
feat(cake): 导入 SIMT 轨 #102
feat(cake): 导入 SIMT 轨 #102
Merged
JunyiAdd on Oct 7
Total: 51 files changed+11045-1
@@ -158,6 +158,27 @@ This file records notable changes to the CANNBot plugin orchestration and delive
158 bundler rewrites the value as before.158 bundler rewrites the value as before.
159- Community plugins are not stamped with a plugin-root licence; each keeps the licence it159- Community plugins are not stamped with a plugin-root licence; each keeps the licence it
160 ships with, and `plugins-community/` carries none.160 ships with, and `plugins-community/` carries none.
161+- cake Skill `simt-codegen` and agent `cake-partial-simt`, the SIMT route for Ascend
162+ 950PR, imported flat from CAKE2 `918b31c6` (PR #538). The skill carries the route's own
163+ measured material: the Ascend 950PR ISA probes, three pass models, and four operator
164+ examples. It is kept whole rather than deduplicated against `ops/ascendc-simt-*`: a
165+ token comparison of its 20 reference files against those 15 puts the overlap at 3–14%,
166+ and its four largest references have no counterpart there, so the two are not
167+ interchangeable. `ops/ascendc-simt-*` stays the general SIMT knowledge; this is the
168+ generation route's own corpus.
169+- Third-party attribution for the SIMT route: one reference header emitted by MindStudio's
170+ operator project generator keeps its Mulan PSL v2 notice and is recorded in
171+ `README.OpenSource` with an `OAT.xml` filteritem exempting it from the CANN-2.0 header
172+ policy. Nine ISA probe records had `verify_cmd` lines naming an absolute path under the
173+ probe author's home directory; the scripts there ship with neither this plugin nor
174+ CAKE2, so those paths now read `${PROBE_WORKSPACE}` and `isa_matrix.md` says the
175+ commands record how a probe was reproduced rather than something to run.
176+- Four operator example files under the SIMT route carried no licence header and now carry
177+ the CANN-2.0 one; the fifth keeps its MindStudio notice. `references/operator_examples/`
178+ gets a `.clang-format` that turns formatting off, as the TileLang templates and the
179+ EasyAsc migration examples already do: these files are what the generator actually
180+ emits and several pages quote them line by line, so reflowing them — 272 lines across
181+ the four — would make the example stop matching the generator.
161- Five cake reference files take the `cann/cannbot-skills` master version, picking up the182- Five cake reference files take the `cann/cannbot-skills` master version, picking up the
162 spelling corrections of `bb72f983` that the import source predates. Four are ordinary183 spelling corrections of `bb72f983` that the import source predates. Four are ordinary
163 English words now spelled `category`, `cannot`, `Double` and `requirement`; the fifth is184 English words now spelled `category`, `cannot`, `Double` and `requirement`; the fifth is
MOAT.xml+3-0
@@ -38,6 +38,7 @@
38 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>38 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>
39 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/cake-docs-search/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>39 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/cake-docs-search/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>
40 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/op-dashboard/assets/chart.umd.min.js" desc="Third-party Chart.js 4.4.7 (MIT), vendored minified build; keeps its upstream notice."/>40 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/op-dashboard/assets/chart.umd.min.js" desc="Third-party Chart.js 4.4.7 (MIT), vendored minified build; keeps its upstream notice."/>
41+ <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/simt-codegen/references/operator_examples/torch_gather_20_20/gather_custom_tiling.h" desc="Part of the MindStudio project, offered under Mulan PSL v2; the file retains the upstream notice, exempt from CANN-2.0 header policy."/>
41 <filteritem type="filepath" name="plugins-community/model-recommend-infer-optimize/framework/.*" desc="Bundled GE_SESSION_DEMO inference sample retains upstream Apache-2.0 licensing (LICENSE/NOTICE shipped under framework/); exempt from repository CANN-2.0 header policy."/>42 <filteritem type="filepath" name="plugins-community/model-recommend-infer-optimize/framework/.*" desc="Bundled GE_SESSION_DEMO inference sample retains upstream Apache-2.0 licensing (LICENSE/NOTICE shipped under framework/); exempt from repository CANN-2.0 header policy."/>
42</filefilter>43</filefilter>
43 <filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">44 <filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
@@ -50,6 +51,7 @@
50 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>51 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>
51 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/cake-docs-search/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>52 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/cake-docs-search/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>
52 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/op-dashboard/assets/chart.umd.min.js" desc="Third-party Chart.js 4.4.7 (MIT), vendored minified build; keeps its upstream notice."/>53 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/op-dashboard/assets/chart.umd.min.js" desc="Third-party Chart.js 4.4.7 (MIT), vendored minified build; keeps its upstream notice."/>
54+ <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/simt-codegen/references/operator_examples/torch_gather_20_20/gather_custom_tiling.h" desc="Part of the MindStudio project; the file retains the upstream Huawei copyright line from MindStudio rather than this repository's own."/>
53 <filteritem type="filepath" name="plugins-community/model-recommend-infer-optimize/framework/.*" desc="Bundled GE_SESSION_DEMO inference sample retains upstream Apache-2.0 licensing (LICENSE/NOTICE shipped under framework/); exempt from repository CANN-2.0 header policy."/>55 <filteritem type="filepath" name="plugins-community/model-recommend-infer-optimize/framework/.*" desc="Bundled GE_SESSION_DEMO inference sample retains upstream Apache-2.0 licensing (LICENSE/NOTICE shipped under framework/); exempt from repository CANN-2.0 header policy."/>
54</filefilter>56</filefilter>
55 <filefilter name="licenseFileNamePolicyFilter" desc="Explicitly licensed components excluded from the repository default license policy">57 <filefilter name="licenseFileNamePolicyFilter" desc="Explicitly licensed components excluded from the repository default license policy">
@@ -109,6 +111,7 @@
109 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/README.OpenSource" desc="Third-party component register in JSON; a header would break the array."/>111 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/README.OpenSource" desc="Third-party component register in JSON; a header would break the array."/>
110 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>112 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>
111 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/cake-docs-search/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>113 <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/cake-docs-search/requirements.txt" desc="pip requirements file; a header would be parsed as a dependency line."/>
114+ <filteritem type="filepath" name="plugins-community/collaborative-agent-kernel-evolution/skills/simt-codegen/references/operator_examples/torch_gather_20_20/gather_custom_tiling.h" desc="Part of the MindStudio project, offered under Mulan PSL v2; the file retains the upstream notice, exempt from CANN-2.0 header policy."/>
112</filefilter>115</filefilter>
113 <filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies">116 <filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies">
114 </filefilter>117 </filefilter>
@@ -11,6 +11,7 @@
11 "agents": [11 "agents": [
12 "./agents/cake.md",12 "./agents/cake.md",
13 "./agents/cake-evo.md",13 "./agents/cake-evo.md",
14- "./agents/cake-partial.md"14+ "./agents/cake-partial.md",
15+ "./agents/cake-partial-simt.md"
15 ]16 ]
16}17}
@@ -34,5 +34,14 @@
34 "Owner": "Chart.js Contributors",34 "Owner": "Chart.js Contributors",
35 "Upstream URL": "https://www.chartjs.org",35 "Upstream URL": "https://www.chartjs.org",
36 "Description": "Vendored minified UMD build used by the op-dashboard skill to render evaluation charts offline. The MIT notice is retained in the file banner."36 "Description": "Vendored minified UMD build used by the op-dashboard skill to render evaluation charts offline. The MIT notice is retained in the file banner."
37+ },
38+ {
39+ "Name": "MindStudio operator tiling header template",
40+ "License": "Mulan PSL v2",
41+ "License File": "skills/simt-codegen/references/operator_examples/torch_gather_20_20/gather_custom_tiling.h",
42+ "Version Number": "vendored",
43+ "Owner": "Huawei Technologies Co., Ltd",
44+ "Upstream URL": "https://www.hiascend.com/developer/mindstudio",
45+ "Description": "skills/simt-codegen/references/operator_examples/torch_gather_20_20/gather_custom_tiling.h is the operator tiling header emitted by MindStudio's operator project generator and kept as a reference example for the SIMT route. It retains the upstream Mulan PSL v2 notice and the license URL."
37 }46 }
38]47]
@@ -0,0 +1,232 @@
1+---
2+name: cake-partial-simt
3+description: AscendC SIMT算子部分生成Agent - SIMT代码生成到评估 (用于进化子任务)
4+model: inherit
5+permissionMode: bypassPermissions
6+tools: Read, Write, Edit, Bash, Glob, Grep, Skill, Agent, Task, TaskCreate, TaskGet, TaskList, TaskOutput, TaskStop, TaskUpdate
7+skills:
8+ - task-progress
9+ - skill-trace
10+ - simt-codegen
11+ - cake-code-review
12+ - ascendc-evaluation
13+ - ascendc-op-debug
14+ - git-version-management
15+ - cake-docs-search
16+---
17+ 
18+您是AscendC SIMT算子代码生成系统的部分流程Agent。您的职责是从SIMT代码生成开始,执行到最终编译评估结束。
19+ 
20+**前置条件**: 在您启动之前,以下文件已经由主Agent(cake-evo)生成并放置在您的输出目录中:
21+- `{op_name}_op_desc.json` - 算子描述
22+- `{op_name}_reference.py` - PyTorch参考实现
23+- `{op_name}_functional.py` - Functional API
24+- `{op_name}_custom.py` - Python 包装器
25+- `{op_name}.cpp` - pybind 绑定
26+- `{op_name}Custom/` - msopgen 项目结构(含 op_host/、op_kernel/、CMakeLists.txt)
27+ 
28+**您不需要生成这些文件,直接从SIMT代码生成开始工作。**
29+ 
30+**重要**: 严格按照这些skill的指引操作。
31+ 
32+## 核心职责
33+ 
34+1. **读取已有文件**
35+ - 读取输出目录中的算子描述JSON
36+ - 读取Functional API文件
37+ - 读取msopgen项目结构
38+ - 读取 `simt_variants.md` 中分配的变体方向
39+ 
40+2. **SIMT代码生成**
41+ - 使用 `simt-codegen` skill 生成 SIMT 内核
42+ - 按照分配的变体覆盖 grid/block 配置和内存策略
43+ - simt-codegen 替换 kernel 并适配 host tiling(参见 `references/msopgen_adaptation.md`)
44+ 
45+3. **输出管理**
46+ - 所有新生成的文件保存到指定的输出目录
47+ - 维护一致的命名规范
48+ 
49+4. **错误处理**
50+ - 对失败的步骤重试最多3次
51+ - 提供清晰的错误消息
52+ 
53+## 工作流程
54+ 
55+```
56+┌─────────────────────────────────────────────────────────────────────┐
57+│ 前置 初始化版本管理(git worktree) │
58+│ + 确认已有文件 + 读取 SIMT 变体分配 │
59+│ → "⚡ SIMT 算子进化变体: {variant_id}" │
60+└──────────────────────────┬──────────────────────────────────────────┘
61+ │
62+┌──────────────────────────▼──────────────────────────────────────────┐
63+│ 阶段 1 SIMT 代码生成(simt-codegen) │
64+│ Pass 0 分析 → Pass 1..N 代码生成 → 编译 │
65+│ - 使用分配的 grid/block 配置覆盖默认值 │
66+│ - 应用分配的内存策略和性能 hint │
67+│ → stage 7 commit │
68+└──────────────────────────┬──────────────────────────────────────────┘
69+ │
70+┌──────────────────────────▼──────────────────────────────────────────┐
71+│ 阶段 2 代码审查(cake-code-review, SIMT checklist) │
72+│ → stage 9 commit │
73+└──────────────────────────┬──────────────────────────────────────────┘
74+ │
75+┌──────────────────────────▼──────────────────────────────────────────┐
76+│ 阶段 3 评估(ascendc-evaluation) │
77+│ 评估模式由 cake-evo 在 prompt 中指定: │
78+│ ├── full: A5 硬件 msprof profiling │
79+│ ├── simulator: msprof op simulator 模拟评估 │
80+│ └── compile-only: 仅编译通过,无性能数据 │
81+│ → stage 10 commit │
82+└──────────────────────────┬──────────────────────────────────────────┘
83+ │
84+┌──────────────────────────▼──────────────────────────────────────────┐
85+│ 阶段 4 返回结果(evaluation_results.json) │
86+└─────────────────────────────────────────────────────────────────────┘
87+```
88+ 
89+### 前置: 初始化版本管理
90+ 
91+按照预加载的 `git-version-management` skill **模块3.3** 的要求,所有 commit 均在本变体的 worktree 目录下执行:先 `cd {output_dir}`,再按 cake-partial-simt 阶段映射表用 `git add <stage-specific-patterns>` 有选择地暂存对应文件,最后 `git commit`。不得使用 `git -C {EVO_DIR}`,禁止使用 `git add -A`(避免误提交 profiling 中间产物或编译产物)。
92+ 
93+### 前置: 初始化 Skill Trace
94+ 
95+按照预加载的 `skill-trace` skill 的 **TRACE-INIT** 规则,在 `{output_dir}/` 下创建 `skill_trace.json`(`mode: "cake-partial-simt"`, `agent_id: "cake-partial-simt"`, `variant_id: "round_{r}/parallel_{p}"`)。
96+ 
97+后续每个 skill 步骤执行前后,必须按 `skill-trace` 的 **TRACE-START** 和 **TRACE-END** 规则记录调用信息。在所有步骤完成后,按 **TRACE-FINALIZE** 写入最终评估结果。
98+ 
99+### 前置: 确认已有文件 + 读取 SIMT 变体分配
100+ 
101+首先确认输出目录中存在预生成的文件:
102+1. 读取 `{op_name}_op_desc.json`
103+2. 读取 `{op_name}_functional.py`
104+3. 确认 `{op_name}Custom/` 目录存在(msopgen scaffold)
105+ 
106+**SIMT 变体读取**:
107+ 
108+从 `shared/simt_variants.md` 读取本 parallel 分配的变体方向:
109+- **Grid/Block 配置**(G-S1~G-S5)
110+- **内存策略**(M-S1~M-S4)
111+- **性能 Hint**(H-S1~H-S4)
112+ 
113+输出检测结果:
114+```
115+⚡ SIMT 算子进化变体: {variant_id}(如 G-S3_M-S2_H-S4)
116+ Grid: {blocks_per_grid} blocks × {threads_per_block} threads
117+ 内存策略: {strategy_name}
118+ 性能 Hint: {hint_list}
119+```
120+ 
121+如果缺少任何文件,立即报告错误并停止。
122+ 
123+### 阶段1: SIMT 代码生成
124+ 
125+执行前后,按 `skill-trace` 的 **TRACE-START** / **TRACE-END** 规则记录调用信息。
126+ 
127+1. **simt-codegen**: 按照预加载的 skill 指引,执行 SIMT 代码生成流程:
128+ - Pass 0:分析 functional.py,确定 SIMT model(A/B/C)和算法模式
129+ - Pass 1..N:生成 `.asc` 内核代码,替换 `{op_name}Custom/op_kernel/` 中的模板
130+ - 适配 `op_host/` 中的 tiling 数据结构(参见 `references/msopgen_adaptation.md`)
131+ 
132+ **变体覆盖**(来自 `simt_variants.md`,传递给 simt-codegen):
133+ - `grid_config`: 覆盖默认 grid/block 配置(simt-codegen SKILL.md line 20 接受此覆盖)
134+ - `memory_strategy`: 指定内存访问策略(direct GM / UB 预搬运 / cache hint / bank padding)
135+ - `perf_hints`: 指定性能优化 hint(ILP / 宽 load / warp dedup / grid-stride)
136+ 
137+ 完成后按照预加载的 `git-version-management` skill **模块2.4 / 模块3.3** 执行 `stage 7` commit。
138+ 
139+### 阶段2: 代码审查
140+ 
141+执行前后,按 `skill-trace` 的 **TRACE-START** / **TRACE-END** 规则记录调用信息。
142+ 
143+2. **cake-code-review**: 按照预加载的 skill 指引,执行 SIMT checklist 审查(code-review skill 自动检测 `.asc` 文件中的 SIMT 模式并切换到 SIMT checklist)。完成后按照预加载的 `git-version-management` skill **模块2.4 / 模块3.3** 执行 `stage 9` commit。
144+ 
145+### 阶段3: 评估
146+ 
147+执行前后,按 `skill-trace` 的 **TRACE-START** / **TRACE-END** 规则记录调用信息。
148+ 
149+3. **ascendc-evaluation**: 按照预加载的 skill 指引,对算子编译部署评估。
150+ 
151+ 评估模式由 cake-evo 在 prompt 中通过 `evaluation_mode` 指定:
152+ 
153+ **full**(A5 硬件可用):
154+ - 标准 msprof 硬件 profiling
155+ - 获取真实 speedup 和详细 pipe utilization
156+ 
157+ **simulator**(无 A5,有模拟器):
158+ - 使用 `msprof op simulator --soc-version=Ascend950PR_950x --aic-metrics=PipeUtilization ${BUILD_DIR}/demo`
159+ - 获取模拟 cycle count 和 pipe utilization
160+ - speedup 由 cake-evo 根据 baseline cycle count 计算
161+ - **必须**生成与 full 模式相同 schema 的 `evaluation_results.json`,区别在于:
162+ - `speedup`: 设为 `null`(由 cake-evo 根据 baseline cycle count 计算)
163+ - `cycle_count`: 从 simulator 输出解析的总 cycle 数
164+ - `evaluation_mode`: `"simulator"`
165+ - `pipe_utilization`: 从 simulator 的 PipeUtilization 输出解析
166+ 
167+ **compile-only**(无 A5 亦无模拟器):
168+ - 仅验证编译通过
169+ - `speedup: null`,单轮终止
170+ 
171+ **重要**: 构建命令必须使用 `source build.sh`(不是 `bash build.sh`),这对 docker+tmux 环境至关重要。
172+ 
173+ 精度通过后按照预加载的 `git-version-management` skill **模块2.4 / 模块3.3** 执行 `stage 10` commit(含 commit hash 绑定到 evaluation_results.json)。
174+ 
175+### 阶段4: 返回结果
176+ 
177+返回 `evaluation_results.json`,包括:
178+- `compilation_success`: 是否编译成功
179+- `precision_passed`: 精度是否通过
180+- `speedup`: 相对PyTorch的加速比(full 模式)/ `null`(simulator 和 compile-only 模式)
181+- `base_time_ms`: PyTorch基准时间
182+- `gen_time_ms`: 生成算子时间
183+- `simt_model`: SIMT model(A/B/C)
184+- `variant_id`: 变体标识(如 G-S3_M-S2_H-S4)
185+- `evaluation_mode`: 评估模式(full/simulator/compile-only)
186+ 
187+**Profiling 字段**(full 或 simulator 模式,从 msprof 输出解析):
188+- `pipe_utilization`: `{simt_vf, scalar, mte2, mte3}` 各 pipe 占比(%)
189+- `icache_miss_rate`: ICache miss 率(%)
190+- `l2_read_hit_rate`: L2 cache 读命中率(%)
191+- `block_imbalance`: 最慢/最快 block 时间比
192+- `cycle_count`: 总 cycle 数(simulator 模式)
193+ 
194+这些字段由 cake-evo 收集到 `simt_profiling_log.json`,用于未来 SIMT-AIC 规则库建设。
195+ 
196+若 precision_passed=True 且 evaluation_mode != "compile-only",生成看板:
197+```bash
198+python3 skills/op-dashboard/scripts/gen_dashboard.py \
199+ --op-dir {output_dir} \
200+ --output {output_dir}/dashboard.html
201+```
202+告知用户:`📊 看板:{output_dir}/dashboard.html(浏览器打开)`
203+ 
204+### 最终: Skill Trace 收尾
205+ 
206+所有步骤完成后,按照 `skill-trace` skill 的 **TRACE-FINALIZE** 规则,将 `evaluation_results.json` 中的结果写入 `skill_trace.json`,生成影响摘要。
207+ 
208+## 重要说明
209+ 
210+- **不要重新生成**算子描述、PyTorch参考、Functional API、pybind 绑定或 msopgen 项目结构
211+- 直接使用Write/Bash/Edit等工具完成工作,不要尝试调用Skill工具
212+- 执行python脚本时请捕获控制台输出并打印
213+- 在进入下一步之前验证输出
214+- 所有生成的文件都保存在用户指定的output目录
215+- 保持每步的精简,不需要总结
216+- 每一步的思考和解释说明都使用中文输出,不得使用韩语、日语或其他非中文语言,除非用户明确要求
217+- 评估算子精度不匹配时,最多尝试两次修复,且仅能修改output目录下文件
218+- 不要编写评估脚本
219+ 
220+## 调试指南
221+ 
222+遇到以下运行期问题时,使用对应的调试技能(已预加载到上下文):
223+- **编译失败**:优先代码修复,再重编译
224+- **运行超时 / 挂死 / 507034 / 精度异常**:`ascendc-op-debug`(症状 → INDEX.md → 分层诊断,工具按需路由)
225+ 
226+### CANNBook 知识库联动
227+ 
228+遇到 Ascend C 编译/运行时错误时(若 `CANNBOOK_ENABLED` 非 false):
229+1. **先查 CANNBook**: `cb search "<错误关键词>" --json`
230+2. 找到 → 直接应用解决方案
231+3. 未找到 → 自行排查,解决后回写 CANNBook(见 cannbook skill 流程 B)
232+4. 同一问题重复出现(≥2次)→ 立即 `cb ask` 记录,`cb upvote` 标记高频
@@ -0,0 +1,541 @@
1+# SIMT Codegen Skill — Architecture Reference
2+ 
3+> Purpose: Give a complete picture of the SIMT feature implementation for future optimization planning.
4+> Last updated: 2026-06-25
5+ 
6+---
7+ 
8+## 1. What This Skill Does
9+ 
10+`simt-codegen` generates compilable AscendC code that runs SIMT (Single Instruction Multiple Thread) execution on Huawei Ascend 950PR/950DT (A5) hardware. It takes a functional PyTorch operator definition and lowers it directly to AscendC `.asc` or `.cpp` files through a multi-pass transformation pipeline.
11+ 
12+**Input**: `{op_name}_functional.py` + `op_desc.json` (+ optional evo grid config)
13+**Output**: Compilable `.asc` file at `output/{op_name}/{op_name}Custom/op_kernel/{op_name}.asc`
14+ 
15+---
16+ 
17+## 2. Position in the CAKE2 Pipeline
18+ 
19+```
20+Stage 0: Environment detection (CANN / Local / Remote)
21+Stage 1: op_desc.json generation
22+Stage 2: Reference PyTorch implementation
23+Stage 3: Functional PyTorch conversion
24+Stage 4: Tiling pre-classification
25+Stage 5: Operator type detection ─────────────────────────────────┐
26+ │ │
27+ ├── Vector? → Stages 6-10 (Vector path) │
28+ ├── CV? → Stages 6-10 (CV path) │
29+ └── SIMT? → Stage 6 (msopgen) ───► simt-codegen ──┘
30+ │
31+ Stage 9: Code review
32+ Stage 10: Evaluation
33+```
34+ 
35+### Routing into SIMT
36+ 
37+Stage 5 inspects `functional.py` for SIMT-candidate patterns (gather, scatter, sort, topk, histogram, etc.) and applies two filter questions:
38+ 
39+- **Q1**: Does the operator have irregular/data-dependent memory access or control flow? (NO → Vector path)
40+- **Q2**: Is the input access pattern contiguous? (YES → Vector path; SIMD+mask is faster for contiguous scans)
41+ 
42+Only operators that pass both filters enter `simt-codegen`. The full Q1–Q6 decision tree lives in [`SKILL.md` §0.1 SIMT Model Selection](SKILL.md) and is the single source for model choice — this document does not restate it.
43+ 
44+---
45+ 
46+## 3. Hardware Target
47+ 
48+| Property | Value |
49+|---|---|
50+| Target SoC | Ascend 950PR / 950DT (A5) |
51+| Compiler arch flag | `--npu-arch=dav-3510` |
52+| AI Vector cores | 56 (AIV) |
53+| Warp size | 32 threads |
54+| Max threads/block | 2048 |
55+| Unified Buffer (UB) | 256 KB total; SIMT gets max 128 KB (DataCache partition) |
56+| CANN version | 9.1.0-beta.1 |
57+ 
58+### SIMT Block Parameters (from `arch.yaml`)
59+ 
60+| Property | Value | Source |
61+|---|---|---|
62+| SIMT cores per AIV | 2 | PEM:1050 |
63+| Max warps | 64 | PEM:1057 |
64+| Threads per warp | 32 | PEM:1058 |
65+| Issue width | 4 (instrs/cycle) | PEM:1059 |
66+| Total SIMT registers | 131,072 | PEM:1053 |
67+| SIMT predicate regs | 32 | PEM:1054 |
68+| Divergence stack depth | 16 | PEM:1132 |
69+| DCache line size | 128 bytes | PEM:1162 |
70+| DCache ways | 4 | PEM:1164 |
71+| UB read latency (SIMT) | 7 cycles | PEM:774 idx7 |
72+| UB write latency (SIMT) | 3 cycles | PEM:776 idx7 |
73+ 
74+**Codegen implications**: The 16-level divergence stack limits nested divergent branches — deeply nested `if/else` chains must be restructured. The 131K register file gives ~64 regs/thread at max occupancy (2048 threads) — heavy register usage reduces occupancy. The 128B DCache line means 32 consecutive `float` accesses coalesce into one line fetch.
75+ 
76+**Authoritative source**: [`references/ascend950pr_isa_probes/arch.yaml`](references/ascend950pr_isa_probes/arch.yaml) — banked hardware parameters with oracle citations (T1-cfg verified).
77+ 
78+### SIMD Vector ISA Dtype Constraints (from `isa_matrix.md`)
79+ 
80+For **Model C** kernels that use `__simd_vf__` (Micro API) or AscendC reductions in the entry function, the underlying SIMD vector ISA dtype support is load-bearing:
81+ 
82+| Op | u8 | s8 | u16 | s16 | f16 | bf16 | u32 | s32 | f32 | Note |
83+|---|---|---|---|---|---|---|---|---|---|---|
84+| vadd/vsub | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | all 9 dtypes |
85+| vmul | ✗ | ✗ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | **no 8-bit** |
86+| vdiv | — | — | ✗ | ✗ | ✓ | — | ✗ | ✗ | ✓ | **float-only** |
87+| vcadd (ReduceSum) | ✗ | ✗ | ✓ | ✓ | ✓ | — | ✓ | ✓ | ✓ | **no s8/u8 on 3510** |
88+| vcmax/vcmin | ✗ | ✗ | ✓ | ✓ | ✓ | — | ✓ | ✓ | ✓ | **no s8/u8 on 3510** |
89+| vmadd (FMA) | — | — | — | — | ✓ | ✓ | — | — | ✓ | f16/bf16/f32 only |
90+ 
91+**Authoritative source**: [`references/ascend950pr_isa_probes/isa_matrix.md`](references/ascend950pr_isa_probes/isa_matrix.md) — full per-op dtype grid with `:line` citations.
92+ 
93+SIMT kernels compiled with `dav-3510` **cannot run on 910B** hardware (ISA mismatch). The `ascend950` SoC identifier in msopgen projects resolves natively via `opc`.
94+ 
95+---
96+ 
97+## 4. Three Programming Models
98+ 
99+### Model A — Pure SIMT (`pure_simt`)
100+ 
@@ -0,0 +1,605 @@
1+---
2+name: simt-codegen
3+description: Unified SIMT code generation — analyse functional PyTorch, select SIMT model (A/B/C), and lower directly to compilable AscendC through multi-pass transformation. Replaces dsl-baseline-generation-simt + dsl-lowering-simt.
jon_jin
jon_jinjon_jin26 days ago

[P1·目录归属建议] 本文件所属技能的知识类内容(ISA/架构参考等 references)建议移至 cannbot-knowledge 仓或 skills 仓 community/ops 目录(domain 按 cake- 前缀命名)——本仓定位为插件编排与安装交付,详见会话区催办评论;请确认调整或说明保留理由。 — jon_jin

likedislike
4+subagent:
5+ enabled: true
6+ agent_type: general
7+ reason: "Multi-pass SIMT transformation with compilation requires autonomous error recovery; subagent keeps orchestrator context clean."
8+---
9+ 
10+ 
11+## Reading Path
12+ 
13+1. Read `{op_name}_functional.py` + `op_desc.json` → understand inputs, compute, access pattern
14+ - Field-by-field contract, accepted values, and a copyable template → `references/input_contract.md`
15+ - Invoking this skill standalone (no upstream stage)? Author both files from that contract first.
16+2. Answer Q1–Q6 (§ Model Selection below) → select Model A, B, or C
17+3. Read `references/pass_details_model_{A|B|C}.md` → follow passes sequentially
18+ - Each file is self-contained — do NOT read other model files
19+ - Compilable skeleton is at the top — copy it, fill in the compute body
20+ - Multi-dtype dispatch is included in the skeleton
21+ - For msopgen projects → also read `references/msopgen_adaptation.md` (tiling data, host function, CMake)
22+ - Fill the whole tiling contract (every kernel-read field) → Step 2b
23+ - If `op_desc.json` declares an **array/ListInt** attribute (`perm`, `axes`, `dims`) → Step 2c (OpDef `.ListInt()`, permuting InferShape, inline-array tiling, `__gm__`-global VF plumbing, `pytorch_npu_helper.hpp` wrapper). Do NOT stub it.
24+4. Write the compute body from operator semantics
25+ - Consult `references/simt_operator_patterns.md` to identify which pattern your operator matches
26+ - If stuck → consult `references/operator_examples/` for a similar access pattern
27+ - If your compute body needs warp ops → read `references/simt_warp_ops.md`
28+ - If it needs cache hints or UB staging → read `references/memory_optimization_guide.md`
29+ - If it needs atomics/CAS/compaction → read `references/simt_advanced_patterns.md`
30+ - If op_desc.json lists multiple dtypes → read `references/simt_multi_dtype_guide.md`
31+5. Before finalizing → check error corrections table (§ Error Corrections below)
32+ - Compile flags, the four include paths, and the compiler-error table → `references/simt_build_and_compile.md`
33+ 
34+### Reference Scope
35+ 
36+When generating code, reference ONLY:
37+- `skills/simt-codegen/references/` (pass details, lowering examples, pattern references)
38+- `skills/cake-docs-search/asc-devkit/examples/` — **optional**, present only if the
39+ devkit has been vendored. It is not part of this repo and is absent by default.
40+ `ls` it before citing it; skip silently if missing.
41+- The current operator's own `output/{op_name}/` directory (for iterative passes)
42+ 
43+Do NOT read other operators' `output/` directories as reference material.
44+If you need a pattern not covered above, state the gap in `codegen_reasoning.md`.
45+ 
46+**Inputs**: `{op_name}_functional.py`, `op_desc.json`, optional grid/block override from `cake-evo`
47+**Output**: Compilable kernel at `output/{op_name}/{op_name}Custom/op_kernel/{op_name}.asc`
48+ 
49+> **Standalone vs msopgen — decide this before writing a line of code.**
50+> A kernel written for an msopgen project uses `GET_TILING_DATA`, which is
51+> **generated by the project's build system and does not exist in the CANN
52+> headers**. A standalone `.asc` carries its own `main()` and reads tiling from
53+> plain arguments instead. Do not mix the two forms.
54+> To type-check a project kernel outside its build, put the `#ifndef GET_TILING_DATA`
55+> fallback in its tiling header — `references/get_tiling_data_pattern.md`.
56+> See also `references/simt_build_and_compile.md`.
57+ 
58+ 
59+## Prerequisites
60+ 
61+SIMT operators require `ascend950` as the compute unit. When Stage 6 (ascend-call-generation) generates the msopgen project, it **must** pass `--soc ascend950` to `gen_project.py` so that CMakePresets.json and op_host are generated with the correct SoC target. Without this, the default `ascend910b` is used and compilation will fail or produce wrong artifacts.
62+ 
63+### Build commands
64+ 
65+Copy-paste recipes live in **`references/simt_build_and_compile.md`** Quick Reference; the reasoning behind
66+each flag is in **`references/simt_build_and_compile.md`**. Read one of them before
67+the first compile — every flag was learned from a failed build. The recipes in brief:
68+ 
69+```bash
70+source /usr/local/Ascend/ascend-toolkit/set_env.sh
71+A="$ASCEND_HOME_PATH/$(uname -m)-linux"
72+ 
73+# Standalone .asc (has its own main(); no GET_TILING_DATA)
74+bisheng --asc-aicore-lang --npu-arch=dav-3510 -std=c++17 -O2 MyOp.asc -o myop \
75+ -I"$A/include" -I"$A/asc/include" -I"$A/asc/impl" -I. \
76+ -L"$A/lib64" -Wl,-rpath,"$A/lib64" -lascendcl -lruntime -lm
77+ 
78+# msopgen project kernel (syntax check only; both flags are required)
79+bisheng --asc-aicore-lang --npu-arch=dav-3510 --cce-aicore-only \
80+ -std=c++17 -O2 -D__NPU_TILING__ \
81+ -c my_op_custom.cpp -o my_op.o \
82+ -I"$A/include" -I"$A/asc/include" -I"$A/asc/impl" -I.
83+ 
84+nm -C my_op.o | grep -c 'simt_' # must be > 0 — see below
85+```
86+ 
87+Six things that are easy to get wrong:
88+- **`--cce-aicore-only` is mandatory on a `-c` compile, and it fails silently.**
89+ Omitting it exits **0** and writes an object with **no device code**: 0 `__simt_vf__`
90+ instantiations, no kernel-type markers — the host half of the translation unit.
91+ Verified on identical sources: 35376 B / VF=0 without the flag, 14368 B / VF=8 with it.
92+ **Check codegen with `nm -C x.o | grep -c 'simt_'`, never with `$?`.** An exit-0 build
93+ with VF=0 is a failed build. Do not pass the flag to a command that links a `main()`
94+ (`cannot specify -o when generating multiple output files`). **The restriction is about the
95+ link phase, not the model** — it combines fine with Model A's `-cce-enable-puresimt` on a
96+ `-c` compile, and is mandatory there too.
97+ <!-- claim: cce-aicore-only-scope · also in: references/simt_build_and_compile.md · find with: grep -rn "claim: cce-aicore-only-scope" skills/simt-codegen · edit all sites together -->
98+- **`asc_atomic_add` *does* have 16-bit overloads — they are just in the dtype headers, not
99+ `device_atomic_functions.h`.** Include `asc_fp16.h` / `asc_bf16.h` and the native overload
100+ resolves; do **not** hand-roll a word-CAS for plain accumulation. The scalar overloads'
@@ -0,0 +1,418 @@
1+# =============================================================================
2+# arch.yaml — book/_meta/arch.yaml (dav-3510 / Ascend950PR-9599)
3+# =============================================================================
4+# Machine-readable single-source of dav-3510 hardware parameters for the 950PR book.
5+# Default tier: 🟢T1-cfg (oracle = the TOML the cycle-accurate sim is configured from).
6+# A few values are 🟢T1-sim (trace-measured): they carry tier: T1-sim + a trace oracle
7+# instead of a config key+line, because the quantity is model-internal (no TOML key).
8+#
9+# ---------------------------------------------------------------------------
10+# STATUS — BANKED (constitution v0.2.3 ratified 2026-06-03; §1 micro-arch scope).
11+# Single-source of dav-3510 hardware params for PB-5/PB-7 + entry §PERF.
12+# Derived by the 2026-06-03 verify panel (probes/hw_verify_20260603/verify_*.md,
13+# the verification records); every banked value re-cites its oracle config key+line.
14+# ---------------------------------------------------------------------------
15+#
16+# INCLUSION DISCIPLINE (enforced top-to-bottom):
17+# - Only verdict=confirmed claims (verify findings A/B/C/D, 2026-06-03) or the
18+# already-verified §1/§2 micro-arch list are banked as fact.
19+# - Every banked value carries its oracle: config key + file:line for T1-cfg,
20+# or a trace JSON path for T1-sim. NO value is banked without an oracle.
21+# - Anything still_UN or refuted is NOT banked; it is enumerated in the TODO
22+# block at the bottom with its closing experiment. NEVER bank a refuted/UN value.
23+# - Where this file DISAGREES with the prior probes/arch_extract/arch_950pr_t1cfg.yaml,
24+# the disagreement is called out inline (search "DISAGREES").
25+#
26+# OUT OF SCOPE FOR THIS FILE (consciously scoped out, not dropped):
27+# - ISA capability/constraint matrix -> book/_meta/isa_matrix.md (its own artifact).
28+# - cannprof analyzer names / observability -> probes/hw_verify_20260603/verify_A_observability.md (+ PB-4 when authored).
29+# These are not hardware parameters and have no home in the closed structure below.
30+#
31+# ORACLE FILES (physical paths; dav_3510/lib is the symlink target of every Ascend950PR_95xx):
32+# PEM = /usr/local/Ascend/cann-9.1.0-beta.1/tools/simulator/dav_3510/lib/1982_cloud_config.toml
33+# MODEL = /usr/local/Ascend/cann-9.1.0-beta.1/tools/simulator/dav_3510/lib/Ascend950pr_9599_model.toml
34+# STARS = /usr/local/Ascend/cann-9.1.0-beta.1/tools/simulator/dav_3510/lib/Ascend950pr_9599_stars_ffts_plus.toml
35+# FFTS = /usr/local/Ascend/cann-9.1.0-beta.1/tools/simulator/dav_3510/lib/Ascend950pr_9599_ffts_plus.toml
36+# TRACE = probes/simd_arith_sweep/golden5/evidence/*.json (Chrome trace, harvested; for T1-sim values)
37+# (citations below: PEM:<line> / MODEL:<line> / STARS:<line> / FFTS:<line>, or trace path.)
38+#
39+# UNITS: PEM latency/depth entries are core-clock CYCLES unless the file's own comment
40+# says otherwise (B = bytes). The DDR/L2 memory latencies have NO oracle-stated time
41+# domain (see TODO close-6b) — banked as raw, domain UNRESOLVED.
42+# =============================================================================
43+ 
44+provenance:
45+ target: dav-3510 (Ascend950PR, model_name Ascend950PR_9599)
46+ soc_version: {model_name: Ascend950PR_9599, cube_cores: 32, vec_cores: 64}
47+ contamination_check: "every Ascend950PR_95xx symlink under tools/simulator/ resolves to dav_3510; no 910/m200/c100 guard relied on"
48+ default_tier: 🟢T1-cfg
49+ verify_basis: "probes/hw_verify_20260603/verify_{A,B,C,D}_*.md (2026-06-03 adversarial verify panel)"
50+ 
51+# =============================================================================
52+# 1. MICRO-ARCH — FU classes + alloc, dual-issue exq0/exq1, dispatch, reg files
53+# Tier 🟢T1-cfg. Oracle keys spot-verified from PEM this session.
54+# =============================================================================
55+micro_arch:
56+ # --- Issue / dispatch (RVEC vector engine front-end) ---
57+ single_issue: false # PEM:275
58+ issue_option: 3 # PEM:276 "3: group in fu, exq0/1 one by one in fu group"
59+ dispatch_size: 2 # PEM:287 instrs/cycle (IFU dispatch)
60+ I1_slot_num: 2 # PEM:366 "1 single issue, 2 exu dual issue"
61+ 
62+ # --- Dual-issue execution queues (exq0 + exq1, each 1-wide => 2/tick) ---
63+ dual_issue:
64+ exq0_iss_width: 1 # PEM:868 "ex_iss_width per que"
65+ exq1_iss_width: 1 # PEM:870
66+ issues_per_tick: 2 # = exq0_iss_width + exq1_iss_width (dual-issue ceiling)
67+ ooo_to_exq_ostd: 2 # PEM:944 "dual_issue"
68+ # CROSS-CHECK (T1-sim, NOT config): f32/f16 dual-issue is structurally observed in
69+ # traces — co-issued same-name events carry DISTINCT slot tags AND distinct pc
70+ # (two real instrs). f32 add: 756 dt=0 cycles / 2023 VADD, peak 2/cy. f16 add 207,
71+ # f16 mul 208. (verify_D_ilp_trace.md claim 2, 🟢T1-sim.) NOTE: the "u8 add is NOT
72+ # dual-issue" claim is REFUTED — u8 dual-issues at 32 chains (176 dt=0 pairs); the
73+ # 1/cy seen at 8 chains is a chain-pressure artifact, not an intrinsic limit. So no
74+ # per-dtype dual-issue restriction is banked.
75+ 
76+ # --- Vector functional-unit (FU) classes + per-class allocation across exq0/exq1 ---
77+ fu_classes: [ADD_CONV, MUL, MOV, LUT, LNEXP, SLIDE, SFU] # 7 classes (PEM:913/919 comments)
78+ fu_alloc_option: [2, 2, 2, 2, 2, 0, 0] # PEM:919 per-class queue: 0=exq0, 1=exq1, 2=exq0+exq1
79+ # => ADD_CONV/MUL/MOV/LUT/LNEXP on both queues; SLIDE/SFU on exq0 only.
80+ fu_instr_limit: [13, 13, 13, 13, 13, 13, 13] # PEM:913 per-class in-flight instr limit (13 each)
81+ # NOTE: the slot->FU-class binding is config-only (this alloc table); it is NOT
82+ # observable in any trace (traces carry generic RVECEX_SLOT00..14 — 15 distinct
83+ # slot tags, the vadd entry trace reaches SLOT14 — zero FU-class tags). See TODO
84+ # close-D5 — banked as config, observability is UN.
85+ 
86+ # --- Scheduler reg-ready binning thresholds (route by VALU latency; NOT a vadd op latency) ---
87+ valu_latency_binning:
88+ shq_spclt_valu_ltcy_thres: 4 # PEM:909 route dst reg to shq rdy tbl if valu_lat <= 4
89+ exq_spclt_valu_ltcy_thres: 7 # PEM:910 route if 4 < valu_lat <= 7
90+ # CAVEAT: these are scheduler binning thresholds, NOT per-FU op latencies.
91+ 
92+ # --- Scheduler queue depths (ISU) ---
93+ queue_depths:
94+ shq_depth: 58 # PEM:853
95+ exq_depth: 13 # PEM:854
96+ ldq_depth: 24 # PEM:855
97+ 
98+ # --- RVEC / SIMD register files (DISTINCT from the SIMT reg file in simt_block) ---
99+ register_files:
100+ vreg_length_bytes: 256 # PEM:828 — UNIT IS BYTES (= 64 f32 / 128 f16 / 256 u8 lanes per RV_VADD; 256 *bits* would be 8 f32 lanes, contradicting the verified 64-lane width, kernel_utils_constants.h:172). The "_bits" name in the prior extract was a stale inference.
101+ phy_vreg_num: 68 # PEM:829 (file comment "# 52" is a stale prior value; live = 68)
102+ phy_preg_num: 32 # PEM:830 "64 available, simd only use 32"
103+ # NB: phy_preg_num=32 here is the RVEC/SIMD predicate file (PEM:830). The SIMT
104+ # pipeline has its OWN predicate count total_phy_p_reg=32 at PEM:1054 (different
105+ # line, different block) — see simt_block. Do not conflate the two.
106+ 
107+# =============================================================================
108+# 2. MEMORY HIERARCHY — UB / L1 / L0A / L0B / L0C, DCACHE / Icache
109+# Tier 🟢T1-cfg unless noted. (verify_B_memory_scheduler.md claims 1a,2,3,4,6a)
110+# =============================================================================
111+memory_hierarchy:
112+ 
113+ UB: # PEM [UB] — vector-engine working store (vadd src/dest)
114+ total_size_bytes: 262144 # PEM:761 "# 256KB" (confirmed, verify_B claim 1a)
115+ # read/write latency are PER-REQUESTER vectors, core-clock CYCLES (UB header), UB_ARB excluded.
116+ # read_latency order: [LSU_R, GSU_R, VEC_SU_R, AIC_SU_R, AIV_SU_R, MTE_R, SFU_R, SIMT_R, BHU_R]
117+ read_latency: [3, 6, 5, 5, 5, 5, 5, 7, 3] # PEM:774 -> VEC_SU_R = 5 (idx 2)
118+ # write_latency order: [LSU_W, GSU_W, VEC_SU_W, AIC_SU_W, AIV_SU_W, MTE_W, SFU_W, SIMT_W, BHU_W]
119+ write_latency: [2, 2, 2, 2, 2, 2, 2, 3, 6] # PEM:776 -> VEC_SU_W = 2 (idx 2)
120+ vec_su_read_latency: 5 # PEM:774 idx2 (the VEC datapath read latency)
121+ vec_su_write_latency: 2 # PEM:776 idx2
122+ # ---------------------------------------------------------------------
123+ # UB GEOMETRY (banks / groups / line size) IS NOT BANKED HERE — see TODO close-B1b.
124+ # DISAGREES WITH probes/arch_extract/arch_950pr_t1cfg.yaml, which lists
125+ # buffer_line_size=32 / buffer_bank_count=16 / bank_group_number=8 (PEM:763/765/767)
126+ # as if operative. verify_B claim 1b REFUTES that: those are the
127+ # ub_area_reduce=FALSE (inactive) layout; the config sets ub_area_reduce=true
128+ # (PEM:785), whose own comment reads "true: 32 bank group, 8-B bank_line;
129+ # false: 16 bank group, 32-B bank_line" (+ subbank_line_size=8 PEM:764). So the
130+ # "32 B line / 16 banks / 8 groups" presentation is contradicted. The operative
131+ # geometry (32 bank-groups / 8-B line) vs whether the literal keys are overridden
132+ # at runtime cannot be settled read-only -> TODO close-B1b.
133+ # ---------------------------------------------------------------------
134+ 
135+ L1: # PEM [L1] (verify_B claim 2)
136+ total_size_bytes: 524288 # PEM:749 "# 512KB"
137+ read_port_num: 1 # PEM:757
138+ write_port_num: 2 # PEM:758
139+ core_access_width_bytes: 256 # PEM:755
140+ dmac_access_width_bytes: 256 # PEM:756
141+ 
142+ L0A: # PEM [L0A] (verify_B claim 3)
143+ total_size_bytes: 65536 # PEM:729 "# 64" KB
144+ 
145+ L0B: # PEM [L0B] (verify_B claim 3)
146+ total_size_bytes: 65536 # PEM:734 "# 64 KB"
147+ 
148+ L0C: # PEM [L0C] (verify_B claim 3)
149+ total_size_bytes: 262144 # PEM:738 "# 256KB"
150+ bank_count: 32 # PEM:740
151+ 
152+ DCACHE: # PEM [DCACHE] scalar data cache (verify_B claim 4)
153+ aic_dc_size_kb: 32 # PEM:417 "dc_size = line*way*set" -> 64*4*128 = 32768 = 32KB
154+ aiv_dc_size_kb: 32 # PEM:418
155+ aic_dc_way_size: 4 # PEM:421 (4-way)
156+ aiv_dc_way_size: 4 # PEM:422
157+ 
158+ Icache: # PEM [IFU] (verify_B claim 4)
159+ aic_ic_size_bytes: 32768 # PEM:293 AIC icache 32KB
160+ aiv_ic_size_bytes: 16384 # PEM:294 AIV icache 16KB
161+ 
162+ # --- DDR / L2 timing block. Raw values confirmed (verify_B claim 6a); TIME DOMAIN UNRESOLVED. ---
163+ # DISAGREES WITH probes/arch_extract: that file labels these "(soc-domain; not core cycles)".
164+ # verify_B claim 6b: that label is an unverified INFERENCE — the physical [DDR]/[L2] lines
165+ # carry NO unit/domain comment (grep: 0 domain annotations on any latency key). Numbers are
166+ # real; the domain qualifier is NOT banked. See TODO close-B6b.
167+ DDR_timing: # PEM [DDR]
168+ min_read_latency: 330 # PEM:183 (raw; time domain UNRESOLVED — see TODO close-B6b)
169+ min_write_latency: 330 # PEM:185 (raw; time domain UNRESOLVED)
170+ L2_timing: # PEM [L2] (on-die L2 timing/window block — see SIM-ONLY for sizes)
171+ min_read_latency: 216 # PEM:198 (raw; time domain UNRESOLVED)
172+ min_write_latency: 238 # PEM:200 (raw; time domain UNRESOLVED)
173+ 
174+# =============================================================================
175+# 3. MTE BANDWIDTHS — memory transfer engine (DMA-class) paths + fixpipe latencies
176+# Tier 🟢T1-cfg. (verify_B_memory_scheduler.md claim 5 — all 11 sub-values exact)
177+# =============================================================================
178+mte_bandwidths:
179+ ub_to_l1_intf_bandwidth_bpc: 256 # PEM:488 bytes/cycle (merged intf width; ub_to_l1_merge=1 PEM:487 merges 2x128B)
180+ l1_to_ub_bandwidth_bpc: 128 # PEM:491 bytes/cycle (l1_to_ub_merge=0 PEM:489 -> reverse stays 128; the 256/128 asymmetry is the merge knobs, not a discrepancy)
181+ l1_to_l0a_bandwidth_bpc: 256 # PEM:499
182+ l1_to_l0b_bandwidth_bpc: 256 # PEM:500
183+ l1_to_l0c_bandwidth_bpc: 64 # PEM:503
184+ biu_to_l1_bandwidth_bpc: 256 # PEM:521
185+ biu_port_width_bytes: 128 # PEM:222 ([BIU])
186+ biu_burst_bytes: [512, 256, 128] # PEM:475
187+ # fixpipe latencies (cycles):
188+ fixp_head_latency: 3 # PEM:567
189+ fixp_ub_increment_latency: 7 # PEM:568
190+ fixp_out_increment_latency: 4 # PEM:569
191+ 
192+# =============================================================================
193+# 4. CUBE GEOMETRY — matrix / MMAD engine (closes ledger P-05)
194+# Tier 🟢T1-cfg + header-anchored. (task §1/§2 list; lines re-verified this session)
195+# =============================================================================
196+cube_geometry:
197+ cube_spec_npe: 256 # PEM:692 MAC PEs
198+ C0_K_size: 32 # PEM:695 K-fractal depth (16-bit/8-bit); fp32 uses 16 (header-anchored)
199+ m_frac_size: 16 # PEM:696 M fractal
200+ n_frac_size: 16 # PEM:697 N fractal
201+ cube_stage_num: 26 # PEM:706 cube pipeline depth (cycles)
202+ fp32_fp16_mac_ratio: 16 # PEM:694 "only 4, 16 supported" (FP32:FP16 MAC ratio)
203+ fp_partial_columns: 4 # PEM:693 "only 4(full), 2, 1 supported"
204+ 
205+# =============================================================================
206+# 5. SIMT BLOCK — separate SIMT front-end pipeline ([SIMT.*] sections)
207+# Tier 🟢T1-cfg. (verify_B_memory_scheduler.md claim 8 — all exact)
208+# =============================================================================
209+simt_block:
210+ num_cores: 2 # PEM:1050
211+ max_warp_num: 64 # PEM:1057 (64 warps)
212+ thread_num_per_warp: 32 # PEM:1058 (x 32 threads)
213+ issue_num: 4 # PEM:1059 issue width
214+ total_reg_num: 131072 # PEM:1053 (SIMT reg file — DISTINCT from micro_arch.register_files)
215+ total_phy_p_reg: 32 # PEM:1054 SIMT predicate regs (NB: micro_arch.phy_preg_num=32 is a DIFFERENT file at PEM:830)
216+ total_phy_v_reg: 26 # PEM:1055 SIMT vector regs
217+ divergence_stack_entry_num: 16 # PEM:1132 ([SIMT.DVG])
218+ dcache_line_size_bytes: 128 # PEM:1162 ([SIMT.DCACHE])
219+ dcache_way_num: 4 # PEM:1164
220+ separate_front_end: true # corroborated: separate_arch=1 (PEM:72) + dedicated [SIMT.IFU] block PEM:1111
221+ # SIMT EXU reg-access latencies: value CONFIRMED (verify_B claim 8), but the config
222+ # file annotates both with '# TBC' (to-be-confirmed) — banked with that caveat noted.
223+ exu_reg_rd_latency: 10 # PEM:1156 ([SIMT.EXU]; config annotates "# TBC")
224+ exu_reg_wr_latency: 10 # PEM:1157 ([SIMT.EXU]; config annotates "# TBC")
225+ 
226+# =============================================================================
227+# 6. SCHEDULER — STARS / FFTS+ (David mode)
228+# Tier 🟢T1-cfg. (verify_B_memory_scheduler.md claim 7)
229+# =============================================================================
230+scheduler:
231+ active_mode: David # STARS:18 ffts_mode=3 "0:FFTS 1:FFTS+ 3:David" -> active mode is David(3)
232+ STARS:
233+ num_rtsq: 1024 # STARS:6 (SIM-ONLY — see quarantine; a simulator-config value, never a silicon fact)
234+ num_notify: 1024 # STARS:9
235+ core_kickstart_latency: 200 # STARS:20 unit = "hwts cycles" (per file comment)
236+ cross_core_latency_recv: [0] # STARS:21 cross-core set-flag latency = 0
237+ cross_core_latency_send: [0] # STARS:22
238+ FFTS_plus: # FFTS+ notify-FIFO infrastructure (configured/present)
239+ notify_fifo1_depth: 16 # FFTS:15 "notify table to FFTS+ FIFO"
240+ notify_fifo2_depth: 64 # FFTS:16
241+ 
242+# =============================================================================
243+# 7. TRACE-MEASURED VALUES (🟢T1-sim) — model-internal, NO TOML key
244+# These are NOT config-keyed. Oracle = harvested Chrome trace JSON. Tier T1-sim.
245+# The execute latency is model-internal (keyed by valu_option=9, PEM:1074); it does
246+# NOT exist as a TOML value, so NO PEM line is fabricated for it.
247+# =============================================================================
248+trace_measured:
249+ per_op_execute_dur: # confirmed (verify_D claim 1; verify_A trace-facts)
250+ tier: 🟢T1-sim
251+ oracle: "probes/simd_arith_sweep/golden5/evidence/*.json (Chrome trace X-event 'dur' field)"
252+ field_semantics: "'dur' is a genuine per-op trace field that varies by op (a fixed glyph would be constant)"
253+ add_sub: 7 # RV_VADD dur=0.007 (x1604 uniform); RV_VSUB=0.007 (sub from int-div trace only — weaker provenance)
254+ mul: 8 # RV_VMUL dur=0.008 (x839)
255+ div_f32: 17 # RV_VDIV dur=0.017 (x643)
256+ div_f16: 22 # RV_VDIV dur=0.022 (x640)
257+ units_caveat: >
258+ Values shown as integers per the project convention, but the raw trace 'dur' is
259+ µs-scale (0.007 etc.). The "= cycles" reading rests on a 1 ns = 1 cycle pin the
260+ sibling isa_cost doc marks NOT discriminable from the trace alone. dur is a
261+ confirmed FIELD; "dur ~= execute cycles" is still_UN (see TODO close-A/D-durcy).
262+ # NOT BANKED (still_UN): latency = dur-3, and lanes/cy (cannsim 256 / hw 128).
263+ # See TODO close-D4 and close-D6. Both fail the inclusion discipline -> TODO only.
264+ 
265+# =============================================================================
266+# SIM-ONLY QUARANTINE BLOCK — these are SIMULATOR-CONFIG values, NEVER silicon claims.
267+# Constitution §8. A consumer of this file MUST NOT present any
268+# value below as a hardware/silicon parameter. (verify_B_memory_scheduler.md claim 9)
269+# =============================================================================
270+SIM_ONLY:
271+ _warning: "NEVER cite any value in this block as a silicon/hardware fact. Simulator config only."
272+ l2_size_model_bytes: 754974720 # MODEL:2 = 720 MB (NOT silicon; simulator-config only)
273+ l2_size_window_bytes: 67108864 # PEM:194 = 64 MB ([L2] timing-block size; distinct from MODEL 720MB)
274+ l2_as_cache_disabled: true # PEM:1229 [L2CACHE] cache_enable=0 (also PEM:204 [L2] l2c_op=0 "no l2c")
275+ ddr_size_bytes: 1073741824 # MODEL:3 = 1 GB (NOT silicon HBM capacity)
276+ num_die: 1 # MODEL:5 (sim flattens package to single die)
277+ num_aicpu: 1 # MODEL:9 (NOT the silicon AI-CPU count)
278+ num_rtsq: 1024 # STARS:6 (NOT the silicon stream count)
279+ note: >
280+ None of the L2 figures here (720 MB top-level / 64 MB window) is a silicon
281+ fact; all are simulator-config artifacts. l2_as_cache_disabled means
282+ the [L2CACHE] model block is inert in 9599 runs.
283+ 
284+# =============================================================================
285+# TODO — still_UN items NOT banked as fact, each with its CLOSING EXPERIMENT.
286+# A value moves from here into the fact blocks ONLY when its experiment confirms it.
287+# =============================================================================
288+TODO:
289+ 
290+ - id: close-B1b
291+ item: "Operative UB geometry: bank count / bank-group count / bank-line size."
292+ status: RAN_2026-06-08 + P-19-CLOSED_2026-06-09 — not trace-resolvable AND the UB bank-conflict COUNT is absent from the msprof-sim export too (visualize_data.bin "UB Read/Write Conflict" field = -1 in all 3 sim metric modes, SIMD+SIMT; probes/simt_profiling/P19_aggregate.md). Residual = MindStudio-Insight or data-dominant-N only
293+ why: >
294+ The literal keys buffer_bank_count=16 (PEM:765), bank_group_number=8 (PEM:767),
295+ buffer_line_size=32 (PEM:763) describe the ub_area_reduce=FALSE layout, but the
296+ config sets ub_area_reduce=true (PEM:785), whose comment gives the active layout
297+ as 32 bank-groups / 8-B line (+ subbank_line_size=8 PEM:764). "32 B line" is
298+ directly contradicted. Whether area_reduce=true overrides the literal keys at
299+ runtime is not decidable from the TOML alone.
300+ ran_2026-06-08: >
301+ Probe probes/hw_runprobe_B/ (RESULTS.md). FOUND a working non-destructive config
302+ override: env CORE_SIM_CFG=<copy> applies file VALUES (proven: single_issue=true
303+ collapses dual-issue). So ub_area_reduce / bank_group_number ARE A/B-toggleable.
304+ BUT the bank-conflict observable is not on the trace/cycle surface: the positive
305+ control (bank_group_number=1 -> 2 banks) produced ZERO change in trace dur / span /
306+ cycle on the vadd (cycle stayed 419). The bank-conflict COUNT surfaces only in the
307+ analyzer chart data (memory_sim_view SVG / shared_bank_conflicts HTML = open probe
308+ P-19), which is degenerate at overhead-bound N. Not claiming "no observable exists"
309+ (only a sequential-access kernel was tried, whose null is expected).
310+ closing_experiment: >
311+ NOT independently trace-resolvable -> now COUPLED to P-19 (decode analyzer chart
312+ data) + the data-dominant-N (>=1M) re-sweep. Needs a bank-stressing (scatter/strided)
313+ kernel at data-dominant N whose conflict count is read from the P-19 chart data
314+ (a 2 MB DMA run did not finish in 205 s here -> data-dominant sweep is wall-clock
315+ expensive). The CORE_SIM_CFG knob makes that future A/B constructible.
316+ 
317+ - id: close-B6b
318+ item: "Time domain of DDR/L2 memory latencies (330 / 216 / 238)."
319+ status: RAN_2026-06-08 — not trace-resolvable; reclassified P-19 + data-dominant-N coupled
320+ why: >
321+ The raw values are confirmed (verify_B claim 6a), but the [DDR]/[L2] lines carry
322+ NO unit/domain comment (grep: zero domain annotations on any latency key). The
323+ "soc-domain, not core cycles" label in the prior arch_extract is an inference,
324+ not oracle-shown. soc_period=105 vs core_period=200 (MODEL:12,14) make a soc-vs-core
325+ distinction plausible but not confirmed.
326+ ran_2026-06-08: >
327+ Probe probes/hw_runprobe_B/ (RESULTS.md). Scaled DDR.min_read/write_latency 330->30000
328+ (x91) via CORE_SIM_CFG (proven-applied override): ZERO change in the vadd trace
329+ dur / span / cycle (cycle stayed 419). The [DDR]/[L2] libpem keys do not drive the
330+ observable trace/cycle timeline. The active DDR model crosses clock domains
331+ (liblpddrsim/libdramsim: ClockDomain + ClockDomainCrosser; "lpddr5 1900 Mbps" device
332+ sim, USE_BAILU=1) and the model runs distinct periods (CoreWrapper ref_period=0.40 /
333+ self_period=0.61; MODEL soc_period=105 vs core_period=200). The latency time domain
334+ is NOT exposed in the trace/cycle observables. (NOT claiming "bailu governs / [DDR]
335+ vestigial" — a single null is consistent with several causes; unproven positive cause.)
336+ closing_experiment: >
337+ NOT trace-resolvable -> COUPLED to P-19 (the only memory-timing observable is the
338+ memory_sim_view chart data, degenerate at overhead-bound N) + the data-dominant-N
339+ (>=1M) re-sweep (wall-clock expensive: a 2 MB DMA run did not finish in 205 s). Even
340+ then the chart exposes bandwidth (GB/s) / requests, which may not directly label the
341+ latency clock domain. Honest residual: domain unmeasured; keys non-governing on the
342+ observable timeline.
343+ 
344+ - id: close-D4
345+ item: "latency = dur - 3 (i.e. 7->4, 8->5, 17->14, 22->19)."
346+ status: still_UN
347+ why: >
348+ The dur side {7,8,17,22} is confirmed (trace_measured above), but the "-3 ->
349+ golden latency" bridge fails twice: (a) {4,5,14,19} are an EXTERNAL user-supplied
350+ hardware golden, not a trace field; (b) the stated mechanism ("-3 = UB read/write")
351+ is REFUTED by config — UB VEC_SU read 5 + write 2 = 7, not 3, so if UB r/w were the
352+ excluded part the offset would be -7. The dur-3 match is an arithmetic tautology.
353+ closing_experiment: >
354+ A source that DIRECTLY labels the vector execute latency (or the valu_option=9
355+ model-internal latency table), independent of the external golden. NOT resolvable
356+ by re-running the sim (a fresh run re-emits the same dur field, not a labeled latency).
357+ 
358+ - id: close-D5
359+ item: "RVECEX slot -> FU-class binding observable in traces?"
360+ status: still_UN
361+ why: >
362+ The 7 FU classes + fu_alloc_option are confirmed CONFIG (banked in micro_arch),
363+ but traces carry only generic numbered slot tags RVECEX_SLOT00..14 (15 distinct
364+ tags; vadd entry trace reaches SLOT14) — grep for ADD_CONV/MUL/MOV/LUT/LNEXP/
365+ SLIDE/SFU across ALL harvested traces = ZERO hits. The slot->class binding is
366+ config-only, not trace-observable.
367+ closing_experiment: >
368+ NOT resolvable by a sim run (a fresh run emits the same fields with no FU-class
369+ tag — a trace-format limitation). Needs either a trace field that labels the FU
370+ class per slot, or model-internal documentation of the slot->class map.
371+ 
372+ - id: close-D6
373+ item: "Lanes/cycle: cannsim ~256, hardware ~128."
374+ status: still_UN
375+ why: >
376+ No lanes/cy event exists in any trace. cannsim-256 is DERIVED (lanes/op by dtype x
377+ ops/cy from dual-issue), not a raw measurement. hardware-128 is a user-EXTERNAL
378+ golden, unverifiable from the toolchain by construction.
379+ closing_experiment: >
380+ cannsim-256: state it only as a derived synthesis, never "directly measured" — no
381+ trace field carries it. hardware-128: needs an external silicon source; NOT
382+ obtainable from the simulator/toolchain.
383+ 
384+ - id: close-A-durcy
385+ item: "'dur ~= execute cycles' (the cycle interpretation of the trace dur field)."
386+ status: split_2026-06-08 # cycle-COUNT half CONFIRMED (cross-oracle); absolute-CLOCK half still_UN
387+ why: >
388+ dur is a confirmed trace FIELD whose raw value is µs-scale (Chrome stores µs;
389+ displayTimeUnit:ns renders it). The closing_experiment was RUN 2026-06-08 (P-20,
390+ probes/msprof_oracle/): msprof simulation (`msprof op simulator` / msopprof, the SAME
391+ Ascend950PR_9599 camodel as cannsim) emits an explicitly cycle-labeled per-op `cycles`
392+ column. CROSS-ORACLE RESULT (cold re-derivation 2026-06-09, REVALIDATION.md): deterministic ops
393+ EXACT (ADD 4<->4, MADD 5<->5); cold-memory ops are OVERLAPPING, NON-identical ranges —
394+ cannsim LD dur*1000 in [414..614] vs msprof cycles in [377..510]
395+ (evidence/crosscheck_dur_vs_cycles.tsv). Never exact on every op. => dur ENCODES the per-op cycle COUNT (CONFIRMED,
396+ no longer an assumption). BUT the absolute cycle->wall-time CLOCK is still_UN: cannsim's
397+ 'ns' label encodes 1 cy = 1 ns (1.0 GHz); msprof applies ~1.78 GHz (cycles/running_time,
398+ a conversion constant — NOT a config value). No ~1786 MHz clock exists in the camodel
399+ config (only unlabeled *_period keys: core_period=200, soc_period=105). So '1 ns = 1
400+ cycle' is shown NON-CANONICAL (a second CANN tool uses a different rate), but the true
401+ clock is not pinned. R-01 ('never assert dur=integer cycles') was softened to the cycle-COUNT-confirmed
402+ split — RATIFIED in constitution v0.2.5 (2026-06-09; planning/staging_amend_v0.2.5).
403+ closing_experiment: >
404+ DONE for the cycle-count half (msprof-sim `cycles` column, P-20). REMAINING for the
405+ absolute clock: a silicon time source, or config documentation of the trace clock /
406+ the *_period unit (core_period=200 / soc_period=105 candidate). Until then bank
407+ 'dur encodes the cycle count' (cross-oracle confirmed) but NOT a ns->time clock.
408+ 
409+# =============================================================================
410+# RECONCILIATION NOTES vs probes/arch_extract/arch_950pr_t1cfg.yaml
411+# (values present in the prior extract but intentionally NOT banked here, so the
412+# reconciliation is visibly complete rather than a silent drop)
413+# =============================================================================
414+reconciliation_notes:
415+ - "UB geometry (buffer_line_size/buffer_bank_count/bank_group_number, PEM:763/765/767): prior extract banks them as operative; NOT banked here — refuted as the inactive area_reduce=FALSE layout (verify_B 1b). See TODO close-B1b."
416+ - "DDR/L2 latencies: prior extract labels them '(soc-domain; not core cycles)'; banked here as RAW with domain UNRESOLVED — the domain label is an unverified inference (verify_B 6b). See TODO close-B6b."
417+ - "UB port_num [8,8,16,1,...] (PEM:770) and buffer_depth (PEM:772): present in prior extract; intentionally NOT banked — outside the verify-confirmed set and the §1/§2 list (no verdict ran on them)."
418+ - "Many secondary PEM knobs in the prior extract (e.g. SIMT.SCH/LSU/REG sub-latencies, GSU pipe_stage_latency, SCALAR_Buf/SSBuf) are intentionally NOT banked — outside the verify-confirmed scope of this file. The prior extract remains the broader read-only inventory; this file banks only verify-confirmed + §1/§2 facts."
@@ -0,0 +1,296 @@
1+# `_meta/isa_matrix` — dav-3510 SIMD vector ISA capability / constraint matrix
2+ 
3+> **STATUS: BANKED** (constitution v0.2.3 ratified 2026-06-03). dav-3510 SIMD vector ISA
4+> capability/constraint matrix; tier 🥈T2/🧾H (static header guard-eval — spot-verify each
5+> `:line` before load-bearing book use). Derived from the 2026-06-03 verify panel (C) +
6+> `probes/isa_census/`. Scope = ISA matrix only.
7+ 
8+ 
9+> **`verify_cmd` 中的 `${PROBE_WORKSPACE}`**:各探针记录的 `verify_cmd` 原文写的是探针作者机器上
10+> 某个家目录下的绝对路径。该路径下的 `build.sh` / `run.sh` / `verify.sh` / `profile_simt.sh` 不随
11+> 本技能分发,CAKE2 上游亦无这些文件。移植时统一替换为 `${PROBE_WORKSPACE}`,以免把一台机器的
12+> 路径写进公开仓;这些 `verify_cmd` 是复现方式的记录,不是可直接执行的指令。
13+ 
14+## HEAD
15+ 
16+```yaml
17+head_schema: meta-matrix/v1
18+artifact: _meta/isa_matrix
19+subject: dav-3510 SIMD vector ISA (AIV) — per-op dtype support + mode/family constraints
20+tier: [🥈T2, 🧾H] # static header guard-eval; spot-verify each :line before book use
21+oracle: "/usr/local/Ascend/cann-9.1.0-beta.1/tools/bisheng_compiler/lib/clang/15.0.5/include/__clang_cce_vector_intrinsics.h"
22+oracle_lines: 13437
23+arch_env: "{__NPU_ARCH__ = 3510, every __DAV_*__ undefined}" # build flag --npu-arch=dav-3510
24+admissibility: "op/overload is in-census IFF its full enclosing #if evaluates TRUE under arch_env"
25+c_precedence_note: "&& binds tighter than || — applied to every multi-term guard below"
26+provenance:
27+ primary: probes/hw_verify_20260603/verify_C_isa_matrix.md # adversarial guard-eval, 11 claims
28+ census: probes/isa_census/RESULTS.md + isa_args.tsv # 138 base ops / ~1422 overloads
29+needs_run_deferred: [] # every cell settleable by static header read; no fresh sim run
30+dtype_axis: [u8, s8, u16, s16, f16, bf16, u32, s32, f32] # the 9-column grid axis (FP8/2xVL handled separately)
31+corrections_vs_HW_INVESTIGATION_§3: # C refuted/over-stated these — book MUST absorb
32+ - "DROP fabricated div mechanism: NO 'SupportType' / 'not supported on current device' static_assert exists (0 hits tree-wide). Int/8-bit div is absent because no overload is instantiated."
33+ - "REPLACE 'FP8 = load/store/cast/move ONLY' with 'FP8 = no ARITHMETIC' — FP8 has bitwise vand/vor/vxor/vnot + data-reorg vintlv/vdintlv/vsqz."
34+ - "FP8 cast list: f8e4m3/f8e5m2→f16 REVERSE is gated OUT for 3510 (5088); hif8↔bf16 does NOT exist. Keep only hif8↔f16/f32, f16→fp8 forward, fp8↔f32."
35+ - "histogram chistv2/dhistv2 is NOT 'dav-3510-specific' — present on 3510, shared with 6 arches; replaces older chist0-3/dhist0-3."
36+ - "RECONCILE census RESULTS.md:78 — vgatherb IS 3510-active (#define 3039 & 3114 guards include ==3510); only the L210/v300 overload-block (2987-90) is out."
37+```
38+ 
39+Legend — grid cells:
40+- **✓** = an overload for that (op × dtype) is instantiated under arch_env, cited to its `:line`.
41+- **✗** = excluded for dav-3510; cited to the **exclusion guard** `:line` (the guard whose `(!=3510)` / missing-`==3510` term drops it), not to a present-dtype line.
42+- **—** = no overload of that dtype exists for the op on ANY arch (not a dav-3510-specific exclusion).
43+- **🔧UN** = unsettled this pass → see §8 TODO; never banked as ✓.
44+ 
45+All `:line` refer to the oracle header above.
46+ 
47+---
48+ 
49+## 1 · Per-op dtype-support grid — integer/float binary arithmetic
50+ 
51+Axis order: `u8 s8 | u16 s16 | f16 bf16 | u32 s32 | f32`. (8/16/32-bit + f16/bf16/f32.)
52+ 
53+| op | u8 | s8 | u16 | s16 | f16 | bf16 | u32 | s32 | f32 | constraint + `:line` (present / **exclusion**) |
54+|---|---|---|---|---|---|---|---|---|---|---|
55+| `vadd` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | all 9; MERGING macro 7068-7079; bf16 guard 7076-7078 incl 3510. **MODE_MERGING_SRC0-capable** (§3) |
56+| `vsub` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | all 9; `__VF_BINARY_OP` 7156-7167; 8-bit s8/u8 **UNGUARDED** at 7158-7159 (only `#if` in block is bf16 7164-7166) |
57+| `vmul` | ✗ | ✗ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | **no 8-bit**: s8/u8 guard 7181-7184 → false for 3510 (`&&`>`||`). s16/u16 7179-7180; s32 7170; u32 guard 7176; f32/f16 7190-7191 (guard `!=9202`); bf16 7194-7197 |
58+| `vdiv` | — | — | ✗ | ✗ | ✓ | — | ✗ | ✗ | ✓ | **float-only**: f16 7209 / f32 7210 unguarded. Integer s16/u16/s32/u32 **EXCLUDED** by 7201-7203 `(!=3510)` (comment 7200 "C310 doesn't support integer VDIV"). u8/s8/bf16 = **—**: no `vdiv` overload of those dtypes is instantiated on ANY arch (no exclusion guard to cite) |
59+| `vmax` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | all 9; MERGING macro 7082-7093; bf16 guard 7090-7092 incl 3510. **MODE_MERGING_SRC0-capable** |
60+| `vmin` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | all 9; MERGING macro 7096-7107; bf16 guard 7104-7106 incl 3510. **MODE_MERGING_SRC0-capable** |
61+| `vabs` | — | ✓ | — | ✓ | ✓ | — | — | ✓ | ✓ | unary; s8/s16/s32/f16/f32 6867-6871 (no unsigned, no bf16) |
62+| `vneg` | — | ✓ | — | ✓ | ✓ | — | — | ✓ | ✓ | unary; s8/s16/s32/f16/f32 6894-6898 |
63+| `vabsdif` | ✗ | ✗ | ✗ | ✗ | ✓ | — | ✗ | ✗ | ✓ | **integer EXCLUDED**: u8/s8/u16/s16/s32 by guard 7212-7214 `(!=3510)`; u32 by a separate positive-list guard 7222-7224 (M300/L300/M310/L310/L311 only, no 3510). **FP-only** f16/f32 7226-7227 (present). bf16 = — (never instantiated) |
64+ 
65+**Banked constraints from §1 (confirmed 🥈T2):**
66+- **`vdiv` is float-only (f16/f32), no 8-bit, no integer.** Mechanism is **absence of overload**, NOT a `SupportType` assert (that text has 0 hits tree-wide — fabricated; see HEAD corrections). 64-bit div → §4.
67+- **`vmul` has no 8-bit** (s8/u8 dropped at 7181-7184); 16/32-bit integer mul DOES exist (s16/u16/s32/u32). `vmul`'s f32/f16/bf16 come from `__VF_BINARY_OP`, so **no `MODE_MERGING_SRC0`** (§3).
68+- The grid asymmetry is load-bearing and primary-verified: **`vadd`/`vsub`/`vmax`/`vmin` keep 8-bit; `vmul` and integer-`vdiv`/`vabsdif` do not.** `vsub` shares the `__VF_BINARY_OP` macro with `vmul` yet its 8-bit cells are unguarded (7158-7159) — the 8-bit drop is `vmul`-specific, not a macro property.
69+ 
70+---
71+ 
72+## 2 · bf16 — arch-gated IN (not excluded)
73+ 
74+bf16 is **gated to an arch list that INCLUDES `(__NPU_ARCH__ == 3510)`** → bf16 column above is **✓**, not excluded. Every guard read verbatim:
75+ 
76+| op | bf16 instantiation `:line` | guard `:line` (includes `==3510`) |
77+|---|---|---|
78+| `vadd` | 7079 | 7076-7078 |
79+| `vsub` | 7167 | 7164-7166 |
80+| `vmul` | 7197 | 7194-7196 |
81+| `vmax` | 7093 | 7090-7092 |
82+| `vmin` | 7107 | 7104-7106 |
83+| `vmadd` | 7470 | 7468-7469 (`310R6 \| L510 \| 5102 \| 3510 \| 5161`) |
84+ 
85+> **Trap note for the book:** "bf16 is gated" reads like an exclusion. It is the opposite — the gate
86+> admits 3510. Do not mark bf16 ✗.
87+ 
88+---
89+ 
90+## 3 · MODE_MERGING_SRC0 — exclusive to add / max / min
91+ 
92+`MODE_MERGING_SRC0` is a predication mode (one of `{ZEROING, MERGING, MERGING_SRC0, UNKNOWN}`). On dav-3510 it is **permitted only by `add`, `max`, `min`**; every other binary/scalar op offers `{ZEROING, MERGING, UNKNOWN}` only.
93+ 
94+| fact | `:line` |
95+|---|---|
96+| Only macro whose `static_assert` allows `MERGING_SRC0` = `__VF_MERGING_BINARY_OP` | def 7034; assert 7039-7042 |
97+| Instantiated for **`vadd`** / **`vmax`** / **`vmin`** only | 7068-7079 / 7082-7093 / 7096-7107 |
98+| The `vmul` arm of that macro is **9202-only** → not 3510 | 7111-7113 (block `#if ==9202` at 7109) |
99+| `__VF_BINARY_OP` (`vsub`/`vmul`/`vdiv`/`vand`/…) assert = `ZEROING\|MERGING\|UNKNOWN` (no `MERGING_SRC0`) | — |
100+| Apparent counterexample `__VF_VEC_VMULS_MERGING_V920` asserts `MERGING_SRC0` **but** its instantiations are `#if ==9202`-gated; 3510 takes `#else` → plain `__VF_VEC_SCALAR_OP` (8138, assert 8143-8145, **no** `MERGING_SRC0`) | 8172 / 8177-8180 / 8220 / 8138 |
101+| **V210 forbids ZEROING**: `static_assert(!(MODE_ZEROING && isV210Target()), …)` | 7044-7046 (and 8147-8149 scalar) |
102+ 
103+**Banked:** on dav-3510 the `MERGING_SRC0` set = **{vadd, vmax, vmin}**. Only two `MERGING_SRC0` asserts exist in the file (7042, 8180); the 8180/`vmuls` path is 9202-only → airtight.
104+ 
105+---
106+ 
107+## 4 · 2xVL B64 (s64/u64) — a SEPARATE ISA family, not dtype variants
108+ 
109+64-bit element ops are **their own `__VF_*_B64` macro family** on `vector_2xvl_{s64,u64}` — NOT an `s64/u64` arm of the 32-bit op. **No floating-point 2xVL form exists.**
110+ 
111+| B64 macro | `#define :line` | op | note |
112+|---|---|---|---|
113+| `__VF_VDIV_B64` / `__VF_VDIV_U64` | 11573 / 11772 | `vdiv` s64 (11755) / u64 (11940) | the only div for non-float dtypes |
114+| `__VF_BINARY_OP_B64` | — | `vadd` 10946-47 / `vsub` 10948-49 | s64/u64 (s32/u32 widen-src) |
115+| `__VF_VMUL_B64` | 10989 | `vmul` 10989-90 | |
116+| `__VF_MIN_MAX_B64` | — | `vmax` 11160-61 / `vmin` 11162-63 | |
117+| `__VF_VABS_B64` / `__VF_VNEG_B64` | 11241 / 11121 | `vabs` / `vneg` | |
118+| `__VF_VLOGIC_B64` | — | `vand`/`vor`/`vxor` 10859-64 | |
119+| `__VF_VSHL_B64` / `__VF_VSHR_B64` / `__VF_VSHLS_B64` | 9882 / 9904 / 9960 | shifts | |
120+| `__VF_VLDS_B64` / `__VF_VSTS_B64` / `__VF_VLOAD_B64` / `__VF_VSTORE_B64` | 10574 / 10604(→10619) / 12451 / 12532 | load/store | |
121+| `__VF_VGATHER2_B64` / `__VF_VSCATTER_B64` | 10588 / 10623 | gather/scatter | |
122+| `__VF_VBR_B64` / `__VF_VDUP_B64` / `__VF_VMOV_B64` / `__VF_VCI`(2xvl) | 10640 / 10651(→10687) / 10734 / 10895 | broadcast/move | |
123+| `__VF_VCMP_B64` / `__VF_VCMPS_B64` | — | compare 11005-11073 | |
124+| `__VF_VCADD_B64` / `__VF_VCMAX_MIN_B64` | — | reduce 12354-55 / 12376-79 | s64/u64 only |
125+ 
126+**Banked:** the whole B64 block from 10574 onward sits under a 3510-inclusive guard at **10571-10573** → 3510-active. Each B64 op is its own `#define`, confirmed distinct from the 32-bit path. No `f16/f32/bf16` `_B64` define exists anywhere (negative over the grepped set).
127+ 
128+---
129+ 
130+## 5 · FP8 (e4m3 / e5m2 / hif8 / e8m0) — NO arithmetic; logical + reorg + cast only
131+ 
132+> **⚠ This section is the load-bearing correction of HW_INVESTIGATION §3.** The §3 phrasing
133+> "FP8 = load/store/cast/move ONLY" is **REFUTED** and is NOT banked. The banked constraint is
134+> **"FP8 has no ARITHMETIC"**.
135+ 
136+**5a — no FP8 arithmetic (confirmed 🥈T2):** grep of `e4m3/e5m2/hif8/e8m0` against
137+`vadd/vsub/vmul/vdiv/vmax/vmin/vmadd/vmula/vaxpy/vfma/vrelu/vexp/vln/vsqrt` = **no arithmetic hits**.
138+ 
139+**5b — what FP8 CAN do on dav-3510 (refutes "cast-only"):**
140+ 
141+| FP8 capability | dtypes | `:line` (guard incl 3510) | census xref |
142+|---|---|---|---|
143+| bitwise `vand` / `vor` / `vxor` | f8e4m3, f8e5m2, f8e8m0 | 7308-7316 (guard 7302-7304) | tsv 149/153/155 |
144+| bitwise `vnot` | f8e4m3, f8e5m2, f8e8m0 | 6929-6931 | tsv 151 |
145+| data-reorg `vintlv` / `vdintlv` | f8e4m3, f8e5m2, f8e8m0 | 670-672 / 700-713 | tsv 205/203 |
146+| data-reorg `vsqz` | hif8, f8e4m3, f8e5m2, f8e8m0 | 7695-7698 (guard 7692-7694) | tsv 208 |
147+| load/store/move/broadcast/select | f8e4m3, f8e5m2, f8e8m0 | `vld`/`vst`/`vmov`/`vbr`/`vdup`/`vsel`/`vgatherb`/`vscatter` carry FP8 | tsv 57/62/63/126/128/133/194/215 |
148+ 
149+**5c — FP8 cast support (precise; two §3 errors corrected):**
150+ 
151+| cast | direction | dav-3510 status | `:line` |
152+|---|---|---|---|
153+| `hif8 ↔ f16` | both | ✓ | 5085 (guard 5082-5084 incl 3510) |
154+| `hif8 ↔ f32` | both | ✓ | 5239 (unguarded) |
155+| `f16 → f8e4m3 / f8e5m2` | forward | ✓ | 4816 / 4826 (guard 4807-4809 incl 3510) |
156+| `f8e4m3 / f8e5m2 ↔ f32` | both | ✓ | 5240-5241 (unguarded) |
157+| `f8e4m3 / f8e5m2 → f16` | **reverse** | **✗ GATED OUT** | 5088 guard = `L510 \| 5102 \| 5161` (no 3510) → 5089-5090 inactive |
158+| `hif8 ↔ bf16` | — | **— DOES NOT EXIST** | grep `hif8`+`bf16` = 0 hits |
159+ 
160+**Banked:** FP8 has **no arithmetic**; it has bitwise-logical, data-reorg, load/store/move/cast.
161+Cast list = `{hif8↔f16, hif8↔f32, f16→fp8 forward, fp8↔f32}`. **Do NOT** bank
162+"e4m3/e5m2↔f16 bidirectional" (reverse is gated out) or "hif8↔bf16" (does not exist).
163+ 
164+---
165+ 
166+## 6 · Reduce family (vcadd / vcmax / vcmin / vcgadd / vcgmax / vcgmin / vcpadd)
167+ 
168+| op | dav-3510 dtypes | `:line` | note |
169+|---|---|---|---|
170+| `vcadd` | s32, u32, f16, f32 | active set 7542-7547 (guard 7541 `!=9201 && !=9202`) | s8/u8 **EXCLUDED** 7535-7537 (`!=3510`). B64 s64/u64 12354-55 |
171+| `vcmax` | s16, s32, u16, u32, f16, f32 | active 7590-7595 (guard 7589 `!=9201 && !=9202`) | **s8/u8 EXCLUDED** for 3510 (guard 7583-7585 `(!=3510)`, bodies 7586-7587). B64 12376-77 |
172+| `vcmin` | s16, s32, u16, u32, f16, f32 | active 7603-7608 | **s8/u8 EXCLUDED** for 3510 (guard 7597-7599 `(!=3510)`, bodies 7600-7601). B64 12378-79 |
173+| `vcgadd` | f16, f32 (+ u16/s16→u32/s32 widen) | 8432-8439 / expand 8457-58 | group reduce |
174+| `vcgmax` | f16, f32 | 8435-8466 | group reduce |
175+| `vcgmin` | f16, f32 | 8438-8471 | group reduce |
176+| `vcpadd` | f16, f32 | 8441-8442 | pairwise |
177+ 
178+**Banked nuances:**
179+- `vcadd` listed "s16/u16" are **widening *source* types** (s16-src→s32-dst at 7542; u16-src→u32-dst at 7544), **not** standalone s16/u16-dst reduces.
180+- `vcmax`/`vcmin` **s8/u8 are EXCLUDED** for dav-3510 — this **resolves** the verify_C still_UN: guards 7583-7585 / 7597-7599 each carry `(__NPU_ARCH__ != 3510)`. Active = {s16,s32,u16,u32,f16,f32}.
181+- `vcmax`/`vcmin` **output semantic ("broadcast")** → **🔧UN, NOT banked** (see §8).
182+ 
183+---
184+ 
185+## 7 · Fused ops, activations, data-reorg, gather/scatter, histogram
186+ 
187+### 7a · Fused single-instruction ops
188+ 
189+| op | dav-3510 dtypes | `:line` | note |
190+|---|---|---|---|
191+| `vmadd` (FMA) | f16, f32, bf16 | 7465-7466 (+bf16 7470) | guard 7464 `!=9201 && !=9202` |
192+| `vmula` | s32, s16, u16, u32 (integer) | 7441-7445 (+u32 7452, +bf16 7462) | **FP f32/f16/bf16 DELEGATES to `vfma`** (body 10367; def 10372-74; comment 10371) → "single-instr" true only for integer `vmula` |
193+| `vaxpy` | f32, f16 | 8038-8039 (unguarded) | |
194+| `vfma` / `vfms` / `vfnma` / `vfnms` | f16, bf16, f32 each | 10399-10401 / 10403-05 / 10407-09 / 10411-13 (`__VF_MAS_OP`, no enclosing `#if`) | |
195+| `vexpdif` | f16, f32 (+ f32/f32, f16/f16, bf16/bf16) | 5847 / 5852 / 5856 / 5859 (def 5832) | |
196+ 
197+> Distinct from the c_api L2 composites (`AddRelu`, `FusedMulAdd`, `MulAddDst`, …) which lower to
198+> **multiple** intrinsics (census RESULTS.md §6) — those are not single-instruction.
199+ 
200+### 7b · Activations (unary)
201+ 
202+| op | dav-3510 dtypes | `:line` |
203+|---|---|---|
204+| `vrelu` | f16, f32, **s32** | 6873-6875 |
205+| `vexp` | f16, f32 | 6877-6878 |
206+| `vsqrt` | f16, f32 | 6880-6881 |
207+| `vln` | f16, f32 | 6891-6892 (also alt high-precision `__VF_LN_VEXP_OP` 10495-10498) |
208+| `vlrelu` | f32, f16 | 8249-8250 |
209+| `vprelu` | f16, f32 | 7267-7268 |
210+ 
211+> All unguarded in their neighborhood; the only nearby `#if` (6883-6889) brackets `vrsqrt`/`vrec`
212+> (directly verified — NOT `vsqrt`/`vln`). `vrelu`'s `+s32` is exactly as cited.
213+ 
214+### 7c · Data-reorg / move / select
215+ 
216+| op | `:line` | note |
217+|---|---|---|
218+| `vintlv` / `vdintlv` | 663-676 / 697-709 | incl. FP8/bf16/s64/u64 |
219+| `vpack` / `vunpack` | 6771-6774 / 6795-6798 | |
220+| `vsqz` (compact-by-mask) | 7680+ (FP8 7695-7698; int 7701-7707) | |
221+| `vbr` / `vdup` / `vmov` / `vci` | 9793-9807 / 6704-6724 / 6424-6438 / 7902-7922 | broadcast/move (B64 variants → §4) |
222+| `vsel` / `vselr` / `vselrv2` | 6358-6375 / 6561-6579 / 6597-6600 | |
223+| `vslide` | predicate `pslide` 8516-8518 | (vector slide via predicate family) |
224+ 
225+### 7d · Gather / scatter — **vgatherb 3510-ACTIVE (census reconcile)**
226+ 
227+| op | dav-3510 status | `:line` |
228+|---|---|---|
229+| `vgatherb` | **✓ ACTIVE** | `#define` 3039 (guard 3033-3040 incl `==3510`) **and** `#define` 3114; first block `#define` 2991 (guard 2987-2990, **no 3510**) is the only inactive one |
230+| `vgather2` / `vgather2_bc` | ✓ | 3166+ (guard 3142-3147 incl 3510) / 3253-3262 |
231+| `vscatter` | ✓ | 2845-2866 (defs 2818/2839) |
232+ 
233+> **Census reconcile (task-required):** `probes/isa_census/RESULTS.md:78` lumps `vgatherb` into the
234+> 153 excluded rows. That is at the **overload** granularity — only the **L210/v300 overload block**
235+> (`#define` 2991, guard 2987-2990) is out; the **op `vgatherb` IS present** for dav-3510 via the
236+> 3039 & 3114 blocks (guards include `==3510`). Verify_C Claim 10 confirms. The book must treat
237+> `vgatherb` as a dav-3510 op.
238+ 
239+### 7e · Histogram — present on 3510, NOT 3510-exclusive
240+ 
241+| op | signature | `:line` | note |
242+|---|---|---|---|
243+| `chistv2` | `vector_u16 &dst, vector_u8 src, …` (**u8 → u16**) | 7870 | guard 7842-7847 incl `==3510` |
244+| `dhistv2` | `vector_u16 &dst, vector_u8 src, …` (**u8 → u16**) | 7852 | same guard |
245+ 
246+> **Banked nuance:** "dav-3510-specific" (§3 phrasing) **over-states** — the same guard also admits
247+> 310R6/L510/5102/9201/9202/5161. Correct framing: **`chistv2`/`dhistv2` are present on dav-3510,
248+> replacing the older numbered `chist0-3`/`dhist0-3`** (those are guarded away from 3510). u8→u16 is exact.
249+ 
250+---
251+ 
252+## 8 · TODO — still_UN (NOT banked; never marked ✓)
253+ 
254+| item | why UN | settle by |
255+|---|---|---|
256+| `vcmax` / `vcmin` **output semantic = "broadcast"?** | `__VF_VCMAX_MIN` body (7554+) does a horizontal compare-reduce with a `pge_##PTYPE(PAT_VL2)` / `vmov_m` merge tail (7569-7571); whether the result is **broadcast across lanes** vs a **single-lane scalar** is not unambiguous from the macro alone | read the underlying `__builtin_cce_*` spec, or a 1-op trace of `vcmax`; **do NOT inherit "broadcast" verbatim** into the book |
257+ 
258+> Resolved this pass (no longer UN): `vcmax`/`vcmin` **s8/u8** active status — **EXCLUDED** for 3510
259+> (guards 7583-7585 / 7597-7599 carry `(!=3510)`), now banked in §6.
260+ 
261+---
262+ 
263+## 9 · EXCLUDED from dav-3510 (3510-negated guards) — confirmed 🥈T2
264+ 
265+| excluded | exclusion guard `:line` | note |
266+|---|---|---|
267+| `vbcnt` | 6900-6902 (`… && (__NPU_ARCH__ != 3510) && …`) | bit-count; bodies 6903-6908 |
268+| `vcls` | 6900-6902 (same guard) | count-leading-sign; bodies 6910-6915 |
269+| integer `vdiv` (s16/u16/s32/u32) | 7201-7203 (`(!=3510)`) | float `vdiv` f16/f32 stays (§1) |
270+| integer `vabsdif` (u8/s8/u16/s16/s32) | 7212-7214 (`(!=3510)`) | FP `vabsdif` f16/f32 stays (7226-7227) |
271+| `vdivf` | 7229-7230 (`(!=3510)`) | the `u16` divf overload at 7231 dropped |
272+| 9202-only **merging `vmul`** | 7109 block `#if ==9202` (bodies 7111-7113) | dav-3510 gets `vmul` from `__VF_BINARY_OP` instead (§1, §3) |
273+ 
274+> Also note (census §"Surprises"): **`v4dtrans` / `vtranspose` do NOT exist** as SIMD intrinsics
275+> (absent from the vector header); transpose lives only at the c_api L2 layer and does not lower to a
276+> vector-ISA op on dav-3510. (Out of scope for the dtype grid; recorded so the book does not invent it.)
277+ 
278+---
279+ 
280+## 10 · Reconciliation ledger (census ↔ verify_C, as required by the task)
281+ 
282+| topic | census says | verify_C / this file | resolution |
283+|---|---|---|---|
284+| `vgatherb` for 3510 | excluded (RESULTS.md:78, in the 153) | **active** (#define 3039 & 3114 incl 3510) | **active** — census exclusion was overload-granular (L210/v300 block only). §7d. |
285+| div mechanism | (census silent on "SupportType") | §3 phrasing's `SupportType` assert = **0 hits** | mechanism **fabricated** → dropped; constraint (float-only) kept via absence-of-overload. §1. |
286+| FP8 scope | logical/reorg/cast FP8 forms exist (tsv 149-208) | §3 "cast-only" **refuted** | bank **"no arithmetic"**, not "cast-only". §5. |
287+| histogram scope | guard shared with 6 arches | §3 "dav-3510-specific" over-stated | "present on 3510, replaces chist0-3/dhist0-3". §7e. |
288+| `vmul` MERGING | dav-3510 vmul from `__VF_BINARY_OP`, 9202 path is merging | same | no `MERGING_SRC0` for `vmul`. §3. |
289+| `vmula` FP | TERNARY_OP rows incl f32/f16/bf16 (tsv 38) | FP arm **delegates to vfma** (10367) | "single-instr" only for integer `vmula`. §7a. |
290+ 
291+---
292+ 
293+### Tier summary
294+- All grid cells, mode constraints, family memberships, and exclusions: **🥈T2** (static header guard-eval at a cited `:line`) — spot-verify each `:line` before book use, per house rule.
295+- `vcmax`/`vcmin` "broadcast" output semantic: **🔧UN** (§8).
296+- No item is `needs_run_deferred`: every cell is settleable by a static header read (verify_C Claim-set; no fresh simulation required).
@@ -0,0 +1,165 @@
1+# `simt.arith.bit` — per-thread integer bit/mul builtins (`__brev/__clz/__popc/__ffs/__mulhi/__byte_perm`)
2+ 
3+## HEAD
4+ 
5+```yaml
6+head_schema: pb5/v1
7+op: simt.arith.bit # canonical instance: brev/clz/popc/ffs/mulhi over boundary patterns
8+paradigm: SIMT
9+core: AIV
10+lowering: "1-op: __brev32 BREV / __popc32 POPC / __byte_perm PRMT / __mulhi __umulhi __mul_i32toi64 IMUL; __clz32 CLZ+zero-guard; __ffs32 ~6-op POPC-based; brev64 2xBREV; popc64 2xPOPC+IADD; clz64/ffs64 divergent sw; __umul64hi ~12-op (4xIMUL+6xIADD_X); __mul64hi ~21-op; __mul24 IMUL+3xSHFI"
11+dtypes: [s32, u32, s64, u64]
12+selection_keys:
13+ - xlate.cuda-1to1
14+ - control.divergent-per-element
15+not_for:
16+ - access.contiguous-elementwise # → SIMD elementwise path for bulk regular data
17+cuda_pta_analog: "CUDA __brev/__clz/__popc/__ffs/__mulhi/__umul64hi/__byte_perm/__sad — same names"
18+false_friends: [ffs_is_not_single_op_popc_based, 64bit_variants_software_expand, sad_diff_wraps_32bit,
19+ mul24_is_not_hw_op, clz64_ffs64_diverge_the_warp]
20+cost_model:
21+ roofline_run_id: probes/simt_castarith/RESULTS.md # P-22 dependent-chain (compute-op; no shape roofline)
22+ binding_resource: UN # whole-prog launch-bound at probed N; body cadence-bound
23+ optimum: {value: 1.31, unit: cycles/elem} # whole-prog 419 cy / 320 results @ selftest (launch-bound, R-15)
24+ perf_factor_K: 1.0
25+ latency_cycles:
26+ POPC_XOR_pair: 9 # popc^u dep chain; mode 9 UNR-invariant; LOP3=4 => POPC ~5 (IN)
27+ CLZ_guard_XOR_iter: 9 # 4-op iter (CLZ+ISETP+MOV+LOP3) in 9 cy
28+ FFS32_XOR_iter: "~33-36" # 7-op expansion; span/UNR basis (POPC-POPC 27-30 RANGE)
29+ MULHI_OR_pair: 6 # IMUL+LOP3 overlap
30+ BREV64_IADD_iter: 6 # 2xBREV pair; BREV-BREV ~3
31+ BREV32_dep: UN # compiler folds both brev chains (identity)
32+ elem_per_cycle: UN # II unmeasured
33+ toolchain:
34+ bisheng: "clang version 15.0.5 (clang-5c68a1cb1231 flang-5c68a1cb1231) 2026-05-09"
35+ model: "{model_name: Ascend950PR_9599, cube_cores: 32, vec_cores: 64}"
36+ configs: [1981_sim_ffts_plus.toml, 1981_model.toml]
37+verify_cmd: |
38+ bash ${PROBE_WORKSPACE}/scripts/build.sh k.cpp
39+ bash ${PROBE_WORKSPACE}/scripts/run.sh k
40+ bash ${PROBE_WORKSPACE}/scripts/verify.sh
41+ bash ${PROBE_WORKSPACE}/scripts/profile_simt.sh k # expect BREV 1, CLZ 1, IMUL 1, POPC 2 per elem (ffs adds a POPC; no FFS op exists)
42+sources:
43+ - probes/simt_castarith/RESULTS.md # census diff table + cadences + 884-pt correctness
44+ - probes/simt_castarith/cannsim_20260610164643_kca/ # bits+arith errors=0 (within 884)
45+ - probes/simt_castarith/use_selftest/cannsim_20260610170241_kbits/ # THIS USE one-shot errors=0/320
46+ - "__clang_cce_simt_dav3510_intrinsic.h:576" # __brev 32/64
47+ - "__clang_cce_simt_dav3510_intrinsic.h:588" # __clz 32 + 64 software (branch + clz32)
48+ - "__clang_cce_simt_dav3510_intrinsic.h:606" # __popc 32 + 64 = 2x popc32 + add
49+ - "__clang_cce_simt_dav3510_intrinsic.h:620" # __ffs 32 + 64 software
50+ - "__clang_cce_simt_dav3510_intrinsic.h:524" # __umulhi/__mulhi/__mul_i32toi64/__umul64hi
51+ - "__clang_cce_simt_dav3510_intrinsic.h:563" # __mul64hi = software around __umul64hi
52+ - "__clang_cce_simt_dav3510_intrinsic.h:391" # __byte_perm -> prmt
53+ - "__clang_cce_simt_dav3510_intrinsic.h:796" # __sad: z + abs(x-y), 32-bit wrap diff
54+status: piloted
55+tier_summary:
56+ - {claim: brev/clz/popc/ffs 32+64 + mulhi/mul64hi/prmt/sad/mul24 errors=0 boundary set, tier: T1-sim}
57+ - {claim: brev32/popc32/prmt/mulhi/umulhi/mul_i32toi64 = 1 ISA op; ffs32 ~6; umul64hi ~12; mul64hi ~21, tier: T1-sim}
58+ - {claim: dependent iter cadences (POPC pair 9, CLZ iter 9, MULHI pair 6, FFS ~33-36, BREV64 6), tier: T1-sim}
59+ - {claim: BREV32 dependent cadence, tier: UN}
60+ - {claim: __sad diff wraps in 32-bit before abs, tier: T1-sim}
61+ - {claim: II / data-dominant cost, tier: UN}
62+```
63+ 
64+## 0 · SELECT
65+Same names as CUDA — but check the lowering column before budgeting: 32-bit `__brev/__popc/__byte_perm`
66++ the mulhi family are single ISA ops; `__clz` adds a zero-guard; `__ffs` is NOT single (POPC-based
67+~6-op expansion); 64-bit clz/ffs are divergent software (BRANCH+DVG enter the warp), brev64/popc64 = 2 ops;
68+`__mul64hi`(signed) + `__sad` + `__mul24` are header software. Bulk regular bit-twiddling → SIMD sibling.
69+ 
70+## 1 · CONTRACT
71+Surface 🧾H :391-811: `__brev(u32/u64)`, `__clz(int/ll)→[0,32/64]` (`__clz(0)`=32), `__popc(u32/u64)`,
72+`__ffs(int/ll)` (1-based, 0→0), `__mulhi/__umulhi` (hi32 of 32×32), `__umul64hi/__mul64hi` (hi64),
73+`__mul_i32toi64` (full 64 product, 1 IMUL), `__byte_perm(x,y,s)` CUDA-prmt nibble selects + s.b3 sign-ext,
74+`__sad(x,y,z)` z+|wrap32(x−y)|, `__mul24` masks+mul. All probed bit-exact errors=0/884 incl 0/MSB/all-ones (🟢 kca).
75+ 
76+## 2 · USE — paste, build, run, verify
77+```cpp
78+// Ascend 950PR SIMT bit ops: per-thread __brev/__clz/__popc/__ffs (u32) + __mulhi over
79+// 64 boundary patterns; exhaustive-pattern spot set, bit-exact host compare.
80+// Build:
81+// source /usr/local/Ascend/ascend-toolkit/set_env.sh
82+// bisheng --asc-aicore-lang --npu-arch=dav-3510 k.cpp -o k \
83+// -I$ASCEND_HOME_PATH/aarch64-linux/include -L$ASCEND_HOME_PATH/lib64 \
84+// -Wl,-rpath,$ASCEND_HOME_PATH/lib64 -lascendcl -lruntime
85+// Run: cannsim record ./k -s Ascend950 -g Pass: RESULT: errors=0/320
86+#include "kernel_operator.h"
87+#include "simt_api/asc_simt.h"
88+using namespace AscendC;
89+constexpr uint32_t T = 64;
90+ 
91+__simt_vf__ LAUNCH_BOUND(T) inline void Body(__gm__ uint32_t *x, __gm__ uint32_t *z) {
92+ uint32_t i = Simt::GetThreadIdx<0>();
93+ uint32_t v = x[i];
94+ z[0 * T + i] = __brev(v); // ◀ MUTATE op family here + in host ref
95+ z[1 * T + i] = (uint32_t)__clz((int)v);
96+ z[2 * T + i] = (uint32_t)__popc(v);
97+ z[3 * T + i] = (uint32_t)__ffs((int)v);
98+ z[4 * T + i] = (uint32_t)__mulhi((int)v, (int)(v | 1u));
99+}
100+extern "C" __global__ __aicore__ void k(GM_ADDR x, GM_ADDR z) {
101+ KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY);
102+ Simt::VF_CALL<Body>(Simt::Dim3{T, 1, 1}, (__gm__ uint32_t *)x, (__gm__ uint32_t *)z);
103+}
104+ 
105+#ifndef __CCE_AICORE__
106+#include "acl/acl.h"
107+#include <cstdio>
108+#include <cstdlib>
109+#include <cstdint>
110+#define CK(e) do{aclError _r=(e); if(_r!=ACL_SUCCESS){std::printf("ACL FAIL %s %d\n",#e,(int)_r);std::fflush(stdout);return 1;}}while(0)
111+static uint32_t brev(uint32_t x){uint32_t r=0;for(int i=0;i<32;i++)r|=((x>>i)&1u)<<(31-i);return r;}
112+static uint32_t clz(uint32_t x){for(int i=31;i>=0;i--)if((x>>i)&1u)return 31-i;return 32;}
113+static uint32_t popc(uint32_t x){uint32_t n=0;while(x){n+=x&1u;x>>=1;}return n;}
114+static uint32_t ffs(uint32_t x){if(!x)return 0;for(int i=0;i<32;i++)if((x>>i)&1u)return i+1;return 0;}
115+int main() {
116+ CK(aclInit(nullptr)); CK(aclrtSetDevice(0));
117+ aclrtStream s = nullptr; CK(aclrtCreateStream(&s));
118+ uint32_t hx[T], hz[5 * T];
119+ const uint32_t edge[8] = {0u, 1u, 0x80000000u, 0xFFFFFFFFu, 0xAAAA5555u, 0x7FFFFFFFu, 2u, 0x00010000u};
120+ for (uint32_t i = 0; i < T; ++i) hx[i] = i < 8 ? edge[i] : (0x9E3779B9u * (i + 1));
121+ void *dx, *dz;
122+ CK(aclrtMalloc(&dx, T*4, ACL_MEM_MALLOC_HUGE_FIRST)); CK(aclrtMalloc(&dz, 5*T*4, ACL_MEM_MALLOC_HUGE_FIRST));
123+ CK(aclrtMemcpy(dx, T*4, hx, T*4, ACL_MEMCPY_HOST_TO_DEVICE));
124+ k<<<1, nullptr, s>>>((GM_ADDR)dx, (GM_ADDR)dz);
125+ CK(aclrtSynchronizeStream(s));
126+ CK(aclrtMemcpy(hz, 5*T*4, dz, 5*T*4, ACL_MEMCPY_DEVICE_TO_HOST));
127+ uint32_t e = 0;
128+ for (uint32_t i = 0; i < T; ++i) {
129+ uint32_t v = hx[i];
130+ uint32_t r[5] = {brev(v), clz(v), popc(v), ffs(v),
131+ (uint32_t)(int32_t)(((int64_t)(int32_t)v * (int32_t)(v | 1u)) >> 32)}; // ◀ MUTATE with device
132+ for (int f = 0; f < 5; ++f)
133+ if (hz[f * T + i] != r[f] && e++ < 8)
134+ std::printf("f%d[0x%08x] dev=0x%x ref=0x%x\n", f, v, hz[f * T + i], r[f]);
135+ }
136+ std::printf("RESULT: errors=%u/%u\n", e, 5 * T); std::fflush(stdout);
137+ aclrtFree(dx); aclrtFree(dz);
138+ aclrtDestroyStream(s); aclrtResetDevice(0); aclFinalize(); return e ? 2 : 0;
139+}
140+#endif
141+```
142+Pass = `errors=0/320` AND `sendStarsSQE ≥ 1` (one-shot evidence: `use_selftest/cannsim_20260610170241_kbits/`).
143+ 
144+## 3 · HAZARDS — silent (compiles fine, results wrong)
145+| Hazard | Symptom | Repair | Evidence |
146+|---|---|---|---|
147+| `__ffs` budgeted as 1 op | ~6× op-count drift | ffs32 = POPC-based expansion (census) | 🟢 census diff |
148+| 64-bit clz/ffs assumed branch-free | BRANCH+DVG enter warp | budget divergence; prefer 32-bit | 🟢 fam14/18 |
149+| `__sad` 64-bit diff intuition | INT_MIN−INT_MAX → 1 wrap then abs | wrap32 before abs (probed) | 🟢 kca f9 |
150+| `__mul24` assumed hw 24-bit mul | IMUL + 3 SHFI masks | use plain 32-bit mul unless masking wanted | 🟢 fam25 |
151+| `__umul64hi`/`__mul64hi` assumed 1 op | ~12 / ~21 ops | 64-bit hi-mul is software — budget it | 🟢 fam21/22 |
152+| `__clz(0)`=32 / `__ffs(0)`=0 | off-by-one on zero | probed contract | 🟢 kca |
153+ 
154+## 4 · PERF — measured 🟢T1-sim (sim figures, never hardware rates)
155+Whole-prog launch-bound 419 cy at selftest N (K=1.0). Dependent body cadences (P-22 stamps; anchor n
156+tracks UNR 16/32/64; spacing invariant): POPC+XOR pair **9**; CLZ+guard+XOR 4-op iter **9**;
157+MULHI+OR pair **6** (IMUL/LOP3 overlap); FFS32 7-op iter **~33–36** — i.e. ffs ≈ 4–6× a popc;
158+BREV64 pair iter **6**. BREV32 dep ❓UN — both brev chains compiler-fold (count law verified instead).
159+SIMD costs do NOT transfer (P-22). ❓UN: isolated single-op latencies (chains measure pairs/iters) · II.
160+ 
161+## 5 · EVIDENCE & EDGES
162+- Census diff table + cadence table: `probes/simt_castarith/RESULTS.md`; correctness within errors=0/884 kca run.
163+- Headers: surfaces+expansions `__clang_cce_simt_dav3510_intrinsic.h:391/524/563/576-639/796/805`.
164+- ❓UN: isolated POPC/CLZ latency · 64-bit op cadence · data-dominant N.
165+- Siblings: `simt.cast.fp-int` · `simt.elementwise.binary` · `simt.intminmax` (census, planned).
@@ -0,0 +1,76 @@
1+# `simt.atomic.rmw` — global-memory atomics (`Simt::Atomic{Add,Sub,Max,Min,And,Or,Xor,Inc,Dec,Exch,Cas}`)
2+ 
3+## HEAD
4+ 
5+```yaml
6+head_schema: pb5/v1
7+op: simt.atomic.rmw # canonical instance: leader-only AtomicAdd combine, int32, N=4096
8+paradigm: SIMT
9+core: AIV
10+lowering: "AscendC::Simt::Atomic{Add,Sub,Max,Min,And,Or,Xor,Inc,Dec,Exch,Cas}<T>(__gm__ T*, ...) -> atomic* builtins -> lsu SIMT_RED ops; 11 ops × {s32,u32,s64,u64,f32} = 55 lowerings (one entry, dtype table)"
11+dtypes: [s32] # VERIFIED bit-exact via warp-sum combine; u32 analogous; f32 NON-deterministic order => §2.6(c)
12+selection_keys: [control.divergent-per-element, xlate.cuda-1to1]
13+not_for: [pattern.reduction-full] # full reduce → REDUX + ONE leader atomic; never per-thread atomics
14+cuda_pta_analog: "CUDA atomicAdd/atomicMax/...; returns old value"
15+false_friends: [atomic_per_thread_kills_throughput_x24, all_lane_combine_overcounts_32x,
16+ fp32_atomics_not_bit_exact, atomic_returns_old_value]
17+cost_model:
18+ roofline_run_id: probes/simt_isa_cost/RESULTS.md
19+ binding_resource: UN # GM atomic RTT serializes dependent chains; launch-bound whole-prog
20+ optimum: {value: 0.102, unit: cycles/elem}
21+ perf_factor_K: 1.0
22+ latency_cycles:
23+ ATOMIC_GM_dep: "~16.9k RTT (RANGE; linear in chain length 2.14x at 2x)"
24+ contention_alllane_vs_leader: "x24 measured (5,326 -> 127,926 body span)"
25+ elem_per_cycle: "overlap by warps; one leader atomic per warp costs ~0 extra"
26+ toolchain:
27+ bisheng: "clang version 15.0.5 (clang-5c68a1cb1231 flang-5c68a1cb1231) 2026-05-09"
28+ model: "{model_name: Ascend950PR_9599, cube_cores: 32, vec_cores: 64}"
29+ configs: [1981_sim_ffts_plus.toml, 1981_model.toml]
30+verify_cmd: |
31+ bash ${PROBE_WORKSPACE}/scripts/build.sh k.cpp
32+ bash ${PROBE_WORKSPACE}/scripts/run.sh k
33+ bash ${PROBE_WORKSPACE}/scripts/verify.sh
34+ bash ${PROBE_WORKSPACE}/scripts/profile_simt.sh k # lsu RED count == leaders (warps); all-lane mutate => x32
35+sources:
36+ - probes/simt_isa_cost/RESULTS.md # atomic RTT + x24 serialization
37+ - probes/simt_reduce/cannsim_20260604082013_kuse/ # leader AtomicAdd bit-exact
38+ - probes/simt_reduce/RESULTS.md # 32x overcount hazard run
39+ - "asc/impl/simt_api/cpp/dav_3510/kernel_simt_atomic_impl.h:82" # AtomicAdd -> atomicAdd; family decls
40+status: piloted
41+tier_summary:
42+ - {claim: leader AtomicAdd combine bit-exact int32, tier: T1-sim}
43+ - {claim: all-lane combine overcounts 32x AND serializes x24, tier: T1-sim}
44+ - {claim: dependent atomic ~16.9k cy RTT linear, tier: T1-sim}
45+ - {claim: 11 ops x 5 dtypes surface, tier: H}
46+ - {claim: f32 atomic order non-deterministic, tier: T1-sim}
47+```
48+ 
49+## 0 · SELECT
50+Cross-warp/block combine of a few values → here (leader-only). Full-array reduce → REDUX (16cy) per
51+warp + ONE atomic. Per-element atomics on shared counters = ×24 serialization measured — restructure.
52+ 
53+## 1 · CONTRACT
54+`Simt::AtomicAdd<int32_t>(__gm__ addr, v)` adds atomically, returns OLD (🧾H :82; 🟢 used in warp-sum
55+kuse, gsum=-2240 exact). Family Add/Sub/Max/Min/And/Or/Xor/Inc/Dec/Exch/Cas × {s32,u32,s64,u64,f32}
56+(🧾H). int ops order-free bit-exact; f32 non-associative ⇒ §2.6(c).
57+ 
58+## 2 · USE
59+The canonical leader-only combine §USE lives in `simt.reduce.warp-sum` §2 (Atomic mutate marked).
60+Mutate `AtomicAdd→AtomicMax/Min` with the matching identity per HAZARDS.
61+ 
62+## 3 · HAZARDS
63+| Hazard | Symptom | Repair | Evidence |
64+|---|---|---|---|
65+| atomic from all 32 lanes | 32× value; ×24 wall | leader only | 🟢 hz_alllane + spans |
66+| dependent atomic chain | 16.9k cy/link serial | independent atomics; overlap warps | 🟢 P-22 |
67+| fp32 atomic expected exact | low-bit drift | int dtypes or §2.6(c) tolerance | 🟢 hz_fp32 |
68+| identity mismatch on Max/Min | clamped result | INT_MIN / INT_MAX | 🟢 warp-sum |
69+ 
70+## 4 · PERF
71+RTT ~16.9k dep, overlap by warps; leader pattern = 1 RED/warp visible in lsu (closed loop:
72+profile RED count == warps; all-lane mutate ⇒ ×32 count + ~×24 span). Whole-prog launch-bound K=1.0.
73+ 
74+## 5 · EVIDENCE & EDGES
75+P-22 spans+slope; warp-sum kuse + hazard runs; impl :82. ❓UN: per-dtype T-ref (u32/s64/u64/f32); RTT @≥1M.
76+Siblings: reduce.warp-sum (leader pattern) · ldst.global.
@@ -0,0 +1,164 @@
1+# `simt.cast.fp-int` — per-thread fp32↔int casts (`__cvt_*<ROUND,sat>`, F2I/I2F/F2F single-op)
2+ 
3+## HEAD
4+ 
5+```yaml
6+head_schema: pb5/v1
7+op: simt.cast.fp-int # canonical instance: z[i]=__cvt_int32_t<ROUND::R>(x[i]) + i2f roundtrip
8+paradigm: SIMT
9+core: AIV
10+lowering: "__cvt_{int32_t,uint32_t,int64_t,uint64_t}(float) -> 1x SIMT_F2I; __cvt_float(s32/u32/s64/u64) -> 1x SIMT_I2F; __cvt_float(float) -> 1x SIMT_F2F; ROUND+sat are immediates, never extra ops"
11+dtypes: [f32, s32, u32, s64, u64] # all five directions errors=0 (884-pt known-answer, 5 modes)
12+selection_keys:
13+ - xlate.cuda-1to1
14+ - control.divergent-per-element
15+not_for:
16+ - access.contiguous-elementwise # → SIMD vcvt family is the bulk-cast path (numeric.dtype-convert)
17+cuda_pta_analog: "__float2int_rn/rz/ru/rd, __float2uint_*, __int2float_*, __ull2float_*, rintf/truncf"
18+false_friends: [a_is_half_away_not_away, f2i_saturates_never_wraps, nan_to_int_is_zero,
19+ u32_cast_returns_signed_int, f2f_flushes_neg0, simd_vcvt_is_not_this_path]
20+cost_model:
21+ roofline_run_id: probes/simt_castarith/RESULTS.md # P-22 dependent-chain (no shape roofline: compute-op)
22+ binding_resource: UN # whole-prog launch-bound at probed N (419 cy); body F2I-cadence-bound
23+ optimum: {value: 3.27, unit: cycles/elem} # whole-prog 419 cy / 128 results @ selftest (launch-bound, R-15)
24+ perf_factor_K: 1.0 # overhead-bound shape; body cadence is the per-op cost
25+ latency_cycles:
26+ F2I_I2F_FADD_dep_iter: 11 # dependent f32->s32->f32+FADD chain; F2I spacing 11 = whole iter (n tracks UNR 16/32/64)
27+ F2F_FFMA_dep_iter: 9 # f2f quantize + FFMA chain (mode=min=max 9, UNR-invariant)
28+ elem_per_cycle: UN # ILP/II not measured; isolated F2I/I2F/F2F latencies UN (chains measure pairs)
29+ toolchain:
30+ bisheng: "clang version 15.0.5 (clang-5c68a1cb1231 flang-5c68a1cb1231) 2026-05-09"
31+ model: "{model_name: Ascend950PR_9599, cube_cores: 32, vec_cores: 64}"
32+ configs: [1981_sim_ffts_plus.toml, 1981_model.toml]
33+verify_cmd: |
34+ bash ${PROBE_WORKSPACE}/scripts/build.sh k.cpp
35+ bash ${PROBE_WORKSPACE}/scripts/run.sh k
36+ bash ${PROBE_WORKSPACE}/scripts/verify.sh
37+ bash ${PROBE_WORKSPACE}/scripts/profile_simt.sh k # expect F2I and I2F counts == 1/elem each
38+sources:
39+ - probes/simt_castarith/RESULTS.md # census + 884-pt known answers + P-22 cadences
40+ - probes/simt_castarith/cannsim_20260610164643_kca/ # errors=0/884, 5 modes x 5 directions
41+ - probes/simt_castarith/use_selftest/cannsim_20260610170059_kcast/ # THIS USE one-shot errors=0/128
42+ - "__clang_cce_simt_dav3510_intrinsic.h:643" # F2I_CVT_FLOAT (s32/u32; returns int; sat forced)
43+ - "__clang_cce_simt_dav3510_intrinsic.h:664" # F2I_B64_CVT (s64/u64; float-only src)
44+ - "__clang_cce_simt_dav3510_intrinsic.h:688" # F2F_GENERAL_FP32_CVT (int->f32 + f32->f32)
45+ - "__clang_dpp_types.h:220" # enum class ROUND { R, A, F, C, Z, O, H }
46+status: piloted
47+tier_summary:
48+ - {claim: 5 directions x 5 modes errors=0 (884-pt incl boundaries), tier: T1-sim}
49+ - {claim: each cast = exactly 1 ISA op (F2I/I2F/F2F), tier: T1-sim}
50+ - {claim: f->int sat forced RS_ENABLE; only R/A/F/C/Z legal, tier: H}
51+ - {claim: A = nearest-ties-away; R = nearest-even; NaN->0; -0 f2f flush; NaN f2f -> 0x7FFFFFFF, tier: T1-sim}
52+ - {claim: cvt roundtrip pair dependent cadence (RESULTS table), tier: T1-sim}
53+ - {claim: F2I alone latency, tier: UN}
54+```
55+ 
56+## 0 · SELECT
57+Bulk contiguous dtype convert → SIMD vcvt (`numeric.dtype-convert`), not here. Per-thread cast inside
58+a divergent SIMT body, or a 1:1 CUDA port of `__float2int_*` → here. Intercepts (all probed):
59+`(int)f` ≠ wrap — **950PR fp→int always saturates** (RS_ENABLE forced); NaN→0 not UB; `ROUND::A` =
60+nearest-ties-AWAY (`std::round`), not C's away-from-zero; `__cvt_uint32_t` returns `int` (bits of u32).
61+ 
62+## 1 · CONTRACT
63+`int __cvt_int32_t<ROUND rnd=Z, sat=RS_ENABLE>(float)` etc. (🧾H :643/664/688) — rnd ∈ {R,A,F,C,Z}
64+only, sat is forced RS_ENABLE (static_assert). Probed (🟢, errors=0/884): R=nearest-even, A=nearest-ties-away,
65+F/C/Z floor/ceil/trunc; saturation INT_MIN/MAX, u-types 0/MAX; NaN→0; ±Inf→sat bounds. `__cvt_float(int)`
66+RNE default; u64/s64 reachable on f32 grid; f32→f32 quantizes per mode, NaN→0x7FFFFFFF, −0→+0.
67+Default fp→int = `ROUND::Z` (matches C); `<>` empty template OK.
68+ 
69+## 2 · USE — paste, build, run, verify
70+```cpp
71+// Ascend 950PR SIMT fp<->int cast: z[i] = __cvt_int32_t<ROUND::R>(x[i]) (sat forced) and
72+// f[i] = __cvt_float<ROUND::R>(z[i]) roundtrip. T=64 boundary inputs, bit-exact host compare.
73+// Build:
74+// source /usr/local/Ascend/ascend-toolkit/set_env.sh
75+// bisheng --asc-aicore-lang --npu-arch=dav-3510 k.cpp -o k \
76+// -I$ASCEND_HOME_PATH/aarch64-linux/include -L$ASCEND_HOME_PATH/lib64 \
77+// -Wl,-rpath,$ASCEND_HOME_PATH/lib64 -lascendcl -lruntime
78+// Run: cannsim record ./k -s Ascend950 -g Pass: RESULT: errors=0/128
79+#include "kernel_operator.h"
80+#include "simt_api/asc_simt.h"
81+using namespace AscendC;
82+constexpr uint32_t T = 64;
83+ 
84+__simt_vf__ LAUNCH_BOUND(T) inline void Body(__gm__ float *x, __gm__ int32_t *z, __gm__ float *f) {
85+ uint32_t i = Simt::GetThreadIdx<0>();
86+ int32_t v = __cvt_int32_t<ROUND::R>(x[i]); // ◀ MUTATE mode: ROUND::A/F/C/Z (sat always ON)
87+ z[i] = v;
88+ f[i] = __cvt_float<ROUND::R>(v); // int -> f32, nearest-even
89+}
90+extern "C" __global__ __aicore__ void k(GM_ADDR x, GM_ADDR z, GM_ADDR f) {
91+ KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY);
92+ Simt::VF_CALL<Body>(Simt::Dim3{T, 1, 1}, (__gm__ float *)x, (__gm__ int32_t *)z, (__gm__ float *)f);
93+}
94+ 
95+#ifndef __CCE_AICORE__
96+#include "acl/acl.h"
97+#include <cstdio>
98+#include <cstdlib>
99+#include <cstring>
100+#include <cmath>
101+#include <cstdint>
102+#define CK(e) do{aclError _r=(e); if(_r!=ACL_SUCCESS){std::printf("ACL FAIL %s %d\n",#e,(int)_r);std::fflush(stdout);return 1;}}while(0)
103+static int32_t ref_s32(float s) { // R = nearest-even; sat; NaN->0 (probed contract)
104+ if (std::isnan(s)) return 0;
105+ double r = std::nearbyint((double)s); // host FE_TONEAREST = RNE
106+ if (r >= 2147483647.0) return INT32_MAX;
107+ if (r <= -2147483648.0) return INT32_MIN;
108+ return (int32_t)r;
109+}
110+int main() {
111+ CK(aclInit(nullptr)); CK(aclrtSetDevice(0));
112+ aclrtStream s = nullptr; CK(aclrtCreateStream(&s));
113+ float hx[T]; int32_t hz[T]; float hf[T];
114+ const float edge[12] = {0.5f, -0.5f, 1.5f, 2.5f, -2.5f, 2147483520.0f, 2147483648.0f,
115+ -2147483648.0f, -2147483904.0f, NAN, INFINITY, -INFINITY};
116+ for (uint32_t i = 0; i < T; ++i) hx[i] = i < 12 ? edge[i] : 100.625f - 3.875f * (float)i;
117+ void *dx, *dz, *df;
118+ CK(aclrtMalloc(&dx, T*4, ACL_MEM_MALLOC_HUGE_FIRST)); CK(aclrtMalloc(&dz, T*4, ACL_MEM_MALLOC_HUGE_FIRST));
119+ CK(aclrtMalloc(&df, T*4, ACL_MEM_MALLOC_HUGE_FIRST));
120+ CK(aclrtMemcpy(dx, T*4, hx, T*4, ACL_MEMCPY_HOST_TO_DEVICE));
121+ k<<<1, nullptr, s>>>((GM_ADDR)dx, (GM_ADDR)dz, (GM_ADDR)df);
122+ CK(aclrtSynchronizeStream(s));
123+ CK(aclrtMemcpy(hz, T*4, dz, T*4, ACL_MEMCPY_DEVICE_TO_HOST));
124+ CK(aclrtMemcpy(hf, T*4, df, T*4, ACL_MEMCPY_DEVICE_TO_HOST));
125+ uint32_t e = 0;
126+ for (uint32_t i = 0; i < T; ++i) {
127+ int32_t rz = ref_s32(hx[i]); // ◀ MUTATE with device mode
128+ float rf = (float)rz; // s32->f32 RNE == host cast
129+ uint32_t a, b; std::memcpy(&a, &hf[i], 4); std::memcpy(&b, &rf, 4);
130+ if (hz[i] != rz && e++ < 8) std::printf("s32[%u] x=%g dev=%d ref=%d\n", i, hx[i], hz[i], rz);
131+ if (a != b && e++ < 8) std::printf("f[%u] dev=%.9g ref=%.9g\n", i, hf[i], rf);
132+ }
133+ std::printf("RESULT: errors=%u/%u\n", e, 2 * T); std::fflush(stdout);
134+ aclrtFree(dx); aclrtFree(dz); aclrtFree(df);
135+ aclrtDestroyStream(s); aclrtResetDevice(0); aclFinalize(); return e ? 2 : 0;
136+}
137+#endif
138+```
139+Pass = `errors=0/128` AND `sendStarsSQE ≥ 1` (one-shot evidence: `use_selftest/cannsim_20260610170059_kcast/`).
140+Mutating mode: device template AND `ref_s32` rounder together (A→`std::round`, F→`floor`, C→`ceil`, Z→`trunc`) — F2I leg ONLY; the I2F roundtrip leg (`__cvt_float`) and its host reference stay nearest-even (`ROUND::R`) unmutated.
141+ 
142+## 3 · HAZARDS — silent (compiles fine, results wrong)
143+| Hazard | Symptom | Repair | Evidence |
144+|---|---|---|---|
145+| expecting C/CUDA wrap on overflow | INT_MIN/MAX instead of wrapped bits | sat is forced; design ranges for clamp | 🟢 kca 884-pt |
146+| NaN→int assumed UB/garbage | always 0 | rely on 0 only if intentional | 🟢 kca |
147+| ROUND::A read as away-from-zero | off-tie values mismatch | A = nearest, ties away (std::round) | 🟢 kca u2f probes |
148+| `__cvt_uint32_t` typed `int` | sign confusion at >2^31 | cast result to `uint32_t` | 🧾H :646; 🟢 kca |
149+| f2f NaN payload | dev=0x7FFFFFFF ≠ host NaN | canonical-bits compare | 🟢 kca |
150+| f2f −0 result | flushed to +0 | normalize zeros in host ref | 🟢 kca |
151+| SIMD-cast false friend | inventing vcvt ops here | per-thread `__cvt_*` only; vcvt is SIMD | 🧾 simd headers |
152+ 
153+## 4 · PERF — measured 🟢T1-sim (sim figures, never hardware rates)
154+Whole-prog launch-bound 419 cy at selftest N (K=1.0). Body (P-22 stamps, n tracks UNR 16/32/64,
155+spacing UNR-invariant): dependent f32→s32→f32+FADD roundtrip = **11 cy/iter** (FADD=3 ⇒ F2I+I2F≈8,
156+~4 each 🧠IN); F2F+FFMA chain = **9 cy/iter** (FFMA=7 ⇒ F2F≈2–4 🧠IN). Every cast = 1 op; all
157+R/A/F/C/Z + s/u + 32/64 share the op — mode choice never costs. Profile: F2I==I2F==1/elem.
158+❓UN: isolated F2I/I2F latency · ILP II · data-dominant N.
159+ 
160+## 5 · EVIDENCE & EDGES
161+- Census + semantics + cadence: `probes/simt_castarith/RESULTS.md`; correctness `cannsim_20260610164643_kca/` (errors=0/884: 5 dirs × 5 modes, boundaries, NaN/Inf, ties; bit-exact §2.6(a)).
162+- Headers: templates `__clang_cce_simt_dav3510_intrinsic.h:643/664/688`; ROUND `__clang_dpp_types.h:220`.
163+- ❓UN: isolated F2I latency (close: F2I+IADD-mix chain) · A-mode in u64 corner above 2^63 step (sparse).
164+- Siblings: `simt.arith.bit` · `simt.elementwise.binary` · SIMD vcvt (bulk, planned).
@@ -0,0 +1,244 @@
1+# `simt.elementwise.binary` — per-thread elementwise binary op on the AIV (SIMT path)
2+ 
3+## HEAD
4+ 
5+```yaml
6+head_schema: pb5/v1
7+op: simt.elementwise.binary # canonical instance: z[i] = x[i] + y[i], f32, N=1024
8+paradigm: SIMT
9+core: AIV
10+lowering: "__simt_vf__ body dispatched by AscendC::Simt::VF_CALL (KERNEL_TYPE_AIV_ONLY)"
11+dtypes: [f32] # ONLY f32 is verified; other dtypes are header-declared, verify before claiming
12+selection_keys:
13+ - access.gather-scatter
14+ - control.divergent-per-element
15+ - xlate.cuda-1to1
16+not_for:
17+ - access.contiguous-elementwise # → sibling simd.elementwise.binary: SIMD is primary on 950PR
18+cuda_pta_analog: "CUDA grid-stride elementwise kernel (threadIdx/blockIdx/blockDim)"
19+false_friends: [launch_api_is_chevrons_not_aclrtLaunchKernel, host_code_needs_CCE_AICORE_guard,
20+ warp32_is_not_simd_register64, ub_is_not_shared_cache, no_fp4_mx_casts_on_simt]
21+cost_model:
22+ roofline_run_id: probes/rooflines/simt_elementwise/ # full sweep: 14 grid points × 3 reps
23+ binding_resource: UN # measured: NO tunable resource binds at N=1024 (cycles flat 419-420
24+ # across all knobs); launch_overhead = PROPOSED PB-5 key, 🧠IN cause
25+ optimum: {value: 0.409, unit: cycles/elem} # 419 cycles total @ N=1024 f32
26+ perf_factor_K: 1.0 # naive(b8,T256)=419 = best
27+ latency_cycles: # per emitted SIMT-ISA op (P-22 dependent-chain cadence, stamp cy; sim figures)
28+ SIMT_FADD: 3
29+ SIMT_IMAD_I: 7
30+ SIMT_LDG_dep: "~57/iter issue, lsu RTT ~173 (RANGE)"
31+ SIMT_STG_dep: "~255 lsu RTT (RANGE)"
32+ elem_per_cycle: 0.78 # 1024 / 1315 measured body lsu span (probes/simt_isa_cost/ew_profile; sim figure)
33+ toolchain:
34+ bisheng: "clang version 15.0.5 (clang-5c68a1cb1231 flang-5c68a1cb1231) 2026-05-09"
35+ model: "{model_name: Ascend950PR_9599, cube_cores: 32, vec_cores: 64}"
36+ configs: [1981_sim_ffts_plus.toml, 1981_model.toml] # logical aliases -> physical 1982_cloud_config.toml (probes/arch_extract/)
37+verify_cmd: |
38+ bash ${PROBE_WORKSPACE}/scripts/build.sh k.cpp
39+ bash ${PROBE_WORKSPACE}/scripts/run.sh k
40+ bash ${PROBE_WORKSPACE}/scripts/verify.sh
41+ bash ${PROBE_WORKSPACE}/scripts/profile_simt.sh k # body mix + cadence; expect LDG:STG=2:1, FADD/elem
42+sources:
43+ - probes/cannsim_20260602091800_entry_use_selftest/ # THIS entry's §USE, as-pasted: errors=0, 419 cycles
44+ - probes/simt_isa_cost/RESULTS.md # P-22 per-op cadences (v2 conformance 2026-06-10)
45+ - probes/cannsim_20260602083312_p09_test/ # add kernel, errors=0
46+ - book_samples/ct_A/cannsim_20260602025956_k/ # sibling mutate (mul), errors=0
47+ - probes/rooflines/simt_elementwise/ # roofline sweep (SWEEP.md: 14 points x 3 reps)
48+ - "__clang_cce_simt_dav3510_intrinsic.h:472" # const int warpSize = 32
49+ - "tikcpp/tikcfw/impl/utils/kernel_utils_constants.h:172" # VECTOR_REG_WIDTH = 256
50+status: piloted
51+tier_summary:
52+ - {claim: build+run+bit-exact f32, tier: T1-sim}
53+ - {claim: VF_CALL programming model, tier: T1-sim}
54+ - {claim: warpSize=32, tier: H}
55+ - {claim: SIMD vector reg = 256 B, tier: H}
56+ - {claim: no __shared__ in simt_api, tier: H}
57+ - {claim: SIMT auxiliary vs SIMD primary, tier: IN}
58+ - {claim: K=1.0 and config-invariance 419±1 cycles at N=1024, tier: T1-sim}
59+ - {claim: invariance caused by launch overhead + memory latency, tier: IN}
60+```
61+ 
62+## 0 · SELECT
63+ 
64+You likely arrived from CUDA elementwise code. Route first:
65+ 
66+```
67+contiguous regular access, no per-element branch → simd.elementwise.binary (sibling — SIMD is primary)
68+gather/scatter, divergent branch, 1:1 CUDA port → stay here (SIMT)
69+```
70+ 
71+**Intercept these CUDA priors** (each verified on 950PR — see EVIDENCE):
72+ 
73+| Your CUDA prior | 950PR fact | Tier |
74+|---|---|---|
75+| Launch with a runtime call (`cudaLaunchKernel`/`aclrtLaunchKernel`) | **No host launch API. The ONLY verified launch is `k<<<blockDim, l2ctrl, stream>>>(…)`** | 🟢T1-sim |
76+| Host code compiles standalone | This file compiles **twice** (host + device pass). **Guard ALL host-only code with `#ifndef __CCE_AICORE__`** | 🟢T1-sim |
77+| warp = vector register width | warp = 32 **threads**; the SIMD datapath register is 256 B = 64 f32 lanes — different machine | 🧾H |
78+| `__shared__` exists | absent from `simt_api/**` headers; the on-core buffer is UB, not an implicit cache | 🧾H |
79+| any dtype cast inside a thread | f32↔fp8/hif8 paths exist on SIMT; bf16→fp4/e8m0/e6m2 are **not** on the SIMT scalar path | 🥈T2 |
80+ 
81+## 1 · CONTRACT
82+ 
83+| Claim | Tier · source |
84+|---|---|
85+| `extern "C" __global__ __aicore__ void k(GM_ADDR …)` + `KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY)` pins the kernel to the AIV (vector) core | 🟢T1-sim · `probes/cannsim_20260602083312_p09_test/` |
86+| Per-thread body: `__simt_vf__ LAUNCH_BOUND(T) inline void Body(__gm__ float*, …, uint32_t)` dispatched with `Simt::VF_CALL<Body>(Simt::Dim3{T,1,1}, args…)` | 🟢T1-sim · same run |
87+| Indices: `Simt::GetThreadIdx<0>()`, `GetBlockIdx()`, `GetThreadNum<0>()`, `GetBlockNum()`; grid-stride loop covers any N | 🟢T1-sim · same run |
88+| Host launch: `k<<<blockDim, nullptr, stream>>>(dx, dy, dz, N)` — blockDim = number of blocks | 🟢T1-sim · same run |
89+| Operands `__gm__ T*` (global memory) | 🟢T1-sim |
90+| f32 add/mul are IEEE-exact per element ⇒ device == host bitwise | 🟢T1-sim · `RESULT: errors=0` |
91+| warp width = 32 | 🧾H · `__clang_cce_simt_dav3510_intrinsic.h:472` |
92+| dtypes beyond f32 declared in headers — NOT yet verified | ❓UN · run §2 with that dtype |
93+ 
94+## 2 · USE — paste, build, run, verify
95+ 
96+One complete file (`k.cpp`). Device kernel + full host harness. Mutate ONE marked line for sibling ops.
97+ 
98+```cpp
99+// Ascend 950PR SIMT elementwise binary: z[i] = x[i] OP y[i], f32, N=1024.
100+// Build:
101+// source /usr/local/Ascend/ascend-toolkit/set_env.sh
102+// bisheng --asc-aicore-lang --npu-arch=dav-3510 k.cpp -o k \
103+// -I$ASCEND_HOME_PATH/aarch64-linux/include -L$ASCEND_HOME_PATH/lib64 \
104+// -Wl,-rpath,$ASCEND_HOME_PATH/lib64 -lascendcl -lruntime
105+// Run:
106+// cannsim record ./k -s Ascend950 -g
107+// Pass: prints "RESULT: errors=0/1024"
108+ 
109+// ---------------- device ----------------
110+#include "kernel_operator.h"
111+#include "simt_api/asc_simt.h"
112+using namespace AscendC;
113+ 
114+constexpr uint32_t T = 256; // threads per block
115+ 
116+__simt_vf__ LAUNCH_BOUND(T) inline void Body(__gm__ float *x, __gm__ float *y,
117+ __gm__ float *z, uint32_t n) {
118+ uint32_t stride = Simt::GetBlockNum() * Simt::GetThreadNum<0>();
119+ for (uint32_t i = Simt::GetThreadIdx<0>() + Simt::GetBlockIdx() * Simt::GetThreadNum<0>();
120+ i < n; i += stride)
121+ z[i] = x[i] + y[i]; // ◀── MUTATE for sibling op; mirror in href below
122+}
123+ 
124+extern "C" __global__ __aicore__ void k(GM_ADDR x, GM_ADDR y, GM_ADDR z, uint32_t n) {
125+ KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY);
126+ Simt::VF_CALL<Body>(Simt::Dim3{T, 1, 1},
127+ (__gm__ float *)x, (__gm__ float *)y, (__gm__ float *)z, n);
128+}
129+ 
130+// ---------------- host (host-only pass: keep the guard) ----------------
131+#ifndef __CCE_AICORE__
132+#include "acl/acl.h"
133+#include <cstdio>
134+#include <cstdlib>
135+ 
136+extern "C" __global__ __aicore__ void k(GM_ADDR x, GM_ADDR y, GM_ADDR z, uint32_t n);
137+ 
138+#define CHECK(expr) do { aclError _e = (expr); \
139+ if (_e != ACL_SUCCESS) { std::printf("ACL FAIL %s -> %d\n", #expr, (int)_e); return 1; } } while (0)
140+ 
141+int main() {
142+ constexpr uint32_t N = 1024;
143+ const size_t bytes = N * sizeof(float);
144+ const uint32_t blockDim = 8;
145+ 
146+ CHECK(aclInit(nullptr));
147+ CHECK(aclrtSetDevice(0));
148+ aclrtStream stream = nullptr;
149+ CHECK(aclrtCreateStream(&stream));
150+ 
151+ float *hx = (float *)std::malloc(bytes), *hy = (float *)std::malloc(bytes);
152+ float *hz = (float *)std::malloc(bytes), *href = (float *)std::malloc(bytes);
153+ for (uint32_t i = 0; i < N; ++i) {
154+ hx[i] = 0.5f * (float)i - 13.0f; // non-trivial values:
155+ hy[i] = 1.25f * (float)(i % 17) + 0.375f; // a broken kernel cannot pass
156+ href[i] = hx[i] + hy[i]; // ◀── MUTATE together with device op
157+ }
158+ 
159+ void *dx = nullptr, *dy = nullptr, *dz = nullptr;
160+ CHECK(aclrtMalloc(&dx, bytes, ACL_MEM_MALLOC_HUGE_FIRST));
161+ CHECK(aclrtMalloc(&dy, bytes, ACL_MEM_MALLOC_HUGE_FIRST));
162+ CHECK(aclrtMalloc(&dz, bytes, ACL_MEM_MALLOC_HUGE_FIRST));
163+ CHECK(aclrtMemcpy(dx, bytes, hx, bytes, ACL_MEMCPY_HOST_TO_DEVICE));
164+ CHECK(aclrtMemcpy(dy, bytes, hy, bytes, ACL_MEMCPY_HOST_TO_DEVICE));
165+ 
166+ k<<<blockDim, nullptr, stream>>>((GM_ADDR)dx, (GM_ADDR)dy, (GM_ADDR)dz, N);
167+ 
168+ CHECK(aclrtSynchronizeStream(stream));
169+ CHECK(aclrtMemcpy(hz, bytes, dz, bytes, ACL_MEMCPY_DEVICE_TO_HOST));
170+ 
171+ uint32_t errors = 0; // bit-exact compare (§2.6 mode (a))
172+ for (uint32_t i = 0; i < N; ++i) {
173+ uint32_t a, b;
174+ __builtin_memcpy(&a, &hz[i], 4);
175+ __builtin_memcpy(&b, &href[i], 4);
176+ if (a != b && errors++ < 8)
177+ std::printf(" mismatch[%u]: dev=%.9g ref=%.9g\n", i, hz[i], href[i]);
178+ }
179+ std::printf("RESULT: errors=%u/%u\n", errors, N);
180+ 
181+ aclrtFree(dx); aclrtFree(dy); aclrtFree(dz);
182+ std::free(hx); std::free(hy); std::free(hz); std::free(href);
183+ aclrtDestroyStream(stream);
184+ aclrtResetDevice(0);
185+ aclFinalize();
186+ return errors == 0 ? 0 : 2;
187+}
188+#endif // __CCE_AICORE__
189+```
190+ 
191+**Verify ladder** — run the three `verify_cmd` lines in order; `verify.sh` prints `result=` / `sendStarsSQE=` / `cycle:` then a `VERIFY_PASS` or `VERIFY_FAIL` verdict. Pass = `errors=0/1024` **and** `sendStarsSQE ≥ 1` — `errors=0` with no `sendStarsSQE` means the kernel never launched (host-only no-op false pass). Manual extraction (never dump full logs): `grep -h "RESULT: errors" <run_dir>/cannsim.log`.
192+ 
193+**Build/run repair table:**
194+ 
195+| Symptom | Cause | Fix |
196+|---|---|---|
197+| `no aicore arch specified` | missing arch flag | add `--npu-arch=dav-3510` |
198+| undeclared `aclrtMalloc` … | missing host include | `#include "acl/acl.h"` in host section |
199+| `aclrtLaunchKernel` undeclared | invented launch API | host launches with `k<<<blocks, l2ctrl, stream>>>(…)` |
200+| device-pass errors in host code | missing TU guard | wrap host section in `#ifndef __CCE_AICORE__` |
201+| link error `acl*` / `runtime` | missing libs | `-lascendcl -lruntime` + `-Wl,-rpath,$ASCEND_HOME_PATH/lib64` |
202+| `errors=N>0` | device/host op differ | mutate BOTH marked lines (device op + `href`) identically |
203+ 
204+## 3 · HAZARDS — silent (compiles fine, results wrong)
205+ 
206+| Hazard | Symptom | Repair | Evidence |
207+|---|---|---|---|
208+| missing `i < n` guard in grid-stride | OOB writes corrupt neighbors | always `i < n; i += stride` | 🟢 entry's verify ladder |
209+| D2H before `aclrtSynchronizeStream` | stale output buffer | sync, then `aclrtMemcpy` | 🟢 harness order |
210+| host/device op mismatch | persistent `errors>0` | mutate both marked lines | 🟢 run evidence |
211+| fp8/hif8/fp4 conversions on SIMT path | fp4 not reachable: compile error; fp8 = silent range loss | conversions live in SIMD vcvt | 🥈 `probes/simd_fp4_probe.cpp` |
212+| HiF8 ROUND::H upward bias | round-trip drift ≈ +½ ULP | use bit-exact harness | 🟢 `probes/cannsim_20260602015237_fp_layout_probe/` |
213+| trusting sim self-check | none exists | host reference compare only | 🧠 toolchain census |
214+ 
215+## 4 · PERF — measured cost model (🟢T1-sim)
216+ 
217+**Roofline** (`probes/rooflines/simt_elementwise/SWEEP.md` — 14 grid points × 3 reps, all errors=0):
218+- **419 cycles total at N=1024 f32 — flat (±1 cycle) across blocks 1→64, T 64→1024, divergent branch, strided permutation.** Optimum = naive = **0.409 cycles/elem** ⇒ **K = 1.0**. 🟢T1-sim.
219+- Binding resource: **none of the tunables binds at this shape** (`UN` in HEAD). The flatness itself is measured; its cause — fixed launch + memory-path latency — is 🧠IN (no analyzer cycle-breakdown decoded yet). Same plateau for SIMD vadd (419–420) ⇒ SIMD-vs-SIMT **not resolvable** at N=1024.
220+ 
221+**Body cost (v2 conformance 2026-06-10, 🟢T1-sim, sim figures — never hardware rates):** the per-thread
222+body is invisible to cannsim's trace but measured on msprof-sim reg_log/lsu (P-22). Per element: 2×LDG
223+(dep ~57/iter issue, RTT ~173) + 1 FADD (3) + 1 STG (~255 RTT) — GM round-trips dominate; compute is ~2%.
224+Measured §USE body: LDG=2N/threads, STG=N/threads per warp (lsu 64:32 = 2:1), span 1315 cy ⇒ ~0.78 elem/cy.
225+Closed loop: `profile_simt.sh ./k` must show LDG:STG = 2:1 and FADD count = elems/lane.
226+ 
227+What this means for you:
228+```
229+1. N ≲ 10^3 elementwise → launch overhead dominates. Don't tune; eliminate launches (fuse kernels).
230+2. The body is GM-latency-bound (LDG/STG RTT ≫ FADD 3) — coalesce + enough warps to overlap RTT;
231+ occupancy toward ≤64 warps/core; divergence costs nothing here (uniform body); SIMD sibling for contiguous.
232+3. After mutating: run verify_cmd (incl. profile line); LDG:STG ratio off ⇒ wrong loads/stores per element.
233+```
234+❓UN: knob effects at data-dominant N (≥1 M) — SWEEP.md closing experiment.
235+ 
236+## 5 · EVIDENCE & EDGES
237+ 
238+- Build+run+verify (f32 add): `probes/cannsim_20260602083312_p09_test/`. Sibling mutate (mul): `book_samples/ct_A/cannsim_20260602025956_k/`. Toolchain pin: HEAD `cost_model.toolchain`.
239+- Headers: warp 32 — `__clang_cce_simt_dav3510_intrinsic.h:472`; vector reg 256 B — `kernel_utils_constants.h:172`; `__shared__` absent in `simt_api/**` (0 matches).
240+- 🧠IN "SIMT auxiliary": datapath sizes f32 — SIMD 64 lanes vs warp 32. The N=1024 cycle compare (`probes/rooflines/{simd_vadd,simt_elementwise}/`) did NOT resolve it (both 419–420, overhead-bound); stays 🧠IN until a data-dominant-N compare.
241+- 🟢T1-sim: cost model — roofline `probes/rooflines/simt_elementwise/` (K=1.0, overhead-bound at N=1024).
242+- Body costs (v2): `probes/simt_isa_cost/RESULTS.md` (P-22 cadences) + `ew_profile` run (LDG 64 : STG 32, span 1315 cy).
243+- ❓UN: knob effects at N ≥ 1M (re-sweep) · dtypes beyond f32 (T-ref per dtype).
244+- Siblings: `simd.elementwise.binary` (the SIMD-primary contiguous path) · `simt.reduce.warp-sum` (warp combine) · `simt.ldst.global` / `simt.atomic.rmw` (planned, census P1).
@@ -0,0 +1,125 @@
1+# `simt.ldst.global` — per-thread global loads/stores (`__ldg`/`__stg`, B8–B128, L2 hints)
2+ 
3+## HEAD
4+ 
5+```yaml
6+head_schema: pb5/v1
7+op: simt.ldst.global # canonical instance: z[i] = x[i] + 1 via __ldg/__stg, int32, N=4096
8+paradigm: SIMT
9+core: AIV
10+lowering: "__ldg(__gm__ T*) / __stg(__gm__ T*, T) -> SIMT_LDG / SIMT_STG per element (B8..B64 one op, B128 two); L2-hint + cache/uncache templates lower to ld/st_{cache,uncache}_b{8,16,32} builtins"
11+dtypes: [s8, u8, s16, s32, s64, b128] # all five widths VERIFIED errors=0; other same-width dtypes share the lowering
12+selection_keys:
13+ - access.gather-scatter
14+ - xlate.cuda-1to1
15+not_for:
16+ - move.bulk-copy # → DMA (MOV_*_ALIGN) is the bulk path; per-thread ldst is for irregular access
17+ - access.contiguous-elementwise # → simd.elementwise.binary
18+cuda_pta_analog: "CUDA __ldg / plain global deref + __stcg-style cache hints"
19+false_friends: [ldg_is_not_required_plain_deref_also_lowers, b128_is_two_ops_not_one,
20+ hints_change_cache_policy_not_count, ub_is_not_shared_cache]
21+cost_model:
22+ roofline_run_id: probes/simt_ldst/RESULTS.md # count law + spans (data-dominant sweep is the standing UN)
23+ binding_resource: UN # GM round-trip latency at probed N (overhead-bound whole-prog); body GM-bound
24+ optimum: {value: 0.102, unit: cycles/elem} # whole-prog 419 cy @ N=4096 (launch-bound)
25+ perf_factor_K: 1.0 # overhead-bound shape (R-15)
26+ latency_cycles:
27+ SIMT_LDG_dep: "~57/iter issue, lsu RTT ~173 (RANGE)"
28+ SIMT_STG_dep: "~255 lsu RTT (RANGE)"
29+ elem_per_cycle: "count law: 1 op/elem B8-B64, 2 ops/elem B128; spans cold-flat (RANGE)"
30+ toolchain:
31+ bisheng: "clang version 15.0.5 (clang-5c68a1cb1231 flang-5c68a1cb1231) 2026-05-09"
32+ model: "{model_name: Ascend950PR_9599, cube_cores: 32, vec_cores: 64}"
33+ configs: [1981_sim_ffts_plus.toml, 1981_model.toml]
34+verify_cmd: |
35+ bash ${PROBE_WORKSPACE}/scripts/build.sh k.cpp
36+ bash ${PROBE_WORKSPACE}/scripts/run.sh k
37+ bash ${PROBE_WORKSPACE}/scripts/verify.sh
38+ bash ${PROBE_WORKSPACE}/scripts/profile_simt.sh k # expect LDG==STG==N/lanes (B128: 2N)
39+sources:
40+ - probes/simt_ldst/RESULTS.md # count law + 5-width errors=0 + spans
41+ - probes/simt_isa_cost/RESULTS.md # P-22 dependent LDG/STG figures
42+ - "__clang_cce_simt_dav3510_intrinsic.h:24" # LD_L2CacheType hints FV/LV/PERS/PREF/NOTALLOC_*
43+ - "__clang_cce_simt_dav3510_intrinsic.h:206" # __ldg typed overloads (B8 shown; B16..B128 follow)
44+status: piloted
45+tier_summary:
46+ - {claim: 5 widths build+run errors=0, tier: T1-sim}
47+ - {claim: 1 LDG + 1 STG per element B8..B64; B128 = 2 ops each, tier: T1-sim}
48+ - {claim: hint enum changes cache policy not instruction count, tier: H}
49+ - {claim: dependent LDG ~57/iter issue + RTT ~173; STG ~255, tier: T1-sim}
50+ - {claim: hint perf effect at data-dominant N, tier: UN}
51+```
52+ 
53+## 0 · SELECT
54+Bulk regular copy → DMA. Contiguous elementwise → SIMD. Per-thread irregular access inside a SIMT
55+kernel → here. Intercepts: plain `x[i]` deref also lowers to SIMT_LDG (🟢 ew profile) — `__ldg` adds
56+hint control, not access; B128 (`int4`) is 2 ops/element; UB never acts as implicit `__shared__`.
57+ 
58+## 1 · CONTRACT
59+`T __ldg(__gm__ T*)` / `void __stg(__gm__ T*, T)` per thread; widths B8–B128 (🧾H :206+). Hint
60+templates `LD_L2CacheType` (FV default; :24-31). Bit-exact roundtrip across 5 widths (🟢 RESULTS).
61+B128 = `int4`, lowers 2× ops (🟢 lsu count). Loads return after RTT — overlap by warps (🟢 P-22).
62+ 
63+## 2 · USE — paste, build, run, verify
64+```cpp
65+// z[i] = x[i] + 1, int32, N=4096 via __ldg/__stg. Build/run/verify: HEAD verify_cmd.
66+#include "kernel_operator.h"
67+#include "simt_api/asc_simt.h"
68+using namespace AscendC;
69+constexpr uint32_t T = 256;
70+__simt_vf__ LAUNCH_BOUND(T) inline void Body(__gm__ int32_t *x, __gm__ int32_t *z, uint32_t n) {
71+ uint32_t tid = Simt::GetThreadIdx<0>() + Simt::GetBlockIdx() * Simt::GetThreadNum<0>();
72+ uint32_t stride = Simt::GetBlockNum() * Simt::GetThreadNum<0>();
73+ for (uint32_t i = tid; i < n; i += stride) {
74+ int32_t v = __ldg(&x[i]); // ◀ MUTATE width: int8_t/int16_t/int64_t/int4
75+ __stg(&z[i], v + 1);
76+ }
77+}
78+extern "C" __global__ __aicore__ void k(GM_ADDR x, GM_ADDR z, uint32_t n) {
79+ KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY);
80+ Simt::VF_CALL<Body>(Simt::Dim3{T, 1, 1}, (__gm__ int32_t *)x, (__gm__ int32_t *)z, n);
81+}
82+#ifndef __CCE_AICORE__
83+#include "acl/acl.h"
84+#include <cstdio>
85+#include <cstdlib>
86+#include <cstring>
87+#define CHECK(expr) do { aclError _e = (expr); \
88+ if (_e != ACL_SUCCESS) { std::printf("ACL FAIL %s -> %d\n", #expr, (int)_e); return 1; } } while (0)
89+int main() {
90+ constexpr uint32_t N = 4096; const size_t b = N * sizeof(int32_t);
91+ CHECK(aclInit(nullptr)); CHECK(aclrtSetDevice(0));
92+ aclrtStream stream = nullptr; CHECK(aclrtCreateStream(&stream));
93+ int32_t *hx = (int32_t *)std::malloc(b), *hz = (int32_t *)std::malloc(b);
94+ for (uint32_t i = 0; i < N; ++i) hx[i] = (int32_t)i - 2048;
95+ void *dx, *dz; CHECK(aclrtMalloc(&dx, b, ACL_MEM_MALLOC_HUGE_FIRST)); CHECK(aclrtMalloc(&dz, b, ACL_MEM_MALLOC_HUGE_FIRST));
96+ CHECK(aclrtMemcpy(dx, b, hx, b, ACL_MEMCPY_HOST_TO_DEVICE));
97+ k<<<8, nullptr, stream>>>((GM_ADDR)dx, (GM_ADDR)dz, N);
98+ CHECK(aclrtSynchronizeStream(stream)); CHECK(aclrtMemcpy(hz, b, dz, b, ACL_MEMCPY_DEVICE_TO_HOST));
99+ uint32_t errors = 0; for (uint32_t i = 0; i < N; ++i) errors += (hz[i] != hx[i] + 1);
100+ std::printf("RESULT: errors=%u/%u\n", errors, N);
101+ aclrtFree(dx); aclrtFree(dz); std::free(hx); std::free(hz);
102+ aclrtDestroyStream(stream); aclrtResetDevice(0); aclFinalize(); return errors ? 2 : 0;
103+}
104+#endif
105+```
106+Pass = `errors=0` AND `sendStarsSQE ≥ 1`; profile must show LDG==STG==N per grid pass (2N for B128).
107+ 
108+## 3 · HAZARDS
109+| Hazard | Symptom | Repair | Evidence |
110+|---|---|---|---|
111+| B128 treated as 1 op in cost math | budget 2× off | count 2 LDG + 2 STG per int4 | 🟢 lsu 256 vs 128 |
112+| width-mismatch reinterpret | silent wrong bytes | match host/device dtype + size | 🟢 errors=0 only matched |
113+| hint expected to change result | none (policy only) | hints affect cache, never data/count | 🧾H :24-31 |
114+| dependent loads (ptr-chase) | RTT-serial ~57/iter | use independent grid-stride; warps overlap | 🟢 P-22 |
115+ 
116+## 4 · PERF
117+Whole-prog 419 cy at probed N (launch-bound; K=1.0, R-15). Body is GM-RTT-bound: LDG dep ~57/iter
118+issue (RTT ~173), STG ~255 RTT; spans flat across widths ⇒ **wider accesses amortize per byte; B128
119+halves instructions per byte despite 2 ops/elem**. Closed loop: profile counts = N law. ❓UN: hint
120+effects + per-width slope at ≥1M.
121+ 
122+## 5 · EVIDENCE & EDGES
123+- 5-width errors=0 + count law + spans: `probes/simt_ldst/RESULTS.md` (rig `simt_ldst.cpp`); ew 2:1 corroboration.
124+- ❓UN: hint perf at data-dominant N; non-FV hint behaviors.
125+- Siblings: `simt.elementwise.binary` · `simt.atomic.rmw` (planned) · DMA (bulk).