Created
December 29, 2017 03:21
-
-
Save BassyKuo/2e119cb51d9f6bdd87a7f6bcbace58c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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