Skip to content

Commit

Permalink
add snitch support
Browse files Browse the repository at this point in the history
  • Loading branch information
tahaelbayad committed Nov 14, 2024
1 parent 4097c33 commit 63a1916
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 1 deletion.
3 changes: 3 additions & 0 deletions DeeployTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ elseif(DEEPLOY_ARCH STREQUAL PULP)
set(USE_NEUREKA OFF)
add_subdirectory(Platforms/PULPOpen)
endif()
elseif(DEEPLOY_ARCH STREQUAL SNITCH)
add_subdirectory(Platforms/Snitch)

endif()
13 changes: 13 additions & 0 deletions DeeployTest/Platforms/Snitch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set(ProjectId ${TESTNAME})

file(GLOB_RECURSE SOURCES
main.c
)

add_deeploy_executable(${ProjectId} EXCLUDE_FROM_ALL ${SOURCES})

target_link_libraries(${ProjectId} PRIVATE network deeploylib)
target_compile_options(${ProjectId} INTERFACE network)
add_banshee_simulation(${ProjectId})
add_snitch_cluster_vsim_simulation(${ProjectId})
add_snitch_cluster_vsim_gui_simulation(${ProjectId})
136 changes: 136 additions & 0 deletions DeeployTest/Platforms/Snitch/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* ----------------------------------------------------------------------
*
* File: deeploytest.c
*
* Last edited: 23.04.2024
*
* Copyright (C) 2024, ETH Zurich and University of Bologna.
*
* Author: Philip Wiese ([email protected]), ETH Zurich
*
* ----------------------------------------------------------------------
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "CycleCounter.h"
#include "Network.h"
#include "snrt.h"
#include "testinputs.h"
#include "testoutputs.h"

int main(void) {

uint32_t core_id = snrt_global_core_idx();
uint32_t compute_core_id = snrt_global_compute_core_idx();

#ifdef BANSHEE_SIMULATION
uint32_t const num_compute_cores = (NUM_CORES - 1);
#else
uint32_t const num_compute_cores = snrt_global_compute_core_num();
#endif

if (snrt_is_dm_core()) {
#ifndef CI
printf("Network running on %d of %d compute cores (+%d DM cores) on %d clusters\r\n", num_compute_cores,
snrt_global_compute_core_num(), snrt_cluster_num() * snrt_cluster_dm_core_num(), snrt_cluster_num());
#endif

printf("Initializing...\r\n");

InitNetwork(core_id, 1);

#ifndef CI
for (uint32_t buf = 0; buf < DeeployNetwork_num_inputs; buf++) {
printf("testInputVector%d @ %p\r\n", buf, testInputVector[buf]);
printf("DeeployNetwork_input_%d @ %p and %u elements\r\n", buf, DeeployNetwork_inputs[buf],
DeeployNetwork_inputs_bytes[buf]);
}
for (uint32_t buf = 0; buf < DeeployNetwork_num_outputs; buf++) {
printf("testInputVector%d @ %p\r\n", buf, testOutputVector[buf]);
printf("DeeployNetwork_output_%d @ %p and %u elements\r\n", buf, DeeployNetwork_outputs[buf],
DeeployNetwork_outputs_bytes[buf]);
}

printf("Initialized\r\n");
#endif

printf("Copy inputs...\r\n");

// WIESEP: Copy inputs to allocated memory
for (uint32_t buf = 0; buf < DeeployNetwork_num_inputs; buf++) {
snrt_dma_start_1d(DeeployNetwork_inputs[buf], testInputVector[buf], DeeployNetwork_inputs_bytes[buf]);
}
snrt_dma_wait_all();

#ifndef CI
printf("Input copied\r\n");
#endif
}

snrt_cluster_hw_barrier();

if (snrt_is_dm_core()) {
printf("Running network...\r\n");
}

// ResetTimer();
// StartTimer();
if (snrt_is_compute_core()) {
RunNetwork(compute_core_id, num_compute_cores);
}
// StopTimer();

snrt_cluster_hw_barrier();

#ifndef CI
if (snrt_is_dm_core()) {
printf("Network done\r\n");
}
#endif

if (snrt_is_dm_core()) {
#ifndef CI
printf("Output:\r\n");
#endif
int32_t tot_err = 0;
uint32_t tot = 0;
int32_t diff;
int32_t expected, actual;
for (uint32_t buf = 0; buf < DeeployNetwork_num_outputs; buf++) {

tot += DeeployNetwork_outputs_bytes[buf];
for (uint32_t i = 0; i < DeeployNetwork_outputs_bytes[buf]; i++) {
expected = ((char *)testOutputVector[buf])[i];
actual = ((char *)DeeployNetwork_outputs[buf])[i];
diff = expected - actual;

if (diff) {
tot_err += 1;
#ifndef CI
printf("Expected: %4d ", expected);
printf("Actual: %4d ", actual);
printf("Diff: %4d at Index %12u in Output %u\r\n", diff, i, buf);
#endif
}
}
}
printf("Runtime: %u cycles\r\n", getCycles());
printf("Errors: %u out of %u \r\n", tot_err, tot);
}

snrt_cluster_hw_barrier();
return 0;
}
53 changes: 53 additions & 0 deletions DeeployTest/testRunner_snitch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# ----------------------------------------------------------------------
#
# File: testRunner_snitch.py
#
# Last edited: 23.04.2024
#
# Copyright (C) 2024, ETH Zurich and University of Bologna.
#
# Authors:
# - Philip Wiese ([email protected]), ETH Zurich
#
# ----------------------------------------------------------------------
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the License); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from testUtils.testRunner import TestRunner, TestRunnerArgumentParser

if __name__ == "__main__":

parser = TestRunnerArgumentParser(
tiling_arguments = False, description = "Deeploy Code Generation Utility for the Snitch Platform (no Tiling).")

parser.add_argument('--cores',
metavar = '<cores>',
dest = 'cores',
type = int,
default = 9,
help = 'Set number of cluster cores')
parser.set_defaults(toolchain_install_dir = "/usr/pack/riscv-1.0-kgf/pulp-llvm-0.12.0")
parser.add_argument('--simulator',
metavar = "<simulator>",
dest = "simulator",
type = str,
choices = ["banshee", "vsim", "vsim.gui"],
default = "banshee",
help = "Select the simulator to use")
args = parser.parse_args()

testRunner = TestRunner(platform = "Snitch", simulator = args.simulator, tiling = False, argument_parser = parser)

testRunner.cmake_args += f" -D NUM_CORES={args.cores}"
testRunner.run()
27 changes: 26 additions & 1 deletion DeeployTest/testUtils/platformMapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@
from Deeploy.Targets.PULPOpen.Deployer import PULPDeployer
from Deeploy.Targets.PULPOpen.Platform import MemoryPULPPlatform, MemoryPULPPlatformWrapper, PULPOptimizer, PULPPlatform

from Deeploy.Targets.Snitch.Deployer import SnitchDeployer
from Deeploy.Targets.Snitch.Platform import SnitchOptimizer, SnitchPlatform

_SIGNPROP_PLATFORMS = ["Apollo3", "Apollo4", "QEMU-ARM", "Generic", "MemPool"]
_NONSIGNPROP_PLATFORMS = ["Siracusa", "Siracusa_w_neureka", "PULPOpen"]
_NONSIGNPROP_PLATFORMS = ["Siracusa", "Siracusa_w_neureka", "PULPOpen", "Snitch"]
_PLATFORMS = _SIGNPROP_PLATFORMS + _NONSIGNPROP_PLATFORMS


Expand Down Expand Up @@ -76,6 +79,10 @@ def mapPlatform(platformName: str) -> Tuple[DeploymentPlatform, bool]:
elif platformName == "Siracusa_w_neureka":
Platform = NeurekaPlatform()

elif platformName == "Snitch":
Platform = SnitchPlatform()


else:
raise RuntimeError(f"Deployment platform {platformName} is not implemented")

Expand Down Expand Up @@ -204,6 +211,24 @@ def mapDeployer(platform: DeploymentPlatform,
default_channels_first = default_channels_first,
deeployStateDir = deeployStateDir)


elif isinstance(platform, (SnitchPlatform)):
if loweringOptimizer is None:
loweringOptimizer = SnitchOptimizer

if default_channels_first is None:
default_channels_first = False

deployer = SnitchDeployer(graph,
platform,
inputTypes,
loweringOptimizer,
scheduler,
name = name,
default_channels_first = default_channels_first,
deeployStateDir = deeployStateDir)


else:
raise RuntimeError(f"Deployer for platform {platform} is not implemented")

Expand Down

0 comments on commit 63a1916

Please sign in to comment.