-
Notifications
You must be signed in to change notification settings - Fork 3
/
xbar_test.py
122 lines (106 loc) · 4.52 KB
/
xbar_test.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
'''Tests the crossbar array HSPICE netlist and PWLs based on the output transients'''
import argparse
import json
import numpy as np
from helper import getpat
# Parse arguments
parser = argparse.ArgumentParser(description='Test the results of a crossbar array from SPICE.')
parser.add_argument('config', help='configuration JSON file')
parser.add_argument('--visualize', help='display checkerboard visualization', action="store_true")
parser.add_argument('--verbose', help='display breakdown of testcases', action="store_true")
args = parser.parse_args()
# Define parameters
params = json.load(open(args.config))
# Open transient result file
infile = open("tr0/%s.tr0" % params['title'])
# Get signal names
nsigs = int(infile.read(4)) + int(infile.read(4))
line = infile.readline()
header = ''
while line.strip()[-4:] != '$&%#':
line = infile.readline()[:-1]
header += line
signals = filter(lambda x: x != '', header.split(' '))[-nsigs-1:-1]
# Function to search .tr0 file for point in range
def find_point_in_range(infile, tmin, tmax):
point = {'TIME' : -1}
while point['TIME'] < tmax:
sigs = []
for _ in range(nsigs):
sigs.append(float(infile.read(11)))
pos = infile.tell()
nextchar = infile.read(1)
if nextchar != '\n':
infile.seek(pos)
point = dict(zip(signals,sigs))
if point['TIME'] >= tmin and point['TIME'] <= tmax:
return point
raise Exception("Could not find time point in range (%s, %s)" % (tmin, tmax))
# Process tests
passed = True
for test in params['tests']:
# Get verify method
verify = test['verify']
# Get pattern
pat = getpat(test, params)
# Skip initial wait+read
t = test['wait'] * 2
if params['type'] == '1R':
t += len(pat) * (test['read']['pw'] + test['wait'])
elif params['type'] == '2R':
t += test['read']['pw'] + test['wait']
for flip in range(test['flips']):
# Skip write pulses
# TODO: not assume same PW for set/reset
t += len(pat) * (test['set']['pw'] + test['wait'])
meas = np.empty((params['rows'], params['cols']))
meas[:] = np.nan
# 1R verification
if params['type'] == '1R':
# Check column current
if verify['method'] == 'current':
for i, j in pat:
point = find_point_in_range(infile, t + test['slewtime'], t + test['read']['pw'] + test['wait'] - test['slewtime'])
meas[i][j] = point["i(vcol_%s" % j]
t += test['read']['pw'] + test['wait']
# Check RRAM filament gap
elif verify['method'] == 'gap':
for i, j in pat:
point = find_point_in_range(infile, t + test['read']['pw'] + test['slewtime'], t + test['read']['pw'] + test['wait'] - test['slewtime'])
meas[i][j] = point["v(gap_%s_%s" % (i,j)]
t += test['read']['pw'] + test['wait']
# 2R verification
elif params['type'] == '2R':
# Check 2R midpoint voltage
if verify['method'] == 'midvoltage':
point = find_point_in_range(infile, t + test['slewtime'], t + test['read']['pw'] + test['wait'] - test['slewtime'])
for i, j in pat:
meas[i][j] = point["v(mid_%s_%s" % (i,j)]
t += test['read']['pw'] + test['wait']
# Display checkerboard if specified
if args.visualize:
import matplotlib, matplotlib.pyplot as plt
if args.verbose:
print(meas)
vmin = min(verify['bounds']['lo'][1], verify['bounds']['hi'][1])*0.99999
vmax = max(verify['bounds']['lo'][0], verify['bounds']['hi'][0])*1.00001
cmap = matplotlib.cm.get_cmap('gray')
cmap.set_bad(color='red')
plt.imshow(meas, cmap, origin='upper', interpolation='nearest', vmin=vmin, vmax=vmax)
plt.show()
# Check if tests passed
for i, j in pat:
expected = 'hi' if (i+j+flip) % 2 == 0 else 'lo'
tpass = meas[i][j] >= verify['bounds'][expected][0] and meas[i][j] <= verify['bounds'][expected][1]
if args.verbose:
print("(flip, i, j, pass) = (%s, %s, %s, %s)" % (flip, i, j, tpass))
if not tpass:
print("Measured: %s" % meas[i][j])
passed = passed and tpass
# Close transient result file
infile.close()
# Display if passed
if passed:
print("PASSED!")
else:
print("FAILED!")