Skip to content

Commit

Permalink
[GPU] Fix issues from unexecuted func tests (openvinotoolkit#22488)
Browse files Browse the repository at this point in the history
### Details:
- Failed
smoke_CLDNN_FP32/StridedSliceLayerTest.Inference/IS=([])_TS={(1.12.100)}_modelType=f32_begin=(0.n6.0)_end=(0.n8.0)_stride=(n1.n2.n1)_begin_m=(1.0.1)_end_m=(1.0.1)_new_axis_m=(0.0.0)_shrink_m=(0.0.0)_ellipsis_m=(0.0.0)_trgDev=GPU
 - *...*

### Tickets:
 - 128235

---------

Signed-off-by: Min, Byungil <[email protected]>
  • Loading branch information
byungilm authored Feb 7, 2024
1 parent 47c738f commit 1e865b3
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 37 deletions.
81 changes: 46 additions & 35 deletions src/plugins/intel_gpu/src/graph/impls/ocl/strided_slice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "strided_slice/strided_slice_kernel_ref.h"
#include "strided_slice/strided_slice_kernel_selector.h"


namespace {
template <typename T, typename DT, typename = typename std::enable_if<std::is_convertible<DT, T>::value>::type>
std::vector<T>& pad_vector_to_size(std::vector<T>& data, size_t size, DT value) {
Expand Down Expand Up @@ -141,51 +142,61 @@ struct strided_slice_impl : typed_primitive_impl_ocl<strided_slice> {
std::vector<int32_t> out_shape;
for (const auto& dim : logical_dims)
out_shape.push_back(static_cast<int32_t>(dim));

if (params.striding_params.size() == 3) {
// If the ith bit of begin_mask is not set, begin[i] is ignored and the range of the appropriate dimension starts from 0.
vector_assign_if_not_mask(params.striding_params[0], 0, params.begin_mask);
// If the ith bit of end_mask is not set, end[i] is ignored and the fullest possible range in that dimension is used
// instead.
vector_assign_if_not_mask(params.striding_params[1], out_shape, params.end_mask);
for (size_t dim = 0; dim < params.striding_params[2].size(); dim++) {
auto begin_org = params.striding_params[0][dim];
auto end_org = params.striding_params[1][dim];
if (params.striding_params[0][dim] < 0)
params.striding_params[0][dim] = std::max(out_shape[dim] + params.striding_params[0][dim], (int32_t)0);
if (params.striding_params[1][dim] < 0)
params.striding_params[1][dim] = std::max(out_shape[dim] + params.striding_params[1][dim], (int32_t)0);

params.striding_params[0][dim] = std::min(params.striding_params[0][dim], out_shape[dim]);
params.striding_params[1][dim] = std::min(params.striding_params[1][dim], out_shape[dim]);

auto& begin = params.striding_params[0][dim];
auto& end = params.striding_params[1][dim];
auto& stride = params.striding_params[2][dim];
bool is_clamp_begin = begin_org != begin;
bool is_clamp_end = end_org != end;
bool is_reverse = stride < 0;
// If begin > end && is_reverse, then we don't need to adjust begin/end values, the kernel will process it correctly
// However, in case of out-of-bounds begin/end values, it will be clamped, so we subtract 1 from each of them manually
// E.g. out_shape[dim] = 100; begin=10000; end=-10000; stride=-1
// clamp: begin=100; end=0;
// sub: begin=99; end=-1;
// If begin <= end, then we swap begin/end values and subtruct 1 from each of them
// E.g. out_shape[dim] = 100; begin=0; end=100; stride=-1
// swap: begin=100; end=0;
// sub: begin=99; end=-1;
// So the kernel will put the slices [99, 0] in reversed order as expected.
if (is_reverse) {
if (begin <= end) {
std::swap(begin, end);
auto begin = params.striding_params[0][dim];
auto end = params.striding_params[1][dim];
auto stride = params.striding_params[2][dim];

// Check out of bounds values for Clamping
auto check_out_of_bounds = [&](int32_t value) -> bool {
auto size = out_shape[dim];
if (value >= size || value < (size * -1))
return true;
else
return false;
};
bool should_clamp_begin = check_out_of_bounds(begin);
bool should_clamp_end = check_out_of_bounds(end);

// Convert a negative value which means reverse indexing from the end
if (begin < 0)
begin += out_shape[dim]; // converted value can be negative if the original one was out of bounds
if (end < 0)
end += out_shape[dim];
bool is_stride_reverse = (stride < 0) ? true : false;

// Clamping
begin = std::min(std::max(begin, (int32_t)0), out_shape[dim]);
end = std::min(std::max(end, (int32_t)0), out_shape[dim]);

if (is_stride_reverse) {
// If begin > end && is_reverse, then we don't need to adjust begin/end values, the kernel will process it correctly
// However, in case of out-of-bounds begin/end values, it will be clamped, so we subtract 1 from each of them manually
// E.g. out_shape[dim] = 100; begin=10000; end=-10000; stride=-1
// clamp: begin=100; end=0;
// sub: begin=99; end=-1;
// If begin <= end, then we swap begin/end values and subtruct 1 from each of them
// E.g. out_shape[dim] = 100; begin=-100; end=100; stride=-1
// sub: begin=-1; end=100;
// swap: begin=100; end=-1;
// So the kernel will put the slices [99, 0] in reversed order as expected.
if (should_clamp_begin)
begin--;
if (should_clamp_end)
end--;
} else if (begin_org != -1) { // If begin is -1 with negative stride, clamping begin is already expected value
if (is_clamp_begin)
begin--;
if (is_clamp_end)
end--;
}
if (begin <= end)
std::swap(begin, end);
}

params.striding_params[0][dim] = begin;
params.striding_params[1][dim] = end;
}
}
return {params, op_params};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ std::vector<StridedSliceSpecificParams> ss_only_test_cases_fp32 = {
{ 1, 12, 100 }})),
{ 0, -6, 0 }, { 0, -8, 0 }, { -1, -2, -1 },
{ 1, 0, 1 }, { 1, 0, 1 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } },
StridedSliceSpecificParams{ ov::test::static_shapes_to_test_representation(std::vector<ov::Shape>({
{ 1, 12, 100 }})),
{ 0, 6, 0 }, { 0, 4, 0 }, { -1, -2, -1 },
{ 1, 0, 1 }, { 1, 0, 1 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } },
StridedSliceSpecificParams{ ov::test::static_shapes_to_test_representation(std::vector<ov::Shape>({
{ 1, 12, 100 }})),
{ 0, -8, 0 }, { 0, -4, 0 }, { -1, 2, -1 },
{ 1, 0, 1 }, { 1, 0, 1 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } },
StridedSliceSpecificParams{ ov::test::static_shapes_to_test_representation(std::vector<ov::Shape>({
{ 1, 12, 100, 1, 1 }})),
{ 0, -1, 0, 0 }, { 0, 0, 0, 0 }, { 1, 1, 1, 1 },
Expand Down Expand Up @@ -109,8 +117,28 @@ std::vector<StridedSliceSpecificParams> ss_only_test_cases_fp32 = {
{ 0, 0, 0, 0, 0 }, { 0, 0, 29, 29, 29 }, { 1, 1, 1, 1, 1 },
{1, 1, 1, 1, 1}, {1, 1, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0} },
StridedSliceSpecificParams{ ov::test::static_shapes_to_test_representation(std::vector<ov::Shape>({
{ 10, 12 }})),
{ -1, 1 }, { -9999, 0 }, { -1, 1 },
{ 10, 10 }})),
{ 0, 0 }, { 1000, 2 }, { 1, 1 },
{ 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 0 } },
StridedSliceSpecificParams{ ov::test::static_shapes_to_test_representation(std::vector<ov::Shape>({
{ 10, 10 }})),
{ -1000, 0 }, { 1000, 2 }, { 1, 1 },
{ 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 0 } },
StridedSliceSpecificParams{ ov::test::static_shapes_to_test_representation(std::vector<ov::Shape>({
{ 10, 10 }})),
{ 1000, 1 }, { -1000, 2 }, { -1, 1 },
{ 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 0 } },
StridedSliceSpecificParams{ ov::test::static_shapes_to_test_representation(std::vector<ov::Shape>({
{ 10, 10 }})),
{ -1, 1 }, { -1000, 2 }, { -1, 1 },
{ 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 0 } },
StridedSliceSpecificParams{ ov::test::static_shapes_to_test_representation(std::vector<ov::Shape>({
{ 10, 10 }})),
{ -1, 1 }, { 0, 2 }, { -1, 1 },
{ 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 0 } },
StridedSliceSpecificParams{ ov::test::static_shapes_to_test_representation(std::vector<ov::Shape>({
{ 10, 10 }})),
{ -4, 1 }, { -8, 0 }, { -1, 1 },
{ 0, 1 }, { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 0 } },
StridedSliceSpecificParams{ ov::test::static_shapes_to_test_representation(std::vector<ov::Shape>({
{ 5, 5, 5, 5 }})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ inline std::string vec2str(const std::vector<vecElementType>& vec) {
}
return std::string("()");
}

template <>
inline std::string vec2str(const std::vector<int64_t>& vec) {
if (!vec.empty()) {
std::ostringstream result;
result << "(";
std::copy(vec.begin(), vec.end() - 1, std::ostream_iterator<int64_t>(result, "."));
result << vec.back() << ")";
auto ret = result.str();
std::replace(ret.begin(), ret.end(), '-', '_');
return ret;
}
return std::string("()");
}

inline void replaceSubstringInString(std::string& str, const std::string& from, const std::string& to) {
size_t pos;
while ((pos = str.find(from)) != std::string::npos) {
Expand Down

0 comments on commit 1e865b3

Please sign in to comment.