Skip to content

Commit b734044

Browse files
ggml-hexagon: add PAD op HVX kernel (#23078)
* ggml-hexagon: add PAD op HVX kernel Implements GGML_OP_PAD on the Hexagon HTP backend using HVX vectorized kernels. Supports zero-padding and circular padding across all 4 tensor dimensions. * hex-ggml: remove duplicate op cases (merge conflict) * hex-pad: fix editorconfig checks and macro alignment --------- Co-authored-by: Max Krasnyansky <maxk@qti.qualcomm.com>
1 parent 5cbaa5e commit b734044

6 files changed

Lines changed: 569 additions & 0 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,6 +2744,18 @@ static bool ggml_hexagon_supported_ssm_conv(const struct ggml_hexagon_session *
27442744
return true;
27452745
}
27462746

2747+
static bool ggml_hexagon_supported_pad(const struct ggml_hexagon_session * sess, const struct ggml_tensor * op) {
2748+
const struct ggml_tensor * src0 = op->src[0];
2749+
const struct ggml_tensor * dst = op;
2750+
2751+
if (src0->type != GGML_TYPE_F32 || dst->type != GGML_TYPE_F32) {
2752+
return false;
2753+
}
2754+
2755+
GGML_UNUSED(sess);
2756+
return true;
2757+
}
2758+
27472759
static bool ggml_hexagon_supported_cumsum(const struct ggml_hexagon_session * sess, const struct ggml_tensor * op) {
27482760
const struct ggml_tensor * src0 = op->src[0];
27492761
const struct ggml_tensor * dst = op;
@@ -2857,6 +2869,8 @@ static htp_op_code op_remap_to_htp(const ggml_tensor * t) {
28572869
case GGML_OP_FILL: return HTP_OP_FILL;
28582870
case GGML_OP_DIAG: return HTP_OP_DIAG;
28592871
case GGML_OP_SOLVE_TRI: return HTP_OP_SOLVE_TRI;
2872+
case GGML_OP_PAD: return HTP_OP_PAD;
2873+
28602874
case GGML_OP_UNARY:
28612875
switch (ggml_get_unary_op(t)) {
28622876
case GGML_UNARY_OP_SILU: return HTP_OP_UNARY_SILU;
@@ -3416,6 +3430,10 @@ static bool ggml_backend_hexagon_device_supports_op(ggml_backend_dev_t dev, cons
34163430
supp = ggml_hexagon_supported_solve_tri(sess, op);
34173431
break;
34183432

3433+
case GGML_OP_PAD:
3434+
supp = ggml_hexagon_supported_pad(sess, op);
3435+
break;
3436+
34193437
default:
34203438
break;
34213439
}

ggml/src/ggml-hexagon/htp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ add_library(${HTP_LIB} SHARED
3838
diag-ops.c
3939
solve-tri-ops.c
4040
gated-delta-net-ops.c
41+
pad-ops.c
4142
)
4243

4344
target_compile_definitions(${HTP_LIB} PRIVATE

ggml/src/ggml-hexagon/htp/htp-ctx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,6 @@ int op_fill(struct htp_ops_context * octx);
107107
int op_diag(struct htp_ops_context * octx);
108108
int op_solve_tri(struct htp_ops_context * octx);
109109
int op_gated_delta_net(struct htp_ops_context * octx);
110+
int op_pad(struct htp_ops_context * octx);
110111

111112
#endif /* HTP_CTX_H */

ggml/src/ggml-hexagon/htp/htp-ops.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ enum htp_op_code {
8686
HTP_OP_SOLVE_TRI,
8787
HTP_OP_L2_NORM,
8888
HTP_OP_GATED_DELTA_NET,
89+
HTP_OP_PAD,
8990

9091
HTP_OP_INVALID
9192
};

ggml/src/ggml-hexagon/htp/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,9 @@ static int execute_op(struct htp_ops_context * octx) {
595595
case HTP_OP_SOLVE_TRI:
596596
return op_solve_tri(octx);
597597

598+
case HTP_OP_PAD:
599+
return op_pad(octx);
600+
598601
case HTP_OP_GATED_DELTA_NET:
599602
return op_gated_delta_net(octx);
600603

0 commit comments

Comments
 (0)