feature: Complete madvise for System Allocator

Related-To: NEO-13715

Provides implmentation of getAtomicAccessAttribute using system
allocator.
Completes the implementation of the madvise feature using the
new IOCTLs in xe_drm header.

Signed-off-by: Chandio, Bibrak Qamar <bibrak.qamar.chandio@intel.com>
This commit is contained in:
Chandio, Bibrak Qamar
2025-09-16 22:57:54 +00:00
committed by Compute-Runtime-Automation
parent 95130b7256
commit cf21cbc910
22 changed files with 920 additions and 133 deletions

View File

@@ -299,31 +299,8 @@ bool DrmMemoryManager::setSharedSystemMemAdvise(const void *ptr, const size_t si
auto &drm = this->getDrm(rootDeviceIndex);
auto ioctlHelper = drm.getIoctlHelper();
uint32_t attribute = 0;
uint64_t param = 0;
switch (memAdviseOp) {
case MemAdvise::setPreferredLocation:
attribute = ioctlHelper->getPreferredLocationAdvise();
param = (static_cast<uint64_t>(-1) << 32) //-1 as currently not supported and ignored. This will be useful in multi device settings.
| static_cast<uint64_t>(ioctlHelper->getDrmParamValue(DrmParam::memoryClassDevice));
break;
case MemAdvise::clearPreferredLocation:
// Assumes that the default location is VRAM, i.e. 1 == DrmParam::memoryClassDevice
attribute = ioctlHelper->getPreferredLocationAdvise();
param = (static_cast<uint64_t>(-1) << 32) | static_cast<uint64_t>(ioctlHelper->getDrmParamValue(DrmParam::memoryClassDevice));
break;
case MemAdvise::setSystemMemoryPreferredLocation:
attribute = ioctlHelper->getPreferredLocationAdvise();
param = (static_cast<uint64_t>(-1) << 32) | static_cast<uint64_t>(ioctlHelper->getDrmParamValue(DrmParam::memoryClassSystem));
break;
case MemAdvise::clearSystemMemoryPreferredLocation:
attribute = ioctlHelper->getPreferredLocationAdvise();
param = (static_cast<uint64_t>(-1) << 32) | static_cast<uint64_t>(ioctlHelper->getDrmParamValue(DrmParam::memoryClassDevice));
break;
default:
return false;
}
uint32_t attribute = ioctlHelper->getPreferredLocationAdvise();
uint64_t param = ioctlHelper->getPreferredLocationArgs(memAdviseOp);
// Apply the shared system USM IOCTL to all the VMs of the device
std::vector<uint32_t> vmIds;
@@ -341,29 +318,8 @@ bool DrmMemoryManager::setSharedSystemAtomicAccess(const void *ptr, const size_t
auto &drm = this->getDrm(rootDeviceIndex);
auto ioctlHelper = drm.getIoctlHelper();
uint32_t attribute = 0;
uint64_t param = 0;
switch (mode) {
case AtomicAccessMode::device:
attribute = ioctlHelper->getAtomicAdvise(false);
param = (static_cast<uint64_t>(ioctlHelper->getDrmParamValue(DrmParam::atomicClassDevice)) << 32);
break;
case AtomicAccessMode::system:
attribute = ioctlHelper->getAtomicAdvise(false);
param = (static_cast<uint64_t>(ioctlHelper->getDrmParamValue(DrmParam::atomicClassGlobal)) << 32);
break;
case AtomicAccessMode::host:
attribute = ioctlHelper->getAtomicAdvise(false);
param = (static_cast<uint64_t>(ioctlHelper->getDrmParamValue(DrmParam::atomicClassSystem)) << 32);
break;
case AtomicAccessMode::none:
attribute = ioctlHelper->getAtomicAdvise(false);
param = (static_cast<uint64_t>(ioctlHelper->getDrmParamValue(DrmParam::atomicClassUndefined)) << 32);
break;
default:
return false;
}
uint32_t attribute = ioctlHelper->getAtomicAdvise(false);
uint64_t param = static_cast<uint64_t>(ioctlHelper->getAtomicAccess(mode));
// Apply the shared system USM IOCTL to all the VMs of the device
std::vector<uint32_t> vmIds;
@@ -377,6 +333,18 @@ bool DrmMemoryManager::setSharedSystemAtomicAccess(const void *ptr, const size_t
return result;
}
AtomicAccessMode DrmMemoryManager::getSharedSystemAtomicAccess(const void *ptr, const size_t size, SubDeviceIdsVec &subDeviceIds, uint32_t rootDeviceIndex) {
auto &drm = this->getDrm(rootDeviceIndex);
auto ioctlHelper = drm.getIoctlHelper();
// Only get the atomic attributes from a single VM since they are replicated in all.
uint32_t vmId = drm.getVirtualMemoryAddressSpace(subDeviceIds[0]);
auto result = ioctlHelper->getVmSharedSystemAtomicAttribute(reinterpret_cast<uint64_t>(ptr), size, vmId);
return result;
}
bool DrmMemoryManager::setAtomicAccess(GraphicsAllocation *gfxAllocation, size_t size, AtomicAccessMode mode, uint32_t rootDeviceIndex) {
auto drmAllocation = static_cast<DrmAllocation *>(gfxAllocation);