From 5318ff18723155618e6c2246a35fec34fbc0088f Mon Sep 17 00:00:00 2001 From: Maciej Dziuban Date: Thu, 15 Apr 2021 16:14:04 +0000 Subject: [PATCH] Defer OsContext initialization Signed-off-by: Maciej Dziuban Related-To: NEO-5610 --- level_zero/core/source/device/device_imp.cpp | 1 + .../sources/cmdqueue/test_cmdqueue.cpp | 18 ++++ .../source/command_queue/command_queue_hw.h | 5 + .../command_queue/command_queue_tests.cpp | 45 ++++++++- .../command_stream_receiver_hw_2_tests.cpp | 25 +++++ .../command_stream_receiver_tests.cpp | 13 +++ opencl/test/unit_test/device/device_tests.cpp | 26 +++++ .../linux/drm_buffer_object_tests.cpp | 1 + .../linux/drm_command_stream_fixture.h | 1 + .../linux/drm_command_stream_tests.cpp | 2 + .../linux/drm_memory_manager_tests.h | 7 ++ .../os_interface/linux/drm_tests.cpp | 22 +++++ .../os_interface/os_context_tests.cpp | 99 +++++++++++++++++++ .../windows/device_command_stream_tests.cpp | 12 +-- .../windows/os_context_win_tests.cpp | 17 ++-- .../windows/os_interface_win_tests.cpp | 1 + .../os_interface/windows/wddm23_tests.cpp | 1 + .../os_interface/windows/wddm_fixture.h | 2 + .../windows/wddm_memory_manager_tests.cpp | 9 +- .../windows/wddm_memory_manager_tests.h | 1 + .../wddm_residency_controller_tests.cpp | 2 + .../test/unit_test/test_files/igdrcl.config | 1 + .../command_stream_receiver_hw_base.inl | 2 + .../debug_settings/debug_variables_base.inl | 1 + shared/source/device/device.cpp | 14 ++- .../os_interface/linux/os_context_linux.cpp | 10 +- .../os_interface/linux/os_context_linux.h | 2 + shared/source/os_interface/os_context.cpp | 35 ++++++- shared/source/os_interface/os_context.h | 20 ++-- .../os_interface/windows/os_context_win.cpp | 11 ++- .../os_interface/windows/os_context_win.h | 2 + shared/test/common/mocks/mock_device.cpp | 1 + .../linux/drm_direct_submission_tests.cpp | 1 + .../windows/wddm_direct_submission_tests.cpp | 1 + .../windows/wddm_preemption_tests.cpp | 1 + 35 files changed, 366 insertions(+), 46 deletions(-) diff --git a/level_zero/core/source/device/device_imp.cpp b/level_zero/core/source/device/device_imp.cpp index 5f0dbb1627..a9645bbe43 100644 --- a/level_zero/core/source/device/device_imp.cpp +++ b/level_zero/core/source/device/device_imp.cpp @@ -130,6 +130,7 @@ ze_result_t DeviceImp::createCommandQueue(const ze_command_queue_desc_t *desc, bool isCopyOnly = hwHelper.isCopyOnlyEngineType(static_cast(engineGroupIndex)); *commandQueue = CommandQueue::create(platform.eProductFamily, this, csr, desc, isCopyOnly, false, returnValue); + csr->getOsContext().ensureContextInitialized(); return returnValue; } diff --git a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp index 3cddfd9a86..3b74222fef 100644 --- a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp @@ -636,6 +636,24 @@ TEST_F(DeviceCreateCommandQueueTest, givenLowPriorityDescWhenCreateCommandQueueI commandQueue->destroy(); } +TEST_F(DeviceCreateCommandQueueTest, givenLowPriorityEngineNotInitializedWhenCreateLowPriorityCommandQueueIsCalledThenEngineIsInitialized) { + NEO::CommandStreamReceiver *lowPriorityCsr = nullptr; + device->getCsrForLowPriority(&lowPriorityCsr); + ASSERT_FALSE(lowPriorityCsr->getOsContext().isInitialized()); + + ze_command_queue_desc_t desc{}; + desc.ordinal = 0u; + desc.index = 0u; + desc.priority = ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_LOW; + ze_command_queue_handle_t commandQueueHandle = {}; + ze_result_t res = device->createCommandQueue(&desc, &commandQueueHandle); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + EXPECT_TRUE(lowPriorityCsr->getOsContext().isInitialized()); + + auto commandQueue = static_cast(L0::CommandQueue::fromHandle(commandQueueHandle)); + commandQueue->destroy(); +} + TEST_F(DeviceCreateCommandQueueTest, givenNormalPriorityDescWhenCreateCommandQueueIsCalledWithValidArgumentThenCsrIsAssignedWithOrdinalAndIndex) { ze_command_queue_desc_t desc{}; desc.ordinal = 0u; diff --git a/opencl/source/command_queue/command_queue_hw.h b/opencl/source/command_queue/command_queue_hw.h index 703c7637f2..41c00e8fe7 100644 --- a/opencl/source/command_queue/command_queue_hw.h +++ b/opencl/source/command_queue/command_queue_hw.h @@ -79,6 +79,11 @@ class CommandQueueHw : public CommandQueue { if (requestedSliceCount > 0) { sliceCount = requestedSliceCount; } + + gpgpuEngine->osContext->ensureContextInitialized(); + if (bcsEngine) { + bcsEngine->osContext->ensureContextInitialized(); + } } static CommandQueue *create(Context *context, diff --git a/opencl/test/unit_test/command_queue/command_queue_tests.cpp b/opencl/test/unit_test/command_queue/command_queue_tests.cpp index 317b328ef8..31eccfef4d 100644 --- a/opencl/test/unit_test/command_queue/command_queue_tests.cpp +++ b/opencl/test/unit_test/command_queue/command_queue_tests.cpp @@ -1509,17 +1509,21 @@ struct CommandQueueOnSpecificEngineTests : ::testing::Test { properties[4] = 0; } - template + template class MockHwHelper : public HwHelperHw { public: const HwHelper::EngineInstancesContainer getGpgpuEngineInstances(const HardwareInfo &hwInfo) const override { HwHelper::EngineInstancesContainer result{}; + for (int i = 0; i < rcsCount; i++) { + result.push_back({aub_stream::ENGINE_RCS, EngineUsage::Regular}); + } for (int i = 0; i < ccsCount; i++) { result.push_back({aub_stream::ENGINE_CCS, EngineUsage::Regular}); } for (int i = 0; i < bcsCount; i++) { result.push_back({aub_stream::ENGINE_BCS, EngineUsage::Regular}); } + return result; } @@ -1544,7 +1548,7 @@ struct CommandQueueOnSpecificEngineTests : ::testing::Test { }; HWTEST_F(CommandQueueOnSpecificEngineTests, givenMultipleFamiliesWhenCreatingQueueOnSpecificEngineThenUseCorrectEngine) { - auto raiiHwHelper = overrideHwHelper>(); + auto raiiHwHelper = overrideHwHelper>(); MockContext context{}; cl_command_queue_properties properties[5] = {}; @@ -1569,7 +1573,7 @@ HWTEST_F(CommandQueueOnSpecificEngineTests, givenMultipleFamiliesWhenCreatingQue } HWTEST_F(CommandQueueOnSpecificEngineTests, givenRootDeviceAndMultipleFamiliesWhenCreatingQueueOnSpecificEngineThenUseDefaultEngine) { - auto raiiHwHelper = overrideHwHelper>(); + auto raiiHwHelper = overrideHwHelper>(); UltClDeviceFactory deviceFactory{1, 2}; MockContext context{deviceFactory.rootDevices[0]}; cl_command_queue_properties properties[5] = {}; @@ -1585,7 +1589,7 @@ HWTEST_F(CommandQueueOnSpecificEngineTests, givenRootDeviceAndMultipleFamiliesWh } HWTEST_F(CommandQueueOnSpecificEngineTests, givenSubDeviceAndMultipleFamiliesWhenCreatingQueueOnSpecificEngineThenUseDefaultEngine) { - auto raiiHwHelper = overrideHwHelper>(); + auto raiiHwHelper = overrideHwHelper>(); UltClDeviceFactory deviceFactory{1, 2}; MockContext context{deviceFactory.subDevices[0]}; cl_command_queue_properties properties[5] = {}; @@ -1611,7 +1615,7 @@ HWTEST_F(CommandQueueOnSpecificEngineTests, givenSubDeviceAndMultipleFamiliesWhe } HWTEST_F(CommandQueueOnSpecificEngineTests, givenBcsFamilySelectedWhenCreatingQueueOnSpecificEngineThenInitializeBcsProperly) { - auto raiiHwHelper = overrideHwHelper>(); + auto raiiHwHelper = overrideHwHelper>(); MockContext context{}; cl_command_queue_properties properties[5] = {}; @@ -1625,3 +1629,34 @@ HWTEST_F(CommandQueueOnSpecificEngineTests, givenBcsFamilySelectedWhenCreatingQu EXPECT_EQ(properties[1], queueBcs.getQueueFamilyIndex()); EXPECT_EQ(properties[3], queueBcs.getQueueIndexWithinFamily()); } + +HWTEST_F(CommandQueueOnSpecificEngineTests, givenNotInitializedCcsOsContextWhenCreatingQueueThenInitializeOsContext) { + DebugManagerStateRestore restore{}; + DebugManager.flags.NodeOrdinal.set(static_cast(aub_stream::EngineType::ENGINE_RCS)); + + auto raiiHwHelper = overrideHwHelper>(); + MockContext context{}; + cl_command_queue_properties properties[5] = {}; + + OsContext &osContext = *context.getDevice(0)->getEngine(aub_stream::ENGINE_CCS, EngineUsage::Regular).osContext; + EXPECT_FALSE(osContext.isInitialized()); + + fillProperties(properties, 1, 0); + MockCommandQueueHw queue(&context, context.getDevice(0), properties); + ASSERT_EQ(&osContext, queue.gpgpuEngine->osContext); + EXPECT_TRUE(osContext.isInitialized()); +} + +HWTEST_F(CommandQueueOnSpecificEngineTests, givenNotInitializedBcsOsContextWhenCreatingQueueThenInitializeOsContext) { + auto raiiHwHelper = overrideHwHelper>(); + MockContext context{}; + cl_command_queue_properties properties[5] = {}; + + OsContext &osContext = *context.getDevice(0)->getEngine(aub_stream::ENGINE_BCS, EngineUsage::Regular).osContext; + EXPECT_FALSE(osContext.isInitialized()); + + fillProperties(properties, 2, 0); + MockCommandQueueHw queue(&context, context.getDevice(0), properties); + ASSERT_EQ(&osContext, queue.bcsEngine->osContext); + EXPECT_TRUE(osContext.isInitialized()); +} diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp index 654d0ed4c0..e362f6e089 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp @@ -358,6 +358,31 @@ HWTEST_F(BcsTests, givenProfilingEnabledWhenBlitBufferThenCommandBufferIsConstru ASSERT_NE(cmdList.end(), cmdIterator); } +HWTEST_F(BcsTests, givenNotInitializedOsContextWhenBlitBufferIsCalledThenInitializeContext) { + auto bcsOsContext = std::unique_ptr(OsContext::create(nullptr, 0, pDevice->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_BCS, EngineUsage::Regular}, PreemptionMode::Disabled, false)); + auto bcsCsr = std::make_unique>(*pDevice->getExecutionEnvironment(), pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield()); + bcsCsr->setupContext(*bcsOsContext); + bcsCsr->initializeTagAllocation(); + + cl_int retVal = CL_SUCCESS; + auto buffer = clUniquePtr(Buffer::create(context.get(), CL_MEM_READ_WRITE, 1, nullptr, retVal)); + void *hostPtr = reinterpret_cast(0x12340000); + auto graphicsAllocation = buffer->getGraphicsAllocation(pDevice->getRootDeviceIndex()); + auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::HostPtrToBuffer, + *bcsCsr, graphicsAllocation, nullptr, hostPtr, + graphicsAllocation->getGpuAddress(), 0, + 0, 0, {1, 1, 1}, 0, 0, 0, 0); + + MockTimestampPacketContainer timestamp(*bcsCsr->getTimestampPacketAllocator(), 1u); + blitProperties.outputTimestampPacket = timestamp.getNode(0); + BlitPropertiesContainer blitPropertiesContainer; + blitPropertiesContainer.push_back(blitProperties); + + EXPECT_FALSE(bcsOsContext->isInitialized()); + bcsCsr->blitBuffer(blitPropertiesContainer, false, true); + EXPECT_TRUE(bcsOsContext->isInitialized()); +} + HWTEST_F(BcsTests, givenInputAllocationsWhenBlitDispatchedThenMakeAllAllocationsResident) { auto &csr = pDevice->getUltCommandStreamReceiver(); csr.storeMakeResidentAllocations = true; diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp index f071802b4b..d52db8de29 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp @@ -383,6 +383,7 @@ HWTEST_F(InitDirectSubmissionTest, whenDirectSubmissionEnabledOnRcsThenExpectFea std::unique_ptr osContext(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, false)); + osContext->ensureContextInitialized(); osContext->setDefaultContext(true); auto hwInfo = device->getRootDeviceEnvironment().getMutableHardwareInfo(); hwInfo->capabilityTable.directSubmissionEngines.data[aub_stream::ENGINE_RCS].engineSupported = true; @@ -401,6 +402,7 @@ HWTEST_F(InitDirectSubmissionTest, givenDirectSubmissionEnabledWhenPlatformNotSu std::unique_ptr osContext(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, false)); + osContext->ensureContextInitialized(); osContext->setDefaultContext(true); auto hwInfo = device->getRootDeviceEnvironment().getMutableHardwareInfo(); hwInfo->capabilityTable.directSubmissionEngines.data[aub_stream::ENGINE_RCS].engineSupported = false; @@ -418,6 +420,7 @@ HWTEST_F(InitDirectSubmissionTest, whenDirectSubmissionEnabledOnBcsThenExpectFea std::unique_ptr osContext(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_BCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, false)); + osContext->ensureContextInitialized(); osContext->setDefaultContext(true); auto hwInfo = device->getRootDeviceEnvironment().getMutableHardwareInfo(); @@ -437,6 +440,7 @@ HWTEST_F(InitDirectSubmissionTest, givenDirectSubmissionEnabledWhenPlatformNotSu std::unique_ptr osContext(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_BCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, false)); + osContext->ensureContextInitialized(); osContext->setDefaultContext(true); auto hwInfo = device->getRootDeviceEnvironment().getMutableHardwareInfo(); @@ -456,6 +460,7 @@ HWTEST_F(InitDirectSubmissionTest, givenLowPriorityContextWhenDirectSubmissionDi std::unique_ptr osContext(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::LowPriority}, PreemptionMode::ThreadGroup, false)); + osContext->ensureContextInitialized(); osContext->setDefaultContext(true); auto hwInfo = device->getRootDeviceEnvironment().getMutableHardwareInfo(); @@ -475,6 +480,7 @@ HWTEST_F(InitDirectSubmissionTest, givenLowPriorityContextWhenDirectSubmissionEn std::unique_ptr osContext(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::LowPriority}, PreemptionMode::ThreadGroup, false)); + osContext->ensureContextInitialized(); auto hwInfo = device->getRootDeviceEnvironment().getMutableHardwareInfo(); hwInfo->capabilityTable.directSubmissionEngines.data[aub_stream::ENGINE_RCS].engineSupported = true; @@ -492,6 +498,7 @@ HWTEST_F(InitDirectSubmissionTest, givenInternalContextWhenDirectSubmissionDisab std::unique_ptr osContext(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Internal}, PreemptionMode::ThreadGroup, false)); + osContext->ensureContextInitialized(); osContext->setDefaultContext(true); auto hwInfo = device->getRootDeviceEnvironment().getMutableHardwareInfo(); @@ -511,6 +518,7 @@ HWTEST_F(InitDirectSubmissionTest, givenInternalContextWhenDirectSubmissionEnabl std::unique_ptr osContext(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Internal}, PreemptionMode::ThreadGroup, false)); + osContext->ensureContextInitialized(); auto hwInfo = device->getRootDeviceEnvironment().getMutableHardwareInfo(); hwInfo->capabilityTable.directSubmissionEngines.data[aub_stream::ENGINE_RCS].engineSupported = true; @@ -529,6 +537,7 @@ HWTEST_F(InitDirectSubmissionTest, givenRootDeviceContextWhenDirectSubmissionDis std::unique_ptr osContext(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, true)); + osContext->ensureContextInitialized(); osContext->setDefaultContext(true); auto hwInfo = device->getRootDeviceEnvironment().getMutableHardwareInfo(); @@ -548,6 +557,7 @@ HWTEST_F(InitDirectSubmissionTest, givenRootDeviceContextWhenDirectSubmissionEna std::unique_ptr osContext(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, true)); + osContext->ensureContextInitialized(); auto hwInfo = device->getRootDeviceEnvironment().getMutableHardwareInfo(); hwInfo->capabilityTable.directSubmissionEngines.data[aub_stream::ENGINE_RCS].engineSupported = true; @@ -566,6 +576,7 @@ HWTEST_F(InitDirectSubmissionTest, givenNonDefaultContextWhenDirectSubmissionDis std::unique_ptr osContext(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, false)); + osContext->ensureContextInitialized(); osContext->setDefaultContext(false); auto hwInfo = device->getRootDeviceEnvironment().getMutableHardwareInfo(); @@ -585,6 +596,7 @@ HWTEST_F(InitDirectSubmissionTest, givenNonDefaultContextContextWhenDirectSubmis std::unique_ptr osContext(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, false)); + osContext->ensureContextInitialized(); osContext->setDefaultContext(false); auto hwInfo = device->getRootDeviceEnvironment().getMutableHardwareInfo(); @@ -606,6 +618,7 @@ HWTEST_F(InitDirectSubmissionTest, GivenBlitterOverrideEnabledWhenBlitterIsNonDe std::unique_ptr osContext(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_BCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, false)); + osContext->ensureContextInitialized(); osContext->setDefaultContext(false); auto hwInfo = device->getRootDeviceEnvironment().getMutableHardwareInfo(); diff --git a/opencl/test/unit_test/device/device_tests.cpp b/opencl/test/unit_test/device/device_tests.cpp index f9630855ad..7d34340910 100644 --- a/opencl/test/unit_test/device/device_tests.cpp +++ b/opencl/test/unit_test/device/device_tests.cpp @@ -573,6 +573,32 @@ TEST(DeviceGenEngineTest, givenEmptyGroupsWhenGettingNonEmptyGroupIndexThenRetur EXPECT_ANY_THROW(device->getIndexOfNonEmptyEngineGroup(static_cast(5u))); } +TEST(DeviceGenEngineTest, givenDeferredContextInitializationEnabledWhenCreatingEnginesThenInitializeOnlyOsContextsWhichRequireIt) { + DebugManagerStateRestore restore{}; + DebugManager.flags.DeferOsContextInitialization.set(1); + + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + const auto defaultEngineType = getChosenEngineType(device->getHardwareInfo()); + EXPECT_NE(0u, device->getEngines().size()); + for (const EngineControl &engine : device->getEngines()) { + OsContext *osContext = engine.osContext; + const bool isDefaultEngine = defaultEngineType == osContext->getEngineType() && osContext->isRegular(); + const bool shouldBeInitialized = osContext->isImmediateContextInitializationEnabled(isDefaultEngine); + EXPECT_EQ(shouldBeInitialized, osContext->isInitialized()); + } +} + +TEST(DeviceGenEngineTest, givenDeferredContextInitializationDisabledWhenCreatingEnginesThenInitializeAllOsContexts) { + DebugManagerStateRestore restore{}; + DebugManager.flags.DeferOsContextInitialization.set(0); + + auto device = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); + EXPECT_NE(0u, device->getEngines().size()); + for (const EngineControl &engine : device->getEngines()) { + EXPECT_TRUE(engine.osContext->isInitialized()); + } +} + using DeviceQueueFamiliesTests = ::testing::Test; HWTEST_F(DeviceQueueFamiliesTests, whenGettingQueueFamilyCapabilitiesAllThenReturnCorrectValue) { diff --git a/opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp index 13721a53d2..d0a036a5af 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp @@ -403,6 +403,7 @@ TEST(DrmBufferObject, givenPerContextVmRequiredWhenBoBoundAndUnboundThenCorrectB auto contextId = device->getExecutionEnvironment()->memoryManager->getRegisteredEnginesCount() / 2; auto osContext = device->getExecutionEnvironment()->memoryManager->getRegisteredEngines()[contextId].osContext; + osContext->ensureContextInitialized(); bo.bind(osContext, 0); EXPECT_TRUE(bo.bindInfo[contextId][0]); diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h b/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h index b80b5110cb..37133d7634 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_fixture.h @@ -42,6 +42,7 @@ class DrmCommandStreamTest : public ::testing::Test { osContext = std::make_unique(*mock, 0u, 1, HwHelper::get(hwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0], PreemptionHelper::getDefaultPreemptionMode(*hwInfo), false); + osContext->ensureContextInitialized(); csr = new DrmCommandStreamReceiver(executionEnvironment, 0, 1, gemCloseWorkerMode::gemCloseWorkerActive); ASSERT_NE(nullptr, csr); diff --git a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp index 834191d35a..acd680936b 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp @@ -235,6 +235,7 @@ HWTEST_TEMPLATED_F(DrmCommandStreamTest, givenDrmContextIdWhenFlushingThenSetIdT HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*defaultHwInfo)[0], PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo), false); + osContext->ensureContextInitialized(); csr->setupContext(*osContext); auto &cs = csr->getCS(); @@ -1340,6 +1341,7 @@ struct DrmCommandStreamBlitterDirectSubmissionTest : public DrmCommandStreamDire osContext.reset(OsContext::create(device->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 0, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_BCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, false)); + osContext->ensureContextInitialized(); csr->initDirectSubmission(*device.get(), *osContext.get()); } diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h index d9758a3d8d..098859dfda 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.h @@ -8,6 +8,7 @@ #pragma once #include "shared/source/os_interface/linux/drm_memory_operations_handler.h" #include "shared/source/os_interface/linux/os_interface.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/mocks/linux/mock_drm_memory_manager.h" #include "shared/test/common/mocks/mock_device.h" @@ -54,6 +55,8 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture { } void SetUp(DrmMockCustom *mock, bool localMemoryEnabled) { + DebugManager.flags.DeferOsContextInitialization.set(0); + environmentWrapper.setCsrType>(); allocationData.rootDeviceIndex = rootDeviceIndex; this->mock = mock; @@ -113,6 +116,7 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture { AllocationData allocationData{}; DrmMockCustom::Ioctls additionalDestroyDeviceIoctls{}; EnvironmentWithCsrWrapper environmentWrapper; + DebugManagerStateRestore restore; }; class DrmMemoryManagerWithLocalMemoryFixture : public DrmMemoryManagerFixture { @@ -132,6 +136,8 @@ class DrmMemoryManagerFixtureWithoutQuietIoctlExpectation { DrmMockCustom *mock; void SetUp() { + DebugManager.flags.DeferOsContextInitialization.set(0); + executionEnvironment = new ExecutionEnvironment; executionEnvironment->prepareRootDeviceEnvironments(numRootDevices); uint32_t i = 0; @@ -159,6 +165,7 @@ class DrmMemoryManagerFixtureWithoutQuietIoctlExpectation { ExecutionEnvironment *executionEnvironment = nullptr; std::unique_ptr device; DrmMockCustom::IoctlResExt ioctlResExt = {0, 0}; + DebugManagerStateRestore restore; const uint32_t rootDeviceIndex = 1u; const uint32_t numRootDevices = 2u; }; diff --git a/opencl/test/unit_test/os_interface/linux/drm_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_tests.cpp index 2c3b713212..f51db5270f 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_tests.cpp @@ -140,6 +140,7 @@ TEST(DrmTest, givenDrmWhenOsContextIsCreatedThenCreateAndDestroyNewDrmOsContext) { OsContextLinux osContext1(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext1.ensureContextInitialized(); EXPECT_EQ(1u, osContext1.getDrmContextIds().size()); EXPECT_EQ(drmMock.receivedCreateContextId, osContext1.getDrmContextIds()[0]); @@ -147,6 +148,7 @@ TEST(DrmTest, givenDrmWhenOsContextIsCreatedThenCreateAndDestroyNewDrmOsContext) { OsContextLinux osContext2(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext2.ensureContextInitialized(); EXPECT_EQ(1u, osContext2.getDrmContextIds().size()); EXPECT_EQ(drmMock.receivedCreateContextId, osContext2.getDrmContextIds()[0]); EXPECT_EQ(0u, drmMock.receivedDestroyContextId); @@ -165,6 +167,7 @@ TEST(DrmTest, whenCreatingDrmContextWithVirtualMemoryAddressSpaceThenProperVmIdI ASSERT_EQ(1u, drmMock.virtualMemoryIds.size()); OsContextLinux osContext(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext.ensureContextInitialized(); EXPECT_EQ(drmMock.receivedContextParamRequest.value, drmMock.getVirtualMemoryAddressSpace(0u)); } @@ -179,6 +182,7 @@ TEST(DrmTest, whenCreatingDrmContextWithNoVirtualMemoryAddressSpaceThenProperCon ASSERT_EQ(0u, drmMock.virtualMemoryIds.size()); OsContextLinux osContext(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext.ensureContextInitialized(); EXPECT_EQ(0u, drmMock.receivedCreateContextId); EXPECT_EQ(0u, drmMock.receivedContextParamRequestCount); @@ -196,6 +200,7 @@ TEST(DrmTest, givenDrmAndNegativeCheckNonPersistentContextsSupportWhenOsContextI drmMock.checkNonPersistentContextsSupport(); expectedCount += 2; OsContextLinux osContext(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext.ensureContextInitialized(); EXPECT_EQ(expectedCount, drmMock.receivedContextParamRequestCount); } { @@ -203,6 +208,7 @@ TEST(DrmTest, givenDrmAndNegativeCheckNonPersistentContextsSupportWhenOsContextI drmMock.checkNonPersistentContextsSupport(); ++expectedCount; OsContextLinux osContext(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext.ensureContextInitialized(); expectedCount += 2; EXPECT_EQ(expectedCount, drmMock.receivedContextParamRequestCount); } @@ -216,16 +222,20 @@ TEST(DrmTest, givenDrmPreemptionEnabledAndLowPriorityEngineWhenCreatingOsContext drmMock.preemptionSupported = false; OsContextLinux osContext1(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext1.ensureContextInitialized(); OsContextLinux osContext2(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::LowPriority}, PreemptionMode::Disabled, false); + osContext2.ensureContextInitialized(); EXPECT_EQ(2u, drmMock.receivedContextParamRequestCount); drmMock.preemptionSupported = true; OsContextLinux osContext3(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext3.ensureContextInitialized(); EXPECT_EQ(3u, drmMock.receivedContextParamRequestCount); OsContextLinux osContext4(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::LowPriority}, PreemptionMode::Disabled, false); + osContext4.ensureContextInitialized(); EXPECT_EQ(5u, drmMock.receivedContextParamRequestCount); EXPECT_EQ(drmMock.receivedCreateContextId, drmMock.receivedContextParamRequest.ctx_id); EXPECT_EQ(static_cast(I915_CONTEXT_PARAM_PRIORITY), drmMock.receivedContextParamRequest.param); @@ -240,6 +250,7 @@ TEST(DrmTest, givenDirectSubmissionEnabledOnBlitterWhenCreateBcsEngineThenLowPri DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]); OsContextLinux osContext(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_BCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext.ensureContextInitialized(); EXPECT_EQ(1u, drmMock.receivedContextParamRequestCount); DebugManagerStateRestore restorer; @@ -247,6 +258,7 @@ TEST(DrmTest, givenDirectSubmissionEnabledOnBlitterWhenCreateBcsEngineThenLowPri DebugManager.flags.DirectSubmissionOverrideBlitterSupport.set(1); OsContextLinux osContext2(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_BCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext2.ensureContextInitialized(); EXPECT_EQ(3u, drmMock.receivedContextParamRequestCount); EXPECT_EQ(drmMock.receivedCreateContextId, drmMock.receivedContextParamRequest.ctx_id); EXPECT_EQ(static_cast(I915_CONTEXT_PARAM_PRIORITY), drmMock.receivedContextParamRequest.param); @@ -254,6 +266,7 @@ TEST(DrmTest, givenDirectSubmissionEnabledOnBlitterWhenCreateBcsEngineThenLowPri EXPECT_EQ(0u, drmMock.receivedContextParamRequest.size); OsContextLinux osContext3(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext3.ensureContextInitialized(); EXPECT_EQ(4u, drmMock.receivedContextParamRequestCount); } @@ -264,6 +277,7 @@ TEST(DrmTest, givenDirectSubmissionEnabledOnBlitterAndDirectSubmissionLowPriorit DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]); OsContextLinux osContext(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_BCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext.ensureContextInitialized(); EXPECT_EQ(1u, drmMock.receivedContextParamRequestCount); DebugManagerStateRestore restorer; @@ -272,6 +286,7 @@ TEST(DrmTest, givenDirectSubmissionEnabledOnBlitterAndDirectSubmissionLowPriorit DebugManager.flags.DirectSubmissionLowPriorityBlitter.set(0); OsContextLinux osContext2(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_BCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext2.ensureContextInitialized(); EXPECT_EQ(2u, drmMock.receivedContextParamRequestCount); } @@ -462,6 +477,7 @@ TEST(DrmTest, givenDrmWhenCreatingOsContextThenCreateDrmContextWithVmId) { executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get()); DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]); OsContextLinux osContext(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext.ensureContextInitialized(); EXPECT_EQ(SysCalls::vmId, drmMock.getVirtualMemoryAddressSpace(0)); @@ -477,9 +493,11 @@ TEST(DrmTest, givenDrmWithPerContextVMRequiredWhenCreatingOsContextsThenImplicit EXPECT_TRUE(drmMock.requirePerContextVM); OsContextLinux osContext1(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext1.ensureContextInitialized(); EXPECT_EQ(0u, drmMock.receivedCreateContextId); OsContextLinux osContext2(drmMock, 5u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext2.ensureContextInitialized(); EXPECT_EQ(0u, drmMock.receivedCreateContextId); } @@ -493,6 +511,7 @@ TEST(DrmTest, givenDrmWithPerContextVMRequiredWhenCreatingOsContextsThenImplicit drmMock.StoredRetValForVmId = 20; OsContextLinux osContext(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext.ensureContextInitialized(); EXPECT_EQ(0u, drmMock.receivedCreateContextId); EXPECT_EQ(1u, drmMock.receivedContextParamRequestCount); @@ -512,6 +531,7 @@ TEST(DrmTest, givenNoPerContextVmsDrmWhenCreatingOsContextsThenVmIdIsNotQueriedA drmMock.StoredRetValForVmId = 1; OsContextLinux osContext(drmMock, 0u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext.ensureContextInitialized(); EXPECT_EQ(0u, drmMock.receivedCreateContextId); EXPECT_EQ(1u, drmMock.receivedContextParamRequestCount); @@ -531,6 +551,7 @@ TEST(DrmTest, givenProgramDebuggingAndContextDebugAvailableWhenCreatingContextTh drmMock.contextDebugSupported = true; OsContextLinux osContext(drmMock, 5u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false); + osContext.ensureContextInitialized(); // drmMock returns ctxId == 0 EXPECT_EQ(0u, drmMock.passedContextDebugId); @@ -548,6 +569,7 @@ TEST(DrmTest, givenProgramDebuggingAndContextDebugAvailableWhenCreatingContextFo drmMock.contextDebugSupported = true; OsContextLinux osContext(drmMock, 5u, 1, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Internal}, PreemptionMode::Disabled, false); + osContext.ensureContextInitialized(); EXPECT_EQ(static_cast(-1), drmMock.passedContextDebugId); } diff --git a/opencl/test/unit_test/os_interface/os_context_tests.cpp b/opencl/test/unit_test/os_interface/os_context_tests.cpp index 0f6d7b6a82..228e98c00f 100644 --- a/opencl/test/unit_test/os_interface/os_context_tests.cpp +++ b/opencl/test/unit_test/os_interface/os_context_tests.cpp @@ -5,7 +5,11 @@ * */ +#include "shared/source/os_interface/device_factory.h" #include "shared/source/os_interface/os_context.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/mocks/mock_device.h" #include "gtest/gtest.h" @@ -42,3 +46,98 @@ TEST(OSContext, givenOsContextCreatedDefaultIsFalseWhenSettingTrueThenFlagTrueRe EXPECT_TRUE(osContext->isDefaultContext()); delete osContext; } + +struct DeferredOsContextCreationTests : ::testing::Test { + void SetUp() override { + device = std::unique_ptr{MockDevice::createWithNewExecutionEnvironment(defaultHwInfo.get())}; + DeviceFactory::prepareDeviceEnvironments(*device->getExecutionEnvironment()); + } + + void expectContextCreation(EngineTypeUsage engineTypeUsage, bool defaultEngine, bool expectedImmediate) { + OSInterface *osInterface = device->getRootDeviceEnvironment().osInterface.get(); + std::unique_ptr osContext{OsContext::create(osInterface, 0, 0, engineTypeUsage, PreemptionMode::Disabled, false)}; + EXPECT_FALSE(osContext->isInitialized()); + + const bool immediate = osContext->isImmediateContextInitializationEnabled(defaultEngine); + EXPECT_EQ(expectedImmediate, immediate); + if (immediate) { + osContext->ensureContextInitialized(); + EXPECT_TRUE(osContext->isInitialized()); + } + } + + void expectDeferredContextCreation(EngineTypeUsage engineTypeUsage, bool defaultEngine) { + expectContextCreation(engineTypeUsage, defaultEngine, false); + } + + void expectImmediateContextCreation(EngineTypeUsage engineTypeUsage, bool defaultEngine) { + expectContextCreation(engineTypeUsage, defaultEngine, true); + } + + std::unique_ptr device; + static inline const EngineTypeUsage engineTypeUsageRegular{aub_stream::ENGINE_RCS, EngineUsage::Regular}; + static inline const EngineTypeUsage engineTypeUsageInternal{aub_stream::ENGINE_RCS, EngineUsage::Internal}; +}; + +TEST_F(DeferredOsContextCreationTests, givenRegularEngineWhenCreatingOsContextThenOsContextIsInitializedDeferred) { + DebugManagerStateRestore restore{}; + + expectDeferredContextCreation(engineTypeUsageRegular, false); + + DebugManager.flags.DeferOsContextInitialization.set(1); + expectDeferredContextCreation(engineTypeUsageRegular, false); + + DebugManager.flags.DeferOsContextInitialization.set(0); + expectImmediateContextCreation(engineTypeUsageRegular, false); +} + +TEST_F(DeferredOsContextCreationTests, givenDefaultEngineWhenCreatingOsContextThenOsContextIsInitializedDeferred) { + DebugManagerStateRestore restore{}; + + expectImmediateContextCreation(engineTypeUsageRegular, true); + + DebugManager.flags.DeferOsContextInitialization.set(1); + expectImmediateContextCreation(engineTypeUsageRegular, true); + + DebugManager.flags.DeferOsContextInitialization.set(0); + expectImmediateContextCreation(engineTypeUsageRegular, true); +} + +TEST_F(DeferredOsContextCreationTests, givenRegularEngineWhenCreatingOsContextThenOsContextIsInitializedImmediately) { + DebugManagerStateRestore restore{}; + + expectImmediateContextCreation(engineTypeUsageInternal, false); + + DebugManager.flags.DeferOsContextInitialization.set(1); + expectImmediateContextCreation(engineTypeUsageInternal, false); + + DebugManager.flags.DeferOsContextInitialization.set(0); + expectImmediateContextCreation(engineTypeUsageInternal, false); +} + +TEST_F(DeferredOsContextCreationTests, givenEnsureContextInitializeCalledMultipleTimesWhenOsContextIsCreatedThenInitializeOnlyOnce) { + struct MyOsContext : OsContext { + MyOsContext(uint32_t contextId, + DeviceBitfield deviceBitfield, + EngineTypeUsage typeUsage, + PreemptionMode preemptionMode, + bool rootDevice) : OsContext(contextId, deviceBitfield, typeUsage, preemptionMode, rootDevice) {} + + void initializeContext() { + initializeContextCalled++; + } + + size_t initializeContextCalled = 0u; + }; + + MyOsContext osContext{0, 0, engineTypeUsageRegular, PreemptionMode::Disabled, false}; + EXPECT_FALSE(osContext.isInitialized()); + + osContext.ensureContextInitialized(); + EXPECT_TRUE(osContext.isInitialized()); + EXPECT_EQ(1u, osContext.initializeContextCalled); + + osContext.ensureContextInitialized(); + EXPECT_TRUE(osContext.isInitialized()); + EXPECT_EQ(1u, osContext.initializeContextCalled); +} diff --git a/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp b/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp index 1bf544005c..b8be2857ae 100644 --- a/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp @@ -56,7 +56,6 @@ using namespace ::testing; class WddmCommandStreamFixture { public: std::unique_ptr device; - std::unique_ptr osContext; DeviceCommandStreamReceiver *csr; MockWddmMemoryManager *memoryManager = nullptr; WddmMock *wddm = nullptr; @@ -72,14 +71,11 @@ class WddmCommandStreamFixture { executionEnvironment->memoryManager.reset(memoryManager); wddm = static_cast(executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->getWddm()); device.reset(MockDevice::create(executionEnvironment, 0u)); - osContext.reset(OsContext::create(executionEnvironment->rootDeviceEnvironments[0]->osInterface.get(), - 0, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, - false)); - osContext->setDefaultContext(true); - csr = new WddmCommandStreamReceiver(*executionEnvironment, 0, device->getDeviceBitfield()); - - device->resetCommandStreamReceiver(csr); ASSERT_NE(nullptr, device); + + csr = new WddmCommandStreamReceiver(*executionEnvironment, 0, device->getDeviceBitfield()); + device->resetCommandStreamReceiver(csr); + csr->getOsContext().ensureContextInitialized(); } virtual void TearDown() { diff --git a/opencl/test/unit_test/os_interface/windows/os_context_win_tests.cpp b/opencl/test/unit_test/os_interface/windows/os_context_win_tests.cpp index 875f6d06ca..862711f0ed 100644 --- a/opencl/test/unit_test/os_interface/windows/os_context_win_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/os_context_win_tests.cpp @@ -26,23 +26,26 @@ struct OsContextWinTest : public WddmTestWithMockGdiDll { }; TEST_F(OsContextWinTest, givenWddm20WhenCreatingOsContextThenOsContextIsInitialized) { - EXPECT_NO_THROW(osContext = std::make_unique(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false)); - EXPECT_NE(nullptr, osContext); + osContext = std::make_unique(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false); + EXPECT_NO_THROW(osContext->ensureContextInitialized()); } TEST_F(OsContextWinTest, givenWddm20WhenCreatingWddmContextFailThenOsContextCreationFails) { wddm->device = INVALID_HANDLE; - EXPECT_ANY_THROW(osContext = std::make_unique(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false)); + osContext = std::make_unique(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false); + EXPECT_ANY_THROW(osContext->ensureContextInitialized()); } TEST_F(OsContextWinTest, givenWddm20WhenCreatingWddmMonitorFenceFailThenOsContextCreationFails) { *getCreateSynchronizationObject2FailCallFcn() = true; - EXPECT_ANY_THROW(osContext = std::make_unique(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false)); + osContext = std::make_unique(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false); + EXPECT_ANY_THROW(osContext->ensureContextInitialized()); } TEST_F(OsContextWinTest, givenWddm20WhenRegisterTrimCallbackFailThenOsContextCreationFails) { *getRegisterTrimNotificationFailCallFcn() = true; - EXPECT_ANY_THROW(osContext = std::make_unique(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false)); + osContext = std::make_unique(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false); + EXPECT_ANY_THROW(osContext->ensureContextInitialized()); } TEST_F(OsContextWinTest, givenWddm20WhenRegisterTrimCallbackIsDisabledThenOsContextIsInitialized) { @@ -50,6 +53,6 @@ TEST_F(OsContextWinTest, givenWddm20WhenRegisterTrimCallbackIsDisabledThenOsCont DebugManager.flags.DoNotRegisterTrimCallback.set(true); *getRegisterTrimNotificationFailCallFcn() = true; - EXPECT_NO_THROW(osContext = std::make_unique(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false)); - EXPECT_NE(nullptr, osContext); + osContext = std::make_unique(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false); + EXPECT_NO_THROW(osContext->ensureContextInitialized()); } diff --git a/opencl/test/unit_test/os_interface/windows/os_interface_win_tests.cpp b/opencl/test/unit_test/os_interface/windows/os_interface_win_tests.cpp index 964733e901..89ba2f1dab 100644 --- a/opencl/test/unit_test/os_interface/windows/os_interface_win_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/os_interface_win_tests.cpp @@ -34,6 +34,7 @@ TEST(OsContextTest, givenWddmWhenCreateOsContextAfterInitWddmThenOsContextIsInit auto osContext = std::make_unique(*wddm, 0u, 1, HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*defaultHwInfo)[0], preemptionMode, false); + osContext->ensureContextInitialized(); EXPECT_EQ(osContext->getWddm(), wddm); EXPECT_EQ(1u, wddm->registerTrimCallbackResult.called); } diff --git a/opencl/test/unit_test/os_interface/windows/wddm23_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm23_tests.cpp index 8a44eb29f9..7683a81511 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm23_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm23_tests.cpp @@ -48,6 +48,7 @@ struct Wddm23TestsWithoutWddmInit : public ::testing::Test, GdiDllFixture { osContext = std::make_unique(*wddm, 0u, 1, HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*defaultHwInfo)[0], preemptionMode, false); + osContext->ensureContextInitialized(); } void TearDown() override { diff --git a/opencl/test/unit_test/os_interface/windows/wddm_fixture.h b/opencl/test/unit_test/os_interface/windows/wddm_fixture.h index 4773a648bd..375fb331aa 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_fixture.h +++ b/opencl/test/unit_test/os_interface/windows/wddm_fixture.h @@ -49,6 +49,7 @@ struct WddmFixture : public Test { auto engine = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0]; osContext = std::make_unique(*osInterface->get()->getWddm(), 0u, 1u, engine, preemptionMode, false); + osContext->ensureContextInitialized(); mockTemporaryResources = static_cast(wddm->temporaryResources.get()); } @@ -85,6 +86,7 @@ struct WddmFixtureWithMockGdiDll : public GdiDllFixture, public MockExecutionEnv auto engine = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0]; osContext = std::make_unique(*osInterface->get()->getWddm(), 0u, 1, engine, preemptionMode, false); + osContext->ensureContextInitialized(); } void TearDown() override { diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index 53d1dea252..10c7a1b530 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -386,13 +386,14 @@ TEST_F(WddmMemoryManagerSimpleTest, givenNonZeroFenceValuesOnMultipleEnginesRegi executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->memoryOperationsInterface = std::make_unique(wddm2); auto hwInfo = executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo(); - memoryManager->createAndRegisterOsContext(csr.get(), HwHelper::get(hwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[1], - deviceBitfield, PreemptionHelper::getDefaultPreemptionMode(*hwInfo), - false); + OsContext *osContext = memoryManager->createAndRegisterOsContext(csr.get(), HwHelper::get(hwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[1], + deviceBitfield, PreemptionHelper::getDefaultPreemptionMode(*hwInfo), + false); + osContext->ensureContextInitialized(); ASSERT_EQ(2u, memoryManager->getRegisteredEnginesCount()); auto allocation = static_cast(memoryManager->allocateGraphicsMemoryWithProperties({0u, 32, GraphicsAllocation::AllocationType::BUFFER, mockDeviceBitfield})); - auto lastEngineFence = &static_cast(memoryManager->getRegisteredEngines()[1].osContext)->getResidencyController().getMonitoredFence(); + auto lastEngineFence = &static_cast(osContext)->getResidencyController().getMonitoredFence(); allocation->getResidencyData().updateCompletionData(129u, 0u); allocation->getResidencyData().updateCompletionData(152u, 1u); diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h index bbb58f2178..ab0db1b1fa 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h @@ -70,6 +70,7 @@ class MockWddmMemoryManagerFixture { osContext = memoryManager->createAndRegisterOsContext(csr.get(), HwHelper::get(hwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0], 1, PreemptionHelper::getDefaultPreemptionMode(*hwInfo), false); + osContext->ensureContextInitialized(); osContext->incRefInternal(); mockTemporaryResources = reinterpret_cast(wddm->getTemporaryResourcesContainer()); diff --git a/opencl/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp index 1427168ff7..0452f22b7f 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp @@ -136,6 +136,7 @@ struct WddmResidencyControllerWithMockWddmTest : public WddmResidencyControllerT osContext = memoryManager->createAndRegisterOsContext(csr.get(), HwHelper::get(hwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0], 1, preemptionMode, false); + osContext->ensureContextInitialized(); osContext->incRefInternal(); residencyController = &static_cast(osContext)->getResidencyController(); @@ -173,6 +174,7 @@ struct WddmResidencyControllerWithGdiAndMemoryManagerTest : ::testing::Test { HwHelper::get(hwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0], 1, PreemptionHelper::getDefaultPreemptionMode(*hwInfo), false); + osContext->ensureContextInitialized(); osContext->incRefInternal(); diff --git a/opencl/test/unit_test/test_files/igdrcl.config b/opencl/test/unit_test/test_files/igdrcl.config index 37b757ca0f..e561e718f2 100644 --- a/opencl/test/unit_test/test_files/igdrcl.config +++ b/opencl/test/unit_test/test_files/igdrcl.config @@ -232,3 +232,4 @@ UseCyclesPerSecondTimer = 0 WaitLoopCount = -1 DebuggerLogBitmask = 0 GTPinAllocateBufferInSharedMemory = -1 +DeferOsContextInitialization = -1 diff --git a/shared/source/command_stream/command_stream_receiver_hw_base.inl b/shared/source/command_stream/command_stream_receiver_hw_base.inl index 082e4ce127..bac61eb833 100644 --- a/shared/source/command_stream/command_stream_receiver_hw_base.inl +++ b/shared/source/command_stream/command_stream_receiver_hw_base.inl @@ -1009,6 +1009,8 @@ uint32_t CommandStreamReceiverHw::blitBuffer(const BlitPropertiesCont auto newTaskCount = taskCount + 1; latestSentTaskCount = newTaskCount; + getOsContext().ensureContextInitialized(); + if (PauseOnGpuProperties::pauseModeAllowed(DebugManager.flags.PauseOnBlitCopy.get(), taskCount, PauseOnGpuProperties::PauseMode::BeforeWorkload)) { BlitCommandsHelper::dispatchDebugPauseCommands(commandStream, getDebugPauseStateGPUAddress(), DebugPauseState::waitingForUserStartConfirmation, DebugPauseState::hasUserStartConfirmation); } diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index dd28ef7f64..1df22f76e2 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -242,6 +242,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, UseVmBind, -1, "Use new residency model on Linux DECLARE_DEBUG_VARIABLE(int32_t, PassBoundBOToExec, -1, "Pass bound BOs to exec call to keep dependencies") DECLARE_DEBUG_VARIABLE(int32_t, EnableStaticPartitioning, -1, "Divide workload into partitions during dispatch, -1: default, 0: disabled, 1: enabled") DECLARE_DEBUG_VARIABLE(int32_t, UpdateTaskCountFromWait, -1, " Do not update task count after each enqueue, but send update request while wait, -1: default(disabled), 0: disabled, 1: enabled") +DECLARE_DEBUG_VARIABLE(int32_t, DeferOsContextInitialization, -1, "-1: default, 0: create all contexts immediately, 1: defer, if possible") DECLARE_DEBUG_VARIABLE(bool, UseMaxSimdSizeToDeduceMaxWorkgroupSize, false, "With this flag on, max workgroup size is deduced using SIMD32 instead of SIMD8, this causes the max wkg size to be 4 times bigger") DECLARE_DEBUG_VARIABLE(bool, ReturnRawGpuTimestamps, false, "Driver returns raw GPU tiemstamps instead of calculated ones.") DECLARE_DEBUG_VARIABLE(bool, ForcePerDssBackedBufferProgramming, false, "Always program per-DSS memory backed buffer in preamble") diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index 73cc793303..5c35be0ca2 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -150,16 +150,17 @@ std::unique_ptr Device::createCommandStreamReceiver() con } bool Device::createEngine(uint32_t deviceCsrIndex, EngineTypeUsage engineTypeUsage) { - auto &hwInfo = getHardwareInfo(); - auto defaultEngineType = getChosenEngineType(hwInfo); + const auto &hwInfo = getHardwareInfo(); + const auto engineType = engineTypeUsage.first; + const auto engineUsage = engineTypeUsage.second; + const auto defaultEngineType = getChosenEngineType(hwInfo); + const bool isDefaultEngine = defaultEngineType == engineType && engineUsage == EngineUsage::Regular; std::unique_ptr commandStreamReceiver = createCommandStreamReceiver(); if (!commandStreamReceiver) { return false; } - auto engineType = engineTypeUsage.first; - bool internalUsage = (engineTypeUsage.second == EngineUsage::Internal); if (internalUsage) { commandStreamReceiver->initializeDefaultsForInternalEngine(); @@ -175,6 +176,9 @@ bool Device::createEngine(uint32_t deviceCsrIndex, EngineTypeUsage engineTypeUsa getDeviceBitfield(), preemptionMode, false); + if (osContext->isImmediateContextInitializationEnabled(isDefaultEngine)) { + osContext->ensureContextInitialized(); + } commandStreamReceiver->setupContext(*osContext); if (!commandStreamReceiver->initializeTagAllocation()) { @@ -185,7 +189,7 @@ bool Device::createEngine(uint32_t deviceCsrIndex, EngineTypeUsage engineTypeUsa return false; } - if (engineType == defaultEngineType && !lowPriority && !internalUsage) { + if (isDefaultEngine) { defaultEngineIndex = deviceCsrIndex; } diff --git a/shared/source/os_interface/linux/os_context_linux.cpp b/shared/source/os_interface/linux/os_context_linux.cpp index 482d29647e..71d371f4e4 100644 --- a/shared/source/os_interface/linux/os_context_linux.cpp +++ b/shared/source/os_interface/linux/os_context_linux.cpp @@ -30,7 +30,9 @@ OsContext *OsContext::create(OSInterface *osInterface, uint32_t contextId, Devic OsContextLinux::OsContextLinux(Drm &drm, uint32_t contextId, DeviceBitfield deviceBitfield, EngineTypeUsage typeUsage, PreemptionMode preemptionMode, bool rootDevice) : OsContext(contextId, deviceBitfield, typeUsage, preemptionMode, rootDevice), - drm(drm) { + drm(drm) {} + +void OsContextLinux::initializeContext() { auto hwInfo = drm.getRootDeviceEnvironment().getHardwareInfo(); auto defaultEngineType = getChosenEngineType(*hwInfo); @@ -96,8 +98,10 @@ void OsContextLinux::waitForPagingFence() { } OsContextLinux::~OsContextLinux() { - for (auto drmContextId : drmContextIds) { - drm.destroyDrmContext(drmContextId); + if (contextInitialized) { + for (auto drmContextId : drmContextIds) { + drm.destroyDrmContext(drmContextId); + } } } } // namespace NEO diff --git a/shared/source/os_interface/linux/os_context_linux.h b/shared/source/os_interface/linux/os_context_linux.h index f269023c7c..8d2c4e5899 100644 --- a/shared/source/os_interface/linux/os_context_linux.h +++ b/shared/source/os_interface/linux/os_context_linux.h @@ -29,6 +29,8 @@ class OsContextLinux : public OsContext { void waitForPagingFence(); protected: + void initializeContext() override; + unsigned int engineFlag = 0; std::vector drmContextIds; std::vector drmVmIds; diff --git a/shared/source/os_interface/os_context.cpp b/shared/source/os_interface/os_context.cpp index b01f6b1276..b88c686107 100644 --- a/shared/source/os_interface/os_context.cpp +++ b/shared/source/os_interface/os_context.cpp @@ -13,6 +13,38 @@ #include "shared/source/helpers/hw_info.h" namespace NEO { +OsContext::OsContext(uint32_t contextId, DeviceBitfield deviceBitfield, EngineTypeUsage typeUsage, PreemptionMode preemptionMode, bool rootDevice) + : contextId(contextId), + deviceBitfield(deviceBitfield), + preemptionMode(preemptionMode), + numSupportedDevices(static_cast(deviceBitfield.count())), + engineType(typeUsage.first), + engineUsage(typeUsage.second), + rootDevice(rootDevice) {} + +bool OsContext::isImmediateContextInitializationEnabled(bool isDefaultEngine) const { + if (DebugManager.flags.DeferOsContextInitialization.get() == 0) { + return true; + } + + if (engineUsage == EngineUsage::Internal) { + return true; + } + + if (isDefaultEngine) { + return true; + } + + return false; +} + +void OsContext::ensureContextInitialized() { + std::call_once(contextInitializedFlag, [this] { + initializeContext(); + contextInitialized = true; + }); +} + bool OsContext::isDirectSubmissionAvailable(const HardwareInfo &hwInfo, bool &submitOnInit) { bool enableDirectSubmission = this->isDirectSubmissionSupported(hwInfo); @@ -85,4 +117,5 @@ bool OsContext::checkDirectSubmissionSupportsEngine(const DirectSubmissionProper return supported; } -} // namespace NEO \ No newline at end of file + +} // namespace NEO diff --git a/shared/source/os_interface/os_context.h b/shared/source/os_interface/os_context.h index 4a80cfc96d..9443cfcbe7 100644 --- a/shared/source/os_interface/os_context.h +++ b/shared/source/os_interface/os_context.h @@ -14,6 +14,7 @@ #include "engine_node.h" #include +#include namespace NEO { class OSInterface; @@ -24,14 +25,19 @@ struct HardwareInfo; class OsContext : public ReferenceTrackedObject { public: OsContext() = delete; - static OsContext *create(OSInterface *osInterface, uint32_t contextId, DeviceBitfield deviceBitfield, EngineTypeUsage typeUsage, PreemptionMode preemptionMode, bool rootDevice); + + bool isImmediateContextInitializationEnabled(bool isDefaultEngine) const; + bool isInitialized() const { return contextInitialized; } + void ensureContextInitialized(); + uint32_t getContextId() const { return contextId; } uint32_t getNumSupportedDevices() const { return numSupportedDevices; } DeviceBitfield getDeviceBitfield() const { return deviceBitfield; } PreemptionMode getPreemptionMode() const { return preemptionMode; } aub_stream::EngineType &getEngineType() { return engineType; } + bool isRegular() const { return engineUsage == EngineUsage::Regular; } bool isLowPriority() const { return engineUsage == EngineUsage::LowPriority; } bool isInternalEngine() const { return engineUsage == EngineUsage::Internal; } bool isRootDevice() const { return rootDevice; } @@ -48,14 +54,8 @@ class OsContext : public ReferenceTrackedObject { bool &startInContext); protected: - OsContext(uint32_t contextId, DeviceBitfield deviceBitfield, EngineTypeUsage typeUsage, PreemptionMode preemptionMode, bool rootDevice) - : contextId(contextId), - deviceBitfield(deviceBitfield), - preemptionMode(preemptionMode), - numSupportedDevices(static_cast(deviceBitfield.count())), - engineType(typeUsage.first), - engineUsage(typeUsage.second), - rootDevice(rootDevice) {} + OsContext(uint32_t contextId, DeviceBitfield deviceBitfield, EngineTypeUsage typeUsage, PreemptionMode preemptionMode, bool rootDevice); + virtual void initializeContext() {} const uint32_t contextId; const DeviceBitfield deviceBitfield; @@ -66,5 +66,7 @@ class OsContext : public ReferenceTrackedObject { const bool rootDevice = false; bool defaultContext = false; bool directSubmissionActive = false; + std::once_flag contextInitializedFlag = {}; + bool contextInitialized = false; }; } // namespace NEO diff --git a/shared/source/os_interface/windows/os_context_win.cpp b/shared/source/os_interface/windows/os_context_win.cpp index 576bc35b2e..c4cae52d43 100644 --- a/shared/source/os_interface/windows/os_context_win.cpp +++ b/shared/source/os_interface/windows/os_context_win.cpp @@ -25,8 +25,9 @@ OsContextWin::OsContextWin(Wddm &wddm, uint32_t contextId, DeviceBitfield device EngineTypeUsage typeUsage, PreemptionMode preemptionMode, bool rootDevice) : OsContext(contextId, deviceBitfield, typeUsage, preemptionMode, rootDevice), wddm(wddm), - residencyController(wddm, contextId) { + residencyController(wddm, contextId) {} +void OsContextWin::initializeContext() { auto wddmInterface = wddm.getWddmInterface(); UNRECOVERABLE_IF(!wddm.createContext(*this)); @@ -40,9 +41,11 @@ OsContextWin::OsContextWin(Wddm &wddm, uint32_t contextId, DeviceBitfield device }; OsContextWin::~OsContextWin() { - wddm.getWddmInterface()->destroyHwQueue(hardwareQueue.handle); - wddm.getWddmInterface()->destroyMonitorFence(residencyController.getMonitoredFence()); - wddm.destroyContext(wddmContextHandle); + if (contextInitialized) { + wddm.getWddmInterface()->destroyHwQueue(hardwareQueue.handle); + wddm.getWddmInterface()->destroyMonitorFence(residencyController.getMonitoredFence()); + wddm.destroyContext(wddmContextHandle); + } } } // namespace NEO diff --git a/shared/source/os_interface/windows/os_context_win.h b/shared/source/os_interface/windows/os_context_win.h index 5c8be779d2..94c04349e9 100644 --- a/shared/source/os_interface/windows/os_context_win.h +++ b/shared/source/os_interface/windows/os_context_win.h @@ -36,6 +36,8 @@ class OsContextWin : public OsContext { MOCKABLE_VIRTUAL WddmResidencyController &getResidencyController() { return residencyController; } protected: + void initializeContext() override; + D3DKMT_HANDLE wddmContextHandle = 0; HardwareQueue hardwareQueue; Wddm &wddm; diff --git a/shared/test/common/mocks/mock_device.cpp b/shared/test/common/mocks/mock_device.cpp index c62fd37c0c..edf61b8325 100644 --- a/shared/test/common/mocks/mock_device.cpp +++ b/shared/test/common/mocks/mock_device.cpp @@ -86,6 +86,7 @@ void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr, uint3 memoryManager->getRegisteredEngines().emplace_back(registeredEngine); osContext->incRefInternal(); newCsr->setupContext(*osContext); + osContext->ensureContextInitialized(); commandStreamReceivers[engineIndex].reset(newCsr); commandStreamReceivers[engineIndex]->initializeTagAllocation(); commandStreamReceivers[engineIndex]->createGlobalFenceAllocation(); diff --git a/shared/test/unit_test/direct_submission/linux/drm_direct_submission_tests.cpp b/shared/test/unit_test/direct_submission/linux/drm_direct_submission_tests.cpp index 026eb58852..9eadb76a5a 100644 --- a/shared/test/unit_test/direct_submission/linux/drm_direct_submission_tests.cpp +++ b/shared/test/unit_test/direct_submission/linux/drm_direct_submission_tests.cpp @@ -32,6 +32,7 @@ struct DrmDirectSubmissionTest : public DrmMemoryManagerBasic { osContext = std::make_unique(*executionEnvironment.rootDeviceEnvironments[0]->osInterface->get()->getDrm(), 0u, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, false); + osContext->ensureContextInitialized(); } void TearDown() override { diff --git a/shared/test/unit_test/direct_submission/windows/wddm_direct_submission_tests.cpp b/shared/test/unit_test/direct_submission/windows/wddm_direct_submission_tests.cpp index 1ab18b80d0..9d00a774be 100644 --- a/shared/test/unit_test/direct_submission/windows/wddm_direct_submission_tests.cpp +++ b/shared/test/unit_test/direct_submission/windows/wddm_direct_submission_tests.cpp @@ -30,6 +30,7 @@ struct WddmDirectSubmissionFixture : public WddmFixture { executionEnvironment->memoryManager.reset(new WddmMemoryManager{*executionEnvironment}); device.reset(MockDevice::create(executionEnvironment.get(), 0u)); osContext = std::make_unique(*wddm, 0u, device->getDeviceBitfield(), EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::ThreadGroup, false); + osContext->ensureContextInitialized(); device->setPreemptionMode(PreemptionMode::ThreadGroup); } diff --git a/shared/test/unit_test/os_interface/windows/wddm_preemption_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_preemption_tests.cpp index 93dfed6289..1fbb2664e9 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_preemption_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_preemption_tests.cpp @@ -45,6 +45,7 @@ class WddmPreemptionTests : public Test { ASSERT_NE(nullptr, hwInfo); auto engine = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0]; osContext = std::make_unique(*wddm, 0u, 1, engine, preemptionMode, false); + osContext->ensureContextInitialized(); } DebugManagerStateRestore *dbgRestorer = nullptr;