Skip to content

Commit 2aa5ff5

Browse files
committed
sw: Align NoC API with systemRDL
1 parent 7cc24e0 commit 2aa5ff5

File tree

3 files changed

+51
-18
lines changed

3 files changed

+51
-18
lines changed

sw/snitch/apps/gemm_2d/src/gemm_2d.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
static inline void allocate_l3_buffers(gemm_args_t *largs ) {
3434

3535
uint32_t prec = largs->prec;
36-
uint32_t mem_tile_idx = dst_tile_for_cluster(snrt_cluster_idx());
36+
uint32_t mem_tile_idx = pb_closest_mem_tile(snrt_cluster_idx());
3737

38-
uintptr_t a_off = l3_tile_offset((uintptr_t) largs -> a);
39-
uintptr_t c_off = l3_tile_offset((uintptr_t) largs -> c);
40-
uintptr_t a_dst = l3_tile_address(mem_tile_idx) + a_off;
41-
uintptr_t c_dst = l3_tile_address(mem_tile_idx) + c_off;
38+
uintptr_t a_off = pb_l3_tile_offset((uintptr_t) largs -> a);
39+
uintptr_t c_off = pb_l3_tile_offset((uintptr_t) largs -> c);
40+
uintptr_t a_dst = pb_l3_tile_address(mem_tile_idx) + a_off;
41+
uintptr_t c_dst = pb_l3_tile_address(mem_tile_idx) + c_off;
4242

4343
// Move data in the correct memory tile location
4444
uint32_t size_a = (size_t)largs->m * (size_t)largs->k;
@@ -61,7 +61,7 @@ static inline void write_back_c_tiles(gemm_args_t* largs, uint32_t m_tile_size,
6161

6262
// Position of the first element in the Tile to be written back
6363
c_src = (uintptr_t )largs->c + (snrt_cluster_idx() * largs->n * m_tile_size) * largs->prec;
64-
c_dst = l3_tile_address(0) + l3_tile_offset( (uintptr_t) c_src);
64+
c_dst = pb_l3_tile_address(0) + pb_l3_tile_offset( (uintptr_t) c_src);
6565
transfer_size = m_tile_size * largs->n * largs->prec;
6666

6767
if (c_src != c_dst) snrt_dma_start_1d((void *) c_dst, (void *) c_src, transfer_size);

sw/snitch/runtime/src/pb_noc_cfg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
//
55
// Lorenzo Leone <[email protected]>
66

7-
#define L3_START_ADDRESS 0x70000000UL // Base address of memory tile 0
8-
#define L3_SIZE 0x100000UL // Size of memory tile (1MiB)
7+
#define L3_START_ADDRESS PICOBELLO_ADDRMAP_L2_SPM_0_BASE_ADDR
8+
#define L3_SIZE 0x00100000
99

1010
#define CLUSTER_PER_ROW 4
1111
#define CLUSTER_PER_COL 4

sw/snitch/runtime/src/pb_team.h

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,82 @@
1616
* management and core-specific operations.
1717
*/
1818

19-
// TODO (lleone): Chekc if these functions can be difend as static
20-
2119
/**
2220
* @brief Get start address of a memory tile
2321
* @param tile_idx The memory tile idx in the NoC
2422
* @return Start addres of memory tile idx
2523
*/
26-
inline uintptr_t l3_tile_address(uint32_t tile_idx) {
27-
return (uintptr_t)L3_START_ADDRESS +
28-
(uintptr_t)tile_idx * (uintptr_t)L3_SIZE;
24+
inline uintptr_t pb_l3_tile_address(uint32_t tile_idx) {
25+
return (uintptr_t) (picobello_addrmap.l2_spm[tile_idx].mem);
2926
}
3027

3128
/**
3229
* @brief Get the address offset of a data respect to the memory tile start address
3330
* @param src_addr The data absolute address
3431
* @return Address location offset respect to the tile start address
3532
*/
36-
inline uintptr_t l3_tile_offset(uintptr_t src_addr) {
33+
inline uintptr_t pb_l3_tile_offset(uintptr_t src_addr) {
3734
return (src_addr - (uintptr_t)L3_START_ADDRESS) & (uintptr_t)(L3_SIZE - 1);
3835
}
3936

37+
4038
/**
4139
* @brief Get the NoC row index
4240
* @param cidx The cluster index
4341
* @return The Row index
4442
*/
45-
inline uint32_t cluster_row(uint32_t cidx)
43+
inline uint32_t pb_cluster_row(uint32_t cidx)
4644
{
4745
return cidx % CLUSTER_PER_ROW;
4846
}
4947

48+
/**
49+
* @brief Get the NoC row index
50+
* This is a convenience orload of pb_cluster_row()
51+
* @return The Row index
52+
*/
53+
inline uint32_t pb_cluster_row()
54+
{
55+
return pb_cluster_row(snrt_cluster_idx());
56+
}
57+
58+
5059
/**
5160
* @brief Get the NoC column index
5261
* @param cidx The cluster index
5362
* @return The Column index
5463
*/
55-
inline uint32_t cluster_col(uint32_t cidx)
64+
inline uint32_t pb_cluster_col(uint32_t cidx)
5665
{
5766
return cidx % CLUSTER_PER_COL;
5867
}
5968

60-
inline uint32_t dst_tile_for_cluster(uint32_t cidx) {
61-
uint32_t row = cluster_row(cidx);
69+
/**
70+
* @brief Get the NoC column index
71+
* This is a convenience orload of pb_cluster_row()
72+
* @return The Column index
73+
*/
74+
inline uint32_t pb_cluster_col()
75+
{
76+
return pb_cluster_col(snrt_cluster_idx());
77+
}
78+
79+
80+
/**
81+
* @brief Get the index of the closest memory tile
82+
* @param cidx The cluster index
83+
* @return Index of the closest memory tile to cidx
84+
*/
85+
inline uint32_t pb_closest_mem_tile(uint32_t cidx) {
86+
uint32_t row = pb_cluster_row(cidx);
6287
return (cidx < 8u) ? row // first 8 clusters -> left column tiles 0..3
6388
: (row + 4u); // clusters >= 8 -> right column tiles 4..7
6489
}
90+
91+
/**
92+
* @brief Get the index of the closest memory tile
93+
* This is a convenience orload of pb_closest_mem_tile()
94+
*/
95+
inline uint32_t pb_closest_mem_tile() {
96+
return pb_closest_mem_tile(snrt_cluster_idx());
97+
}

0 commit comments

Comments
 (0)