Skip to content

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

[GPU] Update creating SpaceToBatch and BatchToSpace for dynamic and static (#29415)

Kelvin Choi1eab89f3454c
diff --git a/src/plugins/intel_gpu/src/plugin/ops/batch_to_space.cpp b/src/plugins/intel_gpu/src/plugin/ops/batch_to_space.cpp
index 94765f6d169..bb2f83b89d0 100644
--- a/src/plugins/intel_gpu/src/plugin/ops/batch_to_space.cpp
+++ b/src/plugins/intel_gpu/src/plugin/ops/batch_to_space.cpp
@@ -17,32 +17,22 @@ static void CreateBatchToSpaceOp(ProgramBuilder& p, const std::shared_ptr<ov::op
auto inputs = p.GetInputInfo(op);
std::string layerName = layer_type_name_ID(op);
- auto rank = op->get_input_partial_shape(0).size();
- auto format = cldnn::format::get_default_format(rank);
-
- std::vector<cldnn::tensor> tensor_inputs;
- tensor_inputs.reserve(3);
+ auto output_pshape = op->get_output_partial_shape(0);
+ auto out_size = output_pshape.is_static() ? tensor_from_dims(output_pshape.to_shape()) : cldnn::tensor();
- bool non_constant_input = false;
+ bool constant_shape = true;
for (size_t i = 1; i < 4; ++i) {
auto inConst = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(i));
-
- bool is_const_input = (inConst != nullptr);
- OPENVINO_ASSERT((i == 1) || (i >= 2 && non_constant_input != is_const_input),
- "[GPU] Unsupported mixed node with constant and parameter in ", op->get_friendly_name(), " (", op->get_type_name(), ")");
-
if (!inConst) {
- non_constant_input = true;
+ constant_shape = false;
+ break;
}
}
- auto output_pshape = op->get_output_partial_shape(0);
- auto out_size = output_pshape.is_static() ? tensor_from_dims(output_pshape.to_shape()) : cldnn::tensor();
-
- if (non_constant_input) {
- auto batchToSpacePrim = cldnn::batch_to_space(layerName, inputs, out_size);
- p.add_primitive(*op, batchToSpacePrim);
- } else {
+ if (!p.use_new_shape_infer() && !op->is_dynamic() && constant_shape) {
+ std::vector<cldnn::tensor> tensor_inputs;
+ auto rank = op->get_input_partial_shape(0).size();
+ auto format = cldnn::format::get_default_format(rank);
for (size_t i = 1; i < 4; ++i) {
auto inConst = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(i));
@@ -62,6 +52,9 @@ static void CreateBatchToSpaceOp(ProgramBuilder& p, const std::shared_ptr<ov::op
out_size);
p.add_primitive(*op, batchToSpacePrim);
+ } else {
+ auto batchToSpacePrim = cldnn::batch_to_space(layerName, inputs, out_size);
+ p.add_primitive(*op, batchToSpacePrim);
}
}
diff --git a/src/plugins/intel_gpu/src/plugin/ops/space_to_batch.cpp b/src/plugins/intel_gpu/src/plugin/ops/space_to_batch.cpp
index e79461ce793..4a13c94df96 100644
--- a/src/plugins/intel_gpu/src/plugin/ops/space_to_batch.cpp
+++ b/src/plugins/intel_gpu/src/plugin/ops/space_to_batch.cpp
@@ -17,34 +17,22 @@ static void CreateSpaceToBatchOp(ProgramBuilder& p, const std::shared_ptr<ov::op
auto inputs = p.GetInputInfo(op);
std::string layerName = layer_type_name_ID(op);
- auto rank = op->get_input_partial_shape(0).size();
- auto format = cldnn::format::get_default_format(rank);
-
- std::vector<cldnn::tensor> tensor_inputs;
- tensor_inputs.reserve(3);
+ auto output_pshape = op->get_output_partial_shape(0);
+ auto out_size = output_pshape.is_static() ? tensor_from_dims(output_pshape.to_shape()) : cldnn::tensor();
- bool non_constant_input = false;
+ bool constant_shape = true;
for (size_t i = 1; i < 4; ++i) {
auto inConst = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(i));
-
- bool is_const_input = (inConst != nullptr);
- OPENVINO_ASSERT((i == 1) || (i >= 2 && non_constant_input != is_const_input),
- "[GPU] Unsupported mixed node with constant and parameter in ", op->get_friendly_name(), " (", op->get_type_name(), ")");
-
if (!inConst) {
- non_constant_input = true;
+ constant_shape = false;
+ break;
}
}
- // In case of dynamic shapes pass dummy shape value to space_to_batch primitive
- // To be removed once we enable internal shape infer for all operations
- auto output_pshape = op->get_output_partial_shape(0);
- auto out_size = output_pshape.is_static() ? tensor_from_dims(output_pshape.to_shape()) : cldnn::tensor();
-
- if (non_constant_input) {
- auto spaceToBatchPrim = cldnn::space_to_batch(layerName, inputs, out_size);
- p.add_primitive(*op, spaceToBatchPrim);
- } else {
+ if (!p.use_new_shape_infer() && !op->is_dynamic() && constant_shape) {
+ std::vector<cldnn::tensor> tensor_inputs;
+ auto rank = op->get_input_partial_shape(0).size();
+ auto format = cldnn::format::get_default_format(rank);
for (size_t i = 1; i < 4; ++i) {
auto inConst = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(i));
@@ -57,13 +45,16 @@ static void CreateSpaceToBatchOp(ProgramBuilder& p, const std::shared_ptr<ov::op
}
auto spaceToBatchPrim = cldnn::space_to_batch(layerName,
- inputs[0], // input data
+ inputs[0], // input
tensor_inputs[0], // block_shape
tensor_inputs[1], // crops_begin
tensor_inputs[2], // crops_end
out_size);
p.add_primitive(*op, spaceToBatchPrim);
+ } else {
+ auto spaceToBatchPrim = cldnn::space_to_batch(layerName, inputs, out_size);
+ p.add_primitive(*op, spaceToBatchPrim);
}
}
diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/batch_to_space.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/batch_to_space.cpp
index 15ada4b92c3..db9e1a7531b 100644
--- a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/batch_to_space.cpp
+++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/batch_to_space.cpp
@@ -165,54 +165,57 @@ const std::vector<ov::test::utils::InputLayerType> restInputTypes = {
ov::test::utils::InputLayerType::PARAMETER
};
-const std::vector<InputShape> inputShapesDynamic3D = {
- {{-1, -1, -1}, {{48, 3, 3}, {24, 4, 5}}},
+const std::vector<InputShape> inputShapes3D = {
+ {{48, 3, 3}, {{48, 3, 3}}},
+ {{-1, -1, -1}, {{48, 3, 3}, {24, 4, 5}}}
};
const std::vector<BatchToSpaceParams> paramsPlain3D = {
BatchToSpaceParams{ { 1, 2, 4 }, { 0, 0, 1 }, { 0, 0, 1 } },
- BatchToSpaceParams{ { 1, 3, 2 }, { 0, 1, 0 }, { 0, 2, 1 } },
+ BatchToSpaceParams{ { 1, 3, 2 }, { 0, 1, 0 }, { 0, 2, 1 } }
};
INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_Plain_Dynamic_3D, BatchToSpaceLayerGPUTest,
::testing::Combine(
- ::testing::ValuesIn(inputShapesDynamic3D),
+ ::testing::ValuesIn(inputShapes3D),
::testing::ValuesIn(paramsPlain3D),
::testing::ValuesIn(inputPrecisions),
::testing::ValuesIn(restInputTypes),
::testing::Values(emptyAdditionalConfig)),
BatchToSpaceLayerGPUTest::getTestCaseName);
-const std::vector<InputShape> inputShapesDynamic4D = {
- {{-1, -1, -1, -1}, {{48, 3, 3, 1}, {24, 4, 5, 6}}},
+const std::vector<InputShape> inputShapes4D = {
+ {{24, 4, 5, 6}, {{24, 4, 5, 6}}},
+ {{-1, -1, -1, -1}, {{48, 3, 3, 1}, {24, 4, 5, 6}}}
};
const std::vector<BatchToSpaceParams> paramsPlain4D = {
BatchToSpaceParams{ { 1, 2, 4, 3 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 } },
- BatchToSpaceParams{ { 1, 3, 2, 4 }, { 0, 1, 0, 1 }, { 0, 2, 1, 3 } },
+ BatchToSpaceParams{ { 1, 3, 2, 4 }, { 0, 1, 0, 1 }, { 0, 2, 1, 3 } }
};
INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_Plain_Dynamic_4D, BatchToSpaceLayerGPUTest,
::testing::Combine(
- ::testing::ValuesIn(inputShapesDynamic4D),
+ ::testing::ValuesIn(inputShapes4D),
::testing::ValuesIn(paramsPlain4D),
::testing::ValuesIn(inputPrecisions),
::testing::ValuesIn(restInputTypes),
::testing::Values(emptyAdditionalConfig)),
BatchToSpaceLayerGPUTest::getTestCaseName);
-const std::vector<InputShape> inputShapesDynamic5D = {
- {{-1, -1, -1, -1, -1}, {{48, 3, 3, 1, 5}, {96, 4, 5, 6, 7}}},
+const std::vector<InputShape> inputShapes5D = {
+ {{96, 4, 5, 6, 7}, {{96, 4, 5, 6, 7}}},
+ {{-1, -1, -1, -1, -1}, {{48, 3, 3, 1, 5}, {96, 4, 5, 6, 7}}}
};
const std::vector<BatchToSpaceParams> paramsPlain5D = {
BatchToSpaceParams{ { 1, 2, 4, 3, 2 }, { 0, 0, 1, 0, 2 }, { 0, 0, 1, 0, 3 } },
- BatchToSpaceParams{ { 1, 3, 2, 4, 2 }, { 0, 1, 0, 1, 3 }, { 0, 2, 1, 3, 2 } },
+ BatchToSpaceParams{ { 1, 3, 2, 4, 2 }, { 0, 1, 0, 1, 3 }, { 0, 2, 1, 3, 2 } }
};
INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_Plain_Dynamic_5D, BatchToSpaceLayerGPUTest,
::testing::Combine(
- ::testing::ValuesIn(inputShapesDynamic5D),
+ ::testing::ValuesIn(inputShapes5D),
::testing::ValuesIn(paramsPlain5D),
::testing::ValuesIn(inputPrecisions),
::testing::ValuesIn(restInputTypes),
diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/space_to_batch.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/space_to_batch.cpp
index 5de49d120c0..c09672fd267 100644
--- a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/space_to_batch.cpp
+++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/space_to_batch.cpp
@@ -155,53 +155,56 @@ const std::vector<ov::test::utils::InputLayerType> restInputTypes = {
ov::test::utils::InputLayerType::PARAMETER
};
-const std::vector<InputShape> inputShapesDynamic3D = {
- {{-1, -1, -1}, {{2, 3, 6}}},
+const std::vector<InputShape> inputShapes3D = {
+ {{2, 3, 6}, {{2, 3, 6}}},
+ {{-1, -1, -1}, {{2, 3, 6}}}
};
const std::vector<SpaceToBatchParams> paramsPlain3D = {
SpaceToBatchParams{ { 1, 2, 3 }, { 0, 2, 2 }, { 0, 3, 1 } },
- SpaceToBatchParams{ { 1, 4, 5 }, { 0, 4, 5 }, { 0, 9, 4 } },
+ SpaceToBatchParams{ { 1, 4, 5 }, { 0, 4, 5 }, { 0, 9, 4 } }
};
INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_Dynamic3D, SpaceToBatchLayerGPUTest,
::testing::Combine(
- ::testing::ValuesIn(inputShapesDynamic3D),
+ ::testing::ValuesIn(inputShapes3D),
::testing::ValuesIn(paramsPlain3D),
::testing::ValuesIn(inputPrecisions),
::testing::ValuesIn(restInputTypes)),
SpaceToBatchLayerGPUTest::getTestCaseName);
-const std::vector<InputShape> inputShapesDynamic4D = {
- {{-1, -1, -1, -1}, {{2, 3, 6, 5}}},
+const std::vector<InputShape> inputShapes4D = {
+ {{{2, 3, 6, 5}}, {{2, 3, 6, 5}}},
+ {{-1, -1, -1, -1}, {{2, 3, 6, 5}}}
};
const std::vector<SpaceToBatchParams> paramsPlain4D = {
SpaceToBatchParams{ { 1, 1, 2, 3 }, { 0, 2, 2, 2 }, { 0, 3, 4, 5 } },
- SpaceToBatchParams{ { 1, 1, 4, 5 }, { 0, 2, 4, 5 }, { 0, 3, 2, 5 } },
+ SpaceToBatchParams{ { 1, 1, 4, 5 }, { 0, 2, 4, 5 }, { 0, 3, 2, 5 } }
};
INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_Dynamic4D, SpaceToBatchLayerGPUTest,
::testing::Combine(
- ::testing::ValuesIn(inputShapesDynamic4D),
+ ::testing::ValuesIn(inputShapes4D),
::testing::ValuesIn(paramsPlain4D),
::testing::ValuesIn(inputPrecisions),
::testing::ValuesIn(restInputTypes)),
SpaceToBatchLayerGPUTest::getTestCaseName);
-const std::vector<InputShape> inputShapesDynamic5D = {
- {{-1, -1, -1, -1, -1}, {{2, 3, 6, 5, 7}}},
+const std::vector<InputShape> inputShapes5D = {
+ {{2, 3, 6, 5, 7}, {{2, 3, 6, 5, 7}}},
+ {{-1, -1, -1, -1, -1}, {{2, 3, 6, 5, 7}}}
};
const std::vector<SpaceToBatchParams> paramsPlain5D = {
SpaceToBatchParams{ { 1, 1, 2, 3, 7 }, { 0, 2, 2, 2, 4 }, { 0, 3, 4, 5, 3 } },
- SpaceToBatchParams{ { 1, 1, 4, 5, 8 }, { 0, 2, 4, 5, 5 }, { 0, 3, 2, 5, 4 } },
+ SpaceToBatchParams{ { 1, 1, 4, 5, 8 }, { 0, 2, 4, 5, 5 }, { 0, 3, 2, 5, 4 } }
};
INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_Dynamic5D, SpaceToBatchLayerGPUTest,
::testing::Combine(
- ::testing::ValuesIn(inputShapesDynamic5D),
+ ::testing::ValuesIn(inputShapes5D),
::testing::ValuesIn(paramsPlain5D),
::testing::ValuesIn(inputPrecisions),
::testing::ValuesIn(restInputTypes)),