MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / NvidiaDevice

Class NvidiaDevice

tensorpack/utils/nvml.py:85–146  ·  view source on GitHub ↗

Represent a single GPUDevice

Source from the content-addressed store, hash-verified

83
84
85class NvidiaDevice(object):
86 """Represent a single GPUDevice"""
87
88 def __init__(self, hnd):
89 super(NvidiaDevice, self).__init__()
90 self.hnd = hnd
91
92 def memory(self):
93 """Memory information in bytes
94
95 Example:
96
97 >>> print(ctx.device(0).memory())
98 {'total': 4238016512L, 'used': 434831360L, 'free': 3803185152L}
99
100 Returns:
101 total/used/free memory in bytes
102 """
103 class GpuMemoryInfo(Structure):
104 _fields_ = [
105 ('total', c_ulonglong),
106 ('free', c_ulonglong),
107 ('used', c_ulonglong),
108 ]
109
110 c_memory = GpuMemoryInfo()
111 _check_return(_NVML.get_function(
112 "nvmlDeviceGetMemoryInfo")(self.hnd, byref(c_memory)))
113 return {'total': c_memory.total, 'free': c_memory.free, 'used': c_memory.used}
114
115 def utilization(self):
116 """Percent of time over the past second was utilized.
117
118 Details:
119 Percent of time over the past second during which one or more kernels was executing on the GPU.
120 Percent of time over the past second during which global (device) memory was being read or written
121
122 Example:
123
124 >>> print(ctx.device(0).utilization())
125 {'gpu': 4L, 'memory': 6L}
126
127 """
128 class GpuUtilizationInfo(Structure):
129
130 _fields_ = [
131 ('gpu', c_uint),
132 ('memory', c_uint),
133 ]
134
135 c_util = GpuUtilizationInfo()
136 _check_return(_NVML.get_function(
137 "nvmlDeviceGetUtilizationRates")(self.hnd, byref(c_util)))
138 return {'gpu': c_util.gpu, 'memory': c_util.memory}
139
140 def name(self):
141 buflen = 1024
142 buf = create_string_buffer(buflen)

Callers 1

deviceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected