-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmtorch.py
48 lines (44 loc) · 1.72 KB
/
mmtorch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import torch
def op(a, b):
#return torch.logdet(a)
#return torch.inverse(a)
#return torch.eig(a)
#return torch.cholesky(torch.mm(a, a.t()))
return torch.mm(a, b)
torch.set_default_dtype(torch.float64)
start = torch.cuda.Event(enable_timing=True)
end = torch.cuda.Event(enable_timing=True)
n = 1024*4
num_ops = 2*n**3-n**2
x = torch.randn(n, n)
y = torch.randn(n, n)
for i in range(2):
start.record()
z = op(x, y)
end.record()
torch.cuda.synchronize()
print(num_ops / start.elapsed_time(end) / 10**6, "GFLOPS CPU double")
torch.set_default_dtype(torch.float64)
device = torch.cuda.current_device()
start = torch.cuda.Event(enable_timing=True)
end = torch.cuda.Event(enable_timing=True)
x = (torch.randn(n, n) + n*torch.eye(n)).to(device)
y = (torch.randn(n, n) + n*torch.eye(n)).to(device)
for i in range(5):
start.record()
z = op(x, y)
end.record()
torch.cuda.synchronize()
print(num_ops / start.elapsed_time(end) / 10**6, "GFLOPS CUDA double")
torch.set_default_dtype(torch.float32)
device = torch.cuda.current_device()
start = torch.cuda.Event(enable_timing=True)
end = torch.cuda.Event(enable_timing=True)
x = (torch.randn(n, n) + n*torch.eye(n)).to(device)
y = (torch.randn(n, n) + n*torch.eye(n)).to(device)
for i in range(5):
start.record()
z = op(x, y)
end.record()
torch.cuda.synchronize()
print(num_ops / start.elapsed_time(end) / 10**6, "GFLOPS CUDA single")