Merged
feat(pypto_pro): Support pypto_pro SIMT #5341
wuzhongxinAdd on Aug 7
feat(pypto_pro): Support pypto_pro SIMT #5341
Merged
wuzhongxinAdd on Aug 7
wuzhongxin
Aug 7

feat(pypto_pro): Support pypto_pro SIMT

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for wuzhongxin's contribution.)
wuzhongxinwuzhongxin
Aug 7 Created pull request, commit 9e0db78e
wuzhongxinwuzhongxin
Aug 7 Associated issue: [Requirement|需求建议]: 支持Pypto-Pro编程框架代码
atomgit-bot
atomgit-bot
Aug 7 Comments:

变更摘要

此 PR 为 PyPTO Pro 框架新增了 A5 架构的 SIMT(单指令多线程)编程支持。核心变更包括:在 IR 层引入 FunctionType::SIMT_VF 函数类型及 maxThreads_ 启动上限字段;新增 10 个 SIMT 相关 IR 算子(线程上下文查询、同步、原子加、启动等);在 CCE 代码生成器中实现 GenerateSimtFunction 方法,将 SIMT 函数直接生成为原生 __simt_vf__ C++ 代码,并将 SIMT 算子降级为 threadIdx/blockDim/atomicAdd/__sync_workitems/cce::async_invoke 等原生 CCE 调用;在 Python 前端新增 @pl.simt_function 装饰器与 pl.simt 命名空间,提供声明式 SIMT DSL;同时修正了 CCE 属性语法从 __aicore__ 到 [aicore]。

主要改动

  • 新增 FunctionType::SIMT_VF 与 maxThreads_ 字段:在 function.h 中为 FunctionType 枚举增加 SIMT_VF = 4 值,并为 Function 类添加 std::optional<uint32_t> maxThreads_ 成员,用于记录 SIMT 函数的编译期启动线程上限;所有构造 Function 的调用点(SSA 转换、Mutator、Passes、Python 绑定)均同步传递该参数。

  • 新增 10 个 SIMT IR 算子并注册:在 simt_ops.cpp 中定义 simt.thread_idx、simt.block_dim、simt.block_idx、simt.grid_dim、simt.linear_thread_idx、simt.warp_size、simt.syncthreads、simt.atomic_add、simt.tile_valid_shape、simt.launch 共 10 个算子,各自带有类型推导逻辑与参数约束校验(如 simt.launch 限制总线程数 ≤ 2048、要求编译期常量维度等)。

  • CCE 代码生成器支持 SIMT 函数生成:在 cce_codegen.cpp 中新增 GenerateSimtFunction 方法,生成 __simt_vf__ __launch_bounds__(N) inline void 签名的原生 C++ 函数,处理 Tensor(__gm__ 指针)、Tile(__ubuf__ 指针 + valid_row/col 参数)和 Scalar 三种参数类型;新增 ResetFunctionGenerationState 统一重置生成状态;在 backend_cce_simt_ops.cpp 中将各 SIMT 算子降级为原生 CCE 语法(如 threadIdx.x、atomicAdd(...)、__sync_workitems()、cce::async_invoke<...>(...) + pipe_barrier(PIPE_ALL))。

  • Python 前端新增 @pl.simt_function 装饰器与 pl.simt DSL:在 decorator.py 中新增 simt_function 装饰器,解析 SIMT 函数体并生成 FunctionType::SimtVF 的 IR 函数,校验参数类型(仅允许 Scalar/Tensor/Tile,且 Tensor 和 Tile 必须静态形状、ND 布局、≥8bit 元素);在 simt.py 中暴露 thread_idx、atomic_add、launch 等公共 API;在 _call_parser.py、_simt_call_parser.py、_expression_parser.py 中新增 SIMT 调用解析逻辑,包括 pl.simt.launch(...) 启动语法校验、tile.valid_shape[axis] 下标访问、pl.simt.atomic_add(counter[0,0], 1) 的特殊参数解析等。

  • CCE 属性语法修正:将生成的 C++ 代码中的 __aicore__/__global__ AICORE 统一改为 [aicore]/__global__ [aicore],涉及 cce_codegen.cpp、jit.py 和 pypto_compile.py 中的函数签名生成与入口包装代码。

likedislike
Incorrect?
atomgit-bot
atomgit-bot
Aug 7 Comments:

代码审查

审查总结

我逐一审查了本次 diff 涉及的 40 个文件,现将审查结论汇总如下。

发现的问题

优先级 数量
P0 0
P1 0
P2 1
P3 0

P2 问题:Function::GetFieldDescriptors()(function.h:137-146)中遗漏了新增的 maxThreads_ 字段,这将导致结构相等性比较(structural_equal.cpp)和结构哈希(structural_hash.cpp)忽略该字段,可能在 IR 去重或缓存场景下产生错误结果。

各文件审查结果

文件 结论
framework/include/ir/function.h P2 问题 — GetFieldDescriptors() 缺少 maxThreads_
framework/include/pypto_pro/codegen/cce/cce_codegen.h 无问题
framework/src/interface/ir/op/simt_ops.cpp 无问题
framework/src/interface/ir/transforms/convert_to_ssa_pass.cpp 无问题
framework/src/interface/ir/transforms/mutator.cpp 无问题
framework/src/interface/ir/transforms/passes.cpp 无问题
framework/src/interface/ir/transforms/printer.cpp 无问题
framework/src/interface/pypto_pro/backend/backend_cce_ops.cpp 无问题
framework/src/interface/pypto_pro/backend/backend_cce_simt_ops.cpp 无问题
framework/src/interface/pypto_pro/codegen/cce/cce_codegen.cpp 无问题
python/pypto_pro/ir/op/__init__.py 无问题
python/pypto_pro/ir/op/_op_registry.py 无问题
python/pypto_pro/ir/op/simt_ops.py 无问题
python/pypto_pro/language/__init__.py 无问题
python/pypto_pro/language/parser/__init__.py 无问题
python/pypto_pro/language/parser/_ast_parser.py 无问题
python/pypto_pro/language/parser/_call_parser.py 无问题
python/pypto_pro/language/parser/_control_flow_parser.py 无问题
python/pypto_pro/language/parser/_expression_parser.py 无问题
python/pypto_pro/language/parser/_simt_call_parser.py 无问题
python/pypto_pro/language/parser/decorator.py 无问题
python/pypto_pro/language/simt.py 无问题
python/pypto_pro/runtime/jit.py 无问题
python/pypto_pro/runtime/opc/pypto_compile.py 无问题
python/src/bindings/ir/ir.cpp 无问题
python/tests/st/pypto_pro/frontend/simt/atomic/test_atomic_add.py 无问题
python/tests/st/pypto_pro/frontend/simt/integration/test_bincount.py 无问题
python/tests/st/pypto_pro/frontend/simt/integration/test_multiple_functions.py 无问题
python/tests/st/pypto_pro/frontend/simt/integration/test_simd_simt_pipeline.py 无问题
python/tests/st/pypto_pro/frontend/simt/launch/test_1d_launch.py 无问题
python/tests/st/pypto_pro/frontend/simt/launch/test_2d_launch.py 无问题
python/tests/st/pypto_pro/frontend/simt/launch/test_3d_launch.py 无问题
python/tests/st/pypto_pro/frontend/simt/launch/test_multicore.py 无问题
python/tests/st/pypto_pro/frontend/simt/memory/test_gm_tensor_access.py 无问题
python/tests/st/pypto_pro/frontend/simt/memory/test_ub_tile_access.py 无问题
python/tests/st/pypto_pro/frontend/simt/thread/test_syncthreads.py 无问题
python/tests/st/pypto_pro/frontend/simt/thread/test_thread_context.py 无问题
python/tests/ut/pypto_pro/codegen/test_cce_simt.py 无问题
python/tests/ut/pypto_pro/language/parser/test_simt.py 无问题
python/tests/ut/pypto_pro/language/test_simt_api.py 无问题

整体风险评估

风险等级:低。本次变更为 PyPTO Pro 新增了 A5 SIMT 编程框架支持,代码整体质量良好,覆盖了前端解析、IR 操作注册、CCE 代码生成以及全面的测试(单元测试、系统测试)。唯一发现的问题是 maxThreads_ 字段在反射描述符中的遗漏,影响结构相等性和哈希,但不会导致运行时的正确性问题(所有已知的 Function 构造点都显式传递了 maxThreads_ 参数,不依赖反射拷贝)。建议在该批合入前修复此问题,以确保 IR 基础设施的正确性。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Aug 7 Added label: stat/needs-squash
673 messages are collapsed here。 See more
gaoxiang618
gaoxiang618Collaborators
Aug 21 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Aug 21 Added label: approved
poorwill
poorwillCollaborators
Aug 21 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Aug 21 Added label: lgtm
CANN-robotCANN-robotCollaborators
Aug 21 Merged pull request