Skip to content

Commit d584238

Browse files
committed
Resize meso benchmarks with iteration time < 1s
The resized benchmarks have suffix "-sized2". The original benchmarks will be kept around for a little while to collect results from both versions in parallel. Some benchmarks had to be updated to support parametrization. Other benchmarks were just copied to a new file. The old file will be deleted later with the old benchmark, so there will be no duplication eventually.
1 parent fa2b47b commit d584238

File tree

11 files changed

+1856
-2
lines changed

11 files changed

+1856
-2
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Copyright (c) 2017, 2021, Oracle and/or its affiliates.
2+
# Copyright (c) 2013, Pablo Mouzo
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy
5+
# of this software and associated documentation files (the "Software"), to deal
6+
# in the Software without restriction, including without limitation the rights
7+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
# copies of the Software, and to permit persons to whom the Software is
9+
# furnished to do so, subject to the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be included in all
12+
# copies or substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
# SOFTWARE.
21+
22+
from array import array
23+
from math import sqrt, atan2, sqrt, sin, cos, ceil, floor
24+
25+
26+
class Image(object):
27+
def __init__(self, width, height, data=None):
28+
self.width = width
29+
self.height = height
30+
if data:
31+
self.data = data
32+
else:
33+
self.data = [0] * (width * height)
34+
35+
def _idx(self, x, y):
36+
if 0 <= x < self.width and 0 <= y < self.height:
37+
return y * self.width + x
38+
raise IndexError
39+
40+
def __getitem__(self, t):
41+
x, y = t
42+
return self.data[self._idx(x, y)]
43+
44+
def __setitem__(self, t, val):
45+
x, y = t
46+
self.data[self._idx(x, y)] = val
47+
48+
def pixels(self, border=0):
49+
for y in xrange(border, self.height - border):
50+
for x in xrange(border, self.width - border):
51+
yield x, y
52+
53+
def sobel(self, horizontal=True, vertical=True):
54+
out = Image(self.width, self.height)
55+
for y in range(1, self.height - 1):
56+
for x in range(1, self.width - 1):
57+
if horizontal:
58+
dx = -1.0 * self[x - 1, y - 1] + 1.0 * self[x + 1, y - 1] + \
59+
-2.0 * self[x - 1, y] + 2.0 * self[x + 1, y] + \
60+
-1.0 * self[x - 1, y + 1] + 1.0 * self[x + 1, y + 1]
61+
else:
62+
dx = self[x, y]
63+
if vertical:
64+
dy = -1.0 * self[x - 1, y - 1] - 2.0 * self[x, y - 1] - 1.0 * self[x + 1, y - 1] + \
65+
1.0 * self[x - 1, y + 1] + 2.0 * self[x, y + 1] + 1.0 * self[x + 1, y + 1]
66+
else:
67+
dy = self[x, y]
68+
out[x, y] = min(int(sqrt(dx * dx + dy * dy) / 4.0), 255)
69+
return out
70+
71+
def fisheye(img, fraction=2, bilinear=False):
72+
if bilinear:
73+
img = BilinImage(img.width, img.height, data=img.data)
74+
else:
75+
img = NNImage(img.width, img.height, data=img.data)
76+
out = Image(img.width, img.height, data=img.data[:])
77+
maxr = img.height / (fraction + 1)
78+
for y in range(int(img.height / 2 - maxr), int(img.height / 2 + maxr)):
79+
for x in range(int(img.width / 2 - maxr), int(img.width / 2 + maxr)):
80+
dx, dy = x - img.width / 2, y - img.height / 2
81+
a = atan2(dy, dx)
82+
r = sqrt(dx ** 2 + dy ** 2)
83+
if r < maxr:
84+
nr = r * r / maxr
85+
nx, ny = nr * cos(a), nr * sin(a)
86+
out[x,y] = min(int(img[nx + img.width / 2, ny + img.height / 2]), 255)
87+
else:
88+
out[x,y] = img[x,y]
89+
return out
90+
91+
92+
class NNImage(Image):
93+
def __getitem__(self, t):
94+
x, y = t
95+
return Image.__getitem__(self, (int(x + 0.5), int(y + 0.5)))
96+
97+
98+
class BilinImage(Image):
99+
def __getitem__(self, t):
100+
x, y = t
101+
if isinstance(x, float) and isinstance(y, float):
102+
x0, x1 = int(floor(x)), int(ceil(x))
103+
y0, y1 = int(floor(y)), int(ceil(y))
104+
xoff, yoff = x - x0, y - y0
105+
return (1.0 - xoff) * (1.0 - yoff) * self[x0, y0] + \
106+
(1.0 - xoff) * ( yoff) * self[x0, y1] + \
107+
( xoff) * (1.0 - yoff) * self[x1, y0] + \
108+
( xoff) * ( yoff) * self[x1, y1]
109+
else:
110+
return Image.__getitem__(self, (x, y))
111+
112+
113+
SZ = 20
114+
import java
115+
INPUT_DATA = java.type("int[]")(SZ * SZ)
116+
for i in range(SZ * SZ):
117+
INPUT_DATA[i] = i
118+
119+
120+
def measure(num):
121+
img = Image(SZ, SZ, data=INPUT_DATA)
122+
for i in range(num):
123+
img = img.sobel(horizontal=True, vertical=True)
124+
img = img.fisheye(bilinear=True, fraction=3)
125+
return img
126+
127+
128+
def __benchmark__(num=10000):
129+
return measure(num)
130+
131+
132+
if __name__ == '__main__':
133+
import sys
134+
import time
135+
start = time.time()
136+
if len(sys.argv) >= 2:
137+
num = int(sys.argv[1])
138+
img = __benchmark__(num)
139+
else:
140+
img = __benchmark__(2)
141+
print(img.data)
142+
print("%s took %s s" % (__file__, time.time() - start))
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
# Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# Subject to the condition set forth below, permission is hereby granted to any
7+
# person obtaining a copy of this software, associated documentation and/or
8+
# data (collectively the "Software"), free of charge and under any and all
9+
# copyright rights in the Software, and any and all patent rights owned or
10+
# freely licensable by each licensor hereunder covering either (i) the
11+
# unmodified Software as contributed to or provided by such licensor, or (ii)
12+
# the Larger Works (as defined below), to deal in both
13+
#
14+
# (a) the Software, and
15+
#
16+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
17+
# one is included with the Software each a "Larger Work" to which the Software
18+
# is contributed by such licensors),
19+
#
20+
# without restriction, including without limitation the rights to copy, create
21+
# derivative works of, display, perform, and distribute the Software and make,
22+
# use, sell, offer for sale, import, export, have made, and have sold the
23+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
24+
# either these or other terms.
25+
#
26+
# This license is subject to the following condition:
27+
#
28+
# The above copyright notice and either this complete permission notice or at a
29+
# minimum a reference to the UPL must be included in all copies or substantial
30+
# portions of the Software.
31+
#
32+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
# SOFTWARE.
39+
40+
"""
41+
******************************************************************
42+
* HISTORY
43+
* 15-Oct-94 Jeff Shufelt (js), Carnegie Mellon University
44+
* Prepared for 15-681, Fall 1994.
45+
* Modified by Shuai Che
46+
******************************************************************
47+
"""
48+
49+
import random
50+
import math
51+
52+
# eta value
53+
ETA = 0.3
54+
55+
# momentum value
56+
MOMENTUM = 0.3
57+
58+
# (16, 1 can not be changed)
59+
n_hidden = 16
60+
n_out = 1
61+
62+
63+
def bpnn_layerforward(l1, l2, conn, n1, n2):
64+
## Set up thresholding unit ##
65+
l1[0] = 1.0
66+
## For each unit in second layer ##
67+
r1 = 1 + n2
68+
r2 = 1 + n1
69+
for j in range(1, r1):
70+
## Compute weighted Sum of its inputs ##
71+
Sum = 0.0
72+
for k in range(r2):
73+
Sum += conn[k*r1 + j] * l1[k]
74+
75+
l2[j] = (1.0 / (1.0 + math.exp(-Sum)))
76+
77+
78+
def bpnn_output_error(delta, target, output, nj):
79+
errSum = 0.0
80+
for j in range(1, 1 + nj):
81+
o = output[j]
82+
t = target[j]
83+
v = o * (1.0 - o) * (t - o)
84+
delta[j] = v
85+
errSum += abs(v)
86+
87+
return errSum
88+
89+
90+
def bpnn_hidden_error(delta_h, nh, delta_o, no, who, hidden):
91+
errSum = 0.0
92+
for j in range(1, 1 + nh):
93+
Sum = 0.0
94+
for k in range(1, 1 + no):
95+
Sum += delta_o[k] * who[j * (1 + no) + k]
96+
h = hidden[j]
97+
delta_h[j] = h * (1.0 - h) * Sum
98+
errSum += abs(delta_h[j])
99+
100+
return errSum
101+
102+
103+
def bpnn_adjust_weights(delta, ndelta, ly, nly, w, oldw):
104+
ly[0] = 1.0
105+
for j in range(1, (1 + ndelta)):
106+
for k in range(nly + 1):
107+
val = ETA * delta[j] * ly[k]
108+
val += MOMENTUM * oldw[k*(1 + ndelta) + j]
109+
oldw[k*(1 + ndelta) + j] = val
110+
w[k*(1 + ndelta) + j] += val
111+
112+
113+
def bpnn_train_kernel(_iu_list, _hu_list, _iw_list, _ou_list, _hw_list, _od_list, _t_list, _hd_list, _hw_prev_list, _iw_prev_list, layer_size):
114+
bpnn_layerforward(_iu_list, _hu_list, _iw_list, layer_size, n_hidden)
115+
bpnn_layerforward(_hu_list, _ou_list, _hw_list, n_hidden, n_out)
116+
out_err = bpnn_output_error(_od_list, _t_list, _ou_list, n_out)
117+
hid_err = bpnn_hidden_error(
118+
_hd_list, n_hidden, _od_list, n_out, _hw_list, _hu_list)
119+
bpnn_adjust_weights(_od_list, n_out, _hu_list,
120+
n_hidden, _hw_list, _hw_prev_list)
121+
bpnn_adjust_weights(_hd_list, n_hidden, _iu_list,
122+
layer_size, _iw_list, _iw_prev_list)
123+
124+
return (out_err, hid_err)
125+
126+
127+
class Data:
128+
def __init__(self):
129+
self._iu_list = None
130+
self._hw_list = None
131+
self._hu_list = None
132+
self._ou_list = None
133+
self._hd_list = None
134+
self._od_list = None
135+
self._iw_list = None
136+
self._iw_prev_list = None
137+
self._hw_prev_list = None
138+
self._t_list = None
139+
140+
self.zeros_list = None
141+
self.random_list = None
142+
143+
144+
data = Data()
145+
146+
default_size = 2 ** 16
147+
148+
149+
def measure(layer_size=default_size):
150+
print("Starting training kernel")
151+
bpnn_train_kernel(data._iu_list, data._hu_list, data._iw_list, data._ou_list, data._hw_list,
152+
data._od_list, data._t_list, data._hd_list, data._hw_prev_list, data._iw_prev_list, layer_size)
153+
154+
155+
def __benchmark__(layer_size=default_size):
156+
measure(layer_size)
157+
158+
159+
def __setup__(layer_size=default_size):
160+
random.seed(7)
161+
print("Input layer size : %d" % layer_size)
162+
# Creates a new fully-connected network from scratch,
163+
# with the given numbers of input, hidden, and output units.
164+
# Threshold units are automatically included. All weights are
165+
# randomly initialized.
166+
167+
# Space is also allocated for temporary storage (momentum weights,
168+
# error computations, etc).
169+
170+
## the input units ##
171+
data._iu_list = [random.random() for i in range(layer_size + 1)]
172+
173+
## weights from hidden to output layer ##
174+
data._hw_list = [random.random()
175+
for i in range((n_out + 1) * (n_hidden + 1))]
176+
177+
## the hidden units ##
178+
data._hu_list = [0. for i in range(n_hidden + 1)]
179+
## the output units ##
180+
data._ou_list = [0. for i in range(n_out + 1)]
181+
182+
## storage for hidden unit error ##
183+
data._hd_list = [0. for i in range(n_hidden + 1)]
184+
## storage for output unit error ##
185+
data._od_list = [0. for i in range(n_out + 1)]
186+
187+
## weights from input to hidden layer ##
188+
data._iw_list = [0. for i in range((n_hidden + 1) * (layer_size + 1))]
189+
190+
## The next two are for momentum ##
191+
## previous change on input to hidden wgt ##
192+
data._iw_prev_list = [0. for i in range((n_hidden + 1) * (layer_size + 1))]
193+
## previous change on hidden to output wgt ##
194+
data._hw_prev_list = [0. for i in range((n_out + 1) * (n_hidden + 1))]
195+
196+
## storage for target vector ##
197+
data._t_list = [0.1 for i in range(n_out + 1)]
198+
199+
data.zeros_list = [data._hu_list, data._ou_list, data._hd_list,
200+
data._od_list, data._iw_list, data._iw_prev_list, data._hw_prev_list]
201+
data.random_list = [data._iu_list, data._hw_list]
202+
203+
204+
def __cleanup__(layer_size=default_size):
205+
# clean up written data
206+
for l in data.zeros_list:
207+
for i in range(len(l)):
208+
l[i] = 0.
209+
for l in data.random_list:
210+
for i in range(len(l)):
211+
l[i] = random.random()
212+
for i in range(len(data._t_list)):
213+
data._t_list[i] = 0.1

0 commit comments

Comments
 (0)