|
| 1 | +import time |
| 2 | +import torch |
| 3 | +import torch_cmspepr |
| 4 | +import torch_cluster |
| 5 | +import tqdm |
| 6 | +gpu = torch.device('cuda') |
| 7 | + |
| 8 | +k = 10 |
| 9 | + |
| 10 | +def gen(cuda=False): |
| 11 | + # 10k nodes with 5 node features |
| 12 | + x = torch.rand((10000, 5)) |
| 13 | + # Split nodes over 4 events with 2500 nodes/evt |
| 14 | + batch = torch.repeat_interleave(torch.arange(4), 2500) |
| 15 | + if cuda: x, batch = x.to(gpu), batch.to(gpu) |
| 16 | + return x, batch |
| 17 | + |
| 18 | +def profile(name, unit): |
| 19 | + t0 = time.time() |
| 20 | + for _ in tqdm.tqdm(range(10)): unit() |
| 21 | + print(f'{name} took {(time.time() - t0)/100.} sec/evt') |
| 22 | + |
| 23 | +def cpu_cmspepr(): |
| 24 | + x, batch = gen() |
| 25 | + torch_cmspepr.knn_graph(x, k, batch=batch) |
| 26 | +profile('CPU (torch_cmspepr)', cpu_cmspepr) |
| 27 | + |
| 28 | +def cpu_cluster(): |
| 29 | + x, batch = gen() |
| 30 | + torch_cluster.knn_graph(x, k, batch=batch) |
| 31 | +profile('CPU (torch_cluster)', cpu_cmspepr) |
| 32 | + |
| 33 | +def cuda_cmspepr(): |
| 34 | + x, batch = gen(cuda=True) |
| 35 | + torch_cmspepr.knn_graph(x, k, batch=batch) |
| 36 | +profile('CUDA (torch_cmspepr)', cuda_cmspepr) |
| 37 | + |
| 38 | +def cuda_cluster(): |
| 39 | + x, batch = gen(cuda=True) |
| 40 | + torch_cluster.knn_graph(x, k, batch=batch) |
| 41 | +profile('CUDA (torch_cluster)', cpu_cmspepr) |
0 commit comments