From dff851aa3124afce5f7d149c843d82b14c05c075 Mon Sep 17 00:00:00 2001 From: Nobuo Tsukamoto Date: Sun, 7 Apr 2024 22:04:44 +0900 Subject: [PATCH 1/2] Changed Makefile to support TF2.6.1. --- makefile_build/Makefile | 25 ++++++++++--------------- makefile_build/README.md | 2 +- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/makefile_build/Makefile b/makefile_build/Makefile index ef7d290..335e74a 100644 --- a/makefile_build/Makefile +++ b/makefile_build/Makefile @@ -22,7 +22,7 @@ LIBEDGETPU_CFLAGS := \ LIBEDGETPU_CXXFLAGS := \ -fPIC \ -Wall \ - -std=c++14 \ + -std=c++17 \ -DDARWINN_PORT_DEFAULT LIBEDGETPU_LDFLAGS := \ @@ -32,7 +32,7 @@ LIBEDGETPU_LDFLAGS := \ -Wl,--version-script=$(BUILDROOT)/tflite/public/libedgetpu.lds \ -fuse-ld=gold \ -lflatbuffers \ - -labsl_flags \ + -labsl_flags_commandlineflag \ -labsl_flags_internal \ -labsl_flags_reflection \ -labsl_flags_marshalling \ @@ -40,6 +40,7 @@ LIBEDGETPU_LDFLAGS := \ -labsl_hashtablez_sampler \ -labsl_raw_hash_set \ -labsl_str_format_internal \ + -labsl_bad_optional_access \ -lusb-1.0 LIBEDGETPU_FLATC_SRCS := \ @@ -59,9 +60,6 @@ LIBEDGETPU_INCLUDES := \ $(BUILDDIR)/$(BUILDROOT) LIBEDGETPU_INCLUDES := $(addprefix -I,$(LIBEDGETPU_INCLUDES)) -LIBEDGETPU_CSRCS := $(TFROOT)/tensorflow/lite/c/common.c -LIBEDGETPU_COBJS := $(call TOBUILDDIR,$(patsubst %.c,%.o,$(LIBEDGETPU_CSRCS))) - LIBEDGETPU_CCSRCS := \ $(BUILDROOT)/api/allocated_buffer.cc \ $(BUILDROOT)/api/buffer.cc \ @@ -140,7 +138,9 @@ LIBEDGETPU_CCSRCS := \ $(BUILDROOT)/tflite/edgetpu_c.cc \ $(BUILDROOT)/tflite/edgetpu_delegate_for_custom_op.cc \ $(BUILDROOT)/tflite/edgetpu_delegate_for_custom_op_tflite_plugin.cc \ - $(TFROOT)/tensorflow/lite/util.cc + $(TFROOT)/tensorflow/lite/core/c/common.cc \ + $(TFROOT)/tensorflow/lite/util.cc \ + $(TFROOT)/tensorflow/lite/array.cc LIBEDGETPU_CCOBJS := $(call TOBUILDDIR,$(patsubst %.cc,%.o,$(LIBEDGETPU_CCSRCS))) # In order to support direct and throttled mode - we need to compile two files @@ -181,11 +181,6 @@ firmware: @echo "} // namespace" >> $(LIBEDGETPU_FW_OUTPUT) -$(LIBEDGETPU_COBJS) : $(BUILDDIR)/%.o: %.c - @$(MKDIR) - @echo "Compiling $<" - @$(CC) $(LIBEDGETPU_CFLAGS) $(LIBEDGETPU_INCLUDES) -c $< -MD -MT $@ -MF $(@:%o=%d) -o $@ - $(LIBEDGETPU_CCOBJS) : $(BUILDDIR)/%.o: %.cc @$(MKDIR) @echo "Compiling $<" @@ -201,14 +196,14 @@ $(LIBEDGETPU_STD_CCOBJS) : $(BUILDDIR)/%-throttled.o: %.cc @echo "Compiling $<" @$(CXX) -DTHROTTLE_EDGE_TPU $(LIBEDGETPU_CXXFLAGS) $(LIBEDGETPU_INCLUDES) -c $< -MD -MT $@ -MF $(@:%o=%d) -o $@ -libedgetpu: | firmware $(LIBEDGETPU_FLATC_OBJS) $(LIBEDGETPU_COBJS) $(LIBEDGETPU_CCOBJS) $(LIBEDGETPU_MAX_CCOBJS) +libedgetpu: | firmware $(LIBEDGETPU_FLATC_OBJS) $(LIBEDGETPU_CCOBJS) $(LIBEDGETPU_MAX_CCOBJS) @mkdir -p $(BUILDDIR)/direct/k8 @echo "Building libedgetpu.so" - @$(CXX) $(LIBEDGETPU_CCFLAGS) $(LIBEDGETPU_LDFLAGS) $(LIBEDGETPU_COBJS) $(LIBEDGETPU_CCOBJS) $(LIBEDGETPU_MAX_CCOBJS) -o $(BUILDDIR)/direct/k8/libedgetpu.so.1.0 + @$(CXX) $(LIBEDGETPU_CCFLAGS) $(LIBEDGETPU_LDFLAGS) ${LDFLAGS} $(LIBEDGETPU_CCOBJS) $(LIBEDGETPU_MAX_CCOBJS) -o $(BUILDDIR)/direct/k8/libedgetpu.so.1.0 @ln -sf $(BUILDDIR)/direct/k8/libedgetpu.so.1.0 $(BUILDDIR)/direct/k8/libedgetpu.so.1 -libedgetpu-throttled: | firmware $(LIBEDGETPU_FLATC_OBJS) $(LIBEDGETPU_COBJS) $(LIBEDGETPU_CCOBJS) $(LIBEDGETPU_STD_CCOBJS) +libedgetpu-throttled: | firmware $(LIBEDGETPU_FLATC_OBJS) $(LIBEDGETPU_CCOBJS) $(LIBEDGETPU_STD_CCOBJS) @mkdir -p $(BUILDDIR)/throttled/k8 @echo "Building throttled libedgetpu.so" - @$(CXX) $(LIBEDGETPU_CCFLAGS) $(LIBEDGETPU_LDFLAGS) $(LIBEDGETPU_COBJS) $(LIBEDGETPU_CCOBJS) $(LIBEDGETPU_STD_CCOBJS) -o $(BUILDDIR)/throttled/k8/libedgetpu.so.1.0 + @$(CXX) $(LIBEDGETPU_CCFLAGS) $(LIBEDGETPU_LDFLAGS) ${LDFLAGS} $(LIBEDGETPU_CCOBJS) $(LIBEDGETPU_STD_CCOBJS) -o $(BUILDDIR)/throttled/k8/libedgetpu.so.1.0 @ln -sf $(BUILDDIR)/throttled/k8/libedgetpu.so.1.0 $(BUILDDIR)/throttled/k8/libedgetpu.so.1 diff --git a/makefile_build/README.md b/makefile_build/README.md index a0ed003..35c5b2f 100644 --- a/makefile_build/README.md +++ b/makefile_build/README.md @@ -10,7 +10,7 @@ sudo apt install libabsl-dev libflatbuffers-dev Next, you'll need to clone the [Tensorflow Repo](https://github.com/tensorflow/tensorflow) at the desired checkout (using TF head isn't advised). If you are planning to use libcoral or pycoral libraries, this should match the ones in those repos' WORKSPACE files. For example, if you are using TF2.5, we can check that [tag in the TF Repo](https://github.com/tensorflow/tensorflow/commit/a4dfb8d1a71385bd6d122e4f27f86dcebb96712d) and then checkout that address: ``` git clone https://github.com/tensorflow/tensorflow -git checkout a4dfb8d1a71385bd6d122e4f27f86dcebb96712d -b tf2.5 +git checkout v2.6.1 ``` To build the library: From b3c3339ee977357407569da16c9f2e74af1b5184 Mon Sep 17 00:00:00 2001 From: Nobuo Tsukamoto Date: Thu, 9 May 2024 21:18:39 +0900 Subject: [PATCH 2/2] Update makefile_build README. --- makefile_build/README.md | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/makefile_build/README.md b/makefile_build/README.md index 35c5b2f..907d851 100644 --- a/makefile_build/README.md +++ b/makefile_build/README.md @@ -2,18 +2,37 @@ If only building for native systems, it is possible to significantly reduce the complexity of the build by removing Bazel (and Docker). This simple approach builds only what is needed, removes build-time depenency fetching, increases the speed, and uses upstream Debian packages. -To prepare your system, you'll need the following packages (both available on Debian Bullseye): +To prepare your system, you'll need the following packages (both available on Debian Bookworm / Ubuntu 22.04): ``` -sudo apt install libabsl-dev libflatbuffers-dev +sudo apt install libabsl-dev libusb-1.0-0-dev xxd ``` -Next, you'll need to clone the [Tensorflow Repo](https://github.com/tensorflow/tensorflow) at the desired checkout (using TF head isn't advised). If you are planning to use libcoral or pycoral libraries, this should match the ones in those repos' WORKSPACE files. For example, if you are using TF2.5, we can check that [tag in the TF Repo](https://github.com/tensorflow/tensorflow/commit/a4dfb8d1a71385bd6d122e4f27f86dcebb96712d) and then checkout that address: +Next, build [FlatBuffers](https://github.com/google/flatbuffers) from source. This is because the version of Flatbuffers provided in the package is different from the version required by TensorFlow v2.16.1. ``` -git clone https://github.com/tensorflow/tensorflow -git checkout v2.6.1 +git clone https://github.com/google/flatbuffers.git +cd flatbuffers/ +git checkout v23.5.26 +mkdir build && cd build +cmake .. \ + -DFLATBUFFERS_BUILD_SHAREDLIB=ON \ + -DFLATBUFFERS_BUILD_TESTS=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/usr/local +make -j$(nproc) +sudo make install ``` -To build the library: +Next, you'll need to clone the [Tensorflow Repo](https://github.com/tensorflow/tensorflow) at the desired checkout (using TF head isn't advised). If you are planning to use libcoral or pycoral libraries, this should match the ones in those repos' WORKSPACE files. For example, if you are using TF2.16.1, we can check that [tag in the TF Repo](https://github.com/tensorflow/tensorflow/tree/v2.16.1) and then checkout that address: ``` -TFROOT= make -j$(nproc) libedgetpu +git clone https://github.com/tensorflow/tensorflow.git +cd tensorflow +git checkout git checkout v2.16.1 +``` + +To build the library: +Note: The `LDFLAGS` flag is required if you specify flatbuffers to be installed to `"/usr/local"`. +``` +git clone https://github.com/google-coral/libedgetpu.git +cd libedgetpu/makefile_build +TFROOT=/home/pi/tensorflow/ LDFLAGS="-L/usr/local/lib" make -j$(nproc) libedgetpu ```