2018-04-05 01:02:07 +08:00
|
|
|
/*
|
2021-03-24 01:11:41 +08:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2018-04-05 01:02:07 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2018-04-05 01:02:07 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/memory_manager/internal_allocation_storage.h"
|
2020-11-02 22:54:01 +08:00
|
|
|
#include "shared/source/memory_manager/os_agnostic_memory_manager.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/os_context.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-05-28 20:05:12 +08:00
|
|
|
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_kernel.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "test.h"
|
2020-02-23 05:50:57 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2018-04-05 01:02:07 +08:00
|
|
|
|
2020-05-28 20:05:12 +08:00
|
|
|
typedef Test<ClDeviceFixture> KernelSubstituteTest;
|
2018-04-05 01:02:07 +08:00
|
|
|
|
|
|
|
TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithGreaterSizeThenAllocatesNewKernelAllocation) {
|
2020-01-14 21:32:11 +08:00
|
|
|
MockKernelWithInternals kernel(*pClDevice);
|
2018-04-05 01:02:07 +08:00
|
|
|
const size_t initialHeapSize = 0x40;
|
2020-05-26 15:36:04 +08:00
|
|
|
kernel.kernelInfo.heapInfo.KernelHeapSize = initialHeapSize;
|
2018-04-05 01:02:07 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(nullptr, kernel.kernelInfo.kernelAllocation);
|
2020-11-13 02:53:30 +08:00
|
|
|
kernel.kernelInfo.createKernelAllocation(*pDevice, false);
|
2018-04-05 01:02:07 +08:00
|
|
|
auto firstAllocation = kernel.kernelInfo.kernelAllocation;
|
|
|
|
EXPECT_NE(nullptr, firstAllocation);
|
|
|
|
auto firstAllocationSize = firstAllocation->getUnderlyingBufferSize();
|
2021-04-23 22:09:03 +08:00
|
|
|
size_t isaPadding = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getPaddingForISAAllocation();
|
|
|
|
EXPECT_EQ(firstAllocationSize, initialHeapSize + isaPadding);
|
2018-04-05 01:02:07 +08:00
|
|
|
|
|
|
|
auto firstAllocationId = static_cast<MemoryAllocation *>(firstAllocation)->id;
|
|
|
|
|
|
|
|
const size_t newHeapSize = initialHeapSize + 1;
|
|
|
|
char newHeap[newHeapSize];
|
|
|
|
|
2021-03-24 01:11:41 +08:00
|
|
|
kernel.mockKernel->substituteKernelHeap(newHeap, newHeapSize);
|
2018-04-05 01:02:07 +08:00
|
|
|
auto secondAllocation = kernel.kernelInfo.kernelAllocation;
|
|
|
|
EXPECT_NE(nullptr, secondAllocation);
|
|
|
|
auto secondAllocationSize = secondAllocation->getUnderlyingBufferSize();
|
2021-04-23 22:09:03 +08:00
|
|
|
EXPECT_NE(secondAllocationSize, initialHeapSize + isaPadding);
|
|
|
|
EXPECT_EQ(secondAllocationSize, newHeapSize + isaPadding);
|
2018-04-05 01:02:07 +08:00
|
|
|
auto secondAllocationId = static_cast<MemoryAllocation *>(secondAllocation)->id;
|
|
|
|
|
|
|
|
EXPECT_NE(firstAllocationId, secondAllocationId);
|
|
|
|
|
|
|
|
pDevice->getMemoryManager()->checkGpuUsageAndDestroyGraphicsAllocations(secondAllocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithSameSizeThenDoesNotAllocateNewKernelAllocation) {
|
2020-01-14 21:32:11 +08:00
|
|
|
MockKernelWithInternals kernel(*pClDevice);
|
2018-04-05 01:02:07 +08:00
|
|
|
const size_t initialHeapSize = 0x40;
|
2020-05-26 15:36:04 +08:00
|
|
|
kernel.kernelInfo.heapInfo.KernelHeapSize = initialHeapSize;
|
2018-04-05 01:02:07 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(nullptr, kernel.kernelInfo.kernelAllocation);
|
2020-11-13 02:53:30 +08:00
|
|
|
kernel.kernelInfo.createKernelAllocation(*pDevice, false);
|
2018-04-05 01:02:07 +08:00
|
|
|
auto firstAllocation = kernel.kernelInfo.kernelAllocation;
|
|
|
|
EXPECT_NE(nullptr, firstAllocation);
|
|
|
|
auto firstAllocationSize = firstAllocation->getUnderlyingBufferSize();
|
2021-04-23 22:09:03 +08:00
|
|
|
size_t isaPadding = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getPaddingForISAAllocation();
|
|
|
|
EXPECT_EQ(firstAllocationSize, initialHeapSize + isaPadding);
|
2018-04-05 01:02:07 +08:00
|
|
|
|
|
|
|
auto firstAllocationId = static_cast<MemoryAllocation *>(firstAllocation)->id;
|
|
|
|
|
|
|
|
const size_t newHeapSize = initialHeapSize;
|
|
|
|
char newHeap[newHeapSize];
|
|
|
|
|
2021-03-24 01:11:41 +08:00
|
|
|
kernel.mockKernel->substituteKernelHeap(newHeap, newHeapSize);
|
2018-04-05 01:02:07 +08:00
|
|
|
auto secondAllocation = kernel.kernelInfo.kernelAllocation;
|
|
|
|
EXPECT_NE(nullptr, secondAllocation);
|
|
|
|
auto secondAllocationSize = secondAllocation->getUnderlyingBufferSize();
|
2021-04-23 22:09:03 +08:00
|
|
|
EXPECT_EQ(secondAllocationSize, initialHeapSize + isaPadding);
|
2018-04-05 01:02:07 +08:00
|
|
|
auto secondAllocationId = static_cast<MemoryAllocation *>(secondAllocation)->id;
|
|
|
|
|
|
|
|
EXPECT_EQ(firstAllocationId, secondAllocationId);
|
|
|
|
|
|
|
|
pDevice->getMemoryManager()->checkGpuUsageAndDestroyGraphicsAllocations(secondAllocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithSmallerSizeThenDoesNotAllocateNewKernelAllocation) {
|
2020-01-14 21:32:11 +08:00
|
|
|
MockKernelWithInternals kernel(*pClDevice);
|
2018-04-05 01:02:07 +08:00
|
|
|
const size_t initialHeapSize = 0x40;
|
2020-05-26 15:36:04 +08:00
|
|
|
kernel.kernelInfo.heapInfo.KernelHeapSize = initialHeapSize;
|
2018-04-05 01:02:07 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(nullptr, kernel.kernelInfo.kernelAllocation);
|
2020-11-13 02:53:30 +08:00
|
|
|
kernel.kernelInfo.createKernelAllocation(*pDevice, false);
|
2018-04-05 01:02:07 +08:00
|
|
|
auto firstAllocation = kernel.kernelInfo.kernelAllocation;
|
|
|
|
EXPECT_NE(nullptr, firstAllocation);
|
|
|
|
auto firstAllocationSize = firstAllocation->getUnderlyingBufferSize();
|
2021-04-23 22:09:03 +08:00
|
|
|
size_t isaPadding = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getPaddingForISAAllocation();
|
|
|
|
EXPECT_EQ(firstAllocationSize, initialHeapSize + isaPadding);
|
2018-04-05 01:02:07 +08:00
|
|
|
|
|
|
|
auto firstAllocationId = static_cast<MemoryAllocation *>(firstAllocation)->id;
|
|
|
|
|
|
|
|
const size_t newHeapSize = initialHeapSize - 1;
|
|
|
|
char newHeap[newHeapSize];
|
|
|
|
|
2021-03-24 01:11:41 +08:00
|
|
|
kernel.mockKernel->substituteKernelHeap(newHeap, newHeapSize);
|
2018-04-05 01:02:07 +08:00
|
|
|
auto secondAllocation = kernel.kernelInfo.kernelAllocation;
|
|
|
|
EXPECT_NE(nullptr, secondAllocation);
|
|
|
|
auto secondAllocationSize = secondAllocation->getUnderlyingBufferSize();
|
2021-04-23 22:09:03 +08:00
|
|
|
EXPECT_EQ(secondAllocationSize, initialHeapSize + isaPadding);
|
2018-04-05 01:02:07 +08:00
|
|
|
auto secondAllocationId = static_cast<MemoryAllocation *>(secondAllocation)->id;
|
|
|
|
|
|
|
|
EXPECT_EQ(firstAllocationId, secondAllocationId);
|
|
|
|
|
|
|
|
pDevice->getMemoryManager()->checkGpuUsageAndDestroyGraphicsAllocations(secondAllocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(KernelSubstituteTest, givenKernelWithUsedKernelAllocationWhenSubstituteKernelHeapAndAllocateNewMemoryThenStoreOldAllocationOnTemporaryList) {
|
2020-01-14 21:32:11 +08:00
|
|
|
MockKernelWithInternals kernel(*pClDevice);
|
2018-04-05 01:02:07 +08:00
|
|
|
auto memoryManager = pDevice->getMemoryManager();
|
2019-07-15 20:28:09 +08:00
|
|
|
auto &commandStreamReceiver = pDevice->getGpgpuCommandStreamReceiver();
|
2018-04-05 01:02:07 +08:00
|
|
|
|
|
|
|
const size_t initialHeapSize = 0x40;
|
2020-05-26 15:36:04 +08:00
|
|
|
kernel.kernelInfo.heapInfo.KernelHeapSize = initialHeapSize;
|
2018-04-05 01:02:07 +08:00
|
|
|
|
2020-11-13 02:53:30 +08:00
|
|
|
kernel.kernelInfo.createKernelAllocation(*pDevice, false);
|
2018-04-05 01:02:07 +08:00
|
|
|
auto firstAllocation = kernel.kernelInfo.kernelAllocation;
|
|
|
|
|
2018-11-02 17:01:56 +08:00
|
|
|
uint32_t notReadyTaskCount = *commandStreamReceiver.getTagAddress() + 1u;
|
|
|
|
|
2018-12-03 17:05:36 +08:00
|
|
|
firstAllocation->updateTaskCount(notReadyTaskCount, commandStreamReceiver.getOsContext().getContextId());
|
2018-04-05 01:02:07 +08:00
|
|
|
|
|
|
|
const size_t newHeapSize = initialHeapSize + 1;
|
|
|
|
char newHeap[newHeapSize];
|
|
|
|
|
2018-10-26 19:05:31 +08:00
|
|
|
EXPECT_TRUE(commandStreamReceiver.getTemporaryAllocations().peekIsEmpty());
|
2018-04-05 01:02:07 +08:00
|
|
|
|
2021-03-24 01:11:41 +08:00
|
|
|
kernel.mockKernel->substituteKernelHeap(newHeap, newHeapSize);
|
2018-04-05 01:02:07 +08:00
|
|
|
auto secondAllocation = kernel.kernelInfo.kernelAllocation;
|
|
|
|
|
2018-10-26 19:05:31 +08:00
|
|
|
EXPECT_FALSE(commandStreamReceiver.getTemporaryAllocations().peekIsEmpty());
|
|
|
|
EXPECT_EQ(commandStreamReceiver.getTemporaryAllocations().peekHead(), firstAllocation);
|
2018-04-05 01:02:07 +08:00
|
|
|
memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(secondAllocation);
|
2018-11-02 17:01:56 +08:00
|
|
|
commandStreamReceiver.getInternalAllocationStorage()->cleanAllocationList(notReadyTaskCount, TEMPORARY_ALLOCATION);
|
2018-04-05 01:02:07 +08:00
|
|
|
}
|