Skip to content

Commit 4ed124a

Browse files
[GPU] static strided_sliced crop to use tensor
1 parent 797229e commit 4ed124a

File tree

7 files changed

+174
-66
lines changed

7 files changed

+174
-66
lines changed

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ 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-
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};
118+
return layout{desc->output_partial_shape, input_layout.data_type, out_fmt};
122119
} else {
123120
OPENVINO_ASSERT("[GPU] Output shape is not provided");
124121
}

src/plugins/intel_gpu/src/plugin/ops/strided_slice.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ static void CreateStridedSliceOp(ProgramBuilder& p, const std::shared_ptr<ov::op
252252
}
253253

254254
auto reshapeOutName = op->get_friendly_name() + "/Crop";
255-
auto reshapePrim = cldnn::reshape(reshapeOutName, layerName, false, output_pattern, output_pshape);
255+
auto output_ts = tensor_from_dims(output_shape);
256+
auto reshapePrim = cldnn::reshape(reshapeOutName, layerName, output_ts);
257+
256258
p.add_primitive(*op, reshapePrim);
257259
last_layer_primitive = reshapeOutName;
258260
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (C) 2018-2025 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#include <vector>
6+
7+
#include "subgraph_tests/stridedslice_eltwise.hpp"
8+
9+
namespace {
10+
using ov::test::StridedSliceEltwiseTest;
11+
12+
std::vector<ov::test::StridedSliceEltwiseSpecificParams> ss_spec = {
13+
ov::test::StridedSliceEltwiseSpecificParams{ ov::test::static_shapes_to_test_representation(std::vector<ov::Shape>({
14+
{ 1, 2, 2, 3}, { 1, 1, 3}})),
15+
{ 0 }, { 2 }, { 1 },
16+
{ 0 }, { 0 }, { 0 }, { 1 }, { 0 } },
17+
ov::test::StridedSliceEltwiseSpecificParams{ ov::test::static_shapes_to_test_representation(std::vector<ov::Shape>({
18+
{ 2, 3, 4, 5}, { 3, 1, 1}})),
19+
{ 0 }, { 2 }, { 1 },
20+
{ 0 }, { 0 }, { 0 }, { 1 }, { 0 } },
21+
};
22+
23+
INSTANTIATE_TEST_SUITE_P(smoke_StridedSliceEltwise, StridedSliceEltwiseTest,
24+
testing::Combine(
25+
testing::ValuesIn(ss_spec),
26+
testing::Values(ov::element::f32),
27+
testing::Values(ov::test::utils::DEVICE_GPU)),
28+
StridedSliceEltwiseTest::getTestCaseName);
29+
30+
} // namespace

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

-61
Original file line numberDiff line numberDiff line change
@@ -3441,67 +3441,6 @@ TEST(eltwise_gpu_f32, broadcast_test_dim3_dim4) {
34413441
}
34423442
}
34433443

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-
35053444
TEST(eltwise_gpu_f16, fs_b_yx_fsv32_basic)
35063445
{
35073446
// Inputs are 2x2x2x2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (C) 2018-2025 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#pragma once
6+
7+
#include "shared_test_classes/subgraph/stridedslice_eltwise.hpp"
8+
9+
namespace ov {
10+
namespace test {
11+
TEST_P(StridedSliceEltwiseTest, Inference) {
12+
run();
13+
};
14+
} // namespace test
15+
} // namespace ov
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (C) 2018-2025 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#pragma once
6+
7+
#include <tuple>
8+
#include <string>
9+
#include <vector>
10+
#include <memory>
11+
12+
#include "shared_test_classes/base/ov_subgraph.hpp"
13+
14+
namespace ov {
15+
namespace test {
16+
17+
struct StridedSliceEltwiseSpecificParams {
18+
std::vector<InputShape> input_shape;
19+
std::vector<int64_t> begin;
20+
std::vector<int64_t> end;
21+
std::vector<int64_t> strides;
22+
std::vector<int64_t> begin_mask;
23+
std::vector<int64_t> end_mask;
24+
std::vector<int64_t> new_axis_mask;
25+
std::vector<int64_t> shrink_axis_mask;
26+
std::vector<int64_t> ellipsis_axis_mask;
27+
};
28+
29+
using StridedSliceEltwiseParamsTuple = typename std::tuple<
30+
StridedSliceEltwiseSpecificParams, // strided_slice params
31+
ov::element::Type, // Network precision
32+
std::string>; // Device name
33+
34+
class StridedSliceEltwiseTest: public testing::WithParamInterface<StridedSliceEltwiseParamsTuple>,
35+
virtual public ov::test::SubgraphBaseStaticTest{
36+
public:
37+
static std::string getTestCaseName(const testing::TestParamInfo<StridedSliceEltwiseParamsTuple> &obj);
38+
protected:
39+
void SetUp() override;
40+
};
41+
} // namespace test
42+
} // namespace ov
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright (C) 2018-2025 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#include "shared_test_classes/subgraph/stridedslice_eltwise.hpp"
6+
7+
#include "common_test_utils/node_builders/constant.hpp"
8+
#include "common_test_utils/node_builders/eltwise.hpp"
9+
#include "common_test_utils/test_enums.hpp"
10+
#include "common_test_utils/ov_tensor_utils.hpp"
11+
12+
#include "openvino/op/parameter.hpp"
13+
#include "openvino/op/constant.hpp"
14+
#include "openvino/op/result.hpp"
15+
#include "openvino/op/reduce_sum.hpp"
16+
17+
namespace ov {
18+
namespace test {
19+
std::string StridedSliceEltwiseTest::getTestCaseName(const testing::TestParamInfo<StridedSliceEltwiseParamsTuple> &obj) {
20+
StridedSliceEltwiseSpecificParams params;
21+
ov::element::Type model_type;
22+
std::string target_device;
23+
std::tie(params, model_type, target_device) = obj.param;
24+
std::ostringstream result;
25+
result << "IS=(";
26+
for (size_t i = 0lu; i < params.input_shape.size(); i++) {
27+
result << ov::test::utils::partialShape2str({params.input_shape[i].first})
28+
<< (i < params.input_shape.size() - 1lu ? "_" : "");
29+
}
30+
result << ")_TS=";
31+
for (size_t i = 0lu; i < params.input_shape.front().second.size(); i++) {
32+
result << "{";
33+
for (size_t j = 0lu; j < params.input_shape.size(); j++) {
34+
result << ov::test::utils::vec2str(params.input_shape[j].second[i]) << (j < params.input_shape.size() - 1lu ? "_" : "");
35+
}
36+
result << "}_";
37+
}
38+
result << "modelType=" << model_type.to_string() << "_";
39+
result << "begin=" << ov::test::utils::vec2str(params.begin) << "_";
40+
result << "end=" << ov::test::utils::vec2str(params.end) << "_";
41+
result << "stride=" << ov::test::utils::vec2str(params.strides) << "_";
42+
result << "begin_m=" << ov::test::utils::vec2str(params.begin_mask) << "_";
43+
result << "end_m=" << ov::test::utils::vec2str(params.end_mask) << "_";
44+
result << "new_axis_m=" << (params.new_axis_mask.empty() ? "def" : ov::test::utils::vec2str(params.new_axis_mask)) << "_";
45+
result << "shrink_m=" << (params.shrink_axis_mask.empty() ? "def" : ov::test::utils::vec2str(params.shrink_axis_mask)) << "_";
46+
result << "ellipsis_m=" << (params.ellipsis_axis_mask.empty() ? "def" : ov::test::utils::vec2str(params.ellipsis_axis_mask)) << "_";
47+
result << "trgDev=" << target_device;
48+
return result.str();
49+
}
50+
51+
void StridedSliceEltwiseTest::SetUp() {
52+
StridedSliceEltwiseSpecificParams ssParams;
53+
ov::element::Type type;
54+
std::tie(ssParams, type, targetDevice) = this->GetParam();
55+
56+
init_input_shapes(ssParams.input_shape);
57+
58+
ASSERT_EQ(ssParams.begin.size(), ssParams.end.size());
59+
ASSERT_EQ(ssParams.begin.size(), ssParams.strides.size());
60+
61+
auto param = std::make_shared<ov::op::v0::Parameter>(type, inputDynamicShapes.front());
62+
ov::Shape const_shape = {ssParams.begin.size()};
63+
auto begin_node = std::make_shared<ov::op::v0::Constant>(ov::element::i64, const_shape, ssParams.begin.data());
64+
auto end_node = std::make_shared<ov::op::v0::Constant>(ov::element::i64, const_shape, ssParams.end.data());
65+
auto stride_node = std::make_shared<ov::op::v0::Constant>(ov::element::i64, const_shape, ssParams.strides.data());
66+
auto stridedSlice = std::make_shared<ov::op::v1::StridedSlice>(param,
67+
begin_node,
68+
end_node,
69+
stride_node,
70+
ssParams.begin_mask,
71+
ssParams.end_mask,
72+
ssParams.new_axis_mask,
73+
ssParams.shrink_axis_mask,
74+
ssParams.ellipsis_axis_mask);
75+
76+
auto constant_input1_tensor = ov::test::utils::create_and_fill_tensor(type, targetStaticShapes.front()[1]);
77+
auto constant_input1 = std::make_shared<ov::op::v0::Constant>(constant_input1_tensor);
78+
auto eltw = ov::test::utils::make_eltwise(stridedSlice, constant_input1, ov::test::utils::EltwiseTypes::ADD);
79+
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(eltw)};
80+
function = std::make_shared<ov::Model>(results, ov::ParameterVector{param}, "StridedSliceEltwise");
81+
}
82+
} // namespace test
83+
} // namespace ov

0 commit comments

Comments
 (0)