Allocate and consume shared heaps atomically

Related-To: NEO-5055

Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
This commit is contained in:
Zbigniew Zdanowicz
2023-02-02 18:57:24 +00:00
committed by Compute-Runtime-Automation
parent ee6eb70f1a
commit f2be0ebfc4
11 changed files with 437 additions and 57 deletions

View File

@@ -331,28 +331,51 @@ IndirectHeap *CommandContainer::getIndirectHeap(HeapType heapType) {
}
}
IndirectHeap *CommandContainer::getCsrAlignedSize(HeapType heapType, size_t size, size_t alignment) {
void *ptr = immediateCmdListCsr->getIndirectHeapCurrentPtr(heapType);
size_t totalSize = size + ptrDiff(alignUp(ptr, alignment), ptr);
IndirectHeap *CommandContainer::initIndirectHeapReservation(ReservedIndirectHeap *indirectHeapReservation, size_t size, size_t alignment, HeapType heapType) {
void *currentHeap = immediateCmdListCsr->getIndirectHeapCurrentPtr(heapType);
auto totalRequiredSize = size + ptrDiff(alignUp(currentHeap, alignment), currentHeap);
auto baseHeap = &immediateCmdListCsr->getIndirectHeap(heapType, totalSize);
auto baseHeap = &immediateCmdListCsr->getIndirectHeap(heapType, totalRequiredSize);
auto usedSize = baseHeap->getUsed();
void *heapCpuBase = baseHeap->getCpuBase();
auto consumedSize = usedSize + totalRequiredSize;
baseHeap->getSpace(totalRequiredSize);
indirectHeapReservation->replaceGraphicsAllocation(baseHeap->getGraphicsAllocation());
indirectHeapReservation->replaceBuffer(heapCpuBase, consumedSize);
indirectHeapReservation->getSpace(usedSize);
indirectHeapReservation->setHeapSizeInPages(baseHeap->getHeapSizeInPages());
return baseHeap;
}
void CommandContainer::ensureHeapSizePrepared(size_t sshRequiredSize, size_t sshDefaultAlignment, size_t dshRequiredSize, size_t dshDefaultAlignment, bool getDsh) {
void CommandContainer::reserveSpaceForDispatch(HeapReserveArguments &sshReserveArg, HeapReserveArguments &dshReserveArg, bool getDsh) {
size_t sshAlignment = sshReserveArg.alignment;
size_t dshAlignment = dshReserveArg.alignment;
if (sshReserveArg.size == 0) {
sshAlignment = 1;
}
if (dshReserveArg.size == 0) {
dshAlignment = 1;
}
if (immediateCmdListCsr) {
auto lock = immediateCmdListCsr->obtainUniqueOwnership();
sharedSshCsrHeap = getCsrAlignedSize(HeapType::SURFACE_STATE, sshRequiredSize, sshDefaultAlignment);
sharedSshCsrHeap = this->initIndirectHeapReservation(sshReserveArg.indirectHeapReservation, sshReserveArg.size, sshAlignment, HeapType::SURFACE_STATE);
if (getDsh) {
sharedDshCsrHeap = getCsrAlignedSize(HeapType::DYNAMIC_STATE, dshRequiredSize, dshDefaultAlignment);
sharedDshCsrHeap = this->initIndirectHeapReservation(dshReserveArg.indirectHeapReservation, dshReserveArg.size, dshAlignment, HeapType::DYNAMIC_STATE);
}
} else {
this->getHeapWithRequiredSizeAndAlignment(HeapType::SURFACE_STATE, sshRequiredSize, sshDefaultAlignment);
this->getHeapWithRequiredSizeAndAlignment(HeapType::SURFACE_STATE, sshReserveArg.size, sshAlignment);
if (getDsh) {
this->getHeapWithRequiredSizeAndAlignment(HeapType::DYNAMIC_STATE, dshRequiredSize, dshDefaultAlignment);
this->getHeapWithRequiredSizeAndAlignment(HeapType::DYNAMIC_STATE, dshReserveArg.size, dshAlignment);
}
// private heaps can be accessed directly
sshReserveArg.indirectHeapReservation = nullptr;
dshReserveArg.indirectHeapReservation = nullptr;
}
}
@@ -455,4 +478,12 @@ void CommandContainer::storeAllocationAndFlushTagUpdate(GraphicsAllocation *allo
this->immediateCmdListCsr->flushTagUpdate();
}
HeapReserveData::HeapReserveData() {
object = std::make_unique<NEO::ReservedIndirectHeap>(nullptr, false);
indirectHeapReservation = object.get();
}
HeapReserveData::~HeapReserveData() {
}
} // namespace NEO

View File

@@ -16,13 +16,14 @@
#include <vector>
namespace NEO {
class HeapHelper;
class AllocationsList;
class CommandStreamReceiver;
class Device;
class GraphicsAllocation;
class LinearStream;
class AllocationsList;
class HeapHelper;
class IndirectHeap;
class LinearStream;
class ReservedIndirectHeap;
using ResidencyContainer = std::vector<GraphicsAllocation *>;
using CmdBufferContainer = std::vector<GraphicsAllocation *>;
@@ -39,6 +40,21 @@ inline constexpr auto minCommandQueueCommandStreamSize = 2 * MemoryConstants::ca
inline constexpr auto csOverfetchSize = MemoryConstants::pageSize;
} // namespace CSRequirements
struct HeapReserveData {
HeapReserveData();
virtual ~HeapReserveData();
ReservedIndirectHeap *indirectHeapReservation = nullptr;
protected:
std::unique_ptr<ReservedIndirectHeap> object;
};
struct HeapReserveArguments {
ReservedIndirectHeap *indirectHeapReservation = nullptr;
size_t size = 0;
size_t alignment = 0;
};
class CommandContainer : public NonCopyableOrMovableClass {
public:
enum class ErrorCode {
@@ -119,7 +135,8 @@ class CommandContainer : public NonCopyableOrMovableClass {
bool immediateCmdListSharedHeap(HeapType heapType) {
return (heapSharingEnabled && (heapType == HeapType::DYNAMIC_STATE || heapType == HeapType::SURFACE_STATE));
}
void ensureHeapSizePrepared(size_t sshRequiredSize, size_t sshDefaultAlignment, size_t dshRequiredSize, size_t dshDefaultAlignment, bool getDsh);
void reserveSpaceForDispatch(HeapReserveArguments &sshReserveArg, HeapReserveArguments &dshReserveArg, bool getDsh);
GraphicsAllocation *reuseExistingCmdBuffer();
GraphicsAllocation *allocateCommandBuffer();
@@ -129,6 +146,13 @@ class CommandContainer : public NonCopyableOrMovableClass {
void fillReusableAllocationLists();
void storeAllocationAndFlushTagUpdate(GraphicsAllocation *allocation);
HeapReserveData &getSurfaceStateHeapReserve() {
return surfaceStateHeapReserveData;
}
HeapReserveData &getDynamicStateHeapReserve() {
return dynamicStateHeapReserveData;
}
HeapContainer sshAllocations;
uint64_t currentLinearStreamStartOffset = 0u;
uint32_t slmSize = std::numeric_limits<uint32_t>::max();
@@ -141,9 +165,11 @@ class CommandContainer : public NonCopyableOrMovableClass {
size_t getTotalCmdBufferSize();
IndirectHeap *getHeapWithRequiredSize(HeapType heapType, size_t sizeRequired, size_t alignment, bool allowGrow);
void createAndAssignNewHeap(HeapType heapType, size_t size);
IndirectHeap *getCsrAlignedSize(HeapType heapType, size_t size, size_t alignment);
IndirectHeap *initIndirectHeapReservation(ReservedIndirectHeap *indirectHeapReservation, size_t size, size_t alignment, HeapType heapType);
GraphicsAllocation *allocationIndirectHeaps[HeapType::NUM_TYPES] = {};
std::unique_ptr<IndirectHeap> indirectHeaps[HeapType::NUM_TYPES];
HeapReserveData dynamicStateHeapReserveData;
HeapReserveData surfaceStateHeapReserveData;
CmdBufferContainer cmdBufferAllocations;
ResidencyContainer residencyContainer;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2022 Intel Corporation
* Copyright (C) 2019-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -30,7 +30,7 @@ class IndirectHeap : public LinearStream {
public:
using Type = IndirectHeapType;
IndirectHeap(void *graphicsAllocation, size_t bufferSize) : BaseClass(graphicsAllocation, bufferSize){};
IndirectHeap(void *buffer, size_t bufferSize) : BaseClass(buffer, bufferSize){};
IndirectHeap(GraphicsAllocation *graphicsAllocation) : BaseClass(graphicsAllocation) {}
IndirectHeap(GraphicsAllocation *graphicsAllocation, bool canBeUtilizedAs4GbHeap)
: BaseClass(graphicsAllocation), canBeUtilizedAs4GbHeap(canBeUtilizedAs4GbHeap) {}
@@ -42,7 +42,7 @@ class IndirectHeap : public LinearStream {
void align(size_t alignment);
uint64_t getHeapGpuStartOffset() const;
uint64_t getHeapGpuBase() const;
uint32_t getHeapSizeInPages() const;
virtual uint32_t getHeapSizeInPages() const;
protected:
bool canBeUtilizedAs4GbHeap = false;
@@ -76,4 +76,27 @@ inline uint64_t IndirectHeap::getHeapGpuBase() const {
return this->graphicsAllocation->getGpuAddress();
}
}
class ReservedIndirectHeap : public IndirectHeap {
public:
ReservedIndirectHeap(void *buffer, size_t bufferSize) : IndirectHeap(buffer, bufferSize) {}
ReservedIndirectHeap(GraphicsAllocation *graphicsAllocation) : IndirectHeap(graphicsAllocation) {}
ReservedIndirectHeap(GraphicsAllocation *graphicsAllocation, bool canBeUtilizedAs4GbHeap)
: IndirectHeap(graphicsAllocation, canBeUtilizedAs4GbHeap) {}
// Disallow copy'ing
ReservedIndirectHeap(const ReservedIndirectHeap &) = delete;
ReservedIndirectHeap &operator=(const ReservedIndirectHeap &) = delete;
uint32_t getHeapSizeInPages() const override {
return parentHeapSizeInPages;
}
void setHeapSizeInPages(uint32_t value) {
parentHeapSizeInPages = value;
}
protected:
uint32_t parentHeapSizeInPages = 0;
};
} // namespace NEO