X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=speed.py;h=e4add261984da7a5275ceb3401d75fa06c8413a2;hb=31ffed8a581c04094e8d2727c88de6e1d2c07a65;hp=f682a169076aca29f3f7b4b695bb55fc179b305d;hpb=31b3e7141d2acb0cb1ff298d2b7fca3911889f25;p=pytorch.git diff --git a/speed.py b/speed.py index f682a16..e4add26 100755 --- a/speed.py +++ b/speed.py @@ -4,20 +4,24 @@ import time, torch if torch.cuda.is_available(): device = torch.device('cuda') + sync = lambda: torch.cuda.synchronize() else: device = torch.device('cpu') + sync = lambda: None nb_runs = 10000 -d1, d2, d3 = 50000, 256, 512 +d1, d2, d3 = 2048, 2048, 2048 a, b = torch.rand(d1, d2).to(device), torch.rand(d2, d3).to(device) +sync() start_time = time.perf_counter() for k in range(nb_runs): c = a @ b +sync() duration = time.perf_counter() - start_time -nb_flop = float(nb_runs * d1 * d2 * d3) +nb_flop = float(nb_runs * d1 * d2 * d3 * 2) # 1 multiply-and-add is 2 ops speed = nb_flop / duration for u in [ '', 'K', 'M', 'G', 'T', 'P' ]: