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