Skip to content

Commit

Permalink
snRuntime: Add all-to-all reduction and use in exit function
Browse files Browse the repository at this point in the history
  • Loading branch information
colluca committed Jan 10, 2024
1 parent 7c2f936 commit 7f1fdf3
Show file tree
Hide file tree
Showing 29 changed files with 122 additions and 92 deletions.
1 change: 1 addition & 0 deletions sw/snRuntime/api/sync_decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ typedef struct {

extern volatile uint32_t _snrt_mutex;
extern volatile snrt_barrier_t _snrt_barrier;
extern volatile uint32_t _reduction_result;

inline volatile uint32_t *snrt_mutex();

Expand Down
1 change: 1 addition & 0 deletions sw/snRuntime/src/start.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static inline void snrt_init_libs() { snrt_alloc_init(); }

#ifdef SNRT_CRT0_EXIT
static inline void snrt_exit_default(int exit_code) {
exit_code = snrt_global_all_to_all_reduction(exit_code);
if (snrt_global_core_idx() == 0)
*(snrt_exit_code_destination()) = (exit_code << 1) | 1;
}
Expand Down
1 change: 1 addition & 0 deletions sw/snRuntime/src/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

volatile uint32_t _snrt_mutex;
volatile snrt_barrier_t _snrt_barrier;
volatile uint32_t _reduction_result;

//================================================================================
// Functions
Expand Down
6 changes: 6 additions & 0 deletions sw/snRuntime/src/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ inline void snrt_global_barrier() {
snrt_cluster_hw_barrier();
}

inline uint32_t snrt_global_all_to_all_reduction(uint32_t value) {
__atomic_add_fetch(&_reduction_result, value, __ATOMIC_RELAXED);
snrt_global_barrier();
return _reduction_result;
}

/**
* @brief Generic barrier
*
Expand Down
1 change: 0 additions & 1 deletion sw/tests/event_unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ volatile static uint32_t sum = 0;
static void task(void *arg, uint32_t argc) {
uint32_t arg0 = ((uint32_t *)arg)[0];
__atomic_add_fetch(&sum, arg0, __ATOMIC_RELAXED);
printf("work arg[0] = %d argc = %d\n", arg0, argc);
}

uint32_t run_and_verify_task(uint32_t *arg, uint32_t n_workers) {
Expand Down
9 changes: 5 additions & 4 deletions sw/tests/fp16_comparison_scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include "printf.h"

int main() {
int errs = 40;

if (snrt_is_compute_core()) {
int errs = 40;

uint32_t i8a = 0xFFFF4248; // 3.14
uint32_t i8an = 0xFFFFC248; // -3.14
uint32_t i8b = 0xFFFF3E79; // 1.618
Expand Down Expand Up @@ -210,7 +210,8 @@ int main() {

errs -= (cmp0 == 0x1);
errs -= (cmp1 == 0x1);
}

return errs;
return errs;
}
return 0;
}
9 changes: 5 additions & 4 deletions sw/tests/fp16_comparison_vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include "printf.h"

int main() {
int errs = 64;

if (snrt_is_compute_core()) {
int errs = 64;

uint32_t fa16 = 0x4048F5C3; // 0x4248 3.14
uint32_t fa16n = 0xC048F5C3; // 0xC248 -3.14
uint32_t fb16 = 0x3FCF1AA0; // 0x3E79 1.618
Expand Down Expand Up @@ -287,7 +287,8 @@ int main() {
"vfeq.h %1, ft8, ft0\n"
: "+r"(cmp0));
errs -= (cmp0 == 0xf);
}

return errs;
return errs;
}
return 0;
}
9 changes: 5 additions & 4 deletions sw/tests/fp16_computation_scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <snrt.h>

int main() {
int errs = 33;

if (snrt_is_compute_core()) {
int errs = 33;

uint32_t i_a = 0xFFFF4248; // 3.14
uint32_t i_an = 0xFFFFC248; // -3.14
uint32_t i_b = 0xFFFF3E79; // 1.618
Expand Down Expand Up @@ -317,7 +317,8 @@ int main() {
"feq.h %0, ft3, ft0\n"
: "+r"(res0));
errs -= (res0 == 0x1);
}

return errs;
return errs;
}
return 0;
}
9 changes: 5 additions & 4 deletions sw/tests/fp16_computation_vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include "snrt.h"

int main() {
int errs = 46;

if (snrt_is_compute_core()) {
int errs = 46;

uint32_t i_a = 0x4048F5C3; // 3.14 0
uint32_t i_an = 0xC048F5C3; // -3.14
uint32_t i_b = 0x3FCF1AA0; // 1.618 2
Expand Down Expand Up @@ -563,7 +563,8 @@ int main() {
"vfeq.h %0, ft7, ft0\n"
: "+r"(res0));
errs -= (res0 == 0xf);
}

return errs;
return errs;
}
return 0;
}
9 changes: 5 additions & 4 deletions sw/tests/fp16alt_comparison_scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include "printf.h"

int main() {
int errs = 40;

if (snrt_is_compute_core()) {
int errs = 40;

uint32_t i8a = 0xFFFF4049; // 3.14
uint32_t i8an = 0xFFFFC049; // -3.14
uint32_t i8b = 0xFFFF3FCF; // 1.618
Expand Down Expand Up @@ -213,7 +213,8 @@ int main() {

errs -= (cmp0 == 0x1);
errs -= (cmp1 == 0x1);
}

return errs;
return errs;
}
return 0;
}
9 changes: 5 additions & 4 deletions sw/tests/fp16alt_comparison_vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include "printf.h"

int main() {
int errs = 64;

if (snrt_is_compute_core()) {
int errs = 64;

uint32_t fa16 = 0x4048F5C3; // 0x4248 3.14
uint32_t fa16n = 0xC048F5C3; // 0xC248 -3.14
uint32_t fb16 = 0x3FCF1AA0; // 0x3E79 1.618
Expand Down Expand Up @@ -289,7 +289,8 @@ int main() {
"vfeq.ah %1, ft8, ft0\n"
: "+r"(cmp0));
errs -= (cmp0 == 0xf);
}

return errs;
return errs;
}
return 0;
}
9 changes: 5 additions & 4 deletions sw/tests/fp16alt_computation_scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <snrt.h>

int main() {
int errs = 33;

if (snrt_is_compute_core()) {
int errs = 33;

uint32_t i_a = 0xFFFF4049; // 3.14
uint32_t i_an = 0xFFFFC049; // -3.14
uint32_t i_b = 0xFFFF3FCF; // 1.618
Expand Down Expand Up @@ -319,7 +319,8 @@ int main() {
"feq.ah %0, ft3, ft0\n"
: "+r"(res0));
errs -= (res0 == 0x1);
}

return errs;
return errs;
}
return 0;
}
9 changes: 5 additions & 4 deletions sw/tests/fp16alt_computation_vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <snrt.h>

int main() {
int errs = 46;

if (snrt_is_compute_core()) {
int errs = 46;

uint32_t i_a = 0x4048F5C3; // 3.14 0
uint32_t i_an = 0xC048F5C3; // -3.14
uint32_t i_b = 0x3FCF1AA0; // 1.618 2
Expand Down Expand Up @@ -566,7 +566,8 @@ int main() {
"vfeq.ah %0, ft7, ft0\n"
: "+r"(res0));
errs -= (res0 == 0xf);
}

return errs;
return errs;
}
return 0;
}
9 changes: 5 additions & 4 deletions sw/tests/fp32_comparison_scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include "printf.h"

int main() {
int errs = 40;

if (snrt_is_compute_core()) {
int errs = 40;

uint32_t i8a = 0x4048F5C3; // 3.14
uint32_t i8an = 0xC048F5C3; // -3.14
uint32_t i8b = 0x3FCF1AA0; // 1.618
Expand Down Expand Up @@ -210,7 +210,8 @@ int main() {

errs -= (cmp0 == 0x1);
errs -= (cmp1 == 0x1);
}

return errs;
return errs;
}
return 0;
}
9 changes: 5 additions & 4 deletions sw/tests/fp32_comparison_vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include "printf.h"

int main() {
int errs = 64;

if (snrt_is_compute_core()) {
int errs = 64;

uint32_t fa32 = 0x4048F5C3; // 0x4248 3.14
uint32_t fa32n = 0xC048F5C3; // 0xC248 -3.14
uint32_t fb32 = 0x3FCF1AA0; // 0x3E79 1.618
Expand Down Expand Up @@ -283,7 +283,8 @@ int main() {
"vfeq.s %1, ft8, ft0\n"
: "+r"(cmp0));
errs -= (cmp0 == 3);
}

return errs;
return errs;
}
return 0;
}
9 changes: 5 additions & 4 deletions sw/tests/fp32_computation_scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <snrt.h>

int main() {
int errs = 33;

if (snrt_is_compute_core()) {
int errs = 33;

uint32_t i_a = 0x4048F5C3; // 3.14
uint32_t i_an = 0xC048F5C3; // -3.14
uint32_t i_b = 0x3FCF1AA0; // 1.618
Expand Down Expand Up @@ -317,7 +317,8 @@ int main() {
"feq.s %0, ft3, ft0\n"
: "+r"(res0));
errs -= (res0 == 0x1);
}

return errs;
return errs;
}
return 0;
}
9 changes: 5 additions & 4 deletions sw/tests/fp32_computation_vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <snrt.h>

int main() {
int errs = 46;

if (snrt_is_compute_core()) {
int errs = 46;

uint32_t i_a = 0x4048F5C3; // 3.14 0
uint32_t i_an = 0xC048F5C3; // -3.14
uint32_t i_b = 0x3FCF1AA0; // 1.618 2
Expand Down Expand Up @@ -531,7 +531,8 @@ int main() {
"vfeq.s %0, ft7, ft0\n"
: "+r"(res0));
errs -= (res0 == 0x3);
}

return errs;
return errs;
}
return 0;
}
9 changes: 5 additions & 4 deletions sw/tests/fp32_conversions_scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
typedef float v2s __attribute__((vector_size(8)));

int main() {
int errs = 48;

if (snrt_is_compute_core()) {
int errs = 48;

unsigned int res_cvt0 = 0;
unsigned int res_cvt1 = 0;

Expand Down Expand Up @@ -480,7 +480,8 @@ int main() {
: "+r"(res_cvt0), "+r"(res_cvt1));
errs -= (res_cvt0 == 0x1);
errs -= (res_cvt1 == 0x1);
}

return errs;
return errs;
}
return 0;
}
7 changes: 4 additions & 3 deletions sw/tests/fp64_conversions_scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
typedef float v2s __attribute__((vector_size(8)));

int main() {
int errs = 48;

if (snrt_is_compute_core()) {
int errs = 48;

unsigned int res_cvt0 = 0;
unsigned int res_cvt1 = 0;

Expand Down Expand Up @@ -495,7 +495,8 @@ int main() {
"+f"(fvalue_negative));
errs -= (res_cvt0 == 0x1);
errs -= (res_cvt1 == 0x1);
}

return errs;
}
return 0;
}
9 changes: 5 additions & 4 deletions sw/tests/fp8_comparison_scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "snrt.h"

int main() {
int errs = 40;

if (snrt_is_compute_core()) {
int errs = 40;

uint32_t i8a = 0xFFFFFF42; // 3.14
uint32_t i8an = 0xFFFFFFC2; // -3.14
uint32_t i8b = 0xFFFFFF3E; // 1.618
Expand Down Expand Up @@ -209,7 +209,8 @@ int main() {

errs -= (cmp0 == 0x1);
errs -= (cmp1 == 0x1);
}

return errs;
return errs;
}
return 0;
}
Loading

0 comments on commit 7f1fdf3

Please sign in to comment.