Skip to content

Commit 42c725f

Browse files
[GPU] 4d extension for output shape of reshape calc_output_layout
1 parent 779d459 commit 42c725f

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

src/plugins/intel_gpu/src/graph/reshape.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ layout reshape_inst::calc_output_layout(reshape_node const& node, kernel_impl_pa
115115
if (desc->output_shape.count() == 0) {
116116
if (desc->output_partial_shape.size() != 0) {
117117
format out_fmt = format::adjust_to_rank(input_layout.format, desc->output_partial_shape.rank().get_length());
118-
return layout{desc->output_partial_shape, input_layout.data_type, out_fmt};
118+
auto output_shape = desc->output_partial_shape;
119+
if (output_shape.size() < 4)
120+
output_shape.insert(output_shape.end(), 4 - output_shape.size(), 1);
121+
return layout{output_shape, input_layout.data_type, out_fmt};
119122
} else {
120123
OPENVINO_ASSERT("[GPU] Output shape is not provided");
121124
}

src/plugins/intel_gpu/tests/unit/test_cases/eltwise_gpu_test.cpp

+63
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
#include <intel_gpu/primitives/eltwise.hpp>
1111
#include <intel_gpu/primitives/gather.hpp>
1212
#include <intel_gpu/primitives/reorder.hpp>
13+
#include <intel_gpu/primitives/reshape.hpp>
1314
#include <intel_gpu/primitives/data.hpp>
1415

1516
#include "eltwise_inst.h"
17+
#include "reshape_inst.h"
1618

1719
using namespace cldnn;
1820
using namespace ::tests;
@@ -3439,6 +3441,67 @@ TEST(eltwise_gpu_f32, broadcast_test_dim3_dim4) {
34393441
}
34403442
}
34413443

3444+
3445+
TEST(eltwise_gpu_f32, broadcast_test_dim3_dim4_new_shape_infer_false) {
3446+
auto& engine = get_test_engine();
3447+
3448+
ov::Shape in2_shape = {1, 1, 4, 1};
3449+
auto input2 = engine.allocate_memory({ ov::PartialShape(in2_shape), data_types::f32, format::bfyx });
3450+
3451+
std::vector<float> const_input = {
3452+
1.f, 0.f, 5.f, 1.5f,
3453+
2.f, 0.f, 6.f, 5.2f,
3454+
3.f, 0.5f, 7.f, 12.f,
3455+
4.f, -0.5f, 8.f, 8.f
3456+
};
3457+
3458+
set_values(input2, {
3459+
0.5f, 2.5f, 0.5f, 2.5f
3460+
});
3461+
3462+
float answers[16] = {
3463+
1.5, 2.5, 5.5, 4,
3464+
2.5, 2.5, 6.5, 7.7,
3465+
3.5, 3, 7.5, 14.5,
3466+
4.5, 2, 8.5, 10.5
3467+
};
3468+
3469+
ExecutionConfig config = get_test_default_config(engine);
3470+
config.set_property(ov::intel_gpu::allow_new_shape_infer(false));
3471+
3472+
// Eltwise in1:dim3, int2:dim4
3473+
{
3474+
ov::Shape in1_shape = {1, 2, 2, 4};
3475+
3476+
auto input = engine.allocate_memory({ ov::PartialShape(in1_shape), data_types::f32, format::bfyx });
3477+
set_values(input, const_input);
3478+
3479+
topology topology;
3480+
topology.add(input_layout("input", input->get_layout()));
3481+
topology.add(input_layout("input2", input2->get_layout()));
3482+
topology.add(reshape("reshape_input1", input_info("input"), false, {}, ov::PartialShape({2, 2, 4})));
3483+
topology.add(eltwise("eltwise", { input_info("reshape_input1"), input_info("input2") }, eltwise_mode::sum));
3484+
3485+
network network(engine, topology, config);
3486+
3487+
network.set_input_data("input", input);
3488+
network.set_input_data("input2", input2);
3489+
auto outputs = network.execute();
3490+
3491+
ASSERT_EQ(outputs.size(), size_t(1));
3492+
ASSERT_EQ(outputs.begin()->first, "eltwise");
3493+
3494+
auto output = outputs.at("eltwise").get_memory();
3495+
3496+
cldnn::mem_lock<float> output_ptr(output, get_test_stream());
3497+
3498+
for (int i = 0; i < 16; i++)
3499+
{
3500+
ASSERT_TRUE(are_equal(answers[i], output_ptr[i]));
3501+
}
3502+
}
3503+
}
3504+
34423505
TEST(eltwise_gpu_f16, fs_b_yx_fsv32_basic)
34433506
{
34443507
// Inputs are 2x2x2x2

0 commit comments

Comments
 (0)