提交 c35b45ff 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!454 Pre-triggering the querying in the background and store for later use

Merge pull request !454 from LiHongzhang/fix_timeout
...@@ -16,15 +16,37 @@ ...@@ -16,15 +16,37 @@
import inspect import inspect
from ctypes import CDLL, Structure, byref, c_char, c_int, c_uint, c_ulong, c_ushort from ctypes import CDLL, Structure, byref, c_char, c_int, c_uint, c_ulong, c_ushort
from functools import lru_cache from functools import lru_cache, wraps
from threading import Thread
from mindinsight.sysmetric.common.log import logger from mindinsight.sysmetric.common.log import logger
try:
libsmi = CDLL('libdrvdsmi_host.so') def _timeout(seconds, default):
except OSError: """
logger.info('Failed to load libdrvdsmi_host.so.') The timeout decorator wait for specified seconds or return the default value.
libsmi = None
Args:
seconds (float): The specified seconds.
default (Any): The default value.
"""
def outer(fn):
def target(*args, **kwargs):
nonlocal default
default = fn(*args, **kwargs)
@wraps(fn)
def inner(*args, **kwargs):
thread = Thread(target=target, args=args, kwargs=kwargs)
thread.start()
thread.join(seconds)
return default
return inner
return outer
def libsmicall(*args, **kwargs): def libsmicall(*args, **kwargs):
...@@ -188,6 +210,7 @@ def dsmi_get_hbm_info(device_id): ...@@ -188,6 +210,7 @@ def dsmi_get_hbm_info(device_id):
} }
@_timeout(0.2, 0)
def dsmi_get_device_utilization_rate(device_id, device_type): def dsmi_get_device_utilization_rate(device_id, device_type):
""" """
Get device utilization rate, %. Get device utilization rate, %.
...@@ -279,3 +302,11 @@ def collect_npu(): ...@@ -279,3 +302,11 @@ def collect_npu():
'temperature': dsmi_get_device_temperature(device_id) 'temperature': dsmi_get_device_temperature(device_id)
}) })
return npus return npus
try:
libsmi = CDLL('libdrvdsmi_host.so')
Thread(target=collect_npu).start()
except OSError:
logger.info('Failed to load libdrvdsmi_host.so.')
libsmi = None
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册