Skip to content

Commit

Permalink
[GPU] static strided_sliced crop to use tensor (#28507)
Browse files Browse the repository at this point in the history
### Details:
 - *static strided_sliced crop to use tensor*

### Tickets:
 - *160254*
  • Loading branch information
kelvinchoi-intel authored Feb 18, 2025
1 parent b3a32cb commit 398842a
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/plugins/intel_gpu/src/plugin/ops/strided_slice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ static void CreateStridedSliceOp(ProgramBuilder& p, const std::shared_ptr<ov::op
}

auto reshapeOutName = op->get_friendly_name() + "/Crop";
auto reshapePrim = cldnn::reshape(reshapeOutName, layerName, false, output_pattern, output_pshape);
auto output_ts = tensor_from_dims(output_shape);
auto reshapePrim = cldnn::reshape(reshapeOutName, layerName, output_ts);

p.add_primitive(*op, reshapePrim);
last_layer_primitive = reshapeOutName;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (C) 2018-2025 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include <vector>

#include "subgraph_tests/stridedslice_eltwise.hpp"

namespace {
using ov::test::StridedSliceEltwiseTest;

std::vector<ov::test::StridedSliceEltwiseSpecificParams> ss_spec = {
ov::test::StridedSliceEltwiseSpecificParams{ ov::test::static_shapes_to_test_representation(std::vector<ov::Shape>({
{ 1, 2, 2, 3}, { 1, 1, 3}})),
{ 0 }, { 2 }, { 1 },
{ 0 }, { 0 }, { 0 }, { 1 }, { 0 } },
ov::test::StridedSliceEltwiseSpecificParams{ ov::test::static_shapes_to_test_representation(std::vector<ov::Shape>({
{ 2, 3, 4, 5}, { 3, 1, 1}})),
{ 0 }, { 2 }, { 1 },
{ 0 }, { 0 }, { 0 }, { 1 }, { 0 } },
};

INSTANTIATE_TEST_SUITE_P(smoke_StridedSliceEltwise, StridedSliceEltwiseTest,
testing::Combine(
testing::ValuesIn(ss_spec),
testing::Values(ov::element::f32),
testing::Values(ov::test::utils::DEVICE_GPU)),
StridedSliceEltwiseTest::getTestCaseName);

} // namespace
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2018-2025 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include "shared_test_classes/subgraph/stridedslice_eltwise.hpp"

namespace ov {
namespace test {
TEST_P(StridedSliceEltwiseTest, Inference) {
run();
};
} // namespace test
} // namespace ov
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) 2018-2025 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <tuple>
#include <string>
#include <vector>
#include <memory>

#include "shared_test_classes/base/ov_subgraph.hpp"

namespace ov {
namespace test {

struct StridedSliceEltwiseSpecificParams {
std::vector<InputShape> input_shape;
std::vector<int64_t> begin;
std::vector<int64_t> end;
std::vector<int64_t> strides;
std::vector<int64_t> begin_mask;
std::vector<int64_t> end_mask;
std::vector<int64_t> new_axis_mask;
std::vector<int64_t> shrink_axis_mask;
std::vector<int64_t> ellipsis_axis_mask;
};

using StridedSliceEltwiseParamsTuple = typename std::tuple<
StridedSliceEltwiseSpecificParams, // strided_slice params
ov::element::Type, // Network precision
std::string>; // Device name

class StridedSliceEltwiseTest: public testing::WithParamInterface<StridedSliceEltwiseParamsTuple>,
virtual public ov::test::SubgraphBaseStaticTest{
public:
static std::string getTestCaseName(const testing::TestParamInfo<StridedSliceEltwiseParamsTuple> &obj);
protected:
void SetUp() override;
};
} // namespace test
} // namespace ov
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (C) 2018-2025 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "shared_test_classes/subgraph/stridedslice_eltwise.hpp"

#include "common_test_utils/node_builders/constant.hpp"
#include "common_test_utils/node_builders/eltwise.hpp"
#include "common_test_utils/test_enums.hpp"
#include "common_test_utils/ov_tensor_utils.hpp"

#include "openvino/op/parameter.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/result.hpp"
#include "openvino/op/reduce_sum.hpp"

namespace ov {
namespace test {
std::string StridedSliceEltwiseTest::getTestCaseName(const testing::TestParamInfo<StridedSliceEltwiseParamsTuple> &obj) {
StridedSliceEltwiseSpecificParams params;
ov::element::Type model_type;
std::string target_device;
std::tie(params, model_type, target_device) = obj.param;
std::ostringstream result;
result << "IS=(";
for (size_t i = 0lu; i < params.input_shape.size(); i++) {
result << ov::test::utils::partialShape2str({params.input_shape[i].first})
<< (i < params.input_shape.size() - 1lu ? "_" : "");
}
result << ")_TS=";
for (size_t i = 0lu; i < params.input_shape.front().second.size(); i++) {
result << "{";
for (size_t j = 0lu; j < params.input_shape.size(); j++) {
result << ov::test::utils::vec2str(params.input_shape[j].second[i]) << (j < params.input_shape.size() - 1lu ? "_" : "");
}
result << "}_";
}
result << "modelType=" << model_type.to_string() << "_";
result << "begin=" << ov::test::utils::vec2str(params.begin) << "_";
result << "end=" << ov::test::utils::vec2str(params.end) << "_";
result << "stride=" << ov::test::utils::vec2str(params.strides) << "_";
result << "begin_m=" << ov::test::utils::vec2str(params.begin_mask) << "_";
result << "end_m=" << ov::test::utils::vec2str(params.end_mask) << "_";
result << "new_axis_m=" << (params.new_axis_mask.empty() ? "def" : ov::test::utils::vec2str(params.new_axis_mask)) << "_";
result << "shrink_m=" << (params.shrink_axis_mask.empty() ? "def" : ov::test::utils::vec2str(params.shrink_axis_mask)) << "_";
result << "ellipsis_m=" << (params.ellipsis_axis_mask.empty() ? "def" : ov::test::utils::vec2str(params.ellipsis_axis_mask)) << "_";
result << "trgDev=" << target_device;
return result.str();
}

void StridedSliceEltwiseTest::SetUp() {
StridedSliceEltwiseSpecificParams ssParams;
ov::element::Type type;
std::tie(ssParams, type, targetDevice) = this->GetParam();

init_input_shapes(ssParams.input_shape);

ASSERT_EQ(ssParams.begin.size(), ssParams.end.size());
ASSERT_EQ(ssParams.begin.size(), ssParams.strides.size());

auto param = std::make_shared<ov::op::v0::Parameter>(type, inputDynamicShapes.front());
ov::Shape const_shape = {ssParams.begin.size()};
auto begin_node = std::make_shared<ov::op::v0::Constant>(ov::element::i64, const_shape, ssParams.begin.data());
auto end_node = std::make_shared<ov::op::v0::Constant>(ov::element::i64, const_shape, ssParams.end.data());
auto stride_node = std::make_shared<ov::op::v0::Constant>(ov::element::i64, const_shape, ssParams.strides.data());
auto stridedSlice = std::make_shared<ov::op::v1::StridedSlice>(param,
begin_node,
end_node,
stride_node,
ssParams.begin_mask,
ssParams.end_mask,
ssParams.new_axis_mask,
ssParams.shrink_axis_mask,
ssParams.ellipsis_axis_mask);

auto constant_input1_tensor = ov::test::utils::create_and_fill_tensor(type, targetStaticShapes.front()[1]);
auto constant_input1 = std::make_shared<ov::op::v0::Constant>(constant_input1_tensor);
auto eltw = ov::test::utils::make_eltwise(stridedSlice, constant_input1, ov::test::utils::EltwiseTypes::ADD);
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(eltw)};
function = std::make_shared<ov::Model>(results, ov::ParameterVector{param}, "StridedSliceEltwise");
}
} // namespace test
} // namespace ov

0 comments on commit 398842a

Please sign in to comment.