Async deleter: move releasing cpu/gpu pointers to main thread

Change-Id: I3c3c9fb6200c38ecf1fc8910380531d6a5f1e875
This commit is contained in:
Mateusz Jablonski
2018-01-12 12:10:26 +01:00
committed by sys_ocldev
parent 7640201585
commit 502e9c2d15
6 changed files with 15 additions and 32 deletions

View File

@@ -21,7 +21,6 @@
*/
#include "runtime/os_interface/windows/wddm.h"
#include "runtime/helpers/aligned_memory.h"
#include "runtime/os_interface/windows/deferrable_deletion_win.h"
namespace OCLRT {
@@ -31,10 +30,10 @@ DeferrableDeletion *DeferrableDeletion::create(Args... args) {
return new DeferrableDeletionImpl(std::forward<Args>(args)...);
}
template DeferrableDeletion *DeferrableDeletion::create(Wddm *wddm, D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue,
D3DKMT_HANDLE resourceHandle, void *cpuPtr, void *gpuPtr);
D3DKMT_HANDLE resourceHandle);
DeferrableDeletionImpl::DeferrableDeletionImpl(Wddm *wddm, D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue,
D3DKMT_HANDLE resourceHandle, void *cpuPtr, void *gpuPtr) {
D3DKMT_HANDLE resourceHandle) {
this->wddm = wddm;
if (handles) {
this->handles = new D3DKMT_HANDLE[allocationCount];
@@ -45,16 +44,10 @@ DeferrableDeletionImpl::DeferrableDeletionImpl(Wddm *wddm, D3DKMT_HANDLE *handle
this->allocationCount = allocationCount;
this->lastFenceValue = lastFenceValue;
this->resourceHandle = resourceHandle;
this->cpuPtr = cpuPtr;
this->gpuPtr = gpuPtr;
}
void DeferrableDeletionImpl::apply() {
bool destroyStatus = wddm->destroyAllocations(handles, allocationCount, lastFenceValue, resourceHandle);
DEBUG_BREAK_IF(!destroyStatus);
::alignedFree(cpuPtr);
cpuPtr = nullptr;
wddm->releaseGpuPtr(gpuPtr);
gpuPtr = nullptr;
}
DeferrableDeletionImpl::~DeferrableDeletionImpl() {
if (handles) {

View File

@@ -30,7 +30,7 @@ class Wddm;
class DeferrableDeletionImpl : public DeferrableDeletion {
public:
DeferrableDeletionImpl(Wddm *wddm, D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue,
D3DKMT_HANDLE resourceHandle, void *cpuPtr, void *gpuPtr);
D3DKMT_HANDLE resourceHandle);
void apply() override;
~DeferrableDeletionImpl();
@@ -40,7 +40,5 @@ class DeferrableDeletionImpl : public DeferrableDeletion {
uint32_t allocationCount;
uint64_t lastFenceValue;
D3DKMT_HANDLE resourceHandle;
void *cpuPtr;
void *gpuPtr;
};
} // namespace OCLRT

View File

@@ -301,20 +301,20 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation
unlockResource(input);
input->setLocked(false);
}
status = tryDeferDeletions(allocationHandles, allocationCount, input->getResidencyData().lastFence, resourceHandle, cpuPtr, gpuPtr);
status = tryDeferDeletions(allocationHandles, allocationCount, input->getResidencyData().lastFence, resourceHandle);
DEBUG_BREAK_IF(!status);
::alignedFree(cpuPtr);
wddm->releaseGpuPtr(gpuPtr);
}
delete gfxAllocation;
}
bool WddmMemoryManager::tryDeferDeletions(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle, void *cpuPtr, void *gpuPtr) {
bool WddmMemoryManager::tryDeferDeletions(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle) {
bool status = true;
if (deferredDeleter) {
deferredDeleter->deferDeletion(DeferrableDeletion::create(wddm, handles, allocationCount, lastFenceValue, resourceHandle, cpuPtr, gpuPtr));
deferredDeleter->deferDeletion(DeferrableDeletion::create(wddm, handles, allocationCount, lastFenceValue, resourceHandle));
} else {
status = wddm->destroyAllocations(handles, allocationCount, lastFenceValue, resourceHandle);
::alignedFree(cpuPtr);
wddm->releaseGpuPtr(gpuPtr);
}
return status;
}
@@ -359,7 +359,7 @@ void WddmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage) {
}
}
bool success = tryDeferDeletions(handles, allocationCount, lastFenceValue, 0, nullptr, nullptr);
bool success = tryDeferDeletions(handles, allocationCount, lastFenceValue, 0);
for (unsigned int i = 0; i < max_fragments_count; i++) {
if (handleStorage.fragmentStorageData[i].freeTheFragment) {

View File

@@ -79,7 +79,7 @@ class WddmMemoryManager : public MemoryManager {
residencyLock = false;
}
bool tryDeferDeletions(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle, void *cpuPtr, void *gpuPtr);
bool tryDeferDeletions(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle);
bool isMemoryBudgetExhausted() const override { return memoryBudgetExhausted; }