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

Introduce OM to T1 project #495

Merged
merged 2 commits into from
May 7, 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
38 changes: 37 additions & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import $file.dependencies.rvdecoderdb.common
import $file.common

object v {
val scala = "2.13.12"
val scala = "2.13.14"
val mainargs = ivy"com.lihaoyi::mainargs:0.5.0"
val json4sJackson = ivy"org.json4s::json4s-jackson:4.0.5"
val oslib = ivy"com.lihaoyi::os-lib:0.9.1"
Expand Down Expand Up @@ -280,6 +280,42 @@ trait Elaborator
def chiselIvy = None
}

object omreaderlib extends OMReaderLib

trait OMReaderLib
extends millbuild.common.OMReaderLibModule {
def scalaVersion = T(v.scala)

def panamaconverterModule = panamaconverter

def circtInstallPath = T.input(PathRef(os.Path(T.ctx().env("CIRCT_INSTALL_PATH"))))

def mainargsIvy = v.mainargs

def chiselModule = Some(chisel)
def chiselPluginJar = T(Some(chisel.pluginModule.jar()))
def chiselPluginIvy = None
def chiselIvy = None
}

object omreader extends OMReader

trait OMReader
extends millbuild.common.OMReaderModule {
def scalaVersion = T(v.scala)

def panamaconverterModule = panamaconverter
def omreaderlibModule = omreaderlib

def circtInstallPath = T.input(PathRef(os.Path(T.ctx().env("CIRCT_INSTALL_PATH"))))

def mainargsIvy = v.mainargs

def chiselModule = Some(chisel)
def chiselPluginJar = T(Some(chisel.pluginModule.jar()))
def chiselPluginIvy = None
def chiselIvy = None
}

/** A simple release flow for T1 generator:
* package required dependency to flat jar.
Expand Down
29 changes: 29 additions & 0 deletions common.sc
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,32 @@ trait ElaboratorModule
super.forkArgs() ++ Seq("--enable-native-access=ALL-UNNAMED", "--enable-preview", s"-Djava.library.path=${ circtInstallPath().path / "lib"}")
)
}

trait OMReaderLibModule
extends ScalaModule
with HasChisel {
def panamaconverterModule: ScalaModule
def circtInstallPath: T[PathRef]
override def moduleDeps = super.moduleDeps ++ Seq(panamaconverterModule)
def mainargsIvy: Dep
override def ivyDeps = T(super.ivyDeps() ++ Seq(mainargsIvy))
override def javacOptions = T(super.javacOptions() ++ Seq("--enable-preview", "--release", "21"))
override def forkArgs: T[Seq[String]] = T(
super.forkArgs() ++ Seq("--enable-native-access=ALL-UNNAMED", "--enable-preview", s"-Djava.library.path=${ circtInstallPath().path / "lib"}")
)
}

trait OMReaderModule
extends ScalaModule
with HasChisel {
def panamaconverterModule: ScalaModule
def omreaderlibModule: ScalaModule
def circtInstallPath: T[PathRef]
override def moduleDeps = super.moduleDeps ++ Seq(panamaconverterModule, omreaderlibModule)
def mainargsIvy: Dep
override def ivyDeps = T(super.ivyDeps() ++ Seq(mainargsIvy))
override def javacOptions = T(super.javacOptions() ++ Seq("--enable-preview", "--release", "21"))
override def forkArgs: T[Seq[String]] = T(
super.forkArgs() ++ Seq("--enable-native-access=ALL-UNNAMED", "--enable-preview", s"-Djava.library.path=${ circtInstallPath().path / "lib"}")
)
}
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions nix/t1/_sources/generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
"chisel": {
"cargoLocks": null,
"date": "2024-04-30",
"date": "2024-05-06",
"extract": null,
"name": "chisel",
"passthru": null,
Expand All @@ -73,11 +73,11 @@
"name": null,
"owner": "chipsalliance",
"repo": "chisel",
"rev": "0cf31392af010dad9ff62ac09f62ba92c1630dbd",
"sha256": "sha256-TFlTwycZDgI2POxVL8o2ID4TSMFLNbRga9cfelBIIIA=",
"rev": "69ec7c2b54a911e3798ad692590fa280d32f42e3",
"sha256": "sha256-EjoDhcqrBDlnQgAZ0iaTI+m3zE8tsvP1KsKU2N+6A7c=",
"type": "github"
},
"version": "0cf31392af010dad9ff62ac09f62ba92c1630dbd"
"version": "69ec7c2b54a911e3798ad692590fa280d32f42e3"
},
"diplomacy": {
"cargoLocks": null,
Expand Down
8 changes: 4 additions & 4 deletions nix/t1/_sources/generated.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
};
chisel = {
pname = "chisel";
version = "0cf31392af010dad9ff62ac09f62ba92c1630dbd";
version = "69ec7c2b54a911e3798ad692590fa280d32f42e3";
src = fetchFromGitHub {
owner = "chipsalliance";
repo = "chisel";
rev = "0cf31392af010dad9ff62ac09f62ba92c1630dbd";
rev = "69ec7c2b54a911e3798ad692590fa280d32f42e3";
fetchSubmodules = false;
sha256 = "sha256-TFlTwycZDgI2POxVL8o2ID4TSMFLNbRga9cfelBIIIA=";
sha256 = "sha256-EjoDhcqrBDlnQgAZ0iaTI+m3zE8tsvP1KsKU2N+6A7c=";
};
date = "2024-04-30";
date = "2024-05-06";
};
diplomacy = {
pname = "diplomacy";
Expand Down
2 changes: 2 additions & 0 deletions nix/t1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ lib.makeScope newScope
configgen = _millOutput.configgen // { meta.mainProgram = "configgen"; };
t1package = _millOutput.t1package;

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

riscv-opcodes-src = self.submodules.sources.riscv-opcodes.src;
Expand Down Expand Up @@ -71,6 +72,7 @@ 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; };
omreaderlib = innerSelf.callPackage ./omreaderlib.nix { inherit mlirbc; };

emu-elaborate = innerSelf.callPackage ./elaborate.nix { target = "ipemu"; /* use-binder = true; */ };
emu-mlirbc = innerSelf.callPackage ./mlirbc.nix { elaborate = emu-elaborate; };
Expand Down
25 changes: 25 additions & 0 deletions nix/t1/om.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ stdenvNoCC
, lib

, omreader
, circt
, mlirbc
}:

let
omReaderArgs = lib.filter (s: s != "") [
"--mlirbc-file"
"${mlirbc}/${mlirbc.elaborateTarget}-${mlirbc.elaborateConfig}.mlirbc"
];
in
stdenvNoCC.mkDerivation {
name = "t1-${mlirbc.elaborateConfig}-${mlirbc.elaborateTarget}-om";

nativeBuildInputs = [ circt omreader ];

buildCommand = ''
omreader ${lib.escapeShellArgs omReaderArgs}
'';

meta.description = "Call CLI dumps OM properties from MLIR bytecodes";
}
90 changes: 90 additions & 0 deletions nix/t1/omreader.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{ lib
, stdenv
, fetchMillDeps
, makeWrapper
, jdk21

# chisel deps
, mill
, espresso
, circt-full
, jextract-21
, strip-nondeterminism

, submodules
}:

let
self = stdenv.mkDerivation rec {
name = "omreader";

src = with lib.fileset; toSource {
root = ./../..;
fileset = unions [
./../../build.sc
./../../common.sc
./../../omreader
./../../omreaderlib
];
};

passthru.millDeps = fetchMillDeps {
inherit name;
src = with lib.fileset; toSource {
root = ./../..;
fileset = unions [
./../../build.sc
./../../common.sc
];
};
millDepsHash = "sha256-ZgcBH7p4/F8Jn6qmsTKmwN6PLVXi37iuRCD0xYxvEO4=";
nativeBuildInputs = [ submodules.setupHook ];
};

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

shellHook = ''
setupSubmodules
'';

nativeBuildInputs = [
mill
jextract-21
strip-nondeterminism
circt-full

makeWrapper
passthru.millDeps.setupHook

submodules.setupHook
];

env = {
CIRCT_INSTALL_PATH = circt-full;
JAVA_TOOL_OPTIONS = "--enable-preview";
};

buildPhase = ''
mill -i 'omreader.assembly'
'';

installPhase = ''
mkdir -p "$out"/bin "$out"/share/java
strip-nondeterminism out/omreader/assembly.dest/out.jar
mv out/omreader/assembly.dest/out.jar "$out"/share/java/omreader.jar
makeWrapper ${jdk21}/bin/java "$out"/bin/omreader --add-flags "--enable-preview --enable-native-access=ALL-UNNAMED -Djava.library.path=${circt-full}/lib -jar $out/share/java/omreader.jar"
echo "$(cat "$out"/bin/omreader) 2> /dev/null" > "$out"/bin/omreader
'';

meta = {
description = "CLI reads OM properties from MLIR bytecodes";
mainProgram = "omreader";
};
};
in
self
2 changes: 1 addition & 1 deletion nix/t1/t1.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let
./../../common.sc
];
};
millDepsHash = "sha256-rkS/bTDnjnyzdQyTIhfLj3e0mMdDn4fzv/660rO3qYg=";
millDepsHash = "sha256-ZgcBH7p4/F8Jn6qmsTKmwN6PLVXi37iuRCD0xYxvEO4=";
nativeBuildInputs = [ submodules.setupHook ];
};

Expand Down
66 changes: 66 additions & 0 deletions omreader/src/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 Jiuyang Liu <[email protected]>

package org.chipsalliance.t1.omreader

import java.io.BufferedInputStream
import mainargs._
import chisel3.panamaom._
import org.chipsalliance.t1.omreaderlib._

object Main {
implicit object PathRead extends TokensReader.Simple[os.Path] {
def shortName = "path"
def read(strs: Seq[String]): Either[String, os.Path] = Right(os.Path(strs.head, os.pwd))
}

@main
def run(
@arg(name = "mlirbc-file") mlirbcFile: Option[os.Path],
@arg(name = "dump-methods") dumpMethods: Flag,
@arg(name = "eval") eval: Option[String],
) = {
val t1Reader = (mlirbcFile match {
case Some(path) => OMReader.fromFile(path)
case None =>
val stdin = new BufferedInputStream(System.in)
val bytes = Stream.continually(stdin.read).takeWhile(_ != -1).map(_.toByte).toArray
OMReader.fromBytes(bytes)
}).t1Reader

if (eval.nonEmpty) {
println(SimpleInputEval(t1Reader.entry, eval.get))
} else if (dumpMethods.value) {
t1Reader.dumpMethods()
} else {
t1Reader.dumpAll()
}
}

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

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

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

def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args)
}

object SimpleInputEval {
def apply(entry: PanamaCIRCTOMEvaluatorValue, input: String): PanamaCIRCTOMEvaluatorValue = {
input.split("\\.").foldLeft(entry) {
case (obj, field) =>
if (field.forall(_.isDigit)) {
obj.asInstanceOf[PanamaCIRCTOMEvaluatorValueList].getElement(field.toLong)
} else {
obj.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject].field(field)
}
}
}
}
sequencer marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading