| feat: 提供 Python 异步图执行接口
Co-authored-by: du-hua1024<duhua2@huawei.com>
# message auto-generated for no-merge-commit merge:
!947 merge tmp2 into develop
feat: 提供 Python 异步图执行接口
Created-by: du-hua1024
Commit-by: du-hua1024
Merged-by: cann-robot
Description: 20260326评审通过
# Pull Request
## 描述
本 PR 补充 GE Python 在异步图执行场景下的关键封装,覆盖基于 stream 的异步运行、输出内存分配策略以及 Host/Device Tensor 互转能力,并同步完善样例、文档和单元测试。
## 主要修改
- Session 新增 run_graph_with_stream_async(graph_id, stream, inputs) 与 remove_graph(graph_id) 接口,支持基于指定 stream 的异步图执行与图卸载,register_external_allocator与unregister_external_allocator接口,支持基于 stream 的外置 allocator 注册与反注册。
- 新增 ge.allocator.Allocator / MemBlock 抽象,以及 _allocator_callback_adapter.py,支持 Python 自定义 external allocator 注册到 GE。
- 当用户未为 stream 注册 external allocator 时,run_graph_with_stream_async 路径自动注册 default allocator;session 析构时清理当前会话注册的 default allocator。
- C wrapper 补充 async run、allocator 注册/反注册、allocator 查询和 GE 初始化状态查询等接口。
- Tensor 新增 Placement 枚举、placement 属性、to_device() / to_host() 能力,支持异步执行场景下的 Device Tensor 输入输出。
- 更新 model_manager.cc,将异步执行静态图场景的输出 Tensor placement 修改为 Device。
- 更新 examples/es/operator_overload_async/python 样例,拆分默认 allocator 与自定义 allocator 两个执行路径,并补充运行说明。
- 补充 session_test.py、tensor_test.py、types_test.py,覆盖新增接口、参数校验和 Placement 相关能力。
## 变更类型
- [ ] 🐛 Bug 修复
- [x] ✨ 新功能
- [ ] 💄 代码风格更新(格式化,局部变量)
- [ ] ♻️ 重构(既不修复错误也不增加功能的代码变动)
- [ ] 📦 构建过程或辅助工具的变动
- [x] 📝 文档内容更新
## 如何测试
1. 运行 examples/es/operator_overload_async/python 路径下异步样例
2. 运行 Python 单元测试:
pytest tests/ge/ut/ge/graph/pyge_tests/session_test.py
pytest tests/ge/ut/ge/graph/pyge_tests/tensor_test.py
pytest tests/ge/ut/ge/graph/pyge_tests/types_test.py
## 其他信息
- 自定义 allocator 按 stream 维度注册;异步执行时 GE 优先使用该 stream 上已注册的 external allocator,否则注册 default allocator。
- 异步执行返回的输出 Tensor 默认位于 Device,需在对应 stream 同步完成后调用 to_host() 再读取数据。
See merge request: cann/ge!947 | 1 个月前 |