Skip to content

Commit e235bdb

Browse files
committed
Share GPU framework allocation with ITSMFT
Initialize GPU memory pool sizes and reconstruction in the legacy ITS workflow. Move ExternalAllocator and its PMR adaptor into common ITSMFT tracking, retain legacy aliases, and pass allocation flags directly to one shared framework adapter. Expose that adapter through GPUChainITS and GPUO2Interface.
1 parent 2fa3f3e commit e235bdb

8 files changed

Lines changed: 140 additions & 86 deletions

File tree

‎Detectors/ITSMFT/ITS/tracking/GPU/ITStrackingGPU/TrackingKernels.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
#include "ITStracking/LineProjection.h"
2727
#include "DetectorsBase/Propagator.h"
2828

29+
namespace o2::itsmft::tracking
30+
{
31+
class ExternalAllocator;
32+
}
33+
2934
namespace o2::its
3035
{
3136
using o2::itsmft::tracking::bounded_vector;
@@ -41,7 +46,7 @@ template <int>
4146
class IndexTableUtils;
4247
class Cluster;
4348
class TrackITSExt;
44-
class ExternalAllocator;
49+
using ExternalAllocator = o2::itsmft::tracking::ExternalAllocator;
4550

4651
template <int NLayers>
4752
struct TrackingKernels {

‎Detectors/ITSMFT/ITS/tracking/include/ITStracking/ExternalAllocator.h‎

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -16,72 +16,13 @@
1616
#ifndef TRACKINGITSU_INCLUDE_EXTERNALALLOCATOR_H_
1717
#define TRACKINGITSU_INCLUDE_EXTERNALALLOCATOR_H_
1818

19-
#include <memory_resource>
2019
#include "GPUO2ExternalUser.h"
21-
#include "Base/GPUMemoryResource.h"
20+
#include "ITSMFTTracking/ExternalAllocator.h"
2221

2322
namespace o2::its
2423
{
25-
26-
class ExternalAllocator
27-
{
28-
using Type = std::underlying_type_t<o2::gpu::GPUMemoryResource::MemoryType>;
29-
30-
public:
31-
virtual void deallocate(char*, size_t) = 0;
32-
virtual void* allocate(size_t) = 0;
33-
void* allocate(size_t s, Type type)
34-
{
35-
auto old = mType;
36-
mType = type;
37-
void* p = allocate(s);
38-
mType = old;
39-
return p;
40-
}
41-
42-
void* allocateStack(size_t s)
43-
{
44-
return allocate(s, (o2::gpu::GPUMemoryResource::MEMORY_GPU | o2::gpu::GPUMemoryResource::MEMORY_STACK));
45-
}
46-
virtual void pushTagOnStack(uint64_t) = 0;
47-
virtual void popTagOffStack(uint64_t) = 0;
48-
49-
void setType(Type t) noexcept { mType = t; }
50-
Type getType() const noexcept { return mType; }
51-
52-
protected:
53-
Type mType;
54-
};
55-
56-
class ExternalAllocatorAdaptor final : public std::pmr::memory_resource
57-
{
58-
public:
59-
explicit ExternalAllocatorAdaptor(ExternalAllocator* alloc) : mAlloc(alloc) {}
60-
61-
protected:
62-
void* do_allocate(size_t bytes, size_t alignment) override
63-
{
64-
void* p = mAlloc->allocate(bytes, o2::gpu::GPUMemoryResource::MemoryType::MEMORY_HOST);
65-
if (!p) {
66-
throw std::bad_alloc();
67-
}
68-
return p;
69-
}
70-
71-
void do_deallocate(void* p, size_t bytes, size_t) override
72-
{
73-
mAlloc->deallocate(static_cast<char*>(p), bytes);
74-
}
75-
76-
bool do_is_equal(const std::pmr::memory_resource& other) const noexcept override
77-
{
78-
return this == &other;
79-
}
80-
81-
private:
82-
ExternalAllocator* mAlloc;
83-
};
84-
24+
using ExternalAllocator = o2::itsmft::tracking::ExternalAllocator;
25+
using ExternalAllocatorAdaptor = o2::itsmft::tracking::ExternalAllocatorAdaptor;
8526
} // namespace o2::its
8627

8728
#endif

‎Detectors/ITSMFT/ITS/workflow/src/TrackerSpec.cxx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ void TrackerDPL::init(InitContext& ic)
4545
mTimer.Reset();
4646
o2::base::GRPGeomHelper::instance().setRequest(mGGCCDBRequest);
4747
mChainITS.reset(mRecChain->AddChain<o2::gpu::GPUChainITS>());
48+
if (mRecChain->Init()) {
49+
throw std::runtime_error("GPU reconstruction initialization failed");
50+
}
4851
mITSTrackingInterface.setTraitsFromProvider(mChainITS->GetITSVertexerTraits(),
4952
mChainITS->GetITSTrackerTraits(),
5053
mChainITS->GetITSTimeframe());
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
///
12+
/// \file ExternalAllocator.h
13+
/// \brief
14+
///
15+
16+
#ifndef ALICEO2_ITSMFT_TRACKING_EXTERNALALLOCATOR_H_
17+
#define ALICEO2_ITSMFT_TRACKING_EXTERNALALLOCATOR_H_
18+
19+
#include <cstddef>
20+
#include <cstdint>
21+
#include <memory_resource>
22+
#include <type_traits>
23+
#include "Base/GPUMemoryResource.h"
24+
25+
namespace o2::itsmft::tracking
26+
{
27+
28+
class ExternalAllocator
29+
{
30+
public:
31+
using Type = std::underlying_type_t<o2::gpu::GPUMemoryResource::MemoryType>;
32+
virtual ~ExternalAllocator() = default;
33+
virtual void deallocate(char*, size_t) = 0;
34+
virtual void* allocate(size_t, Type) = 0;
35+
void* allocate(size_t size) { return allocate(size, mType); }
36+
37+
void* allocateDevice(size_t size, bool stack)
38+
{
39+
return allocate(size, o2::gpu::GPUMemoryResource::MEMORY_GPU | (stack ? o2::gpu::GPUMemoryResource::MEMORY_STACK : 0));
40+
}
41+
42+
void* allocateStack(size_t size) { return allocateDevice(size, true); }
43+
virtual void pushTagOnStack(uint64_t) = 0;
44+
virtual void popTagOffStack(uint64_t) = 0;
45+
46+
void setType(Type t) noexcept { mType = t; }
47+
Type getType() const noexcept { return mType; }
48+
49+
protected:
50+
Type mType{o2::gpu::GPUMemoryResource::MEMORY_HOST};
51+
};
52+
53+
class ExternalAllocatorAdaptor final : public std::pmr::memory_resource
54+
{
55+
public:
56+
explicit ExternalAllocatorAdaptor(ExternalAllocator* alloc) : mAlloc(alloc) {}
57+
58+
protected:
59+
void* do_allocate(size_t bytes, size_t alignment) override
60+
{
61+
void* p = mAlloc->allocate(bytes, o2::gpu::GPUMemoryResource::MemoryType::MEMORY_HOST);
62+
if (!p) {
63+
throw std::bad_alloc();
64+
}
65+
return p;
66+
}
67+
68+
void do_deallocate(void* p, size_t bytes, size_t) override
69+
{
70+
mAlloc->deallocate(static_cast<char*>(p), bytes);
71+
}
72+
73+
bool do_is_equal(const std::pmr::memory_resource& other) const noexcept override
74+
{
75+
return this == &other;
76+
}
77+
78+
private:
79+
ExternalAllocator* mAlloc;
80+
};
81+
82+
} // namespace o2::itsmft::tracking
83+
84+
#endif

‎GPU/GPUTracking/Global/GPUChainITS.cxx‎

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,44 @@
1414

1515
#include "GPUChainITS.h"
1616
#include "GPUConstantMem.h"
17+
#include "GPUDefParametersConstants.h"
1718
#include "DataFormatsITS/TrackITS.h"
18-
#include "ITStracking/ExternalAllocator.h"
19+
#include "ITSMFTTracking/ExternalAllocator.h"
1920
#include "GPUReconstructionIncludesITS.h"
2021

2122
using namespace o2::gpu;
2223

23-
namespace o2::its
24+
namespace
2425
{
25-
class GPUFrameworkExternalAllocator final : public o2::its::ExternalAllocator
26+
class GPUFrameworkExternalAllocator final : public o2::itsmft::tracking::ExternalAllocator
2627
{
2728
public:
28-
void* allocate(size_t size) final
29+
explicit GPUFrameworkExternalAllocator(GPUReconstruction* fwr) : mFWReco(fwr) {}
30+
void* allocate(size_t size, Type type) final
2931
{
30-
return mFWReco->AllocateDirectMemory(size, mType);
32+
return mFWReco->AllocateDirectMemory(size, type);
3133
}
32-
void deallocate(char* ptr, size_t size) final {} // this is a simple no-op
33-
void pushTagOnStack(uint64_t tag) final
34-
{
35-
mFWReco->PushNonPersistentMemory(tag);
36-
}
37-
void popTagOffStack(uint64_t tag) final
38-
{
39-
mFWReco->PopNonPersistentMemory(gpudatatypes::RecoStep::ITSTracking, tag);
40-
}
41-
void setReconstructionFramework(o2::gpu::GPUReconstruction* fwr) { mFWReco = fwr; }
34+
void deallocate(char*, size_t) final {}
35+
void pushTagOnStack(uint64_t tag) final { mFWReco->PushNonPersistentMemory(tag); }
36+
void popTagOffStack(uint64_t tag) final { mFWReco->PopNonPersistentMemory(gpudatatypes::RecoStep::ITSTracking, tag); }
4237

4338
private:
44-
o2::gpu::GPUReconstruction* mFWReco;
39+
GPUReconstruction* mFWReco;
4540
};
46-
} // namespace o2::its
41+
} // namespace
4742

4843
GPUChainITS::~GPUChainITS() = default;
4944

5045
GPUChainITS::GPUChainITS(GPUReconstruction* rec) : GPUChain(rec) {}
5146

5247
int32_t GPUChainITS::Init() { return 0; }
5348

49+
void GPUChainITS::MemorySize(size_t& gpuMem, size_t& pageLockedHostMem)
50+
{
51+
gpuMem = constants::GPU_DEFAULT_MEMORY_SIZE;
52+
pageLockedHostMem = constants::GPU_DEFAULT_HOST_MEMORY_SIZE;
53+
}
54+
5455
o2::its::TrackerTraits<7>* GPUChainITS::GetITSTrackerTraits()
5556
{
5657
if (mITSTrackerTraits == nullptr) {
@@ -74,14 +75,20 @@ o2::its::TimeFrame<7>* GPUChainITS::GetITSTimeframe()
7475
}
7576
#if !defined(GPUCA_STANDALONE)
7677
if (mITSTimeFrame->isGPU()) {
77-
mFrameworkAllocator.reset(new o2::its::GPUFrameworkExternalAllocator());
78-
mFrameworkAllocator->setReconstructionFramework(rec());
79-
mITSTimeFrame->setFrameworkAllocator(mFrameworkAllocator.get());
78+
mITSTimeFrame->setFrameworkAllocator(GetITSMFTFrameworkAllocator());
8079
}
8180
#endif
8281
return mITSTimeFrame.get();
8382
}
8483

84+
o2::itsmft::tracking::ExternalAllocator* GPUChainITS::GetITSMFTFrameworkAllocator()
85+
{
86+
if (mFrameworkAllocator == nullptr && mRec->IsGPU()) {
87+
mFrameworkAllocator = std::make_unique<GPUFrameworkExternalAllocator>(rec());
88+
}
89+
return mFrameworkAllocator.get();
90+
}
91+
8592
int32_t GPUChainITS::PrepareEvent() { return 0; }
8693

8794
int32_t GPUChainITS::Finalize() { return 0; }

‎GPU/GPUTracking/Global/GPUChainITS.h‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ namespace o2::its
2121
struct Cluster;
2222
struct TrackingFrameInfo;
2323
class TrackITSExt;
24-
class GPUFrameworkExternalAllocator;
2524
} // namespace o2::its
25+
namespace o2::itsmft::tracking
26+
{
27+
class ExternalAllocator;
28+
} // namespace o2::itsmft::tracking
2629

2730
namespace o2::gpu
2831
{
@@ -39,15 +42,16 @@ class GPUChainITS final : public GPUChain
3942

4043
void RegisterPermanentMemoryAndProcessors() final {};
4144
void RegisterGPUProcessors() final {};
42-
void MemorySize(size_t&, size_t&) final {};
45+
void MemorySize(size_t& gpuMem, size_t& pageLockedHostMem) final;
4346

4447
o2::its::TrackerTraits<7>* GetITSTrackerTraits();
4548
o2::its::VertexerTraits<7>* GetITSVertexerTraits();
4649
o2::its::TimeFrame<7>* GetITSTimeframe();
50+
o2::itsmft::tracking::ExternalAllocator* GetITSMFTFrameworkAllocator();
4751

4852
protected:
4953
GPUChainITS(GPUReconstruction* rec);
50-
std::unique_ptr<o2::its::GPUFrameworkExternalAllocator> mFrameworkAllocator;
54+
std::unique_ptr<o2::itsmft::tracking::ExternalAllocator> mFrameworkAllocator;
5155
std::unique_ptr<o2::its::TimeFrame<7>> mITSTimeFrame;
5256
std::unique_ptr<o2::its::TrackerTraits<7>> mITSTrackerTraits;
5357
std::unique_ptr<o2::its::VertexerTraits<7>> mITSVertexerTraits;

‎GPU/GPUTracking/Interface/GPUO2Interface.cxx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ void GPUO2Interface::setErrorCodeOutput(std::vector<std::array<uint32_t, 4>>* v)
261261
}
262262
}
263263

264+
o2::itsmft::tracking::ExternalAllocator* GPUO2Interface::GetITSMFTFrameworkAllocator()
265+
{
266+
return mChainITS->GetITSMFTFrameworkAllocator();
267+
}
268+
264269
void GPUO2Interface::GetITSTraits(o2::its::TrackerTraits<7>*& trackerTraits, o2::its::VertexerTraits<7>*& vertexerTraits, o2::its::TimeFrame<7>*& timeFrame)
265270
{
266271
trackerTraits = mChainITS->GetITSTrackerTraits();

‎GPU/GPUTracking/Interface/GPUO2Interface.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class VertexerTraits;
4545
template <int>
4646
class TimeFrame;
4747
} // namespace o2::its
48+
namespace o2::itsmft::tracking
49+
{
50+
class ExternalAllocator;
51+
} // namespace o2::itsmft::tracking
4852

4953
namespace o2::gpu
5054
{
@@ -78,6 +82,7 @@ class GPUO2Interface
7882
void DumpEvent(int32_t nEvent, GPUTrackingInOutPointers* data, uint32_t iThread, const char* dir = "");
7983
void DumpSettings(uint32_t iThread, const char* dir = "");
8084

85+
o2::itsmft::tracking::ExternalAllocator* GetITSMFTFrameworkAllocator();
8186
void GetITSTraits(o2::its::TrackerTraits<7>*& trackerTraits, o2::its::VertexerTraits<7>*& vertexerTraits, o2::its::TimeFrame<7>*& timeFrame);
8287
const o2::base::Propagator* GetDeviceO2Propagator(int32_t iThread = 0) const;
8388
void UseGPUPolynomialFieldInPropagator(o2::base::Propagator* prop) const;

0 commit comments

Comments
 (0)