Skip to content

Commit

Permalink
Fix ci compilation bug for esp32 and tensorflow
Browse files Browse the repository at this point in the history
Fixes #25

At the -O2 optimization level we get gcc compiler errors which break the
build:

root@907bbbd0af42:/opt/tflite-micro-micropython/tensorflow# xtensa-esp32-elf-g++ -DNDEBUG -std=c++11  -fstrict-vol
atile-bitfields -mlongcalls -nostdlib -fno-rtti -fno-exceptions -fno-threadsafe-statics -Werror -fno-unwind-tables
 -ffunction-sections -fdata-sections -fmessage-length=0 -DTF_LITE_STATIC_MEMORY -DTF_LITE_DISABLE_X86_NEON -Wsign-
compare -Wdouble-promotion -Wshadow -Wunused-variable -Wmissing-field-initializers -Wunused-function -Wswitch -Wvl
a -Wall -Wextra -Wstrict-aliasing -Wno-unused-parameter -DESP -Wno-return-type -Wno-strict-aliasing -Wno-ignored-q
ualifiers -Wno-return-type -Wno-strict-aliasing -O2 -I. -Itensorflow/lite/micro/tools/make/downloads/gemmlowp -Ite
nsorflow/lite/micro/tools/make/downloads/flatbuffers/include -Itensorflow/lite/micro/tools/make/downloads/ruy -Ite
nsorflow/lite/micro/tools/make/gen/esp_xtensa-esp32_default/genfiles/ -Itensorflow/lite/micro/tools/make/downloads
/kissfft -c tensorflow/lite/micro/kernels/l2_pool_2d.cc -o tensorflow/lite/micro/tools/make/gen/esp_xtensa-esp32_d
efault/obj/kernels/tensorflow/lite/micro/kernels/l2_pool_2d.o
tensorflow/lite/micro/kernels/l2_pool_2d.cc: In function 'TfLiteStatus tflite::{anonymous}::L2Eval(TfLiteContext*,
 TfLiteNode*)':
tensorflow/lite/micro/kernels/l2_pool_2d.cc:128:1: error: insn does not satisfy its constraints:
 }
 ^
(insn 274 18 183 28 (set (reg/v:SF 20 f1 [orig:77 sum_squares ] [77])
        (mem/u/c:SF (symbol_ref/u:SI ("*.LC28") [flags 0x2]) [0  S4 A32])) "./tensorflow/lite/kernels/internal/ref
erence/pooling.h":169 47 {movsf_internal}
     (expr_list:REG_EQUAL (const_double:SF 0.0 [0x0.0p+0])
        (nil)))
during RTL pass: postreload
tensorflow/lite/micro/kernels/l2_pool_2d.cc:128:1: internal compiler error: in extract_constrain_insn, at recog.c:
2210
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.

Also refer to: jcmvbkbc/gcc-xtensa#14

This failure doesn't happen without the micropython specific build
options:
-fstrict-volatile-bitfields
-mlongcalls
-nostdlib

and it only happens at the -O2 optimization level.

This commit works around the problem by switching to the -O3
optimization level.
  • Loading branch information
Michael O'Cleirigh committed Aug 19, 2021
1 parent 9a7bcba commit 0967b90
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ci/build_tensorflow_esp32.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@

set -e

pip install Pillow

BASE_DIR=/opt/tflite-micro-micropython

cd $BASE_DIR/tensorflow

make -f tensorflow/lite/micro/tools/make/Makefile \
CXXFLAGS="-std=c++11 -DNDEBUG -fstrict-volatile-bitfields -mlongcalls -nostdlib -fno-rtti -fno-exceptions -fno-threadsafe-statics -fno-unwind-tables -ffunction-sections -fdata-sections -fmessage-length=0 -DTF_LITE_STATIC_MEMORY -DTF_LITE_DISABLE_X86_NEON -Werror -Wsign-compare -Wdouble-promotion -Wshadow -Wunused-variable -Wmissing-field-initializers -Wunused-function -Wswitch -Wvla -Wall -Wextra -Wstrict-aliasing -Wno-unused-parameter -DESP -Wno-return-type -Wno-strict-aliasing -Wno-ignored-qualifiers -Wno-return-type -Wno-strict-aliasing" \
TARGET_TOOLCHAIN_PREFIX=xtensa-esp32-elf- TARGET=esp TARGET_ARCH=xtensa-esp32 clean
CXXFLAGS="-std=c++11 -O3 -DNDEBUG -fstrict-volatile-bitfields -mlongcalls -nostdlib -fno-rtti -fno-exceptions -fno-threadsafe-statics -fno-unwind-tables -ffunction-sections -fdata-sections -fmessage-length=0 -DTF_LITE_STATIC_MEMORY -DTF_LITE_DISABLE_X86_NEON -Werror -Wsign-compare -Wdouble-promotion -Wshadow -Wunused-variable -Wmissing-field-initializers -Wunused-function -Wswitch -Wvla -Wall -Wextra -Wstrict-aliasing -Wno-unused-parameter -DESP -Wno-return-type -Wno-strict-aliasing -Wno-ignored-qualifiers -Wno-return-type -Wno-strict-aliasing" \
TARGET_TOOLCHAIN_PREFIX=xtensa-esp32-elf- TARGET=esp TARGET_ARCH=xtensa-esp32 KERNEL_OPTIMIZATION_LEVEL=-O3 clean

rm -rf tensorflow/lite/micro/tools/make/downloads

make -f tensorflow/lite/micro/tools/make/Makefile \
CXXFLAGS="-std=c++11 -DNDEBUG -fstrict-volatile-bitfields -mlongcalls -nostdlib -fno-rtti -fno-exceptions -fno-threadsafe-statics -fno-unwind-tables -ffunction-sections -fdata-sections -fmessage-length=0 -DTF_LITE_STATIC_MEMORY -DTF_LITE_DISABLE_X86_NEON -Werror -Wsign-compare -Wdouble-promotion -Wshadow -Wunused-variable -Wmissing-field-initializers -Wunused-function -Wswitch -Wvla -Wall -Wextra -Wstrict-aliasing -Wno-unused-parameter -DESP -Wno-return-type -Wno-strict-aliasing -Wno-ignored-qualifiers -Wno-return-type -Wno-strict-aliasing" \
TARGET_TOOLCHAIN_PREFIX=xtensa-esp32-elf- TARGET=esp TARGET_ARCH=xtensa-esp32
CXXFLAGS="-std=c++11 -O3 -DNDEBUG -fstrict-volatile-bitfields -mlongcalls -nostdlib -fno-rtti -fno-exceptions -fno-threadsafe-statics -fno-unwind-tables -ffunction-sections -fdata-sections -fmessage-length=0 -DTF_LITE_STATIC_MEMORY -DTF_LITE_DISABLE_X86_NEON -Werror -Wsign-compare -Wdouble-promotion -Wshadow -Wunused-variable -Wmissing-field-initializers -Wunused-function -Wswitch -Wvla -Wall -Wextra -Wstrict-aliasing -Wno-unused-parameter -DESP -Wno-return-type -Wno-strict-aliasing -Wno-ignored-qualifiers -Wno-return-type -Wno-strict-aliasing" \
TARGET_TOOLCHAIN_PREFIX=xtensa-esp32-elf- TARGET=esp TARGET_ARCH=xtensa-esp32 KERNEL_OPTIMIZATION_LEVEL=-O3

echo "cp tensorflow/lite/micro/tools/make/gen/esp_xtensa-esp32_default/lib/libtensorflow-microlite.a $BASE_DIR/lib"
cp tensorflow/lite/micro/tools/make/gen/esp_xtensa-esp32_default/lib/libtensorflow-microlite.a $BASE_DIR/lib
Expand Down

0 comments on commit 0967b90

Please sign in to comment.