Skip to content

Commit 0c18955

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

File tree

12 files changed

+566
-207
lines changed

12 files changed

+566
-207
lines changed

.github/workflows/verify.yml

Lines changed: 146 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,152 @@
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+
files="$(git diff --name-only "$BEFORE" "$SHA" || true)"
45+
echo "Changed files:"
46+
echo "$files"
47+
48+
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
49+
echo "Docker / env inputs changed -> rebuild"
50+
echo "docker_changed=true" >> "$GITHUB_OUTPUT"
51+
else
52+
echo "No Dockerfile/Makefile/pyproject/req changes -> reuse existing image"
53+
echo "docker_changed=false" >> "$GITHUB_OUTPUT"
54+
fi
55+
56+
- name: Log in to GHCR
57+
if: steps.check-changes.outputs.docker_changed == 'true'
58+
uses: docker/login-action@v3
59+
with:
60+
registry: ghcr.io
61+
username: ${{ github.actor }}
62+
password: ${{ secrets.GITHUB_TOKEN }}
63+
64+
- name: Build Docker image via Makefile
65+
if: steps.check-changes.outputs.docker_changed == 'true'
66+
shell: bash
67+
run: |
68+
# Build using your top-level Makefile, but tag with GHCR_IMAGE:dev
69+
make IMAGE="${GHCR_IMAGE}:dev" image
70+
docker tag "${GHCR_IMAGE}:dev" "${GHCR_IMAGE}:${IMAGE_TAG}"
71+
72+
- name: Push image to GHCR
73+
if: steps.check-changes.outputs.docker_changed == 'true'
74+
shell: bash
75+
run: docker push "${GHCR_IMAGE}:${IMAGE_TAG}"
76+
77+
smoke-test:
78+
runs-on: ubuntu-22.04
79+
needs: build-and-push-image
80+
81+
steps:
82+
- name: Checkout code
83+
uses: actions/checkout@v4
84+
85+
- name: Free disk space on runner
86+
run: |
87+
echo "Before cleanup:"; df -h
88+
sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/lib/android /opt/hostedtoolcache/CodeQL || true
89+
sudo apt-get clean || true
90+
sudo rm -rf /var/lib/apt/lists/* || true
91+
docker system prune -af || true
92+
echo "After cleanup:"; df -h
93+
94+
- name: Log in to GHCR
95+
uses: docker/login-action@v3
96+
with:
97+
registry: ghcr.io
98+
username: ${{ github.actor }}
99+
password: ${{ secrets.GITHUB_TOKEN }}
100+
101+
- name: Pull CI image
102+
run: docker pull "${GHCR_IMAGE}:${IMAGE_TAG}"
103+
104+
- name: Smoke test (param_test)
105+
run: |
106+
docker run --rm \
107+
-v "$PWD":/work \
108+
-w /work \
109+
"${GHCR_IMAGE}:${IMAGE_TAG}" \
110+
bash -lc '
111+
mkdir -p run/work
112+
make TEST=param_test smoke_test
113+
'
114+
115+
verify-ibex-soc:
116+
runs-on: ubuntu-22.04
117+
needs: smoke-test
9118

10119
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
120+
- name: Checkout code
121+
uses: actions/checkout@v4
122+
123+
- name: Free disk space on runner
124+
run: |
125+
echo "Before cleanup:"; df -h
126+
sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/lib/android /opt/hostedtoolcache/CodeQL || true
127+
sudo apt-get clean || true
128+
sudo rm -rf /var/lib/apt/lists/* || true
129+
docker system prune -af || true
130+
echo "After cleanup:"; df -h
131+
132+
- name: Log in to GHCR
133+
uses: docker/login-action@v3
134+
with:
135+
registry: ghcr.io
136+
username: ${{ github.actor }}
137+
password: ${{ secrets.GITHUB_TOKEN }}
138+
139+
- name: Pull CI image
140+
run: docker pull "${GHCR_IMAGE}:${IMAGE_TAG}"
141+
142+
- name: Ibex SoC regression + output check
143+
run: |
144+
docker run --rm \
145+
-v "$PWD":/work \
146+
-w /work \
147+
"${GHCR_IMAGE}:${IMAGE_TAG}" \
148+
bash -lc '
149+
fusesoc library add sa_ip "$(pwd -P)" || true
150+
mkdir -p run/work
151+
make TEST=ibex_test smoke_test iclean ibuild irun verify_ibex
152+
'

.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

Makefile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
.PHONY: image start kill enter ibuild irun iclean
2+
3+
# Testing
4+
5+
TEST := param_test
6+
7+
smoke_test:
8+
cd run/work && python -m pytest -s ../$(TEST).py
9+
10+
verify_ibex:
11+
cd ibex-soc && python check_output.py
12+
13+
# Docker
14+
15+
USR := $(shell id -un)
16+
UID := $(shell id -u)
17+
GID := $(shell id -g)
18+
IMAGE := $(USR)/cgra4ml-ibex:dev
19+
CONTAINER := cgra4ml-ibex-$(USR)
20+
HOSTNAME := cgraibex
21+
SHORTUSR := $(shell id -un | cut -c1-4)
22+
23+
image:
24+
docker build \
25+
-f Dockerfile \
26+
--build-arg UID=$(UID) \
27+
--build-arg GID=$(GID) \
28+
--build-arg USERNAME=$(SHORTUSR) \
29+
-t $(IMAGE) .
30+
31+
start:
32+
docker run -d --name $(CONTAINER) \
33+
-h $(HOSTNAME) \
34+
--tty --interactive \
35+
-v $(PWD):/work \
36+
-w /work \
37+
$(IMAGE) bash -lc 'fusesoc library add sa_ip /work || true; tail -f /dev/null'
38+
39+
enter:
40+
docker exec -it $(CONTAINER) bash
41+
42+
kill:
43+
docker kill $(CONTAINER) || true
44+
docker rm $(CONTAINER) || true
45+
46+
# Ibex
47+
48+
ibuild:
49+
${MAKE} -C ibex-soc build
50+
51+
irun:
52+
${MAKE} -C ibex-soc run
53+
54+
iclean:
55+
${MAKE} -C ibex-soc clean
56+
57+
iprint:
58+
${MAKE} -C ibex-soc print

fusesoc.conf

Lines changed: 0 additions & 6 deletions
This file was deleted.

ibex-soc/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ __pycache__
2424
# This is generated by Questa tool when running DV simulations
2525
modelsim.ini
2626

27+
*.hier
28+

0 commit comments

Comments
 (0)