Skip to content

Commit a32fc70

Browse files
committed
ggml : add ggml_is_contiguous_rows
1 parent fe1bb4f commit a32fc70

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

ggml/include/ggml.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,9 @@ extern "C" {
688688
// true for tensor that is stored in memory as CxWxHxN and has been permuted to WxHxCxN
689689
GGML_API bool ggml_is_contiguous_channels(const struct ggml_tensor * tensor);
690690

691+
// true if the elements in dimension 0 are contiguous, or there is just 1 block of elements
692+
GGML_API bool ggml_is_contiguous_rows(const struct ggml_tensor * tensor);
693+
691694
GGML_API bool ggml_are_same_shape (const struct ggml_tensor * t0, const struct ggml_tensor * t1);
692695
GGML_API bool ggml_are_same_stride(const struct ggml_tensor * t0, const struct ggml_tensor * t1);
693696

ggml/src/ggml.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,12 @@ bool ggml_is_contiguous_channels(const struct ggml_tensor * tensor) {
13531353
tensor->nb[2] == ggml_type_size(tensor->type);
13541354
}
13551355

1356+
bool ggml_is_contiguous_rows(const struct ggml_tensor * tensor) {
1357+
return
1358+
tensor->ne[0] == ggml_blck_size(tensor->type) ||
1359+
tensor->nb[0] == ggml_type_size(tensor->type);
1360+
}
1361+
13561362
static inline bool ggml_is_padded_1d(const struct ggml_tensor * tensor) {
13571363
static_assert(GGML_MAX_DIMS == 4, "GGML_MAX_DIMS is not 4 - update this function");
13581364

0 commit comments

Comments
 (0)