diff --git a/backends/cadence/hifi/operators/operators.h b/backends/cadence/hifi/operators/operators.h index fdd87f833f9..325da424225 100644 --- a/backends/cadence/hifi/operators/operators.h +++ b/backends/cadence/hifi/operators/operators.h @@ -29,6 +29,13 @@ void quantize_per_tensor_out( ::executorch::aten::ScalarType dtype, ::executorch::aten::Tensor& out); +::executorch::aten::Tensor& div_out_mode( + ::executorch::runtime::KernelRuntimeContext& ctx, + const ::executorch::aten::Tensor& a, + const ::executorch::aten::Tensor& b, + ::executorch::aten::optional<::executorch::aten::string_view> mode, + ::executorch::aten::Tensor& out); + } // namespace native } // namespace HiFi } // namespace impl diff --git a/backends/cadence/hifi/operators/tests/test_op_div.cpp b/backends/cadence/hifi/operators/tests/test_op_div.cpp new file mode 100644 index 00000000000..98ee6cb63ee --- /dev/null +++ b/backends/cadence/hifi/operators/tests/test_op_div.cpp @@ -0,0 +1,73 @@ +/* + * 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 +#include +#include +#include + +#include + +namespace cadence { +namespace impl { +namespace HiFi { +namespace native { +namespace { + +using ::executorch::aten::optional; +using ::executorch::aten::Scalar; +using ::executorch::aten::ScalarType; +using ::executorch::aten::string_view; +using ::executorch::aten::Tensor; +using ::executorch::aten::TensorImpl; +using ::executorch::runtime::Error; +using ::executorch::runtime::KernelRuntimeContext; +using ::executorch::runtime::runtime_init; +using ::executorch::runtime::testing::TensorFactory; + +class HiFiDivTest : public OperatorTest { + public: + protected: + Tensor& div_out_mode( + const Tensor& a, + const Tensor& b, + optional mode, + Tensor& out) { + return ::cadence::impl::HiFi::native::div_out_mode( + context_, a, b, mode, out); + } +}; + +// TODO: Enable once hifi div_out is fixed. +TEST_F(HiFiDivTest, DISABLED_Int32FloorDivideTest) { + TensorFactory tf; + const std::vector sizes{4, 5, 6}; + Tensor out = tf.zeros(sizes); + constexpr int32_t kNumerator = 73; + constexpr int32_t kDenominator = 55; + // Floor division (73 / 55) = 1. + constexpr int32_t kExpectedResult = kNumerator / kDenominator; + const Tensor numerator = tf.full(sizes, kNumerator); + const Tensor denominator = tf.full(sizes, kDenominator); + + div_out_mode(numerator, denominator, "floor", out); + + EXPECT_TENSOR_EQ(out, tf.full(sizes, kExpectedResult)); +} + +} // namespace +} // namespace native +} // namespace HiFi +} // namespace impl +} // namespace cadence