文件最后提交记录最后更新时间
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_allocatorunregister_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.pytensor_test.pytypes_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!9471 个月前
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_allocatorunregister_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.pytensor_test.pytypes_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!9471 个月前
feat: 新增离线图编译执行 C++ 样例并修复 allocator 回调释放问题 Co-authored-by: du-hua1024<duhua2@huawei.com> # message auto-generated for no-merge-commit merge: !1955 merge tmp2 into develop feat: 新增离线图编译执行 C++ 样例并修复 allocator 回调释放问题 Created-by: du-hua1024 Commit-by: du-hua1024 Merged-by: cann-robot Description: # Pull Request ## 描述 本 PR 包含三类变更: ### 1. 新增 GE C++ 离线图编译执行样例(examples/offline_compile_run/cpp/) - 覆盖单模型(Add 图)和 Bundle 模型(Add + Mul 图)两种场景 - 提供完整的 CMake 构建脚本(CMakeLists.txt)和一键执行脚本(run_sample.sh),支持 build_modelrun_infersample_and_run 等多个 target - 核心 API 流程:aclgrphBuildInitializeaclgrphBuildModel/aclgrphBundleBuildModelaclgrphSaveModel/aclgrphBundleSaveModelaclgrphBuildFinalize,推理通过 aclmdlLoadFromFile/aclmdlBundleLoadFromFile 执行 - 补充 README,与 Python 样例文档结构对齐 ### 2. 编码规范整改 - **ge_api_c_wrapper/c_offline_compile.cc + ge_api_c_wrapper_utils.h**:为离线编译 C Wrapper 接口的指针参数补充 const 修饰(char**const char**Graph*const Graph*int*const int*),同时修正函数声明的参数对齐格式,提升接口语义准确性 - **ir_proto_codec.cc**:将 GET_ATTR_JSON_FUNC(Str, std::string) 宏展开为显式函数,增加 AttrUtils::GetStr 返回空指针时的 null 检查,避免潜在的空指针解引用 - **examples/custom_es_api/run_sample.sh**:添加 set -e,确保脚本在任意命令失败时立即退出,增强健壮性 ### 3. 修复 allocator 回调对象提前释放的问题(_allocator_callback_adapter.py) - 原代码在 _on_allocator_destroy 中直接 pop 丢弃回调对象,未触发回调自身的析构逻辑 - 修复后先取出回调对象再显式调用清理,确保 C++ 侧 ~PyCallbackAllocator 触发时 Python 资源正常释放 ## 变更类型 - [ ] 🐛 Bug 修复 - [x] ✨ 新功能 - [ ] 💄 代码风格更新(格式化,局部变量) - [ ] ♻️ 重构(既不修复错误也不增加功能的代码变动) - [ ] 📦 构建过程或辅助工具的变动 - [x] 📝 文档内容更新 ## 关联的Issue 暂无 ## 如何测试 1. 安装 CANN toolkit 和 ops 包,执行 source /usr/local/Ascend/cann/set_env.sh 2. 进入 examples/offline_compile_run/cpp/ 目录 3. 运行 bash run_sample.sh -t sample_and_run,验证单模型编译与推理成功 4. 运行 bash run_sample.sh -t sample_and_run_bundle,验证 Bundle 编译与推理成功 5. 验证 add_sample.ombundle_sample.om 文件生成 6. 验证 allocator 回调修复:在有自定义 allocator 的场景下,析构时不再出现资源泄漏 ## 核对清单 - [x] 我的代码遵循了项目的代码风格 - [x] 我已对代码进行了自测 - [x] 我已更新了相关的文档 - [x] 我在标题中使用了合适的类型标签(如:feat:, fix:) - [x] 我已经详细阅读了贡献指南(CONTRIBUTING.md),并遵守了其中的所有规定,包括但不限于commit message的格式、无效commit的合并等 ## 其他信息 - C++ 样例与 Python 样例生成的 om 文件同名(add_sample.ombundle_sample.om),请勿在同一目录下混用 - run_sample.sh 使用 CMake 增量编译,多次执行不会清空构建目录 See merge request: cann/ge!19551 个月前