-
Notifications
You must be signed in to change notification settings - Fork 18
/
python3-tensorflow-lite_2.18.0.bb
executable file
·164 lines (137 loc) · 5.94 KB
/
python3-tensorflow-lite_2.18.0.bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
DESCRIPTION = "TensorFlow Lite Standalone Pip"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://LICENSE;md5=4158a261ca7f2525513e31ba9c50ae98"
# Compute branch info from ${PV} as Base PV...
BPV = "${@'.'.join(d.getVar('PV').split('.')[0:2])}"
DPV = "${@'.'.join(d.getVar('PV').split('.')[0:3])}"
SRCREV_tensorflow = "6550e4bd80223cdb8be6c3afd1f81e86a4d433c3"
SRC_URI = " \
git://github.com/tensorflow/tensorflow.git;name=tensorflow;branch=r${BPV};protocol=https \
file://001-Set-CMAKE-SYSTEM-PROCESSOR.patch \
file://001-Fix-neon-sse-file-name-filter.patch \
file://001-Add-Wno-incompatible-pointer-types-flag-to-xnnpack.cmake.patch \
"
SRC_URI:append:riscv32 = " \
file://001-Disable-XNNPACK-RISC-V-Vector-micro-kernels.patch \
file://001-RISCV32_pthreads.patch \
"
S = "${WORKDIR}/git"
DEPENDS += "\
python3-pip-native \
python3-wheel-native \
python3-numpy \
python3-pybind11 \
libgfortran \
protobuf-native \
flatbuffers-native \
"
RDEPENDS:${PN} += " \
python3 \
python3-numpy \
"
inherit setuptools3 cmake
TENSORFLOW_LITE_BUILD_DIR = "${S}/tensorflow/lite/tools/pip_package/gen/tflite_pip/python3"
TENSORFLOW_LITE_DIR = "${S}/tensorflow/lite"
PYBIND11_INCLUDE = "${PYTHON_INCLUDE_DIR}/pybind11"
NUMPY_INCLUDE = "${PKG_CONFIG_SYSROOT_DIR}/${PYTHON_SITEPACKAGES_DIR}/numpy/core/include"
OECMAKE_SOURCEPATH = "${TENSORFLOW_LITE_DIR}"
OECMAKE_TARGET_COMPILE= "_pywrap_tensorflow_interpreter_wrapper"
OECMAKE_C_FLAGS += "-I${PYTHON_INCLUDE_DIR} -I${PYBIND11_IN} -I${NUMPY_INCLUDE}"
OECMAKE_CXX_FLAGS += "-I${PYTHON_INCLUDE_DIR} -I${PYBIND11_INCLUDE} -I${NUMPY_INCLUDE}"
EXTRA_OECMAKE = " \
-DFETCHCONTENT_FULLY_DISCONNECTED=OFF \
-DTFLITE_ENABLE_XNNPACK=OFF \
"
# Note:
# XNNPack is valid only on 64bit.
# In the case of arm 32bit, it will be turned off because the build will be
# an error depending on the combination of target CPUs.
EXTRA_OECMAKE:append:aarch64 = " -DTFLITE_ENABLE_XNNPACK=ON"
EXTRA_OECMAKE:append:riscv32 = " -DTFLITE_ENABLE_XNNPACK=ON"
EXTRA_OECMAKE:append:riscv64 = " -DTFLITE_ENABLE_XNNPACK=ON"
TENSORFLOW_TARGET_ARCH:raspberrypi = "armv6"
TENSORFLOW_TARGET_ARCH:raspberrypi0 = "armv6"
TENSORFLOW_TARGET_ARCH:raspberrypi0-wifi = "armv6"
TENSORFLOW_TARGET_ARCH:raspberrypi-cm = "armv6"
TENSORFLOW_TARGET_ARCH:raspberrypi2 = "armv7"
TENSORFLOW_TARGET_ARCH:raspberrypi3 = "armv7"
TENSORFLOW_TARGET_ARCH:raspberrypi4 = "armv7"
TENSORFLOW_TARGET_ARCH:raspberrypi-cm3 = "armv7"
TENSORFLOW_TARGET_ARCH:raspberrypi0-2w-64 = "aarch64"
TENSORFLOW_TARGET_ARCH:raspberrypi3-64 = "aarch64"
TENSORFLOW_TARGET_ARCH:raspberrypi4-64 = "aarch64"
TENSORFLOW_TARGET_ARCH:raspberrypi5 = "aarch64"
TENSORFLOW_TARGET_ARCH:riscv32 = "riscv32"
TENSORFLOW_TARGET_ARCH:riscv64 = "riscv64"
# Note:
# Download the submodule using FetchContent_Populate.
# Therefore, turn off FETCHCONTENT_FULLY_DISCONNECTED.
EXTRA_OECMAKE:append = " \
-DTENSORFLOW_TARGET_ARCH=${TENSORFLOW_TARGET_ARCH} \
-DTFLITE_HOST_TOOLS_DIR=${WORKDIR}/recipe-sysroot-native/usr/bin/ \
"
do_configure[network] = "1"
do_configure:append() {
if [ -e ${S}/tensorflow/lite/tools/pip_package/riscv32_pthread.patch ]; then
cd ${B}/pthreadpool-source/src
patch < ${S}/tensorflow/lite/tools/pip_package/riscv32_pthread.patch
fi
}
do_compile:prepend() {
TENSORFLOW_VERSION=$(grep "_VERSION = " "${S}/tensorflow/tools/pip_package/setup.py" | cut -d= -f2 | sed "s/[ '-]//g")
export PACKAGE_VERSION="${TENSORFLOW_VERSION}"
export PROJECT_NAME="tflite_runtime"
rm -rf "${TENSORFLOW_LITE_BUILD_DIR}" && mkdir -p "${TENSORFLOW_LITE_BUILD_DIR}/tflite_runtime"
cp -r "${TENSORFLOW_LITE_DIR}/tools/pip_package/debian" \
"${TENSORFLOW_LITE_DIR}/tools/pip_package/MANIFEST.in" \
"${TENSORFLOW_LITE_DIR}/python/interpreter_wrapper" \
"${TENSORFLOW_LITE_BUILD_DIR}"
cp "${TENSORFLOW_LITE_DIR}/tools/pip_package/setup_with_binary.py" "${TENSORFLOW_LITE_BUILD_DIR}/setup.py"
cp "${TENSORFLOW_LITE_DIR}/python/interpreter.py" \
"${TENSORFLOW_LITE_DIR}/python/metrics/metrics_interface.py" \
"${TENSORFLOW_LITE_DIR}/python/metrics/metrics_portable.py" \
"${TENSORFLOW_LITE_BUILD_DIR}/tflite_runtime"
echo "__version__ = '${PACKAGE_VERSION}'" >> "${TENSORFLOW_LITE_BUILD_DIR}/tflite_runtime/__init__.py"
echo "__git_version__ = '$(git -C "${S}" describe)'" >> "${TENSORFLOW_LITE_BUILD_DIR}/tflite_runtime/__init__.py"
}
do_compile:append() {
cp "${B}/_pywrap_tensorflow_interpreter_wrapper.so" \
"${TENSORFLOW_LITE_BUILD_DIR}/tflite_runtime"
cd "${TENSORFLOW_LITE_BUILD_DIR}"
echo ${STAGING_BINDIR_NATIVE}/${PYTHON_PN}-native/${PYTHON_PN}
if [ ${TARGET_ARCH} = "aarch64" ]; then
echo "build aarch64"
export TENSORFLOW_TARGET=aarch64
export TARGET=aarch64
elif [ ${TARGET_ARCH} = "arm" ]; then
echo "build arm"
export TENSORFLOW_TARGET=rpi
export TARGET=rpi
elif [ ${TARGET_ARCH} = "riscv64" ]; then
echo "build riscv64"
export TENSORFLOW_TARGET=riscv64
export TARGET=riscv64
elif [ ${TARGET_ARCH} = "riscv32" ]; then
echo "build riscv32"
export TENSORFLOW_TARGET=riscv32
export TARGET=riscv32
fi
STAGING_INCDIR=${STAGING_INCDIR} \
STAGING_LIBDIR=${STAGING_LIBDIR} \
${STAGING_BINDIR_NATIVE}/${PYTHON_PN}-native/${PYTHON_PN} setup.py \
bdist bdist_wheel
}
do_install() {
echo "Generating pip package"
cd "${TENSORFLOW_LITE_BUILD_DIR}"
install -d ${D}/${PYTHON_SITEPACKAGES_DIR}
echo ${D}/${PYTHON_SITEPACKAGES_DIR}
TAGING_INCDIR=${STAGING_INCDIR} \
STAGING_LIBDIR=${STAGING_LIBDIR} \
${STAGING_BINDIR_NATIVE}/${PYTHON_PN}-native/${PYTHON_PN} -m pip install --disable-pip-version-check -v \
-t ${D}/${PYTHON_SITEPACKAGES_DIR} --no-cache-dir --no-deps \
${S}/tensorflow/lite/tools/pip_package/gen/tflite_pip/python3/dist/tflite_runtime-${DPV}*.whl
}
FILES:${PN}-dev = ""
INSANE_SKIP:${PN} += "dev-so buildpaths"
FILES:${PN} += "${libdir}/* ${datadir}/*"