| Files | Last commit | Last update |
|---|---|---|
fix(codegen): Avoid ASC CACHE_LINE_SIZE and g_tilingKey link conflicts Co-authored-by: anyangle<anyangle@huawei.com> # message auto-generated for no-merge-commit merge: !6246 merge bugfix into master fix(codegen): Avoid ASC CACHE_LINE_SIZE and g_tilingKey link conflicts Created-by: quadrate Commit-by: anyangle Merged-by: cann-robot Description: **根因:** 使能 ASC print/dump后,检测到 $ASCEND_HOME_PATH/asc/include 就默认注入 -D__ENABLE_ASC_PRINTF__,entry/leaf/mid 都会拉 ASC 调试头。新 ASC 头依赖变了,旧包碰不到的符号被编进 PyPTO 多 TU 链接路径,于是炸了两层:CCE上报 CACHE_LINE_SIZE 宏与 ASC const 冲突(F70002);ld -r 时报 g_tilingKey 强符号重复(F70003)。**本质是 CANN ASC 版本问题** **修复:** 1. CACHE_LINE_SIZE 改为 AicorePrintConst::CACHE_LINE_SIZE,避免与 ASC 常量冲突。 2. 用 -DTILING_KEY_VAR=0(头文件内再兜底)抑制 g_tilingKey 多 TU 重复定义。 3. PYPTO_ENABLE_AICORE_PRINT=true 才注入 __ENABLE_ASC_PRINTF__,默认关闭,不再拉 ASC dump/printf 头;打开后 1/2 仍作兼容。 See merge request: cann/pypto!6246 | 2 months ago | |
fix(machine): Add control flow encode Co-authored-by: LordOfMysteries<duhongxiang@huawei.com> Co-authored-by: wan_jianfen<wanjianfen@hisilicon.com> # message auto-generated for no-merge-commit merge: !6666 merge br_test into master fix(machine): Add control flow encode Created-by: wan_jianfen Commit-by: wan_jianfen;LordOfMysteries Merged-by: cann-robot Description: PR 应该避免没有描述信息,描述信息的最重要的作用是描述修改意图,应该清晰明了。例如:标题中包含了 fix 标签,如果没有描述信息,就需要Review人员猜测PR具体修复了哪些内容,或者怀疑修改的必要性。如果PR和特定的Issue相关,可以单独包含一行 Related Issue: 放到描述信息最后。 下面是一个典型的PR描述信息: The origin issue template brings too many noise, it's not suitable for git message. eg: comments are not removed, labels are redundant as the PR tile already contains the tag. The guide gives a clear suggestion on how to write the PR body. Related Issue: #1234,#5678 更多描述信息见:[Commit Message 规范](../docs/zh/contribute/pull-request.md#commit-message) See merge request: cann/pypto!6666 | 2 months ago | |
fix(machine): Page-align ctrlflow .pypto so adrp survives AOT memcpy Co-authored-by: LordOfMysteries<duhongxiang@huawei.com> # message auto-generated for no-merge-commit merge: !6663 merge fix-ctrlflow-pypto-page-align into master fix(machine): Page-align ctrlflow .pypto so adrp survives AOT memcpy Created-by: LordOfMysteries Commit-by: LordOfMysteries Merged-by: cann-robot Description: https://gitcode.com/cann/pypto/issues/3441 # CANN包内 GCC 7升级到14 后 PyPTO 算子精度异常 ## 1. 背景 cann 包内置编译器由 gcc 7 升级到 gcc 14 后,pypto 算子精度异常 pypto的Device ctrlflow机制:跑在device上的aicpu不是完整 .so,只包含了调度大框架。支持动态shape tiling展开的源码使用了AOT技术在host编译,JIT拷贝到device上执行: 1. gcc -S / -c 2. ld -T merge.link 合成 .pypto(*(.pypto.entry) *(.pypto.func) *(.rodata.*),VMA 0x10000) 3. objcopy --dump-section .pypto= 4. memcpy 到 4K 对齐 AOT 池,CallControlFlow 当函数指针跳入(参数在 x0–x3) ## 2. 现象(Device 日志比对) CallRootFunctionStitch(源码 device_execute_context.cpp:611)通过 SchemaGetExpressionTable() 打印 expr 表(同一 gdr_bwd kernel): - **ok.log**(正确): RUid{0,1,3} expr{[0,9,3,23,22,24,16,20,6,19,21,14,4,1,8,10,15,0,7,18,17,5,11,2,0,...]} - **fail.log**(异常): RUid{0,1,3} expr{[-117395325,-117394301,-117397373,-117396349,-117399421,-117398397,-1702252313,1358955619,-1201444600,-1862140633,285473027,445136995,0,0,...]} → fail 情况下 expr 表**前若干个值被写成垃圾数据**,后续值才与 ok 一致。 ## 3. 二进制产物比对 AICPU 侧生成 expr 表的源文件 kernel_aicpu/control_flow_expr_table_*.cpp, OK 与 FAIL 两份**源码完全一致**,差异全部来自编译器生成的汇编码。 ### 3.1 关键指令(错误指令定位) GCC 7编译 000000000001d840 <_ZN3npu8tile_fwk17SetExprBatch_17_0EPvPlPPFS1_S1_mEPNS0_16DevStartArgsBaseEPmS2_>: 1d840: b4007284 cbz x4, 1e690 <_ZN3npu8tile_fwk17SetExprBatch_17_0EPvPlPPFS1_S1_mEPNS0_16DevStartArgsBaseEPmS2_+0xe50> 1d844: a9be7bfd stp x29, x30, [sp, #-32]! 1d848: d280012a mov x10, #0x9 // #9 1d84c: d2800068 mov x8, #0x3 // #3 1d850: 910003fd mov x29, sp 1d854: d28002e9 mov x9, #0x17 // #23 1d858: d28002c2 mov x2, #0x16 // #22 1d85c: d2800307 mov x7, #0x18 // #24 1d860: d2800030 mov x16, #0x1 // #1 1d864: d280008f mov x15, #0x4 // #4 1d868: d2800200 mov x0, #0x10 // #16 GCC 14编译: .arch armv8-a .file "control_flow_expr_table_0_0.cpp" .text .section .pypto.func,"ax",@progbits .align 2 .p2align 5,,15 .global _ZN3npu8tile_fwk16SetExprBatch_0_0EPvPlPPFS1_S1_mEPNS0_16DevStartArgsBaseEPmS2_ .type _ZN3npu8tile_fwk16SetExprBatch_0_0EPvPlPPFS1_S1_mEPNS0_16DevStartArgsBaseEPmS2_, %function _ZN3npu8tile_fwk16SetExprBatch_0_0EPvPlPPFS1_S1_mEPNS0_16DevStartArgsBaseEPmS2_: .LFB1627: .cfi_startproc cbz x4, .L2 adrp x0, .LC0 stp xzr, xzr, [x4, 192] ldr q30, [x0, #:lo12:.LC0] adrp x0, .LC1 ldr q29, [x0, #:lo12:.LC1] adrp x0, .LC2 ldr q31, [x0, #:lo12:.LC2] adrp x0, .LC3 stp q30, q29, [x4] FAIL 构建 kernel_aicpu/control_flow_expr_table_0_0.cpp.s 中,SetExprBatch_0_0 前段: asm ldr q30, [x0, #:lo12:.LC0] ; 从字面量池读 128-bit 常量到 NEON 寄存器 ldr q29, [x0, #:lo12:.LC1] ldr q31, [x0, #:lo12:.LC2] stp q30, q29, [x4] ; 偏移 0 → exprList[0..7] stp q31, q29, [x4, 32] ; 偏移 32 → exprList[8..15] stp q30, q29, [x4, 64] ; 偏移 64 → exprList[16..23] ... 即:gcc14 将"连续写常量到 expr 表"的标量序列**自动向量化**为 128-bit NEON (FP/SIMD q 寄存器)存取指令。写入范围 [x4, 0..160] 恰好覆盖 expr 表前 约 12~23 个被污染的值,与日志中垃圾值所在区间吻合。 ### 3.2 全表统计 | 构建 | 每个 control_flow_expr_table_*.cpp.s 中 NEON q 寄存器出现次数 | |------|:---:| | OK(带 -mgeneral-regs-only) | **0**(全部 19 个表) | | FAIL(不带该选项) | **18**(全部 19 个表) | ### 3.3 对照的 OK 生成形态(纯通用寄存器) asm stp xzr, x8, [x4] ; 使用通用寄存器 x 系列 stp x6, x7, [x4, 16] stp x0, x2, [x4, 32] ... ## 4. 根因(已依据二进制反汇编+重定位实测修正) 一句话:adrp 只负责跳到「某一页的开头」,ldr 再在这一页里加上一个不到 4KB 的偏移。链接时这两段数是按虚拟地址 0x10260 起算的,拷到内存后代码却从页的开头执行,所以加出来的地址落在常量前面。 ### 4.0 真实机制:adrp 的页差和页内偏移按链接地址写死,memcpy 到页首后指错 adrp 只算出某一页的开头,ldr 再加上页内偏移: text adrp x0, .LC0 x0 = 当前指令所在页 + imm × 0x1000 ldr q30, [x0, #lo12] 地址 = x0 + lo12 pg(x) 表示把地址低 12 位清零(一页 0x1000)。imm 和 lo12 都在链接时写进指令,运行时不再修改: | 写进指令的数 | 含义 | |---|---| | imm = 13 | pg(.LC) − pg(这条 adrp) | | lo12 = 0x350 | .LC 链接虚拟地址 0x1e350 的低 12 位 | 链接布局(.pypto 从 0x10260 开始,前面 0x260 是 .eh_frame。这段不在 dump 出的 bin 里,但占了虚拟地址): text 页 0x10000 页 0x11000 页 0x1E000 0x10000 0x10260 0x11184 0x1E350 | 空隙260 |==== .pypto 起点 ====| | adrp | | .LC | text pg(0x1e350) − pg(0x11184) = 0x1e000 − 0x11000 = 0xD000 = 13 页 按链接地址:0x11000 + 13×0x1000 + 0x350 = 0x1e350 在 ELF 里这指对 .LC。objcopy 只抽出 .pypto,bin[0] 对应虚拟地址 0x10260,不是 0x10000: text adrp 在 bin 中的偏移 = 0x11184 − 0x10260 = 0xF24 .LC 在 bin 中的偏移 = 0x1e350 − 0x10260 = 0xE0F0 0xE0F0 落在 bin 的第 14 页(0xE000),页内偏移是 0x0F0,不再是链接时的 0x350。 AOT 把 bin[0] 拷到 4K 对齐的 base(aotCodePoolCodes 为 .p2align 12),再从 base 执行。指令在 base+0xF24,仍属于第 0 页: text x0 = pg(base+0xF24) + 13×0x1000 = base + 0xD000 地址 = base + 0xD000 + 0x350 = base + 0xD350 0xD350 处是别的指令字节,读到 {17960378008443334787, 17960382406489846915}。{0,9} 在 base+0xE0F0。 text 0xE0F0 − 0xD350 = 0xDA0 页号差 1(adrp 落到第 13 页,常量在第 14 页)。字节差不是整页 0x1000,因为 lo12 仍是链接地址的 0x350,常量在 bin 里的页内偏移已经变成 0x0F0。 adrp 可以随整段代码搬家,但搬家量必须是整页的整数倍。这次把「页内第 0x260 字节」当成了新的页首,写死的页差和 lo12 就指到 0xD350。.pypto 的链接地址本身按 4K 对齐时,bin[0] 与页首是同一点,这两段数在拷贝之后仍指向常量。 ### 4.0.1 为什么恰好差一页、为什么只有 gcc14 出问题 - adrp 是 PC 相对的**页(4K)**寻址:imm 表示"PC 所在页 + n 页"。 同一 blob 被整体平移时相对地址不变,**只有当源基址(0x10260)与目标基址(页对齐) 不在同一页关系上(即源基址非页对齐、目标页对齐)时**,跨页引用会整体错一页。 - gcc 7 / OK 构建:SetExprBatch_* 用立即数 mov x8,9; stp xzr,x8,[x4], **没有任何 adrp/字面量池**(.s 中 adrp 计数=0),不存在跨页 .LC 引用 ⇒ 不受影响。 - gcc14 / FAIL 构建:把常量表放 .rodata.cst16 并用 12 条 adrp+ldr q,[x0,#imm] 访问(.s 中 adrp 计数=12),跨页引用在重定位到页对齐池后错一页 ⇒ 读脏数据。 > 更正声明:本文档早期"分发环境不维护 SIMD 寄存器堆 / 进入时 SIMD 寄存器为脏"的说法 > **不正确**。正如你所指:代码是"先 ldr q(载入字面量)再 stp q",寄存器本身没问题; > 真正错误的是 adrp 页偏移在 memcpy 重定位后差一页,导致 ldr q **取错了地址的数据**。 > 问题与 SIMD 寄存器状态无关,而与"gcc14 生成了跨页 adrp 字面量池 + 代码池页对齐重定位"有关。 ## 5 方案 改 ExprBatchGenerator::GenerateLinkScript 生成的 merge.link,让输出段 .pypto 自己落在页边界,并丢掉占位的 .eh_frame: SECTIONS { . = 0x10000; .pypto : ALIGN(4096) { *(.pypto.entry) *(.pypto.func) *(.rodata .rodata.*) } } ALIGN(4096) :即使以后又冒出别的段,.pypto 的链接地址仍然满足 vaddr % 4096 == 0。段内不要再把 .rodata 单独 ALIGN(4096),否则 bin 里会多出整页空洞;只要段起点对齐,ld 会按新地址重填 adrp 和 lo12。 运行时不用改。池子本来就是 .p2align 12,入口仍是 bin[0]。 readelf -S ori.o There are 10 section headers, starting at offset 0x1f6e8: Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .eh_frame PROGBITS 0000000000010000 00010000 0000000000000254 0000000000000000 A 0 0 8 [ 2] .pypto PROGBITS 0000000000010260 00010260 000000000000e110 0000000000000000 AXM 0 0 32 [ 3] .text PROGBITS 000000000001e370 0001e370 0000000000000000 0000000000000000 AX 0 0 1 [ 4] .data PROGBITS 000000000001e370 0001e370 0000000000000000 0000000000000000 WA 0 0 1 [ 5] .bss NOBITS 000000000001e370 0001e370 0000000000000000 0000000000000000 WA 0 0 1 [ 6] .comment PROGBITS 0000000000000000 0001e370 000000000000003e 0000000000000001 MS 0 0 1 [ 7] .symtab SYMTAB 0000000000000000 0001e3b0 0000000000000a08 0000000000000018 8 86 8 [ 8] .strtab STRTAB 0000000000000000 0001edb8 00000000000008e3 0000000000000000 0 0 1 [ 9] .shstrtab STRTAB 0000000000000000 0001f69b 0000000000000046 0000000000000000 0 0 1 readelf -S New.o There are 10 section headers, starting at offset 0x20488: Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .eh_frame PROGBITS 0000000000010000 00010000 0000000000000254 0000000000000000 A 0 0 8 [ 2] .pypto PROGBITS 0000000000011000 00011000 000000000000e110 0000000000000000 AXM 0 0 4096 [ 3] .text PROGBITS 000000000001f110 0001f110 0000000000000000 0000000000000000 AX 0 0 1 [ 4] .data PROGBITS 000000000001f110 0001f110 0000000000000000 0000000000000000 WA 0 0 1 [ 5] .bss NOBITS 000000000001f110 0001f110 0000000000000000 0000000000000000 WA 0 0 1 [ 6] .comment PROGBITS 0000000000000000 0001f110 000000000000003e 0000000000000001 MS 0 0 1 [ 7] .symtab SYMTAB 0000000000000000 0001f150 0000000000000a08 0000000000000018 8 86 8 [ 8] .strtab STRTAB 0000000000000000 0001fb58 00000000000008e4 0000000000000000 0 0 1 [ 9] .shstrtab STRTAB 0000000000000000 0002043c 0000000000000046 0000000000000000 0 0 1 ## 6 影响 对现有 ctrlflow 几乎没有体积、性能和兼容性代价。 ALIGN(4096) 只要求 .pypto 这一段的链接地址落在 4K 边界上,objcopy 抽出来的 bin 仍然从第一条指令开始,不会在 bin 前面多垫 4KB。 See merge request: cann/pypto!6663 | 2 months ago | |
fix(machine): Add control flow encode Co-authored-by: LordOfMysteries<duhongxiang@huawei.com> Co-authored-by: wan_jianfen<wanjianfen@hisilicon.com> # message auto-generated for no-merge-commit merge: !6666 merge br_test into master fix(machine): Add control flow encode Created-by: wan_jianfen Commit-by: wan_jianfen;LordOfMysteries Merged-by: cann-robot Description: PR 应该避免没有描述信息,描述信息的最重要的作用是描述修改意图,应该清晰明了。例如:标题中包含了 fix 标签,如果没有描述信息,就需要Review人员猜测PR具体修复了哪些内容,或者怀疑修改的必要性。如果PR和特定的Issue相关,可以单独包含一行 Related Issue: 放到描述信息最后。 下面是一个典型的PR描述信息: The origin issue template brings too many noise, it's not suitable for git message. eg: comments are not removed, labels are redundant as the PR tile already contains the tag. The guide gives a clear suggestion on how to write the PR body. Related Issue: #1234,#5678 更多描述信息见:[Commit Message 规范](../docs/zh/contribute/pull-request.md#commit-message) See merge request: cann/pypto!6666 | 2 months ago | |
fix(machine): Add aicore-resolve macro Co-authored-by: huanglu<huanglu22@hisilicon.com> # message auto-generated for no-merge-commit merge: !5549 merge master into master fix(machine): Add aicore-resolve macro Created-by: lululu40888 Commit-by: huanglu Merged-by: cann-robot Description: fix(machine): Add aicore-resolve macro See merge request: cann/pypto!5549 | 3 months ago | |
feat(ir): Support dump function attribute Co-authored-by: tsungl4<lidongsheng4@huawei.com> # message auto-generated for no-merge-commit merge: !6675 merge attr into master feat(ir): Support dump function attribute Created-by: tsungl4 Commit-by: tsungl4 Merged-by: cann-robot Description: Related Issue: #2559 See merge request: cann/pypto!6675 | 2 months ago | |
refactor(build): Reuse the common compilation options from common cmake. Co-authored-by: Feiteng Zheng<zhengfeiteng1@h-partners.com> # message auto-generated for no-merge-commit merge: !5292 merge 20260728-intf-pub-2 into master refactor(build): Reuse the common compilation options from common cmake. Created-by: zhengfeiteng Commit-by: Feiteng Zheng Merged-by: cann-robot Description: 切换使用 cann/cmake 仓规定的 intf_pub。 - 通过CANN_GLIBCXX_USE_CXX11_ABI属性设置tile_fwk_calculator的_GLIBCXX_USE_CXX11_ABI Related Issue: #2650 See merge request: cann/pypto!5292 | 3 months ago |
| Files | Last commit | Last update |
|---|---|---|
| 2 months ago | ||
| 2 months ago | ||
| 2 months ago | ||
| 2 months ago | ||
| 3 months ago | ||
| 2 months ago | ||
| 3 months ago |