Commit 72b590d65 for llama.cpp
commit 72b590d65f04adabbb6403d75188edc77bc5a867
Author: Trivikram Reddy <127072883+trivikram-reddy1@users.noreply.github.com>
Date: Tue Sep 15 17:45:28 2026 -0500
hex-cpy: use dma if src and dst are contiguous (#28906)
diff --git a/ggml/src/ggml-hexagon/htp/cpy-ops.c b/ggml/src/ggml-hexagon/htp/cpy-ops.c
index 7f01a8c1e..e68b2d3db 100644
--- a/ggml/src/ggml-hexagon/htp/cpy-ops.c
+++ b/ggml/src/ggml-hexagon/htp/cpy-ops.c
@@ -294,6 +294,18 @@ static inline void cpy_dma_sametype_sameshape(
dma_queue_flush(q);
}
+static inline void cpy_dma_sametype_reshape_contig(
+ struct htp_ops_context * octx,
+ const struct htp_tensor * dst,
+ const struct htp_tensor * src0,
+ uint32_t total_bytes
+) {
+ dma_queue * q = octx->ctx->dma[0];
+ dma_queue_push(q, dma_make_ptr((void *) dst->data, (const void *) src0->data),
+ total_bytes, total_bytes, total_bytes, /*nrows=*/ 1);
+ dma_queue_pop(q);
+}
+
static int exec_cpy(struct htp_ops_context * octx, bool * use_dma) {
cpy_preamble;
*use_dma = false;
@@ -327,6 +339,7 @@ static int exec_cpy(struct htp_ops_context * octx, bool * use_dma) {
const uint32_t n_threads = octx->n_threads;
+ const bool src_is_contiguous = htp_tensor_is_contiguous(src0, ct.src0_type_size);
const bool dst_is_contiguous = htp_tensor_is_contiguous(dst, ct.dst_type_size);
if (sameshape) {
@@ -375,6 +388,12 @@ static int exec_cpy(struct htp_ops_context * octx, bool * use_dma) {
const uint32_t total_elems = ne0 * ne1 * ne2 * ne3;
const uint32_t elems_per_line = (ct.dst_type_size == 4) ? 32 : 64;
+ if (octx->ctx->mdev.count <= 1 && dst_is_contiguous && src_is_contiguous) {
+ *use_dma = true;
+ cpy_dma_sametype_reshape_contig(octx, dst, src0, total_elems * ct.dst_type_size);
+ return HTP_STATUS_OK;
+ }
+
ct.div_ne0 = init_fastdiv_values(ne0);
ct.div_ne1_ne0 = init_fastdiv_values(ne1 * ne0);
ct.div_ne2_ne1_ne0 = init_fastdiv_values(ne2 * ne1 * ne0);