2010-07-05 16:18:09 +02:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
|
// for linear algebra.
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
|
|
|
|
|
//
|
2012-07-13 14:42:47 -04:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2010-07-05 16:18:09 +02:00
|
|
|
|
|
|
|
|
#ifndef EIGEN_COMPLEX_SSE_H
|
|
|
|
|
#define EIGEN_COMPLEX_SSE_H
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
namespace Eigen {
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
namespace internal {
|
|
|
|
|
|
2010-07-06 23:36:00 +02:00
|
|
|
//---------- float ----------
|
2010-07-05 16:18:09 +02:00
|
|
|
struct Packet2cf
|
|
|
|
|
{
|
|
|
|
|
EIGEN_STRONG_INLINE Packet2cf() {}
|
|
|
|
|
EIGEN_STRONG_INLINE explicit Packet2cf(const __m128& a) : v(a) {}
|
|
|
|
|
__m128 v;
|
|
|
|
|
};
|
|
|
|
|
|
2014-03-27 14:47:00 +01:00
|
|
|
// Use the packet_traits defined in AVX/PacketMath.h instead if we're going
|
|
|
|
|
// to leverage AVX instructions.
|
|
|
|
|
#ifndef EIGEN_VECTORIZE_AVX
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> struct packet_traits<std::complex<float> > : default_packet_traits
|
2010-07-05 16:18:09 +02:00
|
|
|
{
|
2010-07-06 23:36:00 +02:00
|
|
|
typedef Packet2cf type;
|
2014-03-28 10:18:04 +01:00
|
|
|
typedef Packet2cf half;
|
2010-07-05 23:27:54 +02:00
|
|
|
enum {
|
2010-07-07 11:10:46 +02:00
|
|
|
Vectorizable = 1,
|
2010-07-08 14:27:47 +02:00
|
|
|
AlignedOnScalar = 1,
|
2010-07-06 23:36:00 +02:00
|
|
|
size = 2,
|
2014-03-28 10:18:04 +01:00
|
|
|
HasHalfPacket = 0,
|
2010-07-06 23:36:00 +02:00
|
|
|
|
2010-07-05 23:27:54 +02:00
|
|
|
HasAdd = 1,
|
|
|
|
|
HasSub = 1,
|
|
|
|
|
HasMul = 1,
|
|
|
|
|
HasDiv = 1,
|
|
|
|
|
HasNegate = 1,
|
|
|
|
|
HasAbs = 0,
|
|
|
|
|
HasAbs2 = 0,
|
|
|
|
|
HasMin = 0,
|
|
|
|
|
HasMax = 0,
|
2014-06-06 20:18:44 -07:00
|
|
|
HasSetLinear = 0,
|
|
|
|
|
HasBlend = 1
|
2010-07-05 23:27:54 +02:00
|
|
|
};
|
2010-07-05 16:18:09 +02:00
|
|
|
};
|
2014-03-27 14:47:00 +01:00
|
|
|
#endif
|
2010-07-05 16:18:09 +02:00
|
|
|
|
Adding lowlevel APIs for optimized RHS packet load in TensorFlow
SpatialConvolution
Low-level APIs are added in order to optimized packet load in gemm_pack_rhs
in TensorFlow SpatialConvolution. The optimization is for scenario when a
packet is split across 2 adjacent columns. In this case we read it as two
'partial' packets and then merge these into 1. Currently this only works for
Packet16f (AVX512) and Packet8f (AVX2). We plan to add this for other
packet types (such as Packet8d) also.
This optimization shows significant speedup in SpatialConvolution with
certain parameters. Some examples are below.
Benchmark parameters are specified as:
Batch size, Input dim, Depth, Num of filters, Filter dim
Speedup numbers are specified for number of threads 1, 2, 4, 8, 16.
AVX512:
Parameters | Speedup (Num of threads: 1, 2, 4, 8, 16)
----------------------------|------------------------------------------
128, 24x24, 3, 64, 5x5 |2.18X, 2.13X, 1.73X, 1.64X, 1.66X
128, 24x24, 1, 64, 8x8 |2.00X, 1.98X, 1.93X, 1.91X, 1.91X
32, 24x24, 3, 64, 5x5 |2.26X, 2.14X, 2.17X, 2.22X, 2.33X
128, 24x24, 3, 64, 3x3 |1.51X, 1.45X, 1.45X, 1.67X, 1.57X
32, 14x14, 24, 64, 5x5 |1.21X, 1.19X, 1.16X, 1.70X, 1.17X
128, 128x128, 3, 96, 11x11 |2.17X, 2.18X, 2.19X, 2.20X, 2.18X
AVX2:
Parameters | Speedup (Num of threads: 1, 2, 4, 8, 16)
----------------------------|------------------------------------------
128, 24x24, 3, 64, 5x5 | 1.66X, 1.65X, 1.61X, 1.56X, 1.49X
32, 24x24, 3, 64, 5x5 | 1.71X, 1.63X, 1.77X, 1.58X, 1.68X
128, 24x24, 1, 64, 5x5 | 1.44X, 1.40X, 1.38X, 1.37X, 1.33X
128, 24x24, 3, 64, 3x3 | 1.68X, 1.63X, 1.58X, 1.56X, 1.62X
128, 128x128, 3, 96, 11x11 | 1.36X, 1.36X, 1.37X, 1.37X, 1.37X
In the higher level benchmark cifar10, we observe a runtime improvement
of around 6% for AVX512 on Intel Skylake server (8 cores).
On lower level PackRhs micro-benchmarks specified in TensorFlow
tensorflow/core/kernels/eigen_spatial_convolutions_test.cc, we observe
the following runtime numbers:
AVX512:
Parameters | Runtime without patch (ns) | Runtime with patch (ns) | Speedup
---------------------------------------------------------------|----------------------------|-------------------------|---------
BM_RHS_NAME(PackRhs, 128, 24, 24, 3, 64, 5, 5, 1, 1, 256, 56) | 41350 | 15073 | 2.74X
BM_RHS_NAME(PackRhs, 32, 64, 64, 32, 64, 5, 5, 1, 1, 256, 56) | 7277 | 7341 | 0.99X
BM_RHS_NAME(PackRhs, 32, 64, 64, 32, 64, 5, 5, 2, 2, 256, 56) | 8675 | 8681 | 1.00X
BM_RHS_NAME(PackRhs, 32, 64, 64, 30, 64, 5, 5, 1, 1, 256, 56) | 24155 | 16079 | 1.50X
BM_RHS_NAME(PackRhs, 32, 64, 64, 30, 64, 5, 5, 2, 2, 256, 56) | 25052 | 17152 | 1.46X
BM_RHS_NAME(PackRhs, 32, 256, 256, 4, 16, 8, 8, 1, 1, 256, 56) | 18269 | 18345 | 1.00X
BM_RHS_NAME(PackRhs, 32, 256, 256, 4, 16, 8, 8, 2, 4, 256, 56) | 19468 | 19872 | 0.98X
BM_RHS_NAME(PackRhs, 32, 64, 64, 4, 16, 3, 3, 1, 1, 36, 432) | 156060 | 42432 | 3.68X
BM_RHS_NAME(PackRhs, 32, 64, 64, 4, 16, 3, 3, 2, 2, 36, 432) | 132701 | 36944 | 3.59X
AVX2:
Parameters | Runtime without patch (ns) | Runtime with patch (ns) | Speedup
---------------------------------------------------------------|----------------------------|-------------------------|---------
BM_RHS_NAME(PackRhs, 128, 24, 24, 3, 64, 5, 5, 1, 1, 256, 56) | 26233 | 12393 | 2.12X
BM_RHS_NAME(PackRhs, 32, 64, 64, 32, 64, 5, 5, 1, 1, 256, 56) | 6091 | 6062 | 1.00X
BM_RHS_NAME(PackRhs, 32, 64, 64, 32, 64, 5, 5, 2, 2, 256, 56) | 7427 | 7408 | 1.00X
BM_RHS_NAME(PackRhs, 32, 64, 64, 30, 64, 5, 5, 1, 1, 256, 56) | 23453 | 20826 | 1.13X
BM_RHS_NAME(PackRhs, 32, 64, 64, 30, 64, 5, 5, 2, 2, 256, 56) | 23167 | 22091 | 1.09X
BM_RHS_NAME(PackRhs, 32, 256, 256, 4, 16, 8, 8, 1, 1, 256, 56) | 23422 | 23682 | 0.99X
BM_RHS_NAME(PackRhs, 32, 256, 256, 4, 16, 8, 8, 2, 4, 256, 56) | 23165 | 23663 | 0.98X
BM_RHS_NAME(PackRhs, 32, 64, 64, 4, 16, 3, 3, 1, 1, 36, 432) | 72689 | 44969 | 1.62X
BM_RHS_NAME(PackRhs, 32, 64, 64, 4, 16, 3, 3, 2, 2, 36, 432) | 61732 | 39779 | 1.55X
All benchmarks on Intel Skylake server with 8 cores.
2019-04-20 06:46:43 +00:00
|
|
|
template<> struct unpacket_traits<Packet2cf> { typedef std::complex<float> type; enum {size=2, alignment=Aligned16, vectorizable=true, masked_load_available=false}; typedef Packet2cf half; };
|
2010-07-05 16:18:09 +02:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_add_ps(a.v,b.v)); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_sub_ps(a.v,b.v)); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a)
|
2010-07-05 16:18:09 +02:00
|
|
|
{
|
|
|
|
|
const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x80000000,0x80000000,0x80000000));
|
|
|
|
|
return Packet2cf(_mm_xor_ps(a.v,mask));
|
2010-07-05 23:27:54 +02:00
|
|
|
}
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a)
|
2010-07-05 23:27:54 +02:00
|
|
|
{
|
|
|
|
|
const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
|
|
|
|
|
return Packet2cf(_mm_xor_ps(a.v,mask));
|
2010-07-05 16:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
|
2010-07-05 16:18:09 +02:00
|
|
|
{
|
2010-07-07 15:34:46 +02:00
|
|
|
#ifdef EIGEN_VECTORIZE_SSE3
|
2010-07-19 08:50:59 +02:00
|
|
|
return Packet2cf(_mm_addsub_ps(_mm_mul_ps(_mm_moveldup_ps(a.v), b.v),
|
|
|
|
|
_mm_mul_ps(_mm_movehdup_ps(a.v),
|
2010-10-25 10:15:22 -04:00
|
|
|
vec4f_swizzle1(b.v, 1, 0, 3, 2))));
|
|
|
|
|
// return Packet2cf(_mm_addsub_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v),
|
|
|
|
|
// _mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
|
|
|
|
|
// vec4f_swizzle1(b.v, 1, 0, 3, 2))));
|
2010-07-07 15:34:46 +02:00
|
|
|
#else
|
2010-07-05 16:18:09 +02:00
|
|
|
const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x00000000,0x80000000,0x00000000));
|
2010-10-25 10:15:22 -04:00
|
|
|
return Packet2cf(_mm_add_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v),
|
|
|
|
|
_mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
|
|
|
|
|
vec4f_swizzle1(b.v, 1, 0, 3, 2)), mask)));
|
2010-07-07 15:34:46 +02:00
|
|
|
#endif
|
2010-07-05 16:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-16 14:43:33 -08:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf ptrue <Packet2cf>(const Packet2cf& a) { return Packet2cf(ptrue(Packet4f(a.v))); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pnot <Packet2cf>(const Packet2cf& a) { return Packet2cf(pnot(Packet4f(a.v))); }
|
2019-01-09 16:34:23 -08:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_and_ps(a.v,b.v)); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_or_ps(a.v,b.v)); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_xor_ps(a.v,b.v)); }
|
2018-12-08 14:27:48 +01:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_andnot_ps(b.v,a.v)); }
|
2010-07-05 16:18:09 +02:00
|
|
|
|
2013-06-10 23:40:56 +02:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pload <Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload<Packet4f>(&numext::real_ref(*from))); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu<Packet4f>(&numext::real_ref(*from))); }
|
2010-07-05 16:18:09 +02:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from)
|
2010-07-09 08:27:58 +02:00
|
|
|
{
|
|
|
|
|
Packet2cf res;
|
2013-01-24 11:59:17 +01:00
|
|
|
#if EIGEN_GNUC_AT_MOST(4,2)
|
|
|
|
|
// Workaround annoying "may be used uninitialized in this function" warning with gcc 4.2
|
2012-01-31 18:56:25 +01:00
|
|
|
res.v = _mm_loadl_pi(_mm_set1_ps(0.0f), reinterpret_cast<const __m64*>(&from));
|
2013-01-24 11:59:17 +01:00
|
|
|
#elif EIGEN_GNUC_AT_LEAST(4,6)
|
|
|
|
|
// Suppress annoying "may be used uninitialized in this function" warning with gcc >= 4.6
|
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
|
#pragma GCC diagnostic ignored "-Wuninitialized"
|
2010-07-09 08:27:58 +02:00
|
|
|
res.v = _mm_loadl_pi(res.v, (const __m64*)&from);
|
2013-01-24 11:59:17 +01:00
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
|
#else
|
|
|
|
|
res.v = _mm_loadl_pi(res.v, (const __m64*)&from);
|
|
|
|
|
#endif
|
2010-07-09 08:27:58 +02:00
|
|
|
return Packet2cf(_mm_movelh_ps(res.v,res.v));
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-23 16:31:42 +01:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from) { return pset1<Packet2cf>(*from); }
|
|
|
|
|
|
2014-04-22 16:03:19 +02:00
|
|
|
template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { EIGEN_DEBUG_ALIGNED_STORE pstore(&numext::real_ref(*to), Packet4f(from.v)); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu(&numext::real_ref(*to), Packet4f(from.v)); }
|
2011-02-23 16:31:42 +01:00
|
|
|
|
2014-03-27 18:29:01 -07:00
|
|
|
|
2015-02-16 15:05:41 +01:00
|
|
|
template<> EIGEN_DEVICE_FUNC inline Packet2cf pgather<std::complex<float>, Packet2cf>(const std::complex<float>* from, Index stride)
|
2014-03-27 18:29:01 -07:00
|
|
|
{
|
|
|
|
|
return Packet2cf(_mm_set_ps(std::imag(from[1*stride]), std::real(from[1*stride]),
|
2014-03-30 22:43:47 +02:00
|
|
|
std::imag(from[0*stride]), std::real(from[0*stride])));
|
2014-03-27 18:29:01 -07:00
|
|
|
}
|
|
|
|
|
|
2015-02-16 15:05:41 +01:00
|
|
|
template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to, const Packet2cf& from, Index stride)
|
2014-03-27 18:29:01 -07:00
|
|
|
{
|
|
|
|
|
to[stride*0] = std::complex<float>(_mm_cvtss_f32(_mm_shuffle_ps(from.v, from.v, 0)),
|
2014-03-30 22:43:47 +02:00
|
|
|
_mm_cvtss_f32(_mm_shuffle_ps(from.v, from.v, 1)));
|
2014-03-27 18:29:01 -07:00
|
|
|
to[stride*1] = std::complex<float>(_mm_cvtss_f32(_mm_shuffle_ps(from.v, from.v, 2)),
|
2014-03-30 22:43:47 +02:00
|
|
|
_mm_cvtss_f32(_mm_shuffle_ps(from.v, from.v, 3)));
|
2014-03-27 18:29:01 -07:00
|
|
|
}
|
|
|
|
|
|
2018-06-07 09:33:10 +02:00
|
|
|
template<> EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float> * addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); }
|
2011-02-23 16:31:42 +01:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(const Packet2cf& a)
|
2010-07-05 16:18:09 +02:00
|
|
|
{
|
2011-02-21 16:11:18 +01:00
|
|
|
#if EIGEN_GNUC_AT_MOST(4,3)
|
|
|
|
|
// Workaround gcc 4.2 ICE - this is not performance wise ideal, but who cares...
|
2011-02-18 15:47:17 +01:00
|
|
|
// This workaround also fix invalid code generation with gcc 4.3
|
2011-02-09 13:04:35 +01:00
|
|
|
EIGEN_ALIGN16 std::complex<float> res[2];
|
|
|
|
|
_mm_store_ps((float*)res, a.v);
|
|
|
|
|
return res[0];
|
|
|
|
|
#else
|
2010-07-22 13:16:53 +02:00
|
|
|
std::complex<float> res;
|
|
|
|
|
_mm_storel_pi((__m64*)&res, a.v);
|
|
|
|
|
return res;
|
2011-02-09 13:04:35 +01:00
|
|
|
#endif
|
2010-07-05 16:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
2014-04-22 16:03:19 +02:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a) { return Packet2cf(_mm_castpd_ps(preverse(Packet2d(_mm_castps_pd(a.v))))); }
|
2010-07-05 16:18:09 +02:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a)
|
2010-07-05 16:18:09 +02:00
|
|
|
{
|
2010-10-25 10:15:22 -04:00
|
|
|
return pfirst(Packet2cf(_mm_add_ps(a.v, _mm_movehl_ps(a.v,a.v))));
|
2010-07-05 16:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf preduxp<Packet2cf>(const Packet2cf* vecs)
|
2010-07-05 16:18:09 +02:00
|
|
|
{
|
|
|
|
|
return Packet2cf(_mm_add_ps(_mm_movelh_ps(vecs[0].v,vecs[1].v), _mm_movehl_ps(vecs[1].v,vecs[0].v)));
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a)
|
2010-07-05 16:18:09 +02:00
|
|
|
{
|
2010-10-25 10:15:22 -04:00
|
|
|
return pfirst(pmul(a, Packet2cf(_mm_movehl_ps(a.v,a.v))));
|
2010-07-05 16:18:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int Offset>
|
2010-10-25 10:15:22 -04:00
|
|
|
struct palign_impl<Offset,Packet2cf>
|
2010-07-05 16:18:09 +02:00
|
|
|
{
|
2012-01-31 12:58:52 +01:00
|
|
|
static EIGEN_STRONG_INLINE void run(Packet2cf& first, const Packet2cf& second)
|
2010-07-05 16:18:09 +02:00
|
|
|
{
|
|
|
|
|
if (Offset==1)
|
|
|
|
|
{
|
|
|
|
|
first.v = _mm_movehl_ps(first.v, first.v);
|
|
|
|
|
first.v = _mm_movelh_ps(first.v, second.v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> struct conj_helper<Packet2cf, Packet2cf, false,true>
|
2010-07-06 19:10:24 +02:00
|
|
|
{
|
|
|
|
|
EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
|
2010-10-25 10:15:22 -04:00
|
|
|
{ return padd(pmul(x,y),c); }
|
2010-07-06 19:10:24 +02:00
|
|
|
|
|
|
|
|
EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
|
|
|
|
|
{
|
2010-07-07 16:37:20 +02:00
|
|
|
#ifdef EIGEN_VECTORIZE_SSE3
|
2011-02-03 17:55:24 +01:00
|
|
|
return internal::pmul(a, pconj(b));
|
2010-07-07 16:37:20 +02:00
|
|
|
#else
|
2010-07-06 19:10:24 +02:00
|
|
|
const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
|
2010-10-25 10:15:22 -04:00
|
|
|
return Packet2cf(_mm_add_ps(_mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v), mask),
|
|
|
|
|
_mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
|
|
|
|
|
vec4f_swizzle1(b.v, 1, 0, 3, 2))));
|
2010-07-07 16:37:20 +02:00
|
|
|
#endif
|
2010-07-06 19:10:24 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> struct conj_helper<Packet2cf, Packet2cf, true,false>
|
2010-07-06 19:10:24 +02:00
|
|
|
{
|
|
|
|
|
EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
|
2010-10-25 10:15:22 -04:00
|
|
|
{ return padd(pmul(x,y),c); }
|
2010-07-06 19:10:24 +02:00
|
|
|
|
|
|
|
|
EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
|
|
|
|
|
{
|
2010-07-07 16:37:20 +02:00
|
|
|
#ifdef EIGEN_VECTORIZE_SSE3
|
2011-02-03 17:55:24 +01:00
|
|
|
return internal::pmul(pconj(a), b);
|
2010-07-07 16:37:20 +02:00
|
|
|
#else
|
2010-07-06 19:10:24 +02:00
|
|
|
const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
|
2010-10-25 10:15:22 -04:00
|
|
|
return Packet2cf(_mm_add_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v),
|
|
|
|
|
_mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
|
|
|
|
|
vec4f_swizzle1(b.v, 1, 0, 3, 2)), mask)));
|
2010-07-07 16:37:20 +02:00
|
|
|
#endif
|
2010-07-06 19:10:24 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> struct conj_helper<Packet2cf, Packet2cf, true,true>
|
2010-07-06 19:10:24 +02:00
|
|
|
{
|
|
|
|
|
EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
|
2010-10-25 10:15:22 -04:00
|
|
|
{ return padd(pmul(x,y),c); }
|
2010-07-06 19:10:24 +02:00
|
|
|
|
|
|
|
|
EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
|
|
|
|
|
{
|
2010-07-07 16:37:20 +02:00
|
|
|
#ifdef EIGEN_VECTORIZE_SSE3
|
2011-02-03 17:55:24 +01:00
|
|
|
return pconj(internal::pmul(a, b));
|
2010-07-07 16:37:20 +02:00
|
|
|
#else
|
2010-07-06 19:10:24 +02:00
|
|
|
const __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0x00000000,0x80000000,0x00000000,0x80000000));
|
2010-10-25 10:15:22 -04:00
|
|
|
return Packet2cf(_mm_sub_ps(_mm_xor_ps(_mm_mul_ps(vec4f_swizzle1(a.v, 0, 0, 2, 2), b.v), mask),
|
|
|
|
|
_mm_mul_ps(vec4f_swizzle1(a.v, 1, 1, 3, 3),
|
|
|
|
|
vec4f_swizzle1(b.v, 1, 0, 3, 2))));
|
2010-07-07 16:37:20 +02:00
|
|
|
#endif
|
2010-07-06 19:10:24 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-15 10:16:30 +02:00
|
|
|
EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f)
|
2010-07-11 23:57:23 +02:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
|
2010-07-06 23:36:00 +02:00
|
|
|
{
|
|
|
|
|
// TODO optimize it for SSE3 and 4
|
2010-10-25 10:15:22 -04:00
|
|
|
Packet2cf res = conj_helper<Packet2cf,Packet2cf,false,true>().pmul(a,b);
|
2010-07-06 23:36:00 +02:00
|
|
|
__m128 s = _mm_mul_ps(b.v,b.v);
|
|
|
|
|
return Packet2cf(_mm_div_ps(res.v,_mm_add_ps(s,_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(s), 0xb1)))));
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-30 16:46:45 +01:00
|
|
|
EIGEN_STRONG_INLINE Packet2cf pcplxflip/* <Packet2cf> */(const Packet2cf& x)
|
2010-07-19 08:50:59 +02:00
|
|
|
{
|
2010-10-25 10:15:22 -04:00
|
|
|
return Packet2cf(vec4f_swizzle1(x.v, 1, 0, 3, 2));
|
2010-07-19 08:50:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-07-06 23:36:00 +02:00
|
|
|
//---------- double ----------
|
|
|
|
|
struct Packet1cd
|
|
|
|
|
{
|
|
|
|
|
EIGEN_STRONG_INLINE Packet1cd() {}
|
|
|
|
|
EIGEN_STRONG_INLINE explicit Packet1cd(const __m128d& a) : v(a) {}
|
|
|
|
|
__m128d v;
|
|
|
|
|
};
|
|
|
|
|
|
2014-03-27 14:47:00 +01:00
|
|
|
// Use the packet_traits defined in AVX/PacketMath.h instead if we're going
|
|
|
|
|
// to leverage AVX instructions.
|
|
|
|
|
#ifndef EIGEN_VECTORIZE_AVX
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> struct packet_traits<std::complex<double> > : default_packet_traits
|
2010-07-06 23:36:00 +02:00
|
|
|
{
|
|
|
|
|
typedef Packet1cd type;
|
2014-03-28 10:18:04 +01:00
|
|
|
typedef Packet1cd half;
|
2010-07-06 23:36:00 +02:00
|
|
|
enum {
|
2010-07-07 11:10:46 +02:00
|
|
|
Vectorizable = 1,
|
2010-07-08 14:27:47 +02:00
|
|
|
AlignedOnScalar = 0,
|
2010-07-06 23:36:00 +02:00
|
|
|
size = 1,
|
2014-03-28 10:18:04 +01:00
|
|
|
HasHalfPacket = 0,
|
2010-07-06 23:36:00 +02:00
|
|
|
|
|
|
|
|
HasAdd = 1,
|
|
|
|
|
HasSub = 1,
|
|
|
|
|
HasMul = 1,
|
|
|
|
|
HasDiv = 1,
|
|
|
|
|
HasNegate = 1,
|
|
|
|
|
HasAbs = 0,
|
|
|
|
|
HasAbs2 = 0,
|
|
|
|
|
HasMin = 0,
|
|
|
|
|
HasMax = 0,
|
|
|
|
|
HasSetLinear = 0
|
|
|
|
|
};
|
|
|
|
|
};
|
2014-03-27 14:47:00 +01:00
|
|
|
#endif
|
2010-07-06 23:36:00 +02:00
|
|
|
|
Adding lowlevel APIs for optimized RHS packet load in TensorFlow
SpatialConvolution
Low-level APIs are added in order to optimized packet load in gemm_pack_rhs
in TensorFlow SpatialConvolution. The optimization is for scenario when a
packet is split across 2 adjacent columns. In this case we read it as two
'partial' packets and then merge these into 1. Currently this only works for
Packet16f (AVX512) and Packet8f (AVX2). We plan to add this for other
packet types (such as Packet8d) also.
This optimization shows significant speedup in SpatialConvolution with
certain parameters. Some examples are below.
Benchmark parameters are specified as:
Batch size, Input dim, Depth, Num of filters, Filter dim
Speedup numbers are specified for number of threads 1, 2, 4, 8, 16.
AVX512:
Parameters | Speedup (Num of threads: 1, 2, 4, 8, 16)
----------------------------|------------------------------------------
128, 24x24, 3, 64, 5x5 |2.18X, 2.13X, 1.73X, 1.64X, 1.66X
128, 24x24, 1, 64, 8x8 |2.00X, 1.98X, 1.93X, 1.91X, 1.91X
32, 24x24, 3, 64, 5x5 |2.26X, 2.14X, 2.17X, 2.22X, 2.33X
128, 24x24, 3, 64, 3x3 |1.51X, 1.45X, 1.45X, 1.67X, 1.57X
32, 14x14, 24, 64, 5x5 |1.21X, 1.19X, 1.16X, 1.70X, 1.17X
128, 128x128, 3, 96, 11x11 |2.17X, 2.18X, 2.19X, 2.20X, 2.18X
AVX2:
Parameters | Speedup (Num of threads: 1, 2, 4, 8, 16)
----------------------------|------------------------------------------
128, 24x24, 3, 64, 5x5 | 1.66X, 1.65X, 1.61X, 1.56X, 1.49X
32, 24x24, 3, 64, 5x5 | 1.71X, 1.63X, 1.77X, 1.58X, 1.68X
128, 24x24, 1, 64, 5x5 | 1.44X, 1.40X, 1.38X, 1.37X, 1.33X
128, 24x24, 3, 64, 3x3 | 1.68X, 1.63X, 1.58X, 1.56X, 1.62X
128, 128x128, 3, 96, 11x11 | 1.36X, 1.36X, 1.37X, 1.37X, 1.37X
In the higher level benchmark cifar10, we observe a runtime improvement
of around 6% for AVX512 on Intel Skylake server (8 cores).
On lower level PackRhs micro-benchmarks specified in TensorFlow
tensorflow/core/kernels/eigen_spatial_convolutions_test.cc, we observe
the following runtime numbers:
AVX512:
Parameters | Runtime without patch (ns) | Runtime with patch (ns) | Speedup
---------------------------------------------------------------|----------------------------|-------------------------|---------
BM_RHS_NAME(PackRhs, 128, 24, 24, 3, 64, 5, 5, 1, 1, 256, 56) | 41350 | 15073 | 2.74X
BM_RHS_NAME(PackRhs, 32, 64, 64, 32, 64, 5, 5, 1, 1, 256, 56) | 7277 | 7341 | 0.99X
BM_RHS_NAME(PackRhs, 32, 64, 64, 32, 64, 5, 5, 2, 2, 256, 56) | 8675 | 8681 | 1.00X
BM_RHS_NAME(PackRhs, 32, 64, 64, 30, 64, 5, 5, 1, 1, 256, 56) | 24155 | 16079 | 1.50X
BM_RHS_NAME(PackRhs, 32, 64, 64, 30, 64, 5, 5, 2, 2, 256, 56) | 25052 | 17152 | 1.46X
BM_RHS_NAME(PackRhs, 32, 256, 256, 4, 16, 8, 8, 1, 1, 256, 56) | 18269 | 18345 | 1.00X
BM_RHS_NAME(PackRhs, 32, 256, 256, 4, 16, 8, 8, 2, 4, 256, 56) | 19468 | 19872 | 0.98X
BM_RHS_NAME(PackRhs, 32, 64, 64, 4, 16, 3, 3, 1, 1, 36, 432) | 156060 | 42432 | 3.68X
BM_RHS_NAME(PackRhs, 32, 64, 64, 4, 16, 3, 3, 2, 2, 36, 432) | 132701 | 36944 | 3.59X
AVX2:
Parameters | Runtime without patch (ns) | Runtime with patch (ns) | Speedup
---------------------------------------------------------------|----------------------------|-------------------------|---------
BM_RHS_NAME(PackRhs, 128, 24, 24, 3, 64, 5, 5, 1, 1, 256, 56) | 26233 | 12393 | 2.12X
BM_RHS_NAME(PackRhs, 32, 64, 64, 32, 64, 5, 5, 1, 1, 256, 56) | 6091 | 6062 | 1.00X
BM_RHS_NAME(PackRhs, 32, 64, 64, 32, 64, 5, 5, 2, 2, 256, 56) | 7427 | 7408 | 1.00X
BM_RHS_NAME(PackRhs, 32, 64, 64, 30, 64, 5, 5, 1, 1, 256, 56) | 23453 | 20826 | 1.13X
BM_RHS_NAME(PackRhs, 32, 64, 64, 30, 64, 5, 5, 2, 2, 256, 56) | 23167 | 22091 | 1.09X
BM_RHS_NAME(PackRhs, 32, 256, 256, 4, 16, 8, 8, 1, 1, 256, 56) | 23422 | 23682 | 0.99X
BM_RHS_NAME(PackRhs, 32, 256, 256, 4, 16, 8, 8, 2, 4, 256, 56) | 23165 | 23663 | 0.98X
BM_RHS_NAME(PackRhs, 32, 64, 64, 4, 16, 3, 3, 1, 1, 36, 432) | 72689 | 44969 | 1.62X
BM_RHS_NAME(PackRhs, 32, 64, 64, 4, 16, 3, 3, 2, 2, 36, 432) | 61732 | 39779 | 1.55X
All benchmarks on Intel Skylake server with 8 cores.
2019-04-20 06:46:43 +00:00
|
|
|
template<> struct unpacket_traits<Packet1cd> { typedef std::complex<double> type; enum {size=1, alignment=Aligned16, vectorizable=true, masked_load_available=false}; typedef Packet1cd half; };
|
2010-07-06 23:36:00 +02:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_add_pd(a.v,b.v)); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_sub_pd(a.v,b.v)); }
|
2014-04-22 16:03:19 +02:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd pnegate(const Packet1cd& a) { return Packet1cd(pnegate(Packet2d(a.v))); }
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd pconj(const Packet1cd& a)
|
2010-07-06 23:36:00 +02:00
|
|
|
{
|
|
|
|
|
const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
|
|
|
|
|
return Packet1cd(_mm_xor_pd(a.v,mask));
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
|
2010-07-06 23:36:00 +02:00
|
|
|
{
|
2010-07-07 15:34:46 +02:00
|
|
|
#ifdef EIGEN_VECTORIZE_SSE3
|
2015-10-06 15:43:27 +02:00
|
|
|
return Packet1cd(_mm_addsub_pd(_mm_mul_pd(_mm_movedup_pd(a.v), b.v),
|
2010-10-25 10:15:22 -04:00
|
|
|
_mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
|
|
|
|
|
vec2d_swizzle1(b.v, 1, 0))));
|
2010-07-07 15:34:46 +02:00
|
|
|
#else
|
2010-07-06 23:36:00 +02:00
|
|
|
const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x0,0x0,0x80000000,0x0));
|
2010-10-25 10:15:22 -04:00
|
|
|
return Packet1cd(_mm_add_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v),
|
|
|
|
|
_mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
|
|
|
|
|
vec2d_swizzle1(b.v, 1, 0)), mask)));
|
2010-07-07 15:34:46 +02:00
|
|
|
#endif
|
2010-07-06 23:36:00 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-16 14:43:33 -08:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd ptrue <Packet1cd>(const Packet1cd& a) { return Packet1cd(ptrue(Packet2d(a.v))); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd pnot <Packet1cd>(const Packet1cd& a) { return Packet1cd(pnot(Packet2d(a.v))); }
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd pand <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_and_pd(a.v,b.v)); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd por <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_or_pd(a.v,b.v)); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd pxor <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_xor_pd(a.v,b.v)); }
|
2018-12-08 14:27:48 +01:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd pandnot<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(_mm_andnot_pd(b.v,a.v)); }
|
2010-07-06 23:36:00 +02:00
|
|
|
|
2010-07-13 15:16:34 +02:00
|
|
|
// FIXME force unaligned load, this is a temporary fix
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd pload <Packet1cd>(const std::complex<double>* from)
|
|
|
|
|
{ EIGEN_DEBUG_ALIGNED_LOAD return Packet1cd(pload<Packet2d>((const double*)from)); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(const std::complex<double>* from)
|
|
|
|
|
{ EIGEN_DEBUG_UNALIGNED_LOAD return Packet1cd(ploadu<Packet2d>((const double*)from)); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(const std::complex<double>& from)
|
|
|
|
|
{ /* here we really have to use unaligned loads :( */ return ploadu<Packet1cd>(&from); }
|
2010-07-06 23:36:00 +02:00
|
|
|
|
2011-02-23 16:31:42 +01:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(const std::complex<double>* from) { return pset1<Packet1cd>(*from); }
|
|
|
|
|
|
2010-07-07 22:50:19 +02:00
|
|
|
// FIXME force unaligned store, this is a temporary fix
|
2014-04-22 16:03:19 +02:00
|
|
|
template<> EIGEN_STRONG_INLINE void pstore <std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((double*)to, Packet2d(from.v)); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((double*)to, Packet2d(from.v)); }
|
2010-07-06 23:36:00 +02:00
|
|
|
|
2018-06-07 09:33:10 +02:00
|
|
|
template<> EIGEN_STRONG_INLINE void prefetch<std::complex<double> >(const std::complex<double> * addr) { _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0); }
|
2010-07-06 23:36:00 +02:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(const Packet1cd& a)
|
2010-07-06 23:36:00 +02:00
|
|
|
{
|
2010-07-20 22:43:55 +02:00
|
|
|
EIGEN_ALIGN16 double res[2];
|
|
|
|
|
_mm_store_pd(res, a.v);
|
2010-08-19 14:47:58 +02:00
|
|
|
return std::complex<double>(res[0],res[1]);
|
2010-07-06 23:36:00 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd preverse(const Packet1cd& a) { return a; }
|
2010-07-06 23:36:00 +02:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(const Packet1cd& a)
|
2010-07-06 23:36:00 +02:00
|
|
|
{
|
2010-10-25 10:15:22 -04:00
|
|
|
return pfirst(a);
|
2010-07-06 23:36:00 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd preduxp<Packet1cd>(const Packet1cd* vecs)
|
2010-07-06 23:36:00 +02:00
|
|
|
{
|
|
|
|
|
return vecs[0];
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(const Packet1cd& a)
|
2010-07-06 23:36:00 +02:00
|
|
|
{
|
2010-10-25 10:15:22 -04:00
|
|
|
return pfirst(a);
|
2010-07-06 23:36:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int Offset>
|
2010-10-25 10:15:22 -04:00
|
|
|
struct palign_impl<Offset,Packet1cd>
|
2010-07-06 23:36:00 +02:00
|
|
|
{
|
2012-01-31 12:58:52 +01:00
|
|
|
static EIGEN_STRONG_INLINE void run(Packet1cd& /*first*/, const Packet1cd& /*second*/)
|
2010-07-06 23:36:00 +02:00
|
|
|
{
|
2010-07-07 11:41:29 +02:00
|
|
|
// FIXME is it sure we never have to align a Packet1cd?
|
|
|
|
|
// Even though a std::complex<double> has 16 bytes, it is not necessarily aligned on a 16 bytes boundary...
|
2010-07-06 23:36:00 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> struct conj_helper<Packet1cd, Packet1cd, false,true>
|
2010-07-06 23:36:00 +02:00
|
|
|
{
|
|
|
|
|
EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const
|
2010-10-25 10:15:22 -04:00
|
|
|
{ return padd(pmul(x,y),c); }
|
2010-07-06 23:36:00 +02:00
|
|
|
|
|
|
|
|
EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const
|
|
|
|
|
{
|
2010-07-07 16:37:20 +02:00
|
|
|
#ifdef EIGEN_VECTORIZE_SSE3
|
2010-11-16 15:54:48 +01:00
|
|
|
return internal::pmul(a, pconj(b));
|
2010-07-07 16:37:20 +02:00
|
|
|
#else
|
2010-07-06 23:36:00 +02:00
|
|
|
const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
|
2010-10-25 10:15:22 -04:00
|
|
|
return Packet1cd(_mm_add_pd(_mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v), mask),
|
|
|
|
|
_mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
|
|
|
|
|
vec2d_swizzle1(b.v, 1, 0))));
|
2010-07-07 16:37:20 +02:00
|
|
|
#endif
|
2010-07-06 23:36:00 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> struct conj_helper<Packet1cd, Packet1cd, true,false>
|
2010-07-06 23:36:00 +02:00
|
|
|
{
|
|
|
|
|
EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const
|
2010-10-25 10:15:22 -04:00
|
|
|
{ return padd(pmul(x,y),c); }
|
2010-07-06 23:36:00 +02:00
|
|
|
|
|
|
|
|
EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const
|
|
|
|
|
{
|
2010-07-07 16:37:20 +02:00
|
|
|
#ifdef EIGEN_VECTORIZE_SSE3
|
2010-11-16 15:54:48 +01:00
|
|
|
return internal::pmul(pconj(a), b);
|
2010-07-07 16:37:20 +02:00
|
|
|
#else
|
2010-07-06 23:36:00 +02:00
|
|
|
const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
|
2010-10-25 10:15:22 -04:00
|
|
|
return Packet1cd(_mm_add_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v),
|
|
|
|
|
_mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
|
|
|
|
|
vec2d_swizzle1(b.v, 1, 0)), mask)));
|
2010-07-07 16:37:20 +02:00
|
|
|
#endif
|
2010-07-06 23:36:00 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> struct conj_helper<Packet1cd, Packet1cd, true,true>
|
2010-07-06 23:36:00 +02:00
|
|
|
{
|
|
|
|
|
EIGEN_STRONG_INLINE Packet1cd pmadd(const Packet1cd& x, const Packet1cd& y, const Packet1cd& c) const
|
2010-10-25 10:15:22 -04:00
|
|
|
{ return padd(pmul(x,y),c); }
|
2010-07-06 23:36:00 +02:00
|
|
|
|
|
|
|
|
EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b) const
|
|
|
|
|
{
|
2010-07-07 16:37:20 +02:00
|
|
|
#ifdef EIGEN_VECTORIZE_SSE3
|
2010-11-16 15:54:48 +01:00
|
|
|
return pconj(internal::pmul(a, b));
|
2010-07-07 16:37:20 +02:00
|
|
|
#else
|
2010-07-06 23:36:00 +02:00
|
|
|
const __m128d mask = _mm_castsi128_pd(_mm_set_epi32(0x80000000,0x0,0x0,0x0));
|
2010-10-25 10:15:22 -04:00
|
|
|
return Packet1cd(_mm_sub_pd(_mm_xor_pd(_mm_mul_pd(vec2d_swizzle1(a.v, 0, 0), b.v), mask),
|
|
|
|
|
_mm_mul_pd(vec2d_swizzle1(a.v, 1, 1),
|
|
|
|
|
vec2d_swizzle1(b.v, 1, 0))));
|
2010-07-07 16:37:20 +02:00
|
|
|
#endif
|
2010-07-06 23:36:00 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-06-15 10:16:30 +02:00
|
|
|
EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd,Packet2d)
|
2010-07-11 15:48:30 +02:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
|
2010-07-06 23:36:00 +02:00
|
|
|
{
|
|
|
|
|
// TODO optimize it for SSE3 and 4
|
2010-10-25 10:15:22 -04:00
|
|
|
Packet1cd res = conj_helper<Packet1cd,Packet1cd,false,true>().pmul(a,b);
|
2010-07-06 23:36:00 +02:00
|
|
|
__m128d s = _mm_mul_pd(b.v,b.v);
|
|
|
|
|
return Packet1cd(_mm_div_pd(res.v, _mm_add_pd(s,_mm_shuffle_pd(s, s, 0x1))));
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-30 16:46:45 +01:00
|
|
|
EIGEN_STRONG_INLINE Packet1cd pcplxflip/* <Packet1cd> */(const Packet1cd& x)
|
2010-07-19 08:50:59 +02:00
|
|
|
{
|
2014-04-22 16:03:19 +02:00
|
|
|
return Packet1cd(preverse(Packet2d(x.v)));
|
2010-07-19 08:50:59 +02:00
|
|
|
}
|
|
|
|
|
|
2014-04-25 10:56:18 +02:00
|
|
|
EIGEN_DEVICE_FUNC inline void
|
|
|
|
|
ptranspose(PacketBlock<Packet2cf,2>& kernel) {
|
2014-03-26 19:03:07 -07:00
|
|
|
__m128d w1 = _mm_castps_pd(kernel.packet[0].v);
|
|
|
|
|
__m128d w2 = _mm_castps_pd(kernel.packet[1].v);
|
|
|
|
|
|
|
|
|
|
__m128 tmp = _mm_castpd_ps(_mm_unpackhi_pd(w1, w2));
|
|
|
|
|
kernel.packet[0].v = _mm_castpd_ps(_mm_unpacklo_pd(w1, w2));
|
|
|
|
|
kernel.packet[1].v = tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-07 16:53:36 -08:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pcmp_eq(const Packet2cf& a, const Packet2cf& b)
|
|
|
|
|
{
|
|
|
|
|
__m128 eq = _mm_cmpeq_ps(a.v, b.v);
|
2019-01-16 14:43:33 -08:00
|
|
|
return Packet2cf(pand<Packet4f>(eq, vec4f_swizzle1(eq, 1, 0, 3, 2)));
|
2019-01-07 16:53:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd pcmp_eq(const Packet1cd& a, const Packet1cd& b)
|
|
|
|
|
{
|
|
|
|
|
__m128d eq = _mm_cmpeq_pd(a.v, b.v);
|
2019-01-16 14:43:33 -08:00
|
|
|
return Packet1cd(pand<Packet2d>(eq, vec2d_swizzle1(eq, 1, 0)));
|
2019-01-07 16:53:36 -08:00
|
|
|
}
|
|
|
|
|
|
2014-06-06 20:18:44 -07:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pblend(const Selector<2>& ifPacket, const Packet2cf& thenPacket, const Packet2cf& elsePacket) {
|
2015-02-17 16:08:07 +01:00
|
|
|
__m128d result = pblend<Packet2d>(ifPacket, _mm_castps_pd(thenPacket.v), _mm_castps_pd(elsePacket.v));
|
2014-06-06 20:18:44 -07:00
|
|
|
return Packet2cf(_mm_castpd_ps(result));
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-02 10:38:13 +01:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pinsertfirst(const Packet2cf& a, std::complex<float> b)
|
|
|
|
|
{
|
|
|
|
|
return Packet2cf(_mm_loadl_pi(a.v, reinterpret_cast<const __m64*>(&b)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd pinsertfirst(const Packet1cd&, std::complex<double> b)
|
|
|
|
|
{
|
|
|
|
|
return pset1<Packet1cd>(b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pinsertlast(const Packet2cf& a, std::complex<float> b)
|
|
|
|
|
{
|
|
|
|
|
return Packet2cf(_mm_loadh_pi(a.v, reinterpret_cast<const __m64*>(&b)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet1cd pinsertlast(const Packet1cd&, std::complex<double> b)
|
|
|
|
|
{
|
|
|
|
|
return pset1<Packet1cd>(b);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
} // end namespace internal
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
} // end namespace Eigen
|
|
|
|
|
|
2010-07-05 16:18:09 +02:00
|
|
|
#endif // EIGEN_COMPLEX_SSE_H
|