Skip to content

Commit

Permalink
[GPU] Add left-alignment for broadcastable check of eltwise NUMPY
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinchoi-intel committed Jan 17, 2025
1 parent 4b1f824 commit f992609
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/plugins/intel_gpu/src/graph/eltwise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,11 @@ eltwise_inst::typed_primitive_inst(network& network, eltwise_node const& node) :
auto base_pshape = input0_pshape;
if (prim->broadcast_spec == ov::op::AutoBroadcastType::NUMPY &&
base_pshape.size() < input_pshape.size()) {
base_pshape.insert(base_pshape.begin(), input_pshape.size() - base_pshape.size(), 1);
if (use_new_shape_infer) {
base_pshape.insert(base_pshape.begin(), input_pshape.size() - base_pshape.size(), 1);
} else {
base_pshape.insert(base_pshape.end(), input_pshape.size() - base_pshape.size(), 1);
}
}

for (size_t d = 0; d < base_pshape.size(); ++d) {
Expand Down
59 changes: 59 additions & 0 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 @@ -3439,6 +3439,65 @@ 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};
auto input2 = engine.allocate_memory({ ov::PartialShape(in2_shape), data_types::f32, format::bfyx });

std::vector<float> const_input = {
1.f, 0.f, 5.f, 1.5f,
2.f, 0.f, 6.f, 5.2f,
3.f, 0.5f, 7.f, 12.f,
4.f, -0.5f, 8.f, 8.f
};

set_values(input2, {
0.5f, 2.5f, 0.5f, 2.5f
});

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
};

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

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

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));

network network(engine, topology, config);

network.set_input_data("input", input);
network.set_input_data("input2", input2);
auto outputs = network.execute();

ASSERT_EQ(outputs.size(), size_t(1));
ASSERT_EQ(outputs.begin()->first, "eltwise");

auto output = outputs.at("eltwise").get_memory();

cldnn::mem_lock<float> output_ptr(output, get_test_stream());

for (int i = 0; i < 16; i++)
{
ASSERT_TRUE(are_equal(answers[i], output_ptr[i]));
}
}
}

TEST(eltwise_gpu_f16, fs_b_yx_fsv32_basic)
{
// Inputs are 2x2x2x2
Expand Down

0 comments on commit f992609

Please sign in to comment.