| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
常量折叠和infershape整改 Co-authored-by: liu-lu<www.liulu824910939@qq.com> # message auto-generated for no-merge-commit merge: !4582 merge master into master 常量折叠和infershape整改 Created-by: liu-lu Commit-by: liu-lu Merged-by: cann-robot Description: ## 描述 本 PR 为 6 个 AICPU 算子(add、round、search_sorted、select_v2、square、squared_difference)使能 GE 图编译期常量折叠,并对 search_sorted、select_v2 进行 infershape/OpDef 整改。 ### 变更内容 **1. 常量折叠使能(6 算子)** | 算子 | CMakeLists | kernel 注册 | |------|-----------|-------------| | add | 增加 HOSTCPU TRUE | REGISTER_CPU_KERNEL → OPS_MATH_REGISTER_CPU_KERNELV2 | | round | 增加 HOSTCPU TRUE | REGISTER_CPU_KERNEL → OPS_MATH_REGISTER_CPU_KERNELV2 | | search_sorted | 增加 HOSTCPU TRUE | REGISTER_CPU_KERNEL → OPS_MATH_REGISTER_CPU_KERNELV2 | | select_v2 | 增加 HOSTCPU TRUE | REGISTER_CPU_KERNEL → OPS_MATH_REGISTER_CPU_KERNELV2 | | square | 增加 HOSTCPU TRUE | REGISTER_CPU_KERNEL → OPS_MATH_REGISTER_CPU_KERNELV2 | | squared_difference | 增加 HOSTCPU TRUE | REGISTER_CPU_KERNEL → OPS_MATH_REGISTER_CPU_KERNELV2 | - 各 kernel 增加 #include "aicpu/math_aicpu_register.h"; - CMakeLists 增加 HOSTCPU TRUE,将算子编入 host 侧折叠 so(libopconstant_folding_math.so)。 **2. infershape / OpDef 整改** - **search_sorted**:新增 op_host/search_sorted_infershape.cpp,实现 InferShape4SearchSorted,输出 shape 取 values(input1)的 shape; - **select_v2**:新增 op_kernel_aicpu/select_v2_aicpu_def.cpp(基于 OpDef 注册输入输出数据类型),删除旧 select_v2.json(JSON 配置方式),统一为 OpDef 注册链路。 ## 关联的Issue #2847 ## 测试 根据代码变更,测试场景如下: 1. **编译构建测试** - 执行 cmake 配置与编译,验证 6 个算子 CMakeLists HOSTCPU TRUE 配置变更正确; - 确认 libopconstant_folding_math.so 中已编入上述 6 个算子的 host 侧 kernel。 2. **常量折叠验证** - 输入为常量时,验证算子可在图编译期被折叠求值(host 侧执行),运行期不再下发 device kernel; - 输入为非常量时,验证 device 侧执行逻辑与折叠前保持一致。 3. **InferShape 验证(search_sorted)** - 验证 search_sorted 输出 shape 与 values 输入 shape 一致; - 覆盖多维度、边界 shape 场景。 4. **算子注册/加载验证(select_v2)** - 验证 select_v2 基于 OpDef 注册后接口可正确加载与调用; - 覆盖全数据类型(COMPLEX128/COMPLEX64/DOUBLE/FLOAT/FLOAT16/INT16/INT32/INT64/INT8/UINT16/UINT32/UINT64/UINT8/BOOL)。 5. **算子泛化** - 对 6 个算子执行二级冒烟与泛化用例,确认功能正确性不受影响。 ## 文档更新 本 PR 不涉及 README/aclnn 接口文档更新。 ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [x] 新特性 - [x] 性能优化 - [ ] 文档更新 - [ ] 其他,请描述: See merge request: cann/ops-math!4582 | 25 天前 | |
optimize the performance of aicpu add operator Co-authored-by: ZhaiPeiChao<zhaipeichao@huawei.com> # message auto-generated for no-merge-commit merge: !2462 merge add into master optimize the performance of aicpu add operator Created-by: ZhaiPeiChao Commit-by: ZhaiPeiChao Merged-by: cann-robot Description: ## 描述 <!--在这里详细描述你的改动,包括改动的原因和所采取的方法。--> AICPU add算子性能优化 fast path 负责 ≥99% 真实工作负载(深度学习里 Add 几乎都是 same-shape 或 scalar-bcast),通用 Eigen 路径只兜底多维非平凡 broadcast。 Compute ├─ NormalMathCheck + dtype permission check ├─ 显式 raw-rank ≤ 8 校验 (保持与原实现等价的失败语义) ├─ Bcast::GenerateBcastInfo ├─ 显式 output-shape 一致性校验 ├─ [fast] 同形 shape → AddSameShape ├─ [fast] scalar bcast → AddScalarBcast └─ [fallback] AddGenericBcast → 原 Eigen TensorMap broadcast 路径 Fast path 关键点: - **裸指针 + __restrict__ + 定长循环** → 编译器自动 NEON/AVX 向量化 (对应 V / E)。 - **按 output bytes 阈值动态选择串行 / ParallelFor** (对应 T / O10): - kParallelBytesThresh = 192 KiB:基于 10 μs ParallelFor 固定调度开销 + ~8 GB/s 单核 add 带宽反推 ~160 KiB,取 20% 余量。 - kBytesPerShard = 256 KiB:初版用 32 KiB 在 16 MiB 负载上产生 0.67× 回退(shard 数过多导致线程间抢带宽),调到 256 KiB 后恢复至 1.02×。 - **__builtin_expect(rc != OK, 0)** 标注冷分支,保持 C++17 合规(不使用 C++20 [[likely]])。 - **全部 reinterpret_cast → PtrToPtr<void,T>** 。 ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> issue [#1522](https://gitcode.com/cann/ops-math/issues/1522) ## 测试 <!--描述进行了哪些测试来验证你的改动。包括但不限于二级冒烟、算子泛化等。--> 基于4线程进行测试: | 形状 | dtype | case | old (μs) | new (μs) | **speedup** | |---|---|---|---:|---:|---:| | SameShape | fp32 | 4 KiB | 0.41 | 0.50 | 0.82× | | SameShape | fp32 | 96 KiB | 2.48 | 2.52 | 0.99× | | SameShape | fp32 | 1 MiB | 48.99 | 18.42 | **2.66×** | | SameShape | fp32 | 16 MiB | 766 | 752 | 1.02× | | ScalarBcast | fp32 | 4 KiB | 0.43 | 0.39 | 1.10× | | ScalarBcast | fp32 | 96 KiB | 3.02 | 1.87 | **1.62×** | | ScalarBcast | fp32 | 1 MiB | 31.7 | 8.07 | **3.93×** | | ScalarBcast | fp32 | 16 MiB | 557 | 520 | 1.07× | | SameShape | i64 | 2 MiB | 80 | 37 | **2.16×** | | ScalarBcast | i64 | 8 KiB | 0.38 | 0.14 | **2.77×** | | ScalarBcast | i64 | 192 KiB | 5.99 | 2.04 | **2.94×** | | ScalarBcast | i64 | 2 MiB | 509 | 187 | **2.73×** | ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> 不涉及 ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [ ] 新特性 - [x] 性能优化 - [ ] 文档更新 - [ ] 其他,请描述: See merge request: cann/ops-math!2462 | 3 个月前 | |
feat: migrate math+conversion json ops to opdef pipeline Co-authored-by: zhaowenrui666<zhaowenrui7@huawei.com> # message auto-generated for no-merge-commit merge: !2130 merge mathdef into master feat: migrate math+conversion json ops to opdef pipeline Created-by: zhaowenrui666 Commit-by: zhaowenrui666 Merged-by: cann-robot Description: ## 描述 math仓aicpu算子信息库由json融合修改为op def文件,修改注册方式以及工程适配 ## 关联的Issue https://gitcode.com/cann/ops-math/issues/1271 ## 测试 本次按 ENABLE_CUSTOM=ON 的 custom 路径验收,已验证 OpDef -> libaicpu_ops.so -> op_build --aicpu -> aicpu_kernel.ini -> parser_ini.py -> cust_aicpu_kernel.json 链路跑通,相关产物已生成并校验通过。AICPU before/after 与 I/O 对比已按新规则重评:input/output -> input0/output0 视为规范化差异;RightShift、SearchSorted、Sinh 在整改前 JSON 缺 I/O,但已对齐 CANN 基线 aicpu_kernel.ini,不判缺失;AddN: input0 -> dynamic_input0 和 AddFake -> Add 也已确认接受,不作为阻塞项。 AICore 回归已补做,before/after 经 parser_ini.py 转 json 后无差异。综合结论:本提交满足当前 OpDef 整改验收标准,可通过。 ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [x] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 其他,请描述: See merge request: cann/ops-math!2130 | 4 个月前 |
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 25 天前 | ||
| 3 个月前 | ||
| 4 个月前 |