Skip to content

Commit

Permalink
Merge pull request #9 from ucb-bar/ci
Browse files Browse the repository at this point in the history
Add FAST CI versions of tests
  • Loading branch information
hngenc authored Dec 3, 2020
2 parents 7d15716 + 3cdddd9 commit 2973bee
Show file tree
Hide file tree
Showing 16 changed files with 312 additions and 56 deletions.
34 changes: 34 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ abs_top_srcdir := @abs_top_srcdir@
XLEN := @XLEN@
RISCVTOOLS := @RISCVTOOLS@
ROCC = examples
RUNNER := "spike --extension=gemmini "

.PHONY: all bareMetalC clean imagenet mlps
all: bareMetalC imagenet mlps
Expand Down Expand Up @@ -31,3 +32,36 @@ clean:
$(MAKE) -C imagenet -f $(abs_top_srcdir)/imagenet/Makefile abs_top_srcdir=$(abs_top_srcdir) PREFIX=$(ROCC)-imagenet clean
$(MAKE) -C mlps -f $(abs_top_srcdir)/mlps/Makefile abs_top_srcdir=$(abs_top_srcdir) PREFIX=$(ROCC)-mlps clean

test-baremetal-bareMetalC:
make -C bareMetalC \
-f $(abs_top_srcdir)/bareMetalC/Makefile \
TARGET_MAKEFILE=$(abs_top_srcdir)/bareMetalC/Makefile \
abs_top_srcdir=$(abs_top_srcdir) \
src_dir=$(abs_top_srcdir)/bareMetalC \
XLEN=$(XLEN) \
PREFIX=$(ROCC)-bareMetalC \
RISCVTOOLS=$(RISCVTOOLS) \
RUNNER=$(RUNNER) \
run-baremetal

test-baremetal: test-baremetal-bareMetalC
make -C mlps \
-f $(abs_top_srcdir)/mlps/Makefile \
TARGET_MAKEFILE=$(abs_top_srcdir)/mlps/Makefile \
abs_top_srcdir=$(abs_top_srcdir) \
src_dir=$(abs_top_srcdir)/mlps \
XLEN=$(XLEN) \
PREFIX=$(ROCC)-mlps \
RISCVTOOLS=$(RISCVTOOLS) \
RUNNER=$(RUNNER) \
run-baremetal
make -C imagenet \
-f $(abs_top_srcdir)/imagenet/Makefile \
TARGET_MAKEFILE=$(abs_top_srcdir)/imagenet/Makefile \
abs_top_srcdir=$(abs_top_srcdir) \
src_dir=$(abs_top_srcdir)/imagenet \
XLEN=$(XLEN) \
PREFIX=$(ROCC)-imagenet \
RISCVTOOLS=$(RISCVTOOLS) \
RUNNER=$(RUNNER) \
run-baremetal
14 changes: 14 additions & 0 deletions bareMetalC/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ tests = \
template

tests_baremetal = $(tests:=-baremetal)

ifeq ($(findstring spike,$(RUNNER)),spike)
# Currently don't support conv or conv-with-pool on spike
runs_baremetal = $(addsuffix .run,$(filter-out conv-baremetal conv_with_pool-baremetal,$(tests_baremetal)))
else
# Don't run very long benchmarks for RTL sim
runs_baremetal = $(addsuffix .run,$(filter-out tiled_matmul_cpu-baremetal tiled_matmul_option-baremetal,$(tests_baremetal)))
endif

ifdef BAREMETAL_ONLY
tests_linux =
else
Expand Down Expand Up @@ -77,5 +86,10 @@ vpath %.c $(src_dir)
%-linux: %.c $(GEMMINI_HEADERS)
$(CC_LINUX) $(CFLAGS) $< $(LFLAGS) -o $@

run-baremetal: $(runs_baremetal)

%-baremetal.run: %-baremetal
$(RUNNER)$(abs_top_srcdir)/build/bareMetalC/$^

junk += $(tests_baremetal) $(tests_linux)

40 changes: 36 additions & 4 deletions bareMetalC/conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@
#define PADDING 1
#define STRIDE 2
#else
#define BATCH_SIZE 3
#ifdef FAST
#define IN_DIM 9
#define IN_CHANNELS 5
#define OUT_CHANNELS 7
#else
#define IN_DIM 23
#define IN_CHANNELS 17
#define OUT_CHANNELS 31
#endif

#define BATCH_SIZE 3
#define KERNEL_DIM 3
#define PADDING 1
#define STRIDE 2

#endif

#define NO_BIAS false
Expand Down Expand Up @@ -112,16 +120,26 @@ bool vec_is_equal(elem_t * a, elem_t * b, int len) {
}

void init_random(elem_t * buf, int len) {
elem_t i = 0;
for (elem_t * ptr = buf; ptr < buf + len; ptr++) {
// *ptr = (rand() % 32) - 16;
*ptr = (rand() % 5) - 2;
#ifdef FAST
*ptr = 1;
#else
*ptr = (rand() % 5) - 2;
#endif
}
}

void init_random_acc(acc_t * buf, int len) {
elem_t i = 0;
for (acc_t * ptr = buf; ptr < buf + len; ptr++) {
// *ptr = (rand() % 32) - 16;
*ptr = (rand() % 5) - 2;
#ifdef FAST
*ptr = 1;
#else
*ptr = (rand() % 5) - 2;
#endif
}
}

Expand Down Expand Up @@ -164,6 +182,7 @@ int main() {

printf("CPU conv...\n");
uint64_t start_cpu = read_cycles();
#ifndef FAST
conv(BATCH_SIZE, IN_CHANNELS, IN_DIM,
OUT_CHANNELS, KERNEL_DIM,
OUT_DIM,
Expand All @@ -172,6 +191,7 @@ int main() {
weights,
bias,
output);
#endif
uint64_t end_cpu = read_cycles();
printf("CPU conv took %llu cycles\n", end_cpu - start_cpu);

Expand Down Expand Up @@ -204,7 +224,20 @@ int main() {

assert(sizeof(output_mat) == sizeof(output));

#ifdef FAST
bool success = true;
for (int orow = 0; orow < BATCH_SIZE * OUT_DIM * OUT_DIM; orow++) {
for (int ocol = 0; ocol < OUT_CHANNELS; ocol++) {
elem_t v = output_mat[orow][ocol];
if (v != 21 && v != 31 && v != 46) {
success = false;
break;
}
}
}
#else
bool success = vec_is_equal(&output[0][0][0][0], &output_mat[0][0], sizeof(output) / sizeof(elem_t));
#endif

if (!success) {
// return 1;
Expand Down Expand Up @@ -294,4 +327,3 @@ int main() {

return 0;
}

36 changes: 33 additions & 3 deletions bareMetalC/conv_with_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@

#else

#define BATCH_SIZE 3
#ifdef FAST
#define IN_DIM 9
#define IN_CHANNELS 5
#define OUT_CHANNELS 7
#else
#define IN_DIM 23
#define IN_CHANNELS 17
#define OUT_CHANNELS 31
#endif

#define BATCH_SIZE 3
#define KERNEL_DIM 3
#define PADDING 1
#define STRIDE 2
Expand All @@ -46,7 +53,7 @@

#define POOL_OUT_DIM ((OUT_DIM + 2*POOL_PADDING - POOL_SIZE) / POOL_STRIDE + 1)

#define NO_POOL false
#define NO_POOL false

#if NO_POOL == true && !(POOL_SIZE == 1 && POOL_STRIDE == 1 && POOL_PADDING == 0)
#error NO_POOL is not set correctly
Expand Down Expand Up @@ -274,16 +281,26 @@ bool vec_is_equal(elem_t * a, elem_t * b, int len) {
}

void init_random(elem_t * buf, int len) {
elem_t i = 0;
for (elem_t * ptr = buf; ptr < buf + len; ptr++) {
// *ptr = (rand() % 32) - 16;
#ifdef FAST
*ptr = 1;
#else
*ptr = (rand() % 5) - 2;
#endif
}
}

void init_random_acc(acc_t * buf, int len) {
elem_t i = 0;
for (acc_t * ptr = buf; ptr < buf + len; ptr++) {
// *ptr = (rand() % 32) - 16;
#ifdef FAST
*ptr = 1;
#else
*ptr = (rand() % 5) - 2;
#endif
}
}

Expand Down Expand Up @@ -327,6 +344,7 @@ int main() {
else
init_random_acc(&bias[0], sizeof(bias) / sizeof(acc_t));

#ifndef FAST
printf("CPU conv...\n");
uint64_t start_cpu = read_cycles();
conv(BATCH_SIZE, IN_CHANNELS, IN_DIM,
Expand All @@ -350,6 +368,7 @@ int main() {
printf("CPU pool took %llu cycles\n", end_cpu_pool - start_cpu_pool);

printf("CPU conv+pool took %llu cycles\n", end_cpu_pool - start_cpu_pool + end_cpu - start_cpu);
#endif

static elem_t weights_mat[PATCH_SIZE][OUT_CHANNELS];
static elem_t output_mat[N_PATCHES][OUT_CHANNELS];
Expand Down Expand Up @@ -388,7 +407,19 @@ int main() {

assert(sizeof(pool_output_mat) == sizeof(pool_output));

#ifdef FAST
bool success = true;
for (int orow = 0; orow < BATCH_SIZE * POOL_OUT_DIM * POOL_OUT_DIM; orow++) {
for (int ocol = 0; ocol < OUT_CHANNELS; ocol++) {
if (pool_output_mat[orow][ocol] != 46) {
success = false;
break;
}
}
}
#else
bool success = vec_is_equal(&pool_output[0][0][0][0], &pool_output_mat[0][0], sizeof(pool_output) / sizeof(elem_t));
#endif

if (!success) {
// return 1;
Expand Down Expand Up @@ -500,4 +531,3 @@ int main() {

return 0;
}

Loading

0 comments on commit 2973bee

Please sign in to comment.