simprim, vat refactor, batchrange
This commit is contained in:
1 parent
63c0b48537
commit
5566b80e52
5 files changed
+229
-270
No files matched your search
+44
-44
@@ -2,17 +2,17 @@ import numpy as np
|
||||
|
||||
from kyupy.wave_sim import WaveSim, WaveSimCuda, wave_eval_cpu, TMIN, TMAX
|
||||
from kyupy.logic_sim import LogicSim
|
||||
from kyupy import verilog, sdf, logic, bench
|
||||
from kyupy import logic, bench, sim
|
||||
from kyupy.logic import mvarray
|
||||
from kyupy.sim import SimPrim
|
||||
|
||||
|
||||
def test_nand_delays():
|
||||
op = (SimPrim.NAND4, 4, 0, 1, 2, 3)
|
||||
op = (sim.NAND4, 4, 0, 1, 2, 3)
|
||||
#op = (0b0111, 4, 0, 1)
|
||||
c = np.full((5*16, 1), TMAX) # 5 waveforms of capacity 16
|
||||
vat = np.zeros((5, 3), dtype='int')
|
||||
for i in range(5): vat[i] = i*16, 16, 0 # 1:1 mapping
|
||||
c_locs = 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
|
||||
|
||||
# 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
|
||||
@@ -32,7 +32,7 @@ def test_nand_delays():
|
||||
|
||||
def wave_assert(inputs, output):
|
||||
for i, a in zip(inputs, c.reshape(-1,16)): a[:len(i)] = i
|
||||
wave_eval_cpu(op, c, vat, 0, line_times, sdata)
|
||||
wave_eval_cpu(op, c, c_locs, c_caps, 0, line_times, sdata)
|
||||
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
|
||||
@@ -53,29 +53,29 @@ def test_tiny_circuit():
|
||||
lt = np.zeros((len(c.lines), 2, 2))
|
||||
lt[:,0,:] = 1.0 # unit delay for all lines
|
||||
wsim = WaveSim(c, lt)
|
||||
assert len(wsim.s) == 5
|
||||
assert wsim.s.shape[1] == 5
|
||||
|
||||
# values for x
|
||||
wsim.s[0,0,:3] = 0, 0.1, 0
|
||||
wsim.s[0,1,:3] = 0, 0.2, 1
|
||||
wsim.s[0,2,:3] = 1, 0.3, 0
|
||||
wsim.s[0,3,:3] = 1, 0.4, 1
|
||||
|
||||
wsim.s[:3,0,0] = 0, 0.1, 0
|
||||
wsim.s[:3,0,1] = 0, 0.2, 1
|
||||
wsim.s[:3,0,2] = 1, 0.3, 0
|
||||
wsim.s[:3,0,3] = 1, 0.4, 1
|
||||
|
||||
# values for y
|
||||
wsim.s[1,0,:3] = 1, 0.5, 0
|
||||
wsim.s[1,1,:3] = 1, 0.6, 0
|
||||
wsim.s[1,2,:3] = 1, 0.7, 0
|
||||
wsim.s[1,3,:3] = 0, 0.8, 1
|
||||
wsim.s[:3,1,0] = 1, 0.5, 0
|
||||
wsim.s[:3,1,1] = 1, 0.6, 0
|
||||
wsim.s[:3,1,2] = 1, 0.7, 0
|
||||
wsim.s[:3,1,3] = 0, 0.8, 1
|
||||
|
||||
wsim.s_to_c()
|
||||
|
||||
x_c_loc = wsim.vat[wsim.ppi_offset+0, 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, 1], [0.2, 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, 3], [TMIN, TMAX, TMAX])
|
||||
|
||||
y_c_loc = wsim.vat[wsim.ppi_offset+1, 0] # 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, 1], [TMIN, 0.6, TMAX])
|
||||
np.testing.assert_allclose(wsim.c[y_c_loc:y_c_loc+3, 2], [TMIN, 0.7, TMAX])
|
||||
@@ -83,19 +83,19 @@ def test_tiny_circuit():
|
||||
|
||||
wsim.c_prop()
|
||||
|
||||
a_c_loc = wsim.vat[wsim.ppo_offset+2, 0] # 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, 1], [1.2, 1.6, 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, 3], [1.8, TMAX, TMAX])
|
||||
|
||||
o_c_loc = wsim.vat[wsim.ppo_offset+3, 0] # 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, 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, 3], [TMIN, TMAX, TMAX])
|
||||
|
||||
n_c_loc = wsim.vat[wsim.ppo_offset+4, 0] # 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, 1], [TMIN, 1.2, TMAX])
|
||||
np.testing.assert_allclose(wsim.c[n_c_loc:n_c_loc+3, 2], [1.3, TMAX, TMAX])
|
||||
@@ -104,22 +104,22 @@ def test_tiny_circuit():
|
||||
wsim.c_to_s()
|
||||
|
||||
# check a captures
|
||||
np.testing.assert_allclose(wsim.s[2, 0, 3:7], [0, TMAX, TMIN, 0])
|
||||
np.testing.assert_allclose(wsim.s[2, 1, 3:7], [0, 1.2, 1.6, 0])
|
||||
np.testing.assert_allclose(wsim.s[2, 2, 3:7], [1, 1.3, 1.3, 0])
|
||||
np.testing.assert_allclose(wsim.s[2, 3, 3:7], [0, 1.8, 1.8, 1])
|
||||
|
||||
# check o captures
|
||||
np.testing.assert_allclose(wsim.s[3, 0, 3:7], [1, 1.5, 1.5, 0])
|
||||
np.testing.assert_allclose(wsim.s[3, 1, 3:7], [1, TMAX, TMIN, 1])
|
||||
np.testing.assert_allclose(wsim.s[3, 2, 3:7], [1, 1.7, 1.7, 0])
|
||||
np.testing.assert_allclose(wsim.s[3, 3, 3:7], [1, TMAX, TMIN, 1])
|
||||
|
||||
# check o captures
|
||||
np.testing.assert_allclose(wsim.s[4, 0, 3:7], [1, TMAX, TMIN, 1])
|
||||
np.testing.assert_allclose(wsim.s[4, 1, 3:7], [1, 1.2, 1.2, 0])
|
||||
np.testing.assert_allclose(wsim.s[4, 2, 3:7], [0, 1.3, 1.3, 1])
|
||||
np.testing.assert_allclose(wsim.s[4, 3, 3:7], [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, 2], [1, 1.3, 1.3, 0])
|
||||
np.testing.assert_allclose(wsim.s[3:7, 2, 3], [0, 1.8, 1.8, 1])
|
||||
|
||||
# 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, 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, 3], [1, TMAX, TMIN, 1])
|
||||
|
||||
# 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, 1], [1, 1.2, 1.2, 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, 3], [0, TMAX, TMIN, 0])
|
||||
|
||||
|
||||
def compare_to_logic_sim(wsim: WaveSim):
|
||||
@@ -127,17 +127,17 @@ def compare_to_logic_sim(wsim: WaveSim):
|
||||
rng = np.random.default_rng(10)
|
||||
tests = rng.choice(choices, (wsim.s_len, wsim.sims))
|
||||
|
||||
wsim.s[:, :, 0] = (tests & 2) >> 1
|
||||
wsim.s[:, :, 3] = (tests & 2) >> 1
|
||||
wsim.s[:, :, 1] = 0.0
|
||||
wsim.s[:, :, 2] = tests & 1
|
||||
wsim.s[:, :, 6] = tests & 1
|
||||
wsim.s[0] = (tests & 2) >> 1
|
||||
wsim.s[3] = (tests & 2) >> 1
|
||||
wsim.s[1] = 0.0
|
||||
wsim.s[2] = tests & 1
|
||||
wsim.s[6] = tests & 1
|
||||
|
||||
wsim.s_to_c()
|
||||
wsim.c_prop()
|
||||
wsim.c_to_s()
|
||||
|
||||
resp = np.array(wsim.s[:, :, 6], dtype=np.uint8) | (np.array(wsim.s[:, :, 3], dtype=np.uint8)<<1)
|
||||
resp = np.array(wsim.s[6], dtype=np.uint8) | (np.array(wsim.s[3], dtype=np.uint8)<<1)
|
||||
resp |= ((resp ^ (resp >> 1)) & 1) << 2 # transitions
|
||||
resp[wsim.pi_s_locs] = logic.UNASSIGNED
|
||||
|
||||
|
||||
Reference in new issue
Block a user