Skip to content

Commit

Permalink
added support for patching cmsis lib to use builtin memcpy and memset
Browse files Browse the repository at this point in the history
  • Loading branch information
driedler committed Nov 30, 2021
1 parent 67b303a commit fe2e554
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TF_DIR=$ROOT_DIR/tensorflow
TFLITE_DIR=$TF_DIR/lite
TFLM_DIR=$TFLITE_DIR/micro

export PACKAGE_VERSION=1.0.0
export PACKAGE_VERSION=1.1.0
PYTHON=python3.7
BUILD_DIR=/tmp/tflite_micro_runtime_build
GIT_HASH=`git rev-parse HEAD`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ $TFLM_DIR/tools/make/flatbuffers_download.sh $TFLM_DIR/tools/make/downloads
$TFLM_DIR/tools/make/ruy_download.sh $TFLM_DIR/tools/make/downloads
$TFLM_DIR/tools/make/ext_libs/cmsis_download.sh $TFLM_DIR/tools/make/downloads

python3 $SCRIPT_DIR/patch_cmsis.py


24 changes: 24 additions & 0 deletions tensorflow/lite/micro/tools/rpi0_pip_package/patch_cmsis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os
import sys

curdir = os.path.dirname(os.path.abspath(__file__))
cmsis_arm_math_types_h_path = f'{curdir}/../make/downloads/cmsis/CMSIS/DSP/Include/arm_math_types.h'


with open(cmsis_arm_math_types_h_path, 'r') as fp:
data = fp.read()

if '#define memset __builtin_memset' in data:
sys.exit()


# Ensure the builtin memset and memcpy
# are used. This greatly reduce the overhead of the kernels.
patch_data = '#define _ARM_MATH_TYPES_H_\n\n'
patch_data += '#define memset __builtin_memset\n'
patch_data += '#define memcpy __builtin_memcpy\n\n'

data = data.replace('#define _ARM_MATH_TYPES_H_', patch_data)

with open(cmsis_arm_math_types_h_path, 'w') as fp:
fp.write(data)

0 comments on commit fe2e554

Please sign in to comment.