Skip to content

Commit f69868b

Browse files
authored
OPEN: Snitch support integration (#14)
- cMake Flow for the Snitch Cluster - Added `snitch_cluster` to Makefile - New Snitch platform with testing application - Testrunner for tiled and untiled execution (`testRunner_snitch.py`, `testRunner_tiled_snitch.py`) - Minimal library with CycleCounter and utility function - Update the Banshee's commit to include a recent PR.
1 parent d2a209b commit f69868b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3064
-7
lines changed

.github/workflows/CI.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ jobs:
8989
simpleRegression
9090
WaveFormer
9191
92+
### Snitch Tests ###
93+
snitch-kernels:
94+
uses: ./.github/workflows/TestRunnerSnitch.yml
95+
with:
96+
test-names: |
97+
testMatMul
9298
9399
### Mempool Tests ###
94100
mempool-kernels:
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: TestRunnerSnitch
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
test-names:
7+
required: true
8+
type: string
9+
10+
jobs:
11+
test-runner-snitch:
12+
runs-on: ubuntu-22.04
13+
container:
14+
image: ghcr.io/pulp-platform/deeploy:main
15+
steps:
16+
- name: Checkout Repo
17+
uses: actions/checkout@v4
18+
with:
19+
submodules: recursive
20+
- name: Build Deeploy
21+
run: pip install -e .
22+
- name: Run Test
23+
run: |
24+
testNames="${{ inputs.test-names }}"
25+
cd DeeployTest
26+
echo "$testNames" | while IFS= read -r testName; do
27+
if [[ -n "$testName" ]]; then
28+
echo "Running test: $testName"
29+
python testRunner_snitch.py -t Tests/$testName --toolchain_install_dir /app/install/riscv-llvm/
30+
fi
31+
done
32+
shell: bash

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,15 @@
2525
- Add a FloatAdder test to the CI for Siracusa and Generic platforms
2626
- Extend `testType.py` with float tests
2727
- LIMITATION: Current LLVM compiler does not support bfp16 and fp16, these types are commented in the library header
28+
29+
## Snitch Cluster Support
30+
31+
### Added
32+
- cMake Flow for the Snitch Cluster
33+
- Added `snitch_cluster` to Makefile
34+
- New Snitch platform with testing application
35+
- Testrunner for tiled and untiled execution (`testRunner_snitch.py`, `testRunner_tiled_snitch.py`)
36+
- Minimal library with CycleCounter and utility function
37+
38+
### Changed
39+
- Update the Banshee's commit to include a recent PR.

CMakeLists.txt

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ if(TOOLCHAIN STREQUAL GCC)
1515
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
1616
endif()
1717

18-
set(platform MemPool CACHE STRING "Platform (MemPool, QEMU, Siracusa, Siracusa_w_neureka, PULP-Open, Generic)")
19-
set_property(CACHE platform PROPERTY STRINGS MemPool QEMU Siracusa Siracusa_w_neureka PULP-Open Generic)
18+
set(platform MemPool CACHE STRING "Platform (MemPool, QEMU, Siracusa, Siracusa_w_neureka, PULP-Open, Generic, Snitch)")
19+
set_property(CACHE platform PROPERTY STRINGS MemPool QEMU Siracusa Siracusa_w_neureka PULP-Open Generic Snitch)
2020

2121
if(platform STREQUAL MemPool)
2222
message(STATUS "Building for platform 'MemPool'")
@@ -30,6 +30,8 @@ elseif(platform STREQUAL PULPOpen)
3030
message(STATUS "Building for platform 'PULP-Open'")
3131
elseif(platform STREQUAL Generic)
3232
message(STATUS "Building for platform 'Generic'")
33+
elseif(platform STREQUAL Snitch)
34+
message(STATUS "Building for platform 'Snitch'")
3335
else()
3436
message(FATAL_ERROR "Invalid platform '${platform}' specified!")
3537
endif()
@@ -181,4 +183,33 @@ if(platform STREQUAL Siracusa OR platform STREQUAL Siracusa_w_neureka OR platfor
181183

182184
endif()
183185

186+
if(platform STREQUAL Snitch)
187+
188+
if(TOOLCHAIN STREQUAL LLVM)
189+
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/cmake/snitch/toolchain_llvm.cmake)
190+
else()
191+
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/cmake/snitch/toolchain_gcc.cmake)
192+
endif()
193+
194+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/snitch/snitch.cmake)
195+
196+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/snitch/snitch_cluster/snitch_cluster.cmake)
197+
198+
project(deeploy LANGUAGES C ASM)
199+
200+
message(STATUS "============================= ${platform} Configuration ============================")
201+
message(STATUS "[cMake ] Number of total cores = " ${NUM_CORES})
202+
message(STATUS "================================================================================")
203+
message(STATUS "")
204+
205+
add_subdirectory(TargetLibraries/Generic)
206+
add_subdirectory(TargetLibraries/Snitch)
207+
target_include_directories(deeploysnitch PUBLIC TargetLibraries/Generic/inc)
208+
209+
add_subdirectory(DeeployTest)
210+
target_link_libraries(deeploylib INTERFACE deeploybasic deeploysnitch)
211+
212+
endif()
213+
214+
184215
print_simulation_config()

Container/Dockerfile

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ FROM ubuntu:22.04 AS builder
33

44
ARG PYTHON_VERSION=3.8.0
55
ARG DEBIAN_FRONTEND=noninteractive
6+
7+
ARG UBUNTU_VERSION=22.04
8+
ARG BENDER_VERSION=0.28.1
9+
ARG SNITCH_LLVM_VERSION=latest
10+
611
ENV TZ=Etc/UTC
712

813
WORKDIR /app
@@ -74,6 +79,26 @@ RUN make qemu
7479
RUN make mempool
7580
RUN make banshee
7681

82+
# Dependencies needed for compiling Snitch
83+
## Bender's installaton
84+
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 && \
85+
tar xzf bender-${BENDER_VERSION}-x86_64-linux-gnu-ubuntu${UBUNTU_VERSION}.tar.gz && cp /app/bender /bin
86+
ENV PATH=/app/bender:$PATH
87+
88+
## Precompiled llvm - Taken form https://github.com/pulp-platform/snitch_cluster (from this file: util/container/Dockerfile)
89+
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/'` && \
90+
echo "SNITCH_LLVM_VERSION=${SNITCH_LLVM_VERSION} LLVM_TAR=${LLVM_TAR} latest_tag=${latest_tag}" && \
91+
test "${SNITCH_LLVM_VERSION}" = "latest" && SNITCH_LLVM_VERSION=${latest_tag} || : ; \
92+
LLVM_TAR=riscv32-pulp-llvm-ubuntu2004-$(echo $SNITCH_LLVM_VERSION | cut -d '-' -f3-).tar.gz && \
93+
mkdir -p riscv-llvm && \
94+
echo "SNITCH_LLVM_VERSION=${SNITCH_LLVM_VERSION} LLVM_TAR=${LLVM_TAR} latest_tag=${latest_tag}" && \
95+
wget -qO- https://github.com/pulp-platform/llvm-project/releases/download/${SNITCH_LLVM_VERSION}/${LLVM_TAR} | \
96+
tar xvz --strip-components=1 -C riscv-llvm
97+
98+
99+
## compile snitch
100+
RUN PATH=/app/riscv-llvm/bin:${PATH} make snitch_runtime && rm -rf /app/snitch_cluster
101+
77102
# Remove toolchain to make the container lighter
78103
RUN rm -rf toolchain
79104

@@ -88,6 +113,7 @@ ENV TZ=Etc/UTC
88113
ENV CMAKE=/usr/bin/cmake
89114
ENV PULP_SDK_HOME=/app/install/pulp-sdk
90115
ENV LLVM_INSTALL_DIR=/app/install/llvm
116+
ENV SNITCH_HOME=/app/install/snitch_cluster
91117
ENV MEMPOOL_HOME=/app/install/mempool
92118
ENV PATH=/app/install/qemu/bin:/app/install/banshee:$PATH
93119
ENV PATH="/root/.cargo/bin:${PATH}"
@@ -114,6 +140,8 @@ pip install toml-to-requirements && \
114140
toml-to-req --toml-file pyproject.toml && \
115141
pip install -r requirements.txt
116142

143+
117144
# Copy pre-built toolchains and emulators
118145
COPY --from=builder /app/install ./install
119-
COPY --from=builder /root/.cargo/bin/banshee /root/.cargo/bin/banshee
146+
COPY --from=builder /root/.cargo/bin/banshee /root/.cargo/bin/banshee
147+
COPY --from=builder /app/riscv-llvm ./install/riscv-llvm

Deeploy/Targets/Snitch/Deployer.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# ----------------------------------------------------------------------
2+
#
3+
# File: SnitchDeployer.py
4+
#
5+
# Last edited: 23.04.2024
6+
#
7+
# Copyright (C) 2024, ETH Zurich and University of Bologna.
8+
#
9+
# Authors:
10+
# - Philip Wiese (wiesep@iis.ee.ethz.ch), ETH Zurich
11+
#
12+
# ----------------------------------------------------------------------
13+
# SPDX-License-Identifier: Apache-2.0
14+
#
15+
# Licensed under the Apache License, Version 2.0 (the License); you may
16+
# not use this file except in compliance with the License.
17+
# You may obtain a copy of the License at
18+
#
19+
# www.apache.org/licenses/LICENSE-2.0
20+
#
21+
# Unless required by applicable law or agreed to in writing, software
22+
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
23+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24+
# See the License for the specific language governing permissions and
25+
# limitations under the License.
26+
27+
from typing import Callable, Dict, Type
28+
29+
import onnx_graphsurgeon as gs
30+
31+
from Deeploy.AbstractDataTypes import Pointer
32+
from Deeploy.CommonExtensions.NetworkDeployers.SignPropDeployer import SignPropDeployer
33+
from Deeploy.CommonExtensions.OptimizationPasses.TopologyOptimizationPasses.LoweringOptimizationPasses import \
34+
NCHWtoNHWCPass, RemoveGlobalOutputReshapePass, TransposeMatmulInputsPass
35+
from Deeploy.DeeployTypes import DeploymentPlatform, TopologyOptimizer
36+
from Deeploy.Targets.Generic.TopologyOptimizationPasses.Passes import ReshapeConstOptPass, TransposeConstOptPass, \
37+
TransposeMergePass, TransposeSplitPass
38+
39+
40+
class SnitchDeployer(SignPropDeployer):
41+
42+
def __init__(self,
43+
graph: gs.Graph,
44+
deploymentPlatform: DeploymentPlatform,
45+
inputTypes: Dict[str, Type[Pointer]],
46+
loweringOptimizer: TopologyOptimizer,
47+
scheduler: Callable = lambda x: x,
48+
name: str = 'DeeployNetwork',
49+
default_channels_first = False,
50+
deeployStateDir: str = "DeeployStateDir",
51+
inputOffsets = {}):
52+
super().__init__(graph,
53+
deploymentPlatform,
54+
inputTypes,
55+
loweringOptimizer,
56+
scheduler,
57+
name,
58+
default_channels_first = default_channels_first,
59+
deeployStateDir = deeployStateDir,
60+
inputOffsets = inputOffsets)
61+
62+
self.loweringOptimizer.passes += [
63+
TransposeMatmulInputsPass(),
64+
NCHWtoNHWCPass(self.default_channels_first),
65+
TransposeSplitPass(),
66+
TransposeMergePass(),
67+
TransposeConstOptPass(),
68+
ReshapeConstOptPass(),
69+
RemoveGlobalOutputReshapePass(),
70+
]

0 commit comments

Comments
 (0)