Skip to content

Commit 224aaf4

Browse files
committed
Fixing review comments in PR 7567
1 parent 4923b83 commit 224aaf4

File tree

4 files changed

+18
-177
lines changed

4 files changed

+18
-177
lines changed

backends/cadence/hifi/operators/op_atan2.cpp

Lines changed: 2 additions & 1 deletion
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 <cmath>
910
#include <executorch/backends/cadence/hifi/kernels/kernels.h>
1011
#include <executorch/kernels/portable/cpu/util/broadcast_util.h>
1112
#include <executorch/kernels/portable/cpu/util/elementwise_util.h>
1213
#include <executorch/runtime/kernel/kernel_includes.h>
13-
#include <cmath>
14+
1415

1516
using executorch::aten::ScalarType;
1617
using executorch::aten::Tensor;

backends/cadence/hifi/operators/op_clamp.cpp

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -48,137 +48,6 @@ namespace impl {
4848
namespace HiFi {
4949
namespace native {
5050

51-
namespace {
52-
53-
template <typename CTYPE_VAL, typename CTYPE_OUT, typename CTYPE_CAST>
54-
/** Check if val, when cast to CTYPE_CAST, is not in the range of CTYPE_OUT */
55-
bool is_out_of_bounds(CTYPE_VAL val) {
56-
const CTYPE_CAST val_cast = static_cast<CTYPE_CAST>(val);
57-
return val_cast < std::numeric_limits<CTYPE_OUT>::lowest() ||
58-
val_cast > std::numeric_limits<CTYPE_OUT>::max();
59-
}
60-
61-
ET_NODISCARD bool check_bounds(
62-
const Scalar& val_scalar,
63-
const ScalarType& val_type,
64-
const ScalarType& out_type,
65-
const char* val_name) {
66-
auto is_valid = true;
67-
68-
ET_SWITCH_SCALAR_OBJ_TYPES(val_type, ctx, "clamp.out", CTYPE_VAL, [&]() {
69-
CTYPE_VAL val = 0;
70-
extract_scalar(val_scalar, &val);
71-
if (isIntegralType(out_type, /*includeBool=*/false)) {
72-
ET_SWITCH_INT_TYPES(out_type, ctx, "clamp.out", CTYPE_OUT, [&]() {
73-
if (is_out_of_bounds<CTYPE_VAL, CTYPE_OUT, long>(val)) {
74-
ET_LOG(Error, "%s value out of bounds", val_name);
75-
is_valid = false;
76-
}
77-
});
78-
} else if (isFloatingType(out_type)) {
79-
ET_SWITCH_FLOATH_TYPES(out_type, ctx, "clamp", CTYPE_OUT, [&]() {
80-
if (std::isfinite(val) &&
81-
is_out_of_bounds<CTYPE_VAL, CTYPE_OUT, double>(val)) {
82-
ET_LOG(Error, "%s value out of bounds", val_name);
83-
is_valid = false;
84-
}
85-
});
86-
}
87-
});
88-
89-
return is_valid;
90-
}
91-
92-
} // namespace
93-
94-
Tensor& clamp_out(
95-
KernelRuntimeContext& ctx,
96-
const Tensor& in,
97-
const exec_aten::optional<Scalar>& min_opt,
98-
const exec_aten::optional<Scalar>& max_opt,
99-
Tensor& out) {
100-
bool has_min = min_opt.has_value();
101-
bool has_max = max_opt.has_value();
102-
103-
ET_KERNEL_CHECK_MSG(
104-
ctx,
105-
has_min || has_max,
106-
InvalidArgument,
107-
out,
108-
"At least one of 'min' or 'max' must not be None");
109-
110-
// Input Dtypes
111-
ScalarType in_type = in.scalar_type();
112-
ScalarType min_type = has_min ? get_scalar_dtype(min_opt.value()) : in_type;
113-
ScalarType max_type = has_max ? get_scalar_dtype(max_opt.value()) : in_type;
114-
ScalarType out_type = out.scalar_type();
115-
116-
// Common Dtype
117-
ScalarType common_type = in_type;
118-
if (has_min) {
119-
common_type = promote_type_with_scalar(common_type, min_opt.value());
120-
}
121-
if (has_max) {
122-
common_type = promote_type_with_scalar(common_type, max_opt.value());
123-
}
124-
125-
// Check Common Dtype
126-
ET_KERNEL_CHECK(ctx, common_type == out_type, InvalidArgument, out);
127-
128-
// Check Scalar Bounds
129-
if (has_min) {
130-
ET_KERNEL_CHECK(
131-
ctx,
132-
check_bounds(min_opt.value(), min_type, out_type, "minimum"),
133-
InvalidArgument,
134-
out);
135-
}
136-
if (has_max) {
137-
ET_KERNEL_CHECK(
138-
ctx,
139-
check_bounds(max_opt.value(), max_type, out_type, "maximum"),
140-
InvalidArgument,
141-
out);
142-
}
143-
144-
// Check Dim Order
145-
ET_KERNEL_CHECK(
146-
ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out);
147-
148-
// Resize
149-
ET_KERNEL_CHECK(
150-
ctx, resize_tensor(out, in.sizes()) == Error::Ok, InvalidArgument, out);
151-
152-
// Compute Dtype
153-
ScalarType compute_type = get_compute_type(common_type);
154-
155-
// @lint-ignore CLANGTIDY facebook-hte-CArray
156-
static constexpr const char op_name[] = "clamp.out";
157-
158-
ET_SWITCH_REALB_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() {
159-
apply_unitensor_elementwise_fn<CTYPE_COMPUTE, op_name>(
160-
[has_min, min_opt, has_max, max_opt](const CTYPE_COMPUTE val_in) {
161-
CTYPE_COMPUTE val_out = val_in;
162-
if (has_min) {
163-
val_out = max_override(
164-
val_out, scalar_to<CTYPE_COMPUTE>(min_opt.value()));
165-
}
166-
if (has_max) {
167-
val_out = min_override(
168-
val_out, scalar_to<CTYPE_COMPUTE>(max_opt.value()));
169-
}
170-
return val_out;
171-
},
172-
ctx,
173-
in,
174-
SupportedTensorDtypes::REALHBBF16,
175-
out,
176-
SupportedTensorDtypes::SAME_AS_COMMON);
177-
});
178-
179-
return out;
180-
}
181-
18251
Tensor& clamp_tensor_out(
18352
RuntimeContext& ctx,
18453
const Tensor& in,

backends/cadence/hifi/operators/op_permute_copy.cpp

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,22 @@ Tensor& permute_copy_out(
8585
optimized = false;
8686

8787
if (optimized) {
88-
if (in_type == ScalarType::Float) {
89-
WORD32* p_inp = (WORD32*)in.const_data_ptr<float>();
90-
WORD32* p_out = (WORD32*)out.mutable_data_ptr<float>();
88+
WORD32 num_inp_dims = in.dim();
89+
WORD32 num_out_dims = num_inp_dims;
9190

92-
WORD32 num_inp_dims = in.dim();
93-
WORD32 num_out_dims = num_inp_dims;
91+
WORD32 p_inp_shape[kNnlibMaxDim];
92+
WORD32 p_out_shape[kNnlibMaxDim];
93+
WORD32 p_permute_vec[kNnlibMaxDim];
9494

95-
WORD32 p_inp_shape[kNnlibMaxDim];
96-
WORD32 p_out_shape[kNnlibMaxDim];
97-
WORD32 p_permute_vec[kNnlibMaxDim];
95+
for (int i = 0; i < num_inp_dims; i++) {
96+
p_inp_shape[i] = in.size(i);
97+
p_out_shape[i] = in.size(dims[i]);
98+
p_permute_vec[i] = dims[i];
99+
}
98100

99-
for (int i = 0; i < num_inp_dims; i++) {
100-
p_inp_shape[i] = in.size(i);
101-
p_out_shape[i] = in.size(dims[i]);
102-
p_permute_vec[i] = dims[i];
103-
}
101+
if (in_type == ScalarType::Float) {
102+
WORD32* p_inp = (WORD32*)in.const_data_ptr<float>();
103+
WORD32* p_out = (WORD32*)out.mutable_data_ptr<float>();
104104

105105
WORD32 ret_val = xa_nn_transpose_32_32(
106106
p_out,
@@ -117,19 +117,6 @@ Tensor& permute_copy_out(
117117
WORD8* p_inp = (WORD8*)in.const_data_ptr<char>();
118118
WORD8* p_out = (WORD8*)out.mutable_data_ptr<char>();
119119

120-
WORD32 num_inp_dims = in.dim();
121-
WORD32 num_out_dims = num_inp_dims;
122-
123-
WORD32 p_inp_shape[kNnlibMaxDim];
124-
WORD32 p_out_shape[kNnlibMaxDim];
125-
WORD32 p_permute_vec[kNnlibMaxDim];
126-
127-
for (int i = 0; i < num_inp_dims; i++) {
128-
p_inp_shape[i] = in.size(i);
129-
p_out_shape[i] = in.size(dims[i]);
130-
p_permute_vec[i] = dims[i];
131-
}
132-
133120
WORD32 val = xa_nn_transpose_8_8(
134121
p_out,
135122
p_out_shape,
@@ -145,19 +132,6 @@ Tensor& permute_copy_out(
145132
WORD8* p_inp = (WORD8*)in.const_data_ptr<uint8_t>();
146133
WORD8* p_out = (WORD8*)out.mutable_data_ptr<uint8_t>();
147134

148-
WORD32 num_inp_dims = in.dim();
149-
WORD32 num_out_dims = num_inp_dims;
150-
151-
WORD32 p_inp_shape[kNnlibMaxDim];
152-
WORD32 p_out_shape[kNnlibMaxDim];
153-
WORD32 p_permute_vec[kNnlibMaxDim];
154-
155-
for (int i = 0; i < num_inp_dims; i++) {
156-
p_inp_shape[i] = in.size(i);
157-
p_out_shape[i] = in.size(dims[i]);
158-
p_permute_vec[i] = dims[i];
159-
}
160-
161135
WORD32 val = xa_nn_transpose_8_8(
162136
p_out,
163137
p_out_shape,

backends/cadence/hifi/third-party/nnlib/xa_nn_elm_minimum_maximum_f32.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2020
2121
******************************************************************************/
22-
#include "nnlib-hifi4/xa_nnlib/include/xa_type_def.h"
23-
#include "nnlib-hifi4/xa_nnlib/algo/common/include/xa_nnlib_common_fpu.h"
24-
#include "nnlib-hifi4/xa_nnlib/algo/common/include/xa_nn_common.h"
25-
#include "nnlib-hifi4/xa_nnlib/algo/common/include/xa_nnlib_err_chk.h"
26-
#include "nnlib-hifi4/xa_nnlib/algo/kernels/basic/hifi4/xa_nn_basic_state.h"
27-
#include "nnlib-hifi4/xa_nnlib/include/nnlib/xa_nnlib_kernels_api.h"
22+
#include "xa_type_def.h"
23+
#include "xa_nnlib_common_fpu.h"
24+
#include "xa_nnlib_err_chk.h"
2825

2926
#if !HAVE_VFPU
3027
DISCARD_FUN_FOR_NONVOID_RETURN(

0 commit comments

Comments
 (0)