Skip to content

Commit

Permalink
Update output shape to 4d for static reshape not using new_shape_infer
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinchoi-intel committed Jan 21, 2025
1 parent 693b983 commit b639368
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
3 changes: 0 additions & 3 deletions src/plugins/intel_gpu/src/graph/eltwise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,6 @@ eltwise_inst::typed_primitive_inst(network& network, eltwise_node const& node) :
bool use_new_shape_infer = network.get_config().get_property(ov::intel_gpu::allow_new_shape_infer);
auto input0_pshape = node.get_input_pshape(0);

if (!use_new_shape_infer && input0_pshape.size() < 4)
input0_pshape.insert(input0_pshape.end(), 4 - input0_pshape.size(), 1);

for (size_t i = 1; i < inputs_count; ++i) {
auto input_pshape = node.get_input_pshape(i);

Expand Down
6 changes: 5 additions & 1 deletion src/plugins/intel_gpu/src/graph/reshape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ layout reshape_inst::calc_output_layout(reshape_node const& node, kernel_impl_pa
if (desc->output_shape.count() == 0) {
if (desc->output_partial_shape.size() != 0) {
format out_fmt = format::adjust_to_rank(input_layout.format, desc->output_partial_shape.rank().get_length());
return layout{desc->output_partial_shape, input_layout.data_type, out_fmt};
auto use_new_shape_infer = node.get_program().is_new_shape_infer();
auto output_shape = desc->output_partial_shape;
if (!use_new_shape_infer && output_shape.size() < 4)
output_shape.insert(output_shape.end(), 4 - output_shape.size(), 1);
return layout{output_shape, input_layout.data_type, out_fmt};
} else {
OPENVINO_ASSERT("[GPU] Output shape is not provided");
}
Expand Down
19 changes: 11 additions & 8 deletions src/plugins/intel_gpu/tests/unit/test_cases/eltwise_gpu_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
#include <intel_gpu/primitives/eltwise.hpp>
#include <intel_gpu/primitives/gather.hpp>
#include <intel_gpu/primitives/reorder.hpp>
#include <intel_gpu/primitives/reshape.hpp>
#include <intel_gpu/primitives/data.hpp>

#include "eltwise_inst.h"
#include "reshape_inst.h"

using namespace cldnn;
using namespace ::tests;
Expand Down Expand Up @@ -3442,7 +3444,7 @@ TEST(eltwise_gpu_f32, broadcast_test_dim3_dim4) {
TEST(eltwise_gpu_f32, broadcast_test_dim3_dim4_new_shape_infer_false) {
auto& engine = get_test_engine();

ov::Shape in2_shape = {1, 4, 1, 1};
ov::Shape in2_shape = {1, 1, 4, 1};
auto input2 = engine.allocate_memory({ ov::PartialShape(in2_shape), data_types::f32, format::bfyx });

std::vector<float> const_input = {
Expand All @@ -3457,26 +3459,27 @@ TEST(eltwise_gpu_f32, broadcast_test_dim3_dim4_new_shape_infer_false) {
});

float answers[16] = {
1.5, 0.5, 7.5, 4,
2.5, 0.5, 8.5, 7.7,
3.5, 1, 9.5, 14.5,
4.5, 0, 10.5, 10.5
1.5, 2.5, 5.5, 4,
2.5, 2.5, 6.5, 7.7,
3.5, 3, 7.5, 14.5,
4.5, 2, 8.5, 10.5
};

ExecutionConfig config = get_test_default_config(engine);
config.set_property(ov::intel_gpu::allow_new_shape_infer(false));

// in1:dim3, int2:dim4
// Eltwise in1:dim3, int2:dim4
{
ov::Shape in1_shape = {2, 4, 2};
ov::Shape in1_shape = {1, 2, 2, 4};

auto input = engine.allocate_memory({ ov::PartialShape(in1_shape), data_types::f32, format::bfyx });
set_values(input, const_input);

topology topology;
topology.add(input_layout("input", input->get_layout()));
topology.add(input_layout("input2", input2->get_layout()));
topology.add(eltwise("eltwise", { input_info("input"), input_info("input2") }, eltwise_mode::sum));
topology.add(reshape("reshape_input1", input_info("input"), false, {}, ov::PartialShape({2, 2, 4})));
topology.add(eltwise("eltwise", { input_info("reshape_input1"), input_info("input2") }, eltwise_mode::sum));

network network(engine, topology, config);

Expand Down

0 comments on commit b639368

Please sign in to comment.