arch/NEON/UnaryFunctors.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // This Source Code Form is subject to the terms of the Mozilla
5 // Public License v. 2.0. If a copy of the MPL was not distributed
6 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 
8 #ifndef EIGEN_NEON_UNARY_FUNCTORS_H
9 #define EIGEN_NEON_UNARY_FUNCTORS_H
10 
11 #include "../../InternalHeaderCheck.h"
12 
13 namespace Eigen {
14 
15 namespace internal {
16 
17 #if EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC
21 template <>
22 struct scalar_logistic_op<Eigen::half> {
23  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
24  Eigen::half operator()(const Eigen::half& x) const {
25  // Convert to float and call scalar_logistic_op<float>.
26  const scalar_logistic_op<float> float_op;
27  return Eigen::half(float_op(float(x)));
28  }
29 
30  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
31  Eigen::half packetOp(const Eigen::half& x) const {
32  return this->operator()(x);
33  }
34 
35  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
36  Packet4hf packetOp(const Packet4hf& x) const {
37  const scalar_logistic_op<float> float_op;
38  return vcvt_f16_f32(float_op.packetOp(vcvt_f32_f16(x)));
39  }
40 
41  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
42  Packet8hf packetOp(const Packet8hf& x) const {
43  const scalar_logistic_op<float> float_op;
44  return vcombine_f16(
45  vcvt_f16_f32(float_op.packetOp(vcvt_f32_f16(vget_low_f16(x)))),
46  vcvt_f16_f32(float_op.packetOp(vcvt_high_f32_f16(x))));
47  }
48 };
49 
50 template<>
51 struct functor_traits<scalar_logistic_op<Eigen::half>> {
52  enum {
53  Cost = functor_traits<scalar_logistic_op<float>>::Cost,
54  PacketAccess = functor_traits<scalar_logistic_op<float>>::PacketAccess,
55  };
56 };
57 #endif // EIGEN_HAS_ARM64_FP16_VECTOR_ARITHMETIC
58 
59 } // end namespace internal
60 
61 } // end namespace Eigen
62 
63 #endif // EIGEN_NEON_UNARY_FUNCTORS_H
IndexedView_or_Block operator()(const RowIndices &rowIndices, const ColIndices &colIndices)
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
: InteropHeaders
Definition: Core:139