forked from arrayfire/arrayfire-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_fft.py
More file actions
69 lines (49 loc) · 1.46 KB
/
bench_fft.py
File metadata and controls
69 lines (49 loc) · 1.46 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 _ in range(iters):
B = af.fft2(A) # FIXME: 'B' is assigned, but not used.
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 _ in range(iters):
B = np.fft.fft2(A) # FIXME: 'B' is assigned, but not used.
return run
def bench(calc, iters=100, upto=13):
_, name = calc.__name__.split("_")
print("Benchmark N x N 2D fft on %s" % name)
for M in range(7, upto):
N = 1 << M
run = calc(N)
start = time()
run(iters)
t = (time() - start) / iters
gflops = (10.0 * N * N * M) / (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=10)