From 313a444b2298613d89633c15a774c09533eed789 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sun, 22 Jun 2025 10:27:31 +0300 Subject: [PATCH] ggml : add ggml_is_contiguous_rows --- ggml/include/ggml.h | 3 +++ ggml/src/ggml.c | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/ggml/include/ggml.h b/ggml/include/ggml.h index 5376696d4c..2c6de09ab9 100644 --- a/ggml/include/ggml.h +++ b/ggml/include/ggml.h @@ -688,6 +688,9 @@ extern "C" { // true for tensor that is stored in memory as CxWxHxN and has been permuted to WxHxCxN GGML_API bool ggml_is_contiguous_channels(const struct ggml_tensor * tensor); + // true if the elements in dimension 0 are contiguous, or there is just 1 block of elements + GGML_API bool ggml_is_contiguous_rows(const struct ggml_tensor * tensor); + GGML_API bool ggml_are_same_shape (const struct ggml_tensor * t0, const struct ggml_tensor * t1); GGML_API bool ggml_are_same_stride(const struct ggml_tensor * t0, const struct ggml_tensor * t1); diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index 13405a7d3b..4779565110 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -1353,6 +1353,12 @@ bool ggml_is_contiguous_channels(const struct ggml_tensor * tensor) { tensor->nb[2] == ggml_type_size(tensor->type); } +bool ggml_is_contiguous_rows(const struct ggml_tensor * tensor) { + return + tensor->ne[0] == ggml_blck_size(tensor->type) || + tensor->nb[0] == ggml_type_size(tensor->type); +} + static inline bool ggml_is_padded_1d(const struct ggml_tensor * tensor) { static_assert(GGML_MAX_DIMS == 4, "GGML_MAX_DIMS is not 4 - update this function");