Skip to content

Instantly share code, notes, and snippets.

@BassyKuo
Created December 29, 2017 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BassyKuo/2e119cb51d9f6bdd87a7f6bcbace58c0 to your computer and use it in GitHub Desktop.
Save BassyKuo/2e119cb51d9f6bdd87a7f6bcbace58c0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import threading
import GPUtil
import numpy as np
gpu_loading = []
num_threads = 2
th = {}
def main():
for th_id in range(num_threads):
th[th_id] = threading.Thread(target=network, args=(th_id,))
th[th_id].start()
# --- [ Waiting for all threads
for th_id in range(num_threads):
th[th_id].join()
# --- [ After all threads done
print ('===THE END===')
print ('averaged utilization:', np.mean(gpu_loading))
def network(idx):
if idx == 0:
gpus = GPUtil.getGPUs()
gpu_loading.append(gpus[1].load)
else:
# network testing
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment