Skip to content

Commit a78d914

Browse files
authored
[GPU] Fix CreateStridedSliceOp() not to use fixed Rank 4 reshape for new_shape_infer case (openvinotoolkit#23319)
### Details: - Fix CreateStridedSliceOp() not to use fixed Rank 4 reshape for new_shape_infer case - Add a func test case - Fix debug log in condition ### Tickets: - 130775
1 parent baf1c9d commit a78d914

File tree

3 files changed

+154
-3
lines changed

3 files changed

+154
-3
lines changed

src/plugins/intel_gpu/src/graph/condition.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ void condition_inst::postprocess_output_memory(network::ptr executed_net, cldnn:
263263
}
264264

265265
_outputs[out_mem_idx] = mem_ptr;
266-
GPU_DEBUG_LOG << "Inner net - Outputs[" << out_mem_idx << "]" << mem_ptr->get_layout().to_short_string() << std::endl;
266+
if (mem_ptr)
267+
GPU_DEBUG_LOG << "Inner net - Outputs[" << out_mem_idx << "]" << mem_ptr->get_layout().to_short_string() << std::endl;
267268
}
268269
}
269270
} // namespace cldnn

src/plugins/intel_gpu/src/plugin/ops/strided_slice.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void CreateStridedSliceOp(ProgramBuilder& p, const std::shared_ptr<ov::op
5353
std::vector<int64_t> strides = stride_constant ? stride_constant->cast_vector<int64_t>() : std::vector<int64_t>{};
5454

5555
do {
56-
if (!begin_constant || !end_constant || !stride_constant || input_pshape.is_dynamic()) {
56+
if (!begin_constant || !end_constant || !stride_constant || input_pshape.is_dynamic() || p.use_new_shape_infer()) {
5757
break;
5858
}
5959

@@ -265,7 +265,7 @@ static void CreateStridedSliceOp(ProgramBuilder& p, const std::shared_ptr<ov::op
265265
auto output_shape = output_pshape.is_static() ? output_pshape.to_shape() : ov::Shape{};
266266

267267
std::shared_ptr<cldnn::strided_slice> stridedSlicePrim = nullptr;
268-
if (begin_constant && end_constant && stride_constant && !input_pshape.is_dynamic() && !output_pshape.is_dynamic()) {
268+
if (begin_constant && end_constant && stride_constant && !input_pshape.is_dynamic() && !output_pshape.is_dynamic() && !p.use_new_shape_infer()) {
269269
stridedSlicePrim = std::make_shared<cldnn::strided_slice>(layerName,
270270
inputs[0],
271271
begin,

src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/strided_slice.cpp

+150
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,144 @@ class StridedSliceLayerGPUTest : public testing::WithParamInterface<StridedSlice
179179
}
180180
};
181181

182+
class StridedSliceLayerReshapeGPUTest : virtual public StridedSliceLayerGPUTest {
183+
public:
184+
void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override {
185+
inputs.clear();
186+
const auto& funcInputs = function->inputs();
187+
ov::Tensor tensor;
188+
189+
// input0: data
190+
int32_t idx = 0;
191+
tensor = ov::test::utils::create_and_fill_tensor(funcInputs[idx].get_element_type(), targetInputStaticShapes[idx]);
192+
inputs.insert({funcInputs[idx].get_node_shared_ptr(), tensor});
193+
194+
// input1: begin
195+
if (rest_input_type[0] == ov::test::utils::InputLayerType::PARAMETER) {
196+
idx += 1;
197+
tensor = ov::Tensor(funcInputs[idx].get_element_type(), targetInputStaticShapes[idx]);
198+
auto *dataPtr = tensor.data<float>();
199+
for (size_t i = 0; i < begin.size(); i++) {
200+
dataPtr[i] = static_cast<float>(begin[i]);
201+
}
202+
inputs.insert({funcInputs[idx].get_node_shared_ptr(), tensor});
203+
}
204+
205+
// input2: end
206+
if (rest_input_type[1] == ov::test::utils::InputLayerType::PARAMETER) {
207+
idx += 1;
208+
tensor = ov::Tensor(funcInputs[idx].get_element_type(), targetInputStaticShapes[idx]);
209+
auto *dataPtr = tensor.data<float>();
210+
for (size_t i = 0; i < end.size(); i++) {
211+
dataPtr[i] = static_cast<float>(end[i]);
212+
}
213+
inputs.insert({funcInputs[idx].get_node_shared_ptr(), tensor});
214+
}
215+
216+
// input3: stride
217+
if (rest_input_type[2] == ov::test::utils::InputLayerType::PARAMETER) {
218+
idx += 1;
219+
tensor = ov::Tensor(funcInputs[idx].get_element_type(), targetInputStaticShapes[idx]);
220+
auto *dataPtr = tensor.data<float>();
221+
for (size_t i = 0; i < stride.size(); i++) {
222+
dataPtr[i] = static_cast<float>(stride[i]);
223+
}
224+
inputs.insert({funcInputs[idx].get_node_shared_ptr(), tensor});
225+
}
226+
227+
// data for input_1d
228+
idx += 1;
229+
tensor = ov::test::utils::create_and_fill_tensor(funcInputs[idx].get_element_type(), targetInputStaticShapes[idx]);
230+
inputs.insert({funcInputs[idx].get_node_shared_ptr(), tensor});
231+
232+
inferRequestNum++;
233+
}
234+
235+
protected:
236+
std::vector<int64_t> begin;
237+
std::vector<int64_t> end;
238+
std::vector<int64_t> stride;
239+
std::vector<ov::test::utils::InputLayerType> rest_input_type;
240+
size_t inferRequestNum = 0;
241+
242+
void SetUp() override {
243+
InputShape shapes;
244+
StridedSliceParams ssParams;
245+
std::tie(shapes, ssParams, inType, rest_input_type) = this->GetParam();
246+
247+
begin = ssParams.begin;
248+
end = ssParams.end;
249+
stride = ssParams.stride;
250+
251+
targetDevice = ov::test::utils::DEVICE_GPU;
252+
253+
std::vector<InputShape> inputShapes;
254+
255+
ov::PartialShape input_1d_shape{1024};
256+
257+
inputShapes.push_back(shapes);
258+
if (rest_input_type[0] == ov::test::utils::InputLayerType::PARAMETER)
259+
inputShapes.push_back(InputShape({static_cast<int64_t>(begin.size())}, std::vector<ov::Shape>(shapes.second.size(), {begin.size()})));
260+
if (rest_input_type[1] == ov::test::utils::InputLayerType::PARAMETER)
261+
inputShapes.push_back(InputShape({static_cast<int64_t>(end.size())}, std::vector<ov::Shape>(shapes.second.size(), {end.size()})));
262+
if (rest_input_type[2] == ov::test::utils::InputLayerType::PARAMETER)
263+
inputShapes.push_back(InputShape({static_cast<int64_t>(stride.size())}, std::vector<ov::Shape>(shapes.second.size(), {stride.size()})));
264+
265+
inputShapes.push_back(InputShape(input_1d_shape, {input_1d_shape.to_shape()}));
266+
267+
init_input_shapes(inputShapes);
268+
269+
ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(inType, inputDynamicShapes.front())};
270+
271+
std::shared_ptr<ov::Node> beginInput, endInput, strideInput;
272+
if (rest_input_type[0] == ov::test::utils::InputLayerType::PARAMETER) {
273+
auto beginNode = std::make_shared<ov::op::v0::Parameter>(ov::element::i64, ov::Shape{begin.size()});
274+
params.push_back(beginNode);
275+
beginInput = beginNode;
276+
} else {
277+
beginInput = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{begin.size()}, begin);
278+
}
279+
280+
if (rest_input_type[1] == ov::test::utils::InputLayerType::PARAMETER) {
281+
auto endNode = std::make_shared<ov::op::v0::Parameter>(ov::element::i64, ov::Shape{end.size()});
282+
params.push_back(endNode);
283+
endInput = endNode;
284+
} else {
285+
endInput = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{end.size()}, end);
286+
}
287+
288+
if (rest_input_type[2] == ov::test::utils::InputLayerType::PARAMETER) {
289+
auto strideNode = std::make_shared<ov::op::v0::Parameter>(ov::element::i64, ov::Shape{stride.size()});
290+
params.push_back(strideNode);
291+
strideInput = strideNode;
292+
} else {
293+
strideInput = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{stride.size()}, stride);
294+
}
295+
296+
auto input_1d = std::make_shared<ov::op::v0::Parameter>(inType, input_1d_shape.to_shape());
297+
params.push_back(input_1d);
298+
299+
auto ss = std::make_shared<ov::op::v1::StridedSlice>(input_1d, beginInput, endInput, strideInput, ssParams.beginMask, ssParams.endMask,
300+
ssParams.newAxisMask, ssParams.shrinkAxisMask, ssParams.ellipsisAxisMask);
301+
auto mul = std::make_shared<ov::op::v1::Multiply>(params[0], ss);
302+
303+
ov::ResultVector results;
304+
for (size_t i = 0; i < mul->get_output_size(); i++) {
305+
results.push_back(std::make_shared<ov::op::v0::Result>(mul->output(i)));
306+
}
307+
308+
function = std::make_shared<ov::Model>(results, params, "StridedSlice");
309+
}
310+
};
311+
182312
TEST_P(StridedSliceLayerGPUTest, Inference) {
183313
run();
184314
}
185315

316+
TEST_P(StridedSliceLayerReshapeGPUTest, Inference) {
317+
run();
318+
}
319+
186320
const std::vector<ov::element::Type> model_types = {
187321
ov::element::f32
188322
};
@@ -305,3 +439,19 @@ INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_Common_Dynamic_6D, StridedSliceLa
305439
::testing::ValuesIn(rest_input_types)),
306440
StridedSliceLayerGPUTest::getTestCaseName);
307441
} // namespace
442+
443+
const std::vector<InputShape> inputShapesDynamic3D = {
444+
{{-1, -1, -1},
445+
{{ 1, 1024, 2 }}},
446+
};
447+
const std::vector<StridedSliceParams> paramsPlain3D = {
448+
StridedSliceParams{ { 0, 0, 0 }, { 0, 0, 0 }, { 1, 1, 1 }, { 0, 1, 0 }, { 0, 1, 0 }, { 1, 0, 1 }, { }, { } },
449+
};
450+
451+
INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_new_axis_3D, StridedSliceLayerReshapeGPUTest,
452+
::testing::Combine(
453+
::testing::ValuesIn(inputShapesDynamic3D),
454+
::testing::ValuesIn(paramsPlain3D),
455+
::testing::ValuesIn(model_types),
456+
::testing::Values(rest_input_types[0])),
457+
StridedSliceLayerGPUTest::getTestCaseName);

0 commit comments

Comments
 (0)