Skip to content

Commit

Permalink
sw: add generic DMA transfer and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Viviane Potocnik committed Sep 16, 2023
1 parent 486825e commit e5404dc
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion sw/apps/transformer/src/transformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit e5404dc

Please sign in to comment.