OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[GPU] Enable shape agnostic kernel execution to `SparseFillEmptyRows` (#31992)
Przemyslaw Wysockica081995aad1
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/sparse_fill_empty_rows.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/sparse_fill_empty_rows.cppindex 31f710ac383..5be0cba5900 100644--- a/src/plugins/intel_gpu/src/graph/impls/ocl/sparse_fill_empty_rows.cpp+++ b/src/plugins/intel_gpu/src/graph/impls/ocl/sparse_fill_empty_rows.cpp@@ -54,7 +54,7 @@ attach_sparse_fill_empty_rows_impl::attach_sparse_fill_empty_rows_impl() {auto formats = {format::bfyx};implementation_map<sparse_fill_empty_rows>::add(impl_types::ocl,- shape_types::static_shape,+ shape_types::any,typed_primitive_impl_ocl<sparse_fill_empty_rows>::create<sparse_fill_empty_rows_impl>,types,formats);diff --git a/src/plugins/intel_gpu/src/graph/registry/registry.hpp b/src/plugins/intel_gpu/src/graph/registry/registry.hppindex 5b779a245ef..341503a2322 100644--- a/src/plugins/intel_gpu/src/graph/registry/registry.hpp+++ b/src/plugins/intel_gpu/src/graph/registry/registry.hpp@@ -232,4 +232,4 @@ REGISTER_DEFAULT_IMPLS(unique_gather, OCL_S, OCL_D);REGISTER_DEFAULT_IMPLS(search_sorted, OCL_S, OCL_D);REGISTER_DEFAULT_IMPLS(STFT, OCL_S, OCL_D);REGISTER_DEFAULT_IMPLS(ISTFT, OCL_S, OCL_D);-REGISTER_DEFAULT_IMPLS(sparse_fill_empty_rows, OCL_S);+REGISTER_DEFAULT_IMPLS(sparse_fill_empty_rows, OCL_S, OCL_D);diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/sparse_fill_empty_rows_ref.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/sparse_fill_empty_rows_ref.clindex 587f4e97723..cb20fee9509 100644--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/sparse_fill_empty_rows_ref.cl+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/sparse_fill_empty_rows_ref.cl@@ -14,6 +14,7 @@ inline bool FUNC(row_exists)(const __global INPUT2_TYPE* restrict indices, uint}KERNEL(sparse_fill_empty_rows_ref)(+ OPTIONAL_SHAPE_INFO_ARGconst __global INPUT0_TYPE* restrict values, // [N] - values at specified indicesconst __global INPUT1_TYPE* restrict _unused, // [2] - shape of the dense tensor (rows, cols)const __global INPUT2_TYPE* restrict indices, // [N, 2] - indices (row, col) coordinates@@ -22,7 +23,7 @@ KERNEL(sparse_fill_empty_rows_ref)(__global OUTPUT1_TYPE* restrict output_values, // [M] - output values__global OUTPUT2_TYPE* restrict empty_row_indicator // [dense_shape[0]] - indicator if row was empty) {- const uint indices_count = INDICES_COUNT; // JIT constant for N+ const uint indices_count = INPUT2_BATCH_NUM;const uint row_idx = get_global_id(0);uint output_base_pos = 0;diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/sparse_fill_empty_rows/sparse_fill_empty_rows_kernel_ref.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/sparse_fill_empty_rows/sparse_fill_empty_rows_kernel_ref.cppindex 1d0a70cb2d9..b1b696cce8b 100644--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/sparse_fill_empty_rows/sparse_fill_empty_rows_kernel_ref.cpp+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/sparse_fill_empty_rows/sparse_fill_empty_rows_kernel_ref.cpp@@ -26,6 +26,7 @@ ParamsKey SparseFillEmptyRowsKernelRef::GetSupportedKey() const {k.EnableTensorPitches();k.EnableBatching();k.EnableDifferentTypes();+ k.EnableDynamicShapesSupport();return k;}@@ -42,6 +43,17 @@ SparseFillEmptyRowsKernelRef::DispatchData SetDefault(const sparse_fill_empty_ro}} // anonymous namespace+void SparseFillEmptyRowsKernelRef::GetUpdateDispatchDataFunc(KernelData& kd) const {+ kd.update_dispatch_data_func = [this](const Params& params, KernelData& kd) {+ const auto& prim_params = static_cast<const sparse_fill_empty_rows_params&>(params);+ auto dispatchData = SetDefault(prim_params);+ OPENVINO_ASSERT(kd.kernels.size() == 1, "[GPU] Invalid kernels size for update dispatch data func");+ kd.kernels[0].params.workGroups.global = dispatchData.gws;+ kd.kernels[0].params.workGroups.local = dispatchData.lws;+ kd.kernels[0].skip_execution = SkipKernelExecution(prim_params);+ };+}+KernelsData SparseFillEmptyRowsKernelRef::GetKernelsData(const Params ¶ms) const {if (!Validate(params)) {return {};@@ -49,23 +61,28 @@ KernelsData SparseFillEmptyRowsKernelRef::GetKernelsData(const Params ¶ms) cKernelData kernel_data = KernelData::Default<sparse_fill_empty_rows_params>(params);kernel_data.kernels[0].skip_execution = SkipKernelExecution(static_cast<const sparse_fill_empty_rows_params&>(params));sparse_fill_empty_rows_params &new_params = dynamic_cast<sparse_fill_empty_rows_params&>(*kernel_data.params.get());+auto sparse_fill_empty_rows_specific_jit = GetJitConstants(new_params);- auto dispatch_data = SetDefault(new_params);auto entry_point = GetEntryPoint(kernelName, new_params.layerID, params);auto jit = CreateJit(kernelName, sparse_fill_empty_rows_specific_jit, entry_point);++ auto dispatch_data = SetDefault(new_params);+ GetUpdateDispatchDataFunc(kernel_data);+FillCLKernelData(kernel_data.kernels[0],dispatch_data,params.engineInfo,kernelName,jit,entry_point,- EXE_MODE_DEFAULT, // exeMode- false, // weights- false, // bias- 4, // number_of_inputs- 0, // number_of_inputs_for_fused_prims- 3, // number_of_outputs- false); // is_dynamic+ EXE_MODE_DEFAULT, // exeMode+ false, // weights+ false, // bias+ 4, // number_of_inputs+ 0, // number_of_inputs_for_fused_prims+ 3, // number_of_outputs+ params.is_shape_agnostic); // is_dynamic+return {kernel_data};}@@ -82,7 +99,6 @@ bool SparseFillEmptyRowsKernelRef::Validate(const Params& p) const {JitConstants SparseFillEmptyRowsKernelRef::GetJitConstants(const sparse_fill_empty_rows_params& params) const {JitConstants jit = MakeBaseParamsJitConstants(params);- jit.AddConstant(MakeJitConstant("INDICES_COUNT", params.inputs[2].LogicalSize() / 2));return jit;}diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/sparse_fill_empty_rows/sparse_fill_empty_rows_kernel_ref.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/sparse_fill_empty_rows/sparse_fill_empty_rows_kernel_ref.hindex c973fec1d4a..4ae11a40362 100644--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/sparse_fill_empty_rows/sparse_fill_empty_rows_kernel_ref.h+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/sparse_fill_empty_rows/sparse_fill_empty_rows_kernel_ref.h@@ -25,7 +25,7 @@ public:protected:JitConstants GetJitConstants(const sparse_fill_empty_rows_params& params) const;bool SkipKernelExecution(const sparse_fill_empty_rows_params& params, size_t kernel_id = 0) const;-// void GetUpdateDispatchDataFunc(KernelData& kd) const override;+ void GetUpdateDispatchDataFunc(KernelData& kd) const override;};} // namespace kernel_selectordiff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/sparse_fill_empty_rows.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/sparse_fill_empty_rows.cppindex cfb9274a456..5527c7adc28 100644--- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/sparse_fill_empty_rows.cpp+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/sparse_fill_empty_rows.cpp@@ -9,6 +9,11 @@namespace ov::test {INSTANTIATE_TEST_SUITE_P(smoke_SparseFillEmptyRows_static,SparseFillEmptyRowsLayerTest,- SparseFillEmptyRowsLayerTest::GetTestDataForDevice(ov::test::utils::DEVICE_GPU),+ SparseFillEmptyRowsLayerTest::GetStaticTestDataForDevice(ov::test::utils::DEVICE_GPU),+ SparseFillEmptyRowsLayerTest::getTestCaseName);++INSTANTIATE_TEST_SUITE_P(smoke_SparseFillEmptyRows_dynamic,+ SparseFillEmptyRowsLayerTest,+ SparseFillEmptyRowsLayerTest::GetDynamicTestDataForDevice(ov::test::utils::DEVICE_GPU),SparseFillEmptyRowsLayerTest::getTestCaseName);} // namespace ov::testdiff --git a/src/plugins/intel_gpu/tests/unit/test_cases/sparse_fill_empty_rows_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/sparse_fill_empty_rows_gpu_test.cppindex 50fbe6f7f22..2a957f55772 100644--- a/src/plugins/intel_gpu/tests/unit/test_cases/sparse_fill_empty_rows_gpu_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/test_cases/sparse_fill_empty_rows_gpu_test.cpp@@ -8,6 +8,7 @@#include <intel_gpu/primitives/sparse_fill_empty_rows.hpp>#include "test_utils.h"+#include "sparse_fill_empty_rows_inst.h"using namespace cldnn;using namespace ::tests;@@ -112,14 +113,14 @@ public:const auto indicesRows = testParam.indicesData.size() / 2;ret.indices = helpers::AllocateTensor<int64_t>(- ov::Shape{indicesRows, 2},+ ov::PartialShape{static_cast<int64_t>(indicesRows), 2},helpers::ConverFloatVector<int64_t>(testParam.indicesData));ret.values = helpers::AllocateTensor<T>(- ov::Shape{testParam.valuesData.size()},+ ov::PartialShape{static_cast<int64_t>(testParam.valuesData.size())},helpers::ConverFloatVector<T>(testParam.valuesData));ret.denseShape = helpers::AllocateTensor<int64_t>(- ov::Shape{2}, helpers::ConverFloatVector<int64_t>(testParam.denseShapeData));- ret.defaultValue = helpers::AllocateTensor<T>(ov::Shape{}, {42.0f});+ ov::PartialShape{2}, helpers::ConverFloatVector<int64_t>(testParam.denseShapeData));+ ret.defaultValue = helpers::AllocateTensor<T>(ov::PartialShape{}, {42.0f});ret.expectedIndicesOutput = helpers::AllocateTensor<int64_t>(ov::Shape{testParam.expectedIndicesOutput.size() / 2, 2},@@ -138,10 +139,16 @@ public:auto stream = get_test_stream_ptr(get_test_default_config(engine_));topology topology;- topology.add(input_layout("values", params.values->get_layout()));- topology.add(input_layout("denseShape", params.denseShape->get_layout()));- topology.add(input_layout("indices", params.indices->get_layout()));- topology.add(input_layout("default_value", params.defaultValue->get_layout()));+ // Create dynamic layouts for input tensors+ auto values_dynamic_layout = layout{ov::PartialShape::dynamic(1), params.values->get_layout().data_type, format::bfyx};+ auto dense_shape_dynamic_layout = layout{ov::PartialShape::dynamic(1), data_types::i64, format::bfyx};+ auto indices_dynamic_layout = layout{ov::PartialShape::dynamic(2), data_types::i64, format::bfyx};+ auto default_value_dynamic_layout = layout{ov::PartialShape::dynamic(0), params.defaultValue->get_layout().data_type, format::bfyx};++ topology.add(input_layout("values", values_dynamic_layout));+ topology.add(input_layout("denseShape", dense_shape_dynamic_layout));+ topology.add(input_layout("indices", indices_dynamic_layout));+ topology.add(input_layout("default_value", default_value_dynamic_layout));std::vector<input_info> inputs = {input_info("values"),@@ -171,6 +178,11 @@ public:network->set_input_data("indices", params.indices);network->set_input_data("default_value", params.defaultValue);+ auto inst = network->get_primitive("sparse_fill_empty_rows");+ auto impl = inst->get_impl();+ ASSERT_TRUE(impl != nullptr);+ ASSERT_TRUE(impl->is_dynamic());+auto outputs = network->execute();auto output_indices = outputs.at("output_indices").get_memory();auto output_values = outputs.at("output_values").get_memory();diff --git a/src/tests/functional/plugin/shared/include/shared_test_classes/single_op/sparse_fill_empty_rows.hpp b/src/tests/functional/plugin/shared/include/shared_test_classes/single_op/sparse_fill_empty_rows.hppindex 7889ec99ae1..b05f5106898 100644--- a/src/tests/functional/plugin/shared/include/shared_test_classes/single_op/sparse_fill_empty_rows.hpp+++ b/src/tests/functional/plugin/shared/include/shared_test_classes/single_op/sparse_fill_empty_rows.hpp@@ -31,6 +31,8 @@ public:testing::internal::ValueArray<const char*>>;static const TGenData GetTestDataForDevice(const char* deviceName);+ static const TGenData GetStaticTestDataForDevice(const char* deviceName);+ static const TGenData GetDynamicTestDataForDevice(const char* deviceName);protected:void SetUp() override;diff --git a/src/tests/functional/plugin/shared/src/single_op/sparse_fill_empty_rows.cpp b/src/tests/functional/plugin/shared/src/single_op/sparse_fill_empty_rows.cppindex d794c984dcd..336a92859ec 100644--- a/src/tests/functional/plugin/shared/src/single_op/sparse_fill_empty_rows.cpp+++ b/src/tests/functional/plugin/shared/src/single_op/sparse_fill_empty_rows.cpp@@ -38,7 +38,7 @@ void SparseFillEmptyRowsLayerTest::SetUp() {auto indices = std::make_shared<ov::op::v0::Parameter>(ov::element::i64, inputDynamicShapes[2]);std::shared_ptr<ov::Node> default_value_node;if (in_type == utils::InputLayerType::PARAMETER) {- default_value_node = std::make_shared<ov::op::v0::Parameter>(values_type, ov::Shape{});+ default_value_node = std::make_shared<ov::op::v0::Parameter>(values_type, ov::PartialShape{});} else {default_value_node = std::make_shared<ov::op::v0::Constant>(values_type, ov::Shape{}, default_value);}@@ -62,14 +62,14 @@ void SparseFillEmptyRowsLayerTest::generate_inputs(const std::vector<ov::Shape>&const auto valuesType = funcInputs[0].get_element_type();const auto idxType = funcInputs[2].get_element_type();- std::vector<int64_t> dense_shape_values;- for (auto v : indicesShape) {- dense_shape_values.push_back(static_cast<int64_t>(v));- }- ov::Tensor dense_shape_tensor(idxType, {2});+ size_t M = indicesShape[0];+ size_t num_rows = std::max(static_cast<size_t>(8), M + 2);+ size_t num_cols = std::max(static_cast<size_t>(5), static_cast<size_t>(3));++ ov::Tensor dense_shape_tensor(idxType, denseShapeShape);auto* ptr = dense_shape_tensor.data<int64_t>();- ptr[0] = dense_shape_values[0];- ptr[1] = dense_shape_values[1];+ ptr[0] = static_cast<int64_t>(num_rows);+ ptr[1] = static_cast<int64_t>(num_cols);inputs[funcInputs[1].get_node_shared_ptr()] = dense_shape_tensor;ov::test::utils::InputGenerateData valuesData;@@ -79,10 +79,7 @@ void SparseFillEmptyRowsLayerTest::generate_inputs(const std::vector<ov::Shape>&inputs[funcInputs[0].get_node_shared_ptr()] = values_tensor;// Generate indices: [M, 2], each row in [0, num_rows-1], col in [0, num_cols-1]- size_t num_rows = dense_shape_values[0];- size_t num_cols = dense_shape_values[1];ov::Tensor indices_tensor(idxType, indicesShape);- size_t M = indicesShape[0];auto* iptr = indices_tensor.data<int64_t>();for (size_t i = 0; i < M; ++i) {iptr[i * 2 + 0] = static_cast<int64_t>(i % num_rows);@@ -118,5 +115,50 @@ const SparseFillEmptyRowsLayerTest::TGenData SparseFillEmptyRowsLayerTest::GetTereturn data;}+const SparseFillEmptyRowsLayerTest::TGenData SparseFillEmptyRowsLayerTest::GetStaticTestDataForDevice(const char* deviceName) {+ const std::vector<std::vector<InputShape>> input_shapes_static = {{+ // values: [M], dense_shape: [2], indices: [M, 2]+ {{{4}, {{4}}}, {{2}, {{2}}}, {{4, 2}, {{4, 2}}}},+ {{{8}, {{8}}}, {{2}, {{2}}}, {{8, 2}, {{8, 2}}}},+ {{{6}, {{6}}}, {{2}, {{2}}}, {{6, 2}, {{6, 2}}}},+ {{{12}, {{12}}}, {{2}, {{2}}}, {{12, 2}, {{12, 2}}}}+ }};++ const std::vector<std::vector<float>> default_values = {{0.0f}, {42.0f}};+ const std::vector<ov::element::Type> values_types = {ov::element::f32, ov::element::f16};+ std::vector<utils::InputLayerType> in_types = {utils::InputLayerType::CONSTANT, utils::InputLayerType::PARAMETER};++ auto data = ::testing::Combine(+ ::testing::ValuesIn(input_shapes_static),+ ::testing::ValuesIn(default_values),+ ::testing::ValuesIn(values_types),+ ::testing::ValuesIn(in_types),+ ::testing::Values(deviceName));+ return data;+}++const SparseFillEmptyRowsLayerTest::TGenData SparseFillEmptyRowsLayerTest::GetDynamicTestDataForDevice(const char* deviceName) {+ const std::vector<std::vector<InputShape>> input_shapes_dynamic = {{+ {{{ov::Dimension(1, 20)}, {{4}, {8}, {6}}}, {{2}, {{2}}}, {{ov::Dimension(1, 20), 2}, {{4, 2}, {8, 2}, {6, 2}}}},+ {{{ov::Dimension(2, 16)}, {{10}, {12}, {14}}}, {{2}, {{2}}}, {{ov::Dimension(2, 16), 2}, {{10, 2}, {12, 2}, {14, 2}}}},+ {{{ov::Dimension(1, 50)}, {{3}, {5}, {7}, {9}}}, {{2}, {{2}}}, {{ov::Dimension(1, 50), 2}, {{3, 2}, {5, 2}, {7, 2}, {9, 2}}}},+ {{{ov::Dimension::dynamic()}, {{2}, {15}, {7}, {20}}}, {{2}, {{2}}}, {{ov::Dimension::dynamic(), 2}, {{2, 2}, {15, 2}, {7, 2}, {20, 2}}}},+ {{{ov::Dimension::dynamic()}, {{1}, {9}, {13}, {25}}}, {{2}, {{2}}}, {{ov::Dimension::dynamic(), 2}, {{1, 2}, {9, 2}, {13, 2}, {25, 2}}}},+ {{{ov::Dimension::dynamic()}, {{11}, {6}, {18}, {4}}}, {{2}, {{2}}}, {{ov::Dimension::dynamic(), 2}, {{11, 2}, {6, 2}, {18, 2}, {4, 2}}}}+ }};++ const std::vector<std::vector<float>> default_values = {{0.0f}, {42.0f}};+ const std::vector<ov::element::Type> values_types = {ov::element::f32, ov::element::f16};+ std::vector<utils::InputLayerType> in_types = {utils::InputLayerType::CONSTANT, utils::InputLayerType::PARAMETER};++ auto data = ::testing::Combine(+ ::testing::ValuesIn(input_shapes_dynamic),+ ::testing::ValuesIn(default_values),+ ::testing::ValuesIn(values_types),+ ::testing::ValuesIn(in_types),+ ::testing::Values(deviceName));+ return data;+}+} // namespace test} // namespace ov