Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for TF 2.17.0 #70

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
60435a8
Add support for TF 2.16.0-rc0
feranick Mar 7, 2024
27b1288
Use c++17 for all platforms
feranick Mar 7, 2024
5c3cae5
Add support for TF 2.16.1 stable
feranick Mar 7, 2024
f3e9264
Simplify versioning in debian
feranick Mar 7, 2024
bf24e54
Merge branch 'google-coral:master' into master
feranick Mar 14, 2024
1adc5c5
Initial support for TF 2.17.0-rc0
feranick Jun 20, 2024
a3e55fb
Updated debian changelog for TF 2.17.0-rc0
feranick Jun 20, 2024
ef12033
Disable previous version of TF in workspace.bzl
feranick Jun 20, 2024
d167fd7
Bug fixes on debian changelog
feranick Jun 20, 2024
1494008
Updated README.md
feranick Jun 21, 2024
05beb38
Updated Dockerfile.windows with latest dependencies
feranick Jun 21, 2024
d609eaa
Added Support for TF 2.17.0-rc1
feranick Jul 7, 2024
28287cf
Add support for TF 2.17.0 stable.
feranick Jul 12, 2024
d254c1a
Added support for Ubuntu:24.04
feranick Aug 11, 2024
1390341
Updated third party libraries Docker.windows
feranick Aug 11, 2024
4f8de82
Updates Makefile for modern versions of Tensorflow
feranick Sep 18, 2024
0f7fb7a
Update makefile_build/README.md
feranick Sep 18, 2024
16d801e
Updated README.md
feranick Sep 30, 2024
7a23e51
Added support for TF 2.18.0-rc0
feranick Oct 1, 2024
3347dd6
Updated Software sources for Docker-windows
feranick Oct 1, 2024
242f258
Bug fix
feranick Oct 1, 2024
b281c55
Update building only with a Makefile
feranick Oct 7, 2024
b68ae68
Added support for Tensorflow 2.17.1
feranick Oct 28, 2024
2dc1461
Updated README.md
feranick Oct 28, 2024
ba7db81
Typo fix.
feranick Oct 28, 2024
ea190a7
Typo fix
feranick Oct 29, 2024
bf2a7fd
Update README.md with info about MacOS cross-compilation
feranick Oct 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
43 changes: 37 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
Expand All @@ -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
Expand All @@ -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=<path to tensorflow source>/ LD_LIBRARY_PATH=/usr/local/lib/ make -f makefile_build/Makefile libedgetpu-throttled
TFROOT=<path to tensorflow source>/ 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=<Directory of Tensorflow> make -f makefile_build/Makefile -j$(nproc) libedgetpu
```
Expand Down Expand Up @@ -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.
ß
8 changes: 7 additions & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
libedgetpu (16.0tf2.17.1-1) stable; urgency=medium
* Build against TF v2.17.1
-- Nicola Ferralis <[email protected]> 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 < [email protected]> 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 < [email protected]> Thu, 07 Mar 2024 14:01:34 -0500
-- Nicola Ferralis <[email protected]> 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 <[email protected]> Tue, 31 Jan 2024 09:10:34 -0500
Expand Down
6 changes: 3 additions & 3 deletions docker/Dockerfile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
39 changes: 39 additions & 0 deletions docker/update_sources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOT >> /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 <<EOT >> /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



22 changes: 9 additions & 13 deletions makefile_build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ LIBEDGETPU_CFLAGS := \
LIBEDGETPU_CXXFLAGS := \
-fPIC \
-Wall \
-std=c++14 \
-std=c++17 \
-DDARWINN_PORT_DEFAULT

LIBEDGETPU_LDFLAGS := \
Expand Down Expand Up @@ -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 := \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 $<"
Expand All @@ -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
32 changes: 27 additions & 5 deletions makefile_build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<Directory of Tensorflow> 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
```
16 changes: 14 additions & 2 deletions workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down