mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Update kernel allocation when substitute kernel heap
Change-Id: Iee02a93d4e10c7b32fae56ffa61c90d8617d6ec9
This commit is contained in:

committed by
sys_ocldev

parent
9bc11a7f48
commit
835a1da175
@ -40,5 +40,6 @@ set(IGDRCL_SRCS_tests_kernel
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/kernel_transformable_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/debug_kernel_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/parent_kernel_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/substitute_kernel_heap_tests.cpp
|
||||
)
|
||||
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_kernel})
|
||||
|
147
unit_tests/kernel/substitute_kernel_heap_tests.cpp
Normal file
147
unit_tests/kernel/substitute_kernel_heap_tests.cpp
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "unit_tests/fixtures/device_fixture.h"
|
||||
#include "unit_tests/mocks/mock_kernel.h"
|
||||
#include "test.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
typedef Test<DeviceFixture> KernelSubstituteTest;
|
||||
|
||||
TEST_F(KernelSubstituteTest, givenKernelWhenSubstituteKernelHeapWithGreaterSizeThenAllocatesNewKernelAllocation) {
|
||||
MockKernelWithInternals kernel(*pDevice);
|
||||
auto pHeader = const_cast<SKernelBinaryHeaderCommon *>(kernel.kernelInfo.heapInfo.pKernelHeader);
|
||||
const size_t initialHeapSize = 0x40;
|
||||
pHeader->KernelHeapSize = initialHeapSize;
|
||||
|
||||
EXPECT_EQ(nullptr, kernel.kernelInfo.kernelAllocation);
|
||||
kernel.kernelInfo.createKernelAllocation(pDevice->getMemoryManager());
|
||||
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(*pDevice);
|
||||
auto pHeader = const_cast<SKernelBinaryHeaderCommon *>(kernel.kernelInfo.heapInfo.pKernelHeader);
|
||||
const size_t initialHeapSize = 0x40;
|
||||
pHeader->KernelHeapSize = initialHeapSize;
|
||||
|
||||
EXPECT_EQ(nullptr, kernel.kernelInfo.kernelAllocation);
|
||||
kernel.kernelInfo.createKernelAllocation(pDevice->getMemoryManager());
|
||||
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(*pDevice);
|
||||
auto pHeader = const_cast<SKernelBinaryHeaderCommon *>(kernel.kernelInfo.heapInfo.pKernelHeader);
|
||||
const size_t initialHeapSize = 0x40;
|
||||
pHeader->KernelHeapSize = initialHeapSize;
|
||||
|
||||
EXPECT_EQ(nullptr, kernel.kernelInfo.kernelAllocation);
|
||||
kernel.kernelInfo.createKernelAllocation(pDevice->getMemoryManager());
|
||||
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(*pDevice);
|
||||
auto pHeader = const_cast<SKernelBinaryHeaderCommon *>(kernel.kernelInfo.heapInfo.pKernelHeader);
|
||||
auto memoryManager = pDevice->getMemoryManager();
|
||||
|
||||
const size_t initialHeapSize = 0x40;
|
||||
pHeader->KernelHeapSize = initialHeapSize;
|
||||
|
||||
kernel.kernelInfo.createKernelAllocation(memoryManager);
|
||||
auto firstAllocation = kernel.kernelInfo.kernelAllocation;
|
||||
|
||||
firstAllocation->taskCount = ObjectNotUsed - 1;
|
||||
|
||||
const size_t newHeapSize = initialHeapSize + 1;
|
||||
char newHeap[newHeapSize];
|
||||
|
||||
EXPECT_TRUE(memoryManager->graphicsAllocations.peekIsEmpty());
|
||||
|
||||
kernel.mockKernel->substituteKernelHeap(newHeap, newHeapSize);
|
||||
auto secondAllocation = kernel.kernelInfo.kernelAllocation;
|
||||
|
||||
EXPECT_FALSE(memoryManager->graphicsAllocations.peekIsEmpty());
|
||||
EXPECT_EQ(memoryManager->graphicsAllocations.peekHead(), firstAllocation);
|
||||
memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(secondAllocation);
|
||||
memoryManager->cleanAllocationList(firstAllocation->taskCount, TEMPORARY_ALLOCATION);
|
||||
}
|
Reference in New Issue
Block a user