Skip to content

Commit 538e0ae

Browse files
Add debug flag to bind at creation time
Signed-off-by: Lukasz Jobczyk <[email protected]>
1 parent 596fe02 commit 538e0ae

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

opencl/test/unit_test/test_files/igdrcl.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ Force2dImageAsArray = -1
369369
ForceExtendedBufferSize = -1
370370
ForceExtendedUSMBufferSize = -1
371371
MakeIndirectAllocationsResidentAsPack = -1
372+
MakeEachAllocationResident = -1
372373
EnableChipsetUniqueUUID = -1
373374
ForceSimdMessageSizeInWalker = -1
374375
UseNewQueryTopoIoctl = 1

shared/source/command_stream/command_stream_receiver.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,16 @@ void CommandStreamReceiver::makeResident(MultiGraphicsAllocation &gfxAllocation)
115115
void CommandStreamReceiver::makeResident(GraphicsAllocation &gfxAllocation) {
116116
auto submissionTaskCount = this->taskCount + 1;
117117
if (gfxAllocation.isResidencyTaskCountBelow(submissionTaskCount, osContext->getContextId())) {
118-
this->getResidencyAllocations().push_back(&gfxAllocation);
118+
auto pushAllocations = true;
119+
120+
if (DebugManager.flags.MakeEachAllocationResident.get() != -1) {
121+
pushAllocations = !DebugManager.flags.MakeEachAllocationResident.get();
122+
}
123+
124+
if (pushAllocations) {
125+
this->getResidencyAllocations().push_back(&gfxAllocation);
126+
}
127+
119128
checkForNewResources(submissionTaskCount, gfxAllocation.getTaskCount(osContext->getContextId()), gfxAllocation);
120129
gfxAllocation.updateTaskCount(submissionTaskCount, osContext->getContextId());
121130
if (!gfxAllocation.isResident(osContext->getContextId())) {

shared/source/debug_settings/debug_variables_base.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, OverrideKernelSizeLimitForSmallDispatch, -1, "-1
242242
DECLARE_DEBUG_VARIABLE(int32_t, OverrideUseKmdWaitFunction, -1, "-1: default (L0: disabled), 0: disabled, 1: enabled. It uses only busy loop to wait or busy loop with KMD wait function, when KMD fallback is enabled")
243243
DECLARE_DEBUG_VARIABLE(int32_t, ResolveDependenciesViaPipeControls, -1, "-1: default , 0: disabled, 1: enabled. If enabled, instead of programming semaphores, dependencies are resolved using task levels")
244244
DECLARE_DEBUG_VARIABLE(int32_t, MakeIndirectAllocationsResidentAsPack, -1, "-1: default, 0:disabled, 1: enabled. If enabled, driver handles all indirect allocations as one pack instead of making them resident individually.")
245+
DECLARE_DEBUG_VARIABLE(int32_t, MakeEachAllocationResident, -1, "-1: default, 0: disabled, 1: bind every allocation at creation time, 2: bind all created allocations in flush")
245246

246247
/*DIRECT SUBMISSION FLAGS*/
247248
DECLARE_DEBUG_VARIABLE(bool, DirectSubmissionPrintBuffers, false, "Print address of submitted command buffers")

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,15 +1046,28 @@ std::vector<GraphicsAllocation *> &DrmMemoryManager::getLocalMemAllocs(uint32_t
10461046
return this->localMemAllocs[rootDeviceIndex];
10471047
}
10481048

1049+
void DrmMemoryManager::makeAllocationResident(GraphicsAllocation *allocation) {
1050+
if (DebugManager.flags.MakeEachAllocationResident.get() == 1) {
1051+
auto drmAllocation = static_cast<DrmAllocation *>(allocation);
1052+
for (uint32_t i = 0; getDrm(allocation->getRootDeviceIndex()).getVirtualMemoryAddressSpace(i) > 0u; i++) {
1053+
drmAllocation->makeBOsResident(registeredEngines[defaultEngineIndex[allocation->getRootDeviceIndex()]].osContext, i, nullptr, true);
1054+
getDrm(allocation->getRootDeviceIndex()).waitForBind(i);
1055+
}
1056+
}
1057+
}
1058+
10491059
void DrmMemoryManager::registerSysMemAlloc(GraphicsAllocation *allocation) {
1060+
makeAllocationResident(allocation);
10501061
std::lock_guard<std::mutex> lock(this->allocMutex);
10511062
this->sysMemAllocs.push_back(allocation);
10521063
}
10531064

10541065
void DrmMemoryManager::registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex) {
1066+
makeAllocationResident(allocation);
10551067
std::lock_guard<std::mutex> lock(this->allocMutex);
10561068
this->localMemAllocs[rootDeviceIndex].push_back(allocation);
10571069
}
1070+
10581071
void DrmMemoryManager::unregisterAllocation(GraphicsAllocation *allocation) {
10591072
std::lock_guard<std::mutex> lock(this->allocMutex);
10601073
sysMemAllocs.erase(std::remove(sysMemAllocs.begin(), sysMemAllocs.end(), allocation),

shared/source/os_interface/linux/drm_memory_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class DrmMemoryManager : public MemoryManager {
123123
void registerAllocationInOs(GraphicsAllocation *allocation) override;
124124
void waitOnCompletionFence(GraphicsAllocation *allocation);
125125
bool allocationTypeForCompletionFence(AllocationType allocationType);
126+
void makeAllocationResident(GraphicsAllocation *allocation);
126127

127128
Drm &getDrm(uint32_t rootDeviceIndex) const;
128129
uint32_t getRootDeviceIndex(const Drm *drm);

shared/source/os_interface/linux/drm_memory_operations_handler_bind.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,15 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::isResident(Device *device
104104
}
105105

106106
MemoryOperationsStatus DrmMemoryOperationsHandlerBind::mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) {
107-
MemoryOperationsStatus retVal = this->makeResidentWithinOsContext(osContext, ArrayRef<GraphicsAllocation *>(residencyContainer), true);
107+
if (DebugManager.flags.MakeEachAllocationResident.get() == 2) {
108+
auto memoryManager = static_cast<DrmMemoryManager *>(this->rootDeviceEnvironment.executionEnvironment.memoryManager.get());
109+
110+
auto allocLock = memoryManager->acquireAllocLock();
111+
this->makeResidentWithinOsContext(osContext, ArrayRef<GraphicsAllocation *>(memoryManager->getSysMemAllocs()), true);
112+
this->makeResidentWithinOsContext(osContext, ArrayRef<GraphicsAllocation *>(memoryManager->getLocalMemAllocs(this->rootDeviceIndex)), true);
113+
}
114+
115+
auto retVal = this->makeResidentWithinOsContext(osContext, ArrayRef<GraphicsAllocation *>(residencyContainer), true);
108116
if (retVal != MemoryOperationsStatus::SUCCESS) {
109117
return retVal;
110118
}

0 commit comments

Comments
 (0)