Unit Testing of RoCC Accelerator Components

41 views
Skip to first unread message

Karl Hallsby

unread,
Jan 6, 2023, 5:23:14 PM1/6/23
to Chipyard
When developing components (Modules) that are a part of a RoCC accelerator, I want to add unit tests to verify the behavior/functionality of the module.

However, a module that requires implicit Parameters that are provided by a Config is giving me trouble. A backtrace is provided below.

should Test description *** FAILED ***
[info]   java.lang.IllegalArgumentException: requirement failed: Key TileKey is not defined in Parameters
[info]   at ... ()
[info]   at chipsalliance.rocketchip.config$View.apply(Config.scala:28)
[info]   at chipsalliance.rocketchip.config$View.apply(Config.scala:25)
[info]   at freechips.rocketchip.tile.HasNonDiplomaticTileParameters.tileParams(BaseTile.scala:45)
[info]   at freechips.rocketchip.tile.HasNonDiplomaticTileParameters.tileParams$(BaseTile.scala:45)
[info]   at freechips.rocketchip.tile.CoreBundle.tileParams(Core.scala:133)
[info]   at freechips.rocketchip.tile.HasCoreParameters.$init$(Core.scala:70)
[info]   at freechips.rocketchip.tile.CoreBundle.<init>(Core.scala:133)
[info]   at freechips.rocketchip.tile.RoCCCommand.<init>(LazyRoCC.scala:29)
[info]   at vcoderocc.ControlUnit$$anon$1$$anon$2.$anonfun$cmd$2(Ctrl.scala:12)


I can even add a new class that extends Config and it is not recognized.
class TileKeyTestConfig extends Config((site, here, up) => {
  case freechips.rocketchip.tile.TileKey => null
})

class VCodeTestConfig extends Config(
  new vcoderocc.WithVCodeAccel ++
  new TileKeyTestConfig ++
  new freechips.rocketchip.subsystem.With1TinyCore() ++
  new freechips.rocketchip.system.DefaultConfig)


What am I missing to get Parameters working to actually test the component?

Karl Hallsby

unread,
Jan 16, 2023, 11:52:08 AM1/16/23
to Chipyard
I managed to solve this after several hours of digging through the Rocket core's source code. What I did was initialize the TileKey as a RocketTile using RocketTileParams and RocketCoreParams.
/** Adds a TileKey configuration, making the simplified testing design a part of
  * the TileLink network, allowing for the processor and accelerator to communicate
  * with the TileLink network.
  *
  * This is needed for the unit tests which require an implicit Parameters object
  * be passed to modules. */

class TileKeyTestConfig extends Config((site, here, up) => {
  case freechips.rocketchip.tile.TileKey => RocketTileParams(
    core = freechips.rocketchip.rocket.RocketCoreParams(), // Use the default Rocket Core configuration
    name = Some("TileParams Config for Unit Testing"),
  )
})

/** A simplified test accelerator Config-uration that allows for quick unit
  * tests. It reuses a default Rocket configuration, while adding TileLink
  * support required for RoCC tests. */
class AccelUnitTestConfig extends Config(
  new WithAccelConfig ++
  new TileKeyTestConfig ++
  new freechips.rocketchip.system.DefaultConfig)

class DecoderTest extends AnyFlatSpec with ChiselScalatestTester {
  implicit val p: Parameters = new AccelUnitTestConfig

  behavior of "Decoder"
  it should s"Decode ${PLUS_INT}" in {
    test(new Decoder) { dut => /* Do something */ }
  }
}
Reply all
Reply to author
Forward
0 new messages