[GPU] Add shape check condition for need_output_update in SyncInferRequest::wait() (#24036)

### Details:
- Add shape check condition for need_output_update in
SyncInferRequest::wait()

### Tickets:
 - 138395

---------

Co-authored-by: Pavel Durandin <pavel.durandin@intel.com>
Co-authored-by: Sergey Shlyapnikov <Sergeishlyapnikov@gmail.com>
This commit is contained in:
Wilson Seok 2024-04-16 23:20:34 +09:00 committed by GitHub
parent 8f9459a6d7
commit e8bb66d1f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 0 deletions

View File

@ -337,6 +337,18 @@ void SyncInferRequest::wait() {
"than required (", output_memory->size(), ")");
bool need_output_update = output_layout.bytes_count() == 0 || (output_memory && output_tensor->get_byte_size() != output_memory->size());
// Check shape is changed when size between output_tensor and output_memory are same.
if (!need_output_update) {
auto output_layout_shape = output_layout.get_shape();
auto output_tensor_shape = output_tensor->get_shape();
if (!output_layout_shape.empty() && !output_tensor_shape.empty()) {
if (output_layout_shape != output_tensor_shape) {
need_output_update = true;
}
}
}
if (need_output_update) {
OV_ITT_SCOPED_TASK(itt::domains::intel_gpu_plugin, "SyncInferRequest::wait::update_output");
auto mem_shape = output_layout.get_shape();

View File

@ -273,4 +273,38 @@ TEST(VariablesTest, smoke_set_get_state_with_convert) {
ov::test::utils::compare(tensor_to_set, state_tensor, 1e-5f, 1e-5f);
}
TEST(TensorTest, smoke_outputTensorShapesForDynamicInput) {
auto core = ov::Core();
using namespace ov::preprocess;
auto p = PrePostProcessor(ov::test::utils::make_split_multi_conv_concat());
p.input().tensor().set_element_type(ov::element::i8);
p.input().preprocess().convert_element_type(ov::element::f32);
auto function = p.build();
std::map<size_t, ov::PartialShape> shapes = { {0, ov::PartialShape{-1, -1, -1, -1}} };
function->reshape(shapes);
auto exec_net = core.compile_model(function, ov::test::utils::DEVICE_GPU);
auto inf_req = exec_net.create_infer_request();
ov::Tensor t1(ov::element::i8, {1, 4, 20, 40});
ov::Tensor t2(ov::element::i8, {1, 4, 40, 20});
ov::Tensor t3(ov::element::i8, {1, 4, 20, 40});
const ov::Shape output1_shape = {1, 10, 12, 32};
const ov::Shape output2_shape = {1, 10, 32, 12};
const ov::Shape output3_shape = {1, 10, 12, 32};
// Check output shape of output tensor is correct
ASSERT_NO_THROW(inf_req.set_input_tensor(t1));
ASSERT_NO_THROW(inf_req.infer());
ASSERT_EQ(inf_req.get_output_tensor().get_shape(), output1_shape);
ASSERT_NO_THROW(inf_req.set_input_tensor(t2));
ASSERT_NO_THROW(inf_req.infer());
ASSERT_EQ(inf_req.get_output_tensor().get_shape(), output2_shape);
ASSERT_NO_THROW(inf_req.set_input_tensor(t3));
ASSERT_NO_THROW(inf_req.infer());
ASSERT_EQ(inf_req.get_output_tensor().get_shape(), output3_shape);
}
} // namespace