Skip to content

Commit

Permalink
[release] add docker image and related document
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Apr 8, 2024
1 parent c09a4f0 commit d320149
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nix/t1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ lib.makeScope newScope
mlirbc = innerSelf.callPackage ./mlirbc.nix { target = "subsystem"; /* use-binder = true; */ };
rtl = innerSelf.callPackage ./rtl.nix { mlirbc = innerSelf.subsystem.mlirbc; };
};

release = innerSelf.callPackage ./release {
ip-emulator = ip.emu-trace;
};
})
)
)
90 changes: 90 additions & 0 deletions nix/t1/release/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{ lib
, newScope

, stdenvNoCC
, fetchFromGitHub
, runCommand
, makeWrapper
, typst
, jq

, configName
, t1-script
, ip-emulator
, cases
, elaborateConfigJson
, pkgsCross
}:

lib.makeScope newScope (scope: rec {
inherit ip-emulator elaborateConfigJson;

testCases = with cases; [
intrinsic.matmul
intrinsic.softmax
intrinsic.linear_normalization
];

emulator-wrapped = runCommand "ip-emulator"
{
nativeBuildInputs = [ makeWrapper ];
}
''
mkdir -p $out/bin
makeWrapper ${t1-script}/bin/t1-helper $out/bin/ip-emulator \
--add-flags "ipemu" \
--add-flags "--config ${elaborateConfigJson}" \
--add-flags "--emulator-path ${ip-emulator}/bin/emulator"
'';

docker-layers = scope.callPackage ./docker-layers.nix {
rv32-gcc = pkgsCross.riscv32-embedded.buildPackages.gcc;
};

doc = stdenvNoCC.mkDerivation {
name = "${configName}-typst-release-doc";

nativeBuildInputs = [ typst jq ];

src = ./doc.typ;

unpackPhase =
let
typstPkgs = [
{
pkgName = "preview/codly";
version = "0.2.0";
src = fetchFromGitHub {
owner = "Dherse";
repo = "codly";
rev = "0037b522957de3ab8e88cb689bf813aafa96a1b8";
hash = "sha256-OZB9D0KpS9qVIU6O62uPQzQKx0xFxm8/nnkFU4MIkqY=";
};
}
];
in
''
export XDG_CACHE_HOME=$(mktemp -d)
typstPkgRoot="$XDG_CACHE_HOME"/typst/packages
${lib.concatMapStringsSep "\n"
(info: ''
dstDir="$typstPkgRoot/${info.pkgName}/${info.version}"
mkdir -p $dstDir
cp -vrT ${info.src} "$dstDir"
'')
typstPkgs}
ls -al $typstPkgRoot
'';

buildPhase = ''
cp -v ${./doc.typ} ./doc.typ
jq '.name = "${configName}"' ${elaborateConfigJson} > config.json
mkdir $out
typst compile \
./doc.typ $out/${configName}.pdf
'';
};
})
67 changes: 67 additions & 0 deletions nix/t1/release/doc.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#import "@preview/codly:0.2.0": *
#show: codly-init.with()
#codly(languages: (
bash: (name: "Bash", icon: none, color: rgb("#CE412B")),
))

= T1 Docker Image Guidance

== Released IP configs

#let table-json(config) = {
let name = config.name
let param = config.parameter
let floatSupport = if param.extensions.first() == "Zve32f" [ True ] else [ False ]
let VRFRamType = param.vrfRamType.split(".").last()
let VRF = [#param.vrfBankSize Bank, #VRFRamType]
let lsuBankCnt = param.lsuBankParameters.len()
let beatByteCnt = param.lsuBankParameters.first().beatbyte
table(
columns: 6,
[*Config Name*], [*DLEN*], [*VLEN*], [*Float support*], [*VRF*], [*LSU*],
[*#name*], [#param.dLen], [#param.vLen], [#floatSupport], [#VRF], [#lsuBankCnt bank, #beatByteCnt beatbyte],
)
}

#table-json(json("./config.json"))

== Address Range

#table(
columns: 3,
[*Range*], [*Usage*], [*Address Range*],
[0-1G], [Scalar Bank], [0x20000000],
[1-3G], [DDR Bank (512M/bank)], [0x40000000],
[3G-3G+2M], [SRAM Bank (256K/bank 8Banks)], [0xc0000000]
)

Scalar core cannot access Vector DDR/SRAM, for, users need to access corresponding memory banks via vector load store instructions.

== How to use the Docker image

```bash
# Load the image into docker registry
docker pull ghcr.io/chipsalliance/t1:latest
# Run the t1/release:latest image with command /bin/bash, name the running container with name "t1", with [i]nterative shell and a working [t]ty.
# The directory `/workspace` will be bind mount on the current directory. The container will be automatically [r]e[m]ove at exit.
docker run --name t1 -it -v $PWD:/workspace --rm t1/release:latest /bin/bash
```

== What is inside

+ IP emulator: `/bin/ip-emulator`
+ Softmax/Linear Normalization/Matmul test cases: `/workspace/cases`
+ RISCV 32 GCC ToolChain

== How to run workload using IP emulator

```bash
# There are three cases under the /workspace/cases directory
ls /workspace/cases
# Choose one of the case to run
ip-emulator --case cases/intrinsic-matmul/bin/intrinsic.matmul.elf
# Get waveform trace file
ip-emulator --trace --case ...
```
63 changes: 63 additions & 0 deletions nix/t1/release/docker-layers.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{ lib
# build deps
, dockerTools
, runCommand

# Runtime deps
, bashInteractive
, which
, stdenv
, jq

# T1 Stuff
, rv32-gcc
, emulator-wrapped
, testCases
}:

let
# Don't use buildImage which relies on KVM feature
self = dockerTools.streamLayeredImage {
name = "t1/release";
tag = "latest";

contents = with dockerTools; [
usrBinEnv
binSh
bashInteractive
which

emulator-wrapped
rv32-gcc
]
++ stdenv.initialPath;

enableFakechroot = true;
fakeRootCommands = ''
echo "Start finalizing rootfs"
echo "Creating testcase directory"
mkdir -p /workspace/cases/
caseArray=( ${lib.escapeShellArgs testCases} )
for caseDir in "''${caseArray[@]}"; do
dirName=$(${jq}/bin/jq -r '.name|split(".")|join("-")' "$caseDir"/*.json)
cp -r "$caseDir" /workspace/cases/"$dirName"
done
chmod u+w -R /workspace/cases
'';

config = {
# Cmd = [ ];
WorkingDir = "/workspace";
};

passthru = {
final-image = runCommand "convert-layer-to-final-image" { } ''
mkdir $out
${bashInteractive}/bin/bash ${self} > $out/image.tar
'';
};
};
in
self

0 comments on commit d320149

Please sign in to comment.