| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
【feat】NPUAffinityController support multiple rangs of affinity cpu core Co-authored-by: zhaoyu<nanzhaogang@qq.com> # message auto-generated for no-merge-commit merge: !34407 merge Affinity into master 【feat】NPUAffinityController support multiple rangs of affinity cpu core Created-by: zhaoyu65 Commit-by: zhaoyu Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 [#1816](https://gitcode.com/Ascend/pytorch/issues/1816) - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 ## 1、修改内容总体 本次 commit 的核心目的是让 **NPUAffinityController 支持绑定多个不连续的 CPU 核范围**。同时修改了lintrunner工具扫描出来的代码规范问题。 主要技术变更: - 将数据结构从 CoreIdRange {start, end} 改为 CoreIdList = std::set<CoreId>,支持离散/多段 CPU 核集合,set容器符合语义,不存在重复值 - 支持解析查出来的多段CPU亲和段 - 对GetAffinityCPUInfo.cpp和NPUAffinityController.cpp重构,优化函数圏复杂度,将cpp内部调用函数使用namespace或static关键词封装, --- ## 2、各文件修改的内容和目的 | 文件 | 修改内容 | 目的 | |------|----------|------| | **NPUAffinityController.h** | 将 CoreIdRange 结构体替换为 CoreIdList = std::set<CoreId>,新增 SetThreadAffinity(const CoreIdList) 接口 | 数据结构重构,支持多核集合 | | **NPUAffinityController.cpp** | 重构核心绑定逻辑:解析配置支持 npu0:0-1,npu0:4-9 多段格式;新增 formatCoreRange() 输出函数;重构 parseDeviceCoreRange() 解析多段范围 | 核心实现支持多段 CPU 核绑定 | | **GetAffinityCPUInfo.cpp** | 将 parseAffinityCPU() 改为 parseAffinityCores(),支持逗号分隔的多段范围;重构 GetExclusiveAffinityCPU() 的核分配逻辑 | DCMI 接口层适配新数据结构,避免重复初始化 | | **GetAffinityCPUInfo.h** | 简化接口,对其他cpp文件只保留 GetAffinityCores(int card_id)接口 | 接口统一 | | **Module.cpp** | Python 绑定增加对 PyList 参数的解析,支持python内部接口侧传入 [0, 1, 4, 5] 格式的核列表 | Python API 支持新参数类型 | | **affinity.py** | _set_thread_affinity() 支持 List[int] 或 List[List[int]] 参数,如 [[0,5], [8,10]] | Python 层 API 扩展 | | **torch_npu_schema.json** | 更新签名 Union[List[int], List[List[int]], NoneType] | 类型提示更新 | | **test_affinity.py** | 新增加多段CPU核相关测试用例 | 新增用例 | --- ## 3、修改后的影响 ### 功能增强 - **用户可配置多段 CPU 核范围**:如 CPU_AFFINITY_CONF='1,npu0:0-3,npu0:8-15',同一设备可绑定不连续的核,取并集 - **API 更灵活**:set_thread_affinity() 新增接受 [[0,5], [8,10]] 格式参数的功能 ### 行为变化 - 环境变量 CPU_AFFINITY_CONF 同一设备多次指定核范围会合并(如 npu0:0-1,npu0:4-9 绑定核 0,1,4,5,6,7,8,9) ### 代码改进 - 新增 formatCoreRange() 函数统一输出格式(如 0-3,8-15) - 代码结构更清晰:解析函数拆分为 parseNpuAffineMode()、parseLazyBindMode()、parseForceMode()、parseDeviceCoreRange() --- # 【资料变更】 在后续2.7.1分支的PR中修改 # 【接口变更】 CPU_AFFINITY_CONF环境变量和set_thread_affinity()接口变更方案已通过SEG例会评审,兼容旧版本; # 【功能验证】 自测OK  验证环境变量CPU_AFFINITY_CONF bash #!/bin/bash # 设置环境变量 export ASCEND_PROCESS_LOG_PATH=$(pwd) export ASCEND_GLOBAL_LOG_LEVEL=0 echo -e 'import torch\na=torch.tensor([1],device="npu")\nb=a+1\n' > add.py # 定义配置和期望值数组 configs=( "1,npu_affine:1,npu0:0-5" "1,npu_affine:1,npu0:0-5,npu1:6-7,npu2:8-8,npu2:10-11,npu0:12-19" "1,npu_affine:1,npu0:0-5,npu1:10-13,npu0:4-7" ) values=( "0-5" "0-5,12-19" "0-7" ) run_test() { local index=$1 local conf=$2 local expected_val=$3 export CPU_AFFINITY_CONF="$conf" # 清理旧日志,确保获取的是本次运行的日志 rm -rf debug/ # 执行测试脚本 python add.py # 检查 python 执行是否成功,可选 if [ $? -ne 0 ]; then echo "[ERROR] Index $index: python add.py failed." >> result.log return 1 fi # 提取 affinity 值 # 使用 find 避免 glob 匹配不到文件时的报错,或者保留原来的 glob 但确保目录存在 local log_file log_file=$(find debug/plog -name "*.log" 2>/dev/null | head -1) if [ -z "$log_file" ]; then echo "[ERROR] Index $index: No log file found in debug/plog/" >> result.log return 1 fi local affinity_line affinity_line=$(grep "Device 0 set acl_thread affinity to" "$log_file" 2>/dev/null | head -1) if [ -z "$affinity_line" ]; then echo "[ERROR] Index $index: Affinity line not found in log." >> result.log return 1 fi # 提取 "affinity to" 后面的具体值 local affinity_value # sed 提取最后一个非空字段,或者根据具体日志格式调整 affinity_value=$(echo "$affinity_line" | sed -n 's/.*affinity to \([^ ]*\).*/\1/p') # 去除可能的首尾空白字符 (trim) affinity_value=$(echo "$affinity_value" | xargs) # 比较实际值与期望值 if [ "$affinity_value" == "$expected_val" ]; then echo "测试环境变量 CPU_AFFINITY_CONF $conf: 的结果为:SUCCESS (Actual: ${affinity_value} == Expected: ${expected_val})" else echo "测试环境变量 CPU_AFFINITY_CONF $conf: 的结果为:FAIL (Actual: ${affinity_value} != Expected: ${expected_val})" fi } # 循环遍历配置 # 使用 C 风格的 for 循环以便同时获取索引 for ((i=0; i<${#configs[@]}; i++)); do run_test "$i" "${configs[$i]}" "${values[$i]}" done echo "All tests completed." 测试结果为:所有用例都通过  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!34407 | 4 个月前 | |
AI assist developer for python dt master Co-authored-by: aksksks<mengzichao@h-partners.com> # message auto-generated for no-merge-commit merge: !26538 merge master into master AI assist developer for python dt master Created-by: aksksks Commit-by: aksksks Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!26538 | 9 个月前 | |
AI assist developer for python dt master Co-authored-by: aksksks<mengzichao@h-partners.com> # message auto-generated for no-merge-commit merge: !26538 merge master into master AI assist developer for python dt master Created-by: aksksks Commit-by: aksksks Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!26538 | 9 个月前 | |
AI assist developer for python dt for master Co-authored-by: aksksks<mengzichao@h-partners.com> # message auto-generated for no-merge-commit merge: !27014 merge master into master AI assist developer for python dt for master Created-by: aksksks Commit-by: aksksks Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!27014 | 9 个月前 | |
refactor(inductor): remove upstreamed NPU compatibility patches Co-authored-by: srhust<hwxhewenxuan321@163.com> # message auto-generated for no-merge-commit merge: !43791 merge cleanup/remove-gpu-monkey-patches into master refactor(inductor): remove upstreamed NPU compatibility patches Created-by: srhust Commit-by: srhust Merged-by: ascend-robot Description: # 【合入来源】 关联 issue: https://gitcode.com/Ascend/pytorch/issues/3634 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [x] 重构优化 - [ ] 资料更新 # 〖修改方案〗 基于 PyTorch upstream 提供的 PrivateUse1 / out-of-tree backend 扩展机制, 将 NPU Inductor 中原有的设备相关 monkey patch 迁移到 DeviceOpOverrides、DeviceInterface 等统一 backend extension points。 同时将 PyTorch 版本差异收敛到 torch_npu/_compat 层: 业务代码不直接进行版本判断,统一通过 compat 接口访问对应能力。 兼容策略: - torch < 2.15:保留原有 legacy patch / mapping 行为。 - torch >= 2.15:使用 PyTorch upstream 提供的统一 backend extension points。 - 当最低支持 PyTorch 版本提升至 2.15 及以上后,可删除对应 legacy compat 实现。 具体修改如下。 1. 接入 C++ wrapper routing 扩展能力 - 在 NewNPUDeviceOpOverrides 中实现: python def uses_gpu_cpp_wrapper(self) -> bool: return True - 通过 PyTorch DeviceOpOverrides.uses_gpu_cpp_wrapper() 向 GraphLowering 提供 NPU C++ wrapper routing capability。 - torch < 2.15 通过 _compat 保留原 patch_codegen_with_cpp_wrapper 行为。 - 对应 upstream:pytorch/pytorch#190615。 2. 接入 device compute-unit 查询能力 - 在 NpuInterface 中实现: python @classmethod def get_multi_processor_count(cls, device=None) -> int: return cls.get_device_properties(device).vector_core_num - 通过 PyTorch DeviceInterface.get_multi_processor_count() 向 DeviceProperties.create() 提供 NPU compute-unit 数量。 - torch < 2.15 通过 _compat 保留原 patch_create_device_properties 行为。 - 对应 upstream:pytorch/pytorch#190615。 3. 接入 AOTI / C++ wrapper ATen DeviceType 扩展能力 - 在 NewNPUDeviceOpOverrides 中实现: python def aten_device_type(self) -> str: return "at::kPrivateUse1" - 通过 PyTorch DeviceOpOverrides.aten_device_type() 提供 NPU ATen DeviceType 映射。 - 新增 _compat.inductor.device_to_aten() 统一接口: - torch >= 2.15 调用 PyTorch upstream device_to_aten(); - torch < 2.15 继续使用 legacy DEVICE_TO_ATEN mapping。 - cpp_wrapper_npu.py 统一通过 _compat 接口获取 ATen DeviceType, 不直接依赖不同 PyTorch 版本下的内部实现。 - 对应 upstream:pytorch/pytorch#193904。 4. 接入 CodeCache system metadata 扩展能力 - 在 NpuInterface 中实现: python @classmethod def get_cache_system_info(cls): try: device_properties = get_device_properties_npu(current_device()) except (AssertionError, RuntimeError): return None return { "name": device_properties.name, "cann": torch.version.cann, } - 通过 PyTorch DeviceInterface.get_cache_system_info() 向 CacheBase.get_system() 提供 NPU device name 和 CANN version。 - 保证 NPU backend metadata 参与统一的 CodeCache system key 及 cache hash 生成。 - torch < 2.15 通过 _compat 保留原 patch_cache_base_get_system 行为。 - 对应 upstream:pytorch/pytorch#193908。 5. 收敛版本兼容逻辑 - 新增 torch_npu/_compat/inductor.py,统一管理上述 Inductor 版本兼容逻辑。 - 业务实现优先调用 _compat 层提供的统一接口,不在业务模块中 分散进行 PyTorch 版本判断。 - CURRENT_VERSION >= (2, 15) 使用 upstream contract; 旧版本继续保持原有 PTA 行为。 - 删除/收敛已由 upstream extension point 替代的版本相关 monkey patch 实现。 6. 同步测试及模块注册信息 - 增加 NPU C++ wrapper routing capability 测试。 - 增加 NPU ATen DeviceType / device_to_aten 测试。 - 增加 NPU compute-unit 查询测试。 - 更新 CodeCache 测试,覆盖 NPU device metadata、CANN version 及 cache hash。 - 覆盖 <2.15 legacy compat 与 >=2.15 upstream contract 的版本分支。 - 同步更新 test_public_bindings.py,使 public bindings 检查与 当前 Inductor 模块结构保持一致。 # 〖资料变更〗 不涉及。 # 〖接口变更〗 不涉及客户可见接口变更。 内部实现使用 PyTorch upstream 提供的以下 backend extension points: - DeviceOpOverrides.uses_gpu_cpp_wrapper() - DeviceInterface.get_multi_processor_count() - DeviceOpOverrides.aten_device_type() - DeviceInterface.get_cache_system_info() PTA 内部新增 _compat 统一适配层,用于隔离不同 PyTorch 版本下 Inductor backend contract 的差异,不新增客户可见 API。 # 〖功能验证〗 新增/更新以下 UT: 1. test/_inductor/test_npu_device.py - 验证 NewNPUDeviceOpOverrides.uses_gpu_cpp_wrapper() 返回 True。 - 验证 NewNPUDeviceOpOverrides.aten_device_type() 返回 at::kPrivateUse1。 - 验证 NPU ATen DeviceType 可通过统一 device_to_aten() 接口获取。 2. test/utils/test_dynamo_device.py - 验证 NpuInterface.get_multi_processor_count() 从 vector_core_num 获取 NPU compute-unit 数量。 3. test/_inductor/test_codecache.py - 验证 CacheBase.get_system()["device_interfaces"]["npu"] 包含 NPU device name 和 CANN version。 - 验证 NPU backend metadata 参与 CodeCache system hash 生成。 4. test/npu/test_public_bindings.py - 验证 public bindings 配置与当前 Inductor 模块结构保持一致。 兼容性验证: - torch < 2.15 使用 legacy compat 实现。 - torch >= 2.15 使用 PyTorch upstream backend extension points。 - compat 版本判断通过 PTA version compatibility checker 约束。 静态检查: - git diff --check 通过。 - python -m compileall 通过。 # 〖CheckList〗 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43791 | 11 天前 | |
AI assist developer for python dt for master Co-authored-by: aksksks<mengzichao@h-partners.com> # message auto-generated for no-merge-commit merge: !27014 merge master into master AI assist developer for python dt for master Created-by: aksksks Commit-by: aksksks Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!27014 | 9 个月前 | |
feat: Supports enabling environment variable log Co-authored-by: chenkun<chenkun82@huawei.com> # message auto-generated for no-merge-commit merge: !28110 merge master_feat_environ_log_v2 into master feat: Supports enabling environment variable log Created-by: kuhn7 Commit-by: chenkun Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** feature **What does this PR do / why do we need it**: Environment variable logging can be enabled by setting export TORCH_NPU_LOGS=env to help debug **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!28110 | 8 个月前 | |
AI assist developer for python dt for master Co-authored-by: aksksks<mengzichao@h-partners.com> # message auto-generated for no-merge-commit merge: !27014 merge master into master AI assist developer for python dt for master Created-by: aksksks Commit-by: aksksks Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!27014 | 9 个月前 | |
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 3 个月前 |
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 4 个月前 | ||
| 9 个月前 | ||
| 9 个月前 | ||
| 9 个月前 | ||
| 11 天前 | ||
| 9 个月前 | ||
| 8 个月前 | ||
| 9 个月前 | ||
| 3 个月前 |