From 901e6af5395b22a5f9bac10c2574a1c810fd3f10 Mon Sep 17 00:00:00 2001 From: Terry Heo Date: Mon, 10 Feb 2020 20:29:57 -0800 Subject: [PATCH] Use single job for building TFLite when RAM isn't enough During native ARM build of TFLite, some devices will get frozen by OOM during the building. This patch prevents it. This patch fixes GitHub issue #36336. PiperOrigin-RevId: 294363969 Change-Id: I0cef7df39d8084544a21a6fa012f04968f492939 --- tensorflow/lite/tools/make/build_aarch64_lib.sh | 10 +++++++++- tensorflow/lite/tools/make/build_rpi_lib.sh | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tensorflow/lite/tools/make/build_aarch64_lib.sh b/tensorflow/lite/tools/make/build_aarch64_lib.sh index 0ce4089c11c..a776e498193 100755 --- a/tensorflow/lite/tools/make/build_aarch64_lib.sh +++ b/tensorflow/lite/tools/make/build_aarch64_lib.sh @@ -20,5 +20,13 @@ set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" TENSORFLOW_DIR="${SCRIPT_DIR}/../../../.." -make -j 4 TARGET=aarch64 -C "${TENSORFLOW_DIR}" -f tensorflow/lite/tools/make/Makefile +FREE_MEM="$(free -m | awk '/^Mem/ {print $2}')" +# Use "-j 4" only memory is larger than 2GB +if [[ "FREE_MEM" -gt "2000" ]]; then + NO_JOB=4 +else + NO_JOB=1 +fi + +make -j ${NO_JOB} TARGET=aarch64 -C "${TENSORFLOW_DIR}" -f tensorflow/lite/tools/make/Makefile diff --git a/tensorflow/lite/tools/make/build_rpi_lib.sh b/tensorflow/lite/tools/make/build_rpi_lib.sh index c7edc6755e9..d3556e9f554 100755 --- a/tensorflow/lite/tools/make/build_rpi_lib.sh +++ b/tensorflow/lite/tools/make/build_rpi_lib.sh @@ -20,5 +20,13 @@ set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" TENSORFLOW_DIR="${SCRIPT_DIR}/../../../.." -make -j 4 TARGET=rpi -C "${TENSORFLOW_DIR}" -f tensorflow/lite/tools/make/Makefile +FREE_MEM="$(free -m | awk '/^Mem/ {print $2}')" +# Use "-j 4" only memory is larger than 2GB +if [[ "FREE_MEM" -gt "2000" ]]; then + NO_JOB=4 +else + NO_JOB=1 +fi + +make -j ${NO_JOB} TARGET=rpi -C "${TENSORFLOW_DIR}" -f tensorflow/lite/tools/make/Makefile