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

[om] export ISA extensions and march #690

Merged
merged 2 commits into from
Aug 1, 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
2 changes: 1 addition & 1 deletion .github/workflows/vcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
nix build '.#t1.${{ matrix.config }}.ip.vcs-emu' --impure --no-link --cores 64
- name: "Build all testcases"
run: |
nix build ".#t1.${{ matrix.config }}.cases.all" --max-jobs auto --no-link --cores 64
nix build ".#t1.${{ matrix.config }}.ip.cases.all" --max-jobs auto --no-link --cores 64
gen-matrix:
name: "Prepare for running testcases"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/verilator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: "Build all testcases"
run: |
# Build testcases with vlen 1024 and vlen 4096
nix build ".#t1.${{ matrix.config }}.cases.all" --max-jobs auto -L --no-link --cores 64
nix build ".#t1.${{ matrix.config }}.ip.cases.all" --max-jobs auto -L --no-link --cores 64
gen-matrix:
name: "Prepare for running testcases"
Expand Down Expand Up @@ -91,4 +91,4 @@ jobs:
run: |
nix run ".#ci-helper" -- postCI --failed-tests-file-path ./failed-tests.md --cycle-update-file-path ./cycle-update.md
cat ./failed-tests.md >> $GITHUB_STEP_SUMMARY
cat ./cycle-update.md >> $GITHUB_STEP_SUMMARY
cat ./cycle-update.md >> $GITHUB_STEP_SUMMARY
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ $ nix run .#t1.<config-name>.ip.emu-omreader -- run --dump-methods

##### `dlen` : Integer

##### `extensionsJson` : Json

| Field | Type |
|---------------------------------|--------|
| `[*]` | string |

##### `march` : String

##### `decoderInstructionsJson` | `decoderInstructionsJsonPretty` : Json

| Field | Type |
Expand Down
36 changes: 25 additions & 11 deletions nix/t1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
, stdenv
, useMoldLinker
, newScope
, runCommand

, pkgsX86
}:
Expand Down Expand Up @@ -51,16 +52,6 @@ lib.makeScope newScope
elaborateConfigJson = configPath;
elaborateConfig = builtins.fromJSON (lib.readFile configPath);

cases = innerSelf.callPackage ../../tests {
inherit (ip) verilator-emu verilator-emu-trace vcs-emu vcs-emu-trace;
};

# for the convenience to use x86 cases on non-x86 machines, avoiding the extra build time
cases-x86 =
if system == "x86-64-linux"
then self.cases
else pkgsX86.t1."${configName}".cases;

ip = rec {
recurseForDerivations = true;

Expand All @@ -80,8 +71,31 @@ lib.makeScope newScope
"--lowering-options=verifLabels,omitVersionComment,emittedLineLength=240,locationInfoStyle=none"
];
};
omreader = self.omreader-unwrapped.mkWrapper { inherit mlirbc; };

om = innerSelf.callPackage ./om.nix { inherit mlirbc; };
omreader = self.omreader-unwrapped.mkWrapper { inherit mlirbc; };

emu-om = innerSelf.callPackage ./om.nix { mlirbc = emu-mlirbc; };
emu-omreader = self.omreader-unwrapped.mkWrapper { mlirbc = emu-mlirbc; };
omGet = args: lib.fileContents (runCommand "get-${args}" { } ''
${emu-omreader}/bin/omreader ${args} > $out
'');
rtlDesignMetadata = {
march = omGet "march";
extensions = builtins.fromJSON (omGet "extensionsJson");
vlen = omGet "vlen";
dlen = omGet "dlen";
};

cases = innerSelf.callPackage ../../tests {
inherit (ip) verilator-emu verilator-emu-trace vcs-emu vcs-emu-trace rtlDesignMetadata;
};

# for the convenience to use x86 cases on non-x86 machines, avoiding the extra build time
cases-x86 =
if system == "x86-64-linux"
then self.cases
else pkgsX86.t1."${configName}".cases;

emu-elaborate = innerSelf.callPackage ./elaborate.nix { target = "ipemu"; };
emu-mlirbc = innerSelf.callPackage ./mlirbc.nix { elaborate = emu-elaborate; };
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 march(@arg(name = "mlirbc-file") mlirbcFile: os.Path) = {
println(simplyGetT1Reader(mlirbcFile).march)
}

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

@main
def decoderInstructionsJson(@arg(name = "mlirbc-file") mlirbcFile: os.Path) = {
println(simplyGetT1Reader(mlirbcFile).decoderInstructionsJson)
Expand Down
6 changes: 6 additions & 0 deletions omreaderlib/src/Interface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ class T1Reader private[omreaderlib](evaluator: PanamaCIRCTOMEvaluator, basePath:
}
def decoderInstructionsJson: String = ujson.write(decoderInstructionsJsonImpl)
def decoderInstructionsJsonPretty: String = ujson.write(decoderInstructionsJsonImpl, 2)
def extensionsJson: String = {
val extensions = t1.field("extensions").asInstanceOf[PanamaCIRCTOMEvaluatorValueList]
val j = extensions.elements.map(_.asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString)
ujson.write(j)
}
def march: String = t1.field("march").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString

def dumpMethods(): Unit = {
val mirror = runtimeMirror(getClass.getClassLoader).reflect(this)
Expand Down
12 changes: 6 additions & 6 deletions script/ci/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ object Main:

val testAttr = testType.toLowerCase() match
case "verilator" =>
s".#t1.$config.cases.$caseName.emu-result.with-offline"
case "vcs" => s".#t1.$config.cases.$caseName.emu-result.with-vcs"
s".#t1.$config.ip.cases.$caseName.emu-result.with-offline"
case "vcs" => s".#t1.$config.ip.cases.$caseName.emu-result.with-vcs"
case _ => Logger.fatal(s"Invalid test type ${testType}")
val testResultPath =
try
Expand All @@ -186,7 +186,7 @@ object Main:
os.read(testResultPath / "offline-check-status").trim() == "0"
if !testSuccess then
Logger.error(s"Offline check FAILED for $caseName ($config)")
allFailedTest :+ s"t1.$config.cases.$caseName"
allFailedTest :+ s"t1.$config.ip.cases.$caseName"
else
Logger.info(s"Offline check PASS for $caseName ($config)")
allFailedTest
Expand Down Expand Up @@ -268,8 +268,8 @@ object Main:
Logger.info("Fetching CI results")
val resultAttr = emuType.toLowerCase() match
case "verilator" =>
s".#t1.$config.cases._allEmuResult"
case "vcs" => s".#t1.$config.cases._allVCSEmuResult"
s".#t1.$config.ip.cases._allEmuResult"
case "vcs" => s".#t1.$config.ip.cases._allVCSEmuResult"
case _ => Logger.fatal(s"Invalid test type ${emuType}")
val emuResultPath = os.Path(nixResolvePath(
resultAttr,
Expand Down Expand Up @@ -359,7 +359,7 @@ object Main:

import scala.util.chaining._
val testPlans: Seq[String] = emulatorConfigs.flatMap: configName =>
val allCasesPath = nixResolvePath(s".#t1.$configName.cases.all")
val allCasesPath = nixResolvePath(s".#t1.$configName.ip.cases.all")
os.walk(os.Path(allCasesPath) / "configs")
.filter: path =>
path.ext == "json"
Expand Down
14 changes: 14 additions & 0 deletions t1/src/T1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ class T1OM extends Class {
val dlenIn = IO(Input(Property[Int]()))
dlen := dlenIn

@public
val extensions = IO(Output(Property[Seq[String]]()))
@public
val extensionsIn = IO(Input(Property[Seq[String]]()))
extensions := extensionsIn

@public
val march = IO(Output(Property[String]()))
@public
val marchIn = IO(Input(Property[String]()))
march := marchIn

@public
val lanes = IO(Output(Property[Seq[AnyClassType]]()))
@public
Expand Down Expand Up @@ -340,6 +352,8 @@ class T1(val parameter: T1Parameter)

omInstance.vlenIn := Property(parameter.vLen)
omInstance.dlenIn := Property(parameter.dLen)
omInstance.extensionsIn := Property(parameter.extensions)
omInstance.marchIn := Property(s"rv32gc_${parameter.extensions.mkString("_").toLowerCase}_zvl${parameter.vLen}b")

/** the LSU Module */

Expand Down
4 changes: 3 additions & 1 deletion tests/asm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
, makeBuilder
, findAndBuild
, t1main
, getTestRequiredFeatures
}:

let
Expand All @@ -13,6 +14,7 @@ let

src = sourcePath;

featuresRequired = getTestRequiredFeatures sourcePath;
isFp = lib.pathExists (lib.path.append sourcePath "isFp");

buildPhase = ''
Expand All @@ -29,5 +31,5 @@ let
meta.description = "test case '${caseName}', written in C assembly";
};
in
findAndBuild ./. build
findAndBuild ./. build

1 change: 1 addition & 0 deletions tests/asm/fpsmoke/features-required.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["zve32f"]
Empty file removed tests/asm/fpsmoke/isFp
Empty file.
36 changes: 16 additions & 20 deletions tests/builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
{ stdenv
, lib
, jq
, elaborateConfig
, isFp
, vLen
, rtlDesignMetadata

, makeEmuResult
}:
Expand All @@ -28,22 +26,17 @@ let

CC = "${stdenv.targetPlatform.config}-cc";

NIX_CFLAGS_COMPILE =
let
march = (if isFp then "rv32gc_zve32f" else "rv32gc_zve32x")
+ "_zvl${toString (lib.min 1024 vLen)}b";
in
[
"-mabi=ilp32f"
"-march=${march}"
"-mno-relax"
"-static"
"-mcmodel=medany"
"-fvisibility=hidden"
"-fno-PIC"
"-g"
"-O3"
];
NIX_CFLAGS_COMPILE = [
"-mabi=ilp32f"
"-march=${rtlDesignMetadata.march}"
"-mno-relax"
"-static"
"-mcmodel=medany"
"-fvisibility=hidden"
"-fno-PIC"
"-g"
"-O3"
];

installPhase = ''
runHook preInstall
Expand All @@ -63,7 +56,10 @@ let

dontFixup = true;

passthru.emu-result = makeEmuResult caseDrv;
passthru = {
inherit rtlDesignMetadata;
emu-result = makeEmuResult caseDrv;
};

} // overrides);
in
Expand Down
Loading