diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index 5a6e7690f2..071ed7fbde 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -182,7 +182,6 @@ LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) { } void CommandStreamReceiver::cleanupResources() { - auto memoryManager = this->getMemoryManager(); if (!memoryManager) return; @@ -210,7 +209,6 @@ void CommandStreamReceiver::cleanupResources() { tagAllocation = nullptr; tagAddress = nullptr; } - experimentalCmdBuffer.reset(nullptr); } bool CommandStreamReceiver::waitForCompletionWithTimeout(bool enableTimeout, int64_t timeoutMicroseconds, uint32_t taskCountToWait) { diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index 1e50584564..bf6917ce21 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -106,9 +106,9 @@ Device::~Device() { if (performanceCounters) { performanceCounters->shutdown(); } + if (executionEnvironment->commandStreamReceiver) { executionEnvironment->commandStreamReceiver->flushBatchedSubmissions(); - executionEnvironment->commandStreamReceiver.reset(nullptr); } if (deviceInfo.sourceLevelDebuggerActive && sourceLevelDebugger) { diff --git a/runtime/execution_environment/execution_environment.h b/runtime/execution_environment/execution_environment.h index 6b71b1ce8f..a91b2369dd 100644 --- a/runtime/execution_environment/execution_environment.h +++ b/runtime/execution_environment/execution_environment.h @@ -39,7 +39,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject ExecutionEnvironment(); ~ExecutionEnvironment() override; void initGmm(const HardwareInfo *hwInfo); - std::unique_ptr commandStreamReceiver; std::unique_ptr memoryManager; + std::unique_ptr commandStreamReceiver; }; } // namespace OCLRT diff --git a/unit_tests/execution_environment/execution_environment_tests.cpp b/unit_tests/execution_environment/execution_environment_tests.cpp index de67ced6ee..076db0bee5 100644 --- a/unit_tests/execution_environment/execution_environment_tests.cpp +++ b/unit_tests/execution_environment/execution_environment_tests.cpp @@ -27,6 +27,7 @@ #include "runtime/memory_manager/os_agnostic_memory_manager.h" #include "runtime/helpers/options.h" #include "runtime/platform/platform.h" +#include "unit_tests/mocks/mock_csr.h" using namespace OCLRT; @@ -104,16 +105,24 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe struct GmmHelperMock : public GmmHelper { using GmmHelper::GmmHelper; ~GmmHelperMock() override { - EXPECT_EQ(destructorId, 1u); + EXPECT_EQ(destructorId, 2u); destructorId++; } }; struct MemoryMangerMock : public OsAgnosticMemoryManager { ~MemoryMangerMock() override { - EXPECT_EQ(destructorId, 0u); + EXPECT_EQ(destructorId, 1u); destructorId++; } }; + + struct CommandStreamReceiverMock : public MockCommandStreamReceiver { + ~CommandStreamReceiverMock() override { + EXPECT_EQ(destructorId, 0u); + destructorId++; + }; + }; + struct MockExecutionEnvironment : ExecutionEnvironment { using ExecutionEnvironment::gmmHelper; }; @@ -121,7 +130,8 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe std::unique_ptr executionEnvironment(new MockExecutionEnvironment); executionEnvironment->gmmHelper.reset(new GmmHelperMock(platformDevices[0])); executionEnvironment->memoryManager.reset(new MemoryMangerMock); + executionEnvironment->commandStreamReceiver.reset(new CommandStreamReceiverMock); executionEnvironment.reset(nullptr); - EXPECT_EQ(2u, destructorId); -} \ No newline at end of file + EXPECT_EQ(3u, destructorId); +}