Skip to content

Commit c4e802f

Browse files
jchodorCompute-Runtime-Automation
authored andcommitted
WSL - fixing resource cleanup on process shutdown
Resolves issues with coexistance of NEO L0 and NEO OCL libraries within a single process running in WSL and using WDDM GPU PV Signed-off-by: Jaroslaw Chodor <jaroslaw.chodor@intel.com>
1 parent c77fe0b commit c4e802f

File tree

13 files changed

+120
-26
lines changed

13 files changed

+120
-26
lines changed

opencl/test/unit_test/os_interface/linux/drm_tests.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,3 +875,11 @@ TEST(DrmQueryTest, GivenRpsMaxFreqFileDoesntExistWhenFrequencyIsQueriedThenFallb
875875

876876
EXPECT_EQ(expectedMaxFrequency, maxFrequency);
877877
}
878+
879+
TEST(DrmTest, whenCheckedIfResourcesCleanupCanBeSkippedThenReturnsFalse) {
880+
auto executionEnvironment = std::make_unique<ExecutionEnvironment>();
881+
executionEnvironment->prepareRootDeviceEnvironments(1);
882+
DrmMock *pDrm = new DrmMock(*executionEnvironment->rootDeviceEnvironments[0]);
883+
EXPECT_FALSE(pDrm->skipResourceCleanup());
884+
delete pDrm;
885+
}

shared/source/command_stream/command_stream_receiver.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,15 @@ bool CommandStreamReceiver::isRcs() const {
211211
return this->osContext->getEngineType() == aub_stream::ENGINE_RCS;
212212
}
213213

214+
bool CommandStreamReceiver::skipResourceCleanup() const {
215+
return this->getOSInterface() && this->getOSInterface()->getDriverModel() && this->getOSInterface()->getDriverModel()->skipResourceCleanup();
216+
}
217+
214218
void CommandStreamReceiver::cleanupResources() {
219+
if (this->skipResourceCleanup()) {
220+
return;
221+
}
222+
215223
waitForTaskCountAndCleanAllocationList(this->latestFlushedTaskCount, TEMPORARY_ALLOCATION);
216224
waitForTaskCountAndCleanAllocationList(this->latestFlushedTaskCount, REUSABLE_ALLOCATION);
217225

shared/source/command_stream/command_stream_receiver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ class CommandStreamReceiver {
288288
return activePartitions;
289289
}
290290

291+
bool skipResourceCleanup() const;
292+
291293
std::unique_ptr<GmmPageTableMngr> pageTableManager;
292294

293295
protected:

shared/source/device/device.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ Device::Device(ExecutionEnvironment *executionEnvironment)
3636
}
3737

3838
Device::~Device() {
39-
getMemoryManager()->freeGraphicsMemory(rtMemoryBackedBuffer);
40-
rtMemoryBackedBuffer = nullptr;
39+
if (false == commandStreamReceivers.empty()) {
40+
if (commandStreamReceivers[0]->skipResourceCleanup()) {
41+
return;
42+
}
43+
}
4144

4245
DEBUG_BREAK_IF(nullptr == executionEnvironment->memoryManager.get());
46+
getMemoryManager()->freeGraphicsMemory(rtMemoryBackedBuffer);
47+
rtMemoryBackedBuffer = nullptr;
4348

4449
if (performanceCounters) {
4550
performanceCounters->shutdown();

shared/source/os_interface/os_interface.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ class DriverModel : public NonCopyableClass {
8383
return std::numeric_limits<size_t>::max();
8484
}
8585

86+
virtual bool skipResourceCleanup() const {
87+
return false;
88+
}
89+
8690
protected:
8791
DriverModelType driverModelType;
8892
};

shared/source/os_interface/windows/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ set(NEO_CORE_OS_INTERFACE_WDDM
8787
${CMAKE_CURRENT_SOURCE_DIR}/wddm/set_gmm_input_args_${DRIVER_MODEL}.cpp
8888
${CMAKE_CURRENT_SOURCE_DIR}/wddm/max_mem_alloc_size_${DRIVER_MODEL}.cpp
8989
${CMAKE_CURRENT_SOURCE_DIR}/wddm/helper_${DRIVER_MODEL}.cpp
90+
${CMAKE_CURRENT_SOURCE_DIR}/wddm/skip_resource_cleanup_${DRIVER_MODEL}.cpp
9091
${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm.cpp
9192
${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm.h
9293
${CMAKE_CURRENT_SOURCE_DIR}/wddm/wddm_defs.h

shared/source/os_interface/windows/os_context_win.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void OsContextWin::initializeContext() {
3939
};
4040

4141
OsContextWin::~OsContextWin() {
42-
if (contextInitialized) {
42+
if (contextInitialized && (false == this->wddm.skipResourceCleanup())) {
4343
wddm.getWddmInterface()->destroyHwQueue(hardwareQueue.handle);
4444
wddm.getWddmInterface()->destroyMonitorFence(residencyController.getMonitoredFence());
4545
wddm.destroyContext(wddmContextHandle);

shared/source/os_interface/windows/wddm/configure_device_address_space_drm_or_wddm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ bool ensureGpuAddressRangeIsReserved(uint64_t address, size_t size, D3DKMT_HANDL
159159
rangeDesc.MaximumAddress = alignUp(address + size, MemoryConstants::pageSize64k);
160160
rangeDesc.Size = MemoryConstants::pageSize64k;
161161
status = gdi.reserveGpuVirtualAddress(&rangeDesc);
162-
if (status != STATUS_SUCCESS) {
162+
if (status == STATUS_SUCCESS) {
163163
DEBUG_BREAK_IF(true);
164164
return false;
165165
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/os_interface/windows/gdi_interface.h"
9+
#include "shared/source/os_interface/windows/wddm/wddm.h"
10+
11+
namespace NEO {
12+
13+
bool Wddm::skipResourceCleanup() const {
14+
D3DKMT_GETDEVICESTATE deviceState = {};
15+
deviceState.hDevice = device;
16+
deviceState.StateType = D3DKMT_DEVICESTATE_PRESENT;
17+
18+
NTSTATUS status = STATUS_SUCCESS;
19+
status = getGdi()->getDeviceState(&deviceState);
20+
return status != STATUS_SUCCESS;
21+
}
22+
23+
} // namespace NEO
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/os_interface/windows/wddm/wddm.h"
9+
10+
namespace NEO {
11+
12+
bool Wddm::skipResourceCleanup() const {
13+
return false;
14+
}
15+
16+
} // namespace NEO

0 commit comments

Comments
 (0)