diff --git a/backends/cadence/aot/functions_hifi.yaml b/backends/cadence/aot/functions_hifi.yaml index d46550094f..9b62b491fa 100644 --- a/backends/cadence/aot/functions_hifi.yaml +++ b/backends/cadence/aot/functions_hifi.yaml @@ -66,6 +66,56 @@ kernels: - arg_meta: null kernel_name: torch::executor::embedding_out + +- op: eq.Scalar_out + kernels: + - arg_meta: null + kernel_name: impl::HiFi::eq_scalar_out + +- op: eq.Tensor_out + kernels: + - arg_meta: null + kernel_name: impl::HiFi::eq_tensor_out + +- op: ge.Scalar_out + kernels: + - arg_meta: null + kernel_name: impl::HiFi::ge_scalar_out + +- op: ge.Tensor_out + kernels: + - arg_meta: null + kernel_name: impl::HiFi::ge_tensor_out + +- op: gt.Scalar_out + kernels: + - arg_meta: null + kernel_name: impl::HiFi::gt_scalar_out + +- op: gt.Tensor_out + kernels: + - arg_meta: null + kernel_name: impl::HiFi::gt_tensor_out + +- op: le.Scalar_out + kernels: + - arg_meta: null + kernel_name: impl::HiFi::le_scalar_out + +- op: le.Tensor_out + kernels: + - arg_meta: null + kernel_name: impl::HiFi::le_tensor_out + +- op: lt.Scalar_out + kernels: + - arg_meta: null + kernel_name: impl::HiFi::lt_scalar_out + +- op: lt.Tensor_out + kernels: + - arg_meta: null + kernel_name: impl::HiFi::lt_tensor_out - op: full.out kernels: @@ -80,7 +130,17 @@ - op: mean.out kernels: - arg_meta: null - kernel_name: impl::HiFi::mean_dim_out + kernel_name: impl::HiFi::mean_dim_out + +- op: ne.Scalar_out + kernels: + - arg_meta: null + kernel_name: impl::HiFi::ne_scalar_out + +- op: ne.Tensor_out + kernels: + - arg_meta: null + kernel_name: impl::HiFi::ne_tensor_out - op: minimum.out kernels: @@ -90,7 +150,7 @@ - op: mm.out kernels: - arg_meta: null - kernel_name: impl::HiFi::mm_out + kernel_name: impl::HiFi::mm_out - op: mul.out kernels: @@ -136,7 +196,7 @@ kernels: - arg_meta: null kernel_name: impl::HiFi::where_out - + # custom ops - func: cadence::quantize_per_tensor.out(Tensor input, float scale, int zero_point, int quant_min, int quant_max, ScalarType dtype, *, Tensor(a!) out) -> Tensor(a!) variants: function diff --git a/backends/cadence/hifi/kernels/CMakeLists.txt b/backends/cadence/hifi/kernels/CMakeLists.txt index 27789135a7..4e77435fe6 100644 --- a/backends/cadence/hifi/kernels/CMakeLists.txt +++ b/backends/cadence/hifi/kernels/CMakeLists.txt @@ -18,6 +18,7 @@ add_library( ${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/xa_nn_elm_minimum_maximum_f32.c ${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/xa_nn_elm_mul_f32_broadcast.c ${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/xa_nn_elm_where_f32xf32_f32.c + ${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/xa_nn_greater_lesser_equal_f32.c ${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/xa_nn_reduce_32_32.c ${EXECUTORCH_ROOT}/backends/cadence/hifi/third-party/nnlib/xa_nn_transpose_32.c ) diff --git a/backends/cadence/hifi/kernels/kernels.h b/backends/cadence/hifi/kernels/kernels.h index ad1da5c98e..042008ad4c 100644 --- a/backends/cadence/hifi/kernels/kernels.h +++ b/backends/cadence/hifi/kernels/kernels.h @@ -32,10 +32,11 @@ extern "C" WORD32 xa_nn_elm_add_broadcast_4D_f32xf32_f32( const FLOAT32* __restrict__ p_inp2, const WORD32* const p_inp2_shape); -extern "C" void xa_nn_elm_atan2_f32(FLOAT32 * z, - const FLOAT32 * y, - const FLOAT32 * x, - WORD32 N ); +extern "C" void xa_nn_elm_atan2_f32( + FLOAT32 * z, + const FLOAT32 * y, + const FLOAT32 * x, + WORD32 N ); extern "C" WORD32 xa_nn_elm_clamp_f32xf32xf32_f32( FLOAT32* __restrict__ p_out, @@ -70,13 +71,27 @@ extern "C" WORD32 xa_nn_elm_div_mode_f32xf32_f32( WORD32 mode); extern "C" WORD32 xa_nn_elm_div_mode_broadcast_4D_f32xf32_f32( - FLOAT32* __restrict__ p_out, - const WORD32* const p_out_shape, - const FLOAT32* __restrict__ p_inp1, - const WORD32* const p_inp1_shape, - const FLOAT32* __restrict__ p_inp2, - const WORD32* const p_inp2_shape, + FLOAT32 * __restrict__ p_out, + const WORD32 *const p_out_shape, + const FLOAT32 * __restrict__ p_inp1, + const WORD32 *const p_inp1_shape, + const FLOAT32 * __restrict__ p_inp2, + const WORD32 *const p_inp2_shape, WORD32 mode); + +extern "C" WORD32 xa_nn_elm_greater_lesser_equal_f32xf32_f32(WORD8 * __restrict__ p_out, + const FLOAT32 * __restrict__ p_inp1, + const FLOAT32 * __restrict__ p_inp2, + WORD32 num_elm, + WORD32 kernel_type); + +extern "C" WORD32 xa_nn_elm_greater_lesser_equal_broadcast_4D_f32xf32_f32(WORD8 * __restrict__ p_out, + const WORD32 *const p_out_shape, + const FLOAT32 * __restrict__ p_inp1, + const WORD32 *const p_inp1_shape, + const FLOAT32 * __restrict__ p_inp2, + const WORD32 *const p_inp2_shape, + WORD32 kernel_type); extern "C" WORD32 xa_nn_elm_maximum_f32xf32_f32( FLOAT32* __restrict__ p_out, diff --git a/backends/cadence/hifi/operators/CMakeLists.txt b/backends/cadence/hifi/operators/CMakeLists.txt index 7c37239153..ec01dfe559 100644 --- a/backends/cadence/hifi/operators/CMakeLists.txt +++ b/backends/cadence/hifi/operators/CMakeLists.txt @@ -25,12 +25,18 @@ set(_aten_ops__srcs "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_bmm.cpp" "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_clamp.cpp" "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_div.cpp" + "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_eq.cpp" "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_full.cpp" + "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_ge.cpp" + "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_gt.cpp" + "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_le.cpp" + "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_lt.cpp" "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_maximum.cpp" "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_mean.cpp" "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_minimum.cpp" "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_mm.cpp" "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_mul.cpp" + "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_ne.cpp" "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_sigmoid.cpp" "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_sub.cpp" "${EXECUTORCH_ROOT}/backends/cadence/hifi/operators/op_tanh.cpp" diff --git a/backends/cadence/hifi/operators/op_eq.cpp b/backends/cadence/hifi/operators/op_eq.cpp new file mode 100644 index 0000000000..500d5b5ff4 --- /dev/null +++ b/backends/cadence/hifi/operators/op_eq.cpp @@ -0,0 +1,180 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include +#include +#include +#include +#include + +#include + +using exec_aten::Scalar; +using exec_aten::ScalarType; +using exec_aten::Tensor; +using executorch::aten::RuntimeContext; +using executorch::runtime::CppTypeToScalarType; +using torch::executor::Error; + +namespace impl { +namespace HiFi { +namespace native { + +Tensor& eq_tensor_out( + RuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + ET_KERNEL_CHECK( + ctx, + resize_to_broadcast_target_size(a, b, out) == Error::Ok, + InvalidArgument, + out); + + ScalarType a_type = a.scalar_type(); + ScalarType b_type = b.scalar_type(); + ScalarType out_type = out.scalar_type(); + + constexpr auto name = "eq.Tensor_out"; + constexpr int kNnlibMaxDim = 4; /*fallback if broadcast and dim > 4 */ + + int a_dim = a.dim(), b_dim = b.dim(), out_dim = out.dim(); + bool optimized = 1; + /*find broadcast*/ + const bool a_is_broadcasted = !out.sizes().equals(a.sizes()); + const bool b_is_broadcasted = !out.sizes().equals(b.sizes()); + const bool broadcast = (a_is_broadcasted || b_is_broadcasted); + int max_dim = a.dim() > b.dim() ? a.dim() : b.dim(); + max_dim = out.dim() > max_dim ? out.dim() : max_dim; + + if (out_type != ScalarType::Float) + optimized = 0; + + if ((a_dim == 0) || (b_dim == 0)) + optimized = 0; + + if ((broadcast == 1) && (max_dim > kNnlibMaxDim)) + optimized = 0; + + if (optimized) { + int8_t* __restrict__ p_out = + (int8_t* __restrict__)out.mutable_data_ptr(); + const float* __restrict__ p_inp1 = + (const float* __restrict__)a.const_data_ptr(); + const float* __restrict__ p_inp2 = + (const float* __restrict__)b.const_data_ptr(); + + if (broadcast) { + int out_shape[kNnlibMaxDim]; + int inp1_shape[kNnlibMaxDim]; + int inp2_shape[kNnlibMaxDim]; + + for (int i = 0; i < kNnlibMaxDim; i++) { + inp1_shape[i] = 1; + inp2_shape[i] = 1; + out_shape[i] = 1; + } + + int off_o = kNnlibMaxDim - out.dim(); + int off_a = kNnlibMaxDim - a.dim(); + int off_b = kNnlibMaxDim - b.dim(); + + for (int i = 0; i < out.dim(); i++) + out_shape[i + off_o] = out.size(i); + for (int i = 0; i < a.dim(); i++) + inp1_shape[i + off_a] = a.size(i); + for (int i = 0; i < b.dim(); i++) + inp2_shape[i + off_b] = b.size(i); + + xa_nn_elm_greater_lesser_equal_broadcast_4D_f32xf32_f32( + p_out, out_shape, p_inp1, inp1_shape, p_inp2, inp2_shape, 4); + } else { + int num_elm = out.numel(); + + xa_nn_elm_greater_lesser_equal_f32xf32_f32( + p_out, p_inp1, p_inp2, num_elm, 4); + } + + return out; + } + + ET_SWITCH_REAL_TYPES_AND(Bool, a_type, ctx, name, CTYPE_A, [&]() { + ET_SWITCH_REAL_TYPES_AND(Bool, b_type, ctx, name, CTYPE_B, [&]() { + using CTYPE_IN = + typename torch::executor::promote_types::type; + ET_DCHECK( + CppTypeToScalarType::value == promoteTypes(a_type, b_type)); + ET_SWITCH_REAL_TYPES_AND(Bool, out_type, ctx, name, CTYPE_OUT, [&]() { + torch::executor:: + apply_binary_elementwise_fn( + [](const CTYPE_A val_a, const CTYPE_B val_b) { + CTYPE_IN a_casted = static_cast(val_a); + CTYPE_IN b_casted = static_cast(val_b); + bool value = a_casted == b_casted; + return static_cast(value); + }, + a, + b, + out); + }); + }); + }); + + return out; +} + +Tensor& eq_scalar_out( + RuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + (void)ctx; + + // Resize for dynamic shape + ET_KERNEL_CHECK_MSG( + ctx, + resize_tensor(out, a.sizes()) == Error::Ok, + InvalidArgument, + out, + "Failed to resize output tensor."); + + constexpr auto name = "eq.Scalar_out"; + + ScalarType a_type = a.scalar_type(); + ScalarType b_type = torch::executor::native::utils::get_scalar_dtype(b); + ScalarType out_type = out.scalar_type(); + + ET_SWITCH_REAL_TYPES_AND(Bool, a_type, ctx, name, CTYPE_A, [&]() { + ET_SWITCH_SCALAR_OBJ_TYPES(b_type, ctx, name, CTYPE_B, [&]() { + using CTYPE_IN = + typename torch::executor::promote_types::type; + ET_DCHECK( + CppTypeToScalarType::value == promoteTypes(a_type, b_type)); + ET_SWITCH_REAL_TYPES_AND(Bool, out_type, ctx, name, CTYPE_OUT, [&]() { + CTYPE_B val_b = 0; + torch::executor::native::utils::extract_scalar(b, &val_b); + torch::executor::apply_unary_map_fn( + [val_b](const CTYPE_A val_a) { + CTYPE_IN a_casted = static_cast(val_a); + CTYPE_IN b_casted = static_cast(val_b); + bool value = a_casted == b_casted; + return static_cast(value); + }, + a.const_data_ptr(), + out.mutable_data_ptr(), + out.numel()); + }); + }); + }); + + return out; +} + +} // namespace native +} // namespace HiFi +} // namespace impl diff --git a/backends/cadence/hifi/operators/op_ge.cpp b/backends/cadence/hifi/operators/op_ge.cpp new file mode 100644 index 0000000000..3853cfd6d1 --- /dev/null +++ b/backends/cadence/hifi/operators/op_ge.cpp @@ -0,0 +1,181 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include +#include +#include +#include +#include + +#include + +using exec_aten::Scalar; +using exec_aten::ScalarType; +using exec_aten::Tensor; +using executorch::aten::RuntimeContext; +using executorch::runtime::CppTypeToScalarType; +using torch::executor::Error; + +namespace impl { +namespace HiFi { +namespace native { + +Tensor& ge_tensor_out( + RuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + // Determine output size and resize for dynamic shapes + ET_KERNEL_CHECK( + ctx, + resize_to_broadcast_target_size(a, b, out) == Error::Ok, + InvalidArgument, + out); + + ScalarType a_type = a.scalar_type(); + ScalarType b_type = b.scalar_type(); + ScalarType out_type = out.scalar_type(); + + constexpr auto name = "ge.Tensor_out"; + constexpr int kNnlibMaxDim = 4; /*fallback if broadcast and dim > 4 */ + + int a_dim = a.dim(), b_dim = b.dim(), out_dim = out.dim(); + bool optimized = 1; + /*find broadcast*/ + const bool a_is_broadcasted = !out.sizes().equals(a.sizes()); + const bool b_is_broadcasted = !out.sizes().equals(b.sizes()); + const bool broadcast = (a_is_broadcasted || b_is_broadcasted); + int max_dim = a.dim() > b.dim() ? a.dim() : b.dim(); + max_dim = out.dim() > max_dim ? out.dim() : max_dim; + + if (out_type != ScalarType::Float) + optimized = 0; + + if ((a_dim == 0) || (b_dim == 0)) + optimized = 0; + + if ((broadcast == 1) && (max_dim > kNnlibMaxDim)) + optimized = 0; + + if (optimized) { + int8_t* __restrict__ p_out = + (int8_t* __restrict__)out.mutable_data_ptr(); + const float* __restrict__ p_inp1 = + (const float* __restrict__)a.const_data_ptr(); + const float* __restrict__ p_inp2 = + (const float* __restrict__)b.const_data_ptr(); + + if (broadcast) { + int out_shape[kNnlibMaxDim]; + int inp1_shape[kNnlibMaxDim]; + int inp2_shape[kNnlibMaxDim]; + + for (int i = 0; i < kNnlibMaxDim; i++) { + inp1_shape[i] = 1; + inp2_shape[i] = 1; + out_shape[i] = 1; + } + + int off_o = kNnlibMaxDim - out.dim(); + int off_a = kNnlibMaxDim - a.dim(); + int off_b = kNnlibMaxDim - b.dim(); + + for (int i = 0; i < out.dim(); i++) + out_shape[i + off_o] = out.size(i); + for (int i = 0; i < a.dim(); i++) + inp1_shape[i + off_a] = a.size(i); + for (int i = 0; i < b.dim(); i++) + inp2_shape[i + off_b] = b.size(i); + + xa_nn_elm_greater_lesser_equal_broadcast_4D_f32xf32_f32( + p_out, out_shape, p_inp1, inp1_shape, p_inp2, inp2_shape, 0); + } else { + int num_elm = out.numel(); + + xa_nn_elm_greater_lesser_equal_f32xf32_f32( + p_out, p_inp1, p_inp2, num_elm, 0); + } + + return out; + } + + ET_SWITCH_REAL_TYPES_AND(Bool, a_type, ctx, name, CTYPE_A, [&]() { + ET_SWITCH_REAL_TYPES_AND(Bool, b_type, ctx, name, CTYPE_B, [&]() { + using CTYPE_IN = + typename torch::executor::promote_types::type; + ET_DCHECK( + CppTypeToScalarType::value == promoteTypes(a_type, b_type)); + ET_SWITCH_REAL_TYPES_AND(Bool, out_type, ctx, name, CTYPE_OUT, [&]() { + torch::executor:: + apply_binary_elementwise_fn( + [](const CTYPE_A val_a, const CTYPE_B val_b) { + CTYPE_IN a_casted = static_cast(val_a); + CTYPE_IN b_casted = static_cast(val_b); + bool value = a_casted >= b_casted; + return static_cast(value); + }, + a, + b, + out); + }); + }); + }); + + return out; +} + +Tensor& ge_scalar_out( + RuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + (void)ctx; + + // Resize for dynamic shape + ET_KERNEL_CHECK_MSG( + ctx, + resize_tensor(out, a.sizes()) == Error::Ok, + InvalidArgument, + out, + "Failed to resize output tensor."); + + constexpr auto name = "ge.Scalar_out"; + + ScalarType a_type = a.scalar_type(); + ScalarType b_type = torch::executor::native::utils::get_scalar_dtype(b); + ScalarType common_type = + torch::executor::native::utils::promote_type_with_scalar(a_type, b); + ScalarType out_type = out.scalar_type(); + + ET_SWITCH_REAL_TYPES_AND(Bool, a_type, ctx, name, CTYPE_A, [&]() { + ET_SWITCH_SCALAR_OBJ_TYPES(b_type, ctx, name, CTYPE_B, [&]() { + ET_SWITCH_REAL_TYPES_AND(Bool, common_type, ctx, name, CTYPE_IN, [&]() { + ET_SWITCH_REAL_TYPES_AND(Bool, out_type, ctx, name, CTYPE_OUT, [&]() { + CTYPE_B val_b = 0; + torch::executor::native::utils::extract_scalar(b, &val_b); + torch::executor::apply_unary_map_fn( + [val_b](const CTYPE_A val_a) { + CTYPE_IN a_casted = static_cast(val_a); + CTYPE_IN b_casted = static_cast(val_b); + bool value = a_casted >= b_casted; + return static_cast(value); + }, + a.const_data_ptr(), + out.mutable_data_ptr(), + out.numel()); + }); + }); + }); + }); + + return out; +} + +} // namespace native +} // namespace HiFi +} // namespace impl diff --git a/backends/cadence/hifi/operators/op_gt.cpp b/backends/cadence/hifi/operators/op_gt.cpp new file mode 100644 index 0000000000..46978ab922 --- /dev/null +++ b/backends/cadence/hifi/operators/op_gt.cpp @@ -0,0 +1,181 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include +#include +#include +#include +#include + +#include + +using exec_aten::Scalar; +using exec_aten::ScalarType; +using exec_aten::Tensor; +using executorch::aten::RuntimeContext; +using executorch::runtime::CppTypeToScalarType; +using torch::executor::Error; + +namespace impl { +namespace HiFi { +namespace native { + +Tensor& gt_tensor_out( + RuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + // Determine output size and resize for dynamic shapes + ET_KERNEL_CHECK( + ctx, + resize_to_broadcast_target_size(a, b, out) == Error::Ok, + InvalidArgument, + out); + + ScalarType a_type = a.scalar_type(); + ScalarType b_type = b.scalar_type(); + ScalarType out_type = out.scalar_type(); + + constexpr auto name = "gt.Tensor_out"; + constexpr int kNnlibMaxDim = 4; /*fallback if broadcast and dim > 4 */ + + int a_dim = a.dim(), b_dim = b.dim(), out_dim = out.dim(); + bool optimized = 1; + /*find broadcast*/ + const bool a_is_broadcasted = !out.sizes().equals(a.sizes()); + const bool b_is_broadcasted = !out.sizes().equals(b.sizes()); + const bool broadcast = (a_is_broadcasted || b_is_broadcasted); + int max_dim = a.dim() > b.dim() ? a.dim() : b.dim(); + max_dim = out.dim() > max_dim ? out.dim() : max_dim; + + if (out_type != ScalarType::Float) + optimized = 0; + + if ((a_dim == 0) || (b_dim == 0)) + optimized = 0; + + if ((broadcast == 1) && (max_dim > kNnlibMaxDim)) + optimized = 0; + + if (optimized) { + int8_t* __restrict__ p_out = + (int8_t* __restrict__)out.mutable_data_ptr(); + const float* __restrict__ p_inp1 = + (const float* __restrict__)a.const_data_ptr(); + const float* __restrict__ p_inp2 = + (const float* __restrict__)b.const_data_ptr(); + + if (broadcast) { + int out_shape[kNnlibMaxDim]; + int inp1_shape[kNnlibMaxDim]; + int inp2_shape[kNnlibMaxDim]; + + for (int i = 0; i < kNnlibMaxDim; i++) { + inp1_shape[i] = 1; + inp2_shape[i] = 1; + out_shape[i] = 1; + } + + int off_o = kNnlibMaxDim - out.dim(); + int off_a = kNnlibMaxDim - a.dim(); + int off_b = kNnlibMaxDim - b.dim(); + + for (int i = 0; i < out.dim(); i++) + out_shape[i + off_o] = out.size(i); + for (int i = 0; i < a.dim(); i++) + inp1_shape[i + off_a] = a.size(i); + for (int i = 0; i < b.dim(); i++) + inp2_shape[i + off_b] = b.size(i); + + xa_nn_elm_greater_lesser_equal_broadcast_4D_f32xf32_f32( + p_out, out_shape, p_inp1, inp1_shape, p_inp2, inp2_shape, 1); + } else { + int num_elm = out.numel(); + + xa_nn_elm_greater_lesser_equal_f32xf32_f32( + p_out, p_inp1, p_inp2, num_elm, 1); + } + + return out; + } + + ET_SWITCH_REAL_TYPES_AND(Bool, a_type, ctx, name, CTYPE_A, [&]() { + ET_SWITCH_REAL_TYPES_AND(Bool, b_type, ctx, name, CTYPE_B, [&]() { + using CTYPE_IN = + typename torch::executor::promote_types::type; + ET_DCHECK( + CppTypeToScalarType::value == promoteTypes(a_type, b_type)); + ET_SWITCH_REAL_TYPES_AND(Bool, out_type, ctx, name, CTYPE_OUT, [&]() { + torch::executor:: + apply_binary_elementwise_fn( + [](const CTYPE_A val_a, const CTYPE_B val_b) { + CTYPE_IN a_casted = static_cast(val_a); + CTYPE_IN b_casted = static_cast(val_b); + bool value = a_casted > b_casted; + return static_cast(value); + }, + a, + b, + out); + }); + }); + }); + + return out; +} + +Tensor& gt_scalar_out( + RuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + (void)ctx; + + // Resize for dynamic shape + ET_KERNEL_CHECK_MSG( + ctx, + resize_tensor(out, a.sizes()) == Error::Ok, + InvalidArgument, + out, + "Failed to resize output tensor."); + + constexpr auto name = "gt.Scalar_out"; + + ScalarType a_type = a.scalar_type(); + ScalarType b_type = torch::executor::native::utils::get_scalar_dtype(b); + ScalarType common_type = + torch::executor::native::utils::promote_type_with_scalar(a_type, b); + ScalarType out_type = out.scalar_type(); + + ET_SWITCH_REAL_TYPES_AND(Bool, a_type, ctx, name, CTYPE_A, [&]() { + ET_SWITCH_SCALAR_OBJ_TYPES(b_type, ctx, name, CTYPE_B, [&]() { + ET_SWITCH_REAL_TYPES_AND(Bool, common_type, ctx, name, CTYPE_IN, [&]() { + ET_SWITCH_REAL_TYPES_AND(Bool, out_type, ctx, name, CTYPE_OUT, [&]() { + CTYPE_B val_b = 0; + torch::executor::native::utils::extract_scalar(b, &val_b); + torch::executor::apply_unary_map_fn( + [val_b](const CTYPE_A val_a) { + CTYPE_IN a_casted = static_cast(val_a); + CTYPE_IN b_casted = static_cast(val_b); + bool value = a_casted > b_casted; + return static_cast(value); + }, + a.const_data_ptr(), + out.mutable_data_ptr(), + out.numel()); + }); + }); + }); + }); + + return out; +} + +} // namespace native +} // namespace HiFi +} // namespace impl diff --git a/backends/cadence/hifi/operators/op_le.cpp b/backends/cadence/hifi/operators/op_le.cpp new file mode 100644 index 0000000000..68a7419fb8 --- /dev/null +++ b/backends/cadence/hifi/operators/op_le.cpp @@ -0,0 +1,181 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include +#include +#include +#include +#include + +#include + +using exec_aten::Scalar; +using exec_aten::ScalarType; +using exec_aten::Tensor; +using executorch::aten::RuntimeContext; +using executorch::runtime::CppTypeToScalarType; +using torch::executor::Error; + +namespace impl { +namespace HiFi { +namespace native { + +Tensor& le_tensor_out( + RuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + // Determine output size and resize for dynamic shapes + ET_KERNEL_CHECK( + ctx, + resize_to_broadcast_target_size(a, b, out) == Error::Ok, + InvalidArgument, + out); + + ScalarType a_type = a.scalar_type(); + ScalarType b_type = b.scalar_type(); + ScalarType out_type = out.scalar_type(); + + constexpr auto name = "le.Tensor_out"; + constexpr int kNnlibMaxDim = 4; /*fallback if broadcast and dim > 4 */ + + int a_dim = a.dim(), b_dim = b.dim(), out_dim = out.dim(); + bool optimized = 1; + /*find broadcast*/ + const bool a_is_broadcasted = !out.sizes().equals(a.sizes()); + const bool b_is_broadcasted = !out.sizes().equals(b.sizes()); + const bool broadcast = (a_is_broadcasted || b_is_broadcasted); + int max_dim = a.dim() > b.dim() ? a.dim() : b.dim(); + max_dim = out.dim() > max_dim ? out.dim() : max_dim; + + if (out_type != ScalarType::Float) + optimized = 0; + + if ((a_dim == 0) || (b_dim == 0)) + optimized = 0; + + if ((broadcast == 1) && (max_dim > kNnlibMaxDim)) + optimized = 0; + + if (optimized) { + int8_t* __restrict__ p_out = + (int8_t* __restrict__)out.mutable_data_ptr(); + const float* __restrict__ p_inp1 = + (const float* __restrict__)a.const_data_ptr(); + const float* __restrict__ p_inp2 = + (const float* __restrict__)b.const_data_ptr(); + + if (broadcast) { + int out_shape[kNnlibMaxDim]; + int inp1_shape[kNnlibMaxDim]; + int inp2_shape[kNnlibMaxDim]; + + for (int i = 0; i < kNnlibMaxDim; i++) { + inp1_shape[i] = 1; + inp2_shape[i] = 1; + out_shape[i] = 1; + } + + int off_o = kNnlibMaxDim - out.dim(); + int off_a = kNnlibMaxDim - a.dim(); + int off_b = kNnlibMaxDim - b.dim(); + + for (int i = 0; i < out.dim(); i++) + out_shape[i + off_o] = out.size(i); + for (int i = 0; i < a.dim(); i++) + inp1_shape[i + off_a] = a.size(i); + for (int i = 0; i < b.dim(); i++) + inp2_shape[i + off_b] = b.size(i); + + xa_nn_elm_greater_lesser_equal_broadcast_4D_f32xf32_f32( + p_out, out_shape, p_inp1, inp1_shape, p_inp2, inp2_shape, 2); + } else { + int num_elm = out.numel(); + + xa_nn_elm_greater_lesser_equal_f32xf32_f32( + p_out, p_inp1, p_inp2, num_elm, 2); + } + + return out; + } + + ET_SWITCH_REAL_TYPES_AND(Bool, a_type, ctx, name, CTYPE_A, [&]() { + ET_SWITCH_REAL_TYPES_AND(Bool, b_type, ctx, name, CTYPE_B, [&]() { + using CTYPE_IN = + typename torch::executor::promote_types::type; + ET_DCHECK( + CppTypeToScalarType::value == promoteTypes(a_type, b_type)); + ET_SWITCH_REAL_TYPES_AND(Bool, out_type, ctx, name, CTYPE_OUT, [&]() { + torch::executor:: + apply_binary_elementwise_fn( + [](const CTYPE_A val_a, const CTYPE_B val_b) { + CTYPE_IN a_casted = static_cast(val_a); + CTYPE_IN b_casted = static_cast(val_b); + bool value = a_casted <= b_casted; + return static_cast(value); + }, + a, + b, + out); + }); + }); + }); + + return out; +} + +Tensor& le_scalar_out( + RuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + (void)ctx; + + // Resize for dynamic shape + ET_KERNEL_CHECK_MSG( + ctx, + resize_tensor(out, a.sizes()) == Error::Ok, + InvalidArgument, + out, + "Failed to resize output tensor."); + + constexpr auto name = "le.Scalar_out"; + + ScalarType a_type = a.scalar_type(); + ScalarType b_type = torch::executor::native::utils::get_scalar_dtype(b); + ScalarType common_type = + torch::executor::native::utils::promote_type_with_scalar(a_type, b); + ScalarType out_type = out.scalar_type(); + + ET_SWITCH_REAL_TYPES_AND(Bool, a_type, ctx, name, CTYPE_A, [&]() { + ET_SWITCH_SCALAR_OBJ_TYPES(b_type, ctx, name, CTYPE_B, [&]() { + ET_SWITCH_REAL_TYPES_AND(Bool, common_type, ctx, name, CTYPE_IN, [&]() { + ET_SWITCH_REAL_TYPES_AND(Bool, out_type, ctx, name, CTYPE_OUT, [&]() { + CTYPE_B val_b = 0; + torch::executor::native::utils::extract_scalar(b, &val_b); + torch::executor::apply_unary_map_fn( + [val_b](const CTYPE_A val_a) { + CTYPE_IN a_casted = static_cast(val_a); + CTYPE_IN b_casted = static_cast(val_b); + bool value = a_casted <= b_casted; + return static_cast(value); + }, + a.const_data_ptr(), + out.mutable_data_ptr(), + out.numel()); + }); + }); + }); + }); + + return out; +} + +} // namespace native +} // namespace HiFi +} // namespace impl \ No newline at end of file diff --git a/backends/cadence/hifi/operators/op_lt.cpp b/backends/cadence/hifi/operators/op_lt.cpp new file mode 100644 index 0000000000..bf0e6ec454 --- /dev/null +++ b/backends/cadence/hifi/operators/op_lt.cpp @@ -0,0 +1,179 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include +#include +#include +#include +#include + +#include + +using exec_aten::Scalar; +using exec_aten::ScalarType; +using exec_aten::Tensor; +using executorch::aten::RuntimeContext; +using executorch::runtime::CppTypeToScalarType; +using torch::executor::Error; + +namespace impl { +namespace HiFi { +namespace native { + +Tensor& lt_tensor_out( + RuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + // Determine output size and resize for dynamic shapes + ET_KERNEL_CHECK( + ctx, + resize_to_broadcast_target_size(a, b, out) == Error::Ok, + InvalidArgument, + out); + + ScalarType a_type = a.scalar_type(); + ScalarType b_type = b.scalar_type(); + ScalarType out_type = out.scalar_type(); + + constexpr auto name = "lt.Tensor_out"; + constexpr int kNnlibMaxDim = 4; /*fallback if broadcast and dim > 4 */ + + int a_dim = a.dim(), b_dim = b.dim(), out_dim = out.dim(); + bool optimized = 1; + /*find broadcast*/ + const bool a_is_broadcasted = !out.sizes().equals(a.sizes()); + const bool b_is_broadcasted = !out.sizes().equals(b.sizes()); + const bool broadcast = (a_is_broadcasted || b_is_broadcasted); + int max_dim = a.dim() > b.dim() ? a.dim() : b.dim(); + max_dim = out.dim() > max_dim ? out.dim() : max_dim; + + if (out_type != ScalarType::Float) + optimized = 0; + + if ((a_dim == 0) || (b_dim == 0)) + optimized = 0; + + if ((broadcast == 1) && (max_dim > kNnlibMaxDim)) + optimized = 0; + + if (optimized) { + int8_t* __restrict__ p_out = + (int8_t* __restrict__)out.mutable_data_ptr(); + const float* __restrict__ p_inp1 = + (const float* __restrict__)a.const_data_ptr(); + const float* __restrict__ p_inp2 = + (const float* __restrict__)b.const_data_ptr(); + + if (broadcast) { + int out_shape[kNnlibMaxDim]; + int inp1_shape[kNnlibMaxDim]; + int inp2_shape[kNnlibMaxDim]; + + for (int i = 0; i < kNnlibMaxDim; i++) { + inp1_shape[i] = 1; + inp2_shape[i] = 1; + out_shape[i] = 1; + } + + int off_o = kNnlibMaxDim - out.dim(); + int off_a = kNnlibMaxDim - a.dim(); + int off_b = kNnlibMaxDim - b.dim(); + + for (int i = 0; i < out.dim(); i++) + out_shape[i + off_o] = out.size(i); + for (int i = 0; i < a.dim(); i++) + inp1_shape[i + off_a] = a.size(i); + for (int i = 0; i < b.dim(); i++) + inp2_shape[i + off_b] = b.size(i); + + xa_nn_elm_greater_lesser_equal_broadcast_4D_f32xf32_f32( + p_out, out_shape, p_inp1, inp1_shape, p_inp2, inp2_shape, 3); + } else { + int num_elm = out.numel(); + + xa_nn_elm_greater_lesser_equal_f32xf32_f32( + p_out, p_inp1, p_inp2, num_elm, 3); + } + + return out; + } + + ET_SWITCH_REAL_TYPES_AND(Bool, a_type, ctx, name, CTYPE_A, [&]() { + ET_SWITCH_REAL_TYPES_AND(Bool, b_type, ctx, name, CTYPE_B, [&]() { + using CTYPE_IN = + typename torch::executor::promote_types::type; + ET_DCHECK( + CppTypeToScalarType::value == promoteTypes(a_type, b_type)); + ET_SWITCH_REAL_TYPES_AND(Bool, out_type, ctx, name, CTYPE_OUT, [&]() { + torch::executor:: + apply_binary_elementwise_fn( + [](const CTYPE_A val_a, const CTYPE_B val_b) { + CTYPE_IN a_casted = static_cast(val_a); + CTYPE_IN b_casted = static_cast(val_b); + bool value = a_casted < b_casted; + return static_cast(value); + }, + a, + b, + out); + }); + }); + }); + + return out; +} + +Tensor& lt_scalar_out( + RuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + // Resize for dynamic shape + ET_KERNEL_CHECK_MSG( + ctx, + resize_tensor(out, a.sizes()) == Error::Ok, + InvalidArgument, + out, + "Failed to resize output tensor."); + + constexpr auto name = "lt.Scalar_out"; + + ScalarType a_type = a.scalar_type(); + ScalarType b_type = torch::executor::native::utils::get_scalar_dtype(b); + ScalarType common_type = + torch::executor::native::utils::promote_type_with_scalar(a_type, b); + ScalarType out_type = out.scalar_type(); + + ET_SWITCH_REAL_TYPES_AND(Bool, a_type, ctx, name, CTYPE_A, [&]() { + ET_SWITCH_SCALAR_OBJ_TYPES(b_type, ctx, name, CTYPE_B, [&]() { + ET_SWITCH_REAL_TYPES_AND(Bool, common_type, ctx, name, CTYPE_IN, [&]() { + ET_SWITCH_REAL_TYPES_AND(Bool, out_type, ctx, name, CTYPE_OUT, [&]() { + CTYPE_B val_b = 0; + torch::executor::native::utils::extract_scalar(b, &val_b); + torch::executor::apply_unary_map_fn( + [val_b](const CTYPE_A val_a) { + CTYPE_IN a_casted = static_cast(val_a); + CTYPE_IN b_casted = static_cast(val_b); + bool value = a_casted < b_casted; + return static_cast(value); + }, + a.const_data_ptr(), + out.mutable_data_ptr(), + out.numel()); + }); + }); + }); + }); + + return out; +} + +} // namespace native +} // namespace HiFi +} // namespace impl diff --git a/backends/cadence/hifi/operators/op_ne.cpp b/backends/cadence/hifi/operators/op_ne.cpp new file mode 100644 index 0000000000..8aad599047 --- /dev/null +++ b/backends/cadence/hifi/operators/op_ne.cpp @@ -0,0 +1,179 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include +#include +#include +#include +#include + +#include + +using exec_aten::Scalar; +using exec_aten::ScalarType; +using exec_aten::Tensor; +using executorch::aten::RuntimeContext; +using executorch::runtime::CppTypeToScalarType; +using torch::executor::Error; + +namespace impl { +namespace HiFi { +namespace native { + +Tensor& ne_tensor_out( + RuntimeContext& ctx, + const Tensor& a, + const Tensor& b, + Tensor& out) { + ET_KERNEL_CHECK( + ctx, + resize_to_broadcast_target_size(a, b, out) == Error::Ok, + InvalidArgument, + out); + + ScalarType a_type = a.scalar_type(); + ScalarType b_type = b.scalar_type(); + ScalarType out_type = out.scalar_type(); + + constexpr auto name = "ne.Tensor_out"; + constexpr int kNnlibMaxDim = 4; /*fallback if broadcast and dim > 4 */ + + int a_dim = a.dim(), b_dim = b.dim(), out_dim = out.dim(); + bool optimized = 1; + /*find broadcast*/ + const bool a_is_broadcasted = !out.sizes().equals(a.sizes()); + const bool b_is_broadcasted = !out.sizes().equals(b.sizes()); + const bool broadcast = (a_is_broadcasted || b_is_broadcasted); + int max_dim = a.dim() > b.dim() ? a.dim() : b.dim(); + max_dim = out.dim() > max_dim ? out.dim() : max_dim; + + if (out_type != ScalarType::Float) + optimized = 0; + + if ((a_dim == 0) || (b_dim == 0)) + optimized = 0; + + if ((broadcast == 1) && (max_dim > kNnlibMaxDim)) + optimized = 0; + + if (optimized) { + int8_t* __restrict__ p_out = + (int8_t* __restrict__)out.mutable_data_ptr(); + const float* __restrict__ p_inp1 = + (const float* __restrict__)a.const_data_ptr(); + const float* __restrict__ p_inp2 = + (const float* __restrict__)b.const_data_ptr(); + + if (broadcast) { + int out_shape[kNnlibMaxDim]; + int inp1_shape[kNnlibMaxDim]; + int inp2_shape[kNnlibMaxDim]; + + for (int i = 0; i < kNnlibMaxDim; i++) { + inp1_shape[i] = 1; + inp2_shape[i] = 1; + out_shape[i] = 1; + } + + int off_o = kNnlibMaxDim - out.dim(); + int off_a = kNnlibMaxDim - a.dim(); + int off_b = kNnlibMaxDim - b.dim(); + + for (int i = 0; i < out.dim(); i++) + out_shape[i + off_o] = out.size(i); + for (int i = 0; i < a.dim(); i++) + inp1_shape[i + off_a] = a.size(i); + for (int i = 0; i < b.dim(); i++) + inp2_shape[i + off_b] = b.size(i); + + xa_nn_elm_greater_lesser_equal_broadcast_4D_f32xf32_f32( + p_out, out_shape, p_inp1, inp1_shape, p_inp2, inp2_shape, 5); + } else { + int num_elm = out.numel(); + + xa_nn_elm_greater_lesser_equal_f32xf32_f32( + p_out, p_inp1, p_inp2, num_elm, 5); + } + + return out; + } + + ET_SWITCH_REAL_TYPES_AND(Bool, a_type, ctx, name, CTYPE_A, [&]() { + ET_SWITCH_REAL_TYPES_AND(Bool, b_type, ctx, name, CTYPE_B, [&]() { + using CTYPE_IN = + typename torch::executor::promote_types::type; + ET_DCHECK( + CppTypeToScalarType::value == promoteTypes(a_type, b_type)); + ET_SWITCH_REAL_TYPES_AND(Bool, out_type, ctx, name, CTYPE_OUT, [&]() { + torch::executor:: + apply_binary_elementwise_fn( + [](const CTYPE_A val_a, const CTYPE_B val_b) { + CTYPE_IN a_casted = static_cast(val_a); + CTYPE_IN b_casted = static_cast(val_b); + bool value = a_casted != b_casted; + return static_cast(value); + }, + a, + b, + out); + }); + }); + }); + + return out; +} + +Tensor& ne_scalar_out( + RuntimeContext& ctx, + const Tensor& a, + const Scalar& b, + Tensor& out) { + (void)ctx; + // Resize for dynamic shape + ET_KERNEL_CHECK_MSG( + ctx, + resize_tensor(out, a.sizes()) == Error::Ok, + InvalidArgument, + out, + "Failed to resize output tensor."); + + constexpr auto name = "ne.Scalar_out"; + + ScalarType a_type = a.scalar_type(); + ScalarType b_type = torch::executor::native::utils::get_scalar_dtype(b); + ScalarType out_type = out.scalar_type(); + + ET_SWITCH_REAL_TYPES_AND(Bool, a_type, ctx, name, CTYPE_A, [&]() { + ET_SWITCH_SCALAR_OBJ_TYPES(b_type, ctx, name, CTYPE_B, [&]() { + using CTYPE_IN = + typename torch::executor::promote_types::type; + ET_DCHECK( + CppTypeToScalarType::value == promoteTypes(a_type, b_type)); + ET_SWITCH_REAL_TYPES_AND(Bool, out_type, ctx, name, CTYPE_OUT, [&]() { + CTYPE_B val_b = 0; + torch::executor::native::utils::extract_scalar(b, &val_b); + torch::executor::apply_unary_map_fn( + [val_b](const CTYPE_A val_a) { + CTYPE_IN a_casted = static_cast(val_a); + CTYPE_IN b_casted = static_cast(val_b); + bool value = a_casted != b_casted; + return static_cast(value); + }, + a.const_data_ptr(), + out.mutable_data_ptr(), + out.numel()); + }); + }); + }); + + return out; +} + +} // namespace native +} // namespace HiFi +} // namespace impl diff --git a/backends/cadence/hifi/third-party/nnlib/xa_nn_greater_lesser_equal_f32.c b/backends/cadence/hifi/third-party/nnlib/xa_nn_greater_lesser_equal_f32.c new file mode 100644 index 0000000000..2372fcadcd --- /dev/null +++ b/backends/cadence/hifi/third-party/nnlib/xa_nn_greater_lesser_equal_f32.c @@ -0,0 +1,2029 @@ +#include "xa_type_def.h" +#include "xa_nnlib_common_fpu.h" +#include "xa_nn_common.h" +#include "xa_nnlib_err_chk.h" +//#include "xa_nn_basic_state.h" +#include "xa_nnlib_kernels_api.h" + + +#if !HAVE_VFPU +DISCARD_FUN_FOR_NONVOID_RETURN( + WORD32, xa_nn_elm_greater_lesser_equal_f32xf32_f32, + ( + WORD8 *y, + const FLOAT32 *x1, + const FLOAT32 *x2, + WORD32 N, + WORD32 kernel_type + ) + ) +#else +WORD32 xa_nn_elm_greater_lesser_equal_f32xf32_f32(WORD8 * __restrict__ p_out, + const FLOAT32 * __restrict__ p_inp1, + const FLOAT32 * __restrict__ p_inp2, + WORD32 num_elm, + WORD32 kernel_type) +{ + /* NULL pointer checks */ + XA_NNLIB_ARG_CHK_PTR(p_out, -1); + XA_NNLIB_ARG_CHK_PTR(p_inp1, -1); + XA_NNLIB_ARG_CHK_PTR(p_inp2, -1); + /* Pointer alignment checks */ + XA_NNLIB_ARG_CHK_ALIGN(p_out, sizeof(UWORD8), -1); + XA_NNLIB_ARG_CHK_ALIGN(p_inp1, sizeof(FLOAT32), -1); + XA_NNLIB_ARG_CHK_ALIGN(p_inp2, sizeof(FLOAT32), -1); + /* Basic Parameter checks */ + XA_NNLIB_ARG_CHK_COND((num_elm <= 0), -1); + + int i; + xtfloatx2 *inp1 = (xtfloatx2 *)p_inp1; + xtfloatx2 *inp2 = (xtfloatx2 *)p_inp2; + //xtfloatx2 *out = (xtfloatx2 *)p_out; + UWORD8 *out = p_out; + xtfloatx2 x1, x2, y; + xtbool check; + + xtfloatx2 float_0 = XT_MOV_SX2(AE_ZERO32()); + + if(kernel_type == 0) + { + if(((((unsigned)p_out)&7) == 0) && ((((unsigned)p_inp1)&7) == 0) && ((((unsigned)p_inp2)&7) == 0)) + { + for(i=0;i < num_elm>>1;i++) + { + XT_LSX2IP(x1, inp1, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, inp2, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_LE_xtfloatx2(x2, x1); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *out++ = store1; + + uint8_t store0 = val & 0x1; + *out++ = store0; + } + } + else + { + ae_valign inp1_a, inp2_a, out_a; + + inp1_a = XT_LASX2PP(inp1); + inp2_a = XT_LASX2PP(inp2); + /* Each iteration of loop is independent so safe to use concurrent pragma */ +#pragma concurrent + for(i=0;i < num_elm>>1;i++) + { + XT_LASX2IP(x1, inp1_a, inp1); + XT_LASX2IP(x2, inp2_a, inp2); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_LE_xtfloatx2(x2, x1); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *out++ = store1; + + uint8_t store0 = val & 0x1; + *out++ = store0; + } + } + // Remainder Loop + if (num_elm & 1) + { + xtfloat a1, a2, a; + XT_LSIP(a1, (xtfloat *)inp1, 0); + XT_LSIP(a2, (xtfloat *)inp2, 0); + + a = XT_SUB_S(a2, a1); + + check = 0; + if(a <= 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *out++ = store; + } + } + else if(kernel_type == 1) + { + if(((((unsigned)p_out)&7) == 0) && ((((unsigned)p_inp1)&7) == 0) && ((((unsigned)p_inp2)&7) == 0)) + { + for(i=0;i < num_elm>>1;i++) + { + XT_LSX2IP(x1, inp1, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, inp2, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_LT_xtfloatx2(x2, x1); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *out++ = store1; + + uint8_t store0 = val & 0x1; + *out++ = store0; + } + } + else + { + ae_valign inp1_a, inp2_a, out_a; + + inp1_a = XT_LASX2PP(inp1); + inp2_a = XT_LASX2PP(inp2); + /* Each iteration of loop is independent so safe to use concurrent pragma */ +#pragma concurrent + for(i=0;i < num_elm>>1;i++) + { + XT_LASX2IP(x1, inp1_a, inp1); + XT_LASX2IP(x2, inp2_a, inp2); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_LT_xtfloatx2(x2, x1); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *out++ = store1; + + uint8_t store0 = val & 0x1; + *out++ = store0; + } + } + // Remainder Loop + if (num_elm & 1) + { + xtfloat a1, a2, a; + XT_LSIP(a1, (xtfloat *)inp1, 0); + XT_LSIP(a2, (xtfloat *)inp2, 0); + + a = XT_SUB_S(a2, a1); + + check = 0; + if(a < 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *out++ = store; + } + } + else if(kernel_type == 2) + { + if(((((unsigned)p_out)&7) == 0) && ((((unsigned)p_inp1)&7) == 0) && ((((unsigned)p_inp2)&7) == 0)) + { + for(i=0;i < num_elm>>1;i++) + { + XT_LSX2IP(x1, inp1, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, inp2, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x1, x2); + xtbool2 check = xtfloatx2_LE_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *out++ = store1; + + uint8_t store0 = val & 0x1; + *out++ = store0; + } + } + else + { + ae_valign inp1_a, inp2_a, out_a; + + inp1_a = XT_LASX2PP(inp1); + inp2_a = XT_LASX2PP(inp2); + /* Each iteration of loop is independent so safe to use concurrent pragma */ +#pragma concurrent + for(i=0;i < num_elm>>1;i++) + { + XT_LASX2IP(x1, inp1_a, inp1); + XT_LASX2IP(x2, inp2_a, inp2); + + //y = XT_SUB_SX2(x1, x2); + xtbool2 check = xtfloatx2_LE_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *out++ = store1; + + uint8_t store0 = val & 0x1; + *out++ = store0; + } + } + // Remainder Loop + if (num_elm & 1) + { + xtfloat a1, a2, a; + XT_LSIP(a1, (xtfloat *)inp1, 0); + XT_LSIP(a2, (xtfloat *)inp2, 0); + + a = XT_SUB_S(a1, a2); + + check = 0; + if(a <= 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *out++ = store; + } + } + else if(kernel_type == 3) + { + if(((((unsigned)p_out)&7) == 0) && ((((unsigned)p_inp1)&7) == 0) && ((((unsigned)p_inp2)&7) == 0)) + { + for(i=0;i < num_elm>>1;i++) + { + XT_LSX2IP(x1, inp1, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, inp2, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x1, x2); + xtbool2 check = xtfloatx2_LT_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *out++ = store1; + + uint8_t store0 = val & 0x1; + *out++ = store0; + } + } + else + { + ae_valign inp1_a, inp2_a, out_a; + + inp1_a = XT_LASX2PP(inp1); + inp2_a = XT_LASX2PP(inp2); + /* Each iteration of loop is independent so safe to use concurrent pragma */ +#pragma concurrent + for(i=0;i < num_elm>>1;i++) + { + XT_LASX2IP(x1, inp1_a, inp1); + XT_LASX2IP(x2, inp2_a, inp2); + + //y = XT_SUB_SX2(x1, x2); + xtbool2 check = xtfloatx2_LT_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *out++ = store1; + + uint8_t store0 = val & 0x1; + *out++ = store0; + } + } + // Remainder Loop + if (num_elm & 1) + { + xtfloat a1, a2, a; + XT_LSIP(a1, (xtfloat *)inp1, 0); + XT_LSIP(a2, (xtfloat *)inp2, 0); + + a = XT_SUB_S(a1, a2); + + check = 0; + if(a < 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *out++ = store; + } + } + else if(kernel_type == 4) + { + if(((((unsigned)p_out)&7) == 0) && ((((unsigned)p_inp1)&7) == 0) && ((((unsigned)p_inp2)&7) == 0)) + { + for(i=0;i < num_elm>>1;i++) + { + XT_LSX2IP(x1, inp1, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, inp2, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_EQ_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *out++ = store1; + + uint8_t store0 = val & 0x1; + *out++ = store0; + } + } + else + { + ae_valign inp1_a, inp2_a, out_a; + + inp1_a = XT_LASX2PP(inp1); + inp2_a = XT_LASX2PP(inp2); + /* Each iteration of loop is independent so safe to use concurrent pragma */ +#pragma concurrent + for(i=0;i < num_elm>>1;i++) + { + XT_LASX2IP(x1, inp1_a, inp1); + XT_LASX2IP(x2, inp2_a, inp2); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_EQ_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *out++ = store1; + + uint8_t store0 = val & 0x1; + *out++ = store0; + } + } + // Remainder Loop + if (num_elm & 1) + { + xtfloat a1, a2, a; + XT_LSIP(a1, (xtfloat *)inp1, 0); + XT_LSIP(a2, (xtfloat *)inp2, 0); + + //a = XT_SUB_S(a2, a1); + + check = 0; + if(a1 == a2) + check = 1; + + uint8_t store = AE_MOVAB(check); + *out++ = store; + } + } + else if(kernel_type == 5) + { + ae_int32x2 ones = AE_MOVDA32(1); + if(((((unsigned)p_out)&7) == 0) && ((((unsigned)p_inp1)&7) == 0) && ((((unsigned)p_inp2)&7) == 0)) + { + for(i=0;i < num_elm>>1;i++) + { + XT_LSX2IP(x1, inp1, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, inp2, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_EQ_xtfloatx2(x1, x2); + + ae_int32x2 store = AE_ZERO32(); + AE_MOVF32X2(store, ones, check); + + *out++ = AE_MOVAD32_H(store); + *out++ = AE_MOVAD32_L(store); + } + } + else + { + ae_valign inp1_a, inp2_a, out_a; + + inp1_a = XT_LASX2PP(inp1); + inp2_a = XT_LASX2PP(inp2); + /* Each iteration of loop is independent so safe to use concurrent pragma */ +#pragma concurrent + for(i=0;i < num_elm>>1;i++) + { + XT_LASX2IP(x1, inp1_a, inp1); + XT_LASX2IP(x2, inp2_a, inp2); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_EQ_xtfloatx2(x1, x2); + + ae_int32x2 store = AE_ZERO32(); + AE_MOVF32X2(store, ones, check); + + *out++ = AE_MOVAD32_H(store); + *out++ = AE_MOVAD32_L(store); + } + } + // Remainder Loop + if (num_elm & 1) + { + xtfloat a1, a2, a; + XT_LSIP(a1, (xtfloat *)inp1, 0); + XT_LSIP(a2, (xtfloat *)inp2, 0); + + a = XT_SUB_S(a2, a1); + + check = 0; + if(a != 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *out++ = store; + } + } + + return 0; +} +#endif + +#if HAVE_VFPU +static void internal_elm_greater_lesser_equal_broadcast_2D_f32xf32_f32(UWORD8 * __restrict__ p_out, + const FLOAT32 * __restrict__ p_inp1, + const FLOAT32 * __restrict__ p_inp2, + WORD32 out_lc, + WORD32 in_lc, + xtbool sign_flag, + WORD32 kernel_type) +{ + int i, j; + + xtfloatx2 * __restrict__ p_a = (xtfloatx2 *)p_inp1; + xtfloatx2 * __restrict__ p_b = (xtfloatx2 *)p_inp2; + + xtbool check; + + xtfloatx2 float_0 = XT_MOV_SX2(AE_ZERO32()); + + int num_simd2_ops; + int num_scalar_ops; + + if(out_lc) + { + num_simd2_ops = in_lc >> 1; + num_scalar_ops = in_lc & 1; + } + else + { + num_simd2_ops = (in_lc >> 2) << 1; + num_scalar_ops = in_lc & 3; + } + + xtfloatx2 x1, x2, y; + xtfloat a0, b0, c0; + + /* For computing inp2 - inp1 */ + if(sign_flag){ + for(i = 0; i < out_lc; i++) + { + p_a = (xtfloatx2 *)&p_inp1[i * in_lc]; + p_b = (xtfloatx2 *)p_inp2; + UWORD8 *p_c = (UWORD8 *)&p_out[i * in_lc]; + + if(kernel_type == 0) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_b)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(j = 0; j < num_simd2_ops; j++) + { + XT_LSX2IP(x1, p_a, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, p_b, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x1, x2); + xtbool2 check = xtfloatx2_LE_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign vinp1, vinp2; + vinp1 = XT_LASX2PP(p_a); + vinp2 = XT_LASX2PP(p_b); + for(j = 0; j < num_simd2_ops; j++) + { + XT_LASX2IP(x1, vinp1, p_a); + XT_LASX2IP(x2, vinp2, p_b); + + //y = XT_SUB_SX2(x1, x2); + xtbool2 check = xtfloatx2_LE_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0, (xtfloat *)p_a, sizeof(FLOAT32)); + XT_LSIP(b0, (xtfloat *)p_b, sizeof(FLOAT32)); + c0 = XT_SUB_S(a0, b0); + + check = 0; + + if(c0 <= 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 1) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_b)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(j = 0; j < num_simd2_ops; j++) + { + XT_LSX2IP(x1, p_a, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, p_b, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x1, x2); + xtbool2 check = xtfloatx2_LT_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign vinp1, vinp2; + vinp1 = XT_LASX2PP(p_a); + vinp2 = XT_LASX2PP(p_b); + for(j = 0; j < num_simd2_ops; j++) + { + XT_LASX2IP(x1, vinp1, p_a); + XT_LASX2IP(x2, vinp2, p_b); + + //y = XT_SUB_SX2(x1, x2); + xtbool2 check = xtfloatx2_LT_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0, (xtfloat *)p_a, sizeof(FLOAT32)); + XT_LSIP(b0, (xtfloat *)p_b, sizeof(FLOAT32)); + c0 = XT_SUB_S(a0, b0); + + check = 0; + + if(c0 < 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 2) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_b)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(j = 0; j < num_simd2_ops; j++) + { + XT_LSX2IP(x1, p_a, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, p_b, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_LE_xtfloatx2(x2, x1); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign vinp1, vinp2; + vinp1 = XT_LASX2PP(p_a); + vinp2 = XT_LASX2PP(p_b); + for(j = 0; j < num_simd2_ops; j++) + { + XT_LASX2IP(x1, vinp1, p_a); + XT_LASX2IP(x2, vinp2, p_b); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_LE_xtfloatx2(x2, x1); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0, (xtfloat *)p_a, sizeof(FLOAT32)); + XT_LSIP(b0, (xtfloat *)p_b, sizeof(FLOAT32)); + c0 = XT_SUB_S(b0, a0); + + check = 0; + + if(c0 <= 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 3) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_b)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(j = 0; j < num_simd2_ops; j++) + { + XT_LSX2IP(x1, p_a, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, p_b, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_LT_xtfloatx2(x2, x1); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign vinp1, vinp2; + vinp1 = XT_LASX2PP(p_a); + vinp2 = XT_LASX2PP(p_b); + for(j = 0; j < num_simd2_ops; j++) + { + XT_LASX2IP(x1, vinp1, p_a); + XT_LASX2IP(x2, vinp2, p_b); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_LT_xtfloatx2(x2, x1); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0, (xtfloat *)p_a, sizeof(FLOAT32)); + XT_LSIP(b0, (xtfloat *)p_b, sizeof(FLOAT32)); + c0 = XT_SUB_S(b0, a0); + + check = 0; + + if(c0 < 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 4) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_b)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(j = 0; j < num_simd2_ops; j++) + { + XT_LSX2IP(x1, p_a, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, p_b, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x1, x2); + xtbool2 check = xtfloatx2_EQ_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign vinp1, vinp2; + vinp1 = XT_LASX2PP(p_a); + vinp2 = XT_LASX2PP(p_b); + for(j = 0; j < num_simd2_ops; j++) + { + XT_LASX2IP(x1, vinp1, p_a); + XT_LASX2IP(x2, vinp2, p_b); + + //y = XT_SUB_SX2(x1, x2); + xtbool2 check = xtfloatx2_EQ_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0, (xtfloat *)p_a, sizeof(FLOAT32)); + XT_LSIP(b0, (xtfloat *)p_b, sizeof(FLOAT32)); + //c0 = XT_SUB_S(a0, b0); + + check = 0; + + if(a0 == b0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 5) + { + ae_int32x2 ones = AE_MOVDA32(1); + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_b)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(j = 0; j < num_simd2_ops; j++) + { + XT_LSX2IP(x1, p_a, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, p_b, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x1, x2); + xtbool2 check = xtfloatx2_EQ_xtfloatx2(x1, x2); + + ae_int32x2 store = AE_ZERO32(); + AE_MOVF32X2(store, ones, check); + + *p_c++ = AE_MOVAD32_H(store); + *p_c++ = AE_MOVAD32_L(store); + } + } + else + { + ae_valign vinp1, vinp2; + vinp1 = XT_LASX2PP(p_a); + vinp2 = XT_LASX2PP(p_b); + for(j = 0; j < num_simd2_ops; j++) + { + XT_LASX2IP(x1, vinp1, p_a); + XT_LASX2IP(x2, vinp2, p_b); + + //y = XT_SUB_SX2(x1, x2); + xtbool2 check = xtfloatx2_EQ_xtfloatx2(x1, x2); + + ae_int32x2 store = AE_ZERO32(); + AE_MOVF32X2(store, ones, check); + + *p_c++ = AE_MOVAD32_H(store); + *p_c++ = AE_MOVAD32_L(store); + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0, (xtfloat *)p_a, sizeof(FLOAT32)); + XT_LSIP(b0, (xtfloat *)p_b, sizeof(FLOAT32)); + c0 = XT_SUB_S(a0, b0); + + check = 0; + + if(c0 != 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + } + } + /* For computing inp1 - inp2 */ + else + { + for(i = 0; i < out_lc; i++) + { + p_a = (xtfloatx2 *)&p_inp1[i * in_lc]; + p_b = (xtfloatx2 *)p_inp2; + UWORD8 *p_c = (UWORD8 *)&p_out[i * in_lc]; + + if(kernel_type == 0) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_b)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(j = 0; j < num_simd2_ops; j++) + { + XT_LSX2IP(x1, p_a, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, p_b, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_LE_xtfloatx2(x2, x1); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign vinp1, vinp2; + vinp1 = XT_LASX2PP(p_a); + vinp2 = XT_LASX2PP(p_b); + + for(j = 0; j < num_simd2_ops; j++) + { + XT_LASX2IP(x1, vinp1, p_a); + XT_LASX2IP(x2, vinp2, p_b); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_LE_xtfloatx2(x2, x1); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0, (xtfloat *)p_a, sizeof(FLOAT32)); + XT_LSIP(b0, (xtfloat *)p_b, sizeof(FLOAT32)); + c0 = XT_SUB_S(b0, a0); + + check = 0; + + if(c0 <= 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if (kernel_type == 1) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_b)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(j = 0; j < num_simd2_ops; j++) + { + XT_LSX2IP(x1, p_a, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, p_b, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_LT_xtfloatx2(x2, x1); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign vinp1, vinp2; + vinp1 = XT_LASX2PP(p_a); + vinp2 = XT_LASX2PP(p_b); + + for(j = 0; j < num_simd2_ops; j++) + { + XT_LASX2IP(x1, vinp1, p_a); + XT_LASX2IP(x2, vinp2, p_b); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_LT_xtfloatx2(x2, x1); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0, (xtfloat *)p_a, sizeof(FLOAT32)); + XT_LSIP(b0, (xtfloat *)p_b, sizeof(FLOAT32)); + c0 = XT_SUB_S(b0, a0); + + check = 0; + + if(c0 < 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 2) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_b)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(j = 0; j < num_simd2_ops; j++) + { + XT_LSX2IP(x1, p_a, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, p_b, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x1, x2); + xtbool2 check = xtfloatx2_LE_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign vinp1, vinp2; + vinp1 = XT_LASX2PP(p_a); + vinp2 = XT_LASX2PP(p_b); + + for(j = 0; j < num_simd2_ops; j++) + { + XT_LASX2IP(x1, vinp1, p_a); + XT_LASX2IP(x2, vinp2, p_b); + + //y = XT_SUB_SX2(x1, x2); + xtbool2 check = xtfloatx2_LE_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0, (xtfloat *)p_a, sizeof(FLOAT32)); + XT_LSIP(b0, (xtfloat *)p_b, sizeof(FLOAT32)); + c0 = XT_SUB_S(a0, b0); + + check = 0; + + if(c0 <= 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 3) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_b)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(j = 0; j < num_simd2_ops; j++) + { + XT_LSX2IP(x1, p_a, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, p_b, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x1, x2); + xtbool2 check = xtfloatx2_LT_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign vinp1, vinp2; + vinp1 = XT_LASX2PP(p_a); + vinp2 = XT_LASX2PP(p_b); + + for(j = 0; j < num_simd2_ops; j++) + { + XT_LASX2IP(x1, vinp1, p_a); + XT_LASX2IP(x2, vinp2, p_b); + + //y = XT_SUB_SX2(x1, x2); + xtbool2 check = xtfloatx2_LT_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0, (xtfloat *)p_a, sizeof(FLOAT32)); + XT_LSIP(b0, (xtfloat *)p_b, sizeof(FLOAT32)); + c0 = XT_SUB_S(a0, b0); + + check = 0; + + if(c0 < 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 4) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_b)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(j = 0; j < num_simd2_ops; j++) + { + XT_LSX2IP(x1, p_a, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, p_b, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_EQ_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign vinp1, vinp2; + vinp1 = XT_LASX2PP(p_a); + vinp2 = XT_LASX2PP(p_b); + + for(j = 0; j < num_simd2_ops; j++) + { + XT_LASX2IP(x1, vinp1, p_a); + XT_LASX2IP(x2, vinp2, p_b); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_EQ_xtfloatx2(x1, x2); + + uint8_t val = AE_MOVAB2(check); + + uint8_t store1 = (val >> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0, (xtfloat *)p_a, sizeof(FLOAT32)); + XT_LSIP(b0, (xtfloat *)p_b, sizeof(FLOAT32)); + //c0 = XT_SUB_S(b0, a0); + + check = 0; + + if(a0 == b0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 5) + { + ae_int32x2 ones = AE_MOVDA32(1); + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_b)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(j = 0; j < num_simd2_ops; j++) + { + XT_LSX2IP(x1, p_a, 2*sizeof(FLOAT32)); + XT_LSX2IP(x2, p_b, 2*sizeof(FLOAT32)); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_EQ_xtfloatx2(x1, x2); + + ae_int32x2 store = AE_ZERO32(); + AE_MOVF32X2(store, ones, check); + + *p_c++ = AE_MOVAD32_H(store); + *p_c++ = AE_MOVAD32_L(store); + } + } + else + { + ae_valign vinp1, vinp2; + vinp1 = XT_LASX2PP(p_a); + vinp2 = XT_LASX2PP(p_b); + + for(j = 0; j < num_simd2_ops; j++) + { + XT_LASX2IP(x1, vinp1, p_a); + XT_LASX2IP(x2, vinp2, p_b); + + //y = XT_SUB_SX2(x2, x1); + xtbool2 check = xtfloatx2_EQ_xtfloatx2(x1, x2); + + ae_int32x2 store = AE_ZERO32(); + AE_MOVF32X2(store, ones, check); + + *p_c++ = AE_MOVAD32_H(store); + *p_c++ = AE_MOVAD32_L(store); + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0, (xtfloat *)p_a, sizeof(FLOAT32)); + XT_LSIP(b0, (xtfloat *)p_b, sizeof(FLOAT32)); + c0 = XT_SUB_S(b0, a0); + + check = 0; + + if(c0 != 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + } + } +} + +static void internal_elm_greater_lesser_equal_broadcast_f32xf32_f32(UWORD8 * __restrict__ p_out, + const FLOAT32 * __restrict__ p_inp1, + const FLOAT32 * __restrict__ p_inp2, + WORD32 num_elm, + xtbool sign_flag, + WORD32 kernel_type) +{ + int i; + xtfloatx2 * __restrict__ p_a = (xtfloatx2 *)p_inp1; + xtfloatx2 * __restrict__ p_b = (xtfloatx2 *)p_inp2; + + xtbool check; + + UWORD8 * p_c = p_out; + xtfloatx2 float_0 = XT_MOV_SX2(AE_ZERO32()); + + const int num_simd2_ops = num_elm >> 1; + const int num_scalar_ops = num_elm & 1; + + xtfloat a0_7, out; + xtfloatx2 x1, x2, y; + x2 = XT_LSI((xtfloat *)p_b, 0); + + /* For computing inp2 - inp1 */ + if(sign_flag){ + if(kernel_type == 0) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign inp1_a, out_a; + inp1_a = XT_LASX2PP(p_a); + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0_7, (xtfloat *)p_a, sizeof(FLOAT32)); + out = XT_SUB_S(a0_7, x2); + + check = 0; + + if(out <= 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 1) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign inp1_a, out_a; + inp1_a = XT_LASX2PP(p_a); + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0_7, (xtfloat *)p_a, sizeof(FLOAT32)); + out = XT_SUB_S(a0_7, x2); + + check = 0; + + if(out < 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 2) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign inp1_a, out_a; + inp1_a = XT_LASX2PP(p_a); + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0_7, (xtfloat *)p_a, sizeof(FLOAT32)); + out = XT_SUB_S(x2, a0_7); + + check = 0; + + if(out <= 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 3) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign inp1_a, out_a; + inp1_a = XT_LASX2PP(p_a); + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0_7, (xtfloat *)p_a, sizeof(FLOAT32)); + out = XT_SUB_S(x2, a0_7); + + check = 0; + + if(out < 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 4) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign inp1_a, out_a; + inp1_a = XT_LASX2PP(p_a); + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0_7, (xtfloat *)p_a, sizeof(FLOAT32)); + out = XT_SUB_S(a0_7, x2); + + check = 0; + + if(out == 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 5) + { + ae_int32x2 ones = AE_MOVDA32(1); + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign inp1_a, out_a; + inp1_a = XT_LASX2PP(p_a); + + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0_7, (xtfloat *)p_a, sizeof(FLOAT32)); + out = XT_SUB_S(x2, a0_7); + + check = 0; + + if(out <= 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 1) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign inp1_a, out_a; + inp1_a = XT_LASX2PP(p_a); + + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0_7, (xtfloat *)p_a, sizeof(FLOAT32)); + out = XT_SUB_S(x2, a0_7); + + check = 0; + + if(out < 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 2) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign inp1_a, out_a; + inp1_a = XT_LASX2PP(p_a); + + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0_7, (xtfloat *)p_a, sizeof(FLOAT32)); + out = XT_SUB_S(a0_7, x2); + + check = 0; + + if(out <= 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 3) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign inp1_a, out_a; + inp1_a = XT_LASX2PP(p_a); + + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0_7, (xtfloat *)p_a, sizeof(FLOAT32)); + out = XT_SUB_S(a0_7, x2); + + check = 0; + + if(out < 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + else if(kernel_type == 4) + { + if(((((unsigned)p_a)&7) == 0) && ((((unsigned)p_c)&7) == 0)) + { + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + else + { + ae_valign inp1_a, out_a; + inp1_a = XT_LASX2PP(p_a); + + for(i=0; i> 1) & 0x1; + *p_c++ = store1; + + uint8_t store0 = val & 0x1; + *p_c++ = store0; + } + } + if(num_scalar_ops !=0) + { + XT_LSIP(a0_7, (xtfloat *)p_a, sizeof(FLOAT32)); + out = XT_SUB_S(x2, a0_7); + + check = 0; + + if(out == 0) + check = 1; + + uint8_t store = AE_MOVAB(check); + *p_c++ = store; + } + } + } +} +#endif + +#if !HAVE_VFPU +DISCARD_FUN_FOR_NONVOID_RETURN( + WORD32, xa_nn_elm_greaterequal_broadcast_4D_f32xf32_f32, + ( + WORD8 * p_out, + const WORD32 *const p_out_shape, + const FLOAT32 * p_inp1, + const WORD32 *const p_inp1_shape, + const FLOAT32 * p_inp2, + const WORD32 *const p_inp2_shape, + WORD32 kernel_type + ) + ) +#else +WORD32 xa_nn_elm_greater_lesser_equal_broadcast_4D_f32xf32_f32(WORD8 * __restrict__ p_out, + const WORD32 *const p_out_shape, + const FLOAT32 * __restrict__ p_inp1, + const WORD32 *const p_inp1_shape, + const FLOAT32 * __restrict__ p_inp2, + const WORD32 *const p_inp2_shape, + WORD32 kernel_type) +{ + /* NULL pointer checks */ + XA_NNLIB_ARG_CHK_PTR(p_out, -1); + XA_NNLIB_ARG_CHK_PTR(p_inp1, -1); + XA_NNLIB_ARG_CHK_PTR(p_inp2, -1); + XA_NNLIB_ARG_CHK_PTR(p_out_shape, -1); + XA_NNLIB_ARG_CHK_PTR(p_inp1_shape, -1); + XA_NNLIB_ARG_CHK_PTR(p_inp2_shape, -1); + /* Pointer alignment checks */ + XA_NNLIB_ARG_CHK_ALIGN(p_out, sizeof(UWORD8), -1); + XA_NNLIB_ARG_CHK_ALIGN(p_inp1, sizeof(FLOAT32), -1); + XA_NNLIB_ARG_CHK_ALIGN(p_inp2, sizeof(FLOAT32), -1); + XA_NNLIB_ARG_CHK_ALIGN(p_out_shape, sizeof(WORD32), -1); + XA_NNLIB_ARG_CHK_ALIGN(p_inp1_shape, sizeof(WORD32), -1); + XA_NNLIB_ARG_CHK_ALIGN(p_inp2_shape, sizeof(WORD32), -1); + + /* Check shapes */ + int i; + xtbool sign_flag; + for(i = 0; i < 4; i++) + { + if((p_inp1_shape[i] != p_inp2_shape[i] && p_inp1_shape[i] != 1 && p_inp2_shape[i] != 1) || + (p_out_shape[i] != (p_inp1_shape[i] > p_inp2_shape[i] ? p_inp1_shape[i] : p_inp2_shape[i]))) + { + return -1; + } + } + + WORD32 inp1_strides[4], inp2_strides[4]; + inp1_strides[3] = 1; + inp2_strides[3] = 1; + for(i = 2; i >= 0; i--) + { + ae_int32x2 d_str, d_shape; + d_str = AE_MOVDA32X2(inp1_strides[i + 1], inp2_strides[i + 1]); + d_shape = AE_MOVDA32X2(p_inp1_shape[i + 1], p_inp2_shape[i + 1]); + d_str = AE_MULP32X2(d_str, d_shape); + inp1_strides[i] = AE_MOVAD32_H(d_str); + inp2_strides[i] = AE_MOVAD32_L(d_str); + } + + int need_broadcast = 0; + int inp1_const = 1, inp2_const = 1; + for(i = 0; i < 4; i++) + { + if(p_inp1_shape[i] != p_inp2_shape[i]) + { + if(p_inp1_shape[i] == 1) + inp1_strides[i] = 0; + else + inp2_strides[i] = 0; + + need_broadcast = 1; + } + if(p_inp1_shape[i] != 1) + inp1_const &= 0; + if(p_inp2_shape[i] != 1) + inp2_const &= 0; + } + int itr0, itr1, itr2; + + UWORD8 *p_out_tmp = p_out; + const FLOAT32 *__restrict__ p_inp1_tmp = p_inp1; + const FLOAT32 *__restrict__ p_inp2_tmp = p_inp2; + if(need_broadcast == 0) + { + sign_flag = 0; + internal_elm_greater_lesser_equal_broadcast_2D_f32xf32_f32( + p_out, + p_inp1, + p_inp2, + 1, + p_out_shape[0] * inp1_strides[0], + sign_flag, + kernel_type); + } + else if(inp1_strides[3] == inp2_strides[3]) + { + WORD32 in_lc, out_lc; + sign_flag = 0; + in_lc = p_out_shape[2] * p_out_shape[3]; + out_lc = 1; + if(inp1_strides[2] == 0) + { + const FLOAT32 *tmp; + tmp = p_inp1_tmp; p_inp1_tmp = p_inp2_tmp; p_inp2_tmp = tmp; + sign_flag = 1; + int tmp_strides[2]; + tmp_strides[0] = inp1_strides[0]; + tmp_strides[1] = inp1_strides[1]; + + inp1_strides[0] = inp2_strides[0]; + inp1_strides[1] = inp2_strides[1]; + + inp2_strides[0] = tmp_strides[0]; + inp2_strides[1] = tmp_strides[1]; + in_lc = p_out_shape[3]; + out_lc = p_out_shape[2]; + } + else if(inp2_strides[2] == 0) + { + in_lc = p_out_shape[3]; + out_lc = p_out_shape[2]; + } + + for(itr0 = 0; itr0 < p_out_shape[0]; itr0++) + { + const FLOAT32 *__restrict__ p_inp1_tmp0 = p_inp1_tmp; + const FLOAT32 *__restrict__ p_inp2_tmp0 = p_inp2_tmp; + for(itr1 = 0; itr1 < p_out_shape[1]; itr1++) + { + internal_elm_greater_lesser_equal_broadcast_2D_f32xf32_f32( + p_out_tmp, + p_inp1_tmp0, + p_inp2_tmp0, + out_lc, + in_lc, + sign_flag, + kernel_type); + p_out_tmp += in_lc * out_lc; + p_inp1_tmp0 += inp1_strides[1]; + p_inp2_tmp0 += inp2_strides[1]; + } + p_inp1_tmp += inp1_strides[0]; + p_inp2_tmp += inp2_strides[0]; + } + } + else if(inp1_const == 1 || inp2_const == 1) + { + sign_flag = 0; + if(inp1_strides[3] == 0) + { + sign_flag = 1; + const FLOAT32 *tmp; + tmp = p_inp1_tmp; p_inp1_tmp = p_inp2_tmp; p_inp2_tmp = tmp; + } + internal_elm_greater_lesser_equal_broadcast_f32xf32_f32( + p_out_tmp, + p_inp1_tmp, + p_inp2_tmp, + p_out_shape[0] * p_out_shape[1] * p_out_shape[2] * p_out_shape[3], + sign_flag, + kernel_type); + } + else + { + sign_flag = 0; + if(inp1_strides[3] == 0) + { + const FLOAT32 *tmp; + tmp = p_inp1_tmp; p_inp1_tmp = p_inp2_tmp; p_inp2_tmp = tmp; + sign_flag = 1; + int tmp_strides[3]; + tmp_strides[0] = inp1_strides[0]; + tmp_strides[1] = inp1_strides[1]; + tmp_strides[2] = inp1_strides[2]; + + inp1_strides[0] = inp2_strides[0]; + inp1_strides[1] = inp2_strides[1]; + inp1_strides[2] = inp2_strides[2]; + + inp2_strides[0] = tmp_strides[0]; + inp2_strides[1] = tmp_strides[1]; + inp2_strides[2] = tmp_strides[2]; + } + for(itr0 = 0; itr0 < p_out_shape[0]; itr0++) + { + const FLOAT32 *__restrict__ p_inp1_tmp0 = p_inp1_tmp; + const FLOAT32 *__restrict__ p_inp2_tmp0 = p_inp2_tmp; + for(itr1 = 0; itr1 < p_out_shape[1]; itr1++) + { + const FLOAT32 *__restrict__ p_inp1_tmp1 = p_inp1_tmp0; + const FLOAT32 *__restrict__ p_inp2_tmp1 = p_inp2_tmp0; + for(itr2 = 0; itr2 < p_out_shape[2]; itr2++) + { + { + internal_elm_greater_lesser_equal_broadcast_f32xf32_f32( + p_out_tmp, + p_inp1_tmp1, + p_inp2_tmp1, + p_out_shape[3], + sign_flag, + kernel_type); + } + p_out_tmp += p_out_shape[3]; + p_inp1_tmp1 += inp1_strides[2]; + p_inp2_tmp1 += inp2_strides[2]; + } + p_inp1_tmp0 += inp1_strides[1]; + p_inp2_tmp0 += inp2_strides[1]; + } + p_inp1_tmp += inp1_strides[0]; + p_inp2_tmp += inp2_strides[0]; + } + } + return 0; +} +#endif