Skip to content

Commit 52fbd57

Browse files
Hsu, Hao-Wei (Ian)GitHub Enterprise
authored andcommitted
[Rearrange source folders] (#94)
- move qnn_executor_runner to examples/backend/qualcomm - move qualcomm/runtime/wrappers to qualcomm/aot/wrappers - move qualcomm/runtime/python to qualcomm/aot/python - change file structure in README accordingly
1 parent 22bd9fe commit 52fbd57

23 files changed

+127
-96
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ endif()
303303
option(EXECUTORCH_BUILD_QNN "Build the backends/qualcomm directory" OFF)
304304
if(EXECUTORCH_BUILD_QNN)
305305
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/qualcomm)
306+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/backend/qualcomm)
306307
endif()
307308

308309
# Add selective build subdirectory

backends/qualcomm/CMakeLists.txt

Lines changed: 46 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ get_filename_component(EXECUTORCH_SOURCE_DIR
1515
"${CMAKE_CURRENT_LIST_DIR}/../.."
1616
ABSOLUTE)
1717
get_filename_component(QNN_EXECUTORCH_ROOT_DIR
18-
${CMAKE_CURRENT_LIST_DIR}/runtime
18+
${CMAKE_CURRENT_LIST_DIR}
1919
ABSOLUTE)
2020
# Let files say "include <executorch/path/to/header.h>".
2121
get_filename_component(_common_include_directories
@@ -25,13 +25,16 @@ get_filename_component(_common_include_directories
2525
if(NOT DEFINED QNN_SDK_ROOT)
2626
message(FATAL_ERROR
2727
"Please define QNN_SDK_ROOT, e.g. cmake <..> -DQNN_SDK_ROOT=<...>")
28+
elseif(CMAKE_TOOLCHAIN_FILE MATCHES ".*ios\.toolchain\.cmake$")
29+
message(FATAL_ERROR
30+
"ios is not supported by Qualcomm AI Engine Direct")
2831
endif()
2932

3033
message(STATUS "Using qnn sdk root ${QNN_SDK_ROOT}")
3134
message(STATUS "Using EXECUTORCH_SOURCE_DIR ${EXECUTORCH_SOURCE_DIR}")
3235

3336
if(${ANDROID})
34-
find_library(android_log log)
37+
find_library(android_log log)
3538
endif()
3639

3740
add_compile_options("-Wall" "-Werror" "-Wno-sign-compare")
@@ -56,12 +59,12 @@ endif()
5659

5760

5861
include_directories(
59-
BEFORE
60-
${_common_include_directories}
62+
BEFORE
63+
${_common_include_directories}
6164
)
6265
include_directories(
63-
BEFORE
64-
${QNN_SDK_ROOT}/include/QNN
66+
BEFORE
67+
${QNN_SDK_ROOT}/include/QNN
6568
)
6669

6770
#
@@ -179,77 +182,52 @@ target_link_options_shared_lib(qnn_executorch_backend)
179182
# add sources
180183
#
181184
add_subdirectory(
182-
${QNN_EXECUTORCH_ROOT_DIR}
185+
${QNN_EXECUTORCH_ROOT_DIR}/runtime
183186
${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch
184187
)
185188
add_subdirectory(
186-
${QNN_EXECUTORCH_ROOT_DIR}/backends
189+
${QNN_EXECUTORCH_ROOT_DIR}/runtime/backends
187190
${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/backends
188191
)
189192
add_subdirectory(
190-
${QNN_EXECUTORCH_ROOT_DIR}/wrappers
193+
${QNN_EXECUTORCH_ROOT_DIR}/aot/wrappers
191194
${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/wrappers
192195
)
193196

194197
# QNN pybind
195198
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
196-
add_subdirectory(${EXECUTORCH_SOURCE_DIR}/third-party/pybind11
197-
${CMAKE_CURRENT_BINARY_DIR}/pybind11)
198-
add_library(PyQnnManagerAdaptor MODULE)
199-
add_library(PyQnnWrapperAdaptor MODULE)
200-
201-
target_link_libraries(PyQnnManagerAdaptor
202-
PRIVATE
203-
pybind11::module
204-
pybind11::lto
205-
qnn_manager
206-
qnn_executorch_header
207-
executorch
208-
)
209-
target_link_libraries(PyQnnWrapperAdaptor
210-
PRIVATE
211-
pybind11::module
212-
pybind11::lto
213-
wrappers
214-
qnn_logging
215-
qnn_executorch_header
216-
)
217-
218-
pybind11_extension(PyQnnManagerAdaptor)
219-
pybind11_extension(PyQnnWrapperAdaptor)
220-
if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo)
221-
# Strip unnecessary sections of the binary
222-
pybind11_strip(PyQnnManagerAdaptor)
223-
pybind11_strip(PyQnnWrapperAdaptor)
224-
endif()
225-
226-
add_subdirectory(
227-
${QNN_EXECUTORCH_ROOT_DIR}/python
228-
${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/python
229-
)
230-
endif()
231-
232-
# ios can only build library but not binary
233-
# though Qualcomm doesn't support ios :)
234-
if(NOT CMAKE_TOOLCHAIN_FILE MATCHES ".*ios\.toolchain\.cmake$")
235-
#
236-
# qnn_executor_runner: Like executor_runner but with QNN, the binary will
237-
# be at ${CMAKE_BINARY_DIR}/backends/qualcomm
238-
#
239-
set(_qnn_executor_runner__srcs ${_executor_runner__srcs})
240-
list(TRANSFORM _qnn_executor_runner__srcs PREPEND "${EXECUTORCH_SOURCE_DIR}/")
241-
list(FILTER _qnn_executor_runner__srcs EXCLUDE REGEX ".*executor_runner.cpp$")
242-
list(
243-
PREPEND
244-
_qnn_executor_runner__srcs
245-
${CMAKE_CURRENT_LIST_DIR}/executor_runner/qnn_executor_runner.cpp
246-
)
247-
add_executable(qnn_executor_runner ${_qnn_executor_runner__srcs})
248-
target_link_libraries(qnn_executor_runner
249-
${_executor_runner_libs}
250-
qnn_executorch_backend
251-
gflags
252-
)
253-
target_compile_options(qnn_executor_runner PUBLIC ${_common_compile_options})
199+
add_subdirectory(${EXECUTORCH_SOURCE_DIR}/third-party/pybind11
200+
${CMAKE_CURRENT_BINARY_DIR}/pybind11)
201+
add_library(PyQnnManagerAdaptor MODULE)
202+
add_library(PyQnnWrapperAdaptor MODULE)
203+
204+
target_link_libraries(PyQnnManagerAdaptor
205+
PRIVATE
206+
pybind11::module
207+
pybind11::lto
208+
qnn_manager
209+
qnn_executorch_header
210+
executorch
211+
)
212+
target_link_libraries(PyQnnWrapperAdaptor
213+
PRIVATE
214+
pybind11::module
215+
pybind11::lto
216+
wrappers
217+
qnn_logging
218+
qnn_executorch_header
219+
)
220+
221+
pybind11_extension(PyQnnManagerAdaptor)
222+
pybind11_extension(PyQnnWrapperAdaptor)
223+
if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo)
224+
# Strip unnecessary sections of the binary
225+
pybind11_strip(PyQnnManagerAdaptor)
226+
pybind11_strip(PyQnnWrapperAdaptor)
227+
endif()
228+
229+
add_subdirectory(
230+
${QNN_EXECUTORCH_ROOT_DIR}/aot/python
231+
${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/python
232+
)
254233
endif()
255-

backends/qualcomm/README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,47 @@ This backend is implemented on the top of
88
[Qualcomm AI Engine Direct SDK](https://developer.qualcomm.com/software/qualcomm-ai-engine-direct-sdk).
99
Please follow [setup](setup.md) to setup environment, build, and run executorch models by this backend.
1010

11-
# Delegate options
11+
## Delegate Options
1212

1313
Please check `generate_qnn_executorch_compiler_spec()` in
1414
[utils.py](./utils/utils.py) for supported SoC and inference type.
1515

16-
### supported chipset
16+
### Supported Chipset
1717
- Snapdragon 8 Gen 1
1818
- Snapdragon 8 Gen 1+
1919
- Snapdragon 8 Gen 2
2020

21-
### supported inference type
21+
### Supported Inference Type
2222
- Quantized
2323
- FP16
2424

25-
# Directory Structure
25+
## Directory Structure
2626

2727
```
2828
backends/qualcomm
29+
├── aot # Codes for generating QNN context binary (AoT Part).
30+
| ├── wrappers # Wrapper of QNN data structures for ease of use.
31+
| └── python # Python interface for using QNN libraries.
2932
├── builders # Codes for lowering each operators (AoT Part).
30-
├── examples # Examples to run QNN backends.
3133
├── partition # QNN Partitioner (AoT Part).
3234
├── passes # Various passes helping lower models to QNN backend (AoT Part).
3335
├── python # Places to put pybind artifacts for accessing QNN APIs, structures, etc (AoT Part).
3436
├── runtime # Here is QNN runtime responsbile for compiling a model on x64.
35-
| # Meanwhile, this is also the runtime responsbile for executing compiled
36-
| # models on a device (Device Part).
37+
| | # Meanwhile, this is also the runtime responsbile for executing compiled
38+
| | # models on a device.
39+
| └── backends # Backends supported by QNN.
40+
| └── htpbackend
41+
| ├── aarch64 # Configuration required to run on device. (Device Part).
42+
| └── x86_64 # Configuration required to compile graph on host. (AoT Part).
3743
├── scripts # Misc supporting scripts, not related to core functionality.
3844
├── tests # Unit tests and model tests go here.
3945
└── utils # Miscellaneous utilities.
46+
47+
examples/backend
48+
└── qualcomm # Examples to run QNN backends.
4049
```
4150

42-
# Examples
51+
## Examples
4352

4453
Please see this [README.md](../../examples/backend/qualcomm/README.md).
4554

backends/qualcomm/runtime/python/PyQnnWrapperAdaptor.cpp renamed to backends/qualcomm/aot/python/PyQnnWrapperAdaptor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree.
77
*/
8+
#include <executorch/backends/qualcomm/aot/python/PyQnnWrapperAdaptor.h>
89
#include <executorch/backends/qualcomm/runtime/Logging.h>
910
#include <executorch/backends/qualcomm/runtime/QnnExecuTorch.h>
10-
#include <executorch/backends/qualcomm/runtime/python/PyQnnWrapperAdaptor.h>
1111
#include <pybind11/numpy.h>
1212
#include <pybind11/pybind11.h>
1313
#include <pybind11/stl.h>

backends/qualcomm/runtime/python/PyQnnWrapperAdaptor.h renamed to backends/qualcomm/aot/python/PyQnnWrapperAdaptor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*/
88
#pragma once
99

10+
#include <executorch/backends/qualcomm/aot/wrappers/OpWrapper.h>
11+
#include <executorch/backends/qualcomm/aot/wrappers/TensorWrapper.h>
1012
#include <executorch/backends/qualcomm/runtime/Logging.h>
11-
#include <executorch/backends/qualcomm/runtime/wrappers/OpWrapper.h>
12-
#include <executorch/backends/qualcomm/runtime/wrappers/TensorWrapper.h>
1313
#include <pybind11/numpy.h>
1414
#include <pybind11/pybind11.h>
1515
#include <pybind11/stl.h>

backends/qualcomm/runtime/wrappers/OpWrapper.cpp renamed to backends/qualcomm/aot/wrappers/OpWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree.
77
*/
8-
#include <executorch/backends/qualcomm/runtime/wrappers/OpWrapper.h>
8+
#include <executorch/backends/qualcomm/aot/wrappers/OpWrapper.h>
99
namespace torch {
1010
namespace executor {
1111
namespace qnn {

backends/qualcomm/runtime/wrappers/OpWrapper.h renamed to backends/qualcomm/aot/wrappers/OpWrapper.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*/
88
#pragma once
99

10-
#include <executorch/backends/qualcomm/runtime/wrappers/ParamWrapper.h>
11-
#include <executorch/backends/qualcomm/runtime/wrappers/QuantizeParamsWrapper.h>
12-
#include <executorch/backends/qualcomm/runtime/wrappers/ScalarParamWrapper.h>
13-
#include <executorch/backends/qualcomm/runtime/wrappers/TensorParamWrapper.h>
14-
#include <executorch/backends/qualcomm/runtime/wrappers/TensorWrapper.h>
10+
#include <executorch/backends/qualcomm/aot/wrappers/ParamWrapper.h>
11+
#include <executorch/backends/qualcomm/aot/wrappers/QuantizeParamsWrapper.h>
12+
#include <executorch/backends/qualcomm/aot/wrappers/ScalarParamWrapper.h>
13+
#include <executorch/backends/qualcomm/aot/wrappers/TensorParamWrapper.h>
14+
#include <executorch/backends/qualcomm/aot/wrappers/TensorWrapper.h>
1515

1616
#include <cstdint>
1717
#include <memory>

backends/qualcomm/runtime/wrappers/QuantizeParamsWrapper.cpp renamed to backends/qualcomm/aot/wrappers/QuantizeParamsWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree.
77
*/
8+
#include <executorch/backends/qualcomm/aot/wrappers/QuantizeParamsWrapper.h>
89
#include <executorch/backends/qualcomm/runtime/Logging.h>
9-
#include <executorch/backends/qualcomm/runtime/wrappers/QuantizeParamsWrapper.h>
1010
namespace torch {
1111
namespace executor {
1212
namespace qnn {

backends/qualcomm/runtime/wrappers/ScalarParamWrapper.h renamed to backends/qualcomm/aot/wrappers/ScalarParamWrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
#pragma once
99

10-
#include <executorch/backends/qualcomm/runtime/wrappers/ParamWrapper.h>
10+
#include <executorch/backends/qualcomm/aot/wrappers/ParamWrapper.h>
1111
#include <executorch/runtime/core/error.h>
1212
namespace torch {
1313
namespace executor {

backends/qualcomm/runtime/wrappers/TensorParamWrapper.h renamed to backends/qualcomm/aot/wrappers/TensorParamWrapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
#pragma once
99

10-
#include <executorch/backends/qualcomm/runtime/wrappers/ParamWrapper.h>
11-
#include <executorch/backends/qualcomm/runtime/wrappers/TensorWrapper.h>
10+
#include <executorch/backends/qualcomm/aot/wrappers/ParamWrapper.h>
11+
#include <executorch/backends/qualcomm/aot/wrappers/TensorWrapper.h>
1212
#include <executorch/runtime/core/error.h>
1313

1414
#include <memory>

backends/qualcomm/runtime/wrappers/TensorWrapper.cpp renamed to backends/qualcomm/aot/wrappers/TensorWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
#include <executorch/backends/qualcomm/runtime/wrappers/TensorWrapper.h>
9+
#include <executorch/backends/qualcomm/aot/wrappers/TensorWrapper.h>
1010

1111
#include <atomic>
1212
#include <cstring>

backends/qualcomm/runtime/wrappers/TensorWrapper.h renamed to backends/qualcomm/aot/wrappers/TensorWrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*/
88
#pragma once
99

10+
#include <executorch/backends/qualcomm/aot/wrappers/QuantizeParamsWrapper.h>
1011
#include <executorch/backends/qualcomm/runtime/Logging.h>
11-
#include <executorch/backends/qualcomm/runtime/wrappers/QuantizeParamsWrapper.h>
1212
#include <executorch/runtime/core/error.h>
1313

1414
#include <memory>

backends/qualcomm/runtime/QnnExecuTorchBackend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* LICENSE file in the root directory of this source tree.
88
*/
99

10+
#include <executorch/backends/qualcomm/aot/wrappers/TensorWrapper.h>
1011
#include <executorch/backends/qualcomm/runtime/QnnExecuTorchBackend.h>
1112
#include <executorch/backends/qualcomm/runtime/QnnManager.h>
12-
#include <executorch/backends/qualcomm/runtime/wrappers/TensorWrapper.h>
1313

1414
#include <array>
1515
#include <string>

backends/qualcomm/runtime/QnnManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*/
88
#pragma once
99

10+
#include <executorch/backends/qualcomm/aot/wrappers/OpWrapper.h>
11+
#include <executorch/backends/qualcomm/aot/wrappers/TensorWrapper.h>
1012
#include <executorch/backends/qualcomm/runtime/Logging.h>
1113
#include <executorch/backends/qualcomm/runtime/QnnExecuTorch.h>
1214
#include <executorch/backends/qualcomm/runtime/backends/QnnBackendFactory.h>
13-
#include <executorch/backends/qualcomm/runtime/wrappers/OpWrapper.h>
14-
#include <executorch/backends/qualcomm/runtime/wrappers/TensorWrapper.h>
1515
#include <executorch/runtime/core/error.h>
1616

1717
#include <memory>

backends/qualcomm/runtime/backends/QnnGraphCommon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
*/
88
#pragma once
99

10+
#include <executorch/backends/qualcomm/aot/wrappers/TensorWrapper.h>
1011
#include <executorch/backends/qualcomm/runtime/Logging.h>
1112
#include <executorch/backends/qualcomm/runtime/backends/QnnContextCommon.h>
1213
#include <executorch/backends/qualcomm/runtime/backends/QnnImplementation.h>
13-
#include <executorch/backends/qualcomm/runtime/wrappers/TensorWrapper.h>
1414

1515
#include <vector>
1616

0 commit comments

Comments
 (0)