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 <executorch/kernels/portable/cpu/util/elementwise_util.h>
10 #include <executorch/runtime/kernel/kernel_includes.h>
11
12 namespace torch {
13 namespace executor {
14 namespace native {
15 namespace internal {
16
17 /**
18 * Implements an op pattern for ops that take two broadcastable input tensors
19 * and performs an element-wise binary logical operation `fn`.
20 */
21 template <const char* op_name>
logical_tensor_out(bool (* fn)(bool,bool),KernelRuntimeContext & ctx,const Tensor & a,const Tensor & b,Tensor & out)22 Tensor& logical_tensor_out(
23 bool (*fn)(bool, bool),
24 KernelRuntimeContext& ctx,
25 const Tensor& a,
26 const Tensor& b,
27 Tensor& out) {
28 ET_KERNEL_CHECK(
29 ctx, tensors_have_same_dim_order(a, b, out), InvalidArgument, out);
30
31 ET_KERNEL_CHECK(
32 ctx,
33 resize_to_broadcast_target_size(a, b, out) == Error::Ok,
34 InvalidArgument,
35 out);
36
37 utils::apply_bitensor_elementwise_fn<bool, op_name>(
38 fn,
39 ctx,
40 a,
41 utils::SupportedTensorDtypes::REALHBBF16,
42 b,
43 utils::SupportedTensorDtypes::REALHBBF16,
44 out,
45 utils::SupportedTensorDtypes::REALHBBF16);
46
47 return out;
48 }
49
50 } // namespace internal
51 } // namespace native
52 } // namespace executor
53 } // namespace torch
54