Skip to content

Commit c100790

Browse files
committed
Fix portable library build on Windows
ghstack-source-id: 9c69a79 ghstack-comment-id: 3172145648 Pull-Request: #13260
1 parent d0e780b commit c100790

File tree

13 files changed

+59
-72
lines changed

13 files changed

+59
-72
lines changed

.lintrunner.toml

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -335,59 +335,6 @@ command = [
335335
'@{{PATHSFILE}}',
336336
]
337337

338-
[[linter]]
339-
code = 'MYPY'
340-
include_patterns = [
341-
# TODO(https://github.com/pytorch/executorch/issues/7441): Gradually start enabling all folders.
342-
# 'backends/**/*.py',
343-
'backends/arm/**/*.py',
344-
'backends/openvino/**/*.py',
345-
'build/**/*.py',
346-
'codegen/**/*.py',
347-
# 'devtools/**/*.py',
348-
'devtools/visualization/**/*.py',
349-
'docs/**/*.py',
350-
# 'examples/**/*.py',
351-
'examples/openvino/**/*.py',
352-
# 'exir/**/*.py',
353-
# 'extension/**/*.py',
354-
'kernels/**/*.py',
355-
'profiler/**/*.py',
356-
'runtime/**/*.py',
357-
'scripts/**/*.py',
358-
'test/**/*.py',
359-
'util/**/*.py',
360-
'*.py',
361-
]
362-
exclude_patterns = [
363-
'third-party/**',
364-
'**/third-party/**',
365-
'scripts/check_binary_dependencies.py',
366-
'profiler/test/test_profiler_e2e.py',
367-
'backends/arm/test/**',
368-
]
369-
command = [
370-
'python',
371-
'-m',
372-
'lintrunner_adapters',
373-
'run',
374-
'mypy_linter',
375-
'--config=.mypy.ini',
376-
'--show-disable',
377-
'--',
378-
'--explicit-package-bases',
379-
'@{{PATHSFILE}}'
380-
]
381-
init_command = [
382-
'python',
383-
'-m',
384-
'lintrunner_adapters',
385-
'run',
386-
'pip_init',
387-
'--dry-run={{DRYRUN}}',
388-
'--requirement=requirements-lintrunner.txt',
389-
]
390-
391338
[[linter]]
392339
code = 'LICENSELINT'
393340
include_patterns = [

kernels/portable/cpu/op_amax.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <c10/util/irange.h>
1010
#include <cmath>
1111

12+
#include <executorch/kernels/portable/cpu/util/math_util.h>
1213
#include <executorch/kernels/portable/cpu/util/reduce_util.h>
1314
#include <executorch/runtime/kernel/kernel_includes.h>
1415
#include <executorch/runtime/platform/assert.h>
@@ -55,7 +56,7 @@ Tensor& amax_out(
5556
for (const auto out_ix : c10::irange(begin, end)) {
5657
out_data[out_ix] = plan.execute<CTYPE>(
5758
[](CTYPE v, CTYPE max_v) {
58-
return std::isnan(v) || v > max_v ? v : max_v;
59+
return utils::isnan_override(v) || v > max_v ? v : max_v;
5960
},
6061
out_ix);
6162
}

kernels/portable/cpu/op_amin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <c10/util/irange.h>
99
#include <cmath>
1010

11+
#include <executorch/kernels/portable/cpu/util/math_util.h>
1112
#include <executorch/kernels/portable/cpu/util/reduce_util.h>
1213
#include <executorch/runtime/kernel/kernel_includes.h>
1314
#include <executorch/runtime/platform/assert.h>
@@ -54,7 +55,7 @@ Tensor& amin_out(
5455
for (const auto out_ix : c10::irange(begin, end)) {
5556
out_data[out_ix] = plan.execute<CTYPE>(
5657
[](CTYPE v, CTYPE min_v) {
57-
return std::isnan(v) || v < min_v ? v : min_v;
58+
return utils::isnan_override(v) || v < min_v ? v : min_v;
5859
},
5960
out_ix);
6061
}

kernels/portable/cpu/op_argmax.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <cmath>
1111
#include <tuple>
1212

13+
#include <executorch/kernels/portable/cpu/util/math_util.h>
1314
#include <executorch/kernels/portable/cpu/util/reduce_util.h>
1415
#include <executorch/runtime/kernel/kernel_includes.h>
1516
#include <executorch/runtime/platform/assert.h>
@@ -58,7 +59,7 @@ Tensor& argmax_out(
5859
// the below condition as written is equivalent to
5960
// !isnan(accval) && (isnan(v) || v > acc_val). See
6061
// argument in op_argmin.cpp.
61-
if (!std::isnan(acc_val) && !(v <= acc_val)) {
62+
if (!utils::isnan_override(acc_val) && !(v <= acc_val)) {
6263
acc_val = v;
6364
acc_ix = ix;
6465
}

kernels/portable/cpu/op_argmin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <cmath>
1111
#include <tuple>
1212

13+
#include <executorch/kernels/portable/cpu/util/math_util.h>
1314
#include <executorch/kernels/portable/cpu/util/reduce_util.h>
1415
#include <executorch/runtime/kernel/kernel_includes.h>
1516
#include <executorch/runtime/platform/assert.h>
@@ -65,7 +66,7 @@ Tensor& argmin_out(
6566
// - false, so the result is true. The result is trivially
6667
// - true for the above condition that uses isnan(v) as
6768
// - well.
68-
if (!std::isnan(acc_val) && !(v >= acc_val)) {
69+
if (!utils::isnan_override(acc_val) && !(v >= acc_val)) {
6970
acc_val = v;
7071
acc_ix = ix;
7172
}

kernels/portable/cpu/op_max.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <cmath>
1111
#include <tuple>
1212

13+
#include <executorch/kernels/portable/cpu/util/math_util.h>
1314
#include <executorch/kernels/portable/cpu/util/reduce_util.h>
1415
#include <executorch/runtime/kernel/kernel_includes.h>
1516
#include <executorch/runtime/platform/assert.h>
@@ -88,8 +89,8 @@ std::tuple<Tensor&, Tensor&> max_out(
8889
for (const auto out_ix : c10::irange(begin, end)) {
8990
std::tuple<CTYPE, long> acc = reduce_over_dim<CTYPE>(
9091
[](CTYPE v, long ix, CTYPE acc_val, long acc_ix) {
91-
if (!std::isnan(acc_val) &&
92-
(std::isnan(v) || v > acc_val)) {
92+
if (!utils::isnan_override(acc_val) &&
93+
(utils::isnan_override(v) || v > acc_val)) {
9394
acc_val = v;
9495
acc_ix = ix;
9596
}
@@ -132,7 +133,7 @@ max_unary_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
132133
data_out[0] = lower_bound<CTYPE_OUT>();
133134
for (const auto i : c10::irange(in.numel())) {
134135
CTYPE_OUT val = static_cast<CTYPE_OUT>(data_in[i]);
135-
if (std::isnan(val)) {
136+
if (utils::isnan_override(val)) {
136137
data_out[0] = val;
137138
break;
138139
}

kernels/portable/cpu/op_min.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <cmath>
1111
#include <tuple>
1212

13+
#include <executorch/kernels/portable/cpu/util/math_util.h>
1314
#include <executorch/kernels/portable/cpu/util/reduce_util.h>
1415
#include <executorch/runtime/kernel/kernel_includes.h>
1516
#include <executorch/runtime/platform/assert.h>
@@ -88,8 +89,8 @@ std::tuple<Tensor&, Tensor&> min_out(
8889
for (const auto out_ix : c10::irange(begin, end)) {
8990
std::tuple<CTYPE, long> acc = reduce_over_dim<CTYPE>(
9091
[](CTYPE v, long ix, CTYPE acc_val, long acc_ix) {
91-
if (!std::isnan(acc_val) &&
92-
(std::isnan(v) || v < acc_val)) {
92+
if (!utils::isnan_override(acc_val) &&
93+
(utils::isnan_override(v) || v < acc_val)) {
9394
acc_val = v;
9495
acc_ix = ix;
9596
}
@@ -132,7 +133,7 @@ min_unary_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
132133
data_out[0] = upper_bound<CTYPE_OUT>();
133134
for (const auto i : c10::irange(in.numel())) {
134135
CTYPE_OUT val = static_cast<CTYPE_OUT>(data_in[i]);
135-
if (std::isnan(val)) {
136+
if (utils::isnan_override(val)) {
136137
data_out[0] = val;
137138
break;
138139
}

kernels/portable/cpu/op_relu.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <cmath>
1010

1111
#include <executorch/kernels/portable/cpu/util/functional_util.h>
12+
#include <executorch/kernels/portable/cpu/util/math_util.h>
1213
#include <executorch/runtime/kernel/kernel_includes.h>
1314
#include <executorch/runtime/platform/assert.h>
1415

@@ -45,7 +46,9 @@ Tensor& relu_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
4546
ET_SWITCH_REALHBF16_TYPES(in.scalar_type(), ctx, "relu.out", CTYPE, [&]() {
4647
apply_unary_map_fn(
4748
[](const CTYPE val_in) {
48-
return (std::isnan(val_in) || val_in >= CTYPE(0)) ? val_in : CTYPE(0);
49+
return (utils::isnan_override(val_in) || val_in >= CTYPE(0))
50+
? val_in
51+
: CTYPE(0);
4952
},
5053
in.const_data_ptr<CTYPE>(),
5154
out.mutable_data_ptr<CTYPE>(),

kernels/portable/cpu/op_sign.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <cstring>
1111

1212
#include <executorch/kernels/portable/cpu/util/functional_util.h>
13+
#include <executorch/kernels/portable/cpu/util/math_util.h>
1314
#include <executorch/runtime/kernel/kernel_includes.h>
1415
#include <executorch/runtime/platform/assert.h>
1516

@@ -42,7 +43,7 @@ Tensor& sign_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
4243
ET_SWITCH_REALHBF16_TYPES(in.scalar_type(), ctx, "sign.out", CTYPE, [&] {
4344
apply_unary_map_fn(
4445
[](const CTYPE val_in) {
45-
if (std::isnan(val_in)) {
46+
if (utils::isnan_override(val_in)) {
4647
return val_in;
4748
} else {
4849
return static_cast<CTYPE>((val_in > 0) - (val_in < 0));

kernels/portable/cpu/op_topk.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <cmath>
1111
#include <tuple>
1212

13+
#include <executorch/kernels/portable/cpu/util/math_util.h>
14+
#include <executorch/runtime/core/exec_aten/exec_aten.h>
1315
#include <executorch/runtime/kernel/kernel_includes.h>
1416

1517
namespace torch {
@@ -62,7 +64,7 @@ bool float_less_than(T x, T y) {
6264
if constexpr (std::is_integral_v<T>) {
6365
return x < y;
6466
}
65-
return (!std::isnan(x) && std::isnan(y)) || x < y;
67+
return (!utils::isnan_override(x) && utils::isnan_override(y)) || x < y;
6668
}
6769

6870
template <typename CTYPE, typename elem_t = std::pair<CTYPE, int64_t>>

0 commit comments

Comments
 (0)