2020-10-16 12:18:09 +08:00
|
|
|
from nmigen import *
|
|
|
|
from nmigen.asserts import *
|
|
|
|
from nmigen.test.utils import *
|
|
|
|
from ...sed.output_network import *
|
2020-11-11 13:59:40 +08:00
|
|
|
from datetime import datetime
|
2020-10-16 12:18:09 +08:00
|
|
|
|
|
|
|
"""
|
|
|
|
Verification tasks for OutputNetwork
|
|
|
|
"""
|
|
|
|
|
2020-11-05 11:35:00 +08:00
|
|
|
class OutputNetworkSpec(Elaboratable):
|
2020-11-09 11:47:47 +08:00
|
|
|
def __init__(self, lane_count, seqn_width, layout_payload):
|
|
|
|
self.lane_count = lane_count
|
|
|
|
self.seqn_width = seqn_width
|
|
|
|
self.layout_payload = layout_payload
|
2020-11-05 11:35:00 +08:00
|
|
|
def elaborate(self, platform):
|
|
|
|
m = Module()
|
2020-11-09 11:47:47 +08:00
|
|
|
m.submodules.output_network = output_network = OutputNetwork(self.lane_count, self.seqn_width, self.layout_payload)
|
2020-11-05 11:35:00 +08:00
|
|
|
|
|
|
|
# Model arbitrary inputs for network nodes
|
|
|
|
for i in range(output_network.lane_count):
|
|
|
|
m.d.comb += output_network.input[i].eq(AnySeq(1))
|
|
|
|
m.d.comb += output_network.input[i].seqn.eq(AnySeq(output_network.seqn_width))
|
|
|
|
m.d.comb += output_network.input[i].replace_occured.eq(0)
|
|
|
|
m.d.comb += output_network.input[i].nondata_replace_occured.eq(0)
|
|
|
|
for field, width in output_network.layout_payload:
|
|
|
|
m.d.comb += getattr(output_network.input[i].payload, field).eq(AnySeq(width))
|
|
|
|
# Indicator of when inputs from the first clock cycle make it
|
|
|
|
# through the sorting network
|
|
|
|
network_latency = latency(output_network.lane_count)
|
|
|
|
counter = Signal(range(network_latency + 1))
|
|
|
|
m.d.sync += counter.eq(counter + 1)
|
|
|
|
with m.If(counter == network_latency):
|
|
|
|
m.d.sync += counter.eq(counter)
|
|
|
|
f_output_valid = Signal()
|
|
|
|
m.d.comb += f_output_valid.eq(counter == network_latency)
|
|
|
|
|
|
|
|
with m.If(f_output_valid):
|
2020-11-10 12:53:30 +08:00
|
|
|
valid_replacement_occurred = Signal()
|
2020-11-05 11:35:00 +08:00
|
|
|
for node in output_network.output:
|
2020-11-10 12:53:30 +08:00
|
|
|
with m.If(node.valid & node.replace_occured):
|
|
|
|
m.d.comb += valid_replacement_occurred.eq(1)
|
2020-11-05 16:34:53 +08:00
|
|
|
valid_channels_unique = Signal(reset=1)
|
2020-11-05 11:35:00 +08:00
|
|
|
for node1 in range(len(output_network.input)):
|
2020-11-05 16:34:53 +08:00
|
|
|
with m.If(Past(output_network.input[node1].valid, clocks=network_latency)):
|
|
|
|
for node2 in range(node1):
|
|
|
|
with m.If(Past(output_network.input[node2].valid, clocks=network_latency)):
|
|
|
|
k1 = Past(output_network.input[node1].payload.channel, clocks=network_latency)
|
|
|
|
k2 = Past(output_network.input[node2].payload.channel, clocks=network_latency)
|
|
|
|
with m.If(k1 == k2):
|
|
|
|
m.d.comb += valid_channels_unique.eq(0)
|
2020-11-10 12:53:30 +08:00
|
|
|
# Among the valid outputs, if there are no replacements then:
|
|
|
|
# - Channel numbers are unique among valid inputs
|
|
|
|
# - All valid inputs make it through the sorting network unmodified
|
|
|
|
with m.If(~valid_replacement_occurred):
|
2020-11-05 16:34:53 +08:00
|
|
|
m.d.comb += Assert(valid_channels_unique)
|
|
|
|
for input_node in output_network.input:
|
|
|
|
appeared = Signal()
|
|
|
|
for output_node in output_network.output:
|
|
|
|
match = Signal(reset=1)
|
|
|
|
with m.If(Past(input_node.valid, clocks=network_latency) != output_node.valid):
|
|
|
|
m.d.comb += match.eq(0)
|
|
|
|
with m.If(Past(input_node.seqn, clocks=network_latency) != output_node.seqn):
|
|
|
|
m.d.comb += match.eq(0)
|
|
|
|
with m.If(Past(input_node.replace_occured, clocks=network_latency) != output_node.replace_occured):
|
|
|
|
m.d.comb += match.eq(0)
|
|
|
|
with m.If(Past(input_node.nondata_replace_occured, clocks=network_latency) != output_node.nondata_replace_occured):
|
|
|
|
m.d.comb += match.eq(0)
|
|
|
|
for field, _ in output_network.layout_payload:
|
|
|
|
with m.If(Past(getattr(input_node.payload, field), clocks=network_latency) != getattr(output_node.payload, field)):
|
|
|
|
m.d.comb += match.eq(0)
|
|
|
|
with m.If(match):
|
|
|
|
m.d.comb += appeared.eq(1)
|
2020-11-10 12:53:30 +08:00
|
|
|
with m.If(Past(input_node.valid, clocks=network_latency)):
|
|
|
|
m.d.comb += Assert(appeared)
|
|
|
|
# Otherwise:
|
|
|
|
# - There is a channel number collision among the valid inputs
|
2020-11-10 17:12:49 +08:00
|
|
|
# - All channel numbers in valid inputs appear at least once as a
|
2020-11-05 11:35:00 +08:00
|
|
|
# valid output
|
|
|
|
# - All valid outputs correspond to a valid input modulo accounting
|
|
|
|
# information
|
2020-11-05 16:34:53 +08:00
|
|
|
with m.Else():
|
2020-11-10 12:53:30 +08:00
|
|
|
m.d.comb += Assert(~valid_channels_unique)
|
2020-11-05 16:34:53 +08:00
|
|
|
for input_node in output_network.input:
|
|
|
|
with m.If(Past(input_node.valid, clocks=network_latency)):
|
2020-11-10 17:12:49 +08:00
|
|
|
appeared = Signal()
|
|
|
|
for output_node in output_network.output:
|
|
|
|
with m.If(output_node.valid & (output_node.payload.channel == Past(input_node.payload.channel, clocks=network_latency))):
|
|
|
|
m.d.comb += appeared.eq(1)
|
|
|
|
m.d.comb += Assert(appeared)
|
2020-11-05 16:34:53 +08:00
|
|
|
for output_node in output_network.output:
|
|
|
|
with m.If(output_node.valid):
|
|
|
|
found_input = Signal()
|
|
|
|
for input_node in output_network.input:
|
|
|
|
match = Signal(reset=1)
|
|
|
|
with m.If(~Past(input_node.valid, clocks=network_latency)):
|
|
|
|
m.d.comb += match.eq(0)
|
|
|
|
with m.If(Past(input_node.seqn, clocks=network_latency) != output_node.seqn):
|
|
|
|
m.d.comb += match.eq(0)
|
|
|
|
for field, _ in output_network.layout_payload:
|
|
|
|
with m.If(Past(getattr(input_node.payload, field), clocks=network_latency) != getattr(output_node.payload, field)):
|
|
|
|
m.d.comb += match.eq(0)
|
|
|
|
with m.If(match):
|
|
|
|
m.d.comb += found_input.eq(1)
|
|
|
|
m.d.comb += Assert(found_input)
|
2020-11-05 11:35:00 +08:00
|
|
|
|
|
|
|
return m
|
|
|
|
|
2020-10-16 12:18:09 +08:00
|
|
|
class OutputNetworkTestCase(FHDLTestCase):
|
|
|
|
def verify(self):
|
2020-11-11 13:59:40 +08:00
|
|
|
startTime = datetime.now()
|
2020-11-10 13:00:18 +08:00
|
|
|
self.assertFormal(
|
|
|
|
OutputNetworkSpec(2, 2, [("data", 32), ("channel", 3)]),
|
|
|
|
mode="prove", depth=latency(2))
|
2020-11-11 13:59:40 +08:00
|
|
|
print("Verification of sorting network with 2 lanes completed in %f ms" % ((datetime.now() - startTime).total_seconds() * 1000))
|
|
|
|
startTime = datetime.now()
|
2020-10-16 12:18:09 +08:00
|
|
|
self.assertFormal(
|
2020-11-09 11:47:47 +08:00
|
|
|
OutputNetworkSpec(4, 2, [("data", 32), ("channel", 3)]),
|
|
|
|
mode="prove", depth=latency(4))
|
2020-11-11 13:59:40 +08:00
|
|
|
print("Verification of sorting network with 4 lanes completed in %f ms" % ((datetime.now() - startTime).total_seconds() * 1000))
|
|
|
|
startTime = datetime.now()
|
2020-11-10 17:12:49 +08:00
|
|
|
self.assertFormal(
|
|
|
|
OutputNetworkSpec(8, 2, [("data", 32), ("channel", 3)]),
|
|
|
|
mode="prove", depth=latency(8))
|
2020-11-11 13:59:40 +08:00
|
|
|
print("Verification of sorting network with 8 lanes completed in %f ms" % ((datetime.now() - startTime).total_seconds() * 1000))
|
2020-10-16 12:18:09 +08:00
|
|
|
|
|
|
|
OutputNetworkTestCase().verify()
|