From 00964275fb81201e94604e55f81a2ca389d19850 Mon Sep 17 00:00:00 2001 From: "Dunajski, Bartosz" Date: Thu, 29 Feb 2024 10:11:37 +0000 Subject: [PATCH] fix: create preemption allocation for Root Csr Signed-off-by: Dunajski, Bartosz --- .../sources/cmdqueue/test_cmdqueue_2.cpp | 7 +---- .../test_cmdqueue_enqueue_cmdlist.cpp | 5 ---- .../dispatch_walker_tests_xehp_and_later.cpp | 24 ++++------------ ...ceiver_flush_task_tests_xehp_and_later.cpp | 28 ++++--------------- shared/source/device/root_device.cpp | 5 +++- .../unit_test/device/neo_device_tests.cpp | 12 ++++++++ 6 files changed, 29 insertions(+), 52 deletions(-) diff --git a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_2.cpp b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_2.cpp index 610d929cbb..4a5c155ffc 100644 --- a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_2.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_2.cpp @@ -356,9 +356,6 @@ HWTEST2_F(MultiTileCommandQueueSynchronizeTest, givenMultiplePartitionCountWhenC ze_result_t returnValue; auto csr = reinterpret_cast *>(neoDevice->getDefaultEngine().commandStreamReceiver); - if (device->getNEODevice()->getPreemptionMode() == PreemptionMode::MidThread) { - csr->createPreemptionAllocation(); - } EXPECT_NE(0u, csr->getImmWritePostSyncWriteOffset()); volatile TagAddressType *tagAddress = csr->getTagAddress(); for (uint32_t i = 0; i < 2; i++) { @@ -399,9 +396,7 @@ HWTEST2_F(MultiTileCommandQueueSynchronizeTest, givenCsrHasMultipleActivePartiti ze_result_t returnValue; auto csr = reinterpret_cast *>(neoDevice->getDefaultEngine().commandStreamReceiver); - if (device->getNEODevice()->getPreemptionMode() == PreemptionMode::MidThread) { - csr->createPreemptionAllocation(); - } + EXPECT_NE(0u, csr->getImmWritePostSyncWriteOffset()); volatile TagAddressType *tagAddress = csr->getTagAddress(); for (uint32_t i = 0; i < 2; i++) { diff --git a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_enqueue_cmdlist.cpp b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_enqueue_cmdlist.cpp index 0e57c83b79..fc0c8bf659 100644 --- a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_enqueue_cmdlist.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_enqueue_cmdlist.cpp @@ -1122,11 +1122,6 @@ HWTEST2_F(MultiDeviceCommandQueueExecuteCommandLists, givenMultiplePartitionCoun EXPECT_EQ(2u, commandQueue->partitionCount); ASSERT_NE(nullptr, commandQueue); - auto &commandStreamReceiver = device->getNEODevice()->getDefaultEngine().commandStreamReceiver; - if (neoDevice->getPreemptionMode() == PreemptionMode::MidThread) { - commandStreamReceiver->createPreemptionAllocation(); - } - ze_fence_desc_t fenceDesc{}; auto fence = whiteboxCast(Fence::create(commandQueue, &fenceDesc)); ASSERT_NE(nullptr, fence); diff --git a/opencl/test/unit_test/command_queue/dispatch_walker_tests_xehp_and_later.cpp b/opencl/test/unit_test/command_queue/dispatch_walker_tests_xehp_and_later.cpp index 41830b9519..30fa424e77 100644 --- a/opencl/test/unit_test/command_queue/dispatch_walker_tests_xehp_and_later.cpp +++ b/opencl/test/unit_test/command_queue/dispatch_walker_tests_xehp_and_later.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2023 Intel Corporation + * Copyright (C) 2021-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -1523,9 +1523,7 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, XeHPAndLaterDispatchWalkerBasicTestDynamicPartition size_t gws[] = {128, 1, 1}; size_t lws[] = {8, 1, 1}; auto &commandStreamReceiver = cmdQ->getUltCommandStreamReceiver(); - if (device->getPreemptionMode() == PreemptionMode::MidThread) { - commandStreamReceiver.createPreemptionAllocation(); - } + EXPECT_EQ(1u, commandStreamReceiver.activePartitions); cmdQ->enqueueKernel(kernel->mockKernel, 1, nullptr, gws, lws, 0, nullptr, nullptr); EXPECT_EQ(1u, commandStreamReceiver.activePartitions); @@ -1559,9 +1557,7 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, XeHPAndLaterDispatchWalkerBasicTestStaticPartition, size_t gws[] = {128, 1, 1}; size_t lws[] = {8, 1, 1}; auto &commandStreamReceiver = cmdQ->getUltCommandStreamReceiver(); - if (device->getPreemptionMode() == PreemptionMode::MidThread) { - commandStreamReceiver.createPreemptionAllocation(); - } + EXPECT_EQ(2u, commandStreamReceiver.activePartitions); cmdQ->enqueueKernel(kernel->mockKernel, 1, nullptr, gws, lws, 0, nullptr, nullptr); EXPECT_EQ(2u, commandStreamReceiver.activePartitions); @@ -1585,9 +1581,7 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, XeHPAndLaterDispatchWalkerBasicTestStaticPartition, size_t gws[] = {129, 1, 1}; size_t lws[] = {8, 1, 1}; auto &commandStreamReceiver = cmdQ->getUltCommandStreamReceiver(); - if (device->getPreemptionMode() == PreemptionMode::MidThread) { - commandStreamReceiver.createPreemptionAllocation(); - } + EXPECT_EQ(2u, commandStreamReceiver.activePartitions); kernel->mockProgram->allowNonUniform = true; cmdQ->enqueueKernel(kernel->mockKernel, 1, nullptr, gws, lws, 0, nullptr, nullptr); @@ -1936,10 +1930,7 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, XeHPAndLaterDispatchWalkerTestMultiTileDevice, give auto cmdQ = std::make_unique>(context.get(), device.get(), nullptr); size_t gws[] = {2, 1, 1}; size_t lws[] = {1, 1, 1}; - auto &commandStreamReceiver = cmdQ->getUltCommandStreamReceiver(); - if (device->getPreemptionMode() == PreemptionMode::MidThread) { - commandStreamReceiver.createPreemptionAllocation(); - } + KernelWithSingleSubdevicePreferences subdeviceKernel(kernel->mockProgram, kernel->kernelInfo, *device); subdeviceKernel.singleSubdevicePreferred = true; cmdQ->enqueueKernel(&subdeviceKernel, 1, nullptr, gws, lws, 0, nullptr, nullptr); @@ -1960,10 +1951,7 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, XeHPAndLaterDispatchWalkerTestMultiTileDevice, give auto cmdQ = std::make_unique>(context.get(), device.get(), nullptr); size_t gws[] = {2, 1, 1}; size_t lws[] = {1, 1, 1}; - auto &commandStreamReceiver = cmdQ->getUltCommandStreamReceiver(); - if (device->getPreemptionMode() == PreemptionMode::MidThread) { - commandStreamReceiver.createPreemptionAllocation(); - } + KernelWithSingleSubdevicePreferences subdeviceKernel(kernel->mockProgram, kernel->kernelInfo, *device); subdeviceKernel.singleSubdevicePreferred = false; cmdQ->enqueueKernel(&subdeviceKernel, 1, nullptr, gws, lws, 0, nullptr, nullptr); diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_tests_xehp_and_later.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_tests_xehp_and_later.cpp index 2eb702cccb..ea0419e0bd 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_tests_xehp_and_later.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_tests_xehp_and_later.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2023 Intel Corporation + * Copyright (C) 2021-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -774,9 +774,7 @@ struct CommandStreamReceiverFlushTaskXeHPAndLaterMultiTileTests : public Command HWCMDTEST_F(IGFX_XE_HP_CORE, CommandStreamReceiverFlushTaskXeHPAndLaterMultiTileTests, givenMultipleStaticActivePartitionsWhenFlushingTaskThenExpectTagUpdatePipeControlWithPartitionFlagOnAndActivePartitionConfig) { auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); - if (pDevice->getPreemptionMode() == PreemptionMode::MidThread) { - commandStreamReceiver.createPreemptionAllocation(); - } + EXPECT_EQ(1u, commandStreamReceiver.activePartitionsConfig); commandStreamReceiver.activePartitions = 2; commandStreamReceiver.taskCount = 3; @@ -797,9 +795,7 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, CommandStreamReceiverFlushTaskXeHPAndLaterMultiTile debugManager.flags.UpdateTaskCountFromWait.set(3); auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); - if (pDevice->getPreemptionMode() == PreemptionMode::MidThread) { - commandStreamReceiver.createPreemptionAllocation(); - } + EXPECT_EQ(1u, commandStreamReceiver.activePartitionsConfig); commandStreamReceiver.activePartitions = 2; commandStreamReceiver.taskCount = 3; @@ -815,9 +811,7 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, CommandStreamReceiverFlushTaskXeHPAndLaterMultiTile HWCMDTEST_F(IGFX_XE_HP_CORE, CommandStreamReceiverFlushTaskXeHPAndLaterMultiTileTests, givenSingleStaticActivePartitionWhenFlushingTaskThenExpectTagUpdatePipeControlWithoutPartitionFlagOnAndNoActivePartitionConfig) { auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); - if (pDevice->getPreemptionMode() == PreemptionMode::MidThread) { - commandStreamReceiver.createPreemptionAllocation(); - } + commandStreamReceiver.activePartitions = 1; commandStreamReceiver.taskCount = 3; flushTask(commandStreamReceiver, true); @@ -838,9 +832,7 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, CommandStreamReceiverFlushTaskXeHPAndLaterMultiTile debugManager.flags.UpdateTaskCountFromWait.set(3); auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); - if (pDevice->getPreemptionMode() == PreemptionMode::MidThread) { - commandStreamReceiver.createPreemptionAllocation(); - } + EXPECT_EQ(1u, commandStreamReceiver.activePartitionsConfig); commandStreamReceiver.activePartitions = 2; commandStreamReceiver.taskCount = 3; @@ -869,9 +861,6 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, CommandStreamReceiverFlushTaskXeHPAndLaterMultiTile HWCMDTEST_F(IGFX_XE_HP_CORE, CommandStreamReceiverFlushTaskXeHPAndLaterMultiTileTests, givenMultipleDynamicActivePartitionsWhenFlushingTaskTwiceThenExpectTagUpdatePipeControlWithoutPartitionFlagAndPartitionRegisters) { auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); - if (pDevice->getPreemptionMode() == PreemptionMode::MidThread) { - commandStreamReceiver.createPreemptionAllocation(); - } commandStreamReceiver.activePartitions = 2; commandStreamReceiver.taskCount = 3; @@ -892,9 +881,7 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, CommandStreamReceiverFlushTaskXeHPAndLaterMultiTile debugManager.flags.UpdateTaskCountFromWait.set(1); auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); - if (pDevice->getPreemptionMode() == PreemptionMode::MidThread) { - commandStreamReceiver.createPreemptionAllocation(); - } + commandStreamReceiver.activePartitions = 2; commandStreamReceiver.taskCount = 3; commandStreamReceiver.staticWorkPartitioningEnabled = false; @@ -907,9 +894,6 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, CommandStreamReceiverFlushTaskXeHPAndLaterMultiTile HWCMDTEST_F(IGFX_XE_HP_CORE, CommandStreamReceiverFlushTaskXeHPAndLaterMultiTileTests, givenMultipleStaticActivePartitionsAndDirectSubmissionActiveWhenFlushingTaskThenExpectTagUpdatePipeControlWithPartitionFlagOnAndNoActivePartitionConfig) { auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); - if (pDevice->getPreemptionMode() == PreemptionMode::MidThread) { - commandStreamReceiver.createPreemptionAllocation(); - } commandStreamReceiver.directSubmission = std::make_unique>>(commandStreamReceiver); commandStreamReceiver.directSubmissionAvailable = true; diff --git a/shared/source/device/root_device.cpp b/shared/source/device/root_device.cpp index 6f18ee73f3..07a0ec3867 100644 --- a/shared/source/device/root_device.cpp +++ b/shared/source/device/root_device.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2023 Intel Corporation + * Copyright (C) 2019-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -70,6 +70,9 @@ void RootDevice::initializeRootCommandStreamReceiver() { rootCommandStreamReceiver->initializeTagAllocation(); rootCommandStreamReceiver->createGlobalFenceAllocation(); rootCommandStreamReceiver->createWorkPartitionAllocation(*this); + if (preemptionMode == PreemptionMode::MidThread) { + rootCommandStreamReceiver->createPreemptionAllocation(); + } commandStreamReceivers.push_back(std::move(rootCommandStreamReceiver)); EngineControl engine{commandStreamReceivers.back().get(), osContext}; diff --git a/shared/test/unit_test/device/neo_device_tests.cpp b/shared/test/unit_test/device/neo_device_tests.cpp index d074e50ae9..381a7d5092 100644 --- a/shared/test/unit_test/device/neo_device_tests.cpp +++ b/shared/test/unit_test/device/neo_device_tests.cpp @@ -596,6 +596,18 @@ TEST_F(DeviceTests, givenDispatchGlobalsAllocationFailsOnSecondSubDeviceThenRtDi EXPECT_EQ(nullptr, rtDispatchGlobalsInfo); } +TEST_F(DeviceTests, givenMtPreemptionEnabledWhenCreatingRootCsrThenCreatePreemptionAllocation) { + DebugManagerStateRestore restorer; + + debugManager.flags.CreateMultipleSubDevices.set(2); + debugManager.flags.ForcePreemptionMode.set(4); + + UltDeviceFactory deviceFactory{1, 2}; + + EXPECT_TRUE(deviceFactory.rootDevices[0]->getDefaultEngine().osContext->isRootDevice()); + EXPECT_NE(nullptr, deviceFactory.rootDevices[0]->getDefaultEngine().commandStreamReceiver->getPreemptionAllocation()); +} + HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZexNumberOfCssEnvVariableDefinedWhenDeviceIsCreatedThenCreateDevicesWithProperCcsCount) { VariableBackup backup(&ultHwConfig); ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false;