add torch.npu.get_device_capability, torch.npu.aclnn.version new

interface

dd clear code

dd npu:0处理

dd update testcase
This commit is contained in:
guanlongfeng
2023-04-23 17:35:22 +08:00
parent ac336f97d1
commit 0a57755011
6 changed files with 69 additions and 4 deletions
+16 -2
View File
@@ -183,7 +183,21 @@ class TorchNPUApiTestCase(TestCase):
total_memory = torch_npu.npu.get_device_properties(0).total_memory
self.assertIsInstance(total_memory, int)
def test_npu_get_device_capability(self):
res = torch_npu.npu.get_device_capability()
self.assertEqual(res, None)
res = torch_npu.npu.get_device_capability(0)
self.assertEqual(res, None)
name = torch_npu.npu.get_device_properties(0).name
res = torch_npu.npu.get_device_capability(name)
self.assertEqual(res, None)
device = torch_npu.npu.device("npu")
res = torch_npu.npu.get_device_capability(device)
self.assertEqual(res, None)
def test_npu_get_aclnn_version(self):
res = torch_npu.npu.aclnn.version()
self.assertEqual(res, None)
if __name__ == "__main__":
run_tests()
+1
View File
@@ -36,6 +36,7 @@ except ImportError as e:
else:
traceback.print_exc()
import torch_npu.npu.amp
import torch_npu.npu.aclnn
import torch_npu.distributed
import torch_npu._C
+2 -2
View File
@@ -17,7 +17,7 @@
__all__ = [
"native_device", "npu_device", "is_initialized", "_lazy_call", "_lazy_init", "init", "set_dump",
"synchronize", "device_count", "set_device", "current_device", "get_device_name",
"get_device_properties", "_get_device_index", "is_available", "device", "device_of",
"get_device_properties", "get_device_capability", "_get_device_index", "is_available", "device", "device_of",
"stream", "current_stream", "default_stream", "init_dump",
"finalize_dump", "set_dump", "manual_seed", "manual_seed_all",
"seed", "seed_all", "initial_seed", "_free_mutex", "caching_allocator_alloc",
@@ -43,7 +43,7 @@ from .device import __device__ as native_device
from .device import __npu_device__ as npu_device
from .utils import (is_initialized, _lazy_call, _lazy_init, init, set_dump,
synchronize, device_count, set_device, current_device, get_device_name,
get_device_properties, _get_device_index, is_available, device, device_of,
get_device_properties, get_device_capability, _get_device_index, is_available, device, device_of,
stream, current_stream, default_stream, init_dump,
finalize_dump, set_dump, _in_bad_fork, get_npu_overflow_flag,
clear_npu_overflow_flag)
+16
View File
@@ -0,0 +1,16 @@
# Copyright (c) 2023 Huawei Technologies Co., Ltd
# All rights reserved.
#
# Licensed under the BSD 3-Clause License (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://opensource.org/licenses/BSD-3-Clause
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .backends import version
+24
View File
@@ -0,0 +1,24 @@
# Copyright (c) 2023, Huawei Technologies.All rights reserved.
#
# Licensed under the BSD 3-Clause License (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://opensource.org/licenses/BSD-3-Clause
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import warnings
def version():
"""Currently, the ACLNN version is not available and does not support it.
By default, it returns None.
"""
warnings.warn("torch_npu.npu.aclnn.version isn't implemented!")
return None
+10
View File
@@ -19,6 +19,7 @@ import traceback
import contextlib
import threading
from multiprocessing.util import register_after_fork as _register_after_fork
import warnings
import torch
import torch._six
@@ -172,6 +173,15 @@ def get_device_properties(device_name=None):
torch_npu.npu._lazy_init()
return torch_npu._C._npu_getDeviceProperties(device_id)
def get_device_capability(device=None):
r"""Query the minor and major data of device. Cann does not
have a corresponding concept and is not supported. By default, it returns None
"""
warnings.warn("torch_npu.npu.get_device_capability isn't implemented!")
return None
def _get_device_index(device, optional=False):
r"""Gets the device index from :attr:`device`, which can be a torch.device
object, a Python integer, or ``None``.