Skip to content

Commit ad3f2b0

Browse files
committed
Fix more warnings on GCC
1 parent 9bc4b60 commit ad3f2b0

File tree

9 files changed

+46
-59
lines changed

9 files changed

+46
-59
lines changed

kernels/optimized/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ endif()
2424
set(_common_compile_options
2525
$<$<CXX_COMPILER_ID:MSVC>:/wd4996>
2626
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated-declarations>
27+
$<$<CXX_COMPILER_ID:GNU>:-Wno-psabi>
2728
)
2829

2930
# Note for apple platform we can rely on Accelerate framework Will come back to

kernels/optimized/cpu/op_add.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ Tensor& opt_add_out(
6767
CTYPE b_val = *b.const_data_ptr<CTYPE>();
6868

6969
using Vec = at::vec::Vectorized<CTYPE>;
70-
at::vec::map<CTYPE>(
71-
[alpha_val, b_val](Vec& x) { return x + Vec(alpha_val * b_val); },
70+
at::vec::map(
71+
[alpha_val, b_val](Vec x) { return x + Vec(alpha_val * b_val); },
7272
out.mutable_data_ptr<CTYPE>(),
7373
a.const_data_ptr<CTYPE>(),
7474
out.numel());
@@ -86,7 +86,7 @@ Tensor& opt_add_out(
8686
CTYPE b_casted = static_cast<CTYPE>(b_val);
8787

8888
using Vec = at::vec::Vectorized<CTYPE>;
89-
at::vec::map<CTYPE>(
89+
at::vec::map(
9090
[alpha_val, b_casted](Vec x) {
9191
return x + Vec(alpha_val * b_casted);
9292
},
@@ -140,7 +140,7 @@ Tensor& opt_add_scalar_out(
140140
ctx, utils::extract_scalar(alpha, &alpha_val), InvalidArgument, );
141141

142142
using Vec = at::vec::Vectorized<CTYPE>;
143-
at::vec::map<CTYPE>(
143+
at::vec::map(
144144
[alpha_val, b_casted](Vec x) {
145145
return x + Vec(alpha_val * b_casted);
146146
},

kernels/optimized/cpu/op_div.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ Tensor& opt_div_out(
8686

8787
using Vec = at::vec::Vectorized<CTYPE>;
8888
if (a.numel() == 1) {
89-
at::vec::map<CTYPE>(
90-
[scalar_casted](Vec& x) { return Vec(scalar_casted) / x; },
89+
at::vec::map(
90+
[scalar_casted](Vec x) { return Vec(scalar_casted) / x; },
9191
out.mutable_data_ptr<CTYPE>(),
9292
tensor->const_data_ptr<CTYPE>(),
9393
out.numel());
9494
} else {
9595
Vec inv_scalar_casted_vec(CTYPE(1) / scalar_casted);
96-
at::vec::map<CTYPE>(
97-
[inv_scalar_casted_vec](Vec& x) {
96+
at::vec::map(
97+
[inv_scalar_casted_vec](Vec x) {
9898
return x * inv_scalar_casted_vec;
9999
},
100100
out.mutable_data_ptr<CTYPE>(),
@@ -111,7 +111,7 @@ Tensor& opt_div_out(
111111
if (selected_optimized_path == ElementwiseOptimizedPath::kTreatAs1d) {
112112
ET_SWITCH_REALB_TYPES(out_type, ctx, op_name, CTYPE, [&]() {
113113
using Vec = at::vec::Vectorized<CTYPE>;
114-
at::vec::map2<CTYPE>(
114+
at::vec::map2(
115115
[](Vec x, Vec y) { return x / y; },
116116
out.mutable_data_ptr<CTYPE>(),
117117
a.const_data_ptr<CTYPE>(),
@@ -193,7 +193,7 @@ Tensor& opt_div_scalar_out(
193193

194194
using Vec = at::vec::Vectorized<CTYPE>;
195195
Vec inv_b_casted_vec(CTYPE(1) / b_casted);
196-
at::vec::map<CTYPE>(
196+
at::vec::map(
197197
[inv_b_casted_vec](Vec x) { return x * inv_b_casted_vec; },
198198
out.mutable_data_ptr<CTYPE>(),
199199
a.const_data_ptr<CTYPE>(),

kernels/optimized/cpu/op_elu.cpp

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
#include <ATen/native/cpu/Elu.h>
9+
#include <cmath>
1010

11+
#include <ATen/cpu/vec/functional.h>
12+
#include <ATen/cpu/vec/vec.h>
1113
#include <executorch/kernels/portable/cpu/scalar_utils.h>
1214
#include <executorch/runtime/kernel/kernel_includes.h>
13-
#include <executorch/runtime/kernel/thread_parallel_interface.h>
1415
#include <executorch/runtime/platform/assert.h>
1516

1617
namespace torch::executor::native {
@@ -31,38 +32,24 @@ void elu(
3132
const auto math_alpha = utils::scalar_to<MathT>(alpha);
3233
const auto math_scale = utils::scalar_to<MathT>(scale);
3334
const auto math_input_scale = utils::scalar_to<MathT>(input_scale);
34-
const auto scalar_func =
35-
at::native::get_scalar_elu_elementwise_func<CTYPE, MathT>(
36-
math_alpha, math_scale, math_input_scale);
37-
const auto vec_func = at::native::get_vectorized_elu_elementwise_func<CTYPE>(
38-
math_alpha, math_scale, math_input_scale);
3935

40-
::executorch::extension::parallel_for(
41-
0,
42-
out.numel(),
43-
::executorch::extension::internal::GRAIN_SIZE,
44-
[&](const auto begin, const auto end) {
45-
using Vec = at::vec::Vectorized<CTYPE>;
46-
const auto vectorized_begin =
47-
begin + (Vec::size() - begin % Vec::size()) % Vec::size();
48-
const auto vectorized_end = end - (end % Vec::size());
49-
// Scalar prologue.
50-
for (const auto idx : c10::irange(begin, vectorized_begin)) {
51-
out_data[idx] = scalar_func(in_data[idx]);
52-
}
36+
using Vec = at::vec::Vectorized<CTYPE>;
37+
at::vec::map(
38+
[math_alpha, math_scale, math_input_scale](Vec x) {
39+
auto scaled_input = x * Vec(static_cast<CTYPE>(math_input_scale));
40+
auto zero = Vec(static_cast<CTYPE>(0));
41+
auto one = Vec(static_cast<CTYPE>(1));
42+
auto alpha_vec = Vec(static_cast<CTYPE>(math_alpha));
43+
auto scale_vec = Vec(static_cast<CTYPE>(math_scale));
5344

54-
// Main vectorized loop.
55-
for (auto idx = vectorized_begin; idx < vectorized_end;
56-
idx += Vec::size()) {
57-
auto result_vec = vec_func(Vec::loadu(&in_data[idx]));
58-
result_vec.store(&out_data[idx]);
59-
}
60-
61-
// Scalar epilogue.
62-
for (const auto idx : c10::irange(vectorized_end, end)) {
63-
out_data[idx] = scalar_func(in_data[idx]);
64-
}
65-
});
45+
auto pos_mask = scaled_input > zero;
46+
auto neg_result = alpha_vec * ((scaled_input.exp()) - one);
47+
auto result = Vec::blendv(neg_result, scaled_input, pos_mask);
48+
return result * scale_vec;
49+
},
50+
out_data,
51+
in_data,
52+
out.numel());
6653
}
6754
} // namespace
6855

kernels/optimized/cpu/op_exp.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ void exp_data(
3535
const size_t numel,
3636
CTYPE_OUT* out_data) {
3737
using Vec = at::vec::Vectorized<CTYPE_IN>;
38-
at::vec::map<CTYPE_IN>(
39-
[](Vec& x) { return x.exp(); }, out_data, in_data, numel);
38+
at::vec::map([](Vec x) { return x.exp(); }, out_data, in_data, numel);
4039
}
4140

4241
/**

kernels/optimized/cpu/op_le.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ Tensor& opt_le_tensor_out(
4747
if (selected_optimized_path == ElementwiseOptimizedPath::kTreatAs1d) {
4848
ET_SWITCH_REALB_TYPES(a_type, ctx, op_name, CTYPE, [&]() {
4949
using Vec = at::vec::Vectorized<CTYPE>;
50-
at::vec::map2<CTYPE>(
51-
[](Vec& x, Vec& y) { return x.le(y); },
50+
at::vec::map2(
51+
[](Vec x, Vec y) { return x.le(y); },
5252
out.mutable_data_ptr<CTYPE>(),
5353
a.const_data_ptr<CTYPE>(),
5454
b.const_data_ptr<CTYPE>(),
@@ -95,7 +95,7 @@ Tensor& opt_le_scalar_out(
9595
ET_EXTRACT_SCALAR(b, b_val);
9696
CTYPE b_casted = static_cast<CTYPE>(b_val);
9797
using Vec = at::vec::Vectorized<CTYPE>;
98-
at::vec::map<CTYPE>(
98+
at::vec::map(
9999
[b_casted](Vec x) { return x.le(Vec(b_casted)); },
100100
out.mutable_data_ptr<CTYPE>(),
101101
a.const_data_ptr<CTYPE>(),

kernels/optimized/cpu/op_mul.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ Tensor& opt_mul_out(
5555
CTYPE b_casted = static_cast<CTYPE>(b_val);
5656

5757
using Vec = at::vec::Vectorized<CTYPE>;
58-
at::vec::map<CTYPE>(
59-
[b_casted](Vec& x) { return x * Vec(b_casted); },
58+
at::vec::map(
59+
[b_casted](Vec x) { return x * Vec(b_casted); },
6060
out.mutable_data_ptr<CTYPE>(),
6161
a.const_data_ptr<CTYPE>(),
6262
out.numel());
@@ -76,7 +76,7 @@ Tensor& opt_mul_out(
7676

7777
ET_SWITCH_COMPLEXH_TYPES(out_type, ctx, op_name, CTYPE, [&]() {
7878
using Vec = at::vec::Vectorized<CTYPE>;
79-
at::vec::map2<CTYPE>(
79+
at::vec::map2(
8080
[](Vec x, Vec y) { return x * y; },
8181
out.mutable_data_ptr<CTYPE>(),
8282
a.const_data_ptr<CTYPE>(),
@@ -86,7 +86,7 @@ Tensor& opt_mul_out(
8686
} else {
8787
ET_SWITCH_REALB_TYPES(out_type, ctx, op_name, CTYPE, [&]() {
8888
using Vec = at::vec::Vectorized<CTYPE>;
89-
at::vec::map2<CTYPE>(
89+
at::vec::map2(
9090
[](Vec x, Vec y) { return x * y; },
9191
out.mutable_data_ptr<CTYPE>(),
9292
a.const_data_ptr<CTYPE>(),
@@ -173,7 +173,7 @@ Tensor& opt_mul_scalar_out(
173173
CTYPE b_casted = utils::scalar_to<CTYPE>(b);
174174

175175
using Vec = at::vec::Vectorized<CTYPE>;
176-
at::vec::map<CTYPE>(
176+
at::vec::map(
177177
[b_casted](Vec x) { return x * Vec(b_casted); },
178178
out.mutable_data_ptr<CTYPE>(),
179179
a.const_data_ptr<CTYPE>(),

kernels/optimized/cpu/op_native_layer_norm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ void layer_norm(
9191
dst_ptr[j] = (src_ptr[j] * scale + offset) * gamma_v + beta_v;
9292
}
9393
} else {
94-
at::vec::map3<CTYPE>(
95-
[scale, offset](auto& x, auto& gamma, auto& beta) {
94+
at::vec::map3(
95+
[scale, offset](auto x, auto gamma, auto beta) {
9696
using Vec = decltype(x);
9797
return (x * Vec(scale) + Vec(offset)) * gamma + beta;
9898
},

kernels/optimized/cpu/op_sub.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ Tensor& opt_sub_out(
8585

8686
using Vec = at::vec::Vectorized<CTYPE>;
8787
if (a.numel() == 1) {
88-
at::vec::map<CTYPE>(
89-
[alpha_val, scalar_casted](Vec& x) {
88+
at::vec::map(
89+
[alpha_val, scalar_casted](Vec x) {
9090
return Vec(scalar_casted) - Vec(alpha_val) * x;
9191
},
9292
out.mutable_data_ptr<CTYPE>(),
9393
tensor->const_data_ptr<CTYPE>(),
9494
out.numel());
9595
} else {
96-
at::vec::map<CTYPE>(
97-
[alpha_val, scalar_casted](Vec& x) {
96+
at::vec::map(
97+
[alpha_val, scalar_casted](Vec x) {
9898
return x - Vec(alpha_val * scalar_casted);
9999
},
100100
out.mutable_data_ptr<CTYPE>(),
@@ -148,7 +148,7 @@ Tensor& opt_sub_scalar_out(
148148
ctx, utils::extract_scalar(alpha, &alpha_val), InvalidArgument, );
149149

150150
using Vec = at::vec::Vectorized<CTYPE>;
151-
at::vec::map<CTYPE>(
151+
at::vec::map(
152152
[alpha_val, b_casted](Vec x) {
153153
return x - Vec(alpha_val * b_casted);
154154
},

0 commit comments

Comments
 (0)