busy / busy.py
lhpku20010120's picture
Upload busy.py
672b9f6 verified
raw
history blame contribute delete
819 Bytes
import torch
import time
from multiprocessing import Pool, set_start_method
def run_on_single_gpu(device):
a = torch.randn(1000,1000).cuda(device)
b = torch.randn(1000,1000).cuda(device)
ta = a
tb = b
while True:
a = ta
b = tb
a = torch.sin(a)
b = torch.sin(b)
a = torch.cos(a)
b = torch.cos(b)
a = torch.tan(a)
b = torch.tan(b)
a = torch.exp(a)
b = torch.exp(b)
a = torch.log(a)
b = torch.log(b)
b = torch.matmul(a, b)
#time.sleep(0.000005)
if __name__ == '__main__':
set_start_method('spawn')
print('start running')
num_gpus = torch.cuda.device_count()
pool = Pool(processes=num_gpus)
pool.map(run_on_single_gpu, range(num_gpus))
pool.close()
pool.join()