-
Notifications
You must be signed in to change notification settings - Fork 6
/
gen_stimuli.py
executable file
·69 lines (50 loc) · 1.73 KB
/
gen_stimuli.py
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
#!/usr/bin/env python
import sys
import random
# Copyright 2017 ETH Zurich and University of Bologna.
# Copyright and related rights are licensed under the Solderpad Hardware
# License, Version 0.51 (the License); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# https://solderpad.org/licenses/SHL-0.51. Unless required by applicable law
# or agreed to in writing, software, hardware and materials distributed under
# this License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
def write_arr(f, name, arr):
f.write('const char %s[] = {\n' % name)
for v in arr:
f.write('%d,\n' % (v))
f.write('};\n\n')
return
def write_arr2(f, name, arr):
f.write('const int %s[] = {\n' % name)
for v in arr:
f.write('%d,\n' % (v))
f.write('};\n\n')
return
################################################################################
f = open('dotMatrixMul8_stimuli.h', 'w')
f.write('#ifndef _DOTMATMUL8_\n')
f.write('#define _DOTMATMUL8_\n')
SIZE = 8
RANGE = 4
m_a = []
m_b = []
m_exp = []
for i in range(0,SIZE):
for j in range(0,SIZE):
a = random.randint(-RANGE, RANGE-1)
b = random.randint(-RANGE, RANGE-1)
m_a.append(a)
m_b.append(b)
for i in range(0,SIZE):
for j in range(0,SIZE):
r = 0
for k in range (0,SIZE):
r = r + m_a[i * SIZE + k] * m_b[k * SIZE + j]
m_exp.append(r)
write_arr(f, 'm_a', m_a)
write_arr(f, 'm_b', m_b)
write_arr2(f, 'm_exp', m_exp)
f.write('#define SIZE %d\n' % SIZE)
f.write('#endif')