Skip to content

Commit 2c298d6

Browse files
Fix cuda kernel of affine grid (#27004)
test=develop
1 parent 8cef2a7 commit 2c298d6

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

paddle/fluid/operators/affine_grid_op.cu

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ __global__ void affine_grid_kernel(const int count, int n, int out_h, int out_w,
6262

6363
int theta_offset = n * 6; // 2 * 3;
6464
// affine from (h_coor, w_coor) to (x, y)
65-
output[index * 2] = theta[theta_offset] * h_coor +
66-
theta[theta_offset + 1] * w_coor +
65+
output[index * 2] = theta[theta_offset] * w_coor +
66+
theta[theta_offset + 1] * h_coor +
6767
theta[theta_offset + 2];
68-
output[index * 2 + 1] = theta[theta_offset + 3] * h_coor +
69-
theta[theta_offset + 4] * w_coor +
68+
output[index * 2 + 1] = theta[theta_offset + 3] * w_coor +
69+
theta[theta_offset + 4] * h_coor +
7070
theta[theta_offset + 5];
7171
}
7272
}
@@ -86,13 +86,13 @@ __global__ void affine_grid_grad_kernel(const int count, int n, int out_h,
8686

8787
int theta_offset = n * 6; // 2 * 3;
8888
T out_grad_x = out_grad[index * 2];
89-
platform::CudaAtomicAdd(theta_grad + theta_offset, out_grad_x * h_coor);
90-
platform::CudaAtomicAdd(theta_grad + theta_offset + 1, out_grad_x * w_coor);
89+
platform::CudaAtomicAdd(theta_grad + theta_offset, out_grad_x * w_coor);
90+
platform::CudaAtomicAdd(theta_grad + theta_offset + 1, out_grad_x * h_coor);
9191
platform::CudaAtomicAdd(theta_grad + theta_offset + 2, out_grad_x);
9292

9393
T out_grad_y = out_grad[index * 2 + 1];
94-
platform::CudaAtomicAdd(theta_grad + theta_offset + 3, out_grad_y * h_coor);
95-
platform::CudaAtomicAdd(theta_grad + theta_offset + 4, out_grad_y * w_coor);
94+
platform::CudaAtomicAdd(theta_grad + theta_offset + 3, out_grad_y * w_coor);
95+
platform::CudaAtomicAdd(theta_grad + theta_offset + 4, out_grad_y * h_coor);
9696
platform::CudaAtomicAdd(theta_grad + theta_offset + 5, out_grad_y);
9797
}
9898
}

python/paddle/fluid/tests/unittests/test_affine_grid_op.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def setUp(self):
4949
self.initTestCase()
5050
self.op_type = "affine_grid"
5151
theta = np.random.randint(1, 3, self.theta_shape).astype("float32")
52-
theta = np.ones(self.theta_shape).astype("float32")
5352
self.inputs = {'Theta': theta}
5453
self.attrs = {
5554
"use_cudnn": self.use_cudnn,

0 commit comments

Comments
 (0)