Skip to content
Open
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
4 changes: 2 additions & 2 deletions kernels/portable/cpu/op_constant_pad_nd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void apply_padding_to_dim(

size_t pad_before = 0;
size_t pad_after = 0;
if (pad_i >= 0 && pad_i < pad.size() / 2) {
if (pad_i < pad.size() / 2) {
pad_before = pad[2 * pad_i];
pad_after = pad[2 * pad_i + 1];
}
Expand Down Expand Up @@ -177,7 +177,7 @@ void constant_pad_nd_out_impl(
out_strides[i] = getTrailingDims(out, static_cast<int64_t>(i));

size_t pad_i = ndim - 1 - i;
if (pad_i >= 0 && pad_i < pad.size() / 2) {
if (pad_i < pad.size() / 2) {
if (pad[2 * pad_i] + pad[2 * pad_i + 1] > 0) {
last_padded_dim = i;
}
Expand Down
8 changes: 4 additions & 4 deletions kernels/portable/cpu/op_convolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ void conv2d_impl(
size_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 >= 0 && in_y < in_H) {
if (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;
in_coord[3] = in_x;

// Only proceed if input x coordinate is within bounds
if (in_x >= 0 && in_x < in_W) {
if (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 @@ -165,14 +165,14 @@ void conv2d_impl(
out_coord[2] = out_y;

// Only proceed if output y coordinate is within bounds
if (out_y >= 0 && out_y < out_H) {
if (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;
out_coord[3] = out_x;

// Only proceed if output x coordinate is within bounds
if (out_x >= 0 && out_x < out_W) {
if (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
4 changes: 2 additions & 2 deletions kernels/portable/cpu/util/kernel_ops_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ void kernel_reduction_then_map_2d(
size_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 >= 0 && in_x < in_W);
const bool y_in_bound = (in_y >= 0 && in_y < in_H);
const bool x_in_bound = (in_x < in_W);
const bool y_in_bound = (in_y < in_H);
const bool xy_in_bound = (x_in_bound && y_in_bound);

CTYPE in_val = 0;
Expand Down
23 changes: 19 additions & 4 deletions kernels/portable/cpu/util/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,20 @@ def define_common_targets():
":broadcast_util",
":dtype_util",
":vectorized_math",
"//executorch/runtime/core/portable_type/c10/c10:aten_headers_for_executorch",
"//executorch/runtime/kernel:kernel_runtime_context",
"//executorch/kernels/portable/cpu:scalar_utils",
"//executorch/extension/threadpool:threadpool",
"//executorch/kernels/portable/cpu:scalar_utils",
],
] + (select({
# Zephyr builds use -fno-exceptions → ET_HAS_EXCEPTIONS=0 →
# ET_USE_PYTORCH_HEADERS=0, so ATen vectorization is unused.
"ovr_config//os:zephyr": [],
"DEFAULT": [
"//executorch/runtime/core/portable_type/c10/c10:aten_headers_for_executorch",
],
}) if not runtime.is_oss else [
"//executorch/runtime/core/portable_type/c10/c10:aten_headers_for_executorch",
]),
deps = [
"//executorch/runtime/kernel:kernel_includes",
],
Expand Down Expand Up @@ -279,9 +287,16 @@ def define_common_targets():
srcs = [],
exported_headers = ["math_util.h"],
visibility = ["//executorch/kernels/portable/cpu/...", "//executorch/kernels/quantized/..."],
exported_deps = [
exported_deps = select({
# Zephyr builds use -fno-exceptions → ET_HAS_EXCEPTIONS=0 →
# ET_USE_PYTORCH_HEADERS=0, so ATen vectorization is unused.
"ovr_config//os:zephyr": [],
"DEFAULT": [
"//executorch/runtime/core/portable_type/c10/c10:aten_headers_for_executorch",
],
}) if not runtime.is_oss else [
"//executorch/runtime/core/portable_type/c10/c10:aten_headers_for_executorch",
],
],
)

runtime.cxx_library(
Expand Down
17 changes: 16 additions & 1 deletion runtime/core/portable_type/c10/c10/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ def define_common_targets():
else:
runtime.cxx_library(
name = "c10",
exported_deps = [":aten_headers_for_executorch"],
exported_deps = select({
"ovr_config//os:zephyr": [],
"DEFAULT": [":aten_headers_for_executorch"],
}),
xplat_exported_deps = select({
"ovr_config//os:zephyr": [
"fbsource//xplat/caffe2/c10:c10_headers",
],
"DEFAULT": [],
}),
fbcode_exported_deps = select({
"ovr_config//os:zephyr": [
"//caffe2/c10:c10_headers",
],
"DEFAULT": [],
}) if not runtime.is_oss else [],
visibility = ["PUBLIC"],
)
Loading