Skip to content

[Docs]: update broadcast docstring, add dtype coverage tests and API doc - #1595

Merged
LLMZhangYC merged 1 commit into
tile-ai:ascendc_ptofrom
2Sheldonlaw:docs/broadcast-api-doc-and-tests
Sep 9, 2026
Merged

LLMZhangYC merged 1 commit into
tile-ai:ascendc_ptofrom
2Sheldonlaw:docs/broadcast-api-doc-and-tests

Conversation

@2Sheldonlaw

Copy link
Copy Markdown
Contributor

改动内容

针对 T.tile.broadcast API 完成文档校验、测试用例补充和 docstring 更新。

1. Docstring 更新(修改)

  • tilelang/language/ascend_tile.pybroadcast 函数的 docstring
  • 在原版基础上补充,不删除原有内容:
    • dtype 支持列表(9 个 dtype)
    • UB scope 约束 + dtype 一致性说明

2. 测试用例(新增)

  • testing/python/language/test_tilelang_ascend_language_tile_broadcast_dtype_coverage.py
  • 26 个用例(26 PASSED + 0 SKIPPED),不重复 test_tilelang_ascend_language_explicit_tmp.pytest_tilelang_ascend_language_elementwise.py 中已有的测试(float32×ascendc explicit tmp runtime、codegen only 测试)
  • LP 分层标记:PR 合入时跑 8 个,每日 CI 跑 26 个
测试函数 用例数 PR执行 LP 类型 覆盖内容
test_broadcast_2d_axis0 18 1 17 全量泛化 9 dtype × ascendc/pto (2D axis=0)
test_broadcast_1d_to_2d_auto_infer 2 1 1 全量泛化 1D→2D axis=None 自动推断
test_broadcast_1d_axis0_ascendc 1 1 0 全量泛化 1D axis=0 × ascendc
test_broadcast_dtype_mismatch_raises 1 1 0 异常边界 dst/src dtype 不一致编译失败
test_broadcast_shape_mismatch_axis0_raises 1 1 0 异常边界 axis=0 shape 不匹配抛异常
test_broadcast_shape_mismatch_axis1_raises 1 1 0 异常边界 axis=1 shape 不匹配抛异常
test_broadcast_invalid_axis_raises 1 1 0 异常边界 axis=2 非法值抛异常
test_broadcast_1d_uninferable_raises 1 1 0 异常边界 1D→2D 无法推断抛异常

LP 标记策略:

  • dtype:float32 默认执行,其余 8 个 dtype 标 low_priority
  • target:ascendc 默认执行,pto 标 low_priority
  • 异常边界测试:全部默认执行(用例少,关键覆盖)

3. API 文档(新增)

  • docs/api_docs/T.tile.broadcast.md

测试结果

  • 26 PASSED + 0 SKIPPED(CI 全绿,0 FAILED)

校验发现

真机测试发现 dtype 支持范围超出校验文档:校验文档原版仅列 int8/uint8/float16/float32(4 个),真机三重验证(编译+运行+精度)确认 int16/uint16/bfloat16/int32/uint32 在 ascendc + pto 后端均实际支持。CANN BroadcastImplstatic_assert(SupportBytes<T, 1, 2, 4, 8>())sizeof(T) 分派,9 个 dtype 均在范围内。已补充至文档。

已知限制(文档 Shape 支持已标注)

限制 说明
2D axis=1 M≥2 ascendc、pto 均不支持(CANN BrcLast 路径 bug,仅第一行正确)
1D axis=0 pto pto 后端不支持(pto codegen 生成错误指令),ascendc 不受影响

详细根因分析记录在 api/bug_investigation/broadcast_bug.md,包含修复尝试记录。

文件改动

文件 类型 改动
tilelang/language/ascend_tile.py 修改 docstring 补充 dtype 列表 + scope 约束
testing/python/language/test_tilelang_ascend_language_tile_broadcast_dtype_coverage.py 新增 26 个测试用例
docs/api_docs/T.tile.broadcast.md 新增 API 文档(dtype 表 9 个 + 已知限制)

@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the TileLang project.

Please remember to run bash format.sh in the root directory of the project to ensure your changes are properly linted and formatted. This will help ensure your contribution passes the format check.

We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work!

🚀

LLMZhangYC
LLMZhangYC previously approved these changes Aug 17, 2026

@LLMZhangYC LLMZhangYC left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Comment thread docs/api_docs/T.tile.broadcast.md Outdated
4. 1D src 广播到 2D dst 时,自动推断广播轴;无法推断时抛出 `ValueError`
5. 不支持 src 与 dst 地址重叠(硬件约束)
6. 仅支持 ND 格式(硬件约束)
7. dim=2 且 axis=0 时,srcShape[1] 必须 32 字节对齐(即元素个数 × 元素大小 ≥ 32 字节)(硬件约束)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"srcShape[1]必须 32 字节对齐(即元素个数 × 元素大小 ≥ 32 字节)(硬件约束)",实测结论:真正约束是 N×size 必须为 32 字节的整数倍,而非"≥ 32 字节",括号应改为"即 元素个数 × 元素大小 % 32 == 0"。另外建议顺带注明非对齐时是静默出错而非报错。

fengz72
fengz72 previously approved these changes Sep 4, 2026
LLMZhangYC
LLMZhangYC previously approved these changes Sep 4, 2026

@LLMZhangYC LLMZhangYC left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm


## 3. 示例代码

**示例 1:1D src 广播到 2D dst(axis 自动推断)**

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

示例命中已知不支持路径标题称这是1D-2D,但src的(4,1)实际是二维;axis=None会推断为axis=1,且M=4正好命中本页已注明AscendC/PTO均不支持、可能静默算错的路径。请改成真正受支持的例子,例如src=(16,)、dst=(4,16),让其自动推断axis=0。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修复。示例 1 从 src=(4,1) 改为 src=(16,),axis=None 推断为 axis=0(受支持路径),不再命中 2D axis=1 M≥2 的已知限制。

import tilelang.language as T
import torch

tilelang.disable_cache()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要在模块导入时关闭全局缓存

disable_cache() 修改进程级 CacheState,这里在 collection/import 阶段执行且从不恢复。CI 使用 pytest-xdist + --forked,worker 收集模块后产生测试子进程,因此其他测试也会继承禁用状态,造成全量 CI 编译时间回归并掩盖缓存相关行为。请删除该调用,或移入保存并恢复原状态的 fixture。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修复。tilelang.disable_cache() 已改为 @pytest.fixture(scope="module", autouse=True) + yield + tilelang.enable_cache() 恢复。

@2Sheldonlaw
2Sheldonlaw force-pushed the docs/broadcast-api-doc-and-tests branch from 9295e1d to c36173b Compare September 7, 2026 02:45

@ChaoyangJi ChaoyangJi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@2Sheldonlaw

Copy link
Copy Markdown
Contributor Author

/re-test

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

🔄 Re-running failed jobs

Original workflow run: View details

Only the failed jobs will be re-executed.

@2Sheldonlaw

Copy link
Copy Markdown
Contributor Author

/re-test

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

🔄 Re-running failed jobs

Original workflow run: View details

Only the failed jobs will be re-executed.

@LLMZhangYC LLMZhangYC left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approve

@LLMZhangYC
LLMZhangYC merged commit eb7ca3c into tile-ai:ascendc_pto Sep 9, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants