Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoder attr #609

Merged
merged 6 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ jobs:
ref: ${{ github.event.pull_request.head.sha }}
- name: "Run testcases"
run: |
nix run ".#ci-helper" -- runTests --jobs "${{ matrix.jobs }}"
nix develop -c t1-helper runTests --jobs "${{ matrix.jobs }}"
- name: "Run OM tests"
run: |
nix develop -c t1-helper runOMTests --jobs "${{ matrix.jobs }}"

report:
name: "Report CI result"
Expand Down
1 change: 1 addition & 0 deletions configgen/generated/blastoise.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"extensions": [
"Zve32f"
],
"t1customInstructions": [],
"lsuBankParameters": [
{
"name": "scalar",
Expand Down
1 change: 1 addition & 0 deletions configgen/generated/machamp.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"extensions": [
"Zve32x"
],
"t1customInstructions": [],
"lsuBankParameters": [
{
"name": "scalar",
Expand Down
1 change: 1 addition & 0 deletions configgen/generated/sandslash.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"extensions": [
"Zve32x"
],
"t1customInstructions": [],
"lsuBankParameters": [
{
"name": "scalar",
Expand Down
5 changes: 5 additions & 0 deletions configgen/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import chisel3.util.{BitPat, log2Ceil}
import chisel3.util.experimental.BitSet
import mainargs._
import org.chipsalliance.t1.rtl._
import org.chipsalliance.t1.rtl.decoder.T1CustomInstruction
import org.chipsalliance.t1.rtl.lsu.LSUInstantiateParameter
import org.chipsalliance.t1.rtl.vrf.RamType

import java.util.LinkedHashMap

object Main {
Expand Down Expand Up @@ -67,6 +69,7 @@ object Main {
vLen,
dLen,
extensions = Seq("Zve32f"),
t1customInstructions = Nil,
lsuBankParameters =
// scalar bank 0-1G
Seq(
Expand Down Expand Up @@ -138,6 +141,7 @@ object Main {
vLen,
dLen,
extensions = Seq("Zve32x"),
t1customInstructions = Nil,
// banks=8 dLen=512 beatbyte16
lsuBankParameters =
// scalar bank 0-1G
Expand Down Expand Up @@ -215,6 +219,7 @@ object Main {
vLen,
dLen,
extensions = Seq("Zve32x"),
t1customInstructions = Nil,
lsuBankParameters =
// scalar bank 0-1G
Seq(
Expand Down
19 changes: 18 additions & 1 deletion ipemu/src/TestBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,27 @@ package org.chipsalliance.t1.ipemu

import chisel3._
import chisel3.experimental.SerializableModuleGenerator
import chisel3.probe._
import chisel3.experimental.hierarchy.{Instance, Instantiate, instantiable, public}
import chisel3.properties.{AnyClassType, Class, ClassType, Property}
import org.chipsalliance.t1.ipemu.dpi._
import org.chipsalliance.t1.rtl.{T1, T1Parameter}

@instantiable
class TestBenchOM extends Class {
@public
val t1 = IO(Output(Property[AnyClassType]()))
@public
val t1In = IO(Input(Property[AnyClassType]()))
t1 := t1In
}

class TestBench(generator: SerializableModuleGenerator[T1, T1Parameter]) extends RawModule {
val omInstance: Instance[TestBenchOM] = Instantiate(new TestBenchOM)
val omType: ClassType = omInstance.toDefinition.getClassType
@public
val om: Property[ClassType] = IO(Output(Property[omType.Type]()))
om := omInstance.getPropertyReference

// Scheduler to schedule different DPI calls for online difftest,
// TODO: after switching to offline version, everything should be cleaned up.
val clockRate = 5
Expand All @@ -32,6 +48,7 @@ class TestBench(generator: SerializableModuleGenerator[T1, T1Parameter]) extends

val dut: T1 = withClockAndReset(clock, reset)(Module(generator.module()))
dut.storeBufferClear := true.B
omInstance.t1In := Property(dut.om.asAnyClassType)

val laneProbes = dut.laneProbes.zipWithIndex.map{case (p, idx) =>
val wire = Wire(p.cloneType).suggestName(s"lane${idx}Probe")
Expand Down
6 changes: 5 additions & 1 deletion nix/t1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ lib.makeScope newScope
configgen = _millOutput.configgen // { meta.mainProgram = "configgen"; };
t1package = _millOutput.t1package;

omreader = self.callPackage ./omreader.nix { };
omreader-unwrapped = self.callPackage ./omreader.nix { };
submodules = self.callPackage ./submodules.nix { };

riscv-opcodes-src = self.submodules.sources.riscv-opcodes.src;
Expand Down Expand Up @@ -65,10 +65,14 @@ lib.makeScope newScope
elaborate = innerSelf.callPackage ./elaborate.nix { target = "ip"; /* use-binder = true; */ };
mlirbc = innerSelf.callPackage ./mlirbc.nix { inherit elaborate; };
rtl = innerSelf.callPackage ./rtl.nix { inherit mlirbc; };

omreader = self.omreader-unwrapped.mkWrapper { inherit mlirbc; };

om = innerSelf.callPackage ./om.nix { inherit mlirbc; };

emu-elaborate = innerSelf.callPackage ./elaborate.nix { target = "ipemu"; /* use-binder = true; */ };
emu-mlirbc = innerSelf.callPackage ./mlirbc.nix { elaborate = emu-elaborate; };
emu-omreader = self.omreader-unwrapped.mkWrapper { mlirbc = emu-mlirbc; };
emu-rtl = innerSelf.callPackage ./rtl.nix { mlirbc = emu-mlirbc; };

emu = innerSelf.callPackage ./ipemu.nix { rtl = ip.emu-rtl; stdenv = moldStdenv; };
Expand Down
23 changes: 17 additions & 6 deletions nix/t1/omreader.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ lib
, stdenv
, runCommand
, fetchMillDeps
, makeWrapper
, jdk21
Expand Down Expand Up @@ -41,12 +42,22 @@ let
nativeBuildInputs = [ submodules.setupHook ];
};

passthru.editable = self.overrideAttrs (_: {
shellHook = ''
setupSubmodulesEditable
mill mill.bsp.BSP/install 0
'';
});
passthru = {
editable = self.overrideAttrs (_: {
shellHook = ''
setupSubmodulesEditable
mill mill.bsp.BSP/install 0
'';
});

mkWrapper = { mlirbc }: runCommand "wrap-omreader"
{ nativeBuildInputs = [ makeWrapper ]; meta.mainProgram = "omreader"; }
''
mkdir -p "$out/bin"
mlirbc=$(find ${mlirbc}/ -type f)
makeWrapper ${self}/bin/omreader "$out/bin/omreader" --append-flags "--mlirbc-file $mlirbc"
'';
};

shellHook = ''
setupSubmodules
Expand Down
10 changes: 10 additions & 0 deletions omreader/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ object Main {
println(simplyGetT1Reader(mlirbcFile).dlen)
}

@main
def decoderInstructionsJson(@arg(name = "mlirbc-file") mlirbcFile: os.Path) = {
println(simplyGetT1Reader(mlirbcFile).decoderInstructionsJson)
}

@main
def decoderInstructionsJsonPretty(@arg(name = "mlirbc-file") mlirbcFile: os.Path) = {
println(simplyGetT1Reader(mlirbcFile).decoderInstructionsJsonPretty)
}

def simplyGetT1Reader(mlirbcFile: os.Path) = OMReader.fromFile(mlirbcFile).t1Reader

def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args)
Expand Down
33 changes: 32 additions & 1 deletion omreaderlib/src/Interface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ class T1Reader private[omreaderlib](evaluator: PanamaCIRCTOMEvaluator, basePath:

def vlen: Long = t1.field("vlen").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer
def dlen: Long = t1.field("dlen").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer
private def decoderInstructionsJsonImpl: ujson.Value = {
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]

ujson.Obj(
"attributes" -> attributes.elements.map(attribute => {
val attr = attribute.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]
val description = attr.field("description").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString
val identifier = attr.field("identifier").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString
val value = attr.field("value").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString
ujson.Obj(
"description" -> description,
"identifier" -> identifier,
"value" -> value
)
})
)
})
}
def decoderInstructionsJson: String = ujson.write(decoderInstructionsJsonImpl)
def decoderInstructionsJsonPretty: String = ujson.write(decoderInstructionsJsonImpl, 2)

def dumpMethods(): Unit = {
val mirror = runtimeMirror(getClass.getClassLoader).reflect(this)
Expand All @@ -52,7 +77,13 @@ class T1Reader private[omreaderlib](evaluator: PanamaCIRCTOMEvaluator, basePath:
)
methods.foreach(method => {
if (!method.name.toString.startsWith("dump")) {
val value = mirror.reflectMethod(method.asMethod)()
var value = mirror.reflectMethod(method.asMethod)().toString.replace("\n", "\\n")

val displayLength = 80
if (value.length > displayLength) {
value = value.take(displayLength) + s" (... ${value.length - displayLength} characters)"
}

println(s"${method.name} = $value")
}
})
Expand Down
Loading