From 75fe358e5d9d955db1cee9f301fab79191155564 Mon Sep 17 00:00:00 2001 From: "Dunajski, Bartosz" Date: Thu, 7 Feb 2019 13:21:58 +0100 Subject: [PATCH] Add HardwareContextController to use multiple Contexts in single AubCsr Change-Id: Ica0f1c8c4e0f55310f4650788e468640406abf51 Signed-off-by: Dunajski, Bartosz --- .../aub_command_stream_receiver_hw.h | 2 +- .../aub_command_stream_receiver_hw.inl | 21 +-- ...mand_stream_receiver_simulated_common_hw.h | 3 +- ...nd_stream_receiver_simulated_common_hw.inl | 4 +- .../tbx_command_stream_receiver_hw.h | 2 +- .../tbx_command_stream_receiver_hw.inl | 19 +-- runtime/helpers/CMakeLists.txt | 2 + .../helpers/hardware_context_controller.cpp | 48 +++++++ runtime/helpers/hardware_context_controller.h | 32 +++++ .../aub_command_stream_receiver_1_tests.cpp | 72 +++++++++- .../aub_command_stream_receiver_2_tests.cpp | 57 ++++++-- .../command_stream/aub_file_stream_tests.cpp | 136 +++++++++++------- .../tbx_command_stream_tests.cpp | 98 ++++++++----- 13 files changed, 358 insertions(+), 138 deletions(-) create mode 100644 runtime/helpers/hardware_context_controller.cpp create mode 100644 runtime/helpers/hardware_context_controller.h diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.h b/runtime/command_stream/aub_command_stream_receiver_hw.h index 31cc8b6de3..37fe5056cc 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.h +++ b/runtime/command_stream/aub_command_stream_receiver_hw.h @@ -33,7 +33,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw::initAdditionalMMIO; using CommandStreamReceiverSimulatedCommonHw::aubManager; - using CommandStreamReceiverSimulatedCommonHw::hardwareContext; + using CommandStreamReceiverSimulatedCommonHw::hardwareContextController; using CommandStreamReceiverSimulatedCommonHw::engineInfoTable; using CommandStreamReceiverSimulatedCommonHw::stream; diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.inl b/runtime/command_stream/aub_command_stream_receiver_hw.inl index 62b99c0d01..6526728cea 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.inl +++ b/runtime/command_stream/aub_command_stream_receiver_hw.inl @@ -18,6 +18,7 @@ #include "runtime/gmm_helper/resource_info.h" #include "runtime/helpers/aligned_memory.h" #include "runtime/helpers/debug_helpers.h" +#include "runtime/helpers/hardware_context_controller.h" #include "runtime/helpers/hash.h" #include "runtime/helpers/ptr_math.h" #include "runtime/helpers/string.h" @@ -151,9 +152,9 @@ const std::string &AUBCommandStreamReceiverHw::getFileName() { template void AUBCommandStreamReceiverHw::initializeEngine() { - if (hardwareContext) { + if (hardwareContextController) { DEBUG_BREAK_IF(allEngineInstances[engineIndex].type != osContext->getEngineType().type); - hardwareContext->initialize(); + hardwareContextController->initialize(); return; } @@ -403,9 +404,9 @@ bool AUBCommandStreamReceiverHw::addPatchInfoComments() { template void AUBCommandStreamReceiverHw::submitBatchBuffer(uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits) { - if (hardwareContext) { + if (hardwareContextController) { if (batchBufferSize) { - hardwareContext->submit(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, MemoryConstants::pageSize64k); + hardwareContextController->submit(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, MemoryConstants::pageSize64k); } return; } @@ -572,8 +573,8 @@ template void AUBCommandStreamReceiverHw::pollForCompletionImpl() { this->pollForCompletionTaskCount = this->taskCount; - if (hardwareContext) { - hardwareContext->pollForCompletion(); + if (hardwareContextController) { + hardwareContextController->pollForCompletion(); return; } @@ -710,8 +711,8 @@ void AUBCommandStreamReceiverHw::expectMemory(const void *gfxAddress, size_t length, uint32_t compareOperation) { pollForCompletion(); - if (hardwareContext) { - hardwareContext->expectMemory(reinterpret_cast(gfxAddress), srcAddress, length, compareOperation); + if (hardwareContextController) { + hardwareContextController->expectMemory(reinterpret_cast(gfxAddress), srcAddress, length, compareOperation); } PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset, uint64_t entryBits) { @@ -763,12 +764,12 @@ void AUBCommandStreamReceiverHw::dumpAllocation(GraphicsAllocation &g gfxAllocation.setAllocDumpable(false); } - if (hardwareContext) { + if (hardwareContextController) { if (AubAllocDump::isWritableBuffer(gfxAllocation)) { if (0 == DebugManager.flags.AUBDumpBufferFormat.get().compare("BIN")) { auto gpuAddress = GmmHelper::decanonize(gfxAllocation.getGpuAddress()); auto size = gfxAllocation.getUnderlyingBufferSize(); - hardwareContext->dumpBufferBIN(gpuAddress, size); + hardwareContextController->dumpBufferBIN(gpuAddress, size); } } return; diff --git a/runtime/command_stream/command_stream_receiver_simulated_common_hw.h b/runtime/command_stream/command_stream_receiver_simulated_common_hw.h index 952f815008..4bbbb2674d 100644 --- a/runtime/command_stream/command_stream_receiver_simulated_common_hw.h +++ b/runtime/command_stream/command_stream_receiver_simulated_common_hw.h @@ -18,6 +18,7 @@ struct AubStream; namespace OCLRT { class GraphicsAllocation; +class HardwareContextController; template class CommandStreamReceiverSimulatedCommonHw : public CommandStreamReceiverHw { protected: @@ -46,7 +47,7 @@ class CommandStreamReceiverSimulatedCommonHw : public CommandStreamReceiverHw hardwareContext; + std::unique_ptr hardwareContextController; struct EngineInfo { void *pLRCA; diff --git a/runtime/command_stream/command_stream_receiver_simulated_common_hw.inl b/runtime/command_stream/command_stream_receiver_simulated_common_hw.inl index a3ad36fd28..1c40aaa6e9 100644 --- a/runtime/command_stream/command_stream_receiver_simulated_common_hw.inl +++ b/runtime/command_stream/command_stream_receiver_simulated_common_hw.inl @@ -8,6 +8,7 @@ #include "runtime/aub/aub_helper.h" #include "runtime/aub_mem_dump/page_table_entry_bits.h" #include "runtime/command_stream/command_stream_receiver_simulated_common_hw.h" +#include "runtime/helpers/hardware_context_controller.h" #include "runtime/os_interface/debug_settings_manager.h" #include "runtime/os_interface/os_context.h" #include "third_party/aub_stream/headers/aub_manager.h" @@ -90,8 +91,7 @@ void CommandStreamReceiverSimulatedCommonHw::setupContext(OsContext & auto &engineType = osContext.getEngineType(); if (aubManager && !(engineType.type == lowPriorityGpgpuEngine.type && engineType.id == lowPriorityGpgpuEngine.id)) { - hardwareContext = std::unique_ptr(aubManager->createHardwareContext(deviceIndex, - engineIndex, flags)); + hardwareContextController = std::make_unique(*aubManager, deviceIndex, engineIndex, flags); } } } // namespace OCLRT diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.h b/runtime/command_stream/tbx_command_stream_receiver_hw.h index f5e9e00d96..a381b48652 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.h +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.h @@ -39,7 +39,7 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw::initAdditionalMMIO; using CommandStreamReceiverSimulatedCommonHw::aubManager; - using CommandStreamReceiverSimulatedCommonHw::hardwareContext; + using CommandStreamReceiverSimulatedCommonHw::hardwareContextController; using CommandStreamReceiverSimulatedCommonHw::engineInfoTable; using CommandStreamReceiverSimulatedCommonHw::stream; diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.inl b/runtime/command_stream/tbx_command_stream_receiver_hw.inl index 21d6375f4a..c841efa82c 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.inl +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.inl @@ -12,6 +12,7 @@ #include "runtime/execution_environment/execution_environment.h" #include "runtime/helpers/aligned_memory.h" #include "runtime/helpers/debug_helpers.h" +#include "runtime/helpers/hardware_context_controller.h" #include "runtime/helpers/hw_helper.h" #include "runtime/helpers/ptr_math.h" #include "runtime/memory_manager/graphics_allocation.h" @@ -80,8 +81,8 @@ TbxCommandStreamReceiverHw::~TbxCommandStreamReceiverHw() { template void TbxCommandStreamReceiverHw::initializeEngine() { - if (hardwareContext) { - hardwareContext->initialize(); + if (hardwareContextController) { + hardwareContextController->initialize(); return; } @@ -218,9 +219,9 @@ FlushStamp TbxCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer template void TbxCommandStreamReceiverHw::submitBatchBuffer(uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits) { - if (hardwareContext) { + if (hardwareContextController) { if (batchBufferSize) { - hardwareContext->submit(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, MemoryConstants::pageSize64k); + hardwareContextController->submit(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, MemoryConstants::pageSize64k); } return; } @@ -346,8 +347,8 @@ void TbxCommandStreamReceiverHw::submitBatchBuffer(uint64_t batchBuff template void TbxCommandStreamReceiverHw::pollForCompletion() { - if (hardwareContext) { - hardwareContext->pollForCompletion(); + if (hardwareContextController) { + hardwareContextController->pollForCompletion(); return; } @@ -409,9 +410,9 @@ void TbxCommandStreamReceiverHw::processResidency(ResidencyContainer template void TbxCommandStreamReceiverHw::makeCoherent(GraphicsAllocation &gfxAllocation) { - if (hardwareContext) { - hardwareContext->readMemory(gfxAllocation.getGpuAddress(), gfxAllocation.getUnderlyingBuffer(), gfxAllocation.getUnderlyingBufferSize(), - this->getMemoryBank(&gfxAllocation), MemoryConstants::pageSize64k); + if (hardwareContextController) { + hardwareContextController->readMemory(gfxAllocation.getGpuAddress(), gfxAllocation.getUnderlyingBuffer(), gfxAllocation.getUnderlyingBufferSize(), + this->getMemoryBank(&gfxAllocation), MemoryConstants::pageSize64k); return; } diff --git a/runtime/helpers/CMakeLists.txt b/runtime/helpers/CMakeLists.txt index 779ef62770..8621a5ec94 100644 --- a/runtime/helpers/CMakeLists.txt +++ b/runtime/helpers/CMakeLists.txt @@ -43,6 +43,8 @@ set(RUNTIME_SRCS_HELPERS_BASE ${CMAKE_CURRENT_SOURCE_DIR}/flush_stamp.h ${CMAKE_CURRENT_SOURCE_DIR}/get_info.h ${CMAKE_CURRENT_SOURCE_DIR}/hash.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware_context_controller.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/hardware_context_controller.h ${CMAKE_CURRENT_SOURCE_DIR}/hw_helper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/hw_helper.h ${CMAKE_CURRENT_SOURCE_DIR}/hw_helper_common.inl diff --git a/runtime/helpers/hardware_context_controller.cpp b/runtime/helpers/hardware_context_controller.cpp new file mode 100644 index 0000000000..34e455a25e --- /dev/null +++ b/runtime/helpers/hardware_context_controller.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/helpers/hardware_context_controller.h" +#include "runtime/memory_manager/memory_constants.h" + +using namespace OCLRT; + +HardwareContextController::HardwareContextController(aub_stream::AubManager &aubManager, uint32_t deviceIndex, uint32_t engineIndex, uint32_t flags) { + hardwareContexts.emplace_back(aubManager.createHardwareContext(deviceIndex, engineIndex, flags)); +} + +void HardwareContextController::initialize() { + for (auto &hardwareContext : hardwareContexts) { + hardwareContext->initialize(); + } +} + +void HardwareContextController::pollForCompletion() { + for (auto &hardwareContext : hardwareContexts) { + hardwareContext->pollForCompletion(); + } +} + +void HardwareContextController::expectMemory(uint64_t gfxAddress, const void *srcAddress, size_t length, uint32_t compareOperation) { + for (auto &hardwareContext : hardwareContexts) { + hardwareContext->expectMemory(gfxAddress, srcAddress, length, compareOperation); + } +} + +void HardwareContextController::submit(uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, + uint32_t memoryBank, uint64_t entryBits) { + for (auto &hardwareContext : hardwareContexts) { + hardwareContext->submit(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, MemoryConstants::pageSize64k); + } +} + +void HardwareContextController::dumpBufferBIN(uint64_t gfxAddress, size_t size) { + hardwareContexts[0]->dumpBufferBIN(gfxAddress, size); +} + +void HardwareContextController::readMemory(uint64_t gfxAddress, void *memory, size_t size, uint32_t memoryBanks, size_t pageSize) { + hardwareContexts[0]->readMemory(gfxAddress, memory, size, memoryBanks, pageSize); +} diff --git a/runtime/helpers/hardware_context_controller.h b/runtime/helpers/hardware_context_controller.h new file mode 100644 index 0000000000..ca0afd1a22 --- /dev/null +++ b/runtime/helpers/hardware_context_controller.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "third_party/aub_stream/headers/aub_manager.h" +#include "third_party/aub_stream/headers/hardware_context.h" + +#include +#include + +namespace OCLRT { + +class HardwareContextController { + public: + HardwareContextController() = delete; + HardwareContextController(aub_stream::AubManager &aubManager, uint32_t deviceIndex, uint32_t engineIndex, uint32_t flags); + + void initialize(); + void pollForCompletion(); + void expectMemory(uint64_t gfxAddress, const void *srcAddress, size_t length, uint32_t compareOperation); + void submit(uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits); + + void dumpBufferBIN(uint64_t gfxAddress, size_t size); + void readMemory(uint64_t gfxAddress, void *memory, size_t size, uint32_t memoryBanks, size_t pageSize); + + std::vector> hardwareContexts; +}; +} // namespace OCLRT diff --git a/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp index 957142c85b..aac22f21d8 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp @@ -6,6 +6,7 @@ */ #include "runtime/aub_mem_dump/page_table_entry_bits.h" +#include "runtime/helpers/hardware_context_controller.h" #include "runtime/os_interface/os_context.h" #include "test.h" #include "unit_tests/fixtures/device_fixture.h" @@ -82,7 +83,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenItIsCre ASSERT_NE(nullptr, aubCsr); EXPECT_EQ(nullptr, aubCsr->aubManager); - EXPECT_EQ(nullptr, aubCsr->hardwareContext); + EXPECT_EQ(nullptr, aubCsr->hardwareContextController); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGetEngineIndexFromInstanceIsCalledForGivenEngineInstanceThenEngineIndexForThatInstanceIsReturned) { @@ -199,11 +200,11 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrWhenOsContextIsSetThenCreateH std::unique_ptr> aubCsr(reinterpret_cast *>(AUBCommandStreamReceiver::create(*platformDevices[0], fileName, true, executionEnvironment))); aubCsr->setDeviceIndex(deviceIndex); - EXPECT_EQ(nullptr, aubCsr->hardwareContext.get()); + EXPECT_EQ(nullptr, aubCsr->hardwareContextController.get()); aubCsr->setupContext(osContext); - EXPECT_NE(nullptr, aubCsr->hardwareContext.get()); - auto mockHardwareContext = static_cast(aubCsr->hardwareContext.get()); + EXPECT_NE(nullptr, aubCsr->hardwareContextController.get()); + auto mockHardwareContext = static_cast(aubCsr->hardwareContextController->hardwareContexts[0].get()); EXPECT_EQ(deviceIndex, mockHardwareContext->deviceIndex); EXPECT_EQ(engineIndex, mockHardwareContext->engineIndex); } @@ -218,10 +219,10 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrWhenLowPriorityOsContextIsSet executionEnvironment.aubCenter = std::unique_ptr(mockAubCenter); std::unique_ptr> aubCsr(reinterpret_cast *>(AUBCommandStreamReceiver::create(*platformDevices[0], fileName, true, executionEnvironment))); - EXPECT_EQ(nullptr, aubCsr->hardwareContext.get()); + EXPECT_EQ(nullptr, aubCsr->hardwareContextController.get()); aubCsr->setupContext(osContext); - EXPECT_EQ(nullptr, aubCsr->hardwareContext.get()); + EXPECT_EQ(nullptr, aubCsr->hardwareContextController.get()); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptureModeWhenItIsCreatedThenFileIsNotCreated) { @@ -318,6 +319,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipl HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenItShouldInitializeEngineInfoTable) { auto aubExecutionEnvironment = getEnvironment>(true, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); + aubCsr->hardwareContextController.reset(nullptr); LinearStream cs(aubExecutionEnvironment->commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; @@ -1096,3 +1098,61 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon EXPECT_FALSE(aubCsr->flushBatchedSubmissionsCalled); EXPECT_TRUE(aubCsr->initProgrammingFlagsCalled); } + +using HardwareContextContainerTests = ::testing::Test; + +TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCalledThenUseAllContexts) { + MockAubManager aubManager; + HardwareContextController hwContextContainer(aubManager, 1, 2, 0); + hwContextContainer.hardwareContexts.emplace_back(aubManager.createHardwareContext(2, 3)); + EXPECT_EQ(2u, hwContextContainer.hardwareContexts.size()); + + auto mockHwContext0 = static_cast(hwContextContainer.hardwareContexts[0].get()); + auto mockHwContext1 = static_cast(hwContextContainer.hardwareContexts[1].get()); + + EXPECT_FALSE(mockHwContext0->initializeCalled); + EXPECT_FALSE(mockHwContext1->initializeCalled); + EXPECT_FALSE(mockHwContext0->pollForCompletionCalled); + EXPECT_FALSE(mockHwContext1->pollForCompletionCalled); + EXPECT_FALSE(mockHwContext0->expectMemoryCalled); + EXPECT_FALSE(mockHwContext1->expectMemoryCalled); + EXPECT_FALSE(mockHwContext0->submitCalled); + EXPECT_FALSE(mockHwContext1->submitCalled); + + hwContextContainer.initialize(); + hwContextContainer.pollForCompletion(); + hwContextContainer.expectMemory(1, reinterpret_cast(0x123), 2, 0); + hwContextContainer.submit(1, reinterpret_cast(0x123), 2, 0, 1); + + EXPECT_TRUE(mockHwContext0->initializeCalled); + EXPECT_TRUE(mockHwContext1->initializeCalled); + EXPECT_TRUE(mockHwContext0->pollForCompletionCalled); + EXPECT_TRUE(mockHwContext1->pollForCompletionCalled); + EXPECT_TRUE(mockHwContext0->expectMemoryCalled); + EXPECT_TRUE(mockHwContext1->expectMemoryCalled); + EXPECT_TRUE(mockHwContext0->submitCalled); + EXPECT_TRUE(mockHwContext1->submitCalled); +} + +TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCalledThenUseFirstContext) { + MockAubManager aubManager; + HardwareContextController hwContextContainer(aubManager, 1, 2, 0); + hwContextContainer.hardwareContexts.emplace_back(aubManager.createHardwareContext(2, 3)); + EXPECT_EQ(2u, hwContextContainer.hardwareContexts.size()); + + auto mockHwContext0 = static_cast(hwContextContainer.hardwareContexts[0].get()); + auto mockHwContext1 = static_cast(hwContextContainer.hardwareContexts[1].get()); + + EXPECT_FALSE(mockHwContext0->dumpBufferBINCalled); + EXPECT_FALSE(mockHwContext1->dumpBufferBINCalled); + EXPECT_FALSE(mockHwContext0->readMemoryCalled); + EXPECT_FALSE(mockHwContext1->readMemoryCalled); + + hwContextContainer.dumpBufferBIN(1, 2); + hwContextContainer.readMemory(1, reinterpret_cast(0x123), 1, 2, 0); + + EXPECT_TRUE(mockHwContext0->dumpBufferBINCalled); + EXPECT_FALSE(mockHwContext1->dumpBufferBINCalled); + EXPECT_TRUE(mockHwContext0->readMemoryCalled); + EXPECT_FALSE(mockHwContext1->readMemoryCalled); +} diff --git a/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp index 41e3a4957e..b284be8e2e 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp @@ -7,11 +7,13 @@ #include "runtime/aub_mem_dump/aub_alloc_dump.h" #include "runtime/aub_mem_dump/page_table_entry_bits.h" +#include "runtime/helpers/hardware_context_controller.h" #include "runtime/mem_obj/mem_obj_helper.h" #include "test.h" #include "third_party/aub_stream/headers/options.h" #include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" +#include "unit_tests/mocks/mock_aub_center.h" #include "unit_tests/mocks/mock_aub_csr.h" #include "unit_tests/mocks/mock_aub_file_stream.h" #include "unit_tests/mocks/mock_aub_manager.h" @@ -888,10 +890,15 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpA DebugManagerStateRestore dbgRestore; DebugManager.flags.AUBDumpBufferFormat.set("BIN"); + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); + + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); - auto mockManager = std::make_unique(); - auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); - aubCsr.hardwareContext = std::unique_ptr(mockHardwareContext); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + aubCsr.setupContext(osContext); + + auto mockHardwareContext = static_cast(aubCsr.hardwareContextController->hardwareContexts[0].get()); auto memoryManager = pDevice->getMemoryManager(); auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); @@ -910,10 +917,15 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpA HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpAllocationIsCalledButDumpFormatIsNotSpecifiedThenGraphicsAllocationShouldNotBeDumped) { DebugManagerStateRestore dbgRestore; + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); + + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); - auto mockManager = std::make_unique(); - auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); - aubCsr.hardwareContext = std::unique_ptr(mockHardwareContext); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + aubCsr.setupContext(osContext); + + auto mockHardwareContext = static_cast(aubCsr.hardwareContextController->hardwareContexts[0].get()); auto memoryManager = pDevice->getMemoryManager(); auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); @@ -933,10 +945,15 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationNonWritableWhenDu DebugManagerStateRestore dbgRestore; DebugManager.flags.AUBDumpBufferFormat.set("BIN"); + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); + + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); - auto mockManager = std::make_unique(); - auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); - aubCsr.hardwareContext = std::unique_ptr(mockHardwareContext); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + aubCsr.setupContext(osContext); + + auto mockHardwareContext = static_cast(aubCsr.hardwareContextController->hardwareContexts[0].get()); auto memoryManager = pDevice->getMemoryManager(); auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); @@ -957,10 +974,15 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationNotDumpableWhenDu DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.set(true); DebugManager.flags.AUBDumpBufferFormat.set("BIN"); + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); + + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); - auto mockManager = std::make_unique(); - auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); - aubCsr.hardwareContext = std::unique_ptr(mockHardwareContext); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + aubCsr.setupContext(osContext); + + auto mockHardwareContext = static_cast(aubCsr.hardwareContextController->hardwareContexts[0].get()); auto memoryManager = pDevice->getMemoryManager(); auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); @@ -982,10 +1004,15 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationDumpableWhenDumpA DebugManager.flags.AUBDumpAllocsOnEnqueueReadOnly.set(true); DebugManager.flags.AUBDumpBufferFormat.set("BIN"); + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); + + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); - auto mockManager = std::make_unique(); - auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); - aubCsr.hardwareContext = std::unique_ptr(mockHardwareContext); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + aubCsr.setupContext(osContext); + + auto mockHardwareContext = static_cast(aubCsr.hardwareContextController->hardwareContexts[0].get()); auto memoryManager = pDevice->getMemoryManager(); auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); diff --git a/unit_tests/command_stream/aub_file_stream_tests.cpp b/unit_tests/command_stream/aub_file_stream_tests.cpp index 2e5c573c89..1ec6238531 100644 --- a/unit_tests/command_stream/aub_file_stream_tests.cpp +++ b/unit_tests/command_stream/aub_file_stream_tests.cpp @@ -6,12 +6,14 @@ */ #include "runtime/aub_mem_dump/page_table_entry_bits.h" +#include "runtime/helpers/hardware_context_controller.h" #include "runtime/command_stream/aub_command_stream_receiver_hw.h" #include "runtime/os_interface/os_context.h" #include "test.h" #include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/mocks/mock_graphics_allocation.h" +#include "unit_tests/mocks/mock_aub_center.h" #include "unit_tests/mocks/mock_aub_csr.h" #include "unit_tests/mocks/mock_aub_file_stream.h" #include "unit_tests/mocks/mock_aub_manager.h" @@ -212,38 +214,42 @@ HWTEST_F(AubFileStreamTests, givenNoNewTaskSinceLastPollWhenDeletingAubCsrThenDo } HWTEST_F(AubFileStreamTests, givenNewTasksAndHardwareContextPresentWhenCallingPollForCompletionThenCallPollForCompletion) { - auto mockManager = std::make_unique(); - auto hardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); auto aubStream = std::make_unique(); - auto aubExecutionEnvironment = getEnvironment>(true, true, true); - auto aubCsr = aubExecutionEnvironment->template getCsr>(); - aubCsr->hardwareContext = std::unique_ptr(hardwareContext); - aubCsr->aubManager = mockManager.get(); - aubCsr->stream = aubStream.get(); + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); - aubCsr->taskCount = 50; - aubCsr->pollForCompletionTaskCount = 49; + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); + MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + aubCsr.setupContext(osContext); + auto hardwareContext = static_cast(aubCsr.hardwareContextController->hardwareContexts[0].get()); + aubCsr.stream = aubStream.get(); + + aubCsr.taskCount = 50; + aubCsr.pollForCompletionTaskCount = 49; ASSERT_FALSE(hardwareContext->pollForCompletionCalled); - aubCsr->pollForCompletion(); + aubCsr.pollForCompletion(); EXPECT_TRUE(hardwareContext->pollForCompletionCalled); } HWTEST_F(AubFileStreamTests, givenNoNewTasksAndHardwareContextPresentWhenCallingPollForCompletionThenDontCallPollForCompletion) { - auto mockManager = std::make_unique(); - auto hardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); auto aubStream = std::make_unique(); - auto aubExecutionEnvironment = getEnvironment>(true, true, true); - auto aubCsr = aubExecutionEnvironment->template getCsr>(); - aubCsr->hardwareContext = std::unique_ptr(hardwareContext); - aubCsr->aubManager = mockManager.get(); - aubCsr->stream = aubStream.get(); + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); - aubCsr->taskCount = 50; - aubCsr->pollForCompletionTaskCount = 50; + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); + MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + aubCsr.setupContext(osContext); + auto hardwareContext = static_cast(aubCsr.hardwareContextController->hardwareContexts[0].get()); + aubCsr.stream = aubStream.get(); + + aubCsr.taskCount = 50; + aubCsr.pollForCompletionTaskCount = 50; ASSERT_FALSE(hardwareContext->pollForCompletionCalled); - aubCsr->pollForCompletion(); + aubCsr.pollForCompletion(); EXPECT_FALSE(hardwareContext->pollForCompletionCalled); } @@ -311,19 +317,26 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenExpectMemoryNotEqu } HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenItShouldCallTheExpectedHwContextFunctions) { - auto mockManager = std::make_unique(); - auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + auto aubStream = std::make_unique(); + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); + auto mockManager = static_cast(mockAubCenter->aubManager.get()); - auto aubExecutionEnvironment = getEnvironment>(true, true, true); - auto aubCsr = aubExecutionEnvironment->template getCsr>(); - aubCsr->hardwareContext = std::unique_ptr(mockHardwareContext); - aubCsr->aubManager = mockManager.get(); + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); + MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + aubCsr.setupContext(osContext); + auto mockHardwareContext = static_cast(aubCsr.hardwareContextController->hardwareContexts[0].get()); + aubCsr.stream = aubStream.get(); - LinearStream cs(aubExecutionEnvironment->commandBuffer); + auto commandBuffer = pDevice->executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + auto tagAllocation = pDevice->executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + aubCsr.setTagAllocation(tagAllocation); + LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 1, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; ResidencyContainer allocationsForResidency; - aubCsr->flush(batchBuffer, allocationsForResidency); + aubCsr.flush(batchBuffer, allocationsForResidency); EXPECT_TRUE(mockHardwareContext->initializeCalled); EXPECT_TRUE(mockHardwareContext->submitCalled); @@ -332,37 +345,48 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenI //call writeMemory on aubManager to clone page tables EXPECT_FALSE(mockHardwareContext->writeMemoryCalled); EXPECT_TRUE(mockManager->writeMemoryCalled); + pDevice->executionEnvironment->memoryManager->freeGraphicsMemory(commandBuffer); } HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledWithZeroSizedBufferThenSubmitIsNotCalledOnHwContext) { - auto mockManager = std::make_unique(); - auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + auto aubStream = std::make_unique(); + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); - auto aubExecutionEnvironment = getEnvironment>(true, true, true); - auto aubCsr = aubExecutionEnvironment->template getCsr>(); - aubCsr->hardwareContext = std::unique_ptr(mockHardwareContext); + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); + MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + aubCsr.setupContext(osContext); + auto mockHardwareContext = static_cast(aubCsr.hardwareContextController->hardwareContexts[0].get()); + aubCsr.stream = aubStream.get(); - LinearStream cs(aubExecutionEnvironment->commandBuffer); + auto commandBuffer = pDevice->executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + auto tagAllocation = pDevice->executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + aubCsr.setTagAllocation(tagAllocation); + LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; ResidencyContainer allocationsForResidency; - aubCsr->flush(batchBuffer, allocationsForResidency); + aubCsr.flush(batchBuffer, allocationsForResidency); EXPECT_FALSE(mockHardwareContext->submitCalled); + pDevice->executionEnvironment->memoryManager->freeGraphicsMemory(commandBuffer); } HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenMakeResidentIsCalledThenItShouldCallTheExpectedHwContextFunctions) { - auto mockManager = std::make_unique(); - auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); + auto mockManager = static_cast(mockAubCenter->aubManager.get()); - auto aubExecutionEnvironment = getEnvironment>(true, true, true); - auto aubCsr = aubExecutionEnvironment->template getCsr>(); - aubCsr->hardwareContext = std::unique_ptr(mockHardwareContext); - aubCsr->aubManager = mockManager.get(); + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); + MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + aubCsr.setupContext(osContext); + auto mockHardwareContext = static_cast(aubCsr.hardwareContextController->hardwareContexts[0].get()); MockGraphicsAllocation allocation(reinterpret_cast(0x1000), 0x1000); ResidencyContainer allocationsForResidency = {&allocation}; - aubCsr->processResidency(allocationsForResidency); + aubCsr.processResidency(allocationsForResidency); //call writeMemory on aubManager to clone page tables EXPECT_FALSE(mockHardwareContext->writeMemoryCalled); @@ -370,29 +394,33 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenMakeResidentIsCall } HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenExpectMemoryEqualIsCalledThenItShouldCallTheExpectedHwContextFunctions) { - auto mockManager = std::make_unique(); - auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); - auto aubExecutionEnvironment = getEnvironment>(true, true, true); - auto aubCsr = aubExecutionEnvironment->template getCsr>(); - aubCsr->hardwareContext = std::unique_ptr(mockHardwareContext); + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); + MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + aubCsr.setupContext(osContext); + auto mockHardwareContext = static_cast(aubCsr.hardwareContextController->hardwareContexts[0].get()); MockGraphicsAllocation allocation(reinterpret_cast(0x1000), 0x1000); - aubCsr->expectMemoryEqual(reinterpret_cast(0x1000), reinterpret_cast(0x1000), 0x1000); + aubCsr.expectMemoryEqual(reinterpret_cast(0x1000), reinterpret_cast(0x1000), 0x1000); EXPECT_TRUE(mockHardwareContext->expectMemoryCalled); } HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenExpectMemoryNotEqualIsCalledThenItShouldCallTheExpectedHwContextFunctions) { - auto mockManager = std::make_unique(); - auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); - auto aubExecutionEnvironment = getEnvironment>(true, true, true); - auto aubCsr = aubExecutionEnvironment->template getCsr>(); - aubCsr->hardwareContext = std::unique_ptr(mockHardwareContext); + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); + MockAubCsr aubCsr(**platformDevices, "", true, *pDevice->executionEnvironment); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + aubCsr.setupContext(osContext); + auto mockHardwareContext = static_cast(aubCsr.hardwareContextController->hardwareContexts[0].get()); MockGraphicsAllocation allocation(reinterpret_cast(0x1000), 0x1000); - aubCsr->expectMemoryNotEqual(reinterpret_cast(0x1000), reinterpret_cast(0x1000), 0x1000); + aubCsr.expectMemoryNotEqual(reinterpret_cast(0x1000), reinterpret_cast(0x1000), 0x1000); EXPECT_TRUE(mockHardwareContext->expectMemoryCalled); } diff --git a/unit_tests/command_stream/tbx_command_stream_tests.cpp b/unit_tests/command_stream/tbx_command_stream_tests.cpp index 51b40aa16d..50505fa9a6 100644 --- a/unit_tests/command_stream/tbx_command_stream_tests.cpp +++ b/unit_tests/command_stream/tbx_command_stream_tests.cpp @@ -10,6 +10,7 @@ #include "runtime/command_stream/tbx_command_stream_receiver_hw.h" #include "runtime/command_stream/command_stream_receiver_hw.h" #include "runtime/helpers/ptr_math.h" +#include "runtime/helpers/hardware_context_controller.h" #include "runtime/memory_manager/memory_banks.h" #include "runtime/os_interface/debug_settings_manager.h" #include "runtime/os_interface/os_context.h" @@ -340,20 +341,24 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenItIsCreatedWith } HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenFlushIsCalledThenItShouldCallTheExpectedHwContextFunctions) { - auto mockManager = std::make_unique(); - auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); + auto mockManager = static_cast(mockAubCenter->aubManager.get()); - auto tbxExecutionEnvironment = getEnvironment>(true, true); - auto tbxCsr = tbxExecutionEnvironment->template getCsr>(); - tbxCsr->hardwareContext = std::unique_ptr(mockHardwareContext); - tbxCsr->aubManager = mockManager.get(); + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); + MockTbxCsr tbxCsr(**platformDevices, *pDevice->executionEnvironment); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + tbxCsr.setupContext(osContext); + auto mockHardwareContext = static_cast(tbxCsr.hardwareContextController->hardwareContexts[0].get()); - LinearStream cs(tbxExecutionEnvironment->commandBuffer); + auto commandBuffer = pDevice->executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + + LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 1, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; MockGraphicsAllocation allocation(reinterpret_cast(0x1000), 0x1000); ResidencyContainer allocationsForResidency = {&allocation}; - tbxCsr->flush(batchBuffer, allocationsForResidency); + tbxCsr.flush(batchBuffer, allocationsForResidency); EXPECT_TRUE(mockHardwareContext->initializeCalled); EXPECT_TRUE(mockHardwareContext->submitCalled); @@ -362,61 +367,74 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenFlushIsCalledTh //call writeMemory on aubManager to clone page tables EXPECT_FALSE(mockHardwareContext->writeMemoryCalled); EXPECT_TRUE(mockManager->writeMemoryCalled); + pDevice->executionEnvironment->memoryManager->freeGraphicsMemory(commandBuffer); } HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverInBatchedModeWhenFlushIsCalledThenItShouldMakeCommandBufferResident) { DebugManagerStateRestore dbgRestore; DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::BatchedDispatch)); - auto mockManager = std::make_unique(); - auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); + auto mockManager = static_cast(mockAubCenter->aubManager.get()); - auto tbxExecutionEnvironment = getEnvironment>(true, true); - auto tbxCsr = tbxExecutionEnvironment->template getCsr>(); - tbxCsr->hardwareContext = std::unique_ptr(mockHardwareContext); - tbxCsr->aubManager = mockManager.get(); + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); + MockTbxCsr tbxCsr(**platformDevices, *pDevice->executionEnvironment); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + tbxCsr.setupContext(osContext); + auto mockHardwareContext = static_cast(tbxCsr.hardwareContextController->hardwareContexts[0].get()); - LinearStream cs(tbxExecutionEnvironment->commandBuffer); + auto commandBuffer = pDevice->executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + + LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 1, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; ResidencyContainer allocationsForResidency; - tbxCsr->flush(batchBuffer, allocationsForResidency); + tbxCsr.flush(batchBuffer, allocationsForResidency); //call writeMemory on aubManager to clone page tables EXPECT_FALSE(mockHardwareContext->writeMemoryCalled); EXPECT_TRUE(mockManager->writeMemoryCalled); - EXPECT_EQ(1u, batchBuffer.commandBufferAllocation->getResidencyTaskCount(tbxCsr->getOsContext().getContextId())); + EXPECT_EQ(1u, batchBuffer.commandBufferAllocation->getResidencyTaskCount(tbxCsr.getOsContext().getContextId())); + pDevice->executionEnvironment->memoryManager->freeGraphicsMemory(commandBuffer); } HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenFlushIsCalledWithZeroSizedBufferThenSubmitIsNotCalledOnHwContext) { - auto mockManager = std::make_unique(); - auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); - auto tbxExecutionEnvironment = getEnvironment>(true, true); - auto tbxCsr = tbxExecutionEnvironment->template getCsr>(); - tbxCsr->hardwareContext = std::unique_ptr(mockHardwareContext); + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); + MockTbxCsr tbxCsr(**platformDevices, *pDevice->executionEnvironment); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + tbxCsr.setupContext(osContext); + auto mockHardwareContext = static_cast(tbxCsr.hardwareContextController->hardwareContexts[0].get()); - LinearStream cs(tbxExecutionEnvironment->commandBuffer); + auto commandBuffer = pDevice->executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + + LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; ResidencyContainer allocationsForResidency; - tbxCsr->flush(batchBuffer, allocationsForResidency); + tbxCsr.flush(batchBuffer, allocationsForResidency); EXPECT_FALSE(mockHardwareContext->submitCalled); + pDevice->executionEnvironment->memoryManager->freeGraphicsMemory(commandBuffer); } HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenMakeResidentIsCalledThenItShouldCallTheExpectedHwContextFunctions) { - auto mockManager = std::make_unique(); - auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); + auto mockManager = static_cast(mockAubCenter->aubManager.get()); - auto tbxExecutionEnvironment = getEnvironment>(true, true); - auto tbxCsr = tbxExecutionEnvironment->template getCsr>(); - tbxCsr->hardwareContext = std::unique_ptr(mockHardwareContext); - tbxCsr->aubManager = mockManager.get(); + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); + MockTbxCsr tbxCsr(**platformDevices, *pDevice->executionEnvironment); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + tbxCsr.setupContext(osContext); + auto mockHardwareContext = static_cast(tbxCsr.hardwareContextController->hardwareContexts[0].get()); MockGraphicsAllocation allocation(reinterpret_cast(0x1000), 0x1000); ResidencyContainer allocationsForResidency = {&allocation}; - tbxCsr->processResidency(allocationsForResidency); + tbxCsr.processResidency(allocationsForResidency); //call writeMemory on aubManager to clone page tables EXPECT_FALSE(mockHardwareContext->writeMemoryCalled); @@ -424,15 +442,17 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenMakeResidentIsC } HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenMakeCoherentIsCalledThenItShouldCallTheExpectedHwContextFunctions) { - auto mockManager = std::make_unique(); - auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + MockAubCenter *mockAubCenter = new MockAubCenter(platformDevices[0], false, ""); + mockAubCenter->aubManager = std::make_unique(); - auto tbxExecutionEnvironment = getEnvironment>(true, true); - auto tbxCsr = tbxExecutionEnvironment->template getCsr>(); - tbxCsr->hardwareContext = std::unique_ptr(mockHardwareContext); + pDevice->executionEnvironment->aubCenter.reset(mockAubCenter); + MockTbxCsr tbxCsr(**platformDevices, *pDevice->executionEnvironment); + OsContext osContext(nullptr, 0, {EngineType::ENGINE_RCS, 0}, PreemptionMode::Disabled); + tbxCsr.setupContext(osContext); + auto mockHardwareContext = static_cast(tbxCsr.hardwareContextController->hardwareContexts[0].get()); MockGraphicsAllocation allocation(reinterpret_cast(0x1000), 0x1000); - tbxCsr->makeCoherent(allocation); + tbxCsr.makeCoherent(allocation); EXPECT_TRUE(mockHardwareContext->readMemoryCalled); } @@ -460,8 +480,8 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenOsContextIsSetThenCreateHardwareC executionEnvironment.aubCenter = std::unique_ptr(mockAubCenter); std::unique_ptr> tbxCsr(reinterpret_cast *>(TbxCommandStreamReceiver::create(*platformDevices[0], fileName, true, executionEnvironment))); - EXPECT_EQ(nullptr, tbxCsr->hardwareContext.get()); + EXPECT_EQ(nullptr, tbxCsr->hardwareContextController.get()); tbxCsr->setupContext(osContext); - EXPECT_NE(nullptr, tbxCsr->hardwareContext.get()); + EXPECT_NE(nullptr, tbxCsr->hardwareContextController.get()); }