Skip to content

Commit 5879685

Browse files
committed
Adding benchmark examples
1 parent 3765c3f commit 5879685

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

examples/benchmarks/bench_blas.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/python
2+
3+
#######################################################
4+
# Copyright (c) 2015, ArrayFire
5+
# All rights reserved.
6+
#
7+
# This file is distributed under 3-clause BSD license.
8+
# The complete license agreement can be obtained at:
9+
# http://arrayfire.com/licenses/BSD-3-Clause
10+
########################################################
11+
12+
13+
import sys
14+
from time import time
15+
from arrayfire import (array, randu, matmul)
16+
import arrayfire as af
17+
18+
def bench(A, iters = 100):
19+
start = time()
20+
for t in range(iters):
21+
B = af.matmul(A, A)
22+
af.sync()
23+
return (time() - start) / iters
24+
25+
if __name__ == "__main__":
26+
27+
if (len(sys.argv) > 1):
28+
af.set_device(int(sys.argv[1]))
29+
30+
af.info()
31+
print("Benchmark N x N matrix multiply")
32+
33+
for n in range(128, 2048 + 128, 128):
34+
A = af.randu(n, n)
35+
af.sync()
36+
37+
t = bench(A)
38+
gflops = 2.0 * (n**3) / (t * 1E9)
39+
print("Time taken for %4d x %4d: %0.4f Gflops" % (n, n, gflops))

examples/benchmarks/bench_fft.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/python
2+
3+
#######################################################
4+
# Copyright (c) 2015, ArrayFire
5+
# All rights reserved.
6+
#
7+
# This file is distributed under 3-clause BSD license.
8+
# The complete license agreement can be obtained at:
9+
# http://arrayfire.com/licenses/BSD-3-Clause
10+
########################################################
11+
12+
13+
import sys
14+
from time import time
15+
from arrayfire import (array, randu, matmul)
16+
import arrayfire as af
17+
18+
def bench(A, iters = 100):
19+
start = time()
20+
for t in range(iters):
21+
B = af.fft2(A)
22+
af.sync()
23+
return (time() - start) / iters
24+
25+
if __name__ == "__main__":
26+
27+
if (len(sys.argv) > 1):
28+
af.set_device(int(sys.argv[1]))
29+
30+
af.info()
31+
print("Benchmark N x N 2D fft")
32+
33+
for M in range(7, 13):
34+
N = 1 << M
35+
A = af.randu(N, N)
36+
af.sync()
37+
38+
t = bench(A)
39+
gflops = (10.0 * N * N * M) / (t * 1E9)
40+
print("Time taken for %4d x %4d: %0.4f Gflops" % (N, N, gflops))

0 commit comments

Comments
 (0)