本文整理汇总了Python中pynvml.nvmlDeviceGetUtilizationRates方法的典型用法代码示例。如果您正苦于以下问题:Python pynvml.nvmlDeviceGetUtilizationRates方法的具体用法?Python pynvml.nvmlDeviceGetUtilizationRates怎么用?Python pynvml.nvmlDeviceGetUtilizationRates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pynvml
的用法示例。
在下文中一共展示了pynvml.nvmlDeviceGetUtilizationRates方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getFreeId
# 需要导入模块: import pynvml [as 别名]
# 或者: from pynvml import nvmlDeviceGetUtilizationRates [as 别名]
def getFreeId():
import pynvml
pynvml.nvmlInit()
def getFreeRatio(id):
handle = pynvml.nvmlDeviceGetHandleByIndex(id)
use = pynvml.nvmlDeviceGetUtilizationRates(handle)
ratio = 0.5*(float(use.gpu+float(use.memory)))
return ratio
deviceCount = pynvml.nvmlDeviceGetCount()
available = []
for i in range(deviceCount):
if getFreeRatio(i)<70:
available.append(i)
gpus = ''
for g in available:
gpus = gpus+str(g)+','
gpus = gpus[:-1]
return gpus
示例2: gpu_info
# 需要导入模块: import pynvml [as 别名]
# 或者: from pynvml import nvmlDeviceGetUtilizationRates [as 别名]
def gpu_info(self):
# pip install nvidia-ml-py3
if len(self.gpu_ids) >= 0 and torch.cuda.is_available():
try:
import pynvml
pynvml.nvmlInit()
self.config_dic['gpu_driver_version'] = pynvml.nvmlSystemGetDriverVersion()
for gpu_id in self.gpu_ids:
handle = pynvml.nvmlDeviceGetHandleByIndex(gpu_id)
gpu_id_name = "gpu%s" % gpu_id
mem_info = pynvml.nvmlDeviceGetMemoryInfo(handle)
gpu_utilize = pynvml.nvmlDeviceGetUtilizationRates(handle)
self.config_dic['%s_device_name' % gpu_id_name] = pynvml.nvmlDeviceGetName(handle)
self.config_dic['%s_mem_total' % gpu_id_name] = gpu_mem_total = round(mem_info.total / 1024 ** 3, 2)
self.config_dic['%s_mem_used' % gpu_id_name] = gpu_mem_used = round(mem_info.used / 1024 ** 3, 2)
# self.config_dic['%s_mem_free' % gpu_id_name] = gpu_mem_free = mem_info.free // 1024 ** 2
self.config_dic['%s_mem_percent' % gpu_id_name] = round((gpu_mem_used / gpu_mem_total) * 100, 1)
self._set_dict_smooth('%s_utilize_gpu' % gpu_id_name, gpu_utilize.gpu, 0.8)
# self.config_dic['%s_utilize_gpu' % gpu_id_name] = gpu_utilize.gpu
# self.config_dic['%s_utilize_memory' % gpu_id_name] = gpu_utilize.memory
pynvml.nvmlShutdown()
except Exception as e:
print(e)
示例3: __query_util
# 需要导入模块: import pynvml [as 别名]
# 或者: from pynvml import nvmlDeviceGetUtilizationRates [as 别名]
def __query_util(handle):
"""Query information on the utilization of a GPU.
Arguments:
handle:
NVML device handle.
Returns:
summaries (:obj:`dict`):
Dictionary containing the memory values for ['mem_util', 'gpu_util'].
All values are given as integers in the range (0, 100).
"""
# Query information on the GPU utilization.
util = nvml.nvmlDeviceGetUtilizationRates(handle)
summaries = dict()
# Percent of time over the past second during which global (device) memory was being
# read or written.
summaries['mem_util'] = util.memory
# Percent of time over the past second during which one or more kernels was executing
# on the GPU.
summaries['gpu_util'] = util.gpu
return summaries
示例4: getFreeId
# 需要导入模块: import pynvml [as 别名]
# 或者: from pynvml import nvmlDeviceGetUtilizationRates [as 别名]
def getFreeId():
import pynvml
pynvml.nvmlInit()
def getFreeRatio(id):
handle = pynvml.nvmlDeviceGetHandleByIndex(id)
use = pynvml.nvmlDeviceGetUtilizationRates(handle)
ratio = 0.5 * (float(use.gpu + float(use.memory)))
return ratio
deviceCount = pynvml.nvmlDeviceGetCount()
available = []
for i in range(deviceCount):
if getFreeRatio(i) < 70:
available.append(i)
gpus = ''
for g in available:
gpus = gpus + str(g) + ','
gpus = gpus[:-1]
return gpus
示例5: get_appropriate_cuda
# 需要导入模块: import pynvml [as 别名]
# 或者: from pynvml import nvmlDeviceGetUtilizationRates [as 别名]
def get_appropriate_cuda(task_scale='s'):
if task_scale not in {'s','m','l'}:
logger.info('task scale wrong!')
exit(2)
import pynvml
pynvml.nvmlInit()
total_cuda_num = pynvml.nvmlDeviceGetCount()
for i in range(total_cuda_num):
logger.info(i)
handle = pynvml.nvmlDeviceGetHandleByIndex(i) # 这里的0是GPU id
memInfo = pynvml.nvmlDeviceGetMemoryInfo(handle)
utilizationInfo = pynvml.nvmlDeviceGetUtilizationRates(handle)
logger.info(i, 'mem:', memInfo.used / memInfo.total, 'util:',utilizationInfo.gpu)
if memInfo.used / memInfo.total < 0.15 and utilizationInfo.gpu <0.2:
logger.info(i,memInfo.used / memInfo.total)
return 'cuda:'+str(i)
if task_scale=='s':
max_memory=2000
elif task_scale=='m':
max_memory=6000
else:
max_memory = 9000
max_id = -1
for i in range(total_cuda_num):
handle = pynvml.nvmlDeviceGetHandleByIndex(0) # 这里的0是GPU id
memInfo = pynvml.nvmlDeviceGetMemoryInfo(handle)
utilizationInfo = pynvml.nvmlDeviceGetUtilizationRates(handle)
if max_memory < memInfo.free:
max_memory = memInfo.free
max_id = i
if id == -1:
logger.info('no appropriate gpu, wait!')
exit(2)
return 'cuda:'+str(max_id)
# if memInfo.used / memInfo.total < 0.5:
# return
示例6: utilization_for
# 需要导入模块: import pynvml [as 别名]
# 或者: from pynvml import nvmlDeviceGetUtilizationRates [as 别名]
def utilization_for(device_handle):
"""Get GPU device consumption in percent
Percent of time over the past sample period during which one or more kernels was executing on the GPU.
"""
try:
return pynvml.nvmlDeviceGetUtilizationRates(device_handle).gpu
except pynvml.NVMLError:
return None
示例7: mem_utilization_for
# 需要导入模块: import pynvml [as 别名]
# 或者: from pynvml import nvmlDeviceGetUtilizationRates [as 别名]
def mem_utilization_for(device_handle):
"""
Percent of time over the past sample period during which global (device) memory was being read or written.
"""
try:
return pynvml.nvmlDeviceGetUtilizationRates(device_handle).memory
except pynvml.NVMLError:
return None
示例8: query_gpu
# 需要导入模块: import pynvml [as 别名]
# 或者: from pynvml import nvmlDeviceGetUtilizationRates [as 别名]
def query_gpu(handle: int) -> Dict:
memory = pynvml.nvmlDeviceGetMemoryInfo(handle) # in Bytes
utilization = pynvml.nvmlDeviceGetUtilizationRates(handle)
return {
"gpu_{}_memory_free".format(handle): int(memory.free),
"gpu_{}_memory_used".format(handle): int(memory.used),
"gpu_{}_utilization".format(handle): utilization.gpu,
}
示例9: _monitor
# 需要导入模块: import pynvml [as 别名]
# 或者: from pynvml import nvmlDeviceGetUtilizationRates [as 别名]
def _monitor(self):
pynvml.nvmlInit()
self._find_gpu()
current_sample = []
while not self.should_stop:
used_cpu = None
used_cpumem = None
used_gpu = None
used_gpumem = None
cpu_process = psutil.Process(self.pid)
used_cpu = cpu_process.cpu_percent() / psutil.cpu_count() # CPU utilization in %
used_cpumem = cpu_process.memory_info().rss // (1024*1024) # Memory use in MB
gpu_processes = pynvml.nvmlDeviceGetComputeRunningProcesses(self.gpu)
for gpu_process in gpu_processes:
if gpu_process.pid == self.pid:
used_gpumem = gpu_process.usedGpuMemory // (1024*1024) # GPU memory use in MB
break
if self.accounting_enabled:
try:
stats = pynvml.nvmlDeviceGetAccountingStats(self.gpu, self.pid)
used_gpu = stats.gpuUtilization
except pynvml.NVMLError: # NVMLError_NotFound
pass
if not used_gpu:
util = pynvml.nvmlDeviceGetUtilizationRates(self.gpu)
used_gpu = util.gpu / len(gpu_processes) # Approximate based on number of processes
current_sample.append((used_cpu, used_cpumem, used_gpu, used_gpumem))
time.sleep(self.sampling_rate)
self.stats.append([round(sum(x) / len(x)) for x in zip(*current_sample)])
pynvml.nvmlShutdown()
示例10: _crawl_in_system
# 需要导入模块: import pynvml [as 别名]
# 或者: from pynvml import nvmlDeviceGetUtilizationRates [as 别名]
def _crawl_in_system(self):
'''
nvidia-smi returns following: MEMORY, UTILIZATION, ECC, TEMPERATURE,
POWER, CLOCK, COMPUTE, PIDS, PERFORMANCE, SUPPORTED_CLOCKS,
PAGE_RETIREMENT, ACCOUNTING
currently, following are requested based on dlaas requirements:
utilization.gpu, utilization.memory,
memory.total, memory.free, memory.used
nvidia-smi --query-gpu=utilization.gpu,utilization.memory,\
memory.total,memory.free,memory.used --format=csv,noheader,nounits
'''
if self._init_nvml() == -1:
return
self.inspect_arr = exec_dockerps()
num_gpus = pynvml.nvmlDeviceGetCount()
for gpuid in range(0, num_gpus):
gpuhandle = pynvml.nvmlDeviceGetHandleByIndex(gpuid)
temperature = pynvml.nvmlDeviceGetTemperature(
gpuhandle, pynvml.NVML_TEMPERATURE_GPU)
memory = pynvml.nvmlDeviceGetMemoryInfo(gpuhandle)
mem_total = memory.total / 1024 / 1024
mem_used = memory.used / 1024 / 1024
mem_free = memory.free / 1024 / 1024
power_draw = pynvml.nvmlDeviceGetPowerUsage(gpuhandle) / 1000
power_limit = pynvml.nvmlDeviceGetEnforcedPowerLimit(
gpuhandle) / 1000
util = pynvml.nvmlDeviceGetUtilizationRates(gpuhandle)
util_gpu = util.gpu
util_mem = util.memory
entry = {
'utilization': {'gpu': util_gpu, 'memory': util_mem},
'memory': {'total': mem_total, 'free': mem_free,
'used': mem_used},
'temperature': temperature,
'power': {'draw': power_draw, 'limit': power_limit}
}
key = self._get_feature_key(gpuhandle, gpuid)
if gpuid == num_gpus - 1:
self._shutdown_nvml()
yield (key, entry, 'gpu')
return
示例11: measure_cpu_gpu_instant_load
# 需要导入模块: import pynvml [as 别名]
# 或者: from pynvml import nvmlDeviceGetUtilizationRates [as 别名]
def measure_cpu_gpu_instant_load():
# Get current cpu gpu load, as
# load = [rank, cpu_load, nvidia_device_id, gpu_load]
# result_arr: [load, load, ...]
if cg_load_backend_ok:
global gpu_a_load
global gpu_m_count
global p_handler
cpu_load = p_handler.cpu_percent()
gpu_m_count += 1
try:
comm = current_communicator()
if comm:
index = comm.local_rank
elif 'cuda' in str(nn.get_current_context().backend):
index = 0
else:
raise Exception
handler = pynvml.nvmlDeviceGetHandleByIndex(index)
gpu_load = [
[index, pynvml.nvmlDeviceGetUtilizationRates(handler).gpu]]
if index in gpu_a_load.keys():
gpu_a_load[index]['name'] = pynvml.nvmlDeviceGetName(
handler).decode("utf-8")
o_load = gpu_a_load[index]['load']
n_load = gpu_load[0][1]
gpu_a_load[index]['load'] = (
(gpu_m_count - 1) * o_load + n_load) / gpu_m_count
else:
gpu_a_load[index] = {
'name': pynvml.nvmlDeviceGetName(handler).decode("utf-8"),
'load': gpu_load[0][1]
}
except Exception:
gpu_load = [[-1, -1]]
callback.update_status(
('cpu_gpu_load', collect_and_shape_result(cpu_load, gpu_load)))