Skip to content

Commit a6d83d7

Browse files
author
Thomas Klijnsma
committed
ran black on script
1 parent b7fecb7 commit a6d83d7

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

scripts/performance.py

+25-8
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,56 @@
33
import torch_cmspepr
44
import torch_cluster
55
import tqdm
6-
gpu = torch.device('cuda')
6+
7+
gpu = torch.device("cuda")
78

89
k = 10
910

11+
1012
def gen(cuda=False):
1113
# 10k nodes with 5 node features
1214
x = torch.rand((10000, 5))
1315
# Split nodes over 4 events with 2500 nodes/evt
1416
batch = torch.repeat_interleave(torch.arange(4), 2500)
15-
if cuda: x, batch = x.to(gpu), batch.to(gpu)
17+
if cuda:
18+
x, batch = x.to(gpu), batch.to(gpu)
1619
return x, batch
1720

21+
1822
def profile(name, unit):
1923
t0 = time.time()
20-
for _ in tqdm.tqdm(range(10)): unit()
21-
print(f'{name} took {(time.time() - t0)/100.} sec/evt')
24+
for _ in tqdm.tqdm(range(10)):
25+
unit()
26+
print(f"{name} took {(time.time() - t0)/100.} sec/evt")
27+
2228

2329
def cpu_cmspepr():
2430
x, batch = gen()
2531
torch_cmspepr.knn_graph(x, k, batch=batch)
26-
profile('CPU (torch_cmspepr)', cpu_cmspepr)
32+
33+
34+
profile("CPU (torch_cmspepr)", cpu_cmspepr)
35+
2736

2837
def cpu_cluster():
2938
x, batch = gen()
3039
torch_cluster.knn_graph(x, k, batch=batch)
31-
profile('CPU (torch_cluster)', cpu_cmspepr)
40+
41+
42+
profile("CPU (torch_cluster)", cpu_cmspepr)
43+
3244

3345
def cuda_cmspepr():
3446
x, batch = gen(cuda=True)
3547
torch_cmspepr.knn_graph(x, k, batch=batch)
36-
profile('CUDA (torch_cmspepr)', cuda_cmspepr)
48+
49+
50+
profile("CUDA (torch_cmspepr)", cuda_cmspepr)
51+
3752

3853
def cuda_cluster():
3954
x, batch = gen(cuda=True)
4055
torch_cluster.knn_graph(x, k, batch=batch)
41-
profile('CUDA (torch_cluster)', cpu_cmspepr)
56+
57+
58+
profile("CUDA (torch_cluster)", cpu_cmspepr)

0 commit comments

Comments
 (0)