Skip to content

Commit bb9d902

Browse files
Add padding for ISA allocations
Related-To: NEO-5771 Signed-off-by: Dominik Dabek <[email protected]>
1 parent 0d05ef2 commit bb9d902

File tree

11 files changed

+72
-14
lines changed

11 files changed

+72
-14
lines changed

level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,20 @@ TEST_F(KernelIsaTests, givenKernelInfoWhenInitializingImmutableDataWithNonIntern
11041104
EXPECT_EQ(NEO::GraphicsAllocation::AllocationType::KERNEL_ISA, kernelImmutableData.getIsaGraphicsAllocation()->getAllocationType());
11051105
}
11061106

1107+
TEST_F(KernelIsaTests, givenKernelInfoWhenInitializingImmutableDataWithIsaThenPaddingIsAdded) {
1108+
uint32_t kernelHeap = 0;
1109+
KernelInfo kernelInfo;
1110+
kernelInfo.heapInfo.KernelHeapSize = 1;
1111+
kernelInfo.heapInfo.pKernelHeap = &kernelHeap;
1112+
1113+
KernelImmutableData kernelImmutableData(device);
1114+
kernelImmutableData.initialize(&kernelInfo, device, 0, nullptr, nullptr, false);
1115+
auto graphicsAllocation = kernelImmutableData.getIsaGraphicsAllocation();
1116+
auto &hwHelper = NEO::HwHelper::get(device->getHwInfo().platform.eRenderCoreFamily);
1117+
size_t isaPadding = hwHelper.getPaddingForISAAllocation();
1118+
EXPECT_EQ(graphicsAllocation->getUnderlyingBufferSize(), kernelInfo.heapInfo.KernelHeapSize + isaPadding);
1119+
}
1120+
11071121
TEST_F(KernelIsaTests, givenGlobalBuffersWhenCreatingKernelImmutableDataThenBuffersAreAddedToResidencyContainer) {
11081122
uint32_t kernelHeap = 0;
11091123
KernelInfo kernelInfo;

opencl/source/kernel/kernel.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,11 @@ void Kernel::substituteKernelHeap(void *newKernelHeap, size_t newKernelHeapSize)
734734

735735
auto currentAllocationSize = pKernelInfo->kernelAllocation->getUnderlyingBufferSize();
736736
bool status = false;
737-
if (currentAllocationSize >= newKernelHeapSize) {
737+
738+
const auto &hwInfo = clDevice.getHardwareInfo();
739+
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
740+
size_t isaPadding = hwHelper.getPaddingForISAAllocation();
741+
if (currentAllocationSize >= newKernelHeapSize + isaPadding) {
738742
auto &hwInfo = clDevice.getDevice().getHardwareInfo();
739743
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
740744
status = MemoryTransferHelper::transferMemoryToAllocation(hwHelper.isBlitCopyRequiredForLocalMemory(hwInfo, *pKernelInfo->getGraphicsAllocation()),

opencl/test/unit_test/fixtures/kernel_data_fixture.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ void KernelDataTest::buildAndDecode() {
116116
if (kernelHeapSize) {
117117
auto kernelAllocation = pKernelInfo->getGraphicsAllocation();
118118
UNRECOVERABLE_IF(kernelAllocation == nullptr);
119-
EXPECT_EQ(kernelAllocation->getUnderlyingBufferSize(), kernelHeapSize);
119+
auto &device = pContext->getDevice(0)->getDevice();
120+
auto &hwHelper = NEO::HwHelper::get(device.getHardwareInfo().platform.eRenderCoreFamily);
121+
size_t isaPadding = hwHelper.getPaddingForISAAllocation();
122+
EXPECT_EQ(kernelAllocation->getUnderlyingBufferSize(), kernelHeapSize + isaPadding);
120123
auto kernelIsa = kernelAllocation->getUnderlyingBuffer();
121124
EXPECT_EQ(0, memcmp(kernelIsa, pKernelInfo->heapInfo.pKernelHeap, kernelHeapSize));
122125
} else {

opencl/test/unit_test/helpers/hw_helper_default_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*

opencl/test/unit_test/kernel/kernel_tests.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2468,7 +2468,25 @@ TEST(KernelInfoTest, GivenArgNameWhenGettingArgNumberByNameThenCorrectValueIsRet
24682468
EXPECT_EQ(-1, info.getArgNumByName("arg1"));
24692469
}
24702470

2471-
TEST(KernelTest, GivenNormalKernelWhenGettingInstructionHeapSizeForExecutionModelThenZeroIsReturned) {
2471+
TEST(KernelInfoTest, givenHwHelperWhenCreatingKernelAllocationThenCorrectPaddingIsAdded) {
2472+
2473+
std::unique_ptr<MockClDevice> clDevice = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get(), mockRootDeviceIndex));
2474+
std::unique_ptr<MockContext> context = std::make_unique<MockContext>(clDevice.get());
2475+
2476+
std::unique_ptr<MockKernelWithInternals> mockKernel = std::make_unique<MockKernelWithInternals>(*clDevice, context.get());
2477+
uint32_t kernelHeap = 0;
2478+
mockKernel->kernelInfo.heapInfo.KernelHeapSize = 1;
2479+
mockKernel->kernelInfo.heapInfo.pKernelHeap = &kernelHeap;
2480+
mockKernel->kernelInfo.createKernelAllocation(clDevice->getDevice(), false);
2481+
2482+
auto graphicsAllocation = mockKernel->kernelInfo.getGraphicsAllocation();
2483+
auto &hwHelper = NEO::HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily);
2484+
size_t isaPadding = hwHelper.getPaddingForISAAllocation();
2485+
EXPECT_EQ(graphicsAllocation->getUnderlyingBufferSize(), mockKernel->kernelInfo.heapInfo.KernelHeapSize + isaPadding);
2486+
clDevice->getMemoryManager()->freeGraphicsMemory(mockKernel->kernelInfo.getGraphicsAllocation());
2487+
}
2488+
2489+
TEST(KernelTest, givenNormalKernelWhenGettingInstructionHeapSizeForExecutionModelThenZeroIsReturned) {
24722490
auto device = clUniquePtr(new MockClDevice(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get())));
24732491
MockKernelWithInternals kernel(*device);
24742492

opencl/test/unit_test/kernel/substitute_kernel_heap_tests.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithGreaterSizeT
2727
auto firstAllocation = kernel.kernelInfo.kernelAllocation;
2828
EXPECT_NE(nullptr, firstAllocation);
2929
auto firstAllocationSize = firstAllocation->getUnderlyingBufferSize();
30-
EXPECT_EQ(initialHeapSize, firstAllocationSize);
30+
size_t isaPadding = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getPaddingForISAAllocation();
31+
EXPECT_EQ(firstAllocationSize, initialHeapSize + isaPadding);
3132

3233
auto firstAllocationId = static_cast<MemoryAllocation *>(firstAllocation)->id;
3334

@@ -38,8 +39,8 @@ TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithGreaterSizeT
3839
auto secondAllocation = kernel.kernelInfo.kernelAllocation;
3940
EXPECT_NE(nullptr, secondAllocation);
4041
auto secondAllocationSize = secondAllocation->getUnderlyingBufferSize();
41-
EXPECT_NE(initialHeapSize, secondAllocationSize);
42-
EXPECT_EQ(newHeapSize, secondAllocationSize);
42+
EXPECT_NE(secondAllocationSize, initialHeapSize + isaPadding);
43+
EXPECT_EQ(secondAllocationSize, newHeapSize + isaPadding);
4344
auto secondAllocationId = static_cast<MemoryAllocation *>(secondAllocation)->id;
4445

4546
EXPECT_NE(firstAllocationId, secondAllocationId);
@@ -57,7 +58,8 @@ TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithSameSizeThen
5758
auto firstAllocation = kernel.kernelInfo.kernelAllocation;
5859
EXPECT_NE(nullptr, firstAllocation);
5960
auto firstAllocationSize = firstAllocation->getUnderlyingBufferSize();
60-
EXPECT_EQ(initialHeapSize, firstAllocationSize);
61+
size_t isaPadding = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getPaddingForISAAllocation();
62+
EXPECT_EQ(firstAllocationSize, initialHeapSize + isaPadding);
6163

6264
auto firstAllocationId = static_cast<MemoryAllocation *>(firstAllocation)->id;
6365

@@ -68,7 +70,7 @@ TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithSameSizeThen
6870
auto secondAllocation = kernel.kernelInfo.kernelAllocation;
6971
EXPECT_NE(nullptr, secondAllocation);
7072
auto secondAllocationSize = secondAllocation->getUnderlyingBufferSize();
71-
EXPECT_EQ(initialHeapSize, secondAllocationSize);
73+
EXPECT_EQ(secondAllocationSize, initialHeapSize + isaPadding);
7274
auto secondAllocationId = static_cast<MemoryAllocation *>(secondAllocation)->id;
7375

7476
EXPECT_EQ(firstAllocationId, secondAllocationId);
@@ -86,7 +88,8 @@ TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithSmallerSizeT
8688
auto firstAllocation = kernel.kernelInfo.kernelAllocation;
8789
EXPECT_NE(nullptr, firstAllocation);
8890
auto firstAllocationSize = firstAllocation->getUnderlyingBufferSize();
89-
EXPECT_EQ(initialHeapSize, firstAllocationSize);
91+
size_t isaPadding = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getPaddingForISAAllocation();
92+
EXPECT_EQ(firstAllocationSize, initialHeapSize + isaPadding);
9093

9194
auto firstAllocationId = static_cast<MemoryAllocation *>(firstAllocation)->id;
9295

@@ -97,7 +100,7 @@ TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithSmallerSizeT
97100
auto secondAllocation = kernel.kernelInfo.kernelAllocation;
98101
EXPECT_NE(nullptr, secondAllocation);
99102
auto secondAllocationSize = secondAllocation->getUnderlyingBufferSize();
100-
EXPECT_EQ(initialHeapSize, secondAllocationSize);
103+
EXPECT_EQ(secondAllocationSize, initialHeapSize + isaPadding);
101104
auto secondAllocationId = static_cast<MemoryAllocation *>(secondAllocation)->id;
102105

103106
EXPECT_EQ(firstAllocationId, secondAllocationId);

opencl/test/unit_test/program/kernel_info_tests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationThenCopyWholeKerne
4545
EXPECT_TRUE(retVal);
4646
auto allocation = kernelInfo.kernelAllocation;
4747
EXPECT_EQ(0, memcmp(allocation->getUnderlyingBuffer(), heap, heapSize));
48-
EXPECT_EQ(heapSize, allocation->getUnderlyingBufferSize());
48+
size_t isaPadding = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getPaddingForISAAllocation();
49+
EXPECT_EQ(allocation->getUnderlyingBufferSize(), heapSize + isaPadding);
4950
device->getMemoryManager()->checkGpuUsageAndDestroyGraphicsAllocations(allocation);
5051
}
5152

opencl/test/unit_test/program/program_tests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ TEST_F(ProgramFromBinaryTest, givenProgramWhenItIsBeingBuildThenItContainsGraphi
579579
auto graphicsAllocation = kernelInfo->getGraphicsAllocation();
580580
ASSERT_NE(nullptr, graphicsAllocation);
581581
EXPECT_TRUE(graphicsAllocation->is32BitAllocation());
582-
EXPECT_EQ(graphicsAllocation->getUnderlyingBufferSize(), kernelInfo->heapInfo.KernelHeapSize);
582+
auto &hwHelper = NEO::HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily);
583+
size_t isaPadding = hwHelper.getPaddingForISAAllocation();
584+
EXPECT_EQ(graphicsAllocation->getUnderlyingBufferSize(), kernelInfo->heapInfo.KernelHeapSize + isaPadding);
583585

584586
auto kernelIsa = graphicsAllocation->getUnderlyingBuffer();
585587
EXPECT_NE(kernelInfo->heapInfo.pKernelHeap, kernelIsa);

shared/source/helpers/hw_helper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class HwHelper {
4848
virtual uint32_t getBindingTableStateAlignement() const = 0;
4949
virtual size_t getInterfaceDescriptorDataSize() const = 0;
5050
virtual size_t getMaxBarrierRegisterPerSlice() const = 0;
51+
virtual size_t getPaddingForISAAllocation() const = 0;
5152
virtual uint32_t getComputeUnitsUsedForScratch(const HardwareInfo *pHwInfo) const = 0;
5253
virtual uint32_t getPitchAlignmentForImage(const HardwareInfo *hwInfo) const = 0;
5354
virtual uint32_t getMaxNumSamplers() const = 0;
@@ -197,6 +198,8 @@ class HwHelperHw : public HwHelper {
197198

198199
size_t getMaxBarrierRegisterPerSlice() const override;
199200

201+
size_t getPaddingForISAAllocation() const override;
202+
200203
uint32_t getMaxThreadsForWorkgroup(const HardwareInfo &hwInfo, uint32_t maxNumEUsPerSubSlice) const override;
201204

202205
uint32_t getComputeUnitsUsedForScratch(const HardwareInfo *pHwInfo) const override;

shared/source/helpers/hw_helper_base.inl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ size_t HwHelperHw<Family>::getMaxBarrierRegisterPerSlice() const {
5959
return 32;
6060
}
6161

62+
template <typename Family>
63+
size_t HwHelperHw<Family>::getPaddingForISAAllocation() const {
64+
return 512;
65+
}
66+
6267
template <typename Family>
6368
uint32_t HwHelperHw<Family>::getPitchAlignmentForImage(const HardwareInfo *hwInfo) const {
6469
return 4u;

0 commit comments

Comments
 (0)