diff --git a/.ci/scripts/build-mediatek-sdk.sh b/.ci/scripts/build-mediatek-sdk.sh new file mode 100755 index 00000000000..81e64b241ce --- /dev/null +++ b/.ci/scripts/build-mediatek-sdk.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +set -eux + +build_neuron_backend() { + echo "Start building neuron backend." + export ANDROID_NDK=/opt/ndk + export MEDIATEK_SDK_ROOT=/tmp/neuropilot + export NEURON_BUFFER_ALLOCATOR_LIB=${MEDIATEK_SDK_ROOT}/libneuron_buffer_allocator.so + export EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)" + + + cd ${EXECUTORCH_ROOT} + ./backends/mediatek/scripts/mtk_build.sh +} + +build_neuron_backend diff --git a/.ci/scripts/setup-mediatek-deps.sh b/.ci/scripts/setup-mediatek-deps.sh new file mode 100755 index 00000000000..f93a319e11a --- /dev/null +++ b/.ci/scripts/setup-mediatek-deps.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +set -eux + +MEDIATEK_INSTALLATION_DIR=/tmp/neuropilot +EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)" + +install_neuropilot() { + echo "Start installing neuropilot." + mkdir -p "${MEDIATEK_INSTALLATION_DIR}" + + curl -Lo /tmp/neuropilot-express.tar.gz "https://s3.ap-southeast-1.amazonaws.com/mediatek.neuropilot.com/06302508-4c94-4bf2-9789-b0ee44e83e27.gz" + echo "Finishing downloading neuropilot sdk." + tar zxvf /tmp/neuropilot-express.tar.gz --strip-components=1 --directory "${MEDIATEK_INSTALLATION_DIR}" + echo "Finishing unzip neuropilot sdk." + + # Copy NP header + cp ${MEDIATEK_INSTALLATION_DIR}/api/NeuronAdapter.h ${EXECUTORCH_ROOT}/backends/mediatek/runtime/include/api/ + + # Print the content for manual verification + ls -lah "${MEDIATEK_INSTALLATION_DIR}" +} + +setup_neuropilot() { + pip3 install -r ${EXECUTORCH_ROOT}/backends/mediatek/requirements.txt + pip3 install ${MEDIATEK_INSTALLATION_DIR}/mtk_neuron-8.2.19-py3-none-linux_x86_64.whl + pip3 install ${MEDIATEK_INSTALLATION_DIR}/mtk_converter-8.13.0_public_packages/mtk_converter-8.13.0+public-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl +} + +setup_calibration_data() { + curl -Lo /tmp/imagenette2-160.tgz https://s3.amazonaws.com/fast-ai-imageclas/imagenette2-160.tgz + tar zxvf /tmp/imagenette2-160.tgz --strip-components=1 --directory "${MEDIATEK_INSTALLATION_DIR}" +} + +install_neuropilot +setup_neuropilot +setup_calibration_data diff --git a/.ci/scripts/test_model.sh b/.ci/scripts/test_model.sh index aa74f3a5447..38a354eddf0 100755 --- a/.ci/scripts/test_model.sh +++ b/.ci/scripts/test_model.sh @@ -244,6 +244,24 @@ test_model_with_mps() { EXPORTED_MODEL=$(find "." -type f -name "${MODEL_NAME}*.pte" -print -quit) } +test_model_with_mediatek() { + if [[ "${MODEL_NAME}" == "dl3" ]]; then + EXPORT_SCRIPT=deeplab_v3 + elif [[ "${MODEL_NAME}" == "mv3" ]]; then + EXPORT_SCRIPT=mobilenet_v3 + elif [[ "${MODEL_NAME}" == "mv2" ]]; then + EXPORT_SCRIPT=mobilenet_v2 + elif [[ "${MODEL_NAME}" == "ic4" ]]; then + EXPORT_SCRIPT=inception_v4 + elif [[ "${MODEL_NAME}" == "ic3" ]]; then + EXPORT_SCRIPT=inception_v3 + fi + + PYTHONPATH=examples/mediatek/ "${PYTHON_EXECUTABLE}" -m examples.mediatek.model_export_scripts.${EXPORT_SCRIPT} -d /tmp/neuropilot/train -a ${EXPORT_SCRIPT} + EXPORTED_MODEL=$(find "./${EXPORT_SCRIPT}" -type f -name "*.pte" -print -quit) +} + + if [[ "${BACKEND}" == "portable" ]]; then echo "Testing ${MODEL_NAME} with portable kernels..." test_model @@ -281,6 +299,12 @@ elif [[ "${BACKEND}" == *"xnnpack"* ]]; then if [[ $? -eq 0 ]]; then prepare_artifacts_upload fi +elif [[ "${BACKEND}" == "mediatek" ]]; then + echo "Testing ${MODEL_NAME} with mediatek..." + test_model_with_mediatek + if [[ $? -eq 0 ]]; then + prepare_artifacts_upload + fi else set +e if [[ "${BACKEND}" == *"quantization"* ]]; then diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index 5b45e203f16..df254b7f409 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -705,6 +705,12 @@ jobs: CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]") conda activate "${CONDA_ENV}" + source .ci/scripts/utils.sh + install_executorch "--use-pt-pinned-commit" + + PYTHON_EXECUTABLE=python bash .ci/scripts/setup-mediatek-deps.sh + PYTHON_EXECUTABLE=python bash .ci/scripts/build-mediatek-sdk.sh + PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh "mv3" "buck2" "mediatek" # placeholder for mediatek to add more tests test-openvino-linux: