Skip to content

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

Extend CPU Plugin with reference implementation of `SparseFillEmptyRows-16` (#30474)

Przemyslaw Wysocki4eda36bc7301
diff --git a/src/core/reference/include/openvino/reference/sparse_fill_empty_rows.hpp b/src/core/reference/include/openvino/reference/sparse_fill_empty_rows.hpp
index 37d2426204e..b1e78cd2116 100644
--- a/src/core/reference/include/openvino/reference/sparse_fill_empty_rows.hpp
+++ b/src/core/reference/include/openvino/reference/sparse_fill_empty_rows.hpp
@@ -17,7 +17,6 @@ void sparse_fill_empty_rows(const T* values,
const size_t values_size,
const T_IDX* dense_shape,
const T_IDX* indices,
- const size_t indices_size,
const T default_value,
T_IDX* output_indices,
T* output_values,
diff --git a/src/core/shape_inference/include/sparse_fill_empty_rows_shape_inference.hpp b/src/core/shape_inference/include/sparse_fill_empty_rows_shape_inference.hpp
index 3da16f1963b..c51f7643c38 100644
--- a/src/core/shape_inference/include/sparse_fill_empty_rows_shape_inference.hpp
+++ b/src/core/shape_inference/include/sparse_fill_empty_rows_shape_inference.hpp
@@ -16,7 +16,6 @@ std::vector<TRShape> shape_infer(const SparseFillEmptyRows* op,
const std::vector<TShape>& input_shapes,
const ITensorAccessor& tensor_accessor = make_tensor_accessor()) {
NODE_VALIDATION_CHECK(op, input_shapes.size() == 4);
-
const auto& values_shape = input_shapes[0];
NODE_SHAPE_INFER_CHECK(op,
input_shapes,
@@ -35,9 +34,10 @@ std::vector<TRShape> shape_infer(const SparseFillEmptyRows* op,
"The dense_shape input must be 1D and have exactly 2 elements, meaning only 2D sparse tensors are supported.");
const auto& indices_shape = input_shapes[2];
- const bool is_indices_shape_valid = indices_shape.rank().is_dynamic() ||
- (indices_shape.size() == 2 && indices_shape[1].compatible(2) &&
- (is_dense_shape_rank_dynamic || indices_shape[0].compatible(values_shape[0])));
+ const bool is_indices_shape_valid =
+ indices_shape.rank().is_dynamic() || (indices_shape.size() == 2 && indices_shape[1].compatible(2) &&
+ (is_dense_shape_rank_dynamic || values_shape.rank().is_dynamic() ||
+ indices_shape[0].compatible(values_shape[0])));
NODE_SHAPE_INFER_CHECK(op,
input_shapes,
is_indices_shape_valid,
@@ -61,10 +61,10 @@ std::vector<TRShape> shape_infer(const SparseFillEmptyRows* op,
empty_row_indicator_shape.resize(1);
output_indices_shape[1] = 2; // Only 2D cases are supported
- if (auto dense_shape_value = get_input_const_data_as_shape<TRShape>(op, 1, tensor_accessor)) {
+ if (auto dense_shape_value = get_input_const_data_as_shape<TRShape>(op, 1, tensor_accessor);
+ dense_shape_value && (*dense_shape_value).is_static()) {
const auto& number_of_rows = (*dense_shape_value)[0].get_length();
empty_row_indicator_shape[0] = number_of_rows;
-
if (auto indices_value = get_input_const_data_as<TRShape, int64_t>(op, 2, tensor_accessor)) {
auto is_valid_index = [](int64_t index, int64_t max_value) -> bool {
return index >= 0 && index < max_value;
diff --git a/src/core/src/op/sparse_fill_empty_rows.cpp b/src/core/src/op/sparse_fill_empty_rows.cpp
index d609ae5d305..87a9d2addad 100644
--- a/src/core/src/op/sparse_fill_empty_rows.cpp
+++ b/src/core/src/op/sparse_fill_empty_rows.cpp
@@ -23,16 +23,20 @@ void SparseFillEmptyRows::validate_and_infer_types() {
OV_OP_SCOPE(v16_SparseFillEmptyRows_validate_and_infer_types);
const auto& indices_element_type = get_input_element_type(2);
+ const auto& dense_shape_element_type = get_input_element_type(1);
+ element::Type merged_type;
+
NODE_VALIDATION_CHECK(this,
- indices_element_type == element::i32 || indices_element_type == element::i64,
- "The element type of the indices input must be i32 or i64. Got: ",
+ element::Type::merge(merged_type, indices_element_type, dense_shape_element_type),
+ "The element types of the dense_shape and indices inputs must match. Got: ",
+ dense_shape_element_type,
+ " and ",
indices_element_type);
- const auto& dense_shape_element_type = get_input_element_type(1);
NODE_VALIDATION_CHECK(this,
- dense_shape_element_type == element::i32 || dense_shape_element_type == element::i64,
- "The element type of the dense_shape input must be i32 or i64. Got: ",
- dense_shape_element_type);
+ merged_type == element::i32 || merged_type == element::i64,
+ "The element type of the indices and dense_shape inputs must be i32 or i64. Got: ",
+ merged_type);
const auto output_shapes = shape_infer(this, ov::util::get_node_input_partial_shapes(*this));
diff --git a/src/core/tests/type_prop/sparse_fill_empty_rows.cpp b/src/core/tests/type_prop/sparse_fill_empty_rows.cpp
index 57ad85efb42..b1ac83e5f7e 100644
--- a/src/core/tests/type_prop/sparse_fill_empty_rows.cpp
+++ b/src/core/tests/type_prop/sparse_fill_empty_rows.cpp
@@ -263,7 +263,7 @@ TEST_F(TypePropSparseFillEmptyRowsTest, invalid_indices_element_type) {
OV_EXPECT_THROW(std::ignore = make_op(values, dense_shape, indices, default_value),
ov::NodeValidationFailure,
- HasSubstr("The element type of the indices input must be i32 or i64"));
+ HasSubstr("The element types of the dense_shape and indices inputs must match"));
}
TEST_F(TypePropSparseFillEmptyRowsTest, invalid_dense_shape_element_type) {
@@ -274,7 +274,29 @@ TEST_F(TypePropSparseFillEmptyRowsTest, invalid_dense_shape_element_type) {
OV_EXPECT_THROW(std::ignore = make_op(values, dense_shape, indices, default_value),
ov::NodeValidationFailure,
- HasSubstr("The element type of the dense_shape input must be i32 or i64"));
+ HasSubstr("The element types of the dense_shape and indices inputs must match"));
+}
+
+TEST_F(TypePropSparseFillEmptyRowsTest, invalid_merged_type) {
+ const auto values = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{3});
+ const auto dense_shape = std::make_shared<op::v0::Parameter>(element::u32, PartialShape{2});
+ const auto indices = std::make_shared<op::v0::Parameter>(element::u32, PartialShape{3, 2});
+ const auto default_value = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{});
+
+ OV_EXPECT_THROW(std::ignore = make_op(values, dense_shape, indices, default_value),
+ ov::NodeValidationFailure,
+ HasSubstr("The element type of the indices and dense_shape inputs must be i32 or i64"));
+}
+
+TEST_F(TypePropSparseFillEmptyRowsTest, incompatible_indices_types) {
+ const auto values = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{3});
+ const auto dense_shape = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{2});
+ const auto indices = std::make_shared<op::v0::Parameter>(element::i64, PartialShape{3, 2});
+ const auto default_value = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{});
+
+ OV_EXPECT_THROW(std::ignore = make_op(values, dense_shape, indices, default_value),
+ ov::NodeValidationFailure,
+ HasSubstr("The element types of the dense_shape and indices inputs must match"));
}
TEST_F(TypePropSparseFillEmptyRowsTest, mismatch_values_and_indices_dimensions) {
diff --git a/src/plugins/intel_cpu/src/cpu_types.cpp b/src/plugins/intel_cpu/src/cpu_types.cpp
index 72dd21cfdd6..7b4a4a23bc1 100644
--- a/src/plugins/intel_cpu/src/cpu_types.cpp
+++ b/src/plugins/intel_cpu/src/cpu_types.cpp
@@ -111,6 +111,7 @@ static const TypeToNameMap& get_type_to_name_tbl() {
{"SpaceToBatch", Type::SpaceToBatch},
{"DepthToSpace", Type::DepthToSpace},
{"SpaceToDepth", Type::SpaceToDepth},
+ {"SparseFillEmptyRows", Type::SparseFillEmptyRows},
{"Roll", Type::Roll},
{"LRN", Type::Lrn},
{"Split", Type::Split},
@@ -309,6 +310,7 @@ std::string NameFromType(const Type type) {
CASE(Transpose);
CASE(SpaceToDepth);
CASE(SpaceToBatch);
+ CASE(SparseFillEmptyRows);
CASE(MemoryOutput);
CASE(MemoryInput);
CASE(RNNSeq);
diff --git a/src/plugins/intel_cpu/src/cpu_types.h b/src/plugins/intel_cpu/src/cpu_types.h
index 2a3527d666f..58e5d9c192f 100644
--- a/src/plugins/intel_cpu/src/cpu_types.h
+++ b/src/plugins/intel_cpu/src/cpu_types.h
@@ -51,6 +51,7 @@ enum class Type {
Transpose,
SpaceToBatch,
SpaceToDepth,
+ SparseFillEmptyRows,
StridedSlice,
MemoryOutput,
MemoryInput,
diff --git a/src/plugins/intel_cpu/src/nodes/sparse_fill_empty_rows.cpp b/src/plugins/intel_cpu/src/nodes/sparse_fill_empty_rows.cpp
new file mode 100644
index 00000000000..30abd5ad7f2
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/sparse_fill_empty_rows.cpp
@@ -0,0 +1,136 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "sparse_fill_empty_rows.h"
+
+#include "openvino/op/sparse_fill_empty_rows.hpp"
+#include "openvino/reference/sparse_fill_empty_rows.hpp"
+
+namespace ov::intel_cpu::node {
+SparseFillEmptyRows::SparseFillEmptyRows(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr& context)
+ : Node(op, context, NgraphShapeInferFactory(op)) {
+ std::string errorMessage;
+ if (!isSupportedOperation(op, errorMessage)) {
+ OPENVINO_THROW_NOT_IMPLEMENTED(errorMessage);
+ }
+}
+
+bool SparseFillEmptyRows::isSupportedOperation(const std::shared_ptr<const ov::Node>& op,
+ std::string& errorMessage) noexcept {
+ try {
+ if (!ov::is_type<ov::op::v16::SparseFillEmptyRows>(op)) {
+ errorMessage = "Only opset16 SparseFillEmptyRows operation is supported";
+ return false;
+ }
+ } catch (...) {
+ return false;
+ }
+ return true;
+}
+
+void SparseFillEmptyRows::getSupportedDescriptors() {
+ // Validation is already done in the ov::opset16::SparseFillEmptyRows
+}
+
+void SparseFillEmptyRows::initSupportedPrimitiveDescriptors() {
+ if (!supportedPrimitiveDescriptors.empty()) {
+ return;
+ }
+ const auto& valuesPrecision = getOriginalInputPrecisionAtPort(0);
+ const auto& indicesPrecision = getOriginalInputPrecisionAtPort(2);
+ addSupportedPrimDesc({{LayoutType::ncsp, valuesPrecision}, // values
+ {LayoutType::ncsp, indicesPrecision}, // dense_shape
+ {LayoutType::ncsp, indicesPrecision}, // indices
+ {LayoutType::ncsp, valuesPrecision}}, // default_value
+ {{LayoutType::ncsp, indicesPrecision}, // output_indices
+ {LayoutType::ncsp, valuesPrecision}, // output_values
+ {LayoutType::ncsp, ov::element::boolean}}, // empty_row_indicator
+ impl_desc_type::ref);
+}
+
+bool SparseFillEmptyRows::created() const {
+ return getType() == Type::SparseFillEmptyRows;
+}
+
+bool SparseFillEmptyRows::needPrepareParams() const {
+ return false;
+}
+
+bool SparseFillEmptyRows::isExecutable() const {
+ return !isInputTensorAtPortEmpty(1) && !isInputTensorAtPortEmpty(3);
+}
+
+void SparseFillEmptyRows::executeDynamicImpl(const dnnl::stream& strm) {
+ const auto& valuesMemory = getSrcMemoryAtPort(0);
+ const auto& indicesMemory = getSrcMemoryAtPort(2);
+ const auto& valuesShape = valuesMemory->getShape();
+ const auto& indicesShape = indicesMemory->getShape();
+
+ const auto* denseShapePtr = getSrcDataAtPortAs<const int32_t>(1);
+ const auto numRows = static_cast<size_t>(denseShapePtr[0]);
+
+ std::unordered_set<int32_t> existingRows;
+ size_t indicesCount = indicesShape.getElementsCount() / 2; // Divide by 2 because indices is [M, 2]
+
+ const auto* indicesPtr = getSrcDataAtPortAs<const int32_t>(2);
+ for (size_t i = 0; i < indicesCount; i++) {
+ existingRows.insert(indicesPtr[i * 2]);
+ }
+
+ size_t emptyRowsCount = numRows - existingRows.size();
+ size_t valuesCount = valuesShape.getElementsCount();
+ ov::Shape outputIndicesShape{valuesCount + emptyRowsCount, 2};
+ ov::Shape outputValuesShape{valuesCount + emptyRowsCount};
+ ov::Shape emptyRowIndicatorShape{numRows};
+
+ redefineOutputMemory({outputIndicesShape, outputValuesShape, emptyRowIndicatorShape});
+ execute(strm);
+}
+
+namespace {
+struct SparseFillEmptyRowsContext {
+ SparseFillEmptyRows& node;
+};
+} // namespace
+
+template <typename T>
+void SparseFillEmptyRows::executeImpl() {
+ ov::reference::sparse_fill_empty_rows(getSrcDataAtPortAs<const T>(0), // values
+ getSrcMemoryAtPort(0)->getShape().getElementsCount(), // values_size
+ getSrcDataAtPortAs<const int32_t>(1), // dense_shape
+ getSrcDataAtPortAs<const int32_t>(2), // indices
+ *getSrcDataAtPortAs<const T>(3), // default_value
+ getDstDataAtPortAs<int32_t>(0), // output_indices
+ getDstDataAtPortAs<T>(1), // output_values
+ getDstDataAtPortAs<bool>(2)); // empty_row_indicator
+}
+
+template <typename T>
+struct SparseFillEmptyRows::SparseFillEmptyRowsExecute {
+ void operator()(SparseFillEmptyRowsContext& ctx) {
+ auto indicesPrecision = ctx.node.getParentEdgeAt(2)->getMemory().getDesc().getPrecision();
+ if (indicesPrecision == ov::element::i32) {
+ ctx.node.executeImpl<T>();
+ } else {
+ OPENVINO_THROW("SparseFillEmptyRows operation supports only i32 indices precision");
+ }
+ }
+};
+
+void SparseFillEmptyRows::execute([[maybe_unused]] const dnnl::stream& strm) {
+ auto valuesPrecision = getParentEdgeAt(0)->getMemory().getDesc().getPrecision();
+ SparseFillEmptyRowsContext ctx = {*this};
+ OV_SWITCH(intel_cpu,
+ SparseFillEmptyRowsExecute,
+ ctx,
+ valuesPrecision,
+ OV_CASE(ov::element::f32, float),
+ OV_CASE(ov::element::f16, ov::float16),
+ OV_CASE(ov::element::bf16, ov::bfloat16),
+ OV_CASE(ov::element::i8, int8_t),
+ OV_CASE(ov::element::u8, uint8_t),
+ OV_CASE(ov::element::i32, int32_t),
+ OV_CASE(ov::element::i64, int64_t))
+}
+} // namespace ov::intel_cpu::node
diff --git a/src/plugins/intel_cpu/src/nodes/sparse_fill_empty_rows.h b/src/plugins/intel_cpu/src/nodes/sparse_fill_empty_rows.h
new file mode 100644
index 00000000000..e23c85cd757
--- /dev/null
+++ b/src/plugins/intel_cpu/src/nodes/sparse_fill_empty_rows.h
@@ -0,0 +1,33 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <node.h>
+
+namespace ov::intel_cpu::node {
+
+class SparseFillEmptyRows : public Node {
+public:
+ SparseFillEmptyRows(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr& context);
+
+ static bool isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::string& errorMessage) noexcept;
+
+ void getSupportedDescriptors() override;
+ void initSupportedPrimitiveDescriptors() override;
+ bool created() const override;
+ bool needPrepareParams() const override;
+ bool isExecutable() const override;
+ void executeDynamicImpl(const dnnl::stream& strm) override;
+ void execute(const dnnl::stream& strm) override;
+
+private:
+ template <typename T>
+ void executeImpl();
+
+ template <typename T>
+ struct SparseFillEmptyRowsExecute;
+};
+
+} // namespace ov::intel_cpu::node
diff --git a/src/plugins/intel_cpu/src/nodes_factory.cpp b/src/plugins/intel_cpu/src/nodes_factory.cpp
index 026c93d3f1f..c4e9acf6f69 100644
--- a/src/plugins/intel_cpu/src/nodes_factory.cpp
+++ b/src/plugins/intel_cpu/src/nodes_factory.cpp
@@ -99,6 +99,7 @@
#include "nodes/softmax.h"
#include "nodes/space_to_batch.h"
#include "nodes/space_to_depth.h"
+#include "nodes/sparse_fill_empty_rows.h"
#include "nodes/split.h"
#include "nodes/stft.h"
#include "nodes/strided_slice.h"
@@ -125,6 +126,7 @@ Node::NodesFactory::NodesFactory() : Factory("NodesFactory") {
INTEL_CPU_NODE(BatchToSpace, Type::BatchToSpace);
INTEL_CPU_NODE(DepthToSpace, Type::DepthToSpace);
INTEL_CPU_NODE(SpaceToDepth, Type::SpaceToDepth);
+ INTEL_CPU_NODE(SparseFillEmptyRows, Type::SparseFillEmptyRows);
INTEL_CPU_NODE(If, Type::If);
INTEL_CPU_NODE(Broadcast, Type::Broadcast);
INTEL_CPU_NODE(ExperimentalDetectronTopKROIs, Type::ExperimentalDetectronTopKROIs);
diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/sparse_fill_empty_rows.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/sparse_fill_empty_rows.cpp
new file mode 100644
index 00000000000..d94d8f5ddea
--- /dev/null
+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/sparse_fill_empty_rows.cpp
@@ -0,0 +1,218 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "sparse_fill_empty_rows.hpp"
+#include "utils/cpu_test_utils.hpp"
+#include "common_test_utils/ov_tensor_utils.hpp"
+#include "shared_test_classes/base/ov_subgraph.hpp"
+#include "utils/precision_support.h"
+#include "openvino/op/sparse_fill_empty_rows.hpp"
+
+using namespace CPUTestUtils;
+
+namespace ov::test::SparseFillEmptyRows {
+
+std::string SparseFillEmptyRowsLayerCPUTest::getTestCaseName(testing::TestParamInfo<SparseFillEmptyRowsLayerCPUTestParamsSet> obj) {
+ SparseFillEmptyRowsLayerTestParams basicParamsSet;
+ CPUSpecificParams cpuParams;
+ SparseFillEmptyRowsSpecificParams sparseFillEmptyRowsPar;
+ std::tie(basicParamsSet, cpuParams) = obj.param;
+ std::string td;
+ ElementType valuesPrecision;
+ ElementType indicesPrecision;
+ ov::test::utils::InputLayerType secondaryInputType;
+ std::tie(sparseFillEmptyRowsPar, valuesPrecision, indicesPrecision, secondaryInputType, td) = basicParamsSet;
+
+ InputShape valuesShape;
+ InputShape indicesShape;
+ std::vector<int64_t> denseShapeValues;
+ int64_t defaultValue;
+ std::tie(valuesShape, indicesShape, denseShapeValues, defaultValue) = sparseFillEmptyRowsPar;
+ std::ostringstream result;
+
+ result << "valuesShape=" << ov::test::utils::partialShape2str({valuesShape.first}) << "_";
+ result << "valuesTS=";
+ result << "(";
+ for (const auto& targetShape : valuesShape.second) {
+ result << ov::test::utils::vec2str(targetShape);
+ }
+ result << ")";
+
+ result << "_indicesShape=" << ov::test::utils::partialShape2str({indicesShape.first}) << "_";
+ result << "indicesTS=";
+ result << "(";
+ for (const auto& targetShape : indicesShape.second) {
+ result << ov::test::utils::vec2str(targetShape);
+ }
+ result << ")";
+
+ result << "_denseShape=" << ov::test::utils::vec2str(denseShapeValues);
+ result << "_defaultValue=" << defaultValue;
+ result << "_valuesPrecision=" << valuesPrecision;
+ result << "_indicesPrecision=" << indicesPrecision;
+ result << "_secondaryInputType=" << secondaryInputType;
+ result << CPUTestsBase::getTestCaseName(cpuParams);
+
+ return result.str();
+}
+
+void SparseFillEmptyRowsLayerCPUTest::generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) {
+ inputs.clear();
+ const auto& funcInputs = function->inputs();
+ const auto secondaryInputType = std::get<3>(std::get<0>(this->GetParam()));
+
+ if (secondaryInputType == ov::test::utils::InputLayerType::CONSTANT) {
+ const auto valuesPrecision = funcInputs[0].get_element_type();
+ const auto& valuesShape = targetInputStaticShapes[0];
+ ov::test::utils::InputGenerateData valuesData;
+ valuesData.start_from = 1;
+ valuesData.range = 10;
+ const auto valuesTensor = ov::test::utils::create_and_fill_tensor(valuesPrecision, valuesShape, valuesData);
+ inputs.insert({funcInputs[0].get_node_shared_ptr(), valuesTensor});
+
+ const auto indicesPrecision = funcInputs[1].get_element_type();
+ ov::Shape indicesShape = {valuesShape[0], 2};
+ ov::test::utils::InputGenerateData indicesData;
+ indicesData.start_from = 0;
+ indicesData.range = 5;
+ const auto indicesTensor = ov::test::utils::create_and_fill_tensor(indicesPrecision, indicesShape, indicesData);
+ inputs.insert({funcInputs[1].get_node_shared_ptr(), indicesTensor});
+
+ } else {
+ const auto valuesPrecision = funcInputs[0].get_element_type();
+ const auto& valuesShape = targetInputStaticShapes[0];
+ ov::test::utils::InputGenerateData valuesData;
+ valuesData.start_from = 1;
+ valuesData.range = 10;
+ const auto valuesTensor = ov::test::utils::create_and_fill_tensor(valuesPrecision, valuesShape, valuesData);
+ inputs.insert({funcInputs[0].get_node_shared_ptr(), valuesTensor});
+
+ const auto indicesPrecision = funcInputs[2].get_element_type();
+ const auto& denseShapeShape = targetInputStaticShapes[1]; // {2}
+
+ const auto& denseShapeValues = std::get<2>(std::get<0>(std::get<0>(this->GetParam())));
+ auto denseShapeTensor = ov::Tensor(indicesPrecision, denseShapeShape);
+ if (indicesPrecision == ov::element::i32) {
+ auto* data_ptr = denseShapeTensor.data<int32_t>();
+ for (size_t i = 0; i < denseShapeValues.size(); i++) {
+ data_ptr[i] = static_cast<int32_t>(denseShapeValues[i]);
+ }
+ } else {
+ auto* data_ptr = denseShapeTensor.data<int64_t>();
+ for (size_t i = 0; i < denseShapeValues.size(); i++) {
+ data_ptr[i] = denseShapeValues[i];
+ }
+ }
+ inputs.insert({funcInputs[1].get_node_shared_ptr(), denseShapeTensor});
+
+ ov::Shape indicesShape = {valuesShape[0], 2};
+ ov::test::utils::InputGenerateData indicesData;
+ indicesData.start_from = 0;
+ indicesData.range = 5;
+ const auto indicesTensor = ov::test::utils::create_and_fill_tensor(indicesPrecision, indicesShape, indicesData);
+ inputs.insert({funcInputs[2].get_node_shared_ptr(), indicesTensor});
+
+ const auto defaultValue = std::get<3>(std::get<0>(std::get<0>(this->GetParam())));
+ const auto defaultValueTensor = ov::test::utils::create_and_fill_tensor(valuesPrecision, {}, defaultValue);
+ inputs.insert({funcInputs[3].get_node_shared_ptr(), defaultValueTensor});
+ }
+}
+
+void SparseFillEmptyRowsLayerCPUTest::SetUp() {
+ SparseFillEmptyRowsLayerTestParams basicParamsSet;
+ CPUSpecificParams cpuParams;
+ std::tie(basicParamsSet, cpuParams) = this->GetParam();
+ std::tie(inFmts, outFmts, priority, selectedType) = cpuParams;
+
+ SparseFillEmptyRowsSpecificParams sparseFillEmptyRowsParams;
+ ElementType valuesPrecision;
+ ElementType indicesPrecision;
+ ov::test::utils::InputLayerType secondaryInputType;
+ std::tie(sparseFillEmptyRowsParams, valuesPrecision, indicesPrecision, secondaryInputType, targetDevice) = basicParamsSet;
+
+ InputShape valuesShape;
+ InputShape indicesShape;
+ std::vector<int64_t> denseShapeValues;
+ int64_t defaultValue;
+ std::tie(valuesShape, indicesShape, denseShapeValues, defaultValue) = sparseFillEmptyRowsParams;
+
+ std::vector<ov::test::InputShape> input_shapes = {
+ valuesShape,
+ {ov::PartialShape{static_cast<ov::Dimension::value_type>(denseShapeValues.size())},
+ std::vector<ov::Shape>{ov::Shape{static_cast<size_t>(denseShapeValues.size())}}},
+ indicesShape,
+ {ov::PartialShape{}, std::vector<ov::Shape>{ov::Shape{}}}
+ };
+ init_input_shapes(input_shapes);
+
+ auto valuesParameter = std::make_shared<ov::op::v0::Parameter>(valuesPrecision, inputDynamicShapes[0]);
+ auto indicesParameter = std::make_shared<ov::op::v0::Parameter>(indicesPrecision, inputDynamicShapes[2]);
+ ov::ParameterVector params{ valuesParameter };
+ std::shared_ptr<ov::Node> sparseFillEmptyRows;
+ if (secondaryInputType == ov::test::utils::InputLayerType::CONSTANT) {
+ params.push_back(indicesParameter);
+ auto denseShapeConst = std::make_shared<ov::op::v0::Constant>(
+ indicesPrecision, ov::Shape{denseShapeValues.size()}, denseShapeValues);
+ auto defaultValueConst = std::make_shared<ov::op::v0::Constant>(
+ valuesPrecision, ov::Shape{}, defaultValue);
+ sparseFillEmptyRows = std::make_shared<ov::op::v16::SparseFillEmptyRows>(
+ valuesParameter, denseShapeConst, indicesParameter, defaultValueConst);
+ } else {
+ auto denseShapeParameter = std::make_shared<ov::op::v0::Parameter>(indicesPrecision, inputDynamicShapes[1]);
+ auto defaultValueParameter = std::make_shared<ov::op::v0::Parameter>(valuesPrecision, inputDynamicShapes[3]);
+ params.push_back(denseShapeParameter);
+ params.push_back(indicesParameter);
+ params.push_back(defaultValueParameter);
+ sparseFillEmptyRows = std::make_shared<ov::op::v16::SparseFillEmptyRows>(
+ valuesParameter, denseShapeParameter, indicesParameter, defaultValueParameter);
+ }
+ function = makeNgraphFunction(valuesPrecision, params, sparseFillEmptyRows, "SparseFillEmptyRows");
+}
+
+TEST_P(SparseFillEmptyRowsLayerCPUTest, CompareWithRefs) {
+ run();
+ CheckPluginRelatedResults(compiledModel, "SparseFillEmptyRows");
+}
+
+const std::vector<ov::test::utils::InputLayerType> secondaryInputTypes = {
+ ov::test::utils::InputLayerType::CONSTANT,
+ ov::test::utils::InputLayerType::PARAMETER
+};
+
+const std::vector<ElementType> indicesPrecisions = {
+ ov::element::i32,
+ ov::element::i64
+};
+
+const std::vector<SparseFillEmptyRowsSpecificParams> SparseFillEmptyRowsParamsVector = {
+ // Basic example
+ SparseFillEmptyRowsSpecificParams {
+ InputShape{{}, {{6}}}, // values shape
+ InputShape{{}, {{6, 2}}}, // indices shape
+ std::vector<int64_t>{10, 10}, // dense_shape
+ 1 // default_value
+ },
+ // Dynamic values shape, sequential inference
+ SparseFillEmptyRowsSpecificParams {
+ InputShape{{-1}, {{3}, {5}, {8}}}, // values shape
+ InputShape{{-1, 2}, {{3, 2}, {5, 2}, {8, 2}}}, // indices shape
+ std::vector<int64_t>{10, 5}, // dense_shape
+ 0 // default_value
+ },
+ // Empty values and indices tensors
+ SparseFillEmptyRowsSpecificParams {
+ InputShape{{}, {{0}}}, // values shape
+ InputShape{{}, {{0, 2}}}, // indices shape
+ std::vector<int64_t>{5, 5}, // dense_shape
+ 99 // default_value
+ },
+ // Different dense_shape
+ SparseFillEmptyRowsSpecificParams {
+ InputShape{{}, {{10}}}, // values shape
+ InputShape{{}, {{10, 2}}}, // indices shape
+ std::vector<int64_t>{20, 30}, // dense_shape
+ 7 // default_value
+ },
+};
+} // namespace ov::test::SparseFillEmptyRows
diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/sparse_fill_empty_rows.hpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/sparse_fill_empty_rows.hpp
new file mode 100644
index 00000000000..ca4fc19fc7f
--- /dev/null
+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/classes/sparse_fill_empty_rows.hpp
@@ -0,0 +1,47 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "shared_test_classes/base/ov_subgraph.hpp"
+#include "common_test_utils/ov_tensor_utils.hpp"
+#include "utils/fusing_test_utils.hpp"
+#include "utils/cpu_test_utils.hpp"
+#include "gtest/gtest.h"
+
+namespace ov::test::SparseFillEmptyRows {
+
+using SparseFillEmptyRowsSpecificParams = std::tuple<
+ InputShape, // values shape
+ InputShape, // indices shape
+ std::vector<int64_t>, // dense_shape values
+ int64_t // default_value
+>;
+
+using SparseFillEmptyRowsLayerTestParams = std::tuple<
+ SparseFillEmptyRowsSpecificParams,
+ ElementType, // values precision
+ ElementType, // indices precision
+ ov::test::utils::InputLayerType, // secondary input type (constant or parameter)
+ ov::test::TargetDevice
+>;
+
+using SparseFillEmptyRowsLayerCPUTestParamsSet = std::tuple<
+ SparseFillEmptyRowsLayerTestParams,
+ CPUTestUtils::CPUSpecificParams>;
+
+class SparseFillEmptyRowsLayerCPUTest : public testing::WithParamInterface<SparseFillEmptyRowsLayerCPUTestParamsSet>,
+ public SubgraphBaseTest, public CPUTestUtils::CPUTestsBase {
+public:
+ static std::string getTestCaseName(testing::TestParamInfo<SparseFillEmptyRowsLayerCPUTestParamsSet> obj);
+protected:
+ void SetUp() override;
+ void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override;
+};
+
+extern const std::vector<SparseFillEmptyRowsSpecificParams> SparseFillEmptyRowsParamsVector;
+extern const std::vector<ov::test::utils::InputLayerType> secondaryInputTypes;
+extern const std::vector<ElementType> indicesPrecisions;
+
+} // namespace ov::test::SparseFillEmptyRows
diff --git a/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/common/sparse_fill_empty_rows.cpp b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/common/sparse_fill_empty_rows.cpp
new file mode 100644
index 00000000000..2cff0ce06b7
--- /dev/null
+++ b/src/plugins/intel_cpu/tests/functional/custom/single_layer_tests/instances/common/sparse_fill_empty_rows.cpp
@@ -0,0 +1,78 @@
+// Copyright (C) 2018-2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "custom/single_layer_tests/classes/sparse_fill_empty_rows.hpp"
+#include "utils/cpu_test_utils.hpp"
+#include "utils/fusing_test_utils.hpp"
+
+using namespace CPUTestUtils;
+
+namespace ov::test::SparseFillEmptyRows {
+INSTANTIATE_TEST_SUITE_P(smoke_SparseFillEmptyRowsF32I32, SparseFillEmptyRowsLayerCPUTest,
+ ::testing::Combine(
+ ::testing::Combine(
+ ::testing::ValuesIn(SparseFillEmptyRowsParamsVector),
+ ::testing::ValuesIn(std::vector<ElementType>{ElementType::f32, ElementType::f16}),
+ ::testing::Values(ElementType::i32),
+ ::testing::ValuesIn(secondaryInputTypes),
+ ::testing::Values(ov::test::utils::DEVICE_CPU)),
+ ::testing::Values(CPUSpecificParams{{}, {}, {}, "ref_f32"})),
+ SparseFillEmptyRowsLayerCPUTest::getTestCaseName);
+
+INSTANTIATE_TEST_SUITE_P(smoke_SparseFillEmptyRowsI32I32, SparseFillEmptyRowsLayerCPUTest,
+ ::testing::Combine(
+ ::testing::Combine(
+ ::testing::ValuesIn(SparseFillEmptyRowsParamsVector),
+ ::testing::Values(ElementType::i32),
+ ::testing::Values(ElementType::i32),
+ ::testing::ValuesIn(secondaryInputTypes),
+ ::testing::Values(ov::test::utils::DEVICE_CPU)),
+ ::testing::Values(CPUSpecificParams{{}, {}, {}, "ref_i32"})),
+ SparseFillEmptyRowsLayerCPUTest::getTestCaseName);
+
+INSTANTIATE_TEST_SUITE_P(smoke_SparseFillEmptyRowsUI8I32, SparseFillEmptyRowsLayerCPUTest,
+ ::testing::Combine(
+ ::testing::Combine(
+ ::testing::ValuesIn(SparseFillEmptyRowsParamsVector),
+ ::testing::Values(ElementType::u8, ElementType::i8),
+ ::testing::Values(ElementType::i32),
+ ::testing::ValuesIn(secondaryInputTypes),
+ ::testing::Values(ov::test::utils::DEVICE_CPU)),
+ ::testing::Values(CPUSpecificParams{{}, {}, {}, "ref_i8"})),
+ SparseFillEmptyRowsLayerCPUTest::getTestCaseName);
+
+INSTANTIATE_TEST_SUITE_P(smoke_SparseFillEmptyRowsF32I64, SparseFillEmptyRowsLayerCPUTest,
+ ::testing::Combine(
+ ::testing::Combine(
+ ::testing::ValuesIn(SparseFillEmptyRowsParamsVector),
+ ::testing::ValuesIn(std::vector<ElementType>{ElementType::f32, ElementType::f16}),
+ ::testing::Values(ElementType::i64),
+ ::testing::ValuesIn(secondaryInputTypes),
+ ::testing::Values(ov::test::utils::DEVICE_CPU)),
+ ::testing::Values(CPUSpecificParams{{}, {}, {}, "ref_f32"})),
+ SparseFillEmptyRowsLayerCPUTest::getTestCaseName);
+
+INSTANTIATE_TEST_SUITE_P(smoke_SparseFillEmptyRowsI32I64, SparseFillEmptyRowsLayerCPUTest,
+ ::testing::Combine(
+ ::testing::Combine(
+ ::testing::ValuesIn(SparseFillEmptyRowsParamsVector),
+ ::testing::Values(ElementType::i32),
+ ::testing::Values(ElementType::i64),
+ ::testing::ValuesIn(secondaryInputTypes),
+ ::testing::Values(ov::test::utils::DEVICE_CPU)),
+ ::testing::Values(CPUSpecificParams{{}, {}, {}, "ref_i32"})),
+ SparseFillEmptyRowsLayerCPUTest::getTestCaseName);
+
+INSTANTIATE_TEST_SUITE_P(smoke_SparseFillEmptyRowsUI8I64, SparseFillEmptyRowsLayerCPUTest,
+ ::testing::Combine(
+ ::testing::Combine(
+ ::testing::ValuesIn(SparseFillEmptyRowsParamsVector),
+ ::testing::Values(ElementType::u8, ElementType::i8),
+ ::testing::Values(ElementType::i64),
+ ::testing::ValuesIn(secondaryInputTypes),
+ ::testing::Values(ov::test::utils::DEVICE_CPU)),
+ ::testing::Values(CPUSpecificParams{{}, {}, {}, "ref_i8"})),
+ SparseFillEmptyRowsLayerCPUTest::getTestCaseName);
+
+} // namespace ov::test::SparseFillEmptyRows
diff --git a/src/plugins/template/backend/ops/sparse_fill_empty_rows.cpp b/src/plugins/template/backend/ops/sparse_fill_empty_rows.cpp
index 3b9ad2b9263..a4c6493f714 100644
--- a/src/plugins/template/backend/ops/sparse_fill_empty_rows.cpp
+++ b/src/plugins/template/backend/ops/sparse_fill_empty_rows.cpp
@@ -37,13 +37,11 @@ bool evaluate_index_type(const std::shared_ptr<ov::op::v16::SparseFillEmptyRows>
bool* empty_row_indicator = outputs[2].data<bool>();
const size_t values_size = inputs[0].get_shape()[0];
- const size_t indices_size = ov::shape_size(inputs[2].get_shape());
ov::reference::sparse_fill_empty_rows(values,
values_size,
dense_shape,
indices,
- indices_size,
default_value,
output_indices,
output_values,
diff --git a/src/plugins/template/tests/functional/op_reference/sparse_fill_empty_rows.cpp b/src/plugins/template/tests/functional/op_reference/sparse_fill_empty_rows.cpp
index 9418ae28f29..55221e10d06 100644
--- a/src/plugins/template/tests/functional/op_reference/sparse_fill_empty_rows.cpp
+++ b/src/plugins/template/tests/functional/op_reference/sparse_fill_empty_rows.cpp
@@ -67,7 +67,6 @@ public:
private:
static std::shared_ptr<ov::Model> CreateFunction(const SparseFillEmptyRowsParams& params) {
- using ov::op::v0::Constant;
using ov::op::v0::Parameter;
const auto values = std::make_shared<Parameter>(params.valuesTensor.type, params.valuesTensor.shape);