From 854b23a3765e0726035f87e89dfd42aa7dad8fe5 Mon Sep 17 00:00:00 2001 From: Luca Colagrande Date: Fri, 12 Sep 2025 16:19:39 +0200 Subject: [PATCH 1/7] Use llvm-mc instead of spike-dasm --- Snakefile | 4 +++- default.yaml | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Snakefile b/Snakefile index f5fbc731..a1ede2e7 100644 --- a/Snakefile +++ b/Snakefile @@ -376,8 +376,10 @@ rule dasm_to_trace: params: spike=config["spike"], gentrace=config["gentrace"], + llvm_mc=config["llvm-mc"], + llvm_mcflags=config["llvm-mcflags"], shell: - "{params.spike} < {input} | {params.gentrace} --permissive --dump-hart-perf {log.json} -o {log.txt}" + "{params.gentrace} {input} --mc-exec {params.llvm_mc} --mc-flags \"{params.llvm_mcflags}\" --permissive --dump-hart-perf {log.json} -o {log.txt}" # Rule used to generate traces for debugging purposes, not used for csv generation diff --git a/default.yaml b/default.yaml index 4f6e12ff..fc2ada8b 100644 --- a/default.yaml +++ b/default.yaml @@ -3,6 +3,7 @@ xdsl-opt: xdsl-opt # from virtualenv mlir-opt: /usr/bin/mlir-opt-16 mlir-translate: /usr/bin/mlir-translate-16 cc: /opt/snitch-llvm/bin/clang++ +llvm-mc: /tools/riscv-llvm/bin/llvm-mc spike: /opt/snitch-spike/bin/spike-dasm vltsim: /opt/snitch-rtl/bin/snitch_cluster.vlt gentrace: /opt/snitch_cluster/util/trace/gen_trace.py @@ -68,6 +69,9 @@ ldflags: - -lc - -lsnRuntime - -lclang_rt.builtins-riscv32 +llvm-mcflags: + - -disassemble + - -mcpu=snitch xdsl-passes: - test-lower-linalg-to-snitch mlir-opt-flags-linalg: From d45efa2db85116f360d07ea525025f5308896143 Mon Sep 17 00:00:00 2001 From: Luca Colagrande Date: Fri, 12 Sep 2025 11:25:40 +0200 Subject: [PATCH 2/7] Use new slim Snitch software-dev container --- default.yaml | 8 ++--- docker/Dockerfile | 73 ++++++++------------------------------------ docker/entrypoint.sh | 13 -------- docker/venv.sh | 20 ------------ requirements.txt | 2 +- 5 files changed, 18 insertions(+), 98 deletions(-) delete mode 100755 docker/entrypoint.sh delete mode 100755 docker/venv.sh diff --git a/default.yaml b/default.yaml index fc2ada8b..f4c49d33 100644 --- a/default.yaml +++ b/default.yaml @@ -2,10 +2,10 @@ xdsl-opt: xdsl-opt # from virtualenv mlir-opt: /usr/bin/mlir-opt-16 mlir-translate: /usr/bin/mlir-translate-16 -cc: /opt/snitch-llvm/bin/clang++ +cc: /tools/riscv-llvm/bin/clang++ llvm-mc: /tools/riscv-llvm/bin/llvm-mc spike: /opt/snitch-spike/bin/spike-dasm -vltsim: /opt/snitch-rtl/bin/snitch_cluster.vlt +vltsim: snitch_cluster.vlt gentrace: /opt/snitch_cluster/util/trace/gen_trace.py xdsl_commit: /src/xdsl_commit.txt @@ -58,10 +58,10 @@ cflags: - -I/opt/snitch_cluster/sw/math/include/bits - -I/opt/snitch_cluster/sw/math/include ldflags: - - -fuse-ld=/opt/snitch-llvm/bin/ld.lld + - -fuse-ld=/tools/riscv-llvm/bin/ld.lld - -nostartfiles - -nostdlib - - -L/opt/snitch-llvm/lib/clang/15.0.0/lib/ + - -L/tools/riscv-llvm/lib/clang/15.0.0/lib/ - -L/opt/snitch_cluster/target/snitch_cluster/sw/runtime/ - -L/opt/snitch_cluster/target/snitch_cluster/sw/runtime/rtl - -L/opt/snitch_cluster/target/snitch_cluster/sw/runtime/rtl/build diff --git a/docker/Dockerfile b/docker/Dockerfile index 5b94d005..e1fc0f33 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,59 +1,17 @@ -#------------------------------------------------------------------------------- -# Stage 1: Builder -# Clones the repository and builds the necessary artifacts. -#------------------------------------------------------------------------------- -FROM ghcr.io/pulp-platform/snitch_cluster:main AS builder +FROM ghcr.io/pulp-platform/snitch_cluster-sw:sw-dev-image AS toolchain +ARG VIRTUAL_ENV="/root/.venvs/snitch_cluster" +ARG PYTHON_VERSION=3.11 # Patch .gitmodules to replace SSH URLs with HTTPS # Clone the snitch_cluster repository into /repo # If the repo URL or commit hash doesn't change, this layer remains cached. RUN git config --global url."https://github".insteadOf "git://github" \ && git config --global url."https://github.com/".insteadOf "git@github.com:" \ - && git clone --recursive https://github.com/pulp-platform/snitch_cluster /repo \ - && cd /repo \ + && git clone --recursive https://github.com/pulp-platform/snitch_cluster /opt/snitch_cluster \ + && cd /opt/snitch_cluster \ && git reset --hard 7f430f2 \ - # Build the verilator model and software in the same layer - && make -C target/snitch_cluster verilator \ - && make -C target/snitch_cluster DEBUG=ON sw \ - && cd /repo/target/snitch_cluster/work-vlt/riscv-isa-sim \ - && ./configure --prefix=/opt/snitch-spike \ - && make install - -WORKDIR /src - -RUN curl -L -o riscv32-snitch-llvm-ubuntu2204-15.0.0-snitch-0.2.0.tar.gz https://github.com/pulp-platform/llvm-project/releases/download/15.0.0-snitch-0.2.0/riscv32-snitch-llvm-ubuntu2204-15.0.0-snitch-0.2.0.tar.gz \ - && tar -xzf riscv32-snitch-llvm-ubuntu2204-15.0.0-snitch-0.2.0.tar.gz -C /src - -#------------------------------------------------------------------------------- -# Stage 2: Final Toolchain Image -# Creates the final, lean image by copying artifacts from the builder -# and installing only necessary runtime dependencies. -#------------------------------------------------------------------------------- -FROM ubuntu:22.04 AS toolchain - -# Set this environment variable early. -ENV DEBIAN_FRONTEND=noninteractive - -# Combine related COPY commands to reduce image layers. -# Copying parent directories is more efficient than many individual sub-directories. - -COPY --from=builder /repo/target/snitch_cluster/bin/snitch_cluster_bin.vlt /opt/snitch-rtl/bin/snitch_cluster.vlt - -COPY --from=builder /opt/snitch-spike /opt/snitch-spike - -COPY --from=builder /src/riscv32-snitch-llvm-ubuntu2204-15.0.0-snitch-0.2.0 /opt/snitch-llvm - -# Copy the entire 'sw' directory at once instead of its individual sub-directories. -COPY --from=builder /repo/sw /opt/snitch_cluster/sw - -# Copy the entire runtime directory at once. -COPY --from=builder /repo/target/snitch_cluster/sw/runtime /opt/snitch_cluster/target/snitch_cluster/sw/runtime - -# Copy Snitch Python package files. -COPY --from=builder /repo/pyproject.toml /opt/snitch_cluster/ -COPY --from=builder /repo/util /opt/snitch_cluster/util -COPY --from=builder /repo/nonfree/util /opt/snitch_cluster/nonfree/util -COPY --from=builder /repo/target/snitch_cluster/util /opt/snitch_cluster/target/snitch_cluster/util + && cd target/snitch_cluster \ + && make DEBUG=ON sn-runtime -j # === Optimized Package Installation === # Split apt commands into logical, cacheable layers. @@ -74,7 +32,8 @@ RUN wget -O /etc/apt/keyrings/llvm-snapshot.gpg.key https://apt.llvm.org/llvm-sn # 3. Update package lists and install final packages. # This is the layer that will most likely change. # Using --no-install-recommends reduces bloat. -RUN apt-get -y update \ +RUN apt-add-repository ppa:deadsnakes/ppa \ + && apt-get -y update \ && apt-get -y install --no-install-recommends \ # python runtime dependencies zlib1g \ @@ -92,16 +51,10 @@ RUN apt-get -y update \ # misc make \ git \ + python${PYTHON_VERSION}-dev \ # 4. Clean up in the SAME RUN command to reduce final image size. && rm -rf /var/lib/apt/lists/* /var/tmp/* /tmp/* -# Install uv and Python in a single layer, and ensure uv is in PATH -RUN wget -qO- https://astral.sh/uv/install.sh | sh \ - && ln -s /root/.local/bin/uv /usr/local/bin/uv \ - && /root/.local/bin/uv python install - -COPY docker/entrypoint.sh /entrypoint.sh -# Ensure the entrypoint is executable -RUN chmod +x /entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] +COPY requirements.txt ./requirements.txt +COPY xdsl ./xdsl +RUN . ${VIRTUAL_ENV}/bin/activate && pip install -r ./requirements.txt diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh deleted file mode 100755 index a90b7f6d..00000000 --- a/docker/entrypoint.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -SETUP=/src/docker/venv.sh - -if [ -f "${SETUP}" ]; then - source "${SETUP}" -else - >&2 echo "WARNING: can't find source repo mounted at /src, brace for bad things" -fi - -exec "$@" diff --git a/docker/venv.sh b/docker/venv.sh deleted file mode 100755 index 32f8777d..00000000 --- a/docker/venv.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -VENV_DIR=/src/.venv-docker -FORCE_VENV=0 - -if [[ -d /src/xdsl ]]; then - pushd /src/xdsl > /dev/null - if [[ 1 -eq ${FORCE_VENV} ]] || [[ ! -d ${VENV_DIR} ]] || [[ ! -f ${VENV_DIR}/bin/activate ]]; then - uv venv -p 3.11 ${VENV_DIR} - source ${VENV_DIR}/bin/activate - uv pip install -r /src/requirements.txt - uv pip install /opt/snitch_cluster/ - else - source ${VENV_DIR}/bin/activate - fi - popd -fi - diff --git a/requirements.txt b/requirements.txt index e0e0baab..9648dae9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,4 @@ pandas seaborn numpy snakemake==8.14.0 --e /src/xdsl +-e xdsl From bf8094d6f52ca0c0f71bd8f0e3522fd89d4d1e59 Mon Sep 17 00:00:00 2001 From: Luca Colagrande Date: Tue, 16 Sep 2025 15:13:45 +0200 Subject: [PATCH 3/7] Fix Snitch container version --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index e1fc0f33..1456420e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/pulp-platform/snitch_cluster-sw:sw-dev-image AS toolchain +FROM ghcr.io/pulp-platform/snitch_cluster-sw@sha256:290416751224ccb0a5bf5a583dbad6bc60c985f8fd4a2577775a4af43f2abf6a AS toolchain ARG VIRTUAL_ENV="/root/.venvs/snitch_cluster" ARG PYTHON_VERSION=3.11 From 24bf085fbc41633d0740e9b8f95a997a9ca8195e Mon Sep 17 00:00:00 2001 From: Luca Colagrande Date: Tue, 16 Sep 2025 15:14:34 +0200 Subject: [PATCH 4/7] Bump Snitch version to latest --- .github/workflows/ci-pivoted.yml | 6 ----- default.yaml | 42 +++++++++++--------------------- docker/Dockerfile | 3 +-- 3 files changed, 15 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci-pivoted.yml b/.github/workflows/ci-pivoted.yml index 322c298f..e852ab62 100644 --- a/.github/workflows/ci-pivoted.yml +++ b/.github/workflows/ci-pivoted.yml @@ -16,14 +16,8 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install dependencies in venv - run: | - uv venv -p 3.11 - uv pip install -r /src/requirements.txt - uv pip install /opt/snitch_cluster/ - name: Clean and make pivoted run: | - . .venv/bin/activate cp results/pivoted.csv results/pivoted_old.csv.txt make clean make diff --git a/default.yaml b/default.yaml index f4c49d33..797f50a4 100644 --- a/default.yaml +++ b/default.yaml @@ -21,18 +21,11 @@ asflags: - -fno-common - -O3 - -D__DEFINED_uint64_t - - -I/opt/snitch_cluster/target/snitch_cluster/sw/runtime/rtl/src - - -I/opt/snitch_cluster/target/snitch_cluster/sw/runtime/common - - -I/opt/snitch_cluster/sw/snRuntime/api - - -I/opt/snitch_cluster/sw/snRuntime/src - - -I/opt/snitch_cluster/sw/snRuntime/src/omp/ - - -I/opt/snitch_cluster/sw/snRuntime/api/omp/ - - -I/opt/snitch_cluster/sw/math/arch/riscv64/bits/ - - -I/opt/snitch_cluster/sw/math/arch/generic - - -I/opt/snitch_cluster/sw/math/src/include - - -I/opt/snitch_cluster/sw/math/src/internal - - -I/opt/snitch_cluster/sw/math/include/bits - - -I/opt/snitch_cluster/sw/math/include + - -I/opt/snitch_cluster/sw/runtime/src + - -I/opt/snitch_cluster/sw/runtime/impl + - -I/opt/snitch_cluster/sw/runtime/api + - -I/opt/snitch_cluster/sw/runtime/src/omp/ + - -I/opt/snitch_cluster/sw/runtime/api/omp/ cflags: - -Wno-unused-command-line-argument - -menable-experimental-extensions @@ -45,27 +38,20 @@ cflags: - -fno-common - -O3 - -D__DEFINED_uint64_t - - -I/opt/snitch_cluster/target/snitch_cluster/sw/runtime/rtl/src - - -I/opt/snitch_cluster/target/snitch_cluster/sw/runtime/common - - -I/opt/snitch_cluster/sw/snRuntime/api - - -I/opt/snitch_cluster/sw/snRuntime/src - - -I/opt/snitch_cluster/sw/snRuntime/src/omp/ - - -I/opt/snitch_cluster/sw/snRuntime/api/omp/ - - -I/opt/snitch_cluster/sw/math/arch/riscv64/bits/ - - -I/opt/snitch_cluster/sw/math/arch/generic - - -I/opt/snitch_cluster/sw/math/src/include - - -I/opt/snitch_cluster/sw/math/src/internal - - -I/opt/snitch_cluster/sw/math/include/bits - - -I/opt/snitch_cluster/sw/math/include + - -I/opt/snitch_cluster/sw/runtime/src + - -I/opt/snitch_cluster/sw/runtime/impl + - -I/opt/snitch_cluster/sw/runtime/api + - -I/opt/snitch_cluster/sw/runtime/src/omp/ + - -I/opt/snitch_cluster/sw/runtime/api/omp/ ldflags: - -fuse-ld=/tools/riscv-llvm/bin/ld.lld - -nostartfiles - -nostdlib - -L/tools/riscv-llvm/lib/clang/15.0.0/lib/ - - -L/opt/snitch_cluster/target/snitch_cluster/sw/runtime/ - - -L/opt/snitch_cluster/target/snitch_cluster/sw/runtime/rtl - - -L/opt/snitch_cluster/target/snitch_cluster/sw/runtime/rtl/build - - -T/opt/snitch_cluster/sw/snRuntime/base.ld + - -L/opt/snitch_cluster/sw/runtime/ + - -L/opt/snitch_cluster/sw/runtime/impl + - -L/opt/snitch_cluster/sw/runtime/build + - -T/opt/snitch_cluster/sw/runtime/base.ld - -lc - -lsnRuntime - -lclang_rt.builtins-riscv32 diff --git a/docker/Dockerfile b/docker/Dockerfile index 1456420e..cbe2e4ba 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -9,8 +9,7 @@ RUN git config --global url."https://github".insteadOf "git://github" \ && git config --global url."https://github.com/".insteadOf "git@github.com:" \ && git clone --recursive https://github.com/pulp-platform/snitch_cluster /opt/snitch_cluster \ && cd /opt/snitch_cluster \ - && git reset --hard 7f430f2 \ - && cd target/snitch_cluster \ + && git reset --hard 742fbe3259125fc182fba11f756fd0af4d87404f \ && make DEBUG=ON sn-runtime -j # === Optimized Package Installation === From 70696a9f518cbc10597961ec0aff3b24b09c6272 Mon Sep 17 00:00:00 2001 From: Luca Colagrande Date: Tue, 16 Sep 2025 19:32:39 +0200 Subject: [PATCH 5/7] Upstream python-dev installation and reinstall uv --- docker/Dockerfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index cbe2e4ba..be62720f 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,6 +1,4 @@ -FROM ghcr.io/pulp-platform/snitch_cluster-sw@sha256:290416751224ccb0a5bf5a583dbad6bc60c985f8fd4a2577775a4af43f2abf6a AS toolchain -ARG VIRTUAL_ENV="/root/.venvs/snitch_cluster" -ARG PYTHON_VERSION=3.11 +FROM ghcr.io/pulp-platform/snitch_cluster-sw@sha256:a09680ebe74b3c8a704af3cc31322dae7359998a570665ae8da413d9efdec42c AS toolchain # Patch .gitmodules to replace SSH URLs with HTTPS # Clone the snitch_cluster repository into /repo @@ -31,8 +29,7 @@ RUN wget -O /etc/apt/keyrings/llvm-snapshot.gpg.key https://apt.llvm.org/llvm-sn # 3. Update package lists and install final packages. # This is the layer that will most likely change. # Using --no-install-recommends reduces bloat. -RUN apt-add-repository ppa:deadsnakes/ppa \ - && apt-get -y update \ +RUN apt-get -y update \ && apt-get -y install --no-install-recommends \ # python runtime dependencies zlib1g \ @@ -50,10 +47,13 @@ RUN apt-add-repository ppa:deadsnakes/ppa \ # misc make \ git \ - python${PYTHON_VERSION}-dev \ # 4. Clean up in the SAME RUN command to reduce final image size. && rm -rf /var/lib/apt/lists/* /var/tmp/* /tmp/* +# Install uv and ensure uv is in PATH +RUN wget -qO- https://astral.sh/uv/install.sh | sh \ + && ln -s /root/.local/bin/uv /usr/local/bin/uv + COPY requirements.txt ./requirements.txt COPY xdsl ./xdsl -RUN . ${VIRTUAL_ENV}/bin/activate && pip install -r ./requirements.txt +RUN uv pip install -r ./requirements.txt From da28856f35c92fc1fe807c5eaf502f267d10dd2e Mon Sep 17 00:00:00 2001 From: Luca Colagrande Date: Wed, 17 Sep 2025 14:42:56 +0200 Subject: [PATCH 6/7] Remove COPY of xdsl --- docker/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index be62720f..79398e5d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -55,5 +55,4 @@ RUN wget -qO- https://astral.sh/uv/install.sh | sh \ && ln -s /root/.local/bin/uv /usr/local/bin/uv COPY requirements.txt ./requirements.txt -COPY xdsl ./xdsl RUN uv pip install -r ./requirements.txt From baaadc1b3d5492f816ee9386de31dce5c23a2161 Mon Sep 17 00:00:00 2001 From: Luca Colagrande Date: Wed, 17 Sep 2025 17:26:26 +0200 Subject: [PATCH 7/7] Bump SHAs after Snitch merge --- docker/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 79398e5d..50406f1a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/pulp-platform/snitch_cluster-sw@sha256:a09680ebe74b3c8a704af3cc31322dae7359998a570665ae8da413d9efdec42c AS toolchain +FROM ghcr.io/pulp-platform/snitch_cluster-sw@sha256:bfe84cbb917169c39ae6a26c811c19665d3bc04ebf926155bc442bcd5cba59db AS toolchain # Patch .gitmodules to replace SSH URLs with HTTPS # Clone the snitch_cluster repository into /repo @@ -7,7 +7,7 @@ RUN git config --global url."https://github".insteadOf "git://github" \ && git config --global url."https://github.com/".insteadOf "git@github.com:" \ && git clone --recursive https://github.com/pulp-platform/snitch_cluster /opt/snitch_cluster \ && cd /opt/snitch_cluster \ - && git reset --hard 742fbe3259125fc182fba11f756fd0af4d87404f \ + && git reset --hard 7c343831fc09819511a4eea54a725a02c4da765f \ && make DEBUG=ON sn-runtime -j # === Optimized Package Installation ===