mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
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:
committed by
Compute-Runtime-Automation
parent
ca2b26e87b
commit
68698c9a74
@@ -218,11 +218,25 @@ cl_int Program::processGenBinary(const ClDevice &clDevice) {
|
||||
auto &buildInfo = buildInfos[rootDeviceIndex];
|
||||
|
||||
if (buildInfo.constantSurface) {
|
||||
clDevice.getMemoryManager()->freeGraphicsMemory(buildInfo.constantSurface->getGraphicsAllocation());
|
||||
auto gpuAddress = reinterpret_cast<void *>(buildInfo.constantSurface->getGpuAddress());
|
||||
if (auto usmPool = clDevice.getDevice().getUsmConstantSurfaceAllocPool();
|
||||
usmPool && usmPool->isInPool(gpuAddress)) {
|
||||
[[maybe_unused]] auto ret = usmPool->freeSVMAlloc(gpuAddress, false);
|
||||
DEBUG_BREAK_IF(!ret);
|
||||
} else {
|
||||
clDevice.getMemoryManager()->freeGraphicsMemory(buildInfo.constantSurface->getGraphicsAllocation());
|
||||
}
|
||||
buildInfo.constantSurface.reset();
|
||||
}
|
||||
if (buildInfo.globalSurface) {
|
||||
clDevice.getMemoryManager()->freeGraphicsMemory(buildInfo.globalSurface->getGraphicsAllocation());
|
||||
auto gpuAddress = reinterpret_cast<void *>(buildInfo.globalSurface->getGpuAddress());
|
||||
if (auto usmPool = clDevice.getDevice().getUsmGlobalSurfaceAllocPool();
|
||||
usmPool && usmPool->isInPool(gpuAddress)) {
|
||||
[[maybe_unused]] auto ret = usmPool->freeSVMAlloc(gpuAddress, false);
|
||||
DEBUG_BREAK_IF(!ret);
|
||||
} else {
|
||||
clDevice.getMemoryManager()->freeGraphicsMemory(buildInfo.globalSurface->getGraphicsAllocation());
|
||||
}
|
||||
buildInfo.globalSurface.reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -188,6 +188,8 @@ class Program : public BaseObject<_cl_program> {
|
||||
return isSpirV;
|
||||
}
|
||||
|
||||
void freeGlobalBufferAllocation(const std::unique_ptr<NEO::SharedPoolAllocation> &buffer);
|
||||
|
||||
NEO::SharedPoolAllocation *getConstantSurface(uint32_t rootDeviceIndex) const;
|
||||
NEO::GraphicsAllocation *getConstantSurfaceGA(uint32_t rootDeviceIndex) const;
|
||||
NEO::SharedPoolAllocation *getGlobalSurface(uint32_t rootDeviceIndex) const;
|
||||
|
||||
Reference in New Issue
Block a user