Skip to content

Commit

Permalink
Optimize ReaderWriter (#345)
Browse files Browse the repository at this point in the history
* Optimize ReaderWriter

* Temporarily remove scalatest

* Revert changes in AddressGenUnit

* scalafmt
  • Loading branch information
IveanEx committed Sep 25, 2024
1 parent f936698 commit 3c94494
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,21 @@ class AddressGenUnit(
new ComplexQueueConcat(
inputWidth = io.addr.head.bits.getWidth * param.numChannel,
outputWidth = io.addr.head.bits.getWidth,
depth = param.outputBufferDepth
depth = param.outputBufferDepth,
pipe = param.pipeFifo
) {
override val desiredName = s"${moduleNamePrefix}_AddressBufferFIFO"
}
)

// Calculate the current base address: the first stride need to be left-shifted
val temporalOffset = VecInit(counters.map(_.io.value)).reduceTree(_ + _)

// This is a table for all possible values that the spatial offset can take
val spatialOffsetTable = for (i <- 0 until param.spatialBounds.length) yield {
(0 until param.spatialBounds(i)).map(io.cfg.spatialStrides(i) * _.U)
}

val spatialOffsets = for (i <- 0 until param.numChannel) yield {
var remainder = i
var spatialOffset = temporalOffset
Expand Down
18 changes: 12 additions & 6 deletions hw/chisel/src/main/scala/snax/readerWriter/DesignParams.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class AddressGenUnitParam(
val addressWidth: Int,
val numChannel: Int,
val outputBufferDepth: Int,
val tcdmSize: Int
val tcdmSize: Int,
val pipeFifo: Boolean
)

object AddressGenUnitParam {
Expand All @@ -41,14 +42,16 @@ object AddressGenUnitParam {
temporalDimension: Int,
numChannel: Int,
outputBufferDepth: Int,
tcdmSize: Int
tcdmSize: Int,
pipeFifo: Boolean
): AddressGenUnitParam = new AddressGenUnitParam(
spatialBounds = spatialBounds,
temporalDimension = temporalDimension,
addressWidth = log2Ceil(tcdmSize) + 10,
numChannel = numChannel,
outputBufferDepth = outputBufferDepth,
tcdmSize = tcdmSize
tcdmSize = tcdmSize,
pipeFifo = pipeFifo
)

// The Very Simple instantiation of the Param
Expand All @@ -57,7 +60,8 @@ object AddressGenUnitParam {
temporalDimension = 2,
numChannel = 8,
outputBufferDepth = 8,
tcdmSize = 128
tcdmSize = 128,
pipeFifo = true
)
}

Expand All @@ -70,14 +74,16 @@ class ReaderWriterParam(
addressBufferDepth: Int = 8,
dataBufferDepth: Int = 8,
val configurableChannel: Boolean = false,
val configurableByteMask: Boolean = false
val configurableByteMask: Boolean = false,
val pipeFifo: Boolean = true
) {
val aguParam = AddressGenUnitParam(
spatialBounds = spatialBounds,
temporalDimension = temporalDimension,
numChannel = numChannel,
outputBufferDepth = addressBufferDepth,
tcdmSize = tcdmSize
tcdmSize = tcdmSize,
pipeFifo = pipeFifo
)

val tcdmParam = TCDMParam(
Expand Down
3 changes: 2 additions & 1 deletion hw/chisel/src/main/scala/snax/readerWriter/Reader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class Reader(
new ComplexQueueConcat(
inputWidth = param.tcdmParam.dataWidth,
outputWidth = param.tcdmParam.dataWidth * param.tcdmParam.numChannel,
depth = param.bufferDepth
depth = param.bufferDepth,
pipe = param.pipeFifo
) {
override val desiredName = s"${moduleNamePrefix}_Reader_DataBuffer"
}
Expand Down
3 changes: 2 additions & 1 deletion hw/chisel/src/main/scala/snax/readerWriter/Writer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class Writer(
new ComplexQueueConcat(
inputWidth = param.tcdmParam.dataWidth * param.tcdmParam.numChannel,
outputWidth = param.tcdmParam.dataWidth,
depth = param.bufferDepth
depth = param.bufferDepth,
pipe = param.pipeFifo
) {
override val desiredName = s"${moduleNamePrefix}_Writer_DataBuffer"
}
Expand Down
10 changes: 7 additions & 3 deletions hw/chisel/src/main/scala/snax/utils/ComplexQueue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ import chisel3.util._
* will be the second option No matter which case, the big width one should
* equal to integer times of the small width one
*/
class ComplexQueueConcat(inputWidth: Int, outputWidth: Int, depth: Int)
extends Module
class ComplexQueueConcat(
inputWidth: Int,
outputWidth: Int,
depth: Int,
pipe: Boolean = false
) extends Module
with RequireAsyncReset {
val bigWidth = Seq(inputWidth, outputWidth).max
val smallWidth = Seq(inputWidth, outputWidth).min
Expand Down Expand Up @@ -50,7 +54,7 @@ class ComplexQueueConcat(inputWidth: Int, outputWidth: Int, depth: Int)
})

val queues = for (i <- 0 until numChannel) yield {
val queue = Module(new Queue(UInt(smallWidth.W), depth))
val queue = Module(new Queue(UInt(smallWidth.W), depth, pipe))
io.nearlyEmpty(i) := queue.io.count < 2.U
io.nearlyFull(i) := queue.io.count > (depth - 2).U
queue
Expand Down
6 changes: 4 additions & 2 deletions hw/chisel/src/main/scala/snax/xdma/xdmaTop/xdmaTop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ object xdmaTopGen extends App {
parsedArgs("axiDataWidth").toInt / parsedArgs("tcdmDataWidth").toInt,
addressBufferDepth = parsedArgs("readerBufferDepth").toInt,
configurableChannel = true,
configurableByteMask = false
configurableByteMask = false,
pipeFifo = true
)

val writerparam = new ReaderWriterParam(
Expand All @@ -187,7 +188,8 @@ object xdmaTopGen extends App {
parsedArgs("axiDataWidth").toInt / parsedArgs("tcdmDataWidth").toInt,
addressBufferDepth = parsedArgs("writerBufferDepth").toInt,
configurableChannel = true,
configurableByteMask = true
configurableByteMask = true,
pipeFifo = true
)
var readerextensionparam = Seq[HasDataPathExtension]()
var writerextensionparam = Seq[HasDataPathExtension]()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class AddressGenUnitTester extends AnyFlatSpec with ChiselScalatestTester {
temporalDimension = 2,
numChannel = 8,
outputBufferDepth = 2,
tcdmSize = 128
tcdmSize = 128,
pipeFifo = false
)
)
)
Expand Down Expand Up @@ -68,7 +69,8 @@ class AddressGenUnitTester extends AnyFlatSpec with ChiselScalatestTester {
temporalDimension = 2,
numChannel = 8,
outputBufferDepth = 2,
tcdmSize = 128
tcdmSize = 128,
pipeFifo = false
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class ReaderTester extends AnyFreeSpec with ChiselScalatestTester {
new Reader(
new ReaderWriterParam(
configurableByteMask = false,
configurableChannel = true
configurableChannel = true,
pipeFifo = false
)
)
).withAnnotations(Seq(WriteVcdAnnotation, VerilatorBackendAnnotation)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class WriterTester extends AnyFreeSpec with ChiselScalatestTester {
new Writer(
new ReaderWriterParam(
configurableByteMask = true,
configurableChannel = true
configurableChannel = true,
pipeFifo = false
)
)
).withAnnotations(Seq(WriteVcdAnnotation, VerilatorBackendAnnotation)) {
Expand Down

0 comments on commit 3c94494

Please sign in to comment.