1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
/*
* Copyright (C) 2018-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/memory_manager/internal_allocation_storage.h"
#include "shared/source/os_interface/os_context.h"
#include "opencl/source/memory_manager/os_agnostic_memory_manager.h"
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
#include "opencl/test/unit_test/mocks/mock_kernel.h"
#include "test.h"
using namespace NEO;
typedef Test<ClDeviceFixture> KernelSubstituteTest;
TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithGreaterSizeThenAllocatesNewKernelAllocation) {
MockKernelWithInternals kernel(*pClDevice);
const size_t initialHeapSize = 0x40;
kernel.kernelInfo.heapInfo.KernelHeapSize = initialHeapSize;
EXPECT_EQ(nullptr, kernel.kernelInfo.kernelAllocation);
kernel.kernelInfo.createKernelAllocation(*pDevice);
auto firstAllocation = kernel.kernelInfo.kernelAllocation;
EXPECT_NE(nullptr, firstAllocation);
auto firstAllocationSize = firstAllocation->getUnderlyingBufferSize();
EXPECT_EQ(initialHeapSize, firstAllocationSize);
auto firstAllocationId = static_cast<MemoryAllocation *>(firstAllocation)->id;
const size_t newHeapSize = initialHeapSize + 1;
char newHeap[newHeapSize];
kernel.mockKernel->substituteKernelHeap(newHeap, newHeapSize);
auto secondAllocation = kernel.kernelInfo.kernelAllocation;
EXPECT_NE(nullptr, secondAllocation);
auto secondAllocationSize = secondAllocation->getUnderlyingBufferSize();
EXPECT_NE(initialHeapSize, secondAllocationSize);
EXPECT_EQ(newHeapSize, secondAllocationSize);
auto secondAllocationId = static_cast<MemoryAllocation *>(secondAllocation)->id;
EXPECT_NE(firstAllocationId, secondAllocationId);
pDevice->getMemoryManager()->checkGpuUsageAndDestroyGraphicsAllocations(secondAllocation);
}
TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithSameSizeThenDoesNotAllocateNewKernelAllocation) {
MockKernelWithInternals kernel(*pClDevice);
const size_t initialHeapSize = 0x40;
kernel.kernelInfo.heapInfo.KernelHeapSize = initialHeapSize;
EXPECT_EQ(nullptr, kernel.kernelInfo.kernelAllocation);
kernel.kernelInfo.createKernelAllocation(*pDevice);
auto firstAllocation = kernel.kernelInfo.kernelAllocation;
EXPECT_NE(nullptr, firstAllocation);
auto firstAllocationSize = firstAllocation->getUnderlyingBufferSize();
EXPECT_EQ(initialHeapSize, firstAllocationSize);
auto firstAllocationId = static_cast<MemoryAllocation *>(firstAllocation)->id;
const size_t newHeapSize = initialHeapSize;
char newHeap[newHeapSize];
kernel.mockKernel->substituteKernelHeap(newHeap, newHeapSize);
auto secondAllocation = kernel.kernelInfo.kernelAllocation;
EXPECT_NE(nullptr, secondAllocation);
auto secondAllocationSize = secondAllocation->getUnderlyingBufferSize();
EXPECT_EQ(initialHeapSize, secondAllocationSize);
auto secondAllocationId = static_cast<MemoryAllocation *>(secondAllocation)->id;
EXPECT_EQ(firstAllocationId, secondAllocationId);
pDevice->getMemoryManager()->checkGpuUsageAndDestroyGraphicsAllocations(secondAllocation);
}
TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithSmallerSizeThenDoesNotAllocateNewKernelAllocation) {
MockKernelWithInternals kernel(*pClDevice);
const size_t initialHeapSize = 0x40;
kernel.kernelInfo.heapInfo.KernelHeapSize = initialHeapSize;
EXPECT_EQ(nullptr, kernel.kernelInfo.kernelAllocation);
kernel.kernelInfo.createKernelAllocation(*pDevice);
auto firstAllocation = kernel.kernelInfo.kernelAllocation;
EXPECT_NE(nullptr, firstAllocation);
auto firstAllocationSize = firstAllocation->getUnderlyingBufferSize();
EXPECT_EQ(initialHeapSize, firstAllocationSize);
auto firstAllocationId = static_cast<MemoryAllocation *>(firstAllocation)->id;
const size_t newHeapSize = initialHeapSize - 1;
char newHeap[newHeapSize];
kernel.mockKernel->substituteKernelHeap(newHeap, newHeapSize);
auto secondAllocation = kernel.kernelInfo.kernelAllocation;
EXPECT_NE(nullptr, secondAllocation);
auto secondAllocationSize = secondAllocation->getUnderlyingBufferSize();
EXPECT_EQ(initialHeapSize, secondAllocationSize);
auto secondAllocationId = static_cast<MemoryAllocation *>(secondAllocation)->id;
EXPECT_EQ(firstAllocationId, secondAllocationId);
pDevice->getMemoryManager()->checkGpuUsageAndDestroyGraphicsAllocations(secondAllocation);
}
TEST_F(KernelSubstituteTest, givenKernelWithUsedKernelAllocationWhenSubstituteKernelHeapAndAllocateNewMemoryThenStoreOldAllocationOnTemporaryList) {
MockKernelWithInternals kernel(*pClDevice);
auto memoryManager = pDevice->getMemoryManager();
auto &commandStreamReceiver = pDevice->getGpgpuCommandStreamReceiver();
const size_t initialHeapSize = 0x40;
kernel.kernelInfo.heapInfo.KernelHeapSize = initialHeapSize;
kernel.kernelInfo.createKernelAllocation(*pDevice);
auto firstAllocation = kernel.kernelInfo.kernelAllocation;
uint32_t notReadyTaskCount = *commandStreamReceiver.getTagAddress() + 1u;
firstAllocation->updateTaskCount(notReadyTaskCount, commandStreamReceiver.getOsContext().getContextId());
const size_t newHeapSize = initialHeapSize + 1;
char newHeap[newHeapSize];
EXPECT_TRUE(commandStreamReceiver.getTemporaryAllocations().peekIsEmpty());
kernel.mockKernel->substituteKernelHeap(newHeap, newHeapSize);
auto secondAllocation = kernel.kernelInfo.kernelAllocation;
EXPECT_FALSE(commandStreamReceiver.getTemporaryAllocations().peekIsEmpty());
EXPECT_EQ(commandStreamReceiver.getTemporaryAllocations().peekHead(), firstAllocation);
memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(secondAllocation);
commandStreamReceiver.getInternalAllocationStorage()->cleanAllocationList(notReadyTaskCount, TEMPORARY_ALLOCATION);
}
|