From 5a8f455a84c6dae3ca6a1dae7cb24b1f49a73d20 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Tue, 5 Nov 2019 13:38:20 +0100 Subject: [PATCH] Remove csrsContainer from root device environment improve mocking: - add method to create RootDevice in Platform - add method to create SubDevice in RootDevice - add method to create CommandStreamReceiver in Device Related-To: NEO-3691 Change-Id: Ie9fe3de260492604333c8ca93796bfbffae518c4 Signed-off-by: Mateusz Jablonski --- .../root_device_environment.cpp | 1 - .../root_device_environment.h | 3 +- core/helpers/common_types.h | 2 - runtime/device/CMakeLists.txt | 1 + runtime/device/device.cpp | 25 +++-- runtime/device/device.h | 8 +- runtime/device/root_device.cpp | 20 ++-- runtime/device/root_device.h | 8 +- runtime/device/root_device_initialize.cpp | 15 +++ runtime/device/sub_device.cpp | 2 +- runtime/device/sub_device.h | 2 +- runtime/execution_environment/CMakeLists.txt | 1 - .../execution_environment.cpp | 22 ----- .../execution_environment.h | 4 +- .../execution_environment_initialize.cpp | 15 --- runtime/platform/platform.cpp | 6 +- runtime/platform/platform.h | 2 + unit_tests/aub_tests/fixtures/aub_fixture.h | 2 - .../aub_command_stream_receiver_2_tests.cpp | 2 +- .../command_stream/aub_file_stream_tests.cpp | 10 +- ...and_stream_receiver_flush_task_3_tests.cpp | 4 +- .../command_stream_receiver_tests.cpp | 18 ++-- .../create_command_stream_receiver_tests.cpp | 7 +- unit_tests/device/device_tests.cpp | 46 ++++++++-- unit_tests/device/sub_device_tests.cpp | 58 ++++-------- .../execution_environment_tests.cpp | 92 ++----------------- unit_tests/fixtures/buffer_enqueue_fixture.h | 6 +- unit_tests/fixtures/dispatch_flags_fixture.h | 5 +- .../fixtures/memory_allocator_fixture.h | 12 ++- .../fixtures/memory_manager_fixture.cpp | 6 +- unit_tests/fixtures/memory_manager_fixture.h | 2 +- unit_tests/gen11/hw_helper_tests_gen11.cpp | 2 +- .../gen12lp/hw_helper_tests_gen12lp.cpp | 2 +- unit_tests/gen8/hw_helper_tests_gen8.cpp | 2 +- unit_tests/gen9/hw_helper_tests_gen9.cpp | 2 +- .../deferrable_allocation_deletion_tests.cpp | 2 +- .../memory_manager/host_ptr_manager_tests.cpp | 5 +- .../internal_allocation_storage_tests.cpp | 1 - .../memory_manager/memory_manager_tests.cpp | 4 +- unit_tests/memory_manager/surface_tests.cpp | 6 +- unit_tests/mocks/mock_aub_csr.h | 13 +-- unit_tests/mocks/mock_device.cpp | 22 ++--- unit_tests/mocks/mock_device.h | 54 ++++++++++- unit_tests/mocks/mock_execution_environment.h | 21 ----- .../linux/drm_command_stream_fixture.h | 4 +- .../linux/drm_memory_manager_tests.cpp | 8 +- .../windows/device_command_stream_tests.cpp | 18 ++-- .../windows/wddm_memory_manager_tests.cpp | 8 +- unit_tests/preemption/preemption_tests.cpp | 8 +- ...d_write_buffer_scenarios_windows_tests.cpp | 7 +- .../source_level_debugger_csr_tests.cpp | 8 +- 51 files changed, 253 insertions(+), 351 deletions(-) create mode 100644 runtime/device/root_device_initialize.cpp delete mode 100644 runtime/execution_environment/execution_environment_initialize.cpp diff --git a/core/execution_environment/root_device_environment.cpp b/core/execution_environment/root_device_environment.cpp index e43d94f5e1..d818e48170 100644 --- a/core/execution_environment/root_device_environment.cpp +++ b/core/execution_environment/root_device_environment.cpp @@ -8,7 +8,6 @@ #include "core/execution_environment/root_device_environment.h" #include "runtime/aub/aub_center.h" -#include "runtime/command_stream/command_stream_receiver.h" namespace NEO { diff --git a/core/execution_environment/root_device_environment.h b/core/execution_environment/root_device_environment.h index 5dd31b9dd5..8ccc9dbeb9 100644 --- a/core/execution_environment/root_device_environment.h +++ b/core/execution_environment/root_device_environment.h @@ -6,7 +6,7 @@ */ #pragma once -#include "core/helpers/common_types.h" +#include namespace NEO { @@ -18,6 +18,5 @@ struct RootDeviceEnvironment { RootDeviceEnvironment(RootDeviceEnvironment &&); ~RootDeviceEnvironment(); std::unique_ptr aubCenter; - CsrContainer commandStreamReceivers; }; } // namespace NEO diff --git a/core/helpers/common_types.h b/core/helpers/common_types.h index b2533c4f35..096aed2d58 100644 --- a/core/helpers/common_types.h +++ b/core/helpers/common_types.h @@ -10,9 +10,7 @@ #include #include namespace NEO { -class CommandStreamReceiver; struct EngineControl; -using CsrContainer = std::vector>>; using EngineControlContainer = std::vector; using DeviceBitfield = std::bitset<32>; } // namespace NEO \ No newline at end of file diff --git a/runtime/device/CMakeLists.txt b/runtime/device/CMakeLists.txt index 909345f40c..96fa388f10 100644 --- a/runtime/device/CMakeLists.txt +++ b/runtime/device/CMakeLists.txt @@ -16,6 +16,7 @@ set(RUNTIME_SRCS_DEVICE ${CMAKE_CURRENT_SOURCE_DIR}/driver_info.h ${CMAKE_CURRENT_SOURCE_DIR}/root_device.cpp ${CMAKE_CURRENT_SOURCE_DIR}/root_device.h + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/root_device_initialize.cpp ${CMAKE_CURRENT_SOURCE_DIR}/sub_device.cpp ${CMAKE_CURRENT_SOURCE_DIR}/sub_device.h ) diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index 133ca182ee..c985794c6d 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -23,6 +23,7 @@ namespace NEO { decltype(&PerformanceCounters::create) Device::createPerformanceCountersFunc = PerformanceCounters::create; +extern CommandStreamReceiver *createCommandStream(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex); DeviceVector::DeviceVector(const cl_device_id *devices, cl_uint numDevices) { @@ -41,8 +42,8 @@ void DeviceVector::toDeviceIDs(std::vector &devIDs) { } } -Device::Device(ExecutionEnvironment *executionEnvironment, uint32_t internalDeviceIndex) - : executionEnvironment(executionEnvironment), internalDeviceIndex(internalDeviceIndex) { +Device::Device(ExecutionEnvironment *executionEnvironment) + : executionEnvironment(executionEnvironment) { memset(&deviceInfo, 0, sizeof(deviceInfo)); deviceExtensions.reserve(1000); name.reserve(100); @@ -70,7 +71,7 @@ Device::~Device() { if (deviceInfo.sourceLevelDebuggerActive && executionEnvironment->sourceLevelDebugger) { executionEnvironment->sourceLevelDebugger->notifyDeviceDestruction(); } - + commandStreamReceivers.clear(); executionEnvironment->memoryManager->waitForDeletions(); executionEnvironment->decRefInternal(); } @@ -132,18 +133,24 @@ bool Device::createEngines() { return true; } +std::unique_ptr Device::createCommandStreamReceiver() const { + return std::unique_ptr(createCommandStream(*executionEnvironment, getRootDeviceIndex())); +} + bool Device::createEngine(uint32_t deviceCsrIndex, aub_stream::EngineType engineType) { auto &hwInfo = getHardwareInfo(); auto defaultEngineType = getChosenEngineType(hwInfo); - if (!executionEnvironment->initializeCommandStreamReceiver(getRootDeviceIndex(), internalDeviceIndex, deviceCsrIndex)) { + std::unique_ptr commandStreamReceiver = createCommandStreamReceiver(); + if (!commandStreamReceiver) { return false; } - - auto commandStreamReceiver = executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()].commandStreamReceivers[internalDeviceIndex][deviceCsrIndex].get(); + if (HwHelper::get(hwInfo.platform.eRenderCoreFamily).isPageTableManagerSupported(hwInfo)) { + commandStreamReceiver->createPageTableManager(); + } bool lowPriority = (deviceCsrIndex == HwHelper::lowPriorityGpgpuEngineIndex); - auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(commandStreamReceiver, engineType, + auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(commandStreamReceiver.get(), engineType, getDeviceBitfieldForOsContext(), preemptionMode, lowPriority); commandStreamReceiver->setupContext(*osContext); @@ -158,7 +165,8 @@ bool Device::createEngine(uint32_t deviceCsrIndex, aub_stream::EngineType engine return false; } - engines.push_back({commandStreamReceiver, osContext}); + engines.push_back({commandStreamReceiver.get(), osContext}); + commandStreamReceivers.push_back(std::move(commandStreamReceiver)); return true; } @@ -219,4 +227,5 @@ EngineControl &Device::getEngine(aub_stream::EngineType engineType, bool lowPrio } UNRECOVERABLE_IF(true); } + } // namespace NEO diff --git a/runtime/device/device.h b/runtime/device/device.h index 814a04895a..55c4e5a1c5 100644 --- a/runtime/device/device.h +++ b/runtime/device/device.h @@ -99,13 +99,10 @@ class Device : public BaseObject<_cl_device_id> { } virtual uint32_t getNumAvailableDevices() const = 0; virtual Device *getDeviceById(uint32_t deviceId) const = 0; - uint32_t getInternalDeviceIndex() const { - return internalDeviceIndex; - } protected: Device() = delete; - Device(ExecutionEnvironment *executionEnvironment, uint32_t internalDeviceIndex); + Device(ExecutionEnvironment *executionEnvironment); template static T *createDeviceInternals(T *device) { @@ -121,6 +118,7 @@ class Device : public BaseObject<_cl_device_id> { virtual bool createEngines(); bool createEngine(uint32_t deviceCsrIndex, aub_stream::EngineType engineType); + MOCKABLE_VIRTUAL std::unique_ptr createCommandStreamReceiver() const; MOCKABLE_VIRTUAL void initializeCaps(); void setupFp64Flags(); void appendOSExtensions(std::string &deviceExtensions); @@ -132,13 +130,13 @@ class Device : public BaseObject<_cl_device_id> { std::unique_ptr driverInfo; std::unique_ptr performanceCounters; + std::vector> commandStreamReceivers; std::vector engines; std::string exposedBuiltinKernels = ""; PreemptionMode preemptionMode; ExecutionEnvironment *executionEnvironment = nullptr; - const uint32_t internalDeviceIndex; uint32_t defaultEngineIndex = 0; }; diff --git a/runtime/device/root_device.cpp b/runtime/device/root_device.cpp index 1163254385..1cd4914e1d 100644 --- a/runtime/device/root_device.cpp +++ b/runtime/device/root_device.cpp @@ -12,6 +12,7 @@ #include "runtime/os_interface/debug_settings_manager.h" namespace NEO { +RootDevice::RootDevice(ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex) : Device(executionEnvironment), rootDeviceIndex(rootDeviceIndex) {} RootDevice::~RootDevice() = default; @@ -38,7 +39,10 @@ Device *RootDevice::getDeviceById(uint32_t deviceId) const { return subdevices[deviceId].get(); }; -RootDevice::RootDevice(ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex) : Device(executionEnvironment, 0u), rootDeviceIndex(rootDeviceIndex) {} +SubDevice *RootDevice::createSubDevice(uint32_t subDeviceIndex) { + return Device::create(executionEnvironment, subDeviceIndex, *this); +} + bool RootDevice::createDeviceImpl() { auto numSubDevices = DeviceHelper::getSubDevicesCount(&getHardwareInfo()); if (numSubDevices == 1) { @@ -47,7 +51,7 @@ bool RootDevice::createDeviceImpl() { subdevices.resize(numSubDevices); for (auto i = 0u; i < numSubDevices; i++) { - auto subDevice = Device::create(executionEnvironment, i + 1, i, *this); + auto subDevice = createSubDevice(i); if (!subDevice) { return false; } @@ -71,22 +75,14 @@ unique_ptr_if_unused RootDevice::release() { } DeviceBitfield RootDevice::getDeviceBitfieldForOsContext() const { DeviceBitfield deviceBitfield; - deviceBitfield.set(internalDeviceIndex); + deviceBitfield.set(0); return deviceBitfield; } bool RootDevice::createEngines() { - if (!executionEnvironment->initializeRootCommandStreamReceiver(*this)) { + if (!initializeRootCommandStreamReceiver()) { return Device::createEngines(); } return true; } - -void RootDevice::setupRootEngine(EngineControl engine) { - if (engines.size() > 0u) { - return; - } - defaultEngineIndex = 0; - engines.emplace_back(engine); -} } // namespace NEO diff --git a/runtime/device/root_device.h b/runtime/device/root_device.h index b8942cd991..78cb26fab6 100644 --- a/runtime/device/root_device.h +++ b/runtime/device/root_device.h @@ -18,17 +18,21 @@ class RootDevice : public Device { ~RootDevice() override; bool createDeviceImpl() override; uint32_t getNumAvailableDevices() const override; - uint32_t getNumSubDevices() const; uint32_t getRootDeviceIndex() const override; Device *getDeviceById(uint32_t deviceId) const override; /* We hide the retain and release function of BaseObject. */ void retain() override; unique_ptr_if_unused release() override; - void setupRootEngine(EngineControl engineControl); + + uint32_t getNumSubDevices() const; protected: DeviceBitfield getDeviceBitfieldForOsContext() const override; bool createEngines() override; + + MOCKABLE_VIRTUAL bool initializeRootCommandStreamReceiver(); + MOCKABLE_VIRTUAL SubDevice *createSubDevice(uint32_t subDeviceIndex); + std::vector> subdevices; const uint32_t rootDeviceIndex; }; diff --git a/runtime/device/root_device_initialize.cpp b/runtime/device/root_device_initialize.cpp new file mode 100644 index 0000000000..58227e9959 --- /dev/null +++ b/runtime/device/root_device_initialize.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/device/root_device.h" + +namespace NEO { +bool RootDevice::initializeRootCommandStreamReceiver() { + return false; +} + +} // namespace NEO diff --git a/runtime/device/sub_device.cpp b/runtime/device/sub_device.cpp index 32790130cf..04785ce4d7 100644 --- a/runtime/device/sub_device.cpp +++ b/runtime/device/sub_device.cpp @@ -11,7 +11,7 @@ namespace NEO { -SubDevice::SubDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex, uint32_t subDeviceIndex, RootDevice &rootDevice) : Device(executionEnvironment, deviceIndex), subDeviceIndex(subDeviceIndex), rootDevice(rootDevice) {} +SubDevice::SubDevice(ExecutionEnvironment *executionEnvironment, uint32_t subDeviceIndex, RootDevice &rootDevice) : Device(executionEnvironment), subDeviceIndex(subDeviceIndex), rootDevice(rootDevice) {} void SubDevice::retain() { rootDevice.incRefInternal(); Device::retain(); diff --git a/runtime/device/sub_device.h b/runtime/device/sub_device.h index a0a17ef486..2dec0768d9 100644 --- a/runtime/device/sub_device.h +++ b/runtime/device/sub_device.h @@ -12,7 +12,7 @@ namespace NEO { class RootDevice; class SubDevice : public Device { public: - SubDevice(ExecutionEnvironment *executionEnvironment, uint32_t internalDeviceIndex, uint32_t subDeviceIndex, RootDevice &rootDevice); + SubDevice(ExecutionEnvironment *executionEnvironment, uint32_t subDeviceIndex, RootDevice &rootDevice); void retain() override; unique_ptr_if_unused release() override; void retainInternal(); diff --git a/runtime/execution_environment/CMakeLists.txt b/runtime/execution_environment/CMakeLists.txt index 5417f66858..52c1c499c1 100644 --- a/runtime/execution_environment/CMakeLists.txt +++ b/runtime/execution_environment/CMakeLists.txt @@ -8,7 +8,6 @@ set(RUNTIME_SRCS_EXECUTION_ENVIRONMENT ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/execution_environment.h ${CMAKE_CURRENT_SOURCE_DIR}/execution_environment.cpp - ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/execution_environment_initialize.cpp ) get_property(NEO_CORE_EXECUTION_ENVIRONMENT GLOBAL PROPERTY NEO_CORE_EXECUTION_ENVIRONMENT) diff --git a/runtime/execution_environment/execution_environment.cpp b/runtime/execution_environment/execution_environment.cpp index 39c2ed0a0b..5cb0ae51d6 100644 --- a/runtime/execution_environment/execution_environment.cpp +++ b/runtime/execution_environment/execution_environment.cpp @@ -31,7 +31,6 @@ ExecutionEnvironment::~ExecutionEnvironment() { builtins.reset(); rootDeviceEnvironments.clear(); } -extern CommandStreamReceiver *createCommandStream(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex); void ExecutionEnvironment::initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType) { if (!rootDeviceEnvironments[0].aubCenter) { @@ -46,27 +45,6 @@ void ExecutionEnvironment::initGmm() { void ExecutionEnvironment::setHwInfo(const HardwareInfo *hwInfo) { *this->hwInfo = *hwInfo; } -bool ExecutionEnvironment::initializeCommandStreamReceiver(uint32_t rootDeviceIndex, uint32_t internalDeviceIndex, uint32_t deviceCsrIndex) { - if (internalDeviceIndex + 1 > rootDeviceEnvironments[rootDeviceIndex].commandStreamReceivers.size()) { - rootDeviceEnvironments[rootDeviceIndex].commandStreamReceivers.resize(internalDeviceIndex + 1); - } - - if (deviceCsrIndex + 1 > rootDeviceEnvironments[rootDeviceIndex].commandStreamReceivers[internalDeviceIndex].size()) { - rootDeviceEnvironments[rootDeviceIndex].commandStreamReceivers[internalDeviceIndex].resize(deviceCsrIndex + 1); - } - if (this->rootDeviceEnvironments[rootDeviceIndex].commandStreamReceivers[internalDeviceIndex][deviceCsrIndex]) { - return true; - } - std::unique_ptr commandStreamReceiver(createCommandStream(*this, rootDeviceIndex)); - if (!commandStreamReceiver) { - return false; - } - if (HwHelper::get(hwInfo->platform.eRenderCoreFamily).isPageTableManagerSupported(*hwInfo)) { - commandStreamReceiver->createPageTableManager(); - } - this->rootDeviceEnvironments[rootDeviceIndex].commandStreamReceivers[internalDeviceIndex][deviceCsrIndex] = std::move(commandStreamReceiver); - return true; -} void ExecutionEnvironment::initializeMemoryManager() { if (this->memoryManager) { return; diff --git a/runtime/execution_environment/execution_environment.h b/runtime/execution_environment/execution_environment.h index bf4edadf51..a92e4cf5be 100644 --- a/runtime/execution_environment/execution_environment.h +++ b/runtime/execution_environment/execution_environment.h @@ -12,10 +12,10 @@ #include "runtime/os_interface/device_factory.h" #include +#include namespace NEO { class BuiltIns; -class CommandStreamReceiver; class CompilerInterface; class GmmHelper; class MemoryManager; @@ -40,8 +40,6 @@ class ExecutionEnvironment : public ReferenceTrackedObject MOCKABLE_VIRTUAL void initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType); void initGmm(); - bool initializeCommandStreamReceiver(uint32_t rootDeviceIndex, uint32_t internalDeviceIndex, uint32_t deviceCsrIndex); - MOCKABLE_VIRTUAL bool initializeRootCommandStreamReceiver(RootDevice &rootDevice); void initializeMemoryManager(); void initSourceLevelDebugger(); void setHwInfo(const HardwareInfo *hwInfo); diff --git a/runtime/execution_environment/execution_environment_initialize.cpp b/runtime/execution_environment/execution_environment_initialize.cpp deleted file mode 100644 index 2e72d0945b..0000000000 --- a/runtime/execution_environment/execution_environment_initialize.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) 2019 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "runtime/execution_environment/execution_environment.h" - -namespace NEO { -bool ExecutionEnvironment::initializeRootCommandStreamReceiver(RootDevice &device) { - return false; -} - -} // namespace NEO diff --git a/runtime/platform/platform.cpp b/runtime/platform/platform.cpp index a294e22321..3694cafd7f 100644 --- a/runtime/platform/platform.cpp +++ b/runtime/platform/platform.cpp @@ -147,7 +147,7 @@ bool Platform::initialize() { this->devices.resize(numDevicesReturned); for (uint32_t deviceOrdinal = 0; deviceOrdinal < numDevicesReturned; ++deviceOrdinal) { - auto pDevice = Device::create(executionEnvironment, deviceOrdinal); + auto pDevice = createRootDevice(deviceOrdinal); DEBUG_BREAK_IF(!pDevice); if (pDevice) { this->devices[deviceOrdinal] = pDevice; @@ -249,4 +249,8 @@ std::unique_ptr Platform::setAsyncEventsHandler(std::unique_ return handler; } +RootDevice *Platform::createRootDevice(uint32_t rootDeviceIndex) const { + return Device::create(executionEnvironment, rootDeviceIndex); +} + } // namespace NEO diff --git a/runtime/platform/platform.h b/runtime/platform/platform.h index 56a2694c4c..8fac750f10 100644 --- a/runtime/platform/platform.h +++ b/runtime/platform/platform.h @@ -18,6 +18,7 @@ namespace NEO { class CompilerInterface; +class RootDevice; class Device; class AsyncEventsHandler; class ExecutionEnvironment; @@ -66,6 +67,7 @@ class Platform : public BaseObject<_cl_platform_id> { cl_uint state = StateNone; void fillGlobalDispatchTable(); MOCKABLE_VIRTUAL void initializationLoopHelper(){}; + MOCKABLE_VIRTUAL RootDevice *createRootDevice(uint32_t rootDeviceIndex) const; std::unique_ptr platformInfo; DeviceVector devices; std::string compilerExtensions; diff --git a/unit_tests/aub_tests/fixtures/aub_fixture.h b/unit_tests/aub_tests/fixtures/aub_fixture.h index ddcd93d2a2..46985bd7ea 100644 --- a/unit_tests/aub_tests/fixtures/aub_fixture.h +++ b/unit_tests/aub_tests/fixtures/aub_fixture.h @@ -43,8 +43,6 @@ class AUBFixture : public CommandQueueHwFixture { this->csr = AUBCommandStreamReceiver::create(strfilename.str(), true, *executionEnvironment, 0); } - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.resize(deviceIndex + 1); - device.reset(MockDevice::create(executionEnvironment, deviceIndex)); device->resetCommandStreamReceiver(this->csr); 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 29c8b164da..c6779cbfd5 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 @@ -839,7 +839,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrWhenAskedForMemoryExpectation auto mockStream = std::make_unique(); MyMockAubCsr myMockCsr(std::string(), true, *pDevice->getExecutionEnvironment(), pDevice->getRootDeviceIndex()); - myMockCsr.setupContext(pDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->getOsContext()); + myMockCsr.setupContext(pDevice->commandStreamReceivers[0]->getOsContext()); myMockCsr.stream = mockStream.get(); myMockCsr.expectMemoryNotEqual(mockAddress, mockAddress, 1); diff --git a/unit_tests/command_stream/aub_file_stream_tests.cpp b/unit_tests/command_stream/aub_file_stream_tests.cpp index 5b5a243e97..d6e50baee2 100644 --- a/unit_tests/command_stream/aub_file_stream_tests.cpp +++ b/unit_tests/command_stream/aub_file_stream_tests.cpp @@ -359,7 +359,7 @@ HWTEST_F(AubFileStreamTests, givenNewTaskSinceLastPollWhenDeletingAubCsrThenCall aubCsr->pollForCompletionTaskCount = 49; ASSERT_FALSE(aubStream->registerPollCalled); - aubExecutionEnvironment->executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0].reset(); + aubExecutionEnvironment->commandStreamReceiver.reset(); EXPECT_TRUE(aubStream->registerPollCalled); } @@ -373,7 +373,7 @@ HWTEST_F(AubFileStreamTests, givenNoNewTaskSinceLastPollWhenDeletingAubCsrThenDo aubCsr->pollForCompletionTaskCount = 50; ASSERT_FALSE(aubStream->registerPollCalled); - aubExecutionEnvironment->executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0].reset(); + aubExecutionEnvironment->commandStreamReceiver.reset(); EXPECT_FALSE(aubStream->registerPollCalled); } @@ -666,7 +666,7 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenF HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenExpectMemoryIsCalledThenPageWalkIsCallingStreamsExpectMemory) { auto mockAubFileStream = std::make_unique(); auto aubCsr = std::make_unique>("", true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()); - aubCsr->setupContext(pDevice->executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->getOsContext()); + aubCsr->setupContext(pDevice->commandStreamReceivers[0]->getOsContext()); aubCsr->stream = mockAubFileStream.get(); @@ -689,7 +689,7 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWithoutAubManagerWhenE aubCsr->aubManager = nullptr; aubCsr->stream = mockAubFileStream.get(); - aubCsr->setupContext(pDevice->executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->getOsContext()); + aubCsr->setupContext(pDevice->commandStreamReceivers[0]->getOsContext()); aubCsr->initFile(fileName); aubCsr->expectMMIO(5, 10); @@ -705,7 +705,7 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWithAubManagerWhenExpe auto aubCsr = std::make_unique>(fileName.c_str(), true, *pDevice->executionEnvironment, pDevice->getRootDeviceIndex()); aubCsr->stream = mockAubFileStream.get(); - aubCsr->setupContext(pDevice->executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->getOsContext()); + aubCsr->setupContext(pDevice->commandStreamReceivers[0]->getOsContext()); aubCsr->initFile(fileName); aubCsr->expectMMIO(5, 10); diff --git a/unit_tests/command_stream/command_stream_receiver_flush_task_3_tests.cpp b/unit_tests/command_stream/command_stream_receiver_flush_task_3_tests.cpp index 20bb79bc32..71856ebf24 100644 --- a/unit_tests/command_stream/command_stream_receiver_flush_task_3_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_flush_task_3_tests.cpp @@ -670,9 +670,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTotalRes ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); auto mockedMemoryManager = new MockedMemoryManager(*executionEnvironment); executionEnvironment->memoryManager.reset(mockedMemoryManager); - auto mockCsr = new MockCsrHw2(*executionEnvironment, 0); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.resize(1); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::unique_ptr(mockCsr)); + auto mockCsr = std::make_unique>(*executionEnvironment, 0); if (pDevice->getPreemptionMode() == PreemptionMode::MidThread || pDevice->isSourceLevelDebuggerActive()) { mockCsr->createPreemptionAllocation(); diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index de78700f61..f34bbe8a39 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -300,21 +300,17 @@ TEST(CommandStreamReceiverSimpleTest, givenCommandStreamReceiverWhenItIsDestroye auto mockGraphicsAllocation = new MockGraphicsAllocationWithDestructorTracing(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0llu, 0llu, 1u, MemoryPool::MemoryNull); mockGraphicsAllocation->destructorCalled = &destructorCalled; MockExecutionEnvironment executionEnvironment(*platformDevices); - executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers.resize(1); - executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::make_unique(executionEnvironment, 0)); - auto csr = executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers[0][0].get(); + auto csr = std::make_unique(executionEnvironment, 0); executionEnvironment.memoryManager.reset(new OsAgnosticMemoryManager(executionEnvironment)); csr->setTagAllocation(mockGraphicsAllocation); EXPECT_FALSE(destructorCalled); - executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers[0][0].reset(nullptr); + csr.reset(nullptr); EXPECT_TRUE(destructorCalled); } TEST(CommandStreamReceiverSimpleTest, givenCommandStreamReceiverWhenInitializeTagAllocationIsCalledThenTagAllocationIsBeingAllocated) { MockExecutionEnvironment executionEnvironment(*platformDevices); - auto csr = new MockCommandStreamReceiver(executionEnvironment, 0); - executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers.resize(1); - executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::unique_ptr(csr)); + auto csr = std::make_unique(executionEnvironment, 0); executionEnvironment.memoryManager.reset(new OsAgnosticMemoryManager(executionEnvironment)); EXPECT_EQ(nullptr, csr->getTagAllocation()); EXPECT_TRUE(csr->getTagAddress() == nullptr); @@ -329,9 +325,7 @@ TEST(CommandStreamReceiverSimpleTest, givenNullHardwareDebugModeWhenInitializeTa DebugManagerStateRestore dbgRestore; DebugManager.flags.EnableNullHardware.set(true); MockExecutionEnvironment executionEnvironment(*platformDevices); - executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers.resize(1); - auto csr = new MockCommandStreamReceiver(executionEnvironment, 0); - executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::unique_ptr(csr)); + auto csr = std::make_unique(executionEnvironment, 0); executionEnvironment.memoryManager.reset(new OsAgnosticMemoryManager(executionEnvironment)); EXPECT_EQ(nullptr, csr->getTagAllocation()); EXPECT_TRUE(csr->getTagAddress() == nullptr); @@ -371,8 +365,8 @@ TEST(CommandStreamReceiverMultiContextTests, givenMultipleCsrsWhenSameResourcesA std::unique_ptr device(Device::create(executionEnvironment, 0u)); - auto &commandStreamReceiver0 = *executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]; - auto &commandStreamReceiver1 = *executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][1]; + auto &commandStreamReceiver0 = *device->commandStreamReceivers[0]; + auto &commandStreamReceiver1 = *device->commandStreamReceivers[1]; auto csr0ContextId = commandStreamReceiver0.getOsContext().getContextId(); auto csr1ContextId = commandStreamReceiver1.getOsContext().getContextId(); diff --git a/unit_tests/command_stream/create_command_stream_receiver_tests.cpp b/unit_tests/command_stream/create_command_stream_receiver_tests.cpp index e132169609..b5d590fb5b 100644 --- a/unit_tests/command_stream/create_command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/create_command_stream_receiver_tests.cpp @@ -31,13 +31,12 @@ HWTEST_P(CreateCommandStreamReceiverTest, givenCreateCommandStreamWhenCsrIsSetTo VariableBackup backup(&overrideCommandStreamReceiverCreation, true); DebugManager.flags.SetCommandStreamReceiver.set(csrType); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.resize(1); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::unique_ptr(createCommandStream(*executionEnvironment, 0))); + auto csr = std::unique_ptr(createCommandStream(*executionEnvironment, 0)); if (csrType < CommandStreamReceiverType::CSR_TYPES_NUM) { - EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0].get()); + EXPECT_NE(nullptr, csr.get()); } else { - EXPECT_EQ(nullptr, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]); + EXPECT_EQ(nullptr, csr.get()); } EXPECT_NE(nullptr, executionEnvironment->memoryManager.get()); } diff --git a/unit_tests/device/device_tests.cpp b/unit_tests/device/device_tests.cpp index 6f7af68465..fe30d6acee 100644 --- a/unit_tests/device/device_tests.cpp +++ b/unit_tests/device/device_tests.cpp @@ -15,6 +15,7 @@ #include "runtime/platform/platform.h" #include "test.h" #include "unit_tests/fixtures/device_fixture.h" +#include "unit_tests/helpers/unit_test_helper.h" #include "unit_tests/helpers/variable_backup.h" #include "unit_tests/libult/create_command_stream.h" #include "unit_tests/libult/ult_command_stream_receiver.h" @@ -171,12 +172,12 @@ TEST(DeviceCreation, givenDefaultHwCsrInDebugVarsWhenDeviceIsCreatedThenIsSimula } TEST(DeviceCreation, givenDeviceWhenItIsCreatedThenOsContextIsRegistredInMemoryManager) { - auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); auto memoryManager = device->getMemoryManager(); auto numEnginesForDevice = HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances().size(); if (device->getNumAvailableDevices() > 1) { numEnginesForDevice *= device->getNumAvailableDevices(); - numEnginesForDevice += device->getExecutionEnvironment()->rootDeviceEnvironments[0].commandStreamReceivers[0].size(); + numEnginesForDevice += device->engines.size(); } EXPECT_EQ(numEnginesForDevice, memoryManager->getRegisteredEnginesCount()); } @@ -226,16 +227,11 @@ TEST(DeviceCreation, givenMultiRootDeviceWhenTheyAreCreatedThenEachDeviceHasSepe auto device1 = std::unique_ptr(Device::create(executionEnvironment, 0u)); auto device2 = std::unique_ptr(Device::create(executionEnvironment, 1u)); - EXPECT_EQ(1u, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.size()); - EXPECT_EQ(1u, executionEnvironment->rootDeviceEnvironments[1].commandStreamReceivers.size()); - EXPECT_EQ(numGpgpuEngines, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0].size()); - EXPECT_EQ(numGpgpuEngines, executionEnvironment->rootDeviceEnvironments[1].commandStreamReceivers[0].size()); + EXPECT_EQ(numGpgpuEngines, device1->commandStreamReceivers.size()); + EXPECT_EQ(numGpgpuEngines, device2->commandStreamReceivers.size()); for (uint32_t i = 0; i < static_cast(numGpgpuEngines); i++) { - EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][i]); - EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[1].commandStreamReceivers[0][i]); - EXPECT_EQ(executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][i].get(), device1->engines[i].commandStreamReceiver); - EXPECT_EQ(executionEnvironment->rootDeviceEnvironments[1].commandStreamReceivers[0][i].get(), device2->engines[i].commandStreamReceiver); + EXPECT_NE(device2->engines[i].commandStreamReceiver, device1->engines[i].commandStreamReceiver); } } @@ -263,3 +259,33 @@ TEST(DeviceCreation, givenDeviceWhenCheckingEnginesCountThenNumberGreaterThanZer auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); EXPECT_GT(DeviceHelper::getEnginesCount(device->getHardwareInfo()), 0u); } + +using DeviceHwTest = ::testing::Test; + +HWTEST_F(DeviceHwTest, givenHwHelperInputWhenInitializingCsrThenCreatePageTableManagerIfAllowed) { + HardwareInfo localHwInfo = *platformDevices[0]; + localHwInfo.capabilityTable.ftrRenderCompressedBuffers = false; + localHwInfo.capabilityTable.ftrRenderCompressedImages = false; + + ExecutionEnvironment executionEnvironment; + executionEnvironment.incRefInternal(); + executionEnvironment.initializeMemoryManager(); + executionEnvironment.setHwInfo(&localHwInfo); + std::unique_ptr device; + device.reset(MockDevice::createWithExecutionEnvironment(&localHwInfo, &executionEnvironment, 0)); + auto &csr0 = device->getUltCommandStreamReceiver(); + EXPECT_FALSE(csr0.createPageTableManagerCalled); + + auto hwInfo = executionEnvironment.getMutableHardwareInfo(); + hwInfo->capabilityTable.ftrRenderCompressedBuffers = true; + hwInfo->capabilityTable.ftrRenderCompressedImages = false; + device.reset(MockDevice::createWithExecutionEnvironment(&localHwInfo, &executionEnvironment, 0)); + auto &csr1 = device->getUltCommandStreamReceiver(); + EXPECT_EQ(UnitTestHelper::isPageTableManagerSupported(*hwInfo), csr1.createPageTableManagerCalled); + + hwInfo->capabilityTable.ftrRenderCompressedBuffers = false; + hwInfo->capabilityTable.ftrRenderCompressedImages = true; + device.reset(MockDevice::createWithExecutionEnvironment(&localHwInfo, &executionEnvironment, 0)); + auto &csr2 = device->getUltCommandStreamReceiver(); + EXPECT_EQ(UnitTestHelper::isPageTableManagerSupported(*hwInfo), csr2.createPageTableManagerCalled); +} diff --git a/unit_tests/device/sub_device_tests.cpp b/unit_tests/device/sub_device_tests.cpp index a167aed894..635f6c1d66 100644 --- a/unit_tests/device/sub_device_tests.cpp +++ b/unit_tests/device/sub_device_tests.cpp @@ -29,16 +29,13 @@ TEST(SubDevicesTest, givenCreateMultipleSubDevicesFlagSetWhenCreateRootDeviceThe auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(*platformDevices)); EXPECT_EQ(2u, device->getNumSubDevices()); - EXPECT_EQ(0u, device->internalDeviceIndex); EXPECT_EQ(0u, device->getRootDeviceIndex()); EXPECT_EQ(0u, device->subdevices.at(0)->getRootDeviceIndex()); EXPECT_EQ(0u, device->subdevices.at(0)->getSubDeviceIndex()); - EXPECT_EQ(1u, device->subdevices.at(0)->getInternalDeviceIndex()); EXPECT_EQ(0u, device->subdevices.at(1)->getRootDeviceIndex()); EXPECT_EQ(1u, device->subdevices.at(1)->getSubDeviceIndex()); - EXPECT_EQ(2u, device->subdevices.at(1)->getInternalDeviceIndex()); } TEST(SubDevicesTest, givenCreateMultipleSubDevicesFlagSetWhenCreateRootDeviceThenItContainsSubDevices) { @@ -149,44 +146,21 @@ TEST(SubDevicesTest, givenSubDevicesWhenGettingDeviceByIdZeroThenGetThisSubDevic EXPECT_THROW(subDevice->getDeviceById(1), std::exception); } -TEST(SubDevicesTest, givenRootDeviceWithSubdevicesWhenSetupRootEngineOnceAgainThenDontOverrideEngine) { - DebugManagerStateRestore restorer; - DebugManager.flags.CreateMultipleSubDevices.set(2); - VariableBackup mockDeviceFlagBackup(&MockDevice::createSingleDevice, false); - auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(*platformDevices)); - EXPECT_EQ(2u, device->getNumSubDevices()); - auto subDevice = device->subdevices.at(0).get(); - - auto subDeviceEngine = subDevice->getDefaultEngine(); - auto rootDeviceEngine = device->getDefaultEngine(); - - EXPECT_NE(subDeviceEngine.commandStreamReceiver, rootDeviceEngine.commandStreamReceiver); - EXPECT_NE(subDeviceEngine.osContext, rootDeviceEngine.osContext); - - device->setupRootEngine(subDeviceEngine); - rootDeviceEngine = device->getDefaultEngine(); - - EXPECT_NE(subDeviceEngine.commandStreamReceiver, rootDeviceEngine.commandStreamReceiver); - EXPECT_NE(subDeviceEngine.osContext, rootDeviceEngine.osContext); -} - -TEST(SubDevicesTest, givenRootDeviceWithoutEngineWhenSetupRootEngine) { - auto executionEnvironment = platform()->peekExecutionEnvironment(); - MockDevice device(executionEnvironment, 0); - EXPECT_EQ(0u, device.engines.size()); - EngineControl dummyEngine{reinterpret_cast(0x123), reinterpret_cast(0x456)}; - device.setupRootEngine(dummyEngine); - EXPECT_EQ(1u, device.engines.size()); - EXPECT_EQ(dummyEngine.commandStreamReceiver, device.engines[0].commandStreamReceiver); - EXPECT_EQ(dummyEngine.osContext, device.engines[0].osContext); - - device.engines.clear(); -} - -TEST(SubDevicesTest, givenRootDeviceWhenExecutionEnvironmentInitializesRootCommandStreamReceiverThenDeviceDoesntCreateExtraEngines) { +TEST(RootDevicesTest, givenRootDeviceWhenInitializeRootCommandStreamReceiverReturnsTrueThenDeviceDoesntCreateExtraEngines) { auto executionEnvironment = new MockExecutionEnvironment; - executionEnvironment->initRootCommandStreamReceiver = true; - executionEnvironment->initializeMemoryManager(); - std::unique_ptr device(MockDevice::createWithExecutionEnvironment(*platformDevices, executionEnvironment, 0u)); - EXPECT_EQ(0u, device->engines.size()); + MockDevice device(executionEnvironment, 0); + device.callBaseInitializeRootCommandStreamReceiver = false; + device.initializeRootCommandStreamReceiverReturnValue = true; + EXPECT_EQ(0u, device.engines.size()); + device.createEngines(); + EXPECT_EQ(0u, device.engines.size()); +} +TEST(RootDevicesTest, givenRootDeviceWhenInitializeRootCommandStreamReceiverReturnsFalseThenDeviceCreatesExtraEngines) { + auto executionEnvironment = new MockExecutionEnvironment; + MockDevice device(executionEnvironment, 0); + device.callBaseInitializeRootCommandStreamReceiver = false; + device.initializeRootCommandStreamReceiverReturnValue = false; + EXPECT_EQ(0u, device.engines.size()); + device.createEngines(); + EXPECT_LT(0u, device.engines.size()); } diff --git a/unit_tests/execution_environment/execution_environment_tests.cpp b/unit_tests/execution_environment/execution_environment_tests.cpp index 7d6645badb..97c3caf86e 100644 --- a/unit_tests/execution_environment/execution_environment_tests.cpp +++ b/unit_tests/execution_environment/execution_environment_tests.cpp @@ -21,8 +21,6 @@ #include "runtime/platform/platform.h" #include "runtime/source_level_debugger/source_level_debugger.h" #include "test.h" -#include "unit_tests/helpers/unit_test_helper.h" -#include "unit_tests/mocks/mock_csr.h" #include "unit_tests/mocks/mock_device.h" #include "unit_tests/mocks/mock_execution_environment.h" #include "unit_tests/mocks/mock_memory_manager.h" @@ -81,13 +79,6 @@ TEST(ExecutionEnvironment, givenDeviceThatHaveRefferencesAfterPlatformIsDestroye device->decRefInternal(); } -TEST(ExecutionEnvironment, givenPlatformWhenItIsCreatedThenItCreatesCommandStreamReceiverInExecutionEnvironment) { - Platform platform; - auto executionEnvironment = platform.peekExecutionEnvironment(); - platform.initialize(); - EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0].get()); -} - TEST(ExecutionEnvironment, givenPlatformWhenItIsCreatedThenItCreatesMemoryManagerInExecutionEnvironment) { Platform platform; auto executionEnvironment = platform.peekExecutionEnvironment(); @@ -103,42 +94,6 @@ TEST(ExecutionEnvironment, givenDeviceWhenItIsDestroyedThenMemoryManagerIsStillA EXPECT_NE(nullptr, executionEnvironment->memoryManager); } -TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeCommandStreamReceiverIsCalledThenItIsInitalized) { - ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); - executionEnvironment->initializeMemoryManager(); - executionEnvironment->rootDeviceEnvironments.resize(2); - executionEnvironment->initializeCommandStreamReceiver(0, 0, 0); - EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]); - executionEnvironment->initializeCommandStreamReceiver(1, 0, 0); - EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[1].commandStreamReceivers[0][0]); -} - -TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeIsCalledWithDifferentDeviceIndexesThenInternalStorageIsResized) { - ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); - executionEnvironment->initializeMemoryManager(); - EXPECT_EQ(0u, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.size()); - executionEnvironment->initializeCommandStreamReceiver(0, 0, 0); - EXPECT_EQ(1u, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.size()); - EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]); - executionEnvironment->initializeCommandStreamReceiver(0, 1, 0); - EXPECT_EQ(2u, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.size()); - EXPECT_NE(nullptr, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[1][0]); -} - -TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeIsCalledMultipleTimesForTheSameIndexThenCommandStreamReceiverIsReused) { - ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); - executionEnvironment->initializeMemoryManager(); - EXPECT_EQ(0u, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.size()); - executionEnvironment->initializeCommandStreamReceiver(0, 0, 1); - - auto currentCommandStreamReceiver = executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][1].get(); - executionEnvironment->initializeCommandStreamReceiver(0, 0, 1); - - EXPECT_EQ(currentCommandStreamReceiver, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][1].get()); - EXPECT_EQ(2u, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0].size()); - EXPECT_EQ(nullptr, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0].get()); -} - TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeAubCenterIsCalledThenItIsReceivesCorrectInputParams) { MockExecutionEnvironment executionEnvironment; executionEnvironment.setHwInfo(*platformDevices); @@ -177,7 +132,6 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerI const HardwareInfo *hwInfo = platformDevices[0]; auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(hwInfo)); auto executionEnvironment = device->getExecutionEnvironment(); - executionEnvironment->initializeCommandStreamReceiver(0, 0, 0); auto enableLocalMemory = HwHelper::get(hwInfo->platform.eRenderCoreFamily).getEnableLocalMemory(*hwInfo); executionEnvironment->initializeMemoryManager(); EXPECT_EQ(enableLocalMemory, executionEnvironment->memoryManager->isLocalMemorySupported()); @@ -185,7 +139,6 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerI TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerIsCalledThenItIsInitalized) { ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); - executionEnvironment->initializeCommandStreamReceiver(0, 0, 0); executionEnvironment->initializeMemoryManager(); EXPECT_NE(nullptr, executionEnvironment->memoryManager); } @@ -201,24 +154,21 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe struct MockExecutionEnvironment : ExecutionEnvironment { using ExecutionEnvironment::gmmHelper; }; - struct GmmHelperMock : public DestructorCounted { + struct GmmHelperMock : public DestructorCounted { GmmHelperMock(uint32_t &destructorId, const HardwareInfo *hwInfo) : DestructorCounted(destructorId, hwInfo) {} }; - struct OsInterfaceMock : public DestructorCounted { + struct OsInterfaceMock : public DestructorCounted { OsInterfaceMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} }; - struct MemoryOperationsHandlerMock : public DestructorCounted { + struct MemoryOperationsHandlerMock : public DestructorCounted { MemoryOperationsHandlerMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} }; - struct MemoryMangerMock : public DestructorCounted { + struct MemoryMangerMock : public DestructorCounted { MemoryMangerMock(uint32_t &destructorId, ExecutionEnvironment &executionEnvironment) : DestructorCounted(destructorId, executionEnvironment) {} }; - struct AubCenterMock : public DestructorCounted { + struct AubCenterMock : public DestructorCounted { AubCenterMock(uint32_t &destructorId) : DestructorCounted(destructorId, platformDevices[0], false, "", CommandStreamReceiverType::CSR_AUB) {} }; - struct CommandStreamReceiverMock : public DestructorCounted { - CommandStreamReceiverMock(uint32_t &destructorId, ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) : DestructorCounted(destructorId, executionEnvironment, rootDeviceIndex) {} - }; struct BuiltinsMock : public DestructorCounted { BuiltinsMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} }; @@ -231,19 +181,17 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe auto executionEnvironment = std::make_unique(); executionEnvironment->setHwInfo(*platformDevices); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.resize(1); executionEnvironment->gmmHelper = std::make_unique(destructorId, platformDevices[0]); executionEnvironment->osInterface = std::make_unique(destructorId); executionEnvironment->memoryOperationsInterface = std::make_unique(destructorId); executionEnvironment->memoryManager = std::make_unique(destructorId, *executionEnvironment); executionEnvironment->rootDeviceEnvironments[0].aubCenter = std::make_unique(destructorId); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::make_unique(destructorId, *executionEnvironment, 0)); executionEnvironment->builtins = std::make_unique(destructorId); executionEnvironment->compilerInterface = std::make_unique(destructorId); executionEnvironment->sourceLevelDebugger = std::make_unique(destructorId); executionEnvironment.reset(nullptr); - EXPECT_EQ(9u, destructorId); + EXPECT_EQ(8u, destructorId); } TEST(ExecutionEnvironment, givenMultipleRootDevicesWhenTheyAreCreatedTheyAllReuseTheSameMemoryManager) { @@ -258,34 +206,6 @@ TEST(ExecutionEnvironment, givenMultipleRootDevicesWhenTheyAreCreatedTheyAllReus EXPECT_EQ(memoryManager, device2->getMemoryManager()); } -typedef ::testing::Test ExecutionEnvironmentHw; - -HWTEST_F(ExecutionEnvironmentHw, givenHwHelperInputWhenInitializingCsrThenCreatePageTableManagerIfAllowed) { - HardwareInfo localHwInfo = *platformDevices[0]; - localHwInfo.capabilityTable.ftrRenderCompressedBuffers = false; - localHwInfo.capabilityTable.ftrRenderCompressedImages = false; - - ExecutionEnvironment executionEnvironment; - executionEnvironment.initializeMemoryManager(); - executionEnvironment.setHwInfo(&localHwInfo); - executionEnvironment.initializeCommandStreamReceiver(0, 0, 0); - auto csr0 = static_cast *>(executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers[0][0].get()); - EXPECT_FALSE(csr0->createPageTableManagerCalled); - - auto hwInfo = executionEnvironment.getMutableHardwareInfo(); - hwInfo->capabilityTable.ftrRenderCompressedBuffers = true; - hwInfo->capabilityTable.ftrRenderCompressedImages = false; - executionEnvironment.initializeCommandStreamReceiver(0, 1, 0); - auto csr1 = static_cast *>(executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers[1][0].get()); - EXPECT_EQ(UnitTestHelper::isPageTableManagerSupported(*hwInfo), csr1->createPageTableManagerCalled); - - hwInfo->capabilityTable.ftrRenderCompressedBuffers = false; - hwInfo->capabilityTable.ftrRenderCompressedImages = true; - executionEnvironment.initializeCommandStreamReceiver(0, 2, 0); - auto csr2 = static_cast *>(executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers[2][0].get()); - EXPECT_EQ(UnitTestHelper::isPageTableManagerSupported(*hwInfo), csr2->createPageTableManagerCalled); -} - TEST(ExecutionEnvironment, givenUnproperSetCsrFlagValueWhenInitializingMemoryManagerThenCreateDefaultMemoryManager) { DebugManagerStateRestore restorer; DebugManager.flags.SetCommandStreamReceiver.set(10); diff --git a/unit_tests/fixtures/buffer_enqueue_fixture.h b/unit_tests/fixtures/buffer_enqueue_fixture.h index 36fed91d02..9dbeac9114 100644 --- a/unit_tests/fixtures/buffer_enqueue_fixture.h +++ b/unit_tests/fixtures/buffer_enqueue_fixture.h @@ -35,10 +35,8 @@ struct BufferEnqueueFixture : public HardwareParse, template void initializeFixture() { - auto mockCsr = new MockCsrHw2(*executionEnvironment, 0); - - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.resize(1); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::unique_ptr(mockCsr)); + EnvironmentWithCsrWrapper environment; + environment.setCsrType>(); memoryManager = new MockMemoryManager(*executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); diff --git a/unit_tests/fixtures/dispatch_flags_fixture.h b/unit_tests/fixtures/dispatch_flags_fixture.h index b7d0ac2ada..8a4834b1e3 100644 --- a/unit_tests/fixtures/dispatch_flags_fixture.h +++ b/unit_tests/fixtures/dispatch_flags_fixture.h @@ -17,11 +17,12 @@ namespace NEO { struct DispatchFlagsTests : public ::testing::Test { template void SetUpImpl() { - auto executionEnvironment = new MockExecutionEnvironmentWithCsr(**platformDevices, 1u); - device.reset(MockDevice::createWithExecutionEnvironment(*platformDevices, executionEnvironment, 0)); + environmentWrapper.setCsrType(); + device.reset(MockDevice::createWithNewExecutionEnvironment(*platformDevices)); context = std::make_unique(device.get()); } + EnvironmentWithCsrWrapper environmentWrapper; std::unique_ptr device; std::unique_ptr context; DebugManagerStateRestore restore; diff --git a/unit_tests/fixtures/memory_allocator_fixture.h b/unit_tests/fixtures/memory_allocator_fixture.h index 9135534568..9c46ee4127 100644 --- a/unit_tests/fixtures/memory_allocator_fixture.h +++ b/unit_tests/fixtures/memory_allocator_fixture.h @@ -13,6 +13,7 @@ #include "runtime/memory_manager/os_agnostic_memory_manager.h" #include "unit_tests/fixtures/memory_management_fixture.h" #include "unit_tests/libult/create_command_stream.h" +#include "unit_tests/mocks/mock_device.h" #include "unit_tests/mocks/mock_memory_manager.h" using namespace NEO; @@ -21,24 +22,25 @@ class MemoryAllocatorFixture : public MemoryManagementFixture { public: void SetUp() override { MemoryManagementFixture::SetUp(); - executionEnvironment = std::make_unique(); + executionEnvironment = new ExecutionEnvironment(); executionEnvironment->setHwInfo(*platformDevices); - executionEnvironment->initializeCommandStreamReceiver(0, 0, 0); + device.reset(MockDevice::createWithExecutionEnvironment(*platformDevices, executionEnvironment, 0u)); memoryManager = new MockMemoryManager(false, false, *executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); - csr = executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0].get(); + csr = &device->getGpgpuCommandStreamReceiver(); auto engineType = HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0]; auto osContext = memoryManager->createAndRegisterOsContext(csr, engineType, 1, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false); csr->setupContext(*osContext); } void TearDown() override { - executionEnvironment.reset(); + device.reset(); MemoryManagementFixture::TearDown(); } protected: - std::unique_ptr executionEnvironment; + std::unique_ptr device; + ExecutionEnvironment *executionEnvironment; MockMemoryManager *memoryManager = nullptr; CommandStreamReceiver *csr = nullptr; }; diff --git a/unit_tests/fixtures/memory_manager_fixture.cpp b/unit_tests/fixtures/memory_manager_fixture.cpp index c20eb65af8..8de5b0060f 100644 --- a/unit_tests/fixtures/memory_manager_fixture.cpp +++ b/unit_tests/fixtures/memory_manager_fixture.cpp @@ -17,14 +17,12 @@ using namespace NEO; void MemoryManagerWithCsrFixture::SetUp() { executionEnvironment.setHwInfo(*platformDevices); - csr = new MockCommandStreamReceiver(this->executionEnvironment, 0); + csr = std::make_unique(this->executionEnvironment, 0); memoryManager = new MockMemoryManager(executionEnvironment); executionEnvironment.memoryManager.reset(memoryManager); csr->tagAddress = ¤tGpuTag; - executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers.resize(1); - executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::unique_ptr(csr)); auto engine = HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0]; - auto osContext = memoryManager->createAndRegisterOsContext(csr, engine, 1, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false); + auto osContext = memoryManager->createAndRegisterOsContext(csr.get(), engine, 1, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false); csr->setupContext(*osContext); } diff --git a/unit_tests/fixtures/memory_manager_fixture.h b/unit_tests/fixtures/memory_manager_fixture.h index 2bdedf5938..fb48efdee9 100644 --- a/unit_tests/fixtures/memory_manager_fixture.h +++ b/unit_tests/fixtures/memory_manager_fixture.h @@ -20,7 +20,7 @@ class MemoryManagerWithCsrFixture { public: MockMemoryManager *memoryManager; ExecutionEnvironment executionEnvironment; - MockCommandStreamReceiver *csr; + std::unique_ptr csr; uint32_t taskCount = 0; uint32_t currentGpuTag = initialHardwareTag; diff --git a/unit_tests/gen11/hw_helper_tests_gen11.cpp b/unit_tests/gen11/hw_helper_tests_gen11.cpp index 10ecfadb7b..d2ee889cc2 100644 --- a/unit_tests/gen11/hw_helper_tests_gen11.cpp +++ b/unit_tests/gen11/hw_helper_tests_gen11.cpp @@ -49,5 +49,5 @@ GEN11TEST_F(HwHelperTestGen11, whenGetConfigureAddressSpaceModeThenReturnZero) { GEN11TEST_F(HwHelperTestGen11, whenGetGpgpuEnginesThenReturnTwoRcsEngines) { whenGetGpgpuEnginesThenReturnTwoRcsEngines(); - EXPECT_EQ(2u, pDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].commandStreamReceivers[0].size()); + EXPECT_EQ(2u, pDevice->engines.size()); } diff --git a/unit_tests/gen12lp/hw_helper_tests_gen12lp.cpp b/unit_tests/gen12lp/hw_helper_tests_gen12lp.cpp index 65b38a4973..6b1c122353 100644 --- a/unit_tests/gen12lp/hw_helper_tests_gen12lp.cpp +++ b/unit_tests/gen12lp/hw_helper_tests_gen12lp.cpp @@ -119,7 +119,7 @@ GEN12LPTEST_F(HwHelperTestGen12Lp, givenDifferentSizesOfAllocationWhenCheckingCo } GEN12LPTEST_F(HwHelperTestGen12Lp, whenGetGpgpuEnginesThenReturnTwoRcsEnginesAndOneCcsEngine) { - EXPECT_EQ(3u, pDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].commandStreamReceivers[0].size()); + EXPECT_EQ(3u, pDevice->engines.size()); auto &engines = HwHelperHw::get().getGpgpuEngineInstances(); EXPECT_EQ(3u, engines.size()); EXPECT_EQ(aub_stream::ENGINE_RCS, engines[0]); diff --git a/unit_tests/gen8/hw_helper_tests_gen8.cpp b/unit_tests/gen8/hw_helper_tests_gen8.cpp index 5b5f73b88f..6eca995b26 100644 --- a/unit_tests/gen8/hw_helper_tests_gen8.cpp +++ b/unit_tests/gen8/hw_helper_tests_gen8.cpp @@ -55,5 +55,5 @@ GEN8TEST_F(HwHelperTestGen8, whenGetConfigureAddressSpaceModeThenReturnZero) { GEN8TEST_F(HwHelperTestGen8, whenGetGpgpuEnginesThenReturnTwoRcsEngines) { whenGetGpgpuEnginesThenReturnTwoRcsEngines(); - EXPECT_EQ(2u, pDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].commandStreamReceivers[0].size()); + EXPECT_EQ(2u, pDevice->engines.size()); } diff --git a/unit_tests/gen9/hw_helper_tests_gen9.cpp b/unit_tests/gen9/hw_helper_tests_gen9.cpp index fd4f15832f..04e8bd38f1 100644 --- a/unit_tests/gen9/hw_helper_tests_gen9.cpp +++ b/unit_tests/gen9/hw_helper_tests_gen9.cpp @@ -56,5 +56,5 @@ GEN9TEST_F(HwHelperTestGen9, whenGetConfigureAddressSpaceModeThenReturnZero) { GEN9TEST_F(HwHelperTestGen9, whenGetGpgpuEnginesThenReturnTwoRcsEngines) { whenGetGpgpuEnginesThenReturnTwoRcsEngines(); - EXPECT_EQ(2u, pDevice->getExecutionEnvironment()->rootDeviceEnvironments[0].commandStreamReceivers[0].size()); + EXPECT_EQ(2u, pDevice->engines.size()); } diff --git a/unit_tests/memory_manager/deferrable_allocation_deletion_tests.cpp b/unit_tests/memory_manager/deferrable_allocation_deletion_tests.cpp index 292842cdf1..92f6eeaa3c 100644 --- a/unit_tests/memory_manager/deferrable_allocation_deletion_tests.cpp +++ b/unit_tests/memory_manager/deferrable_allocation_deletion_tests.cpp @@ -78,7 +78,7 @@ TEST_F(DeferrableAllocationDeletionTest, givenDeferrableAllocationWhenApplyThenW } HWTEST_F(DeferrableAllocationDeletionTest, givenAllocationUsedByTwoOsContextsWhenApplyDeletionThenWaitForBothContextsAndFlushNotReadyCsr) { - auto &nonDefaultCommandStreamReceiver = static_cast &>(*device->getExecutionEnvironment()->rootDeviceEnvironments[0].commandStreamReceivers[0][1]); + auto &nonDefaultCommandStreamReceiver = static_cast &>(*device->commandStreamReceivers[1]); auto nonDefaultOsContextId = nonDefaultCommandStreamReceiver.getOsContext().getContextId(); auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); *hwTag = 0u; diff --git a/unit_tests/memory_manager/host_ptr_manager_tests.cpp b/unit_tests/memory_manager/host_ptr_manager_tests.cpp index 91dc1788fc..cb9b1ecaa4 100644 --- a/unit_tests/memory_manager/host_ptr_manager_tests.cpp +++ b/unit_tests/memory_manager/host_ptr_manager_tests.cpp @@ -861,13 +861,12 @@ HWTEST_F(HostPtrAllocationTest, givenOverlappingFragmentsWhenCheckIsCalledThenWa EXPECT_EQ(1u, engines.size()); auto csr0 = static_cast(engines[0].commandStreamReceiver); - auto csr1 = new MockCommandStreamReceiver(executionEnvironment, 0); + auto csr1 = std::make_unique(executionEnvironment, 0); uint32_t csr0GpuTag = taskCountNotReady; uint32_t csr1GpuTag = taskCountNotReady; csr0->tagAddress = &csr0GpuTag; csr1->tagAddress = &csr1GpuTag; - executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::unique_ptr(csr1)); - auto osContext = memoryManager->createAndRegisterOsContext(csr1, aub_stream::EngineType::ENGINE_RCS, 0, PreemptionMode::Disabled, true); + auto osContext = memoryManager->createAndRegisterOsContext(csr1.get(), aub_stream::EngineType::ENGINE_RCS, 0, PreemptionMode::Disabled, true); csr1->setupContext(*osContext); void *cpuPtr = reinterpret_cast(0x100004); diff --git a/unit_tests/memory_manager/internal_allocation_storage_tests.cpp b/unit_tests/memory_manager/internal_allocation_storage_tests.cpp index 912235e8f9..6c4fae898b 100644 --- a/unit_tests/memory_manager/internal_allocation_storage_tests.cpp +++ b/unit_tests/memory_manager/internal_allocation_storage_tests.cpp @@ -19,7 +19,6 @@ struct InternalAllocationStorageTest : public MemoryAllocatorFixture, using MemoryAllocatorFixture::TearDown; void SetUp() override { MemoryAllocatorFixture::SetUp(); - csr->initializeTagAllocation(); storage = csr->getInternalAllocationStorage(); } InternalAllocationStorage *storage; diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index ee17285ef7..5949c3fc9a 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -1380,7 +1380,7 @@ TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsCompletedWhenche } TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsNotCompletedWhencheckGpuUsageAndDestroyGraphicsAllocationsIsCalledThenItIsAddedToTemporaryAllocationList) { - memoryManager->createAndRegisterOsContext(csr, HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0], + memoryManager->createAndRegisterOsContext(csr.get(), HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0], 1, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false); auto usedAllocationAndNotGpuCompleted = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); @@ -1566,7 +1566,7 @@ HWTEST_F(GraphicsAllocationTests, givenAllocationUsedOnlyByNonDefaultDeviceWhenC ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); auto device = std::unique_ptr(Device::create(executionEnvironment, 0u)); auto &defaultCommandStreamReceiver = device->getGpgpuCommandStreamReceiver(); - auto &nonDefaultCommandStreamReceiver = static_cast &>(*executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][1]); + auto &nonDefaultCommandStreamReceiver = static_cast &>(*device->commandStreamReceivers[1]); auto memoryManager = executionEnvironment->memoryManager.get(); auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); auto notReadyTaskCount = *nonDefaultCommandStreamReceiver.getTagAddress() + 1; diff --git a/unit_tests/memory_manager/surface_tests.cpp b/unit_tests/memory_manager/surface_tests.cpp index 65d3c404c8..276609d73a 100644 --- a/unit_tests/memory_manager/surface_tests.cpp +++ b/unit_tests/memory_manager/surface_tests.cpp @@ -62,12 +62,10 @@ HWTEST_TYPED_TEST(SurfaceTest, GivenSurfaceWhenInterfaceIsUsedThenSurfaceBehaves int32_t execStamp; ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.resize(1); - MockCsr *csr = new MockCsr(execStamp, *executionEnvironment, 0); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::unique_ptr(csr)); executionEnvironment->initializeMemoryManager(); + auto csr = std::make_unique>(execStamp, *executionEnvironment, 0); auto engine = HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0]; - auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(csr, engine, 1, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false); + auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(csr.get(), engine, 1, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false); csr->setupContext(*osContext); Surface *surface = createSurface::Create(this->data, diff --git a/unit_tests/mocks/mock_aub_csr.h b/unit_tests/mocks/mock_aub_csr.h index 00a5086bd9..5c8a90f45f 100644 --- a/unit_tests/mocks/mock_aub_csr.h +++ b/unit_tests/mocks/mock_aub_csr.h @@ -162,9 +162,10 @@ struct MockAubCsr : public AUBCommandStreamReceiverHw { struct AubExecutionEnvironment { std::unique_ptr executionEnvironment; GraphicsAllocation *commandBuffer = nullptr; + std::unique_ptr commandStreamReceiver; template CsrType *getCsr() { - return static_cast(executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0].get()); + return static_cast(commandStreamReceiver.get()); } ~AubExecutionEnvironment() { if (commandBuffer) { @@ -179,23 +180,23 @@ std::unique_ptr getEnvironment(bool createTagAllocation executionEnvironment->setHwInfo(*platformDevices); executionEnvironment->rootDeviceEnvironments[0].aubCenter.reset(new AubCenter()); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.resize(1); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::make_unique("", standalone, *executionEnvironment, 0)); executionEnvironment->initializeMemoryManager(); + auto commandStreamReceiver = std::make_unique("", standalone, *executionEnvironment, 0); if (createTagAllocation) { - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->initializeTagAllocation(); + commandStreamReceiver->initializeTagAllocation(); } - auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0].get(), + auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(commandStreamReceiver.get(), getChosenEngineType(*platformDevices[0]), 1, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->setupContext(*osContext); + commandStreamReceiver->setupContext(*osContext); std::unique_ptr aubExecutionEnvironment(new AubExecutionEnvironment); if (allocateCommandBuffer) { aubExecutionEnvironment->commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); } aubExecutionEnvironment->executionEnvironment = std::move(executionEnvironment); + aubExecutionEnvironment->commandStreamReceiver = std::move(commandStreamReceiver); return aubExecutionEnvironment; } } // namespace NEO diff --git a/unit_tests/mocks/mock_device.cpp b/unit_tests/mocks/mock_device.cpp index bae5277eff..5d41b324c5 100644 --- a/unit_tests/mocks/mock_device.cpp +++ b/unit_tests/mocks/mock_device.cpp @@ -17,21 +17,22 @@ using namespace NEO; bool MockDevice::createSingleDevice = true; +decltype(&createCommandStream) MockSubDevice::createCommandStreamReceiverFunc = createCommandStream; +decltype(&createCommandStream) MockDevice::createCommandStreamReceiverFunc = createCommandStream; MockDevice::MockDevice() : MockDevice(new MockExecutionEnvironment(), 0u) { CommandStreamReceiver *commandStreamReceiver = createCommandStream(*this->executionEnvironment, this->getRootDeviceIndex()); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.resize(internalDeviceIndex + 1); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[internalDeviceIndex].resize(defaultEngineIndex + 1); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[internalDeviceIndex][defaultEngineIndex].reset(commandStreamReceiver); + commandStreamReceivers.resize(1); + commandStreamReceivers[0].reset(commandStreamReceiver); this->executionEnvironment->memoryManager = std::move(this->mockMemoryManager); - this->engines.resize(defaultEngineIndex + 1); - this->engines[defaultEngineIndex] = {commandStreamReceiver, nullptr}; + this->engines.resize(1); + this->engines[0] = {commandStreamReceiver, nullptr}; initializeCaps(); } -MockDevice::MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) - : RootDevice(executionEnvironment, deviceIndex) { +MockDevice::MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex) + : RootDevice(executionEnvironment, rootDeviceIndex) { auto &hwInfo = getHardwareInfo(); bool enableLocalMemory = HwHelper::get(hwInfo.platform.eRenderCoreFamily).getEnableLocalMemory(hwInfo); bool aubUsage = (testMode == TestMode::AubTests) || (testMode == TestMode::AubTestsWithTbx); @@ -70,7 +71,6 @@ void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) { } void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr, uint32_t engineIndex) { - UNRECOVERABLE_IF(internalDeviceIndex != 0u); auto osContext = this->engines[engineIndex].osContext; auto memoryManager = executionEnvironment->memoryManager.get(); @@ -81,11 +81,11 @@ void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr, uint3 memoryManager->getRegisteredEngines().emplace_back(registeredEngine); osContext->incRefInternal(); newCsr->setupContext(*osContext); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[internalDeviceIndex][engineIndex].reset(newCsr); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[internalDeviceIndex][engineIndex]->initializeTagAllocation(); + commandStreamReceivers[engineIndex].reset(newCsr); + commandStreamReceivers[engineIndex]->initializeTagAllocation(); if (preemptionMode == PreemptionMode::MidThread || isSourceLevelDebuggerActive()) { - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[internalDeviceIndex][engineIndex]->createPreemptionAllocation(); + commandStreamReceivers[engineIndex]->createPreemptionAllocation(); } } diff --git a/unit_tests/mocks/mock_device.h b/unit_tests/mocks/mock_device.h index 5c28df6e39..21168e2724 100644 --- a/unit_tests/mocks/mock_device.h +++ b/unit_tests/mocks/mock_device.h @@ -7,8 +7,10 @@ #pragma once #include "runtime/device/root_device.h" +#include "runtime/device/sub_device.h" #include "runtime/helpers/hw_helper.h" #include "unit_tests/fixtures/mock_aub_center_fixture.h" +#include "unit_tests/helpers/variable_backup.h" #include "unit_tests/libult/ult_command_stream_receiver.h" #include "unit_tests/mocks/mock_allocation_properties.h" @@ -18,8 +20,18 @@ class FailMemoryManager; extern CommandStreamReceiver *createCommandStream(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex); +struct MockSubDevice : public SubDevice { + using SubDevice::SubDevice; + + std::unique_ptr createCommandStreamReceiver() const override { + return std::unique_ptr(createCommandStreamReceiverFunc(*executionEnvironment, getRootDeviceIndex())); + } + static decltype(&createCommandStream) createCommandStreamReceiverFunc; +}; + class MockDevice : public RootDevice { public: + using Device::commandStreamReceivers; using Device::createDeviceInternals; using Device::createEngine; using Device::deviceInfo; @@ -27,7 +39,7 @@ class MockDevice : public RootDevice { using Device::engines; using Device::executionEnvironment; using Device::initializeCaps; - using Device::internalDeviceIndex; + using RootDevice::createEngines; using RootDevice::subdevices; void setOSTime(OSTime *osTime); @@ -39,7 +51,7 @@ class MockDevice : public RootDevice { bool getCpuTime(uint64_t *timeStamp) { return true; }; MockDevice(); - MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex); + MockDevice(ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex); void setPreemptionMode(PreemptionMode mode) { preemptionMode = mode; @@ -73,10 +85,10 @@ class MockDevice : public RootDevice { } template - static T *createWithExecutionEnvironment(const HardwareInfo *pHwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) { + static T *createWithExecutionEnvironment(const HardwareInfo *pHwInfo, ExecutionEnvironment *executionEnvironment, uint32_t rootDeviceIndex) { pHwInfo = pHwInfo ? pHwInfo : platformDevices[0]; executionEnvironment->setHwInfo(pHwInfo); - T *device = new T(executionEnvironment, deviceIndex); + T *device = new T(executionEnvironment, rootDeviceIndex); executionEnvironment->memoryManager = std::move(device->mockMemoryManager); return createDeviceInternals(device); } @@ -90,6 +102,24 @@ class MockDevice : public RootDevice { executionEnvironment->setHwInfo(pHwInfo); return createWithExecutionEnvironment(pHwInfo, executionEnvironment, 0u); } + bool initializeRootCommandStreamReceiver() override { + if (callBaseInitializeRootCommandStreamReceiver) { + return RootDevice::initializeRootCommandStreamReceiver(); + } + return initializeRootCommandStreamReceiverReturnValue; + } + + SubDevice *createSubDevice(uint32_t subDeviceIndex) override { + return Device::create(executionEnvironment, subDeviceIndex, *this); + } + + std::unique_ptr createCommandStreamReceiver() const override { + return std::unique_ptr(createCommandStreamReceiverFunc(*executionEnvironment, getRootDeviceIndex())); + } + static decltype(&createCommandStream) createCommandStreamReceiverFunc; + + bool callBaseInitializeRootCommandStreamReceiver = true; + bool initializeRootCommandStreamReceiverReturnValue = false; std::unique_ptr mockMemoryManager; }; @@ -118,4 +148,20 @@ class MockAlignedMallocManagerDevice : public MockDevice { public: MockAlignedMallocManagerDevice(ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex); }; + +struct EnvironmentWithCsrWrapper { + template + void setCsrType() { + createSubDeviceCsrFuncBackup = EnvironmentWithCsrWrapper::createCommandStreamReceiver; + createRootDeviceCsrFuncBackup = EnvironmentWithCsrWrapper::createCommandStreamReceiver; + } + + template + static CommandStreamReceiver *createCommandStreamReceiver(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) { + return new CsrType(executionEnvironment, 0); + } + + VariableBackup createSubDeviceCsrFuncBackup{&MockSubDevice::createCommandStreamReceiverFunc}; + VariableBackup createRootDeviceCsrFuncBackup{&MockDevice::createCommandStreamReceiverFunc}; +}; } // namespace NEO diff --git a/unit_tests/mocks/mock_execution_environment.h b/unit_tests/mocks/mock_execution_environment.h index 5a5527ff5c..9acff01777 100644 --- a/unit_tests/mocks/mock_execution_environment.h +++ b/unit_tests/mocks/mock_execution_environment.h @@ -32,30 +32,9 @@ struct MockExecutionEnvironment : ExecutionEnvironment { } ExecutionEnvironment::initAubCenter(localMemoryEnabled, aubFileName, csrType); } - bool initializeRootCommandStreamReceiver(RootDevice &device) override { - return initRootCommandStreamReceiver; - } bool initAubCenterCalled = false; bool localMemoryEnabledReceived = false; std::string aubFileNameReceived = ""; bool useMockAubCenter = true; - bool initRootCommandStreamReceiver = false; -}; - -template -struct MockExecutionEnvironmentWithCsr : public ExecutionEnvironment { - MockExecutionEnvironmentWithCsr() = delete; - MockExecutionEnvironmentWithCsr(const HardwareInfo &hwInfo, uint32_t devicesCount) { - setHwInfo(&hwInfo); - auto &gpgpuEngines = HwHelper::get(hwInfo.platform.eRenderCoreFamily).getGpgpuEngineInstances(); - auto offset = devicesCount > 1 ? 1u : 0u; - rootDeviceEnvironments[0].commandStreamReceivers.resize(devicesCount + offset); - - for (uint32_t deviceIndex = 0; deviceIndex < devicesCount; deviceIndex++) { - for (uint32_t csrIndex = 0; csrIndex < gpgpuEngines.size(); csrIndex++) { - rootDeviceEnvironments[0].commandStreamReceivers[deviceIndex + offset].push_back(std::unique_ptr(new CsrType(*this, 0))); - } - } - } }; } // namespace NEO diff --git a/unit_tests/os_interface/linux/drm_command_stream_fixture.h b/unit_tests/os_interface/linux/drm_command_stream_fixture.h index 1637ffc814..542d2433b9 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_fixture.h +++ b/unit_tests/os_interface/linux/drm_command_stream_fixture.h @@ -39,8 +39,6 @@ class DrmCommandStreamTest : public ::testing::Test { csr = new DrmCommandStreamReceiver(executionEnvironment, 0, gemCloseWorkerMode::gemCloseWorkerActive); ASSERT_NE(nullptr, csr); - executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers.resize(1); - executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::unique_ptr(csr)); csr->setupContext(*osContext); // Memory manager creates pinBB with ioctl, expect one call @@ -61,7 +59,7 @@ class DrmCommandStreamTest : public ::testing::Test { void TearDownT() { memoryManager->waitForDeletions(); memoryManager->peekGemCloseWorker()->close(true); - executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers.clear(); + delete csr; ::testing::Mock::VerifyAndClearExpectations(mock.get()); // Memory manager closes pinBB with ioctl, expect one call EXPECT_CALL(*mock, ioctl(::testing::_, ::testing::_)) diff --git a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp index ace42619ba..e3ef6e34a1 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -504,7 +504,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmAllocationWhenHandleFenceCompletionThenCall mock->ioctl_expected.gemClose = 1; mock->ioctl_expected.gemWait = 2; - mock->ioctl_expected.contextDestroy = static_cast(device->getExecutionEnvironment()->rootDeviceEnvironments[0].commandStreamReceivers[0].size()); + mock->ioctl_expected.contextDestroy = static_cast(device->engines.size()); memoryManager->freeGraphicsMemory(allocation); } @@ -545,7 +545,7 @@ TEST_F(DrmMemoryManagerTest, getMinimumSystemSharedMemory) { mock->ioctl_expected.contextGetParam = 2; EXPECT_EQ(hostMemorySize, systemSharedMemorySize); mock->testIoctls(); - mock->ioctl_expected.contextDestroy = static_cast(device->getExecutionEnvironment()->rootDeviceEnvironments[0].commandStreamReceivers[0].size()); + mock->ioctl_expected.contextDestroy = static_cast(device->engines.size()); } TEST_F(DrmMemoryManagerTest, BoWaitFailure) { @@ -1267,7 +1267,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedAn injectFailures(method); mock->reset(); - mock->ioctl_expected.contextDestroy = static_cast(device->getExecutionEnvironment()->rootDeviceEnvironments[0].commandStreamReceivers[0].size()); + mock->ioctl_expected.contextDestroy = static_cast(device->engines.size()); } HWTEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedFromHostPtrThenallocateGraphicsMemoryForImageIsUsed) { @@ -1682,7 +1682,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenAllocationFails injectFailures(method); mock->reset(); - mock->ioctl_expected.contextDestroy = static_cast(device->getExecutionEnvironment()->rootDeviceEnvironments[0].commandStreamReceivers[0].size()); + mock->ioctl_expected.contextDestroy = static_cast(device->engines.size()); } TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndThreeOsHandlesWhenReuseCreatesAreCalledThenGraphicsAllocationsAreReturned) { diff --git a/unit_tests/os_interface/windows/device_command_stream_tests.cpp b/unit_tests/os_interface/windows/device_command_stream_tests.cpp index fcd77351b3..fe4a4b45d6 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -242,19 +242,18 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOf hwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::Disabled; executionEnvironment->setHwInfo(hwInfo); auto wddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.resize(1); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::make_unique>(*executionEnvironment, 0)); + auto csr = std::make_unique>(*executionEnvironment, 0); executionEnvironment->memoryManager.reset(new MemoryManagerCreate(false, false, *executionEnvironment)); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->overrideDispatchPolicy(DispatchMode::ImmediateDispatch); + csr->overrideDispatchPolicy(DispatchMode::ImmediateDispatch); OsContextWin osContext(*wddm, 0u, 1, HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*hwInfo), false); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->setupContext(osContext); + csr->setupContext(osContext); auto commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs}; - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->flush(batchBuffer, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->getResidencyAllocations()); + csr->flush(batchBuffer, csr->getResidencyAllocations()); auto commandHeader = wddm->submitResult.commandHeaderSubmitted; COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast(commandHeader); @@ -268,20 +267,19 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOn hwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::MidThread; executionEnvironment->setHwInfo(hwInfo); auto wddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.resize(1); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::make_unique>(*executionEnvironment, 0)); + auto csr = std::make_unique>(*executionEnvironment, 0); executionEnvironment->memoryManager.reset(new MemoryManagerCreate(false, false, *executionEnvironment)); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->overrideDispatchPolicy(DispatchMode::ImmediateDispatch); + csr->overrideDispatchPolicy(DispatchMode::ImmediateDispatch); OsContextWin osContext(*wddm, 0u, 1, HwHelper::get(platformDevices[0]->platform.eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*hwInfo), false); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->setupContext(osContext); + csr->setupContext(osContext); auto commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, QueueSliceCount::defaultSliceCount, cs.getUsed(), &cs}; - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->flush(batchBuffer, executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0]->getResidencyAllocations()); + csr->flush(batchBuffer, csr->getResidencyAllocations()); auto commandHeader = wddm->submitResult.commandHeaderSubmitted; COMMAND_BUFFER_HEADER *pHeader = reinterpret_cast(commandHeader); diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp index 7b87024094..c4d56789cb 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -1615,7 +1615,7 @@ TEST_F(WddmMemoryManagerTest2, givenReadOnlyMemoryPassedToPopulateOsHandlesWhenC TEST(WddmMemoryManagerCleanupTest, givenUsedTagAllocationInWddmMemoryManagerWhenCleanupMemoryManagerThenDontAccessCsr) { ExecutionEnvironment &executionEnvironment = *platform()->peekExecutionEnvironment(); - auto csr = createCommandStream(executionEnvironment, 0); + auto csr = std::unique_ptr(createCommandStream(executionEnvironment, 0)); auto wddm = new WddmMock(); auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]); auto hwInfo = *platformDevices[0]; @@ -1624,16 +1624,14 @@ TEST(WddmMemoryManagerCleanupTest, givenUsedTagAllocationInWddmMemoryManagerWhen executionEnvironment.osInterface = std::make_unique(); executionEnvironment.osInterface->get()->setWddm(wddm); executionEnvironment.memoryOperationsInterface = std::make_unique(wddm); - executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers.resize(1); - executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::unique_ptr(csr)); executionEnvironment.memoryManager = std::make_unique(executionEnvironment); - auto osContext = executionEnvironment.memoryManager->createAndRegisterOsContext(csr, aub_stream::ENGINE_RCS, 1, preemptionMode, false); + auto osContext = executionEnvironment.memoryManager->createAndRegisterOsContext(csr.get(), aub_stream::ENGINE_RCS, 1, preemptionMode, false); csr->setupContext(*osContext); auto tagAllocator = csr->getEventPerfCountAllocator(100); auto allocation = tagAllocator->getTag()->getBaseGraphicsAllocation(); allocation->updateTaskCount(1, csr->getOsContext().getContextId()); - executionEnvironment.rootDeviceEnvironments[0].commandStreamReceivers.clear(); + csr.reset(); EXPECT_NO_THROW(executionEnvironment.memoryManager.reset()); } diff --git a/unit_tests/preemption/preemption_tests.cpp b/unit_tests/preemption/preemption_tests.cpp index 41bb75b110..0b61fe143c 100644 --- a/unit_tests/preemption/preemption_tests.cpp +++ b/unit_tests/preemption/preemption_tests.cpp @@ -457,15 +457,13 @@ HWTEST_P(PreemptionTest, whenFailToCreatePreemptionAllocationThenFailToCreateDev bool isSourceLevelDebuggerActive() const override { return true; } + std::unique_ptr createCommandStreamReceiver() const override { + return std::make_unique(*executionEnvironment); + } }; ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); - platformImpl->peekExecutionEnvironment()->rootDeviceEnvironments[0].commandStreamReceivers.resize(1); - platformImpl->peekExecutionEnvironment()->rootDeviceEnvironments[0].commandStreamReceivers[0].resize(2); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][1].reset(new MockUltCsr(*executionEnvironment)); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0][0].reset(new MockUltCsr(*executionEnvironment)); - std::unique_ptr mockDevice(MockDevice::create(executionEnvironment, 0)); EXPECT_EQ(nullptr, mockDevice); } diff --git a/unit_tests/scenarios/windows/enqueue_read_write_buffer_scenarios_windows_tests.cpp b/unit_tests/scenarios/windows/enqueue_read_write_buffer_scenarios_windows_tests.cpp index c95c39b66a..252c225c7d 100644 --- a/unit_tests/scenarios/windows/enqueue_read_write_buffer_scenarios_windows_tests.cpp +++ b/unit_tests/scenarios/windows/enqueue_read_write_buffer_scenarios_windows_tests.cpp @@ -36,16 +36,13 @@ struct EnqueueBufferWindowsTest : public HardwareParse, template void initializeFixture() { - auto wddmCsr = new WddmCommandStreamReceiver(*executionEnvironment, 0); - - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.resize(1); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::unique_ptr(wddmCsr)); + EnvironmentWithCsrWrapper environment; + environment.setCsrType>(); memoryManager = new MockWddmMemoryManager(*executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); device = std::unique_ptr(Device::create(executionEnvironment, 0)); - context = std::make_unique(device.get()); const size_t bufferMisalignment = 1; diff --git a/unit_tests/source_level_debugger/source_level_debugger_csr_tests.cpp b/unit_tests/source_level_debugger/source_level_debugger_csr_tests.cpp index 1846b362f1..7ac1da6065 100644 --- a/unit_tests/source_level_debugger/source_level_debugger_csr_tests.cpp +++ b/unit_tests/source_level_debugger/source_level_debugger_csr_tests.cpp @@ -25,21 +25,19 @@ class CommandStreamReceiverWithActiveDebuggerTest : public ::testing::Test { template auto createCSR() { hwInfo = nullptr; + EnvironmentWithCsrWrapper environment; + environment.setCsrType>(); executionEnvironment = getExecutionEnvironmentImpl(hwInfo); hwInfo->capabilityTable = platformDevices[0]->capabilityTable; hwInfo->capabilityTable.sourceLevelDebuggerSupported = true; - auto mockCsr = new MockCsrHw2(*executionEnvironment, 0); - - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers.resize(1); - executionEnvironment->rootDeviceEnvironments[0].commandStreamReceivers[0].push_back(std::unique_ptr(mockCsr)); auto mockMemoryManager = new MockMemoryManager(*executionEnvironment); executionEnvironment->memoryManager.reset(mockMemoryManager); device.reset(Device::create(executionEnvironment, 0)); device->setSourceLevelDebuggerActive(true); - return mockCsr; + return static_cast *>(device->getDefaultEngine().commandStreamReceiver); } std::unique_ptr device;