Skip to content

Commit 02ba19b

Browse files
author
zhouwg
committed
ggml-qnn: Windows port --- step3
1 parent 2b86342 commit 02ba19b

File tree

8 files changed

+302
-222
lines changed

8 files changed

+302
-222
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ include(CheckIncludeFileCXX)
66
set(CMAKE_WARN_UNUSED_CLI YES)
77

88
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
9+
set(CMAKE_VERBOSE_MAKEFILE on)
910

1011
if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
1112
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)

examples/export-lora/export-lora.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ struct lora_merge_ctx {
148148

149149
ctx_out = gguf_init_empty();
150150
struct ggml_init_params params = {
151-
/*.mem_size =*/ gguf_get_n_tensors(base_model.ctx_gguf)*ggml_tensor_overhead(),
151+
/*.mem_size =*/ static_cast<size_t>(gguf_get_n_tensors(base_model.ctx_gguf)*ggml_tensor_overhead()),
152152
/*.mem_buffer =*/ NULL,
153153
/*.no_alloc =*/ true,
154154
};

ggml/src/ggml-qnn/CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
message(STATUS "Using QNN backend")
2+
3+
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
4+
find_library(LOG_LIB log)
5+
set(QNN_LINK_LIBRARIES ${LOG_LIB})
6+
set(QNN_DEFAULT_LIB_SEARCH_PATH "/data/local/tmp/" CACHE STRING "customized library search path for QNN backend")
7+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
8+
set(QNN_DEFAULT_LIB_SEARCH_PATH "C:\\" CACHE STRING "customized library search path for QNN backend")
9+
else()
10+
message(FATAL_ERROR "QNN now only available on Android and Windows(Windows on ARM)")
11+
endif()
12+
13+
if(NOT DEFINED GGML_QNN_SDK_PATH)
14+
# try read from environment variable
15+
if(DEFINED ENV{QNN_SDK_PATH})
16+
set(GGML_QNN_SDK_PATH $ENV{QNN_SDK_PATH})
17+
else()
18+
message(FATAL_ERROR "GGML_QNN_SDK_PATH not defined")
19+
endif()
20+
endif()
21+
22+
message("QNN_SDK_PATH: ${GGML_QNN_SDK_PATH}")
23+
24+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
25+
26+
file(GLOB QNN_SOURCES "${CMAKE_CURRENT_LIST_DIR}/*.cpp")
27+
ggml_add_backend_library(ggml-qnn
28+
${QNN_SOURCES}
29+
)
30+
31+
target_include_directories(ggml-qnn PRIVATE ${GGML_QNN_SDK_PATH}/include/QNN ${CMAKE_CURRENT_LIST_DIR})
32+
target_link_libraries(ggml-qnn PRIVATE ${QNN_LINK_LIBRARIES})
33+
34+
string(REGEX REPLACE "/$" "" GGML_QNN_DEFAULT_LIB_SEARCH_PATH "${QNN_DEFAULT_LIB_SEARCH_PATH}")
35+
target_compile_definitions(ggml-qnn PRIVATE GGML_QNN_DEFAULT_LIB_SEARCH_PATH="${QNN_DEFAULT_LIB_SEARCH_PATH}/")

ggml/src/ggml-qnn/ggml-qnn-impl.h

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ class qnn_perf {
255255
#else
256256
class qnn_perf {
257257
public:
258-
qnn_perf(const std::string & perf_name) {}
258+
qnn_perf(const std::string & perf_name) {
259+
GGML_UNUSED(perf_name);
260+
}
259261
qnn_perf() = delete;
260262
qnn_perf(const qnn_perf & ) = delete;
261263
qnn_perf & operator= (const qnn_perf & ) = delete;
@@ -287,86 +289,86 @@ class qnn_interface {
287289
qnn_interface() = default;
288290

289291
// QnnBackend
290-
DEFINE_SHIM_FUNCTION_INTERFACE(backend_create, backendCreate);
292+
DEFINE_SHIM_FUNCTION_INTERFACE(backend_create, backendCreate)
291293

292-
DEFINE_SHIM_FUNCTION_INTERFACE(backend_free, backendFree);
294+
DEFINE_SHIM_FUNCTION_INTERFACE(backend_free, backendFree)
293295

294-
DEFINE_SHIM_FUNCTION_INTERFACE(backend_register_op_package, backendRegisterOpPackage);
296+
DEFINE_SHIM_FUNCTION_INTERFACE(backend_register_op_package, backendRegisterOpPackage)
295297

296-
DEFINE_SHIM_FUNCTION_INTERFACE(backend_validate_op_config, backendValidateOpConfig);
298+
DEFINE_SHIM_FUNCTION_INTERFACE(backend_validate_op_config, backendValidateOpConfig)
297299

298-
DEFINE_SHIM_FUNCTION_INTERFACE(backend_get_api_version, backendGetApiVersion);
300+
DEFINE_SHIM_FUNCTION_INTERFACE(backend_get_api_version, backendGetApiVersion)
299301

300302
// QnnDevice
301-
DEFINE_SHIM_FUNCTION_INTERFACE(device_create, deviceCreate);
303+
DEFINE_SHIM_FUNCTION_INTERFACE(device_create, deviceCreate)
302304

303-
DEFINE_SHIM_FUNCTION_INTERFACE(device_free, deviceFree);
305+
DEFINE_SHIM_FUNCTION_INTERFACE(device_free, deviceFree)
304306

305-
DEFINE_SHIM_FUNCTION_INTERFACE(device_get_infrastructure, deviceGetInfrastructure);
307+
DEFINE_SHIM_FUNCTION_INTERFACE(device_get_infrastructure, deviceGetInfrastructure)
306308

307-
DEFINE_SHIM_FUNCTION_INTERFACE(device_get_platform_info, deviceGetPlatformInfo);
309+
DEFINE_SHIM_FUNCTION_INTERFACE(device_get_platform_info, deviceGetPlatformInfo)
308310

309-
DEFINE_SHIM_FUNCTION_INTERFACE(device_get_info, deviceGetInfo);
311+
DEFINE_SHIM_FUNCTION_INTERFACE(device_get_info, deviceGetInfo)
310312

311313
// QnnContext
312-
DEFINE_SHIM_FUNCTION_INTERFACE(context_create, contextCreate);
314+
DEFINE_SHIM_FUNCTION_INTERFACE(context_create, contextCreate)
313315

314-
DEFINE_SHIM_FUNCTION_INTERFACE(context_get_binary_size, contextGetBinarySize);
316+
DEFINE_SHIM_FUNCTION_INTERFACE(context_get_binary_size, contextGetBinarySize)
315317

316-
DEFINE_SHIM_FUNCTION_INTERFACE(context_get_binary, contextGetBinary);
318+
DEFINE_SHIM_FUNCTION_INTERFACE(context_get_binary, contextGetBinary)
317319

318-
DEFINE_SHIM_FUNCTION_INTERFACE(context_create_from_binary, contextCreateFromBinary);
320+
DEFINE_SHIM_FUNCTION_INTERFACE(context_create_from_binary, contextCreateFromBinary)
319321

320-
DEFINE_SHIM_FUNCTION_INTERFACE(context_free, contextFree);
322+
DEFINE_SHIM_FUNCTION_INTERFACE(context_free, contextFree)
321323

322324
// QnnGraph
323-
DEFINE_SHIM_FUNCTION_INTERFACE(graph_create, graphCreate);
325+
DEFINE_SHIM_FUNCTION_INTERFACE(graph_create, graphCreate)
324326

325-
DEFINE_SHIM_FUNCTION_INTERFACE(graph_add_node, graphAddNode);
327+
DEFINE_SHIM_FUNCTION_INTERFACE(graph_add_node, graphAddNode)
326328

327-
DEFINE_SHIM_FUNCTION_INTERFACE(graph_finalize, graphFinalize);
329+
DEFINE_SHIM_FUNCTION_INTERFACE(graph_finalize, graphFinalize)
328330

329-
DEFINE_SHIM_FUNCTION_INTERFACE(graph_execute, graphExecute);
331+
DEFINE_SHIM_FUNCTION_INTERFACE(graph_execute, graphExecute)
330332

331-
DEFINE_SHIM_FUNCTION_INTERFACE(graph_retrieve, graphRetrieve);
333+
DEFINE_SHIM_FUNCTION_INTERFACE(graph_retrieve, graphRetrieve)
332334

333335
// QnnLog
334-
DEFINE_SHIM_FUNCTION_INTERFACE(log_create, logCreate);
336+
DEFINE_SHIM_FUNCTION_INTERFACE(log_create, logCreate)
335337

336-
DEFINE_SHIM_FUNCTION_INTERFACE(log_free, logFree);
338+
DEFINE_SHIM_FUNCTION_INTERFACE(log_free, logFree)
337339

338-
DEFINE_SHIM_FUNCTION_INTERFACE(log_set_log_level, logSetLogLevel);
340+
DEFINE_SHIM_FUNCTION_INTERFACE(log_set_log_level, logSetLogLevel)
339341

340342
// QnnProfile
341-
DEFINE_SHIM_FUNCTION_INTERFACE(profile_create, profileCreate);
343+
DEFINE_SHIM_FUNCTION_INTERFACE(profile_create, profileCreate)
342344

343-
DEFINE_SHIM_FUNCTION_INTERFACE(profile_get_events, profileGetEvents);
345+
DEFINE_SHIM_FUNCTION_INTERFACE(profile_get_events, profileGetEvents)
344346

345-
DEFINE_SHIM_FUNCTION_INTERFACE(profile_get_sub_events, profileGetSubEvents);
347+
DEFINE_SHIM_FUNCTION_INTERFACE(profile_get_sub_events, profileGetSubEvents)
346348

347-
DEFINE_SHIM_FUNCTION_INTERFACE(profile_get_event_data, profileGetEventData);
349+
DEFINE_SHIM_FUNCTION_INTERFACE(profile_get_event_data, profileGetEventData)
348350

349-
DEFINE_SHIM_FUNCTION_INTERFACE(profile_free, profileFree);
351+
DEFINE_SHIM_FUNCTION_INTERFACE(profile_free, profileFree)
350352

351353
// QnnMem
352-
DEFINE_SHIM_FUNCTION_INTERFACE(mem_register, memRegister);
354+
DEFINE_SHIM_FUNCTION_INTERFACE(mem_register, memRegister)
353355

354-
DEFINE_SHIM_FUNCTION_INTERFACE(mem_de_register, memDeRegister);
356+
DEFINE_SHIM_FUNCTION_INTERFACE(mem_de_register, memDeRegister)
355357

356358
// QnnProperty
357-
DEFINE_SHIM_FUNCTION_INTERFACE(property_has_capability, propertyHasCapability);
359+
DEFINE_SHIM_FUNCTION_INTERFACE(property_has_capability, propertyHasCapability)
358360

359361
// QnnTensor
360-
DEFINE_SHIM_FUNCTION_INTERFACE(tensor_create_context_tensor, tensorCreateContextTensor);
362+
DEFINE_SHIM_FUNCTION_INTERFACE(tensor_create_context_tensor, tensorCreateContextTensor)
361363

362-
DEFINE_SHIM_FUNCTION_INTERFACE(tensor_create_graph_tensor, tensorCreateGraphTensor);
364+
DEFINE_SHIM_FUNCTION_INTERFACE(tensor_create_graph_tensor, tensorCreateGraphTensor)
363365

364366
// QnnSystem
365-
DEFINE_SHIM_FUNCTION_SYS_INTERFACE(system_context_create, systemContextCreate);
367+
DEFINE_SHIM_FUNCTION_SYS_INTERFACE(system_context_create, systemContextCreate)
366368

367-
DEFINE_SHIM_FUNCTION_SYS_INTERFACE(system_context_get_binary_info, systemContextGetBinaryInfo);
369+
DEFINE_SHIM_FUNCTION_SYS_INTERFACE(system_context_get_binary_info, systemContextGetBinaryInfo)
368370

369-
DEFINE_SHIM_FUNCTION_SYS_INTERFACE(system_context_free, systemContextFree);
371+
DEFINE_SHIM_FUNCTION_SYS_INTERFACE(system_context_free, systemContextFree)
370372

371373
void set_qnn_interface(const QnnInterface_t * qnn_interface) {
372374
_qnn_interface = qnn_interface;
@@ -398,7 +400,7 @@ class qnn_instance {
398400
const std::string & model_name) :
399401
_lib_path(std::move(lib_path)),
400402
_backend_name(std::move(backend_name)),
401-
_model_name(std::move(model_name)) {};
403+
_model_name(std::move(model_name)) {}
402404

403405
~qnn_instance() {
404406
}
@@ -428,19 +430,19 @@ class qnn_instance {
428430
return _qnn_raw_system_interface;
429431
}
430432

431-
const Qnn_LogHandle_t get_qnn_log_handle() { return _qnn_log_handle; }
433+
Qnn_LogHandle_t get_qnn_log_handle() { return _qnn_log_handle; }
432434

433-
const Qnn_ProfileHandle_t get_qnn_profile_handle() { return _qnn_profile_handle; }
435+
Qnn_ProfileHandle_t get_qnn_profile_handle() { return _qnn_profile_handle; }
434436

435-
const Qnn_DeviceHandle_t get_qnn_device_handle() { return _qnn_device_handle; }
437+
Qnn_DeviceHandle_t get_qnn_device_handle() { return _qnn_device_handle; }
436438

437-
const Qnn_BackendHandle_t get_qnn_backend_handle() { return _qnn_backend_handle; }
439+
Qnn_BackendHandle_t get_qnn_backend_handle() { return _qnn_backend_handle; }
438440

439-
const Qnn_ContextHandle_t get_qnn_context_handle() { return _qnn_context_handle; }
441+
Qnn_ContextHandle_t get_qnn_context_handle() { return _qnn_context_handle; }
440442

441-
const QnnSystemContext_Handle_t get_qnn_system_handle() { return _qnn_system_handle; }
443+
QnnSystemContext_Handle_t get_qnn_system_handle() { return _qnn_system_handle; }
442444

443-
const Qnn_GraphHandle_t get_qnn_graph_handle() { return _qnn_graph_handle; }
445+
Qnn_GraphHandle_t get_qnn_graph_handle() { return _qnn_graph_handle; }
444446

445447
int init_qnn_graph(const char * graph_name,
446448
bool debug,

0 commit comments

Comments
 (0)