Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Open the app screen (red frame button in the image below), and if the string is displayed like "body", it is successful.

...

Compile a Python module (Numba)

...

This article describes the steps to build Numba, which is used to speed up Python.

Download source code

Several modules are required to run Numba. Please download each source code from the URL below. Also, please select a version of each module that is compatible with Python 3.7.9.

Numba 0.56.4:
https://github.com/numba/numba/archive/refs/tags/0.56.4.zip

Numpy 1.19.4:
https://github.com/numpy/numpy/archive/v1.19.4.tar.gz

LLVM 11.1.0:
https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-11.1.0.tar.gz

llvmlite 0.39.1:
https://github.com/numba/llvmlite/archive/refs/tags/v0.39.1.tar.gz

importlib_metadata 6.7.0:
https://github.com/python/importlib_metadata/archive/refs/tags/v6.7.0.zip

typing_extensions 4.7.1:
https://github.com/python/typing_extensions/archive/refs/tags/4.7.1.zip

zipp 3.15.0:
https://github.com/jaraco/zipp/archive/refs/tags/v3.15.0.zip

Place the downloaded file in the following directory. ${SDK_DIR}/external/build/sample/docker/docker_volume

Update the compilation instructions file

The compilation procedure is described in the file below.
${SDK_DIR}/external/build/sample/docker/docker_volume/module_compile.sh

Please copy the content below.

Code Block
#!/bin/sh -x

#----------
HOME_PATH=/home/docker
LIB_INSTALL_DIR=${HOME_PATH}/install_path
SITE_PACKAGES=${LIB_INSTALL_DIR}/lib/python3.7/site-packages

NUMPY_ARCHIVES=numpy-1.19.4.tar.gz
NUMPY_DIR=numpy-1.19.4

LLVM_ARCHIVES=llvmorg-11.1.0.tar.gz
LLVM_DIR=llvm-project-llvmorg-11.1.0
LLVM_INSTALL_DIR=${LIB_INSTALL_DIR}/llvm
LLVM_PATCH_SRC=${LLVMLITE_DIR}/conda-recipes
LLVM_PATCH_DST=${LLVM_DIR}/llvm

LLVMLITE_ARCHIVES=llvmlite-0.39.1.tar.gz
LLVMLITE_DIR=llvmlite-0.39.1

NUMBA_ARCHIVES=numba-0.56.4.zip
NUMBA_DIR=numba-0.56.4

#----------

# NumPy
cd ${HOME_PATH}
mkdir -p ${SITE_PACKAGES}
tar xf ${NUMPY_ARCHIVES}
cd ${NUMPY_DIR}
python setup.py build
PYTHONPATH=$PYTHONPATH:${SITE_PACKAGES}
export PYTHONPATH
python setup.py install --prefix=${LIB_INSTALL_DIR}


# LLVM / llvmlite
cd ${HOME_PATH}
tar xf ${LLVM_ARCHIVES}
tar xf ${LLVMLITE_ARCHIVES}

cd ${LLVM_PATCH_DST}
for patchFile in $(find ../../${LLVM_PATCH_SRC} -name "*.patch" -type f); do
	patch --dry-run -f -p1 -i ${patchFile}
	if [ $? -eq 0 ]; then
		patch -p1 -i ${patchFile}
	fi
done

LLVM_BUILD_SH="../../${LLVMLITE_DIR}/conda-recipes/llvmdev/build.sh"
mkdir -p ${LLVM_INSTALL_DIR}
export PREFIX=${LLVM_INSTALL_DIR} CPU_COUNT=2
sed -i -e "s/\(^LLVM_TARGETS_TO_BUILD=\).*/\1\$\{LLVM_TARGETS_TO_BUILD:-\"AArch64\"\}/" ${LLVM_BUILD_SH}
sed -i -e "/LLVM_ENABLE_ASSERTIONS/d" ${LLVM_BUILD_SH}
sed -i -e "/LLVM_EXPERIMENTAL_TARGETS_TO_BUILD/d" ${LLVM_BUILD_SH}
chmod +x ${LLVM_BUILD_SH}
${LLVM_BUILD_SH}
cd ../../

cd ${LLVMLITE_DIR}
export LLVM_CONFIG=${LLVM_INSTALL_DIR}/bin/llvm-config
python setup.py build
python setup.py install --prefix=${LIB_INSTALL_DIR}
cd ../


# numba
unzip ${NUMBA_ARCHIVES}
cd ${NUMBA_DIR}
export NUMBA_DISABLE_TBB=1
python setup.py build
python setup.py install --prefix=${LIB_INSTALL_DIR}
cd ../


# replace some libraries compatible with python3.7
cd ${HOME_PATH}
unzip importlib_metadata-6.7.0.zip
mv importlib_metadata-6.7.0/importlib_metadata ${SITE_PACKAGES}
unzip typing_extensions-4.7.1.zip
mv typing_extensions-4.7.1/src/typing_extensions.py ${SITE_PACKAGES}
unzip zipp-3.15.0.zip
mv zipp-3.15.0/zipp ${SITE_PACKAGES}


# cleanup
cd ${SITE_PACKAGES}
rm -f easy-install.pth setuptools.pth site.py
find . -maxdepth 2 -name numpy -type d -exec mv {} . \;
find . -maxdepth 2 -name numba -type d -exec mv {} . \;
rm -rf *.egg*
find . -name *pycache* -type d -print | xargs rm -rf
find . -name tests -type d -print | xargs rm -rf
find . -name *.so | xargs aarch64-linux-gnu-strip --strip-debug
cd ${HOME_PATH}

compile

Compile each module using Docker.
Run Docker in the directory below.
${SDK_DIR}/external/build/sample/docker

Code Block
$ docker run --rm -it --name aarch64-ubuntu -v `pwd`/docker_volume:/home/docker compile/ubuntu-rel:0.1

Compiled modules are placed in the following directories.
${SDK_DIR}/external/build/sample/docker/docker_volume/install_path/lib/python3.7/site-packages

Info

LLVM will take some time to compile, so please wait for a while.
The total file size of the compiled module is approximately 60MByte.

Place in AdamApp

Place the created module so that it can be used by AdamApp.
The tutorial uses the following as an example.
${SDK_DIR}/src/adamapp-py/yuv_yolov5_app

Place the module

Copy the compiled module to the AdamApp source directory, keeping the directory structure as is.

$ cp -R ${SDK_DIR}/external/build/sample/docker/docker_volume/install_path/lib/python3.7/site-packages ${SDK_DIR}/src/adamapp-py/yuv_yolov5_app/python/

update pymain.py

Change the source code to be compatible with numba. Replace the attached file "pymain.py" with the file below.
\src\adamapp-py\yuv_yolov5_app\python\pymain.py

View file
namepymain_numba.zip

Build the sample app

Build the sample app "yuv_yolov5_app" and install it on the camera. Please perform the build method according to each SDK version. When you open the app screen, if there is a frame around the object (such as a person) on the screen, it is a success.

Please also refer to the operation explanation of the sample application.

If it fails, a message will be displayed on the application screen indicating that the application has failed to start. From now on, please use the message content and debugging tools to solve the problem and create an application.

...