From 14ebbd5f2f3ab7dbbeeb7d91bc3facd0011b618a Mon Sep 17 00:00:00 2001 From: Ravi Panchumarthy Date: Tue, 29 Sep 2026 00:24:01 +0530 Subject: [PATCH] ggml-openvino: mark unaligned batch-stride views unsupported (#29603) --- ggml/src/ggml-openvino/ggml-openvino.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ggml/src/ggml-openvino/ggml-openvino.cpp b/ggml/src/ggml-openvino/ggml-openvino.cpp index 02c5962238..b2d81df97d 100644 --- a/ggml/src/ggml-openvino/ggml-openvino.cpp +++ b/ggml/src/ggml-openvino/ggml-openvino.cpp @@ -9,6 +9,7 @@ #include "ggml-quants.h" #include "ggml.h" +#include #include #include #include @@ -960,6 +961,24 @@ static bool has_view_op_input(const ggml_tensor * op) { return false; } +// OV slices whole elements per axis, so each stride must be a multiple of the next smaller one +// (e.g. a batch stride of m*nb[1] + pad bytes cannot be expressed and would be read wrongly). +static bool has_strides_on_element_grid(const ggml_tensor * t) { + std::vector strides; + for (int i = 0; i < GGML_MAX_DIMS; i++) { + if (t->ne[i] > 1) { + strides.push_back(t->nb[i]); + } + } + std::sort(strides.begin(), strides.end()); + for (size_t i = 1; i < strides.size(); i++) { + if (strides[i - 1] == 0 || strides[i] % strides[i - 1] != 0) { + return false; + } + } + return true; +} + static bool has_non_contiguous_view_input(const ggml_tensor * op) { for (int i = 0; i < GGML_MAX_SRC; i++) { if (op->src[i] == nullptr) { @@ -1540,6 +1559,9 @@ static ggml_openvino_op_support ggml_backend_openvino_device_supports_op_impl(gg if (supported_types.find(src->type) == supported_types.end()) { return {false, "src[" + std::to_string(i) + "] type " + std::string(ggml_type_name(src->type)) + " is not supported"}; } + if (!has_strides_on_element_grid(src)) { + return {false, "src[" + std::to_string(i) + "] strides are not multiples of each other"}; + } const bool is_supported_3d_moe_expert = op->op == GGML_OP_MUL_MAT_ID && i == 0 && (src->type == GGML_TYPE_MXFP4 || src->ne[3] == 1); if (ggml_is_quantized(src->type) && src->ne[2] != 1 && !is_supported_3d_moe_expert) {