Skip to content

Commit

Permalink
Added restrict to firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
Aba committed Jul 23, 2024
1 parent cc961ce commit 6d36dcf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
9 changes: 0 additions & 9 deletions deepsocflow/c/deepsocflow_xilinx.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,11 @@

#define MEM_BASEADDR 0x20000000

#ifdef NDEBUG
#define debug_xil_printf(...)
#else
#define debug_xil_printf xil_printf
#endif

static inline void flush_cache(void *addr, uint32_t bytes) {
Xil_DCacheFlushRange((INTPTR)addr, bytes);
}

// RUNTIME.H
//#define printf xil_printf
#include "runtime.h"
//#undef printf

static inline void hardware_setup(){
init_platform();
Expand Down
23 changes: 12 additions & 11 deletions deepsocflow/c/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ typedef struct {

#ifdef __cplusplus
#define EXT_C "C"
#define restrict __restrict__
#else
#define EXT_C
#endif
Expand All @@ -95,14 +96,14 @@ typedef struct {

#else
#define sim_fprintf(...)
#define mem (*(Memory_st*)MEM_BASEADDR)
#define mem (*(Memory_st* restrict)MEM_BASEADDR)

inline volatile u32 get_config(u32 offset){
return *(volatile u32 *)(CONFIG_BASEADDR + offset);
}

inline void set_config(u32 offset, u32 data){
volatile u32 *Addr = (volatile u32 *)(CONFIG_BASEADDR + offset);
volatile u32 *Addr = (volatile u32 *restrict)(CONFIG_BASEADDR + offset);
*Addr = data;
}
#endif
Expand All @@ -124,7 +125,7 @@ static inline void print_output () {
}
}

static inline void write_flush_u8(u8* addr, u8 val) {
static inline void write_flush_u8(u8*restrict addr, u8 val) {
*addr = val;
flush_cache(addr, 1);
}
Expand All @@ -148,7 +149,7 @@ static inline i32 quant_lrelu(i32 x, i8 nzero, i8 shift, i8 pl_scale){
}


static inline void write_x(i8 val, i8 *p_out_buffer, i32 ib, i32 ixp, i32 ixn, i32 ixl, i32 ixw, i32 ixcm, i32 ixr, Bundle_t *pb_out, i32 xcm ){
static inline void write_x(i8 val, i8 *restrict p_out_buffer, i32 ib, i32 ixp, i32 ixn, i32 ixl, i32 ixw, i32 ixcm, i32 ixr, Bundle_t *restrict pb_out, i32 xcm ){

#define WRITEX_DEBUG_INFO "--- ib:%d ixp:%d ixn:%d ixl:%d ixw:%d ixcm:%d ixr:%d xcm :%d \n",ib,ixp,ixn,ixl,ixw,ixcm,ixr,xcm
assert_printf (ixr , <, PE_ROWS+pb_out->x_pad, "write_x", WRITEX_DEBUG_INFO);
Expand Down Expand Up @@ -179,7 +180,7 @@ static inline void write_x(i8 val, i8 *p_out_buffer, i32 ib, i32 ixp, i32 ixn, i
}


static inline void tile_write( i32 out_val, i8 *p_out_buffer, i32 ib, Bundle_t *pb, i32 i_yn, i32 i_yh, i32 i_yw, i32 i_yc, i32 yn, i32 yh, i32 yw, i32 yc ) {
static inline void tile_write( i32 out_val, i8 *restrict p_out_buffer, i32 ib, Bundle_t *restrict pb, i32 i_yn, i32 i_yh, i32 i_yw, i32 i_yc, i32 yn, i32 yh, i32 yw, i32 yc ) {

// ------ FLATTEN ------
if (pb->is_flatten) {
Expand Down Expand Up @@ -210,7 +211,7 @@ static inline void tile_write( i32 out_val, i8 *p_out_buffer, i32 ib, Bundle_t *
mem.add_buffers[pb->add_out_buffer_idx][iy_nhwc] = (i8)out_val;

// If output only goes to residual add, early return
Bundle_t* pb_out;
Bundle_t*restrict pb_out;
if (pb->ib_out == -1)
return;
else
Expand Down Expand Up @@ -251,10 +252,10 @@ static inline void tile_write( i32 out_val, i8 *p_out_buffer, i32 ib, Bundle_t *

extern EXT_C u8 model_run() {

static Bundle_t *pb = &bundles[0];
static Bundle_t *restrict pb = &bundles[0];
static i32 it_bias=0;
static i32 ib=0, ip=0, it=0, in=0, il=0, iw_kw2=0;
static i8 *p_out_buffer = (i8*)&mem.out_buffers[0];
static i8 *restrict p_out_buffer = (i8*)&mem.out_buffers[0];

i32 iy_nhwc;
div_t div_ch, div_cw, div_ixh, div_ixw;
Expand Down Expand Up @@ -581,7 +582,7 @@ extern EXT_C void sim_fill_memory (){
fclose(fp);
}

extern EXT_C u32 addr_64to32(void* addr){
extern EXT_C u32 addr_64to32(void* restrict addr){
u64 offset = (u64)addr - (u64)&mem;
return (u32)offset + 0x20000000;
}
Expand All @@ -592,14 +593,14 @@ extern EXT_C u64 sim_addr_32to64(u32 addr){

extern EXT_C u8 get_byte_a32 (u32 addr_32){
u64 addr = sim_addr_32to64(addr_32);
u8 val = *(u8*)addr;
u8 val = *(u8*restrict)addr;
//debug_printf("get_byte_a32: addr32:0x%x, addr64:0x%lx, val:0x%x\n", addr_32, addr, val);
return val;
}

extern EXT_C void set_byte_a32 (u32 addr_32, u8 data){
u64 addr = sim_addr_32to64(addr_32);
*(u8*)addr = data;
*(u8*restrict)addr = data;
}
#else

Expand Down
4 changes: 2 additions & 2 deletions run/param_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ def product_dict(**kwargs):
axi_width = [ 128 ],
config_baseaddr = ["B0000000"],
target_cpu_int_bits = [ 32 ],
valid_prob = [ 0.01 ],
ready_prob = [ 0.1 ],
valid_prob = [ 1 ],
ready_prob = [ 1 ],
data_dir = ['vectors'],
)))
def test_dnn_engine(PARAMS):
Expand Down

0 comments on commit 6d36dcf

Please sign in to comment.