Skip to content

Commit fd56fa4

Browse files
committed
ITS: allow sharing of arena in Tracker & Vertexer
1 parent 4467ca0 commit fd56fa4

4 files changed

Lines changed: 33 additions & 4 deletions

File tree

Detectors/ITSMFT/ITS/tracking/include/ITStracking/TrackingInterface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "GPUO2Interface.h"
2929
#include "GPUChainITS.h"
3030

31+
#include <oneapi/tbb/task_arena.h>
32+
3133
namespace o2::its
3234
{
3335
class ITSTrackingInterface
@@ -97,6 +99,7 @@ class ITSTrackingInterface
9799
std::unique_ptr<Vertexer> mVertexer = nullptr;
98100
const o2::dataformats::MeanVertexObject* mMeanVertex;
99101
std::shared_ptr<BoundedMemoryResource> mMemoryPool;
102+
tbb::task_arena mTaskArena;
100103
};
101104

102105
} // namespace o2::its

Detectors/ITSMFT/ITS/tracking/src/TrackerTraits.cxx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,9 +1266,16 @@ void TrackerTraits<nLayers>::setNThreads(int n)
12661266
mNThreads = n > 0 ? n : 1;
12671267
#if defined(OPTIMISATION_OUTPUT) || defined(CA_DEBUG)
12681268
mNThreads = 1; // only works while serial
1269-
#endif
12701269
mTaskArena.initialize(mNThreads);
1271-
LOGP(info, "Setting tracker with {} threads.", mNThreads);
1270+
#else
1271+
if (tbb::this_task_arena::current_thread_index() == tbb::task_arena::not_initialized) {
1272+
mTaskArena.initialize(mNThreads);
1273+
LOGP(info, "Setting tracker with {} threads.", mNThreads);
1274+
} else {
1275+
mTaskArena.initialize(tbb::task_arena::attach{});
1276+
LOGP(info, "Attaching tracker to calling threads arena");
1277+
}
1278+
#endif
12721279
}
12731280

12741281
template class TrackerTraits<7>;

Detectors/ITSMFT/ITS/tracking/src/TrackingInterface.cxx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ void ITSTrackingInterface::initialise()
148148
}
149149
mTracker->setParameters(trackParams);
150150
mVertexer->setParameters(vertParams);
151+
if (trackConf.nThreads == vertConf.nThreads && tbb::this_task_arena::current_thread_index() == tbb::task_arena::not_initialized) {
152+
bool clamped{false};
153+
int nThreads = trackConf.nThreads;
154+
if (nThreads > 0) {
155+
const int hw = std::thread::hardware_concurrency();
156+
const int maxThreads = (hw == 0 ? 1 : hw);
157+
nThreads = std::clamp(nThreads, 1, maxThreads);
158+
clamped = trackConf.nThreads > maxThreads;
159+
}
160+
LOGP(info, "Tracker and Vertexer will share the task arena with {} threads{}", nThreads, (clamped) ? " (clamped)" : "");
161+
mTaskArena.initialize(std::abs(nThreads));
162+
}
151163
}
152164

153165
void ITSTrackingInterface::run(framework::ProcessingContext& pc)

Detectors/ITSMFT/ITS/tracking/src/VertexerTraits.cxx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,14 @@ void VertexerTraits::setNThreads(int n)
695695
mNThreads = n > 0 ? n : 1;
696696
#if defined(VTX_DEBUG)
697697
mNThreads = 1;
698-
#endif
699698
mTaskArena.initialize(mNThreads);
700-
LOGP(info, "Setting seeding vertexer with {} threads.", mNThreads);
699+
#else
700+
if (tbb::this_task_arena::current_thread_index() == tbb::task_arena::not_initialized) {
701+
mTaskArena.initialize(mNThreads);
702+
LOGP(info, "Setting seeding vertexer with {} threads.", mNThreads);
703+
} else {
704+
mTaskArena.initialize(tbb::task_arena::attach{});
705+
LOGP(info, "Attaching vertexer to calling thread's arena");
706+
}
707+
#endif
701708
}

0 commit comments

Comments
 (0)