已合并
refactor(example): rename NPU_ARCH to NPU_SOC_VERSION with backward compat #1079
liu-wei创建于 7月2日
refactor(example): rename NPU_ARCH to NPU_SOC_VERSION with backward compat #1079
已合并
liu-wei创建于 7月2日
liu-wei
liu-wei成员
7月2日

描述

examples/fast_kernel_launch_example/ 里有两处需要改造,合并到同一个重构 PR:

改动 A:NPU_ARCH 重命名为 NPU_SOC_VERSION

PyTorch 官方 torch_npu 的同名环境变量 NPU_ARCH 在新版本里被复用为昇腾 SOC 版本号,原本"扩展模块编译目标架构"的语义已发生迁移。继续使用旧名容易在用户 shell / CI 环境里跟 torch_npu 的同名变量直接撞车。统一改成 NPU_SOC_VERSION 更贴合"芯片型号"的语义。

向后兼容策略:

  • 旧变量 NPU_ARCH 仍可读取,仅打印 deprecation 日志
  • CMake / Python 任一端能识别 NPU_SOC_VERSION 时优先使用,识别不到再回退到 NPU_ARCH

改动 B:README 文档同步 + sample code polish

  • README 新增 NPU_SOC_VERSION 三种芯片档位说明(Atlas A2 → ascend910b、Atlas A3 → ascend910_93、Ascend 950PR/950DT → ascend950)
  • 旧 NPU_ARCH 文档标注为 deprecated 但仍兼容
  • sample 代码块里 blockDim 变量名改为 numBlocks(语义更直接)
  • 标点 , → , 跟中文文档风格统一

变更清单

CMakeLists.txt (+10/-2)

  • NPU_ARCH 的 cache 读取逻辑替换为 NPU_SOC_VERSION + fallback(NPU_ARCH 仍能识别,fallback 到 ascend910b)

cmake/func.cmake (+2/-2)

  • recursive_add_subdirectory 宏变量引用从 NPU_ARCH 改成 NPU_SOC_VERSION

setup.py (+8/-4)

  • CMakeBuildCommand 的环境变量读取迁移,并加 deprecation 日志
  • 传给 cmake 的 -DNPU_ARCH=... 改为 -DNPU_SOC_VERSION=...

README.md (+8/-6)

  • 新增 NPU_SOC_VERSION env 文档 + 三种芯片档位映射
  • sample 代码 blockDim → numBlocks
  • 标点全角化

关联的Issue

  • 跟仓库 NPU_ARCH 弃用计划相关(待建 issue 跟踪 NPU_ARCH 兼容层完全移除的 release 计划)
  • 无具体关联 issue 编号

测试

  1. 新变量生效:

    cd examples/fast_kernel_launch_example
    export NPU_SOC_VERSION=ascend910_93
    python3 -m build --wheel -n
    ls dist/*.whl
    # 期望:构建成功,cp tag 跟当前 python 版本一致
    
  2. 旧变量兼容 + deprecation 日志:

    unset NPU_SOC_VERSION
    export NPU_ARCH=ascend910b
    python3 -m build --wheel -n
    # 期望:构建成功,setup.py 日志里看到 "NPU_ARCH is deprecated, please use NPU_SOC_VERSION."
    
  3. 多 Python 版本验证(cp39 / cp310 / cp311):

    for py in 3.9 3.10 3.11; do
      python$py -m venv venv-$py && source venv-$py/bin/activate
      python3 -m build --wheel -n
      ls dist/*.whl  # cp tag 应与 python$py --version 一致
      deactivate
    done
    
  4. 回退验证:

    • 都不设两个变量:默认 ascend910b
    • 同时设两个:NPU_SOC_VERSION 优先

文档更新

本 PR 本身就是 README 文档改动的一部分。其他无。

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 liu-wei 的贡献)
liu-weiliu-wei成员
7月2日 创建了 pull request,commit 804f52fb
CANN-robotCANN-robot成员
7月2日 添加了label:cann-cla/yes
liu-wei
liu-wei成员
7月2日 评论:

compile

likedislike
CANN-robot
CANN-robot成员
7月2日 评论:

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
*/*/README.md ✅ 杜慧萍, 陈娇, 周奇龙 (3/2) ✅ 杜慧萍, 陈娇 (2/1)
** ✅ 陈娇, gcw_kUomxQ2l, 周奇龙 (3/2) ✅ 陈娇, gcw_kUomxQ2l (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

liu-wei, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
liu-weiliu-wei成员
7月2日 预合并成功(commit_id: 9fbed2d603fa85c2d2b6e22d94865488dfbb94df)
liu-weiliu-wei成员
7月2日 修改了pull request 的描述
CANN-robotCANN-robot成员
7月2日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月2日 评论:

流水线任务触发成功
任务链接 [82d6c323f3874fbba8d07adf4b0a7a76][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5 ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Pre ✅ SUCCESS >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
UT_Test ❌ FAILED
PreSmoke_A900 ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>
likedislike
CANN-robot
CANN-robot成员
7月2日 评论:

流水线任务触发成功
任务链接 [b643d045609e4479a35b738734678288][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_checkpr ✅ SUCCESS
StaticCheck_codespell_check ✅ SUCCESS
StaticCheck_link_validity_check ✅ SUCCESS
StaticCheck_resource_existence_check ✅ SUCCESS
StaticCheck_tag_closed_check ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_codestyle ✅ SUCCESS >>>>>
codecheck_precommit ✅ SUCCESS >>>>> >>>>>

[2026-07-02 15:46:49]    CI执行结束

likedislike
CANN-robotCANN-robot成员
7月2日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7月2日 添加了label:ci-pipeline-failed
atomgit-bot
atomgit-bot
7月2日 评论:

变更摘要

本次重构将示例项目中的环境变量与 CMake 变量从 NPU_ARCH 重命名为 NPU_SOC_VERSION,并在 setup.py 中保留了对旧变量 NPU_ARCH 的向后兼容支持,同时输出弃用提示。这一改动主要影响 fast kernel 启动示例的构建配置流程。

主要改动

  • CMake 宏变量重命名:在 func.cmake 的 recursive_add_subdirectory 宏中,将 ${NPU_ARCH} 替换为 ${NPU_SOC_VERSION},使子目录查找逻辑使用新变量名。
  • 构建脚本变量优先级调整:在 setup.py 中,优先读取环境变量 NPU_SOC_VERSION;若未设置则回退到已弃用的 NPU_ARCH,并在检测到 NPU_ARCH 时输出 "NPU_ARCH is deprecated, please use NPU_SOC_VERSION." 的日志提示。
  • CMake 传参更新:setup.py 中调用 CMake 配置时,将 -DNPU_ARCH= 参数改为 -DNPU_SOC_VERSION=,确保与新变量名保持一致。
likedislike
不准确?
atomgit-bot
atomgit-bot
7月2日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
liu-wei
liu-wei成员
7月7日 评论:

compile

likedislike
liu-weiliu-wei成员
7月7日 预合并成功(commit_id: 1de174b86a63b8a35e1b02375a2e59e0991b66aa)
CANN-robotCANN-robot成员
7月7日 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
7月7日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月7日 评论:

流水线任务触发成功
任务链接 [3dc3428644154758863d1e5436aef559][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5 ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Pre ✅ SUCCESS >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_harmony-infer-chs-cv ✅ SUCCESS >>>>>
UT_Test ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-07-07 09:37:56]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
7月7日 评论:

流水线任务触发成功
任务链接 [908a21e9e1534cf1b511e804a692b8a9][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_checkpr ✅ SUCCESS
StaticCheck_codespell_check ✅ SUCCESS
StaticCheck_link_validity_check ✅ SUCCESS
StaticCheck_resource_existence_check ✅ SUCCESS
StaticCheck_tag_closed_check ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_codestyle ✅ SUCCESS >>>>>
codecheck_precommit ✅ SUCCESS >>>>> >>>>>

[2026-07-07 09:21:48]    CI执行结束

likedislike
CANN-robotCANN-robot成员
7月7日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7月7日 添加了label:ci-pipeline-passed
ZhaiPeiChao
ZhaiPeiChao成员
7月7日 评论:

/lgtm
/approve

likedislike
CANN-robot
CANN-robot成员
7月7日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
ZhaiPeiChao

likedislike
CANN-robot
CANN-robot成员
7月7日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
ZhaiPeiChao

likedislike
liu-wei
liu-wei成员
7月7日 评论:
likedislike
gitee-duhuiping成员
7月7日 评论:

/approve

likedislike
CANN-robot
CANN-robot成员
7月7日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
ZhaiPeiChao

likedislike
chenjiao成员
7月7日 评论:

/approve

likedislike
CANN-robot
CANN-robot成员
7月7日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
ZhaiPeiChao

likedislike
liu-weiliu-wei成员
7月7日 关联了issue:NPU_ARCH deprecation timelin更改
sunday成员
7月7日 评论:

/lgtm
/approve

likedislike
CANN-robot
CANN-robot成员
7月7日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
ZhaiPeiChao

likedislike
CANN-robot
CANN-robot成员
7月7日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
ZhaiPeiChao

likedislike
llimwang成员
7月8日 评论:

/approve

likedislike
CANN-robot
CANN-robot成员
7月8日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
王林木, ZhaiPeiChao

likedislike
liulun0308成员
7月8日 评论:

/approve

likedislike
CANN-robot
CANN-robot成员
7月8日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
王林木, ZhaiPeiChao

likedislike
CANN-robotCANN-robot成员
7月8日 添加了label:lgtmapproved
CANN-robotCANN-robot成员
7月8日 合入了pull request