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

Method worker

tensorpack/callbacks/prof.py:122–159  ·  view source on GitHub ↗

Args: devices (list[int])

(evt, rst_queue, stop_evt, devices)

Source from the content-addressed store, hash-verified

120
121 @staticmethod
122 def worker(evt, rst_queue, stop_evt, devices):
123 """
124 Args:
125 devices (list[int])
126 """
127 try:
128 with NVMLContext() as ctx:
129 devices = [ctx.device(i) for i in devices]
130 while True:
131 evt.wait() # start epoch
132 evt.clear()
133 if stop_evt.is_set(): # or on exit
134 return
135
136 stats = np.zeros((len(devices),), dtype='f4')
137 cnt = 0
138 while True:
139 time.sleep(1)
140
141 data = [d.utilization()['gpu'] for d in devices]
142 data = list(map(float, data))
143 stats += data
144 cnt += 1
145
146 if evt.is_set(): # stop epoch
147 if stop_evt.is_set(): # or on exit
148 return
149 if cnt > 1:
150 # Ignore the last datapoint. Usually is zero, makes us underestimate the util.
151 stats -= data
152 cnt -= 1
153 rst_queue.put(stats / cnt)
154 evt.clear()
155 break
156 except Exception:
157 logger.exception("Exception in GPUUtilizationTracker.worker")
158 rst_queue.put(-1)
159 return
160
161
162# Can add more features from tfprof

Callers

nothing calls this directly

Calls 4

NVMLContextClass · 0.85
deviceMethod · 0.80
utilizationMethod · 0.80
putMethod · 0.80

Tested by

no test coverage detected