From e5404dca4d61cb75a9e8014350859aa75ce50357 Mon Sep 17 00:00:00 2001 From: Viviane Potocnik Date: Sun, 17 Sep 2023 00:35:39 +0200 Subject: [PATCH] sw: add generic DMA transfer and documentation --- sw/apps/transformer/src/transformer.h | 34 ++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/sw/apps/transformer/src/transformer.h b/sw/apps/transformer/src/transformer.h index 0b25832a82..7301a0d5c1 100644 --- a/sw/apps/transformer/src/transformer.h +++ b/sw/apps/transformer/src/transformer.h @@ -83,6 +83,38 @@ dump_float(ifmap, 6); dump_float(weights, 10); // = 0xa dump_float(value, 12); // = 0xc +/** + * @brief Generic DMA transfer function + * @param dst Pointer to destination + * @param src Pointer to source + * @param size How many bytes to transfer in total + * @param dst_stride Stride of the destination, i.e. how many bytes to jump + * between two consecutive transfers in the same row of + * the destination + * @param src_stride Stride of the source, i.e. how many bytes to jump + * between two consecutive transfers in the same row of + * the source + * @param repetitions How many rows to transfer + */ + +static inline void dma_transfer(void *dst, void *src, uint32_t size, uint32_t dst_stride, + uint32_t src_stride, uint32_t repetitions) { + if (!snrt_is_compute_core()) { + snrt_dma_txid_t txid = + snrt_dma_start_2d( + dst, /* dst */ + src, /* src */ + size, /* size */ + dst_stride, /* dst_stride */ + src_stride, /* src_stride */ + repetitions); /* repetitions */ + + snrt_dma_wait_all(); + } + snrt_cluster_hw_barrier(); +} + + /** * Implementation of the GELU layer */ @@ -216,7 +248,7 @@ static inline void transformer_layer(transformer_layer_t *const l) { S_TILE * sizeof(float), /* size */ l->embeddings, /* dst_stride */ l->embeddings, /* src_stride */ - l->seq_len); /* repetitions */ + S_TILE); /* repetitions */ snrt_dma_wait_all();