feature: add pooling of USM global/constant surface

Related-To: NEO-12287
Signed-off-by: Fabian Zwoliński <fabian.zwolinski@intel.com>
This commit is contained in:
Fabian Zwoliński
2025-09-19 14:53:48 +00:00
committed by Compute-Runtime-Automation
parent 0b6b0e3954
commit a1c5fa1a13
15 changed files with 635 additions and 42 deletions

View File

@@ -124,21 +124,8 @@ Program::~Program() {
}
for (const auto &buildInfo : buildInfos) {
if (auto &constantSurface = buildInfo.constantSurface; constantSurface) {
if ((nullptr != context) && (nullptr != context->getSVMAllocsManager()) && (context->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast<const void *>(constantSurface->getGpuAddress())))) {
context->getSVMAllocsManager()->freeSVMAlloc(reinterpret_cast<void *>(constantSurface->getGpuAddress()));
} else {
this->executionEnvironment.memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(constantSurface->getGraphicsAllocation());
}
}
if (auto &globalSurface = buildInfo.globalSurface; globalSurface) {
if ((nullptr != context) && (nullptr != context->getSVMAllocsManager()) && (context->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast<const void *>(globalSurface->getGpuAddress())))) {
context->getSVMAllocsManager()->freeSVMAlloc(reinterpret_cast<void *>(globalSurface->getGpuAddress()));
} else {
this->executionEnvironment.memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(globalSurface->getGraphicsAllocation());
}
}
freeGlobalBufferAllocation(buildInfo.constantSurface);
freeGlobalBufferAllocation(buildInfo.globalSurface);
}
notifyModuleDestroy();
@@ -148,6 +135,41 @@ Program::~Program() {
}
}
void Program::freeGlobalBufferAllocation(const std::unique_ptr<NEO::SharedPoolAllocation> &globalBuffer) {
if (!globalBuffer) {
return;
}
auto graphicsAllocation = globalBuffer->getGraphicsAllocation();
if (!graphicsAllocation) {
return;
}
auto gpuAddress = reinterpret_cast<void *>(globalBuffer->getGpuAddress());
for (const auto &device : clDevices) {
if (auto usmPool = device->getDevice().getUsmConstantSurfaceAllocPool();
usmPool && usmPool->isInPool(gpuAddress)) {
[[maybe_unused]] auto ret = usmPool->freeSVMAlloc(gpuAddress, false);
DEBUG_BREAK_IF(!ret);
return;
}
if (auto usmPool = device->getDevice().getUsmGlobalSurfaceAllocPool();
usmPool && usmPool->isInPool(gpuAddress)) {
[[maybe_unused]] auto ret = usmPool->freeSVMAlloc(gpuAddress, false);
DEBUG_BREAK_IF(!ret);
return;
}
}
if ((nullptr != context) && (nullptr != context->getSVMAllocsManager()) && (context->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast<const void *>(globalBuffer->getGpuAddress())))) {
context->getSVMAllocsManager()->freeSVMAlloc(reinterpret_cast<void *>(globalBuffer->getGpuAddress()));
} else {
this->executionEnvironment.memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(globalBuffer->getGraphicsAllocation());
}
}
cl_int Program::createProgramFromBinary(
const void *pBinary,
size_t binarySize, ClDevice &clDevice) {