Skip to content

Commit cf4a031

Browse files
authored
[GPU] Avoid raising up the reorder added for reshaping the output of reduce. (#30271)
### Details: - *Fixed the reorder added for squeezing the output of reduce to not be removed.* ### Tickets: - *165886*
1 parent b494d7a commit cf4a031

File tree

3 files changed

+105
-3
lines changed

3 files changed

+105
-3
lines changed

src/plugins/intel_gpu/src/graph/graph_optimizer/compile_graph.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void compile_graph::run(program& p) {
5656
node->get_primitive()->type_string(),
5757
"\noriginal_type: ",
5858
node->get_primitive()->origin_op_type_name,
59-
fail_reason);
59+
" ", fail_reason);
6060
} catch (std::exception&) {
6161
exception = std::current_exception();
6262
}

src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing_through.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ void prepare_primitive_fusing_through::run(program& p) {
4848
if (node->is_type<reshape>() && node->get_dependencies().front().first->is_type<reduce>())
4949
return false;
5050

51-
// Not to raise up target node through reshape where the size of dimension is changed (e.g. Unsqueeze)
52-
if (node->is_type<reshape>() &&
51+
// Not to raise up target node through reshape or reorder where the size of dimension is changed (e.g. Unsqueeze or Squeeze)
52+
if ((node->is_type<reshape>() || node->is_type<reorder>()) &&
5353
node->get_output_pshape().size() != node->get_input_pshape(0).size())
5454
return false;
5555

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Copyright (C) 2024 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#include "common_test_utils/ov_tensor_utils.hpp"
6+
#include "common_test_utils/file_utils.hpp"
7+
#include "shared_test_classes/base/ov_subgraph.hpp"
8+
#include "openvino/op/parameter.hpp"
9+
#include "openvino/op/constant.hpp"
10+
#include "openvino/op/reduce_sum.hpp"
11+
#include "openvino/op/add.hpp"
12+
#include "openvino/op/multiply.hpp"
13+
#include "openvino/runtime/intel_gpu/properties.hpp"
14+
15+
namespace {
16+
17+
using ov::test::InputShape;
18+
using ReduceInputParams = std::tuple<
19+
ov::Shape, // Input shapes
20+
ov::element::Type, // Input precision
21+
std::vector<int64_t>, // Reduce Axes
22+
bool>; // Keep dims
23+
24+
25+
class ReduceSumSqueezeTest : public testing::WithParamInterface<ReduceInputParams>,
26+
virtual public ov::test::SubgraphBaseStaticTest {
27+
public:
28+
static std::string getTestCaseName(testing::TestParamInfo<ReduceInputParams> obj) {
29+
ov::Shape input_shape;
30+
ov::element::Type input_precisions;
31+
std::vector<int64_t> reduce_axes;
32+
bool keep_dims;
33+
34+
std::tie(input_shape, input_precisions, reduce_axes, keep_dims) = obj.param;
35+
36+
std::ostringstream result;
37+
result << "IS=ReduceSum_";
38+
result << ov::test::utils::vec2str(input_shape) << "_";
39+
result << "reduce_axes=" << ov::test::utils::vec2str(reduce_axes) << "_";
40+
result << "keep_dims=" << keep_dims << "_";
41+
result << "input_precision=" << input_precisions;
42+
return result.str();
43+
}
44+
45+
protected:
46+
ov::Shape input_shape;
47+
std::vector<int64_t> reduce_axes;
48+
bool keep_dims;
49+
50+
void SetUp() override {
51+
targetDevice = ov::test::utils::DEVICE_GPU;
52+
core->set_property(targetDevice, ov::enable_profiling(true));
53+
ov::element::Type input_precision;
54+
std::tie(input_shape, input_precision, reduce_axes, keep_dims) = GetParam();
55+
56+
ov::Shape add_val_shape = {input_shape.begin(), input_shape.end() - 1};
57+
ov::test::utils::InputGenerateData in_data;
58+
in_data.start_from = -10;
59+
in_data.range = 10;
60+
auto add_val_tensor = ov::test::utils::create_and_fill_tensor(input_precision, add_val_shape, in_data);
61+
62+
auto input_node = std::make_shared<ov::op::v0::Parameter>(input_precision, input_shape);
63+
auto axes_node = ov::op::v0::Constant::create(ov::element::i64, {1}, reduce_axes);
64+
auto reduce_node = std::make_shared<ov::op::v1::ReduceSum>(input_node, axes_node, keep_dims);
65+
reduce_node->set_friendly_name("ReduceSum");
66+
auto add_val_node = std::make_shared<ov::op::v0::Constant>(add_val_tensor);
67+
auto add_node = std::make_shared<ov::op::v1::Add>(reduce_node, add_val_node);
68+
auto mul_val_node = std::make_shared<ov::op::v0::Constant>(ov::element::f16, ov::Shape{}, 1.5f);
69+
auto mul_node = std::make_shared<ov::op::v1::Multiply>(add_node, mul_val_node);
70+
auto result = std::make_shared<ov::op::v0::Result>(mul_node);
71+
function = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input_node}, "input");
72+
}
73+
74+
void run() override {
75+
ov::test::SubgraphBaseStaticTest::run();
76+
ov::Shape input_shape;
77+
std::tie(input_shape, std::ignore, std::ignore, std::ignore) = GetParam();
78+
auto profile_info = inferRequest.get_profiling_info();
79+
auto num_executed = std::count_if(profile_info.begin(), profile_info.end(),
80+
[](const ov::ProfilingInfo& p) { return p.status == ov::ProfilingInfo::Status::EXECUTED; });
81+
// This ensures that primitive_fusing_through does not happen across "dimension-change-barrier" in reduce
82+
ASSERT_EQ(num_executed, 3);
83+
}
84+
};
85+
86+
TEST_P(ReduceSumSqueezeTest, Inference) {
87+
run();
88+
}
89+
90+
const std::vector<ov::Shape> input_shapes = {{{1, 2, 3, 2, 4}}};
91+
const std::vector<ov::element::Type> input_prec = {ov::element::f16};
92+
93+
INSTANTIATE_TEST_SUITE_P(
94+
Smoke_ReduceSumSqueezeTest,
95+
ReduceSumSqueezeTest,
96+
::testing::Combine(::testing::ValuesIn(input_shapes),
97+
::testing::ValuesIn(input_prec),
98+
::testing::Values(std::vector<int64_t>{4}),
99+
::testing::Values(false)),
100+
ReduceSumSqueezeTest::getTestCaseName);
101+
102+
} // namespace

0 commit comments

Comments
 (0)