refactor: split CpuInaccessible MemoryPool types to Device and System

Signed-off-by: Dunajski, Bartosz <bartosz.dunajski@intel.com>
This commit is contained in:
Dunajski, Bartosz
2023-10-12 16:26:32 +00:00
committed by Compute-Runtime-Automation
parent 30b066c40e
commit 2e8cf5fdf5
29 changed files with 396 additions and 81 deletions

View File

@@ -590,7 +590,9 @@ bool DrmMemoryManager::mapPhysicalToVirtualMemory(GraphicsAllocation *physicalAl
}
GraphicsAllocation *DrmMemoryManager::allocatePhysicalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) {
const auto memoryPool = MemoryPool::SystemCpuInaccessible;
auto memoryBanks = static_cast<uint32_t>(allocationData.storageInfo.memoryBanks.to_ulong());
const auto memoryPool = (memoryBanks == 0) ? MemoryPool::SystemCpuInaccessible : MemoryPool::LocalCpuInaccessible;
StorageInfo systemMemoryStorageInfo = {};
auto &productHelper = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHelper<ProductHelper>();
@@ -601,7 +603,7 @@ GraphicsAllocation *DrmMemoryManager::allocatePhysicalDeviceMemory(const Allocat
auto &drm = getDrm(allocationData.rootDeviceIndex);
auto ioctlHelper = drm.getIoctlHelper();
uint32_t handle = ioctlHelper->createGem(bufferSize, static_cast<uint32_t>(allocationData.storageInfo.memoryBanks.to_ulong()));
uint32_t handle = ioctlHelper->createGem(bufferSize, memoryBanks);
auto patIndex = drm.getPatIndex(gmm.get(), allocationData.type, CacheRegion::Default, CachePolicy::WriteBack, false, MemoryPoolHelper::isSystemMemoryPool(memoryPool));
@@ -616,7 +618,9 @@ GraphicsAllocation *DrmMemoryManager::allocatePhysicalDeviceMemory(const Allocat
}
GraphicsAllocation *DrmMemoryManager::allocateMemoryByKMD(const AllocationData &allocationData) {
const auto memoryPool = MemoryPool::SystemCpuInaccessible;
auto memoryBanks = static_cast<uint32_t>(allocationData.storageInfo.memoryBanks.to_ulong());
const auto memoryPool = (memoryBanks == 0) ? MemoryPool::SystemCpuInaccessible : MemoryPool::LocalCpuInaccessible;
auto &productHelper = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHelper<ProductHelper>();
StorageInfo systemMemoryStorageInfo = {};
@@ -628,7 +632,7 @@ GraphicsAllocation *DrmMemoryManager::allocateMemoryByKMD(const AllocationData &
auto &drm = getDrm(allocationData.rootDeviceIndex);
auto ioctlHelper = drm.getIoctlHelper();
uint32_t handle = ioctlHelper->createGem(bufferSize, static_cast<uint32_t>(allocationData.storageInfo.memoryBanks.to_ulong()));
uint32_t handle = ioctlHelper->createGem(bufferSize, memoryBanks);
auto patIndex = drm.getPatIndex(gmm.get(), allocationData.type, CacheRegion::Default, CachePolicy::WriteBack, false, MemoryPoolHelper::isSystemMemoryPool(memoryPool));
@@ -657,13 +661,15 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A
return alloc;
}
auto memoryBanks = static_cast<uint32_t>(allocationData.storageInfo.memoryBanks.to_ulong());
UNRECOVERABLE_IF(allocationData.imgInfo->useLocalMemory);
const auto memoryPool = MemoryPool::SystemCpuInaccessible;
uint64_t gpuRange = acquireGpuRange(allocationData.imgInfo->size, allocationData.rootDeviceIndex, HeapIndex::HEAP_STANDARD);
auto &drm = this->getDrm(allocationData.rootDeviceIndex);
auto ioctlHelper = drm.getIoctlHelper();
uint32_t handle = ioctlHelper->createGem(allocationData.imgInfo->size, static_cast<uint32_t>(allocationData.storageInfo.memoryBanks.to_ulong()));
uint32_t handle = ioctlHelper->createGem(allocationData.imgInfo->size, memoryBanks);
auto patIndex = drm.getPatIndex(gmm.get(), allocationData.type, CacheRegion::Default, CachePolicy::WriteBack, false, MemoryPoolHelper::isSystemMemoryPool(memoryPool));
@@ -969,7 +975,7 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o
bo = findAndReferenceSharedBufferObject(boHandle, properties.rootDeviceIndex);
}
const auto memoryPool = MemoryPool::SystemCpuInaccessible;
const auto memoryPool = isHostIpcAllocation ? MemoryPool::SystemCpuInaccessible : MemoryPool::LocalCpuInaccessible;
if (bo == nullptr) {
size_t size = SysCalls::lseek(handle, 0, SEEK_END);

View File

@@ -111,6 +111,8 @@ bool WddmMemoryManager::mapPhysicalToVirtualMemory(GraphicsAllocation *physicalA
}
GraphicsAllocation *WddmMemoryManager::allocatePhysicalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) {
auto memoryBanks = static_cast<uint32_t>(allocationData.storageInfo.memoryBanks.to_ulong());
const auto memoryPool = (memoryBanks == 0) ? MemoryPool::SystemCpuInaccessible : MemoryPool::LocalCpuInaccessible;
auto &productHelper = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHelper<ProductHelper>();
StorageInfo systemMemoryStorageInfo = {};
@@ -120,7 +122,7 @@ GraphicsAllocation *WddmMemoryManager::allocatePhysicalDeviceMemory(const Alloca
auto allocation = std::make_unique<WddmAllocation>(allocationData.rootDeviceIndex,
1u, // numGmms
allocationData.type, nullptr, 0, allocationData.size, nullptr,
MemoryPool::SystemCpuInaccessible, allocationData.flags.shareable, maxOsContextCount);
memoryPool, allocationData.flags.shareable, maxOsContextCount);
allocation->setDefaultGmm(gmm.get());
if (!createPhysicalAllocation(allocation.get())) {
return nullptr;
@@ -136,6 +138,9 @@ GraphicsAllocation *WddmMemoryManager::allocateMemoryByKMD(const AllocationData
return allocateHugeGraphicsMemory(allocationData, false);
}
auto memoryBanks = static_cast<uint32_t>(allocationData.storageInfo.memoryBanks.to_ulong());
const auto memoryPool = (memoryBanks == 0) ? MemoryPool::SystemCpuInaccessible : MemoryPool::LocalCpuInaccessible;
auto &productHelper = executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getHelper<ProductHelper>();
StorageInfo systemMemoryStorageInfo = {};
systemMemoryStorageInfo.isLockable = allocationData.storageInfo.isLockable;
@@ -144,7 +149,7 @@ GraphicsAllocation *WddmMemoryManager::allocateMemoryByKMD(const AllocationData
auto allocation = std::make_unique<WddmAllocation>(allocationData.rootDeviceIndex,
1u, // numGmms
allocationData.type, nullptr, 0, allocationData.size, nullptr,
MemoryPool::SystemCpuInaccessible, allocationData.flags.shareable, maxOsContextCount);
memoryPool, allocationData.flags.shareable, maxOsContextCount);
allocation->setDefaultGmm(gmm.get());
void *requiredGpuVa = nullptr;
adjustGpuPtrToHostAddressSpace(*allocation.get(), requiredGpuVa);
@@ -158,10 +163,13 @@ GraphicsAllocation *WddmMemoryManager::allocateMemoryByKMD(const AllocationData
}
GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) {
UNRECOVERABLE_IF(allocationData.imgInfo->useLocalMemory);
const auto memoryPool = MemoryPool::SystemCpuInaccessible;
auto allocation = std::make_unique<WddmAllocation>(allocationData.rootDeviceIndex,
1u, // numGmms
allocationData.type, nullptr, 0, allocationData.imgInfo->size,
nullptr, MemoryPool::SystemCpuInaccessible,
nullptr, memoryPool,
0u, // shareable
maxOsContextCount);
allocation->setDefaultGmm(gmm.get());
@@ -549,7 +557,8 @@ bool WddmMemoryManager::isNTHandle(osHandle handle, uint32_t rootDeviceIndex) {
}
GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle, AllocationType allocationType, uint32_t rootDeviceIndex, void *mapPointer) {
auto allocation = std::make_unique<WddmAllocation>(rootDeviceIndex, allocationType, nullptr, 0, handle, MemoryPool::SystemCpuInaccessible, maxOsContextCount, 0llu);
const auto memoryPool = MemoryPool::LocalCpuInaccessible;
auto allocation = std::make_unique<WddmAllocation>(rootDeviceIndex, allocationType, nullptr, 0, handle, memoryPool, maxOsContextCount, 0llu);
bool status = ntHandle ? getWddm(rootDeviceIndex).openNTHandle(reinterpret_cast<HANDLE>(static_cast<uintptr_t>(handle)), allocation.get())
: getWddm(rootDeviceIndex).openSharedHandle(handle, allocation.get());