Move createDrmAllocation to common file

Related-To: NEO-6149

Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:
Szymon Morek
2021-09-14 11:29:11 +00:00
committed by Compute-Runtime-Automation
parent 8b16874e5f
commit 1301f77e17
4 changed files with 66 additions and 30 deletions

View File

@@ -1316,4 +1316,35 @@ BufferObject *DrmMemoryManager::createBufferObjectInMemoryRegion(Drm *drm,
return bo;
}
bool DrmMemoryManager::createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddress, size_t maxOsContextCount) {
std::array<std::unique_ptr<BufferObject>, EngineLimits::maxHandleCount> bos{};
auto &storageInfo = allocation->storageInfo;
auto boAddress = gpuAddress;
auto currentBank = 0u;
for (auto handleId = 0u; handleId < storageInfo.getNumBanks(); handleId++, currentBank++) {
uint32_t memoryBanks = static_cast<uint32_t>(storageInfo.memoryBanks.to_ulong());
if (storageInfo.getNumBanks() > 1) {
//check if we have this bank, if not move to next one
//we may have holes in memoryBanks that we need to skip i.e. memoryBanks 1101 and 3 handle allocation
while (!(memoryBanks & (1u << currentBank))) {
currentBank++;
}
memoryBanks &= 1u << currentBank;
}
auto boSize = alignUp(allocation->getGmm(handleId)->gmmResourceInfo->getSizeAllocation(), MemoryConstants::pageSize64k);
bos[handleId] = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(drm, boAddress, boSize, memoryBanks, maxOsContextCount));
if (nullptr == bos[handleId]) {
return false;
}
allocation->getBufferObjectToModify(currentBank) = bos[handleId].get();
if (storageInfo.multiStorage) {
boAddress += boSize;
}
}
for (auto &bo : bos) {
bo.release();
}
return true;
}
} // namespace NEO

View File

@@ -9,9 +9,6 @@
#include "shared/source/os_interface/linux/drm_memory_manager.h"
namespace NEO {
bool DrmMemoryManager::createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddress, size_t maxOsContextCount) {
return false;
}
DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool hasMappedPtr) {
drm_prime_handle openFd = {0, 0, 0};

View File

@@ -112,31 +112,6 @@ DrmAllocation *DrmMemoryManager::createAllocWithAlignment(const AllocationData &
}
}
bool DrmMemoryManager::createDrmAllocation(Drm *drm, DrmAllocation *allocation, uint64_t gpuAddress, size_t maxOsContextCount) {
std::array<std::unique_ptr<BufferObject>, EngineLimits::maxHandleCount> bos{};
auto &storageInfo = allocation->storageInfo;
auto boAddress = gpuAddress;
for (auto handleId = 0u; handleId < storageInfo.getNumBanks(); handleId++) {
uint32_t memoryBanks = 1u;
if (storageInfo.getNumBanks() > 1) {
memoryBanks &= 1u << handleId;
}
auto boSize = alignUp(allocation->getGmm(handleId)->gmmResourceInfo->getSizeAllocation(), MemoryConstants::pageSize64k);
bos[handleId] = std::unique_ptr<BufferObject>(createBufferObjectInMemoryRegion(drm, boAddress, boSize, memoryBanks, maxOsContextCount));
if (nullptr == bos[handleId]) {
return false;
}
allocation->getBufferObjectToModify(handleId) = bos[handleId].get();
if (storageInfo.multiStorage) {
boAddress += boSize;
}
}
for (auto &bo : bos) {
bo.release();
}
return true;
}
void *DrmMemoryManager::lockResourceInLocalMemoryImpl(BufferObject *bo) {
if (bo == nullptr)
return nullptr;