Skip to content

Commit f1fa089

Browse files
committed
difftest: pipeline FPGA batch bus + beat-serialize AXIS to ease congestion
- Cut the wide Gateway->Host path with a register slice to reduce long routes. - Replace 16008-bit per-beat shift with beat-indexed serialization to shrink active cones. - Intended to ease routing congestion and improve PCIe-clock timing.
1 parent e96b92b commit f1fa089

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

src/main/scala/fpga/Host.scala

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class Difftest2AXIs(val difftest_width: Int, val axis_width: Int) extends Module
3232
val numPacketPerRange = 8 // packet in each range
3333
val pkt_id_w = 8 // pkt = (difftest_data, pkt_id)
3434
val axis_send_len = (difftest_width + pkt_id_w + axis_width - 1) / axis_width
35+
val payload_width = axis_send_len * axis_width
36+
val payload_pad_width = payload_width - difftest_width - pkt_id_w
3537
val fifo_depth = 16
3638
val fifo_addr_width = log2Ceil(fifo_depth)
3739

@@ -48,20 +50,13 @@ class Difftest2AXIs(val difftest_width: Int, val axis_width: Int) extends Module
4850
val wr_occupancy = wr_cnt - rd_cnt_sync // Calculate occupancy in write clock domain
4951

5052
// Write side (difftest side)
51-
val pktID = RegInit(0.U(pkt_id_w.W))
52-
val wrRangeCounter = RegInit(0.U(3.W)) // 0 to 7
5353
val fifo_not_full = wr_occupancy < (fifo_depth - 1).U
5454
io.difftest.ready := fifo_not_full // Backpressure based on FIFO space - only consider FIFO occupancy
5555
val wr_en = io.difftest.fire
5656

5757
when(wr_en) {
5858
fifo_ram.write(wr_ptr, io.difftest.bits)
5959
wr_ptr := wr_ptr + 1.U
60-
wrRangeCounter := Mux(wrRangeCounter === (numPacketPerRange - 1).U, 0.U, wrRangeCounter + 1.U)
61-
// Increment packet ID when starting a new range
62-
when(wrRangeCounter === (numPacketPerRange - 1).U) {
63-
pktID := pktID + 1.U
64-
}
6560
wr_cnt := wr_cnt + 1.U // Increment write counter
6661
}
6762

@@ -72,27 +67,35 @@ class Difftest2AXIs(val difftest_width: Int, val axis_width: Int) extends Module
7267
val rd_occupancy = wr_cnt_sync - rd_cnt // Calculate occupancy in read clock domain
7368

7469
val inTransfer = RegInit(false.B)
75-
val mix_data = RegInit(0.U((difftest_width + pkt_id_w).W))
70+
val packetBeats = RegInit(VecInit(Seq.fill(axis_send_len)(0.U(axis_width.W))))
7671
val sendCnt = RegInit(0.U(log2Ceil(axis_send_len).W))
7772
val sendLast = sendCnt === (axis_send_len - 1).U
7873
val counter = RegInit(0.U(3.W)) // 0 to 7
7974
val currentPktID = RegInit(0.U(pkt_id_w.W))
8075
val sendPacketEnd = counter === (numPacketPerRange - 1).U
8176
// Read from FIFO
8277
val fifo_out = fifo_ram.read(rd_ptr)
78+
val packetPayload =
79+
if (payload_pad_width > 0) {
80+
Cat(0.U(payload_pad_width.W), fifo_out, currentPktID)
81+
} else {
82+
Cat(fifo_out, currentPktID)
83+
}
84+
val packetPayloadBeats = packetPayload.asTypeOf(Vec(axis_send_len, UInt(axis_width.W)))
85+
val startTransfer = !inTransfer && rd_occupancy >= numPacketPerRange.U
86+
val loadNextPacket = startTransfer || (io.axis.fire && sendLast && !sendPacketEnd)
8387

84-
// Counter for throttling debug prints
8588
// Start transfer when we have data available
86-
when(!inTransfer) {
87-
when(rd_occupancy >= numPacketPerRange.U) {
88-
mix_data := Cat(fifo_out, currentPktID) // First data in range
89-
rd_ptr := rd_ptr + 1.U
90-
rd_cnt := rd_cnt + 1.U // Increment read counter
91-
// counter := 0.U // 0~7
92-
inTransfer := true.B
93-
sendCnt := 0.U
94-
}
95-
}.otherwise {
89+
when(loadNextPacket) {
90+
packetBeats := packetPayloadBeats
91+
rd_ptr := rd_ptr + 1.U
92+
rd_cnt := rd_cnt + 1.U // Increment read counter
93+
}
94+
95+
when(startTransfer) {
96+
inTransfer := true.B
97+
sendCnt := 0.U
98+
}.elsewhen(inTransfer) {
9699
when(io.axis.fire) {
97100
when(sendLast) {
98101
sendCnt := 0.U
@@ -102,23 +105,17 @@ class Difftest2AXIs(val difftest_width: Int, val axis_width: Int) extends Module
102105
counter := 0.U
103106
currentPktID := currentPktID + 1.U // Increment ID for next range
104107
}.otherwise {
105-
// Read next data in range
106-
mix_data := Cat(fifo_out, currentPktID)
107-
rd_ptr := rd_ptr + 1.U
108-
rd_cnt := rd_cnt + 1.U // Increment read counter
109108
counter := counter + 1.U
110109
}
111110
}.otherwise {
112-
// Still sending beats of current data
113111
sendCnt := sendCnt + 1.U
114-
mix_data := mix_data >> axis_width
115112
}
116113
}
117114
}
118115

119116
// AXI output
120117
io.axis.valid := inTransfer
121-
io.axis.bits.data := mix_data(axis_width - 1, 0)
118+
io.axis.bits.data := packetBeats(sendCnt)
122119
io.axis.bits.last := inTransfer && sendLast && sendPacketEnd
123120
}
124121
}

0 commit comments

Comments
 (0)