mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-09 22:43:00 +08:00
[1/n] Improve indirect allocations handling.
Add new functions that would treat all indirect allocations as single pack. Signed-off-by: Michal Mrozek <michal.mrozek@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
22bbce42dd
commit
52d636394c
@@ -332,6 +332,8 @@ void SVMAllocsManager::removeSVMAlloc(const SvmAllocationData &svmAllocData) {
|
||||
bool SVMAllocsManager::freeSVMAlloc(void *ptr, bool blocking) {
|
||||
SvmAllocationData *svmData = getSVMAlloc(ptr);
|
||||
if (svmData) {
|
||||
this->prepareIndirectAllocationForDestruction(svmData);
|
||||
|
||||
if (blocking) {
|
||||
if (svmData->cpuAllocation) {
|
||||
this->memoryManager->waitForEnginesCompletion(*svmData->cpuAllocation);
|
||||
@@ -485,6 +487,53 @@ bool SVMAllocsManager::hasHostAllocations() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void SVMAllocsManager::makeIndirectAllocationsResident(CommandStreamReceiver &commandStreamReceiver, uint32_t taskCount) {
|
||||
std::unique_lock<SpinLock> lock(mtx);
|
||||
bool parseAllAllocations = false;
|
||||
auto entry = indirectAllocationsResidency.find(&commandStreamReceiver);
|
||||
|
||||
if (entry == indirectAllocationsResidency.end()) {
|
||||
parseAllAllocations = true;
|
||||
|
||||
InternalAllocationsTracker tracker = {};
|
||||
tracker.latestResidentObjectId = this->allocationsCounter;
|
||||
tracker.latestSentTaskCount = taskCount;
|
||||
|
||||
this->indirectAllocationsResidency.insert(std::make_pair(&commandStreamReceiver, tracker));
|
||||
} else {
|
||||
if (this->allocationsCounter > entry->second.latestResidentObjectId) {
|
||||
parseAllAllocations = true;
|
||||
|
||||
entry->second.latestResidentObjectId = this->allocationsCounter;
|
||||
}
|
||||
entry->second.latestSentTaskCount = taskCount;
|
||||
}
|
||||
if (parseAllAllocations) {
|
||||
for (auto &allocation : this->SVMAllocs.allocations) {
|
||||
auto gpuAllocation = allocation.second.gpuAllocations.getGraphicsAllocation(commandStreamReceiver.getRootDeviceIndex());
|
||||
UNRECOVERABLE_IF(nullptr == gpuAllocation);
|
||||
commandStreamReceiver.makeResident(*gpuAllocation);
|
||||
gpuAllocation->updateResidencyTaskCount(GraphicsAllocation::objectAlwaysResident, commandStreamReceiver.getOsContext().getContextId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SVMAllocsManager::prepareIndirectAllocationForDestruction(SvmAllocationData *allocationData) {
|
||||
std::unique_lock<SpinLock> lock(mtx);
|
||||
if (this->indirectAllocationsResidency.size() > 0u) {
|
||||
for (auto &internalAllocationsHandling : this->indirectAllocationsResidency) {
|
||||
auto commandStreamReceiver = internalAllocationsHandling.first;
|
||||
auto gpuAllocation = allocationData->gpuAllocations.getGraphicsAllocation(commandStreamReceiver->getRootDeviceIndex());
|
||||
auto desiredTaskCount = std::max(internalAllocationsHandling.second.latestSentTaskCount, gpuAllocation->getTaskCount(commandStreamReceiver->getOsContext().getContextId()));
|
||||
if (gpuAllocation->getResidencyTaskCount(commandStreamReceiver->getOsContext().getContextId()) == GraphicsAllocation::objectAlwaysResident) {
|
||||
gpuAllocation->updateResidencyTaskCount(GraphicsAllocation::objectNotResident, commandStreamReceiver->getOsContext().getContextId());
|
||||
gpuAllocation->updateResidencyTaskCount(desiredTaskCount, commandStreamReceiver->getOsContext().getContextId());
|
||||
gpuAllocation->updateTaskCount(desiredTaskCount, commandStreamReceiver->getOsContext().getContextId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SvmMapOperation *SVMAllocsManager::getSvmMapOperation(const void *ptr) {
|
||||
std::unique_lock<SpinLock> lock(mtx);
|
||||
return svmMapOperations.get(ptr);
|
||||
|
||||
@@ -100,6 +100,11 @@ class SVMAllocsManager {
|
||||
bool readOnly = false;
|
||||
};
|
||||
|
||||
struct InternalAllocationsTracker {
|
||||
uint32_t latestSentTaskCount = 0lu;
|
||||
uint32_t latestResidentObjectId = 0lu;
|
||||
};
|
||||
|
||||
struct UnifiedMemoryProperties {
|
||||
UnifiedMemoryProperties(InternalMemoryType memoryType,
|
||||
const std::set<uint32_t> &rootDeviceIndices,
|
||||
@@ -149,6 +154,10 @@ class SVMAllocsManager {
|
||||
void freeSvmAllocationWithDeviceStorage(SvmAllocationData *svmData);
|
||||
bool hasHostAllocations();
|
||||
std::atomic<uint32_t> allocationsCounter = 0;
|
||||
void makeIndirectAllocationsResident(CommandStreamReceiver &commandStreamReceiver, uint32_t taskCount);
|
||||
void prepareIndirectAllocationForDestruction(SvmAllocationData *);
|
||||
|
||||
std::map<CommandStreamReceiver *, InternalAllocationsTracker> indirectAllocationsResidency;
|
||||
|
||||
protected:
|
||||
void *createZeroCopySvmAllocation(size_t size, const SvmAllocationProperties &svmProperties,
|
||||
|
||||
Reference in New Issue
Block a user