Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
sequencer committed Oct 12, 2024
1 parent 8ead88f commit e6bc7a6
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 37 deletions.
8 changes: 6 additions & 2 deletions omreader/src/t1om.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object t1om {

@main
def instructions(@arg(name = "mlirbc-file") mlirbcFile: os.Path) =
upickle.default.write(new T1(os.read.bytes(mlirbcFile)).instructions).foreach(println)
new T1(os.read.bytes(mlirbcFile)).instructions.foreach(println)

@main
def extensions(
Expand All @@ -35,7 +35,11 @@ object t1om {

@main
def sram(@arg(name = "mlirbc-file") mlirbcFile: os.Path) =
println(upickle.default.write(new T1(os.read.bytes(mlirbcFile)).sram))
new T1(os.read.bytes(mlirbcFile)).sram.foreach(s => println(upickle.default.write(s)))

@main
def retime(@arg(name = "mlirbc-file") mlirbcFile: os.Path) =
new T1(os.read.bytes(mlirbcFile)).retime.foreach(r => println(upickle.default.write(r)))

def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args)
}
41 changes: 39 additions & 2 deletions omreaderlib/src/T1OMReaderAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ case class SRAM(
maskGranularity: Int)

object Retime {
implicit val rw: ReadWriter[SRAM] = macroRW
implicit val rw: ReadWriter[Retime] = macroRW
}

/** Module to be retimed. */
Expand All @@ -43,7 +43,44 @@ case class Instruction(
instructionName: String,
documentation: String,
bitPat: String,
attributes: Seq[InstructionAttributes])
attributes: Seq[InstructionAttributes]) {
override def toString: String =
s"${instructionName} -> ${attributes.map(a => s"${a.identifier}:${a.value}").mkString(",")}"
}

object Path {
implicit val rw: ReadWriter[Instruction] = macroRW
def parse(str: String): Path =
str match {
case s"OMReferenceTarget:~${top}|${hier}>${local}" =>
Path(
top,
hier
.split("/")
.map(i => {
val s = i.split(":")
(s.head, s.last)
}),
Some(local)
)
case s"OMReferenceTarget:~${top}|${hier}" =>
Path(
top,
hier
.split("/")
.map(i => {
val s = i.split(":")
(s.head, s.last)
}),
None
)
}
}

case class Path(top: String, hierarchy: Seq[(String, String)], local: Option[String]) {
def module: String = hierarchy.last._2
def path: String = hierarchy.map(_._1).mkString(".")
}

/** Public Module under T1 should implement Modules below. */
trait T1OMReaderAPI extends OMReader {
Expand Down
34 changes: 23 additions & 11 deletions omreaderlib/src/t1/T1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package org.chipsalliance.t1.omreaderlib.t1

import chisel3.panamaom._
import org.chipsalliance.t1.omreaderlib.{Instruction, InstructionAttributes, Retime, SRAM, T1OMReaderAPI}
import org.chipsalliance.t1.omreaderlib.{Instruction, InstructionAttributes, Path, Retime, SRAM, T1OMReaderAPI}

/** OM API for [[org.chipsalliance.t1.rtl.T1OM]] */
class T1(val mlirbc: Array[Byte]) extends T1OMReaderAPI {
Expand All @@ -30,23 +30,20 @@ class T1(val mlirbc: Array[Byte]) extends T1OMReaderAPI {
.map(_.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject])
.map { attr =>
InstructionAttributes(
attr.field("description").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString,
attr.field("identifier").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString,
attr.field("description").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString,
attr.field("value").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString
)
}
)

})
}
def extensions: Seq[String] = {
val extensions = t1.field("extensions").asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
extensions.elements().map(_.asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString)
}

def march: String = t1.field("march").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString

def sram: Seq[SRAM] = t1
def march: String = t1.field("march").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString
def sram: Seq[SRAM] = t1
.field("lanes")
.asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
.elements()
Expand All @@ -58,7 +55,8 @@ class T1(val mlirbc: Array[Byte]) extends T1OMReaderAPI {
.asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
srams.elements().map(_.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]).map { sram =>
SRAM(
moduleName = sram.field("hierarchy").asInstanceOf[PanamaCIRCTOMEvaluatorValuePath].toString,
moduleName =
Path.parse(sram.field("hierarchy").asInstanceOf[PanamaCIRCTOMEvaluatorValuePath].toString).module,
depth = sram.field("depth").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer.toInt,
width = sram.field("width").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer.toInt,
read = sram.field("read").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer.toInt,
Expand All @@ -72,7 +70,21 @@ class T1(val mlirbc: Array[Byte]) extends T1OMReaderAPI {
)
}
}

/** All Modules that need to be retimed */
def retime: Seq[Retime] = ???
.distinct
def retime: Seq[Retime] = {
t1
.field("lanes")
.asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
.elements()
.map(_.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject].field("vfus"))
.flatMap(
_.asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
.elements()
.map(_.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject])
.filter(_.field("cycles").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer != 0)
)
.map(_.field("clock").asInstanceOf[PanamaCIRCTOMEvaluatorValuePath])
.map(p => Retime(Path.parse(p.toString).module))
.distinct
}
}
31 changes: 10 additions & 21 deletions omreaderlib/src/t1emu/Testbench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ import org.chipsalliance.t1.omreaderlib.{Instruction, InstructionAttributes, Ret

/** OM API for [[org.chipsalliance.t1.rtl.T1OM]] */
class Testbench(val mlirbc: Array[Byte]) extends T1OMReaderAPI {
val top: String = "Testbench_Class"
private val t1: PanamaCIRCTOMEvaluatorValueObject = entry
val top: String = "Testbench_Class"
private val t1: PanamaCIRCTOMEvaluatorValueObject = entry
.field("om")
.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]
.field("t1")
.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]
def vlen: Int = t1.field("vlen").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer.toInt
def dlen: Int = t1.field("dlen").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer.toInt
def extensions: Seq[String] = {
def vlen: Int = t1.field("vlen").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer.toInt
def dlen: Int = t1.field("dlen").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer.toInt
def extensions: Seq[String] = {
val extensions = t1.field("extensions").asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
extensions.elements().map(_.asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString)
}
def march: String = t1.field("march").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString

// TODO: This is not correct, we should include scalar instructions.
def instructions: Seq[Instruction] = {
def march: String = t1.field("march").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString
def instructions: Seq[Instruction] = {
val decoder = t1.field("decoder").asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]
val instructions = decoder.field("instructions").asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
instructions
Expand All @@ -31,10 +29,6 @@ class Testbench(val mlirbc: Array[Byte]) extends T1OMReaderAPI {
val instr = instruction.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]
val attributes = instr.field("attributes").asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
instr.field("attributes").asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
// instructionName
// documentation
// bitPat
// attributes
Instruction(
instr.field("instructionName").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString,
instr.field("documentation").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString,
Expand All @@ -44,19 +38,14 @@ class Testbench(val mlirbc: Array[Byte]) extends T1OMReaderAPI {
.map(_.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject])
.map { attr =>
InstructionAttributes(
attr.field("description").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString,
attr.field("identifier").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString,
attr.field("description").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString,
attr.field("value").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString
)
}
)

})
}

// This is not used by tests
override def sram: Seq[SRAM] = Nil

// This is not used by tests
override def retime: Seq[Retime] = Nil
override def sram: Seq[SRAM] = Nil
override def retime: Seq[Retime] = Nil
}
101 changes: 101 additions & 0 deletions omreaderlib/src/t1rocketv/T1RocketTile.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 Jiuyang Liu <[email protected]>

package org.chipsalliance.t1.omreaderlib.t1rocketv

import chisel3.panamaom._
import org.chipsalliance.t1.omreaderlib.{Instruction, InstructionAttributes, Path, Retime, SRAM, T1OMReaderAPI}

/** OM API for [[org.chipsalliance.t1.rtl.T1OM]] */
class T1RocketTile(val mlirbc: Array[Byte]) extends T1OMReaderAPI {
val top: String = "T1RocketTile_Class"
private val t1: PanamaCIRCTOMEvaluatorValueObject = entry
.field("om")
.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]
.field("t1")
.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]
private val rocket: PanamaCIRCTOMEvaluatorValueObject = entry
.field("om")
.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]
.field("rocket")
.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]
def vlen: Int = t1.field("vlen").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer.toInt
def dlen: Int = t1.field("dlen").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer.toInt
def instructions: Seq[Instruction] = {
val decoder = t1.field("decoder").asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]
val instructions = decoder.field("instructions").asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
instructions
.elements()
.map(instruction => {
val instr = instruction.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]
val attributes = instr.field("attributes").asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
instr.field("attributes").asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
Instruction(
instr.field("instructionName").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString,
instr.field("documentation").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString,
instr.field("bitPat").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString,
attributes
.elements()
.map(_.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject])
.map { attr =>
InstructionAttributes(
attr.field("identifier").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString,
attr.field("description").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString,
attr.field("value").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString
)
}
)
})
}
def extensions: Seq[String] = {
val extensions = t1.field("extensions").asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
extensions.elements().map(_.asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString)
}
def march: String = t1.field("march").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString
def vrf: Seq[SRAM] = t1
.field("lanes")
.asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
.elements()
.map(_.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject].field("vrf"))
.flatMap { vrf =>
val srams = vrf
.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]
.field("srams")
.asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
srams.elements().map(_.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]).map { sram =>
SRAM(
moduleName =
Path.parse(sram.field("hierarchy").asInstanceOf[PanamaCIRCTOMEvaluatorValuePath].toString).module,
depth = sram.field("depth").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer.toInt,
width = sram.field("width").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer.toInt,
read = sram.field("read").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer.toInt,
write = sram.field("write").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer.toInt,
readwrite = sram.field("readwrite").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer.toInt,
maskGranularity = sram
.field("maskGranularity")
.asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger]
.integer
.toInt
)
}
}
.distinct
def sram = vrf
def vfu: Seq[Retime] = {
t1
.field("lanes")
.asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
.elements()
.map(_.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject].field("vfus"))
.flatMap(
_.asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
.elements()
.map(_.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject])
.filter(_.field("cycles").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer != 0)
)
.map(_.field("clock").asInstanceOf[PanamaCIRCTOMEvaluatorValuePath])
.map(p => Retime(Path.parse(p.toString).module))
.distinct
}
def retime = vfu
}
9 changes: 8 additions & 1 deletion t1/src/VectorFunctionUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class VFUOM extends Class {
@public
val cyclesIn = IO(Input(Property[Int]()))
cycles := cyclesIn
@public
val clock = IO(Output(Property[Path]))
@public
val clockIn = IO(Input(Property[Path]))
clock := clockIn
}

@instantiable
Expand All @@ -48,7 +53,9 @@ abstract class VFUModule(p: VFUParameter) extends Module {
@public
val responseIO: DecoupledIO[VFUPipeBundle] = IO(Decoupled(p.outputBundle))
om := omInstance.getPropertyReference
omInstance.cyclesIn := Property(p.latency)
// I don't under the parameter of VFU, dirty hack
omInstance.cyclesIn := Property(if (p.singleCycle) 1 else 0)
omInstance.clockIn := Property(Path(clock))

val vfuRequestReady: Option[Bool] = Option.when(!p.singleCycle)(Wire(Bool()))
val requestReg: VFUPipeBundle = RegEnable(requestIO.bits, 0.U.asTypeOf(requestIO.bits), requestIO.fire)
Expand Down

0 comments on commit e6bc7a6

Please sign in to comment.