Pull Request已成功合入, 合并人@ascend-robot
(感谢 chenweiheng 的贡献)变更摘要
本 PR 修复了 prof(profiling)开关在代码生成阶段被写死的问题。此前生成的 wrapper 代码把 prof_enabled 作为编译期常量(static const bool prof_enabled = ...)在生成时固化,导致运行期无法反映 profiler 的实际状态;本次改为在生成的代码中提供运行时可变全局变量 prof_enabled(默认 false)并通过导出的 set_prof_enabled 接口动态更新,同时在 Python 侧新增同步逻辑,在加载与每次运行时将当前 profiler 状态同步到动态库中,并补充了对应的代码生成测试断言。
主要改动
- prof 开关改为运行时可变: 在
_asc_codegen.py中,删除生成期根据ProfPathCreator().is_prof_inited拼装的编译期常量,改为static bool prof_enabled = false;,并新增导出的extern "C" void set_prof_enabled(uint8_t enabled)用于运行时修改该开关。 - 新增 prof 状态同步逻辑: 在
_kernel.py中新增_sync_prof_enabled(dl, lib_wrapper),通过ProfPathCreator().is_prof_inited获取当前 prof 状态并调用dl.set_prof_enabled,用按lib_wrapper缓存的_prof_enabled_cache避免重复设置;该函数在NpuInductorKernel的初始化(__init__)和每次运行(run)时都会被调用。 - 自动调优内核同步 prof 状态: 在
_autotune.py中,NpuInductorAutoTuneKernel引入_sync_prof_enabled并在其__init__与run中调用,确保自动调优路径下的内核同样能在运行时同步 prof 开关。 - 补充代码生成测试断言: 在
test_profiling_codegen.py中新增断言,验证生成的源码包含set_prof_enabled导出,且不再包含编译期常量static const bool prof_enabled。


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-Ascend/torchair | ✅ fu-hao-huawei, dingdairong (2/2) | ✅ fu-hao-huawei (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
chenweiheng, thanks for your pull request. All authors of the commits have signed the CLA. 👍


compile


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_x86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| 开发者测试 | smoke_npugraph_ex | ✅ | >>> |
| 流水线 | PR-pipeline_torchair_smoke | ✅ | >>> |
- smoke : 运行流水线


ascend docs pipeline is running...


✅ 跳过 docs ci 检查,没有需要检查的文档文件


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_x86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | codecheck_pre-commit | ✅ | >>> |
| pre-commit | ❌ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 流水线 | PR-pipeline_torchair | ❌ | >>> |
- compile : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


ascend docs pipeline is running...


✅ 跳过 docs ci 检查,没有需要检查的文档文件


compile


ascend docs pipeline is running...


ascend docs pipeline is running...


✅ 跳过 docs ci 检查,没有需要检查的文档文件


✅ 跳过 docs ci 检查,没有需要检查的文档文件


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_x86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | codecheck_pre-commit | ✅ | >>> |
| pre-commit | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 流水线 | PR-pipeline_torchair | ✅ | >>> |
- compile : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


/lgtm


/approve


修复prof开关写死问题