5 if torch.cuda.is_available():
6 device = torch.device('cuda')
8 device = torch.device('cpu')
11 d1, d2, d3 = 50000, 256, 512
13 a, b = torch.rand(d1, d2).to(device), torch.rand(d2, d3).to(device)
15 start_time = time.perf_counter()
16 for k in range(nb_runs):
18 duration = time.perf_counter() - start_time
20 nb_flop = float(nb_runs * d1 * d2 * d3)
21 speed = nb_flop / duration
23 for u in [ '', 'K', 'M', 'G', 'T', 'P' ]:
27 print(f'{speed:.02f} {u}flops on {device}')