Assign_MKL.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2011, Intel Corporation. All rights reserved.
3  Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr>
4 
5  Redistribution and use in source and binary forms, with or without modification,
6  are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation
12  and/or other materials provided with the distribution.
13  * Neither the name of Intel Corporation nor the names of its contributors may
14  be used to endorse or promote products derived from this software without
15  specific prior written permission.
16 
17  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28  ********************************************************************************
29  * Content : Eigen bindings to Intel(R) MKL
30  * MKL VML support for coefficient-wise unary Eigen expressions like a=b.sin()
31  ********************************************************************************
32 */
33 
34 #ifndef EIGEN_ASSIGN_VML_H
35 #define EIGEN_ASSIGN_VML_H
36 
37 namespace Eigen {
38 
39 namespace internal {
40 
41 template<typename Dst, typename Src>
43 {
44  private:
45  enum {
48  StorageOrdersAgree = (int(Dst::IsRowMajor) == int(Src::IsRowMajor)),
49  InnerSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::SizeAtCompileTime)
50  : int(Dst::Flags)&RowMajorBit ? int(Dst::ColsAtCompileTime)
51  : int(Dst::RowsAtCompileTime),
52  InnerMaxSize = int(Dst::IsVectorAtCompileTime) ? int(Dst::MaxSizeAtCompileTime)
53  : int(Dst::Flags)&RowMajorBit ? int(Dst::MaxColsAtCompileTime)
54  : int(Dst::MaxRowsAtCompileTime),
55  MaxSizeAtCompileTime = Dst::SizeAtCompileTime,
56 
57  MightEnableVml = StorageOrdersAgree && DstHasDirectAccess && SrcHasDirectAccess && Src::InnerStrideAtCompileTime==1 && Dst::InnerStrideAtCompileTime==1,
58  MightLinearize = MightEnableVml && (int(Dst::Flags) & int(Src::Flags) & LinearAccessBit),
60  LargeEnough = VmlSize==Dynamic || VmlSize>=EIGEN_MKL_VML_THRESHOLD
61  };
62  public:
63  enum {
64  EnableVml = MightEnableVml && LargeEnough,
66  };
67 };
68 
69 #define EIGEN_PP_EXPAND(ARG) ARG
70 #if !defined (EIGEN_FAST_MATH) || (EIGEN_FAST_MATH != 1)
71 #define EIGEN_VMLMODE_EXPAND_xLA , VML_HA
72 #else
73 #define EIGEN_VMLMODE_EXPAND_xLA , VML_LA
74 #endif
75 
76 #define EIGEN_VMLMODE_EXPAND_x_
77 
78 #define EIGEN_VMLMODE_PREFIX_xLA vm
79 #define EIGEN_VMLMODE_PREFIX_x_ v
80 #define EIGEN_VMLMODE_PREFIX(VMLMODE) EIGEN_CAT(EIGEN_VMLMODE_PREFIX_x,VMLMODE)
81 
82 #define EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, VMLOP, EIGENTYPE, VMLTYPE, VMLMODE) \
83  template< typename DstXprType, typename SrcXprNested> \
84  struct Assignment<DstXprType, CwiseUnaryOp<scalar_##EIGENOP##_op<EIGENTYPE>, SrcXprNested>, assign_op<EIGENTYPE,EIGENTYPE>, \
85  Dense2Dense, typename enable_if<vml_assign_traits<DstXprType,SrcXprNested>::EnableVml>::type> { \
86  typedef CwiseUnaryOp<scalar_##EIGENOP##_op<EIGENTYPE>, SrcXprNested> SrcXprType; \
87  static void run(DstXprType &dst, const SrcXprType &src, const assign_op<EIGENTYPE,EIGENTYPE> &func) { \
88  resize_if_allowed(dst, src, func); \
89  eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); \
90  if(vml_assign_traits<DstXprType,SrcXprNested>::Traversal==LinearTraversal) { \
91  VMLOP(dst.size(), (const VMLTYPE*)src.nestedExpression().data(), \
92  (VMLTYPE*)dst.data() EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE) ); \
93  } else { \
94  const Index outerSize = dst.outerSize(); \
95  for(Index outer = 0; outer < outerSize; ++outer) { \
96  const EIGENTYPE *src_ptr = src.IsRowMajor ? &(src.nestedExpression().coeffRef(outer,0)) : \
97  &(src.nestedExpression().coeffRef(0, outer)); \
98  EIGENTYPE *dst_ptr = dst.IsRowMajor ? &(dst.coeffRef(outer,0)) : &(dst.coeffRef(0, outer)); \
99  VMLOP( dst.innerSize(), (const VMLTYPE*)src_ptr, \
100  (VMLTYPE*)dst_ptr EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE)); \
101  } \
102  } \
103  } \
104  }; \
105 
106 
107 #define EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(EIGENOP, VMLOP, VMLMODE) \
108  EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE),s##VMLOP), float, float, VMLMODE) \
109  EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE),d##VMLOP), double, double, VMLMODE)
110 
111 #define EIGEN_MKL_VML_DECLARE_UNARY_CALLS_CPLX(EIGENOP, VMLOP, VMLMODE) \
112  EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE),c##VMLOP), scomplex, MKL_Complex8, VMLMODE) \
113  EIGEN_MKL_VML_DECLARE_UNARY_CALL(EIGENOP, EIGEN_CAT(EIGEN_VMLMODE_PREFIX(VMLMODE),z##VMLOP), dcomplex, MKL_Complex16, VMLMODE)
114 
115 #define EIGEN_MKL_VML_DECLARE_UNARY_CALLS(EIGENOP, VMLOP, VMLMODE) \
116  EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(EIGENOP, VMLOP, VMLMODE) \
117  EIGEN_MKL_VML_DECLARE_UNARY_CALLS_CPLX(EIGENOP, VMLOP, VMLMODE)
118 
119 
129 // EIGEN_MKL_VML_DECLARE_UNARY_CALLS(abs, Abs, _)
134 
140 
141 #define EIGEN_MKL_VML_DECLARE_POW_CALL(EIGENOP, VMLOP, EIGENTYPE, VMLTYPE, VMLMODE) \
142  template< typename DstXprType, typename SrcXprNested, typename Plain> \
143  struct Assignment<DstXprType, CwiseBinaryOp<scalar_##EIGENOP##_op<EIGENTYPE,EIGENTYPE>, SrcXprNested, \
144  const CwiseNullaryOp<internal::scalar_constant_op<EIGENTYPE>,Plain> >, assign_op<EIGENTYPE,EIGENTYPE>, \
145  Dense2Dense, typename enable_if<vml_assign_traits<DstXprType,SrcXprNested>::EnableVml>::type> { \
146  typedef CwiseBinaryOp<scalar_##EIGENOP##_op<EIGENTYPE,EIGENTYPE>, SrcXprNested, \
147  const CwiseNullaryOp<internal::scalar_constant_op<EIGENTYPE>,Plain> > SrcXprType; \
148  static void run(DstXprType &dst, const SrcXprType &src, const assign_op<EIGENTYPE,EIGENTYPE> &func) { \
149  resize_if_allowed(dst, src, func); \
150  eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols()); \
151  VMLTYPE exponent = reinterpret_cast<const VMLTYPE&>(src.rhs().functor().m_other); \
152  if(vml_assign_traits<DstXprType,SrcXprNested>::Traversal==LinearTraversal) \
153  { \
154  VMLOP( dst.size(), (const VMLTYPE*)src.lhs().data(), exponent, \
155  (VMLTYPE*)dst.data() EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE) ); \
156  } else { \
157  const Index outerSize = dst.outerSize(); \
158  for(Index outer = 0; outer < outerSize; ++outer) { \
159  const EIGENTYPE *src_ptr = src.IsRowMajor ? &(src.lhs().coeffRef(outer,0)) : \
160  &(src.lhs().coeffRef(0, outer)); \
161  EIGENTYPE *dst_ptr = dst.IsRowMajor ? &(dst.coeffRef(outer,0)) : &(dst.coeffRef(0, outer)); \
162  VMLOP( dst.innerSize(), (const VMLTYPE*)src_ptr, exponent, \
163  (VMLTYPE*)dst_ptr EIGEN_PP_EXPAND(EIGEN_VMLMODE_EXPAND_x##VMLMODE)); \
164  } \
165  } \
166  } \
167  };
168 
169 EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmsPowx, float, float, LA)
170 EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmdPowx, double, double, LA)
171 EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmcPowx, scomplex, MKL_Complex8, LA)
172 EIGEN_MKL_VML_DECLARE_POW_CALL(pow, vmzPowx, dcomplex, MKL_Complex16, LA)
173 
174 } // end namespace internal
175 
176 } // end namespace Eigen
177 
178 #endif // EIGEN_ASSIGN_VML_H
Eigen::internal::vml_assign_traits::MightLinearize
@ MightLinearize
Definition: Assign_MKL.h:58
gtsam.examples.DogLegOptimizerExample.int
int
Definition: DogLegOptimizerExample.py:111
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
atan
const EIGEN_DEVICE_FUNC AtanReturnType atan() const
Definition: ArrayCwiseUnaryOps.h:283
ceres::sin
Jet< T, N > sin(const Jet< T, N > &f)
Definition: jet.h:439
Eigen::DefaultTraversal
@ DefaultTraversal
Definition: Constants.h:277
Eigen::internal::vml_assign_traits::Traversal
@ Traversal
Definition: Assign_MKL.h:65
Eigen::RowMajorBit
const unsigned int RowMajorBit
Definition: Constants.h:66
EIGEN_MKL_VML_DECLARE_POW_CALL
#define EIGEN_MKL_VML_DECLARE_POW_CALL(EIGENOP, VMLOP, EIGENTYPE, VMLTYPE, VMLMODE)
Definition: Assign_MKL.h:141
log
const EIGEN_DEVICE_FUNC LogReturnType log() const
Definition: ArrayCwiseUnaryOps.h:128
EIGEN_MKL_VML_DECLARE_UNARY_CALLS
#define EIGEN_MKL_VML_DECLARE_UNARY_CALLS(EIGENOP, VMLOP, VMLMODE)
Definition: Assign_MKL.h:115
Eigen::internal::vml_assign_traits::MightEnableVml
@ MightEnableVml
Definition: Assign_MKL.h:57
asin
const EIGEN_DEVICE_FUNC AsinReturnType asin() const
Definition: ArrayCwiseUnaryOps.h:311
exp
const EIGEN_DEVICE_FUNC ExpReturnType exp() const
Definition: ArrayCwiseUnaryOps.h:97
ceres::acos
Jet< T, N > acos(const Jet< T, N > &f)
Definition: jet.h:432
Eigen::DirectAccessBit
const unsigned int DirectAccessBit
Definition: Constants.h:155
ceres::cos
Jet< T, N > cos(const Jet< T, N > &f)
Definition: jet.h:426
cosh
const EIGEN_DEVICE_FUNC CoshReturnType cosh() const
Definition: ArrayCwiseUnaryOps.h:353
Eigen::internal::vml_assign_traits::MaxSizeAtCompileTime
@ MaxSizeAtCompileTime
Definition: Assign_MKL.h:55
Round
static int Round(int n)
Definition: benchmark_main.cc:39
Eigen::internal::vml_assign_traits::StorageOrdersAgree
@ StorageOrdersAgree
Definition: Assign_MKL.h:48
Eigen::internal::vml_assign_traits::VmlSize
@ VmlSize
Definition: Assign_MKL.h:59
Eigen::internal::vml_assign_traits::InnerMaxSize
@ InnerMaxSize
Definition: Assign_MKL.h:52
square
const EIGEN_DEVICE_FUNC SquareReturnType square() const
Definition: ArrayCwiseUnaryOps.h:425
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:22
arg
Definition: cast.h:1412
Eigen::scomplex
std::complex< float > scomplex
Definition: MKL_support.h:126
round
double round(double x)
Definition: round.c:38
EIGEN_MKL_VML_DECLARE_UNARY_CALLS_CPLX
#define EIGEN_MKL_VML_DECLARE_UNARY_CALLS_CPLX(EIGENOP, VMLOP, VMLMODE)
Definition: Assign_MKL.h:111
Eigen::dcomplex
std::complex< double > dcomplex
Definition: MKL_support.h:125
tan
const EIGEN_DEVICE_FUNC TanReturnType tan() const
Definition: ArrayCwiseUnaryOps.h:269
ceres::pow
Jet< T, N > pow(const Jet< T, N > &f, double g)
Definition: jet.h:570
Eigen::LinearAccessBit
const unsigned int LinearAccessBit
Definition: Constants.h:130
tanh
const EIGEN_DEVICE_FUNC TanhReturnType tanh() const
Definition: ArrayCwiseUnaryOps.h:325
Eigen::internal::vml_assign_traits::SrcHasDirectAccess
@ SrcHasDirectAccess
Definition: Assign_MKL.h:47
Eigen::LinearTraversal
@ LinearTraversal
Definition: Constants.h:279
EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL
#define EIGEN_MKL_VML_DECLARE_UNARY_CALLS_REAL(EIGENOP, VMLOP, VMLMODE)
Definition: Assign_MKL.h:107
Eigen::internal::vml_assign_traits::InnerSize
@ InnerSize
Definition: Assign_MKL.h:49
ceil
const EIGEN_DEVICE_FUNC CeilReturnType ceil() const
Definition: ArrayCwiseUnaryOps.h:495
internal
Definition: BandTriangularSolver.h:13
Eigen::internal::vml_assign_traits
Definition: Assign_MKL.h:42
Eigen::internal::vml_assign_traits::EnableVml
@ EnableVml
Definition: Assign_MKL.h:64
sinh
const EIGEN_DEVICE_FUNC SinhReturnType sinh() const
Definition: ArrayCwiseUnaryOps.h:339
_
constexpr descr< N - 1 > _(char const (&text)[N])
Definition: descr.h:109
Eigen::internal::vml_assign_traits::DstHasDirectAccess
@ DstHasDirectAccess
Definition: Assign_MKL.h:46
ceres::sqrt
Jet< T, N > sqrt(const Jet< T, N > &f)
Definition: jet.h:418
log10
const EIGEN_DEVICE_FUNC Log10ReturnType log10() const
Definition: ArrayCwiseUnaryOps.h:158
floor
const EIGEN_DEVICE_FUNC FloorReturnType floor() const
Definition: ArrayCwiseUnaryOps.h:481


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:08