Skip to content

Commit

Permalink
sw: Add cluster-to-cluster multicast app
Browse files Browse the repository at this point in the history
  • Loading branch information
colluca committed Dec 26, 2023
1 parent d66fdf2 commit d322a4d
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ jobs:
submodules: 'recursive'
- name: Generate single-cluster Occamy RTL sources
run: |
make -C target/sim CFG_OVERRIDE=cfg/single-cluster.hjson rtl
make -C target/sim CFG_OVERRIDE=cfg/U-Q1C1.hjson rtl
8 changes: 4 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ docs:
occamy-single-cluster-vsim:
script:
- cd target/sim
- make CFG_OVERRIDE=cfg/single-cluster.hjson rtl
- make CFG_OVERRIDE=cfg/U-Q1C1.hjson rtl
- make sw
- make bin/occamy_top.vsim
- ./run.py sw/run-single-cluster.yaml --simulator vsim
Expand All @@ -61,7 +61,7 @@ occamy-single-cluster-vsim:
occamy-full-vsim:
script:
- cd target/sim
- make CFG_OVERRIDE=cfg/full.hjson rtl
- make CFG_OVERRIDE=cfg/U-Q6C4.hjson rtl
- make LENGTH=384 sw
- make bin/occamy_top.vsim
- ./run.py sw/run-full-occamy.yaml --simulator vsim
Expand All @@ -77,7 +77,7 @@ occamy-mcast-vsim:
DATA_CFG: "$(PWD)/sw/device/apps/blas/gemm/params.hjson"
script:
- cd target/sim
- make CFG_OVERRIDE=cfg/M-Q8C4.hjson rtl
- make CFG_OVERRIDE=cfg/M-Q4C4.hjson rtl
- make LENGTH=1024 sw
- make bin/occamy_top.vsim
- ./run.py sw/run-full-occamy.yaml -j
- ./run.py sw/run-mcast-occamy.yaml -j
3 changes: 2 additions & 1 deletion target/sim/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ CVA6_TRACE = trace_hart_0.log
# to be rebuilt. This file is used to express this condition as a
# prerequisite for other rules.
CFG = cfg/lru.hjson
DEFAULT_CFG = cfg/U-Q6C4.hjson

#####################
# Simulator options #
Expand Down Expand Up @@ -147,7 +148,7 @@ VLT_COBJ += $(VLT_BUILDDIR)/vlt/verilated_vcd_c.o
$(CFG): FORCE
@# If the LRU config file doesn't exist, we use the default config.
@if [ ! -e $@ ] ; then \
DEFAULT_CFG="cfg/full.hjson"; \
DEFAULT_CFG=$(DEFAULT_CFG); \
echo "Using default config file: $$DEFAULT_CFG"; \
cp $$DEFAULT_CFG $@; \
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
}
narrow_xbar_slv_id_width: 4,
narrow_xbar_user_width: 5, // clog2(total number of clusters)
nr_s1_quadrant: 8,
nr_s1_quadrant: 4,
s1_quadrant: {
nr_clusters: 4,
// number of pending transactions on the narrow/wide network
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions target/sim/sw/device/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Add user applications to APPS variable
APPS = blas/axpy
APPS += blas/gemm
APPS += mcast

TARGET ?= all

Expand Down
10 changes: 10 additions & 0 deletions target/sim/sw/device/apps/mcast/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2023 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Luca Colagrande <colluca@iis.ee.ethz.ch>

APP = mcast
SRCS = main.c

include ../common.mk
52 changes: 52 additions & 0 deletions target/sim/sw/device/apps/mcast/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2023 ETH Zurich and University of Bologna.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
//
// Author: Luca Colagrande <colluca@iis.ee.ethz.ch>

#include "snrt.h"

#define LENGTH 32
#define INITIALIZER 0xAAAAAAAA

// Allocate a buffer in main memory which we will use to copy data around
// with the DMA.
uint32_t buffer_src[LENGTH];

int main() {
uint32_t is_first_cluster = snrt_cluster_idx() == 0;

// Allocate destination buffer
uint32_t *buffer_dst = snrt_l1_next();

// First cluster initializes the source buffer in DRAM and multicast-
// copies it to the destination buffer in every cluster's TCDM.
if (snrt_is_dm_core() && is_first_cluster) {
// Initializing the DRAM source buffer using the LSU may cause data
// races with the DMA "later" copying the source buffer to the TCDM
// destinations. We therefore initialize the DRAM source buffer using
// the DMA itself, from a TCDM source buffer initialized with the LSU.
uint32_t *buffer_src_tcdm = buffer_dst + LENGTH;
for (uint32_t i = 0; i < LENGTH; i++) {
buffer_src_tcdm[i] = INITIALIZER;
}
snrt_dma_start_1d(buffer_src, buffer_src_tcdm, sizeof(buffer_src));

// Initiate DMA transfer
dma_broadcast_to_clusters(buffer_dst, buffer_src, sizeof(buffer_src));
}

// All other clusters wait on a global barrier to signal the transfer
// completion.
snrt_global_barrier();

// Every cluster checks that the data in the destination buffer is correct.
if (snrt_is_dm_core()) {
uint32_t n_errs = LENGTH;
for (uint32_t i = 0; i < LENGTH; i++) {
if (buffer_dst[i] == INITIALIZER) n_errs--;
}
return n_errs;
} else
return 0;
}
7 changes: 7 additions & 0 deletions target/sim/sw/device/runtime/src/mcast.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2023 ETH Zurich and University of Bologna.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
//
// Author: Luca Colagrande <colluca@iis.ee.ethz.ch>

extern void dma_broadcast_to_clusters();
12 changes: 12 additions & 0 deletions target/sim/sw/device/runtime/src/mcast.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2023 ETH Zurich and University of Bologna.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
//
// Author: Luca Colagrande <colluca@iis.ee.ethz.ch>

#define BCAST_MASK ((snrt_cluster_num() - 1) << 18)

inline void dma_broadcast_to_clusters(void* dst, void* src, size_t size) {
snrt_dma_start_1d_mcast(dst, src, BCAST_MASK, size);
snrt_dma_wait_all();
}
1 change: 1 addition & 0 deletions target/sim/sw/device/runtime/src/snrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "cluster_interrupts.c"
#include "dma.c"
#include "global_interrupts.c"
#include "mcast.c"
#include "occamy_device.c"
#include "occamy_memory.c"
#include "occamy_start.c"
Expand Down
1 change: 1 addition & 0 deletions target/sim/sw/device/runtime/src/snrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "dma.h"
#include "dump.h"
#include "global_interrupts.h"
#include "mcast.h"
#include "occamy_device.h"
#include "occamy_memory.h"
#include "printf.h"
Expand Down
1 change: 1 addition & 0 deletions target/sim/sw/host/apps/offload/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ APP = offload
SRCS = src/offload.c
DEVICE_APPS = blas/axpy
DEVICE_APPS += blas/gemm
DEVICE_APPS += mcast

# Compiler toolchain
RISCV_CC = riscv64-unknown-elf-gcc
Expand Down
12 changes: 12 additions & 0 deletions target/sim/sw/run-mcast-occamy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2023 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

runs:
- elf: host/apps/offload/build/offload-axpy.elf
cmd: [../../../deps/snitch_cluster/sw/blas/axpy/verify.py, --symbols-bin,
./device/apps/blas/axpy/build/axpy.elf, "${sim_bin}", "${elf}"]
- elf: host/apps/offload/build/offload-gemm.elf
cmd: [../../../deps/snitch_cluster/sw/blas/gemm/verify.py, --symbols-bin,
./device/apps/blas/gemm/build/gemm.elf, "${sim_bin}", "${elf}"]
- elf: host/apps/offload/build/offload-mcast.elf

0 comments on commit d322a4d

Please sign in to comment.