File: blas.py

package info (click to toggle)
pytorch 1.13.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 139,252 kB
  • sloc: cpp: 1,100,274; python: 706,454; ansic: 83,052; asm: 7,618; java: 3,273; sh: 2,841; javascript: 612; makefile: 323; xml: 269; ruby: 185; yacc: 144; objc: 68; lex: 44
file content (64 lines) | stat: -rw-r--r-- 1,928 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# BLAS performance testing helper
# Copyright (C) 2021 M. Zhou <lumin@debian.org>
import os
import sys
import time
import numpy as np
import torch as th
os.system('update-alternatives --display libblas.so.3-x86_64-linux-gnu')

print('F32 Numpy Refrence Group', end='\t')
sys.stdout.flush()
N, reference = 8, []
for i in range(N):
    x = np.random.rand(4096, 4096).astype(np.float32)
    y = np.random.rand(4096, 4096).astype(np.float32)
    time_start = time.time()
    z = x @ y
    time_end = time.time()
    reference.append(time_end - time_start)
    print('.', end='')
    sys.stdout.flush()
print(f'{1000*np.mean(reference):.1f}ms pm {1000*np.std(reference):.1f}ms')

print('F64 Numpy Refrence Group', end='\t')
sys.stdout.flush()
N, reference = 8, []
for i in range(N):
    x = np.random.rand(4096, 4096).astype(np.float64)
    y = np.random.rand(4096, 4096).astype(np.float64)
    time_start = time.time()
    z = x @ y
    time_end = time.time()
    reference.append(time_end - time_start)
    print('.', end='')
    sys.stdout.flush()
print(f'{1000*np.mean(reference):.1f}ms pm {1000*np.std(reference):.1f}ms')

print('F32 Torch', end='\t')
sys.stdout.flush()
N, results = 8, []
for i in range(N):
    x = th.rand(4096, 4096).to(th.float32)
    y = th.rand(4096, 4096).to(th.float32)
    time_start = time.time()
    z = x @ y
    time_end = time.time()
    results.append(time_end - time_start)
    print('.', end='')
    sys.stdout.flush()
print(f'{1000*np.mean(results):.1f}ms pm {1000*np.std(results):.1f}ms')

print('F64 Torch', end='\t')
sys.stdout.flush()
N, results = 8, []
for i in range(N):
    x = th.rand(4096, 4096).to(th.float64)
    y = th.rand(4096, 4096).to(th.float64)
    time_start = time.time()
    z = x @ y
    time_end = time.time()
    results.append(time_end - time_start)
    print('.', end='')
    sys.stdout.flush()
print(f'{1000*np.mean(results):.1f}ms pm {1000*np.std(results):.1f}ms')