Add improvements to heap estimation in level zero command lists

- add estimation parameter for interface descriptor data count
- add to the heap estimation alignment parameter for dynamic and surface heaps
- extend encode interface and implementations to allow child heaps

Related-To: NEO-5055

Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
This commit is contained in:
Zbigniew Zdanowicz
2023-02-02 18:57:24 +00:00
committed by Compute-Runtime-Automation
parent 5a833e2c08
commit 7e0401d280
18 changed files with 154 additions and 66 deletions

View File

@@ -93,7 +93,7 @@ struct UnitTestHelper {
static bool getDisableFusionStateFromFrontEndCommand(const typename GfxFamily::VFE_STATE_TYPE &feCmd);
static bool getComputeDispatchAllWalkerFromFrontEndCommand(const typename GfxFamily::VFE_STATE_TYPE &feCmd);
static bool getSystolicFlagValueFromPipelineSelectCommand(const typename GfxFamily::PIPELINE_SELECT &pipelineSelectCmd);
static size_t getAdditionalDshSize();
static size_t getAdditionalDshSize(uint32_t iddCount);
static bool expectNullDsh(const DeviceInfo &deviceInfo);
};

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Intel Corporation
* Copyright (C) 2022-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -93,8 +93,8 @@ bool UnitTestHelper<GfxFamily>::getSystolicFlagValueFromPipelineSelectCommand(co
}
template <typename GfxFamily>
size_t UnitTestHelper<GfxFamily>::getAdditionalDshSize() {
return sizeof(typename GfxFamily::INTERFACE_DESCRIPTOR_DATA);
size_t UnitTestHelper<GfxFamily>::getAdditionalDshSize(uint32_t iddCount) {
return iddCount * sizeof(typename GfxFamily::INTERFACE_DESCRIPTOR_DATA);
}
} // namespace NEO

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2022 Intel Corporation
* Copyright (C) 2021-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -122,7 +122,7 @@ bool UnitTestHelper<GfxFamily>::getSystolicFlagValueFromPipelineSelectCommand(co
}
template <typename GfxFamily>
size_t UnitTestHelper<GfxFamily>::getAdditionalDshSize() {
size_t UnitTestHelper<GfxFamily>::getAdditionalDshSize(uint32_t iddCount) {
return 0;
}

View File

@@ -6,6 +6,7 @@
*/
#include "shared/source/command_container/cmdcontainer.h"
#include "shared/source/command_container/command_encoder.h"
#include "shared/source/command_stream/linear_stream.h"
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/helpers/heap_helper.h"
@@ -940,6 +941,9 @@ HWTEST_F(CommandContainerTest, givenCmdContainerHasImmediateCsrWhenGettingHeapWi
cmdContainer.setImmediateCmdListCsr(pDevice->getDefaultEngine().commandStreamReceiver);
cmdContainer.immediateReusableAllocationList = std::make_unique<NEO::AllocationsList>();
const size_t dshAlign = NEO::EncodeDispatchKernel<FamilyType>::getDefaultDshAlignment();
const size_t sshAlign = NEO::EncodeDispatchKernel<FamilyType>::getDefaultSshAlignment();
cmdContainer.setNumIddPerBlock(1);
auto code = cmdContainer.initialize(pDevice, nullptr, true);
EXPECT_EQ(CommandContainer::ErrorCode::SUCCESS, code);
@@ -956,7 +960,7 @@ HWTEST_F(CommandContainerTest, givenCmdContainerHasImmediateCsrWhenGettingHeapWi
auto &ultCsr = pDevice->getUltCommandStreamReceiver<FamilyType>();
ultCsr.recursiveLockCounter = 0;
cmdContainer.ensureHeapSizePrepared(0, 0, false);
cmdContainer.ensureHeapSizePrepared(0, sshAlign, 0, dshAlign, false);
EXPECT_EQ(1u, ultCsr.recursiveLockCounter);
EXPECT_EQ(nullptr, cmdContainer.getIndirectHeap(HeapType::DYNAMIC_STATE));
@@ -968,22 +972,54 @@ HWTEST_F(CommandContainerTest, givenCmdContainerHasImmediateCsrWhenGettingHeapWi
EXPECT_NO_THROW(cmdContainer.getHeapSpaceAllowGrow(HeapType::SURFACE_STATE, 0));
EXPECT_NO_THROW(cmdContainer.getHeapWithRequiredSizeAndAlignment(HeapType::SURFACE_STATE, 0, 0));
cmdContainer.ensureHeapSizePrepared(0, 0, true);
cmdContainer.ensureHeapSizePrepared(0, sshAlign, 0, dshAlign, true);
EXPECT_EQ(2u, ultCsr.recursiveLockCounter);
EXPECT_NE(nullptr, cmdContainer.getIndirectHeap(HeapType::DYNAMIC_STATE));
EXPECT_NE(nullptr, cmdContainer.getIndirectHeap(HeapType::SURFACE_STATE));
ASSERT_NE(nullptr, cmdContainer.getIndirectHeap(HeapType::DYNAMIC_STATE));
ASSERT_NE(nullptr, cmdContainer.getIndirectHeap(HeapType::SURFACE_STATE));
cmdContainer.ensureHeapSizePrepared(4 * MemoryConstants::kiloByte, 4 * MemoryConstants::kiloByte, true);
auto sshHeap = cmdContainer.getIndirectHeap(HeapType::SURFACE_STATE);
EXPECT_NE(nullptr, sshHeap);
size_t sizeUsedDsh = 0;
size_t sizeUsedSsh = sshHeap->getUsed();
size_t initSshSize = sizeUsedSsh;
constexpr size_t misAlignedSize = 3;
cmdContainer.ensureHeapSizePrepared(misAlignedSize, sshAlign, misAlignedSize, dshAlign, true);
EXPECT_EQ(3u, ultCsr.recursiveLockCounter);
auto dshHeap = cmdContainer.getIndirectHeap(HeapType::DYNAMIC_STATE);
EXPECT_NE(nullptr, dshHeap);
auto sshHeap = cmdContainer.getIndirectHeap(HeapType::SURFACE_STATE);
sshHeap->getSpace(misAlignedSize);
dshHeap->getSpace(misAlignedSize);
cmdContainer.ensureHeapSizePrepared(sshAlign, sshAlign, dshAlign, dshAlign, true);
EXPECT_EQ(4u, ultCsr.recursiveLockCounter);
sshHeap->align(sshAlign);
sshHeap->getSpace(sshAlign);
dshHeap->align(dshAlign);
dshHeap->getSpace(dshAlign);
sizeUsedDsh = dshHeap->getUsed();
sizeUsedSsh = sshHeap->getUsed();
EXPECT_EQ(2 * sshAlign + initSshSize, sizeUsedSsh);
EXPECT_EQ(2 * dshAlign, sizeUsedDsh);
cmdContainer.ensureHeapSizePrepared(4 * MemoryConstants::kiloByte, sshAlign, 4 * MemoryConstants::kiloByte, dshAlign, true);
EXPECT_EQ(5u, ultCsr.recursiveLockCounter);
dshHeap = cmdContainer.getIndirectHeap(HeapType::DYNAMIC_STATE);
EXPECT_NE(nullptr, dshHeap);
sshHeap = cmdContainer.getIndirectHeap(HeapType::SURFACE_STATE);
EXPECT_NE(nullptr, sshHeap);
size_t sizeUsedDsh = dshHeap->getUsed();
size_t sizeUsedSsh = sshHeap->getUsed();
sizeUsedDsh = dshHeap->getUsed();
sizeUsedSsh = sshHeap->getUsed();
void *dshPtr = cmdContainer.getHeapSpaceAllowGrow(HeapType::DYNAMIC_STATE, 64);
void *sshPtr = cmdContainer.getHeapSpaceAllowGrow(HeapType::SURFACE_STATE, 64);
@@ -1012,12 +1048,15 @@ HWTEST_F(CommandContainerTest, givenCmdContainerUsedInRegularCmdListWhenGettingH
GTEST_SKIP();
}
const size_t dshAlign = NEO::EncodeDispatchKernel<FamilyType>::getDefaultDshAlignment();
const size_t sshAlign = NEO::EncodeDispatchKernel<FamilyType>::getDefaultSshAlignment();
MyMockCommandContainer cmdContainer;
auto code = cmdContainer.initialize(pDevice, nullptr, true);
EXPECT_EQ(CommandContainer::ErrorCode::SUCCESS, code);
cmdContainer.ensureHeapSizePrepared(0, 0, true);
cmdContainer.ensureHeapSizePrepared(0, sshAlign, 0, dshAlign, true);
auto dsh = cmdContainer.getIndirectHeap(HeapType::DYNAMIC_STATE);
auto ssh = cmdContainer.getIndirectHeap(HeapType::SURFACE_STATE);
@@ -1027,7 +1066,7 @@ HWTEST_F(CommandContainerTest, givenCmdContainerUsedInRegularCmdListWhenGettingH
dsh->getSpace(dsh->getAvailableSpace() - 64);
cmdContainer.ensureHeapSizePrepared(4 * MemoryConstants::kiloByte, 4 * MemoryConstants::kiloByte, false);
cmdContainer.ensureHeapSizePrepared(4 * MemoryConstants::kiloByte, sshAlign, 4 * MemoryConstants::kiloByte, dshAlign, false);
dsh = cmdContainer.getIndirectHeap(HeapType::DYNAMIC_STATE);
EXPECT_EQ(64u, dsh->getAvailableSpace());

View File

@@ -800,7 +800,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandEncodeStatesTest, giveNumSamplersOneWhenHeapI
auto dshBeforeFlush = cmdContainer->getIndirectHeap(HeapType::DYNAMIC_STATE);
auto &kernelDescriptor = dispatchInterface->getKernelDescriptor();
dshBeforeFlush->getSpace(dshBeforeFlush->getAvailableSpace() - NEO::EncodeDispatchKernel<FamilyType>::getSizeRequiredDsh(kernelDescriptor));
dshBeforeFlush->getSpace(dshBeforeFlush->getAvailableSpace() - NEO::EncodeDispatchKernel<FamilyType>::getSizeRequiredDsh(kernelDescriptor, cmdContainer->getNumIddPerBlock()));
auto cpuBaseBeforeFlush = dshBeforeFlush->getCpuBase();
EncodeDispatchKernel<FamilyType>::encode(*cmdContainer.get(), dispatchArgs, nullptr);
@@ -853,7 +853,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandEncodeStatesTest, giveNumSamplersOneAndNextID
auto dshBeforeFlush = cmdContainer->getIndirectHeap(HeapType::DYNAMIC_STATE);
auto &kernelDescriptor = dispatchInterface->getKernelDescriptor();
auto sizeRequiredMinusIDD = dshBeforeFlush->getAvailableSpace() - NEO::EncodeDispatchKernel<FamilyType>::getSizeRequiredDsh(kernelDescriptor) + sizeof(INTERFACE_DESCRIPTOR_DATA);
auto sizeRequiredMinusIDD = dshBeforeFlush->getAvailableSpace() - NEO::EncodeDispatchKernel<FamilyType>::getSizeRequiredDsh(kernelDescriptor, cmdContainer->getNumIddPerBlock()) + sizeof(INTERFACE_DESCRIPTOR_DATA);
dshBeforeFlush->getSpace(sizeRequiredMinusIDD);
auto cpuBaseBeforeFlush = dshBeforeFlush->getCpuBase();
auto usedBefore = cmdContainer->getIndirectHeap(HeapType::SURFACE_STATE)->getUsed();
@@ -1526,12 +1526,12 @@ HWTEST_F(CommandEncodeStatesTest, givenKernelInfoWhenGettingRequiredDshSpaceThen
using INTERFACE_DESCRIPTOR_DATA = typename FamilyType::INTERFACE_DESCRIPTOR_DATA;
using SAMPLER_STATE = typename FamilyType::SAMPLER_STATE;
size_t additionalSize = UnitTestHelper<FamilyType>::getAdditionalDshSize();
size_t additionalSize = UnitTestHelper<FamilyType>::getAdditionalDshSize(cmdContainer->getNumIddPerBlock());
size_t expectedSize = alignUp(additionalSize, EncodeStates<FamilyType>::alignInterfaceDescriptorData);
// no samplers
kernelInfo.kernelDescriptor.payloadMappings.samplerTable.numSamplers = 0;
size_t size = EncodeDispatchKernel<FamilyType>::getSizeRequiredDsh(kernelInfo.kernelDescriptor);
size_t size = EncodeDispatchKernel<FamilyType>::getSizeRequiredDsh(kernelInfo.kernelDescriptor, cmdContainer->getNumIddPerBlock());
EXPECT_EQ(expectedSize, size);
// two samplers, no border color state
@@ -1549,7 +1549,7 @@ HWTEST_F(CommandEncodeStatesTest, givenKernelInfoWhenGettingRequiredDshSpaceThen
expectedSize = alignedSamplers;
}
size = EncodeDispatchKernel<FamilyType>::getSizeRequiredDsh(kernelInfo.kernelDescriptor);
size = EncodeDispatchKernel<FamilyType>::getSizeRequiredDsh(kernelInfo.kernelDescriptor, cmdContainer->getNumIddPerBlock());
EXPECT_EQ(expectedSize, size);
// three samplers, border color state
@@ -1565,7 +1565,7 @@ HWTEST_F(CommandEncodeStatesTest, givenKernelInfoWhenGettingRequiredDshSpaceThen
} else {
expectedSize = alignedSamplers;
}
size = EncodeDispatchKernel<FamilyType>::getSizeRequiredDsh(kernelInfo.kernelDescriptor);
size = EncodeDispatchKernel<FamilyType>::getSizeRequiredDsh(kernelInfo.kernelDescriptor, cmdContainer->getNumIddPerBlock());
EXPECT_EQ(expectedSize, size);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2022 Intel Corporation
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -17,7 +17,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandEncodeStatesTest, WhenProgrammingThenMediaInt
using MEDIA_STATE_FLUSH = typename FamilyType::MEDIA_STATE_FLUSH;
using MEDIA_INTERFACE_DESCRIPTOR_LOAD = typename FamilyType::MEDIA_INTERFACE_DESCRIPTOR_LOAD;
EncodeMediaInterfaceDescriptorLoad<FamilyType>::encode(*cmdContainer.get());
EncodeMediaInterfaceDescriptorLoad<FamilyType>::encode(*cmdContainer.get(), nullptr);
GenCmdList commands;
CmdParse<FamilyType>::parseCommandBuffer(commands, ptrOffset(cmdContainer->getCommandStream()->getCpuBase(), 0), cmdContainer->getCommandStream()->getUsed());

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2022 Intel Corporation
* Copyright (C) 2021-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -13,7 +13,7 @@ using CommandEncodeStatesTest = Test<CommandEncodeStatesFixture>;
HWTEST2_F(CommandEncodeStatesTest, givenCommandContainerWhenEncodingMediaDescriptorThenUsedSizeDidNotIncreased, IsAtLeastXeHpCore) {
auto sizeBefore = cmdContainer->getCommandStream()->getUsed();
EncodeMediaInterfaceDescriptorLoad<FamilyType>::encode(*cmdContainer.get());
EncodeMediaInterfaceDescriptorLoad<FamilyType>::encode(*cmdContainer.get(), nullptr);
auto sizeAfter = cmdContainer->getCommandStream()->getUsed();
EXPECT_EQ(sizeBefore, sizeAfter);
}