Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[NPU] Correct layout handling for low-precision tensors end-to-end (#39939)

Pawel Raasz0313ef793cb7
diff --git a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp
index 695ec411dc0..ed34b557475 100644
--- a/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp
+++ b/src/plugins/intel_npu/src/backend/src/zero_pipeline.cpp
@@ -14,6 +14,8 @@
#include "intel_npu/utils/logger/logger.hpp"
#include "intel_npu/utils/zero/zero_cmd_queue_pool.hpp"
#include "intel_npu/utils/zero/zero_types.hpp"
+#include "intel_npu/utils/zero/zero_utils.hpp"
+#include "openvino/core/memory_util.hpp"
namespace {
@@ -27,46 +29,10 @@ uint32_t get_graph_unique_id_or_throw(const std::shared_ptr<intel_npu::IGraph>&
namespace intel_npu {
std::vector<size_t> IPipeline::get_strides(const ov::ITensor& tensor, bool reverse_order) {
- const auto& element_type = tensor.get_element_type();
- if (element_type.bitwidth() < 8) {
- // Packed sub-byte tensors have no byte strides, so contiguous element strides are derived from the shape
- const auto& shape = tensor.get_shape();
- std::vector<size_t> element_strides(shape.size());
- size_t stride = 1;
- for (size_t dim = shape.size(); dim > 0; --dim) {
- element_strides[dim - 1] = stride;
- stride *= shape[dim - 1];
- }
- if (reverse_order) {
- std::reverse(element_strides.begin(), element_strides.end());
- }
- return element_strides;
- }
-
- const auto element_size = element_type.size();
- const auto& strides_in_bytes = tensor.get_strides();
- std::vector<size_t> element_strides(strides_in_bytes.size());
- const auto convert_to_element_stride = [element_size](size_t byte_stride) {
- OPENVINO_ASSERT(byte_stride % element_size == 0,
- "Stride ",
- byte_stride,
- " bytes is not aligned to element size ",
- element_size,
- " bytes. Strides must be multiples of element size.");
-
- return byte_stride / element_size;
- };
+ auto element_strides = zeroUtils::byte_strides_to_element_strides(tensor.get_strides(), tensor.get_element_type());
if (reverse_order) {
- std::transform(strides_in_bytes.rbegin(),
- strides_in_bytes.rend(),
- element_strides.begin(),
- convert_to_element_stride);
- } else {
- std::transform(strides_in_bytes.begin(),
- strides_in_bytes.end(),
- element_strides.begin(),
- convert_to_element_stride);
+ std::reverse(element_strides.begin(), element_strides.end());
}
return element_strides;
@@ -216,8 +182,8 @@ Pipeline::Pipeline(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,
_logger.debug("Pipeline - set args for input index: %zu", io_index);
const auto& tensor = input_tensors.at(io_index).at(i);
- if (tensor->get_element_type().bitwidth() < 8 || tensor->is_continuous() ||
- tensor->get_strides().empty()) {
+ if (!ov::util::can_compute_byte_strides(tensor->get_element_type(), tensor->get_shape()) ||
+ tensor->is_continuous() || tensor->get_strides().empty()) {
_graph->set_argument_value(desc.indexUsedByDriver, tensor->data());
} else {
_graph->set_argument_value_with_strides(desc.indexUsedByDriver,
@@ -229,7 +195,8 @@ Pipeline::Pipeline(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,
}
const auto& tensor = input_tensors.at(io_index).at(0);
- if (tensor->get_element_type().bitwidth() < 8 || tensor->is_continuous() || tensor->get_strides().empty()) {
+ if (!ov::util::can_compute_byte_strides(tensor->get_element_type(), tensor->get_shape()) ||
+ tensor->is_continuous() || tensor->get_strides().empty()) {
_graph->set_argument_value(
desc.indexUsedByDriver,
static_cast<unsigned char*>(tensor->data()) + (i * tensor->get_byte_size()) / _batch_size);
@@ -246,7 +213,8 @@ Pipeline::Pipeline(const std::shared_ptr<ZeroInitStructsHolder>& init_structs,
io_index = 0;
for (const auto& desc : _graph->get_metadata().outputs) {
const auto& tensor = output_tensors.at(io_index);
- if (tensor->get_element_type().bitwidth() < 8 || tensor->is_continuous() || tensor->get_strides().empty()) {
+ if (!ov::util::can_compute_byte_strides(tensor->get_element_type(), tensor->get_shape()) ||
+ tensor->is_continuous() || tensor->get_strides().empty()) {
_graph->set_argument_value(
desc.indexUsedByDriver,
static_cast<unsigned char*>(tensor->data()) + (i * tensor->get_byte_size()) / _batch_size);
@@ -392,7 +360,8 @@ void Pipeline::update_graph_arguments(uint32_t index,
const size_t number_of_command_lists = _command_lists.size();
for (size_t i = 0; i < number_of_command_lists; i++) {
- if (tensor->get_element_type().bitwidth() < 8 || tensor->is_continuous() || tensor->get_strides().empty()) {
+ if (!ov::util::can_compute_byte_strides(tensor->get_element_type(), tensor->get_shape()) ||
+ tensor->is_continuous() || tensor->get_strides().empty()) {
_command_lists.at(i)->updateMutableCommandList(index,
static_cast<const unsigned char*>(tensor->data()) +
(i * tensor->get_byte_size()) / number_of_command_lists);
@@ -418,7 +387,8 @@ void Pipeline::update_graph_arguments(uint32_t index,
"Command list index is higher than the number of Command lists ",
batch_index);
- if (tensor->get_element_type().bitwidth() < 8 || tensor->is_continuous() || tensor->get_strides().empty()) {
+ if (!ov::util::can_compute_byte_strides(tensor->get_element_type(), tensor->get_shape()) ||
+ tensor->is_continuous() || tensor->get_strides().empty()) {
_command_lists.at(batch_index)->updateMutableCommandList(index, tensor->data());
} else {
_command_lists.at(batch_index)
diff --git a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_utils.hpp b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_utils.hpp
index df9465d09a1..b725160a038 100644
--- a/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_utils.hpp
+++ b/src/plugins/intel_npu/src/utils/include/intel_npu/utils/zero/zero_utils.hpp
@@ -8,6 +8,7 @@
#include <limits.h>
#include <ze_graph_ext.h>
+#include <algorithm>
#include <cstring>
#include <optional>
#include <string>
@@ -17,6 +18,7 @@
#include "intel_npu/utils/logger/logger.hpp"
#include "intel_npu/utils/zero/zero_api.hpp"
#include "intel_npu/utils/zero/zero_result.hpp"
+#include "openvino/core/memory_util.hpp"
#include "zero_types.hpp"
namespace intel_npu {
@@ -199,13 +201,16 @@ std::optional<Type> extract_object(const ov::AnyMap& params, const ov::Property<
return ov::Any(itrHandle->second).as<Type>();
}
-static inline size_t get_capacity_size(const ov::Shape& shape, const ov::Strides& strides) {
+static inline size_t get_capacity_size(const ov::element::Type& type,
+ const ov::Shape& shape,
+ const ov::Strides& strides) {
+ const auto byte_shape = ov::util::get_byte_memory_shape(type, shape);
size_t capacity = 0;
const size_t rank = shape.size();
for (size_t i = 0; i < rank; ++i) {
if (i == rank - 1) {
// Last dimension: use shape[i] * stride[i]
- capacity += shape[i] * strides[i];
+ capacity += byte_shape[i] * strides[i];
} else {
// Other dimensions: use (shape[i] - 1) * stride[i]
capacity += (shape[i] - 1) * strides[i];
@@ -215,6 +220,31 @@ static inline size_t get_capacity_size(const ov::Shape& shape, const ov::Strides
return capacity;
}
+// Converts byte strides to element strides, accounting for sub-byte element types whose
+// innermost dimension byte stride is a non-addressable placeholder (element stride is always 1).
+static inline ov::Strides byte_strides_to_element_strides(const ov::Strides& byte_strides,
+ const ov::element::Type& type) {
+ const auto bitwidth = type.bitwidth();
+ OPENVINO_ASSERT(bitwidth != 0, "Element bitwidth must be greater than 0");
+
+ ov::Strides element_strides(byte_strides.size());
+ std::transform(byte_strides.begin(), byte_strides.end(), element_strides.begin(), [bitwidth](size_t byte_stride) {
+ OPENVINO_ASSERT((byte_stride * CHAR_BIT) % bitwidth == 0,
+ "Stride ",
+ byte_stride,
+ " bytes is not aligned to element bitwidth ",
+ bitwidth,
+ ". Strides must be whole-byte multiples of the element size.");
+ return byte_stride * CHAR_BIT / bitwidth;
+ });
+
+ if (!element_strides.empty() && bitwidth < CHAR_BIT) {
+ element_strides.back() = 1;
+ }
+
+ return element_strides;
+}
+
static inline uint32_t findCommandQueueGroupOrdinal(
ze_device_handle_t device_handle,
const ze_command_queue_group_property_flags_t command_queue_group_property) {
diff --git a/src/plugins/intel_npu/src/utils/src/vm/mem_ref_type.cpp b/src/plugins/intel_npu/src/utils/src/vm/mem_ref_type.cpp
index f402c9586e1..53aa6aae3ab 100644
--- a/src/plugins/intel_npu/src/utils/src/vm/mem_ref_type.cpp
+++ b/src/plugins/intel_npu/src/utils/src/vm/mem_ref_type.cpp
@@ -7,7 +7,9 @@
#include <sstream>
#include "intel_npu/utils/vm/npu_vm_runtime_api.hpp"
+#include "intel_npu/utils/zero/zero_utils.hpp"
#include "openvino/core/except.hpp"
+#include "openvino/core/memory_util.hpp"
namespace intel_npu {
@@ -73,13 +75,13 @@ void MemRefType::set(const void* arg, int64_t offset, std::shared_ptr<ov::ITenso
setArg(arg);
setOffset(offset);
setSize(tensor->get_shape());
- const auto& elementType = tensor->get_element_type();
- if (elementType.bitwidth() < 8) {
- // Packed sub-byte tensors have no byte strides, so contiguous element strides are derived from the shape
+ if (!ov::util::can_compute_byte_strides(tensor->get_element_type(), tensor->get_shape())) {
+ // Byte strides are not representable for this type/shape (e.g. an unaligned sub-byte row) -
+ // fall back to shape-derived contiguous element strides.
updateStride();
return;
}
- setStrides(tensor->get_strides(), static_cast<int32_t>(elementType.size()));
+ setStrides(zeroUtils::byte_strides_to_element_strides(tensor->get_strides(), tensor->get_element_type()), 1);
}
void MemRefType::updateStride() {
diff --git a/src/plugins/intel_npu/src/utils/src/zero/zero_remote_tensor.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_remote_tensor.cpp
index ed03cad91df..919dd16a4e1 100644
--- a/src/plugins/intel_npu/src/utils/src/zero/zero_remote_tensor.cpp
+++ b/src/plugins/intel_npu/src/utils/src/zero/zero_remote_tensor.cpp
@@ -33,7 +33,7 @@ void validate_src_roi_bounds(const ov::Shape& owner_shape,
OPENVINO_ASSERT(owner_shape.size() == roi_shape.size(), "ROI rank must match parent tensor rank");
size_t total_bytes = ov::util::get_memory_size(type, ov::shape_size(owner_shape));
- size_t roi_bytes = intel_npu::zeroUtils::get_capacity_size(roi_shape, owner_strides);
+ size_t roi_bytes = intel_npu::zeroUtils::get_capacity_size(type, roi_shape, owner_strides);
OPENVINO_ASSERT(offset + roi_bytes <= total_bytes,
"ROI with offset ",
@@ -264,19 +264,9 @@ void ZeroRemoteTensor::set_shape(ov::Shape new_shape) {
}
void ZeroRemoteTensor::update_strides() {
- if (_element_type.bitwidth() < 8) {
- return;
- }
-
auto& shape = get_shape();
- if (_strides.empty() && !shape.empty()) {
- _strides.resize(shape.size());
- _strides.back() = shape.back() == 0 ? 0 : _element_type.size();
- std::transform(shape.crbegin(),
- shape.crend() - 1,
- _strides.rbegin(),
- _strides.rbegin() + 1,
- std::multiplies<size_t>());
+ if (_strides.empty() && ov::util::can_compute_byte_strides(_element_type, shape)) {
+ _strides = ov::util::get_dense_byte_strides(_element_type, shape);
}
}
diff --git a/src/plugins/intel_npu/src/utils/src/zero/zero_tensor.cpp b/src/plugins/intel_npu/src/utils/src/zero/zero_tensor.cpp
index d3bcd024b81..416cc3688b5 100644
--- a/src/plugins/intel_npu/src/utils/src/zero/zero_tensor.cpp
+++ b/src/plugins/intel_npu/src/utils/src/zero/zero_tensor.cpp
@@ -60,7 +60,7 @@ ZeroTensor::ZeroTensor(const std::shared_ptr<ZeroInitStructsHolder>& init_struct
_user_tensor(user_tensor),
_element_type{_user_tensor->get_element_type()},
_shape{_user_tensor->get_shape()},
- _strides{_element_type.bitwidth() >= 8 ? _user_tensor->get_strides() : ov::Strides{}},
+ _strides{ov::util::can_compute_byte_strides(_element_type, _shape) ? _user_tensor->get_strides() : ov::Strides{}},
_strides_once{} {
OPENVINO_ASSERT(_element_type.is_static());
@@ -147,36 +147,26 @@ const ov::Shape& ZeroTensor::get_shape() const {
}
void ZeroTensor::update_strides() const {
- if (_element_type.bitwidth() < 8) {
- return;
- }
-
auto& shape = get_shape();
- if (_strides.empty() && !shape.empty()) {
- _strides.resize(shape.size());
- _strides.back() = shape.back() == 0 ? 0 : _element_type.size();
- std::transform(shape.crbegin(),
- shape.crend() - 1,
- _strides.rbegin(),
- _strides.rbegin() + 1,
- std::multiplies<size_t>());
+ if (_strides.empty() && ov::util::can_compute_byte_strides(_element_type, shape)) {
+ _strides = ov::util::get_dense_byte_strides(_element_type, shape);
}
}
size_t ZeroTensor::get_bytes_capacity() const {
size_t original_shape_size = ov::shape_size(_shape);
- if (_user_tensor == nullptr || _element_type.bitwidth() < 8 || original_shape_size == 0 || _shape.empty() ||
- _strides.empty()) {
+ if (_user_tensor == nullptr || !ov::util::can_compute_byte_strides(_element_type, _shape) ||
+ original_shape_size == 0 || _shape.empty() || _strides.empty()) {
return ov::util::get_memory_size(_element_type, original_shape_size);
}
- return intel_npu::zeroUtils::get_capacity_size(_shape, _strides);
+ return intel_npu::zeroUtils::get_capacity_size(_element_type, _shape, _strides);
}
const ov::Strides& ZeroTensor::get_strides() const {
- OPENVINO_ASSERT(_element_type.bitwidth() >= 8,
- "Could not get strides for types with bitwidths less than 8 bit. Tensor type: ",
+ OPENVINO_ASSERT(ov::util::can_compute_byte_strides(_element_type, _shape),
+ "Could not get strides for tensor type: ",
_element_type);
std::call_once(_strides_once, &ZeroTensor::update_strides, this);
diff --git a/src/plugins/intel_npu/tests/functional/internal/backend/zero_tensor_tests.cpp b/src/plugins/intel_npu/tests/functional/internal/backend/zero_tensor_tests.cpp
index 0e1419da8b8..49777c02f48 100644
--- a/src/plugins/intel_npu/tests/functional/internal/backend/zero_tensor_tests.cpp
+++ b/src/plugins/intel_npu/tests/functional/internal/backend/zero_tensor_tests.cpp
@@ -587,6 +587,36 @@ TEST_P(ZeroTensorTestsCheckDataType, CopyZeroTensorAndCheckTensorDataType) {
EXPECT_EQ(zero_tensor->get_element_type(), copy_zero_tensor->get_element_type());
}
+TEST_P(ZeroTensorTestsCheckDataType, WrapNonContiguousUserTensorPreservesByteStrides) {
+ SKIP_IF_CURRENT_TEST_IS_DISABLED()
+
+ constexpr size_t rows = 2;
+ constexpr size_t row_elements = 16;
+ const size_t inner_stride = element_type.bitwidth() < 8 ? 1 : element_type.size();
+ const size_t dense_row_bytes = row_elements * element_type.bitwidth() / 8;
+ const size_t padded_row_bytes = 2 * dense_row_bytes;
+
+ std::shared_ptr<::intel_npu::IEngineBackend> engine_backend = std::make_shared<::intel_npu::ZeroEngineBackend>();
+ auto zero_context = std::make_shared<::intel_npu::RemoteContextImpl>(engine_backend);
+
+ // Backing memory holds 'rows' padded rows, i.e. twice the dense size.
+ auto host_tensor =
+ std::make_shared<::intel_npu::ZeroHostTensor>(zero_context,
+ init_struct,
+ element_type,
+ Shape{2 * rows, row_elements});
+
+ const Shape shape{rows, row_elements};
+ const Strides strides{padded_row_bytes, inner_stride};
+ auto strided_tensor = make_tensor(element_type, shape, host_tensor->data(), strides);
+
+ std::shared_ptr<::intel_npu::ZeroTensor> zero_tensor;
+ ASSERT_NO_THROW(zero_tensor = std::make_shared<::intel_npu::ZeroTensor>(init_struct, strided_tensor));
+ EXPECT_EQ(shape, zero_tensor->get_shape());
+ EXPECT_EQ(strides, zero_tensor->get_strides());
+ EXPECT_EQ(host_tensor->data(), zero_tensor->data());
+}
+
} // namespace behavior
} // namespace test
} // namespace ov
diff --git a/src/plugins/intel_npu/tests/unit/CMakeLists.txt b/src/plugins/intel_npu/tests/unit/CMakeLists.txt
index c1576349326..b7db2f10c8e 100644
--- a/src/plugins/intel_npu/tests/unit/CMakeLists.txt
+++ b/src/plugins/intel_npu/tests/unit/CMakeLists.txt
@@ -187,6 +187,7 @@ target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/npu/state_tensor_binding_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npu/mem_ref_type_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npu/zero_extension_query_test.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/npu/zero_utils_strides_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_compiled_model_graph_options_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_compiled_model_set_property_test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/npuw/llm_4d_float_attention_mask_test.cpp
diff --git a/src/plugins/intel_npu/tests/unit/npu/mem_ref_type_test.cpp b/src/plugins/intel_npu/tests/unit/npu/mem_ref_type_test.cpp
index 60ab18de41a..c8bccc9ee7b 100644
--- a/src/plugins/intel_npu/tests/unit/npu/mem_ref_type_test.cpp
+++ b/src/plugins/intel_npu/tests/unit/npu/mem_ref_type_test.cpp
@@ -41,4 +41,32 @@ TEST(NpuMemRefStridedTensorTest, PreservesNonContiguousF16Strides) {
EXPECT_EQ(memref._data, storage.data());
}
+class NpuMemRefStridedSubByteTest : public testing::TestWithParam<ov::element::Type> {};
+
+TEST_P(NpuMemRefStridedSubByteTest, PreservesNonContiguousSubByteStrides) {
+ const auto type = GetParam();
+ constexpr size_t row_elements = 16;
+ const size_t dense_row_bytes = row_elements * type.bitwidth() / 8;
+ const size_t padded_row_bytes = 2 * dense_row_bytes;
+ std::vector<uint8_t> storage(2 * padded_row_bytes);
+
+ const auto tensor =
+ ov::make_tensor(type, ov::Shape{2, row_elements}, storage.data(), ov::Strides{padded_row_bytes, 1});
+
+ intel_npu::MemRefType memref;
+ ASSERT_NO_THROW(memref.set(tensor->data(), 0, tensor));
+ EXPECT_EQ(memref._sizes, (std::vector<int64_t>{2, static_cast<int64_t>(row_elements)}));
+ EXPECT_EQ(memref._strides, (std::vector<int64_t>{static_cast<int64_t>(padded_row_bytes * 8 / type.bitwidth()), 1}));
+ EXPECT_EQ(memref._data, storage.data());
+}
+
+INSTANTIATE_TEST_SUITE_P(HostCompile,
+ NpuMemRefStridedSubByteTest,
+ testing::Values(ov::element::u1,
+ ov::element::u2,
+ ov::element::u4,
+ ov::element::i4,
+ ov::element::nf4,
+ ov::element::f4e2m1));
+
} // namespace
diff --git a/src/plugins/intel_npu/tests/unit/npu/zero_utils_strides_test.cpp b/src/plugins/intel_npu/tests/unit/npu/zero_utils_strides_test.cpp
new file mode 100644
index 00000000000..592790bb288
--- /dev/null
+++ b/src/plugins/intel_npu/tests/unit/npu/zero_utils_strides_test.cpp
@@ -0,0 +1,51 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <gtest/gtest.h>
+
+#include "intel_npu/utils/zero/zero_utils.hpp"
+#include "openvino/core/except.hpp"
+
+namespace ov::test {
+
+using intel_npu::zeroUtils::byte_strides_to_element_strides, intel_npu::zeroUtils::get_capacity_size;
+
+TEST(ZeroUtilsStridesTest, ByteGranularTypeKeepsNonUnitInnermostStride) {
+ EXPECT_EQ(byte_strides_to_element_strides(ov::Strides{16, 4}, ov::element::f16), (ov::Strides{8, 2}));
+ EXPECT_EQ(byte_strides_to_element_strides(ov::Strides{24, 8, 4}, ov::element::f32), (ov::Strides{6, 2, 1}));
+ EXPECT_EQ(byte_strides_to_element_strides(ov::Strides{3, 1}, ov::element::u8), (ov::Strides{3, 1}));
+}
+
+TEST(ZeroUtilsStridesTest, SubByteTypeConvertsOuterStridesAndForcesInnermostToOne) {
+ EXPECT_EQ(byte_strides_to_element_strides(ov::Strides{8, 1}, ov::element::u4), (ov::Strides{16, 1}));
+ EXPECT_EQ(byte_strides_to_element_strides(ov::Strides{16, 8, 1}, ov::element::nf4), (ov::Strides{32, 16, 1}));
+ EXPECT_EQ(byte_strides_to_element_strides(ov::Strides{4, 1}, ov::element::u2), (ov::Strides{16, 1}));
+ EXPECT_EQ(byte_strides_to_element_strides(ov::Strides{2, 1}, ov::element::u1), (ov::Strides{16, 1}));
+ EXPECT_EQ(byte_strides_to_element_strides(ov::Strides{8, 1}, ov::element::f4e2m1), (ov::Strides{16, 1}));
+}
+
+TEST(ZeroUtilsStridesTest, EmptyStridesStayEmpty) {
+ EXPECT_TRUE(byte_strides_to_element_strides(ov::Strides{}, ov::element::u4).empty());
+ EXPECT_TRUE(byte_strides_to_element_strides(ov::Strides{}, ov::element::f32).empty());
+}
+
+TEST(ZeroUtilsStridesTest, ThrowsWhenStrideIsNotMultipleOfElementSize) {
+ EXPECT_THROW(byte_strides_to_element_strides(ov::Strides{6, 4}, ov::element::f32), ov::Exception);
+}
+
+TEST(ZeroUtilsStridesTest, CapacityOfByteGranularTensor) {
+ EXPECT_EQ(get_capacity_size(ov::element::f32, ov::Shape{2, 3}, ov::Strides{16, 4}), 28u);
+ EXPECT_EQ(get_capacity_size(ov::element::f32, ov::Shape{2, 3}, ov::Strides{12, 4}), 24u);
+}
+
+TEST(ZeroUtilsStridesTest, CapacityOfSubByteTensorUsesPackedLastDimension) {
+ // Dense u4 {2, 16}: 2 rows * 8 bytes.
+ EXPECT_EQ(get_capacity_size(ov::element::u4, ov::Shape{2, 16}, ov::Strides{8, 1}), 16u);
+ // Padded rows (16 bytes apart): one full padded row plus one packed row.
+ EXPECT_EQ(get_capacity_size(ov::element::u4, ov::Shape{2, 16}, ov::Strides{16, 1}), 24u);
+ EXPECT_EQ(get_capacity_size(ov::element::u1, ov::Shape{3, 16}, ov::Strides{4, 1}), 10u);
+ EXPECT_EQ(get_capacity_size(ov::element::u2, ov::Shape{2, 16}, ov::Strides{8, 1}), 12u);
+}
+
+} // namespace