Commit Graph
4 Commits
Author SHA1 Message Date
LiNuohang c1d2049682 [feat]mempool基本结构对齐pytorch
Co-authored-by: LiNuohang<linuohang@huawei.com>



# message auto-generated for no-merge-commit merge:
!39284 merge mempool-core into master

[feat]mempool基本结构对齐pytorch

Created-by: LiNuohang
Commit-by: LiNuohang
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->

# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新

# 【修改方案】
核心改动:将 MemPool 对自定义分配器的所有权从 thread-local 全局状态(MemPoolContext)改为由 PrivatePool 内部持有 shared_ptr<NPUAllocator>。
具体变更:
PrivatePool 新增 allocator_ 成员,分配/释放路径不再依赖全局状态,改为 pool->owner_PrivatePool->allocator()->raw_alloc/raw_delete
删除 MemPoolContext 类及其 thread-local 全局变量
MemPool API变更:allocator() 改为 use_count(),构造函数接收 shared_ptr 而非裸指针
API 重命名:_npu_endAllocateCurrentStreamToPool → _npu_endAllocateToPool
测试重构:将 mempool 测试集中到 test_npu_allocator.py,新增 alloc/free 配对验证和 allocator 先于 tensor 删除的回归测试

# 【资料变更】
删除 MemPoolContext 类及其 thread-local 全局变量
MemPool API变更:allocator() 改为 use_count(),构造函数接收 shared_ptr 而非裸指针
重命名:_npu_endAllocateCurrentStreamToPool → _npu_endAllocateToPool

# 【接口变更】
删除 MemPoolContext 类及其 thread-local 全局变量
MemPool API变更:allocator() 改为 use_count(),构造函数接收 shared_ptr 而非裸指针
重命名:_npu_endAllocateCurrentStreamToPool → _npu_endAllocateToPool

# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!39284
2026-07-02 19:35:37 +08:00
LiNuohang 033d3c1b6d [feat] support torch.accelerator
Co-authored-by: LiNuohang<linuohang@huawei.com>



# message auto-generated for no-merge-commit merge:
!35518 merge acc-m into master

[feat] support torch.accelerator

Created-by: LiNuohang
Commit-by: LiNuohang
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->

# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新

# 【修改方案】
对齐社区支持torch.accelerator接口

# 【资料变更】
涉及

# 【接口变更】
新增API/环境变量列表:
| --- | --- | --- |
| accelerator接口 | PyTorch开始支持版本 | PTA开始支持版本 |
| device_count | 2.6.0 | 已支持 |
| is_available | 2.6.0 | 已支持 |
| current_accelerator | 2.6.0 | 已支持 |
| set_device_index | 2.6.0 | 已支持 |
| set_device_idx | 2.6.0 | 已支持 |
| current_device_index | 2.6.0 | 已支持 |
| current_device_idx | 2.6.0 | 已支持 |
| get_device_capability | 2.12.0 | 本次支持2.13.0 |
| set_stream | 2.6.0 | 已支持 |
| current_stream | 2.6.0 | 已支持 |
| synchronize | 2.6.0 | 已支持 |
| device_index | 2.8.0 | 本次支持2.13.0 |
| Graph | | 不关注 |
| Memory
management | | |
| empty_cache | 2.9.1 | 本次支持2.13.0 |
| empty_host_cache | 2.12.0 | 本次支持2.13.0 |
| get_memory_info | 2.10.0 | 本次支持2.13.0 |
| max_memory_allocated | 2.9.1 | 本次支持2.13.0 |
| max_memory_reserved | 2.9.1 | 本次支持2.13.0 |
| memory_allocated | 2.9.1 | 本次支持2.13.0 |
| memory_reserved | 2.9.1 | 本次支持2.13.0 |
| memory_stats | 2.9.1 | 本次支持2.13.0 |
| reset_accumulated_memory_stats | 2.9.1 | 本次支持2.13.0 |
| reset_peak_memory_stats | 2.9.1 | 本次支持2.13.0 |

# 【功能验证】
新增UT,测试新增接口是否可用

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!35518
2026-06-24 15:08:25 +08:00
liupeng303 9b54c804d7 !22643 !9425 Provide interface such as getDeviceStatus, resetPeakStats for NP…
Merge pull request !22643 from liupeng303/master
2025-07-07 02:58:20 +00:00
杜金航 6c0149451e !9492 [feat] Add Pluggable NPU allocator backend.
Merge pull request !9492 from 杜金航/master
2024-02-08 02:07:01 +00:00