Skip to content

Commit

Permalink
Merge pull request #5 from chipsalliance/ci
Browse files Browse the repository at this point in the history
[ci] add github ci
  • Loading branch information
sequencer authored Sep 11, 2024
2 parents 6ea7e8a + 06b23a9 commit 440eb14
Show file tree
Hide file tree
Showing 18 changed files with 372 additions and 82 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/checkfmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Check the format of a PR
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
- labeled
env:
USER: runner

# Cancel the current workflow when new commit pushed
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:

check-format:
name: "Check format"
runs-on: [self-hosted, linux, nixos]
strategy:
fail-fast: false
defaults:
run:
working-directory: ./templates/chisel
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: "Check Scala format"
continue-on-error: true
run: |
nix develop -c bash -c 'mill -i gcd.checkFormat && mill -i elaborator.checkFormat'
- name: "Check Rust format"
continue-on-error: true
run: |
cd gcdemu
nix develop -c cargo fmt --check
cd ..
- name: "Check nix format"
continue-on-error: true
run: |
nix fmt -- --check nix flake.nix
66 changes: 66 additions & 0 deletions .github/workflows/daily-bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Dependencies Bump
on:
schedule:
# Run this job everyday at 5:30 AM UTC+8
- cron: '30 21 * * *'

jobs:
bump-deps:
name: "Bump Chisel and CIRCT"
if: ${{ !cancelled() }}
runs-on: [self-hosted, linux, nixos]
permissions:
contents: write
defaults:
run:
working-directory: ./templates/chisel
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: master
- name: Bump nixpkgs
run: |
nix flake update
- name: Bump Chisel
run: |
cd nix/pkgs/dependencies
nix run '.#nvfetcher' -- -f '^chisel$'
- name: Bump all mill deps
run: |
oldHash=$(nix derivation show .#gcd.gcd-compiled.millDeps | jq -r 'to_entries[0].value.env.outputHash')
nix build '.#gcd.gcd-compiled.millDeps' --rebuild > milldeps-log.txt 2>&1 || true
newHash=$(cat milldeps-log.txt \
| grep -P '^\s+got:\s+sha256-.*$' \
| cut -d':' -f2 \
| xargs)
if [ -z "$newHash" ] || [ "$newHash" = "$oldHash" ]; then
echo "Original build logs for debug: "
cat milldeps-log.txt
echo "Hash unchanged, exit"
exit 0
fi
echo "Updating hash $oldHash to $newHash"
sed -i "s|$oldHash|$newHash|" nix/gcd/gcd.nix
- name: Commit changes
env:
GITHUB_TOKEN: ${{ secrets.BIYUN_GITHUB_ACTION }}
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
currentDate=$(date +%F)
branch="dependencies-bumping-$currentDate"
git checkout -b "$branch"
git add 'nix/pkgs/dependencies'
git add 'flake.lock'
if ! git diff --quiet --cached --exit-code; then
updatedFiles=$(git diff --cached --name-only)
echo "File changed"
git commit -m "[deps] Bump dependencies"
git push origin "$branch" --force-with-lease
nix run '.#gh' -- \
pr create --title "Bump dependencies" --body "Updated: $updatedFiles"
fi
75 changes: 75 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Build and Run Simulation
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
- labeled
env:
USER: runner

# Cancel the current workflow when new commit pushed
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:

build-simulators:
name: "Build Simulators"
runs-on: [self-hosted, linux, nixos, BIGRAM]
strategy:
fail-fast: false
defaults:
run:
working-directory: ./templates/chisel
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: "Build vcs simulator"
run: |
nix build '.#gcd.vcs' --impure
- name: "Build vcs simulator with trace"
run: |
nix build '.#gcd.vcs-trace' --impure
- name: "Build verilator simulator"
run: |
nix build '.#gcd.verilated'
- name: "Build verilator simulator with trace"
run: |
nix build '.#gcd.verilated-trace'
run-vcs:
name: "Run VCS"
strategy:
fail-fast: false
runs-on: [self-hosted, linux, nixos]
defaults:
run:
working-directory: ./templates/chisel
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: "Run VCS"
run: |
nix build '.#gcd.vcs.tests.simple-sim' --impure -L
run-verilator:
name: "Run Verilator"
strategy:
fail-fast: false
runs-on: [self-hosted, linux, nixos]
defaults:
run:
working-directory: ./templates/chisel
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: "Run verilator"
run: |
nix run '.#gcd.verilated'
10 changes: 10 additions & 0 deletions templates/chisel/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
.bloop
.bsp
.jvm-opts
.mill-jvm-opts
.metals/
.vscode/

out/
result*
gcd-sim-result/
/dependencies/
target/

*.vcd
*.fst
*.fsdb
*.log
2 changes: 1 addition & 1 deletion templates/chisel/.scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ lineEndings = preserve
includeCurlyBraceInSelectChains = false
danglingParentheses.preset = true

align.tokens.add = [
align.tokens."+" = [
{
code = ":"
}
Expand Down
2 changes: 1 addition & 1 deletion templates/chisel/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ trait GCD extends millbuild.common.HasChisel with ScalafmtModule {
}

object elaborator extends Elaborator
trait Elaborator extends millbuild.common.ElaboratorModule {
trait Elaborator extends millbuild.common.ElaboratorModule with ScalafmtModule {
def scalaVersion = T(deps.scalaVer)

def panamaconverterModule = panamaconverter
Expand Down
2 changes: 1 addition & 1 deletion templates/chisel/configs/GCDTestBenchMain.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"width": 16,
"useAsyncReset": false
},
"timeout": 5000,
"timeout": 70000,
"testSize": 100
}
2 changes: 2 additions & 0 deletions templates/chisel/elaborator/src/GCD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ object GCDMain extends Elaborator {
case class GCDParameterMain(
@arg(name = "xLen") xLen: Int,
@arg(name = "useAsyncReset") useAsyncReset: Boolean) {
require(xLen > 0, "xLen must be a non-negative integer")
require(chisel3.util.isPow2(xLen), "xLen must be a power of 2")
def convert: GCDParameter = GCDParameter(xLen, useAsyncReset)
}

Expand Down
3 changes: 2 additions & 1 deletion templates/chisel/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
overlays = [ overlay ];
inherit system;
};
in {
in
{
formatter = pkgs.nixpkgs-fmt;
legacyPackages = pkgs;
devShells.default = pkgs.mkShell ({
Expand Down
4 changes: 2 additions & 2 deletions templates/chisel/gcdemu/src/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ impl Driver {
WATCHDOG_FINISH
} else if tick - self.last_input_cycle > self.timeout {
error!(
"[{}] watchdog timeout, last input tick = {}",
tick, self.last_input_cycle
"[{}] watchdog timeout, last input tick = {}, {} tests completed",
tick, self.last_input_cycle, self.test_num
);
WATCHDOG_TIMEOUT
} else {
Expand Down
91 changes: 45 additions & 46 deletions templates/chisel/nix/gcd/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,55 @@

{ lib, newScope, }:
lib.makeScope newScope (scope:
let
designTarget = "GCD";
tbTarget = "GCDTestBench";
dpiLibName = "gcdemu";
in {
# RTL
gcd-compiled = scope.callPackage ./gcd.nix { target = designTarget; };
elaborate = scope.callPackage ./elaborate.nix {
elaborator = scope.gcd-compiled.elaborator;
};
mlirbc = scope.callPackage ./mlirbc.nix { };
rtl = scope.callPackage ./rtl.nix { };
let
designTarget = "GCD";
tbTarget = "GCDTestBench";
dpiLibName = "gcdemu";
in
{
# RTL
gcd-compiled = scope.callPackage ./gcd.nix { target = designTarget; };
elaborate = scope.callPackage ./elaborate.nix {
elaborator = scope.gcd-compiled.elaborator;
};
mlirbc = scope.callPackage ./mlirbc.nix { };
rtl = scope.callPackage ./rtl.nix { };

# Testbench
tb-compiled = scope.callPackage ./gcd.nix { target = tbTarget; };
tb-elaborate = scope.callPackage ./elaborate.nix {
elaborator = scope.tb-compiled.elaborator;
};
tb-mlirbc =
scope.callPackage ./mlirbc.nix { elaborate = scope.tb-elaborate; };
tb-rtl = scope.callPackage ./rtl.nix { mlirbc = scope.tb-mlirbc; };
tb-dpi-lib = scope.callPackage ./dpi-lib.nix { inherit dpiLibName; };
# Testbench
tb-compiled = scope.callPackage ./gcd.nix { target = tbTarget; };
tb-elaborate = scope.callPackage ./elaborate.nix {
elaborator = scope.tb-compiled.elaborator;
};
tb-mlirbc =
scope.callPackage ./mlirbc.nix { elaborate = scope.tb-elaborate; };
tb-rtl = scope.callPackage ./rtl.nix { mlirbc = scope.tb-mlirbc; };
tb-dpi-lib = scope.callPackage ./dpi-lib.nix { inherit dpiLibName; };

verilated = scope.callPackage ./verilated.nix {
rtl = scope.tb-rtl.override { enable-layers = [ "Verification" ]; };
dpi-lib = scope.tb-dpi-lib;
};
verilated-trace = scope.verilated.override {
dpi-lib = scope.verilated.dpi-lib.override { enable-trace = true; };
};
vcs = scope.callPackage ./vcs.nix {
dpi-lib = scope.tb-dpi-lib.override {
sv2023 = false;
vpi = true;
};
rtl = scope.tb-rtl.override {
enable-layers =
[ "Verification" "Verification.Assert" "Verification.Cover" ];
};
verilated = scope.callPackage ./verilated.nix {
rtl = scope.tb-rtl.override { enable-layers = [ "Verification" ]; };
dpi-lib = scope.tb-dpi-lib;
};
verilated-trace = scope.verilated.override {
dpi-lib = scope.verilated.dpi-lib.override { enable-trace = true; };
};
vcs = scope.callPackage ./vcs.nix {
dpi-lib = scope.tb-dpi-lib.override {
sv2023 = false;
vpi = true;
timescale = 1000;
};
vcs-trace = scope.vcs.override {
dpi-lib = scope.vcs.dpi-lib.override {
enable-trace = true;
timescale = 1000;
};
rtl = scope.tb-rtl.override {
enable-layers =
[ "Verification" "Verification.Assert" "Verification.Cover" ];
};
};
vcs-trace = scope.vcs.override {
dpi-lib = scope.vcs.dpi-lib.override { enable-trace = true; };
};

# TODO: designConfig should be read from OM
tbConfig = with builtins;
fromJSON (readFile ./../../configs/${tbTarget}Main.json);
# TODO: designConfig should be read from OM
tbConfig = with builtins;
fromJSON (readFile ./../../configs/${tbTarget}Main.json);

})
})

11 changes: 9 additions & 2 deletions templates/chisel/nix/gcd/dpi-lib.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2024 Jiuyang Liu <liu@jiuyang.me>

{ lib, rustPlatform, tbConfig, dpiLibName, sv2023 ? true, vpi ? false
, enable-trace ? false, timescale ? 1 }:
{ lib
, rustPlatform
, tbConfig
, dpiLibName
, sv2023 ? true
, vpi ? false
, enable-trace ? false
, timescale ? 1
}:

rustPlatform.buildRustPackage rec {
name = "dpi-lib";
Expand Down
Loading

0 comments on commit 440eb14

Please sign in to comment.