mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-25 05:24:02 +08:00
Allocate per-context memory with specific GPU VA
Related-To: NEO-4829 Change-Id: I821f6709bfa98df3b51a1c966b7a953752d85f74 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
1f63f39d77
commit
fea4472553
@@ -254,6 +254,35 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithHostPtr(const Allocat
|
||||
return res;
|
||||
}
|
||||
|
||||
GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryWithGpuVa(const AllocationData &allocationData) {
|
||||
auto osContextLinux = static_cast<OsContextLinux *>(allocationData.osContext);
|
||||
|
||||
const size_t minAlignment = MemoryConstants::allocationAlignment;
|
||||
size_t alignedSize = alignUp(allocationData.size, minAlignment);
|
||||
|
||||
auto res = alignedMallocWrapper(alignedSize, minAlignment);
|
||||
if (!res)
|
||||
return nullptr;
|
||||
|
||||
BufferObject *bo = allocUserptr(reinterpret_cast<uintptr_t>(res), alignedSize, 0, allocationData.rootDeviceIndex);
|
||||
if (!bo) {
|
||||
alignedFreeWrapper(res);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UNRECOVERABLE_IF(allocationData.gpuAddress == 0);
|
||||
bo->gpuAddress = allocationData.gpuAddress;
|
||||
|
||||
if (forcePinEnabled && pinBBs.at(allocationData.rootDeviceIndex) != nullptr && alignedSize >= this->pinThreshold) {
|
||||
pinBBs.at(allocationData.rootDeviceIndex)->pin(&bo, 1, osContextLinux->getContextId());
|
||||
}
|
||||
|
||||
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo, res, bo->gpuAddress, alignedSize, MemoryPool::System4KBPages);
|
||||
allocation->setDriverAllocatedCpuPtr(res);
|
||||
|
||||
return allocation;
|
||||
}
|
||||
|
||||
DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) {
|
||||
if (allocationData.size == 0 || !allocationData.hostPtr)
|
||||
return nullptr;
|
||||
@@ -762,4 +791,13 @@ uint32_t DrmMemoryManager::getRootDeviceIndex(const Drm *drm) {
|
||||
return CommonConstants::unspecifiedDeviceIndex;
|
||||
}
|
||||
|
||||
AddressRange DrmMemoryManager::reserveGpuAddress(size_t size, uint32_t rootDeviceIndex) {
|
||||
auto gpuVa = acquireGpuRange(size, false, rootDeviceIndex, false);
|
||||
return AddressRange{gpuVa, size};
|
||||
}
|
||||
|
||||
void DrmMemoryManager::freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) {
|
||||
releaseGpuRange(reinterpret_cast<void *>(addressRange.address), addressRange.size, rootDeviceIndex);
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -55,6 +55,8 @@ class DrmMemoryManager : public MemoryManager {
|
||||
bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, size_t sizeToCopy) override;
|
||||
|
||||
int obtainFdFromHandle(int boHandle, uint32_t rootDeviceindex);
|
||||
AddressRange reserveGpuAddress(size_t size, uint32_t rootDeviceIndex) override;
|
||||
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override;
|
||||
|
||||
protected:
|
||||
BufferObject *findAndReferenceSharedBufferObject(int boHandle);
|
||||
@@ -75,6 +77,7 @@ class DrmMemoryManager : public MemoryManager {
|
||||
DrmAllocation *allocateGraphicsMemory64kb(const AllocationData &allocationData) override;
|
||||
GraphicsAllocation *allocateShareableMemory(const AllocationData &allocationData) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryWithGpuVa(const AllocationData &allocationData) override;
|
||||
|
||||
void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
||||
void *lockResourceInLocalMemoryImpl(GraphicsAllocation &graphicsAllocation);
|
||||
|
||||
Reference in New Issue
Block a user