Author: Maciej Fijalkowski <[email protected]>
Branch: extradoc
Changeset: r3680:3988bd9abc42
Date: 2011-06-14 22:20 +0200
http://bitbucket.org/pypy/extradoc/changeset/3988bd9abc42/
Log: finish porting convolution
diff --git a/talk/iwtc11/benchmarks/benchmark.sh
b/talk/iwtc11/benchmarks/benchmark.sh
--- a/talk/iwtc11/benchmarks/benchmark.sh
+++ b/talk/iwtc11/benchmarks/benchmark.sh
@@ -18,20 +18,18 @@
./runner.py -n 5 -c "$* -lstdc++" image/sobel.cc 1002 1002
rm a.out
else
- #./runner.py -n 10 sqrt/sqrt.py main int
- #./runner.py -n 10 sqrt/sqrt.py main float
- #./runner.py -n 10 sqrt/sqrt.py main Fix16
+ ./runner.py -n 10 sqrt/sqrt.py main int
+ ./runner.py -n 10 sqrt/sqrt.py main float
+ ./runner.py -n 10 sqrt/sqrt.py main Fix16
./runner.py convolution/convolution.py conv3 1
- ./runner.py convolution/convolution.py conv3 100
- ./runner.py convolution/convolution.py conv3 1000
-
-# $* sqrt/time_sqrt.py float
-# $* sqrt/time_sqrt.py int
-# $* sqrt/time_sqrt.py Fix16
-# $* convolution/time_conv.py 1
-# $* convolution/time_conv.py 100
-# $* convolution/time_conv.py 1000
-# $* convolution/time_conv2d.py
+ ./runner.py convolution/convolution.py conv5 1
+ ./runner.py -n 10 convolution/convolution.py conv3 100
+ ./runner.py -n 10 convolution/convolution.py conv5 100
+ ./runner.py -n 10 convolution/convolution.py conv3 1000
+ ./runner.py -n 10 convolution/convolution.py conv5 1000
+ ./runner.py -n 10 convolution/convolution.py conv3x3 1000000 3
+ ./runner.py -n 10 convolution/convolution.py conv3x3 1000 1000
+ ./runner.py -n 10 convolution/convolution.py dilate3x3 1000 1000
# $* image/noborder.py NoBorderImagePadded
# $* image/noborder.py NoBorderImage
# $* image/time_sobel.py NoBorderImagePadded
diff --git a/talk/iwtc11/benchmarks/convolution/convolution.py
b/talk/iwtc11/benchmarks/convolution/convolution.py
--- a/talk/iwtc11/benchmarks/convolution/convolution.py
+++ b/talk/iwtc11/benchmarks/convolution/convolution.py
@@ -1,4 +1,5 @@
from array import array
+from math import log10
def _conv3(a, k, n=1):
assert len(k)==3
@@ -12,8 +13,8 @@
def conv3(args):
n = int(args[0])
_conv3(array('d', [1]) * (100000000/n),
- array('d', [-1, 0, 1]), n)
-
+ array('d', [-1, 0, 1]), n)
+ return 'conv3(1e%d)' % log10(100000000/n)
def _conv5(a, k, n=1):
assert len(k)==5
@@ -24,6 +25,12 @@
b[i] = k[4]*a[i] + k[3]*a[i+1] + k[2]*a[i+2] + k[1]*a[i+3] +
k[0]*a[i+4]
return b
+def conv5(args):
+ n = int(args[0])
+ _conv5(array('d', [1]) * (100000000/n),
+ array('d', [1, 4, 6, 4, 1]), n)
+ return 'conv5(1e%d)' % log10(100000000/n)
+
class Array2D(object):
def __init__(self, w, h):
self.width = w
@@ -60,7 +67,7 @@
k[2,0]*a[x-1, y+1] + k[1,0]*a[x, y+1] + k[0,0]*a[x+1,
y+1]
return b
-def _morphology3x3(a, k, func):
+def morphology3x3(a, k, func):
assert k.width == k.height == 3
b = Array2D(a.width, a.height)
for y in xrange(1, a.height-1):
@@ -75,3 +82,11 @@
def _erode3x3(a, k):
return morphology3x3(a, k, min)
+
+def conv3x3(args):
+ _conv3x3(Array2D(int(args[0]), int(args[1])), Array2D(3,3))
+ return 'conv3x3(%s)' % args[1]
+
+def dilate3x3(args):
+ _dilate3x3(Array2D(int(args[0]), int(args[1])), Array2D(3,3))
+ return 'dilate3x3(%s)' % args[1]
diff --git a/talk/iwtc11/benchmarks/runner.py b/talk/iwtc11/benchmarks/runner.py
--- a/talk/iwtc11/benchmarks/runner.py
+++ b/talk/iwtc11/benchmarks/runner.py
@@ -24,6 +24,12 @@
parser.add_option('-c', dest='compile_command',
help='for *.c a compile command')
options, args = parser.parse_args()
+ try:
+ import pypyjit
+ except ImportError:
+ pass
+ else:
+ pypyjit.set_param(trace_limit=20000)
if args[0].endswith('.py'):
mod = py.path.local(args[0]).pyimport()
sys.stderr.write("warming up")
@@ -37,10 +43,9 @@
all = []
for i in range(options.no):
t0 = time.time()
- func(args)
+ name = func(args)
all.append(time.time() - t0)
print >>sys.stderr, "Next:", all[-1]
- name = mod.name
else:
# not needed
options.warmup = 0
diff --git a/talk/iwtc11/benchmarks/sqrt/sqrt.py
b/talk/iwtc11/benchmarks/sqrt/sqrt.py
--- a/talk/iwtc11/benchmarks/sqrt/sqrt.py
+++ b/talk/iwtc11/benchmarks/sqrt/sqrt.py
@@ -49,6 +49,5 @@
return Fix16((Fix16(other).val << 16) / self.val, False)
def main(argv):
- global name
- name = 'sqrt(%s)' % argv[0]
sqrt(eval(argv[0])(123456), 100000000)
+ return 'sqrt(%s)' % argv[0]
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit