Move tag allocation destruction to command stream receiver.

Change-Id: I657df755c6cdd695103769a45a8dce749f7bd545
This commit is contained in:
Mrozek, Michal
2018-07-13 14:11:04 +02:00
committed by sys_ocldev
parent d9757a93a1
commit 0abacce160
12 changed files with 132 additions and 119 deletions

View File

@ -20,18 +20,18 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/built_ins/built_ins.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/built_ins/built_ins.h"
#include "runtime/command_stream/experimental_command_buffer.h"
#include "runtime/command_stream/preemption.h"
#include "runtime/device/device.h"
#include "runtime/gtpin/gtpin_notify.h"
#include "runtime/helpers/array_count.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/helpers/cache_policy.h"
#include "runtime/os_interface/os_interface.h"
#include "runtime/event/event.h"
#include "runtime/event/event_builder.h"
#include "runtime/gtpin/gtpin_notify.h"
#include "runtime/helpers/array_count.h"
#include "runtime/helpers/cache_policy.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/os_interface/os_interface.h"
namespace OCLRT {
// Global table of CommandStreamReceiver factories for HW and tests
@ -204,6 +204,12 @@ void CommandStreamReceiver::cleanupResources() {
commandStream.replaceGraphicsAllocation(nullptr);
commandStream.replaceBuffer(nullptr, 0);
}
if (tagAllocation) {
memoryManager->freeGraphicsMemory(tagAllocation);
tagAllocation = nullptr;
tagAddress = nullptr;
}
experimentalCmdBuffer.reset(nullptr);
}

View File

@ -122,7 +122,6 @@ Device::~Device() {
}
executionEnvironment->memoryManager->waitForDeletions();
executionEnvironment->memoryManager->freeGraphicsMemory(tagAllocation);
alignedFree(this->slmWindowStartAddress);
}
executionEnvironment->decRefInternal();

View File

@ -27,10 +27,10 @@
#include "runtime/mem_obj/buffer.h"
#include "runtime/mem_obj/image.h"
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
#include "unit_tests/libult/ult_command_stream_receiver.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/mocks/mock_context.h"
#include "test.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/libult/ult_command_stream_receiver.h"
#include "unit_tests/mocks/mock_context.h"
using namespace OCLRT;
@ -488,29 +488,11 @@ HWTEST_F(EnqueueThreading, flushWaitList_ReleaseOwnershipWhenQueueIsBlocked) {
auto pMyDevice = new MyMockDevice();
ASSERT_NE(nullptr, pMyDevice);
auto pCommandStreamReceiver = new CommandStreamReceiverMock<FamilyType>(pMyDevice);
ASSERT_NE(nullptr, pCommandStreamReceiver);
auto memoryManager = pCommandStreamReceiver->createMemoryManager(false);
memoryManager->device = pMyDevice;
ASSERT_NE(nullptr, memoryManager);
pMyDevice->setMemoryManager(memoryManager);
auto pTagAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t));
*(uint32_t *)(pTagAllocation->getUnderlyingBuffer()) = initialHardwareTag;
ASSERT_NE(nullptr, pTagAllocation);
pMyDevice->setTagAllocation(pTagAllocation);
pMyDevice->resetCommandStreamReceiver(pCommandStreamReceiver);
auto pMyCmdQ = new MockCommandQueue(pMyDevice);
ASSERT_NE(nullptr, pMyCmdQ);
EXPECT_TRUE(pMyCmdQ->isQueueBlocked());
auto csr = (CommandStreamReceiverMock<FamilyType> *)&pMyDevice->getCommandStreamReceiver();
csr->expectedToFreeCount = 0u;
pMyCmdQ->flushWaitList(0, nullptr, 0);
EXPECT_EQ(pMyDevice->takeOwnershipCount, 0u);

View File

@ -31,8 +31,8 @@
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/mocks/mock_aub_subcapture_manager.h"
#include "unit_tests/mocks/mock_gmm.h"
#include "unit_tests/mocks/mock_csr.h"
#include "unit_tests/mocks/mock_gmm.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "unit_tests/mocks/mock_mdi.h"
@ -267,7 +267,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIs
std::unique_ptr<MockAubCsr<FamilyType>> aubCsr(new MockAubCsr<FamilyType>(*platformDevices[0], "", true));
memoryManager.reset(aubCsr->createMemoryManager(false));
aubCsr->setTagAllocation(pDevice->getTagAllocation());
aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
ASSERT_NE(nullptr, aubCsr->getTagAllocation());
GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096);
@ -291,7 +291,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptur
std::unique_ptr<MockAubCsr<FamilyType>> aubCsr(new MockAubCsr<FamilyType>(*platformDevices[0], "", true));
memoryManager.reset(aubCsr->createMemoryManager(false));
aubCsr->setTagAllocation(pDevice->getTagAllocation());
aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
ASSERT_NE(nullptr, aubCsr->getTagAllocation());
auto aubSubCaptureManagerMock = new AubSubCaptureManagerMock("");
@ -321,7 +321,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIs
std::unique_ptr<MockAubCsr<FamilyType>> aubCsr(new MockAubCsr<FamilyType>(*platformDevices[0], "", true));
memoryManager.reset(aubCsr->createMemoryManager(false));
aubCsr->setTagAllocation(pDevice->getTagAllocation());
aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
ASSERT_NE(nullptr, aubCsr->getTagAllocation());
GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096);
@ -359,7 +359,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNonStanda
auto engineType = OCLRT::ENGINE_RCS;
ResidencyContainer allocationsForResidency = {};
aubCsr->setTagAllocation(pDevice->getTagAllocation());
aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
ASSERT_NE(nullptr, aubCsr->getTagAllocation());
EXPECT_EQ(initialHardwareTag, *aubCsr->getTagAddress());
@ -388,7 +388,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon
auto engineType = OCLRT::ENGINE_RCS;
ResidencyContainer allocationsForResidency = {};
aubCsr->setTagAllocation(pDevice->getTagAllocation());
aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
ASSERT_NE(nullptr, aubCsr->getTagAllocation());
EXPECT_EQ(initialHardwareTag, *aubCsr->getTagAddress());
@ -423,7 +423,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon
auto engineType = OCLRT::ENGINE_RCS;
ResidencyContainer allocationsForResidency = {};
aubCsr->setTagAllocation(pDevice->getTagAllocation());
aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
ASSERT_NE(nullptr, aubCsr->getTagAllocation());
EXPECT_EQ(initialHardwareTag, *aubCsr->getTagAddress());
@ -458,7 +458,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNonStanda
auto engineType = OCLRT::ENGINE_RCS;
ResidencyContainer allocationsForResidency = {};
aubCsr->setTagAllocation(pDevice->getTagAllocation());
aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
ASSERT_NE(nullptr, aubCsr->getTagAllocation());
EXPECT_EQ(initialHardwareTag, *aubCsr->getTagAddress());
@ -508,7 +508,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon
std::unique_ptr<MockAubCsr<FamilyType>> aubCsr(new MockAubCsr<FamilyType>(*platformDevices[0], "", true));
memoryManager.reset(aubCsr->createMemoryManager(false));
aubCsr->setTagAllocation(pDevice->getTagAllocation());
aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
ASSERT_NE(nullptr, aubCsr->getTagAllocation());
GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096);
@ -560,7 +560,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon
std::unique_ptr<MockAubCsr<FamilyType>> aubCsr(new MockAubCsr<FamilyType>(*platformDevices[0], "", true));
memoryManager.reset(aubCsr->createMemoryManager(false));
aubCsr->setTagAllocation(pDevice->getTagAllocation());
aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
ASSERT_NE(nullptr, aubCsr->getTagAllocation());
auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false);
@ -635,7 +635,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon
aubCsr->subCaptureManager.reset(aubSubCaptureManagerMock);
ASSERT_TRUE(aubCsr->subCaptureManager->isSubCaptureEnabled());
aubCsr->setTagAllocation(pDevice->getTagAllocation());
aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
ASSERT_NE(nullptr, aubCsr->getTagAllocation());
auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false);
@ -1270,7 +1270,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenDefault
auto mockHelper = new MockFlatBatchBufferHelper<FamilyType>(aubCsr->getMemoryManager());
aubCsr->overwriteFlatBatchBufferHelper(mockHelper);
aubCsr->setTagAllocation(pDevice->getTagAllocation());
aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
ASSERT_NE(nullptr, aubCsr->getTagAllocation());
GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096);
@ -1298,7 +1298,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF
auto mockHelper = new MockFlatBatchBufferHelper<FamilyType>(aubCsr->getMemoryManager());
aubCsr->overwriteFlatBatchBufferHelper(mockHelper);
aubCsr->setTagAllocation(pDevice->getTagAllocation());
aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
ASSERT_NE(nullptr, aubCsr->getTagAllocation());
GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096);
@ -1333,7 +1333,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF
auto mockHelper = new MockFlatBatchBufferHelper<FamilyType>(aubCsr->getMemoryManager());
aubCsr->overwriteFlatBatchBufferHelper(mockHelper);
aubCsr->setTagAllocation(pDevice->getTagAllocation());
aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
ASSERT_NE(nullptr, aubCsr->getTagAllocation());
GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096);
@ -1360,7 +1360,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF
auto mockHelper = new MockFlatBatchBufferHelper<FamilyType>(aubCsr->getMemoryManager());
aubCsr->overwriteFlatBatchBufferHelper(mockHelper);
aubCsr->setTagAllocation(pDevice->getTagAllocation());
aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
ASSERT_NE(nullptr, aubCsr->getTagAllocation());
GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096);
@ -1392,7 +1392,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAddPatc
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
auto engineType = OCLRT::ENGINE_RCS;
ResidencyContainer allocationsForResidency;
aubCsr->setTagAllocation(pDevice->getTagAllocation());
aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
EXPECT_CALL(*aubCsr, addPatchInfoComments()).Times(1);
aubCsr->flush(batchBuffer, engineType, &allocationsForResidency);
@ -1412,7 +1412,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAddPatc
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
auto engineType = OCLRT::ENGINE_RCS;
ResidencyContainer allocationsForResidency;
aubCsr->setTagAllocation(pDevice->getTagAllocation());
aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
EXPECT_CALL(*aubCsr, addPatchInfoComments()).Times(0);
aubCsr->flush(batchBuffer, engineType, &allocationsForResidency);

View File

@ -23,24 +23,29 @@
#include "reg_configs_common.h"
#include "runtime/built_ins/built_ins.h"
#include "runtime/command_queue/command_queue_hw.h"
#include "runtime/command_queue/gpgpu_walker.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/command_stream/linear_stream.h"
#include "runtime/os_interface/debug_settings_manager.h"
#include "runtime/command_stream/preemption.h"
#include "runtime/event/user_event.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/helpers/aligned_memory.h"
#include "runtime/helpers/cache_policy.h"
#include "runtime/helpers/preamble.h"
#include "runtime/helpers/ptr_math.h"
#include "runtime/mem_obj/buffer.h"
#include "runtime/memory_manager/graphics_allocation.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/mem_obj/buffer.h"
#include "runtime/command_stream/preemption.h"
#include "unit_tests/libult/ult_command_stream_receiver.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "runtime/os_interface/debug_settings_manager.h"
#include "runtime/utilities/linux/debug_env_reader.h"
#include "test.h"
#include "unit_tests/fixtures/built_in_fixture.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/fixtures/ult_command_stream_receiver_fixture.h"
#include "unit_tests/helpers/hw_parse.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/helpers/hw_parse.h"
#include "unit_tests/libult/create_command_stream.h"
#include "unit_tests/libult/ult_command_stream_receiver.h"
#include "unit_tests/mocks/mock_buffer.h"
#include "unit_tests/mocks/mock_command_queue.h"
#include "unit_tests/mocks/mock_context.h"
@ -48,11 +53,6 @@
#include "unit_tests/mocks/mock_event.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "unit_tests/mocks/mock_submissions_aggregator.h"
#include "unit_tests/libult/create_command_stream.h"
#include "test.h"
#include "runtime/utilities/linux/debug_env_reader.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/command_queue/gpgpu_walker.h"
using namespace OCLRT;
@ -770,7 +770,7 @@ struct CommandStreamReceiverHwLog : public UltCommandStreamReceiver<FamilyType>
HWTEST_F(CommandStreamReceiverFlushTaskTests, flushTaskWithBothCSCallsFlushOnce) {
CommandStreamReceiverHwLog<FamilyType> commandStreamReceiver(*platformDevices[0]);
commandStreamReceiver.setMemoryManager(pDevice->getMemoryManager());
commandStreamReceiver.setTagAllocation(pDevice->getTagAllocation());
commandStreamReceiver.setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
commandStream.getSpace(sizeof(typename FamilyType::MI_NOOP));
flushTask(commandStreamReceiver);
@ -2572,7 +2572,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTotalRes
mockedMemoryManager->device = pDevice;
mockCsr->setMemoryManager(mockedMemoryManager.get());
mockCsr->setTagAllocation(pDevice->getTagAllocation());
mockCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt());
mockCsr->setPreemptionCsrAllocation(pDevice->getPreemptionAllocation());
mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch);

View File

@ -20,20 +20,20 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/command_stream/linear_stream.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/command_stream/linear_stream.h"
#include "runtime/command_stream/preemption.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/memory_manager/graphics_allocation.h"
#include "runtime/helpers/cache_policy.h"
#include "runtime/mem_obj/buffer.h"
#include "unit_tests/mocks/mock_buffer.h"
#include "unit_tests/mocks/mock_context.h"
#include "runtime/memory_manager/graphics_allocation.h"
#include "runtime/memory_manager/memory_manager.h"
#include "test.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/mocks/mock_buffer.h"
#include "unit_tests/mocks/mock_builtins.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_csr.h"
#include "unit_tests/mocks/mock_program.h"
#include "test.h"
#include "runtime/helpers/cache_policy.h"
#include "gmock/gmock.h"
@ -309,6 +309,26 @@ TEST(CommandStreamReceiverSimpleTest, givenCSRWithTagAllocationSetWhenGetTagAllo
EXPECT_EQ(&allocation, csr.getTagAllocation());
}
TEST(CommandStreamReceiverSimpleTest, givenCommandStreamReceiverWhenItIsDestroyedThenItDestroysTagAllocation) {
struct MockGraphicsAllocation : public GraphicsAllocation {
using GraphicsAllocation::GraphicsAllocation;
~MockGraphicsAllocation() override { *destructorCalled = true; }
bool *destructorCalled = nullptr;
};
bool destructorCalled = false;
auto mockGraphicsAllocation = new MockGraphicsAllocation(nullptr, 1u);
mockGraphicsAllocation->destructorCalled = &destructorCalled;
std::unique_ptr<MockCommandStreamReceiver> csr(new MockCommandStreamReceiver);
std::unique_ptr<OsAgnosticMemoryManager> memoryManager(new OsAgnosticMemoryManager);
csr->setMemoryManager(memoryManager.get());
csr->setTagAllocation(mockGraphicsAllocation);
EXPECT_FALSE(destructorCalled);
csr.reset(nullptr);
EXPECT_TRUE(destructorCalled);
}
TEST(CommandStreamReceiverSimpleTest, givenCSRWhenWaitBeforeMakingNonResidentWhenRequiredIsCalledWithBlockingFlagSetThenItReturnsImmediately) {
MockCommandStreamReceiver csr;
uint32_t tag = 0;
@ -318,4 +338,4 @@ TEST(CommandStreamReceiverSimpleTest, givenCSRWhenWaitBeforeMakingNonResidentWhe
csr.waitBeforeMakingNonResidentWhenRequired(true);
EXPECT_EQ(0u, tag);
}
}

View File

@ -20,17 +20,17 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/device/device.h"
#include "runtime/helpers/options.h"
#include "runtime/indirect_heap/indirect_heap.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/libult/ult_command_stream_receiver.h"
#include "test.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/libult/create_command_stream.h"
#include "unit_tests/libult/ult_command_stream_receiver.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_csr.h"
#include "unit_tests/libult/create_command_stream.h"
#include "test.h"
#include <memory>
#include "runtime/device/device.h"
using namespace OCLRT;

View File

@ -21,26 +21,26 @@
*/
#include "event_fixture.h"
#include "runtime/event/perf_counter.h"
#include "unit_tests/os_interface/mock_performance_counters.h"
#include "runtime/command_queue/command_queue_hw.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/memory_manager/surface.h"
#include "runtime/os_interface/os_interface.h"
#include "runtime/event/perf_counter.h"
#include "runtime/helpers/hw_info.h"
#include "runtime/helpers/task_information.h"
#include "unit_tests/mocks/mock_context.h"
#include "runtime/memory_manager/surface.h"
#include "runtime/os_interface/os_interface.h"
#include "test.h"
#include "unit_tests/fixtures/image_fixture.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/mocks/mock_command_queue.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_csr.h"
#include "unit_tests/mocks/mock_event.h"
#include "unit_tests/mocks/mock_program.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "unit_tests/mocks/mock_mdi.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/fixtures/image_fixture.h"
#include "unit_tests/mocks/mock_program.h"
#include "unit_tests/os_interface/mock_performance_counters.h"
#include <memory>
#include <type_traits>
#include "test.h"
TEST(Event, NonCopyable) {
EXPECT_FALSE(std::is_move_constructible<Event>::value);
@ -937,6 +937,7 @@ HWTEST_F(InternalsEventTest, GivenBufferWithoutZeroCopyOnCommandMapOrUnmapFlushe
EXPECT_EQ(1, buffer.dataTransferedStamp);
EXPECT_EQ(nullptr, commandUnMap->getCommandStream());
pDevice->getCommandStreamReceiver().setTagAllocation(nullptr);
delete pCmdQ;
}

View File

@ -145,7 +145,6 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw<GfxFamily> {
template <typename GfxFamily>
UltCommandStreamReceiver<GfxFamily>::~UltCommandStreamReceiver() {
this->setTagAllocation(nullptr);
if (tempPreemptionLocation) {
this->setPreemptionCsrAllocation(nullptr);
delete tempPreemptionLocation;

View File

@ -22,11 +22,11 @@
#include "unit_tests/mocks/mock_device.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/device/driver_info.h"
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
#include "runtime/os_interface/os_time.h"
#include "runtime/device/driver_info.h"
#include "unit_tests/mocks/mock_ostime.h"
#include "unit_tests/mocks/mock_memory_manager.h"
#include "unit_tests/mocks/mock_ostime.h"
using namespace OCLRT;
@ -67,6 +67,7 @@ void MockDevice::injectMemoryManager(MockMemoryManager *memoryManager) {
}
void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) {
auto tagAllocation = this->disconnectCurrentTagAllocationAndReturnIt();
executionEnvironment->commandStreamReceiver.reset(newCsr);
executionEnvironment->commandStreamReceiver->setMemoryManager(executionEnvironment->memoryManager.get());
executionEnvironment->commandStreamReceiver->setTagAllocation(tagAllocation);

View File

@ -21,10 +21,10 @@
*/
#pragma once
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/device/device.h"
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/helpers/hw_info.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
#include "unit_tests/libult/ult_command_stream_receiver.h"
#include "unit_tests/mocks/mock_memory_manager.h"
@ -97,6 +97,11 @@ class MockDevice : public Device {
void resetCommandStreamReceiver(CommandStreamReceiver *newCsr);
GraphicsAllocation *getTagAllocation() { return tagAllocation; }
GraphicsAllocation *disconnectCurrentTagAllocationAndReturnIt() {
auto currentTagAllocation = tagAllocation;
this->getCommandStreamReceiver().setTagAllocation(nullptr);
return currentTagAllocation;
}
void setSourceLevelDebuggerActive(bool active) {
this->deviceInfo.sourceLevelDebuggerActive = active;

View File

@ -20,34 +20,34 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/command_stream/aub_command_stream_receiver.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/command_stream/command_stream_receiver_with_aub_dump.h"
#include "runtime/command_stream/aub_command_stream_receiver.h"
#include "runtime/command_stream/device_command_stream.h"
#include "runtime/command_stream/linear_stream.h"
#include "runtime/command_stream/preemption.h"
#include "runtime/helpers/built_ins_helper.h"
#include "runtime/gen_common/hw_cmds.h"
#include "runtime/helpers/built_ins_helper.h"
#include "runtime/helpers/options.h"
#include "runtime/helpers/translationtable_callbacks.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/mem_obj/buffer.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/os_interface/windows/wddm_device_command_stream.h"
#include "runtime/os_interface/windows/wddm_memory_manager.h"
#include "unit_tests/fixtures/memory_management_fixture.h"
#include "unit_tests/mocks/mock_builtins.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/mocks/mock_buffer.h"
#include "unit_tests/mocks/mock_builtins.h"
#include "unit_tests/mocks/mock_device.h"
#include "unit_tests/mocks/mock_gmm_page_table_mngr.h"
#include "unit_tests/mocks/mock_graphics_allocation.h"
#include "unit_tests/mocks/mock_program.h"
#include "unit_tests/mocks/mock_submissions_aggregator.h"
#include "unit_tests/mocks/mock_gmm_page_table_mngr.h"
#include "unit_tests/mocks/mock_wddm23.h"
#include "unit_tests/os_interface/windows/mock_gdi_interface.h"
#include "unit_tests/os_interface/windows/mock_wddm_memory_manager.h"
#include "unit_tests/os_interface/windows/wddm_fixture.h"
#include "unit_tests/os_interface/windows/mock_gdi_interface.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "test.h"
@ -100,7 +100,6 @@ class WddmCommandStreamWithMockGdiFixture {
WddmMock *wddm = nullptr;
MockGdi *gdi = nullptr;
DebugManagerStateRestore stateRestore;
GraphicsAllocation *tagAllocation;
GraphicsAllocation *preemptionAllocation = nullptr;
virtual void SetUp() {
@ -118,20 +117,15 @@ class WddmCommandStreamWithMockGdiFixture {
device = MockDevice::createWithMemoryManager<MockDevice>(platformDevices[0], memManager);
ASSERT_NE(nullptr, device);
memManager->device = device;
tagAllocation = memManager->allocateGraphicsMemory(1024);
if (device->getPreemptionMode() == PreemptionMode::MidThread) {
preemptionAllocation = memManager->allocateGraphicsMemory(1024);
}
auto tagBuffer = (uint32_t *)tagAllocation->getUnderlyingBuffer();
tagBuffer[0] = initialHardwareTag;
}
virtual void TearDown() {
memManager->freeGraphicsMemory(tagAllocation);
if (preemptionAllocation) {
memManager->freeGraphicsMemory(preemptionAllocation);
}
delete csr->getTagAddress();
delete csr;
wddm = nullptr;
delete device;
@ -676,7 +670,7 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt
tmpAllocation = GlobalMockSipProgram::sipProgram->getAllocation();
GlobalMockSipProgram::sipProgram->resetAllocation(memManager->allocateGraphicsMemory(1024));
}
std::unique_ptr<MockWddmCsr<FamilyType>> mockCsr(new MockWddmCsr<FamilyType>(*platformDevices[0], this->wddm));
auto mockCsr = new MockWddmCsr<FamilyType>(*platformDevices[0], this->wddm);
mockCsr->setMemoryManager(memManager);
mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch);
@ -687,8 +681,9 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt
auto dshAlloc = memManager->allocateGraphicsMemory(1024);
auto iohAlloc = memManager->allocateGraphicsMemory(1024);
auto sshAlloc = memManager->allocateGraphicsMemory(1024);
this->device->resetCommandStreamReceiver(mockCsr);
mockCsr->setTagAllocation(tagAllocation);
auto tagAllocation = mockCsr->getTagAllocation();
mockCsr->setPreemptionCsrAllocation(preemptionAllocation);
LinearStream cs(commandBuffer);
@ -855,59 +850,64 @@ HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenInitializedThenDon
HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenFlushingThenInitTranslationTableOnce) {
createMockWddm();
MockWddmCsr<FamilyType> mockWddmCsr(hwInfo, myMockWddm.get());
mockWddmCsr.overrideDispatchPolicy(DispatchMode::BatchedDispatch);
auto mockWddmCsr = new MockWddmCsr<FamilyType>(hwInfo, myMockWddm.get());
mockWddmCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch);
auto mockMngr = reinterpret_cast<MockGmmPageTableMngr *>(myMockWddm->getPageTableManager());
mockWddmCsr.setMemoryManager(memManager);
mockWddmCsr.setTagAllocation(tagAllocation);
mockWddmCsr.setPreemptionCsrAllocation(preemptionAllocation);
auto &csrCS = mockWddmCsr.getCS();
mockWddmCsr->setMemoryManager(memManager);
this->device->resetCommandStreamReceiver(mockWddmCsr);
mockWddmCsr->setPreemptionCsrAllocation(preemptionAllocation);
auto &csrCS = mockWddmCsr->getCS();
auto graphicsAllocation = memManager->allocateGraphicsMemory(1024);
IndirectHeap cs(graphicsAllocation);
EXPECT_FALSE(mockWddmCsr.pageTableManagerInitialized);
EXPECT_FALSE(mockWddmCsr->pageTableManagerInitialized);
EXPECT_CALL(*mockMngr, initContextAuxTableRegister(&mockWddmCsr, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS))
EXPECT_CALL(*mockMngr, initContextAuxTableRegister(mockWddmCsr, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS))
.Times(1)
.WillOnce(Return(GMM_SUCCESS));
EXPECT_CALL(*mockMngr, initContextTRTableRegister(&mockWddmCsr, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS))
EXPECT_CALL(*mockMngr, initContextTRTableRegister(mockWddmCsr, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS))
.Times(1)
.WillOnce(Return(GMM_SUCCESS));
DispatchFlags dispatchFlags;
mockWddmCsr.flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags);
mockWddmCsr->flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags);
EXPECT_TRUE(mockWddmCsr.pageTableManagerInitialized);
EXPECT_TRUE(mockWddmCsr->pageTableManagerInitialized);
// flush again to check if PT manager was initialized once
mockWddmCsr.flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags);
mockWddmCsr->flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags);
mockWddmCsr->flushBatchedSubmissions();
memManager->freeGraphicsMemory(graphicsAllocation);
}
HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenFlushingThenDontInitTranslationTable) {
setCompressionEnabled(false);
createMockWddm();
MockWddmCsr<FamilyType> mockWddmCsr(hwInfo, myMockWddm.get());
mockWddmCsr.overrideDispatchPolicy(DispatchMode::BatchedDispatch);
auto mockWddmCsr = new MockWddmCsr<FamilyType>(hwInfo, myMockWddm.get());
mockWddmCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch);
EXPECT_EQ(nullptr, myMockWddm->getPageTableManager());
mockWddmCsr.setMemoryManager(memManager);
mockWddmCsr.setTagAllocation(tagAllocation);
mockWddmCsr.setPreemptionCsrAllocation(preemptionAllocation);
mockWddmCsr->setMemoryManager(memManager);
mockWddmCsr->setPreemptionCsrAllocation(preemptionAllocation);
this->device->resetCommandStreamReceiver(mockWddmCsr);
auto graphicsAllocation = memManager->allocateGraphicsMemory(1024);
IndirectHeap cs(graphicsAllocation);
EXPECT_FALSE(mockWddmCsr.pageTableManagerInitialized);
EXPECT_FALSE(mockWddmCsr->pageTableManagerInitialized);
DispatchFlags dispatchFlags;
mockWddmCsr.flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags);
mockWddmCsr->flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags);
EXPECT_FALSE(mockWddmCsr.pageTableManagerInitialized);
EXPECT_FALSE(mockWddmCsr->pageTableManagerInitialized);
mockWddmCsr->flushBatchedSubmissions();
memManager->freeGraphicsMemory(graphicsAllocation);
}