Skip to content

Commit

Permalink
Furhter fix SW lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvan Tortorella committed Feb 17, 2024
1 parent cfd71df commit 54b739f
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 167 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ jobs:
ColumnLimit: 100,
AlignEscapedNewlines: DontAlign,
SortIncludes: false,
AllowShortFunctionsOnASingleLine: None,
AllowShortFunctionsOnASingleLine: true,
AllowShortIfStatementsOnASingleLine: true,
AllowShortLoopsOnASingleLine: true
}
exclude: |
./sw/inc/*
./sw/utils/tinyprintf.h
37 changes: 18 additions & 19 deletions sw/archi_redmule.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,28 @@

#define ARCHI_CL_EVT_ACC0 0
#define ARCHI_CL_EVT_ACC1 1
#define __builtin_bitinsert(a,b,c,d) (a | (((b << (32-c)) >> (32-c)) << d))

// RedMulE architecture
#define ADDR_WIDTH 32
#define DATA_WIDTH 512
#define REDMULE_FMT 16
#define ADDR_WIDTH 32
#define DATA_WIDTH 512
#define REDMULE_FMT 16
#define ARRAY_HEIGHT 8
#define PIPE_REGS 3
#define ARRAY_WIDTH 24 /* Superior limit is ARRAY_HEIGHT*PIPE_REGS */
#define PIPE_REGS 3
#define ARRAY_WIDTH 24 /* Superior limit is ARRAY_HEIGHT*PIPE_REGS */

// Base address
#define REDMULE_BASE_ADD 0x00100000

// Commands
#define REDMULE_TRIGGER 0x00
#define REDMULE_ACQUIRE 0x04
#define REDMULE_FINISHED 0x08
#define REDMULE_STATUS 0x0C
#define REDMULE_TRIGGER 0x00
#define REDMULE_ACQUIRE 0x04
#define REDMULE_FINISHED 0x08
#define REDMULE_STATUS 0x0C
#define REDMULE_RUNNING_JOB 0x10
#define REDMULE_SOFT_CLEAR 0x14
#define REDMULE_SOFT_CLEAR 0x14

// Registers
#define REDMULE_REG_OFFS 0x40
#define REDMULE_REG_OFFS 0x40
#define REDMULE_REG_X_PTR 0x00
#define REDMULE_REG_W_PTR 0x04
#define REDMULE_REG_Z_PTR 0x08
Expand All @@ -81,7 +80,7 @@

// OPs definition
#define MATMUL 0x0
#define GEMM 0x1
#define GEMM 0x1
#define ADDMAX 0x2
#define ADDMIN 0x3
#define MULMAX 0x4
Expand All @@ -90,15 +89,15 @@
#define MINMAX 0x7

// GEMM formats
#define Float8 0x0
#define Float16 0x1
#define Float8Alt 0x2
#define Float8 0x0
#define Float16 0x1
#define Float8Alt 0x2
#define Float16Alt 0x3

// FP Formats encoding
#define FP16 0x2
#define FP8 0x3
#define FP16 0x2
#define FP8 0x3
#define FP16ALT 0x4
#define FP8ALT 0x5
#define FP8ALT 0x5

#endif
64 changes: 19 additions & 45 deletions sw/hal_redmule.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,92 +10,66 @@

#include "tensor_dim.h"

/*
*
* For control, generic configuration register layout,
* and job-dependent register map, look at redmule_archi.h
*
*/

/* LOW-LEVEL HAL */
#define REDMULE_ADDR_BASE REDMULE_BASE_ADD
#define REDMULE_ADDR_SPACE 0x00000100

// For all the following functions we use __builtin_pulp_OffsetedWrite and __builtin_pulp_OffsetedRead
// instead of classic load/store because otherwise the compiler is not able to correctly factorize
// the HWPE base in case several accesses are done, ending up with twice more code

#define HWPE_WRITE(value, offset) *(int *)(REDMULE_ADDR_BASE + offset) = value
#define HWPE_READ(offset) *(int *)(REDMULE_ADDR_BASE + offset)

static inline void redmule_x_add_set (unsigned int value) {
static inline void redmule_x_add_set(unsigned int value) {
HWPE_WRITE(value, REDMULE_REG_OFFS + REDMULE_REG_X_PTR);
}

static inline void redmule_w_add_set (unsigned int value) {
static inline void redmule_w_add_set(unsigned int value) {
HWPE_WRITE(value, REDMULE_REG_OFFS + REDMULE_REG_W_PTR);
}

static inline void redmule_z_add_set (unsigned int value) {
static inline void redmule_z_add_set(unsigned int value) {
HWPE_WRITE(value, REDMULE_REG_OFFS + REDMULE_REG_Z_PTR);
}

static inline void redmule_mcfg_set (uint32_t mcfg0, uint32_t mcfg1) {
static inline void redmule_mcfg_set(uint32_t mcfg0, uint32_t mcfg1) {
HWPE_WRITE(mcfg0, REDMULE_REG_OFFS + REDMULE_MCFG0_PTR);
HWPE_WRITE(mcfg1, REDMULE_REG_OFFS + REDMULE_MCFG1_PTR);
}

static inline void redmule_arith_set (uint32_t arith) {
static inline void redmule_arith_set(uint32_t arith) {
HWPE_WRITE(arith, REDMULE_REG_OFFS + REDMULE_ARITH_PTR);
}

static inline void hwpe_trigger_job() {
HWPE_WRITE(0, REDMULE_TRIGGER);
}
static inline void hwpe_trigger_job() { HWPE_WRITE(0, REDMULE_TRIGGER); }

static inline int hwpe_acquire_job() {
return HWPE_READ(REDMULE_ACQUIRE);
}
static inline int hwpe_acquire_job() { return HWPE_READ(REDMULE_ACQUIRE); }

static inline unsigned int hwpe_get_status() {
return HWPE_READ(REDMULE_STATUS);
}
static inline unsigned int hwpe_get_status() { return HWPE_READ(REDMULE_STATUS); }

static inline void hwpe_soft_clear() {
volatile int i;
HWPE_WRITE(0, REDMULE_SOFT_CLEAR);
}

static inline void hwpe_cg_enable() {
return;
}
static inline void hwpe_cg_enable() { return; }

static inline void hwpe_cg_disable() {
return;
}
static inline void hwpe_cg_disable() { return; }

void redmule_cfg (unsigned int x, unsigned int w, unsigned int z,
uint16_t m_size, uint16_t n_size, uint16_t k_size,
uint8_t gemm_op, uint8_t gemm_fmt){
void redmule_cfg(unsigned int x, unsigned int w, unsigned int z, uint16_t m_size, uint16_t n_size,
uint16_t k_size, uint8_t gemm_op, uint8_t gemm_fmt) {

uint32_t mcfg_reg0 = 0;
uint32_t mcfg_reg1 = 0;
uint32_t arith_reg = 0;

mcfg_reg0 = (k_size << 16) |
(m_size << 0);
mcfg_reg0 = (k_size << 16) | (m_size << 0);
mcfg_reg1 = n_size << 0;

arith_reg = (gemm_op << 10) |
(gemm_fmt << 7);
arith_reg = (gemm_op << 10) | (gemm_fmt << 7);

redmule_x_add_set ((unsigned int) x);
redmule_w_add_set ((unsigned int) w);
redmule_z_add_set ((unsigned int) z);
redmule_mcfg_set ((unsigned int) mcfg_reg0,
(unsigned int) mcfg_reg1);
redmule_arith_set ((unsigned int) arith_reg);

redmule_x_add_set((unsigned int)x);
redmule_w_add_set((unsigned int)w);
redmule_z_add_set((unsigned int)z);
redmule_mcfg_set((unsigned int)mcfg_reg0, (unsigned int)mcfg_reg1);
redmule_arith_set((unsigned int)arith_reg);
}

#endif
25 changes: 11 additions & 14 deletions sw/redmule.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,35 @@ int main() {

volatile int errors = 0;
int gold_sum = 0, check_sum = 0;
int i,j;
int i, j;

int offload_id_tmp, offload_id;

// Enable RedMulE
hwpe_cg_enable();

hwpe_soft_clear();

while( ( offload_id_tmp = hwpe_acquire_job() ) < 0);

redmule_cfg ((unsigned int) x,
(unsigned int) w,
(unsigned int) y,
m_size, n_size, k_size,
(uint8_t) GEMM,
(uint8_t) Float16);
while ((offload_id_tmp = hwpe_acquire_job()) < 0)
;

redmule_cfg((unsigned int)x, (unsigned int)w, (unsigned int)y, m_size, n_size, k_size,
(uint8_t)GEMM, (uint8_t)Float16);

// Start RedMulE operation
hwpe_trigger_job();

// Wait for end of computation
asm volatile ("wfi" ::: "memory");
asm volatile("wfi" ::: "memory");

// Disable RedMulE
hwpe_cg_disable();

errors = redmule16_compare_int(y, golden, m_size*k_size/2);
errors = redmule16_compare_int(y, golden, m_size * k_size / 2);

*(int *) 0x80000000 = errors;
*(int *)0x80000000 = errors;

tfp_printf ("Terminated test with %d errors. See you!\n", errors);
tfp_printf("Terminated test with %d errors. See you!\n", errors);

return errors;
}
32 changes: 15 additions & 17 deletions sw/redmule_complex.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ int main() {
uint16_t n_size = N_SIZE;
uint16_t k_size = K_SIZE;

uint32_t x_addr = *(uint32_t *) &x;
uint32_t w_addr = *(uint32_t *) &w;
uint32_t y_addr = *(uint32_t *) &y;
uint32_t x_addr = *(uint32_t *)&x;
uint32_t w_addr = *(uint32_t *)&w;
uint32_t y_addr = *(uint32_t *)&y;
uint32_t cfg_reg0 = ((k_size << 16) | (m_size << 0));
uint32_t cfg_reg1 = (n_size << 0);
asm volatile ("addi t0, %0, 0" :: "r"(x_addr));
asm volatile ("addi t1, %0, 0" :: "r"(w_addr));
asm volatile ("addi t2, %0, 0" :: "r"(y_addr));
asm volatile ("addi t3, %0, 0" :: "r"(cfg_reg0));
asm volatile ("addi t4, %0, 0" :: "r"(cfg_reg1));
asm volatile("addi t0, %0, 0" ::"r"(x_addr));
asm volatile("addi t1, %0, 0" ::"r"(w_addr));
asm volatile("addi t2, %0, 0" ::"r"(y_addr));
asm volatile("addi t3, %0, 0" ::"r"(cfg_reg0));
asm volatile("addi t4, %0, 0" ::"r"(cfg_reg1));

/* mcnfig instruction */
// asm volatile(
Expand All @@ -44,9 +44,8 @@ int main() {
// (0b11100 << 15) | \ /* Rs1 */
// (0x00 << 7) | \ /* Empty */
// (0b0001011 << 0) \n"); /* OpCode */

asm volatile(
".word (0x0 << 25) | \

asm volatile(".word (0x0 << 25) | \
(0b11101 << 20) | \
(0b11100 << 15) | \
(0x00 << 7) | \
Expand All @@ -66,8 +65,7 @@ int main() {
// (0b001 << 7) | \ /* Data format */
// (0b0101011 << 0) \n"); /* OpCode */

asm volatile(
".word (0b00111 << 27) | \
asm volatile(".word (0b00111 << 27) | \
(0b00 << 25) | \
(0b00110 << 20) | \
(0b00101 << 15) | \
Expand All @@ -78,13 +76,13 @@ int main() {
(0b0101011 << 0) \n");

// Wait for end of computation
asm volatile ("wfi" ::: "memory");
asm volatile("wfi" ::: "memory");

errors = redmule16_compare_int(y, golden, m_size*k_size/2);
errors = redmule16_compare_int(y, golden, m_size * k_size / 2);

*(int *) 0x80000000 = errors;
*(int *)0x80000000 = errors;

tfp_printf ("Terminated test with %d errors. See you!\n", errors);
tfp_printf("Terminated test with %d errors. See you!\n", errors);

return errors;
}
Loading

0 comments on commit 54b739f

Please sign in to comment.