[python-arrayfire] 12/58: Add numpy benchmarks to fft and blas.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Sep 28 13:57:03 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository python-arrayfire.

commit ed52b90ac407a9e18cd2bd7d3ed5bb81386a5ec8
Author: Dzhelil Rufat <drufat at caltech.edu>
Date:   Tue May 3 12:11:32 2016 -0700

    Add numpy benchmarks to fft and blas.
    
    * Add numpy benchmarks to fft and blas. Switch to timeit for benchmark measurements.
    
    * Use a more descriptive name for benchmark.
    
    * Switch back to using time module for benchmarks to ensure that af.sync() is run only once.
---
 examples/benchmarks/bench_blas.py | 57 ++++++++++++++++++++++++++++---------
 examples/benchmarks/bench_fft.py  | 60 +++++++++++++++++++++++++++++----------
 2 files changed, 88 insertions(+), 29 deletions(-)

diff --git a/examples/benchmarks/bench_blas.py b/examples/benchmarks/bench_blas.py
index 1b31590..aaf4eb1 100644
--- a/examples/benchmarks/bench_blas.py
+++ b/examples/benchmarks/bench_blas.py
@@ -12,15 +12,49 @@
 
 import sys
 from time import time
-from arrayfire import (array, randu, matmul)
 import arrayfire as af
 
-def bench(A, iters = 100):
-    start = time()
-    for t in range(iters):
-        B = af.matmul(A, A)
+try:
+    import numpy as np
+except:
+    np = None
+
+
+def calc_arrayfire(n):
+    A = af.randu(n, n)
     af.sync()
-    return (time() - start) / iters
+
+    def run(iters):
+        for t in range(iters):
+            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):
+            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__":
 
@@ -28,12 +62,7 @@ if __name__ == "__main__":
         af.set_device(int(sys.argv[1]))
 
     af.info()
-    print("Benchmark N x N matrix multiply")
-
-    for n in range(128, 2048 + 128, 128):
-        A = af.randu(n, n)
-        af.sync()
 
-        t = bench(A)
-        gflops = 2.0 * (n**3) / (t * 1E9)
-        print("Time taken for %4d x %4d: %0.4f Gflops" % (n, n, gflops))
+    bench(calc_arrayfire)
+    if np:
+        bench(calc_numpy, upto=512)
diff --git a/examples/benchmarks/bench_fft.py b/examples/benchmarks/bench_fft.py
index 735e8d6..9a2d283 100644
--- a/examples/benchmarks/bench_fft.py
+++ b/examples/benchmarks/bench_fft.py
@@ -12,15 +12,51 @@
 
 import sys
 from time import time
-from arrayfire import (array, randu, matmul)
 import arrayfire as af
 
-def bench(A, iters = 100):
-    start = time()
-    for t in range(iters):
-        B = af.fft2(A)
+try:
+    import numpy as np
+except:
+    np = None
+
+
+def calc_arrayfire(n):
+    A = af.randu(n, n)
     af.sync()
-    return (time() - start) / iters
+
+    def run(iters):
+        for t in range(iters):
+            B = af.fft2(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):
+            B = np.fft.fft2(A)
+
+    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__":
 
@@ -28,13 +64,7 @@ if __name__ == "__main__":
         af.set_device(int(sys.argv[1]))
 
     af.info()
-    print("Benchmark N x N 2D fft")
 
-    for M in range(7, 13):
-        N = 1 << M
-        A = af.randu(N, N)
-        af.sync()
-
-        t = bench(A)
-        gflops = (10.0 * N * N * M) / (t * 1E9)
-        print("Time taken for %4d x %4d: %0.4f Gflops" % (N, N, gflops))
+    bench(calc_arrayfire)
+    if np:
+        bench(calc_numpy, upto=10)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-arrayfire.git



More information about the debian-science-commits mailing list