Compare commits
10 Commits
1b875f6d70
...
d477d24d39
Author | SHA1 | Date |
---|---|---|
yanenshuo | d477d24d39 | 3 months ago |
Sean McBride | 2f57d46df4 | 4 years ago |
Sean McBride | 9728147fe3 | 4 years ago |
Sean McBride | 3bbad277b3 | 4 years ago |
Sean McBride | 3060d01025 | 4 years ago |
Sean McBride | 8df9f4d8a3 | 4 years ago |
Sean McBride | 5d9da0b611 | 4 years ago |
Sean McBride | 7780166d30 | 4 years ago |
phani | 8f2ad3f048 | 5 years ago |
phani | 3ded1584df | 5 years ago |
@ -1,73 +1,97 @@
|
|||||||
BASE_DIR=../
|
BASE_DIR=../../../
|
||||||
include Makefile.wasm.inc
|
|
||||||
|
AWSM_CC=awsm
|
||||||
# SOD does not generally require a Makefile to build. Just drop sod.c and its accompanying
|
|
||||||
# header files on your source tree and you are done.
|
NATIVE_CC=clang
|
||||||
NCC = clang
|
NATIVE_CFLAGS = -I. -DCPU_FREQ=3600 -O3 -lm -DSOD_DISABLE_CNN -DLIBCOX_DISABLE_DISK_IO
|
||||||
NCFLAGS = -I. -DCPU_FREQ=3600 -O3 -lm -DSOD_DISABLE_CNN -DLIBCOX_DISABLE_DISK_IO
|
|
||||||
WCFLAGS = -DWASM -I. -DSOD_DISABLE_CNN -lm -DLIBCOX_DISABLE_DISK_IO
|
OPTFLAGS=-O3 -flto
|
||||||
|
|
||||||
#sod: sod.c
|
WASM_CC=wasm32-unknown-unknown-wasm-clang
|
||||||
# $(CC) sod.c samples/cnn_face_detection.c -o sod_face_detect -I. $(CFLAGS)
|
WASM_LDFLAGS=-Wl,-z,stack-size=524288,--allow-undefined,--no-threads,--stack-first,--no-entry,--export-all,--export=main,--export=dummy
|
||||||
|
WASM_CFLAGS=${WASM_LDFLAGS} -nostartfiles -DWASM -I. -DSOD_DISABLE_CNN -lm -DLIBCOX_DISABLE_DISK_IO
|
||||||
EXT = out
|
|
||||||
WEXT = wout
|
MEMC_64=64bit_nix.c
|
||||||
|
|
||||||
SAMPLES = resize_image \
|
# for aWsm compiler
|
||||||
license_plate_detection
|
# Currently only uses wasmception backing
|
||||||
|
AWSM_DIR=${BASE_DIR}/awsm/
|
||||||
#SAMPLES = batch_img_loading \
|
AWSM_RT_DIR=${AWSM_DIR}/runtime/
|
||||||
# blob_detection \
|
AWSM_RT_MEM=${AWSM_RT_DIR}/memory/
|
||||||
# canny_edge_detection \
|
AWSM_RT_LIBC=${AWSM_RT_DIR}/libc/wasmception_backing.c
|
||||||
# cnn_coco \
|
AWSM_RT_ENV=${AWSM_RT_DIR}/libc/env.c
|
||||||
# cnn_face_detection \
|
AWSM_RT_RT=${AWSM_RT_DIR}/runtime.c
|
||||||
# cnn_object_detection \
|
AWSM_RT_MEMC=${AWSM_RT_MEM}/${MEMC_64}
|
||||||
# cnn_voc \
|
DUMMY=${AWSM_DIR}/code_benches/dummy.c
|
||||||
# crop_image \
|
|
||||||
# dilate_image \
|
# for SLEdge serverless runtime
|
||||||
# erode_image \
|
SLEDGE_RT_DIR=${BASE_DIR}/runtime/
|
||||||
# grayscale_image \
|
SLEDGE_RT_INC=${SLEDGE_RT_DIR}/include/
|
||||||
# hilditch_thin \
|
SLEDGE_MEMC=${SLEDGE_RT_DIR}/compiletime/memory/${MEMC_64}
|
||||||
# hough_lines_detection \
|
|
||||||
# license_plate_detection \
|
SLEDGE_BIN_DIR=${SLEDGE_RT_DIR}/bin/
|
||||||
# minutiae \
|
WASMISA=${SLEDGE_RT_DIR}/compiletime/instr.c
|
||||||
# otsu_image \
|
|
||||||
# realnet_face_detection \
|
SAMPLES = resize_image \
|
||||||
# realnet_face_detection_embedded \
|
license_plate_detection
|
||||||
# realnet_train_model \
|
|
||||||
# resize_image \
|
#SAMPLES = batch_img_loading \
|
||||||
# rnn_text_gen \
|
# blob_detection \
|
||||||
# rotate_image \
|
# canny_edge_detection \
|
||||||
# sobel_operator_img
|
# cnn_coco \
|
||||||
|
# cnn_face_detection \
|
||||||
SAMPLESOUT = $(SAMPLES:%=%.$(EXT))
|
# cnn_object_detection \
|
||||||
SAMPLESWOUT = $(SAMPLES:%=%.$(WEXT))
|
# cnn_voc \
|
||||||
|
# crop_image \
|
||||||
all: clean dir copy
|
# dilate_image \
|
||||||
|
# erode_image \
|
||||||
native: samples
|
# grayscale_image \
|
||||||
wasm: samples.wasm
|
# hilditch_thin \
|
||||||
# samples.wasm
|
# hough_lines_detection \
|
||||||
# samples
|
# license_plate_detection \
|
||||||
|
# minutiae \
|
||||||
dir:
|
# otsu_image \
|
||||||
mkdir -p bin/
|
# realnet_face_detection \
|
||||||
|
# realnet_face_detection_embedded \
|
||||||
copy:
|
# realnet_train_model \
|
||||||
cp samples/*.png bin/
|
# resize_image \
|
||||||
cp samples/*.jpg bin/
|
# rnn_text_gen \
|
||||||
|
# rotate_image \
|
||||||
samples: $(SAMPLESOUT)
|
# sobel_operator_img
|
||||||
|
|
||||||
samples.wasm: $(SAMPLESWOUT)
|
all: dir copy
|
||||||
|
|
||||||
%.$(EXT):
|
dir:
|
||||||
$(NCC) $(NCFLAGS) sod.c samples/$(@:%.$(EXT)=%.c) -o bin/$@
|
@mkdir -p bin/
|
||||||
|
|
||||||
%.$(WEXT):
|
copy:
|
||||||
$(WASMCC) $(WCFLAGS) $(WASMCFLAGS) $(OPTFLAGS) sod.c samples/$(@:%.$(WEXT)=%.c) $(DUMMY) -o bin/$(@:%.$(WEXT)=%.wasm)
|
cp samples/*.png bin/
|
||||||
$(SFCC) bin/$(@:%.$(WEXT)=%.wasm) -o bin/$(@:%.$(WEXT)=%.bc)
|
cp samples/*.jpg bin/
|
||||||
$(CC) ${CFLAGS} ${EXTRA_CFLAGS} $(OPTFLAGS) -D$(USE_MEM) bin/$(@:%.$(WEXT)=%.bc) $(RT_LIBC) $(RT_RT) ${MEMC} -o bin/$@
|
|
||||||
|
.PHONY: samples.wasm
|
||||||
clean:
|
samples.wasm: resize_image.wasm license_plate_detection.wasm
|
||||||
rm -f bin/*
|
|
||||||
|
.PHONY: samples.so
|
||||||
|
samples.so: resize_image.so license_plate_detection.so
|
||||||
|
|
||||||
|
.PHONY: samples.out
|
||||||
|
samples.out: resize_image.out license_plate_detection.out
|
||||||
|
|
||||||
|
%.wasm: samples/%.c
|
||||||
|
@$(WASM_CC) $(WASM_CFLAGS) $(OPTFLAGS) sod.c $< $(DUMMY) -o bin/$@
|
||||||
|
|
||||||
|
%.out: %.wasm
|
||||||
|
@$(AWSM_CC) $< -o $(<:.wasm=.bc)
|
||||||
|
@$(NATIVE_CC) ${CFLAGS} ${EXTRA_CFLAGS} $(OPTFLAGS) -DUSE_MEM_VM bin/$(<:.wasm=.bc) $(AWSM_RT_LIBC) $(AWSM_RT_RT) $(AWSM_RT_ENV) $(AWSM_RT_MEMC) -o $@
|
||||||
|
|
||||||
|
%.so: %.wasm
|
||||||
|
@$(AWSM_CC) --inline-constant-globals --runtime-globals bin/$< -o bin/$(@:.so=.bc)
|
||||||
|
@$(NATIVE_CC) --shared -fPIC ${CFLAGS} ${EXTRA_CFLAGS} $(OPTFLAGS) -DUSE_MEM_VM -I${SLEDGE_RT_INC} bin/$(@:.so=.bc) $(WASMISA) ${SLEDGE_MEMC} -o bin/$@
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
rm -f bin/*
|
||||||
|
rm -f *.wasm
|
||||||
|
rm -f *.bc
|
||||||
|
rm -f *.so
|
||||||
|
rm -f *.out
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
BASE=awsm
|
|
||||||
SFCC=silverfish
|
|
||||||
CC=clang
|
|
||||||
WASMCC=wasm32-unknown-unknown-wasm-clang
|
|
||||||
|
|
||||||
OPTFLAGS=-O3 -flto
|
|
||||||
# same stack-size for all
|
|
||||||
WASMLINKFLAGS=-Wl,-z,stack-size=524288,--allow-undefined,--no-threads,--stack-first,--no-entry,--export-all,--export=main,--export=dummy
|
|
||||||
WASMCFLAGS=${WASMLINKFLAGS} -nostartfiles
|
|
||||||
|
|
||||||
MEMC_64=64bit_nix.c
|
|
||||||
MEMC_NO=no_protection.c
|
|
||||||
MEMC_GEN=generic.c
|
|
||||||
MEMC_MPX=mpx.c
|
|
||||||
MEMC_SEG=segmented.c
|
|
||||||
|
|
||||||
# for silverfish
|
|
||||||
RT_DIR=${BASE_DIR}/runtime/
|
|
||||||
RT_MEM=${RT_DIR}/memory/
|
|
||||||
RT_LIBC=${RT_DIR}/libc/libc_backing.c
|
|
||||||
RT_RT=${RT_DIR}/runtime.c
|
|
||||||
|
|
||||||
MEMC=${RT_MEM}/${MEMC_64}
|
|
||||||
DUMMY=${BASE_DIR}/code_benches/dummy.c
|
|
||||||
|
|
||||||
# for awsm
|
|
||||||
ABASE_DIR=${BASE_DIR}/../
|
|
||||||
ART_DIR=${ABASE_DIR}/runtime/
|
|
||||||
ART_INC=${ART_DIR}/include/
|
|
||||||
|
|
||||||
USE_MEM=USE_MEM_VM
|
|
||||||
ifeq ($(USE_MEM),USE_MEM_VM)
|
|
||||||
AMEMC=${ART_DIR}/compiletime/memory/${MEMC_64}
|
|
||||||
endif
|
|
||||||
WASMISA=${ART_DIR}/compiletime/instr.c
|
|
||||||
|
|
||||||
ABIN_DIR=${ART_DIR}/bin/
|
|
||||||
TMP_DIR=tmp/
|
|
@ -0,0 +1,47 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "sod.h"
|
||||||
|
|
||||||
|
#define MAX_IMG_SZ 1024*1024
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
unsigned char *zInpbuf = NULL;
|
||||||
|
|
||||||
|
zInpbuf = malloc(MAX_IMG_SZ);
|
||||||
|
if (!zInpbuf)
|
||||||
|
{
|
||||||
|
perror("malloc");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t imgSz = read(0, zInpbuf, MAX_IMG_SZ);
|
||||||
|
if (imgSz <= 0)
|
||||||
|
{
|
||||||
|
perror("read");
|
||||||
|
free(zInpbuf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sod_img imgIn = sod_img_load_from_mem(zInpbuf, imgSz, SOD_IMG_COLOR /* full color channels */);
|
||||||
|
if (imgIn.data == 0) {
|
||||||
|
/* Invalid path, unsupported format, memory failure, etc. */
|
||||||
|
//puts("Cannot load input image..exiting");
|
||||||
|
printf("Error loading input\n");
|
||||||
|
free(zInpbuf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < imgIn.w * imgIn.h * imgIn.c; i++)
|
||||||
|
{
|
||||||
|
imgIn.data[i] = 255.0f - imgIn.data[i];
|
||||||
|
}
|
||||||
|
sod_img_save_as_png(imgIn, NULL);
|
||||||
|
sod_free_image(imgIn);
|
||||||
|
free(zInpbuf);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in new issue