diff --git a/build.sbt b/build.sbt index 38f7367..f9e4986 100644 --- a/build.sbt +++ b/build.sbt @@ -23,6 +23,8 @@ libraryDependencies ++= (if (standalone) { Nil }) +libraryDependencies += "com.typesafe.play" %% "play-json" % "2.9.3" + addCompilerPlugin("edu.berkeley.cs" % "chisel3-plugin" % (if (standalone) "3.5.2" else "3.5.1") cross CrossVersion.full) @@ -35,4 +37,3 @@ Test / testGrouping := (Test / testGrouping).value.flatMap { group => } } concurrentRestrictions := Seq(Tags.limit(Tags.ForkedTestGroup, 72)) - diff --git a/docs/source/index.rst b/docs/source/index.rst index 1c2ee47..b1ddde0 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -20,7 +20,7 @@ Constellation is a Chisel NoC RTL generator framework designed from the ground u .. image:: diagrams/bigsoc.svg :width: 600px - + .. toctree:: :maxdepth: 4 :caption: Contents: diff --git a/src/main/scala/noc/JsonConverter.scala b/src/main/scala/noc/JsonConverter.scala new file mode 100644 index 0000000..0b7b4fb --- /dev/null +++ b/src/main/scala/noc/JsonConverter.scala @@ -0,0 +1,115 @@ +package constellation.noc + +import chisel3._ +import chisel3.util._ + +import freechips.rocketchip.config.{Field, Parameters} +import freechips.rocketchip.diplomacy.{LazyModule, LazyModuleImp, BundleBridgeSink, InModuleBody} +import constellation.router._ +import constellation.channel._ +import constellation.routing._ +import constellation.topology.{PhysicalTopology, UnidirectionalLine} + +import play.api.libs.json._ + +object JSONConverters { + implicit val jsonUserVirtualChannelParams = new Writes[UserVirtualChannelParams] { + def writes(uvcp: UserVirtualChannelParams) = Json.obj( + "bufferSize" -> uvcp.bufferSize + ) + } + + implicit val jsonUserChannelParams = new Writes[UserChannelParams] { + def writes(ucp: UserChannelParams) = Json.obj( + "virtualChannelParams" -> ucp.virtualChannelParams, + // excluding channelGen + "crossingType" -> ucp.getClass.getName(), + "srcSpeedup" -> ucp.srcSpeedup, + "dstSpeedup" -> ucp.destSpeedup + ) + } + + case class UserChannelParamsWrapper( + srcId: Int, + destId: Int, + userChannelParams: UserChannelParams + ) + + implicit val jsonUserChannelParamsWrapper = new Writes[UserChannelParamsWrapper] { + def writes(ucpw: UserChannelParamsWrapper) = Json.obj( + "srcId" -> ucpw.srcId, + "destId" -> ucpw.destId, + "userChannelParams" -> ucpw.userChannelParams + ) + } + + implicit val jsonUserIngressParams = new Writes[UserIngressParams] { + def writes(uip: UserIngressParams) = Json.obj( + "destId" -> uip.destId, + "payloadBits" -> uip.payloadBits + ) + } + + implicit val jsonUserEgressParams = new Writes[UserEgressParams] { + def writes(uep: UserEgressParams) = Json.obj( + "srcId" -> uep.srcId, + "payloadBits" -> uep.payloadBits + ) + } + + implicit val jsonUserRouterParams = new Writes[UserRouterParams] { + def writes(urp: UserRouterParams) = Json.obj( + "payloadBits" -> urp.payloadBits, + "combineSAST" -> urp.combineSAST, + "combineRCVA" -> urp.combineRCVA, + "coupleSAVA" -> urp.coupleSAVA + ) + } + + implicit val jsonFlowParams = new Writes[FlowParams] { + def writes(fp: FlowParams) = Json.obj( + "ingressId" -> fp.ingressId, + "egressId" -> fp.egressId, + "vNetId" -> fp.vNetId + ) + } + + implicit val jsonNoCParams = new Writes[NoCParams] { + def writes(nocParams: NoCParams) = { + val nNodes = nocParams.topology.nNodes + val channelParams = Seq.tabulate(nNodes, nNodes) { case (i,j) => + if (nocParams.topology.topo(i, j)) { + val cP = nocParams.channelParamGen(i, j) + Some(UserChannelParamsWrapper( + srcId = i, + destId = j, + userChannelParams = cP, + )) + } else { + None + } + }.flatten.flatten + + val routerParams = (0 until nNodes).map { i => + nocParams.routerParams(i) + } + + Json.obj( + "topology" -> nocParams.topology.getClass().getName(), + "channelParams" -> channelParams, + "ingresses" -> nocParams.ingresses, + "egresses" -> nocParams.egresses, + "routerParams" -> routerParams, + // vNetBlocking is a function + "flows" -> nocParams.flows, + "routingRelation" -> nocParams.routingRelation.getClass().getName(), + "nocName" -> nocParams.nocName + ) + } + } + + def printAsJson(np: NoCParams): JsValue = { + Json.toJson(np) + } + +} \ No newline at end of file diff --git a/src/main/scala/noc/NoC.scala b/src/main/scala/noc/NoC.scala index b008cdd..644f9dd 100644 --- a/src/main/scala/noc/NoC.scala +++ b/src/main/scala/noc/NoC.scala @@ -13,6 +13,8 @@ import constellation.channel._ import constellation.routing.{RoutingRelation, ChannelRoutingInfo} import constellation.topology.{PhysicalTopology, UnidirectionalLine} +import play.api.libs.json._ + class NoCTerminalIO( val ingressParams: Seq[IngressChannelParams], @@ -209,6 +211,8 @@ class NoC(nocParams: NoCParams)(implicit p: Parameters) extends LazyModule { (outs ++ egresses ++ ingresses).mkString("\n") }.mkString("\n") ElaborationArtefacts.add(prepend("noc.edgeprops"), edgeProps) + import JSONConverters._ + ElaborationArtefacts.add(prepend("noc_cfg.json"), Json.toJson(nocParams).toString()) println(s"Constellation: $nocName Finished NoC RTL generation") }