From 687425d1c17c99acdcee2c0617e84e93fc3e1c13 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Tue, 9 Apr 2024 15:24:10 -0700 Subject: [PATCH 1/2] Fix tutorial for Qualcomm AI Engine Direct Backend We have refactors recently and need to update the tutorial and cmake --- backends/qualcomm/CMakeLists.txt | 2 +- ...d-run-qualcomm-ai-engine-direct-backend.md | 21 ++++++++++++------- examples/qualcomm/CMakeLists.txt | 1 + .../executor_runner/qnn_executor_runner.cpp | 4 +++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/backends/qualcomm/CMakeLists.txt b/backends/qualcomm/CMakeLists.txt index 8883e5ee026..727952b4fe4 100644 --- a/backends/qualcomm/CMakeLists.txt +++ b/backends/qualcomm/CMakeLists.txt @@ -253,7 +253,7 @@ target_link_libraries(qnn_executorch_backend qnn_executorch_header qnn_schema qnn_manager - executorch + executorch_no_prim_ops qcir_utils ) target_link_libraries(utils diff --git a/docs/source/build-run-qualcomm-ai-engine-direct-backend.md b/docs/source/build-run-qualcomm-ai-engine-direct-backend.md index 30904b29ddb..c7ff5061514 100644 --- a/docs/source/build-run-qualcomm-ai-engine-direct-backend.md +++ b/docs/source/build-run-qualcomm-ai-engine-direct-backend.md @@ -115,8 +115,12 @@ Python APIs on x64 are required to compile models to Qualcomm AI Engine Direct b ```bash cd $EXECUTORCH_ROOT -mkdir build_x86_64 -cd build_x86_64 +# Workaround for fbs files in exir/_serialize +cp schema/program.fbs exir/_serialize/program.fbs +cp schema/scalar_type.fbs exir/_serialize/scalar_type.fbs + +mkdir cmake_out +cd cmake_out cmake .. -DEXECUTORCH_BUILD_QNN=ON -DQNN_SDK_ROOT=${QNN_SDK_ROOT} cmake --build . -t "PyQnnManagerAdaptor" "PyQnnWrapperAdaptor" -j8 @@ -134,12 +138,12 @@ Commands to build `qnn_executor_runner` for Android: ```bash cd $EXECUTORCH_ROOT -mkdir build_android -cd build_android +mkdir cmake_android_out +cd cmake_android_out # build executorch & qnn_executorch_backend cmake .. \ - -DBUCK2=buck2 \ -DCMAKE_INSTALL_PREFIX=$PWD \ + -DEXECUTORCH_BUILD_SDK=ON \ -DEXECUTORCH_BUILD_QNN=ON \ -DQNN_SDK_ROOT=$QNN_SDK_ROOT \ -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \ @@ -162,7 +166,7 @@ cmake --build examples/qualcomm -j16 **Note:** If you want to build for release, add `-DCMAKE_BUILD_TYPE=Release` to the `cmake` command options. -You can find `qnn_executor_runner` under `build_android/examples/qualcomm/`. +You can find `qnn_executor_runner` under `cmake_android_out/examples/qualcomm/`. ## Deploying and running on device @@ -174,7 +178,7 @@ We use deeplab-v3-resnet101 as an example in this tutorial. Run below commands t ``` cd $EXECUTORCH_ROOT -python -m examples.qualcomm.scripts.deeplab_v3 -b build_android -m SM8550 --compile_only --download +python -m examples.qualcomm.scripts.deeplab_v3 -b cmake_android_out -m SM8550 --compile_only --download ``` You might see something like below: @@ -219,7 +223,8 @@ So, we can run `qnn_executor_runner` like ```bash adb push ./deeplab_v3/dlv3_qnn.pte ${DEVICE_DIR} -adb push ${EXECUTORCH_ROOT}/build_android/examples/qualcomm/qnn_executor_runner ${DEVICE_DIR} +adb push ${EXECUTORCH_ROOT}/cmake_android_out/examples/qualcomm/qnn_executor_runner ${DEVICE_DIR} +adb push ${EXECUTORCH_ROOT}/cmake_android_out/lib/libqnn_executorch_backend.so ${DEVICE_DIR} adb shell "cd ${DEVICE_DIR} \ && export LD_LIBRARY_PATH=${DEVICE_DIR} \ && export ADSP_LIBRARY_PATH=${DEVICE_DIR} \ diff --git a/examples/qualcomm/CMakeLists.txt b/examples/qualcomm/CMakeLists.txt index cff5db2a63d..46548d1b8be 100644 --- a/examples/qualcomm/CMakeLists.txt +++ b/examples/qualcomm/CMakeLists.txt @@ -35,6 +35,7 @@ endif() # portable_ops_lib, etdump, bundled_program. find_package(executorch CONFIG REQUIRED) target_compile_options(executorch INTERFACE -DET_EVENT_TRACER_ENABLED) +set(gflags_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../third-party/gflags) find_package(gflags REQUIRED) set(_common_compile_options -Wno-deprecated-declarations -fPIC) diff --git a/examples/qualcomm/executor_runner/qnn_executor_runner.cpp b/examples/qualcomm/executor_runner/qnn_executor_runner.cpp index b2691da2ec7..8998ee634e0 100644 --- a/examples/qualcomm/executor_runner/qnn_executor_runner.cpp +++ b/examples/qualcomm/executor_runner/qnn_executor_runner.cpp @@ -202,8 +202,10 @@ int main(int argc, char** argv) { // be used by a single thread at at time, but it can be reused. // torch::executor::ETDumpGen etdump_gen = torch::executor::ETDumpGen(); + // TODO: So far we have issues with etdump_gen during load_method. Enable it + // after the issues are fixed. Result method = - program->load_method(method_name, &memory_manager, &etdump_gen); + program->load_method(method_name, &memory_manager, nullptr); ET_CHECK_MSG( method.ok(), "Loading of method %s failed with status 0x%" PRIx32, From b152bbcf55612e96449f769f3b2cee96852b0370 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Tue, 9 Apr 2024 20:32:36 -0700 Subject: [PATCH 2/2] Make minimal changes --- ...uild-run-qualcomm-ai-engine-direct-backend.md | 16 ++++++++-------- examples/qualcomm/CMakeLists.txt | 1 - 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/source/build-run-qualcomm-ai-engine-direct-backend.md b/docs/source/build-run-qualcomm-ai-engine-direct-backend.md index c7ff5061514..1a94577e90c 100644 --- a/docs/source/build-run-qualcomm-ai-engine-direct-backend.md +++ b/docs/source/build-run-qualcomm-ai-engine-direct-backend.md @@ -119,8 +119,8 @@ cd $EXECUTORCH_ROOT cp schema/program.fbs exir/_serialize/program.fbs cp schema/scalar_type.fbs exir/_serialize/scalar_type.fbs -mkdir cmake_out -cd cmake_out +mkdir build_x86_64 +cd build_x86_64 cmake .. -DEXECUTORCH_BUILD_QNN=ON -DQNN_SDK_ROOT=${QNN_SDK_ROOT} cmake --build . -t "PyQnnManagerAdaptor" "PyQnnWrapperAdaptor" -j8 @@ -138,8 +138,8 @@ Commands to build `qnn_executor_runner` for Android: ```bash cd $EXECUTORCH_ROOT -mkdir cmake_android_out -cd cmake_android_out +mkdir build_android +cd build_android # build executorch & qnn_executorch_backend cmake .. \ -DCMAKE_INSTALL_PREFIX=$PWD \ @@ -166,7 +166,7 @@ cmake --build examples/qualcomm -j16 **Note:** If you want to build for release, add `-DCMAKE_BUILD_TYPE=Release` to the `cmake` command options. -You can find `qnn_executor_runner` under `cmake_android_out/examples/qualcomm/`. +You can find `qnn_executor_runner` under `build_android/examples/qualcomm/`. ## Deploying and running on device @@ -178,7 +178,7 @@ We use deeplab-v3-resnet101 as an example in this tutorial. Run below commands t ``` cd $EXECUTORCH_ROOT -python -m examples.qualcomm.scripts.deeplab_v3 -b cmake_android_out -m SM8550 --compile_only --download +python -m examples.qualcomm.scripts.deeplab_v3 -b build_android -m SM8550 --compile_only --download ``` You might see something like below: @@ -223,8 +223,8 @@ So, we can run `qnn_executor_runner` like ```bash adb push ./deeplab_v3/dlv3_qnn.pte ${DEVICE_DIR} -adb push ${EXECUTORCH_ROOT}/cmake_android_out/examples/qualcomm/qnn_executor_runner ${DEVICE_DIR} -adb push ${EXECUTORCH_ROOT}/cmake_android_out/lib/libqnn_executorch_backend.so ${DEVICE_DIR} +adb push ${EXECUTORCH_ROOT}/build_android/examples/qualcomm/qnn_executor_runner ${DEVICE_DIR} +adb push ${EXECUTORCH_ROOT}/build_android/lib/libqnn_executorch_backend.so ${DEVICE_DIR} adb shell "cd ${DEVICE_DIR} \ && export LD_LIBRARY_PATH=${DEVICE_DIR} \ && export ADSP_LIBRARY_PATH=${DEVICE_DIR} \ diff --git a/examples/qualcomm/CMakeLists.txt b/examples/qualcomm/CMakeLists.txt index 46548d1b8be..cff5db2a63d 100644 --- a/examples/qualcomm/CMakeLists.txt +++ b/examples/qualcomm/CMakeLists.txt @@ -35,7 +35,6 @@ endif() # portable_ops_lib, etdump, bundled_program. find_package(executorch CONFIG REQUIRED) target_compile_options(executorch INTERFACE -DET_EVENT_TRACER_ENABLED) -set(gflags_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../third-party/gflags) find_package(gflags REQUIRED) set(_common_compile_options -Wno-deprecated-declarations -fPIC)