Skip to content

Commit cb20b56

Browse files
committed
GPU: Improve ROOT Debug dump utility class
1 parent 6309593 commit cb20b56

11 files changed

Lines changed: 264 additions & 127 deletions

File tree

GPU/GPUTracking/Base/GPUReconstruction.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#include "GPUReconstruction.h"
3939
#include "GPUReconstructionIncludes.h"
40+
#include "GPUROOTDumpCore.h"
4041

4142
#include "GPUMemoryResource.h"
4243
#include "GPUChain.h"
@@ -103,6 +104,7 @@ GPUReconstruction::GPUReconstruction(const GPUSettingsDeviceBackend& cfg) : mHos
103104
processors()->tpcClusterer[i].mISlice = i;
104105
#endif
105106
}
107+
mROOTDump = GPUROOTDumpCore::getAndCreate();
106108
}
107109

108110
GPUReconstruction::~GPUReconstruction()

GPU/GPUTracking/Base/GPUReconstruction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ namespace gpu
4848
class GPUChain;
4949
struct GPUMemorySizeScalers;
5050
struct GPUReconstructionPipelineContext;
51+
class GPUROOTDumpCore;
5152

5253
class GPUReconstruction
5354
{
@@ -362,6 +363,7 @@ class GPUReconstruction
362363
unsigned int mNEventsProcessed = 0;
363364
double mStatKernelTime = 0.;
364365
double mStatWallTime = 0.;
366+
std::shared_ptr<GPUROOTDumpCore> mROOTDump;
365367

366368
int mMaxThreads = 0; // Maximum number of threads that may be running, on CPU or GPU
367369
int mThreadId = -1; // Thread ID that is valid for the local CUDA context

GPU/GPUTracking/Base/GPUTPCGPURootDump.h

Lines changed: 0 additions & 108 deletions
This file was deleted.

GPU/GPUTracking/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ set(SRCS_NO_CINT
7777
Global/GPUTrackingInputProvider.cxx
7878
Global/GPUErrors.cxx
7979
Merger/GPUTPCGMMergerGPU.cxx
80+
Debug/GPUROOTDumpCore.cxx
8081
utils/timer.cxx)
8182

8283
set(SRCS_NO_H SliceTracker/GPUTPCTrackerDump.cxx
@@ -144,6 +145,7 @@ set(HDRS_INSTALL
144145
Definitions/GPUDefOpenCL12Templates.h
145146
Definitions/GPULogging.h
146147
Definitions/GPUDefMacros.h
148+
Debug/GPUROOTDump.h
147149
)
148150

149151
# Sources only for O2
@@ -289,6 +291,7 @@ if(ALIGPU_BUILD_TYPE STREQUAL "O2")
289291
Interface
290292
Merger
291293
Refit
294+
Debug
292295
DataCompression
293296
TPCClusterFinder
294297
TARGETVARNAME targetName
@@ -345,6 +348,7 @@ if(ALIGPU_BUILD_TYPE STREQUAL "ALIROOT")
345348
${CMAKE_SOURCE_DIR}/GPU/Common
346349
${CMAKE_SOURCE_DIR}/GPU/Utils
347350
${CMAKE_SOURCE_DIR}/GPU/GPUTracking
351+
${CMAKE_SOURCE_DIR}/GPU/GPUTracking/Debug
348352
${CMAKE_SOURCE_DIR}/GPU/GPUTracking/Definitions
349353
${CMAKE_SOURCE_DIR}/GPU/GPUTracking/DataTypes
350354
${CMAKE_SOURCE_DIR}/GPU/GPUTracking/Base
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \file GPUROOTDump.h
12+
/// \author David Rohr
13+
14+
#ifndef GPUROOTDUMP_H
15+
#define GPUROOTDUMP_H
16+
17+
#include "GPUROOTDumpCore.h"
18+
19+
#if !defined(GPUCA_NO_ROOT) && !defined(GPUCA_GPUCODE)
20+
#include <TTree.h>
21+
#include <TNtuple.h>
22+
#include <memory>
23+
#include <stdexcept>
24+
#endif
25+
26+
namespace GPUCA_NAMESPACE
27+
{
28+
namespace gpu
29+
{
30+
#if !defined(GPUCA_NO_ROOT) && !defined(GPUCA_GPUCODE)
31+
namespace
32+
{
33+
template <class S>
34+
struct internal_Branch {
35+
template <typename... Args>
36+
static void Branch(S* p, Args... args)
37+
{
38+
}
39+
};
40+
template <>
41+
struct internal_Branch<TTree> {
42+
template <typename... Args>
43+
static void Branch(TTree* p, Args... args)
44+
{
45+
p->Branch(args...);
46+
}
47+
};
48+
} // namespace
49+
50+
template <class T>
51+
class GPUROOTDump : public GPUROOTDumpBase
52+
{
53+
public:
54+
static GPUROOTDump<T>& get(const char* name)
55+
{
56+
static GPUROOTDump<T> instance(name);
57+
}
58+
GPUROOTDump(const char* name)
59+
{
60+
mTree = new TTree(name, name);
61+
mTree->Branch(name, &mObj);
62+
}
63+
64+
void write() override { mTree->Write(); }
65+
66+
void Fill(const T& o)
67+
{
68+
mObj = o;
69+
mTree->Fill();
70+
}
71+
72+
private:
73+
TTree* mTree = nullptr;
74+
T mObj;
75+
};
76+
77+
template <>
78+
class GPUROOTDump<TNtuple> : public GPUROOTDumpBase
79+
{
80+
public:
81+
static GPUROOTDump<TNtuple>& get(const char* name, const char* options)
82+
{
83+
static GPUROOTDump<TNtuple> instance(name, options);
84+
return instance;
85+
}
86+
GPUROOTDump(const char* name, const char* options)
87+
{
88+
mNTuple = new TNtuple(name, name, options);
89+
}
90+
91+
void write() override { mNTuple->Write(); }
92+
93+
template <typename... Args>
94+
void Fill(Args... args)
95+
{
96+
mNTuple->Fill(args...);
97+
}
98+
99+
private:
100+
TNtuple* mNTuple;
101+
};
102+
#else
103+
template <class T>
104+
class GPUROOTDump
105+
{
106+
public:
107+
GPUROOTDump() = delete;
108+
};
109+
#endif
110+
} // namespace gpu
111+
} // namespace GPUCA_NAMESPACE
112+
113+
#endif
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \file GPUROOTDumpCore.cxx
12+
/// \author David Rohr
13+
14+
#include "GPUROOTDumpCore.h"
15+
16+
#if (!defined(GPUCA_STANDALONE) || defined(GPUCA_BUILD_QA)) && !defined(GPUCA_GPUCODE)
17+
#include <atomic>
18+
#include <memory>
19+
#include <TFile.h>
20+
21+
using namespace GPUCA_NAMESPACE::gpu;
22+
23+
std::weak_ptr<GPUROOTDumpCore> GPUROOTDumpCore::sInstance;
24+
25+
GPUROOTDumpCore::GPUROOTDumpCore()
26+
{
27+
mFile.reset(new TFile("debug.root", "recreate"));
28+
}
29+
30+
GPUROOTDumpCore::~GPUROOTDumpCore()
31+
{
32+
for (unsigned int i = 0; i < mBranches.size(); i++) {
33+
mBranches[i]->write();
34+
}
35+
mFile->Close();
36+
}
37+
38+
std::shared_ptr<GPUROOTDumpCore> GPUROOTDumpCore::getAndCreate()
39+
{
40+
static std::atomic_flag lock = ATOMIC_FLAG_INIT;
41+
while (lock.test_and_set(std::memory_order_acquire)) {
42+
}
43+
std::shared_ptr<GPUROOTDumpCore> retVal = sInstance.lock();
44+
if (!retVal) {
45+
retVal = std::make_shared<GPUROOTDumpCore>();
46+
sInstance = retVal;
47+
}
48+
lock.clear(std::memory_order_release);
49+
return retVal;
50+
}
51+
52+
GPUROOTDumpBase::GPUROOTDumpBase()
53+
{
54+
std::shared_ptr<GPUROOTDumpCore> p = GPUROOTDumpCore::get().lock();
55+
if (!p) {
56+
throw std::runtime_error("No instance of GPUROOTDumpCore exists");
57+
}
58+
p->mBranches.emplace_back(this);
59+
p->mFile->cd();
60+
}
61+
62+
#endif

0 commit comments

Comments
 (0)