[python-dtcwt] 153/497: opencl: add (very) simple benchmark script

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Tue Jul 21 18:05:59 UTC 2015


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

ghisvail-guest pushed a commit to branch debian/sid
in repository python-dtcwt.

commit 47421db042993874d3fed763113b58574a91fb7f
Author: Rich Wareham <rjw57 at cam.ac.uk>
Date:   Thu Nov 7 20:27:28 2013 +0000

    opencl: add (very) simple benchmark script
    
    This script will not win any awards for cleverness but it exercises the
    three low-level filtering routines to see what speed up one gets. Note
    that, at the moment, the colifilt routine is un-accelerated.
---
 scripts/benchmark_opencl.py | 74 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/scripts/benchmark_opencl.py b/scripts/benchmark_opencl.py
new file mode 100644
index 0000000..0d70a5e
--- /dev/null
+++ b/scripts/benchmark_opencl.py
@@ -0,0 +1,74 @@
+"""
+A simple script to benchmark the OpenCL low-level routines in comparison to the
+CPU ones.
+
+"""
+
+from __future__ import print_function, division
+
+import os
+import timeit
+
+import numpy as np
+
+from dtcwt.coeffs import biort, qshift
+
+lena = np.load(os.path.join(os.path.dirname(__file__), '..', 'tests', 'lena.npz'))['lena']
+h0o, g0o, h1o, g1o = biort('near_sym_b')
+h0a, h0b, g0a, g0b, h1a, h1b, g1a, g1b = qshift('qshift_d')
+
+def format_time(t):
+    units = (
+        (60*60, 'hr'), (60, 'min'), (1, 's'), (1e-3, 'ms')
+    )
+
+    for scale, unit in units:
+        if t >= scale:
+            return '{0:.2f} {1}'.format(t/scale, unit)
+
+    return '{0:.2f} {1}'.format(t*1e6, 'us')
+
+def benchmark(statement='pass', setup='pass'):
+    number, repeat = (1, 3)
+    min_time = 0
+    
+    while min_time < 0.2:
+        number *= 10
+        times = timeit.repeat(statement, setup, repeat=repeat, number=number)
+        min_time = min(times)
+
+    t = min_time / number
+    print('{0} loops, best of {1}: {2}'.format(number, repeat, format_time(t)))
+
+    return t
+
+def main():
+    print('Running NumPy colfilter...')
+    a = benchmark('colfilter(lena, h1o)',
+            'from dtcwt.lowlevel import colfilter; from __main__ import lena, h1o')
+    print('Running OpenCL colfilter...')
+    b = benchmark('colfilter(lena, h1o)',
+            'from dtcwt.opencl.lowlevel import colfilter; from __main__ import lena, h1o')
+    print('Percentage speed up: {0:.0f}%'.format(1e2*a/b))
+    print('=====')
+
+    print('Running NumPy coldfilt...')
+    a = benchmark('coldfilt(lena, h0b, h0a)',
+            'from dtcwt.lowlevel import coldfilt; from __main__ import lena, h0b, h0a')
+    print('Running OpenCL coldfilt...')
+    b = benchmark('coldfilt(lena, h0b, h0a)',
+            'from dtcwt.opencl.lowlevel import coldfilt; from __main__ import lena, h0b, h0a')
+    print('Percentage speed up: {0:.0f}%'.format(1e2*a/b))
+    print('=====')
+
+    print('Running NumPy colifilt...')
+    a = benchmark('colifilt(lena, h0b, h0a)',
+            'from dtcwt.lowlevel import colifilt; from __main__ import lena, h0b, h0a')
+    print('Running OpenCL colifilt...')
+    b = benchmark('colifilt(lena, h0b, h0a)',
+            'from dtcwt.opencl.lowlevel import colifilt; from __main__ import lena, h0b, h0a')
+    print('Percentage speed up: {0:.0f}%'.format(1e2*a/b))
+    print('=====')
+
+if __name__ == '__main__':
+    main()

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



More information about the debian-science-commits mailing list