[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [UNIKRAFT/LIBTFLITE PATCH v2 1/1] Add main and improve Readme
Signed-off-by: George Muraru <murarugeorgec@xxxxxxxxx> --- Config.uk | 6 +- Makefile.uk | 106 ++++++++++++++++------------- README.md | 56 +++++++++++++-- main.cpp | 56 +++++++++++++++ patches/0001-Change-zu-to-lu.patch | 47 +++++++++++++ 5 files changed, 216 insertions(+), 55 deletions(-) create mode 100644 main.cpp create mode 100644 patches/0001-Change-zu-to-lu.patch diff --git a/Config.uk b/Config.uk index 38bc5fb..2efd518 100644 --- a/Config.uk +++ b/Config.uk @@ -8,7 +8,6 @@ menuconfig LIBTFLITE select LIBCOMPILER_RT_ATOMIC select LIBEIGEN select LIBFFT2D - select LIBFFT2D_2D select LIBFLATBUFFERS select LIBGEMMLOWP select LIBFARMHASH @@ -32,3 +31,8 @@ if LIBTFLITE default n endif +if LIBTFLITE +config LIBTFLITE_MAIN_FUNCTION + bool "Provide main function" + default y +endif diff --git a/Makefile.uk b/Makefile.uk index 2b5db3f..7223603 100644 --- a/Makefile.uk +++ b/Makefile.uk @@ -38,8 +38,11 @@ $(eval $(call addlib_s,libtflite,$(CONFIG_LIBTFLITE))) # Sources ################################################################################ LIBTFLITE_VERSION=2.0.1 +LIBTFLITE_PATCHDIR=$(LIBTFLITE_BASE)/patches + LIBTFLITE_URL=https://github.com/tensorflow/tensorflow/archive/v$(LIBTFLITE_VERSION).tar.gz $(eval $(call fetch,libtflite,$(LIBTFLITE_URL))) +$(eval $(call patch,libtflite,$(LIBTFLITE_PATCHDIR),tensorflow-$(LIBTFLITE_VERSION))) ################################################################################ # Helpers @@ -57,14 +60,23 @@ CXXINCLUDES-$(CONFIG_LIBTFLITE) += -I$(LIBTFLITE_SRC)/tensorflow/lite CINCLUDES-$(CONFIG_LIBTFLITE) += -I$(LIBTFLITE_SRC)/ CINCLUDES-$(CONFIG_LIBTFLITE) += -I$(LIBTFLITE_SRC)/tensorflow/lite +################################################################################ +# Main code +################################################################################ + +ifdef CONFIG_LIBTFLITE_MAIN_FUNCTION +LIBTFLITE_SRCS-$(CONFIG_LIBTFLITE_MAIN_FUNCTION) += $(LIBTFLITE_BASE)/main.cpp +endif + ################################################################################ # Global flags ################################################################################ -LIBTFLITE_SUPPRESS_FLAGS += -Wno-sign-compare -Wno-unused-parameter -Wno-comment -LIBTFLITE_SUPPRESS_FLAGS += -Wno-missing-field-initializers +LIBTFLITE_SUPPRESS_FLAGS += -Wno-sign-compare -Wno-unused-parameter -Wno-comment \ + -Wno-missing-field-initializers -Wno-parantheses \ + -Wno-unused-function -Wno-unknown-pragmas LIBTFLITE_CXXFLAGS-y += $(LIBTFLITE_SUPPRESS_FLAGS) - +LIBTFLITE_CFLAGS-y += $(LIBTFLITE_SUPPRESS_FLAGS) ifdef CONFIG_LIBTFLITE_BUILD_WITH_RUY LIBTFLITE_CXXFLAGS-y += -D TFLITE_WITH_RUY @@ -79,58 +91,58 @@ endif ################################################################################ # Library sources ################################################################################ -MINIMAL_SRCS := \ - $(LIBTFLITE_SRC)/tensorflow/lite/examples/minimal/minimal.cc +MINIMAL_SRCS := $(LIBTFLITE_SRC)/tensorflow/lite/examples/minimal/minimal.cc CORE_CC_ALL_SRCS := \ - $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*.cc) \ - $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*.c) \ - $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/c/*.c) \ - $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/core/*.cc) \ - $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/core/api/*.cc) \ - $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/experimental/resource_variable/*.cc) \ - $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/allocator.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/block_map.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/blocking_counter.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/context.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/detect_dotprod.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/kernel_arm32.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/kernel_arm64.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/pack_arm.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/pmu.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/thread_pool.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/trace.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/trmul.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/tune.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/wait.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/minimal_logging_default.cc + $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*.cc) \ + $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*.c) \ + $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/c/*.c) \ + $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/core/*.cc) \ + $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/core/api/*.cc) \ + $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/experimental/resource_variable/*.cc) \ + $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/allocator.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/block_map.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/blocking_counter.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/context.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/detect_dotprod.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/kernel_arm32.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/kernel_arm64.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/pack_arm.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/pmu.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/thread_pool.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/trace.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/trmul.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/tune.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/wait.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/minimal_logging_default.cc CORE_CC_ALL_SRCS += \ - $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/*.cc) \ - $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/internal/*.cc) \ - $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/internal/optimized/*.cc) \ - $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/internal/reference/*.cc) + $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/*.cc) \ + $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/internal/*.cc) \ + $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/internal/optimized/*.cc) \ + $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/internal/reference/*.cc) CORE_CC_ALL_SRCS := $(sort $(CORE_CC_ALL_SRCS)) CORE_CC_EXCLUDE_SRCS := \ - $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*test.cc) \ - $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*/*test.cc) \ - $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*/*/*test.cc) \ - $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*/*/*/*test.cc) \ - $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/*test_main.cc) \ - $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/*test_util.cc) \ - $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/pmu.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/minimal_logging_android.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/minimal_logging_ios.cc \ - $(MINIMAL_SRCS) + $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*test.cc) \ + $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*/*test.cc) \ + $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*/*/*test.cc) \ + $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/*/*/*/*test.cc) \ + $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/*test_main.cc) \ + $(wildcard $(LIBTFLITE_SRC)/tensorflow/lite/kernels/*test_util.cc) \ + $(LIBTFLITE_SRC)/tensorflow/lite/experimental/ruy/pmu.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/minimal_logging_android.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/minimal_logging_ios.cc \ + $(MINIMAL_SRCS) + COMPILE_MANUAL_SRCS := \ - $(LIBTFLITE_SRC)/tensorflow/lite/kernels/internal/mfcc.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/kernels/mfcc.cc + $(LIBTFLITE_SRC)/tensorflow/lite/kernels/internal/mfcc.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/kernels/mfcc.cc ifeq ($(CONFIG_LIBUKMMAP),y) @@ -141,13 +153,13 @@ endif ifeq ($(LIBTFLITE_BUILD_WITH_NNAPI),y) CORE_CC_ALL_SRCS += \ - $(LIBTFLITE_SRC)/tensorflow/lite/delegates/nnapi/nnapi_delegate.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/delegates/nnapi/quant_lstm_sup.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/nnapi/nnapi_implementation.cc + $(LIBTFLITE_SRC)/tensorflow/lite/delegates/nnapi/nnapi_delegate.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/delegates/nnapi/quant_lstm_sup.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/nnapi/nnapi_implementation.cc else CORE_CC_ALL_SRCS += \ - $(LIBTFLITE_SRC)/tensorflow/lite/delegates/nnapi/nnapi_delegate_disabled.cc \ - $(LIBTFLITE_SRC)/tensorflow/lite/nnapi/nnapi_implementation_disabled.cc + $(LIBTFLITE_SRC)/tensorflow/lite/delegates/nnapi/nnapi_delegate_disabled.cc \ + $(LIBTFLITE_SRC)/tensorflow/lite/nnapi/nnapi_implementation_disabled.cc endif LIBTFLITE_SRCS-y += $(filter-out $(CORE_CC_EXCLUDE_SRCS) $(COMPILE_MANUAL_SRCS), $(CORE_CC_ALL_SRCS)) diff --git a/README.md b/README.md index a7a1a6d..617a8bd 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,54 @@ -gemmlowp for Unikraft +TensorFlowLite for Unikraft ============================= -This is the port of gemmlowp as a Unikraft external library. It -depends on the following libraries that need to be added to `Makefile` -in this order: +This is the port of tensorflowlite as external library +Please refer to the `README.md` as well as the documentation in the `doc/` +subdirectory of the main unikraft repository. + +## Build +TensorFlowLite interpreter depends on the following libraries, that need to +be added to `Makefile` in this order: -* CXX standard library, e.g. `libunwind`, `compiler-rt`, `libcxxabi`, `libcxx` +* `pthreads`, e.g. `pthread-embedded` +* `libcxx` +* `libcxxabi` * `libc`, e.g. `newlib` +* `libunwind` +* `libcompilerrt` +* `libgemmlowp` +* `libflatbuffers` +* `libfarmhash` +* `libeigen` +* `libfft2` -Please refer to the `README.md` as well as the documentation in the `doc/` -subdirectory of the main unikraft repository. +## Root filesystem +### Creating the filesystem +TensorFlowLite needs a filesystem which should contain one or more *tflite* +models. Therefore, the filesystem needs to be created before running the VM. + +### Using the filesystem +Mounting the filesystem is a transparent operation. All you have to do +is to provide the right Qemu parameters in order for Unikraft to mount +the filesystem. We will use the 9pfs support for filesystems and for +this you will need to use the following parameters: + +```bash +-fsdev local,id=myid,path=<some directory>,security_model=none \ +-device virtio-9p-pci,fsdev=myid,mount_tag=rootfs,disable-modern=on,disable-legacy=off +``` +You should also use `vfs.rootdev=rootfs` (set by default) to specify the 9pfs mounting +tag to Unikraft. To enable 9pfs, you'll need to select the following +menu options, all under `Library Configuration`: + +* `uk9p: 9p client` +* `vfscore: VFS Core Interface` + → `vfscore: Configuration` + → `Automatically mount a root filesysytem` + → `Default root filesystem` + → `9PFS` + +## How to run +Currently, `main.cpp` contains a minimal example for loading a *tflite* model and +printing the interpreter state. The sample program will try to load the model from +`mobilenet_v1_1.0_224.tflite` (this model and other models from the same family can +be downloaded from [here](https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet_v1.md)) diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..45f9b07 --- /dev/null +++ b/main.cpp @@ -0,0 +1,56 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#define __clrsbDI2 __NDW(clrsb,2) + +#include <cstdio> +#include "tensorflow/lite/interpreter.h" +#include "tensorflow/lite/kernels/register.h" +#include "tensorflow/lite/model.h" +#include "tensorflow/lite/optional_debug_tools.h" + +#include <sys/mount.h> +#include <sys/types.h> +#include <fcntl.h> + +// This is an example that is minimal to read a model +// from disk and perform inference. There is no data being loaded +// that is up to you to add as a user. +// +// NOTE: Do not add any dependencies to this that cannot be built with +// the minimal makefile. This example must remain trivial to build with +// the minimal build tool. +// +// Usage: minimal <tflite model> + +using namespace tflite; + +int main() { + const char* filename = "mobilenet_v1_1.0_224.tflite"; + + // Load model + std::unique_ptr<tflite::FlatBufferModel> model = + tflite::FlatBufferModel::BuildFromFile(filename); + + // Build the interpreter + tflite::ops::builtin::BuiltinOpResolver resolver; + InterpreterBuilder builder(*model, resolver); + std::unique_ptr<Interpreter> interpreter; + builder(&interpreter); + + printf("=== Interpreter State ===\n"); + tflite::PrintInterpreterState(interpreter.get()); + + return 0; +} diff --git a/patches/0001-Change-zu-to-lu.patch b/patches/0001-Change-zu-to-lu.patch new file mode 100644 index 0000000..d68a26e --- /dev/null +++ b/patches/0001-Change-zu-to-lu.patch @@ -0,0 +1,47 @@ +From f34b41fd728c06517a1223178af2fbb97dce5dfe Mon Sep 17 00:00:00 2001 +From: George Muraru <murarugeorgec@xxxxxxxxx> +Date: Tue, 21 Apr 2020 23:16:50 +0300 +Subject: [PATCH 1/1] Change zu to lu + +--- + tensorflow/lite/optional_debug_tools.cc | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/tensorflow/lite/optional_debug_tools.cc b/tensorflow/lite/optional_debug_tools.cc +index a59af3d..c9339b0 100644 +--- a/tensorflow/lite/optional_debug_tools.cc ++++ b/tensorflow/lite/optional_debug_tools.cc +@@ -80,7 +80,7 @@ const char* AllocTypeName(TfLiteAllocationType type) { + + // Prints a dump of what tensors and what nodes are in the interpreter. + void PrintInterpreterState(Interpreter* interpreter) { +- printf("Interpreter has %zu tensors and %zu nodes\n", ++ printf("Interpreter has %lu tensors and %lu nodes\n", + interpreter->tensors_size(), interpreter->nodes_size()); + printf("Inputs:"); + PrintIntVector(interpreter->inputs()); +@@ -90,7 +90,7 @@ void PrintInterpreterState(Interpreter* interpreter) { + for (size_t tensor_index = 0; tensor_index < interpreter->tensors_size(); + tensor_index++) { + TfLiteTensor* tensor = interpreter->tensor(static_cast<int>(tensor_index)); +- printf("Tensor %3zu %-20s %10s %15s %10zu bytes (%4.1f MB) ", tensor_index, ++ printf("Tensor %3lu %-20s %10s %15s %10lu bytes (%4.1f MB) ", tensor_index, + tensor->name, TensorTypeName(tensor->type), + AllocTypeName(tensor->allocation_type), tensor->bytes, + (static_cast<float>(tensor->bytes) / (1 << 20))); +@@ -104,10 +104,10 @@ void PrintInterpreterState(Interpreter* interpreter) { + const TfLiteNode& node = node_and_reg->first; + const TfLiteRegistration& reg = node_and_reg->second; + if (reg.custom_name != nullptr) { +- printf("Node %3zu Operator Custom Name %s\n", node_index, ++ printf("Node %3lu Operator Custom Name %s\n", node_index, + reg.custom_name); + } else { +- printf("Node %3zu Operator Builtin Code %3d\n", node_index, ++ printf("Node %3lu Operator Builtin Code %3d\n", node_index, + reg.builtin_code); + } + printf(" Inputs:"); +-- +2.17.1 + -- 2.17.1
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |