From 341fcfc0910e9fb857d28b6b9d9ff0630f5b446f Mon Sep 17 00:00:00 2001 From: "Stefanowski, Adam" Date: Wed, 23 Jan 2019 11:59:54 +0100 Subject: [PATCH] [1/n] Move Hardware Info to Execution Environment - remove gmm_environment_fixture - remove hwInfo parameter from ExecutionEnvironment methods Change-Id: Ieb0f9b5b89191fbbaf7676685c77644d42d69c26 Signed-off-by: Adam Stefanowski --- .../aub_command_stream_receiver_hw.inl | 2 +- .../tbx_command_stream_receiver_hw.inl | 4 +- runtime/device/device.cpp | 6 +- .../execution_environment.cpp | 23 +- .../execution_environment.h | 12 +- .../execution_environment_initialize.cpp | 2 +- runtime/os_interface/device_factory.cpp | 3 +- .../linux/device_factory_linux.cpp | 1 + .../windows/device_factory_win.cpp | 3 +- runtime/platform/platform.cpp | 4 +- unit_tests/aub_tests/fixtures/aub_fixture.h | 3 +- .../aub_command_stream_receiver_1_tests.cpp | 47 ++--- .../aub_command_stream_receiver_2_tests.cpp | 25 +-- ...and_stream_receiver_flush_task_2_tests.cpp | 2 +- .../command_stream_receiver_tests.cpp | 7 +- ...nd_stream_receiver_with_aub_dump_tests.cpp | 20 +- .../create_command_stream_receiver_tests.cpp | 18 +- .../command_stream/get_devices_tests.cpp | 11 +- .../tbx_command_stream_tests.cpp | 13 +- unit_tests/device/device_tests.cpp | 45 ++-- unit_tests/event/event_tests.cpp | 2 +- .../execution_environment_tests.cpp | 69 +++--- unit_tests/fixtures/CMakeLists.txt | 3 +- unit_tests/fixtures/device_fixture.h | 3 +- unit_tests/fixtures/gmm_environment_fixture.h | 22 -- unit_tests/fixtures/image_fixture.h | 3 +- .../fixtures/memory_allocator_fixture.h | 3 +- .../gen9/windows/os_interface_tests_gen9.cpp | 5 +- unit_tests/gmm_helper/gmm_helper_tests.cpp | 12 +- .../helpers/execution_environment_helper.cpp | 3 +- unit_tests/helpers/timestamp_packet_tests.cpp | 35 ++-- unit_tests/libult/create_command_stream.cpp | 1 + unit_tests/mem_obj/buffer_tests.cpp | 13 +- unit_tests/mem_obj/image_tests.cpp | 12 +- .../mem_obj/mem_obj_destruction_tests.cpp | 8 +- unit_tests/mem_obj/mem_obj_tests.cpp | 8 +- .../deferrable_allocation_deletion_tests.cpp | 5 +- .../memory_manager/memory_manager_tests.cpp | 47 ++--- unit_tests/mocks/mock_device.cpp | 5 +- unit_tests/mocks/mock_device.h | 8 +- unit_tests/mocks/mock_execution_environment.h | 7 +- .../os_interface/device_factory_tests.cpp | 26 +-- .../linux/device_command_stream_tests.cpp | 4 +- .../linux/drm_command_stream_tests.cpp | 4 +- .../linux/drm_memory_manager_tests.cpp | 6 +- .../windows/device_command_stream_tests.cpp | 198 +++++++++--------- .../os_interface/windows/wddm20_tests.cpp | 23 +- .../os_interface/windows/wddm23_tests.cpp | 8 +- .../windows/wddm_address_space_tests.cpp | 14 +- .../os_interface/windows/wddm_fixture.h | 31 ++- .../windows/wddm_kmdaf_listener_tests.cpp | 8 +- ..._manager_allocate_in_device_pool_tests.inl | 2 +- .../windows/wddm_memory_manager_tests.cpp | 45 ++-- .../windows/wddm_memory_manager_tests.h | 41 ++-- .../wddm_residency_controller_tests.cpp | 6 +- unit_tests/preemption/preemption_tests.cpp | 7 +- .../sharings/gl/gl_arb_sync_event_tests.cpp | 3 +- unit_tests/sharings/gl/gl_texture_tests.cpp | 11 +- .../source_level_debugger_device_tests.cpp | 13 +- .../source_level_debugger_tests.cpp | 9 +- unit_tests/ult_config_listener.cpp | 3 +- 61 files changed, 480 insertions(+), 507 deletions(-) delete mode 100644 unit_tests/fixtures/gmm_environment_fixture.h diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.inl b/runtime/command_stream/aub_command_stream_receiver_hw.inl index 728da65292..1363c423b9 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.inl +++ b/runtime/command_stream/aub_command_stream_receiver_hw.inl @@ -40,7 +40,7 @@ AUBCommandStreamReceiverHw::AUBCommandStreamReceiverHw(const Hardware : BaseClass(hwInfoIn, executionEnvironment), standalone(standalone) { - executionEnvironment.initAubCenter(&this->peekHwInfo(), this->localMemoryEnabled, fileName, this->getType()); + executionEnvironment.initAubCenter(this->localMemoryEnabled, fileName, this->getType()); auto aubCenter = executionEnvironment.aubCenter.get(); UNRECOVERABLE_IF(nullptr == aubCenter); diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.inl b/runtime/command_stream/tbx_command_stream_receiver_hw.inl index 6eb0c0e081..fb8202258e 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.inl +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.inl @@ -35,7 +35,7 @@ TbxCommandStreamReceiverHw::TbxCommandStreamReceiverHw(const Hardware : BaseClass(hwInfoIn, executionEnvironment) { physicalAddressAllocator.reset(this->createPhysicalAddressAllocator(&hwInfoIn)); - executionEnvironment.initAubCenter(&this->peekHwInfo(), this->localMemoryEnabled, "", this->getType()); + executionEnvironment.initAubCenter(this->localMemoryEnabled, "", this->getType()); auto aubCenter = executionEnvironment.aubCenter.get(); UNRECOVERABLE_IF(nullptr == aubCenter); @@ -176,7 +176,7 @@ CommandStreamReceiver *TbxCommandStreamReceiverHw::create(const Hardw auto &hwHelper = HwHelper::get(hwInfoIn.pPlatform->eRenderCoreFamily); auto localMemoryEnabled = hwHelper.getEnableLocalMemory(hwInfoIn); auto fullName = AUBCommandStreamReceiver::createFullFilePath(hwInfoIn, baseName); - executionEnvironment.initAubCenter(&hwInfoIn, localMemoryEnabled, fullName, CommandStreamReceiverType::CSR_TBX_WITH_AUB); + executionEnvironment.initAubCenter(localMemoryEnabled, fullName, CommandStreamReceiverType::CSR_TBX_WITH_AUB); csr = new CommandStreamReceiverWithAUBDump>(hwInfoIn, baseName, executionEnvironment); } else { diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index 86d7496cbd..bf458095b9 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -74,7 +74,7 @@ Device::Device(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnviro preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfo); if (!getSourceLevelDebugger()) { - this->executionEnvironment->initSourceLevelDebugger(hwInfo); + this->executionEnvironment->initSourceLevelDebugger(); } this->executionEnvironment->incRefInternal(); auto &hwHelper = HwHelper::get(hwInfo.pPlatform->eRenderCoreFamily); @@ -106,7 +106,7 @@ Device::~Device() { } bool Device::createDeviceImpl(const HardwareInfo *pHwInfo) { - executionEnvironment->initGmm(pHwInfo); + executionEnvironment->initGmm(); if (!createEngines(pHwInfo)) { return false; @@ -167,7 +167,7 @@ bool Device::createEngines(const HardwareInfo *pHwInfo) { auto &gpgpuEngines = HwHelper::get(pHwInfo->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances(); for (uint32_t deviceCsrIndex = 0; deviceCsrIndex < gpgpuEngines.size(); deviceCsrIndex++) { - if (!executionEnvironment->initializeCommandStreamReceiver(pHwInfo, getDeviceIndex(), deviceCsrIndex)) { + if (!executionEnvironment->initializeCommandStreamReceiver(getDeviceIndex(), deviceCsrIndex)) { return false; } diff --git a/runtime/execution_environment/execution_environment.cpp b/runtime/execution_environment/execution_environment.cpp index fd10821469..458cc76a97 100644 --- a/runtime/execution_environment/execution_environment.cpp +++ b/runtime/execution_environment/execution_environment.cpp @@ -25,17 +25,20 @@ ExecutionEnvironment::ExecutionEnvironment() = default; ExecutionEnvironment::~ExecutionEnvironment() = default; extern CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo, ExecutionEnvironment &executionEnvironment); -void ExecutionEnvironment::initAubCenter(const HardwareInfo *pHwInfo, bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType) { +void ExecutionEnvironment::initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType) { if (!aubCenter) { - aubCenter.reset(new AubCenter(pHwInfo, localMemoryEnabled, aubFileName, csrType)); + aubCenter.reset(new AubCenter(this->hwInfo, localMemoryEnabled, aubFileName, csrType)); } } -void ExecutionEnvironment::initGmm(const HardwareInfo *hwInfo) { +void ExecutionEnvironment::initGmm() { if (!gmmHelper) { - gmmHelper.reset(new GmmHelper(hwInfo)); + gmmHelper.reset(new GmmHelper(this->hwInfo)); } } -bool ExecutionEnvironment::initializeCommandStreamReceiver(const HardwareInfo *pHwInfo, uint32_t deviceIndex, uint32_t deviceCsrIndex) { +void ExecutionEnvironment::setHwInfo(const HardwareInfo *hwInfo) { + this->hwInfo = hwInfo; +} +bool ExecutionEnvironment::initializeCommandStreamReceiver(uint32_t deviceIndex, uint32_t deviceCsrIndex) { if (deviceIndex + 1 > commandStreamReceivers.size()) { commandStreamReceivers.resize(deviceIndex + 1); } @@ -46,11 +49,11 @@ bool ExecutionEnvironment::initializeCommandStreamReceiver(const HardwareInfo *p if (this->commandStreamReceivers[deviceIndex][deviceCsrIndex]) { return true; } - std::unique_ptr commandStreamReceiver(createCommandStream(pHwInfo, *this)); + std::unique_ptr commandStreamReceiver(createCommandStream(this->hwInfo, *this)); if (!commandStreamReceiver) { return false; } - if (HwHelper::get(pHwInfo->pPlatform->eRenderCoreFamily).isPageTableManagerSupported(*pHwInfo)) { + if (HwHelper::get(this->hwInfo->pPlatform->eRenderCoreFamily).isPageTableManagerSupported(*this->hwInfo)) { commandStreamReceiver->createPageTableManager(); } commandStreamReceiver->setDeviceIndex(deviceIndex); @@ -83,12 +86,12 @@ void ExecutionEnvironment::initializeMemoryManager(bool enable64KBpages, bool en } DEBUG_BREAK_IF(!this->memoryManager); } -void ExecutionEnvironment::initSourceLevelDebugger(const HardwareInfo &hwInfo) { - if (hwInfo.capabilityTable.sourceLevelDebuggerSupported) { +void ExecutionEnvironment::initSourceLevelDebugger() { + if (this->hwInfo->capabilityTable.sourceLevelDebuggerSupported) { sourceLevelDebugger.reset(SourceLevelDebugger::create()); } if (sourceLevelDebugger) { - bool localMemorySipAvailable = (SipKernelType::DbgCsrLocal == SipKernel::getSipKernelType(hwInfo.pPlatform->eRenderCoreFamily, true)); + bool localMemorySipAvailable = (SipKernelType::DbgCsrLocal == SipKernel::getSipKernelType(this->hwInfo->pPlatform->eRenderCoreFamily, true)); sourceLevelDebugger->initialize(localMemorySipAvailable); } } diff --git a/runtime/execution_environment/execution_environment.h b/runtime/execution_environment/execution_environment.h index a0b55f68d3..133831f8d5 100644 --- a/runtime/execution_environment/execution_environment.h +++ b/runtime/execution_environment/execution_environment.h @@ -36,17 +36,19 @@ class ExecutionEnvironment : public ReferenceTrackedObject protected: std::unique_ptr gmmHelper; + const HardwareInfo *hwInfo = nullptr; public: ExecutionEnvironment(); ~ExecutionEnvironment() override; - MOCKABLE_VIRTUAL void initAubCenter(const HardwareInfo *hwInfo, bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType); - void initGmm(const HardwareInfo *hwInfo); - bool initializeCommandStreamReceiver(const HardwareInfo *pHwInfo, uint32_t deviceIndex, uint32_t deviceCsrIndex); - void initializeSpecialCommandStreamReceiver(const HardwareInfo &hwInfo); + MOCKABLE_VIRTUAL void initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType); + void initGmm(); + bool initializeCommandStreamReceiver(uint32_t deviceIndex, uint32_t deviceCsrIndex); + void initializeSpecialCommandStreamReceiver(); void initializeMemoryManager(bool enable64KBpages, bool enableLocalMemory); - void initSourceLevelDebugger(const HardwareInfo &hwInfo); + void initSourceLevelDebugger(); + void setHwInfo(const HardwareInfo *hwInfo); GmmHelper *getGmmHelper() const; MOCKABLE_VIRTUAL CompilerInterface *getCompilerInterface(); diff --git a/runtime/execution_environment/execution_environment_initialize.cpp b/runtime/execution_environment/execution_environment_initialize.cpp index d28289de50..5001b6c40e 100644 --- a/runtime/execution_environment/execution_environment_initialize.cpp +++ b/runtime/execution_environment/execution_environment_initialize.cpp @@ -8,7 +8,7 @@ #include "runtime/execution_environment/execution_environment.h" namespace OCLRT { -void ExecutionEnvironment::initializeSpecialCommandStreamReceiver(const HardwareInfo &hwInfo) { +void ExecutionEnvironment::initializeSpecialCommandStreamReceiver() { } } // namespace OCLRT diff --git a/runtime/os_interface/device_factory.cpp b/runtime/os_interface/device_factory.cpp index 00f8216c3d..5390fb37cc 100644 --- a/runtime/os_interface/device_factory.cpp +++ b/runtime/os_interface/device_factory.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -35,6 +35,7 @@ bool DeviceFactory::getDevicesForProductFamilyOverride(HardwareInfo **pHWInfos, numDevices++; } *pHWInfos = tempHwInfos.get(); + executionEnvironment.setHwInfo(*pHWInfos); DeviceFactory::numDevices = numDevices; DeviceFactory::hwInfos = tempHwInfos.get(); tempHwInfos.release(); diff --git a/runtime/os_interface/linux/device_factory_linux.cpp b/runtime/os_interface/linux/device_factory_linux.cpp index 2f0aa150d1..d7054ce8bf 100644 --- a/runtime/os_interface/linux/device_factory_linux.cpp +++ b/runtime/os_interface/linux/device_factory_linux.cpp @@ -59,6 +59,7 @@ bool DeviceFactory::getDevices(HardwareInfo **pHWInfos, size_t &numDevices, Exec numDevices = devNum; *pHWInfos = ptr; + executionEnvironment.setHwInfo(*pHWInfos); DeviceFactory::numDevices = devNum; DeviceFactory::hwInfos = ptr; diff --git a/runtime/os_interface/windows/device_factory_win.cpp b/runtime/os_interface/windows/device_factory_win.cpp index 1d63d38ccb..f721d30be5 100644 --- a/runtime/os_interface/windows/device_factory_win.cpp +++ b/runtime/os_interface/windows/device_factory_win.cpp @@ -51,7 +51,8 @@ bool DeviceFactory::getDevices(HardwareInfo **pHWInfos, size_t &numDevices, Exec DeviceFactory::hwInfos = tempHwInfos.get(); tempHwInfos.release(); - executionEnvironment.initGmm(*pHWInfos); + executionEnvironment.setHwInfo(*pHWInfos); + executionEnvironment.initGmm(); auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(**pHWInfos); bool success = executionEnvironment.osInterface->get()->getWddm()->init(preemptionMode); DEBUG_BREAK_IF(!success); diff --git a/runtime/platform/platform.cpp b/runtime/platform/platform.cpp index 923eb95d9c..97688eacbe 100644 --- a/runtime/platform/platform.cpp +++ b/runtime/platform/platform.cpp @@ -175,7 +175,7 @@ bool Platform::initialize() { return false; } } - executionEnvironment->initializeSpecialCommandStreamReceiver(*hwInfo); + executionEnvironment->initializeSpecialCommandStreamReceiver(); const bool sourceLevelDebuggerActive = executionEnvironment->sourceLevelDebugger && executionEnvironment->sourceLevelDebugger->isDebuggerActive(); if (devices[0]->getPreemptionMode() == PreemptionMode::MidThread || sourceLevelDebuggerActive) { @@ -186,7 +186,7 @@ bool Platform::initialize() { CommandStreamReceiverType csrType = this->devices[0]->getDefaultEngine().commandStreamReceiver->getType(); if (csrType != CommandStreamReceiverType::CSR_HW) { auto enableLocalMemory = HwHelper::get(hwInfo->pPlatform->eRenderCoreFamily).getEnableLocalMemory(*hwInfo); - executionEnvironment->initAubCenter(&hwInfo[0], enableLocalMemory, "aubfile", csrType); + executionEnvironment->initAubCenter(enableLocalMemory, "aubfile", csrType); } this->fillGlobalDispatchTable(); diff --git a/unit_tests/aub_tests/fixtures/aub_fixture.h b/unit_tests/aub_tests/fixtures/aub_fixture.h index f45ae2f877..66900f6210 100644 --- a/unit_tests/aub_tests/fixtures/aub_fixture.h +++ b/unit_tests/aub_tests/fixtures/aub_fixture.h @@ -13,6 +13,7 @@ #include "runtime/command_stream/tbx_command_stream_receiver_hw.h" #include "runtime/helpers/hw_helper.h" #include "runtime/os_interface/os_interface.h" +#include "runtime/platform/platform.h" #include "unit_tests/command_queue/command_queue_fixture.h" #include "unit_tests/mocks/mock_device.h" #include "unit_tests/tests_configuration.h" @@ -34,7 +35,7 @@ class AUBFixture : public CommandQueueHwFixture { std::stringstream strfilename; strfilename << testInfo->test_case_name() << "_" << testInfo->name() << "_" << hwHelper.getCsTraits(engineType).name; - executionEnvironment = new ExecutionEnvironment; + executionEnvironment = platformImpl->peekExecutionEnvironment(); if (testMode == TestMode::AubTestsWithTbx) { this->csr = TbxCommandStreamReceiver::create(hwInfo, strfilename.str(), true, *executionEnvironment); } else { 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 b1471a214b..c451ce08b2 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 @@ -81,7 +81,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenItIsCre DebugManager.flags.UseAubStream.set(false); HardwareInfo hwInfo = *platformDevices[0]; - auto aubCsr = std::make_unique>(hwInfo, "", true, executionEnvironment); + auto aubCsr = std::make_unique>(hwInfo, "", true, *pDevice->executionEnvironment); ASSERT_NE(nullptr, aubCsr); EXPECT_EQ(nullptr, aubCsr->aubManager); @@ -89,7 +89,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenItIsCre } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGetEngineIndexFromInstanceIsCalledForGivenEngineInstanceThenEngineIndexForThatInstanceIsReturned) { - auto aubCsr = std::make_unique>(**platformDevices, "", true, executionEnvironment); + auto aubCsr = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); EXPECT_NE(nullptr, aubCsr); EXPECT_TRUE(aubCsr->getEngineIndex(EngineInstanceT(EngineType::ENGINE_RCS, 0)) < allEngineInstances.size()); @@ -105,7 +105,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGetEngi } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGetEngineIndexIsCalledForGivenEngineTypeThenEngineIndexForThatTypeIsReturned) { - auto aubCsr = std::make_unique>(**platformDevices, "", true, executionEnvironment); + auto aubCsr = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); EXPECT_NE(nullptr, aubCsr); auto engineIndex = aubCsr->getEngineIndex(EngineInstanceT(EngineType::ENGINE_RCS, 1)); @@ -134,52 +134,47 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenItIsCre } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesAreCreatedThenTheyOperateOnSingleFileStream) { - ExecutionEnvironment executionEnvironment; - auto aubCsr1 = std::make_unique>(**platformDevices, "", true, executionEnvironment); - auto aubCsr2 = std::make_unique>(**platformDevices, "", true, executionEnvironment); + auto aubCsr1 = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); + auto aubCsr2 = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); EXPECT_EQ(aubCsr1->stream, aubCsr2->stream); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesAreCreatedThenTheyUseTheSameFileStream) { - ExecutionEnvironment executionEnvironment; - auto aubCsr1 = std::make_unique>(**platformDevices, "", true, executionEnvironment); - auto streamProvider1 = executionEnvironment.aubCenter->getStreamProvider(); + auto aubCsr1 = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); + auto streamProvider1 = pDevice->executionEnvironment->aubCenter->getStreamProvider(); EXPECT_NE(nullptr, streamProvider1); - auto aubCsr2 = std::make_unique>(**platformDevices, "", true, executionEnvironment); - auto streamProvider2 = executionEnvironment.aubCenter->getStreamProvider(); + auto aubCsr2 = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); + auto streamProvider2 = pDevice->executionEnvironment->aubCenter->getStreamProvider(); EXPECT_NE(nullptr, streamProvider2); EXPECT_EQ(streamProvider1, streamProvider2); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesAreCreatedThenTheyUseTheSamePhysicalAddressAllocator) { - ExecutionEnvironment executionEnvironment; - auto aubCsr1 = std::make_unique>(**platformDevices, "", true, executionEnvironment); - auto physicalAddressAlocator1 = executionEnvironment.aubCenter->getPhysicalAddressAllocator(); + auto aubCsr1 = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); + auto physicalAddressAlocator1 = pDevice->executionEnvironment->aubCenter->getPhysicalAddressAllocator(); EXPECT_NE(nullptr, physicalAddressAlocator1); - auto aubCsr2 = std::make_unique>(**platformDevices, "", true, executionEnvironment); - auto physicalAddressAlocator2 = executionEnvironment.aubCenter->getPhysicalAddressAllocator(); + auto aubCsr2 = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); + auto physicalAddressAlocator2 = pDevice->executionEnvironment->aubCenter->getPhysicalAddressAllocator(); EXPECT_NE(nullptr, physicalAddressAlocator2); EXPECT_EQ(physicalAddressAlocator1, physicalAddressAlocator2); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesAreCreatedThenTheyUseTheSameAddressMapper) { - ExecutionEnvironment executionEnvironment; - auto aubCsr1 = std::make_unique>(**platformDevices, "", true, executionEnvironment); - auto addressMapper1 = executionEnvironment.aubCenter->getAddressMapper(); + auto aubCsr1 = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); + auto addressMapper1 = pDevice->executionEnvironment->aubCenter->getAddressMapper(); EXPECT_NE(nullptr, addressMapper1); - auto aubCsr2 = std::make_unique>(**platformDevices, "", true, executionEnvironment); - auto addressMapper2 = executionEnvironment.aubCenter->getAddressMapper(); + auto aubCsr2 = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); + auto addressMapper2 = pDevice->executionEnvironment->aubCenter->getAddressMapper(); EXPECT_NE(nullptr, addressMapper2); EXPECT_EQ(addressMapper1, addressMapper2); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesAreCreatedThenTheyUseTheSameSubCaptureManager) { - ExecutionEnvironment executionEnvironment; - auto aubCsr1 = std::make_unique>(**platformDevices, "", true, executionEnvironment); - auto subCaptureManager1 = executionEnvironment.aubCenter->getSubCaptureManager(); + auto aubCsr1 = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); + auto subCaptureManager1 = pDevice->executionEnvironment->aubCenter->getSubCaptureManager(); EXPECT_NE(nullptr, subCaptureManager1); - auto aubCsr2 = std::make_unique>(**platformDevices, "", true, executionEnvironment); - auto subCaptureManager2 = executionEnvironment.aubCenter->getSubCaptureManager(); + auto aubCsr2 = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); + auto subCaptureManager2 = pDevice->executionEnvironment->aubCenter->getSubCaptureManager(); EXPECT_NE(nullptr, subCaptureManager2); EXPECT_EQ(subCaptureManager1, subCaptureManager2); } 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 b79b1e8dce..8eec899853 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 @@ -10,6 +10,7 @@ #include "runtime/helpers/hardware_context_controller.h" #include "runtime/helpers/hw_helper.h" #include "runtime/mem_obj/mem_obj_helper.h" +#include "runtime/platform/platform.h" #include "test.h" #include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" @@ -468,13 +469,13 @@ class OsAgnosticMemoryManagerForImagesWithNoHostPtr : public OsAgnosticMemoryMan using AubCommandStreamReceiverNoHostPtrTests = ::testing::Test; HWTEST_F(AubCommandStreamReceiverNoHostPtrTests, givenAubCommandStreamReceiverWhenWriteMemoryIsCalledOnImageWithNoHostPtrThenResourceShouldBeLockedToGetCpuAddress) { - ExecutionEnvironment executionEnvironment; - auto memoryManager = new OsAgnosticMemoryManagerForImagesWithNoHostPtr(executionEnvironment); - executionEnvironment.memoryManager.reset(memoryManager); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + auto memoryManager = new OsAgnosticMemoryManagerForImagesWithNoHostPtr(*executionEnvironment); + executionEnvironment->memoryManager.reset(memoryManager); auto engineInstance = HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0]; MockOsContext osContext(nullptr, 0, 1, engineInstance, PreemptionMode::Disabled); - std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, executionEnvironment)); + std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *executionEnvironment)); aubCsr->setupContext(osContext); cl_image_desc imgDesc = {}; @@ -703,11 +704,11 @@ HWTEST_F(AubCommandStreamReceiverTests, whenAubCommandStreamReceiverIsCreatedThe } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenEngineIsInitializedThenDumpHandleIsGenerated) { - executionEnvironment.aubCenter.reset(new AubCenter()); + pDevice->executionEnvironment->aubCenter.reset(new AubCenter()); auto engineInstance = HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0]; MockOsContext osContext(nullptr, 0, 1, engineInstance, PreemptionMode::Disabled); - auto aubCsr = std::make_unique>(**platformDevices, "", true, executionEnvironment); + auto aubCsr = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); EXPECT_NE(nullptr, aubCsr); aubCsr->setupContext(osContext); @@ -721,7 +722,7 @@ HWTEST_F(InjectMmmioTest, givenAddMmioKeySetToZeroWhenInitAdditionalMmioCalledTh DebugManagerStateRestore stateRestore; DebugManager.flags.AubDumpAddMmioRegistersList.set(""); - auto aubCsr = std::make_unique>(**platformDevices, "", true, executionEnvironment); + auto aubCsr = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); EXPECT_NE(nullptr, aubCsr); auto stream = std::make_unique(); @@ -738,7 +739,7 @@ HWTEST_F(InjectMmmioTest, givenAddMmioRegistersListSetWhenInitAdditionalMmioCall DebugManagerStateRestore stateRestore; DebugManager.flags.AubDumpAddMmioRegistersList.set(registers); - auto aubCsr = std::make_unique>(**platformDevices, "", true, executionEnvironment); + auto aubCsr = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); EXPECT_NE(nullptr, aubCsr); auto stream = std::make_unique(); @@ -755,7 +756,7 @@ HWTEST_F(InjectMmmioTest, givenLongSequenceOfAddMmioRegistersListSetWhenInitAddi DebugManagerStateRestore stateRestore; DebugManager.flags.AubDumpAddMmioRegistersList.set(registers); - auto aubCsr = std::make_unique>(**platformDevices, "", true, executionEnvironment); + auto aubCsr = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); EXPECT_NE(nullptr, aubCsr); auto stream = std::make_unique(); @@ -773,7 +774,7 @@ HWTEST_F(InjectMmmioTest, givenSequenceWithIncompletePairOfAddMmioRegistersListS DebugManagerStateRestore stateRestore; DebugManager.flags.AubDumpAddMmioRegistersList.set(registers); - auto aubCsr = std::make_unique>(**platformDevices, "", true, executionEnvironment); + auto aubCsr = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); EXPECT_NE(nullptr, aubCsr); auto stream = std::make_unique(); @@ -792,7 +793,7 @@ HWTEST_F(InjectMmmioTest, givenAddMmioRegistersListSetWithSemicolonAtTheEndWhenI DebugManagerStateRestore stateRestore; DebugManager.flags.AubDumpAddMmioRegistersList.set(registers); - auto aubCsr = std::make_unique>(**platformDevices, "", true, executionEnvironment); + auto aubCsr = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); EXPECT_NE(nullptr, aubCsr); auto stream = std::make_unique(); @@ -809,7 +810,7 @@ HWTEST_F(InjectMmmioTest, givenAddMmioRegistersListSetWithInvalidValueWhenInitAd DebugManagerStateRestore stateRestore; DebugManager.flags.AubDumpAddMmioRegistersList.set(registers); - auto aubCsr = std::make_unique>(**platformDevices, "", true, executionEnvironment); + auto aubCsr = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); EXPECT_NE(nullptr, aubCsr); auto stream = std::make_unique(); diff --git a/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp b/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp index ed426aa3c3..2c1fb6a585 100644 --- a/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp @@ -385,7 +385,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, GivenKernelWithSlmWhenPreviousSLML HWTEST_F(CommandStreamReceiverFlushTaskTests, CreateCommandStreamReceiverHw) { const HardwareInfo hwInfo = *platformDevices[0]; - auto csrHw = CommandStreamReceiverHw::create(hwInfo, executionEnvironment); + auto csrHw = CommandStreamReceiverHw::create(hwInfo, *pDevice->executionEnvironment); EXPECT_NE(nullptr, csrHw); GmmPageTableMngr *ptm = csrHw->createPageTableManager(); diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index 624487bce0..506cc3f260 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -15,6 +15,7 @@ #include "runtime/memory_manager/internal_allocation_storage.h" #include "runtime/memory_manager/memory_manager.h" #include "runtime/memory_manager/surface.h" +#include "runtime/platform/platform.h" #include "runtime/utilities/tag_allocator.h" #include "test.h" #include "unit_tests/fixtures/device_fixture.h" @@ -287,7 +288,7 @@ HWTEST_F(CommandStreamReceiverTest, givenDebugVariableEnabledWhenCreatingCsrThen } HWTEST_F(CommandStreamReceiverTest, whenCsrIsCreatedThenUseTimestampPacketWriteIfPossible) { - CommandStreamReceiverHw csr(*platformDevices[0], executionEnvironment); + CommandStreamReceiverHw csr(*platformDevices[0], *pDevice->executionEnvironment); EXPECT_EQ(UnitTestHelper::isTimestampPacketWriteSupported(), csr.peekTimestampPacketWriteEnabled()); } @@ -396,7 +397,7 @@ TEST(CommandStreamReceiverSimpleTest, givenCSRWhenWaitBeforeMakingNonResidentWhe } TEST(CommandStreamReceiverMultiContextTests, givenMultipleCsrsWhenSameResourcesAreUsedThenResidencyIsProperlyHandled) { - auto executionEnvironment = new ExecutionEnvironment; + auto executionEnvironment = platformImpl->peekExecutionEnvironment(); std::unique_ptr device(Device::create(nullptr, executionEnvironment, 0u)); @@ -433,7 +434,7 @@ TEST(CommandStreamReceiverMultiContextTests, givenMultipleCsrsWhenSameResourcesA struct CreateAllocationForHostSurfaceTest : public ::testing::Test { void SetUp() override { - executionEnvironment = new ExecutionEnvironment; + executionEnvironment = platformImpl->peekExecutionEnvironment(); gmockMemoryManager = new ::testing::NiceMock(*executionEnvironment); executionEnvironment->memoryManager.reset(gmockMemoryManager); device.reset(MockDevice::create(&hwInfo, executionEnvironment, 0u)); diff --git a/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp b/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp index 11060bc32a..8fcd60b4b4 100644 --- a/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp @@ -13,6 +13,7 @@ #include "runtime/helpers/dispatch_info.h" #include "runtime/helpers/hw_helper.h" #include "runtime/os_interface/os_context.h" +#include "runtime/platform/platform.h" #include "test.h" #include "unit_tests/libult/ult_command_stream_receiver.h" #include "unit_tests/mocks/mock_allocation_properties.h" @@ -102,23 +103,24 @@ struct MyMockCsrWithAubDump : CommandStreamReceiverWithAUBDump { struct CommandStreamReceiverWithAubDumpTest : public ::testing::TestWithParam { void SetUp() override { + executionEnvironment = platformImpl->peekExecutionEnvironment(); createAubCSR = GetParam(); - csrWithAubDump = new MyMockCsrWithAubDump(DEFAULT_TEST_PLATFORM::hwInfo, createAubCSR, executionEnvironment); + csrWithAubDump = new MyMockCsrWithAubDump(DEFAULT_TEST_PLATFORM::hwInfo, createAubCSR, *executionEnvironment); ASSERT_NE(nullptr, csrWithAubDump); - executionEnvironment.initializeMemoryManager(false, false); - memoryManager = executionEnvironment.memoryManager.get(); + executionEnvironment->initializeMemoryManager(false, false); + memoryManager = executionEnvironment->memoryManager.get(); ASSERT_NE(nullptr, memoryManager); - auto osContext = executionEnvironment.memoryManager->createAndRegisterOsContext(csrWithAubDump, - getChosenEngineType(DEFAULT_TEST_PLATFORM::hwInfo), - 1, PreemptionHelper::getDefaultPreemptionMode(DEFAULT_TEST_PLATFORM::hwInfo)); + auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(csrWithAubDump, + getChosenEngineType(DEFAULT_TEST_PLATFORM::hwInfo), + 1, PreemptionHelper::getDefaultPreemptionMode(DEFAULT_TEST_PLATFORM::hwInfo)); csrWithAubDump->setupContext(*osContext); } void TearDown() override { delete csrWithAubDump; } - ExecutionEnvironment executionEnvironment; + ExecutionEnvironment *executionEnvironment; MyMockCsrWithAubDump *csrWithAubDump; MemoryManager *memoryManager; bool createAubCSR; @@ -127,9 +129,9 @@ struct CommandStreamReceiverWithAubDumpTest : public ::testing::TestWithParampeekExecutionEnvironment(); - CommandStreamReceiverWithAUBDump> csrWithAubDump(*platformDevices[0], "aubfile", executionEnvironment); + CommandStreamReceiverWithAUBDump> csrWithAubDump(*platformDevices[0], "aubfile", *executionEnvironment); MockOsContext osContext(nullptr, 0, 1, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])); csrWithAubDump.setupContext(osContext); 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 eb4d93942f..ba55e5e589 100644 --- a/unit_tests/command_stream/create_command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/create_command_stream_receiver_tests.cpp @@ -11,7 +11,6 @@ #include "runtime/helpers/options.h" #include "runtime/memory_manager/os_agnostic_memory_manager.h" #include "test.h" -#include "unit_tests/fixtures/gmm_environment_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/helpers/execution_environment_helper.h" #include "unit_tests/helpers/variable_backup.h" @@ -19,25 +18,12 @@ using namespace OCLRT; -struct CreateCommandStreamReceiverTest : public GmmEnvironmentFixture, public ::testing::TestWithParam { - void SetUp() override { - GmmEnvironmentFixture::SetUp(); - storeInitHWTag = initialHardwareTag; - } - - void TearDown() override { - initialHardwareTag = storeInitHWTag; - GmmEnvironmentFixture::TearDown(); - } - - protected: - int storeInitHWTag; -}; +struct CreateCommandStreamReceiverTest : public ::testing::TestWithParam {}; HWTEST_P(CreateCommandStreamReceiverTest, givenCreateCommandStreamWhenCsrIsSetToValidTypeThenTheFuntionReturnsCommandStreamReceiver) { DebugManagerStateRestore stateRestorer; HardwareInfo *hwInfo = nullptr; - std::unique_ptr executionEnvironment = std::unique_ptr(getExecutionEnvironmentImpl(hwInfo)); + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); CommandStreamReceiverType csrType = GetParam(); diff --git a/unit_tests/command_stream/get_devices_tests.cpp b/unit_tests/command_stream/get_devices_tests.cpp index f643a671c1..8450eb3b74 100644 --- a/unit_tests/command_stream/get_devices_tests.cpp +++ b/unit_tests/command_stream/get_devices_tests.cpp @@ -10,6 +10,7 @@ #include "runtime/helpers/options.h" #include "runtime/memory_manager/os_agnostic_memory_manager.h" #include "runtime/os_interface/device_factory.h" +#include "runtime/platform/platform.h" #include "test.h" #include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/libult/create_command_stream.h" @@ -58,9 +59,9 @@ HWTEST_F(GetDevicesTest, givenGetDevicesWhenCsrIsSetToVariousTypesThenTheFunctio } DebugManager.flags.ProductFamilyOverride.set(productFamily); - ExecutionEnvironment exeEnv; + ExecutionEnvironment *exeEnv = platformImpl->peekExecutionEnvironment(); - const auto ret = getDevices(&hwInfo, numDevices, exeEnv); + const auto ret = getDevices(&hwInfo, numDevices, *exeEnv); switch (csrType) { case CSR_HW: @@ -89,6 +90,7 @@ HWTEST_F(GetDevicesTest, givenGetDevicesWhenCsrIsSetToVariousTypesThenTheFunctio EXPECT_EQ(0, memcmp(&hardwareInfoTable[i]->capabilityTable, &hwInfo->capabilityTable, sizeof(RuntimeCapabilityTable))); EXPECT_EQ(0, memcmp(hardwareInfoTable[i]->pWaTable, hwInfo->pWaTable, sizeof(WorkaroundTable))); EXPECT_STREQ(hardwarePrefix[i], productFamily.c_str()); + DeviceFactory::releaseDevices(); break; default: break; @@ -104,9 +106,9 @@ HWTEST_F(GetDevicesTest, givenGetDevicesAndUnknownProductFamilyWhenCsrIsSetToVal DebugManager.flags.SetCommandStreamReceiver.set(csrType); DebugManager.flags.ProductFamilyOverride.set(productFamily); - ExecutionEnvironment exeEnv; + ExecutionEnvironment *exeEnv = platformImpl->peekExecutionEnvironment(); - auto ret = getDevices(&hwInfo, numDevices, exeEnv); + auto ret = getDevices(&hwInfo, numDevices, *exeEnv); switch (csrType) { case CSR_HW: @@ -135,6 +137,7 @@ HWTEST_F(GetDevicesTest, givenGetDevicesAndUnknownProductFamilyWhenCsrIsSetToVal EXPECT_EQ(0, memcmp(defaultHwInfo->pPlatform, hwInfo->pPlatform, sizeof(PLATFORM))); EXPECT_EQ(0, memcmp(&defaultHwInfo->capabilityTable, &hwInfo->capabilityTable, sizeof(RuntimeCapabilityTable))); EXPECT_EQ(0, memcmp(defaultHwInfo->pWaTable, hwInfo->pWaTable, sizeof(WorkaroundTable))); + DeviceFactory::releaseDevices(); break; } default: diff --git a/unit_tests/command_stream/tbx_command_stream_tests.cpp b/unit_tests/command_stream/tbx_command_stream_tests.cpp index 99c66d0d0d..2e0f518f19 100644 --- a/unit_tests/command_stream/tbx_command_stream_tests.cpp +++ b/unit_tests/command_stream/tbx_command_stream_tests.cpp @@ -15,6 +15,7 @@ #include "runtime/memory_manager/memory_banks.h" #include "runtime/os_interface/debug_settings_manager.h" #include "runtime/os_interface/os_context.h" +#include "runtime/platform/platform.h" #include "test.h" #include "unit_tests/command_queue/command_queue_fixture.h" #include "unit_tests/fixtures/device_fixture.h" @@ -148,8 +149,8 @@ TEST(TbxCommandStreamReceiverTest, givenTbxCommandStreamReceiverWhenItIsCreatedW TEST(TbxCommandStreamReceiverTest, givenTbxCommandStreamReceiverWhenTypeIsCheckedThenTbxCsrIsReturned) { HardwareInfo hwInfo = *platformDevices[0]; - ExecutionEnvironment executionEnvironment; - std::unique_ptr csr(TbxCommandStreamReceiver::create(hwInfo, "", false, executionEnvironment)); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + std::unique_ptr csr(TbxCommandStreamReceiver::create(hwInfo, "", false, *executionEnvironment)); EXPECT_NE(nullptr, csr); EXPECT_EQ(CommandStreamReceiverType::CSR_TBX, csr->getType()); } @@ -293,8 +294,7 @@ HWTEST_F(TbxCommandStreamTests, givenDbgDeviceIdFlagIsSetWhenTbxCsrIsCreatedThen DebugManagerStateRestore stateRestore; DebugManager.flags.OverrideAubDeviceId.set(9); //this is Hsw, not used const HardwareInfo &hwInfoIn = *platformDevices[0]; - ExecutionEnvironment executionEnvironment; - std::unique_ptr> tbxCsr(reinterpret_cast *>(TbxCommandStreamReceiver::create(hwInfoIn, "", false, executionEnvironment))); + std::unique_ptr> tbxCsr(reinterpret_cast *>(TbxCommandStreamReceiver::create(hwInfoIn, "", false, *pDevice->executionEnvironment))); EXPECT_EQ(9u, tbxCsr->aubDeviceId); } @@ -482,14 +482,13 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenOsContextIsSetThenCreateHardwareC } HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenPollForCompletionImplIsCalledThenSimulatedCsrMethodIsCalled) { - ExecutionEnvironment executionEnvironment; - - std::unique_ptr> tbxCsr(reinterpret_cast *>(TbxCommandStreamReceiver::create(*platformDevices[0], "", false, executionEnvironment))); + std::unique_ptr> tbxCsr(reinterpret_cast *>(TbxCommandStreamReceiver::create(*platformDevices[0], "", false, *pDevice->executionEnvironment))); tbxCsr->pollForCompletionImpl(); } HWTEST_F(TbxCommandStreamTests, givenTbxCsrWhenCreatedWithAubDumpThenFileNameIsExtendedWithSystemInfo) { MockExecutionEnvironment executionEnvironment; + executionEnvironment.setHwInfo(*platformDevices); auto fullName = AUBCommandStreamReceiver::createFullFilePath(*platformDevices[0], "aubfile"); diff --git a/unit_tests/device/device_tests.cpp b/unit_tests/device/device_tests.cpp index eddf8c00b6..58d7d985eb 100644 --- a/unit_tests/device/device_tests.cpp +++ b/unit_tests/device/device_tests.cpp @@ -10,6 +10,7 @@ #include "runtime/helpers/options.h" #include "runtime/indirect_heap/indirect_heap.h" #include "runtime/os_interface/os_context.h" +#include "runtime/platform/platform.h" #include "test.h" #include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" @@ -154,15 +155,14 @@ TEST(DeviceCreation, givenDeviceWhenItIsCreatedThenOsContextIsRegistredInMemoryM } TEST(DeviceCreation, givenMultiDeviceWhenTheyAreCreatedThenEachOsContextHasUniqueId) { - ExecutionEnvironment executionEnvironment; - executionEnvironment.incRefInternal(); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); const size_t numDevices = 2; const auto &numGpgpuEngines = static_cast(HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances().size()); - auto device1 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 0u)); - auto device2 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 1u)); + auto device1 = std::unique_ptr(Device::create(nullptr, executionEnvironment, 0u)); + auto device2 = std::unique_ptr(Device::create(nullptr, executionEnvironment, 1u)); - auto ®isteredEngines = executionEnvironment.memoryManager->getRegisteredEngines(); + auto ®isteredEngines = executionEnvironment->memoryManager->getRegisteredEngines(); EXPECT_EQ(numGpgpuEngines * numDevices, registeredEngines.size()); for (uint32_t i = 0; i < numGpgpuEngines; i++) { @@ -176,43 +176,40 @@ TEST(DeviceCreation, givenMultiDeviceWhenTheyAreCreatedThenEachOsContextHasUniqu EXPECT_EQ(registeredEngines[i + numGpgpuEngines].commandStreamReceiver, device2->getEngine(i).commandStreamReceiver); } - EXPECT_EQ(numGpgpuEngines * numDevices, executionEnvironment.memoryManager->getRegisteredEnginesCount()); + EXPECT_EQ(numGpgpuEngines * numDevices, executionEnvironment->memoryManager->getRegisteredEnginesCount()); } TEST(DeviceCreation, givenMultiDeviceWhenTheyAreCreatedThenEachDeviceHasSeperateDeviceIndex) { - ExecutionEnvironment executionEnvironment; - executionEnvironment.incRefInternal(); - auto device = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 0u)); - auto device2 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 1u)); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + auto device = std::unique_ptr(Device::create(nullptr, executionEnvironment, 0u)); + auto device2 = std::unique_ptr(Device::create(nullptr, executionEnvironment, 1u)); EXPECT_EQ(0u, device->getDeviceIndex()); EXPECT_EQ(1u, device2->getDeviceIndex()); } TEST(DeviceCreation, givenMultiDeviceWhenTheyAreCreatedThenEachDeviceHasSeperateCommandStreamReceiver) { - ExecutionEnvironment executionEnvironment; - executionEnvironment.incRefInternal(); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); const size_t numDevices = 2; const auto &numGpgpuEngines = HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances().size(); - auto device1 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 0u)); - auto device2 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 1u)); + auto device1 = std::unique_ptr(Device::create(nullptr, executionEnvironment, 0u)); + auto device2 = std::unique_ptr(Device::create(nullptr, executionEnvironment, 1u)); - EXPECT_EQ(numDevices, executionEnvironment.commandStreamReceivers.size()); - EXPECT_EQ(numGpgpuEngines, executionEnvironment.commandStreamReceivers[0].size()); - EXPECT_EQ(numGpgpuEngines, executionEnvironment.commandStreamReceivers[1].size()); + EXPECT_EQ(numDevices, executionEnvironment->commandStreamReceivers.size()); + EXPECT_EQ(numGpgpuEngines, executionEnvironment->commandStreamReceivers[0].size()); + EXPECT_EQ(numGpgpuEngines, executionEnvironment->commandStreamReceivers[1].size()); for (uint32_t i = 0; i < static_cast(numGpgpuEngines); i++) { - EXPECT_NE(nullptr, executionEnvironment.commandStreamReceivers[0][i]); - EXPECT_NE(nullptr, executionEnvironment.commandStreamReceivers[1][i]); - EXPECT_EQ(executionEnvironment.commandStreamReceivers[0][i].get(), device1->getEngine(i).commandStreamReceiver); - EXPECT_EQ(executionEnvironment.commandStreamReceivers[1][i].get(), device2->getEngine(i).commandStreamReceiver); + EXPECT_NE(nullptr, executionEnvironment->commandStreamReceivers[0][i]); + EXPECT_NE(nullptr, executionEnvironment->commandStreamReceivers[1][i]); + EXPECT_EQ(executionEnvironment->commandStreamReceivers[0][i].get(), device1->getEngine(i).commandStreamReceiver); + EXPECT_EQ(executionEnvironment->commandStreamReceivers[1][i].get(), device2->getEngine(i).commandStreamReceiver); } } TEST(DeviceCreation, givenDeviceWhenAskingForDefaultEngineThenReturnValidValue) { - ExecutionEnvironment executionEnvironment; - executionEnvironment.incRefInternal(); - auto device = std::unique_ptr(Device::create(platformDevices[0], &executionEnvironment, 0)); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + auto device = std::unique_ptr(Device::create(platformDevices[0], executionEnvironment, 0)); auto &defaultEngine = device->getDefaultEngine().osContext->getEngineType(); diff --git a/unit_tests/event/event_tests.cpp b/unit_tests/event/event_tests.cpp index 44866ee408..d4525f92c3 100644 --- a/unit_tests/event/event_tests.cpp +++ b/unit_tests/event/event_tests.cpp @@ -391,7 +391,7 @@ TEST_F(EventTest, Event_Wait_NonBlocking) { struct UpdateEventTest : public ::testing::Test { void SetUp() override { - executionEnvironment = new ExecutionEnvironment; + executionEnvironment = platformImpl->peekExecutionEnvironment(); memoryManager = new MockMemoryManager(*executionEnvironment); hostPtrManager = static_cast(memoryManager->getHostPtrManager()); executionEnvironment->memoryManager.reset(memoryManager); diff --git a/unit_tests/execution_environment/execution_environment_tests.cpp b/unit_tests/execution_environment/execution_environment_tests.cpp index 619d0dc954..13db659b14 100644 --- a/unit_tests/execution_environment/execution_environment_tests.cpp +++ b/unit_tests/execution_environment/execution_environment_tests.cpp @@ -102,39 +102,37 @@ TEST(ExecutionEnvironment, givenPlatformWhenItIsCreatedThenItCreatesMemoryManage } TEST(ExecutionEnvironment, givenDeviceWhenItIsDestroyedThenMemoryManagerIsStillAvailable) { - std::unique_ptr executionEnvironment(new ExecutionEnvironment); - executionEnvironment->incRefInternal(); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); executionEnvironment->initializeMemoryManager(false, false); - std::unique_ptr device(Device::create(nullptr, executionEnvironment.get(), 0u)); + std::unique_ptr device(Device::create(nullptr, executionEnvironment, 0u)); device.reset(nullptr); EXPECT_NE(nullptr, executionEnvironment->memoryManager); } TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeCommandStreamReceiverIsCalledThenItIsInitalized) { - std::unique_ptr executionEnvironment(new ExecutionEnvironment); - executionEnvironment->initializeCommandStreamReceiver(platformDevices[0], 0, 0); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + executionEnvironment->initializeCommandStreamReceiver(0, 0); EXPECT_NE(nullptr, executionEnvironment->commandStreamReceivers[0][0]); } TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeIsCalledWithDifferentDeviceIndexesThenInternalStorageIsResized) { - std::unique_ptr executionEnvironment(new ExecutionEnvironment); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); EXPECT_EQ(0u, executionEnvironment->commandStreamReceivers.size()); - executionEnvironment->initializeCommandStreamReceiver(platformDevices[0], 0, 0); + executionEnvironment->initializeCommandStreamReceiver(0, 0); EXPECT_EQ(1u, executionEnvironment->commandStreamReceivers.size()); EXPECT_NE(nullptr, executionEnvironment->commandStreamReceivers[0][0]); - executionEnvironment->initializeCommandStreamReceiver(platformDevices[0], 1, 0); + executionEnvironment->initializeCommandStreamReceiver(1, 0); EXPECT_EQ(2u, executionEnvironment->commandStreamReceivers.size()); EXPECT_NE(nullptr, executionEnvironment->commandStreamReceivers[1][0]); } TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeIsCalledMultipleTimesForTheSameIndexThenCommandStreamReceiverIsReused) { - auto executionEnvironment = std::make_unique(); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); EXPECT_EQ(0u, executionEnvironment->commandStreamReceivers.size()); - executionEnvironment->initializeCommandStreamReceiver(platformDevices[0], 0, 1); + executionEnvironment->initializeCommandStreamReceiver(0, 1); auto currentCommandStreamReceiver = executionEnvironment->commandStreamReceivers[0][1].get(); - - executionEnvironment->initializeCommandStreamReceiver(platformDevices[0], 0, 1); + executionEnvironment->initializeCommandStreamReceiver(0, 1); EXPECT_EQ(currentCommandStreamReceiver, executionEnvironment->commandStreamReceivers[0][1].get()); EXPECT_EQ(2u, executionEnvironment->commandStreamReceivers[0].size()); @@ -143,7 +141,8 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeIsCalledMultip TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeAubCenterIsCalledThenItIsReceivesCorrectInputParams) { MockExecutionEnvironment executionEnvironment; - executionEnvironment.initAubCenter(platformDevices[0], true, "test.aub", CommandStreamReceiverType::CSR_AUB); + executionEnvironment.setHwInfo(*platformDevices); + executionEnvironment.initAubCenter(true, "test.aub", CommandStreamReceiverType::CSR_AUB); EXPECT_TRUE(executionEnvironment.initAubCenterCalled); EXPECT_TRUE(executionEnvironment.localMemoryEnabledReceived); EXPECT_STREQ(executionEnvironment.aubFileNameReceived.c_str(), "test.aub"); @@ -153,46 +152,47 @@ TEST(ExecutionEnvironment, givenUseAubStreamFalseWhenGetAubManagerIsCalledThenRe DebugManagerStateRestore dbgRestore; DebugManager.flags.UseAubStream.set(false); - ExecutionEnvironment executionEnvironment; - executionEnvironment.initAubCenter(platformDevices[0], false, "", CommandStreamReceiverType::CSR_AUB); - auto aubManager = executionEnvironment.aubCenter->getAubManager(); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + executionEnvironment->initAubCenter(false, "", CommandStreamReceiverType::CSR_AUB); + auto aubManager = executionEnvironment->aubCenter->getAubManager(); EXPECT_EQ(nullptr, aubManager); } TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeAubCenterIsCalledThenItIsInitalizedOnce) { - ExecutionEnvironment executionEnvironment; - executionEnvironment.initAubCenter(platformDevices[0], false, "", CommandStreamReceiverType::CSR_AUB); - auto currentAubCenter = executionEnvironment.aubCenter.get(); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + executionEnvironment->initAubCenter(false, "", CommandStreamReceiverType::CSR_AUB); + auto currentAubCenter = executionEnvironment->aubCenter.get(); EXPECT_NE(nullptr, currentAubCenter); auto currentAubStreamProvider = currentAubCenter->getStreamProvider(); EXPECT_NE(nullptr, currentAubStreamProvider); auto currentAubFileStream = currentAubStreamProvider->getStream(); EXPECT_NE(nullptr, currentAubFileStream); - executionEnvironment.initAubCenter(platformDevices[0], false, "", CommandStreamReceiverType::CSR_AUB); - EXPECT_EQ(currentAubCenter, executionEnvironment.aubCenter.get()); - EXPECT_EQ(currentAubStreamProvider, executionEnvironment.aubCenter->getStreamProvider()); - EXPECT_EQ(currentAubFileStream, executionEnvironment.aubCenter->getStreamProvider()->getStream()); + executionEnvironment->initAubCenter(false, "", CommandStreamReceiverType::CSR_AUB); + EXPECT_EQ(currentAubCenter, executionEnvironment->aubCenter.get()); + EXPECT_EQ(currentAubStreamProvider, executionEnvironment->aubCenter->getStreamProvider()); + EXPECT_EQ(currentAubFileStream, executionEnvironment->aubCenter->getStreamProvider()->getStream()); } TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerIsCalledThenLocalMemorySupportedInMemoryManagerHasCorrectValue) { const HardwareInfo *hwInfo = platformDevices[0]; auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(hwInfo)); auto executionEnvironment = device->getExecutionEnvironment(); - executionEnvironment->initializeCommandStreamReceiver(hwInfo, 0, 0); + executionEnvironment->initializeCommandStreamReceiver(0, 0); auto enableLocalMemory = HwHelper::get(hwInfo->pPlatform->eRenderCoreFamily).getEnableLocalMemory(*hwInfo); executionEnvironment->initializeMemoryManager(false, enableLocalMemory); EXPECT_EQ(enableLocalMemory, executionEnvironment->memoryManager->isLocalMemorySupported()); } TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerIsCalledThenItIsInitalized) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->initializeCommandStreamReceiver(platformDevices[0], 0, 0); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + executionEnvironment->initializeCommandStreamReceiver(0, 0); executionEnvironment->initializeMemoryManager(false, false); EXPECT_NE(nullptr, executionEnvironment->memoryManager); } static_assert(sizeof(ExecutionEnvironment) == sizeof(std::vector>) + sizeof(std::unique_ptr) + sizeof(std::mutex) + + sizeof(HardwareInfo *) + (is64bit ? 80 : 44), "New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct"); @@ -247,7 +247,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe } TEST(ExecutionEnvironment, givenMultipleDevicesWhenTheyAreCreatedTheyAllReuseTheSameMemoryManagerAndCommandStreamReceiver) { - auto executionEnvironment = new ExecutionEnvironment; + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); std::unique_ptr device(Device::create(nullptr, executionEnvironment, 0u)); auto &commandStreamReceiver = device->getCommandStreamReceiver(); auto memoryManager = device->getMemoryManager(); @@ -265,26 +265,27 @@ HWTEST_F(ExecutionEnvironmentHw, givenHwHelperInputWhenInitializingCsrThenCreate localHwInfo.capabilityTable.ftrRenderCompressedImages = false; ExecutionEnvironment executionEnvironment; - executionEnvironment.initializeCommandStreamReceiver(&localHwInfo, 0, 0); + executionEnvironment.setHwInfo(&localHwInfo); + executionEnvironment.initializeCommandStreamReceiver(0, 0); auto csr0 = static_cast *>(executionEnvironment.commandStreamReceivers[0][0].get()); EXPECT_FALSE(csr0->createPageTableManagerCalled); localHwInfo.capabilityTable.ftrRenderCompressedBuffers = true; localHwInfo.capabilityTable.ftrRenderCompressedImages = false; - executionEnvironment.initializeCommandStreamReceiver(&localHwInfo, 1, 0); + executionEnvironment.initializeCommandStreamReceiver(1, 0); auto csr1 = static_cast *>(executionEnvironment.commandStreamReceivers[1][0].get()); EXPECT_EQ(UnitTestHelper::isPageTableManagerSupported(localHwInfo), csr1->createPageTableManagerCalled); localHwInfo.capabilityTable.ftrRenderCompressedBuffers = false; localHwInfo.capabilityTable.ftrRenderCompressedImages = true; - executionEnvironment.initializeCommandStreamReceiver(&localHwInfo, 2, 0); + executionEnvironment.initializeCommandStreamReceiver(2, 0); auto csr2 = static_cast *>(executionEnvironment.commandStreamReceivers[2][0].get()); EXPECT_EQ(UnitTestHelper::isPageTableManagerSupported(localHwInfo), csr2->createPageTableManagerCalled); } TEST(ExecutionEnvironment, whenSpecialCsrNotExistThenReturnNullSpecialEngineControl) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->initializeCommandStreamReceiver(platformDevices[0], 0, 0); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + executionEnvironment->initializeCommandStreamReceiver(0, 0); executionEnvironment->initializeMemoryManager(false, false); EXPECT_NE(nullptr, executionEnvironment->memoryManager); auto engineControl = executionEnvironment->getEngineControlForSpecialCsr(); @@ -292,8 +293,8 @@ TEST(ExecutionEnvironment, whenSpecialCsrNotExistThenReturnNullSpecialEngineCont } TEST(ExecutionEnvironment, whenSpecialCsrExistsThenReturnSpecialEngineControl) { - auto executionEnvironment = std::make_unique(); - executionEnvironment->initializeCommandStreamReceiver(platformDevices[0], 0, 0); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + executionEnvironment->initializeCommandStreamReceiver(0, 0); executionEnvironment->initializeMemoryManager(false, false); EXPECT_NE(nullptr, executionEnvironment->memoryManager); diff --git a/unit_tests/fixtures/CMakeLists.txt b/unit_tests/fixtures/CMakeLists.txt index 46e5ac3f49..ce94df60e5 100644 --- a/unit_tests/fixtures/CMakeLists.txt +++ b/unit_tests/fixtures/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2018 Intel Corporation +# Copyright (C) 2018-2019 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -15,7 +15,6 @@ set(IGDRCL_SRCS_tests_fixtures ${CMAKE_CURRENT_SOURCE_DIR}/enqueue_handler_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/execution_model_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/execution_model_kernel_fixture.h - ${CMAKE_CURRENT_SOURCE_DIR}/gmm_environment_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/hello_world_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/hello_world_kernel_fixture.h ${CMAKE_CURRENT_SOURCE_DIR}/image_fixture.cpp diff --git a/unit_tests/fixtures/device_fixture.h b/unit_tests/fixtures/device_fixture.h index 71e249b30b..4729528b90 100644 --- a/unit_tests/fixtures/device_fixture.h +++ b/unit_tests/fixtures/device_fixture.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2018 Intel Corporation + * Copyright (C) 2017-2019 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -22,6 +22,5 @@ struct DeviceFixture { volatile uint32_t *pTagMemory = nullptr; HardwareInfo hwInfoHelper = {}; PLATFORM platformHelper = {}; - ExecutionEnvironment executionEnvironment; }; } // namespace OCLRT diff --git a/unit_tests/fixtures/gmm_environment_fixture.h b/unit_tests/fixtures/gmm_environment_fixture.h deleted file mode 100644 index bf63fe239b..0000000000 --- a/unit_tests/fixtures/gmm_environment_fixture.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2018 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once - -#include "runtime/execution_environment/execution_environment.h" -#include "runtime/helpers/options.h" - -namespace OCLRT { - -struct GmmEnvironmentFixture { - virtual void SetUp() { - executionEnvironment.initGmm(*platformDevices); - } - virtual void TearDown(){}; - ExecutionEnvironment executionEnvironment; -}; -} // namespace OCLRT diff --git a/unit_tests/fixtures/image_fixture.h b/unit_tests/fixtures/image_fixture.h index 00eb1c0262..d43a6c0654 100644 --- a/unit_tests/fixtures/image_fixture.h +++ b/unit_tests/fixtures/image_fixture.h @@ -120,7 +120,8 @@ class ImageClearColorFixture { hwInfoHelper.hwInfo.capabilityTable.ftrRenderCompressedImages = true; OCLRT::platformImpl.reset(); - OCLRT::constructPlatform()->peekExecutionEnvironment()->initGmm(&hwInfoHelper.hwInfo); + OCLRT::constructPlatform()->peekExecutionEnvironment()->setHwInfo(&hwInfoHelper.hwInfo); + OCLRT::platform()->peekExecutionEnvironment()->initGmm(); surfaceState = FamilyType::cmdInitRenderSurfaceState; surfaceState.setAuxiliarySurfaceMode(AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_CCS_E); diff --git a/unit_tests/fixtures/memory_allocator_fixture.h b/unit_tests/fixtures/memory_allocator_fixture.h index 5cb5467699..3919854fae 100644 --- a/unit_tests/fixtures/memory_allocator_fixture.h +++ b/unit_tests/fixtures/memory_allocator_fixture.h @@ -22,7 +22,8 @@ class MemoryAllocatorFixture : public MemoryManagementFixture { void SetUp() override { MemoryManagementFixture::SetUp(); executionEnvironment = std::make_unique(); - executionEnvironment->initializeCommandStreamReceiver(*platformDevices, 0, 0); + executionEnvironment->setHwInfo(*platformDevices); + executionEnvironment->initializeCommandStreamReceiver(0, 0); memoryManager = new MockMemoryManager(false, false, *executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); csr = memoryManager->getDefaultCommandStreamReceiver(0); diff --git a/unit_tests/gen9/windows/os_interface_tests_gen9.cpp b/unit_tests/gen9/windows/os_interface_tests_gen9.cpp index b203ed57d7..bc99ca0ca5 100644 --- a/unit_tests/gen9/windows/os_interface_tests_gen9.cpp +++ b/unit_tests/gen9/windows/os_interface_tests_gen9.cpp @@ -6,6 +6,7 @@ */ #include "runtime/execution_environment/execution_environment.h" +#include "runtime/platform/platform.h" #include "test.h" #include "unit_tests/os_interface/windows/os_interface_win_tests.h" @@ -15,8 +16,8 @@ GEN9TEST_F(OsInterfaceTestSkl, askKmdIfPreemptionRegisterWhitelisted) { HardwareInfo *hwInfo = nullptr; size_t numDevices = 0; - ExecutionEnvironment executionEnvironment; - bool success = DeviceFactory::getDevices(&hwInfo, numDevices, executionEnvironment); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + bool success = DeviceFactory::getDevices(&hwInfo, numDevices, *executionEnvironment); EXPECT_TRUE(success); for (size_t i = 0u; i < numDevices; i++) { diff --git a/unit_tests/gmm_helper/gmm_helper_tests.cpp b/unit_tests/gmm_helper/gmm_helper_tests.cpp index 4075f5d873..27020e5662 100644 --- a/unit_tests/gmm_helper/gmm_helper_tests.cpp +++ b/unit_tests/gmm_helper/gmm_helper_tests.cpp @@ -30,9 +30,9 @@ using namespace ::testing; namespace OCLRT { struct GmmTests : public ::testing::Test { void SetUp() override { - executionEnvironment.initGmm(*platformDevices); + executionEnvironment = platformImpl->peekExecutionEnvironment(); } - ExecutionEnvironment executionEnvironment; + ExecutionEnvironment *executionEnvironment; }; TEST(GmmGlTests, givenGmmWhenAskedforCubeFaceIndexThenProperValueIsReturned) { @@ -53,7 +53,7 @@ TEST(GmmGlTests, givenGmmWhenAskedforCubeFaceIndexThenProperValueIsReturned) { } TEST_F(GmmTests, resourceCreation) { - std::unique_ptr mm(new OsAgnosticMemoryManager(false, false, executionEnvironment)); + std::unique_ptr mm(new OsAgnosticMemoryManager(false, false, *executionEnvironment)); void *pSysMem = mm->allocateSystemMemory(4096, 4096); std::unique_ptr gmm(new Gmm(pSysMem, 4096, false)); @@ -67,7 +67,7 @@ TEST_F(GmmTests, resourceCreation) { } TEST_F(GmmTests, resourceCreationUncacheable) { - std::unique_ptr mm(new OsAgnosticMemoryManager(false, false, executionEnvironment)); + std::unique_ptr mm(new OsAgnosticMemoryManager(false, false, *executionEnvironment)); void *pSysMem = mm->allocateSystemMemory(4096, 4096); std::unique_ptr gmm(new Gmm(pSysMem, 4096, true)); @@ -83,7 +83,7 @@ TEST_F(GmmTests, resourceCreationUncacheable) { } TEST_F(GmmTests, resourceCleanupOnDelete) { - std::unique_ptr mm(new OsAgnosticMemoryManager(false, false, executionEnvironment)); + std::unique_ptr mm(new OsAgnosticMemoryManager(false, false, *executionEnvironment)); void *pSysMem = mm->allocateSystemMemory(4096, 4096); std::unique_ptr gmm(new Gmm(pSysMem, 4096, false)); @@ -96,7 +96,7 @@ TEST_F(GmmTests, resourceCleanupOnDelete) { TEST_F(GmmTests, GivenBufferSizeLargerThenMaxPitchWhenAskedForGmmCreationThenGMMResourceIsCreatedWithNoRestrictionsFlag) { auto maxSize = static_cast(GmmHelper::maxPossiblePitch); - MemoryManager *mm = new OsAgnosticMemoryManager(false, false, executionEnvironment); + MemoryManager *mm = new OsAgnosticMemoryManager(false, false, *executionEnvironment); void *pSysMem = mm->allocateSystemMemory(4096, 4096); auto gmmRes = new Gmm(pSysMem, maxSize, false); diff --git a/unit_tests/helpers/execution_environment_helper.cpp b/unit_tests/helpers/execution_environment_helper.cpp index 77568be4a3..8fde8f53a0 100644 --- a/unit_tests/helpers/execution_environment_helper.cpp +++ b/unit_tests/helpers/execution_environment_helper.cpp @@ -10,11 +10,12 @@ #include "runtime/device/device.h" #include "runtime/helpers/hw_helper.h" #include "runtime/os_interface/device_factory.h" +#include "runtime/platform/platform.h" namespace OCLRT { ExecutionEnvironment *getExecutionEnvironmentImpl(HardwareInfo *&hwInfo) { - ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment; + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); size_t numDevicesReturned = 0; hwInfo = nullptr; DeviceFactory::getDevices(&hwInfo, numDevicesReturned, *executionEnvironment); diff --git a/unit_tests/helpers/timestamp_packet_tests.cpp b/unit_tests/helpers/timestamp_packet_tests.cpp index fac531e08e..dedfa08498 100644 --- a/unit_tests/helpers/timestamp_packet_tests.cpp +++ b/unit_tests/helpers/timestamp_packet_tests.cpp @@ -10,6 +10,7 @@ #include "runtime/event/user_event.h" #include "runtime/helpers/options.h" #include "runtime/helpers/timestamp_packet.h" +#include "runtime/platform/platform.h" #include "runtime/utilities/tag_allocator.h" #include "test.h" #include "unit_tests/helpers/debug_manager_state_restore.h" @@ -86,8 +87,8 @@ struct TimestampPacketSimpleTests : public ::testing::Test { struct TimestampPacketTests : public TimestampPacketSimpleTests { void SetUp() override { - executionEnvironment.incRefInternal(); - device = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 0u)); + executionEnvironment = platformImpl->peekExecutionEnvironment(); + device = std::unique_ptr(Device::create(nullptr, executionEnvironment, 0u)); context = new MockContext(device.get()); kernel = std::make_unique(*device, context); mockCmdQ = new MockCommandQueue(context, device.get(), nullptr); @@ -129,7 +130,7 @@ struct TimestampPacketTests : public TimestampPacketSimpleTests { } } - ExecutionEnvironment executionEnvironment; + ExecutionEnvironment *executionEnvironment; std::unique_ptr device; MockContext *context; std::unique_ptr kernel; @@ -252,7 +253,7 @@ TEST_F(TimestampPacketSimpleTests, whenAskedForStampAddressThenReturnWithValidOf } HWTEST_F(TimestampPacketTests, givenCommandStreamReceiverHwWhenObtainingPreferredTagPoolSizeThenReturnCorrectValue) { - CommandStreamReceiverHw csr(*platformDevices[0], executionEnvironment); + CommandStreamReceiverHw csr(*platformDevices[0], *executionEnvironment); EXPECT_EQ(512u, csr.getPreferredTagPoolSize()); } @@ -488,7 +489,7 @@ HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEnqueueingThe auto &csr = device->getUltCommandStreamReceiver(); csr.timestampPacketWriteEnabled = true; - auto mockTagAllocator = new MockTagAllocator<>(executionEnvironment.memoryManager.get()); + auto mockTagAllocator = new MockTagAllocator<>(executionEnvironment->memoryManager.get()); csr.timestampPacketAllocator.reset(mockTagAllocator); auto cmdQ = std::make_unique>(context, device.get(), nullptr); @@ -557,7 +558,7 @@ HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEnqueueingThe } HWTEST_F(TimestampPacketTests, givenEventsRequestWhenEstimatingStreamSizeForCsrThenAddSizeForSemaphores) { - auto device2 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 1u)); + auto device2 = std::unique_ptr(Device::create(nullptr, executionEnvironment, 1u)); MockContext context2(device2.get()); auto cmdQ2 = std::make_unique>(&context2, device2.get(), nullptr); @@ -644,7 +645,7 @@ HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEnqueueingThe using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT; using MI_ATOMIC = typename FamilyType::MI_ATOMIC; - auto device2 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 1u)); + auto device2 = std::unique_ptr(Device::create(nullptr, executionEnvironment, 1u)); device->getUltCommandStreamReceiver().timestampPacketWriteEnabled = true; device2->getUltCommandStreamReceiver().timestampPacketWriteEnabled = true; @@ -755,7 +756,7 @@ HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledOnDifferentCSRsFr HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEnqueueingBlockedThenProgramSemaphoresOnCsrStreamOnFlush) { using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT; - auto device2 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 1u)); + auto device2 = std::unique_ptr(Device::create(nullptr, executionEnvironment, 1u)); device->getUltCommandStreamReceiver().timestampPacketWriteEnabled = true; device2->getUltCommandStreamReceiver().timestampPacketWriteEnabled = true; @@ -800,7 +801,7 @@ HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEnqueueingBlo HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledOnDifferentCSRsFromOneDeviceWhenEnqueueingBlockedThenProgramSemaphoresOnCsrStreamOnFlush) { using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT; - auto device2 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 1u)); + auto device2 = std::unique_ptr(Device::create(nullptr, executionEnvironment, 1u)); device->getUltCommandStreamReceiver().timestampPacketWriteEnabled = true; @@ -847,7 +848,7 @@ HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenDispatchingTh using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT; using WALKER = WALKER_TYPE; - auto device2 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 1u)); + auto device2 = std::unique_ptr(Device::create(nullptr, executionEnvironment, 1u)); device->getUltCommandStreamReceiver().timestampPacketWriteEnabled = true; device2->getUltCommandStreamReceiver().timestampPacketWriteEnabled = true; MockContext context2(device2.get()); @@ -1011,7 +1012,7 @@ HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledOnDifferentCSRsFr } HWTEST_F(TimestampPacketTests, givenAlreadyAssignedNodeWhenEnqueueingNonBlockedThenMakeItResident) { - auto mockTagAllocator = new MockTagAllocator<>(executionEnvironment.memoryManager.get(), 1); + auto mockTagAllocator = new MockTagAllocator<>(executionEnvironment->memoryManager.get(), 1); auto &csr = device->getUltCommandStreamReceiver(); csr.timestampPacketAllocator.reset(mockTagAllocator); @@ -1033,7 +1034,7 @@ HWTEST_F(TimestampPacketTests, givenAlreadyAssignedNodeWhenEnqueueingNonBlockedT } HWTEST_F(TimestampPacketTests, givenAlreadyAssignedNodeWhenEnqueueingBlockedThenMakeItResident) { - auto mockTagAllocator = new MockTagAllocator<>(executionEnvironment.memoryManager.get(), 1); + auto mockTagAllocator = new MockTagAllocator<>(executionEnvironment->memoryManager.get(), 1); auto &csr = device->getUltCommandStreamReceiver(); csr.timestampPacketAllocator.reset(mockTagAllocator); @@ -1150,8 +1151,8 @@ HWTEST_F(TimestampPacketTests, givenAlreadyAssignedNodeWhenEnqueueingToOoqThenDo } HWTEST_F(TimestampPacketTests, givenEventsWaitlistFromDifferentDevicesWhenEnqueueingThenMakeAllTimestampsResident) { - TagAllocator tagAllocator(executionEnvironment.memoryManager.get(), 1, 1); - auto device2 = std::unique_ptr(Device::create(nullptr, &executionEnvironment, 1u)); + TagAllocator tagAllocator(executionEnvironment->memoryManager.get(), 1, 1); + auto device2 = std::unique_ptr(Device::create(nullptr, executionEnvironment, 1u)); auto &ultCsr = device->getUltCommandStreamReceiver(); ultCsr.timestampPacketWriteEnabled = true; @@ -1185,7 +1186,7 @@ HWTEST_F(TimestampPacketTests, givenEventsWaitlistFromDifferentDevicesWhenEnqueu } HWTEST_F(TimestampPacketTests, givenEventsWaitlistFromDifferentCSRsWhenEnqueueingThenMakeAllTimestampsResident) { - TagAllocator tagAllocator(executionEnvironment.memoryManager.get(), 1, 1); + TagAllocator tagAllocator(executionEnvironment->memoryManager.get(), 1, 1); auto &ultCsr = device->getUltCommandStreamReceiver(); ultCsr.timestampPacketWriteEnabled = true; @@ -1436,7 +1437,7 @@ HWTEST_F(TimestampPacketTests, givenKernelWhichDoesntRequiersFlushWhenEnquingKer auto &csr = device->getUltCommandStreamReceiver(); csr.timestampPacketWriteEnabled = true; - auto mockTagAllocator = new MockTagAllocator<>(executionEnvironment.memoryManager.get()); + auto mockTagAllocator = new MockTagAllocator<>(executionEnvironment->memoryManager.get()); csr.timestampPacketAllocator.reset(mockTagAllocator); auto cmdQ = std::make_unique>(context, device.get(), nullptr); // obtain first node for cmdQ and event1 @@ -1453,7 +1454,7 @@ HWTEST_F(TimestampPacketTests, givenKernelWhichRequiersFlushWhenEnquingKernelThe auto &csr = device->getUltCommandStreamReceiver(); csr.timestampPacketWriteEnabled = true; - auto mockTagAllocator = new MockTagAllocator<>(executionEnvironment.memoryManager.get()); + auto mockTagAllocator = new MockTagAllocator<>(executionEnvironment->memoryManager.get()); csr.timestampPacketAllocator.reset(mockTagAllocator); auto cmdQ = std::make_unique>(context, device.get(), nullptr); kernel->mockKernel->svmAllocationsRequireCacheFlush = true; diff --git a/unit_tests/libult/create_command_stream.cpp b/unit_tests/libult/create_command_stream.cpp index 7863bfbb4c..25ac9c3f1a 100644 --- a/unit_tests/libult/create_command_stream.cpp +++ b/unit_tests/libult/create_command_stream.cpp @@ -40,6 +40,7 @@ CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo, Executio bool getDevices(HardwareInfo **hwInfo, size_t &numDevicesReturned, ExecutionEnvironment &executionEnvironment) { if (overrideDeviceWithDefaultHardwareInfo) { *hwInfo = const_cast(*platformDevices); + executionEnvironment.setHwInfo(*hwInfo); numDevicesReturned = numPlatformDevices; return getDevicesResult; } diff --git a/unit_tests/mem_obj/buffer_tests.cpp b/unit_tests/mem_obj/buffer_tests.cpp index a2a974163b..ad1b326729 100644 --- a/unit_tests/mem_obj/buffer_tests.cpp +++ b/unit_tests/mem_obj/buffer_tests.cpp @@ -15,6 +15,7 @@ #include "runtime/mem_obj/buffer.h" #include "runtime/memory_manager/svm_memory_manager.h" #include "runtime/os_interface/os_context.h" +#include "runtime/platform/platform.h" #include "test.h" #include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/fixtures/memory_management_fixture.h" @@ -399,15 +400,14 @@ TEST(Buffer, givenZeroFlagsNoSharedContextAndRenderCompressedBuffersDisabledWhen } TEST(Buffer, givenClMemCopyHostPointerPassedToBufferCreateWhenAllocationIsNotInSystemMemoryPoolThenAllocationIsWrittenByEnqueueWriteBuffer) { - ExecutionEnvironment executionEnvironment; - executionEnvironment.incRefInternal(); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); - auto *memoryManager = new ::testing::NiceMock(executionEnvironment); - executionEnvironment.memoryManager.reset(memoryManager); + auto *memoryManager = new ::testing::NiceMock(*executionEnvironment); + executionEnvironment->memoryManager.reset(memoryManager); EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_)) .WillRepeatedly(::testing::Invoke(memoryManager, &GMockMemoryManagerFailFirstAllocation::baseAllocateGraphicsMemoryInDevicePool)); - std::unique_ptr device(MockDevice::create(*platformDevices, &executionEnvironment, 0)); + std::unique_ptr device(MockDevice::create(*platformDevices, executionEnvironment, 0)); MockContext ctx(device.get()); EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_)) @@ -427,7 +427,8 @@ TEST(Buffer, givenClMemCopyHostPointerPassedToBufferCreateWhenAllocationIsNotInS struct RenderCompressedBuffersTests : public ::testing::Test { void SetUp() override { localHwInfo = *platformDevices[0]; - device.reset(Device::create(&localHwInfo, new ExecutionEnvironment(), 0u)); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + device.reset(Device::create(&localHwInfo, executionEnvironment, 0u)); context = std::make_unique(device.get(), true); context->setContextType(ContextType::CONTEXT_TYPE_UNRESTRICTIVE); } diff --git a/unit_tests/mem_obj/image_tests.cpp b/unit_tests/mem_obj/image_tests.cpp index df569fda28..9b1c6594ad 100644 --- a/unit_tests/mem_obj/image_tests.cpp +++ b/unit_tests/mem_obj/image_tests.cpp @@ -634,7 +634,7 @@ TEST_P(CreateImageHostPtr, failedAllocationInjection) { } TEST_P(CreateImageHostPtr, checkWritingOutsideAllocatedMemoryWhileCreatingImage) { - auto mockMemoryManager = new MockMemoryManager(executionEnvironment); + auto mockMemoryManager = new MockMemoryManager(*pDevice->executionEnvironment); pDevice->injectMemoryManager(mockMemoryManager); context->setMemoryManager(mockMemoryManager); mockMemoryManager->redundancyRatio = 2; @@ -1294,15 +1294,13 @@ TEST(ImageTest, givenForcedLinearImages3DImageAndProperDescriptorValuesWhenIsCop } TEST(ImageTest, givenClMemCopyHostPointerPassedToImageCreateWhenAllocationIsNotInSystemMemoryPoolThenAllocationIsWrittenByEnqueueWriteImage) { - ExecutionEnvironment executionEnvironment; - executionEnvironment.incRefInternal(); - - auto *memoryManager = new ::testing::NiceMock(executionEnvironment); - executionEnvironment.memoryManager.reset(memoryManager); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + auto *memoryManager = new ::testing::NiceMock(*executionEnvironment); + executionEnvironment->memoryManager.reset(memoryManager); EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_)) .WillRepeatedly(::testing::Invoke(memoryManager, &GMockMemoryManagerFailFirstAllocation::baseAllocateGraphicsMemoryInDevicePool)); - std::unique_ptr device(MockDevice::create(*platformDevices, &executionEnvironment, 0)); + std::unique_ptr device(MockDevice::create(*platformDevices, executionEnvironment, 0)); MockContext ctx(device.get()); EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_)) diff --git a/unit_tests/mem_obj/mem_obj_destruction_tests.cpp b/unit_tests/mem_obj/mem_obj_destruction_tests.cpp index e09ecfbcd2..7f791ee9cc 100644 --- a/unit_tests/mem_obj/mem_obj_destruction_tests.cpp +++ b/unit_tests/mem_obj/mem_obj_destruction_tests.cpp @@ -8,6 +8,7 @@ #include "runtime/mem_obj/mem_obj.h" #include "runtime/memory_manager/allocations_list.h" #include "runtime/os_interface/os_context.h" +#include "runtime/platform/platform.h" #include "test.h" #include "unit_tests/libult/ult_command_stream_receiver.h" #include "unit_tests/mocks/mock_context.h" @@ -29,11 +30,10 @@ void CL_CALLBACK emptyDestructorCallback(cl_mem memObj, void *userData) { class MemObjDestructionTest : public ::testing::TestWithParam { public: void SetUp() override { - executionEnvironment = std::make_unique(); - executionEnvironment->incRefInternal(); + executionEnvironment = platformImpl->peekExecutionEnvironment(); memoryManager = new MockMemoryManager(*executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); - device.reset(MockDevice::create(*platformDevices, executionEnvironment.get(), 0)); + device.reset(MockDevice::create(*platformDevices, executionEnvironment, 0)); context.reset(new MockContext(device.get())); allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{size}); @@ -64,7 +64,7 @@ class MemObjDestructionTest : public ::testing::TestWithParam { } constexpr static uint32_t taskCountReady = 3u; - std::unique_ptr executionEnvironment; + ExecutionEnvironment *executionEnvironment; std::unique_ptr device; uint32_t contextId = 0; MockMemoryManager *memoryManager; diff --git a/unit_tests/mem_obj/mem_obj_tests.cpp b/unit_tests/mem_obj/mem_obj_tests.cpp index a837425f4f..893e81ff54 100644 --- a/unit_tests/mem_obj/mem_obj_tests.cpp +++ b/unit_tests/mem_obj/mem_obj_tests.cpp @@ -12,6 +12,7 @@ #include "runtime/mem_obj/mem_obj.h" #include "runtime/memory_manager/allocations_list.h" #include "runtime/os_interface/os_context.h" +#include "runtime/platform/platform.h" #include "unit_tests/mocks/mock_context.h" #include "unit_tests/mocks/mock_deferred_deleter.h" #include "unit_tests/mocks/mock_device.h" @@ -161,11 +162,10 @@ TEST(MemObj, givenNotReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThe } TEST(MemObj, givenReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThenAllocationIsNotAddedToMemoryManagerAllocationList) { - ExecutionEnvironment executionEnvironment; - executionEnvironment.incRefInternal(); - auto device = std::unique_ptr(MockDevice::create(*platformDevices, &executionEnvironment, 0)); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + auto device = std::unique_ptr(MockDevice::create(*platformDevices, executionEnvironment, 0)); MockContext context(device.get()); - auto memoryManager = executionEnvironment.memoryManager.get(); + auto memoryManager = executionEnvironment->memoryManager.get(); auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); allocation->updateTaskCount(1, device->getDefaultEngine().osContext->getContextId()); diff --git a/unit_tests/memory_manager/deferrable_allocation_deletion_tests.cpp b/unit_tests/memory_manager/deferrable_allocation_deletion_tests.cpp index 35da7e4551..573c61e2fa 100644 --- a/unit_tests/memory_manager/deferrable_allocation_deletion_tests.cpp +++ b/unit_tests/memory_manager/deferrable_allocation_deletion_tests.cpp @@ -10,6 +10,7 @@ #include "runtime/memory_manager/deferrable_allocation_deletion.h" #include "runtime/memory_manager/deferred_deleter.h" #include "runtime/os_interface/os_context.h" +#include "runtime/platform/platform.h" #include "test.h" #include "unit_tests/libult/ult_command_stream_receiver.h" #include "unit_tests/mocks/mock_allocation_properties.h" @@ -36,10 +37,10 @@ struct DeferredDeleterPublic : DeferredDeleter { struct DeferrableAllocationDeletionTest : ::testing::Test { void SetUp() override { - auto executionEnvironment = std::make_unique(); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); memoryManager = new MockMemoryManager(*executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); - device.reset(Device::create(nullptr, executionEnvironment.release(), 0u)); + device.reset(Device::create(nullptr, executionEnvironment, 0u)); hwTag = device->getDefaultEngine().commandStreamReceiver->getTagAddress(); defaultOsContextId = device->getDefaultEngine().osContext->getContextId(); asyncDeleter = std::make_unique(); diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 67a1183e4c..3c0f0c1a9b 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -16,6 +16,7 @@ #include "runtime/memory_manager/memory_constants.h" #include "runtime/os_interface/os_context.h" #include "runtime/os_interface/os_interface.h" +#include "runtime/platform/platform.h" #include "runtime/program/printf_handler.h" #include "runtime/program/program.h" #include "test.h" @@ -550,16 +551,14 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenForce32bitallocationI } TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenAllocateGraphicsMemoryForImageIsCalledThenGraphicsAllocationIsReturned) { - ExecutionEnvironment executionEnvironment; - MockMemoryManager memoryManager(false, false, executionEnvironment); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + MockMemoryManager memoryManager(false, false, *executionEnvironment); cl_image_desc imgDesc = {}; imgDesc.image_width = 512; imgDesc.image_height = 1; imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - executionEnvironment.initGmm(*platformDevices); - MockMemoryManager::AllocationData allocationData; allocationData.imgInfo = &imgInfo; @@ -571,16 +570,14 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenAllocateGraphicsMemor } TEST(OsAgnosticMemoryManager, givenEnabledLocalMemoryWhenAllocateGraphicsMemoryForImageIsCalledThenUseLocalMemoryIsNotSet) { - ExecutionEnvironment executionEnvironment; - MockMemoryManager memoryManager(false, true, executionEnvironment); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + MockMemoryManager memoryManager(false, true, *executionEnvironment); cl_image_desc imgDesc = {}; imgDesc.image_width = 1; imgDesc.image_height = 1; imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - executionEnvironment.initGmm(*platformDevices); - MockMemoryManager::AllocationData allocationData; allocationData.imgInfo = &imgInfo; @@ -591,9 +588,8 @@ TEST(OsAgnosticMemoryManager, givenEnabledLocalMemoryWhenAllocateGraphicsMemoryF } TEST(OsAgnosticMemoryManager, givenHostPointerNotRequiringCopyWhenAllocateGraphicsMemoryForImageFromHostPtrIsCalledThenGraphicsAllocationIsReturned) { - ExecutionEnvironment executionEnvironment; - MockMemoryManager memoryManager(false, false, executionEnvironment); - executionEnvironment.initGmm(*platformDevices); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + MockMemoryManager memoryManager(false, false, *executionEnvironment); cl_image_desc imgDesc = {}; imgDesc.image_width = 4; @@ -631,9 +627,8 @@ TEST(OsAgnosticMemoryManager, givenHostPointerNotRequiringCopyWhenAllocateGraphi } TEST(OsAgnosticMemoryManager, givenHostPointerRequiringCopyWhenAllocateGraphicsMemoryForImageFromHostPtrIsCalledThenNullptrIsReturned) { - ExecutionEnvironment executionEnvironment; - MockMemoryManager memoryManager(false, false, executionEnvironment); - executionEnvironment.initGmm(*platformDevices); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + MockMemoryManager memoryManager(false, false, *executionEnvironment); cl_image_desc imgDesc = {}; imgDesc.image_width = 4; @@ -1168,16 +1163,14 @@ TEST(OsAgnosticMemoryManager, givenLocalMemorySupportedAndAubUsageWhenMemoryMana } TEST(MemoryManager, givenSharedResourceCopyWhenAllocatingGraphicsMemoryThenAllocateGraphicsMemoryForImageIsCalled) { - ExecutionEnvironment executionEnvironment; - MockMemoryManager memoryManager(false, true, executionEnvironment); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + MockMemoryManager memoryManager(false, true, *executionEnvironment); cl_image_desc imgDesc = {}; imgDesc.image_width = 1; imgDesc.image_height = 1; imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - executionEnvironment.initGmm(*platformDevices); - MockMemoryManager::AllocationData allocationData; allocationData.imgInfo = &imgInfo; allocationData.type = GraphicsAllocation::AllocationType::SHARED_RESOURCE_COPY; @@ -1479,12 +1472,11 @@ HWTEST_F(GraphicsAllocationTests, givenAllocationUsedOnlyByNonDefaultCsrWhenChec } HWTEST_F(GraphicsAllocationTests, givenAllocationUsedOnlyByNonDefaultDeviceWhenCheckingUsageBeforeDestroyThenStoreItAsTemporaryAllocation) { - ExecutionEnvironment executionEnvironment; - executionEnvironment.incRefInternal(); - auto device = std::unique_ptr(Device::create(platformDevices[0], &executionEnvironment, 0u)); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + auto device = std::unique_ptr(Device::create(platformDevices[0], executionEnvironment, 0u)); auto &defaultCommandStreamReceiver = device->getCommandStreamReceiver(); - auto &nonDefaultCommandStreamReceiver = static_cast &>(*executionEnvironment.commandStreamReceivers[0][1]); - auto memoryManager = executionEnvironment.memoryManager.get(); + auto &nonDefaultCommandStreamReceiver = static_cast &>(*executionEnvironment->commandStreamReceivers[0][1]); + auto memoryManager = executionEnvironment->memoryManager.get(); auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); auto notReadyTaskCount = *nonDefaultCommandStreamReceiver.getTagAddress() + 1; @@ -1502,15 +1494,14 @@ HWTEST_F(GraphicsAllocationTests, givenAllocationUsedOnlyByNonDefaultDeviceWhenC } HWTEST_F(GraphicsAllocationTests, givenAllocationUsedByManyOsContextsWhenCheckingUsageBeforeDestroyThenMultiContextDestructorIsUsedForWaitingForAllOsContexts) { - ExecutionEnvironment executionEnvironment; - executionEnvironment.incRefInternal(); - auto memoryManager = new MockMemoryManager(false, false, executionEnvironment); - executionEnvironment.memoryManager.reset(memoryManager); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + auto memoryManager = new MockMemoryManager(false, false, *executionEnvironment); + executionEnvironment->memoryManager.reset(memoryManager); auto multiContextDestructor = new MockDeferredDeleter(); multiContextDestructor->expectDrainBlockingValue(false); memoryManager->multiContextResourceDestructor.reset(multiContextDestructor); - auto device = std::unique_ptr(MockDevice::create(platformDevices[0], &executionEnvironment, 0u)); + auto device = std::unique_ptr(MockDevice::create(platformDevices[0], executionEnvironment, 0u)); auto nonDefaultOsContext = device->getEngine(EngineInstanceConstants::lowPriorityGpgpuEngineIndex).osContext; auto nonDefaultCsr = reinterpret_cast *>(device->getEngine(EngineInstanceConstants::lowPriorityGpgpuEngineIndex).commandStreamReceiver); auto defaultCsr = reinterpret_cast *>(device->getDefaultEngine().commandStreamReceiver); diff --git a/unit_tests/mocks/mock_device.cpp b/unit_tests/mocks/mock_device.cpp index 4e7fb4bd31..417fcda18d 100644 --- a/unit_tests/mocks/mock_device.cpp +++ b/unit_tests/mocks/mock_device.cpp @@ -9,6 +9,7 @@ #include "runtime/device/driver_info.h" #include "runtime/os_interface/os_context.h" +#include "unit_tests/mocks/mock_execution_environment.h" #include "unit_tests/mocks/mock_memory_manager.h" #include "unit_tests/mocks/mock_ostime.h" #include "unit_tests/tests_configuration.h" @@ -16,7 +17,7 @@ using namespace OCLRT; MockDevice::MockDevice(const HardwareInfo &hwInfo) - : MockDevice(hwInfo, new ExecutionEnvironment, 0u) { + : MockDevice(hwInfo, new MockExecutionEnvironment(&hwInfo), 0u) { CommandStreamReceiver *commandStreamReceiver = createCommandStream(&hwInfo, *this->executionEnvironment); executionEnvironment->commandStreamReceivers.resize(getDeviceIndex() + 1); executionEnvironment->commandStreamReceivers[getDeviceIndex()].resize(defaultEngineIndex + 1); @@ -73,4 +74,4 @@ FailDevice::FailDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executi FailDeviceAfterOne::FailDeviceAfterOne(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) : MockDevice(hwInfo, executionEnvironment, deviceIndex) { this->mockMemoryManager.reset(new FailMemoryManager(1)); -} +} \ No newline at end of file diff --git a/unit_tests/mocks/mock_device.h b/unit_tests/mocks/mock_device.h index 9261b270db..8b10fcd836 100644 --- a/unit_tests/mocks/mock_device.h +++ b/unit_tests/mocks/mock_device.h @@ -83,6 +83,7 @@ class MockDevice : public Device { template static T *createWithExecutionEnvironment(const HardwareInfo *pHwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) { pHwInfo = getDeviceInitHwInfo(pHwInfo); + executionEnvironment->setHwInfo(pHwInfo); T *device = new T(*pHwInfo, executionEnvironment, deviceIndex); executionEnvironment->memoryManager = std::move(device->mockMemoryManager); return createDeviceInternals(pHwInfo, device); @@ -90,7 +91,9 @@ class MockDevice : public Device { template static T *createWithNewExecutionEnvironment(const HardwareInfo *pHwInfo) { - return createWithExecutionEnvironment(pHwInfo, new ExecutionEnvironment(), 0u); + ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment(); + executionEnvironment->setHwInfo(pHwInfo); + return createWithExecutionEnvironment(pHwInfo, executionEnvironment, 0u); } void allocatePreemptionAllocationIfNotPresent() { @@ -122,8 +125,8 @@ inline Device *MockDevice::createWithNewExecutionEnvironment(const Hardw enableLocalMemory = HwHelper::get(pHwInfo->pPlatform->eRenderCoreFamily).getEnableLocalMemory(*pHwInfo); enable64kbPages = getEnabled64kbPages(*pHwInfo); } + executionEnvironment->setHwInfo(*platformDevices); executionEnvironment->initializeMemoryManager(enable64kbPages, enableLocalMemory); - return Device::create(pHwInfo, executionEnvironment, 0u); } @@ -141,5 +144,4 @@ class MockAlignedMallocManagerDevice : public MockDevice { public: MockAlignedMallocManagerDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex); }; - } // namespace OCLRT diff --git a/unit_tests/mocks/mock_execution_environment.h b/unit_tests/mocks/mock_execution_environment.h index f5bc9cf1cf..c076d86ea2 100644 --- a/unit_tests/mocks/mock_execution_environment.h +++ b/unit_tests/mocks/mock_execution_environment.h @@ -13,13 +13,16 @@ namespace OCLRT { struct MockExecutionEnvironment : ExecutionEnvironment { MockExecutionEnvironment() = default; - void initAubCenter(const HardwareInfo *hwInfo, bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType) override { + MockExecutionEnvironment(const HardwareInfo *hwInfo) { + setHwInfo(hwInfo); + } + void initAubCenter(bool localMemoryEnabled, const std::string &aubFileName, CommandStreamReceiverType csrType) override { if (!initAubCenterCalled) { initAubCenterCalled = true; localMemoryEnabledReceived = localMemoryEnabled; aubFileNameReceived = aubFileName; } - ExecutionEnvironment::initAubCenter(hwInfo, localMemoryEnabled, aubFileName, csrType); + ExecutionEnvironment::initAubCenter(localMemoryEnabled, aubFileName, csrType); } bool initAubCenterCalled = false; bool localMemoryEnabledReceived = false; diff --git a/unit_tests/os_interface/device_factory_tests.cpp b/unit_tests/os_interface/device_factory_tests.cpp index aced1ec0f9..2beb8abbfb 100644 --- a/unit_tests/os_interface/device_factory_tests.cpp +++ b/unit_tests/os_interface/device_factory_tests.cpp @@ -11,6 +11,7 @@ #include "runtime/memory_manager/memory_constants.h" #include "runtime/os_interface/device_factory.h" #include "runtime/os_interface/os_library.h" +#include "runtime/platform/platform.h" #include "unit_tests/helpers/debug_manager_state_restore.h" #include "gtest/gtest.h" @@ -23,6 +24,7 @@ struct DeviceFactoryTest : public ::testing::Test { public: void SetUp() override { const HardwareInfo hwInfo = *platformDevices[0]; + executionEnvironment = platformImpl->peekExecutionEnvironment(); mockGdiDll = setAdapterInfo(hwInfo.pPlatform, hwInfo.pSysInfo); } @@ -32,14 +34,14 @@ struct DeviceFactoryTest : public ::testing::Test { protected: OsLibrary *mockGdiDll; - ExecutionEnvironment executionEnvironment; + ExecutionEnvironment *executionEnvironment; }; TEST_F(DeviceFactoryTest, GetDevices_Expect_True_If_Returned) { DeviceFactoryCleaner cleaner; HardwareInfo *hwInfo = nullptr; size_t numDevices = 0; - bool success = DeviceFactory::getDevices(&hwInfo, numDevices, executionEnvironment); + bool success = DeviceFactory::getDevices(&hwInfo, numDevices, *executionEnvironment); EXPECT_TRUE((numDevices > 0) ? success : !success); } @@ -48,7 +50,7 @@ TEST_F(DeviceFactoryTest, GetDevices_Check_HwInfo_Null) { DeviceFactoryCleaner cleaner; HardwareInfo *hwInfo = nullptr; size_t numDevices = 0; - bool success = DeviceFactory::getDevices(&hwInfo, numDevices, executionEnvironment); + bool success = DeviceFactory::getDevices(&hwInfo, numDevices, *executionEnvironment); EXPECT_TRUE((numDevices > 0) ? success : !success); if (numDevices > 0) { @@ -66,7 +68,7 @@ TEST_F(DeviceFactoryTest, GetDevices_Check_HwInfo_Platform) { const HardwareInfo *refHwinfo = *platformDevices; size_t numDevices = 0; - bool success = DeviceFactory::getDevices(&hwInfo, numDevices, executionEnvironment); + bool success = DeviceFactory::getDevices(&hwInfo, numDevices, *executionEnvironment); EXPECT_TRUE((numDevices > 0) ? success : !success); if (numDevices > 0) { @@ -85,7 +87,7 @@ TEST_F(DeviceFactoryTest, overrideKmdNotifySettings) { HardwareInfo *hwInfoOverriden = nullptr; size_t numDevices = 0; - bool success = DeviceFactory::getDevices(&hwInfoReference, numDevices, executionEnvironment); + bool success = DeviceFactory::getDevices(&hwInfoReference, numDevices, *executionEnvironment); ASSERT_TRUE(success); auto refEnableKmdNotify = hwInfoReference->capabilityTable.kmdNotifyProperties.enableKmdNotify; auto refDelayKmdNotifyMicroseconds = hwInfoReference->capabilityTable.kmdNotifyProperties.delayKmdNotifyMicroseconds; @@ -104,7 +106,7 @@ TEST_F(DeviceFactoryTest, overrideKmdNotifySettings) { DebugManager.flags.OverrideEnableQuickKmdSleepForSporadicWaits.set(!refEnableQuickKmdSleepForSporadicWaits); DebugManager.flags.OverrideDelayQuickKmdSleepForSporadicWaitsMicroseconds.set(static_cast(refDelayQuickKmdSleepForSporadicWaitsMicroseconds) + 12); - success = DeviceFactory::getDevices(&hwInfoOverriden, numDevices, executionEnvironment); + success = DeviceFactory::getDevices(&hwInfoOverriden, numDevices, *executionEnvironment); ASSERT_TRUE(success); EXPECT_EQ(!refEnableKmdNotify, hwInfoOverriden->capabilityTable.kmdNotifyProperties.enableKmdNotify); @@ -127,7 +129,7 @@ TEST_F(DeviceFactoryTest, getEngineTypeDebugOverride) { HardwareInfo *hwInfoOverriden = nullptr; size_t numDevices = 0; - bool success = DeviceFactory::getDevices(&hwInfoOverriden, numDevices, executionEnvironment); + bool success = DeviceFactory::getDevices(&hwInfoOverriden, numDevices, *executionEnvironment); ASSERT_TRUE(success); ASSERT_NE(nullptr, hwInfoOverriden); int32_t actualEngineType = static_cast(hwInfoOverriden->capabilityTable.defaultEngineType); @@ -138,7 +140,7 @@ TEST_F(DeviceFactoryTest, givenPointerToHwInfoWhenGetDevicedCalledThenRequiedSur DeviceFactoryCleaner cleaner; HardwareInfo *hwInfo = nullptr; size_t numDevices = 0; - bool success = DeviceFactory::getDevices(&hwInfo, numDevices, executionEnvironment); + bool success = DeviceFactory::getDevices(&hwInfo, numDevices, *executionEnvironment); ASSERT_TRUE(success); EXPECT_EQ(hwInfo->pSysInfo->CsrSizeInMb * MemoryConstants::megaByte, hwInfo->capabilityTable.requiredPreemptionSurfaceSize); @@ -151,7 +153,7 @@ TEST_F(DeviceFactoryTest, givenCreateMultipleDevicesDebugFlagWhenGetDevicesIsCal DebugManager.flags.CreateMultipleDevices.set(requiredDeviceCount); HardwareInfo *hwInfo = nullptr; size_t numDevices = 0; - bool success = DeviceFactory::getDevices(&hwInfo, numDevices, executionEnvironment); + bool success = DeviceFactory::getDevices(&hwInfo, numDevices, *executionEnvironment); ASSERT_NE(nullptr, hwInfo); for (auto deviceIndex = 0u; deviceIndex < requiredDeviceCount; deviceIndex++) { @@ -174,7 +176,7 @@ TEST_F(DeviceFactoryTest, givenCreateMultipleDevicesDebugFlagWhenGetDevicesForPr DebugManager.flags.CreateMultipleDevices.set(requiredDeviceCount); HardwareInfo *hwInfo = nullptr; size_t numDevices = 0; - bool success = DeviceFactory::getDevicesForProductFamilyOverride(&hwInfo, numDevices, executionEnvironment); + bool success = DeviceFactory::getDevicesForProductFamilyOverride(&hwInfo, numDevices, *executionEnvironment); ASSERT_NE(nullptr, hwInfo); for (auto deviceIndex = 0u; deviceIndex < requiredDeviceCount; deviceIndex++) { @@ -194,7 +196,7 @@ TEST_F(DeviceFactoryTest, givenGetDevicesCallWhenItIsDoneThenOsInterfaceIsAlloca DeviceFactoryCleaner cleaner; HardwareInfo *hwInfo = nullptr; size_t numDevices = 0; - bool success = DeviceFactory::getDevices(&hwInfo, numDevices, executionEnvironment); + bool success = DeviceFactory::getDevices(&hwInfo, numDevices, *executionEnvironment); EXPECT_TRUE(success); - EXPECT_NE(nullptr, executionEnvironment.osInterface); + EXPECT_NE(nullptr, executionEnvironment->osInterface); } diff --git a/unit_tests/os_interface/linux/device_command_stream_tests.cpp b/unit_tests/os_interface/linux/device_command_stream_tests.cpp index a2d3bc6178..415826121c 100644 --- a/unit_tests/os_interface/linux/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/device_command_stream_tests.cpp @@ -27,10 +27,10 @@ using namespace OCLRT; struct DeviceCommandStreamLeaksTest : ::testing::Test { void SetUp() override { HardwareInfo *hwInfo = nullptr; - executionEnvironment = std::unique_ptr(getExecutionEnvironmentImpl(hwInfo)); + executionEnvironment = getExecutionEnvironmentImpl(hwInfo); } - std::unique_ptr executionEnvironment; + ExecutionEnvironment *executionEnvironment; }; HWTEST_F(DeviceCommandStreamLeaksTest, Create) { diff --git a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp index 792f25eb4e..3986943d76 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -39,6 +39,7 @@ class DrmCommandStreamFixture { mock = std::make_unique<::testing::NiceMock>(mockFd); + executionEnvironment.setHwInfo(*platformDevices); executionEnvironment.osInterface = std::make_unique(); executionEnvironment.osInterface->get()->setDrm(mock.get()); @@ -565,7 +566,8 @@ class DrmCommandStreamEnhancedFixture virtual void SetUp() { executionEnvironment = new ExecutionEnvironment; executionEnvironment->incRefInternal(); - executionEnvironment->initGmm(*platformDevices); + executionEnvironment->setHwInfo(*platformDevices); + executionEnvironment->initGmm(); this->dbgState = std::make_unique(); //make sure this is disabled, we don't want test this now DebugManager.flags.EnableForcePin.set(false); 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 30b1b6c1e9..851837f6de 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -107,6 +107,7 @@ class DrmMemoryManagerFixtureWithoutQuietIoctlExpectation : public MemoryManagem void SetUp() override { MemoryManagementFixture::SetUp(); executionEnvironment = new ExecutionEnvironment; + executionEnvironment->setHwInfo(*platformDevices); this->mock = new DrmMockCustom; memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, *executionEnvironment); ASSERT_NE(nullptr, memoryManager); @@ -1222,8 +1223,6 @@ TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenAllocateGraphicsMemoryForImag imgInfo.size = 4096u; imgInfo.rowPitch = 512u; - ExecutionEnvironment executionEnvironment; - executionEnvironment.initGmm(*platformDevices); TestedDrmMemoryManager::AllocationData allocationData; allocationData.imgInfo = &imgInfo; @@ -1945,9 +1944,6 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenLockUnlockIsCalledOnAlloca imgInfo.size = 4096u; imgInfo.rowPitch = 512u; - ExecutionEnvironment executionEnvironment; - executionEnvironment.initGmm(*platformDevices); - TestedDrmMemoryManager::AllocationData allocationData; allocationData.imgInfo = &imgInfo; 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 04610c524b..712bce201e 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -24,9 +24,9 @@ #include "runtime/os_interface/windows/wddm_device_command_stream.h" #include "runtime/os_interface/windows/wddm_memory_manager.h" #include "runtime/os_interface/windows/wddm_residency_controller.h" +#include "runtime/platform/platform.h" #include "test.h" #include "unit_tests/fixtures/device_fixture.h" -#include "unit_tests/fixtures/gmm_environment_fixture.h" #include "unit_tests/fixtures/memory_management_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/helpers/execution_environment_helper.h" @@ -117,7 +117,6 @@ class WddmCommandStreamWithMockGdiFixture { virtual void SetUp() { HardwareInfo *hwInfo = nullptr; ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); - executionEnvironment->initGmm(*platformDevices); wddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); gdi = new MockGdi(); wddm->gdi.reset(gdi); @@ -147,23 +146,24 @@ class WddmCommandStreamWithMockGdiFixture { using WddmCommandStreamTest = ::Test; using WddmCommandStreamMockGdiTest = ::Test; using WddmDefaultTest = ::Test; -using DeviceCommandStreamTest = ::Test; -TEST_F(DeviceCommandStreamTest, CreateWddmCSR) { +TEST(DeviceCommandStreamTest, CreateWddmCSR) { auto wddm = Wddm::createWddm(); - this->executionEnvironment.osInterface = std::make_unique(); - this->executionEnvironment.osInterface->get()->setWddm(static_cast(wddm)); - std::unique_ptr> csr(static_cast *>(WddmCommandStreamReceiver::create(DEFAULT_TEST_PLATFORM::hwInfo, false, this->executionEnvironment))); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + executionEnvironment->osInterface = std::make_unique(); + executionEnvironment->osInterface->get()->setWddm(static_cast(wddm)); + std::unique_ptr> csr(static_cast *>(WddmCommandStreamReceiver::create(DEFAULT_TEST_PLATFORM::hwInfo, false, *executionEnvironment))); EXPECT_NE(nullptr, csr); auto wddmFromCsr = csr->peekWddm(); EXPECT_NE(nullptr, wddmFromCsr); } -TEST_F(DeviceCommandStreamTest, CreateWddmCSRWithAubDump) { +TEST(DeviceCommandStreamTest, CreateWddmCSRWithAubDump) { auto wddm = Wddm::createWddm(); - this->executionEnvironment.osInterface = std::make_unique(); - this->executionEnvironment.osInterface->get()->setWddm(static_cast(wddm)); - std::unique_ptr> csr(static_cast *>(WddmCommandStreamReceiver::create(DEFAULT_TEST_PLATFORM::hwInfo, true, this->executionEnvironment))); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + executionEnvironment->osInterface = std::make_unique(); + executionEnvironment->osInterface->get()->setWddm(static_cast(wddm)); + std::unique_ptr> csr(static_cast *>(WddmCommandStreamReceiver::create(DEFAULT_TEST_PLATFORM::hwInfo, true, *executionEnvironment))); EXPECT_NE(nullptr, csr); auto wddmFromCsr = csr->peekWddm(); EXPECT_NE(nullptr, wddmFromCsr); @@ -240,7 +240,7 @@ TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledThenCoherencyRequiredFl TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOffWhenWorkloadIsSubmittedThenHeaderDoesntHavePreemptionFieldSet) { HardwareInfo *hwInfo = nullptr; - std::unique_ptr executionEnvironment = std::unique_ptr(getExecutionEnvironmentImpl(hwInfo)); + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); hwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::Disabled; auto wddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); executionEnvironment->commandStreamReceivers.resize(1); @@ -265,7 +265,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOf TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOnWhenWorkloadIsSubmittedThenHeaderDoesHavePreemptionFieldSet) { HardwareInfo *hwInfo = nullptr; - std::unique_ptr executionEnvironment = std::unique_ptr(getExecutionEnvironmentImpl(hwInfo)); + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); hwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::MidThread; auto wddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); executionEnvironment->commandStreamReceivers.resize(1); @@ -291,7 +291,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOn TEST(WddmPreemptionHeaderTests, givenDeviceSupportingPreemptionWhenCommandStreamReceiverIsCreatedThenHeaderContainsPreemptionFieldSet) { HardwareInfo *hwInfo = nullptr; - std::unique_ptr executionEnvironment = std::unique_ptr(getExecutionEnvironmentImpl(hwInfo)); + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); hwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::MidThread; auto commandStreamReceiver = std::make_unique>(hwInfo[0], *executionEnvironment); auto commandHeader = commandStreamReceiver->commandBufferHeader; @@ -301,7 +301,7 @@ TEST(WddmPreemptionHeaderTests, givenDeviceSupportingPreemptionWhenCommandStream TEST(WddmPreemptionHeaderTests, givenDevicenotSupportingPreemptionWhenCommandStreamReceiverIsCreatedThenHeaderPreemptionFieldIsNotSet) { HardwareInfo *hwInfo = nullptr; - std::unique_ptr executionEnvironment = std::unique_ptr(getExecutionEnvironmentImpl(hwInfo)); + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); hwInfo->capabilityTable.defaultPreemptionMode = PreemptionMode::Disabled; auto commandStreamReceiver = std::make_unique>(hwInfo[0], *executionEnvironment); auto commandHeader = commandStreamReceiver->commandBufferHeader; @@ -785,6 +785,7 @@ using WddmSimpleTest = ::testing::Test; HWTEST_F(WddmSimpleTest, givenDefaultWddmCsrWhenItIsCreatedThenBatchingIsTurnedOn) { DebugManager.flags.CsrDispatchMode.set(0); ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment; + executionEnvironment->setHwInfo(*platformDevices); std::unique_ptr device(Device::create(platformDevices[0], executionEnvironment, 0u)); auto wddm = Wddm::createWddm(); executionEnvironment->osInterface = std::make_unique(); @@ -818,55 +819,60 @@ struct WddmCsrCompressionTests : ::testing::Test { WddmMock *myMockWddm; }; -HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenInitializedThenCreatePagetableMngr) { - bool compressionEnabled[2][2] = {{true, false}, {false, true}}; - for (size_t i = 0; i < 2; i++) { - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); - std::unique_ptr device(Device::create(hwInfo, executionEnvironment, 0u)); - setCompressionEnabled(compressionEnabled[i][0], compressionEnabled[i][1]); - myMockWddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); - EXPECT_EQ(nullptr, myMockWddm->getPageTableManager()); - - MockWddmCsr mockWddmCsr(hwInfo[0], *executionEnvironment); - mockWddmCsr.createPageTableManager(); - ASSERT_NE(nullptr, myMockWddm->getPageTableManager()); - - auto mockMngr = reinterpret_cast(myMockWddm->getPageTableManager()); - - GMM_DEVICE_CALLBACKS_INT expectedDeviceCb = {}; - GMM_TRANSLATIONTABLE_CALLBACKS expectedTTCallbacks = {}; - unsigned int expectedFlags = (TT_TYPE::TRTT | TT_TYPE::AUXTT); - auto myGdi = myMockWddm->getGdi(); - // clang-format off - expectedDeviceCb.Adapter.KmtHandle = myMockWddm->getAdapter(); - expectedDeviceCb.hDevice.KmtHandle = myMockWddm->getDevice(); - expectedDeviceCb.hCsr = &mockWddmCsr; - expectedDeviceCb.PagingQueue = myMockWddm->getPagingQueue(); - expectedDeviceCb.PagingFence = myMockWddm->getPagingQueueSyncObject(); - - expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnAllocate = myGdi->createAllocation; - expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnDeallocate = myGdi->destroyAllocation; - expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnMapGPUVA = myGdi->mapGpuVirtualAddress; - expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnMakeResident = myGdi->makeResident; - expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnEvict = myGdi->evict; - expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnReserveGPUVA = myGdi->reserveGpuVirtualAddress; - expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnUpdateGPUVA = myGdi->updateGpuVirtualAddress; - expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnWaitFromCpu = myGdi->waitForSynchronizationObjectFromCpu; - expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnLock = myGdi->lock2; - expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnUnLock = myGdi->unlock2; - expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnEscape = myGdi->escape; - expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnNotifyAubCapture = DeviceCallbacks::notifyAubCapture; - - expectedTTCallbacks.pfWriteL3Adr = TTCallbacks::writeL3Address; - // clang-format on - - EXPECT_TRUE(memcmp(&expectedDeviceCb, &mockMngr->deviceCb, sizeof(GMM_DEVICE_CALLBACKS_INT)) == 0); - EXPECT_TRUE(memcmp(&expectedDeviceCb.Adapter, &mockMngr->deviceCb.Adapter, sizeof(GMM_HANDLE_EXT)) == 0); - EXPECT_TRUE(memcmp(&expectedDeviceCb.hDevice, &mockMngr->deviceCb.hDevice, sizeof(GMM_HANDLE_EXT)) == 0); - EXPECT_TRUE(memcmp(&expectedDeviceCb.DevCbPtrs.KmtCbPtrs, &mockMngr->deviceCb.DevCbPtrs.KmtCbPtrs, sizeof(GMM_DEVICE_CB_PTRS::KmtCbPtrs)) == 0); - EXPECT_TRUE(memcmp(&expectedTTCallbacks, &mockMngr->translationTableCb, sizeof(GMM_TRANSLATIONTABLE_CALLBACKS)) == 0); - EXPECT_TRUE(memcmp(&expectedFlags, &mockMngr->translationTableFlags, sizeof(unsigned int)) == 0); +struct WddmCsrCompressionParameterizedTest : WddmCsrCompressionTests, ::testing::WithParamInterface { + void SetUp() override { + compressionEnabled = GetParam(); } + + bool compressionEnabled; +}; + +HWTEST_P(WddmCsrCompressionParameterizedTest, givenEnabledCompressionWhenInitializedThenCreatePagetableMngr) { + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); + std::unique_ptr device(Device::create(hwInfo, executionEnvironment, 0u)); + setCompressionEnabled(compressionEnabled, !compressionEnabled); + myMockWddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); + EXPECT_EQ(nullptr, myMockWddm->getPageTableManager()); + + MockWddmCsr mockWddmCsr(hwInfo[0], *executionEnvironment); + mockWddmCsr.createPageTableManager(); + ASSERT_NE(nullptr, myMockWddm->getPageTableManager()); + + auto mockMngr = reinterpret_cast(myMockWddm->getPageTableManager()); + + GMM_DEVICE_CALLBACKS_INT expectedDeviceCb = {}; + GMM_TRANSLATIONTABLE_CALLBACKS expectedTTCallbacks = {}; + unsigned int expectedFlags = (TT_TYPE::TRTT | TT_TYPE::AUXTT); + auto myGdi = myMockWddm->getGdi(); + // clang-format off + expectedDeviceCb.Adapter.KmtHandle = myMockWddm->getAdapter(); + expectedDeviceCb.hDevice.KmtHandle = myMockWddm->getDevice(); + expectedDeviceCb.hCsr = &mockWddmCsr; + expectedDeviceCb.PagingQueue = myMockWddm->getPagingQueue(); + expectedDeviceCb.PagingFence = myMockWddm->getPagingQueueSyncObject(); + + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnAllocate = myGdi->createAllocation; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnDeallocate = myGdi->destroyAllocation; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnMapGPUVA = myGdi->mapGpuVirtualAddress; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnMakeResident = myGdi->makeResident; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnEvict = myGdi->evict; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnReserveGPUVA = myGdi->reserveGpuVirtualAddress; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnUpdateGPUVA = myGdi->updateGpuVirtualAddress; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnWaitFromCpu = myGdi->waitForSynchronizationObjectFromCpu; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnLock = myGdi->lock2; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnUnLock = myGdi->unlock2; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnEscape = myGdi->escape; + expectedDeviceCb.DevCbPtrs.KmtCbPtrs.pfnNotifyAubCapture = DeviceCallbacks::notifyAubCapture; + + expectedTTCallbacks.pfWriteL3Adr = TTCallbacks::writeL3Address; + // clang-format on + + EXPECT_TRUE(memcmp(&expectedDeviceCb, &mockMngr->deviceCb, sizeof(GMM_DEVICE_CALLBACKS_INT)) == 0); + EXPECT_TRUE(memcmp(&expectedDeviceCb.Adapter, &mockMngr->deviceCb.Adapter, sizeof(GMM_HANDLE_EXT)) == 0); + EXPECT_TRUE(memcmp(&expectedDeviceCb.hDevice, &mockMngr->deviceCb.hDevice, sizeof(GMM_HANDLE_EXT)) == 0); + EXPECT_TRUE(memcmp(&expectedDeviceCb.DevCbPtrs.KmtCbPtrs, &mockMngr->deviceCb.DevCbPtrs.KmtCbPtrs, sizeof(GMM_DEVICE_CB_PTRS::KmtCbPtrs)) == 0); + EXPECT_TRUE(memcmp(&expectedTTCallbacks, &mockMngr->translationTableCb, sizeof(GMM_TRANSLATIONTABLE_CALLBACKS)) == 0); + EXPECT_TRUE(memcmp(&expectedFlags, &mockMngr->translationTableFlags, sizeof(unsigned int)) == 0); } HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenInitializedThenDontCreatePagetableMngr) { @@ -878,50 +884,52 @@ HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenInitializedThenDon EXPECT_EQ(nullptr, myMockWddm->getPageTableManager()); } -HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenFlushingThenInitTranslationTableOnce) { - bool compressionEnabled[2][2] = {{true, false}, {false, true}}; - for (size_t i = 0; i < 2; i++) { - ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); - setCompressionEnabled(compressionEnabled[i][0], compressionEnabled[i][1]); - myMockWddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); - auto mockWddmCsr = new MockWddmCsr(hwInfo[0], *executionEnvironment); - mockWddmCsr->createPageTableManager(); - mockWddmCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); - executionEnvironment->memoryManager.reset(new WddmMemoryManager(false, false, executionEnvironment->osInterface->get()->getWddm(), *executionEnvironment)); +HWTEST_P(WddmCsrCompressionParameterizedTest, givenEnabledCompressionWhenFlushingThenInitTranslationTableOnce) { + ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); + setCompressionEnabled(compressionEnabled, !compressionEnabled); + myMockWddm = static_cast(executionEnvironment->osInterface->get()->getWddm()); + auto mockWddmCsr = new MockWddmCsr(hwInfo[0], *executionEnvironment); + mockWddmCsr->createPageTableManager(); + mockWddmCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); + executionEnvironment->memoryManager.reset(new WddmMemoryManager(false, false, executionEnvironment->osInterface->get()->getWddm(), *executionEnvironment)); - auto mockMngr = reinterpret_cast(myMockWddm->getPageTableManager()); - std::unique_ptr device(Device::create(hwInfo, executionEnvironment, 0u)); - device->resetCommandStreamReceiver(mockWddmCsr); + auto mockMngr = reinterpret_cast(myMockWddm->getPageTableManager()); + std::unique_ptr device(Device::create(hwInfo, executionEnvironment, 0u)); + device->resetCommandStreamReceiver(mockWddmCsr); - auto memoryManager = executionEnvironment->memoryManager.get(); + auto memoryManager = executionEnvironment->memoryManager.get(); - mockWddmCsr->getCS(); + mockWddmCsr->getCS(); - auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); - IndirectHeap cs(graphicsAllocation); + auto graphicsAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); + IndirectHeap cs(graphicsAllocation); - EXPECT_FALSE(mockWddmCsr->pageTableManagerInitialized); + EXPECT_FALSE(mockWddmCsr->pageTableManagerInitialized); - EXPECT_CALL(*mockMngr, initContextAuxTableRegister(mockWddmCsr, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS)) - .Times(1) - .WillOnce(Return(GMM_SUCCESS)); - EXPECT_CALL(*mockMngr, initContextTRTableRegister(mockWddmCsr, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS)) - .Times(1) - .WillOnce(Return(GMM_SUCCESS)); + EXPECT_CALL(*mockMngr, initContextAuxTableRegister(mockWddmCsr, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS)) + .Times(1) + .WillOnce(Return(GMM_SUCCESS)); + EXPECT_CALL(*mockMngr, initContextTRTableRegister(mockWddmCsr, GMM_ENGINE_TYPE::ENGINE_TYPE_RCS)) + .Times(1) + .WillOnce(Return(GMM_SUCCESS)); - DispatchFlags dispatchFlags; - mockWddmCsr->flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags, *device); + DispatchFlags dispatchFlags; + mockWddmCsr->flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags, *device); - EXPECT_TRUE(mockWddmCsr->pageTableManagerInitialized); + EXPECT_TRUE(mockWddmCsr->pageTableManagerInitialized); - // flush again to check if PT manager was initialized once - mockWddmCsr->flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags, *device); + // flush again to check if PT manager was initialized once + mockWddmCsr->flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags, *device); - mockWddmCsr->flushBatchedSubmissions(); - memoryManager->freeGraphicsMemory(graphicsAllocation); - } + mockWddmCsr->flushBatchedSubmissions(); + memoryManager->freeGraphicsMemory(graphicsAllocation); } +INSTANTIATE_TEST_CASE_P( + WddmCsrCompressionParameterizedTestCreate, + WddmCsrCompressionParameterizedTest, + ::testing::Bool()); + HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenFlushingThenDontInitTranslationTable) { ExecutionEnvironment *executionEnvironment = getExecutionEnvironmentImpl(hwInfo); setCompressionEnabled(false, false); diff --git a/unit_tests/os_interface/windows/wddm20_tests.cpp b/unit_tests/os_interface/windows/wddm20_tests.cpp index e088379658..7eb4322146 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -170,7 +170,7 @@ TEST_F(Wddm20Tests, whenInitializeWddmThenContextIsCreated) { } TEST_F(Wddm20Tests, allocation) { - OsAgnosticMemoryManager mm(false, false, executionEnvironment); + OsAgnosticMemoryManager mm(false, false, *executionEnvironment); WddmAllocation allocation(GraphicsAllocation::AllocationType::UNDECIDED, mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull, false); Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); @@ -334,7 +334,7 @@ TEST_F(Wddm20WithMockGdiDllTests, GivenThreeOsHandlesWhenAskedForDestroyAllocati } TEST_F(Wddm20Tests, mapAndFreeGpuVa) { - OsAgnosticMemoryManager mm(false, false, executionEnvironment); + OsAgnosticMemoryManager mm(false, false, *executionEnvironment); WddmAllocation allocation(GraphicsAllocation::AllocationType::UNDECIDED, mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull, false); Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); @@ -359,7 +359,7 @@ TEST_F(Wddm20Tests, mapAndFreeGpuVa) { } TEST_F(Wddm20Tests, givenNullAllocationWhenCreateThenAllocateAndMap) { - OsAgnosticMemoryManager mm(false, false, executionEnvironment); + OsAgnosticMemoryManager mm(false, false, *executionEnvironment); WddmAllocation allocation(GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 100, nullptr, MemoryPool::MemoryNull, false); Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); @@ -379,7 +379,7 @@ TEST_F(Wddm20Tests, givenNullAllocationWhenCreateThenAllocateAndMap) { } TEST_F(Wddm20Tests, makeResidentNonResident) { - OsAgnosticMemoryManager mm(false, false, executionEnvironment); + OsAgnosticMemoryManager mm(false, false, *executionEnvironment); WddmAllocation allocation(GraphicsAllocation::AllocationType::UNDECIDED, mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull, false); Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); @@ -418,7 +418,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); EXPECT_EQ(0u, status); - WddmMemoryManager mm(false, false, wddm, executionEnvironment); + WddmMemoryManager mm(false, false, wddm, *executionEnvironment); auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false); auto wddmAllocation = (WddmAllocation *)graphicsAllocation; @@ -454,7 +454,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); EXPECT_EQ(0u, status); - WddmMemoryManager mm(false, false, wddm, executionEnvironment); + WddmMemoryManager mm(false, false, wddm, *executionEnvironment); auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false); auto wddmAllocation = (WddmAllocation *)graphicsAllocation; @@ -482,8 +482,6 @@ HWTEST_F(Wddm20InstrumentationTest, configureDeviceAddressSpaceOnInit) { D3DKMT_HANDLE adapterHandle = ADAPTER_HANDLE; D3DKMT_HANDLE deviceHandle = DEVICE_HANDLE; const HardwareInfo hwInfo = *platformDevices[0]; - ExecutionEnvironment executionEnvironment; - executionEnvironment.initGmm(&hwInfo); BOOLEAN FtrL3IACoherency = hwInfo.pSkuTable->ftrL3IACoherency ? 1 : 0; uintptr_t maxAddr = hwInfo.capabilityTable.gpuAddressSpace == MemoryConstants::max48BitAddress ? reinterpret_cast(sysInfo.lpMaximumApplicationAddress) + 1 @@ -502,8 +500,6 @@ HWTEST_F(Wddm20InstrumentationTest, configureDeviceAddressSpaceOnInit) { TEST_F(Wddm20InstrumentationTest, configureDeviceAddressSpaceNoAdapter) { wddm->adapter = static_cast(0); - ExecutionEnvironment executionEnvironment; - executionEnvironment.initGmm(*platformDevices); EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(static_cast(0), ::testing::_, ::testing::_, ::testing::_, ::testing::_)) .Times(0); @@ -514,8 +510,6 @@ TEST_F(Wddm20InstrumentationTest, configureDeviceAddressSpaceNoAdapter) { TEST_F(Wddm20InstrumentationTest, configureDeviceAddressSpaceNoDevice) { wddm->device = static_cast(0); - ExecutionEnvironment executionEnvironment; - executionEnvironment.initGmm(*platformDevices); EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(::testing::_, static_cast(0), ::testing::_, ::testing::_, ::testing::_)) .Times(0); @@ -526,8 +520,6 @@ TEST_F(Wddm20InstrumentationTest, configureDeviceAddressSpaceNoDevice) { TEST_F(Wddm20InstrumentationTest, configureDeviceAddressSpaceNoEscFunc) { wddm->gdi->escape = static_cast(nullptr); - ExecutionEnvironment executionEnvironment; - executionEnvironment.initGmm(*platformDevices); EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(::testing::_, ::testing::_, static_cast(nullptr), ::testing::_, ::testing::_)) .Times(0); @@ -590,7 +582,6 @@ TEST(DebugFlagTest, givenDebugManagerWhenGetForUseNoRingFlushesKmdModeIsCalledTh } TEST_F(Wddm20Tests, makeResidentMultipleHandles) { - D3DKMT_HANDLE handles[2] = {ALLOCATION_HANDLE, ALLOCATION_HANDLE}; gdi->getMakeResidentArg().NumAllocations = 0; gdi->getMakeResidentArg().AllocationList = nullptr; @@ -979,7 +970,7 @@ TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceThenOtherReso } TEST_F(WddmLockWithMakeResidentTests, whenAlllocationNeedsBlockingMakeResidentBeforeLockThenLockWithBlockingMakeResident) { - WddmMemoryManager memoryManager(false, false, wddm, executionEnvironment); + WddmMemoryManager memoryManager(false, false, wddm, *executionEnvironment); MockWddmAllocation allocation; allocation.needsMakeResidentBeforeLock = false; memoryManager.lockResource(&allocation); diff --git a/unit_tests/os_interface/windows/wddm23_tests.cpp b/unit_tests/os_interface/windows/wddm23_tests.cpp index 00cf2d496e..0a562d6f7d 100644 --- a/unit_tests/os_interface/windows/wddm23_tests.cpp +++ b/unit_tests/os_interface/windows/wddm23_tests.cpp @@ -11,8 +11,8 @@ #include "runtime/os_interface/windows/gdi_interface.h" #include "runtime/os_interface/windows/os_context_win.h" #include "runtime/os_interface/windows/os_interface.h" +#include "runtime/platform/platform.h" #include "test.h" -#include "unit_tests/fixtures/gmm_environment_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/mocks/mock_wddm.h" #include "unit_tests/mocks/mock_wddm_interface23.h" @@ -20,11 +20,11 @@ using namespace OCLRT; -struct Wddm23TestsWithoutWddmInit : public ::testing::Test, GdiDllFixture, public GmmEnvironmentFixture { +struct Wddm23TestsWithoutWddmInit : public ::testing::Test, GdiDllFixture { void SetUp() override { - GmmEnvironmentFixture::SetUp(); GdiDllFixture::SetUp(); + executionEnvironment = platformImpl->peekExecutionEnvironment(); wddm = static_cast(Wddm::createWddm()); osInterface = std::make_unique(); osInterface->get()->setWddm(wddm); @@ -43,13 +43,13 @@ struct Wddm23TestsWithoutWddmInit : public ::testing::Test, GdiDllFixture, publi void TearDown() override { GdiDllFixture::TearDown(); - GmmEnvironmentFixture::TearDown(); } std::unique_ptr osInterface; std::unique_ptr osContext; WddmMock *wddm = nullptr; WddmMockInterface23 *wddmMockInterface = nullptr; + ExecutionEnvironment *executionEnvironment; }; struct Wddm23Tests : public Wddm23TestsWithoutWddmInit { diff --git a/unit_tests/os_interface/windows/wddm_address_space_tests.cpp b/unit_tests/os_interface/windows/wddm_address_space_tests.cpp index 24a6886ddb..201f65e5da 100644 --- a/unit_tests/os_interface/windows/wddm_address_space_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_address_space_tests.cpp @@ -6,8 +6,8 @@ */ #include "runtime/command_stream/preemption.h" +#include "runtime/helpers/options.h" #include "test.h" -#include "unit_tests/fixtures/gmm_environment_fixture.h" #include "unit_tests/mocks/mock_wddm.h" using namespace OCLRT; @@ -54,9 +54,7 @@ class WddmMockReserveAddress : public WddmMock { uint32_t returnNullIter = 0; }; -using WddmReserveAddressTest = Test; - -TEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsSuccessfulThenReturnReserveAddress) { +TEST(WddmReserveAddressTest, givenWddmWhenFirstIsSuccessfulThenReturnReserveAddress) { std::unique_ptr wddm(new WddmMockReserveAddress()); size_t size = 0x1000; void *reserve = nullptr; @@ -73,7 +71,7 @@ TEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsSuccessfulThenReturnReserveAd wddm->releaseReservedAddress(reserve); } -TEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsNullThenReturnNull) { +TEST(WddmReserveAddressTest, givenWddmWhenFirstIsNullThenReturnNull) { std::unique_ptr wddm(new WddmMockReserveAddress()); size_t size = 0x1000; void *reserve = nullptr; @@ -86,7 +84,7 @@ TEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsNullThenReturnNull) { EXPECT_EQ(expectedReserve, reinterpret_cast(reserve)); } -TEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsInvalidSecondSuccessfulThenReturnSecond) { +TEST(WddmReserveAddressTest, givenWddmWhenFirstIsInvalidSecondSuccessfulThenReturnSecond) { std::unique_ptr wddm(new WddmMockReserveAddress()); size_t size = 0x1000; void *reserve = nullptr; @@ -103,7 +101,7 @@ TEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsInvalidSecondSuccessfulThenRe wddm->releaseReservedAddress(reserve); } -TEST_F(WddmReserveAddressTest, givenWddmWhenSecondIsInvalidThirdSuccessfulThenReturnThird) { +TEST(WddmReserveAddressTest, givenWddmWhenSecondIsInvalidThirdSuccessfulThenReturnThird) { std::unique_ptr wddm(new WddmMockReserveAddress()); size_t size = 0x1000; void *reserve = nullptr; @@ -120,7 +118,7 @@ TEST_F(WddmReserveAddressTest, givenWddmWhenSecondIsInvalidThirdSuccessfulThenRe wddm->releaseReservedAddress(reserve); } -TEST_F(WddmReserveAddressTest, givenWddmWhenFirstIsInvalidSecondNullThenReturnSecondNull) { +TEST(WddmReserveAddressTest, givenWddmWhenFirstIsInvalidSecondNullThenReturnSecondNull) { std::unique_ptr wddm(new WddmMockReserveAddress()); size_t size = 0x1000; void *reserve = nullptr; diff --git a/unit_tests/os_interface/windows/wddm_fixture.h b/unit_tests/os_interface/windows/wddm_fixture.h index bf86ade330..df0fbbe5d9 100644 --- a/unit_tests/os_interface/windows/wddm_fixture.h +++ b/unit_tests/os_interface/windows/wddm_fixture.h @@ -12,8 +12,8 @@ #include "runtime/os_interface/windows/gdi_interface.h" #include "runtime/os_interface/windows/os_context_win.h" #include "runtime/os_interface/windows/os_interface.h" +#include "runtime/platform/platform.h" #include "test.h" -#include "unit_tests/fixtures/gmm_environment_fixture.h" #include "unit_tests/mocks/mock_wddm.h" #include "unit_tests/os_interface/windows/gdi_dll_fixture.h" #include "unit_tests/os_interface/windows/mock_gdi_interface.h" @@ -21,9 +21,9 @@ #include "mock_gmm_memory.h" namespace OCLRT { -struct WddmFixture : public GmmEnvironmentFixture { - void SetUp() override { - GmmEnvironmentFixture::SetUp(); +struct WddmFixture : ::testing::Test { + void SetUp() { + executionEnvironment = platformImpl->peekExecutionEnvironment(); wddm = static_cast(Wddm::createWddm()); osInterface = std::make_unique(); osInterface->get()->setWddm(wddm); @@ -35,20 +35,17 @@ struct WddmFixture : public GmmEnvironmentFixture { ASSERT_TRUE(wddm->isInitialized()); } - void TearDown() override { - GmmEnvironmentFixture::TearDown(); - }; - WddmMock *wddm = nullptr; std::unique_ptr osInterface; std::unique_ptr osContext; + ExecutionEnvironment *executionEnvironment; MockGdi *gdi = nullptr; }; -struct WddmFixtureWithMockGdiDll : public GmmEnvironmentFixture, public GdiDllFixture { +struct WddmFixtureWithMockGdiDll : public GdiDllFixture { void SetUp() override { - GmmEnvironmentFixture::SetUp(); + executionEnvironment = platformImpl->peekExecutionEnvironment(); GdiDllFixture::SetUp(); wddm = static_cast(Wddm::createWddm()); osInterface = std::make_unique(); @@ -64,30 +61,30 @@ struct WddmFixtureWithMockGdiDll : public GmmEnvironmentFixture, public GdiDllFi void TearDown() override { GdiDllFixture::TearDown(); - GmmEnvironmentFixture::TearDown(); } WddmMock *wddm = nullptr; std::unique_ptr osInterface; std::unique_ptr osContext; + ExecutionEnvironment *executionEnvironment; }; -struct WddmInstrumentationGmmFixture : public GmmEnvironmentFixture { - void SetUp() override { - GmmEnvironmentFixture::SetUp(); +struct WddmInstrumentationGmmFixture { + void SetUp() { + executionEnvironment = platformImpl->peekExecutionEnvironment(); wddm.reset(static_cast(Wddm::createWddm())); gmmMem = new ::testing::NiceMock(); wddm->gmmMemory.reset(gmmMem); } - void TearDown() override { - GmmEnvironmentFixture::TearDown(); + void TearDown() { } std::unique_ptr wddm; GmockGmmMemory *gmmMem = nullptr; + ExecutionEnvironment *executionEnvironment; }; -using WddmTest = Test; +using WddmTest = WddmFixture; using WddmTestWithMockGdiDll = Test; using WddmInstrumentationTest = Test; using WddmTestSingle = ::testing::Test; diff --git a/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp b/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp index 097626047b..54690b8671 100644 --- a/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp @@ -11,8 +11,8 @@ #include "runtime/memory_manager/memory_manager.h" #include "runtime/os_interface/windows/wddm/wddm.h" #include "runtime/os_interface/windows/wddm_allocation.h" +#include "runtime/platform/platform.h" #include "test.h" -#include "unit_tests/fixtures/gmm_environment_fixture.h" #include "unit_tests/mock_gdi/mock_gdi.h" #include "unit_tests/os_interface/windows/mock_gdi_interface.h" #include "unit_tests/os_interface/windows/mock_kmdaf_listener.h" @@ -35,20 +35,20 @@ class WddmWithKmDafMock : public Wddm { } }; -class WddmKmDafListenerTest : public GmmEnvironmentFixture, public ::testing::Test { +class WddmKmDafListenerTest : public ::testing::Test { public: void SetUp() { - GmmEnvironmentFixture::SetUp(); + executionEnvironment = platformImpl->peekExecutionEnvironment(); wddmWithKmDafMock.reset(new WddmWithKmDafMock()); wddmWithKmDafMock->gdi.reset(new MockGdi()); wddmWithKmDafMock->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])); wddmWithKmDafMock->featureTable->ftrKmdDaf = true; } void TearDown() { - GmmEnvironmentFixture::TearDown(); } std::unique_ptr wddmWithKmDafMock; + ExecutionEnvironment *executionEnvironment; }; TEST_F(WddmKmDafListenerTest, givenWddmWhenLockResourceIsCalledThenKmDafListenerNotifyLockIsFedWithCorrectParams) { diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl b/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl index 8bd1880b9d..88ffa7a718 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl +++ b/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl @@ -14,7 +14,7 @@ using namespace OCLRT; using namespace ::testing; TEST_F(WddmMemoryManagerSimpleTest, givenUseSystemMemorySetToTrueWhenAllocateInDevicePoolIsCalledThenNullptrIsReturned) { - memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); + memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment)); MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; AllocationData allocData; allocData.size = MemoryConstants::pageSize; 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 dd1d5236db..a7e7c260be 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -30,7 +30,6 @@ using namespace OCLRT; using namespace ::testing; void WddmMemoryManagerFixture::SetUp() { - GmmEnvironmentFixture::SetUp(); GdiDllFixture::SetUp(); wddm = static_cast(Wddm::createWddm()); @@ -43,10 +42,11 @@ void WddmMemoryManagerFixture::SetUp() { constexpr uint64_t heap32Base = (is32bit) ? 0x1000 : 0x800000000000; wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1); - executionEnvironment.osInterface = std::make_unique(); - executionEnvironment.osInterface->get()->setWddm(wddm); + executionEnvironment = platformImpl->peekExecutionEnvironment(); + executionEnvironment->osInterface = std::make_unique(); + executionEnvironment->osInterface->get()->setWddm(wddm); - memoryManager = std::make_unique(wddm, executionEnvironment); + memoryManager = std::make_unique(wddm, *executionEnvironment); } TEST(ResidencyData, givenNewlyConstructedResidencyDataThenItIsNotResidentOnAnyOsContext) { @@ -132,7 +132,7 @@ TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabled } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenMemoryPoolIsSystem4KBPages) { - memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); + memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment)); auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); EXPECT_NE(nullptr, allocation); @@ -142,7 +142,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemory64kbIsCalledThenMemoryPoolIsSystem64KBPages) { - memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); + memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment)); AllocationData allocationData; allocationData.size = 4096u; auto allocation = memoryManager->allocateGraphicsMemory64kb(allocationData); @@ -153,7 +153,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAl } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPages) { - memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); + memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment)); void *ptr = reinterpret_cast(0x1001); auto size = 4096u; auto allocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, size}, ptr); @@ -166,7 +166,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) { - memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); + memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment)); void *ptr = reinterpret_cast(0x1001); auto size = MemoryConstants::pageSize; @@ -180,7 +180,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocate32BitGraphicsM } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMThen4KBGraphicsAllocationIsReturned) { - memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); + memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment)); auto size = MemoryConstants::pageSize; auto svmAllocation = memoryManager->allocateGraphicsMemoryWithProperties({size, GraphicsAllocation::AllocationType::SVM}); @@ -191,7 +191,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesDisabledWhenA } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMThenMemoryPoolIsSystem64KBPages) { - memoryManager.reset(new MockWddmMemoryManager(true, false, wddm, executionEnvironment)); + memoryManager.reset(new MockWddmMemoryManager(true, false, wddm, *executionEnvironment)); auto size = MemoryConstants::pageSize; auto svmAllocation = memoryManager->allocateGraphicsMemoryWithProperties({size, GraphicsAllocation::AllocationType::SVM}); @@ -201,7 +201,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAl } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenCreateAllocationFromHandleIsCalledThenMemoryPoolIsSystemCpuInaccessible) { - memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); + memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment)); auto osHandle = 1u; gdi->getQueryResourceInfoArgOut().NumAllocations = 1; std::unique_ptr gmm(new Gmm(nullptr, 0, false)); @@ -221,7 +221,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenCreateAllocationFromHa TEST_F(WddmMemoryManagerSimpleTest, givenAllocateGraphicsMemoryForNonSvmHostPtrIsCalledWhenNotAlignedPtrIsPassedThenAlignedGraphicsAllocationIsCreated) { - memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); + memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, *executionEnvironment)); void *hostPtr = reinterpret_cast(0x5001); auto allocation = memoryManager->allocateGraphicsMemoryForNonSvmHostPtr(13, hostPtr); @@ -584,8 +584,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageWithMipCountNo } TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreatedFromHostPtrThenallocateGraphicsMemoryForImageIsUsed) { - executionEnvironment.incRefInternal(); // to prevent destrorying execution environment by destructor of device - std::unique_ptr device(MockDevice::createWithExecutionEnvironment(*platformDevices, &executionEnvironment, 0u)); + std::unique_ptr device(MockDevice::createWithExecutionEnvironment(*platformDevices, executionEnvironment, 0u)); MockContext context(device.get()); context.setMemoryManager(memoryManager.get()); @@ -1252,7 +1251,7 @@ TEST_F(MockWddmMemoryManagerTest, givenEnabled64kbpagesWhenCreatingGraphicsMemor auto wddm = std::make_unique(); EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]))); DebugManager.flags.Enable64kbpages.set(true); - WddmMemoryManager memoryManager64k(true, false, wddm.get(), executionEnvironment); + WddmMemoryManager memoryManager64k(true, false, wddm.get(), *executionEnvironment); EXPECT_EQ(0, wddm->createAllocationResult.called); GraphicsAllocation *galloc = memoryManager64k.allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize64k, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY}); @@ -1270,7 +1269,7 @@ TEST_F(OsAgnosticMemoryManagerUsingWddmTest, givenEnabled64kbPagesWhenAllocation auto wddm = std::make_unique(); EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]))); DebugManager.flags.Enable64kbpages.set(true); - MockWddmMemoryManager memoryManager(true, false, wddm.get(), executionEnvironment); + MockWddmMemoryManager memoryManager(true, false, wddm.get(), *executionEnvironment); AllocationData allocationData; allocationData.size = 1u; auto graphicsAllocation = memoryManager.allocateGraphicsMemory64kb(allocationData); @@ -1304,7 +1303,7 @@ TEST_F(MockWddmMemoryManagerTest, givenWddmWhenallocateGraphicsMemory64kbThenLoc TEST_F(MockWddmMemoryManagerTest, givenDefaultMemoryManagerWhenItIsCreatedThenAsyncDeleterEnabledIsTrue) { auto wddm = std::make_unique(); - WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment); + WddmMemoryManager memoryManager(false, false, wddm.get(), *executionEnvironment); EXPECT_TRUE(memoryManager.isAsyncDeleterEnabled()); EXPECT_NE(nullptr, memoryManager.getDeferredDeleter()); } @@ -1333,7 +1332,7 @@ TEST_F(MockWddmMemoryManagerTest, givenEnabledAsyncDeleterFlagWhenMemoryManagerI bool defaultEnableDeferredDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get(); DebugManager.flags.EnableDeferredDeleter.set(true); auto wddm = std::make_unique(); - WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment); + WddmMemoryManager memoryManager(false, false, wddm.get(), *executionEnvironment); EXPECT_TRUE(memoryManager.isAsyncDeleterEnabled()); EXPECT_NE(nullptr, memoryManager.getDeferredDeleter()); DebugManager.flags.EnableDeferredDeleter.set(defaultEnableDeferredDeleterFlag); @@ -1343,7 +1342,7 @@ TEST_F(MockWddmMemoryManagerTest, givenDisabledAsyncDeleterFlagWhenMemoryManager bool defaultEnableDeferredDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get(); DebugManager.flags.EnableDeferredDeleter.set(false); auto wddm = std::make_unique(); - WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment); + WddmMemoryManager memoryManager(false, false, wddm.get(), *executionEnvironment); EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled()); EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter()); DebugManager.flags.EnableDeferredDeleter.set(defaultEnableDeferredDeleterFlag); @@ -1352,7 +1351,7 @@ TEST_F(MockWddmMemoryManagerTest, givenDisabledAsyncDeleterFlagWhenMemoryManager TEST_F(MockWddmMemoryManagerTest, givenPageTableManagerWhenMapAuxGpuVaCalledThenUseWddmToMap) { auto myWddm = std::make_unique(); EXPECT_TRUE(myWddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]))); - WddmMemoryManager memoryManager(false, false, myWddm.get(), executionEnvironment); + WddmMemoryManager memoryManager(false, false, myWddm.get(), *executionEnvironment); auto mockMngr = new NiceMock(); myWddm->resetPageTableManager(mockMngr); @@ -1412,7 +1411,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenMappedGpuVa TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenReleaseingThenUnmapAuxVa) { auto wddm = std::make_unique(); EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]))); - WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment); + WddmMemoryManager memoryManager(false, false, wddm.get(), *executionEnvironment); D3DGPU_VIRTUAL_ADDRESS gpuVa = 123; auto mockMngr = new NiceMock(); @@ -1438,7 +1437,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenReleaseingT TEST_F(MockWddmMemoryManagerTest, givenNonRenderCompressedAllocationWhenReleaseingThenDontUnmapAuxVa) { auto wddm = std::make_unique(); EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]))); - WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment); + WddmMemoryManager memoryManager(false, false, wddm.get(), *executionEnvironment); auto mockMngr = new NiceMock(); wddm->resetPageTableManager(mockMngr); @@ -1484,7 +1483,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedFlagSetWhenInternalIsUnse D3DGPU_VIRTUAL_ADDRESS gpuVa = 0; auto wddm = std::make_unique(); EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]))); - WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment); + WddmMemoryManager memoryManager(false, false, wddm.get(), *executionEnvironment); auto mockMngr = new NiceMock(); wddm->resetPageTableManager(mockMngr); diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h index 31cbe3fdd0..c14c084722 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h @@ -9,7 +9,6 @@ #include "runtime/os_interface/windows/os_interface.h" #include "test.h" -#include "unit_tests/fixtures/gmm_environment_fixture.h" #include "unit_tests/mocks/mock_context.h" #include "unit_tests/mocks/mock_gmm.h" #include "unit_tests/mocks/mock_gmm_page_table_mngr.h" @@ -25,26 +24,25 @@ using namespace OCLRT; using namespace ::testing; -class WddmMemoryManagerFixture : public GmmEnvironmentFixture, public GdiDllFixture { +class WddmMemoryManagerFixture : public GdiDllFixture { public: void SetUp() override; void TearDown() override { GdiDllFixture::TearDown(); - GmmEnvironmentFixture::TearDown(); } + ExecutionEnvironment *executionEnvironment; std::unique_ptr memoryManager; WddmMock *wddm; }; typedef ::Test WddmMemoryManagerTest; -class MockWddmMemoryManagerFixture : public GmmEnvironmentFixture { +class MockWddmMemoryManagerFixture { public: void SetUp() { - GmmEnvironmentFixture::SetUp(); - + executionEnvironment = platformImpl->peekExecutionEnvironment(); gdi = new MockGdi(); wddm = static_cast(Wddm::createWddm()); @@ -53,10 +51,10 @@ class MockWddmMemoryManagerFixture : public GmmEnvironmentFixture { wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1); EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]))); - executionEnvironment.osInterface.reset(new OSInterface()); - executionEnvironment.osInterface->get()->setWddm(wddm); + executionEnvironment->osInterface.reset(new OSInterface()); + executionEnvironment->osInterface->get()->setWddm(wddm); - memoryManager = std::make_unique(wddm, executionEnvironment); + memoryManager = std::make_unique(wddm, *executionEnvironment); osContext = memoryManager->createAndRegisterOsContext(nullptr, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], 1, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])); osContext->incRefInternal(); @@ -64,9 +62,9 @@ class MockWddmMemoryManagerFixture : public GmmEnvironmentFixture { void TearDown() { osContext->decRefInternal(); - GmmEnvironmentFixture::TearDown(); } + ExecutionEnvironment *executionEnvironment; std::unique_ptr memoryManager; WddmMock *wddm = nullptr; OsContext *osContext = nullptr; @@ -75,12 +73,20 @@ class MockWddmMemoryManagerFixture : public GmmEnvironmentFixture { typedef ::Test WddmMemoryManagerResidencyTest; -class WddmMemoryManagerFixtureWithGmockWddm : public GmmEnvironmentFixture { +class ExecutionEnvironmentFixture : public ::testing::Test { + public: + ExecutionEnvironmentFixture() { + executionEnvironment = platformImpl->peekExecutionEnvironment(); + } + + ExecutionEnvironment *executionEnvironment; +}; + +class WddmMemoryManagerFixtureWithGmockWddm : public ExecutionEnvironmentFixture { public: MockWddmMemoryManager *memoryManager = nullptr; - void SetUp() { - GmmEnvironmentFixture::SetUp(); + void SetUp() override { // wddm is deleted by memory manager wddm = new NiceMock; osInterface = std::make_unique(); @@ -89,7 +95,7 @@ class WddmMemoryManagerFixtureWithGmockWddm : public GmmEnvironmentFixture { EXPECT_TRUE(wddm->init(preemptionMode)); osInterface->get()->setWddm(wddm); wddm->init(preemptionMode); - memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm, executionEnvironment); + memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm, *executionEnvironment); //assert we have memory manager ASSERT_NE(nullptr, memoryManager); osContext = memoryManager->createAndRegisterOsContext(nullptr, HwHelper::get(platformDevices[0]->pPlatform->eRenderCoreFamily).getGpgpuEngineInstances()[0], 1, preemptionMode); @@ -99,10 +105,9 @@ class WddmMemoryManagerFixtureWithGmockWddm : public GmmEnvironmentFixture { ON_CALL(*wddm, createAllocationsAndMapGpuVa(::testing::_)).WillByDefault(::testing::Invoke(wddm, &GmockWddm::baseCreateAllocationAndMapGpuVa)); } - void TearDown() { + void TearDown() override { osContext->decRefInternal(); delete memoryManager; - GmmEnvironmentFixture::TearDown(); } NiceMock *wddm = nullptr; @@ -110,7 +115,7 @@ class WddmMemoryManagerFixtureWithGmockWddm : public GmmEnvironmentFixture { OsContext *osContext; }; -typedef ::Test WddmMemoryManagerTest2; +using WddmMemoryManagerTest2 = WddmMemoryManagerFixtureWithGmockWddm; class BufferWithWddmMemory : public ::testing::Test, public WddmMemoryManagerFixture { @@ -145,5 +150,5 @@ class WddmMemoryManagerSimpleTest : public MockWddmMemoryManagerFixture, public } }; -using MockWddmMemoryManagerTest = ::Test; +using MockWddmMemoryManagerTest = ExecutionEnvironmentFixture; using OsAgnosticMemoryManagerUsingWddmTest = MockWddmMemoryManagerTest; diff --git a/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp b/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp index 0788058e3f..a0621102eb 100644 --- a/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_residency_controller_tests.cpp @@ -14,6 +14,7 @@ #include "runtime/os_interface/windows/os_interface.h" #include "runtime/os_interface/windows/wddm/wddm_interface.h" #include "runtime/os_interface/windows/wddm_residency_controller.h" +#include "runtime/platform/platform.h" #include "test.h" #include "unit_tests/mocks/mock_allocation_properties.h" #include "unit_tests/mocks/mock_wddm.h" @@ -80,8 +81,7 @@ struct WddmResidencyControllerWithGdiTest : ::testing::Test { struct WddmResidencyControllerWithMockWddmTest : public WddmResidencyControllerTest { void SetUp() { - executionEnvironment = std::make_unique(); - executionEnvironment->initGmm(*platformDevices); + executionEnvironment = platformImpl->peekExecutionEnvironment(); wddm = new ::testing::NiceMock(); wddm->gdi = std::make_unique(); @@ -102,7 +102,7 @@ struct WddmResidencyControllerWithMockWddmTest : public WddmResidencyControllerT osContext->decRefInternal(); } - std::unique_ptr executionEnvironment; + ExecutionEnvironment *executionEnvironment; std::unique_ptr memoryManager; ::testing::NiceMock *wddm = nullptr; OsContext *osContext; diff --git a/unit_tests/preemption/preemption_tests.cpp b/unit_tests/preemption/preemption_tests.cpp index 09bf044aab..450e88c0d7 100644 --- a/unit_tests/preemption/preemption_tests.cpp +++ b/unit_tests/preemption/preemption_tests.cpp @@ -478,11 +478,10 @@ HWTEST_F(MidThreadPreemptionTests, givenMidThreadPreemptionWhenFailingOnCsrSurfa uint32_t allocateGraphicsMemoryCount = 0; }; - ExecutionEnvironment executionEnvironment; - executionEnvironment.incRefInternal(); - executionEnvironment.memoryManager = std::make_unique(executionEnvironment); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + executionEnvironment->memoryManager = std::make_unique(*executionEnvironment); - std::unique_ptr mockDevice(MockDevice::create(platformDevices[0], &executionEnvironment, 0)); + std::unique_ptr mockDevice(MockDevice::create(platformDevices[0], executionEnvironment, 0)); EXPECT_EQ(nullptr, mockDevice.get()); } diff --git a/unit_tests/sharings/gl/gl_arb_sync_event_tests.cpp b/unit_tests/sharings/gl/gl_arb_sync_event_tests.cpp index aea7c4b066..5f12c73548 100644 --- a/unit_tests/sharings/gl/gl_arb_sync_event_tests.cpp +++ b/unit_tests/sharings/gl/gl_arb_sync_event_tests.cpp @@ -9,6 +9,7 @@ #include "runtime/event/user_event.h" #include "runtime/execution_environment/execution_environment.h" #include "runtime/os_interface/os_interface.h" +#include "runtime/platform/platform.h" #include "runtime/sharings/gl/gl_arb_sync_event.h" #include "runtime/sharings/sharing.h" #include "test.h" @@ -63,7 +64,7 @@ struct GlArbSyncEventTest : public ::testing::Test { } void SetUp() override { - executionEnvironment = new ExecutionEnvironment; + executionEnvironment = platformImpl->peekExecutionEnvironment(); auto mockCsr = new MockCommandStreamReceiver(*executionEnvironment); executionEnvironment->memoryManager = std::make_unique(false, false, *executionEnvironment); device.reset(MockDevice::create(nullptr, executionEnvironment, 0u)); diff --git a/unit_tests/sharings/gl/gl_texture_tests.cpp b/unit_tests/sharings/gl/gl_texture_tests.cpp index 77cb3a1c8b..33d6f67a3b 100644 --- a/unit_tests/sharings/gl/gl_texture_tests.cpp +++ b/unit_tests/sharings/gl/gl_texture_tests.cpp @@ -6,6 +6,7 @@ */ #include "runtime/mem_obj/image.h" +#include "runtime/platform/platform.h" #include "runtime/sharings/gl/gl_texture.h" #include "unit_tests/libult/create_command_stream.h" #include "unit_tests/libult/ult_command_stream_receiver.h" @@ -48,15 +49,15 @@ class GlSharingTextureTests : public ::testing::Test { }; void SetUp() override { - executionEnvironment.incRefInternal(); + executionEnvironment = platformImpl->peekExecutionEnvironment(); imgDesc = {}; imgDesc.image_type = CL_MEM_OBJECT_IMAGE1D; imgDesc.image_width = 10; auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - tempMM = new TempMM(executionEnvironment); - executionEnvironment.memoryManager.reset(tempMM); - device.reset(MockDevice::create(*platformDevices, &executionEnvironment, 0)); + tempMM = new TempMM(*executionEnvironment); + executionEnvironment->memoryManager.reset(tempMM); + device.reset(MockDevice::create(*platformDevices, executionEnvironment, 0)); clContext = std::make_unique(device.get()); mockGlSharingFunctions = glSharing->sharingFunctions.release(); @@ -75,7 +76,7 @@ class GlSharingTextureTests : public ::testing::Test { mockGmmResInfo->setUnifiedAuxTranslationCapable(); } - ExecutionEnvironment executionEnvironment; + ExecutionEnvironment *executionEnvironment; cl_image_desc imgDesc; TempMM *tempMM; std::unique_ptr device; diff --git a/unit_tests/source_level_debugger/source_level_debugger_device_tests.cpp b/unit_tests/source_level_debugger/source_level_debugger_device_tests.cpp index b9d5c6c0f1..4908face93 100644 --- a/unit_tests/source_level_debugger/source_level_debugger_device_tests.cpp +++ b/unit_tests/source_level_debugger/source_level_debugger_device_tests.cpp @@ -5,6 +5,7 @@ * */ +#include "runtime/platform/platform.h" #include "runtime/source_level_debugger/source_level_debugger.h" #include "test.h" #include "unit_tests/fixtures/device_fixture.h" @@ -36,18 +37,18 @@ class MockDeviceWithDebuggerActive : public MockDevice { }; TEST(DeviceWithSourceLevelDebugger, givenDeviceWithSourceLevelDebuggerActiveWhenDeviceIsDestructedThenSourceLevelDebuggerIsNotified) { - auto exeEnv = new ExecutionEnvironment; + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); auto gmock = new ::testing::NiceMock(new MockOsLibrary); - exeEnv->sourceLevelDebugger.reset(gmock); - auto device = std::unique_ptr(MockDevice::create(nullptr, exeEnv, 0u)); + executionEnvironment->sourceLevelDebugger.reset(gmock); + auto device = std::unique_ptr(MockDevice::create(nullptr, executionEnvironment, 0u)); EXPECT_CALL(*gmock, notifyDeviceDestruction()).Times(1); } TEST(DeviceWithSourceLevelDebugger, givenDeviceWithSourceLevelDebuggerActiveWhenDeviceIsCreatedThenPreemptionIsDisabled) { - auto exeEnv = new ExecutionEnvironment; - exeEnv->sourceLevelDebugger.reset(new MockActiveSourceLevelDebugger(new MockOsLibrary)); - auto device = std::unique_ptr(MockDevice::create(nullptr, exeEnv, 0u)); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); + executionEnvironment->sourceLevelDebugger.reset(new MockActiveSourceLevelDebugger(new MockOsLibrary)); + auto device = std::unique_ptr(MockDevice::create(nullptr, executionEnvironment, 0u)); EXPECT_EQ(PreemptionMode::Disabled, device->getPreemptionMode()); } diff --git a/unit_tests/source_level_debugger/source_level_debugger_tests.cpp b/unit_tests/source_level_debugger/source_level_debugger_tests.cpp index 4505b0f85f..9ee11f20c4 100644 --- a/unit_tests/source_level_debugger/source_level_debugger_tests.cpp +++ b/unit_tests/source_level_debugger/source_level_debugger_tests.cpp @@ -528,15 +528,14 @@ TEST(SourceLevelDebugger, givenTwoDevicesWhenSecondIsCreatedThenNotCreatingNewSo DebuggerLibrary::setDebuggerActive(true); DebuggerLibrary::injectDebuggerLibraryInterceptor(&interceptor); - std::unique_ptr executionEnvironment(new ExecutionEnvironment); - executionEnvironment->incRefInternal(); + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); - std::unique_ptr device1(Device::create(nullptr, executionEnvironment.get(), 0u)); + std::unique_ptr device1(Device::create(nullptr, executionEnvironment, 0u)); EXPECT_NE(nullptr, executionEnvironment->memoryManager); EXPECT_TRUE(interceptor.initCalled); interceptor.initCalled = false; - std::unique_ptr device2(Device::create(nullptr, executionEnvironment.get(), 1u)); + std::unique_ptr device2(Device::create(nullptr, executionEnvironment, 1u)); EXPECT_NE(nullptr, executionEnvironment->memoryManager); EXPECT_FALSE(interceptor.initCalled); } @@ -549,7 +548,7 @@ TEST(SourceLevelDebugger, givenMultipleDevicesWhenTheyAreCreatedTheyAllReuseTheS DebuggerLibrary::setLibraryAvailable(true); DebuggerLibrary::setDebuggerActive(true); - auto executionEnvironment = new ExecutionEnvironment; + ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment(); std::unique_ptr device1(Device::create(nullptr, executionEnvironment, 0u)); auto sourceLevelDebugger = device1->getSourceLevelDebugger(); std::unique_ptr device2(Device::create(nullptr, executionEnvironment, 1u)); diff --git a/unit_tests/ult_config_listener.cpp b/unit_tests/ult_config_listener.cpp index 5555305f53..a6aece9b16 100644 --- a/unit_tests/ult_config_listener.cpp +++ b/unit_tests/ult_config_listener.cpp @@ -12,8 +12,9 @@ #include "runtime/platform/platform.h" void OCLRT::UltConfigListener::OnTestStart(const ::testing::TestInfo &testInfo) { + constructPlatform()->peekExecutionEnvironment()->setHwInfo(*platformDevices); // Create platform and initialize gmm that dont want to create Platform and test gmm initialization path - constructPlatform()->peekExecutionEnvironment()->initGmm(*platformDevices); + platform()->peekExecutionEnvironment()->initGmm(); } void OCLRT::UltConfigListener::OnTestEnd(const ::testing::TestInfo &testInfo) { // Clear global platform that it shouldn't be reused between tests