Skip to content

Commit d0a0176

Browse files
committed
Add docker setup, ibex output checking, github actions
1 parent 3ac8bd3 commit d0a0176

File tree

12 files changed

+593
-207
lines changed

12 files changed

+593
-207
lines changed

.github/workflows/verify.yml

Lines changed: 173 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,179 @@
1-
21
name: Verify
32

4-
on: [push]
3+
on:
4+
push:
5+
6+
permissions:
7+
contents: read
8+
packages: write
9+
10+
env:
11+
GHCR_IMAGE: ghcr.io/kastnerrg/cgra4ml-ibex
12+
IMAGE_TAG: latest
513

614
jobs:
7-
verify-with-verilator:
8-
runs-on: ubuntu-latest
15+
build-and-push-image:
16+
runs-on: ubuntu-22.04
17+
18+
outputs:
19+
docker_changed: ${{ steps.check-changes.outputs.docker_changed }}
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
- id: check-changes
28+
name: Detect Docker / env changes
29+
shell: bash
30+
run: |
31+
set -e
32+
33+
BEFORE="${{ github.event.before }}"
34+
SHA="${{ github.sha }}"
35+
36+
# First push to branch (no "before" commit)? Force rebuild.
37+
if [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
38+
echo "First push on this branch -> rebuild image"
39+
echo "docker_changed=true" >> "$GITHUB_OUTPUT"
40+
exit 0
41+
fi
42+
43+
echo "Diffing $BEFORE..$SHA"
44+
45+
# If BEFORE commit is not in this clone (rebased branch / force push / shallow mismatch),
46+
# just force a rebuild instead of trying to diff.
47+
if ! git cat-file -e "$BEFORE^{commit}" 2>/dev/null; then
48+
echo "Base commit $BEFORE not found in local history -> rebuild image"
49+
echo "docker_changed=true" >> "$GITHUB_OUTPUT"
50+
exit 0
51+
fi
52+
53+
files="$(git diff --name-only "$BEFORE" "$SHA")"
54+
echo "Changed files:"
55+
echo "$files"
56+
57+
if echo "$files" | grep -E '^(Dockerfile|Makefile|pyproject.toml|ibex-soc/python-requirements.txt|ibex-soc/vendor/google_riscv-dv/requirements.txt)$' >/dev/null; then
58+
echo "Docker / env inputs changed -> rebuild"
59+
echo "docker_changed=true" >> "$GITHUB_OUTPUT"
60+
else
61+
echo "No Dockerfile/Makefile/pyproject/req changes -> reuse existing image"
62+
echo "docker_changed=false" >> "$GITHUB_OUTPUT"
63+
fi
64+
65+
- name: Log in to GHCR
66+
if: steps.check-changes.outputs.docker_changed == 'true'
67+
uses: docker/login-action@v3
68+
with:
69+
registry: ghcr.io
70+
username: ${{ github.actor }}
71+
password: ${{ secrets.GITHUB_TOKEN }}
72+
73+
- name: Build Docker image via Makefile
74+
if: steps.check-changes.outputs.docker_changed == 'true'
75+
shell: bash
76+
run: |
77+
# Build using your top-level Makefile, but tag with GHCR_IMAGE:dev
78+
make IMAGE="${GHCR_IMAGE}:dev" image
79+
docker tag "${GHCR_IMAGE}:dev" "${GHCR_IMAGE}:${IMAGE_TAG}"
80+
81+
- name: Push image to GHCR
82+
if: steps.check-changes.outputs.docker_changed == 'true'
83+
shell: bash
84+
run: docker push "${GHCR_IMAGE}:${IMAGE_TAG}"
85+
86+
riscv:
87+
runs-on: ubuntu-22.04
88+
needs: build-and-push-image
89+
90+
steps:
91+
- name: Check
92+
run: |
93+
docker run --rm \
94+
-v "$PWD":/work \
95+
-w /work \
96+
"${GHCR_IMAGE}:${IMAGE_TAG}" \
97+
bash -lc '
98+
echo $PATH
99+
which riscv32-unknown-elf-gcc
100+
ls /opt/lowrisc-toolchain/bin/
101+
riscv32-unknown-elf-gcc --version
102+
'
103+
104+
smoke-test:
105+
runs-on: ubuntu-22.04
106+
needs: build-and-push-image
107+
108+
steps:
109+
- name: Checkout code
110+
uses: actions/checkout@v4
111+
112+
- name: Free disk space on runner
113+
run: |
114+
echo "Before cleanup:"; df -h
115+
sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/lib/android /opt/hostedtoolcache/CodeQL || true
116+
sudo apt-get clean || true
117+
sudo rm -rf /var/lib/apt/lists/* || true
118+
docker system prune -af || true
119+
echo "After cleanup:"; df -h
120+
121+
- name: Log in to GHCR
122+
uses: docker/login-action@v3
123+
with:
124+
registry: ghcr.io
125+
username: ${{ github.actor }}
126+
password: ${{ secrets.GITHUB_TOKEN }}
127+
128+
- name: Pull CI image
129+
run: docker pull "${GHCR_IMAGE}:${IMAGE_TAG}"
130+
131+
- name: Smoke test (param_test)
132+
run: |
133+
docker run --rm \
134+
-v "$PWD":/work \
135+
-w /work \
136+
"${GHCR_IMAGE}:${IMAGE_TAG}" \
137+
bash -lc '
138+
mkdir -p run/work
139+
make TEST=param_test smoke_test
140+
'
141+
142+
verify-ibex-soc:
143+
runs-on: ubuntu-22.04
144+
needs: smoke-test
9145

10146
steps:
11-
- uses: actions/checkout@v4
12-
13-
- name: Cache modules
14-
id: cache-verify
15-
uses: actions/cache@v3
16-
env:
17-
cache-name: cache-verify
18-
with:
19-
path: ~/.verify
20-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
21-
restore-keys: |
22-
${{ runner.os }}-build-${{ env.cache-name }}-
23-
${{ runner.os }}-build-
24-
${{ runner.os }}-
25-
26-
- name: Set up Python 3.11.5
27-
uses: actions/setup-python@v4
28-
with:
29-
python-version: '3.11.5'
30-
31-
- name: Install Verilator
32-
run: |
33-
sudo apt-get install --only-upgrade python3
34-
sudo apt-get install git help2man perl python3 make autoconf g++ flex bison ccache libunwind-dev
35-
sudo apt-get install libgoogle-perftools-dev numactl #perl-doc
36-
sudo apt-get install libfl2 # Ubuntu only (ignore if gives error)
37-
sudo apt-get install libfl-dev # Ubuntu only (ignore if gives error)
38-
# sudo apt-get install zlibc zlib1g zlib1g-dev # Ubuntu only (ignore if gives error)
39-
40-
git clone https://github.com/abarajithan11/verilator-compiled
41-
cd verilator-compiled
42-
tar -C ${HOME} -xzf verilator.tar.gz
43-
44-
- name: Install DeepSoCFlow
45-
run: |
46-
python -m pip install --upgrade pip
47-
pip install .
48-
49-
- name: Verify Full Design
50-
run: |
51-
export VERILATOR_ROOT=${HOME}/verilator
52-
export PATH=${VERILATOR_ROOT}/bin:${PATH}
53-
export PYMTL_VERILATOR_INCLUDE_DIR=${VERILATOR_ROOT}/share/verilator/include
54-
verilator --version
55-
56-
mkdir -p run/work
57-
cd run/work
58-
python -m pytest -s ../param_test.py
59-
60-
61-
# resnet50:
62-
# runs-on: ubuntu-latest
63-
64-
# steps:
65-
# - uses: actions/checkout@v2
66-
67-
# - name: Cache modules
68-
# id: cache-verify
69-
# uses: actions/cache@v3
70-
# env:
71-
# cache-name: cache-verify
72-
# with:
73-
# path: ~/.verify
74-
# key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
75-
# restore-keys: |
76-
# ${{ runner.os }}-build-${{ env.cache-name }}-
77-
# ${{ runner.os }}-build-
78-
# ${{ runner.os }}-
79-
80-
# - name: Install Verilator
81-
# run: |
82-
# sudo apt-get install git help2man perl python3 make autoconf g++ flex bison ccache libunwind-dev
83-
# sudo apt-get install libgoogle-perftools-dev numactl #perl-doc
84-
# sudo apt-get install libfl2 # Ubuntu only (ignore if gives error)
85-
# sudo apt-get install libfl-dev # Ubuntu only (ignore if gives error)
86-
# # sudo apt-get install zlibc zlib1g zlib1g-dev # Ubuntu only (ignore if gives error)
87-
88-
# git clone https://github.com/abarajithan11/verilator-compiled
89-
# cd verilator-compiled
90-
# tar -C ${HOME} -xzf verilator.tar.gz
91-
92-
# - name: Install DeepSoCFlow
93-
# run: |
94-
# pip install .
95-
96-
# - name: Verify Full Design
97-
# run: |
98-
# export VERILATOR_ROOT=${HOME}/verilator
99-
# export PATH=${VERILATOR_ROOT}/bin:${PATH}
100-
# export PYMTL_VERILATOR_INCLUDE_DIR=${VERILATOR_ROOT}/share/verilator/include
101-
# verilator --version
102-
103-
# mkdir -p run/work_resnet
104-
# cd run/work_resnet
105-
# python ../resnet_50.py
147+
- name: Checkout code
148+
uses: actions/checkout@v4
149+
150+
- name: Free disk space on runner
151+
run: |
152+
echo "Before cleanup:"; df -h
153+
sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/lib/android /opt/hostedtoolcache/CodeQL || true
154+
sudo apt-get clean || true
155+
sudo rm -rf /var/lib/apt/lists/* || true
156+
docker system prune -af || true
157+
echo "After cleanup:"; df -h
158+
159+
- name: Log in to GHCR
160+
uses: docker/login-action@v3
161+
with:
162+
registry: ghcr.io
163+
username: ${{ github.actor }}
164+
password: ${{ secrets.GITHUB_TOKEN }}
165+
166+
- name: Pull CI image
167+
run: docker pull "${GHCR_IMAGE}:${IMAGE_TAG}"
168+
169+
- name: Ibex SoC regression + output check
170+
run: |
171+
docker run --rm \
172+
-v "$PWD":/work \
173+
-w /work \
174+
"${GHCR_IMAGE}:${IMAGE_TAG}" \
175+
bash -lc '
176+
fusesoc library add sa_ip "$(pwd -P)" || true
177+
mkdir -p run/work
178+
make TEST=ibex_test smoke_test iclean ibuild irun verify_ibex
179+
'

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
old/
22
__pycache__
33

4+
*.conf
5+
run/work/*.log
6+
47
temp/
58

69
run/fpga/*

Dockerfile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
FROM python:3.11.5-slim
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
5+
RUN apt-get update && apt-get install -y \
6+
build-essential \
7+
git curl wget \
8+
libelf-dev srecord \
9+
autoconf automake autotools-dev \
10+
libmpc-dev libmpfr-dev libgmp-dev \
11+
gawk bison flex texinfo patchutils libexpat1-dev \
12+
libfl2 libfl-dev \
13+
help2man perl \
14+
liblzma-dev libunwind-dev libgoogle-perftools-dev numactl \
15+
ccache \
16+
&& rm -rf /var/lib/apt/lists/*
17+
18+
COPY ibex-soc/python-requirements.txt /tmp/python-requirements.txt
19+
COPY ibex-soc/vendor/google_riscv-dv/requirements.txt /tmp/vendor/google_riscv-dv/requirements.txt
20+
RUN python3 -m pip install --no-cache-dir -r /tmp/python-requirements.txt \
21+
&& rm -rf /tmp/python-requirements.txt /tmp/vendor
22+
23+
ARG VERILATOR_VERSION=v5.024
24+
RUN git clone https://github.com/verilator/verilator.git \
25+
&& cd verilator && git checkout ${VERILATOR_VERSION} \
26+
&& autoconf && ./configure \
27+
&& make -j"$(nproc)" && make install \
28+
&& cd .. && rm -rf verilator
29+
30+
WORKDIR /tmp/pybuild
31+
COPY pyproject.toml .
32+
COPY LICENSE .
33+
COPY README.md .
34+
COPY deepsocflow ./deepsocflow
35+
RUN python3 -m pip install --no-cache-dir .
36+
37+
ARG RISCV_TOOLCHAIN_VERSION=20240206-1
38+
RUN wget https://raw.githubusercontent.com/lowRISC/opentitan/master/util/get-toolchain.py -O /tmp/get-toolchain.py \
39+
&& python3 /tmp/get-toolchain.py \
40+
--install-dir /opt/lowrisc-toolchain \
41+
--release-version ${RISCV_TOOLCHAIN_VERSION} \
42+
--update \
43+
&& rm /tmp/get-toolchain.py
44+
45+
ENV RISCV_TOOLCHAIN=/opt/lowrisc-toolchain
46+
ENV RISCV_GCC=${RISCV_TOOLCHAIN}/bin/riscv32-unknown-elf-gcc
47+
ENV RISCV_OBJCOPY=${RISCV_TOOLCHAIN}/bin/riscv32-unknown-elf-objcopy
48+
ENV PATH=${RISCV_TOOLCHAIN}/bin:${PATH}
49+
50+
# Create non-root user to match host UID/GID
51+
ARG USERNAME=usr
52+
ARG UID=1000
53+
ARG GID=1000
54+
55+
RUN groupadd -g ${GID} ${USERNAME} \
56+
&& useradd -m -u ${UID} -g ${GID} ${USERNAME}
57+
58+
USER ${USERNAME}
59+
WORKDIR /work
60+
61+
RUN echo 'export PS1="\[\e[0;33m\][\u@\h \W]\$ \[\e[m\] "' >> /home/${USERNAME}/.bashrc

0 commit comments

Comments
 (0)