Skip to content

Commit 7e96a11

Browse files
author
zhouwg
committed
ggml-hexagon:add skelton code of offload GGML_OP_SOFT_MAX/GGML_OP_RMS_NORM/GGML_OP_POOL_2D to Hexagon cDSP
1 parent d0aaf11 commit 7e96a11

File tree

5 files changed

+71
-307
lines changed

5 files changed

+71
-307
lines changed

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,9 @@ static constexpr const hexagon_op_caps ggmlhexagon_k_op_caps[] = {
598598
{true, GGML_OP_ADD, 2, "ggmlop_dsp_add", ggmlop_dsp_add},
599599
{false, GGML_OP_ADD1, 0, nullptr, nullptr},
600600
{false, GGML_OP_ACC, 0, nullptr, nullptr},
601-
{true, GGML_OP_SUB, 2, "ggmlop_dsp_sub", ggmlop_dsp_sub},
602-
{true, GGML_OP_MUL, 2, "ggmlop_dsp_mul", ggmlop_dsp_mul},
603-
{true, GGML_OP_DIV, 2, "ggmlop_dsp_div", ggmlop_dsp_div},
601+
{false, GGML_OP_SUB, 2, nullptr, nullptr},
602+
{false, GGML_OP_MUL, 2, nullptr, nullptr},
603+
{false, GGML_OP_DIV, 2, nullptr, nullptr},
604604
{false, GGML_OP_SQR, 0, nullptr, nullptr},
605605
{false, GGML_OP_SQRT, 0, nullptr, nullptr},
606606
{false, GGML_OP_LOG, 0, nullptr, nullptr},
@@ -616,7 +616,7 @@ static constexpr const hexagon_op_caps ggmlhexagon_k_op_caps[] = {
616616
{false, GGML_OP_CONCAT, 0, nullptr, nullptr},
617617
{false, GGML_OP_SILU_BACK, 0, nullptr, nullptr},
618618
{false, GGML_OP_NORM, 0, nullptr, nullptr},
619-
{false, GGML_OP_RMS_NORM, 0, nullptr, nullptr},
619+
{true, GGML_OP_RMS_NORM, 1, "ggmlop_dsp_rmsnorm", ggmlop_dsp_rmsnorm},
620620
{false, GGML_OP_RMS_NORM_BACK, 0, nullptr, nullptr},
621621
{false, GGML_OP_GROUP_NORM, 0, nullptr, nullptr},
622622
{false, GGML_OP_L2_NORM, 0, nullptr, nullptr},
@@ -636,7 +636,7 @@ static constexpr const hexagon_op_caps ggmlhexagon_k_op_caps[] = {
636636
{false, GGML_OP_DIAG, 0, nullptr, nullptr},
637637
{false, GGML_OP_DIAG_MASK_INF, 0, nullptr, nullptr},
638638
{false, GGML_OP_DIAG_MASK_ZERO, 0, nullptr, nullptr},
639-
{false, GGML_OP_SOFT_MAX, 0, nullptr, nullptr},
639+
{true, GGML_OP_SOFT_MAX, 1, "ggmlop_dsp_softmax", ggmlop_dsp_softmax},
640640
{false, GGML_OP_SOFT_MAX_BACK, 0, nullptr, nullptr},
641641
{false, GGML_OP_ROPE, 0, nullptr, nullptr},
642642
{false, GGML_OP_ROPE_BACK, 0, nullptr, nullptr},
@@ -646,7 +646,7 @@ static constexpr const hexagon_op_caps ggmlhexagon_k_op_caps[] = {
646646
{false, GGML_OP_IM2COL_BACK, 0, nullptr, nullptr},
647647
{false, GGML_OP_CONV_TRANSPOSE_2D, 0, nullptr, nullptr},
648648
{false, GGML_OP_POOL_1D, 0, nullptr, nullptr},
649-
{false, GGML_OP_POOL_2D, 0, nullptr, nullptr},
649+
{true, GGML_OP_POOL_2D, 1, "ggmlop_dsp_pool2d", ggmlop_dsp_pool2d},
650650
{false, GGML_OP_POOL_2D_BACK, 0, nullptr, nullptr},
651651
{false, GGML_OP_UPSCALE, 0, nullptr, nullptr},
652652
{false, GGML_OP_PAD, 0, nullptr, nullptr},
@@ -694,10 +694,10 @@ static constexpr const hexagon_op_caps ggmlhexagon_k_op_caps[] = {
694694
{false, static_cast<ggml_op>(GGML_UNARY_OP_EXP), 0, nullptr, nullptr}
695695
};
696696

697-
static_assert(ggmlhexagon_k_op_caps[GGML_OP_NONE].supported, "GGML_OP_NONE is not true");
698-
static_assert(ggmlhexagon_k_op_caps[GGML_OP_ADD].supported, "GGML_OP_ADD is not true");
699-
static_assert(ggmlhexagon_k_op_caps[GGML_OP_MUL].supported, "GGML_OP_MUL is not true");
700-
static_assert(ggmlhexagon_k_op_caps[GGML_OP_MUL_MAT].supported, "GGML_OP_MUL_MAT is not true");
697+
static_assert(ggmlhexagon_k_op_caps[GGML_OP_NONE].supported, "GGML_OP_NONE is not true");
698+
static_assert(ggmlhexagon_k_op_caps[GGML_OP_ADD].supported, "GGML_OP_ADD is not true");
699+
static_assert(ggmlhexagon_k_op_caps[GGML_OP_MUL_MAT].supported, "GGML_OP_MUL_MAT is not true");
700+
static_assert(ggmlhexagon_k_op_caps[GGML_OP_SOFT_MAX].supported, "GGML_OP_SOFT_MAX is not true");
701701
static_assert(std::size(ggmlhexagon_k_op_caps) == (static_cast<size_t>(GGML_OP_COUNT) + static_cast<size_t>(GGML_UNARY_OP_COUNT)),
702702
"pls check ggmlhexagon_k_op_caps and ensure is corresponding to latest ggml.h");
703703

@@ -5086,11 +5086,19 @@ static bool ggmlhexagon_can_handle_op_through_cdsp(ggml_backend_dev_t dev, const
50865086
{
50875087
ggmlhexagon_dump_op_info(op_tensor);
50885088
if (1 == g_hexagon_appcfg.enable_q_mulmat)
5089-
return (src0->type == GGML_TYPE_F32 || src0->type == GGML_TYPE_Q6_K
5089+
return (src0->type == GGML_TYPE_F32
5090+
|| src0->type == GGML_TYPE_Q4_0 || src0->type == GGML_TYPE_Q8_0
5091+
|| src0->type == GGML_TYPE_Q6_K || src0->type == GGML_TYPE_Q8_K
50905092
) && (src1->type == GGML_TYPE_F32) && (op_tensor->type == GGML_TYPE_F32);
50915093
else
50925094
return (src0->type == GGML_TYPE_F32) && (src1->type == GGML_TYPE_F32) && (op_tensor->type == GGML_TYPE_F32);
50935095
}
5096+
case GGML_OP_SOFT_MAX:
5097+
case GGML_OP_RMS_NORM:
5098+
case GGML_OP_POOL_2D:
5099+
{
5100+
ggmlhexagon_dump_op_info(op_tensor);
5101+
}
50945102
default:
50955103
break;
50965104
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,15 @@ __QAIC_STUB_EXPORT int __QAIC_STUB(ggmlop_dsp_mulmat)(remote_handle64 _handle, c
446446
uint32_t _mid = 4;
447447
return _stub_method_1(_handle, _mid, (uintptr_t*)src0, (uintptr_t*)src1, (uintptr_t*)dst);
448448
}
449-
__QAIC_STUB_EXPORT int __QAIC_STUB(ggmlop_dsp_mul)(remote_handle64 _handle, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_STUB_ATTRIBUTE {
449+
__QAIC_STUB_EXPORT int __QAIC_STUB(ggmlop_dsp_softmax)(remote_handle64 _handle, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_STUB_ATTRIBUTE {
450450
uint32_t _mid = 5;
451451
return _stub_method_1(_handle, _mid, (uintptr_t*)src0, (uintptr_t*)src1, (uintptr_t*)dst);
452452
}
453-
__QAIC_STUB_EXPORT int __QAIC_STUB(ggmlop_dsp_sub)(remote_handle64 _handle, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_STUB_ATTRIBUTE {
453+
__QAIC_STUB_EXPORT int __QAIC_STUB(ggmlop_dsp_rmsnorm)(remote_handle64 _handle, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_STUB_ATTRIBUTE {
454454
uint32_t _mid = 6;
455455
return _stub_method_1(_handle, _mid, (uintptr_t*)src0, (uintptr_t*)src1, (uintptr_t*)dst);
456456
}
457-
__QAIC_STUB_EXPORT int __QAIC_STUB(ggmlop_dsp_div)(remote_handle64 _handle, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_STUB_ATTRIBUTE {
457+
__QAIC_STUB_EXPORT int __QAIC_STUB(ggmlop_dsp_pool2d)(remote_handle64 _handle, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_STUB_ATTRIBUTE {
458458
uint32_t _mid = 7;
459459
return _stub_method_1(_handle, _mid, (uintptr_t*)src0, (uintptr_t*)src1, (uintptr_t*)dst);
460460
}

ggml/src/ggml-hexagon/kernels/ggmlop_ap_skel.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ __QAIC_HEADER_EXPORT int __QAIC_HEADER(ggmlop_dsp_close)(remote_handle64 h) __QA
274274
__QAIC_HEADER_EXPORT AEEResult __QAIC_HEADER(ggmlop_dsp_setclocks)(remote_handle64 _h, int32 power_level, int32 latency, int32 dcvs_enable) __QAIC_HEADER_ATTRIBUTE;
275275
__QAIC_HEADER_EXPORT int __QAIC_HEADER(ggmlop_dsp_add)(remote_handle64 _h, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_HEADER_ATTRIBUTE;
276276
__QAIC_HEADER_EXPORT int __QAIC_HEADER(ggmlop_dsp_mulmat)(remote_handle64 _h, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_HEADER_ATTRIBUTE;
277-
__QAIC_HEADER_EXPORT int __QAIC_HEADER(ggmlop_dsp_mul)(remote_handle64 _h, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_HEADER_ATTRIBUTE;
278-
__QAIC_HEADER_EXPORT int __QAIC_HEADER(ggmlop_dsp_sub)(remote_handle64 _h, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_HEADER_ATTRIBUTE;
279-
__QAIC_HEADER_EXPORT int __QAIC_HEADER(ggmlop_dsp_div)(remote_handle64 _h, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_HEADER_ATTRIBUTE;
277+
__QAIC_HEADER_EXPORT int __QAIC_HEADER(ggmlop_dsp_softmax)(remote_handle64 _h, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_HEADER_ATTRIBUTE;
278+
__QAIC_HEADER_EXPORT int __QAIC_HEADER(ggmlop_dsp_rmsnorm)(remote_handle64 _h, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_HEADER_ATTRIBUTE;
279+
__QAIC_HEADER_EXPORT int __QAIC_HEADER(ggmlop_dsp_pool2d)(remote_handle64 _h, const dsptensor* src0, const dsptensor* src1, dsptensor* dst) __QAIC_HEADER_ATTRIBUTE;
280280
#ifndef ggmlop_URI
281281
#define ggmlop_URI "file:///libggmlop_skel.so?ggmlop_skel_handle_invoke&_modver=1.0&_idlver=0.0.1"
282282
#endif /*ggmlop_URI*/

0 commit comments

Comments
 (0)