Skip to content

Commit

Permalink
Merge pull request #285 from gwsystems/tests-makefile-cleanup
Browse files Browse the repository at this point in the history
build: Makefile cleanup
  • Loading branch information
bushidocodes authored Dec 5, 2021
2 parents 79ca1f0 + 1f25f3d commit b841889
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 242 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
uses: actions/cache@v2
with:
path: ./runtime/bin/gocr_wasm.so
key: ${{ runner.os }}-gocr2-${{ hashFiles('./runtime/tests/gocr/**', './runtime/compiletime/**') }}
key: ${{ runner.os }}-gocr2-${{ hashFiles('./runtime/tests/Makefile', './runtime/tests/gocr/**', './runtime/compiletime/**', './runtime/compiletime/memory/**') }}
if: success() || failure()
- name: Hyde
run: |
Expand Down Expand Up @@ -138,7 +138,7 @@ jobs:
uses: actions/cache@v2
with:
path: ./runtime/bin/ekf_wasm.so
key: ${{ runner.os }}-gocr2-${{ hashFiles('./runtime/tests/TinyEKF/**', './runtime/compiletime/**') }}
key: ${{ runner.os }}-gocr2-${{ hashFiles('./runtime/tests/Makefile', './runtime/tests/TinyEKF/**', './runtime/compiletime/**', './runtime/compiletime/memory/**') }}
if: success() || failure()
- name: EKF one iteration
run: |
Expand Down
3 changes: 2 additions & 1 deletion runtime/compiletime/instr.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <assert.h>
#include <math.h>
#include <types.h>

#include "types.h"

#define CHAR_BIT 8

Expand Down
3 changes: 3 additions & 0 deletions runtime/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.wasm
*.bc
*.so
122 changes: 73 additions & 49 deletions runtime/tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,60 +1,84 @@
include Makefile.inc
AWSMCC=awsm
CC=clang

TESTS=fibonacci empty empty
OPTFLAGS=-O3 -flto

TESTSRT=$(TESTS:%=%_rt)
# Compiletime Components to link into *.so
SLEDGE_BASE_DIR=../../
SLEDGE_RT_DIR=${SLEDGE_BASE_DIR}/runtime/
SLEDGE_COMPILETIME_INC=${SLEDGE_RT_DIR}/include
SLEDGE_COMPILETIME_SRC=${SLEDGE_RT_DIR}/compiletime/instr.c ${SLEDGE_RT_DIR}/compiletime/memory/64bit_nix.c

.PHONY: all
all: rttests tinyekf cifar10 gocr sod
@echo "Test Compilation done!"
ALL=fibonacci empty ekf cifar10 gocr lpd resize
ALL_COPY_DEST=$(ALL:%=../../runtime/bin/%_wasm.so)

.PHONY: rttests
rttests: $(TESTSRT)
.PHONY: all
all: $(ALL_COPY_DEST)

.PHONY: clean
clean:
@echo "Cleaning Test Applications"
@rm -rf ${TMP_DIR}
@make clean -C ./fibonacci
@make clean -C ./empty
@make clean -C ./TinyEKF/extras/c/ -f wasm.mk
@make clean -C ./CMSIS_5_NN/ -f Makefile
@make clean -C ./gocr/src/ -f wasm.mk
@make clean -C ./sod/
@rm -f ../../runtime/bin/*.so

fibonacci.wasm:
@make fibonacci.wasm -C ./fibonacci
@cp ./fibonacci/fibonacci.wasm fibonacci.wasm

empty.wasm:
@make empty.wasm -C ./empty
@cp ./empty/empty.wasm empty.wasm

ekf.wasm:
@make gps_ekf_fn.wasm -C ./TinyEKF/extras/c/ -f wasm.mk
@cp ./TinyEKF/extras/c/gps_ekf_fn.wasm ekf.wasm

cifar10.wasm:
@make cifar10.wasm -C ./CMSIS_5_NN/ -f Makefile
@cp ./CMSIS_5_NN/cifar10.wasm cifar10.wasm

gocr.wasm:
@make gocr.wasm -C ./gocr/src/ -f wasm.mk
@cp ./gocr/src/gocr.wasm gocr.wasm

lpd.wasm:
@make dir license_plate_detection.wasm -C ./sod/
@cp ./sod/bin/license_plate_detection.wasm lpd.wasm

resize.wasm:
@make dir resize_image.wasm -C ./sod/
@cp ./sod/bin/resize_image.wasm resize.wasm

%.bc: %.wasm
${AWSMCC} --inline-constant-globals --runtime-globals $^ -o $@

%_wasm.so: %.bc ${SLEDGE_COMPILETIME_SRC}
${CC} --shared -fPIC ${OPTFLAGS} -I${SLEDGE_COMPILETIME_INC} $^ -o $@

../../runtime/bin/%.so: %.so
cp $^ $@

.PHONY: fibonacci.install
fibonacci.install: ../../runtime/bin/fibonacci_wasm.so

.PHONY: empty.install
empty.install: ../../runtime/bin/empty_wasm.so

.PHONY: ekf.install
ekf.install: ../../runtime/bin/ekf_wasm.so

.PHONY: cifar10.install
cifar10.install: ../../runtime/bin/cifar10_wasm.so

.PHONY: gocr.install
gocr.install: ../../runtime/bin/gocr_wasm.so

.PHONY: tinyekf
tinyekf:
@echo "Making and Installing tinyekf"
@make gps_ekf_fn.so -C ./TinyEKF/extras/c/ -f wasm.mk
@cp ./TinyEKF/extras/c/gps_ekf_fn.so ${SLEDGE_BIN_DIR}/ekf_wasm.so

.PHONY: cifar10
cifar10:
@echo "Making and Installing cifar10"
@make cifar10.so -C ./CMSIS_5_NN/ -f Makefile
@cp ./CMSIS_5_NN/cifar10.so ${SLEDGE_BIN_DIR}/cifar10_wasm.so

.PHONY: gocr
gocr:
@echo "Making and Installing gocr"
@make gocr.so -C ./gocr/src/ -f wasm.mk
@cp ./gocr/src/gocr.so ${SLEDGE_BIN_DIR}/gocr_wasm.so

.PHONY: sod
sod:
@echo "Making and Installing license_plate_detection and image_resize"
@make dir samples.so -C ./sod/
@cp ./sod/bin/license_plate_detection.so ${SLEDGE_BIN_DIR}/lpd_wasm.so
@cp ./sod/bin/resize_image.so ${SLEDGE_BIN_DIR}/resize_wasm.so

%_rt:
@mkdir -p ${TMP_DIR}
# Compile the wasm file
@echo "Compiling $(@:%_rt=%)"
${WASMCC} ${$(@:%_rt=%)_CFLAGS} ${WASMCFLAGS} ${OPTFLAGS} $(@:%_rt=%)/*.c $(AWSM_DUMMY) -o ${TMP_DIR}/$(@:%_rt=%).wasm

# Compile the *.bc file

${AWSM_NAME} --inline-constant-globals --runtime-globals ${TMP_DIR}/$(@:%_rt=%).wasm -o ${TMP_DIR}/$(@:%_rt=%).bc
# Compile the *.so file
${CC} --shared -fPIC ${OPTFLAGS} -I${SLEDGE_RT_INC} -D${USE_MEM} ${TMP_DIR}/$(@:%_rt=%).bc ${SLEDGE_MEMC} ${SLEDGE_WASMISA} -o ${TMP_DIR}/$(@:%_rt=%)_wasm.so
# Copy the *.so file to the binary directory
@cp ${TMP_DIR}/$(@:%_rt=%)_wasm.so ${SLEDGE_BIN_DIR}
# @rm -rf ${TMP_DIR}
.PHONY: lpd.install
lpd.install: ../../runtime/bin/lpd_wasm.so

.PHONY: resize.install
resize.install: ../../runtime/bin/resize_wasm.so
42 changes: 0 additions & 42 deletions runtime/tests/Makefile.inc

This file was deleted.

2 changes: 1 addition & 1 deletion runtime/tests/TinyEKF
12 changes: 12 additions & 0 deletions runtime/tests/empty/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
WASMCC=wasm32-unknown-unknown-wasm-clang
OPTFLAGS=-O3 -flto
WASMLINKFLAGS=-Wl,-z,stack-size=524288,--allow-undefined,--no-threads,--stack-first,--no-entry,--export-all,--export=main,--export=dummy
WASMCFLAGS=${WASMLINKFLAGS} -nostartfiles

all: empty.wasm

clean:
rm -rf empty.wasm

empty.wasm: *.c
${WASMCC} ${WASMCFLAGS} ${OPTFLAGS} $^ -o $@
15 changes: 15 additions & 0 deletions runtime/tests/empty/wasmception_hack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// !!! HACK ALERT !!!
// We need the __init_libc symbol in the output executable (so the runtime can initialize libc)
// We can't directly export it since it's in a linked library
// Thus we export a dummy function that uses it, forcing it to be included


#define IMPORT __attribute__((visibility("default")))
#define EXPORT __attribute__((visibility("default")))

IMPORT void __init_libc(char **, char *);
EXPORT void
dummy()
{
__init_libc(0, 0);
}
12 changes: 12 additions & 0 deletions runtime/tests/fibonacci/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
WASMCC=wasm32-unknown-unknown-wasm-clang
OPTFLAGS=-O3 -flto
WASMLINKFLAGS=-Wl,-z,stack-size=524288,--allow-undefined,--no-threads,--stack-first,--no-entry,--export-all,--export=main,--export=dummy
WASMCFLAGS=${WASMLINKFLAGS} -nostartfiles

all: fibonacci.wasm

clean:
rm -rf fibonacci.wasm

fibonacci.wasm: *.c
${WASMCC} ${WASMCFLAGS} ${OPTFLAGS} $^ -o $@
44 changes: 0 additions & 44 deletions runtime/tests/fibonacci/get_time.h

This file was deleted.

18 changes: 8 additions & 10 deletions runtime/tests/fibonacci/main.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <stdio.h>
// #include "get_time.h"
unsigned long int
fib(unsigned long int n)
#include <stdint.h>

uint32_t
fib(uint32_t n)
{
if (n <= 1) return n;
return fib(n - 1) + fib(n - 2);
Expand All @@ -10,13 +11,10 @@ fib(unsigned long int n)
int
main(int argc, char **argv)
{
unsigned long n = 0, r;
scanf("%lu", &n);
// unsigned long long st = get_time(), en;
r = fib(n);
// en = get_time();
printf("%lu\n", r);
uint32_t n = 0;
scanf("%u", &n);

// print_time(st, en);
uint32_t result = fib(n);
printf("%u\n", result);
return 0;
}
32 changes: 0 additions & 32 deletions runtime/tests/fibonacci/run_fib.sh

This file was deleted.

15 changes: 15 additions & 0 deletions runtime/tests/fibonacci/wasmception_hack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// !!! HACK ALERT !!!
// We need the __init_libc symbol in the output executable (so the runtime can initialize libc)
// We can't directly export it since it's in a linked library
// Thus we export a dummy function that uses it, forcing it to be included


#define IMPORT __attribute__((visibility("default")))
#define EXPORT __attribute__((visibility("default")))

IMPORT void __init_libc(char **, char *);
EXPORT void
dummy()
{
__init_libc(0, 0);
}
Loading

0 comments on commit b841889

Please sign in to comment.