|
3 | 3 | import torch_cmspepr
|
4 | 4 | import torch_cluster
|
5 | 5 | import tqdm
|
6 |
| -gpu = torch.device('cuda') |
| 6 | + |
| 7 | +gpu = torch.device("cuda") |
7 | 8 |
|
8 | 9 | k = 10
|
9 | 10 |
|
| 11 | + |
10 | 12 | def gen(cuda=False):
|
11 | 13 | # 10k nodes with 5 node features
|
12 | 14 | x = torch.rand((10000, 5))
|
13 | 15 | # Split nodes over 4 events with 2500 nodes/evt
|
14 | 16 | 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) |
16 | 19 | return x, batch
|
17 | 20 |
|
| 21 | + |
18 | 22 | def profile(name, unit):
|
19 | 23 | 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 | + |
22 | 28 |
|
23 | 29 | def cpu_cmspepr():
|
24 | 30 | x, batch = gen()
|
25 | 31 | 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 | + |
27 | 36 |
|
28 | 37 | def cpu_cluster():
|
29 | 38 | x, batch = gen()
|
30 | 39 | 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 | + |
32 | 44 |
|
33 | 45 | def cuda_cmspepr():
|
34 | 46 | x, batch = gen(cuda=True)
|
35 | 47 | 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 | + |
37 | 52 |
|
38 | 53 | def cuda_cluster():
|
39 | 54 | x, batch = gen(cuda=True)
|
40 | 55 | 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