diff --git a/pkg/utensor/Makefile b/pkg/utensor/Makefile new file mode 100644 index 0000000000..de34ac9732 --- /dev/null +++ b/pkg/utensor/Makefile @@ -0,0 +1,16 @@ +PKG_NAME=utensor +PKG_URL=https://github.com/uTensor/uTensor +PKG_VERSION=b22aa5cbc1ef1b3dd42a899b393a9b999afd1305 +PKG_LICENSE=Apache2.0 + +PKG_BASEDIR = $(PKG_BUILDDIR)/src/uTensor + +.PHONY: all + +all: + "$(MAKE)" -C $(PKG_BASEDIR)/core -f $(CURDIR)/Makefile.$(PKG_NAME) + "$(MAKE)" -C $(PKG_BASEDIR)/util -f $(CURDIR)/Makefile.$(PKG_NAME).util + "$(MAKE)" -C $(PKG_BASEDIR)/ops -f $(CURDIR)/Makefile.$(PKG_NAME).ops + + +include $(RIOTBASE)/pkg/pkg.mk diff --git a/pkg/utensor/Makefile.dep b/pkg/utensor/Makefile.dep new file mode 100644 index 0000000000..657b56d8f9 --- /dev/null +++ b/pkg/utensor/Makefile.dep @@ -0,0 +1,4 @@ +FEATURES_REQUIRED += cpp + +USEMODULE += utensor-ops +USEMODULE += utensor-util diff --git a/pkg/utensor/Makefile.include b/pkg/utensor/Makefile.include new file mode 100644 index 0000000000..6b0ee8302c --- /dev/null +++ b/pkg/utensor/Makefile.include @@ -0,0 +1,17 @@ +INCLUDES += -I$(PKGDIRBASE)/utensor +INCLUDES += -I$(PKGDIRBASE)/utensor/src +INCLUDES += -I$(PKGDIRBASE)/utensor/src/uTensor +INCLUDES += -I$(PKGDIRBASE)/utensor/src/uTensor/core +INCLUDES += -I$(PKGDIRBASE)/utensor/src/uTensor/ops +INCLUDES += -I$(PKGDIRBASE)/utensor/src/uTensor/util + +CXXEXFLAGS += -Wno-sign-compare + +ifeq (llvm,$(TOOLCHAIN)) + CXXEXFLAGS += -Wno-unused-variable + CXXEXFLAGS += -Wno-shift-count-negative +endif + +ifneq (native,$(BOARD)) + CXXEXFLAGS += -std=c++11 +endif diff --git a/pkg/utensor/Makefile.utensor b/pkg/utensor/Makefile.utensor new file mode 100644 index 0000000000..21009d92bd --- /dev/null +++ b/pkg/utensor/Makefile.utensor @@ -0,0 +1,5 @@ +MODULE = utensor + +CXXEXFLAGS += -Wno-unused-parameter + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/utensor/Makefile.utensor.ops b/pkg/utensor/Makefile.utensor.ops new file mode 100644 index 0000000000..267fd924ed --- /dev/null +++ b/pkg/utensor/Makefile.utensor.ops @@ -0,0 +1,3 @@ +MODULE = utensor-ops + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/utensor/Makefile.utensor.util b/pkg/utensor/Makefile.utensor.util new file mode 100644 index 0000000000..e5dc1a5361 --- /dev/null +++ b/pkg/utensor/Makefile.utensor.util @@ -0,0 +1,5 @@ +MODULE = utensor-util + +CXXEXFLAGS += -Wno-c++14-binary-literal + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/utensor/doc.txt b/pkg/utensor/doc.txt new file mode 100644 index 0000000000..ce1a8b14e0 --- /dev/null +++ b/pkg/utensor/doc.txt @@ -0,0 +1,7 @@ +/** + * @defgroup pkg_utensor uTensor + * @ingroup pkg + * @brief Provides a package for AI inference based on TensorFlow + * + * @see https://github.com/uTensor/uTensor + */ diff --git a/pkg/utensor/patches/0001-fix-integer-format.patch b/pkg/utensor/patches/0001-fix-integer-format.patch new file mode 100644 index 0000000000..f0366d3c43 --- /dev/null +++ b/pkg/utensor/patches/0001-fix-integer-format.patch @@ -0,0 +1,51 @@ +From 737ff6e1e4f3411a557b3f7436ed94461c67249e Mon Sep 17 00:00:00 2001 +From: Alexandre Abadie +Date: Sat, 23 Nov 2019 13:09:31 +0100 +Subject: [PATCH] Fix wrong integer format in print + +--- + src/uTensor/core/context.cpp | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/src/uTensor/core/context.cpp b/src/uTensor/core/context.cpp +index 112308e..96020f5 100644 +--- a/src/uTensor/core/context.cpp ++++ b/src/uTensor/core/context.cpp +@@ -3,7 +3,7 @@ + S_TENSOR Context::add(Tensor* t, TName _name, uint8_t init_count) { + if(t == nullptr) { ERR_EXIT("null pointer tensor"); } + if(rTable.find(_name) != rTable.end()) { +- ERR_EXIT("tensor with name \"%d\" address already exist in rTable", t->getName().get_value()); ++ ERR_EXIT("tensor with name \"%d\" address already exist in rTable", static_cast(t->getName().get_value())); + } + + t->setName(_name); +@@ -23,7 +23,7 @@ S_TENSOR Context::add(Tensor* t, TName _name, uint8_t init_count) { + } + + S_TENSOR Context::get(TName const &t_name) { +- if(rTable.find(t_name) == rTable.end()) ERR_EXIT("No tensor with name: %d", t_name.get_value()); ++ if(rTable.find(t_name) == rTable.end()) ERR_EXIT("No tensor with name: %d", static_cast(t_name.get_value())); + return rTable[t_name].ptr; + } + +@@ -64,14 +64,14 @@ void Context::push(Operator* op, TNameList &in_names, TNameList &out_names) { + //error checking in the Op class + S_TList _inputs; + for(auto in:in_names) { +- if(rTable.find(in) == rTable.end()) { ERR_EXIT("Tensor \"%d\" not found", in.get_value()); } ++ if(rTable.find(in) == rTable.end()) { ERR_EXIT("Tensor \"%d\" not found", static_cast(in.get_value())); } + Ref_Record r = rTable[in]; + _inputs.push_back(r.ptr); + } + + S_TList _outputs; + for(auto out:out_names) { +- if(rTable.find(out) == rTable.end()) { ERR_EXIT("Tensor \"%d\" not found", out.get_value()); } ++ if(rTable.find(out) == rTable.end()) { ERR_EXIT("Tensor \"%d\" not found", static_cast(out.get_value())); } + Ref_Record r = rTable[out]; + _outputs.push_back(r.ptr); + } +-- +2.20.1 + diff --git a/pkg/utensor/patches/0002-fix-mbed-specific-code.patch b/pkg/utensor/patches/0002-fix-mbed-specific-code.patch new file mode 100644 index 0000000000..3c6b7e60a4 --- /dev/null +++ b/pkg/utensor/patches/0002-fix-mbed-specific-code.patch @@ -0,0 +1,46 @@ +From 3a6aa2c894923f3d4a5aff0ea09e71f7c68dbde7 Mon Sep 17 00:00:00 2001 +From: Alexandre Abadie +Date: Sat, 23 Nov 2019 13:11:00 +0100 +Subject: [PATCH] Fix mbed specific code + +--- + src/uTensor/util/uTensor_util.cpp | 4 ++-- + src/uTensor/util/uTensor_util.hpp | 2 -- + 2 files changed, 2 insertions(+), 4 deletions(-) + +diff --git a/src/uTensor/util/uTensor_util.cpp b/src/uTensor/util/uTensor_util.cpp +index 4d1dd48..32c50df 100644 +--- a/src/uTensor/util/uTensor_util.cpp ++++ b/src/uTensor/util/uTensor_util.cpp +@@ -1,5 +1,5 @@ + #include "src/uTensor/util/uTensor_util.hpp" +-#if !(defined(TARGET_MBED) || defined(ARDUINO)) ++#ifdef BOARD_NATIVE + #include + #include + #endif +@@ -45,7 +45,7 @@ uint32_t ntoh32(uint32_t val) { + return ret; + } + +-#ifdef ARDUINO ++#ifndef BOARD_NATIVE + void int_env() { + } + #else +diff --git a/src/uTensor/util/uTensor_util.hpp b/src/uTensor/util/uTensor_util.hpp +index 25ebcf3..5390ed8 100644 +--- a/src/uTensor/util/uTensor_util.hpp ++++ b/src/uTensor/util/uTensor_util.hpp +@@ -106,8 +106,6 @@ void printVector(std::vector vec); + #undef min + #undef round + #undef abs +-#else +- #include "mbed.h" + #endif + //# error "Unknown compiler" + // little endian to big endian +-- +2.20.1 + diff --git a/pkg/utensor/patches/0003-fix-variadic-macro.patch b/pkg/utensor/patches/0003-fix-variadic-macro.patch new file mode 100644 index 0000000000..051056af10 --- /dev/null +++ b/pkg/utensor/patches/0003-fix-variadic-macro.patch @@ -0,0 +1,55 @@ +From f68167af0e950ac5330ba5586758ebdc77cb66a1 Mon Sep 17 00:00:00 2001 +From: Alexandre Abadie +Date: Mon, 25 Nov 2019 16:18:30 +0100 +Subject: [PATCH] util: fix variadic macros + +--- + src/uTensor/util/uTensor_util.hpp | 12 ++++++------ + 1 file changed, 6 insertions(+), 6 deletions(-) + +diff --git a/src/uTensor/util/uTensor_util.hpp b/src/uTensor/util/uTensor_util.hpp +index 9fff08b..31206a3 100644 +--- a/src/uTensor/util/uTensor_util.hpp ++++ b/src/uTensor/util/uTensor_util.hpp +@@ -28,9 +28,9 @@ void return_error(int ret_val); + return_error(FUNC); \ + } + +-#define DEBUG(MSG, ...) \ ++#define DEBUG(...) \ + { \ +- printf(MSG, ##__VA_ARGS__); \ ++ printf(__VA_ARGS__); \ + fflush(stdout); \ + } + +@@ -44,16 +44,16 @@ enum Padding { + // } + + #define ON_ERR(FUNC, MSG) FUNC +-#define DEBUG(MSG, ...) ++#define DEBUG(...) + + #endif + + void utensor_exit(void); + +-#define ERR_EXIT(MSG, ...) \ ++#define ERR_EXIT(...) \ + { \ + printf("[Error] %s:%d @%s ", __FILE__, __LINE__, __func__); \ +- printf(MSG, ##__VA_ARGS__); \ ++ printf(__VA_ARGS__); \ + fflush(stdout); \ + utensor_exit(); \ + } +@@ -130,4 +130,4 @@ uint16_t ntoh16(uint16_t val); + uint32_t ntoh32(uint32_t val); + + void init_env(); +-#endif +\ No newline at end of file ++#endif +-- +2.20.1 +