diff --git a/Makefile b/Makefile index d1479b8..6ebba5c 100644 --- a/Makefile +++ b/Makefile @@ -172,7 +172,7 @@ chmod a+w /; \ groupadd --gid $(shell id -g) $(shell id -g -n); \ useradd -m -e '' -s /bin/bash --gid $(shell id -g) --uid $(shell id -u) $(shell id -u -n); \ echo '$(shell id -u -n) ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers; \ -su $(shell id -u -n) $(if $(1),-c '$(1)',) +su $(if $(1),-c '$(1)',) endef docker-image: diff --git a/README.md b/README.md index a8f85cc..dc5d55b 100644 --- a/README.md +++ b/README.md @@ -35,9 +35,9 @@ debuild -us -uc -tc -b -a amd64 -d ``` ### Bazel -The version of `bazel` needs to be the same as that recommended for the corresponding version of tensorflow. For example, it requires `Bazel 6.5.0` to compile TF 2.16.1. +The version of `bazel` needs to be the same as that recommended for the corresponding version of tensorflow. For example, it requires `Bazel 6.5.0` to compile TF 2.17.1. -Current version of tensorflow supported is `2.16.1`. +The current version of Tensorflow supported is `2.17.1`. Build native binaries on Linux and macOS: ``` @@ -61,6 +61,12 @@ $ CPU=armv7a make $ CPU=aarch64 make ``` +Cross-compile for Apple Silicon (arm64), or Intel (x86_64) on MacOS: +``` +$ CPU=darwin_arm64 make +$ CPU=darwin_x86_64 make +``` + To package a Debian deb: ``` debuild -us -uc -tc -b @@ -77,18 +83,42 @@ Repeat compilation. 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 Bookworm, Bullseye or Buster-Backports): +To prepare your system, you'll need the following packages: ``` 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.15, we can check that [tag in the TF Repo](https://github.com/tensorflow/tensorflow/tree/r2.15) get the latest commit for that stable release and then checkout that address: +For Ubuntu 24.10 or newer you also need: +``` +sudo apt install libflatbuffers-dev +``` +For previous versions, you need a newer version of `libflatbuffers-dev` than the one available from the distribution: + +``` +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 +make +sudo make install +``` + + +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 TF 2.17.1, we can check that [tag in the TF Repo](https://github.com/tensorflow/tensorflow/tree/r2.15) get the latest commit for that stable release and then checkout that address: ``` git clone https://github.com/tensorflow/tensorflow -git checkout v2.16.1 +git checkout v2.17.1 +``` + +To build the library for Debian/Ubuntu: +``` +TFROOT=/ LD_LIBRARY_PATH=/usr/local/lib/ make -f makefile_build/Makefile libedgetpu-throttled +TFROOT=/ LD_LIBRARY_PATH=/usr/local/lib/ make -f makefile_build/Makefile libedgetpu-throttled +debuild -us -uc -tc -b -a amd64 -d ``` -To build the library: +To build the library for MacOS: ``` TFROOT= make -f makefile_build/Makefile -j$(nproc) libedgetpu ``` @@ -116,3 +146,4 @@ Google does not accept any responsibility for any loss or damage if the device is operated outside of the recommended ambient temperature range. Note: This issue affects only USB-based Coral devices, and is irrelevant for PCIe devices. +ß diff --git a/debian/changelog b/debian/changelog index d0f73ba..b3fdf55 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,12 @@ +libedgetpu (16.0tf2.17.1-1) stable; urgency=medium + * Build against TF v2.17.1 +-- Nicola Ferralis Mon, 24 Oct 2024 11:33:39 -0400 +libedgetpu (16.0tf2.17.0-1) stable; urgency=medium + * Build against TF v2.17.0 +-- Nicola Ferralis < feranick@hotmail.com> Fri, 12 Jul 2024 09:41:18 -0400 libedgetpu (16.0tf2.16.1-1) stable; urgency=medium * Build against TF v2.16.1 --- Nicola Ferralis < feranick@hotmail.com> Thu, 07 Mar 2024 14:01:34 -0500 +-- Nicola Ferralis Thu, 07 Mar 2024 14:01:34 -0500 libedgetpu (16.0tf2.15.0-1) stable; urgency=medium * Build against TF v2.15.0 -- Nicola Ferralis Tue, 31 Jan 2024 09:10:34 -0500 diff --git a/docker/Dockerfile.windows b/docker/Dockerfile.windows index 89d5cd5..cf85092 100644 --- a/docker/Dockerfile.windows +++ b/docker/Dockerfile.windows @@ -28,20 +28,20 @@ RUN choco install -y 7zip RUN setx /M PATH $($Env:PATH + ';C:\Program Files\7-Zip') # Install msys2 -ARG MSYS_VERSION=20240113 +ARG MSYS_VERSION=20240727 ADD http://repo.msys2.org/distrib/x86_64/msys2-base-x86_64-${MSYS_VERSION}.tar.xz c:/windows/temp RUN 7z.exe x c:\windows\temp\msys2-base-x86_64-$env:MSYS_VERSION.tar.xz RUN 7z.exe x c:\msys2-base-x86_64-$env:MSYS_VERSION.tar -o"c:\\" RUN setx /M PATH $($Env:PATH + ';C:\msys64\usr\bin') # Install patch -ARG PATCH_VERSION=2.7.6-1 +ARG PATCH_VERSION=2.7.6-2 ADD http://repo.msys2.org/msys/x86_64/patch-${PATCH_VERSION}-x86_64.pkg.tar.xz c:/windows/temp RUN 7z.exe x -y c:\windows\temp\patch-$env:PATCH_VERSION-x86_64.pkg.tar.xz RUN 7z.exe x -y c:\patch-$env:PATCH_VERSION-x86_64.pkg.tar -o"c:\\msys64" # Install vim (for xxd) -ARG VIM_VERSION=9.1.0000-1 +ARG VIM_VERSION=9.1.0707-1 ADD http://repo.msys2.org/msys/x86_64/vim-${VIM_VERSION}-x86_64.pkg.tar.zst c:/windows/temp RUN 7z.exe x -y c:\windows\temp\vim-$env:VIM_VERSION-x86_64.pkg.tar.zst RUN 7z.exe x -y c:\vim-$env:VIM_VERSION-x86_64.pkg.tar -o"c:\\msys64" diff --git a/docker/update_sources.sh b/docker/update_sources.sh index 19ddaa1..7913d7e 100755 --- a/docker/update_sources.sh +++ b/docker/update_sources.sh @@ -18,8 +18,47 @@ sed -i "s/deb\ /deb \[arch=amd64\]\ /g" /etc/apt/sources.list +if [ ${UBUNTU_CODENAME} == "noble" ]; then + +echo "NOBLE" + +rm /etc/apt/sources.list.d/ubuntu.sources +cat <> /etc/apt/sources.list.d/ubuntu.sources + +Types: deb +URIs: http://archive.ubuntu.com/ubuntu/ +Suites: ${UBUNTU_CODENAME} ${UBUNTU_CODENAME}-updates ${UBUNTU_CODENAME}-backports +Components: main universe restricted multiverse +Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg +Architectures: amd64 + +## Ubuntu security updates. Aside from URIs and Suites, +## this should mirror your choices in the previous section. +Types: deb +URIs: http://security.ubuntu.com/ubuntu/ +Suites: ${UBUNTU_CODENAME}-security +Components: main universe restricted multiverse +Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg +Architectures: amd64 + +Types: deb +URIs: http://ports.ubuntu.com/ubuntu-ports +Suites: ${UBUNTU_CODENAME} ${UBUNTU_CODENAME}-updates ${UBUNTU_CODENAME}-security +Components: main universe +Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg +Architectures: arm64 armhf + +EOT + +else + cat <> /etc/apt/sources.list deb [arch=arm64,armhf] http://ports.ubuntu.com/ubuntu-ports ${UBUNTU_CODENAME} main universe deb [arch=arm64,armhf] http://ports.ubuntu.com/ubuntu-ports ${UBUNTU_CODENAME}-updates main universe deb [arch=arm64,armhf] http://ports.ubuntu.com/ubuntu-ports ${UBUNTU_CODENAME}-security main universe EOT + +fi + + + diff --git a/makefile_build/Makefile b/makefile_build/Makefile index ef7d290..fc1893a 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 := \ @@ -59,7 +59,7 @@ LIBEDGETPU_INCLUDES := \ $(BUILDDIR)/$(BUILDROOT) LIBEDGETPU_INCLUDES := $(addprefix -I,$(LIBEDGETPU_INCLUDES)) -LIBEDGETPU_CSRCS := $(TFROOT)/tensorflow/lite/c/common.c +LIBEDGETPU_CSRCS := $(TFROOT)/tensorflow/lite/c/common_internal.cc LIBEDGETPU_COBJS := $(call TOBUILDDIR,$(patsubst %.c,%.o,$(LIBEDGETPU_CSRCS))) LIBEDGETPU_CCSRCS := \ @@ -140,7 +140,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 @@ -180,12 +182,6 @@ firmware: done @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 +197,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..8bcfea9 100644 --- a/makefile_build/README.md +++ b/makefile_build/README.md @@ -2,18 +2,40 @@ 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/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 +``` + +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: + ``` git clone https://github.com/tensorflow/tensorflow -git checkout a4dfb8d1a71385bd6d122e4f27f86dcebb96712d -b tf2.5 +cd tensorflow +git checkout v2.17.0 ``` To build the library: +Note: The `LDFLAGS` flag is required if you specify flatbuffers to be installed to `"/usr/local"`. + ``` -TFROOT= make -j$(nproc) libedgetpu +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 ``` diff --git a/workspace.bzl b/workspace.bzl index 979e44d..bbda68e 100644 --- a/workspace.bzl +++ b/workspace.bzl @@ -46,8 +46,20 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") #TENSORFLOW_SHA256 = "bb25fa4574e42ea4d452979e1d2ba3b86b39569d6b8106a846a238b880d73652" # TF release 2.16.1 as of 03/07/2024. Current. -TENSORFLOW_COMMIT = "5bc9d26649cca274750ad3625bd93422617eed4b" -TENSORFLOW_SHA256 = "fe592915c85d1a89c20f3dd89db0772ee22a0fbda78e39aa46a778d638a96abc" +#TENSORFLOW_COMMIT = "5bc9d26649cca274750ad3625bd93422617eed4b" +#TENSORFLOW_SHA256 = "fe592915c85d1a89c20f3dd89db0772ee22a0fbda78e39aa46a778d638a96abc" + +# TF release 2.17.0 as of 07/12/2024. +#TENSORFLOW_COMMIT = "ad6d8cc177d0c868982e39e0823d0efbfb95f04c" +#TENSORFLOW_SHA256 = "75b8dc9b33afff6f2e2d2e2dacc26dd0973bdcee94eec2af290828c1bc574bdc" + +# TF release 2.17.1 as of 10/24/2024. +TENSORFLOW_COMMIT = "3c92ac03cab816044f7b18a86eb86aa01a294d95" +TENSORFLOW_SHA256 = "317dd95c4830a408b14f3e802698eb68d70d81c7c7cfcd3d28b0ba023fe84a68" + +# TF release 2.18.0 as of 10/24/2024. +#TENSORFLOW_COMMIT = "6550e4bd80223cdb8be6c3afd1f81e86a4d433c3" +#TENSORFLOW_SHA256 = "403916fbcfcbd5657cd891a871debc72433d7a8c56760297a79085e1abc8f18a" #CORAL_CROSSTOOL_COMMIT = "6bcc2261d9fc60dff386b557428d98917f0af491" #CORAL_CROSSTOOL_SHA256 = "38cb4da13009d07ebc2fed4a9d055b0f914191b344dd2d1ca5803096343958b4"