Skip to content

Commit b7fecb7

Browse files
author
Thomas Klijnsma
committed
added performance script and small fixes to readme
1 parent e0d82f1 commit b7fecb7

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Example Singularity instructions:
9494

9595
```bash
9696
singularity pull docker://pytorch/pytorch:2.0.0-cuda11.7-cudnn8-devel
97-
singularity run --nv sifs/pytorch_2.0.0-cuda11.7-cudnn8-devel.sif
97+
singularity run --nv pytorch_2.0.0-cuda11.7-cudnn8-devel.sif
9898
```
9999

100100
And then once in the container:

scripts/performance.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

Comments
 (0)