Skip to content

Commit c013c5f

Browse files
authored
cast bounds check to ssize_t (#18162)
Differential Revision: D96500399 Pull Request resolved: #18162
1 parent a391d67 commit c013c5f

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

kernels/portable/cpu/op_convolution.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ void conv2d_impl(
109109
ssize_t in_y = stride_y * out_y + dilation_y * w_y - padding_y;
110110
in_coord[2] = in_y;
111111
// Only proceed if input y coordinate is within bounds
112-
if (in_y >= 0 && in_y < in_H) {
112+
if (in_y >= 0 && in_y < static_cast<ssize_t>(in_H)) {
113113
for (const auto w_x : c10::irange(w_W)) {
114114
w_coord[3] = w_x;
115115

116116
ssize_t in_x = stride_x * out_x + dilation_x * w_x - padding_x;
117117
in_coord[3] = in_x;
118118

119119
// Only proceed if input x coordinate is within bounds
120-
if (in_x >= 0 && in_x < in_W) {
120+
if (in_x >= 0 && in_x < static_cast<ssize_t>(in_W)) {
121121
size_t in_idx =
122122
calculate_linear_index(in_coord, in_strides.data(), 4);
123123
CTYPE in_val = in_ptr[in_idx];
@@ -165,14 +165,14 @@ void conv2d_impl(
165165
out_coord[2] = out_y;
166166

167167
// Only proceed if output y coordinate is within bounds
168-
if (out_y >= 0 && out_y < out_H) {
168+
if (out_y >= 0 && out_y < static_cast<ssize_t>(out_H)) {
169169
for (const auto w_x : c10::irange(w_W)) {
170170
w_coord[3] = w_x;
171171
ssize_t out_x = stride_x * in_x + dilation_x * w_x - padding_x;
172172
out_coord[3] = out_x;
173173

174174
// Only proceed if output x coordinate is within bounds
175-
if (out_x >= 0 && out_x < out_W) {
175+
if (out_x >= 0 && out_x < static_cast<ssize_t>(out_W)) {
176176
size_t w_idx =
177177
calculate_linear_index(w_coord, w_strides.data(), 4);
178178
CTYPE w_val = w_ptr[w_idx];

kernels/portable/cpu/util/kernel_ops_util.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,10 @@ void kernel_reduction_then_map_2d(
229229
ssize_t in_x = stride_x * out_x + dilation_x * w_x - padding_x;
230230
in_coord[in_dim - 1] = in_x;
231231

232-
const bool x_in_bound = (in_x >= 0 && in_x < in_W);
233-
const bool y_in_bound = (in_y >= 0 && in_y < in_H);
232+
const bool x_in_bound =
233+
(in_x >= 0 && in_x < static_cast<ssize_t>(in_W));
234+
const bool y_in_bound =
235+
(in_y >= 0 && in_y < static_cast<ssize_t>(in_H));
234236
const bool xy_in_bound = (x_in_bound && y_in_bound);
235237

236238
CTYPE in_val = 0;

0 commit comments

Comments
 (0)