[Fix] Harden row-expand layouts and clean up legacy tooling 🤖 - #1495
Open
platelett wants to merge 3 commits into
Open
[Fix] Harden row-expand layouts and clean up legacy tooling 🤖#1495platelett wants to merge 3 commits into
platelett wants to merge 3 commits into
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
👋 Hi! Thank you for contributing to the TileLang project. Please remember to run We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀 |
platelett
force-pushed
the
fix/flags-rowexpand-env
branch
from
July 29, 2026 13:20
89013a0 to
0f2fb10
Compare
Fold contiguous leading Buffer and BufferRegion dimensions into the logical row count instead of dropping them. Reject gapped regions and enforce the 256-byte row, packed src1, scalar-plus-tmp, dtype, count, and workspace contracts. Add focused frontend coverage and a two-backend multistage numerical regression.
Remove the public init_flag and clear_flag helpers together with the Ascend codegen branch that injected their prebuilt SetFlag/WaitFlag strings. Keep the structured set_flag/wait_flag APIs unchanged and add a regression that confirms the legacy helpers are no longer exported.
Resolve the sourced script path with the active shell, export the canonical TL_ROOT, and prepend it to PYTHONPATH only when needed. Handle unset and empty PYTHONPATH without an implicit current-directory entry, remain safe under nounset, and avoid duplication across repeated sourcing.
platelett
force-pushed
the
fix/flags-rowexpand-env
branch
from
July 29, 2026 16:51
0f2fb10 to
d079907
Compare
platelett
marked this pull request as ready for review
July 31, 2026 03:50
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
本 PR 处理三个“调用看起来有效,但实际行为已经偏离接口表面含义”的问题:
T.init_flag/T.clear_flag在 AscendC 生成 flag 指令,在 PTO 则被静默忽略;set_env.sh在 Bash 首次 source 时正常,但换成 Zsh 或重复 source 后结果会变化。三项修改相互独立,因此分别放在三个 commit 中 review。
1. 修正 row-expand 的行数和布局
Row-expand 的最后一维固定为 256 字节,即 fp32 的 64 列或 fp16 的 128 列;前面的维度都应合并为行数。
例如,一个 fp32 Buffer 的 shape 是
[3, 8, 64]。完整 Buffer 应被视为[24, 64],但旧逻辑只看到[8, 64]。类似地,[1:3, :, :]的指针已经覆盖两个 stage,src1的 shape 计算却可能丢掉 stage 维,导致行标量数量与实际数据不一致。本 PR 让
Buffer和BufferRegion都按同一规则折叠前导维度。只有实际连续的 region 才能折叠;例如从[2, 128, 8]中选择[0:2, 0:64, :]会跨过未选择的内存,因此现在直接报错。这不改变乘、减、除的计算,只修正 shape,并在进入 codegen 前拒绝当前后端无法表示的布局。
在下面列出的支持范围内,AscendC 和 PTO 现在都会使用同一个折叠后的
rows,并通过了相同的单 stage 和多 stage 数值用例。具体接受哪些布局
rows是静态的 8 的倍数,范围为8..248;tmp时,src1每行包含一个重复标量的 32 字节 block;tmp时,src1是连续标量数组,tmp每行提供一个 32 字节 block;chunk * 64等符号化 offset 在 TIR 能证明其对齐时仍可使用。AscendC codegen 也会检查
uint8_t能表示的 row 数和 stride,防止手工构造 intrinsic 时发生截断。2. 删除只在 AscendC 生效的旧 flag 接口
T.init_flag/T.clear_flag随 2025 年的实验性 AscendC backend加入。名字像通用同步 API,实际却是在 Python 端拼接AscendC::SetFlag/WaitFlag源码,再由 AscendC codegen 原样输出。PTO 只支持结构化的
T.set_flag/T.wait_flag,不会处理这种 AscendC 字符串 AttrStmt。调用旧接口时 PTO 不报错,但也不生成 flag 指令,因而可能静默丢失同步。当前代码和历史中没有找到这两个公开函数的调用、测试或文档;示例中的同名函数是各自定义的局部
T.macro,与它们无关。经 ChaoyangJi 确认,本 PR 直接删除这组公开函数及 AscendC 特例;结构化 flag API 保持不变。3. 让
set_env.sh在 Bash/Zsh 中保持稳定新脚本分别用
BASH_SOURCE[0]和${(%):-%N}找到被 source 的文件,并只在需要时把 canonicalTL_ROOT放到PYTHONPATH首位:/opt/lib$TL_ROOT:/opt/libPYTHONPATH为空$TL_ROOT:,包含当前目录$TL_ROOT$TL_ROOT:$TL_ROOT:$old$TL_ROOT:$oldTL_ROOT因此,常见的 Bash 首次 source 保持原搜索顺序;空环境和重复 source 的差异则是有意删除空 path 和重复前缀。
测试
仓库中只保留最小回归,大矩阵仅在本地执行:
15 passed,本地 AscendC/PTO 多 stage NPU 矩阵24/24 passed;exp_experiment回归5 passed;1 passed,Bash/Zsh 环境矩阵12/12 passed;git diff --check均通过。