|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | + |
| 9 | +#include <gtest/gtest.h> |
| 10 | +#include <sys/times.h> |
| 11 | +#include <xtensa/sim.h> |
| 12 | + |
| 13 | +#include <executorch/kernels/test/TestUtil.h> |
| 14 | +#include <executorch/runtime/core/error.h> |
| 15 | +#include <executorch/runtime/core/exec_aten/exec_aten.h> |
| 16 | +#include <executorch/runtime/core/exec_aten/testing_util/tensor_factory.h> |
| 17 | +#include <executorch/runtime/core/exec_aten/testing_util/tensor_util.h> |
| 18 | +#include <executorch/runtime/platform/runtime.h> |
| 19 | + |
| 20 | +#include <executorch/backends/cadence/hifi/operators/operators.h> |
| 21 | + |
| 22 | +namespace cadence { |
| 23 | +namespace impl { |
| 24 | +namespace HiFi { |
| 25 | +namespace native { |
| 26 | +namespace { |
| 27 | + |
| 28 | +using ::executorch::aten::optional; |
| 29 | +using ::executorch::aten::Scalar; |
| 30 | +using ::executorch::aten::ScalarType; |
| 31 | +using ::executorch::aten::string_view; |
| 32 | +using ::executorch::aten::Tensor; |
| 33 | +using ::executorch::aten::TensorImpl; |
| 34 | +using ::executorch::runtime::Error; |
| 35 | +using ::executorch::runtime::KernelRuntimeContext; |
| 36 | +using ::executorch::runtime::runtime_init; |
| 37 | +using ::executorch::runtime::testing::TensorFactory; |
| 38 | + |
| 39 | +class HiFiDivTest : public OperatorTest { |
| 40 | + public: |
| 41 | + protected: |
| 42 | + Tensor& div_out_mode( |
| 43 | + const Tensor& a, |
| 44 | + const Tensor& b, |
| 45 | + optional<string_view> mode, |
| 46 | + Tensor& out) { |
| 47 | + return ::cadence::impl::HiFi::native::div_out_mode( |
| 48 | + context_, a, b, mode, out); |
| 49 | + } |
| 50 | +}; |
| 51 | + |
| 52 | +// TODO: Enable once hifi div_out is fixed. |
| 53 | +TEST_F(HiFiDivTest, DISABLED_Int32FloorDivideTest) { |
| 54 | + TensorFactory<ScalarType::Int> tf; |
| 55 | + const std::vector<int> sizes{4, 5, 6}; |
| 56 | + Tensor out = tf.zeros(sizes); |
| 57 | + constexpr int32_t kNumerator = 73; |
| 58 | + constexpr int32_t kDenominator = 55; |
| 59 | + // Floor division (73 / 55) = 1. |
| 60 | + constexpr int32_t kExpectedResult = kNumerator / kDenominator; |
| 61 | + const Tensor numerator = tf.full(sizes, kNumerator); |
| 62 | + const Tensor denominator = tf.full(sizes, kDenominator); |
| 63 | + |
| 64 | + div_out_mode(numerator, denominator, "floor", out); |
| 65 | + |
| 66 | + EXPECT_TENSOR_EQ(out, tf.full(sizes, kExpectedResult)); |
| 67 | +} |
| 68 | + |
| 69 | +} // namespace |
| 70 | +} // namespace native |
| 71 | +} // namespace HiFi |
| 72 | +} // namespace impl |
| 73 | +} // namespace cadence |
0 commit comments