pre-merge

This commit is contained in:
Richard Yan
2023-04-22 21:28:38 -07:00
parent 8715bede37
commit b895d304bb

View File

@@ -71,30 +71,38 @@ class RespQueueEntry(sourceWidth: Int, sizeWidth: Int, maxSize: Int) extends Bun
}
class MonoCoalescer(size: Int, window: Seq[CoalShiftQueue]) extends Module {
// constructor: size, window
// inputs: none
// outputs: leader idx, base addr, match OH, match count, coverage hits
class MonoCoalescer[QueueT: CoalShiftQueue](coalSize: Int, coalWindow: Seq[QueueT]) extends Module {
val io = IO(new Bundle {
val leader_idx = Output(UInt(log2Ceil(CoalescerConsts.NUM_LANES).W)),
val base_addr = Output(UInt(CoalescerConsts.ADDR_WIDTH.W)),
val match_oh = Output(Vec(NUM_LANES, UInt(CoalescerConsts.DEPTH.W))),
val leader_idx = Output(UInt(log2Ceil(CoalescerConsts.NUM_LANES).W))
val base_addr = Output(UInt(CoalescerConsts.ADDR_WIDTH.W))
val match_oh = Output(Vec(CoalescerConsts.NUM_LANES, UInt(CoalescerConsts.DEPTH.W)))
val coverage_hits = Output(UInt((1 << CoalescerConsts.MAX_SIZE).W))
})
// def can_match(req0: ReqQueueEntry, req1: ReqQueueEntry): Bool
val size = coalSize
val mask = ((1 << CoalescerConsts.ADDR_WIDTH - 1) - (1 << size - 1)).U
val window = coalWindow
def can_match(req0: Valid[ReqQueueEntry], req1: Valid[ReqQueueEntry]): Bool = {
(req0.bits.op === req1.bits.op) &&
(req0.valid && req1.valid) &&
((req0.bits.address & this.mask) === (req1.bits.address & this.mask))
}
// combinational logic to drive output from window contents
leaders = coalWindow.map(_.head)
}
class MultiCoalescer(sizes: Seq[Int], window: Seq[CoalShiftQueue], reqQueueEntryT: ReqQueueEntry) extends Module {
// constructor: sizes, window: Seq[CoalShiftQueue]
// instantiate MonoCoalescers
class MultiCoalescer[QueueT: CoalShiftQueue]
(sizes: Seq[Int], window: Seq[QueueT], reqQueueEntryT: ReqQueueEntry) extends Module {
val coalescers = sizes.map(size => Module(new MonoCoalescer(size, window)))
// inputs: none
// outputs: out_req: Valid(ReqQueueEntry), invalidate: Valid(Seq[UInt(LOGDEPTH.W)])
val io = IO(new Bundle {
val out_req = Output(Valid(reqQueueEntryT.cloneType)),
val invalidate = Output(Valid(UInt(log2Ceil(LOGDEPTH.W)))),
val out_req = Output(Valid(reqQueueEntryT.cloneType))
val invalidate = Output(Valid(UInt(log2Ceil(CoalescerConsts.LOGDEPTH.W))))
})
}
@@ -360,7 +368,7 @@ class UncoalescingUnit(
val sourceWidth: Int,
val coalDataWidth: Int,
val numInflightCoalRequests: Int
) extends Module {
) extends Module {
val inflightTable = Module(
new InflightCoalReqTable(numLanes, numPerLaneReqs, sourceWidth, numInflightCoalRequests)
)
@@ -442,7 +450,7 @@ class InflightCoalReqTable(
val numPerLaneReqs: Int,
val sourceWidth: Int,
val entries: Int
) extends Module {
) extends Module {
val offsetBits = 4 // FIXME hardcoded
val sizeBits = 2 // FIXME hardcoded
val entryT =
@@ -522,7 +530,7 @@ class InflightCoalReqTableEntry(
val sourceWidth: Int,
val offsetBits: Int,
val sizeBits: Int
) extends Bundle {
) extends Bundle {
class CoreReq extends Bundle {
val valid = Bool()
val offset = UInt(offsetBits.W)
@@ -547,13 +555,12 @@ class CoalShiftQueue[T <: Data](
val entries: Int,
pipe: Boolean = true,
flow: Boolean = false
) extends Module {
) extends Module {
val io = IO(new Bundle {
val queue = new QueueIO(gen, entries) {
val queue = new QueueIO(gen, entries)
val invalidate = Input(Valid(UInt(entries.W)))
val mask = Output(UInt(entries.W))
val elts = Output(Vec(entries, gen))
}
})
private val valid = RegInit(VecInit(Seq.fill(entries) { false.B }))
@@ -576,56 +583,56 @@ class CoalShiftQueue[T <: Data](
if (i == -1) true.B else if (i == entries) false.B else mask(i)
}
def paddedUsed = pad({ i: Int => used(i) })
def validAfterInv(i: Int) = valid(i) && !io.invalidate(i)
def validAfterInv(i: Int) = valid(i) && !io.invalidate.bits(i)
val shift = io.deq.ready || (used =/= 0.U) && !validAfterInv(0)
val shift = io.queue.deq.ready || (used =/= 0.U) && !validAfterInv(0)
for (i <- 0 until entries) {
val wdata = if (i == entries - 1) io.enq.bits else Mux(!used(i + 1), io.enq.bits, elts(i + 1))
val wdata = if (i == entries - 1) io.queue.enq.bits else Mux(!used(i + 1), io.queue.enq.bits, elts(i + 1))
val wen = Mux(
shift,
(io.enq.fire && !paddedUsed(i + 1) && used(i)) || pad(validAfterInv)(i + 1),
(io.queue.enq.fire && !paddedUsed(i + 1) && used(i)) || pad(validAfterInv)(i + 1),
// enqueue to the first empty slot above the top
(io.enq.fire && paddedUsed(i - 1) && !used(i)) || !validAfterInv(i)
(io.queue.enq.fire && paddedUsed(i - 1) && !used(i)) || !validAfterInv(i)
)
when(wen) { elts(i) := wdata }
valid(i) := Mux(
shift,
(io.enq.fire && !paddedUsed(i + 1) && used(i)) || pad(validAfterInv)(i + 1),
(io.enq.fire && paddedUsed(i - 1) && !used(i)) || validAfterInv(i)
(io.queue.enq.fire && !paddedUsed(i + 1) && used(i)) || pad(validAfterInv)(i + 1),
(io.queue.enq.fire && paddedUsed(i - 1) && !used(i)) || validAfterInv(i)
)
}
when(io.enq.fire) {
when(!io.deq.fire) {
when(io.queue.enq.fire) {
when(!io.queue.deq.fire) {
used := (used << 1.U) | 1.U
}
}.elsewhen(io.deq.fire) {
}.elsewhen(io.queue.deq.fire) {
used := used >> 1.U
}
io.enq.ready := !valid(entries - 1)
io.queue.enq.ready := !valid(entries - 1)
// We don't want to invalidate deq.valid response right away even when
// io.invalidate(head) is true.
// Coalescing unit consumes queue head's validity, and produces its new
// validity. Deasserting deq.valid right away will result in a combinational
// cycle.
io.deq.valid := valid(0)
io.deq.bits := elts.head
io.queue.deq.valid := valid(0)
io.queue.deq.bits := elts.head
assert(!flow, "flow-through is not implemented")
if (flow) {
when(io.enq.valid) { io.deq.valid := true.B }
when(!valid(0)) { io.deq.bits := io.enq.bits }
when(io.queue.enq.valid) { io.queue.deq.valid := true.B }
when(!valid(0)) { io.queue.deq.bits := io.queue.enq.bits }
}
if (pipe) {
when(io.deq.ready) { io.enq.ready := true.B }
when(io.queue.deq.ready) { io.queue.enq.ready := true.B }
}
io.mask := valid.asUInt
io.elts := elts
io.count := PopCount(io.mask)
io.queue.count := PopCount(io.mask)
}
class MemTraceDriver(numLanes: Int = 4, traceFile : String = "vecadd.core1.thread4.trace")(implicit p: Parameters) extends LazyModule {