Skip to content

Commit

Permalink
Qualcomm AI Engine Direct - Move soc infomation from cpp to python (#…
Browse files Browse the repository at this point in the history
…1679)

Summary:
- Using flatbuffer as compile spec to communicate between python and cpp
 - Collect soc information into backends/qualcomm/serialization/qnn_compile_spec_schema.py which is convenient to add more SoC
 - Add flatbuffer into cmake build flow
 - Add tutorial to add new soc supported
 - Set SoCModel instead of arch because arch will be deprecated by QNN. (Generating deprecated warning after QNN 2.14)
 - Add a macro wrapper for log with different log level

Pull Request resolved: #1679

Reviewed By: JacobSzwejbka

Differential Revision: D53191783

Pulled By: cccclai

fbshipit-source-id: 3c2a7a7633480be4541f542ed339cb5e491438df
  • Loading branch information
shewu-quic authored and facebook-github-bot committed Mar 1, 2024
1 parent 06035f3 commit 81b3232
Show file tree
Hide file tree
Showing 55 changed files with 1,011 additions and 1,015 deletions.
52 changes: 45 additions & 7 deletions backends/qualcomm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,43 @@ include_directories(
${EXECUTORCH_SOURCE_DIR}/third-party/flatbuffers/include
)

set(_qnn_schema__srcs
backends/qualcomm/serialization/schema.fbs
)
set(_qnn_schema__include_dir "${CMAKE_BINARY_DIR}/schema/include")
# Paths to headers generated from the .fbs files.
set(_qnn_schema__outputs)
foreach(fbs_file ${_qnn_schema__srcs})
string(REGEX REPLACE "serialization/([^/]+)[.]fbs$" "\\1_generated.h"
generated "${fbs_file}")
list(APPEND _qnn_schema__outputs
"${_qnn_schema__include_dir}/executorch/${generated}")
endforeach()

# Generate the headers from the .fbs files.
add_custom_command(
OUTPUT ${_qnn_schema__outputs}
COMMAND
${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --scoped-enums -o
"${_qnn_schema__include_dir}/executorch/backends/qualcomm"
${_qnn_schema__srcs}
WORKING_DIRECTORY ${EXECUTORCH_SOURCE_DIR}
COMMENT "Generating qnn_schema headers"
VERBATIM)


include_directories(
BEFORE
${_qnn_schema__include_dir}
${EXECUTORCH_SOURCE_DIR}/third-party/flatbuffers/include
)

#
# declare targets
#
add_library(qcir INTERFACE qcir_schema_output)
add_library(qcir_utils STATIC)
add_library(qnn_schema INTERFACE ${_qnn_schema__outputs})
add_library(executorch_backend INTERFACE)
add_library(qnn_executorch_backend SHARED)
add_library(qnn_executorch_header INTERFACE)
Expand All @@ -107,7 +139,6 @@ add_library(qnn_backend STATIC)
add_library(qnn_factory STATIC)
add_library(qnn_header INTERFACE)
add_library(wrappers STATIC)
add_library(utils STATIC)

#
# declare dependency
Expand All @@ -119,6 +150,7 @@ target_link_libraries(qcir_utils
target_link_libraries(wrappers
PRIVATE
qnn_header
qnn_executorch_logging
)
target_link_libraries(qnn_function_interface
INTERFACE
Expand All @@ -142,6 +174,10 @@ target_link_libraries(qnn_sys_implementation
qnn_executorch_logging
${CMAKE_DL_LIBS}
)
target_link_libraries(qnn_executorch_logging
PRIVATE
qnn_schema
)
target_link_libraries(qnn_logger
PRIVATE
qnn_implementation
Expand All @@ -157,7 +193,6 @@ target_link_libraries(qnn_device
qnn_executorch_logging
qnn_implementation
qnn_logger
utils
)
target_link_libraries(qnn_backend_cache
PRIVATE
Expand All @@ -177,12 +212,12 @@ target_link_libraries(qnn_graph
qnn_executorch_logging
qnn_implementation
qnn_context
utils
)
target_link_libraries(qnn_factory
PUBLIC
qnn_header
PRIVATE
qnn_schema
qnn_backend
qnn_device
qnn_context
Expand All @@ -192,18 +227,16 @@ target_link_libraries(qnn_manager
PRIVATE
qnn_factory
wrappers
qnn_schema
)
target_link_libraries(qnn_executorch_backend
PRIVATE
qnn_executorch_header
qnn_schema
qnn_manager
executorch
qcir_utils
)
target_link_libraries(utils
PRIVATE
qnn_executorch_logging
)

#
# add linker option
Expand Down Expand Up @@ -237,11 +270,16 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
${CMAKE_CURRENT_BINARY_DIR}/pybind11)
add_library(PyQnnManagerAdaptor MODULE)
add_library(PyQnnWrapperAdaptor MODULE)
# PyQnnManager containing a pybind type triggers the warning
# because pybind11 code internally forces hidden visibility.
set_target_properties(PyQnnManagerAdaptor
PROPERTIES CXX_VISIBILITY_PRESET hidden)

target_link_libraries(PyQnnManagerAdaptor
PRIVATE
pybind11::module
pybind11::lto
qnn_schema
qnn_manager
qnn_executorch_header
executorch
Expand Down
14 changes: 14 additions & 0 deletions backends/qualcomm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ Please check `generate_qnn_executorch_compiler_spec()` in
- Snapdragon 8 Gen 1
- Snapdragon 8 Gen 1+
- Snapdragon 8 Gen 2
- Snapdragon 8 Gen 3

### How to add more supported Chipset

#### Step 1: Check SoC model of snapdragon device
Get SoC model which would like to be supported from the document of Qualcomm AI Engine Direct SDK.

#### Step 2: Update schema of compiler option and SoC information in serialization
Add SoC model into QcomChipset enum in [schema](./serialization/schema.fbs) and [qnn_compile_spec_schema](./serialization/qnn_compile_spec_schema.py).
Insert new SoC information into _soc_info_table in [qnn_compile_spec_schema](./serialization/qnn_compile_spec_schema.py).

#### Step 3: Recompile the .pte file
Follow [setup](setup.md) to setup environment and build runtime with new schema header.

### Supported Inference Type
- Quantized
Expand All @@ -41,6 +54,7 @@ backends/qualcomm
| ├── aarch64 # Configuration required to run on device. (Device Part).
| └── x86_64 # Configuration required to compile graph on host. (AoT Part).
├── scripts # Misc supporting scripts, not related to core functionality.
├── serialization # Contains files related to serializing QNN compiler options and SoC information
├── tests # Unit tests and model tests go here.
└── utils # Miscellaneous utilities.
Expand Down
1 change: 1 addition & 0 deletions backends/qualcomm/aot/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
target_sources(PyQnnManagerAdaptor
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/PyQnnManagerAdaptor.cpp
${CMAKE_CURRENT_LIST_DIR}/PyQnnManagerAdaptor.h
)

# PyQnnWrapperAdaptor
Expand Down
Loading

0 comments on commit 81b3232

Please sign in to comment.