Skip to content

Commit

Permalink
Modified for WebAssembly
Browse files Browse the repository at this point in the history
  • Loading branch information
NSKernel committed Nov 5, 2023
1 parent 7c0e8fc commit 9f77621
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 2,573 deletions.
2 changes: 0 additions & 2 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
all:
@$(MAKE) -C benchmark all
@$(MAKE) -C hello all
@$(MAKE) -C mnist all

clean:
@$(MAKE) -C benchmark clean
@$(MAKE) -C hello clean
@$(MAKE) -C mnist clean
13 changes: 8 additions & 5 deletions examples/benchmark/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# Makefile for application
#

WASI_SDK_PATH ?= /home/nskernel/wasi/wasi-sdk-20.0
CROSS_COMPILE ?=

AS := $(CROSS_COMPILE)gcc -x assembler-with-cpp
CC := $(CROSS_COMPILE)gcc
CC := $(WASI_SDK_PATH)/bin/clang
CXX := $(CROSS_COMPILE)g++
LD := $(CROSS_COMPILE)ld
AR := $(CROSS_COMPILE)ar
Expand All @@ -14,9 +15,9 @@ OD := $(CROSS_COMPILE)objdump
RM := rm -fr

ASFLAGS := -g -ggdb -Wall -O3
CFLAGS := -g -ggdb -Wall -O3
CFLAGS := $(TARGET) -D_WASI_EMULATED_PROCESS_CLOCKS --sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot/
CXXFLAGS := -g -ggdb -Wall -O3
LDFLAGS :=
LDFLAGS := $(TARGET) -Wl,-lc -Wl,--allow-undefined -Wl,--export=main -Wl,--export=__wasm_call_ctors -Wl,--export=__heap_base,--export=__data_end
OCFLAGS := -v -O binary
ODFLAGS :=
MCFLAGS :=
Expand Down Expand Up @@ -45,13 +46,15 @@ OBJDIRS := $(patsubst %, %, $(SRCDIRS))
NAME := benchmark
VPATH := $(OBJDIRS)

LIBOBJS := $(foreach dir, ../../src ../../src/default, $(wildcard $(dir)/*.o))

.PHONY: all clean

all : $(NAME)

$(NAME) : $(OBJS)
$(NAME) : $(OBJS) $(LIBOBJS)
@echo [LD] Linking $@
@$(CC) $(LDFLAGS) $(LIBDIRS) $^ -o $@ $(LIBS) -static
@$(CC) $(LDFLAGS) $(LIBDIRS) $^ -o $@ -static

$(SOBJS) : %.o : %.S
@echo [AS] $<
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static void profiler_dump(struct hmap_t * m, int count)
{
p = (struct profiler_t *)e->value;
total += p->elapsed;
printf("%-32s %ld %12.3f(us)\r\n", e->key, p->count, (p->count > 0) ? ((double)p->elapsed / 1000.0f) / (double)p->count : 0);
printf("%-32s %lld %12.3f(us)\r\n", e->key, p->count, (p->count > 0) ? ((double)p->elapsed / 1000.0f) / (double)p->count : 0);
}
if(count > 0)
{
Expand Down
13 changes: 8 additions & 5 deletions examples/hello/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
# Makefile for application
#

WASI_SDK_PATH ?= /home/nskernel/wasi/wasi-sdk-20.0
CROSS_COMPILE ?=

AS := $(CROSS_COMPILE)gcc -x assembler-with-cpp
CC := $(CROSS_COMPILE)gcc
CC := $(WASI_SDK_PATH)/bin/clang
CXX := $(CROSS_COMPILE)g++
LD := $(CROSS_COMPILE)ld
AR := $(CROSS_COMPILE)ar
Expand All @@ -14,9 +15,9 @@ OD := $(CROSS_COMPILE)objdump
RM := rm -fr

ASFLAGS := -g -ggdb -Wall -O3
CFLAGS := -g -ggdb -Wall -O3
CFLAGS := $(TARGET) -D_WASI_EMULATED_PROCESS_CLOCKS --sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot/
CXXFLAGS := -g -ggdb -Wall -O3
LDFLAGS :=
LDFLAGS := $(TARGET) -Wl,-lc -Wl,--allow-undefined -Wl,--export=main -Wl,--export=__wasm_call_ctors -Wl,--export=__heap_base,--export=__data_end
OCFLAGS := -v -O binary
ODFLAGS :=
MCFLAGS :=
Expand Down Expand Up @@ -45,13 +46,15 @@ OBJDIRS := $(patsubst %, %, $(SRCDIRS))
NAME := hello
VPATH := $(OBJDIRS)

LIBOBJS := $(foreach dir, ../../src ../../src/default, $(wildcard $(dir)/*.o))

.PHONY: all clean

all : $(NAME)

$(NAME) : $(OBJS)
$(NAME) : $(OBJS) $(LIBOBJS)
@echo [LD] Linking $@
@$(CC) $(LDFLAGS) $(LIBDIRS) $^ -o $@ $(LIBS) -static
@$(CC) $(LDFLAGS) $(LIBDIRS) $^ -o $@ -static

$(SOBJS) : %.o : %.S
@echo [AS] $<
Expand Down
4 changes: 2 additions & 2 deletions examples/hello/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2254,7 +2254,7 @@ int main(int argc, char * argv[])
/*
* Dump onnx context
*/
onnx_context_dump(ctx, 0);
//onnx_context_dump(ctx, 0);

/*
* Get input tensor by name
Expand All @@ -2274,7 +2274,7 @@ int main(int argc, char * argv[])
/*
* Dump input tensor
*/
onnx_tensor_dump(input, 1);
//onnx_tensor_dump(input, 1);

/*
* Run inference
Expand Down
19 changes: 0 additions & 19 deletions examples/mnist/.gitignore

This file was deleted.

71 changes: 0 additions & 71 deletions examples/mnist/Makefile

This file was deleted.

Loading

0 comments on commit 9f77621

Please sign in to comment.