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
74 lines
1.9 KiB
Python
74 lines
1.9 KiB
Python
import threading
|
|
|
|
import torch
|
|
from torch.testing._internal.common_distributed import MultiProcessTestCase
|
|
from torch.testing._internal.common_utils import run_tests
|
|
|
|
import torch_npu
|
|
|
|
|
|
class TestDevice(MultiProcessTestCase):
|
|
def setUp(self):
|
|
super().setUp()
|
|
self._spawn_processes()
|
|
|
|
@property
|
|
def world_size(self):
|
|
return 1
|
|
|
|
def test_event_create(self):
|
|
a = torch.full((3, 4), float(0), device='npu:0')
|
|
e = torch.npu.Event()
|
|
s = torch.npu.Stream()
|
|
|
|
def target_fuc(result):
|
|
e.record(s)
|
|
e.synchronize()
|
|
result[0] = 1
|
|
|
|
result = [0]
|
|
t = threading.Thread(target=target_fuc, args=(result, ))
|
|
t.start()
|
|
t.join()
|
|
self.assertEqual(result[0], 1)
|
|
|
|
def test_event_isinstance(self):
|
|
npu_event = torch.npu.Event()
|
|
self.assertIsInstance(npu_event, torch.npu.Event)
|
|
self.assertIsInstance(npu_event, torch.Event)
|
|
# Check whether torch_npu.npu.Event is a subclass of torch.Event
|
|
self.assertTrue(issubclass(torch_npu.npu.Event, torch.Event))
|
|
|
|
def test_stream_create(self):
|
|
s = torch_npu._C._npu_getCurrentStream(0)
|
|
|
|
def test_tensor(self):
|
|
a = torch.full((3, 4), float(0), device='npu:0')
|
|
|
|
def target_fuc(result):
|
|
b = torch.full((3, 4), float(0), device='npu:0')
|
|
result[0] = 1
|
|
|
|
result = [0]
|
|
t = threading.Thread(target=target_fuc, args=(result, ))
|
|
t.start()
|
|
t.join()
|
|
self.assertEqual(result[0], 1)
|
|
|
|
def test_storage(self):
|
|
s = torch.npu.Stream()
|
|
|
|
def target_fuc(result):
|
|
b = torch.npu.FloatStorage(10)
|
|
result[0] = 1
|
|
|
|
result = [0]
|
|
t = threading.Thread(target=target_fuc, args=(result, ))
|
|
t.start()
|
|
t.join()
|
|
self.assertEqual(result[0], 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
run_tests()
|