mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-24 21:18:24 +08:00
feature: atomic attributes for shared system alloc
Related-To: NEO-13715, NEO-14862 Signed-off-by: Chandio, Bibrak Qamar <bibrak.qamar.chandio@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
cb4fa456b7
commit
c1867ed981
@@ -294,7 +294,7 @@ bool DrmMemoryManager::setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdvise
|
||||
return drmAllocation->setMemAdvise(&this->getDrm(rootDeviceIndex), flags);
|
||||
}
|
||||
|
||||
bool DrmMemoryManager::setSharedSystemMemAdvise(const void *ptr, const size_t size, MemAdvise memAdviseOp, uint32_t rootDeviceIndex) {
|
||||
bool DrmMemoryManager::setSharedSystemMemAdvise(const void *ptr, const size_t size, MemAdvise memAdviseOp, SubDeviceIdsVec &subDeviceIds, uint32_t rootDeviceIndex) {
|
||||
|
||||
auto &drm = this->getDrm(rootDeviceIndex);
|
||||
auto ioctlHelper = drm.getIoctlHelper();
|
||||
@@ -321,27 +321,43 @@ bool DrmMemoryManager::setSharedSystemMemAdvise(const void *ptr, const size_t si
|
||||
attribute = ioctlHelper->getPreferredLocationAdvise();
|
||||
param = (static_cast<uint64_t>(-1) << 32) | static_cast<uint64_t>(ioctlHelper->getDrmParamValue(DrmParam::memoryClassDevice));
|
||||
break;
|
||||
case MemAdvise::setAtomicDevice:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
// Apply the shared system USM IOCTL to all the VMs of the device
|
||||
std::vector<uint32_t> vmIds;
|
||||
vmIds.reserve(subDeviceIds.size());
|
||||
for (auto subDeviceId : subDeviceIds) {
|
||||
vmIds.push_back(drm.getVirtualMemoryAddressSpace(subDeviceId));
|
||||
}
|
||||
|
||||
auto result = ioctlHelper->setVmSharedSystemMemAdvise(reinterpret_cast<uint64_t>(ptr), size, attribute, param, vmIds);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DrmMemoryManager::setSharedSystemAtomicAccess(const void *ptr, const size_t size, AtomicAccessMode mode, SubDeviceIdsVec &subDeviceIds, uint32_t rootDeviceIndex) {
|
||||
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 MemAdvise::clearAtomicDevice:
|
||||
attribute = ioctlHelper->getAtomicAdvise(false);
|
||||
param = (static_cast<uint64_t>(ioctlHelper->getDrmParamValue(DrmParam::atomicClassUndefined)) << 32);
|
||||
break;
|
||||
case MemAdvise::setAtomicGlobal:
|
||||
case AtomicAccessMode::system:
|
||||
attribute = ioctlHelper->getAtomicAdvise(false);
|
||||
param = (static_cast<uint64_t>(ioctlHelper->getDrmParamValue(DrmParam::atomicClassGlobal)) << 32);
|
||||
break;
|
||||
case MemAdvise::clearAtomicGlobal:
|
||||
attribute = ioctlHelper->getAtomicAdvise(false);
|
||||
param = (static_cast<uint64_t>(ioctlHelper->getDrmParamValue(DrmParam::atomicClassUndefined)) << 32);
|
||||
break;
|
||||
case MemAdvise::setAtomicCpu:
|
||||
case AtomicAccessMode::host:
|
||||
attribute = ioctlHelper->getAtomicAdvise(false);
|
||||
param = (static_cast<uint64_t>(ioctlHelper->getDrmParamValue(DrmParam::atomicClassSystem)) << 32);
|
||||
break;
|
||||
case MemAdvise::clearAtomicCpu:
|
||||
case AtomicAccessMode::none:
|
||||
attribute = ioctlHelper->getAtomicAdvise(false);
|
||||
param = (static_cast<uint64_t>(ioctlHelper->getDrmParamValue(DrmParam::atomicClassUndefined)) << 32);
|
||||
break;
|
||||
@@ -349,11 +365,14 @@ bool DrmMemoryManager::setSharedSystemMemAdvise(const void *ptr, const size_t si
|
||||
return false;
|
||||
}
|
||||
|
||||
// Single vm_id for shared system allocation
|
||||
uint32_t vmHandleId = 0;
|
||||
auto vmId = drm.getVirtualMemoryAddressSpace(vmHandleId);
|
||||
// Apply the shared system USM IOCTL to all the VMs of the device
|
||||
std::vector<uint32_t> vmIds;
|
||||
vmIds.reserve(subDeviceIds.size());
|
||||
for (auto subDeviceId : subDeviceIds) {
|
||||
vmIds.push_back(drm.getVirtualMemoryAddressSpace(subDeviceId));
|
||||
}
|
||||
|
||||
auto result = ioctlHelper->setVmSharedSystemMemAdvise(reinterpret_cast<uint64_t>(ptr), size, attribute, param, vmId);
|
||||
auto result = ioctlHelper->setVmSharedSystemMemAdvise(reinterpret_cast<uint64_t>(ptr), size, attribute, param, vmIds);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -87,10 +87,11 @@ class DrmMemoryManager : public MemoryManager {
|
||||
bool isKmdMigrationAvailable(uint32_t rootDeviceIndex) override;
|
||||
|
||||
bool setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags, uint32_t rootDeviceIndex) override;
|
||||
bool setSharedSystemMemAdvise(const void *ptr, const size_t size, MemAdvise memAdviseOp, uint32_t rootDeviceIndex) override;
|
||||
bool setSharedSystemMemAdvise(const void *ptr, const size_t size, MemAdvise memAdviseOp, SubDeviceIdsVec &subDeviceIds, uint32_t rootDeviceIndex) override;
|
||||
bool setMemPrefetch(GraphicsAllocation *gfxAllocation, SubDeviceIdsVec &subDeviceIds, uint32_t rootDeviceIndex) override;
|
||||
bool prefetchSharedSystemAlloc(const void *ptr, const size_t size, SubDeviceIdsVec &subDeviceIds, uint32_t rootDeviceIndex) override;
|
||||
bool setAtomicAccess(GraphicsAllocation *gfxAllocation, size_t size, AtomicAccessMode mode, uint32_t rootDeviceIndex) override;
|
||||
bool setSharedSystemAtomicAccess(const void *ptr, const size_t size, AtomicAccessMode mode, SubDeviceIdsVec &subDeviceIds, uint32_t rootDeviceIndex) override;
|
||||
[[nodiscard]] std::unique_lock<std::mutex> acquireAllocLock();
|
||||
std::vector<GraphicsAllocation *> &getSysMemAllocs();
|
||||
std::vector<GraphicsAllocation *> &getLocalMemAllocs(uint32_t rootDeviceIndex);
|
||||
|
||||
@@ -130,7 +130,7 @@ class IoctlHelper {
|
||||
virtual uint32_t getPreferredLocationAdvise() = 0;
|
||||
virtual std::optional<MemoryClassInstance> getPreferredLocationRegion(PreferredLocation memoryLocation, uint32_t memoryInstance) = 0;
|
||||
virtual bool setVmBoAdvise(int32_t handle, uint32_t attribute, void *region) = 0;
|
||||
virtual bool setVmSharedSystemMemAdvise(uint64_t handle, const size_t size, const uint32_t attribute, const uint64_t param, const uint32_t vmId) { return true; }
|
||||
virtual bool setVmSharedSystemMemAdvise(uint64_t handle, const size_t size, const uint32_t attribute, const uint64_t param, const std::vector<uint32_t> &vmIds) { return true; }
|
||||
virtual bool setVmBoAdviseForChunking(int32_t handle, uint64_t start, uint64_t length, uint32_t attribute, void *region) = 0;
|
||||
virtual bool setVmPrefetch(uint64_t start, uint64_t length, uint32_t region, uint32_t vmId) = 0;
|
||||
virtual bool setGemTiling(void *setTiling) = 0;
|
||||
|
||||
@@ -848,8 +848,20 @@ bool IoctlHelperXe::setVmBoAdvise(int32_t handle, uint32_t attribute, void *regi
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IoctlHelperXe::setVmSharedSystemMemAdvise(uint64_t handle, const size_t size, const uint32_t attribute, const uint64_t param, const uint32_t vmId) {
|
||||
xeLog(" -> IoctlHelperXe::%s h=0x%llx s=0x%llx vmid=0x%x\n", __FUNCTION__, handle, size, vmId);
|
||||
bool IoctlHelperXe::setVmSharedSystemMemAdvise(uint64_t handle, const size_t size, const uint32_t attribute, const uint64_t param, const std::vector<uint32_t> &vmIds) {
|
||||
std::string vmIdsStr = "[";
|
||||
for (size_t i = 0; i < vmIds.size(); ++i) {
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << std::hex << vmIds[i];
|
||||
vmIdsStr += "0x" + ss.str();
|
||||
}
|
||||
if (i != vmIds.size() - 1) {
|
||||
vmIdsStr += ", ";
|
||||
}
|
||||
}
|
||||
vmIdsStr += "]";
|
||||
xeLog(" -> IoctlHelperXe::%s h=0x%x s=0x%lx vmids=%s\n", __FUNCTION__, handle, size, vmIdsStr.c_str());
|
||||
// There is no vmAdvise attribute in Xe, so return success
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class IoctlHelperXe : public IoctlHelper {
|
||||
uint32_t getPreferredLocationAdvise() override;
|
||||
std::optional<MemoryClassInstance> getPreferredLocationRegion(PreferredLocation memoryLocation, uint32_t memoryInstance) override;
|
||||
bool setVmBoAdvise(int32_t handle, uint32_t attribute, void *region) override;
|
||||
bool setVmSharedSystemMemAdvise(uint64_t handle, const size_t size, const uint32_t attribute, const uint64_t param, const uint32_t vmId) override;
|
||||
bool setVmSharedSystemMemAdvise(uint64_t handle, const size_t size, const uint32_t attribute, const uint64_t param, const std::vector<uint32_t> &vmIds) override;
|
||||
bool setVmBoAdviseForChunking(int32_t handle, uint64_t start, uint64_t length, uint32_t attribute, void *region) override;
|
||||
bool setVmPrefetch(uint64_t start, uint64_t length, uint32_t region, uint32_t vmId) override;
|
||||
bool setGemTiling(void *setTiling) override;
|
||||
|
||||
Reference in New Issue
Block a user