Pull Request has been successfully merged by CANN-robot.
(Thank you for wuzhongxin's contribution.)变更摘要
此 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.simtDSL:在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中的函数签名生成与入口包装代码。


代码审查
审查总结
我逐一审查了本次 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 |
💬 仅评论


/lgtm
/approve


/lgtm
/approve


feat(pypto_pro): Support pypto_pro SIMT