Skip to content

Commit 9ac6f2f

Browse files
JakeStevensjpiat
authored andcommitted
Portable kernel fixes for sabaton tests (pytorch#18038)
Summary: When running in Sabaton Zephyr Posix tests, the compiler complains for things like ``` foo >= 0 && foo < bar ``` when foo is unsigned. Also avoid bringing in aten Reviewed By: rascani Differential Revision: D95834771
1 parent 3a59a56 commit 9ac6f2f

4 files changed

Lines changed: 41 additions & 11 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
size_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 < in_H) {
113113
for (const auto w_x : c10::irange(w_W)) {
114114
w_coord[3] = w_x;
115115

116116
size_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 < 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 < out_H) {
169169
for (const auto w_x : c10::irange(w_W)) {
170170
w_coord[3] = w_x;
171171
size_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 < 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ void kernel_reduction_then_map_2d(
229229
size_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 = (in_x < in_W);
233+
const bool y_in_bound = (in_y < in_H);
234234
const bool xy_in_bound = (x_in_bound && y_in_bound);
235235

236236
CTYPE in_val = 0;

kernels/portable/cpu/util/targets.bzl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,20 @@ def define_common_targets():
115115
":broadcast_util",
116116
":dtype_util",
117117
":vectorized_math",
118-
"//executorch/runtime/core/portable_type/c10/c10:aten_headers_for_executorch",
119118
"//executorch/runtime/kernel:kernel_runtime_context",
120119
"//executorch/kernels/portable/cpu:scalar_utils",
121120
"//executorch/extension/threadpool:threadpool",
122121
"//executorch/kernels/portable/cpu:scalar_utils",
123-
],
122+
] + (select({
123+
# Zephyr builds use -fno-exceptions → ET_HAS_EXCEPTIONS=0 →
124+
# ET_USE_PYTORCH_HEADERS=0, so ATen vectorization is unused.
125+
"ovr_config//os:zephyr": [],
126+
"DEFAULT": [
127+
"//executorch/runtime/core/portable_type/c10/c10:aten_headers_for_executorch",
128+
],
129+
}) if not runtime.is_oss else [
130+
"//executorch/runtime/core/portable_type/c10/c10:aten_headers_for_executorch",
131+
]),
124132
deps = [
125133
"//executorch/runtime/kernel:kernel_includes",
126134
],
@@ -279,9 +287,16 @@ def define_common_targets():
279287
srcs = [],
280288
exported_headers = ["math_util.h"],
281289
visibility = ["//executorch/kernels/portable/cpu/...", "//executorch/kernels/quantized/..."],
282-
exported_deps = [
290+
exported_deps = select({
291+
# Zephyr builds use -fno-exceptions → ET_HAS_EXCEPTIONS=0 →
292+
# ET_USE_PYTORCH_HEADERS=0, so ATen vectorization is unused.
293+
"ovr_config//os:zephyr": [],
294+
"DEFAULT": [
295+
"//executorch/runtime/core/portable_type/c10/c10:aten_headers_for_executorch",
296+
],
297+
}) if not runtime.is_oss else [
283298
"//executorch/runtime/core/portable_type/c10/c10:aten_headers_for_executorch",
284-
],
299+
],
285300
)
286301

287302
runtime.cxx_library(

runtime/core/portable_type/c10/c10/targets.bzl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,21 @@ def define_common_targets():
134134
else:
135135
runtime.cxx_library(
136136
name = "c10",
137-
exported_deps = [":aten_headers_for_executorch"],
137+
exported_deps = select({
138+
"ovr_config//os:zephyr": [],
139+
"DEFAULT": [":aten_headers_for_executorch"],
140+
}),
141+
xplat_exported_deps = select({
142+
"ovr_config//os:zephyr": [
143+
"fbsource//xplat/caffe2/c10:c10_headers",
144+
],
145+
"DEFAULT": [],
146+
}),
147+
fbcode_exported_deps = select({
148+
"ovr_config//os:zephyr": [
149+
"//caffe2/c10:c10_headers",
150+
],
151+
"DEFAULT": [],
152+
}) if not runtime.is_oss else [],
138153
visibility = ["PUBLIC"],
139154
)

0 commit comments

Comments
 (0)