Skip to content

Commit 0fa67f6

Browse files
haowhsu-quicfacebook-github-bot
authored andcommitted
Qualcomm AI Engine Direct - support online prepare (#1692)
Summary: Summary - online graph building mechanism for incoming backends (GPU/DSP) - introduce flatbuffer to help IR serialization - change compiler spec / test spec accordingly Pull Request resolved: #1692 Reviewed By: kirklandsign Differential Revision: D53947011 Pulled By: cccclai fbshipit-source-id: 523f4245b2cd36b0e7abde94f41cfee26252b15b
1 parent d25a219 commit 0fa67f6

26 files changed

+713
-47
lines changed

backends/qualcomm/CMakeLists.txt

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ if(${ANDROID})
3737
find_library(android_log log)
3838
endif()
3939

40+
if(NOT FLATC_EXECUTABLE)
41+
set(FLATC_EXECUTABLE flatc)
42+
endif()
43+
44+
set(qcir_schema_include_dir ${CMAKE_CURRENT_LIST_DIR}/aot/ir)
45+
set(qcir_schema_output ${qcir_schema_include_dir}/qcir_generated.h)
46+
add_custom_command(
47+
OUTPUT qcir_schema_output
48+
COMMAND
49+
${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --scoped-enums -o
50+
${qcir_schema_include_dir}
51+
${qcir_schema_include_dir}/qcir.fbs
52+
COMMENT "Generating qualcomm ir schema headers"
53+
VERBATIM
54+
)
55+
4056
add_compile_options("-Wall" "-Werror" "-Wno-sign-compare")
4157

4258
# GNU emit wanring for ignored attributes
@@ -57,19 +73,18 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release")
5773
add_compile_definitions("-O3" "-ffunction-sections" "-fdata-sections")
5874
endif()
5975

60-
6176
include_directories(
6277
BEFORE
6378
${_common_include_directories}
64-
)
65-
include_directories(
66-
BEFORE
6779
${QNN_SDK_ROOT}/include/QNN
80+
${EXECUTORCH_SOURCE_DIR}/third-party/flatbuffers/include
6881
)
6982

7083
#
7184
# declare targets
7285
#
86+
add_library(qcir INTERFACE qcir_schema_output)
87+
add_library(qcir_utils STATIC)
7388
add_library(executorch_backend INTERFACE)
7489
add_library(qnn_executorch_backend SHARED)
7590
add_library(qnn_executorch_header INTERFACE)
@@ -93,6 +108,10 @@ add_library(utils STATIC)
93108
#
94109
# declare dependency
95110
#
111+
target_link_libraries(qcir_utils
112+
PRIVATE
113+
qcir
114+
)
96115
target_link_libraries(wrappers
97116
PRIVATE
98117
qnn_header
@@ -139,6 +158,7 @@ target_link_libraries(qnn_device
139158
target_link_libraries(qnn_backend_cache
140159
PRIVATE
141160
qnn_sys_implementation
161+
qcir_utils
142162
)
143163
target_link_libraries(qnn_context
144164
PRIVATE
@@ -174,6 +194,7 @@ target_link_libraries(qnn_executorch_backend
174194
qnn_executorch_header
175195
qnn_manager
176196
executorch
197+
qcir_utils
177198
)
178199
target_link_libraries(utils
179200
PRIVATE
@@ -200,6 +221,10 @@ add_subdirectory(
200221
${QNN_EXECUTORCH_ROOT_DIR}/aot/wrappers
201222
${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/wrappers
202223
)
224+
add_subdirectory(
225+
${QNN_EXECUTORCH_ROOT_DIR}/aot/ir
226+
${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/ir
227+
)
203228
install(TARGETS qnn_executorch_backend DESTINATION lib)
204229

205230
# QNN pybind
@@ -216,6 +241,7 @@ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
216241
qnn_manager
217242
qnn_executorch_header
218243
executorch
244+
qcir_utils
219245
)
220246
target_link_libraries(PyQnnWrapperAdaptor
221247
PRIVATE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) Qualcomm Innovation Center, Inc.
2+
# All rights reserved
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
8+
# QCIR
9+
target_sources(qcir_utils
10+
PRIVATE
11+
${CMAKE_CURRENT_LIST_DIR}/qcir_utils.h
12+
${CMAKE_CURRENT_LIST_DIR}/qcir_utils.cpp
13+
)

backends/qualcomm/aot/ir/qcir.fbs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//
2+
// Copyright (c) Qualcomm Innovation Center, Inc.
3+
// All rights reserved.
4+
//
5+
// This source code is licensed under the BSD-style license found in the
6+
// LICENSE file in the root directory of this source tree.
7+
//
8+
9+
namespace qcir;
10+
11+
enum TensorType : byte {
12+
WRITE = 0,
13+
READ,
14+
READWRITE,
15+
NATIVE,
16+
STATIC,
17+
OPTIONAL,
18+
UNDEFINED,
19+
}
20+
21+
enum DataType : byte {
22+
INT8 = 0,
23+
INT16,
24+
INT32,
25+
INT64,
26+
UINT8,
27+
UINT16,
28+
UINT32,
29+
UINT64,
30+
FLOAT16,
31+
FLOAT32,
32+
FLOAT64,
33+
SFIXED4,
34+
SFIXED8,
35+
SFIXED16,
36+
SFIXED32,
37+
UFIXED4,
38+
UFIXED8,
39+
UFIXED16,
40+
UFIXED32,
41+
BOOL,
42+
STRING,
43+
UNDEFINED,
44+
}
45+
46+
enum QuantizeDef : byte {
47+
IMPL_GENERATED = 0,
48+
DEFINED,
49+
UNDEFINED,
50+
}
51+
52+
enum QuantizeType : byte {
53+
SCALE_OFFSET = 0,
54+
AXIS_SCALE_OFFSET,
55+
// TODO: enable
56+
// QNN_QUANTIZATION_ENCODING_BW_SCALE_OFFSET
57+
// QNN_QUANTIZATION_ENCODING_BW_AXIS_SCALE_OFFSET
58+
UNDEFINED,
59+
}
60+
61+
struct ScaleOffset {
62+
scale: float;
63+
offset: int;
64+
}
65+
66+
table QuantizeParam {
67+
def: QuantizeDef;
68+
type: QuantizeType;
69+
axis: int;
70+
data: [ScaleOffset];
71+
}
72+
73+
table Tensor {
74+
name: string;
75+
shape: [uint];
76+
type: TensorType;
77+
dtype: DataType;
78+
qparam: QuantizeParam;
79+
data: [ubyte];
80+
}
81+
82+
table Operator {
83+
name: string;
84+
package_name: string;
85+
type_name: string;
86+
// keep only tensor indexes
87+
inputs: [int];
88+
outputs: [int];
89+
params: [int];
90+
}
91+
92+
table Graph {
93+
nodes: [Operator];
94+
tensors: [Tensor];
95+
}
96+
97+
root_type Graph;

0 commit comments

Comments
 (0)