Skip to content

Commit 8235cf6

Browse files
author
zhouwg
committed
ggml-hexagon: minimum viable PR
1 parent 98b0c5e commit 8235cf6

File tree

5 files changed

+19
-70
lines changed

5 files changed

+19
-70
lines changed

ggml/src/ggml-hexagon/ggml-hexagon.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ using pfn_rpc_mem_deinit = void (*)(void);
187187
using pfn_rpc_mem_alloc = void *(*)(int, uint32_t, int);
188188
using pfn_rpc_mem_free = void (*)(void *);
189189
using pfn_rpc_mem_to_fd = int (*)(void *);
190-
using _pfn_QnnSaver_initialize = decltype(QnnSaver_initialize);
191-
using _pfn_QnnInterface_getProviders = decltype(QnnInterface_getProviders);
192-
using _pfn_QnnSystemInterface_getProviders = decltype(QnnSystemInterface_getProviders);
190+
using pfn_qnnsaver_initialize = decltype(QnnSaver_initialize);
191+
using pfn_qnninterface_getproviders = decltype(QnnInterface_getProviders);
192+
using pfn_qnnsysteminterface_getproviders = decltype(QnnSystemInterface_getProviders);
193193

194194
//QNN resource management for the general approach through QNN
195195
using qnn_tensors_t = std::vector< Qnn_Tensor_t >;
@@ -702,7 +702,7 @@ static constexpr const hexagon_op_caps ggmlhexagon_k_op_caps[] = {
702702
{false, GGML_OP_CONCAT, 0, nullptr, nullptr},
703703
{false, GGML_OP_SILU_BACK, 0, nullptr, nullptr},
704704
{false, GGML_OP_NORM, 0, nullptr, nullptr},
705-
{true, GGML_OP_RMS_NORM, 1, "ggmlop_dsp_rmsnorm", ggmlop_dsp_rmsnorm},
705+
{false, GGML_OP_RMS_NORM, 0, nullptr, nullptr},
706706
{false, GGML_OP_RMS_NORM_BACK, 0, nullptr, nullptr},
707707
{false, GGML_OP_GROUP_NORM, 0, nullptr, nullptr},
708708
{false, GGML_OP_L2_NORM, 0, nullptr, nullptr},
@@ -723,7 +723,7 @@ static constexpr const hexagon_op_caps ggmlhexagon_k_op_caps[] = {
723723
{false, GGML_OP_DIAG, 0, nullptr, nullptr},
724724
{false, GGML_OP_DIAG_MASK_INF, 0, nullptr, nullptr},
725725
{false, GGML_OP_DIAG_MASK_ZERO, 0, nullptr, nullptr},
726-
{true, GGML_OP_SOFT_MAX, 1, "ggmlop_dsp_softmax", ggmlop_dsp_softmax},
726+
{false, GGML_OP_SOFT_MAX, 0, nullptr, nullptr},
727727
{false, GGML_OP_SOFT_MAX_BACK, 0, nullptr, nullptr},
728728
{false, GGML_OP_ROPE, 0, nullptr, nullptr},
729729
{false, GGML_OP_ROPE_BACK, 0, nullptr, nullptr},
@@ -735,7 +735,7 @@ static constexpr const hexagon_op_caps ggmlhexagon_k_op_caps[] = {
735735
{false, GGML_OP_CONV_2D_DW, 0, nullptr, nullptr},
736736
{false, GGML_OP_CONV_TRANSPOSE_2D, 0, nullptr, nullptr},
737737
{false, GGML_OP_POOL_1D, 0, nullptr, nullptr},
738-
{true, GGML_OP_POOL_2D, 1, "ggmlop_dsp_pool2d", ggmlop_dsp_pool2d},
738+
{false, GGML_OP_POOL_2D, 0, nullptr, nullptr},
739739
{false, GGML_OP_POOL_2D_BACK, 0, nullptr, nullptr},
740740
{false, GGML_OP_UPSCALE, 0, nullptr, nullptr},
741741
{false, GGML_OP_PAD, 0, nullptr, nullptr},
@@ -770,7 +770,6 @@ static constexpr const hexagon_op_caps ggmlhexagon_k_op_caps[] = {
770770
static_assert(ggmlhexagon_k_op_caps[GGML_OP_NONE].supported, "GGML_OP_NONE is not true");
771771
static_assert(ggmlhexagon_k_op_caps[GGML_OP_ADD].supported, "GGML_OP_ADD is not true");
772772
static_assert(ggmlhexagon_k_op_caps[GGML_OP_MUL_MAT].supported, "GGML_OP_MUL_MAT is not true");
773-
static_assert(ggmlhexagon_k_op_caps[GGML_OP_SOFT_MAX].supported, "GGML_OP_SOFT_MAX is not true");
774773
static_assert(std::size(ggmlhexagon_k_op_caps) == (static_cast<size_t>(GGML_OP_COUNT)),
775774
"pls check ggmlhexagon_k_op_caps and ensure is corresponding to latest ggml.h");
776775

@@ -3154,7 +3153,7 @@ int qnn_instance::load_backend(std::string & lib_path, const QnnSaver_Config_t *
31543153
return 1;
31553154
}
31563155

3157-
auto get_providers = ggmlqnn_load_qnn_functionpointers<_pfn_QnnInterface_getProviders *>(
3156+
auto get_providers = ggmlqnn_load_qnn_functionpointers<pfn_qnninterface_getproviders *>(
31583157
lib_handle,
31593158
"QnnInterface_getProviders");
31603159
if (nullptr == get_providers) {
@@ -3204,7 +3203,7 @@ int qnn_instance::load_backend(std::string & lib_path, const QnnSaver_Config_t *
32043203
_backend_id = backend_id;
32053204

32063205
auto saver_initialize =
3207-
ggmlqnn_load_qnn_functionpointers<_pfn_QnnSaver_initialize *>(_loaded_lib_handle, "QnnSaver_initialize");
3206+
ggmlqnn_load_qnn_functionpointers<pfn_qnnsaver_initialize *>(_loaded_lib_handle, "QnnSaver_initialize");
32083207
if (nullptr != saver_initialize) {
32093208
error = saver_initialize(saver_config);
32103209
if (error != QNN_SUCCESS) {
@@ -3255,7 +3254,7 @@ int qnn_instance::load_system() {
32553254
}
32563255
}
32573256

3258-
auto * get_providers = reinterpret_cast<_pfn_QnnSystemInterface_getProviders *>(dlsym(
3257+
auto * get_providers = reinterpret_cast<pfn_qnnsysteminterface_getproviders *>(dlsym(
32593258
_system_lib_handle, "QnnSystemInterface_getProviders"));
32603259
if (nullptr == get_providers) {
32613260
GGMLHEXAGON_LOG_WARN("can not load QNN symbol QnnSystemInterface_getProviders: %s\n", dlerror());
@@ -6239,7 +6238,10 @@ static ggml_backend_buffer_t ggml_backend_hexagon_buffer_type_alloc_buffer(
62396238
GGMLHEXAGON_LOG_DEBUG("size %ld(%d MiB), rpc_mempool_usage %ld(%d MiB), rpc_mempool_len %ld(%d MiB)",
62406239
size, size / SIZE_IN_MB, ctx->rpc_mempool_usage, ctx->rpc_mempool_usage / SIZE_IN_MB,
62416240
ctx->rpc_mempool_len, ctx->rpc_mempool_len / SIZE_IN_MB);
6242-
GGML_ASSERT(size + ctx->rpc_mempool_usage <= ctx->rpc_mempool_len);
6241+
if (size + ctx->rpc_mempool_usage >= ctx->rpc_mempool_len) {
6242+
GGMLHEXAGON_LOG_WARN("device memory allocation of size %ld failed", size);
6243+
return nullptr;
6244+
}
62436245
buffer_ctx->buffer = (static_cast<char*>(ctx->rpc_mempool)) + ctx->rpc_mempool_usage;
62446246
GGMLHEXAGON_LOG_DEBUG("buffer_ctx->buffer %p", buffer_ctx->buffer);
62456247
GGML_ASSERT(nullptr != buffer_ctx->buffer);

ggml/src/ggml-hexagon/kernels/entry.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -88,28 +88,3 @@ AEEResult ggmlop_dsp_setclocks(remote_handle64 handle, int32 power_level, int32
8888
GGMLHEXAGON_LOG_DEBUG("leave %s", __func__ );
8989
return AEE_SUCCESS;
9090
}
91-
92-
// =================================================================================================
93-
// implementation of ggml-hexagon kernel, it's better to put every hexagon-kernel to a single file
94-
// =================================================================================================
95-
int ggmlop_dsp_softmax(remote_handle64 h, const dsptensor * src0, const dsptensor * src1, dsptensor * dst) {
96-
GGMLHEXAGON_LOG_DEBUG("enter %s", __func__ );
97-
GGMLHEXAGON_LOG_DEBUG("leave %s", __func__ );
98-
return 0;
99-
}
100-
101-
int ggmlop_dsp_rmsnorm(remote_handle64 h, const dsptensor * src0, const dsptensor * src1, dsptensor * dst) {
102-
GGMLHEXAGON_LOG_DEBUG("enter %s", __func__ );
103-
GGMLHEXAGON_LOG_DEBUG("leave %s", __func__ );
104-
return 0;
105-
}
106-
107-
int ggmlop_dsp_pool2d(remote_handle64 h, const dsptensor * src0, const dsptensor * src1, dsptensor * dst) {
108-
GGMLHEXAGON_LOG_DEBUG("enter %s", __func__ );
109-
GGMLHEXAGON_LOG_DEBUG("leave %s", __func__ );
110-
return 0;
111-
}
112-
113-
int ggmlop_get_thread_counts(void) {
114-
return g_thread_counts;
115-
}

ggml/src/ggml-hexagon/kernels/mulmat.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,6 @@ static int ggmlop_dsp_mulmat_singlethread(remote_handle64 h, const ggml_tensor *
232232
return 0;
233233
}
234234

235-
static int ggmlop_dsp_mulmat_multithread(remote_handle64 h, const struct dsptensor * src0, const struct dsptensor * src1, dsptensor * dst) {
236-
GGMLHEXAGON_LOG_DEBUG("enter %s", __func__ );
237-
GGMLHEXAGON_LOG_DEBUG("leave %s", __func__ );
238-
return 0;
239-
}
240-
241235
int ggmlop_dsp_mulmat(remote_handle64 h, const struct dsptensor * src0, const struct dsptensor * src1, dsptensor * dst) {
242-
if (ggmlop_get_thread_counts() > 1) {
243-
return ggmlop_dsp_mulmat_multithread(h, src0, src1, dst);
244-
} else {
245-
return ggmlop_dsp_mulmat_singlethread(h, src0, src1, dst);
246-
}
236+
return ggmlop_dsp_mulmat_singlethread(h, src0, src1, dst);
247237
}

ggml/src/ggml-hexagon/kernels/skel.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,11 @@ static const StructType structTypes[1] = {{0x7,&(typeArrays[0]),0x70,0x4,0x6c,0x
278278
static const Type types[5] = {{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4},{0x10,{{(const uintptr_t)&(types[0]),(const uintptr_t)0x4}}, 8,0x4},{0x40,{{(const uintptr_t)&(types[0]),(const uintptr_t)0x10}}, 8,0x4},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[4]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8)},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4}};
279279
static const Parameter parameters[6] = {{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)0x0,0}}, 4,SLIM_IFPTR32(0x4,0x8),0,0},{SLIM_IFPTR32(0x4,0x8),{{(const uintptr_t)0xdeadc0de,(const uintptr_t)0}}, 0,SLIM_IFPTR32(0x4,0x8),3,0},{SLIM_IFPTR32(0x4,0x8),{{(const uintptr_t)0xdeadc0de,(const uintptr_t)0}}, 0,SLIM_IFPTR32(0x4,0x8),0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{SLIM_IFPTR32(0x74,0x80),{{(const uintptr_t)&(structTypes[0]),0}}, 22,SLIM_IFPTR32(0x4,0x8),0,0},{SLIM_IFPTR32(0x74,0x80),{{(const uintptr_t)&(structTypes[0]),0}}, 22,SLIM_IFPTR32(0x4,0x8),3,0}};
280280
static const Parameter* const parameterArrays[9] = {(&(parameters[4])),(&(parameters[4])),(&(parameters[5])),(&(parameters[3])),(&(parameters[3])),(&(parameters[3])),(&(parameters[0])),(&(parameters[1])),(&(parameters[2]))};
281-
static const Method methods[4] = {{REMOTE_SCALARS_MAKEX(0,0,0x2,0x0,0x0,0x1),0x4,0x0,2,2,(&(parameterArrays[6])),0x4,0x1},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x1,0x0),0x0,0x0,1,1,(&(parameterArrays[8])),0x1,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0xc,0x0,3,3,(&(parameterArrays[3])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x3,0x2,0x0,0x0),0xe4,0x6c,3,3,(&(parameterArrays[0])),0x4,0x4}};
282-
static const Method* const methodArrays[8] = {&(methods[0]),&(methods[1]),&(methods[2]),&(methods[3]),&(methods[3]),&(methods[3]),&(methods[3]),&(methods[3])};
283-
static const char strings[167] = "dsp_setclocks\0dsp_rmsnorm\0dsp_softmax\0dcvs_enable\0power_level\0dsp_pool2d\0dsp_mulmat\0op_params\0dsp_add\0latency\0flags\0close\0src1\0data\0type\0src0\0open\0dst\0uri\0op\0nb\0ne\0h\0";
284-
static const uint16_t methodStrings[134] = {62,137,132,161,158,155,84,110,127,122,132,161,158,155,84,110,127,147,132,161,158,155,84,110,127,14,137,132,161,158,155,84,110,127,122,132,161,158,155,84,110,127,147,132,161,158,155,84,110,127,26,137,132,161,158,155,84,110,127,122,132,161,158,155,84,110,127,147,132,161,158,155,84,110,127,73,137,132,161,158,155,84,110,127,122,132,161,158,155,84,110,127,147,132,161,158,155,84,110,127,94,137,132,161,158,155,84,110,127,122,132,161,158,155,84,110,127,147,132,161,158,155,84,110,127,0,50,102,38,142,151,164,116,164};
285-
static const uint16_t methodStringsArrays[8] = {129,132,125,100,75,50,25,0};
281+
static const Method methods[4] = {{REMOTE_SCALARS_MAKEX(0,0,0x2,0x0,0x0,0x1),0x4,0x0,2,2,(&(parameterArrays[7])),0x4,0x1},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x1,0x0),0x0,0x0,1,1,(&(parameterArrays[9])),0x1,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x10,0x0,4,4,(&(parameterArrays[0])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x3,0x2,0x0,0x0),0xe4,0x6c,3,3,(&(parameterArrays[4])),0x4,0x4}};
282+
static const Method* const methodArrays[5] = {&(methods[0]),&(methods[1]),&(methods[2]),&(methods[3]),&(methods[3])};
283+
static const char strings[145] = "mulmat_algotype\0thread_counts\0dsp_setclocks\0power_level\0dsp_mulmat\0op_params\0dsp_add\0latency\0flags\0close\0src1\0data\0src0\0open\0dst\0uri\0op\0nb\0ne\0h\0";
284+
static const uint16_t methodStrings[60] = {56,115,11,139,136,133,67,93,110,105,11,139,136,133,67,93,110,125,11,139,136,133,67,93,110,77,115,11,139,136,133,67,93,110,105,11,139,136,133,67,93,110,125,11,139,136,133,67,93,110,30,44,85,0,16,120,129,142,99,142};
285+
static const uint16_t methodStringsArrays[5] = {55,58,50,25,0};
286286
__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(ggmlop_slim) = {8,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings};
287287
#endif //_GGMLOP_SLIM_H
288288
extern int adsp_mmap_fd_getinfo(int, uint32_t *);
@@ -610,12 +610,6 @@ __QAIC_SKEL_EXPORT int __QAIC_SKEL(ggmldsp_skel_handle_invoke)(remote_handle64 _
610610
return _skel_method(__QAIC_IMPL(ggmlop_dsp_add), _h, _sc, _pra);
611611
case 4:
612612
return _skel_method(__QAIC_IMPL(ggmlop_dsp_mulmat), _h, _sc, _pra);
613-
case 5:
614-
return _skel_method(__QAIC_IMPL(ggmlop_dsp_softmax), _h, _sc, _pra);
615-
case 6:
616-
return _skel_method(__QAIC_IMPL(ggmlop_dsp_rmsnorm), _h, _sc, _pra);
617-
case 7:
618-
return _skel_method(__QAIC_IMPL(ggmlop_dsp_pool2d), _h, _sc, _pra);
619613
}
620614
return AEE_EUNSUPPORTED;
621615
}

ggml/src/ggml-hexagon/kernels/stub.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -449,15 +449,3 @@ __QAIC_STUB_EXPORT int __QAIC_STUB(ggmlop_dsp_mulmat)(remote_handle64 _handle, c
449449
uint32_t _mid = 4;
450450
return _stub_method_1(_handle, _mid, (uintptr_t*)src0, (uintptr_t*)src1, (uintptr_t*)dst);
451451
}
452-
__QAIC_STUB_EXPORT int __QAIC_STUB(ggmlop_dsp_softmax)(remote_handle64 _handle, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_STUB_ATTRIBUTE {
453-
uint32_t _mid = 5;
454-
return _stub_method_1(_handle, _mid, (uintptr_t*)src0, (uintptr_t*)src1, (uintptr_t*)dst);
455-
}
456-
__QAIC_STUB_EXPORT int __QAIC_STUB(ggmlop_dsp_rmsnorm)(remote_handle64 _handle, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_STUB_ATTRIBUTE {
457-
uint32_t _mid = 6;
458-
return _stub_method_1(_handle, _mid, (uintptr_t*)src0, (uintptr_t*)src1, (uintptr_t*)dst);
459-
}
460-
__QAIC_STUB_EXPORT int __QAIC_STUB(ggmlop_dsp_pool2d)(remote_handle64 _handle, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_STUB_ATTRIBUTE {
461-
uint32_t _mid = 7;
462-
return _stub_method_1(_handle, _mid, (uintptr_t*)src0, (uintptr_t*)src1, (uintptr_t*)dst);
463-
}

0 commit comments

Comments
 (0)