From f61ab615e7306b517b4cccd7d00cc76946c3b8f9 Mon Sep 17 00:00:00 2001 From: Zbigniew Zdanowicz Date: Mon, 22 Jul 2024 17:44:23 +0000 Subject: [PATCH] refactor: do not add bindless heaps to kernel residency Related-To: NEO-11719 Signed-off-by: Zbigniew Zdanowicz --- level_zero/core/source/kernel/kernel_imp.cpp | 11 ----------- .../test/unit_tests/sources/kernel/test_kernel.cpp | 4 +++- .../test/unit_tests/sources/kernel/test_kernel_2.cpp | 8 ++++---- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/level_zero/core/source/kernel/kernel_imp.cpp b/level_zero/core/source/kernel/kernel_imp.cpp index e0c6b805ad..dcc5d5ae5e 100644 --- a/level_zero/core/source/kernel/kernel_imp.cpp +++ b/level_zero/core/source/kernel/kernel_imp.cpp @@ -145,10 +145,6 @@ ze_result_t KernelImmutableData::initialize(NEO::KernelInfo *kernelInfo, Device } auto ssInHeap = globalConstBuffer->getBindlessInfo(); - if (ssInHeap.heapAllocation) { - this->residencyContainer.push_back(ssInHeap.heapAllocation); - } - patchImplicitArgBindlessOffsetAndSetSurfaceState(crossThreadDataArrayRef, surfaceStateHeapArrayRef, globalConstBuffer, kernelDescriptor->payloadMappings.implicitArgs.globalConstantsSurfaceAddress, *neoDevice, deviceImp->isImplicitScalingCapable(), ssInHeap, kernelInfo->kernelDescriptor); @@ -172,10 +168,6 @@ ze_result_t KernelImmutableData::initialize(NEO::KernelInfo *kernelInfo, Device } auto ssInHeap = globalVarBuffer->getBindlessInfo(); - if (ssInHeap.heapAllocation) { - this->residencyContainer.push_back(ssInHeap.heapAllocation); - } - patchImplicitArgBindlessOffsetAndSetSurfaceState(crossThreadDataArrayRef, surfaceStateHeapArrayRef, globalVarBuffer, kernelDescriptor->payloadMappings.implicitArgs.globalVariablesSurfaceAddress, *neoDevice, deviceImp->isImplicitScalingCapable(), ssInHeap, kernelInfo->kernelDescriptor); @@ -620,7 +612,6 @@ ze_result_t KernelImp::setArgRedescribedImage(uint32_t argIndex, ze_image_handle image->copyRedescribedSurfaceStateToSSH(ptrOffset(ssInHeap->ssPtr, surfaceStateSize * NEO::BindlessImageSlot::redescribedImage), 0u); isBindlessOffsetSet[argIndex] = true; - this->residencyContainer.push_back(ssInHeap->heapAllocation); } else { usingSurfaceStateHeap[argIndex] = true; auto ssPtr = ptrOffset(surfaceStateHeapData.get(), getSurfaceStateIndexForBindlessOffset(arg.bindless) * surfaceStateSize); @@ -824,7 +815,6 @@ ze_result_t KernelImp::setArgImage(uint32_t argIndex, size_t argSize, const void image->copyImplicitArgsSurfaceStateToSSH(ptrOffset(ssInHeap->ssPtr, surfaceStateSize), 0u); isBindlessOffsetSet[argIndex] = true; - this->residencyContainer.push_back(ssInHeap->heapAllocation); } else { usingSurfaceStateHeap[argIndex] = true; auto ssPtr = ptrOffset(surfaceStateHeapData.get(), getSurfaceStateIndexForBindlessOffset(arg.bindless) * surfaceStateSize); @@ -1240,7 +1230,6 @@ void *KernelImp::patchBindlessSurfaceState(NEO::GraphicsAllocation *alloc, uint3 auto &gfxCoreHelper = this->module->getDevice()->getGfxCoreHelper(); auto ssInHeap = alloc->getBindlessInfo(); - this->residencyContainer.push_back(ssInHeap.heapAllocation); auto patchLocation = ptrOffset(getCrossThreadData(), bindless); auto patchValue = gfxCoreHelper.getBindlessSurfaceExtendedMessageDescriptorValue(static_cast(ssInHeap.surfaceStateOffset)); patchWithRequiredSize(const_cast(patchLocation), sizeof(patchValue), patchValue); diff --git a/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp b/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp index bf97035c66..7384917bf6 100644 --- a/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp +++ b/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp @@ -2221,7 +2221,7 @@ TEST_F(KernelImpPatchBindlessTest, GivenKernelImpWhenPatchBindlessOffsetCalledTh EXPECT_EQ(ssPtr, expectedSsInHeap.ssPtr); EXPECT_TRUE(memcmp(const_cast(patchLocation), &patchValue, sizeof(patchValue)) == 0); - EXPECT_TRUE(std::find(kernel.getResidencyContainer().begin(), kernel.getResidencyContainer().end(), expectedSsInHeap.heapAllocation) != kernel.getResidencyContainer().end()); + EXPECT_FALSE(std::find(kernel.getResidencyContainer().begin(), kernel.getResidencyContainer().end(), expectedSsInHeap.heapAllocation) != kernel.getResidencyContainer().end()); neoDevice->decRefInternal(); } @@ -2829,6 +2829,7 @@ HWTEST2_F(SetKernelArg, givenImageAndBindlessKernelWhenSetArgImageThenCopySurfac EXPECT_EQ(imageHW->passedSurfaceStateOffset, 0u); EXPECT_TRUE(kernel->isBindlessOffsetSet[3]); EXPECT_FALSE(kernel->usingSurfaceStateHeap[3]); + EXPECT_EQ(0, std::count(kernel->residencyContainer.begin(), kernel->residencyContainer.end(), expectedSsInHeap.heapAllocation)); } HWTEST2_F(SetKernelArg, givenNoGlobalAllocatorAndBindlessKernelWhenSetArgImageThenBindlessOffsetIsNotSetAndSshIsUsed, ImageSupport) { @@ -2950,6 +2951,7 @@ HWTEST2_F(SetKernelArg, givenImageBindlessKernelAndGlobalBindlessHelperWhenSetAr EXPECT_EQ(imageHW->passedRedescribedSurfaceStateOffset, 0u); EXPECT_TRUE(kernel->isBindlessOffsetSet[3]); EXPECT_FALSE(kernel->usingSurfaceStateHeap[3]); + EXPECT_EQ(0, std::count(kernel->residencyContainer.begin(), kernel->residencyContainer.end(), expectedSsInHeap.heapAllocation)); } HWTEST2_F(SetKernelArg, givenGlobalBindlessHelperAndImageViewWhenAllocatingBindlessSlotThenViewHasDifferentSlotThanParentImage, ImageSupport) { diff --git a/level_zero/core/test/unit_tests/sources/kernel/test_kernel_2.cpp b/level_zero/core/test/unit_tests/sources/kernel/test_kernel_2.cpp index 25640bca69..950703c72f 100644 --- a/level_zero/core/test/unit_tests/sources/kernel/test_kernel_2.cpp +++ b/level_zero/core/test/unit_tests/sources/kernel/test_kernel_2.cpp @@ -710,9 +710,9 @@ HWTEST2_F(KernelImmutableDataBindlessTest, givenGlobalConstBufferAndBindlessExpl EXPECT_EQ(surfaceStateSize * kernelInfo->kernelDescriptor.kernelAttributes.numArgsStateful, kernelImmutableData->getSurfaceStateHeapSize()); auto &residencyContainer = kernelImmutableData->getResidencyContainer(); - EXPECT_EQ(2u, residencyContainer.size()); + EXPECT_EQ(1u, residencyContainer.size()); EXPECT_EQ(1, std::count(residencyContainer.begin(), residencyContainer.end(), &globalConstBuffer)); - EXPECT_EQ(1, std::count(residencyContainer.begin(), residencyContainer.end(), globalConstBuffer.getBindlessInfo().heapAllocation)); + EXPECT_EQ(0, std::count(residencyContainer.begin(), residencyContainer.end(), globalConstBuffer.getBindlessInfo().heapAllocation)); auto crossThreadData = kernelImmutableData->getCrossThreadDataTemplate(); auto patchLocation = reinterpret_cast(ptrOffset(crossThreadData, globalConstSurfaceAddressBindlessOffset)); @@ -789,9 +789,9 @@ HWTEST2_F(KernelImmutableDataBindlessTest, givenGlobalVarBufferAndBindlessExplic EXPECT_EQ(surfaceStateSize * kernelInfo->kernelDescriptor.kernelAttributes.numArgsStateful, kernelImmutableData->getSurfaceStateHeapSize()); auto &residencyContainer = kernelImmutableData->getResidencyContainer(); - EXPECT_EQ(2u, residencyContainer.size()); + EXPECT_EQ(1u, residencyContainer.size()); EXPECT_EQ(1, std::count(residencyContainer.begin(), residencyContainer.end(), &globalVarBuffer)); - EXPECT_EQ(1, std::count(residencyContainer.begin(), residencyContainer.end(), globalVarBuffer.getBindlessInfo().heapAllocation)); + EXPECT_EQ(0, std::count(residencyContainer.begin(), residencyContainer.end(), globalVarBuffer.getBindlessInfo().heapAllocation)); auto crossThreadData = kernelImmutableData->getCrossThreadDataTemplate(); auto patchLocation = reinterpret_cast(ptrOffset(crossThreadData, globalVariablesSurfaceAddressBindlessOffset));