Skip to content

Commit f600144

Browse files
committed
Avoid inclusion of Vc/Vc in RandomRing
Inclusiong of Vc/Vc is argued to cause gcc10 to take lot's of memory leading to crashes in the CI. In this particular case, I think we can avoid the inclusion og Vc/Vc in this header and leave it it to the source files to do so. (But this might not always be possible);
1 parent 9bd6d41 commit f600144

File tree

5 files changed

+59
-48
lines changed

5 files changed

+59
-48
lines changed

Common/MathUtils/include/MathUtils/RandomRing.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,19 @@
2828
#ifndef ALICEO2_MATHUTILS_RANDOMRING_H_
2929
#define ALICEO2_MATHUTILS_RANDOMRING_H_
3030

31-
#include "Vc/Vc"
3231
#include <array>
3332

3433
#include "TF1.h"
3534
#include "TRandom.h"
3635
#include <functional>
3736

38-
using float_v = Vc::float_v;
3937

4038
namespace o2
4139
{
4240
namespace math_utils
4341
{
4442

45-
template <size_t N = float_v::size() * 100000>
43+
template <size_t N = 4 * 100000>
4644
class RandomRing
4745
{
4846
public:
@@ -92,10 +90,15 @@ class RandomRing
9290
/// used for vectorised programming and increases the buffer
9391
/// position by the size of the vector
9492
/// @return vector with random values
95-
float_v getNextValueVc()
93+
template <typename VcType>
94+
VcType getNextValueVc()
9695
{
97-
const float_v value = float_v(&mRandomNumbers[mRingPosition]);
98-
mRingPosition += float_v::size();
96+
// This function is templated so that we don't need to include the <Vc/Vc> header
97+
// within this header file (to reduce memory problems during compilation).
98+
// The hope is that the calling user calls this with a
99+
// correct Vc type (Vc::float_v) in a source file.
100+
const VcType value = VcType(&mRandomNumbers[mRingPosition]);
101+
mRingPosition += VcType::size();
99102
if (mRingPosition >= mRandomNumbers.size()) {
100103
mRingPosition = 0;
101104
}

Detectors/FIT/FDD/simulation/include/FDDSimulation/Digitizer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class Digitizer
3535
{
3636

3737
private:
38-
typedef math_utils::RandomRing<float_v::size() * DigitizationParameters::PheRRSize> HitRandomRingType;
39-
typedef math_utils::RandomRing<float_v::size() * DigitizationParameters::HitRRSize> PheRandomRingType;
38+
typedef math_utils::RandomRing</*float_v::size()*/ 4 * DigitizationParameters::PheRRSize> HitRandomRingType;
39+
typedef math_utils::RandomRing</*float_v::size()*/ 4 * DigitizationParameters::HitRRSize> PheRandomRingType;
4040

4141
using ChannelBCDataF = std::array<float, NTimeBinsPerBC>;
4242

Detectors/FIT/FDD/simulation/src/Digitizer.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <algorithm>
1818
#include <cassert>
1919
#include <iostream>
20+
#include <Vc/Vc>
2021

2122
using namespace o2::math_utils;
2223
using namespace o2::fdd;
@@ -138,7 +139,7 @@ void Digitizer::createPulse(int nPhE, int parID, double timeHit, std::array<o2::
138139
q += Vc::float_v::Size;
139140
Vc::prefetchForOneRead(q);
140141
workVc.load(p);
141-
workVc += mRndGainVar.getNextValueVc() * charge * pmtVc;
142+
workVc += mRndGainVar.getNextValueVc<Vc::float_v>() * charge * pmtVc;
142143
workVc.store(p);
143144
p += Vc::float_v::Size;
144145
Vc::prefetchForOneRead(p);

Detectors/FIT/FT0/simulation/include/FT0Simulation/Digitizer.h

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Digitizer
3737
{
3838
private:
3939
using DP = DigitizationConstants;
40-
typedef math_utils::RandomRing<float_v::size() * DP::NOISE_RANDOM_RING_SIZE> NoiseRandomRingType;
40+
typedef math_utils::RandomRing</*float_v::size()*/ 4 * DP::NOISE_RANDOM_RING_SIZE> NoiseRandomRingType;
4141

4242
public:
4343
Digitizer(Int_t mode = 0) : mMode(mode), mRndGaus(NoiseRandomRingType::RandomType::Gaus), mNumNoiseSamples(), mNoiseSamples(), mSincTable(), mSignalTable(), mSignalCache() { initParameters(); }
@@ -109,13 +109,15 @@ class Digitizer
109109
return mSignalTable[index] + rem * (mSignalTable[index + 1] - mSignalTable[index]);
110110
}
111111

112-
inline Vc::float_v signalFormVc(Vc::float_v x) const
112+
template <typename VcType>
113+
inline VcType signalFormVc(VcType x) const
113114
{ // table lookup for the signal shape (SIMD version)
115+
// implemented as template function, so that we don't need to include <Vc/Vc> here
114116
auto const y = x / DigitizationParameters::Instance().mBunchWidth * DP::SIGNAL_TABLE_SIZE;
115-
Vc::float_v::IndexType const index = Vc::floor(y);
117+
typename VcType::IndexType const index = floor(y);
116118
auto const rem = y - index;
117-
Vc::float_v val(0);
118-
for (size_t i = 0; i < float_v::size(); ++i) {
119+
VcType val(0);
120+
for (size_t i = 0; i < VcType::size(); ++i) {
119121
if (y[i] < 0.0f) {
120122
continue;
121123
}
@@ -159,40 +161,6 @@ class Digitizer
159161
ClassDefNV(Digitizer, 2);
160162
};
161163

162-
// signal shape function
163-
template <typename Float>
164-
Float signalForm_i(Float x)
165-
{
166-
using namespace std;
167-
Float const a = -0.45458;
168-
Float const b = -0.83344945;
169-
return x > Float(0) ? -(exp(b * x) - exp(a * x)) / Float(7.8446501) : Float(0);
170-
//return -(exp(-0.83344945 * x) - exp(-0.45458 * x)) * (x >= 0) / 7.8446501; // Maximum should be 7.0/250 mV
171-
};
172-
173-
// integrated signal shape function
174-
inline float signalForm_integral(float x)
175-
{
176-
using namespace std;
177-
double const a = -0.45458;
178-
double const b = -0.83344945;
179-
if (x < 0) {
180-
x = 0;
181-
}
182-
return -(exp(b * x) / b - exp(a * x) / a) / 7.8446501;
183-
};
184-
185-
// SIMD version of the integrated signal shape function
186-
inline Vc::float_v signalForm_integralVc(Vc::float_v x)
187-
{
188-
auto const mask = (x >= 0.0f);
189-
Vc::float_v arg(0);
190-
arg.assign(x, mask); // branchless if
191-
Vc::float_v const a(-0.45458f);
192-
Vc::float_v const b(-0.83344945f);
193-
Vc::float_v result = -(Vc::exp(b * arg) / b - Vc::exp(a * arg) / a) / 7.8446501f;
194-
return result;
195-
};
196164
} // namespace ft0
197165
} // namespace o2
198166

Detectors/FIT/FT0/simulation/src/Digitizer.cxx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,50 @@
2121
#include <cassert>
2222
#include <iostream>
2323
#include <optional>
24+
#include <Vc/Vc>
2425

2526
using namespace o2::ft0;
2627

2728
ClassImp(Digitizer);
2829

30+
namespace o2::ft0
31+
{
32+
// signal shape function
33+
template <typename Float>
34+
Float signalForm_i(Float x)
35+
{
36+
using namespace std;
37+
Float const a = -0.45458;
38+
Float const b = -0.83344945;
39+
return x > Float(0) ? -(exp(b * x) - exp(a * x)) / Float(7.8446501) : Float(0);
40+
//return -(exp(-0.83344945 * x) - exp(-0.45458 * x)) * (x >= 0) / 7.8446501; // Maximum should be 7.0/250 mV
41+
};
42+
43+
// integrated signal shape function
44+
inline float signalForm_integral(float x)
45+
{
46+
using namespace std;
47+
double const a = -0.45458;
48+
double const b = -0.83344945;
49+
if (x < 0) {
50+
x = 0;
51+
}
52+
return -(exp(b * x) / b - exp(a * x) / a) / 7.8446501;
53+
};
54+
55+
// SIMD version of the integrated signal shape function
56+
inline Vc::float_v signalForm_integralVc(Vc::float_v x)
57+
{
58+
auto const mask = (x >= 0.0f);
59+
Vc::float_v arg(0);
60+
arg.assign(x, mask); // branchless if
61+
Vc::float_v const a(-0.45458f);
62+
Vc::float_v const b(-0.83344945f);
63+
Vc::float_v result = -(Vc::exp(b * arg) / b - Vc::exp(a * arg) / a) / 7.8446501f;
64+
return result;
65+
};
66+
} // namespace o2::ft0
67+
2968
Digitizer::CFDOutput Digitizer::get_time(const std::vector<float>& times, float deadTime)
3069
{
3170
assert(std::is_sorted(std::begin(times), std::end(times)));

0 commit comments

Comments
 (0)