Skip to content

Commit 4e89e2a

Browse files
committed
fixed lint issues.
1 parent 605f374 commit 4e89e2a

File tree

9 files changed

+792
-117
lines changed

9 files changed

+792
-117
lines changed

1.txt

Lines changed: 676 additions & 0 deletions
Large diffs are not rendered by default.

backends/cadence/cadence.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ set(CMAKE_CXX_COMPILER ${TOOLCHAIN_HOME}/bin/${CROSS_COMPILE_TARGET}-clang++)
4444
set(CMAKE_C_FLAGS_INIT "-stdlib=libc++ -mtext-section-literals -mlongcalls")
4545
set(CMAKE_CXX_FLAGS_INIT "-stdlib=libc++ -mtext-section-literals -mlongcalls")
4646
#workaround for larger compilation time
47-
SET(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -fno-strict-aliasing")
47+
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -fno-strict-aliasing")
4848

4949
set(CMAKE_SYSROOT ${TOOLCHAIN_HOME}/${SYSROOT_TARGET})
5050
set(CMAKE_LINKER ${TOOLCHAIN_HOME}/bin/xt-ld)

backends/cadence/hifi/kernels/kernels.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,24 @@
1616
#include "xa_nnlib_kernels_api.h"
1717

1818
/* Potential NNLIB function/APIs */
19-
extern "C" WORD32 xa_nn_elm_add_broadcast_4D_f32xf32_f32(FLOAT32 * __restrict__ p_out,
19+
extern "C" WORD32 xa_nn_elm_add_broadcast_4D_f32xf32_f32(
20+
FLOAT32 * __restrict__ p_out,
2021
const WORD32 *const p_out_shape,
2122
const FLOAT32 * __restrict__ p_inp1,
2223
const WORD32 *const p_inp1_shape,
2324
const FLOAT32 * __restrict__ p_inp2,
2425
const WORD32 *const p_inp2_shape);
2526

26-
extern "C" WORD32 xa_nn_elm_div_broadcast_4D_f32xf32_f32(FLOAT32 * __restrict__ p_out,
27+
extern "C" WORD32 xa_nn_elm_div_broadcast_4D_f32xf32_f32(
28+
FLOAT32 * __restrict__ p_out,
2729
const WORD32 *const p_out_shape,
2830
const FLOAT32 * __restrict__ p_inp1,
2931
const WORD32 *const p_inp1_shape,
3032
const FLOAT32 * __restrict__ p_inp2,
3133
const WORD32 *const p_inp2_shape);
3234

33-
extern "C" WORD32 xa_nn_elm_div_mode_f32xf32_f32(FLOAT32 * __restrict__ p_out,
35+
extern "C" WORD32 xa_nn_elm_div_mode_f32xf32_f32(
36+
FLOAT32 * __restrict__ p_out,
3437
const FLOAT32 * __restrict__ p_inp1,
3538
const FLOAT32 * __restrict__ p_inp2,
3639
WORD32 num_elm,
@@ -45,7 +48,8 @@ extern "C" WORD32 xa_nn_elm_div_mode_broadcast_4D_f32xf32_f32(
4548
const WORD32 *const p_inp2_shape,
4649
WORD32 mode);
4750

48-
extern "C" WORD32 xa_nn_elm_mul_broadcast_4D_f32xf32_f32(FLOAT32 * __restrict__ p_out,
51+
extern "C" WORD32 xa_nn_elm_mul_broadcast_4D_f32xf32_f32(
52+
FLOAT32 * __restrict__ p_out,
4953
const WORD32 *const p_out_shape,
5054
const FLOAT32 * __restrict__ p_inp1,
5155
const WORD32 *const p_inp1_shape,

backends/cadence/hifi/operators/op_add.cpp

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

9+
#include <executorch/backends/cadence/hifi/kernels/kernels.h>
910
#include <executorch/kernels/portable/cpu/scalar_utils.h>
1011
#include <executorch/kernels/portable/cpu/util/broadcast_util.h>
1112
#include <executorch/kernels/portable/cpu/util/functional_util.h>
1213
#include <executorch/kernels/portable/cpu/util/kernel_ops_util.h>
1314
#include <executorch/runtime/kernel/kernel_includes.h>
1415
#include <executorch/runtime/platform/assert.h>
15-
#include <executorch/backends/cadence/hifi/kernels/kernels.h>
1616

1717
using exec_aten::Scalar;
1818
using exec_aten::ScalarType;
@@ -23,7 +23,7 @@ using executorch::runtime::KernelRuntimeContext;
2323
using torch::executor::Error;
2424

2525
namespace impl {
26-
namespace HiFi {
26+
namespace HiFi {
2727
namespace native {
2828

2929
namespace {
@@ -97,14 +97,15 @@ Tensor& add_out(
9797

9898
ScalarType a_type = a.scalar_type();
9999
ScalarType b_type = b.scalar_type();
100-
ScalarType alpha_type = torch::executor::native::utils::get_scalar_dtype(alpha);
100+
ScalarType alpha_type =
101+
torch::executor::native::utils::get_scalar_dtype(alpha);
101102
ScalarType common_type = promoteTypes(a_type, b_type, /*half_to_float*/ true);
102103
ScalarType out_type = out.scalar_type();
103104

104105
ET_KERNEL_CHECK(ctx, canCast(common_type, out_type), InvalidArgument, out);
105106
ET_KERNEL_CHECK(
106107
ctx, check_alpha_type(alpha_type, common_type), InvalidArgument, out);
107-
108+
108109
float alpha_val;
109110
torch::executor::native::utils::extract_scalar(alpha, &alpha_val);
110111

@@ -119,30 +120,28 @@ Tensor& add_out(
119120
const bool broadcast = (a_is_broadcasted || b_is_broadcasted);
120121
int max_dim = a.dim() > b.dim() ? a.dim() : b.dim();
121122
max_dim = out.dim() > max_dim ? out.dim() : max_dim;
122-
123-
if((out_type != ScalarType::Float) || (alpha_val != 1.0))
123+
124+
if ((out_type != ScalarType::Float) || (alpha_val != 1.0))
124125
optimized = 0;
125-
126-
if((a_dim == 0) || (b_dim == 0) )
126+
127+
if ((a_dim == 0) || (b_dim == 0) )
127128
optimized = 0;
128129

129-
if((broadcast == 1) && (max_dim > kNnlibMaxDim))
130+
if ((broadcast == 1) && (max_dim > kNnlibMaxDim))
130131
optimized = 0;
131132

132133

133-
if(optimized)
134-
{
134+
if (optimized) {
135135
const float* const a_data = a.const_data_ptr<float>();
136136
const float* const b_data = b.const_data_ptr<float>();
137137
float* const out_data = out.mutable_data_ptr<float>();
138-
if(broadcast == 1)
139-
{
138+
139+
if(broadcast == 1) {
140140
int out_shape[kNnlibMaxDim];
141141
int inp1_shape[kNnlibMaxDim];
142142
int inp2_shape[kNnlibMaxDim];
143143

144-
for(int i = 0; i < kNnlibMaxDim; i++)
145-
{
144+
for (int i = 0; i < kNnlibMaxDim; i++) {
146145
out_shape[i] = 1;
147146
inp1_shape[i] = 1;
148147
inp2_shape[i] = 1;
@@ -152,15 +151,15 @@ Tensor& add_out(
152151
int off_a = kNnlibMaxDim - a.dim();
153152
int off_b = kNnlibMaxDim - b.dim();
154153

155-
for(int i = 0; i < out.dim(); i++)
154+
for (int i = 0; i < out.dim(); i++)
156155
out_shape[i+off_o] = out.size(i);
157-
for(int i = 0; i < a.dim(); i++)
156+
for (int i = 0; i < a.dim(); i++)
158157
inp1_shape[i+off_a] = a.size(i);
159-
for(int i = 0; i < b.dim(); i++)
158+
for (int i = 0; i < b.dim(); i++)
160159
inp2_shape[i+off_b] = b.size(i);
161160

162-
xa_nn_elm_add_broadcast_4D_f32xf32_f32(out_data, out_shape, a_data, inp1_shape,
163-
b_data, inp2_shape);
161+
xa_nn_elm_add_broadcast_4D_f32xf32_f32(
162+
out_data, out_shape, a_data, inp1_shape, b_data, inp2_shape);
164163
}
165164
else
166165
{
@@ -193,6 +192,6 @@ Tensor& add_out(
193192
}
194193

195194

196-
} // namespace impl
197-
} // namespace HiFi
198195
} // namespace native
196+
} // namespace HiFi
197+
} // namespace impl

backends/cadence/hifi/operators/op_div.cpp

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

9+
#include <executorch/backends/cadence/hifi/kernels/kernels.h>
910
#include <executorch/kernels/portable/cpu/scalar_utils.h>
1011
#include <executorch/kernels/portable/cpu/util/broadcast_util.h>
1112
#include <executorch/kernels/portable/cpu/util/functional_util.h>
1213
#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
#include <cmath>
16-
#include <executorch/backends/cadence/hifi/kernels/kernels.h>
1717

1818
using exec_aten::Scalar;
1919
using exec_aten::ScalarType;
@@ -22,7 +22,7 @@ using executorch::aten::RuntimeContext;
2222
using torch::executor::Error;
2323

2424
namespace impl {
25-
namespace HiFi {
25+
namespace HiFi {
2626
namespace native {
2727

2828
namespace {
@@ -74,29 +74,27 @@ div_out(RuntimeContext& ctx, const Tensor& a, const Tensor& b, Tensor& out) {
7474
int max_dim = a.dim() > b.dim() ? a.dim() : b.dim();
7575
max_dim = out.dim() > max_dim ? out.dim() : max_dim;
7676

77-
if((a_type != ScalarType::Float) || (b_type != ScalarType::Float))
77+
if ((a_type != ScalarType::Float) || (b_type != ScalarType::Float))
7878
optimized = 0;
7979

80-
if((a_dim == 0) || (b_dim == 0) )
80+
if ((a_dim == 0) || (b_dim == 0) )
8181
optimized = 0;
8282

83-
if((broadcast == 1) && (max_dim > kNnlibMaxDim))
83+
if ((broadcast == 1) && (max_dim > kNnlibMaxDim))
8484
optimized = 0;
8585

86-
if(optimized)
87-
{
86+
if (optimized) {
8887
float* a_data = a.mutable_data_ptr<float>();
8988
float* b_data = b.mutable_data_ptr<float>();
9089
float* out_data = out.mutable_data_ptr<float>();
9190

92-
if(broadcast == 1)
93-
{
91+
if (broadcast == 1) {
9492

9593
int out_shape[kNnlibMaxDim];
9694
int inp1_shape[kNnlibMaxDim];
9795
int inp2_shape[kNnlibMaxDim];
9896

99-
for(int i = 0; i < kNnlibMaxDim; i++)
97+
for (int i = 0; i < kNnlibMaxDim; i++)
10098
{
10199
out_shape[i] = 1;
102100
inp1_shape[i] = 1;
@@ -106,34 +104,35 @@ div_out(RuntimeContext& ctx, const Tensor& a, const Tensor& b, Tensor& out) {
106104
int off_o = kNnlibMaxDim - out.dim();
107105
int off_a = kNnlibMaxDim - a.dim();
108106
int off_b = kNnlibMaxDim - b.dim();
109-
for(int i = 0; i < out.dim(); i++)
107+
for (int i = 0; i < out.dim(); i++)
110108
out_shape[i+off_o] = out.size(i);
111-
for(int i = 0; i < a.dim(); i++)
109+
for (int i = 0; i < a.dim(); i++)
112110
inp1_shape[i+off_a] = a.size(i);
113-
for(int i = 0; i < b.dim(); i++)
111+
for (int i = 0; i < b.dim(); i++)
114112
inp2_shape[i+off_b] = b.size(i);
115113

116-
xa_nn_elm_div_broadcast_4D_f32xf32_f32(out_data, out_shape, a_data, inp1_shape, b_data, inp2_shape);
114+
xa_nn_elm_div_broadcast_4D_f32xf32_f32(
115+
out_data, out_shape, a_data, inp1_shape, b_data, inp2_shape);
117116
}
118117
else
119118
{
120-
121119
xa_nn_elm_div_f32xf32_f32(out_data, a_data, b_data, out.numel());
122120
}
123-
121+
124122
return out;
125123
}
126-
124+
127125
ScalarType common_type = get_compute_type(a_type, b_type);
128126
ScalarType out_type = out.scalar_type();
129-
127+
130128
ET_KERNEL_CHECK(ctx, canCast(common_type, out_type), InvalidArgument, out);
131-
129+
132130
ET_SWITCH_REAL_TYPES_AND(Bool, a_type, ctx, "div.out", CTYPE_A, [&]() {
133131
ET_SWITCH_REAL_TYPES_AND(Bool, b_type, ctx, "div.out", CTYPE_B, [&]() {
134132
ET_SWITCH_FLOAT_TYPES(common_type, ctx, "div.out", CTYPE_IN, [&]() {
135133
ET_SWITCH_FLOAT_TYPES(out_type, ctx, "div.out", CTYPE_OUT, [&]() {
136-
torch::executor::apply_binary_elementwise_fn<CTYPE_A, CTYPE_B, CTYPE_OUT>(
134+
torch::executor::
135+
apply_binary_elementwise_fn<CTYPE_A, CTYPE_B, CTYPE_OUT>(
137136
[](const CTYPE_A val_a, const CTYPE_B val_b) {
138137
CTYPE_IN a_casted = static_cast<CTYPE_IN>(val_a);
139138
CTYPE_IN b_casted = static_cast<CTYPE_IN>(val_b);
@@ -188,13 +187,13 @@ Tensor& div_out_mode(
188187
int max_dim = a.dim() > b.dim() ? a.dim() : b.dim();
189188
max_dim = out.dim() > max_dim ? out.dim() : max_dim;
190189

191-
if((a_type != ScalarType::Float) || (b_type != ScalarType::Float))
190+
if ((a_type != ScalarType::Float) || (b_type != ScalarType::Float))
192191
optimized = 0;
193192

194-
if((a_dim == 0) || (b_dim == 0))
193+
if ((a_dim == 0) || (b_dim == 0))
195194
optimized = 0;
196195

197-
if((broadcast == 1) && (max_dim > kNnlibMaxDim))
196+
if ((broadcast == 1) && (max_dim > kNnlibMaxDim))
198197
optimized = 0;
199198
int mode_val = -1;
200199
if (mode.has_value() && mode.value() == "trunc")
@@ -204,20 +203,17 @@ Tensor& div_out_mode(
204203
else
205204
optimized = 0;
206205

207-
if(optimized)
208-
{
206+
if (optimized) {
209207
float* a_data = a.mutable_data_ptr<float>();
210208
float* b_data = b.mutable_data_ptr<float>();
211209
float* out_data = out.mutable_data_ptr<float>();
212210

213-
if(broadcast)
214-
{
211+
if (broadcast) {
215212
int out_shape[kNnlibMaxDim];
216213
int inp1_shape[kNnlibMaxDim];
217214
int inp2_shape[kNnlibMaxDim];
218215

219-
for(int i = 0; i < kNnlibMaxDim; i++)
220-
{
216+
for (int i = 0; i < kNnlibMaxDim; i++) {
221217
inp1_shape[i] = 1;
222218
inp2_shape[i] = 1;
223219
out_shape[i] = 1;
@@ -227,18 +223,20 @@ Tensor& div_out_mode(
227223
int off_a = kNnlibMaxDim - a.dim();
228224
int off_b = kNnlibMaxDim - b.dim();
229225

230-
for(int i = 0; i < out.dim(); i++)
226+
for (int i = 0; i < out.dim(); i++)
231227
out_shape[i+off_o] = out.size(i);
232-
for(int i = 0; i < a.dim(); i++)
228+
for (int i = 0; i < a.dim(); i++)
233229
inp1_shape[i+off_a] = a.size(i);
234-
for(int i = 0; i < b.dim(); i++)
230+
for (int i = 0; i < b.dim(); i++)
235231
inp2_shape[i+off_b] = b.size(i);
236232

237-
xa_nn_elm_div_mode_broadcast_4D_f32xf32_f32(out_data, out_shape, a_data, inp1_shape, b_data, inp2_shape, mode_val);
233+
xa_nn_elm_div_mode_broadcast_4D_f32xf32_f32(
234+
out_data, out_shape, a_data, inp1_shape, b_data, inp2_shape, mode_val);
238235
}
239236
else
240237
{
241-
xa_nn_elm_div_mode_f32xf32_f32(out_data, a_data, b_data, out.numel(), mode_val);
238+
xa_nn_elm_div_mode_f32xf32_f32(
239+
out_data, a_data, b_data, out.numel(), mode_val);
242240
}
243241

244242
return out;
@@ -248,7 +246,8 @@ Tensor& div_out_mode(
248246
ET_SWITCH_REAL_TYPES_AND(Bool, b_type, ctx, "div.out_mode", CTYPE_B, [&]() {
249247
ET_SWITCH_FLOAT_TYPES(common_type, ctx, "div.out_mode", CTYPE_IN, [&]() {
250248
ET_SWITCH_REAL_TYPES(out_type, ctx, "div.out_mode", CTYPE_OUT, [&]() {
251-
torch::executor::apply_binary_elementwise_fn<CTYPE_A, CTYPE_B, CTYPE_OUT>(
249+
torch::executor::
250+
apply_binary_elementwise_fn<CTYPE_A, CTYPE_B, CTYPE_OUT>(
252251
[mode](const CTYPE_A val_a, const CTYPE_B val_b) {
253252
CTYPE_IN a_casted = static_cast<CTYPE_IN>(val_a);
254253
CTYPE_IN b_casted = static_cast<CTYPE_IN>(val_b);
@@ -272,6 +271,6 @@ Tensor& div_out_mode(
272271
}
273272

274273

275-
} // namespace impl
276-
} // namespace HiFi
277274
} // namespace native
275+
} // namespace HiFi
276+
} // namespace impl

0 commit comments

Comments
 (0)