Skip to content

Commit f992609

Browse files
[GPU] Add left-alignment for broadcastable check of eltwise NUMPY
1 parent 4b1f824 commit f992609

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

src/plugins/intel_gpu/src/graph/eltwise.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,11 @@ eltwise_inst::typed_primitive_inst(network& network, eltwise_node const& node) :
410410
auto base_pshape = input0_pshape;
411411
if (prim->broadcast_spec == ov::op::AutoBroadcastType::NUMPY &&
412412
base_pshape.size() < input_pshape.size()) {
413-
base_pshape.insert(base_pshape.begin(), input_pshape.size() - base_pshape.size(), 1);
413+
if (use_new_shape_infer) {
414+
base_pshape.insert(base_pshape.begin(), input_pshape.size() - base_pshape.size(), 1);
415+
} else {
416+
base_pshape.insert(base_pshape.end(), input_pshape.size() - base_pshape.size(), 1);
417+
}
414418
}
415419

416420
for (size_t d = 0; d < base_pshape.size(); ++d) {

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

+59
Original file line numberDiff line numberDiff line change
@@ -3439,6 +3439,65 @@ TEST(eltwise_gpu_f32, broadcast_test_dim3_dim4) {
34393439
}
34403440
}
34413441

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

0 commit comments

Comments
 (0)