Skip to content

Commit

Permalink
[GPU] Fix Interpolate assert (openvinotoolkit#16806)
Browse files Browse the repository at this point in the history
  • Loading branch information
sshlyapn authored Apr 10, 2023
1 parent ed50d37 commit 2075dcb
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct resample : public primitive_base<resample> {
cube_coeff(cube_coeff),
coord_trans_mode(ctm),
round_mode(nm) {
if (scales.size() != axes.size())
if (scales.size() != axes.size() && shape_calc_mode == InterpolateOp::ShapeCalcMode::SCALES)
throw std::runtime_error("Resample's scales/axes count does not match");
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/graph/resample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ std::vector<layout> resample_inst::calc_output_layouts(resample_node const& /*no

if (((sizes_data.empty() && !memory_deps.count(1)) || !sizes_calc_mod) &&
((scales_data.empty() && !memory_deps.count(2)) || sizes_calc_mod)) {
return { layout{ShapeType::dynamic(input_rank), input_layout.data_type, input_layout.format} };
return { layout{ShapeType::dynamic(input_rank), input_layout.data_type, input_layout.format} };
}

auto axes_data = desc->axes;
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/intel_gpu/src/plugin/ops/interpolate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ static void CreateInterpolateOp(Program& p, const std::shared_ptr<ngraph::op::v4
}
}

OPENVINO_ASSERT(!scales_constant || axes.size() == scales.size(), op->get_friendly_name(), " Incorrect axes and scales should be the same size");
if (attrs.shape_calculation_mode == ov::op::v4::Interpolate::ShapeCalcMode::SCALES && scales_constant) {
OPENVINO_ASSERT(axes.size() == scales.size(), "[GPU] Incorrect axes and scales values for Interpolate operation with id ", op->get_friendly_name());
}

// TODO shouldn't be all this checking done in ngraph::op::v4::Interpolate?
auto interpolateMode = attrs.mode;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/template/backend/evaluates_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4272,7 +4272,7 @@ bool evaluate_interpolate(const shared_ptr<op::v11::Interpolate>& op,
padded_input_shape.emplace_back(m_attrs.pads_begin[i] + m_attrs.pads_end[i] + input_shape[i].get_length());
}

auto axes = get_axes_vector(inputs, inputs[1]->get_shape().size(), axes_port, max_num_of_ports);
auto axes = get_axes_vector(inputs, inputs[1]->get_shape()[0], axes_port, max_num_of_ports);
auto scales = get_scales_vector(inputs, padded_input_shape, m_attrs, axes, scales_sizes_port);

ov::PartialShape output_shape{padded_input_shape};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ using ShapeParams = std::tuple<ngraph::op::v4::Interpolate::ShapeCalcMode, // Sh

using InterpolateLayerGPUTestParamsSet = std::tuple<InterpolateSpecificParams,
ShapeParams,
ElementType>;
ElementType,
bool>; // use Interpolate_v11

class InterpolateLayerGPUTest : public testing::WithParamInterface<InterpolateLayerGPUTestParamsSet>,
virtual public SubgraphBaseTest {
Expand All @@ -40,8 +41,9 @@ class InterpolateLayerGPUTest : public testing::WithParamInterface<InterpolateLa
InterpolateSpecificParams specificParams;
ShapeParams shapeParams;
ElementType prec;
bool useInterpolateV11;
std::map<std::string, std::string> additionalConfig;
std::tie(specificParams, shapeParams, prec) = obj.param;
std::tie(specificParams, shapeParams, prec, useInterpolateV11) = obj.param;

ngraph::op::v4::Interpolate::InterpolateMode mode;
ngraph::op::v4::Interpolate::CoordinateTransformMode transfMode;
Expand Down Expand Up @@ -87,6 +89,7 @@ class InterpolateLayerGPUTest : public testing::WithParamInterface<InterpolateLa
result << "PE=" << CommonTestUtils::vec2str(padEnd) << "_";
result << "Axes=" << CommonTestUtils::vec2str(axes) << "_";
result << "PRC=" << prec << "_";
result << "v11=" << useInterpolateV11 << "_";

if (!additionalConfig.empty()) {
result << "_PluginConf";
Expand All @@ -105,14 +108,16 @@ class InterpolateLayerGPUTest : public testing::WithParamInterface<InterpolateLa
const auto& funcInput = funcInputs[i];
ov::Tensor tensor;

if (i == 1) {
if (shapeCalcMode == ngraph::op::v4::Interpolate::ShapeCalcMode::SIZES) {
if (i == 0) {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], 2560, 0, 256);
} else if (i == 1) {
if (shapeCalcMode == ngraph::op::v4::Interpolate::ShapeCalcMode::SIZES || funcInputs.size() == 3) {
tensor = ov::Tensor(funcInput.get_element_type(), targetInputStaticShapes[i], sizes[inferRequestNum].data());
} else {
tensor = ov::Tensor(funcInput.get_element_type(), targetInputStaticShapes[i], scales[inferRequestNum].data());
}
} else {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], 2560, 0, 256);
tensor = ov::Tensor(funcInput.get_element_type(), targetInputStaticShapes[i], scales[inferRequestNum].data());
}

inputs.insert({funcInput.get_node_shared_ptr(), tensor});
Expand Down Expand Up @@ -156,7 +161,8 @@ class InterpolateLayerGPUTest : public testing::WithParamInterface<InterpolateLa
InterpolateSpecificParams specificParams;
ShapeParams shapeParams;
ElementType ngPrc;
std::tie(specificParams, shapeParams, ngPrc) = this->GetParam();
bool useInterpolateV11;
std::tie(specificParams, shapeParams, ngPrc, useInterpolateV11) = this->GetParam();

ngraph::op::v4::Interpolate::InterpolateMode mode;
ngraph::op::v4::Interpolate::CoordinateTransformMode transfMode;
Expand Down Expand Up @@ -241,12 +247,27 @@ class InterpolateLayerGPUTest : public testing::WithParamInterface<InterpolateLa

ngraph::op::v4::Interpolate::InterpolateAttrs interpAttr{mode, shapeCalcMode, padBegin, padEnd, transfMode, nearMode,
antiAlias, cubeCoef};
std::shared_ptr<ngraph::op::Op> interpolate;
bool scalesMode = shapeCalcMode == ngraph::op::v4::Interpolate::ShapeCalcMode::SCALES;
if (useInterpolateV11) {
if (axes.size() != dataShape.first.size()) {
interpolate = std::make_shared<ngraph::op::v11::Interpolate>(params[0],
scalesMode ? scalesInput : sizesInput,
axesInput,
interpAttr);
} else {
interpolate = std::make_shared<ngraph::op::v11::Interpolate>(params[0],
scalesMode ? scalesInput : sizesInput,
interpAttr);
}
} else {
interpolate = std::make_shared<ngraph::op::v4::Interpolate>(params[0],
sizesInput,
scalesInput,
axesInput,
interpAttr);
}

auto interpolate = std::make_shared<ngraph::op::v4::Interpolate>(params[0],
sizesInput,
scalesInput,
axesInput,
interpAttr);
ngraph::ResultVector results;
for (int i = 0; i < interpolate->get_output_size(); ++i) {
results.push_back(std::make_shared<ngraph::opset1::Result>(interpolate->output(i)));
Expand Down Expand Up @@ -310,6 +331,10 @@ const std::vector<std::vector<int64_t>> defaultAxes4D = {
{0, 1, 2, 3}
};

const std::vector<std::vector<int64_t>> reducedAxes4D = {
{2, 3}, {3}
};

const std::vector<ShapeParams> shapeParams4D_Smoke = {
ShapeParams{
ngraph::op::v4::Interpolate::ShapeCalcMode::SCALES,
Expand All @@ -327,6 +352,14 @@ const std::vector<ShapeParams> shapeParams4D_Smoke = {
{{1.f, 1.f, 0.5f, 2.0f}},
defaultAxes4D.front()
},
ShapeParams{
ngraph::op::v4::Interpolate::ShapeCalcMode::SCALES,
InputShape{{-1, {1, 10}, -1, -1}, {{1, 2, 12, 20}}},
ngraph::helpers::InputLayerType::PARAMETER,
ngraph::helpers::InputLayerType::PARAMETER,
{{0.5f, 2.0f}},
reducedAxes4D.front()
},
ShapeParams{
ngraph::op::v4::Interpolate::ShapeCalcMode::SIZES,
InputShape{{-1, {2, 20}, -1, -1}, {{1, 11, 4, 4}, {2, 7, 6, 5}, {1, 11, 4, 4}}},
Expand All @@ -342,6 +375,14 @@ const std::vector<ShapeParams> shapeParams4D_Smoke = {
ngraph::helpers::InputLayerType::PARAMETER,
{{1, 2, 24, 10}},
defaultAxes4D.front()
},
ShapeParams{
ngraph::op::v4::Interpolate::ShapeCalcMode::SIZES,
InputShape{{-1, {1, 10}, -1, -1}, {{1, 2, 12, 20}}},
ngraph::helpers::InputLayerType::PARAMETER,
ngraph::helpers::InputLayerType::PARAMETER,
{{24, 10}},
reducedAxes4D.front()
}
};

Expand All @@ -364,6 +405,41 @@ const std::vector<ShapeParams> shapeParams4D_Full = {
}
};

const std::vector<ShapeParams> shapeParams4DReducedAxis_Full = {
ShapeParams{
ngraph::op::v4::Interpolate::ShapeCalcMode::SCALES,
InputShape{{-1, {2, 20}, -1, -1}, {{1, 11, 4, 4}, {2, 7, 6, 5}, {1, 11, 4, 4}}},
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::CONSTANT,
{{1.f, 1.f, 1.25f, 1.5f}},
defaultAxes4D.front()
},
ShapeParams{
ngraph::op::v4::Interpolate::ShapeCalcMode::SIZES,
InputShape{{-1, {2, 20}, -1, -1}, {{1, 11, 4, 4}}},
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::CONSTANT,
{{1, 11, 5, 6}},
defaultAxes4D.front()
},
ShapeParams{
ngraph::op::v4::Interpolate::ShapeCalcMode::SCALES,
InputShape{{-1, {2, 20}, -1, -1}, {{1, 11, 4, 4}, {2, 7, 6, 5}, {1, 11, 4, 4}}},
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::CONSTANT,
{{1.5f}},
reducedAxes4D.back()
},
ShapeParams{
ngraph::op::v4::Interpolate::ShapeCalcMode::SIZES,
InputShape{{-1, {2, 20}, -1, -1}, {{1, 11, 4, 4}}},
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::CONSTANT,
{{6}},
reducedAxes4D.back()
}
};

const auto interpolateCasesNN_Smoke = ::testing::Combine(
::testing::Values(ngraph::op::v4::Interpolate::InterpolateMode::NEAREST),
::testing::ValuesIn(coordinateTransformModes_Smoke),
Expand All @@ -386,14 +462,16 @@ INSTANTIATE_TEST_SUITE_P(smoke_InterpolateNN_Layout_Test, InterpolateLayerGPUTes
::testing::Combine(
interpolateCasesNN_Smoke,
::testing::ValuesIn(shapeParams4D_Smoke),
::testing::Values(ElementType::f32)),
::testing::Values(ElementType::f32),
::testing::Values(true, false)),
InterpolateLayerGPUTest::getTestCaseName);

INSTANTIATE_TEST_SUITE_P(InterpolateNN_Layout_Test, InterpolateLayerGPUTest,
::testing::Combine(
interpolateCasesNN_Full,
::testing::ValuesIn(shapeParams4D_Full),
::testing::Values(ElementType::f32)),
interpolateCasesNN_Full,
::testing::ValuesIn(shapeParams4DReducedAxis_Full),
::testing::Values(ElementType::f32),
::testing::Values(true, false)),
InterpolateLayerGPUTest::getTestCaseName);

const auto interpolateCasesLinearOnnx_Smoke = ::testing::Combine(
Expand All @@ -418,14 +496,16 @@ INSTANTIATE_TEST_SUITE_P(smoke_InterpolateLinearOnnx_Layout_Test, InterpolateLay
::testing::Combine(
interpolateCasesLinearOnnx_Smoke,
::testing::ValuesIn(shapeParams4D_Smoke),
::testing::Values(ElementType::f32)),
::testing::Values(ElementType::f32),
::testing::Values(false)),
InterpolateLayerGPUTest::getTestCaseName);

INSTANTIATE_TEST_SUITE_P(InterpolateLinearOnnx_Layout_Test, InterpolateLayerGPUTest,
::testing::Combine(
interpolateCasesLinearOnnx_Full,
::testing::ValuesIn(shapeParams4D_Full),
::testing::Values(ElementType::f32)),
::testing::Values(ElementType::f32),
::testing::Values(true, false)),
InterpolateLayerGPUTest::getTestCaseName);

const auto interpolateCasesLinear_Smoke = ::testing::Combine(
Expand All @@ -450,14 +530,16 @@ INSTANTIATE_TEST_SUITE_P(smoke_InterpolateLinear_Layout_Test, InterpolateLayerGP
::testing::Combine(
interpolateCasesLinear_Smoke,
::testing::ValuesIn(shapeParams4D_Smoke),
::testing::Values(ElementType::f32)),
::testing::Values(ElementType::f32),
::testing::Values(false)),
InterpolateLayerGPUTest::getTestCaseName);

INSTANTIATE_TEST_SUITE_P(InterpolateLinear_Layout_Test, InterpolateLayerGPUTest,
::testing::Combine(
interpolateCasesLinear_Full,
::testing::ValuesIn(shapeParams4D_Full),
::testing::Values(ElementType::f32)),
::testing::ValuesIn(shapeParams4DReducedAxis_Full),
::testing::Values(ElementType::f32),
::testing::Values(true, false)),
InterpolateLayerGPUTest::getTestCaseName);

const auto interpolateCasesCubic_Smoke = ::testing::Combine(
Expand All @@ -482,14 +564,16 @@ INSTANTIATE_TEST_SUITE_P(smoke_InterpolateCubic_Layout_Test, InterpolateLayerGPU
::testing::Combine(
interpolateCasesCubic_Smoke,
::testing::ValuesIn(shapeParams4D_Smoke),
::testing::Values(ElementType::f32)),
::testing::Values(ElementType::f32),
::testing::Values(false)),
InterpolateLayerGPUTest::getTestCaseName);

INSTANTIATE_TEST_SUITE_P(InterpolateCubic_Layout_Test, InterpolateLayerGPUTest,
::testing::Combine(
interpolateCasesCubic_Full,
::testing::ValuesIn(shapeParams4D_Full),
::testing::Values(ElementType::f32)),
::testing::ValuesIn(shapeParams4DReducedAxis_Full),
::testing::Values(ElementType::f32),
::testing::Values(true, false)),
InterpolateLayerGPUTest::getTestCaseName);

////////////////////////5D/////////////////////////////
Expand All @@ -502,6 +586,10 @@ const std::vector<std::vector<int64_t>> defaultAxes5D = {
{0, 1, 2, 3, 4}
};

const std::vector<std::vector<int64_t>> reducedAxes5D = {
{2, 3, 4}
};

const std::vector<ShapeParams> shapeParams5D_Smoke = {
ShapeParams{
ngraph::op::v4::Interpolate::ShapeCalcMode::SCALES,
Expand All @@ -527,14 +615,22 @@ const std::vector<ShapeParams> shapeParams5D_Smoke = {
{{1, 11, 5, 6, 2}, {2, 7, 8, 7, 4}, {1, 11, 5, 6, 2}},
defaultAxes5D.front()
},
ShapeParams{
ShapeParams{
ngraph::op::v4::Interpolate::ShapeCalcMode::SIZES,
InputShape{{-1, {2, 10}, -1, -1, -1}, {{1, 4, 2, 3, 4}}},
InputShape{{-1, {2, 10}, -1, -1, -1}, {{1, 4, 2, 3, 4}}},
ngraph::helpers::InputLayerType::PARAMETER,
ngraph::helpers::InputLayerType::PARAMETER,
{{1, 4, 4, 1, 6}},
defaultAxes5D.front()
},
ShapeParams{
ngraph::op::v4::Interpolate::ShapeCalcMode::SIZES,
InputShape{{-1, {2, 10}, -1, -1, -1}, {{1, 4, 2, 3, 4}}},
ngraph::helpers::InputLayerType::PARAMETER,
ngraph::helpers::InputLayerType::PARAMETER,
{{4, 1, 6}},
reducedAxes5D.front()
},
};

const std::vector<ShapeParams> shapeParams5D_Full = {
Expand All @@ -553,6 +649,14 @@ const std::vector<ShapeParams> shapeParams5D_Full = {
ngraph::helpers::InputLayerType::CONSTANT,
{{1, 11, 5, 6, 4}},
defaultAxes5D.front()
},
ShapeParams{
ngraph::op::v4::Interpolate::ShapeCalcMode::SIZES,
InputShape{{-1, {2, 20}, -1, -1, -1}, {{1, 11, 4, 4, 4}, {1, 11, 5, 5, 8}, {1, 11, 4, 4, 4}}},
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::CONSTANT,
{{1, 6, 4}},
reducedAxes5D.front()
}
};

Expand All @@ -578,14 +682,16 @@ INSTANTIATE_TEST_SUITE_P(smoke_InterpolateLinearOnnx5D_Layout_Test, InterpolateL
::testing::Combine(
interpolateCasesLinearOnnx5D_Smoke,
::testing::ValuesIn(shapeParams5D_Smoke),
::testing::Values(ElementType::f32)),
::testing::Values(ElementType::f32),
::testing::Values(false)),
InterpolateLayerGPUTest::getTestCaseName);

INSTANTIATE_TEST_SUITE_P(InterpolateLinearOnnx5D_Layout_Test, InterpolateLayerGPUTest,
::testing::Combine(
interpolateCasesLinearOnnx5D_Full,
::testing::ValuesIn(shapeParams5D_Full),
::testing::Values(ElementType::f32)),
::testing::Values(ElementType::f32),
::testing::Values(true, false)),
InterpolateLayerGPUTest::getTestCaseName);

const auto interpolateCasesNN5D_Smoke = ::testing::Combine(
Expand All @@ -610,14 +716,16 @@ INSTANTIATE_TEST_SUITE_P(smoke_InterpolateNN5D_Layout_Test, InterpolateLayerGPUT
::testing::Combine(
interpolateCasesNN5D_Smoke,
::testing::ValuesIn(shapeParams5D_Smoke),
::testing::Values(ElementType::f32)),
::testing::Values(ElementType::f32),
::testing::Values(true, false)),
InterpolateLayerGPUTest::getTestCaseName);

INSTANTIATE_TEST_SUITE_P(InterpolateNN5D_Layout_Test, InterpolateLayerGPUTest,
::testing::Combine(
interpolateCasesNN5D_Full,
::testing::ValuesIn(shapeParams5D_Full),
::testing::Values(ElementType::f32)),
::testing::Values(ElementType::f32),
::testing::Values(true, false)),
InterpolateLayerGPUTest::getTestCaseName);

} // namespace
Expand Down

0 comments on commit 2075dcb

Please sign in to comment.