|
|
@ -11,28 +11,28 @@ def test_nand_delays(): |
|
|
|
c = np.full((5*16, 1), TMAX) # 5 waveforms of capacity 16 |
|
|
|
c = np.full((5*16, 1), TMAX) # 5 waveforms of capacity 16 |
|
|
|
c_locs = np.zeros((5,), dtype='int') |
|
|
|
c_locs = np.zeros((5,), dtype='int') |
|
|
|
c_caps = np.zeros((5,), dtype='int') |
|
|
|
c_caps = np.zeros((5,), dtype='int') |
|
|
|
|
|
|
|
|
|
|
|
for i in range(5): c_locs[i], c_caps[i] = i*16, 16 # 1:1 mapping |
|
|
|
for i in range(5): c_locs[i], c_caps[i] = i*16, 16 # 1:1 mapping |
|
|
|
|
|
|
|
|
|
|
|
# SDF specifies IOPATH delays with respect to output polarity |
|
|
|
# SDF specifies IOPATH delays with respect to output polarity |
|
|
|
# SDF pulse rejection value is determined by IOPATH causing last transition and polarity of last transition |
|
|
|
# SDF pulse rejection value is determined by IOPATH causing last transition and polarity of last transition |
|
|
|
line_times = np.zeros((5, 2, 2)) |
|
|
|
delays = np.zeros((1, 5, 2, 2)) |
|
|
|
line_times[0, 0, 0] = 0.1 # A -> Z rise delay |
|
|
|
delays[0, 0, 0, 0] = 0.1 # A -> Z rise delay |
|
|
|
line_times[0, 0, 1] = 0.2 # A -> Z fall delay |
|
|
|
delays[0, 0, 0, 1] = 0.2 # A -> Z fall delay |
|
|
|
line_times[0, 1, 0] = 0.1 # A -> Z negative pulse limit (terminate in rising Z) |
|
|
|
delays[0, 0, 1, 0] = 0.1 # A -> Z negative pulse limit (terminate in rising Z) |
|
|
|
line_times[0, 1, 1] = 0.2 # A -> Z positive pulse limit |
|
|
|
delays[0, 0, 1, 1] = 0.2 # A -> Z positive pulse limit |
|
|
|
line_times[1, :, 0] = 0.3 # as above for B -> Z |
|
|
|
delays[0, 1, :, 0] = 0.3 # as above for B -> Z |
|
|
|
line_times[1, :, 1] = 0.4 |
|
|
|
delays[0, 1, :, 1] = 0.4 |
|
|
|
line_times[2, :, 0] = 0.5 # as above for C -> Z |
|
|
|
delays[0, 2, :, 0] = 0.5 # as above for C -> Z |
|
|
|
line_times[2, :, 1] = 0.6 |
|
|
|
delays[0, 2, :, 1] = 0.6 |
|
|
|
line_times[3, :, 0] = 0.7 # as above for D -> Z |
|
|
|
delays[0, 3, :, 0] = 0.7 # as above for D -> Z |
|
|
|
line_times[3, :, 1] = 0.8 |
|
|
|
delays[0, 3, :, 1] = 0.8 |
|
|
|
|
|
|
|
|
|
|
|
sdata = np.asarray([1, -1, 0, 0], dtype='float32') |
|
|
|
sdata = np.asarray([1, -1, 0, 0], dtype='float32') |
|
|
|
|
|
|
|
|
|
|
|
def wave_assert(inputs, output): |
|
|
|
def wave_assert(inputs, output): |
|
|
|
for i, a in zip(inputs, c.reshape(-1,16)): a[:len(i)] = i |
|
|
|
for i, a in zip(inputs, c.reshape(-1,16)): a[:len(i)] = i |
|
|
|
wave_eval_cpu(op, c, c_locs, c_caps, 0, line_times, sdata) |
|
|
|
wave_eval_cpu(op, c, c_locs, c_caps, 0, delays, sdata) |
|
|
|
for i, v in enumerate(output): np.testing.assert_allclose(c.reshape(-1,16)[4,i], v) |
|
|
|
for i, v in enumerate(output): np.testing.assert_allclose(c.reshape(-1,16)[4,i], v) |
|
|
|
|
|
|
|
|
|
|
|
wave_assert([[TMAX,TMAX],[TMAX,TMAX],[TMIN,TMAX],[TMIN,TMAX]], [TMIN,TMAX]) # NAND(0,0,1,1) => 1 |
|
|
|
wave_assert([[TMAX,TMAX],[TMAX,TMAX],[TMIN,TMAX],[TMIN,TMAX]], [TMIN,TMAX]) # NAND(0,0,1,1) => 1 |
|
|
@ -50,75 +50,74 @@ def test_nand_delays(): |
|
|
|
|
|
|
|
|
|
|
|
def test_tiny_circuit(): |
|
|
|
def test_tiny_circuit(): |
|
|
|
c = bench.parse('input(x, y) output(a, o, n) a=and(x,y) o=or(x,y) n=not(x)') |
|
|
|
c = bench.parse('input(x, y) output(a, o, n) a=and(x,y) o=or(x,y) n=not(x)') |
|
|
|
lt = np.zeros((len(c.lines), 2, 2)) |
|
|
|
delays = np.full((1, len(c.lines), 2, 2), 1.0) # unit delay for all lines |
|
|
|
lt[:,0,:] = 1.0 # unit delay for all lines |
|
|
|
wsim = WaveSim(c, delays) |
|
|
|
wsim = WaveSim(c, lt) |
|
|
|
|
|
|
|
assert wsim.s.shape[1] == 5 |
|
|
|
assert wsim.s.shape[1] == 5 |
|
|
|
|
|
|
|
|
|
|
|
# values for x |
|
|
|
# values for x |
|
|
|
wsim.s[:3,0,0] = 0, 0.1, 0 |
|
|
|
wsim.s[:3,0,0] = 0, 10, 0 |
|
|
|
wsim.s[:3,0,1] = 0, 0.2, 1 |
|
|
|
wsim.s[:3,0,1] = 0, 20, 1 |
|
|
|
wsim.s[:3,0,2] = 1, 0.3, 0 |
|
|
|
wsim.s[:3,0,2] = 1, 30, 0 |
|
|
|
wsim.s[:3,0,3] = 1, 0.4, 1 |
|
|
|
wsim.s[:3,0,3] = 1, 40, 1 |
|
|
|
|
|
|
|
|
|
|
|
# values for y |
|
|
|
# values for y |
|
|
|
wsim.s[:3,1,0] = 1, 0.5, 0 |
|
|
|
wsim.s[:3,1,0] = 1, 50, 0 |
|
|
|
wsim.s[:3,1,1] = 1, 0.6, 0 |
|
|
|
wsim.s[:3,1,1] = 1, 60, 0 |
|
|
|
wsim.s[:3,1,2] = 1, 0.7, 0 |
|
|
|
wsim.s[:3,1,2] = 1, 70, 0 |
|
|
|
wsim.s[:3,1,3] = 0, 0.8, 1 |
|
|
|
wsim.s[:3,1,3] = 0, 80, 1 |
|
|
|
|
|
|
|
|
|
|
|
wsim.s_to_c() |
|
|
|
wsim.s_to_c() |
|
|
|
|
|
|
|
|
|
|
|
x_c_loc = wsim.c_locs[wsim.ppi_offset+0] # check x waveforms |
|
|
|
x_c_loc = wsim.c_locs[wsim.ppi_offset+0] # check x waveforms |
|
|
|
np.testing.assert_allclose(wsim.c[x_c_loc:x_c_loc+3, 0], [TMAX, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[x_c_loc:x_c_loc+3, 0], [TMAX, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[x_c_loc:x_c_loc+3, 1], [0.2, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[x_c_loc:x_c_loc+3, 1], [20, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[x_c_loc:x_c_loc+3, 2], [TMIN, 0.3, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[x_c_loc:x_c_loc+3, 2], [TMIN, 30, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[x_c_loc:x_c_loc+3, 3], [TMIN, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[x_c_loc:x_c_loc+3, 3], [TMIN, TMAX, TMAX]) |
|
|
|
|
|
|
|
|
|
|
|
y_c_loc = wsim.c_locs[wsim.ppi_offset+1] # check y waveforms |
|
|
|
y_c_loc = wsim.c_locs[wsim.ppi_offset+1] # check y waveforms |
|
|
|
np.testing.assert_allclose(wsim.c[y_c_loc:y_c_loc+3, 0], [TMIN, 0.5, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[y_c_loc:y_c_loc+3, 0], [TMIN, 50, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[y_c_loc:y_c_loc+3, 1], [TMIN, 0.6, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[y_c_loc:y_c_loc+3, 1], [TMIN, 60, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[y_c_loc:y_c_loc+3, 2], [TMIN, 0.7, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[y_c_loc:y_c_loc+3, 2], [TMIN, 70, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[y_c_loc:y_c_loc+3, 3], [0.8, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[y_c_loc:y_c_loc+3, 3], [80, TMAX, TMAX]) |
|
|
|
|
|
|
|
|
|
|
|
wsim.c_prop() |
|
|
|
wsim.c_prop() |
|
|
|
|
|
|
|
|
|
|
|
a_c_loc = wsim.c_locs[wsim.ppo_offset+2] # check a waveforms |
|
|
|
a_c_loc = wsim.c_locs[wsim.ppo_offset+2] # check a waveforms |
|
|
|
np.testing.assert_allclose(wsim.c[a_c_loc:a_c_loc+3, 0], [TMAX, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[a_c_loc:a_c_loc+3, 0], [TMAX, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[a_c_loc:a_c_loc+3, 1], [1.2, 1.6, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[a_c_loc:a_c_loc+3, 1], [21, 61, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[a_c_loc:a_c_loc+3, 2], [TMIN, 1.3, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[a_c_loc:a_c_loc+3, 2], [TMIN, 31, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[a_c_loc:a_c_loc+3, 3], [1.8, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[a_c_loc:a_c_loc+3, 3], [81, TMAX, TMAX]) |
|
|
|
|
|
|
|
|
|
|
|
o_c_loc = wsim.c_locs[wsim.ppo_offset+3] # check o waveforms |
|
|
|
o_c_loc = wsim.c_locs[wsim.ppo_offset+3] # check o waveforms |
|
|
|
np.testing.assert_allclose(wsim.c[o_c_loc:o_c_loc+3, 0], [TMIN, 1.5, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[o_c_loc:o_c_loc+3, 0], [TMIN, 51, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[o_c_loc:o_c_loc+3, 1], [TMIN, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[o_c_loc:o_c_loc+3, 1], [TMIN, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[o_c_loc:o_c_loc+3, 2], [TMIN, 1.7, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[o_c_loc:o_c_loc+3, 2], [TMIN, 71, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[o_c_loc:o_c_loc+3, 3], [TMIN, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[o_c_loc:o_c_loc+3, 3], [TMIN, TMAX, TMAX]) |
|
|
|
|
|
|
|
|
|
|
|
n_c_loc = wsim.c_locs[wsim.ppo_offset+4] # check n waveforms |
|
|
|
n_c_loc = wsim.c_locs[wsim.ppo_offset+4] # check n waveforms |
|
|
|
np.testing.assert_allclose(wsim.c[n_c_loc:n_c_loc+3, 0], [TMIN, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[n_c_loc:n_c_loc+3, 0], [TMIN, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[n_c_loc:n_c_loc+3, 1], [TMIN, 1.2, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[n_c_loc:n_c_loc+3, 1], [TMIN, 21, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[n_c_loc:n_c_loc+3, 2], [1.3, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[n_c_loc:n_c_loc+3, 2], [31, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[n_c_loc:n_c_loc+3, 3], [TMAX, TMAX, TMAX]) |
|
|
|
np.testing.assert_allclose(wsim.c[n_c_loc:n_c_loc+3, 3], [TMAX, TMAX, TMAX]) |
|
|
|
|
|
|
|
|
|
|
|
wsim.c_to_s() |
|
|
|
wsim.c_to_s() |
|
|
|
|
|
|
|
|
|
|
|
# check a captures |
|
|
|
# check a captures |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 2, 0], [0, TMAX, TMIN, 0]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 2, 0], [0, TMAX, TMIN, 0]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 2, 1], [0, 1.2, 1.6, 0]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 2, 1], [0, 21, 61, 0]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 2, 2], [1, 1.3, 1.3, 0]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 2, 2], [1, 31, 31, 0]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 2, 3], [0, 1.8, 1.8, 1]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 2, 3], [0, 81, 81, 1]) |
|
|
|
|
|
|
|
|
|
|
|
# check o captures |
|
|
|
# check o captures |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 3, 0], [1, 1.5, 1.5, 0]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 3, 0], [1, 51, 51, 0]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 3, 1], [1, TMAX, TMIN, 1]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 3, 1], [1, TMAX, TMIN, 1]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 3, 2], [1, 1.7, 1.7, 0]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 3, 2], [1, 71, 71, 0]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 3, 3], [1, TMAX, TMIN, 1]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 3, 3], [1, TMAX, TMIN, 1]) |
|
|
|
|
|
|
|
|
|
|
|
# check o captures |
|
|
|
# check o captures |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 4, 0], [1, TMAX, TMIN, 1]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 4, 0], [1, TMAX, TMIN, 1]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 4, 1], [1, 1.2, 1.2, 0]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 4, 1], [1, 21, 21, 0]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 4, 2], [0, 1.3, 1.3, 1]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 4, 2], [0, 31, 31, 1]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 4, 3], [0, TMAX, TMIN, 0]) |
|
|
|
np.testing.assert_allclose(wsim.s[3:7, 4, 3], [0, TMAX, TMIN, 0]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -157,13 +156,16 @@ def compare_to_logic_sim(wsim: WaveSim): |
|
|
|
np.testing.assert_allclose(resp, exp) |
|
|
|
np.testing.assert_allclose(resp, exp) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_b14(b14_circuit, b14_timing): |
|
|
|
def test_b14(b14_circuit, b14_delays): |
|
|
|
compare_to_logic_sim(WaveSim(b14_circuit, b14_timing, 8)) |
|
|
|
compare_to_logic_sim(WaveSim(b14_circuit, b14_delays, 8)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_b14_strip_forks(b14_circuit, b14_delays): |
|
|
|
|
|
|
|
compare_to_logic_sim(WaveSim(b14_circuit, b14_delays, 8, strip_forks=True)) |
|
|
|
|
|
|
|
|
|
|
|
def test_b14_strip_forks(b14_circuit, b14_timing): |
|
|
|
|
|
|
|
compare_to_logic_sim(WaveSim(b14_circuit, b14_timing, 8, strip_forks=True)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_b14_cuda(b14_circuit, b14_delays): |
|
|
|
|
|
|
|
compare_to_logic_sim(WaveSimCuda(b14_circuit, b14_delays, 8, strip_forks=True)) |
|
|
|
|
|
|
|
|
|
|
|
def test_b14_cuda(b14_circuit, b14_timing): |
|
|
|
if __name__ == '__main__': |
|
|
|
compare_to_logic_sim(WaveSimCuda(b14_circuit, b14_timing, 8, strip_forks=True)) |
|
|
|
test_nand_delays() |