diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..9b6a1acdf --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +* +!sw/**/*.py +!util/**/*.py +!pyproject.toml diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml deleted file mode 100644 index 5c073ab5d..000000000 --- a/.github/workflows/build-docker.yml +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright 2020 ETH Zurich and University of Bologna. -# Licensed under the Apache License, Version 2.0, see LICENSE for details. -# SPDX-License-Identifier: Apache-2.0 - -# Build Docker image and publish to pulp-platform's GHCR. -name: build-docker -on: - push: - branches: [main] - workflow_dispatch: -jobs: - build-docker: - name: Deploy Docker image - runs-on: ubuntu-22.04 - steps: - # Free up disk space on Github-hosted runner - - name: Disk usage - run: df -h - - uses: jlumbroso/free-disk-space@v1.3.1 - with: - android: true - dotnet: true - haskell: true - large-packages: true - - name: Disk usage after freeing up space - run: df -h - # Actually build the Docker container - - uses: actions/checkout@v2 - - uses: docker/setup-buildx-action@v1 - - name: GHCR Log-in - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: . - file: util/container/Dockerfile - push: true - tags: ghcr.io/pulp-platform/snitch_cluster:${{ github.ref_name }} - build-args: |- - SNITCH_LLVM_VERSION=latest diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b486b231..d3d44586f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,8 +5,42 @@ # Run functional regression checks name: ci on: [push, pull_request] + jobs: + ########################## + # Build Docker Container # + ########################## + + build-docker: + name: Deploy Docker image + runs-on: ubuntu-22.04 + if: > + github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name != github.repository + steps: + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@main + with: + docker-images: false + - uses: actions/checkout@v4 + - uses: docker/setup-buildx-action@v3 + - name: GHCR Log-in + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + cache-from: type=gha + cache-to: type=gha,mode=max` + file: util/container/Dockerfile + push: true + tags: ghcr.io/pulp-platform/snitch_cluster:${{ github.ref_name }} + ######## # Docs # ######## @@ -14,8 +48,12 @@ jobs: docs: name: Build documentation runs-on: ubuntu-22.04 + needs: build-docker + if: > + github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name != github.repository container: - image: ghcr.io/pulp-platform/snitch_cluster:main + image: ghcr.io/pulp-platform/snitch_cluster:${{ github.ref_name }} steps: - uses: actions/checkout@v2 - name: Build docs @@ -28,8 +66,12 @@ jobs: pytest: name: Python unit tests runs-on: ubuntu-22.04 + needs: build-docker + if: > + github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name != github.repository container: - image: ghcr.io/pulp-platform/snitch_cluster:main + image: ghcr.io/pulp-platform/snitch_cluster:${{ github.ref_name }} steps: - uses: actions/checkout@v2 - name: Run pytest @@ -42,23 +84,40 @@ jobs: sw-snitch-cluster-vlt: name: Simulate SW on Snitch Cluster w/ Verilator runs-on: ubuntu-22.04 + needs: build-docker + if: > + github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name != github.repository container: - image: ghcr.io/pulp-platform/snitch_cluster:main + image: ghcr.io/pulp-platform/snitch_cluster:${{ github.ref_name }} steps: - uses: actions/checkout@v2 with: submodules: 'recursive' - - name: Install local Python packages - run: pip install . - - name: Build Software - working-directory: target/snitch_cluster - run: | - bender vendor init - make CFG_OVERRIDE=cfg/github-ci.hjson sw + - name: Hash Verilator prerequisites + id: verilator-hash + uses: colluca/list-make-prerequisites@v1.0.1 + with: + working-directory: target/snitch_cluster + target: bin/snitch_cluster.vlt + flags: --recursive + - name: Set up cache for Verilator build + id: verilator-cache + uses: actions/cache@v3 + with: + path: target/snitch_cluster/bin + key: verilator-${{ steps.verilator-hash.outputs.hash }} + restore-keys: | + verilator- - name: Build Hardware + if: steps.verilator-cache.outputs.cache-hit != 'true' working-directory: target/snitch_cluster run: | make CFG_OVERRIDE=cfg/github-ci.hjson VLT_JOBS=1 bin/snitch_cluster.vlt + - name: Build Software + working-directory: target/snitch_cluster + run: | + make CFG_OVERRIDE=cfg/github-ci.hjson sw - name: Run Tests working-directory: target/snitch_cluster run: | @@ -69,28 +128,64 @@ jobs: run: | make SIM_DIR=./runs/simple annotate -j - ######################################### - # Build SW on Snitch Cluster w/ Banshee # - ######################################### + # ######################################### + # # Build SW on Snitch Cluster w/ Banshee # + # ######################################### + + # sw-snitch-cluster-banshee: + # name: Simulate SW on Snitch Cluster w/ Banshee + # runs-on: ubuntu-22.04 + # needs: build-docker + # if: > + # github.event_name != 'pull_request' || + # github.event.pull_request.head.repo.full_name != github.repository + # container: + # image: ghcr.io/pulp-platform/snitch_cluster:${{ github.ref_name }} + # steps: + # - uses: actions/checkout@v2 + # with: + # submodules: 'recursive' + # - name: Build Software + # run: | + # bender vendor init + # make -C target/snitch_cluster SELECT_RUNTIME=banshee sw + # - name: Run Tests + # env: + # SNITCH_LOG: info + # working-directory: target/snitch_cluster + # run: | + # ./util/run.py sw/run.yaml --simulator banshee -j - sw-snitch-cluster-banshee: - name: Simulate SW on Snitch Cluster w/ Banshee + ###################### + # Sources Up-to-Date # + ###################### + sources-up-to-date: + name: Check Sources Up-to-Date runs-on: ubuntu-22.04 + needs: build-docker + if: > + github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name != github.repository container: - image: ghcr.io/pulp-platform/snitch_cluster:main + image: ghcr.io/pulp-platform/snitch_cluster:${{ github.ref_name }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: - submodules: 'recursive' - - name: Install local Python packages - run: pip install . - - name: Build Software + submodules: true + - name: Generate opcodes run: | - bender vendor init - make -C target/snitch_cluster SELECT_RUNTIME=banshee sw - - name: Run Tests - env: - SNITCH_LOG: info + ./util/generate-opcodes.sh + - name: Generate RTL sources working-directory: target/snitch_cluster run: | - ./util/run.py sw/run.yaml --simulator banshee -j + make rtl + # For some reason, the checkout is done by a different user, + # than that running `git diff` (root, possibly due to Docker). + # So we need to set the repository as a safe directory. + - name: Git config safe.directory + run: | + git config --global --add safe.directory $GITHUB_WORKSPACE + - name: Diff porcelain + uses: mmontes11/diff-porcelain@v0.0.1 + with: + message: Found differences, please update all sources diff --git a/.github/workflows/gitlab-ci.yaml b/.github/workflows/gitlab-ci.yaml index e367a594b..237b6af31 100644 --- a/.github/workflows/gitlab-ci.yaml +++ b/.github/workflows/gitlab-ci.yaml @@ -13,10 +13,10 @@ jobs: - name: Check Gitlab CI uses: pulp-platform/pulp-actions/gitlab-ci@v2.1.0 # Skip on forks or pull requests from forks due to missing secrets. - if: - # yamllint disable rule:line-length - github.repository == 'pulp-platform/snitch_cluster' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) - # yamllint enable rule:line-length + if: > + github.repository == 'pulp-platform/snitch_cluster' && + (github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name == github.repository) with: domain: iis-git.ee.ethz.ch repo: github-mirror/snitch_cluster diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a2ab4fabc..152446d3d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,6 +14,9 @@ jobs: verible-lint: name: Lint Verilog sources runs-on: ubuntu-latest + if: > + github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name != github.repository steps: - uses: actions/checkout@v3 - uses: chipsalliance/verible-linter-action@main @@ -32,48 +35,22 @@ jobs: bender-vendor-up-to-date: name: Check bender vendor up-to-date runs-on: ubuntu-latest + if: > + github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name != github.repository steps: - name: Check bender vendor up-to-date uses: pulp-platform/pulp-actions/bender-vendor-up-to-date@v2.1.0 - ###################### - # Sources Up-to-Date # - ###################### - sources-up-to-date: - name: Check Sources Up-to-Date - runs-on: ubuntu-22.04 - container: - image: ghcr.io/pulp-platform/snitch_cluster:main - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - name: Install local Python packages - run: pip install . - - name: Generate opcodes - run: | - ./util/generate-opcodes.sh - - name: Generate RTL sources - working-directory: target/snitch_cluster - run: | - make rtl - # For some reason, the checkout is done by a different user, - # than that running `git diff` (root, possibly due to Docker). - # So we need to set the repository as a safe directory. - - name: Git config safe.directory - run: | - git config --global --add safe.directory $GITHUB_WORKSPACE - - name: Diff porcelain - uses: mmontes11/diff-porcelain@v0.0.1 - with: - message: Found differences, please update all sources - ################# # Check License # ################# license-lint: name: Check License headers runs-on: ubuntu-latest + if: > + github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name != github.repository steps: - name: Check License uses: pulp-platform/pulp-actions/lint-license@v2.1.0 @@ -97,6 +74,9 @@ jobs: yaml-lint: name: Lint YAML Sources runs-on: ubuntu-latest + if: > + github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name != github.repository steps: - uses: actions/checkout@v3 - name: yaml-lint @@ -109,6 +89,9 @@ jobs: ######################## python-lint: runs-on: ubuntu-latest + if: > + github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name != github.repository name: Lint Python Sources steps: - name: Check out source repository @@ -130,9 +113,12 @@ jobs: clangfmt: name: Lint C/C++ Sources runs-on: ubuntu-latest + if: > + github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name != github.repository steps: - uses: actions/checkout@v3 - - uses: DoozyX/clang-format-lint-action@v0.16.2 + - uses: DoozyX/clang-format-lint-action@v0.18.1 with: clangFormatVersion: 10 @@ -143,6 +129,9 @@ jobs: editorconfig-lint: name: Lint Editorconfig runs-on: ubuntu-latest + if: > + github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name != github.repository steps: - uses: actions/checkout@v3 - uses: editorconfig-checker/action-editorconfig-checker@main diff --git a/apt-requirements.txt b/apt-requirements.txt deleted file mode 100644 index 15f12e8b7..000000000 --- a/apt-requirements.txt +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright 2020 ETH Zurich and University of Bologna. -# Licensed under the Apache License, Version 2.0, see LICENSE for details. -# SPDX-License-Identifier: Apache-2.0 - -# Keep sorted. -clang-format -device-tree-compiler -graphviz -tar diff --git a/docs/requirements.txt b/docs/requirements.txt deleted file mode 100644 index e913931e3..000000000 --- a/docs/requirements.txt +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright 2020 ETH Zurich and University of Bologna. -# Licensed under the Apache License, Version 2.0, see LICENSE for details. -# SPDX-License-Identifier: Apache-2.0 - -# Keep sorted. -mkdocs -mkdocs-material -mkdocs-include-markdown-plugin -mkdocs-macros-plugin -mkdocstrings -mkdocstrings-python diff --git a/docs/ug/documentation.md b/docs/ug/documentation.md index de61ab105..24467bc24 100644 --- a/docs/ug/documentation.md +++ b/docs/ug/documentation.md @@ -7,7 +7,7 @@ theme](https://squidfunk.github.io/mkdocs-material/). Before building the documentation, make sure you have the required dependencies installed: ```shell -pip install -r docs/requirements.txt +pip install . ``` After everything is installed, you can build a static copy of the `html` documentation by diff --git a/iis-setup.sh b/iis-setup.sh index e4cde0480..c77be7bec 100755 --- a/iis-setup.sh +++ b/iis-setup.sh @@ -8,19 +8,17 @@ export BENDER=bender-0.27.1 export CC=gcc-9.2.0 export CXX=g++-9.2.0 export VCS_SEPP=vcs-2020.12 -export VERILATOR_SEPP=verilator-5.006 +export VERILATOR_SEPP=verilator-5.020 export QUESTA_SEPP=questa-2022.3 export LLVM_BINROOT=/usr/pack/riscv-1.0-kgf/pulp-llvm-0.12.0/bin # Create Python virtual environment with required packages -/usr/local/anaconda3-2022.05/bin/python3 -m venv .venv +/usr/local/anaconda3-2023.07/bin/python -m venv .venv source .venv/bin/activate -# Unpack packages in a local temporary directory which can be safely cleaned -# after installation. Also protects against "No space left on device" errors +# Install local packages in editable mode and unpack packages in a +# local temporary directory which can be safely cleaned after installation. +# Also protects against "No space left on device" errors # occurring when the /tmp folder is filled by other processes. mkdir tmp -TMPDIR=tmp pip install -r python-requirements.txt +TMPDIR=tmp pip install -e . rm -rf tmp - -# Install local packages in editable mode. -pip install -e . diff --git a/pyproject.toml b/pyproject.toml index 9e1fc9597..6488077b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ # SPDX-License-Identifier: SHL-0.51 [build-system] -requires = ["setuptools>=42"] +requires = ["setuptools>=64"] build-backend = "setuptools.build_meta" [project] @@ -12,8 +12,44 @@ authors = [ {name = "Luca Colagrande", email = "colluca@iis.ee.ethz.ch"} ] dynamic = ["version"] +dependencies = [ + # Keep sorted. + "bin2coe", + "dataclasses", + "editorconfig-checker==2.3.51", + "flake8", + "gitpython", + "hjson", + "humanize", + "json5", + "jsonref", + "jsonschema", + "mako", + "matplotlib", + "mkdocs", + "mkdocs-material", + "mkdocs-include-markdown-plugin", + "mkdocs-macros-plugin", + "mkdocstrings", + "mkdocstrings-python", + "numpy", + "pandas", + "prettytable", + "progressbar2", + "psutil", + "pyelftools", + "pyflexfloat", + "pytablewriter", + "pytest", + "pyyaml", + "scikit-learn", + "tabulate", + "termcolor", + "torch", + "yamllint" +] [tool.setuptools.package-dir] "snitch.dnn" = "sw/dnn" "snitch.blas" = "sw/blas" -"snitch.util" = "util" \ No newline at end of file +"snitch.util" = "util" diff --git a/python-requirements.txt b/python-requirements.txt deleted file mode 100644 index d9a7d89a9..000000000 --- a/python-requirements.txt +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright 2020 ETH Zurich and University of Bologna. -# Licensed under the Apache License, Version 2.0, see LICENSE for details. -# SPDX-License-Identifier: Apache-2.0 - -# Keep sorted. -bin2coe -dataclasses -editorconfig-checker==2.3.51 -flake8 -gitpython -hjson -humanize -json5 -jsonref -jsonschema -mako -matplotlib -mkdocs-material -pandas -prettytable -progressbar2 -psutil -pyelftools -pyflexfloat -pytablewriter -pytest -pyyaml -scikit-learn -tabulate -termcolor -yamllint - --r docs/requirements.txt --r sw/dnn/requirements.txt diff --git a/sw/dnn/requirements.txt b/sw/dnn/requirements.txt deleted file mode 100644 index c42e8ddf8..000000000 --- a/sw/dnn/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright 2022 ETH Zurich and University of Bologna. -# Licensed under the Apache License, Version 2.0, see LICENSE for details. -# SPDX-License-Identifier: Apache-2.0 - -numpy -torch -json5 diff --git a/target/common/common.mk b/target/common/common.mk index 54a39bd77..c54dff0fd 100644 --- a/target/common/common.mk +++ b/target/common/common.mk @@ -89,9 +89,9 @@ VLT_FLAGS += -Wno-UNSIGNED VLT_FLAGS += -Wno-UNOPTFLAT VLT_FLAGS += -Wno-fatal VLT_FLAGS += --unroll-count 1024 -VLT_FLAGS += --threads $(VLT_NUM_THREADS) +VLT_FLAGS += --threads $(VLT_NUM_THREADS) VLT_CFLAGS += -std=c++20 -pthread -VLT_CFLAGS += -I $(VLT_ROOT)/include -I $(VLT_ROOT)/include/vltstd -I $(VLT_FESVR)/include -I $(TB_DIR) -I ${MKFILE_DIR}test +VLT_CFLAGS += -I $(VLT_FESVR)/include -I $(TB_DIR) -I ${MKFILE_DIR}test RISCV_MC_FLAGS ?= -disassemble -mcpu=snitch ANNOTATE_FLAGS ?= -q --keep-time --addr2line=$(ADDR2LINE) diff --git a/target/common/verilator.mk b/target/common/verilator.mk index b5e86a19b..eb02ee346 100644 --- a/target/common/verilator.mk +++ b/target/common/verilator.mk @@ -4,7 +4,7 @@ $(BIN_DIR)/$(TARGET).vlt: $(VLT_SOURCES) $(TB_CC_SOURCES) $(VLT_CC_SOURCES) $(VLT_BUILDDIR)/lib/libfesvr.a | $(BIN_DIR) $(VLT) $(shell $(BENDER) script verilator $(VLT_BENDER)) \ - $(VLT_FLAGS) -Mdir $(VLT_BUILDDIR) \ + $(VLT_FLAGS) --Mdir $(VLT_BUILDDIR) \ -CFLAGS "$(VLT_CFLAGS)" \ -LDFLAGS "$(VLT_LDFLAGS)" \ -j $(VLT_JOBS) \ diff --git a/util/container/Dockerfile b/util/container/Dockerfile index bfef21266..65670487f 100644 --- a/util/container/Dockerfile +++ b/util/container/Dockerfile @@ -4,174 +4,119 @@ # Docker container for Snitch development. -# 1. Stage -FROM ubuntu:22.04 AS builder -ARG CMAKE_VERSION=3.19.4 -ARG PYTHON_VERSION=3.9.12 +# 1. Stage: Use the verilator container to get the Verilator binary. +ARG VERILATOR_VERSION=5.020 +ARG UBUNTU_VERSION=22.04 + +# 1. Stage: Install additional IIS tools +FROM ubuntu:${UBUNTU_VERSION} AS builder ARG BENDER_VERSION=0.27.1 -ARG SPIKE_DASM_VERSION=0.1.0 -ARG VERILATOR_VERSION=5.006 ARG DOXYGEN_VERSION=1.12.0 +ARG VERIBLE_VERSION=0.0-3318-g8d254167 +ARG SNITCH_LLVM_VERSION=latest +ARG RUST_VERSION=1.63.0 +ARG UBUNTU_VERSION # Run dpkg without interactive dialogue ARG DEBIAN_FRONTEND=noninteractive # Install APT requirements -COPY apt-requirements.txt /tmp/apt-requirements.txt RUN apt-get update && \ - sed 's/#.*//' /tmp/apt-requirements.txt \ - | xargs apt-get install -y && \ apt-get install -y \ - build-essential \ - curl \ - git \ - gnupg2 \ - lsb-release \ - software-properties-common \ - unzip \ - wget \ - zlib1g-dev \ - autoconf \ - help2man \ - flex \ - bison \ - llvm-12-dev \ - libclang-common-12-dev \ - libreadline-dev \ - libncursesw5-dev \ - libssl-dev \ - libsqlite3-dev \ - tk-dev \ - libgdbm-dev \ - libc6-dev \ - libbz2-dev \ - libffi-dev - -# Install Python -RUN wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz -RUN tar xzf Python-${PYTHON_VERSION}.tgz -RUN cd Python-${PYTHON_VERSION} && \ - ./configure --enable-optimizations --prefix=/opt/python/ && \ - make install -j - -# Build Rust tools -RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y -ENV PATH "/root/.cargo/bin:${PATH}" -RUN rustup install 1.70.0 -RUN rustup override set 1.70.0 - -# Build Verilator -RUN git clone https://github.com/verilator/verilator && \ - cd verilator && \ - git checkout "v${VERILATOR_VERSION}" && \ - autoconf && \ - ./configure --prefix /tools/verilator && \ - make && \ - make install + # General requirements + curl wget git tar \ + # Required for rust + build-essential + #\ + # # Required for banshee + # cmake llvm-12-dev libclang-common-12-dev zlib1g-dev + +# # Build Rust tools +# RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +# ENV PATH="/root/.cargo/bin:${PATH}" +# RUN rustup install ${RUST_VERSION} && \ +# rustup override set ${RUST_VERSION} # Change working directory WORKDIR /tools -# Install a newer version of cmake (we need this for banshee) -RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz && \ - tar -x -f cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz --strip-components=1 -C . && \ - rm -rf cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz -ENV PATH "/tools/bin:${PATH}" - -# Install `banshee` (needs cmake) -RUN rustup install 1.67.0 -RUN rustup override set 1.67.0 -RUN git clone https://github.com/pulp-platform/banshee.git /tmp/banshee --recurse-submodules -RUN cargo install --path /tmp/banshee +# # Install `banshee` (needs cmake) +# RUN git clone https://github.com/pulp-platform/banshee.git /tmp/banshee --recurse-submodules && \ +# cargo install --path /tmp/banshee # Install Bender -RUN wget https://github.com/pulp-platform/bender/releases/download/v${BENDER_VERSION}/bender-${BENDER_VERSION}-x86_64-linux-gnu-ubuntu18.04.tar.gz -RUN tar xzf bender-${BENDER_VERSION}-x86_64-linux-gnu-ubuntu18.04.tar.gz +RUN wget https://github.com/pulp-platform/bender/releases/download/v${BENDER_VERSION}/bender-${BENDER_VERSION}-x86_64-linux-gnu-ubuntu${UBUNTU_VERSION}.tar.gz && \ + tar xzf bender-${BENDER_VERSION}-x86_64-linux-gnu-ubuntu${UBUNTU_VERSION}.tar.gz -# Install spike-dasm -RUN wget https://github.com/pulp-platform/riscv-isa-sim/releases/download/snitch-v${SPIKE_DASM_VERSION}/snitch-spike-dasm-${SPIKE_DASM_VERSION}-x86_64-linux-gnu-ubuntu18.04.tar.gz -RUN tar xzf snitch-spike-dasm-${SPIKE_DASM_VERSION}-x86_64-linux-gnu-ubuntu18.04.tar.gz +# Install Verible +RUN wget https://github.com/chipsalliance/verible/releases/download/v${VERIBLE_VERSION}/verible-v${VERIBLE_VERSION}-linux-static-x86_64.tar.gz && \ + tar -x -f verible-v${VERIBLE_VERSION}-linux-static-x86_64.tar.gz --strip-components=1 -C . && \ + rm -rf verible-v${VERIBLE_VERSION}-linux-static-x86_64.tar.gz # Install Doxygen -RUN wget https://www.doxygen.nl/files/doxygen-${DOXYGEN_VERSION}.linux.bin.tar.gz -RUN tar xzf doxygen-${DOXYGEN_VERSION}.linux.bin.tar.gz -RUN mv doxygen-${DOXYGEN_VERSION} doxygen +RUN wget https://www.doxygen.nl/files/doxygen-${DOXYGEN_VERSION}.linux.bin.tar.gz && \ + tar xzf doxygen-${DOXYGEN_VERSION}.linux.bin.tar.gz && \ + mv doxygen-${DOXYGEN_VERSION} doxygen -# 2. Stage -FROM ubuntu:22.04 AS snitch_cluster -ARG SNITCH_LLVM_VERSION=latest -ARG VERIBLE_VERSION=0.0-3318-g8d254167 +# Get the precompiled LLVM toolchain +RUN latest_tag=`curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/pulp-platform/llvm-project/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'` && \ +echo "SNITCH_LLVM_VERSION=${SNITCH_LLVM_VERSION} LLVM_TAR=${LLVM_TAR} latest_tag=${latest_tag}" && \ +test "${SNITCH_LLVM_VERSION}" = "latest" && SNITCH_LLVM_VERSION=${latest_tag} || : ; \ +LLVM_TAR=riscv32-pulp-llvm-ubuntu2004-$(echo $SNITCH_LLVM_VERSION | cut -d '-' -f3-).tar.gz && \ +mkdir -p riscv-llvm && \ +echo "SNITCH_LLVM_VERSION=${SNITCH_LLVM_VERSION} LLVM_TAR=${LLVM_TAR} latest_tag=${latest_tag}" && \ +wget -qO- https://github.com/pulp-platform/llvm-project/releases/download/${SNITCH_LLVM_VERSION}/${LLVM_TAR} | \ +tar xvz --strip-components=1 -C riscv-llvm + +# 2. Stage: Create the final container +FROM verilator/verilator:v${VERILATOR_VERSION} AS snitch_cluster +ARG PYTHON_VERSION=3.11 +# Run dpkg without interactive dialogue +ARG DEBIAN_FRONTEND=noninteractive LABEL version="0.1" LABEL description="Snitch container for hardware and software development." LABEL maintainer="zarubaf@iis.ee.ethz.ch" -LABEL org.opencontainers.image.source https://github.com/pulp-platform/snitch_cluster +LABEL org.opencontainers.image.source=https://github.com/pulp-platform/snitch_cluster -WORKDIR /tools - -# Install (and cleanup) required packages (from apt-requirements.txt) -# The list of extra packages is leftover from before this Dockerfile used -# apt-requirements.txt -# -COPY apt-requirements.txt /tmp/apt-requirements.txt RUN apt-get update && \ - sed 's/#.*//' /tmp/apt-requirements.txt \ - | xargs apt-get install -y && \ apt-get install -y --no-install-recommends \ - ca-certificates \ - gnupg2 \ - curl \ - wget \ - build-essential \ - git && \ - apt-get clean ; \ - rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* - -# Get the precompiled LLVM toolchain -RUN latest_tag=`curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/pulp-platform/llvm-project/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'` && \ - echo "SNITCH_LLVM_VERSION=${SNITCH_LLVM_VERSION} LLVM_TAR=${LLVM_TAR} latest_tag=${latest_tag}" && \ - test "${SNITCH_LLVM_VERSION}" = "latest" && SNITCH_LLVM_VERSION=${latest_tag} || : ; \ - LLVM_TAR=riscv32-pulp-llvm-ubuntu2004-$(echo $SNITCH_LLVM_VERSION | cut -d '-' -f3-).tar.gz && \ - mkdir -p riscv-llvm && \ - echo "SNITCH_LLVM_VERSION=${SNITCH_LLVM_VERSION} LLVM_TAR=${LLVM_TAR} latest_tag=${latest_tag}" && \ - wget -qO- https://github.com/pulp-platform/llvm-project/releases/download/${SNITCH_LLVM_VERSION}/${LLVM_TAR} | \ - tar xvz --strip-components=1 -C riscv-llvm -ENV LLVM_BINROOT "/tools/riscv-llvm/bin" - -# Install Verible -RUN wget https://github.com/chipsalliance/verible/releases/download/v${VERIBLE_VERSION}/verible-v${VERIBLE_VERSION}-linux-static-x86_64.tar.gz && \ - tar -x -f verible-v${VERIBLE_VERSION}-linux-static-x86_64.tar.gz --strip-components=1 -C . && \ - rm -rf verible-v${VERIBLE_VERSION}-linux-static-x86_64.tar.gz -ENV PATH "/tools/bin:${PATH}" - -# Install git>=2.18, required by Github checkout action to recurse submodules -RUN apt-get update && apt-get install software-properties-common -y && \ - add-apt-repository -y ppa:git-core/ppa && \ + # General requirements + curl wget build-essential git \ + # Required for python + software-properties-common gnupg2 \ + # Required for fesvr + device-tree-compiler && \ + # Install Python + apt-add-repository ppa:deadsnakes/ppa && \ apt-get update && \ - apt-get install git -y + apt-get install -y --no-install-recommends \ + python${PYTHON_VERSION}-venv && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* -# Copy artifacts from stage 1. -COPY --from=builder /tools/bender bin/ -COPY --from=builder /tools/spike-dasm bin/ -COPY --from=builder /root/.cargo/bin/banshee bin/ -COPY --from=builder /opt/python /opt/python -COPY --from=builder /tools/verilator /tools/verilator/ -COPY --from=builder /tools/doxygen/bin/doxygen bin/ +# Copy all needed files to install the package +COPY pyproject.toml . +COPY sw ./sw +COPY util ./util # Create and activate virtual environment -ENV VIRTUAL_ENV "/root/.venvs/snitch_cluster" -RUN /opt/python/bin/python3 -m venv ${VIRTUAL_ENV} +ARG VIRTUAL_ENV="/root/.venvs/snitch_cluster" +RUN python${PYTHON_VERSION} -m venv ${VIRTUAL_ENV} + +# Upgrade pip and install packages using the virtual environment's pip +RUN ${VIRTUAL_ENV}/bin/pip install --upgrade pip && \ + ${VIRTUAL_ENV}/bin/pip install . + +# Copy the tools from the builder stage +COPY --from=builder /tools/bender /tools/bin/ +# COPY --from=builder /root/.cargo/bin/banshee /tools/bin/ +COPY --from=builder /tools/doxygen/bin/doxygen /tools/bin/ +COPY --from=builder /tools/verible* /tools/bin/ +COPY --from=builder /tools/riscv-llvm /tools/riscv-llvm + +# Modify environment and path variables +ENV VLT="verilator-wrap.sh" +ENV LLVM_BINROOT="/tools/riscv-llvm/bin" ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" -# Install Python requirements -COPY python-requirements.txt /tmp/python-requirements.txt -COPY docs/requirements.txt /tmp/docs/requirements.txt -COPY sw/dnn/requirements.txt /tmp/sw/dnn/requirements.txt -RUN pip install -r /tmp/python-requirements.txt - -# Add Verilator to PATH -ENV PATH "/tools/verilator/bin:${PATH}" -ENV VLT_ROOT "/tools/verilator/share/verilator/" - -# Set locale to UTF-8, required because Python 3.6 defaults on ASCII encoding. -# See https://click.palletsprojects.com/en/8.1.x/unicode-support/ -ENV LC_ALL "C.UTF-8" -ENV LANG "C.UTF-8" +ENV PATH="/tools/bin:${PATH}" +ENV PATH="/tools/riscv-llvm/bin:${PATH}" diff --git a/util/container/README.md b/util/container/README.md index ffc8305eb..714e55a13 100644 --- a/util/container/README.md +++ b/util/container/README.md @@ -28,7 +28,7 @@ In case you cannot use the pre-built container, e.g. if you need to make changes container locally by running the following command in the root of the repository: ```shell -$ sudo docker build -t ghcr.io/pulp-platform/snitch_cluster:main -f util/container/Dockerfile . +$ sudo docker buildx build -t ghcr.io/pulp-platform/snitch_cluster:main -f util/container/Dockerfile . ``` ## Usage