Skip to content

Commit 9c9e074

Browse files
committed
Qualcomm AI Engine Direct - CDSP Direct Mode
1 parent a5423eb commit 9c9e074

46 files changed

Lines changed: 1236 additions & 150 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backends/qualcomm/CMakeLists.txt

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ add_library(qnn_sys_function_interface INTERFACE)
164164
add_library(qnn_sys_implementation STATIC)
165165
add_library(shared_buffer STATIC)
166166
add_library(wrappers STATIC)
167-
add_library(utils STATIC)
168167

169168
#
170169
# declare dependency
@@ -230,24 +229,40 @@ target_link_libraries(
230229
)
231230

232231
target_link_libraries(
233-
qnn_manager
234-
PRIVATE qnn_factory
235-
qnn_backend_unified_registry
236-
wrappers
237-
qnn_schema
238-
utils
239-
shared_buffer
240-
qnn_dlc_manager
232+
qnn_manager PRIVATE qnn_factory qnn_backend_unified_registry wrappers
233+
qnn_schema shared_buffer qnn_dlc_manager
241234
)
242235
target_link_libraries(
243236
qnn_executorch_backend
244237
PRIVATE qnn_executorch_header qnn_schema qnn_manager executorch_core
245238
extension_tensor qnn_backend_options
246239
)
240+
241+
# Add CTX_BIN_ALIGNMENT here so all backend files has access to this macro.
242+
add_compile_definitions(QNN_CTX_BIN_ALIGNMENT=256)
243+
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES Hexagon)
244+
# Add macro here so we can dlopen the correct .so library.
245+
if(DSP_TYPE STREQUAL "3")
246+
string(TOUPPER ${DSP_VERSION} CAPITAL_DSP_VERSION)
247+
set(HEXAGON_LIB "libQnnHtp${CAPITAL_DSP_VERSION}.so")
248+
add_compile_definitions(HEXAGON_LIB="${HEXAGON_LIB}")
249+
message(STATUS "For hexagon build, using HTP Library: ${HEXAGON_LIB}")
250+
else()
251+
message(FATAL_ERROR "Unknown DSP_TYPE ${DSP_TYPE}")
252+
endif()
253+
254+
target_link_libraries(
255+
qnn_executorch_backend
256+
PRIVATE
257+
${HEXAGON_TOOLS_ROOT}/Tools/target/hexagon/lib/${DSP_VERSION}/G0/pic/libc.so
258+
${HEXAGON_TOOLS_ROOT}/Tools/target/hexagon/lib/${DSP_VERSION}/G0/pic/libc++.so.1
259+
${HEXAGON_TOOLS_ROOT}/Tools/target/hexagon/lib/${DSP_VERSION}/G0/pic/libc++abi.so.1
260+
)
261+
endif()
262+
247263
set_target_properties(
248264
qnn_executorch_backend PROPERTIES LINK_FLAGS "-Wl,-rpath='$ORIGIN'"
249265
)
250-
target_link_libraries(utils PRIVATE qnn_executorch_logging)
251266
target_link_libraries(
252267
shared_buffer PRIVATE qnn_executorch_logging ${CMAKE_DL_LIBS}
253268
)
@@ -278,6 +293,13 @@ install(
278293
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/executorch/backends/qualcomm
279294
)
280295

296+
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES Hexagon)
297+
add_subdirectory(
298+
${QNN_EXECUTORCH_ROOT_DIR}/runtime/backends/direct_mode
299+
${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/direct_mode
300+
)
301+
endif()
302+
281303
# QNN pybind
282304
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
283305
add_subdirectory(

backends/qualcomm/aot/python/PyQnnManagerAdaptor.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ std::shared_ptr<TensorWrapper> CreateTensorWrapper(
147147
copy_data);
148148
}
149149

150+
int GetQNNCtxBinAlignment() {
151+
return QNN_CTX_BIN_ALIGNMENT;
152+
}
153+
150154
std::string GetQnnSdkBuildId(std::string library_path) {
151155
QnnImplementation qnn_loaded_backend = QnnImplementation(library_path);
152156
ET_CHECK_MSG(
@@ -191,6 +195,7 @@ PYBIND11_MODULE(PyQnnManagerAdaptor, m) {
191195
using namespace qnn_delegate;
192196
PYBIND11_NUMPY_DTYPE(PyQnnTensorWrapper::EncodingData, scale, offset);
193197

198+
m.def("GetQNNCtxBinAlignment", &GetQNNCtxBinAlignment);
194199
m.def("GetQnnSdkBuildId", &GetQnnSdkBuildId);
195200
m.def("StripProtocol", &StripProtocol);
196201
py::class_<QnnExecuTorchContextBinary>(m, "QnnExecuTorchContextBinary")

backends/qualcomm/runtime/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ target_sources(
4242
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Logging.cpp
4343
)
4444

45-
# utils
46-
target_sources(
47-
utils
48-
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/Utils.h
49-
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Utils.cpp
50-
)
51-
5245
# shared_buffer
5346
target_sources(
5447
shared_buffer PRIVATE ${CMAKE_CURRENT_LIST_DIR}/SharedBuffer.h

backends/qualcomm/runtime/Logging.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#ifdef __ANDROID__
1212
#include <android/log.h>
1313
#endif
14+
#ifdef __hexagon__
15+
#include "HAP_farf.h"
16+
#endif
1417
namespace executorch {
1518
namespace backends {
1619
namespace qnn {
@@ -58,10 +61,18 @@ void Log(QnnExecuTorchLogLevel log_level, const char* format, ...) {
5861
}
5962
__android_log_vprint(android_severity, "[Qnn ExecuTorch]", format, args);
6063
#endif
64+
65+
#ifndef __hexagon__
6166
fprintf(stderr, "[%s] [Qnn ExecuTorch]: ", serverity_name);
6267
vfprintf(stderr, format, args);
6368
va_end(args);
6469
fputc('\n', stderr);
70+
#else
71+
char buf[QNN_EXECUTORCH_FARF_BUF_SIZE] = {0};
72+
vsnprintf(buf, QNN_EXECUTORCH_FARF_BUF_SIZE, format, args);
73+
va_end(args);
74+
FARF(RUNTIME_HIGH, "[%s] [Qnn ExecuTorch]: %s\n", serverity_name, buf);
75+
#endif
6576
}
6677
} // namespace qnn
6778
} // namespace backends

backends/qualcomm/runtime/Logging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ using namespace qnn_delegate;
1616

1717
void Log(QnnExecuTorchLogLevel log_level, const char* format, ...);
1818

19+
#define QNN_EXECUTORCH_FARF_BUF_SIZE 128
20+
1921
#define QNN_EXECUTORCH_LOG(log_level, format, ...) \
2022
do { \
2123
Log(log_level, format, ##__VA_ARGS__); \

backends/qualcomm/runtime/QnnExecuTorchBackend.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,12 @@ Result<DelegateHandle*> QnnExecuTorchBackend::init(
112112
}
113113
}
114114
add_cached_delegate(signature, qnn_manager);
115+
116+
#ifndef __hexagon__
115117
// This backend does not need its processed data after Init.
116118
processed->Free();
119+
#endif
120+
117121
return qnn_manager;
118122
}
119123

backends/qualcomm/runtime/QnnManager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <executorch/backends/qualcomm/runtime/QnnBackendOptions.h>
1010
#include <executorch/backends/qualcomm/runtime/QnnManager.h>
1111
#include <executorch/backends/qualcomm/runtime/SharedBuffer.h>
12-
#include <executorch/backends/qualcomm/runtime/Utils.h>
1312
#include <executorch/backends/qualcomm/runtime/backends/QnnBackendCommon.h>
1413
#include <executorch/backends/qualcomm/runtime/backends/QnnCustomProtocol.h>
1514
#include <executorch/backends/qualcomm/runtime/backends/QnnImplementation.h>

backends/qualcomm/runtime/Utils.cpp

Lines changed: 0 additions & 36 deletions
This file was deleted.

backends/qualcomm/runtime/Utils.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

backends/qualcomm/runtime/backends/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ set(HOST_ARCHITECTURE_HTP
5151
)
5252
set(HOST_ARCHITECTURE_IR ${CMAKE_CURRENT_LIST_DIR}/ir/${CMAKE_SYSTEM_PROCESSOR})
5353

54+
set(platform target)
55+
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64)
56+
set(platform host)
57+
endif()
58+
59+
set(HOST_ARCHITECTURE_GPU ${CMAKE_CURRENT_LIST_DIR}/gpu/${platform})
60+
set(HOST_ARCHITECTURE_HTP ${CMAKE_CURRENT_LIST_DIR}/htp/${platform})
61+
set(HOST_ARCHITECTURE_IR ${CMAKE_CURRENT_LIST_DIR}/ir/${platform})
62+
5463
# qnn_device
5564
target_sources(
5665
qnn_device

0 commit comments

Comments
 (0)