Skip to content

Commit f1b794d

Browse files
authored
fix flip kernel which used by reverse (#72945)
1 parent 614aab2 commit f1b794d

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

paddle/phi/kernels/cpu/flip_kernel.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ void FlipKernel(const Context& dev_ctx,
4242
auto numel = x.numel();
4343
const T* x_data = x.data<T>();
4444
T* out_data = dev_ctx.template Alloc<T>(out);
45+
if (out->numel() == 0) {
46+
return;
47+
}
4548
#ifdef PADDLE_WITH_MKLML
4649
#pragma omp parallel for
4750
#endif

paddle/phi/kernels/gpu/flip_kernel.cu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ void FlipKernel(const Context& dev_ctx,
6868
DenseTensor* out) {
6969
auto* in_data = x.data<T>();
7070
auto* out_data = dev_ctx.template Alloc<T>(out);
71+
if (out->numel() == 0) {
72+
return;
73+
}
7174

7275
auto x_dims = x.dims();
7376
const int rank = x_dims.size();

test/legacy_test/test_reverse_op.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@ def initTestCase(self):
9191
self.axis = [-1, -2]
9292

9393

94+
class TestCase4(TestReverseOp):
95+
def initTestCase(self):
96+
self.x = np.random.random((3, 0, 10)).astype('float64')
97+
self.axis = [1, 2]
98+
99+
100+
class TestCase5(TestReverseOp):
101+
def initTestCase(self):
102+
self.x = np.random.random((2, 0, 3)).astype('float32')
103+
self.axis = [0]
104+
105+
106+
class TestCase6(TestReverseOp):
107+
def initTestCase(self):
108+
self.x = np.random.random((2, 0, 0)).astype('float32')
109+
self.axis = [
110+
0,
111+
]
112+
113+
94114
if __name__ == '__main__':
95115
paddle.enable_static()
96116
unittest.main()

0 commit comments

Comments
 (0)