Re: AGL+Tensorflowlite

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for the reply.  With the help of a colleague, I was able to get tflite 2.4 built by modifying the tensorflow/lite/tools/make/Makefile to use with the build_aarch64_lib.sh script in the same folder.  He gave me two patches that I am attaching here to build both libtensorflowlite.a and .so using the aarch64-agl-linux.  These patches are for the Makefile on the master branch  I was able to get it built but during compile time of my app I had other issues related to header files and tflite dependencies (the tensorflow team modified the namespace of a few headers), so ultimately I used the r2.4 branch with flatbuffers 1.12 that I also built with the aarch64-agl-linux toolchain from AGL.  The Makefile I am attaching is for r2.4 branch, the patches dont work out of the box for r2.4 since it was slightly modified but between the Makefile and the patches, Im guessing most people here can see what and how things were modified.  Note that when you run the build script, the resulting libs will be in tensorflow/lite/tools/make/gen/linux_aarch64/lib and you still need to manually extract all the headers on whatever branch you are on.

Cheers!
_._,_._,_

Links:

You receive all messages sent to this group.

View/Reply Online (#8991) | Reply To Group | Reply To Sender | Mute This Topic | New Topic
Your Subscription | Contact Group Owner | Unsubscribe [list-automotive-discussions82@xxxxxxxxxxx]

_._,_._,_
From 526e873f4edaa34dcdba4dbb8535b0e0a62e2db6 Mon Sep 17 00:00:00 2001
From: Jon Emrich <emricht32@xxxxxxxxx>
Date: Tue, 29 Dec 2020 16:07:40 -0800
Subject: [PATCH 1/2] modify to compile with AGL toolchain

---
 tensorflow/lite/tools/make/Makefile | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/tensorflow/lite/tools/make/Makefile b/tensorflow/lite/tools/make/Makefile
index 99fe540d22f..cd69f7d74d9 100644
--- a/tensorflow/lite/tools/make/Makefile
+++ b/tensorflow/lite/tools/make/Makefile
@@ -62,6 +62,8 @@ LIBS := \
 # There are no rules for compiling objects for the host system (since we don't
 # generate things like the protobuf compiler that require that), so all of
 # these settings are for the target compiler.
+EXTRA_CFLAGS := --sysroot=/opt/agl-sdk/10.0.1-aarch64/sysroots/aarch64-agl-linux
+EXTRA_CXXFLAGS := --sysroot=/opt/agl-sdk/10.0.1-aarch64/sysroots/aarch64-agl-linux
 CFLAGS := -O3 -DNDEBUG -DCPU_SETSIZE=__CPU_SETSIZE -fPIC $(EXTRA_CFLAGS)
 CXXFLAGS := $(CFLAGS) --std=c++11 $(EXTRA_CXXFLAGS)
 LDOPTS := -L/usr/local/lib
@@ -304,9 +306,12 @@ BENCHMARK_PERF_OPTIONS_BINARY := $(BINDIR)$(BENCHMARK_PERF_OPTIONS_BINARY_NAME)
 MINIMAL_BINARY := $(BINDIR)minimal
 LABEL_IMAGE_BINARY := $(BINDIR)label_image
 
-CXX := $(CC_PREFIX)${TARGET_TOOLCHAIN_PREFIX}g++
-CC := $(CC_PREFIX)${TARGET_TOOLCHAIN_PREFIX}gcc
-AR := $(CC_PREFIX)${TARGET_TOOLCHAIN_PREFIX}ar
+#CXX := $(CC_PREFIX)${TARGET_TOOLCHAIN_PREFIX}g++
+#CC := $(CC_PREFIX)${TARGET_TOOLCHAIN_PREFIX}gcc
+#AR := $(CC_PREFIX)${TARGET_TOOLCHAIN_PREFIX}ar
+CXX := aarch64-agl-linux-g++
+CC := aarch64-agl-linux-gcc
+AR := aarch64-agl-linux-ar
 
 MINIMAL_OBJS := $(addprefix $(OBJDIR), \
 $(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(MINIMAL_SRCS))))
-- 
2.17.1

From aa010e3e378b07346edcf79154ff361fd0868b0a Mon Sep 17 00:00:00 2001
From: Jon Emrich <emricht32@xxxxxxxxx>
Date: Tue, 29 Dec 2020 18:02:12 -0800
Subject: [PATCH 2/2] adding rule to create dynamic libraries as well

---
 tensorflow/lite/tools/make/Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tensorflow/lite/tools/make/Makefile b/tensorflow/lite/tools/make/Makefile
index cd69f7d74d9..815f04e9514 100644
--- a/tensorflow/lite/tools/make/Makefile
+++ b/tensorflow/lite/tools/make/Makefile
@@ -68,6 +68,7 @@ CFLAGS := -O3 -DNDEBUG -DCPU_SETSIZE=__CPU_SETSIZE -fPIC $(EXTRA_CFLAGS)
 CXXFLAGS := $(CFLAGS) --std=c++11 $(EXTRA_CXXFLAGS)
 LDOPTS := -L/usr/local/lib
 ARFLAGS := -r
+LIBFLAGS := --sysroot=/opt/agl-sdk/10.0.1-aarch64/sysroots/aarch64-agl-linux -shared
 TARGET_TOOLCHAIN_PREFIX :=
 CC_PREFIX :=
 
@@ -100,9 +101,11 @@ endif
 # This library is the main target for this makefile. It will contain a minimal
 # runtime that can be linked in to other programs.
 LIB_NAME := libtensorflow-lite.a
+LIB_NAME_SO := libtensorflow-lite.so
 
 # Benchmark static library and binary
 BENCHMARK_LIB_NAME := benchmark-lib.a
+BENCHMARK_LIB_NAME_SO := libbenchmark.so
 BENCHMARK_BINARY_NAME := benchmark_model
 BENCHMARK_PERF_OPTIONS_BINARY_NAME := benchmark_model_performance_options
 
@@ -360,9 +363,13 @@ tensorflow/lite/schema/schema_generated.h:
 $(LIB_PATH): tensorflow/lite/schema/schema_generated.h $(LIB_OBJS)
 	@mkdir -p $(dir $@)
 	$(AR) $(ARFLAGS) $(LIB_PATH) $(LIB_OBJS)
+	$(CXX) $(LIBFLAGS) -o $(LIBDIR)$(LIB_NAME_SO) $(LIB_OBJS)
+	
+
 $(LIB_PATH): tensorflow/lite/experimental/acceleration/configuration/configuration_generated.h $(LIB_OBJS)
 	@mkdir -p $(dir $@)
 	$(AR) $(ARFLAGS) $(LIB_PATH) $(LIB_OBJS)
+	$(CXX) $(LIBFLAGS) -o $(LIBDIR)$(LIB_NAME_SO) $(LIB_OBJS)
 
 lib: $(LIB_PATH)
 
@@ -385,6 +392,8 @@ label_image: $(LABEL_IMAGE_BINARY)
 $(BENCHMARK_LIB) : $(LIB_PATH) $(BENCHMARK_LIB_OBJS)
 	@mkdir -p $(dir $@)
 	$(AR) $(ARFLAGS) $(BENCHMARK_LIB) $(LIB_OBJS) $(BENCHMARK_LIB_OBJS)
+	$(CXX) $(LIBFLAGS) -o $(LIBDIR)$(BENCHMARK_LIB_NAME_SO) $(BENCHMARK_LIB_OBJS)
+	
 
 benchmark_lib: $(BENCHMARK_LIB)
 
-- 
2.17.1

Attachment: Makefile_r2.4
Description: Binary data


[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux