Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
#include "ITStracking/LineProjection.h"
#include "DetectorsBase/Propagator.h"

namespace o2::itsmft::tracking
{
class ExternalAllocator;
}

namespace o2::its
{
using o2::itsmft::tracking::bounded_vector;
Expand All @@ -41,7 +46,7 @@ template <int>
class IndexTableUtils;
class Cluster;
class TrackITSExt;
class ExternalAllocator;
using ExternalAllocator = o2::itsmft::tracking::ExternalAllocator;

template <int NLayers>
struct TrackingKernels {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,72 +16,13 @@
#ifndef TRACKINGITSU_INCLUDE_EXTERNALALLOCATOR_H_
#define TRACKINGITSU_INCLUDE_EXTERNALALLOCATOR_H_

#include <memory_resource>
#include "GPUO2ExternalUser.h"
#include "Base/GPUMemoryResource.h"
#include "ITSMFTTracking/ExternalAllocator.h"

namespace o2::its
{

class ExternalAllocator
{
using Type = std::underlying_type_t<o2::gpu::GPUMemoryResource::MemoryType>;

public:
virtual void deallocate(char*, size_t) = 0;
virtual void* allocate(size_t) = 0;
void* allocate(size_t s, Type type)
{
auto old = mType;
mType = type;
void* p = allocate(s);
mType = old;
return p;
}

void* allocateStack(size_t s)
{
return allocate(s, (o2::gpu::GPUMemoryResource::MEMORY_GPU | o2::gpu::GPUMemoryResource::MEMORY_STACK));
}
virtual void pushTagOnStack(uint64_t) = 0;
virtual void popTagOffStack(uint64_t) = 0;

void setType(Type t) noexcept { mType = t; }
Type getType() const noexcept { return mType; }

protected:
Type mType;
};

class ExternalAllocatorAdaptor final : public std::pmr::memory_resource
{
public:
explicit ExternalAllocatorAdaptor(ExternalAllocator* alloc) : mAlloc(alloc) {}

protected:
void* do_allocate(size_t bytes, size_t alignment) override
{
void* p = mAlloc->allocate(bytes, o2::gpu::GPUMemoryResource::MemoryType::MEMORY_HOST);
if (!p) {
throw std::bad_alloc();
}
return p;
}

void do_deallocate(void* p, size_t bytes, size_t) override
{
mAlloc->deallocate(static_cast<char*>(p), bytes);
}

bool do_is_equal(const std::pmr::memory_resource& other) const noexcept override
{
return this == &other;
}

private:
ExternalAllocator* mAlloc;
};

using ExternalAllocator = o2::itsmft::tracking::ExternalAllocator;
using ExternalAllocatorAdaptor = o2::itsmft::tracking::ExternalAllocatorAdaptor;
} // namespace o2::its

#endif
3 changes: 3 additions & 0 deletions Detectors/ITSMFT/ITS/workflow/src/TrackerSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ void TrackerDPL::init(InitContext& ic)
mTimer.Reset();
o2::base::GRPGeomHelper::instance().setRequest(mGGCCDBRequest);
mChainITS.reset(mRecChain->AddChain<o2::gpu::GPUChainITS>());
if (mRecChain->Init()) {
throw std::runtime_error("GPU reconstruction initialization failed");
}
mITSTrackingInterface.setTraitsFromProvider(mChainITS->GetITSVertexerTraits(),
mChainITS->GetITSTrackerTraits(),
mChainITS->GetITSTimeframe());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \file ExternalAllocator.h
/// \brief
///

#ifndef ALICEO2_ITSMFT_TRACKING_EXTERNALALLOCATOR_H_
#define ALICEO2_ITSMFT_TRACKING_EXTERNALALLOCATOR_H_

#include <cstddef>
#include <cstdint>
#include <memory_resource>
#include <type_traits>
#include "Base/GPUMemoryResource.h"

namespace o2::itsmft::tracking
{

class ExternalAllocator
{
public:
using Type = std::underlying_type_t<o2::gpu::GPUMemoryResource::MemoryType>;
virtual ~ExternalAllocator() = default;
virtual void deallocate(char*, size_t) = 0;
virtual void* allocate(size_t, Type) = 0;
void* allocate(size_t size) { return allocate(size, mType); }

void* allocateDevice(size_t size, bool stack)
{
return allocate(size, o2::gpu::GPUMemoryResource::MEMORY_GPU | (stack ? o2::gpu::GPUMemoryResource::MEMORY_STACK : 0));
}

void* allocateStack(size_t size) { return allocateDevice(size, true); }
virtual void pushTagOnStack(uint64_t) = 0;
virtual void popTagOffStack(uint64_t) = 0;

void setType(Type t) noexcept { mType = t; }
Type getType() const noexcept { return mType; }

protected:
Type mType{o2::gpu::GPUMemoryResource::MEMORY_HOST};
};

class ExternalAllocatorAdaptor final : public std::pmr::memory_resource
{
public:
explicit ExternalAllocatorAdaptor(ExternalAllocator* alloc) : mAlloc(alloc) {}

protected:
void* do_allocate(size_t bytes, size_t alignment) override
{
void* p = mAlloc->allocate(bytes, o2::gpu::GPUMemoryResource::MemoryType::MEMORY_HOST);
if (!p) {
throw std::bad_alloc();
}
return p;
}

void do_deallocate(void* p, size_t bytes, size_t) override
{
mAlloc->deallocate(static_cast<char*>(p), bytes);
}

bool do_is_equal(const std::pmr::memory_resource& other) const noexcept override
{
return this == &other;
}

private:
ExternalAllocator* mAlloc;
};

} // namespace o2::itsmft::tracking

#endif
47 changes: 27 additions & 20 deletions GPU/GPUTracking/Global/GPUChainITS.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,44 @@

#include "GPUChainITS.h"
#include "GPUConstantMem.h"
#include "GPUDefParametersConstants.h"
#include "DataFormatsITS/TrackITS.h"
#include "ITStracking/ExternalAllocator.h"
#include "ITSMFTTracking/ExternalAllocator.h"
#include "GPUReconstructionIncludesITS.h"

using namespace o2::gpu;

namespace o2::its
namespace
{
class GPUFrameworkExternalAllocator final : public o2::its::ExternalAllocator
class GPUFrameworkExternalAllocator final : public o2::itsmft::tracking::ExternalAllocator
{
public:
void* allocate(size_t size) final
explicit GPUFrameworkExternalAllocator(GPUReconstruction* fwr) : mFWReco(fwr) {}
void* allocate(size_t size, Type type) final
{
return mFWReco->AllocateDirectMemory(size, mType);
return mFWReco->AllocateDirectMemory(size, type);
}
void deallocate(char* ptr, size_t size) final {} // this is a simple no-op
void pushTagOnStack(uint64_t tag) final
{
mFWReco->PushNonPersistentMemory(tag);
}
void popTagOffStack(uint64_t tag) final
{
mFWReco->PopNonPersistentMemory(gpudatatypes::RecoStep::ITSTracking, tag);
}
void setReconstructionFramework(o2::gpu::GPUReconstruction* fwr) { mFWReco = fwr; }
void deallocate(char*, size_t) final {}
void pushTagOnStack(uint64_t tag) final { mFWReco->PushNonPersistentMemory(tag); }
void popTagOffStack(uint64_t tag) final { mFWReco->PopNonPersistentMemory(gpudatatypes::RecoStep::ITSTracking, tag); }

private:
o2::gpu::GPUReconstruction* mFWReco;
GPUReconstruction* mFWReco;
};
} // namespace o2::its
} // namespace

GPUChainITS::~GPUChainITS() = default;

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

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

void GPUChainITS::MemorySize(size_t& gpuMem, size_t& pageLockedHostMem)
{
gpuMem = constants::GPU_DEFAULT_MEMORY_SIZE;
pageLockedHostMem = constants::GPU_DEFAULT_HOST_MEMORY_SIZE;
}

o2::its::TrackerTraits<7>* GPUChainITS::GetITSTrackerTraits()
{
if (mITSTrackerTraits == nullptr) {
Expand All @@ -74,14 +75,20 @@ o2::its::TimeFrame<7>* GPUChainITS::GetITSTimeframe()
}
#if !defined(GPUCA_STANDALONE)
if (mITSTimeFrame->isGPU()) {
mFrameworkAllocator.reset(new o2::its::GPUFrameworkExternalAllocator());
mFrameworkAllocator->setReconstructionFramework(rec());
mITSTimeFrame->setFrameworkAllocator(mFrameworkAllocator.get());
mITSTimeFrame->setFrameworkAllocator(GetITSMFTFrameworkAllocator());
}
#endif
return mITSTimeFrame.get();
}

o2::itsmft::tracking::ExternalAllocator* GPUChainITS::GetITSMFTFrameworkAllocator()
{
if (mFrameworkAllocator == nullptr && mRec->IsGPU()) {
mFrameworkAllocator = std::make_unique<GPUFrameworkExternalAllocator>(rec());
}
return mFrameworkAllocator.get();
}

int32_t GPUChainITS::PrepareEvent() { return 0; }

int32_t GPUChainITS::Finalize() { return 0; }
Expand Down
10 changes: 7 additions & 3 deletions GPU/GPUTracking/Global/GPUChainITS.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ namespace o2::its
struct Cluster;
struct TrackingFrameInfo;
class TrackITSExt;
class GPUFrameworkExternalAllocator;
} // namespace o2::its
namespace o2::itsmft::tracking
{
class ExternalAllocator;
} // namespace o2::itsmft::tracking

namespace o2::gpu
{
Expand All @@ -39,15 +42,16 @@ class GPUChainITS final : public GPUChain

void RegisterPermanentMemoryAndProcessors() final {};
void RegisterGPUProcessors() final {};
void MemorySize(size_t&, size_t&) final {};
void MemorySize(size_t& gpuMem, size_t& pageLockedHostMem) final;

o2::its::TrackerTraits<7>* GetITSTrackerTraits();
o2::its::VertexerTraits<7>* GetITSVertexerTraits();
o2::its::TimeFrame<7>* GetITSTimeframe();
o2::itsmft::tracking::ExternalAllocator* GetITSMFTFrameworkAllocator();

protected:
GPUChainITS(GPUReconstruction* rec);
std::unique_ptr<o2::its::GPUFrameworkExternalAllocator> mFrameworkAllocator;
std::unique_ptr<o2::itsmft::tracking::ExternalAllocator> mFrameworkAllocator;
std::unique_ptr<o2::its::TimeFrame<7>> mITSTimeFrame;
std::unique_ptr<o2::its::TrackerTraits<7>> mITSTrackerTraits;
std::unique_ptr<o2::its::VertexerTraits<7>> mITSVertexerTraits;
Expand Down
5 changes: 5 additions & 0 deletions GPU/GPUTracking/Interface/GPUO2Interface.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ void GPUO2Interface::setErrorCodeOutput(std::vector<std::array<uint32_t, 4>>* v)
}
}

o2::itsmft::tracking::ExternalAllocator* GPUO2Interface::GetITSMFTFrameworkAllocator()
{
return mChainITS->GetITSMFTFrameworkAllocator();
}

void GPUO2Interface::GetITSTraits(o2::its::TrackerTraits<7>*& trackerTraits, o2::its::VertexerTraits<7>*& vertexerTraits, o2::its::TimeFrame<7>*& timeFrame)
{
trackerTraits = mChainITS->GetITSTrackerTraits();
Expand Down
5 changes: 5 additions & 0 deletions GPU/GPUTracking/Interface/GPUO2Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class VertexerTraits;
template <int>
class TimeFrame;
} // namespace o2::its
namespace o2::itsmft::tracking
{
class ExternalAllocator;
} // namespace o2::itsmft::tracking

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

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