已合并
fix: 统一管理 Python 解释器生命周期 #3631
duhua创建于 6月22日
fix: 统一管理 Python 解释器生命周期 #3631
已合并
Pull Request已成功合入, 合并人@CANN-robot
(感谢 duhua 的贡献)6月22日 添加了label:enhancement
6月22日 添加了label:stat/needs-squash
6月22日 添加了label:cann-cla/yes
CANN-robot
6月22日 评论:
6月22日 评论:
Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-cann/ge | ✅ yangyongqiang0606, kobemini, stevenaw0 (3/2) | ✅ yangyongqiang0606 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
du-hua1024, thanks for your pull request. All authors of the commits have signed the CLA. 👍


此处折叠了502条消息 查看更多
6月26日 添加了label:lgtm
yangyongqiang
6月26日 评论:
6月26日 评论:
/lgtm


yangyongqiang
6月26日 评论:
6月26日 评论:
/approve


6月26日 添加了label:approved
6月26日 合入了pull request
Pull Request
描述
当前 TBE、Python Pass 等多处依赖 Python 解释器,本 PR 引入
GePythonRuntimeManager,在 GE 各初始化入口统一探测、加载 libpython 并管理 Python 解释器生命周期,为 Python Fusion Pass 等能力提供一致的运行时基础。主要变更:
1. 新增
GePythonRuntimeManager(base/common/python_runtime/)ge_python_runtime_manager.h:管理器类定义,提供EnsureReady()/ShutdownProcess()接口ge_python_runtime_manager.cc:管理器实现,包含EnsureReadyLocked()、FinalizeOwnedInterpreterLocked()等核心逻辑ge_python_runtime_manager_helper.h:辅助头文件,包含 Python C API 类型定义、符号常量、探测脚本及inline工具函数(ResolvePythonCApi、EnsureLibpythonLoaded、ProbePythonRuntimeFromCommand等)python3/python并解析 libpython 路径,通过dlopen加载 Python C API2. 接入 GE 初始化链路
GEInitializeV2/GEFinalizeV2(api/session/client/ge_api_v2.cc)GeGenerator::Initialize(compiler/api/generator/ge_generator.cc)aclgrphBuildInitializeImpl/aclgrphBuildFinalize(compiler/api/aclgrph/ge_ir_build.cc)api/atc/main_impl.cc):GenerateModel、GenerateSingleOp等入口在GELib::Initialize前调用EnsureReady(),失败/退出路径补充ShutdownProcess()3. 测试更新
ge_python_runtime_unittest.cc,覆盖 attach 已有解释器、owned interpreter 初始化与 shutdown 场景fusion_pass_executor_unittest.cc:添加python_pass_loaded_状态追踪,SetUp/TearDown 仅在加载过 Python pass 时调用UnloadPythonPasses()ge_generator_unittest.cc、ge_api_v2_unittest.cc、ge_ir_build_unittest.cc等,在 teardown 中调用ShutdownProcess()避免用例间状态污染test_main.cc、rt2_test_main.cc、dump_test_fixture.h)添加ShutdownProcess()test.cc、init_ge.h、dflow_api_unittest.cc、ge_api_dflow_unittest.cc)添加GEFinalize()调用scoped_unset_ld_preload.h辅助类,用于ge_running_env_test中临时清除LD_PRELOAD环境变量变更类型
关联的Issue
无
如何测试
[GePythonRuntime] Loaded libpython或Initialize owned interpreter)ge_python_runtime_unittest验证 attach/owned interpreter 生命周期管理fusion_pass_executor_unittest验证 Python pass 注册与卸载逻辑核对清单
其他信息
无