pkg: add support for utensor as a package

This commit is contained in:
Alexandre Abadie 2019-11-23 14:48:31 +01:00
parent 421d174f60
commit 087246ea0f
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
10 changed files with 209 additions and 0 deletions

16
pkg/utensor/Makefile Normal file
View File

@ -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

4
pkg/utensor/Makefile.dep Normal file
View File

@ -0,0 +1,4 @@
FEATURES_REQUIRED += cpp
USEMODULE += utensor-ops
USEMODULE += utensor-util

View File

@ -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

View File

@ -0,0 +1,5 @@
MODULE = utensor
CXXEXFLAGS += -Wno-unused-parameter
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,3 @@
MODULE = utensor-ops
include $(RIOTBASE)/Makefile.base

View File

@ -0,0 +1,5 @@
MODULE = utensor-util
CXXEXFLAGS += -Wno-c++14-binary-literal
include $(RIOTBASE)/Makefile.base

7
pkg/utensor/doc.txt Normal file
View File

@ -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
*/

View File

@ -0,0 +1,51 @@
From 737ff6e1e4f3411a557b3f7436ed94461c67249e Mon Sep 17 00:00:00 2001
From: Alexandre Abadie <alexandre.abadie@inria.fr>
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<unsigned>(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<unsigned>(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<unsigned>(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<unsigned>(out.get_value())); }
Ref_Record r = rTable[out];
_outputs.push_back(r.ptr);
}
--
2.20.1

View File

@ -0,0 +1,46 @@
From 3a6aa2c894923f3d4a5aff0ea09e71f7c68dbde7 Mon Sep 17 00:00:00 2001
From: Alexandre Abadie <alexandre.abadie@inria.fr>
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 <sys/stat.h>
#include <dirent.h>
#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<uint32_t> vec);
#undef min
#undef round
#undef abs
-#else
- #include "mbed.h"
#endif
//# error "Unknown compiler"
// little endian to big endian
--
2.20.1

View File

@ -0,0 +1,55 @@
From f68167af0e950ac5330ba5586758ebdc77cb66a1 Mon Sep 17 00:00:00 2001
From: Alexandre Abadie <alexandre.abadie@inria.fr>
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