11
INTEL CONFIDENTIAL Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. Other names and brands may be claimed as the property of others. All products, dates, and figures are preliminary and are subject to change without any Auto-vectorization 1/ ::Mask cannot be translated – hence some source code modifications in declaration/definition…: template<TranslationIdType tid, RotationIdType rid, class TubeType=TubeTraits::HollowTubeWithPhi, class T=double> template<typename VectorType = Vc::Vector<T> > inline __attribute__((always_inline)) typename VectorType::Mask determineRHit( VectorType const & /*x-vec*/, VectorType const & /*y-vec*/, inline __attribute__((always_inline)) int determineRHitav( T const & /*x-vec*/, T const & /*y- vec*/, T const & /*z-vec*/,

INTEL CONFIDENTIAL Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other

Embed Size (px)

Citation preview

Page 1: INTEL CONFIDENTIAL Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other

INTEL CONFIDENTIALIntel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. Other names and brandsmay be claimed as the property of others. All products, dates, and figures are preliminary and are subject to change without any notice. Copyright © 2013, Intel Corporation.

Auto-vectorization 1/

• ::Mask cannot be translated – hence some source code modifications in declaration/definition…:

template<TranslationIdType tid, RotationIdType rid, class TubeType=TubeTraits::HollowTubeWithPhi, class T=double>

template<typename VectorType = Vc::Vector<T> >

inline __attribute__((always_inline))

typename VectorType::Mask determineRHit( VectorType const & /*x-vec*/, VectorType const & /*y-vec*/,

inline __attribute__((always_inline))

int determineRHitav( T const & /*x-vec*/, T const & /*y-vec*/, T const & /*z-vec*/,

Page 2: INTEL CONFIDENTIAL Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other

INTEL CONFIDENTIALIntel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. Other names and brandsmay be claimed as the property of others. All products, dates, and figures are preliminary and are subject to change without any notice. Copyright © 2013, Intel Corporation.

Auto-vectorization 2/

• Source code is still too adherent to Vc• Ex PointIsInPhiSector method:

void PointIsInPhiSector(T const & phi1normalx, T const & phi1normaly,

T const & phi2normalx, T const & phi2normaly,

Vc::Vector<T> const & xcoord,

Vc::Vector<T> const & ycoord,

typename Vc::Vector<T>::Mask & isinphi )

{// method based on calculating the scalar product of position vectors with the normals of the (empty) phi sektor

// avoids taking the atan2

// this method could be template specialized in case DeltaPhi = 180^o

Vc::Vector<T> scalarproduct1 = phi1normalx*xcoord + phi1normaly*ycoord;

Vc::Vector<T> scalarproduct2 = phi2normalx*xcoord + phi2normaly*ycoord;

isinphi = (scalarproduct1 > Vc::Zero && scalarproduct2 > Vc::Zero);

}

Page 3: INTEL CONFIDENTIAL Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other

INTEL CONFIDENTIALIntel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. Other names and brandsmay be claimed as the property of others. All products, dates, and figures are preliminary and are subject to change without any notice. Copyright © 2013, Intel Corporation.

Auto-vectorization 3/

• Vc master branch + VecGeom prototypev1 compiled with gcc-4.8.1 + CHEP13Benchmark• For 1024 vector length and 1000 repetition

vecnav.DistToNextBoundary() best timing is: ~94ms• Machine is a E5-2697 v2 @ 2.70GHz

Page 4: INTEL CONFIDENTIAL Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other

INTEL CONFIDENTIALIntel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. Other names and brandsmay be claimed as the property of others. All products, dates, and figures are preliminary and are subject to change without any notice. Copyright © 2013, Intel Corporation.

Auto-vectorization 4/

• Intel Vtune gives the following profile (sampling overhead pushed the 94ms to ~130ms)

• Decision to “port” to auto-vectorisation the PlacedUSolidsTube<tid,rid,TubeType,ValueType>::DistanceToIn method (hotspot#2). Baseline timing 30ms.

Page 5: INTEL CONFIDENTIAL Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other

INTEL CONFIDENTIALIntel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. Other names and brandsmay be claimed as the property of others. All products, dates, and figures are preliminary and are subject to change without any notice. Copyright © 2013, Intel Corporation.

Auto-vectorization 5/

• Vc generates very nice asm…

Page 6: INTEL CONFIDENTIAL Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other

INTEL CONFIDENTIALIntel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. Other names and brandsmay be claimed as the property of others. All products, dates, and figures are preliminary and are subject to change without any notice. Copyright © 2013, Intel Corporation.

Auto-vectorization 6/• Could not instanciate a

PlacedUSolidsTube<tid,rid,TubeType,ValueType>::DistanceToIn method for template parameter = double

• Choice was to re-implement another overloaded method for such type:

Page 7: INTEL CONFIDENTIAL Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other

INTEL CONFIDENTIALIntel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. Other names and brandsmay be claimed as the property of others. All products, dates, and figures are preliminary and are subject to change without any notice. Copyright © 2013, Intel Corporation.

Auto-vectorization 7/

• Not a small kernel; but code is quite easily portable to auto-vectorization:‒ MaskType inz_m = safez > Utils::fgToleranceVc;‒ done_m = !inz_m && ( z*dirz >= Vc::Zero ); // particle outside the

z-range and moving away‒ …‒ int inz_m = (safez > Utils::fgTolerance) ? 1 : 0;‒ int done_m = (!inz_m && (z*dirz >= 0.0)) ? 1 : 0; // particle

outside the z-range and moving away

‒ VectorType distanceRmax( Utils::kInfinityVc );

‒ distanceRmax( canhitrmax ) = (-b - Vc::sqrt( discriminant ))*inverse2a;

‒ ValueType distanceRmax = (canhitrmax) ? ((-b - std::sqrt(discriminant))*inverse2a) : Utils::kInfinity;

Page 8: INTEL CONFIDENTIAL Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other

INTEL CONFIDENTIALIntel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. Other names and brandsmay be claimed as the property of others. All products, dates, and figures are preliminary and are subject to change without any notice. Copyright © 2013, Intel Corporation.

Auto-vectorization 8/• Auto-vectorization timings are not too catastrophic …~40ms vs 30ms for Vc

(speed-down of 33%)

• No arithmetic perturbation visible !?

• Same behavior for x10 repetitions

• Asm inspection shows partial vectorization for g++ -- need to dig in this direction, as g++ is doing a pretty good job in handling recursive template inlining form out of the box….

Page 9: INTEL CONFIDENTIAL Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other

INTEL CONFIDENTIALIntel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. Other names and brandsmay be claimed as the property of others. All products, dates, and figures are preliminary and are subject to change without any notice. Copyright © 2013, Intel Corporation.

Auto-vectorization 9/• With Intel compiler vectorisation seems complete (see next slide for asm

inspection), although for the rest of the code embedding Vc template our compiler seems to be lost!

Page 10: INTEL CONFIDENTIAL Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other

INTEL CONFIDENTIALIntel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. Other names and brandsmay be claimed as the property of others. All products, dates, and figures are preliminary and are subject to change without any notice. Copyright © 2013, Intel Corporation.

Auto-vectorization 10/

Page 11: INTEL CONFIDENTIAL Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other

INTEL CONFIDENTIALIntel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. Other names and brandsmay be claimed as the property of others. All products, dates, and figures are preliminary and are subject to change without any notice. Copyright © 2013, Intel Corporation.

Auto-vectorization 11/

• I would recommend to always keep in mind the auto-vectorisation branch in template writing.• Auto-vectorization can be a pain – depending how

compiler handles recursive template inlining..Ours seems to do a very poor job – I will initiate an internal review of this code with compiler engineering.• Need also to review reasons of partial vectorization for

g++• Need to test other kernels more complicated• Try this on Haswell (int will be promoted to 256bits vl)• Try this on MIC• …