drbh HF Staff commited on
Commit
021b089
·
verified ·
1 Parent(s): 20ffcb1

Upload benchmark.py

Browse files
Files changed (1) hide show
  1. benchmarks/benchmark.py +29 -0
benchmarks/benchmark.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn.functional as F
3
+
4
+ from kernels.benchmark import Benchmark
5
+
6
+
7
+ class ReluBenchmark(Benchmark):
8
+ seed: int = 42
9
+
10
+ def setup(self):
11
+ self.x = torch.randn(1024, 1024, device="cuda", dtype=torch.float32)
12
+ self.out = torch.empty_like(self.x)
13
+
14
+ def benchmark_base(self):
15
+ self.out = self.kernel.relu(self.x)
16
+
17
+ def verify_base(self) -> torch.Tensor:
18
+ return F.relu(self.x)
19
+
20
+ def setup_large(self):
21
+ self.x = torch.randn(4096, 4096, device="cuda", dtype=torch.float32)
22
+ self.out = torch.empty_like(self.x)
23
+
24
+ def benchmark_large(self):
25
+ self.out = self.kernel.relu(self.x)
26
+
27
+ def verify_large(self) -> torch.Tensor:
28
+ return F.relu(self.x)
29
+