fix: [BugFix] API compatibility is maintained with CUDA
This commit is contained in:
@@ -169,6 +169,13 @@ class TorchNPUApiTestCase(TestCase):
|
||||
def test_npu_get_device_name(self):
|
||||
res = torch_npu.npu.get_device_name(0)
|
||||
self.assertIsInstance(res, str)
|
||||
res = torch_npu.npu.get_device_name()
|
||||
self.assertIsInstance(res, str)
|
||||
res = torch_npu.npu.get_device_name("npu:0")
|
||||
self.assertIsInstance(res, str)
|
||||
device = torch.device("npu:0")
|
||||
res = torch_npu.npu.get_device_name(device)
|
||||
self.assertIsInstance(res, str)
|
||||
|
||||
def test_npu_get_device_properties(self):
|
||||
name = torch_npu.npu.get_device_properties(0).name
|
||||
|
||||
@@ -157,14 +157,16 @@ def current_device():
|
||||
torch_npu.npu._lazy_init()
|
||||
return torch_npu._C._npu_getDevice()
|
||||
|
||||
def get_device_name(device_id: int):
|
||||
def get_device_name(device_name=None):
|
||||
device_id = _get_device_index(device_name, optional=True)
|
||||
if device_id < 0 or device_id >= device_count():
|
||||
raise AssertionError("Invalid device id")
|
||||
torch_npu.npu._lazy_init()
|
||||
device_prop = torch_npu._C._npu_getDeviceProperties(device_id)
|
||||
return device_prop.name
|
||||
|
||||
def get_device_properties(device_id: int):
|
||||
def get_device_properties(device_name=None):
|
||||
device_id = _get_device_index(device_name, optional=True)
|
||||
if device_id < 0 or device_id >= device_count():
|
||||
raise AssertionError("Invalid device id")
|
||||
torch_npu.npu._lazy_init()
|
||||
|
||||
Reference in New Issue
Block a user