forked from arrayfire/arrayfire-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_blas.py
More file actions
69 lines (50 loc) · 1.5 KB
/
bench_blas.py
File metadata and controls
69 lines (50 loc) · 1.5 KB
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
65
66
67
68
69
#!/usr/bin/env python
#######################################################
# Copyright (c) 2019, ArrayFire
# All rights reserved.
#
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause
########################################################
import sys
from time import time
import arrayfire as af
try:
import numpy as np
except ImportError:
np = None
def calc_arrayfire(n):
A = af.randu(n, n)
af.sync()
def run(iters):
for t in range(iters):
# FIXME: B is assigned, but not used in function
B = af.matmul(A, A)
af.sync()
return run
def calc_numpy(n):
np.random.seed(1)
A = np.random.rand(n, n).astype(np.float32)
def run(iters):
for t in range(iters):
# FIXME: B is assigned, but not used in function
B = np.dot(A, A)
return run
def bench(calc, iters=100, upto=2048):
_, name = calc.__name__.split("_")
print("Benchmark N x N matrix multiply on %s" % name)
for n in range(128, upto + 128, 128):
run = calc(n)
start = time()
run(iters)
t = (time() - start) / iters
gflops = 2.0 * (n ** 3) / (t * 1E9)
print("Time taken for %4d x %4d: %0.4f Gflops" % (n, n, gflops))
if __name__ == "__main__":
if len(sys.argv) > 1:
af.set_device(int(sys.argv[1]))
af.info()
bench(calc_arrayfire)
if np:
bench(calc_numpy, upto=512)