Project
Loading...
Searching...
No Matches
GPUReconstructionProcessing.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
17
18using namespace o2::gpu;
19
21{
22 int32_t nThreads = 0;
23 if (mProcessingSettings.inKernelParallel == 2 && mNActiveThreadsOuterLoop) {
24 if (splitCores) {
27 } else {
28 nThreads = mMaxHostThreads;
29 }
30 nThreads = std::max(1, nThreads);
31 } else {
32 nThreads = mProcessingSettings.inKernelParallel ? mMaxHostThreads : 1;
33 }
34 return nThreads;
35}
36
38{
39 mActiveHostKernelThreads = std::max(1, n < 0 ? mMaxHostThreads : std::min(n, mMaxHostThreads));
40 mThreading->activeThreads = std::make_unique<tbb::task_arena>(mActiveHostKernelThreads);
41 if (mProcessingSettings.debugLevel >= 3) {
42 GPUInfo("Set number of active parallel kernels threads on host to %d (%d requested)", mActiveHostKernelThreads, n);
43 }
44}
45
46void GPUReconstructionProcessing::runParallelOuterLoop(bool doGPU, uint32_t nThreads, std::function<void(uint32_t)> lambda)
47{
48 tbb::task_arena(SetAndGetNActiveThreadsOuterLoop(!doGPU, nThreads)).execute([&] {
49 tbb::parallel_for<uint32_t>(0, nThreads, lambda, tbb::simple_partitioner());
50 });
51}
52
53namespace o2::gpu
54{
55namespace // anonymous
56{
57static std::atomic_flag timerFlag = ATOMIC_FLAG_INIT; // TODO: Should be a class member not global, but cannot be moved to header due to ROOT limitation
58} // anonymous namespace
59} // namespace o2::gpu
60
61GPUReconstructionProcessing::timerMeta* GPUReconstructionProcessing::insertTimer(uint32_t id, std::string&& name, int32_t J, int32_t num, int32_t type, RecoStep step)
62{
63 while (timerFlag.test_and_set()) {
64 }
65 if (mTimers.size() <= id) {
66 mTimers.resize(id + 1);
67 }
68 if (mTimers[id] == nullptr) {
69 if (J >= 0) {
70 name += std::to_string(J);
71 }
72 mTimers[id].reset(new timerMeta{std::unique_ptr<HighResTimer[]>{new HighResTimer[num]}, name, num, type, 1u, step, (size_t)0});
73 } else {
74 mTimers[id]->count++;
75 }
76 timerMeta* retVal = mTimers[id].get();
77 timerFlag.clear();
78 return retVal;
79}
80
81GPUReconstructionProcessing::timerMeta* GPUReconstructionProcessing::getTimerById(uint32_t id, bool increment)
82{
83 timerMeta* retVal = nullptr;
84 while (timerFlag.test_and_set()) {
85 }
86 if (mTimers.size() > id && mTimers[id]) {
87 retVal = mTimers[id].get();
88 retVal->count += increment;
89 }
90 timerFlag.clear();
91 return retVal;
92}
93
94uint32_t GPUReconstructionProcessing::getNextTimerId()
95{
96 static std::atomic<uint32_t> id{0};
97 return id.fetch_add(1);
98}
99
101{
102 if (condition && mProcessingSettings.inKernelParallel != 1) {
103 mNActiveThreadsOuterLoop = mProcessingSettings.inKernelParallel == 2 ? std::min<uint32_t>(max, mMaxHostThreads) : mMaxHostThreads;
104 } else {
106 }
107 if (mProcessingSettings.debugLevel >= 5) {
108 printf("Running %d threads in outer loop\n", mNActiveThreadsOuterLoop);
109 }
111}
112
113std::unique_ptr<gpu_reconstruction_kernels::threadContext> GPUReconstructionProcessing::GetThreadContext()
114{
115 return std::make_unique<gpu_reconstruction_kernels::threadContext>();
116}
117
int32_t retVal
double num
virtual std::unique_ptr< gpu_reconstruction_kernels::threadContext > GetThreadContext() override
void runParallelOuterLoop(bool doGPU, uint32_t nThreads, std::function< void(uint32_t)> lambda)
std::vector< std::unique_ptr< timerMeta > > mTimers
uint32_t SetAndGetNActiveThreadsOuterLoop(bool condition, uint32_t max)
GPUSettingsProcessing mProcessingSettings
std::shared_ptr< GPUReconstructionThreading > mThreading
GLdouble n
Definition glcorearb.h:1982
GLuint const GLchar * name
Definition glcorearb.h:781
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLuint id
Definition glcorearb.h:650
value_T step
Definition TrackUtils.h:42
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
constexpr size_t max