Use single SimMemTrace instance

This commit is contained in:
Hansung Kim
2023-03-04 21:57:47 -08:00
parent 172ab51355
commit ef1608505f

View File

@@ -8,7 +8,7 @@ import freechips.rocketchip.config.Parameters
import freechips.rocketchip.diplomacy._ import freechips.rocketchip.diplomacy._
import freechips.rocketchip.unittest._ import freechips.rocketchip.unittest._
class CoalescingLogic(threads: Int = 1)(implicit p: Parameters) class CoalescingLogic(numThreads: Int = 1)(implicit p: Parameters)
extends LazyModule { extends LazyModule {
val node = TLIdentityNode() val node = TLIdentityNode()
@@ -29,7 +29,7 @@ class CoalescingLogic(threads: Int = 1)(implicit p: Parameters)
fifoId = Some(0) fifoId = Some(0)
) )
) )
val vec_node_entry = Seq.tabulate(threads) { _ => val vec_node_entry = Seq.tabulate(numThreads) { _ =>
TLManagerNode(Seq(TLSlavePortParameters.v1(seqparam, beatBytes))) TLManagerNode(Seq(TLSlavePortParameters.v1(seqparam, beatBytes)))
} }
// Assign each vec_node to the identity node // Assign each vec_node to the identity node
@@ -37,7 +37,6 @@ class CoalescingLogic(threads: Int = 1)(implicit p: Parameters)
lazy val module = new Impl lazy val module = new Impl
class Impl extends LazyModuleImp(this) { class Impl extends LazyModuleImp(this) {
// Example 1: accessing the entire A channel data for Thread 0 // Example 1: accessing the entire A channel data for Thread 0
val (tl_in_0, edge0) = vec_node_entry(0).in(0) val (tl_in_0, edge0) = vec_node_entry(0).in(0)
dontTouch(tl_in_0.a) dontTouch(tl_in_0.a)
@@ -48,9 +47,7 @@ class CoalescingLogic(threads: Int = 1)(implicit p: Parameters)
} }
} }
class CoalescingEntry(implicit p: Parameters) class CoalescingEntry(implicit p: Parameters) extends LazyModule {
extends LazyModule {
val node = TLIdentityNode() val node = TLIdentityNode()
lazy val module = new Impl lazy val module = new Impl
@@ -64,10 +61,10 @@ class CoalescingEntry(implicit p: Parameters)
} }
} }
class MemTraceDriver(threads: Int = 1)(implicit p: Parameters) class MemTraceDriver(numThreads: Int = 1)(implicit p: Parameters)
extends LazyModule { extends LazyModule {
// Create N client nodes together // Create N client nodes together
val thread_nodes = Seq.tabulate(threads) { i => val thread_nodes = Seq.tabulate(numThreads) { i =>
val clients = Seq( val clients = Seq(
TLMasterParameters.v1( TLMasterParameters.v1(
name = "MemTraceDriver" + i.toString, name = "MemTraceDriver" + i.toString,
@@ -84,29 +81,37 @@ class MemTraceDriver(threads: Int = 1)(implicit p: Parameters)
node := thread_node node := thread_node
} }
lazy val module = new MemTraceDriverImp(this, "YourTraceFileName", threads) lazy val module = new MemTraceDriverImp(this, numThreads)
}
class TraceReq extends Bundle {
val valid = Bool()
val address = UInt(64.W)
val finished = Bool()
} }
class MemTraceDriverImp( class MemTraceDriverImp(
outer: MemTraceDriver, outer: MemTraceDriver,
trace_file: String, numThreads: Int
num_threads: Int ) extends LazyModuleImp(outer) {
) extends LazyModuleImp(outer) val io = IO(new Bundle with UnitTestIO {
with UnitTestModule { val reqs = Output(Vec(numThreads, new TraceReq))
// Creating N indepdent behaving thread modules })
val sims = Seq.tabulate(num_threads) { i => val sim = Module(new SimMemTrace(filename = "vecadd.core1.thread4.trace", 4))
val ith_file_name = trace_file + (i + 1).toString (0 to numThreads - 1).map(i =>
Module(new SimMemTrace(trace_file = ith_file_name, 4)) // Split sim.io.trace_read.address, which is flattened across all lanes,
} // back to each lane's value.
io.reqs(i).address := (sim.io.trace_read.address >> (64 * i))
)
sim.io.clock := clock
sim.io.reset := reset.asBool
sim.io.trace_read.ready := true.B
// Connect each sim module to its respective TL connection // Connect each sim module to its respective TL connection
sims.zipWithIndex.foreach { case (sim, i) => (0 to numThreads - 1).map { i =>
sim.io.clock := clock
sim.io.reset := reset.asBool
sim.io.trace_read.ready := true.B
val (tl_out, edge) = outer.thread_nodes(i).out(0) val (tl_out, edge) = outer.thread_nodes(i).out(0)
tl_out.a.valid := sim.io.trace_read.valid tl_out.a.valid := sim.io.trace_read.valid
// TODO: placeholders, use actual value from trace
tl_out.a.bits := edge tl_out.a.bits := edge
.Put( .Put(
fromSource = 0.U, fromSource = 0.U,
@@ -122,14 +127,12 @@ class MemTraceDriverImp(
tl_out.d.ready := true.B tl_out.d.ready := true.B
} }
// FIXME, current this simulation terminates when thread 0 terminates io.finished := sim.io.trace_read.finished
// we're finished when there is no more memtrace to read
io.finished := !sims(0).io.trace_read.valid
} }
class SimMemTrace(val trace_file: String, num_threads: Int) class SimMemTrace(val filename: String, numThreads: Int)
extends BlackBox( extends BlackBox(
Map("TRACE_FILE" -> trace_file, "NUM_THREADS" -> num_threads) Map("filename" -> filename, "numThreads" -> numThreads)
) )
with HasBlackBoxResource { with HasBlackBoxResource {
val io = IO(new Bundle { val io = IO(new Bundle {
@@ -138,10 +141,10 @@ class SimMemTrace(val trace_file: String, num_threads: Int)
val trace_read = new Bundle { val trace_read = new Bundle {
val ready = Input(Bool()) val ready = Input(Bool())
val valid = Output(UInt(num_threads.W)) val valid = Output(UInt(numThreads.W))
// Chisel can't interface with Verilog 2D port, so flatten all lanes into // Chisel can't interface with Verilog 2D port, so flatten all lanes into
// single wide 1D array. // single wide 1D array.
val address = Output(UInt((64 * num_threads).W)) val address = Output(UInt((64 * numThreads).W))
val finished = Output(Bool()) val finished = Output(Bool())
} }
}) })
@@ -153,8 +156,8 @@ class SimMemTrace(val trace_file: String, num_threads: Int)
class CoalConnectTrace(implicit p: Parameters) extends LazyModule { class CoalConnectTrace(implicit p: Parameters) extends LazyModule {
val coal_entry = LazyModule(new CoalescingEntry) val coal_entry = LazyModule(new CoalescingEntry)
val coal_logic = LazyModule(new CoalescingLogic(threads = 2)) val coal_logic = LazyModule(new CoalescingLogic(numThreads = 4))
val driver = LazyModule(new MemTraceDriver(threads = 2)) val driver = LazyModule(new MemTraceDriver(numThreads = 4))
coal_logic.node :=* coal_entry.node :=* driver.node coal_logic.node :=* coal_entry.node :=* driver.node