Remove debug flag ForceResourceLockOnTransferCalls

Unlock locked resoures in freeGraphicsMemory method

Change-Id: I2baae7b7f9d8260f19a4b083849c5bf0d1a764f3
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski 2019-01-24 15:16:12 +01:00 committed by sys_ocldev
parent 82046c25d2
commit 128bf4552f
13 changed files with 66 additions and 49 deletions

View File

@ -54,11 +54,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueReadBuffer(
TransferProperties transferProperties(buffer, CL_COMMAND_READ_BUFFER, 0, true, &offset, &size, ptr);
EventsRequest eventsRequest(numEventsInWaitList, eventWaitList, event);
cpuDataTransferHandler(transferProperties, eventsRequest, retVal);
if (DebugManager.flags.ForceResourceLockOnTransferCalls.get()) {
if (transferProperties.lockedPtr != nullptr) {
buffer->getMemoryManager()->unlockResource(buffer->getGraphicsAllocation());
}
}
return retVal;
}
MultiDispatchInfo dispatchInfo;

View File

@ -52,12 +52,6 @@ cl_int CommandQueueHw<GfxFamily>::enqueueWriteBuffer(
TransferProperties transferProperties(buffer, CL_COMMAND_WRITE_BUFFER, 0, true, &offset, &size, const_cast<void *>(ptr));
EventsRequest eventsRequest(numEventsInWaitList, eventWaitList, event);
cpuDataTransferHandler(transferProperties, eventsRequest, retVal);
if (DebugManager.flags.ForceResourceLockOnTransferCalls.get()) {
if (transferProperties.lockedPtr != nullptr) {
buffer->getMemoryManager()->unlockResource(buffer->getGraphicsAllocation());
}
}
return retVal;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Intel Corporation
* Copyright (C) 2018-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -21,10 +21,8 @@ TransferProperties::TransferProperties(MemObj *memObj, cl_command_type cmdType,
if (memObj->peekClMemObjType() == CL_MEM_OBJECT_BUFFER) {
size[0] = *sizePtr;
offset[0] = *offsetPtr;
if (DebugManager.flags.ForceResourceLockOnTransferCalls.get()) {
if ((false == MemoryPool::isSystemMemoryPool(memObj->getGraphicsAllocation()->getMemoryPool())) && (memObj->getMemoryManager() != nullptr)) {
this->lockedPtr = memObj->getMemoryManager()->lockResource(memObj->getGraphicsAllocation());
}
if ((false == MemoryPool::isSystemMemoryPool(memObj->getGraphicsAllocation()->getMemoryPool())) && (memObj->getMemoryManager() != nullptr)) {
this->lockedPtr = memObj->getMemoryManager()->lockResource(memObj->getGraphicsAllocation());
}
} else {
size = {{sizePtr[0], sizePtr[1], sizePtr[2]}};

View File

@ -110,9 +110,10 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
void setEvictable(bool evictable) { this->evictable = evictable; }
bool peekEvictable() const { return evictable; }
bool isResident(uint32_t contextId) const { return GraphicsAllocation::objectNotResident != getResidencyTaskCount(contextId); }
void setLocked(bool locked) { this->locked = locked; }
bool isLocked() const { return locked; }
void lock(void *ptr) { this->lockedPtr = ptr; }
void unlock() { this->lockedPtr = nullptr; }
bool isLocked() const { return lockedPtr != nullptr; }
void *getLockedPtr() const { return lockedPtr; }
void incReuseCount() { reuseCount++; }
void decReuseCount() { reuseCount--; }
@ -128,6 +129,7 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
uint32_t getInspectionId(uint32_t contextId) { return usageInfos[contextId].inspectionId; }
void setInspectionId(uint32_t newInspectionId, uint32_t contextId) { usageInfos[contextId].inspectionId = newInspectionId; }
bool isResident(uint32_t contextId) const { return GraphicsAllocation::objectNotResident != getResidencyTaskCount(contextId); }
void updateResidencyTaskCount(uint32_t newTaskCount, uint32_t contextId) { usageInfos[contextId].residencyTaskCount = newTaskCount; }
uint32_t getResidencyTaskCount(uint32_t contextId) const { return usageInfos[contextId].residencyTaskCount; }
void releaseResidencyInOsContext(uint32_t contextId) { updateResidencyTaskCount(objectNotResident, contextId); }
@ -155,7 +157,7 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
uint64_t gpuAddress = 0;
bool coherent = false;
osHandle sharedHandle = Sharing::nonSharedResource;
bool locked = false;
void *lockedPtr = nullptr;
uint32_t reuseCount = 0; // GraphicsAllocation can be reused by shared resources
bool evictable = true;
MemoryPool::Type memoryPool = MemoryPool::MemoryNull;

View File

@ -137,6 +137,9 @@ void MemoryManager::freeGraphicsMemory(GraphicsAllocation *gfxAllocation) {
if (!gfxAllocation) {
return;
}
if (gfxAllocation->isLocked()) {
unlockResource(gfxAllocation);
}
freeGraphicsMemoryImpl(gfxAllocation);
}
//if not in use destroy in place
@ -353,9 +356,11 @@ void *MemoryManager::lockResource(GraphicsAllocation *graphicsAllocation) {
if (!graphicsAllocation) {
return nullptr;
}
DEBUG_BREAK_IF(graphicsAllocation->isLocked());
if (graphicsAllocation->isLocked()) {
return graphicsAllocation->getLockedPtr();
}
auto retVal = lockResourceImpl(*graphicsAllocation);
graphicsAllocation->setLocked(true);
graphicsAllocation->lock(retVal);
return retVal;
}
@ -365,6 +370,6 @@ void MemoryManager::unlockResource(GraphicsAllocation *graphicsAllocation) {
}
DEBUG_BREAK_IF(!graphicsAllocation->isLocked());
unlockResourceImpl(*graphicsAllocation);
graphicsAllocation->setLocked(false);
graphicsAllocation->unlock();
}
} // namespace OCLRT

View File

@ -76,7 +76,6 @@ DECLARE_DEBUG_VARIABLE(bool, UseNewHeapAllocator, true, "Custom 4GB heap allocat
DECLARE_DEBUG_VARIABLE(bool, UseNoRingFlushesKmdMode, true, "Windows only, passes flag to KMD that informs KMD to not emit any ring buffer flushes.")
DECLARE_DEBUG_VARIABLE(bool, DisableZeroCopyForUseHostPtr, false, "When active all buffer allocations created with CL_MEM_USE_HOST_PTR flag will not share memory with CPU.")
DECLARE_DEBUG_VARIABLE(bool, DisableZeroCopyForBuffers, false, "When active all buffer allocations will not share memory with CPU.")
DECLARE_DEBUG_VARIABLE(bool, ForceResourceLockOnTransferCalls, false, "Forces resource locking on memory transfer calls")
DECLARE_DEBUG_VARIABLE(bool, EnableHostPtrTracking, true, "Enable host ptr tracking")
/*FEATURE FLAGS*/

View File

@ -329,9 +329,6 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation
allocationHandles = &input->handle;
allocationCount = 1;
}
if (input->isLocked()) {
unlockResource(input);
}
auto status = tryDeferDeletions(allocationHandles, allocationCount, resourceHandle);
DEBUG_BREAK_IF(!status);
alignedFreeWrapper(input->driverAllocatedCpuPointer);

View File

@ -454,9 +454,8 @@ HWTEST_F(EnqueueReadBufferTypeTest, givenCommandQueueWhenEnqueueReadBufferIsCall
EXPECT_TRUE(mockCmdQ->notifyEnqueueReadBufferCalled);
}
HWTEST_F(EnqueueReadBufferTypeTest, givenEnqueueReadBufferCalledWhenLockedPtrInTransferPropertisIsAvailableThenItIsUnlocked) {
HWTEST_F(EnqueueReadBufferTypeTest, givenEnqueueReadBufferCalledWhenLockedPtrInTransferPropertisIsAvailableThenItIsNotUnlocked) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.ForceResourceLockOnTransferCalls.set(true);
DebugManager.flags.DoCpuCopyOnReadBuffer.set(true);
ExecutionEnvironment executionEnvironment;
@ -479,12 +478,11 @@ HWTEST_F(EnqueueReadBufferTypeTest, givenEnqueueReadBufferCalledWhenLockedPtrInT
nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(1u, memoryManager.unlockResourceCalled);
EXPECT_EQ(0u, memoryManager.unlockResourceCalled);
}
HWTEST_F(EnqueueReadBufferTypeTest, gicenEnqueueReadBufferCalledWhenLockedPtrInTransferPropertisIsNotAvailableThenItIsNotUnlocked) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.ForceResourceLockOnTransferCalls.set(true);
DebugManager.flags.DoCpuCopyOnReadBuffer.set(true);
ExecutionEnvironment executionEnvironment;

View File

@ -363,9 +363,8 @@ HWTEST_F(EnqueueWriteBufferTypeTest, givenInOrderQueueAndEnabledSupportCpuCopies
EXPECT_EQ(pCmdQ->taskLevel, 1u);
}
HWTEST_F(EnqueueWriteBufferTypeTest, givenEnqueueWriteBufferCalledWhenLockedPtrInTransferPropertisIsAvailableThenItIsUnlocked) {
HWTEST_F(EnqueueWriteBufferTypeTest, givenEnqueueWriteBufferCalledWhenLockedPtrInTransferPropertisIsAvailableThenItIsNotUnlocked) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.ForceResourceLockOnTransferCalls.set(true);
DebugManager.flags.DoCpuCopyOnWriteBuffer.set(true);
ExecutionEnvironment executionEnvironment;
@ -388,12 +387,11 @@ HWTEST_F(EnqueueWriteBufferTypeTest, givenEnqueueWriteBufferCalledWhenLockedPtrI
nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(1u, memoryManager.unlockResourceCalled);
EXPECT_EQ(0u, memoryManager.unlockResourceCalled);
}
HWTEST_F(EnqueueWriteBufferTypeTest, givenEnqueueWriteBufferCalledWhenLockedPtrInTransferPropertisIsNotAvailableThenItIsNotUnlocked) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.ForceResourceLockOnTransferCalls.set(true);
DebugManager.flags.DoCpuCopyOnWriteBuffer.set(true);
ExecutionEnvironment executionEnvironment;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Intel Corporation
* Copyright (C) 2018-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -21,9 +21,7 @@ TEST(TransferPropertiesTest, givenTransferPropertiesCreatedWhenDefaultDebugSetti
EXPECT_EQ(nullptr, transferProperties.lockedPtr);
}
TEST(TransferPropertiesTest, givenTransferPropertiesCreatedWhenForceResourceLockOnTransferCallsSetThenLockPtrIsSet) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.ForceResourceLockOnTransferCalls.set(true);
TEST(TransferPropertiesTest, givenAllocationInNonSystemPoolWhenTransferPropertiesAreCreatedForMapBufferThenLockPtrIsSet) {
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, true, executionEnvironment);
@ -40,9 +38,7 @@ TEST(TransferPropertiesTest, givenTransferPropertiesCreatedWhenForceResourceLock
EXPECT_NE(nullptr, transferProperties.lockedPtr);
}
TEST(TransferPropertiesTest, givenTransferPropertiesCreatedWhenForceResourceLockOnTransferCallsSetAndMemoryPoolIsSystemMemoryThenLockPtrIsNotSet) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.ForceResourceLockOnTransferCalls.set(true);
TEST(TransferPropertiesTest, givenAllocationInSystemPoolWhenTransferPropertiesAreCreatedForMapBufferThenLockPtrIsNotSet) {
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, true, executionEnvironment);
@ -59,10 +55,7 @@ TEST(TransferPropertiesTest, givenTransferPropertiesCreatedWhenForceResourceLock
EXPECT_EQ(nullptr, transferProperties.lockedPtr);
}
TEST(TransferPropertiesTest, givenTransferPropertiesCreatedWhenForceResourceLockOnTransferCallsSetAndMemoryManagerInMemObjectIsNotSetThenLockPtrIsNotSet) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.ForceResourceLockOnTransferCalls.set(true);
TEST(TransferPropertiesTest, givenTransferPropertiesCreatedWhenMemoryManagerInMemObjectIsNotSetThenLockPtrIsNotSet) {
MockBuffer buffer;
size_t offset = 0;
@ -72,8 +65,6 @@ TEST(TransferPropertiesTest, givenTransferPropertiesCreatedWhenForceResourceLock
}
TEST(TransferPropertiesTest, givenTransferPropertiesWhenLockedPtrIsSetThenItIsReturnedForReadWrite) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.ForceResourceLockOnTransferCalls.set(true);
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, true, executionEnvironment);

View File

@ -1572,3 +1572,38 @@ TEST(ResidencyDataTest, givenResidencyDataWhenUpdateCompletionDataIsCalledThenIt
EXPECT_EQ(lastFenceValue3, residency.lastFenceValues[1]);
EXPECT_EQ(lastFenceValue3, residency.getFenceValueForContextId(osContext2.getContextId()));
}
TEST(MemoryManagerTest, givenMemoryManagerWhenLockIsCalledOnLockedResourceThenDoesNothing) {
ExecutionEnvironment executionEnvironment;
MockMemoryManager memoryManager(false, false, executionEnvironment);
auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
EXPECT_FALSE(allocation->isLocked());
auto ptr = memoryManager.MemoryManager::lockResource(allocation);
EXPECT_TRUE(allocation->isLocked());
EXPECT_EQ(1u, memoryManager.lockResourceCalled);
EXPECT_EQ(0u, memoryManager.unlockResourceCalled);
auto ptr2 = memoryManager.MemoryManager::lockResource(allocation);
EXPECT_TRUE(allocation->isLocked());
EXPECT_EQ(1u, memoryManager.lockResourceCalled);
EXPECT_EQ(0u, memoryManager.unlockResourceCalled);
EXPECT_EQ(ptr, ptr2);
memoryManager.freeGraphicsMemory(allocation);
}
TEST(MemoryManagerTest, givenMemoryManagerWhenAllocationWasNotUnlockedThenItIsUnlockedDuringDestruction) {
ExecutionEnvironment executionEnvironment;
MockMemoryManager memoryManager(false, false, executionEnvironment);
auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
EXPECT_FALSE(allocation->isLocked());
memoryManager.MemoryManager::lockResource(allocation);
EXPECT_TRUE(allocation->isLocked());
EXPECT_EQ(1u, memoryManager.lockResourceCalled);
EXPECT_EQ(0u, memoryManager.unlockResourceCalled);
memoryManager.freeGraphicsMemory(allocation);
EXPECT_EQ(1u, memoryManager.unlockResourceCalled);
}

View File

@ -55,6 +55,11 @@ class MockMemoryManager : public OsAgnosticMemoryManager {
OsAgnosticMemoryManager::freeGraphicsMemoryImpl(gfxAllocation);
};
void *lockResourceImpl(GraphicsAllocation &gfxAllocation) override {
lockResourceCalled++;
return OsAgnosticMemoryManager::lockResourceImpl(gfxAllocation);
}
void unlockResourceImpl(GraphicsAllocation &gfxAllocation) override {
unlockResourceCalled++;
OsAgnosticMemoryManager::unlockResourceImpl(gfxAllocation);
@ -62,6 +67,7 @@ class MockMemoryManager : public OsAgnosticMemoryManager {
uint32_t freeGraphicsMemoryCalled = 0u;
uint32_t unlockResourceCalled = 0u;
uint32_t lockResourceCalled = 0u;
bool allocationCreated = false;
bool allocation64kbPageCreated = false;
bool allocationInDevicePoolCreated = false;

View File

@ -98,7 +98,6 @@ AubDumpOverrideMmioRegister = 0
AubDumpOverrideMmioRegisterValue = 0
PowerSavingMode = 0
AubDumpAddMmioRegistersList = unk
ForceResourceLockOnTransferCalls = 0
RenderCompressedImagesEnabled = -1
RenderCompressedBuffersEnabled = -1
AUBDumpForceAllToLocalMemory = 0