Skip to content

Commit 223ce99

Browse files
Update full tflite to 2.16.1, add native Mac ARM64 libs (#22)
* updated source * updated compiled libs * bash script and readme fixes * Makefile and readme changes for mac arm64 and TI
1 parent 806ca3b commit 223ce99

File tree

1,270 files changed

+73381
-142225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,270 files changed

+73381
-142225
lines changed

Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,29 +83,32 @@ CFLAGS += -Itensorflow-lite/
8383
CCSOURCES += $(wildcard edge-impulse-sdk/tensorflow/lite/kernels/custom/*.cc)
8484

8585
ifeq (${TARGET_LINUX_ARMV7},1)
86-
LDFLAGS += -L./tflite/linux-armv7 -Wl,--no-as-needed -ldl -ltensorflow-lite -lfarmhash -lfft2d_fftsg -lfft2d_fftsg2d -lflatbuffers -lruy -lXNNPACK -lpthreadpool -lpthread -lcpuinfo -lclog
86+
LDFLAGS += -L./tflite/linux-armv7 -Wl,--no-as-needed -ldl -ltensorflow-lite -lfarmhash -lfft2d_fftsg -lfft2d_fftsg2d -lflatbuffers -lruy -lXNNPACK -lpthreadpool -lpthread -lcpuinfo
8787
endif # TARGET_LINUX_ARMV7
8888
ifeq (${TARGET_LINUX_AARCH64},1)
8989
CFLAGS += -DDISABLEFLOAT16
90-
LDFLAGS += -L./tflite/linux-aarch64 -Wl,--no-as-needed -ldl -ltensorflow-lite -lfarmhash -lfft2d_fftsg -lfft2d_fftsg2d -lruy -lXNNPACK -lcpuinfo -lpthreadpool -lclog -lpthread
90+
LDFLAGS += -L./tflite/linux-aarch64 -Wl,--no-as-needed -ldl -ltensorflow-lite -lfarmhash -lfft2d_fftsg -lfft2d_fftsg2d -lruy -lXNNPACK -lcpuinfo -lpthreadpool -lpthread
9191
endif # TARGET_LINUX_AARCH64
9292
ifeq (${TARGET_LINUX_X86},1)
93-
LDFLAGS += -L./tflite/linux-x86 -Wl,--no-as-needed -ldl -ltensorflow-lite -lfarmhash -lfft2d_fftsg -lfft2d_fftsg2d -lruy -lXNNPACK -lcpuinfo -lpthreadpool -lclog -lpthread
93+
LDFLAGS += -L./tflite/linux-x86 -Wl,--no-as-needed -ldl -ltensorflow-lite -lfarmhash -lfft2d_fftsg -lfft2d_fftsg2d -lruy -lXNNPACK -lcpuinfo -lpthreadpool -lpthread
9494
endif # TARGET_LINUX_X86
9595
ifeq (${TARGET_MAC_X86_64},1)
96-
LDFLAGS += -L./tflite/mac-x86_64 -ltensorflow-lite -lcpuinfo -lfarmhash -lfft2d_fftsg -lfft2d_fftsg2d -lruy -lXNNPACK -lpthreadpool -lclog
96+
LDFLAGS += -L./tflite/mac-x86_64 -ltensorflow-lite -lcpuinfo -lfarmhash -lfft2d_fftsg -lfft2d_fftsg2d -lruy -lXNNPACK -lpthreadpool
9797
endif # TARGET_MAC_X86_64
98+
ifeq (${TARGET_MAC_ARM64},1)
99+
LDFLAGS += -L./tflite/mac-arm64 -ltensorflow-lite -lcpuinfo -lfarmhash -lfft2d_fftsg -lfft2d_fftsg2d -lruy -lXNNPACK -lpthreadpool
100+
endif # TARGET_MAC_ARM64
98101

99102
ifeq (${LINK_TFLITE_FLEX_LIBRARY},1)
100-
LDFLAGS += -ltensorflowlite_flex_2.6.5
103+
LDFLAGS += -ltensorflowlite_flex_2.16.1
101104
endif
102105

103106
else ifeq (${USE_AKIDA},1) # USE_FULL_TFLITE
104107
CFLAGS += -DEI_CLASSIFIER_USE_FULL_TFLITE=1
105108
CFLAGS += -DPYBIND11_DETAILED_ERROR_MESSAGES # add more detailed pybind error descriptions
106109
CFLAGS += -Itensorflow-lite
107110
CFLAGS += -Iedge-impulse-sdk/third_party/gemmlowp
108-
LDFLAGS += -Wl,--no-as-needed -ldl -ltensorflow-lite -lfarmhash -lfft2d_fftsg -lfft2d_fftsg2d -lruy -lXNNPACK -lcpuinfo -lpthreadpool -lclog -lpthread
111+
LDFLAGS += -Wl,--no-as-needed -ldl -ltensorflow-lite -lfarmhash -lfft2d_fftsg -lfft2d_fftsg2d -lruy -lXNNPACK -lcpuinfo -lpthreadpool -lpthread
109112
ifeq (${TARGET_LINUX_AARCH64},1)
110113
CFLAGS += $(shell $(PYTHON_CROSS_PATH)python3-config --cflags)
111114
LDFLAGS += -L./tflite/linux-aarch64
@@ -125,6 +128,8 @@ CCSOURCES += $(wildcard edge-impulse-sdk/tensorflow/lite/kernels/*.cc) $(wildcar
125128
endif # not USE_FULL_TFLITE
126129

127130
ifeq (${USE_MEMRYX},1)
131+
CFLAGS += -Iedge-impulse-sdk/third_party/gemmlowp
132+
LDFLAGS += -Wl,--no-as-needed -ldl -ltensorflow-lite -lfarmhash -lfft2d_fftsg -lfft2d_fftsg2d -lruy -lXNNPACK -lcpuinfo -lpthreadpool -lpthread
128133
ifeq (${TARGET_LINUX_AARCH64},1)
129134
$(error MemryX drivers and runtime do not support AARCH64)
130135
else ifeq (${TARGET_LINUX_X86},1)
@@ -133,6 +138,7 @@ CFLAGS += $(shell python3-config --cflags)
133138
CFLAGS += -DPYBIND11_DETAILED_ERROR_MESSAGES
134139
LDFLAGS += -rdynamic $(shell python3-config --ldflags --embed)
135140
else
141+
LDFLAGS += -L./tflite/linux-x86
136142
LDFLAGS += -lmemx
137143
endif # USE_MEMRYX_SOFTWARE
138144
endif # USE_MEMRYX && TARGET_LINUX_X86

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,9 @@ $ APP_CUSTOM=1 TARGET_MAC_X86_64=1 USE_FULL_TFLITE=1 make -j
126126
Build with the following flags:
127127
128128
```
129-
$ APP_CUSTOM=1 TARGET_MAC_X86_64=1 USE_FULL_TFLITE=1 arch -x86_64 /usr/bin/make -j
129+
$ APP_CUSTOM=1 TARGET_MAC_ARM64=1 USE_FULL_TFLITE=1 /usr/bin/make -j
130130
```
131131
132-
Note that this does build an x86 binary, but it runs very fast through Rosetta.
133-
134132
### AARCH64 with AI Acceleration
135133
136134
#### NVIDIA Jetson Orin - TensorRT (JetPack 5.1.2)
@@ -224,13 +222,16 @@ In case of any issues during runtime, check [Troubleshooting](https://docs.edgei
224222
225223
You can also build with support for TIDL, this fully leverages the Deep Learning Accelerator on the Texas Instruments TDA4VM (AM68PA), AM62A, AM68A.
226224
225+
> [!IMPORTANT]
226+
> Texas Instruments boards are legacy-supported. Current version of Tensorflow Lite (2.16.1) is not supported, you need to checkout the earlier commit before proceeding.
227+
> `git checkout ab4fa0758093a0ebb713e49462ae3c615d19bfa1`
228+
227229
##### TDA4VM (AM68PA)
228230
229231
1. Go to the **Deployment** page in the Edge Impulse Studio.
230-
1. Select the 'TIDL-RT Library', and the 'float32' optimizations.
231-
1. Build the library and copy the folders into this repository.
232-
1. Build your (.eim) application:
233-
232+
2. Select the 'TIDL-RT Library', and the 'float32' optimizations.
233+
3. Build the library and copy the folders into this repository.
234+
4. Build your (.eim) application:
234235
```
235236
$ APP_EIM=1 TARGET_TDA4VM=1 make -j
236237
```
@@ -244,9 +245,9 @@ $ APP_EIM=1 TARGET_TDA4VM=1 USE_ONNX=1 make -j
244245
##### TI AM62A
245246
246247
1. Go to the **Deployment** page in the Edge Impulse Studio.
247-
1. Select the 'TIDL-RT Library (AM62A)', and the 'float32' optimizations.
248-
1. Build the library and copy the folders into this repository.
249-
1. Build your (.eim) application:
248+
2. Select the 'TIDL-RT Library (AM62A)', and the 'float32' optimizations.
249+
3. Build the library and copy the folders into this repository.
250+
4. Build your (.eim) application:
250251
251252
```
252253
$ APP_EIM=1 TARGET_AM62A=1 make -j
@@ -261,9 +262,9 @@ $ APP_EIM=1 TARGET_AM62A=1 USE_ONNX=1 make -j
261262
##### TI AM68A
262263
263264
1. Go to the **Deployment** page in the Edge Impulse Studio.
264-
1. Select the 'TIDL-RT Library (AM68A)', and the 'float32' optimizations.
265-
1. Build the library and copy the folders into this repository.
266-
1. Build your (.eim) application:
265+
2. Select the 'TIDL-RT Library (AM68A)', and the 'float32' optimizations.
266+
3. Build the library and copy the folders into this repository.
267+
4. Build your (.eim) application:
267268
268269
```
269270
$ APP_EIM=1 TARGET_AM68A=1 make -j
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2021 Google Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef FLATBUFFERS_ALLOCATOR_H_
18+
#define FLATBUFFERS_ALLOCATOR_H_
19+
20+
#include "tensorflow-lite/flatbuffers/base.h"
21+
22+
namespace flatbuffers {
23+
24+
// Allocator interface. This is flatbuffers-specific and meant only for
25+
// `vector_downward` usage.
26+
class Allocator {
27+
public:
28+
virtual ~Allocator() {}
29+
30+
// Allocate `size` bytes of memory.
31+
virtual uint8_t *allocate(size_t size) = 0;
32+
33+
// Deallocate `size` bytes of memory at `p` allocated by this allocator.
34+
virtual void deallocate(uint8_t *p, size_t size) = 0;
35+
36+
// Reallocate `new_size` bytes of memory, replacing the old region of size
37+
// `old_size` at `p`. In contrast to a normal realloc, this grows downwards,
38+
// and is intended specifcally for `vector_downward` use.
39+
// `in_use_back` and `in_use_front` indicate how much of `old_size` is
40+
// actually in use at each end, and needs to be copied.
41+
virtual uint8_t *reallocate_downward(uint8_t *old_p, size_t old_size,
42+
size_t new_size, size_t in_use_back,
43+
size_t in_use_front) {
44+
FLATBUFFERS_ASSERT(new_size > old_size); // vector_downward only grows
45+
uint8_t *new_p = allocate(new_size);
46+
memcpy_downward(old_p, old_size, new_p, new_size, in_use_back,
47+
in_use_front);
48+
deallocate(old_p, old_size);
49+
return new_p;
50+
}
51+
52+
protected:
53+
// Called by `reallocate_downward` to copy memory from `old_p` of `old_size`
54+
// to `new_p` of `new_size`. Only memory of size `in_use_front` and
55+
// `in_use_back` will be copied from the front and back of the old memory
56+
// allocation.
57+
void memcpy_downward(uint8_t *old_p, size_t old_size, uint8_t *new_p,
58+
size_t new_size, size_t in_use_back,
59+
size_t in_use_front) {
60+
memcpy(new_p + new_size - in_use_back, old_p + old_size - in_use_back,
61+
in_use_back);
62+
memcpy(new_p, old_p, in_use_front);
63+
}
64+
};
65+
66+
} // namespace flatbuffers
67+
68+
#endif // FLATBUFFERS_ALLOCATOR_H_

0 commit comments

Comments
 (0)