Commit c7b26496 authored by Vakhtang Tsulaia's avatar Vakhtang Tsulaia
Browse files

Merge branch 'master-sincos-vec-2' into 'master'

Vectorized sincos calculation in LArWheelCalculator

See merge request !40107
parents 431b19e7 0647e0c7
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
*/
#ifndef GEOSPECIALSHAPES_LARWHEELCALCULATOR_H
......@@ -7,11 +7,16 @@
#include <vector>
// FMV and other checks
#include "CxxUtils/features.h"
#include "CLHEP/Vector/ThreeVector.h"
#ifndef XAOD_STANDALONE
#include "AthenaKernel/CLASS_DEF.h"
#endif // XAOD_STANDALONE
#if HAVE_VECTOR_SIZE_ATTRIBUTE
#include "vec_parametrized_sincos.h"
#endif
#include "GeoSpecialShapes/LArWheelCalculatorEnums.h"
#define LARWC_SINCOS_POLY 5
......@@ -207,8 +212,11 @@ class LArWheelCalculator
LArWheelCalculator_Impl::IDistanceCalculator *m_distanceCalcImpl;
LArWheelCalculator_Impl::IFanCalculator *m_fanCalcImpl;
void fill_sincos_parameterization();
#if HAVE_VECTOR_SIZE_ATTRIBUTE
vsincos_par m_vsincos_par{};
#endif
};
#ifndef XAOD_STANDALONE
......
/*
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
*/
/**
* @brief vectorized version of parametrized sincos
* see ATLASSIM-4753 for details
* @author Miha Muskinja, Chistos Anastopoulos
*/
#ifndef VEC_PARAMETRIZED_SINCOS_H
#define VEC_PARAMETRIZED_SINCOS_H
#include "CxxUtils/restrict.h"
#include "CxxUtils/vec.h"
struct vsincos_par
{
CxxUtils::vec<double, 4> param_0 = {};
CxxUtils::vec<double, 4> param_1 = {};
CxxUtils::vec<double, 4> param_2 = {};
#if HAVE_FUNCTION_MULTIVERSIONING
#if defined(__x86_64__)
__attribute__((target("avx2,fma")))
void
evaluate(const double r,
double &ATH_RESTRICT sin_a,
double &ATH_RESTRICT cos_a) const ATH_RESTRICT
{
const double r2 = r * r;
CxxUtils::vec<double, 4> P = r2 * param_0 + param_1;
P = r2 * P + param_2;
CxxUtils::vec<double, 4> P2 = {P[1], P[0], P[3], P[2]};
CxxUtils::vec<double, 4> res = r * P2 + P;
sin_a = res[0];
cos_a = res[2];
}
__attribute__((target("avx2")))
void
eval(const double r,
double &ATH_RESTRICT sin_a,
double &ATH_RESTRICT cos_a) const ATH_RESTRICT
{
const double r2 = r * r;
CxxUtils::vec<double, 4> P = r2 * param_0 + param_1;
P = r2 * P + param_2;
CxxUtils::vec<double, 4> P2 = {P[1], P[0], P[3], P[2]};
CxxUtils::vec<double, 4> res = r * P2 + P;
sin_a = res[0];
cos_a = res[2];
}
__attribute__((target("default")))
#endif // x86
#endif // FMV
void
eval(const double r,
double &ATH_RESTRICT sin_a,
double &ATH_RESTRICT cos_a) const ATH_RESTRICT
{
const double r2 = r * r;
CxxUtils::vec<double, 4> P = r2 * param_0 + param_1;
P = r2 * P + param_2;
sin_a = r * P[1] + P[0];
cos_a = r * P[3] + P[2];
}
};
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
*/
#include "DistanceCalculatorSaggingOff.h"
......@@ -48,7 +48,7 @@ namespace LArWheelCalculator_Impl
const double cos_a = scalpha.cs, sin_a = scalpha.sn;
#else // parameterized sine
double cos_a, sin_a;
lwc()->parameterized_sincos(P.y(), sin_a, cos_a);
lwc()->m_vsincos_par.eval(P.y(), sin_a, cos_a);
#endif
// determination of the nearest quarter-wave number
int nqwave = (z < 0.) ? 0 : int(z / lwc()->m_QuarterWaveLength);
......@@ -160,7 +160,7 @@ namespace LArWheelCalculator_Impl
double cos_a = scalpha.cs, sin_a = scalpha.sn;
#else // parameterized sine
double cos_a, sin_a;
lwc()->parameterized_sincos(P.y(), sin_a, cos_a);
lwc()->m_vsincos_par.eval(P.y(), sin_a, cos_a);
#endif
bool sqw = false;
......@@ -251,7 +251,7 @@ namespace LArWheelCalculator_Impl
const double cos_a = scalpha.cs, sin_a = scalpha.sn;
#else // parameterized sine
double cos_a, sin_a;
lwc()->parameterized_sincos(P.y(), sin_a, cos_a);
lwc()->m_vsincos_par.eval(P.y(), sin_a, cos_a);
#endif
int nqwave;
......@@ -339,7 +339,7 @@ namespace LArWheelCalculator_Impl
double cos_a = scalpha.cs, sin_a = scalpha.sn;
#else // parameterized sine
double cos_a, sin_a;
lwc()->parameterized_sincos(P.y(), sin_a, cos_a);
lwc()->m_vsincos_par.eval(P.y(), sin_a, cos_a);
#endif
bool sqw = false;
......@@ -434,7 +434,7 @@ namespace LArWheelCalculator_Impl
// parameterized sine
#else
double cos_a, sin_a;
lwc()->parameterized_sincos(P.y(), sin_a, cos_a);
lwc()->m_vsincos_par.eval(P.y(), sin_a, cos_a);
#endif
// determination of the nearest quarter-wave number
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
*/
#include "GeoSpecialShapes/LArWheelCalculator.h"
......@@ -98,6 +98,24 @@ void LArWheelCalculator::fill_sincos_parameterization()
m_sin_parametrization[i] = sin_parametrization[S][i];
m_cos_parametrization[i] = cos_parametrization[S][i];
}
// Parameterization for the vectorized sincos calculation
// see ATLASSIM-4753 for details
// s4, s5, c4, c5
// s2, s3, c2, c3
// s0, s1, c0, c1
m_vsincos_par.param_0[0] = m_sin_parametrization[4];
m_vsincos_par.param_0[1] = m_sin_parametrization[5];
m_vsincos_par.param_0[2] = m_cos_parametrization[4];
m_vsincos_par.param_0[3] = m_cos_parametrization[5];
m_vsincos_par.param_1[0] = m_sin_parametrization[2];
m_vsincos_par.param_1[1] = m_sin_parametrization[3];
m_vsincos_par.param_1[2] = m_cos_parametrization[2];
m_vsincos_par.param_1[3] = m_cos_parametrization[3];
m_vsincos_par.param_2[0] = m_sin_parametrization[0];
m_vsincos_par.param_2[1] = m_sin_parametrization[1];
m_vsincos_par.param_2[2] = m_cos_parametrization[0];
m_vsincos_par.param_2[3] = m_cos_parametrization[1];
return;
}
......@@ -139,6 +157,23 @@ void LArWheelCalculator::fill_sincos_parameterization()
cos_parametrization[S][i] = params_cos[i];
}
// Parameterization for the vectorized sincos calculation
// see ATLASSIM-4753 for details
// s4, s5, c4, c5
// s2, s3, c2, c3
// s0, s1, c0, c1
m_vsincos_par.param_0[0] = m_sin_parametrization[4];
m_vsincos_par.param_0[1] = m_sin_parametrization[5];
m_vsincos_par.param_0[2] = m_cos_parametrization[4];
m_vsincos_par.param_0[3] = m_cos_parametrization[5];
m_vsincos_par.param_1[0] = m_sin_parametrization[2];
m_vsincos_par.param_1[1] = m_sin_parametrization[3];
m_vsincos_par.param_1[2] = m_cos_parametrization[2];
m_vsincos_par.param_1[3] = m_cos_parametrization[3];
m_vsincos_par.param_2[0] = m_sin_parametrization[0];
m_vsincos_par.param_2[1] = m_sin_parametrization[1];
m_vsincos_par.param_2[2] = m_cos_parametrization[0];
m_vsincos_par.param_2[3] = m_cos_parametrization[1];
filled[S] = true;
// FIXME: nothing below is needed unless debug printing
......@@ -156,7 +191,17 @@ void LArWheelCalculator::fill_sincos_parameterization()
for(double r = Rmin + 40.; r < Rmax - 40.; r += Rstep / 10.){
CxxUtils::sincos scalpha(parameterized_slant_angle(r));
double sin_a, cos_a;
double sin_a_v, cos_a_v;
parameterized_sincos(r, sin_a, cos_a);
m_vsincos_par.eval(r, sin_a_v, cos_a_v);
#if DEBUGPRINT
std::streamsize ss = std::cout.precision();
std::cout.precision(16);
std::cout << "def: " << r << " " << sin_a << " " << cos_a << std::endl;
std::cout << "vec: " << r << " " << sin_a_v << " " << cos_a_v << std::endl;
std::cout << "dif: " << r << " " << (sin_a - sin_a_v) / sin_a << " " << (cos_a - cos_a_v) / cos_a << std::endl;
std::cout.precision(ss);
#endif
double ds = fabs(scalpha.sn - sin_a);
if(ds > dsin){
dsin = ds;
......
......@@ -27,7 +27,7 @@ ciRefFileMap = {
's3505-21.0' : 'v2',
's3505-21.3' : 'v1',
's3505-21.9' : 'v1',
's3505-22.0' : 'v12',
's3505-22.0' : 'v13',
# OverlayTier0Test_required-test
'overlay-d1498-21.0' : 'v2',
'overlay-d1498-22.0' : 'v38',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment