Skip to content

Commit

Permalink
bug fix for stride_slice when strides < 0 on XPU (#62923)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyk0314 authored Mar 27, 2024
1 parent 84a7446 commit 064a998
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion paddle/phi/kernels/xpu/stride_slice_grad_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ void StridedSliceRawGradKernel(const Context& dev_ctx,
end = xshape[cur_axe];
}
if (end < 0) {
end += xshape[cur_axe];
if (!(end == -1 && strides_[i] < 0)) {
end = end + xshape[cur_axe];
if (end < 0) {
end = 0;
}
}
}

ends_in[cur_axe] = end;
Expand Down
7 changes: 6 additions & 1 deletion paddle/phi/kernels/xpu/stride_slice_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ void StridedSliceRawKernel(const Context& dev_ctx,
end = xshape[cur_axe];
}
if (end < 0) {
end += xshape[cur_axe];
if (!(end == -1 && strides_[i] < 0)) {
end = end + xshape[cur_axe];
if (end < 0) {
end = 0;
}
}
}

ends_in[cur_axe] = end;
Expand Down

0 comments on commit 064a998

Please sign in to comment.