Snitch Runtime
Loading...
Searching...
No Matches
dma.h File Reference

This file provides functions to program the Snitch DMA. More...

#include <math.h>

Go to the source code of this file.

Typedefs

typedef uint32_t snrt_dma_txid_t
 A DMA transfer identifier.
 

Functions

static uint32_t snrt_dma_start_1d (uint64_t dst, uint64_t src, size_t size, const uint32_t channel=0)
 Start an asynchronous 1D DMA transfer with 64-bit wide pointers on a specific DMA channel.
 
static uint32_t snrt_dma_start_1d (volatile void *dst, volatile void *src, size_t size, const uint32_t channel=0)
 Start an asynchronous 1D DMA transfer using native-size pointers.
 
void snrt_dma_enable_mcast (uint32_t mask)
 Enable multicast for successive transfers.
 
void snrt_dma_disable_mcast ()
 Disable multicast for successive transfers.
 
static uint32_t snrt_dma_start_1d_mcast (uint64_t dst, uint64_t src, size_t size, uint32_t mask, const uint32_t channel=0)
 Start an asynchronous multicast 1D DMA transfer with 64-bit wide pointers.
 
static uint32_t snrt_dma_start_1d_mcast (volatile void *dst, volatile void *src, size_t size, uint32_t mask, const uint32_t channel=0)
 Start an asynchronous multicast 1D DMA transfer using native-size pointers.
 
static snrt_dma_txid_t snrt_dma_start_2d (uint64_t dst, uint64_t src, size_t size, size_t dst_stride, size_t src_stride, size_t repeat, const uint32_t channel=0)
 Start an asynchronous 2D DMA transfer with 64-bit wide pointers.
 
static uint32_t snrt_dma_start_2d (volatile void *dst, volatile void *src, size_t size, size_t dst_stride, size_t src_stride, size_t repeat, const uint32_t channel=0)
 Start an asynchronous 2D DMA transfer using native-size pointers.
 
static uint32_t snrt_dma_start_2d_mcast (uint64_t dst, uint64_t src, size_t size, size_t dst_stride, size_t src_stride, size_t repeat, uint32_t mask, const uint32_t channel=0)
 Start an asynchronous, multicast 2D DMA transfer with 64-bit wide pointers.
 
static uint32_t snrt_dma_start_2d_mcast (volatile void *dst, volatile void *src, size_t size, size_t dst_stride, size_t src_stride, size_t repeat, uint32_t mask, const uint32_t channel=0)
 Start an asynchronous, multicast 2D DMA transfer using native-size pointers.
 
static void snrt_dma_wait (snrt_dma_txid_t txid, const uint32_t channel=0)
 Block until a DMA transfer finishes on a specific DMA channel.
 
static void snrt_dma_wait_all (const uint32_t channel=0)
 Block until a specific DMA channel is idle.
 
void snrt_dma_wait_all_channels (uint32_t num_channels)
 Block until the first num_channels channels are idle.
 
void snrt_dma_start_tracking ()
 Start tracking of dma performance region. Does not have any implications on the HW. Only injects a marker in the DMA traces that can be analyzed.
 
void snrt_dma_stop_tracking ()
 Stop tracking of dma performance region. Does not have any implications on the HW. Only injects a marker in the DMA traces that can be analyzed.
 
void snrt_dma_memset (void *ptr, uint8_t value, uint32_t len)
 Fast memset function performed by DMA.
 
snrt_dma_txid_t snrt_dma_load_1d_tile (volatile void *dst, volatile void *src, size_t tile_idx, size_t tile_size, uint32_t prec)
 Load a tile of a 1D array.
 
snrt_dma_txid_t snrt_dma_load_1d_tile_mcast (void *dst, void *src, size_t tile_idx, size_t tile_size, uint32_t prec, uint32_t mcast)
 Load a tile of a 1D array.
 
snrt_dma_txid_t snrt_dma_1d_to_2d (volatile void *dst, volatile void *src, size_t size, size_t row_size, size_t stride)
 Transfer and reshape a 1D array into a 2D array.
 
snrt_dma_txid_t snrt_dma_2d_to_1d (volatile void *dst, volatile void *src, size_t size, size_t row_size, size_t stride)
 Transfer and reshape a 2D array into a 1D array.
 
snrt_dma_txid_t snrt_dma_store_1d_tile (void *dst, void *src, size_t tile_idx, size_t tile_size, uint32_t prec)
 Store a tile to a 1D array.
 
snrt_dma_txid_t snrt_dma_load_2d_tile (void *dst, void *src, size_t tile_x1_idx, size_t tile_x0_idx, size_t tile_x1_size, size_t tile_x0_size, size_t full_x0_size, uint32_t prec, size_t tile_ld)
 Load a 2D tile of a 2D array.
 
snrt_dma_txid_t snrt_dma_load_2d_tile (void *dst, void *src, size_t tile_x1_idx, size_t tile_x0_idx, size_t tile_x1_size, size_t tile_x0_size, size_t full_x0_size, uint32_t prec)
 Load a 2D tile of a 2D array.
 
snrt_dma_txid_t snrt_dma_load_2d_tile_mcast (void *dst, void *src, size_t tile_x1_idx, size_t tile_x0_idx, size_t tile_x1_size, size_t tile_x0_size, size_t full_x0_size, uint32_t prec, size_t tile_ld, uint32_t mask)
 Load a 2D tile of a 2D array using multicast.
 
snrt_dma_txid_t snrt_dma_load_2d_tile_mcast (void *dst, void *src, size_t tile_x1_idx, size_t tile_x0_idx, size_t tile_x1_size, size_t tile_x0_size, size_t full_x0_size, uint32_t prec, uint32_t mask)
 Load a 2D tile of a 2D array.
 
snrt_dma_txid_t snrt_dma_load_2d_tile_in_banks (void *dst, void *src, size_t tile_x1_idx, size_t tile_x0_idx, size_t tile_x1_size, size_t tile_x0_size, size_t full_x0_size, uint32_t prec, size_t num_banks)
 Load a 2D tile of a 2D array and reshape it to occupy a subset of TCDM banks.
 
snrt_dma_txid_t snrt_dma_store_2d_tile (void *dst, void *src, size_t tile_x1_idx, size_t tile_x0_idx, size_t tile_x1_size, size_t tile_x0_size, size_t full_x0_size, uint32_t prec, size_t tile_ld)
 Store a 2D tile to a 2D array.
 
snrt_dma_txid_t snrt_dma_store_2d_tile (void *dst, void *src, size_t tile_x1_idx, size_t tile_x0_idx, size_t tile_x1_size, size_t tile_x0_size, size_t full_x0_size, uint32_t prec)
 Store a 2D tile of a 2D array.
 
snrt_dma_txid_t snrt_dma_store_2d_tile_from_banks (void *dst, void *src, size_t tile_x1_idx, size_t tile_x0_idx, size_t tile_x1_size, size_t tile_x0_size, size_t full_x0_size, uint32_t prec, size_t num_banks)
 Store a 2D tile of a 2D array from a 1D layout occupying a subset of TCDM banks.
 

Detailed Description

This file provides functions to program the Snitch DMA.

Function Documentation

◆ snrt_dma_1d_to_2d()

snrt_dma_txid_t snrt_dma_1d_to_2d ( volatile void * dst,
volatile void * src,
size_t size,
size_t row_size,
size_t stride )
inline

Transfer and reshape a 1D array into a 2D array.

Parameters
dstPointer to the destination array.
srcPointer to the source array.
sizeNumber of bytes to transfer.
row_sizeSize of a row in the 2D array, in bytes.
strideStride between successive rows in the 2D array, in bytes.
348 {
349 return snrt_dma_start_2d(dst, src, row_size, stride, row_size,
350 size / row_size);
351}
static snrt_dma_txid_t snrt_dma_start_2d(uint64_t dst, uint64_t src, size_t size, size_t dst_stride, size_t src_stride, size_t repeat, const uint32_t channel=0)
Start an asynchronous 2D DMA transfer with 64-bit wide pointers.
Definition dma.h:128

◆ snrt_dma_2d_to_1d()

snrt_dma_txid_t snrt_dma_2d_to_1d ( volatile void * dst,
volatile void * src,
size_t size,
size_t row_size,
size_t stride )
inline

Transfer and reshape a 2D array into a 1D array.

Parameters
dstPointer to the destination array.
srcPointer to the source array.
sizeNumber of bytes to transfer.
row_sizeSize of a row in the 2D array, in bytes.
strideStride between successive rows in the 2D array, in bytes.
363 {
364 return snrt_dma_start_2d(dst, src, row_size, row_size, stride,
365 size / row_size);
366}

◆ snrt_dma_disable_mcast()

void snrt_dma_disable_mcast ( )
inline

Disable multicast for successive transfers.

Resets the multicast mask to zero.

76{ asm volatile("dmuser zero, zero \n"); }

◆ snrt_dma_enable_mcast()

void snrt_dma_enable_mcast ( uint32_t mask)
inline

Enable multicast for successive transfers.

Parameters
maskMulticast mask applied to successive transfers.
68 {
69 asm volatile("dmuser %[mask], zero \n" : : [ mask ] "r"(mask));
70}

◆ snrt_dma_load_1d_tile()

snrt_dma_txid_t snrt_dma_load_1d_tile ( volatile void * dst,
volatile void * src,
size_t tile_idx,
size_t tile_size,
uint32_t prec )
inline

Load a tile of a 1D array.

Parameters
dstPointer to the tile destination.
srcPointer to the source array.
tile_idxIndex of the tile in the 1D array.
tile_sizeNumber of elements within a tile of the 1D array.
precNumber of bytes of each element in the 1D array.
312 {
313 size_t tile_nbytes = tile_size * prec;
314 return snrt_dma_start_1d(
315 (uint64_t)dst, (uint64_t)src + tile_idx * tile_nbytes, tile_nbytes);
316}
static uint32_t snrt_dma_start_1d(uint64_t dst, uint64_t src, size_t size, const uint32_t channel=0)
Start an asynchronous 1D DMA transfer with 64-bit wide pointers on a specific DMA channel.
Definition dma.h:31

◆ snrt_dma_load_1d_tile_mcast()

snrt_dma_txid_t snrt_dma_load_1d_tile_mcast ( void * dst,
void * src,
size_t tile_idx,
size_t tile_size,
uint32_t prec,
uint32_t mcast )
inline

Load a tile of a 1D array.

Parameters
dstPointer to the tile destination.
srcPointer to the source array.
tile_idxIndex of the tile in the 1D array.
tile_sizeNumber of elements within a tile of the 1D array.
precNumber of bytes of each element in the 1D array.
mcastMulticast mask applied on the destination address.
331 {
332 size_t tile_nbytes = tile_size * prec;
333 return snrt_dma_start_1d_mcast((uintptr_t)dst,
334 (uintptr_t)src + tile_idx * tile_nbytes,
335 tile_nbytes, mcast);
336}
static uint32_t snrt_dma_start_1d_mcast(uint64_t dst, uint64_t src, size_t size, uint32_t mask, const uint32_t channel=0)
Start an asynchronous multicast 1D DMA transfer with 64-bit wide pointers.
Definition dma.h:85

◆ snrt_dma_load_2d_tile() [1/2]

snrt_dma_txid_t snrt_dma_load_2d_tile ( void * dst,
void * src,
size_t tile_x1_idx,
size_t tile_x0_idx,
size_t tile_x1_size,
size_t tile_x0_size,
size_t full_x0_size,
uint32_t prec )
inline

Load a 2D tile of a 2D array.

The stride in the destination tile is assumed to be that of a 1D tile, effectively. In other words, this is the same as snrt_dma_2d_to_1d().

See also
snrt_dma_load_2d_tile(void *, void *, size_t, size_t, size_t, size_t, size_t, uint32_t, size_t) for a detailed description of the parameters.
430 {
431 return snrt_dma_load_2d_tile(dst, src, tile_x1_idx, tile_x0_idx,
432 tile_x1_size, tile_x0_size, full_x0_size, prec,
433 tile_x0_size * prec);
434}
snrt_dma_txid_t snrt_dma_load_2d_tile(void *dst, void *src, size_t tile_x1_idx, size_t tile_x0_idx, size_t tile_x1_size, size_t tile_x0_size, size_t full_x0_size, uint32_t prec, size_t tile_ld)
Load a 2D tile of a 2D array.
Definition dma.h:399

◆ snrt_dma_load_2d_tile() [2/2]

snrt_dma_txid_t snrt_dma_load_2d_tile ( void * dst,
void * src,
size_t tile_x1_idx,
size_t tile_x0_idx,
size_t tile_x1_size,
size_t tile_x0_size,
size_t full_x0_size,
uint32_t prec,
size_t tile_ld )
inline

Load a 2D tile of a 2D array.

Parameters
dstPointer to the tile destination.
srcPointer to the source array.
tile_x1_idxOutermost coordinate of the tile in the 2D array.
tile_x0_idxInnermost coordinate of the tile in the 2D array.
tile_x1_sizeNumber of elements in the outermost dimension of the tile.
tile_x0_sizeNumber of elements in the innermost dimension of the tile.
full_x0_sizeNumber of elements in the innermost dimension of the array.
precNumber of bytes of each element in the 2D array.
tile_ldLeading dimension of the tile, in bytes.
402 {
403 size_t src_offset = 0;
404 // Advance src array in x0 and x1 dimensions, and convert to byte offset
405 src_offset += tile_x0_idx * tile_x0_size;
406 src_offset += tile_x1_idx * tile_x1_size * full_x0_size;
407 src_offset *= prec;
408 // Initiate transfer
409 return snrt_dma_start_2d((uint64_t)dst, // dst
410 (uint64_t)src + src_offset, // src
411 tile_x0_size * prec, // size
412 tile_ld, // dst_stride
413 full_x0_size * prec, // src_stride
414 tile_x1_size // repeat
415 );
416}

◆ snrt_dma_load_2d_tile_in_banks()

snrt_dma_txid_t snrt_dma_load_2d_tile_in_banks ( void * dst,
void * src,
size_t tile_x1_idx,
size_t tile_x0_idx,
size_t tile_x1_size,
size_t tile_x0_size,
size_t full_x0_size,
uint32_t prec,
size_t num_banks )
inline

Load a 2D tile of a 2D array and reshape it to occupy a subset of TCDM banks.

Parameters
dstPointer to the tile destination.
srcPointer to the source array.
tile_x1_idxOutermost coordinate of the tile in the 2D array.
tile_x0_idxInnermost coordinate of the tile in the 2D array.
tile_x1_sizeNumber of elements in the outermost dimension of the tile.
tile_x0_sizeNumber of elements in the innermost dimension of the tile.
full_x0_sizeNumber of elements in the innermost dimension of the array.
precNumber of bytes of each element in the 2D array.
num_banksNumber of banks to reshape the tile into.
500 {
501 // Calculate new tile size after reshaping the tile in the selected banks
502 size_t tile_x0_size_in_banks = (num_banks * SNRT_TCDM_BANK_WIDTH) / prec;
503 size_t tile_x1_size_in_banks =
504 ceil((tile_x1_size * tile_x0_size) / (double)tile_x0_size_in_banks);
505 size_t tile_ld = SNRT_TCDM_HYPERBANK_WIDTH;
506 return snrt_dma_load_2d_tile(dst, src, tile_x1_idx, tile_x0_idx,
507 tile_x1_size_in_banks, tile_x0_size_in_banks,
508 full_x0_size, prec, tile_ld);
509}

◆ snrt_dma_load_2d_tile_mcast() [1/2]

snrt_dma_txid_t snrt_dma_load_2d_tile_mcast ( void * dst,
void * src,
size_t tile_x1_idx,
size_t tile_x0_idx,
size_t tile_x1_size,
size_t tile_x0_size,
size_t full_x0_size,
uint32_t prec,
size_t tile_ld,
uint32_t mask )
inline

Load a 2D tile of a 2D array using multicast.

Parameters
maskMulticast mask.
See also
snrt_dma_load_2d_tile(void *, void *, size_t, size_t, size_t, size_t, size_t, uint32_t, size_t) for a description of the other parameters.
446 {
447 size_t src_offset = 0;
448 // Advance src array in x0 and x1 dimensions, and convert to byte offset
449 src_offset += tile_x0_idx * tile_x0_size;
450 src_offset += tile_x1_idx * tile_x1_size * full_x0_size;
451 src_offset *= prec;
452 // Initiate transfer
453 return snrt_dma_start_2d_mcast((uint64_t)dst, // dst
454 (uint64_t)src + src_offset, // src
455 tile_x0_size * prec, // size
456 tile_ld, // dst_stride
457 full_x0_size * prec, // src_stride
458 tile_x1_size, // repeat
459 mask // mask
460 );
461}
static uint32_t snrt_dma_start_2d_mcast(uint64_t dst, uint64_t src, size_t size, size_t dst_stride, size_t src_stride, size_t repeat, uint32_t mask, const uint32_t channel=0)
Start an asynchronous, multicast 2D DMA transfer with 64-bit wide pointers.
Definition dma.h:178

◆ snrt_dma_load_2d_tile_mcast() [2/2]

snrt_dma_txid_t snrt_dma_load_2d_tile_mcast ( void * dst,
void * src,
size_t tile_x1_idx,
size_t tile_x0_idx,
size_t tile_x1_size,
size_t tile_x0_size,
size_t full_x0_size,
uint32_t prec,
uint32_t mask )
inline

Load a 2D tile of a 2D array.

The stride in the destination tile is assumed to be that of a 1D tile, effectively. In other words, this is similar to snrt_dma_2d_to_1d().

See also
snrt_dma_load_2d_tile_mcast(void *, void *, size_t, size_t, size_t, size_t, size_t, uint32_t, size_t, uint32_t) for a detailed description of the parameters.
475 {
476 return snrt_dma_load_2d_tile_mcast(dst, src, tile_x1_idx, tile_x0_idx,
477 tile_x1_size, tile_x0_size, full_x0_size,
478 prec, tile_x0_size * prec, mask);
479}
snrt_dma_txid_t snrt_dma_load_2d_tile_mcast(void *dst, void *src, size_t tile_x1_idx, size_t tile_x0_idx, size_t tile_x1_size, size_t tile_x0_size, size_t full_x0_size, uint32_t prec, size_t tile_ld, uint32_t mask)
Load a 2D tile of a 2D array using multicast.
Definition dma.h:443

◆ snrt_dma_memset()

void snrt_dma_memset ( void * ptr,
uint8_t value,
uint32_t len )
inline

Fast memset function performed by DMA.

Parameters
ptrPointer to the start of the region.
valueValue to set.
lenNumber of bytes, must be a multiple of the DMA bus width to use the DMA.
282 {
283 // We set the first 64 bytes to the value, and then we use the DMA to copy
284 // these into the remaining memory region. DMA is used only if len is
285 // larger than 64 bytes, and an integer multiple of 64 bytes.
286 size_t n_1d_transfers = len / 64;
287 size_t use_dma = (len % 64) == 0 && len > 64;
288 uint8_t *p = (uint8_t *)ptr;
289
290 uint32_t nbytes = len < 64 || !use_dma ? len : 64;
291 while (nbytes--) {
292 *p++ = value;
293 }
294
295 if (use_dma) {
296 snrt_dma_start_2d(ptr, ptr, 64, 64, 0, n_1d_transfers);
298 }
299}
static void snrt_dma_wait_all(const uint32_t channel=0)
Block until a specific DMA channel is idle.
Definition dma.h:239

◆ snrt_dma_start_1d() [1/2]

static uint32_t snrt_dma_start_1d ( uint64_t dst,
uint64_t src,
size_t size,
const uint32_t channel = 0 )
inlinestatic

Start an asynchronous 1D DMA transfer with 64-bit wide pointers on a specific DMA channel.

Parameters
dstThe destination address.
srcThe source address.
sizeThe size of the transfer in bytes.
channelThe index of the channel.
Returns
The DMA transfer ID.
Note
The function passes the channel argument as an immediate, thus this must be known at compile time. As a consequence, the function must use internal linkage (static keyword) and must be always inlined. This is true also for all functions invoking this function, and passing down an argument to channel.
33 {
34 uint32_t dst_lo = dst & 0xFFFFFFFF;
35 uint32_t dst_hi = dst >> 32;
36 uint32_t src_lo = src & 0xFFFFFFFF;
37 uint32_t src_hi = src >> 32;
38 uint32_t txid;
39
40 asm volatile(
41 "dmsrc %[src_lo], %[src_hi] \n"
42 "dmdst %[dst_lo], %[dst_hi] \n"
43 "dmcpyi %[txid], %[size], (%[channel] << 2) | 0b00 \n"
44 : [ txid ] "=r"(txid)
45 : [ src_lo ] "r"(src_lo), [ src_hi ] "r"(src_hi),
46 [ dst_lo ] "r"(dst_lo), [ dst_hi ] "r"(dst_hi), [ size ] "r"(size),
47 [ channel ] "i"(channel));
48
49 return txid;
50}

◆ snrt_dma_start_1d() [2/2]

static uint32_t snrt_dma_start_1d ( volatile void * dst,
volatile void * src,
size_t size,
const uint32_t channel = 0 )
inlinestatic

Start an asynchronous 1D DMA transfer using native-size pointers.

This is a convenience overload of snrt_dma_start_1d(uint64_t, uint64_t, size_t, uint32_t) using void* pointers.

60 {
61 return snrt_dma_start_1d((uint64_t)dst, (uint64_t)src, size, channel);
62}

◆ snrt_dma_start_1d_mcast() [1/2]

static uint32_t snrt_dma_start_1d_mcast ( uint64_t dst,
uint64_t src,
size_t size,
uint32_t mask,
const uint32_t channel = 0 )
inlinestatic

Start an asynchronous multicast 1D DMA transfer with 64-bit wide pointers.

Parameters
maskMulticast mask applied on the destination address.
See also
snrt_dma_start_1d(uint64_t, uint64_t, size_t, uint32_t) for a description of the other parameters.
87 {
89 uint32_t txid = snrt_dma_start_1d(dst, src, size, channel);
91 return txid;
92}
void snrt_dma_enable_mcast(uint32_t mask)
Enable multicast for successive transfers.
Definition dma.h:68
void snrt_dma_disable_mcast()
Disable multicast for successive transfers.
Definition dma.h:76

◆ snrt_dma_start_1d_mcast() [2/2]

static uint32_t snrt_dma_start_1d_mcast ( volatile void * dst,
volatile void * src,
size_t size,
uint32_t mask,
const uint32_t channel = 0 )
inlinestatic

Start an asynchronous multicast 1D DMA transfer using native-size pointers.

This is a convenience overload of snrt_dma_start_1d_mcast(uint64_t, uint64_t, size_t, uint32_t, uint32_t) using void* pointers.

105 {
106 return snrt_dma_start_1d_mcast((uint64_t)dst, (uint64_t)src, size, mask,
107 channel);
108}

◆ snrt_dma_start_2d() [1/2]

static snrt_dma_txid_t snrt_dma_start_2d ( uint64_t dst,
uint64_t src,
size_t size,
size_t dst_stride,
size_t src_stride,
size_t repeat,
const uint32_t channel = 0 )
inlinestatic

Start an asynchronous 2D DMA transfer with 64-bit wide pointers.

Parameters
dstThe destination address.
srcThe source address.
sizeThe size of every 1D transfer within the 2D transfer in bytes.
dst_strideThe offset between consecutive 1D transfers at the destination, in bytes.
src_strideThe offset between consecutive 1D transfers at the source, in bytes.
repeatThe number of 1D transfers composing the 2D transfer.
channelThe index of the channel.
Returns
The DMA transfer ID.
Note
The function passes the channel argument as an immediate, thus this must be known at compile time. As a consequence, the function must use internal linkage (static keyword) and must be always inlined. This is true also for all functions invoking this function, and passing down an argument to channel.
132 {
133 uint32_t dst_lo = dst & 0xFFFFFFFF;
134 uint32_t dst_hi = dst >> 32;
135 uint32_t src_lo = src & 0xFFFFFFFF;
136 uint32_t src_hi = src >> 32;
137 uint32_t txid;
138
139 asm volatile(
140 "dmsrc %[src_lo], %[src_hi] \n"
141 "dmdst %[dst_lo], %[dst_hi] \n"
142 "dmstr %[src_stride], %[dst_stride] \n"
143 "dmrep %[repeat] \n"
144 "dmcpyi %[txid], %[size], (%[channel] << 2) | 0b10 \n"
145 : [ txid ] "=r"(txid)
146 : [ src_lo ] "r"(src_lo), [ src_hi ] "r"(src_hi),
147 [ dst_lo ] "r"(dst_lo), [ dst_hi ] "r"(dst_hi),
148 [ dst_stride ] "r"(dst_stride), [ src_stride ] "r"(src_stride),
149 [ repeat ] "r"(repeat), [ size ] "r"(size), [ channel ] "i"(channel));
150
151 return txid;
152}

◆ snrt_dma_start_2d() [2/2]

static uint32_t snrt_dma_start_2d ( volatile void * dst,
volatile void * src,
size_t size,
size_t dst_stride,
size_t src_stride,
size_t repeat,
const uint32_t channel = 0 )
inlinestatic

Start an asynchronous 2D DMA transfer using native-size pointers.

This is a convenience overload of snrt_dma_start_2d(uint64_t, uint64_t, size_t, size_t, size_t, size_t, uint32_t) using void* pointers.

164 {
165 return snrt_dma_start_2d((uint64_t)dst, (uint64_t)src, size, dst_stride,
166 src_stride, repeat, channel);
167}

◆ snrt_dma_start_2d_mcast() [1/2]

static uint32_t snrt_dma_start_2d_mcast ( uint64_t dst,
uint64_t src,
size_t size,
size_t dst_stride,
size_t src_stride,
size_t repeat,
uint32_t mask,
const uint32_t channel = 0 )
inlinestatic

Start an asynchronous, multicast 2D DMA transfer with 64-bit wide pointers.

Parameters
maskMulticast mask.
See also
snrt_dma_start_2d(uint64_t, uint64_t, size_t, size_t, size_t, size_t, uint32_t) for a description of the other parameters.
182 {
184 uint32_t txid = snrt_dma_start_2d(dst, src, size, dst_stride, src_stride,
185 repeat, channel);
187 return txid;
188}

◆ snrt_dma_start_2d_mcast() [2/2]

static uint32_t snrt_dma_start_2d_mcast ( volatile void * dst,
volatile void * src,
size_t size,
size_t dst_stride,
size_t src_stride,
size_t repeat,
uint32_t mask,
const uint32_t channel = 0 )
inlinestatic

Start an asynchronous, multicast 2D DMA transfer using native-size pointers.

This is a convenience overload of snrt_dma_start_2d_mcast(uint64_t, uint64_t, size_t, size_t, size_t, size_t, uint32_t, uint32_t) using void* pointers.

203 {
204 return snrt_dma_start_2d_mcast((uint64_t)dst, (uint64_t)src, size,
205 dst_stride, src_stride, repeat, mask,
206 channel);
207}

◆ snrt_dma_start_tracking()

void snrt_dma_start_tracking ( )
inline

Start tracking of dma performance region. Does not have any implications on the HW. Only injects a marker in the DMA traces that can be analyzed.

Deprecated
265{ asm volatile("dmstati zero, 0 \n"); }

◆ snrt_dma_stop_tracking()

void snrt_dma_stop_tracking ( )
inline

Stop tracking of dma performance region. Does not have any implications on the HW. Only injects a marker in the DMA traces that can be analyzed.

Deprecated
273{ asm volatile("dmstati zero, 0 \n"); }

◆ snrt_dma_store_1d_tile()

snrt_dma_txid_t snrt_dma_store_1d_tile ( void * dst,
void * src,
size_t tile_idx,
size_t tile_size,
uint32_t prec )
inline

Store a tile to a 1D array.

Parameters
dstPointer to the destination array.
srcPointer to the source tile.
tile_idxIndex of the tile in the 1D array.
tile_sizeNumber of elements within a tile of the 1D array.
precNumber of bytes of each element in the 1D array.
378 {
379 size_t tile_nbytes = tile_size * prec;
380 return snrt_dma_start_1d((uint64_t)dst + tile_idx * tile_nbytes,
381 (uint64_t)src, tile_nbytes);
382}

◆ snrt_dma_store_2d_tile() [1/2]

snrt_dma_txid_t snrt_dma_store_2d_tile ( void * dst,
void * src,
size_t tile_x1_idx,
size_t tile_x0_idx,
size_t tile_x1_size,
size_t tile_x0_size,
size_t full_x0_size,
uint32_t prec )
inline

Store a 2D tile of a 2D array.

The stride in the source tile is assumed to be that of a 1D tile, effectively. In other words, this is the same as snrt_dma_1d_to_2d().

See also
snrt_dma_store_2d_tile(void *, void *, size_t, size_t, size_t, size_t, size_t, uint32_t, size_t) for a detailed description of the parameters.
557 {
558 return snrt_dma_store_2d_tile(dst, src, tile_x1_idx, tile_x0_idx,
559 tile_x1_size, tile_x0_size, full_x0_size,
560 prec, tile_x0_size * prec);
561}
snrt_dma_txid_t snrt_dma_store_2d_tile(void *dst, void *src, size_t tile_x1_idx, size_t tile_x0_idx, size_t tile_x1_size, size_t tile_x0_size, size_t full_x0_size, uint32_t prec, size_t tile_ld)
Store a 2D tile to a 2D array.
Definition dma.h:526

◆ snrt_dma_store_2d_tile() [2/2]

snrt_dma_txid_t snrt_dma_store_2d_tile ( void * dst,
void * src,
size_t tile_x1_idx,
size_t tile_x0_idx,
size_t tile_x1_size,
size_t tile_x0_size,
size_t full_x0_size,
uint32_t prec,
size_t tile_ld )
inline

Store a 2D tile to a 2D array.

Parameters
dstPointer to the destination array.
srcPointer to the source tile.
tile_x1_idxOutermost coordinate of the tile in the 2D array.
tile_x0_idxInnermost coordinate of the tile in the 2D array.
tile_x1_sizeNumber of elements in the outermost dimension of the tile.
tile_x0_sizeNumber of elements in the innermost dimension of the tile.
full_x0_sizeNumber of elements in the innermost dimension of the array.
precNumber of bytes of each element in the 2D array.
tile_ldLeading dimension of the tile, in bytes.
529 {
530 size_t dst_offset = 0;
531 // Advance dst array in x0 and x1 dimensions, and convert to byte offset
532 dst_offset += tile_x0_idx * tile_x0_size;
533 dst_offset += tile_x1_idx * tile_x1_size * full_x0_size;
534 dst_offset *= prec;
535 // Initiate transfer
536 return snrt_dma_start_2d((uint64_t)dst + dst_offset, // dst
537 (uint64_t)src, // src
538 tile_x0_size * prec, // size
539 full_x0_size * prec, // dst_stride
540 tile_ld, // src_stride
541 tile_x1_size // repeat
542 );
543}

◆ snrt_dma_store_2d_tile_from_banks()

snrt_dma_txid_t snrt_dma_store_2d_tile_from_banks ( void * dst,
void * src,
size_t tile_x1_idx,
size_t tile_x0_idx,
size_t tile_x1_size,
size_t tile_x0_size,
size_t full_x0_size,
uint32_t prec,
size_t num_banks )
inline

Store a 2D tile of a 2D array from a 1D layout occupying a subset of TCDM banks.

Parameters
dstPointer to the destination array.
srcPointer to the source tile.
tile_x1_idxOutermost coordinate of the tile in the 2D array.
tile_x0_idxInnermost coordinate of the tile in the 2D array.
tile_x1_sizeNumber of elements in the outermost dimension of the tile.
tile_x0_sizeNumber of elements in the innermost dimension of the tile.
full_x0_sizeNumber of elements in the innermost dimension of the array.
precNumber of bytes of each element in the 2D array.
num_banksNumber of banks the tile is stored in.
582 {
583 // Calculate new tile size after reshaping the tile in the selected banks
584 size_t tile_x0_size_in_banks = (num_banks * SNRT_TCDM_BANK_WIDTH) / prec;
585 size_t tile_x1_size_in_banks =
586 ceil((tile_x1_size * tile_x0_size) / (double)tile_x0_size_in_banks);
587 size_t tile_ld = SNRT_TCDM_HYPERBANK_WIDTH;
588 return snrt_dma_store_2d_tile(dst, src, tile_x1_idx, tile_x0_idx,
589 tile_x1_size_in_banks, tile_x0_size_in_banks,
590 full_x0_size, prec, tile_ld);
591}

◆ snrt_dma_wait()

static void snrt_dma_wait ( snrt_dma_txid_t txid,
const uint32_t channel = 0 )
inlinestatic

Block until a DMA transfer finishes on a specific DMA channel.

Parameters
txidThe DMA transfer's ID.
channelThe index of the channel.
Note
The function passes the channel argument as an immediate, thus this must be known at compile time. As a consequence, the function must use internal linkage (static keyword) and must be always inlined. This is true also for all functions invoking this function, and passing down an argument to channel.
220 {
221 asm volatile(
222 "1: \n"
223 "dmstati t0, (%[channel] << 2) | 0 \n"
224 "bltu t0, %[txid], 1b \n"
225 :
226 : [ txid ] "r"(txid), [ channel ] "i"(channel)
227 : "t0");
228}

◆ snrt_dma_wait_all()

static void snrt_dma_wait_all ( const uint32_t channel = 0)
inlinestatic

Block until a specific DMA channel is idle.

Parameters
channelThe index of the channel.
Note
The function passes the channel argument as an immediate, thus this must be known at compile time. As a consequence, the function must use internal linkage (static keyword) and must be always inlined. This is true also for all functions invoking this function, and passing down an argument to channel.
239 {
240 uint32_t busy;
241 asm volatile(
242 "1: \n"
243 "dmstati %[busy], (%[channel] << 2) | 2 \n"
244 "bne %[busy], zero, 1b \n"
245 : [ busy ] "=r"(busy)
246 : [ channel ] "i"(channel));
247}

◆ snrt_dma_wait_all_channels()

void snrt_dma_wait_all_channels ( uint32_t num_channels)
inline

Block until the first num_channels channels are idle.

Parameters
num_channelsThe number of channels to wait on.
253 {
254 for (int c = 0; c < num_channels; c++) {
256 }
257}