Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions kernels/portable/cpu/op_convolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ void conv2d_impl(
for (const auto w_y : c10::irange(w_H)) {
w_coord[2] = w_y;

size_t in_y = stride_y * out_y + dilation_y * w_y - padding_y;
ssize_t in_y = stride_y * out_y + dilation_y * w_y - padding_y;
in_coord[2] = in_y;
// Only proceed if input y coordinate is within bounds
if (in_y < in_H) {
if (in_y >= 0 && in_y < in_H) {
for (const auto w_x : c10::irange(w_W)) {
w_coord[3] = w_x;

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

// Only proceed if input x coordinate is within bounds
if (in_x < in_W) {
if (in_x >= 0 && in_x < in_W) {
size_t in_idx =
calculate_linear_index(in_coord, in_strides.data(), 4);
CTYPE in_val = in_ptr[in_idx];
Expand Down Expand Up @@ -161,18 +161,18 @@ void conv2d_impl(
w_coord[0] = in_c;
for (const auto w_y : c10::irange(w_H)) {
w_coord[2] = w_y;
size_t out_y = stride_y * in_y + dilation_y * w_y - padding_y;
ssize_t out_y = stride_y * in_y + dilation_y * w_y - padding_y;
out_coord[2] = out_y;

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

// Only proceed if output x coordinate is within bounds
if (out_x < out_W) {
if (out_x >= 0 && out_x < out_W) {
size_t w_idx =
calculate_linear_index(w_coord, w_strides.data(), 4);
CTYPE w_val = w_ptr[w_idx];
Expand Down
8 changes: 4 additions & 4 deletions kernels/portable/cpu/util/kernel_ops_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,19 @@ void kernel_reduction_then_map_2d(
int64_t padding_y = p_H;
int64_t dilation_y = d_H;

size_t in_y = stride_y * out_y + dilation_y * w_y - padding_y;
ssize_t in_y = stride_y * out_y + dilation_y * w_y - padding_y;
in_coord[in_dim - 2] = in_y;

for (const auto w_x : c10::irange(k_W)) {
int64_t stride_x = s_W;
int64_t padding_x = p_W;
int64_t dilation_x = d_W;

size_t in_x = stride_x * out_x + dilation_x * w_x - padding_x;
ssize_t in_x = stride_x * out_x + dilation_x * w_x - padding_x;
in_coord[in_dim - 1] = in_x;

const bool x_in_bound = (in_x < in_W);
const bool y_in_bound = (in_y < in_H);
const bool x_in_bound = (in_x >= 0 && in_x < in_W);
const bool y_in_bound = (in_y >= 0 && in_y < in_H);
const bool xy_in_bound = (x_in_bound && y_in_bound);

CTYPE in_val = 0;
Expand Down
Loading