Update kernel allocation when substitute kernel heap

Change-Id: Iee02a93d4e10c7b32fae56ffa61c90d8617d6ec9
This commit is contained in:
Mateusz Jablonski
2018-04-04 19:02:07 +02:00
committed by sys_ocldev
parent 9bc11a7f48
commit 835a1da175
8 changed files with 219 additions and 16 deletions

View File

@ -21,16 +21,12 @@
*/
#include "runtime/program/kernel_info.h"
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
#include "gtest/gtest.h"
#include <type_traits>
#include <memory>
using OCLRT::KernelInfo;
using OCLRT::SPatchStatelessConstantMemoryObjectKernelArgument;
using OCLRT::SPatchStatelessGlobalMemoryObjectKernelArgument;
using OCLRT::SPatchGlobalMemoryObjectKernelArgument;
using OCLRT::SPatchImageMemoryObjectKernelArgument;
using OCLRT::SPatchSamplerKernelArgument;
using namespace OCLRT;
TEST(KernelInfo, NonCopyable) {
EXPECT_FALSE(std::is_move_constructible<KernelInfo>::value);
@ -129,6 +125,42 @@ TEST(KernelInfo, decodeImageKernelArgument) {
delete pKernelInfo;
}
TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationThenCopyWholeKernelHeapToKernelAllocation) {
KernelInfo kernelInfo;
OsAgnosticMemoryManager memoryManager;
SKernelBinaryHeaderCommon kernelHeader;
const size_t heapSize = 0x40;
char heap[heapSize];
kernelHeader.KernelHeapSize = heapSize;
kernelInfo.heapInfo.pKernelHeader = &kernelHeader;
kernelInfo.heapInfo.pKernelHeap = &heap;
for (size_t i = 0; i < heapSize; i++) {
heap[i] = static_cast<char>(i);
}
auto retVal = kernelInfo.createKernelAllocation(&memoryManager);
EXPECT_TRUE(retVal);
auto allocation = kernelInfo.kernelAllocation;
EXPECT_EQ(0, memcmp(allocation->getUnderlyingBuffer(), heap, heapSize));
EXPECT_EQ(heapSize, allocation->getUnderlyingBufferSize());
memoryManager.checkGpuUsageAndDestroyGraphicsAllocations(allocation);
}
class MyMemoryManager : public OsAgnosticMemoryManager {
public:
GraphicsAllocation *createInternalGraphicsAllocation(const void *ptr, size_t allocationSize) override { return nullptr; }
};
TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationAndCannotAllocateMemoryThenReturnsFalse) {
KernelInfo kernelInfo;
MyMemoryManager memoryManager;
SKernelBinaryHeaderCommon kernelHeader;
kernelInfo.heapInfo.pKernelHeader = &kernelHeader;
auto retVal = kernelInfo.createKernelAllocation(&memoryManager);
EXPECT_FALSE(retVal);
}
TEST(KernelInfo, decodeGlobalMemObjectKernelArgument) {
uint32_t argumentNumber = 1;
KernelInfo *pKernelInfo = KernelInfo::create();