From 186e3d2b834ee247e58eba8c3ca3cb958e9cce9d Mon Sep 17 00:00:00 2001 From: Zbigniew Zdanowicz Date: Tue, 13 Feb 2024 12:19:57 +0000 Subject: [PATCH] refactor: add residency parameter to command list append kernel call Signed-off-by: Zbigniew Zdanowicz --- level_zero/core/source/cmdlist/cmdlist.h | 2 +- level_zero/core/source/cmdlist/cmdlist_hw.h | 10 +++---- level_zero/core/source/cmdlist/cmdlist_hw.inl | 4 +-- .../source/cmdlist/cmdlist_hw_immediate.h | 4 +-- .../source/cmdlist/cmdlist_hw_immediate.inl | 2 +- .../cmdlist/cmdlist_hw_skl_to_tgllp.inl | 4 +-- .../cmdlist/cmdlist_hw_xehp_and_later.inl | 12 ++++---- .../source/cmdlist/cmdlist_launch_params.h | 3 +- .../unit_tests/fixtures/cmdlist_fixture.h | 4 +-- .../test/unit_tests/fixtures/module_fixture.h | 1 + .../core/test/unit_tests/mocks/mock_cmdlist.h | 8 ++--- .../sources/cmdlist/test_cmdlist_8.cpp | 4 +-- .../test_cmdlist_append_launch_kernel_1.cpp | 30 ++++++++++++++++++- 13 files changed, 60 insertions(+), 28 deletions(-) diff --git a/level_zero/core/source/cmdlist/cmdlist.h b/level_zero/core/source/cmdlist/cmdlist.h index 17776a33ec..e6cdfca273 100644 --- a/level_zero/core/source/cmdlist/cmdlist.h +++ b/level_zero/core/source/cmdlist/cmdlist.h @@ -97,7 +97,7 @@ struct CommandList : _ze_command_list_handle_t { ze_event_handle_t *phWaitEvents, bool relaxedOrderingDispatch) = 0; virtual ze_result_t appendLaunchKernel(ze_kernel_handle_t kernelHandle, const ze_group_count_t &threadGroupDimensions, ze_event_handle_t hEvent, uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents, - const CmdListKernelLaunchParams &launchParams, bool relaxedOrderingDispatch) = 0; + CmdListKernelLaunchParams &launchParams, bool relaxedOrderingDispatch) = 0; virtual ze_result_t appendLaunchCooperativeKernel(ze_kernel_handle_t kernelHandle, const ze_group_count_t &launchKernelArgs, ze_event_handle_t hSignalEvent, diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.h b/level_zero/core/source/cmdlist/cmdlist_hw.h index fd20312214..d654758649 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.h +++ b/level_zero/core/source/cmdlist/cmdlist_hw.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -105,7 +105,7 @@ struct CommandListCoreFamily : public CommandListImp { const ze_group_count_t &threadGroupDimensions, ze_event_handle_t hEvent, uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents, - const CmdListKernelLaunchParams &launchParams, bool relaxedOrderingDispatch) override; + CmdListKernelLaunchParams &launchParams, bool relaxedOrderingDispatch) override; ze_result_t appendLaunchCooperativeKernel(ze_kernel_handle_t kernelHandle, const ze_group_count_t &launchKernelArgs, ze_event_handle_t hSignalEvent, @@ -253,18 +253,18 @@ struct CommandListCoreFamily : public CommandListImp { virtual ze_result_t appendLaunchKernelWithParams(Kernel *kernel, const ze_group_count_t &threadGroupDimensions, Event *event, - const CmdListKernelLaunchParams &launchParams); + CmdListKernelLaunchParams &launchParams); MOCKABLE_VIRTUAL ze_result_t appendLaunchKernelSplit(Kernel *kernel, const ze_group_count_t &threadGroupDimensions, Event *event, - const CmdListKernelLaunchParams &launchParams); + CmdListKernelLaunchParams &launchParams); ze_result_t appendUnalignedFillKernel(bool isStateless, uint32_t unalignedSize, const AlignedAllocationData &dstAllocation, const void *pattern, Event *signalEvent, - const CmdListKernelLaunchParams &launchParams); + CmdListKernelLaunchParams &launchParams); void appendWaitOnSingleEvent(Event *event, bool relaxedOrderingAllowed); diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.inl b/level_zero/core/source/cmdlist/cmdlist_hw.inl index 5c243523dc..c478b821cd 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw.inl @@ -348,7 +348,7 @@ ze_result_t CommandListCoreFamily::appendLaunchKernel(ze_kernel_h ze_event_handle_t hEvent, uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents, - const CmdListKernelLaunchParams &launchParams, bool relaxedOrderingDispatch) { + CmdListKernelLaunchParams &launchParams, bool relaxedOrderingDispatch) { NEO::Device *neoDevice = device->getNEODevice(); uint32_t callId = 0; @@ -1804,7 +1804,7 @@ ze_result_t CommandListCoreFamily::appendMemoryPrefetch(const voi } template -ze_result_t CommandListCoreFamily::appendUnalignedFillKernel(bool isStateless, uint32_t unalignedSize, const AlignedAllocationData &dstAllocation, const void *pattern, Event *signalEvent, const CmdListKernelLaunchParams &launchParams) { +ze_result_t CommandListCoreFamily::appendUnalignedFillKernel(bool isStateless, uint32_t unalignedSize, const AlignedAllocationData &dstAllocation, const void *pattern, Event *signalEvent, CmdListKernelLaunchParams &launchParams) { const bool isHeapless = this->isHeaplessModeEnabled(); auto builtin = BuiltinTypeHelper::adjustBuiltinType(isStateless, isHeapless); diff --git a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.h b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.h index 197c4f511e..fd78026995 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw_immediate.h +++ b/level_zero/core/source/cmdlist/cmdlist_hw_immediate.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -56,7 +56,7 @@ struct CommandListCoreFamilyImmediate : public CommandListCoreFamily ze_result_t CommandListCoreFamilyImmediate::appendLaunchKernel( ze_kernel_handle_t kernelHandle, const ze_group_count_t &threadGroupDimensions, ze_event_handle_t hSignalEvent, uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents, - const CmdListKernelLaunchParams &launchParams, bool relaxedOrderingDispatch) { + CmdListKernelLaunchParams &launchParams, bool relaxedOrderingDispatch) { relaxedOrderingDispatch = isRelaxedOrderingDispatchAllowed(numWaitEvents); bool stallingCmdsForRelaxedOrdering = hasStallingCmdsForRelaxedOrdering(numWaitEvents, relaxedOrderingDispatch); diff --git a/level_zero/core/source/cmdlist/cmdlist_hw_skl_to_tgllp.inl b/level_zero/core/source/cmdlist/cmdlist_hw_skl_to_tgllp.inl index 95c1b24bc1..9e7bf94000 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw_skl_to_tgllp.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw_skl_to_tgllp.inl @@ -49,7 +49,7 @@ template ze_result_t CommandListCoreFamily::appendLaunchKernelWithParams(Kernel *kernel, const ze_group_count_t &threadGroupDimensions, Event *event, - const CmdListKernelLaunchParams &launchParams) { + CmdListKernelLaunchParams &launchParams) { UNRECOVERABLE_IF(kernel == nullptr); UNRECOVERABLE_IF(launchParams.skipInOrderNonWalkerSignaling); const auto driverHandle = static_cast(device->getDriverHandle()); @@ -324,7 +324,7 @@ template ze_result_t CommandListCoreFamily::appendLaunchKernelSplit(Kernel *kernel, const ze_group_count_t &threadGroupDimensions, Event *event, - const CmdListKernelLaunchParams &launchParams) { + CmdListKernelLaunchParams &launchParams) { return appendLaunchKernelWithParams(kernel, threadGroupDimensions, nullptr, launchParams); } diff --git a/level_zero/core/source/cmdlist/cmdlist_hw_xehp_and_later.inl b/level_zero/core/source/cmdlist/cmdlist_hw_xehp_and_later.inl index e9c590b1de..9746950130 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw_xehp_and_later.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw_xehp_and_later.inl @@ -83,7 +83,7 @@ bool CommandListCoreFamily::isInOrderNonWalkerSignalingRequired(c template ze_result_t CommandListCoreFamily::appendLaunchKernelWithParams(Kernel *kernel, const ze_group_count_t &threadGroupDimensions, Event *event, - const CmdListKernelLaunchParams &launchParams) { + CmdListKernelLaunchParams &launchParams) { if (NEO::debugManager.flags.ForcePipeControlPriorToWalker.get()) { NEO::PipeControlArgs args; @@ -388,9 +388,11 @@ ze_result_t CommandListCoreFamily::appendLaunchKernelWithParams(K // Attach kernel residency to our CommandList residency { commandContainer.addToResidencyContainer(kernelImmutableData->getIsaGraphicsAllocation()); - auto &residencyContainer = kernel->getResidencyContainer(); - for (auto resource : residencyContainer) { - commandContainer.addToResidencyContainer(resource); + if (!launchParams.omitAddingKernelResidency) { + auto &residencyContainer = kernel->getResidencyContainer(); + for (auto resource : residencyContainer) { + commandContainer.addToResidencyContainer(resource); + } } } @@ -485,7 +487,7 @@ template ze_result_t CommandListCoreFamily::appendLaunchKernelSplit(Kernel *kernel, const ze_group_count_t &threadGroupDimensions, Event *event, - const CmdListKernelLaunchParams &launchParams) { + CmdListKernelLaunchParams &launchParams) { if (event) { if (eventSignalPipeControl(launchParams.isKernelSplitOperation, getDcFlushRequired(event->isSignalScope()))) { event = nullptr; diff --git a/level_zero/core/source/cmdlist/cmdlist_launch_params.h b/level_zero/core/source/cmdlist/cmdlist_launch_params.h index 390e6d64ac..ecceb6361f 100644 --- a/level_zero/core/source/cmdlist/cmdlist_launch_params.h +++ b/level_zero/core/source/cmdlist/cmdlist_launch_params.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -27,5 +27,6 @@ struct CmdListKernelLaunchParams { bool isHostSignalScopeEvent = false; bool skipInOrderNonWalkerSignaling = false; bool pipeControlSignalling = false; + bool omitAddingKernelResidency = false; }; } // namespace L0 diff --git a/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h b/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h index 63f0c009c6..16d7eb9f72 100644 --- a/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/cmdlist_fixture.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -216,7 +216,7 @@ class AppendFillFixture : public DeviceFixture { ze_result_t appendLaunchKernelWithParams(Kernel *kernel, const ze_group_count_t &pThreadGroupDimensions, L0::Event *event, - const CmdListKernelLaunchParams &launchParams) override { + CmdListKernelLaunchParams &launchParams) override { if (numberOfCallsToAppendLaunchKernelWithParams == thresholdOfCallsToAppendLaunchKernelWithParamsToFail) { return ZE_RESULT_ERROR_UNKNOWN; } diff --git a/level_zero/core/test/unit_tests/fixtures/module_fixture.h b/level_zero/core/test/unit_tests/fixtures/module_fixture.h index fa825d5766..2f0f7bf8e6 100644 --- a/level_zero/core/test/unit_tests/fixtures/module_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/module_fixture.h @@ -92,6 +92,7 @@ struct ModuleImmutableDataFixture : public DeviceFixture { using KernelImp::printfBuffer; using KernelImp::privateMemoryGraphicsAllocation; using KernelImp::requiredWorkgroupOrder; + using KernelImp::residencyContainer; using KernelImp::surfaceStateHeapData; using KernelImp::surfaceStateHeapDataSize; using KernelImp::unifiedMemoryControls; diff --git a/level_zero/core/test/unit_tests/mocks/mock_cmdlist.h b/level_zero/core/test/unit_tests/mocks/mock_cmdlist.h index 3eba722aff..c73670be92 100644 --- a/level_zero/core/test/unit_tests/mocks/mock_cmdlist.h +++ b/level_zero/core/test/unit_tests/mocks/mock_cmdlist.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -111,7 +111,7 @@ struct WhiteBox<::L0::CommandListCoreFamily> ze_result_t appendLaunchKernelWithParams(::L0::Kernel *kernel, const ze_group_count_t &threadGroupDimensions, ::L0::Event *event, - const CmdListKernelLaunchParams &launchParams) override { + CmdListKernelLaunchParams &launchParams) override { usedKernelLaunchParams = launchParams; if (launchParams.isKernelSplitOperation && (launchParams.numKernelsExecutedInSplitLaunch == 0)) { @@ -301,7 +301,7 @@ struct MockCommandList : public CommandList { const ze_group_count_t &threadGroupDimensions, ze_event_handle_t hEvent, uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents, - const CmdListKernelLaunchParams &launchParams, bool relaxedOrderingDispatch)); + CmdListKernelLaunchParams &launchParams, bool relaxedOrderingDispatch)); ADDMETHOD_NOBASE(appendLaunchCooperativeKernel, ze_result_t, ZE_RESULT_SUCCESS, (ze_kernel_handle_t kernelHandle, @@ -699,7 +699,7 @@ class MockCommandListForAppendLaunchKernel : public WhiteBox<::L0::CommandListCo ze_event_handle_t hEvent, uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents, - const CmdListKernelLaunchParams &launchParams, bool relaxedOrderingDispatch) override { + CmdListKernelLaunchParams &launchParams, bool relaxedOrderingDispatch) override { const auto kernel = Kernel::fromHandle(kernelHandle); cmdListHelper.isaAllocation = kernel->getIsaAllocation(); diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_8.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_8.cpp index cd3394a284..9f0cb60618 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_8.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_8.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Intel Corporation + * Copyright (C) 2023-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -1273,7 +1273,7 @@ class MockCommandListHwKernelSplit : public WhiteBox<::L0::CommandListCoreFamily ze_result_t appendLaunchKernelSplit(::L0::Kernel *kernel, const ze_group_count_t &threadGroupDimensions, ::L0::Event *event, - const CmdListKernelLaunchParams &launchParams) override { + CmdListKernelLaunchParams &launchParams) override { passedKernel = kernel; return status; } diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel_1.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel_1.cpp index 2acc72ddef..4f7cf0ae6c 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel_1.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_launch_kernel_1.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2023 Intel Corporation + * Copyright (C) 2020-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -17,6 +17,7 @@ #include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/libult/ult_command_stream_receiver.h" #include "shared/test/common/mocks/mock_device.h" +#include "shared/test/common/mocks/mock_graphics_allocation.h" #include "shared/test/common/test_macros/hw_test.h" #include "level_zero/core/source/cmdlist/cmdlist_hw_immediate.h" @@ -1455,5 +1456,32 @@ HWTEST2_F(CommandListAppendLaunchKernel, whenUpdateStreamPropertiesIsCalledThenC } } +HWTEST2_F(CommandListAppendLaunchKernelMockModule, + givenFlagOmitKernelResourcePassToCmdlistResidencyWhenAppendingKernelThenExpectNoKernelArgumentsInCmdlistResidency, + IsAtLeastXeHpCore) { + NEO::MockGraphicsAllocation mockAllocation; + NEO::GraphicsAllocation *allocation = &mockAllocation; + kernel->residencyContainer.push_back(allocation); + + ze_group_count_t groupCount{1, 1, 1}; + ze_result_t returnValue; + CmdListKernelLaunchParams launchParams = {}; + launchParams.omitAddingKernelResidency = true; + returnValue = commandList->appendLaunchKernel(kernel->toHandle(), groupCount, nullptr, 0, nullptr, launchParams, false); + ASSERT_EQ(ZE_RESULT_SUCCESS, returnValue); + + auto &cmdlistResidency = commandList->getCmdContainer().getResidencyContainer(); + + auto kernelAllocationIt = std::find(cmdlistResidency.begin(), cmdlistResidency.end(), allocation); + EXPECT_EQ(kernelAllocationIt, cmdlistResidency.end()); + + launchParams.omitAddingKernelResidency = false; + returnValue = commandList->appendLaunchKernel(kernel->toHandle(), groupCount, nullptr, 0, nullptr, launchParams, false); + ASSERT_EQ(ZE_RESULT_SUCCESS, returnValue); + + kernelAllocationIt = std::find(cmdlistResidency.begin(), cmdlistResidency.end(), allocation); + EXPECT_NE(kernelAllocationIt, cmdlistResidency.end()); +} + } // namespace ult } // namespace L0