feature: prepare for l0 usm device pooling

Related-To: NEO-6893

Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
This commit is contained in:
Dominik Dabek
2025-04-25 17:35:55 +00:00
committed by Compute-Runtime-Automation
parent c2266fc69e
commit 75e313ce28
23 changed files with 459 additions and 35 deletions

View File

@@ -274,12 +274,17 @@ ze_result_t ContextImp::allocDeviceMem(ze_device_handle_t hDevice,
unifiedMemoryProperties.allocationFlags.flags.resource48Bit = productHelper.is48bResourceNeededForRayTracing();
}
if (false == lookupTable.exportMemory &&
neoDevice->getUsmMemAllocPoolsManager()) {
neoDevice->getUsmMemAllocPoolsManager()->ensureInitialized(this->driverHandle->svmAllocsManager);
if (auto usmPtrFromPool = neoDevice->getUsmMemAllocPoolsManager()->createUnifiedMemoryAllocation(size, unifiedMemoryProperties)) {
*ptr = usmPtrFromPool;
return ZE_RESULT_SUCCESS;
if (false == lookupTable.exportMemory) {
if (neoDevice->getUsmMemAllocPoolsManager()) {
if (auto usmPtrFromPool = neoDevice->getUsmMemAllocPoolsManager()->createUnifiedMemoryAllocation(size, unifiedMemoryProperties)) {
*ptr = usmPtrFromPool;
return ZE_RESULT_SUCCESS;
}
} else if (neoDevice->getUsmMemAllocPool()) {
if (auto usmPtrFromPool = neoDevice->getUsmMemAllocPool()->createUnifiedMemoryAllocation(size, unifiedMemoryProperties)) {
*ptr = usmPtrFromPool;
return ZE_RESULT_SUCCESS;
}
}
}
@@ -464,6 +469,10 @@ ze_result_t ContextImp::freeMem(const void *ptr, bool blocking) {
blocking)) {
return ZE_RESULT_SUCCESS;
}
} else if (auto deviceUsmPool = allocation->device->getUsmMemAllocPool()) {
if (deviceUsmPool->freeSVMAlloc(ptr, blocking)) {
return ZE_RESULT_SUCCESS;
}
}
}
this->driverHandle->svmAllocsManager->freeSVMAlloc(const_cast<void *>(ptr), blocking);
@@ -487,6 +496,18 @@ ze_result_t ContextImp::freeMemExt(const ze_memory_free_ext_desc_t *pMemFreeDesc
this->freePeerAllocations(ptr, false, Device::fromHandle(pairDevice.second));
}
if (InternalMemoryType::hostUnifiedMemory == allocation->memoryType) {
if (this->driverHandle->usmHostMemAllocPool.freeSVMAlloc(ptr, false)) {
return ZE_RESULT_SUCCESS;
}
} else if (InternalMemoryType::deviceUnifiedMemory == allocation->memoryType) {
if (auto deviceUsmPool = allocation->device->getUsmMemAllocPool()) {
if (deviceUsmPool->freeSVMAlloc(ptr, false)) {
return ZE_RESULT_SUCCESS;
}
}
}
this->driverHandle->svmAllocsManager->freeSVMAllocDefer(const_cast<void *>(ptr));
return ZE_RESULT_SUCCESS;
}
@@ -641,6 +662,11 @@ void ContextImp::setIPCHandleData(NEO::GraphicsAllocation *graphicsAllocation, u
ipcData.poolOffset = poolOffset;
break;
}
} else if (auto deviceUsmMemAllocPool = neoDevice->getUsmMemAllocPool()) {
if (auto poolOffset = deviceUsmMemAllocPool->getOffsetInPool(addrToPtr(ptrAddress))) {
ipcData.poolOffset = poolOffset;
break;
}
}
}
}

View File

@@ -1625,6 +1625,8 @@ void DeviceImp::releaseResources() {
getNEODevice()->getMemoryManager()->freeGraphicsMemory(syncDispatchTokenAllocation);
getNEODevice()->cleanupUsmAllocationPool();
this->bcsSplit.releaseResources();
if (neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]->debugger.get()) {

View File

@@ -300,7 +300,15 @@ ze_result_t DriverHandleImp::initialize(std::vector<std::unique_ptr<NEO::Device>
}
this->svmAllocsManager->initUsmAllocationsCaches(*this->devices[0]->getNEODevice());
this->initHostUsmAllocPool();
for (auto &device : this->devices) {
this->initDeviceUsmAllocPool(*device->getNEODevice());
if (auto deviceUsmAllocPool = device->getNEODevice()->getUsmMemAllocPool()) {
deviceUsmAllocPool->ensureInitialized(this->svmAllocsManager);
}
if (auto deviceUsmAllocPoolsManager = device->getNEODevice()->getUsmMemAllocPoolsManager()) {
deviceUsmAllocPoolsManager->ensureInitialized(this->svmAllocsManager);
}
}
this->numDevices = static_cast<uint32_t>(this->devices.size());
uuidTimestamp = static_cast<uint64_t>(std::chrono::system_clock::now().time_since_epoch().count());
@@ -352,6 +360,23 @@ void DriverHandleImp::initHostUsmAllocPool() {
}
}
void DriverHandleImp::initDeviceUsmAllocPool(NEO::Device &device) {
const uint64_t minServicedSize = 0u;
const uint64_t maxServicedSize = 1 * MemoryConstants::megaByte;
bool enabled = NEO::ApiSpecificConfig::isDeviceUsmPoolingEnabled() && device.getProductHelper().isDeviceUsmPoolAllocatorSupported();
uint64_t poolSize = 2 * MemoryConstants::megaByte;
if (NEO::debugManager.flags.EnableDeviceUsmAllocationPool.get() != -1) {
enabled = NEO::debugManager.flags.EnableDeviceUsmAllocationPool.get() > 0;
poolSize = NEO::debugManager.flags.EnableDeviceUsmAllocationPool.get() * MemoryConstants::megaByte;
}
if (enabled) {
device.resetUsmAllocationPool(new NEO::UsmMemAllocPool(rootDeviceIndices, deviceBitfields, &device, InternalMemoryType::deviceUnifiedMemory,
poolSize, minServicedSize, maxServicedSize));
}
}
ze_result_t DriverHandleImp::getDevice(uint32_t *pCount, ze_device_handle_t *phDevices) {
// If the user has requested FLAT or COMBINED device hierarchy model, then report all the sub devices as devices.

View File

@@ -124,6 +124,7 @@ struct DriverHandleImp : public DriverHandle {
std::map<uint64_t, IpcHandleTracking *> &getIPCHandleMap() { return this->ipcHandles; };
[[nodiscard]] std::unique_lock<std::mutex> lockIPCHandleMap() { return std::unique_lock<std::mutex>(this->ipcHandleMapMutex); };
void initHostUsmAllocPool();
void initDeviceUsmAllocPool(NEO::Device &device);
std::unique_ptr<HostPointerManager> hostPointerManager;

View File

@@ -60,7 +60,7 @@ bool ApiSpecificConfig::isHostAllocationCacheEnabled() {
}
bool ApiSpecificConfig::isDeviceUsmPoolingEnabled() {
return true;
return false;
}
bool ApiSpecificConfig::isHostUsmPoolingEnabled() {