Skip to content

Commit df75088

Browse files
authored
Add test for floor divide.
Differential Revision: D73675567 Pull Request resolved: #10483
1 parent 9ea9313 commit df75088

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

backends/cadence/hifi/operators/operators.h

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ void quantize_per_tensor_out(
2929
::executorch::aten::ScalarType dtype,
3030
::executorch::aten::Tensor& out);
3131

32+
::executorch::aten::Tensor& div_out_mode(
33+
::executorch::runtime::KernelRuntimeContext& ctx,
34+
const ::executorch::aten::Tensor& a,
35+
const ::executorch::aten::Tensor& b,
36+
::executorch::aten::optional<::executorch::aten::string_view> mode,
37+
::executorch::aten::Tensor& out);
38+
3239
} // namespace native
3340
} // namespace HiFi
3441
} // namespace impl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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

Comments
 (0)