Skip to content

Commit 9a43a23

Browse files
committed
fix compiling error at new hexagon sdk
1 parent 4a3a874 commit 9a43a23

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

ggml/src/ggml-qnn/npu/CMakeLists.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ else()
1010
message(FATAL_ERROR "HEXAGON_SDK_ROOT not defined")
1111
endif()
1212

13+
if(${CMAKE_SYSTEM_NAME} MATCHES "Android")
14+
set(PREBUILT_LIB_DIR "android_aarch64")
15+
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
16+
set(PREBUILT_LIB_DIR "UbuntuARM_aarch64")
17+
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
18+
# Windows
19+
set(PREBUILT_LIB_DIR "windows_aarch64")
20+
endif()
21+
1322
if(HEXAGON_SDK_ROOT)
1423
include(${HEXAGON_SDK_ROOT}/build/cmake/hexagon_fun.cmake)
1524
else()
@@ -138,21 +147,13 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Android|Linux|Windows")
138147

139148
link_options(hexagon-npu-host)
140149

141-
if(${CMAKE_SYSTEM_NAME} MATCHES "Android")
142-
set(PREBUILT_LIB_DIR "android_aarch64")
143-
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
144-
set(PREBUILT_LIB_DIR "UbuntuARM_aarch64")
145-
else()
146-
# Windows
147-
set(PREBUILT_LIB_DIR "windows_aarch64")
148-
endif()
149-
150150
choose_dsprpc("3" dsprpc) # cdsprpc
151151
link_custom_library(hexagon-npu-host ${dsprpc})
152152

153153
cmake_host_system_information(RESULT BUILD_CPU_COUNT QUERY NUMBER_OF_PHYSICAL_CORES)
154154
add_dsp_targets_for_host(hexagon-npu-host "v73" ${BUILD_CPU_COUNT})
155155
add_dsp_targets_for_host(hexagon-npu-host "v75" ${BUILD_CPU_COUNT})
156+
add_dsp_targets_for_host(hexagon-npu-host "v79" ${BUILD_CPU_COUNT})
156157

157158
list(APPEND NPU_RUNTIME_LIBS "${HEXAGON_SDK_ROOT}/tools/utils/sysmon/sysMonApp")
158159
list(APPEND NPU_RUNTIME_LIBS "${HEXAGON_SDK_ROOT}/tools/utils/sysmon/sysMonAppLE")
@@ -249,6 +250,7 @@ else()
249250
target_link_libraries(hexagon_npu_skel
250251
${HEXAGON_LIB_DIR}/${HEXAGON_ARCH}/G0/pic/libc++abi.a
251252
${HEXAGON_LIB_DIR}/${HEXAGON_ARCH}/G0/pic/libc++.a
253+
${HEXAGON_LIB_DIR}/${HEXAGON_ARCH}/G0/pic/libc.a
252254
)
253255
set_target_properties(hexagon_npu_skel PROPERTIES OUTPUT_NAME "hexagon_npu_skel_${HEXAGON_ARCH}")
254256
target_link_libraries(hexagon_npu_skel qprintf_static)

ggml/src/ggml-qnn/npu/device/op_mul_mat.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "thread_pool.hpp" // TODO: remove this dependency
44
#include "type_traits.hpp"
55
#include "vec_ops.hpp"
6-
#include "vtcm_mem.hpp"
76

87
namespace {
98

ggml/src/ggml-qnn/npu/device/thread_pool.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <qurt.h>
44

5+
#include <array>
56
#include <atomic>
67
#include <cstdint>
78
#include <memory>
@@ -237,8 +238,8 @@ template <size_t _ThreadCount> class thread_pool {
237238
DEVICE_LOG_DEBUG("thread_func_impl.end: %zu", param->tidx);
238239
}
239240

240-
std::atomic_bool _thread_exit = false;
241-
std::array<qurt_thread_ptr, kMaxSubThreadCount> _threads;
241+
std::atomic_bool _thread_exit = false;
242+
std::array<qurt_thread_ptr, kMaxSubThreadCount> _threads = {};
242243
qurt_barrier_t _pending = {};
243244
qurt_barrier_t _completed = {};
244245
thread_params _thread_params[kMaxThreadCount] = {};

ggml/src/ggml-qnn/npu/device/vtcm_mem.hpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <HAP_compute_res.h>
34
#include <HAP_vtcm_mgr.h>
45

56
#include "util.hpp"
@@ -9,15 +10,28 @@ namespace hexagon {
910
class vtcm_mem {
1011
public:
1112
explicit vtcm_mem(size_t size, bool single_page) {
13+
constexpr const unsigned int kTimeoutUs = 10000; // 10ms timeout
14+
1215
size_t avail_size = single_page ? get_avail_page_size() : get_avail_block_size();
1316
if (size > avail_size) {
1417
DEVICE_LOG_ERROR("Requested VTCM size %zu exceeds available size %zu\n", size, avail_size);
1518
return;
1619
}
1720

18-
_vtcm_mem = HAP_request_VTCM((unsigned int) size, single_page ? 1 : 0);
21+
compute_res_attr_t compute_res;
22+
HAP_compute_res_attr_init(&compute_res);
23+
HAP_compute_res_attr_set_serialize(&compute_res, false);
24+
HAP_compute_res_attr_set_vtcm_param(&compute_res, size, single_page ? 1 : 0);
25+
26+
_vtcm_context_id = HAP_compute_res_acquire(&compute_res, kTimeoutUs); // 10ms timeout
27+
if (_vtcm_context_id == 0) {
28+
DEVICE_LOG_ERROR("Failed to acquire VTCM context: %zu bytes, timeout %zu us\n", size, kTimeoutUs);
29+
return;
30+
}
31+
32+
_vtcm_mem = HAP_compute_res_attr_get_vtcm_ptr(&compute_res);
1933
if (_vtcm_mem == nullptr) {
20-
DEVICE_LOG_ERROR("Failed to allocate VTCM memory: %zu bytes\n", size);
34+
DEVICE_LOG_ERROR("Failed to allocate VTCM memory: %zu bytes, timeout %zu us\n", size, kTimeoutUs);
2135
return;
2236
}
2337

@@ -26,7 +40,18 @@ class vtcm_mem {
2640
}
2741

2842
explicit vtcm_mem(size_t size, bool single_page, size_t timeout_us) {
29-
_vtcm_mem = HAP_request_async_VTCM((unsigned int) size, single_page ? 1 : 0, (unsigned int) timeout_us);
43+
compute_res_attr_t compute_res;
44+
HAP_compute_res_attr_init(&compute_res);
45+
HAP_compute_res_attr_set_serialize(&compute_res, false);
46+
HAP_compute_res_attr_set_vtcm_param(&compute_res, size, single_page ? 1 : 0);
47+
48+
_vtcm_context_id = HAP_compute_res_acquire(&compute_res, timeout_us);
49+
if (_vtcm_context_id == 0) {
50+
DEVICE_LOG_ERROR("Failed to acquire VTCM context: %zu bytes, timeout %zu us\n", size, timeout_us);
51+
return;
52+
}
53+
54+
_vtcm_mem = HAP_compute_res_attr_get_vtcm_ptr(&compute_res);
3055
if (_vtcm_mem == nullptr) {
3156
DEVICE_LOG_ERROR("Failed to allocate VTCM memory: %zu bytes, timeout %zu us\n", size, timeout_us);
3257
return;
@@ -37,8 +62,8 @@ class vtcm_mem {
3762
}
3863

3964
~vtcm_mem() {
40-
if (is_valid()) {
41-
auto ret = HAP_release_VTCM(_vtcm_mem);
65+
if (_vtcm_context_id != 0) {
66+
auto ret = HAP_compute_res_release(_vtcm_context_id);
4267
if (ret != AEE_SUCCESS) {
4368
DEVICE_LOG_ERROR("Failed to release VTCM memory: %d\n", ret);
4469
}
@@ -95,6 +120,8 @@ class vtcm_mem {
95120
void * _vtcm_mem = nullptr;
96121
size_t _vtcm_size = 0;
97122

123+
unsigned int _vtcm_context_id = 0;
124+
98125
DISABLE_COPY_AND_MOVE(vtcm_mem);
99126
};
100127

0 commit comments

Comments
 (0)