mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-22 10:17:01 +08:00
Program refactor
* decouple program_info * move global allocations relocation to linker * remove obsolete tests * initial cleanup to kernel_info kernelInfo * unified patchtoken validation Change-Id: I0567cd6d607b4f3cf44e6caf33681f6210760f76
This commit is contained in:
committed by
sys_ocldev
parent
570b09850d
commit
f057712fa7
@@ -9,6 +9,7 @@
|
||||
#include "core/memory_manager/allocations_list.h"
|
||||
#include "core/memory_manager/graphics_allocation.h"
|
||||
#include "core/memory_manager/unified_memory_manager.h"
|
||||
#include "core/program/program_info_from_patchtokens.h"
|
||||
#include "core/unit_tests/compiler_interface/linker_mock.h"
|
||||
#include "runtime/platform/platform.h"
|
||||
#include "runtime/program/program.h"
|
||||
@@ -184,12 +185,14 @@ TEST_F(ProgramDataTest, whenGlobalConstantsAreExportedThenAllocateSurfacesAsSvm)
|
||||
return;
|
||||
}
|
||||
|
||||
setupConstantAllocation();
|
||||
char constantData[128] = {};
|
||||
ProgramInfo programInfo;
|
||||
programInfo.globalConstants.initData = constantData;
|
||||
programInfo.globalConstants.size = sizeof(constantData);
|
||||
std::unique_ptr<WhiteBox<NEO::LinkerInput>> mockLinkerInput = std::make_unique<WhiteBox<NEO::LinkerInput>>();
|
||||
mockLinkerInput->traits.exportsGlobalConstants = true;
|
||||
static_cast<MockProgram *>(pProgram)->linkerInput = std::move(mockLinkerInput);
|
||||
|
||||
buildAndDecodeProgramPatchList();
|
||||
programInfo.linkerInput = std::move(mockLinkerInput);
|
||||
this->pProgram->processProgramInfo(programInfo);
|
||||
|
||||
ASSERT_NE(nullptr, pProgram->getConstantSurface());
|
||||
EXPECT_NE(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast<const void *>(pProgram->getConstantSurface()->getGpuAddress())));
|
||||
@@ -200,15 +203,14 @@ TEST_F(ProgramDataTest, whenGlobalConstantsAreNotExportedThenAllocateSurfacesAsN
|
||||
return;
|
||||
}
|
||||
|
||||
setupConstantAllocation();
|
||||
char constantData[128] = {};
|
||||
ProgramInfo programInfo;
|
||||
programInfo.globalConstants.initData = constantData;
|
||||
programInfo.globalConstants.size = sizeof(constantData);
|
||||
std::unique_ptr<WhiteBox<NEO::LinkerInput>> mockLinkerInput = std::make_unique<WhiteBox<NEO::LinkerInput>>();
|
||||
mockLinkerInput->traits.exportsGlobalConstants = false;
|
||||
static_cast<MockProgram *>(pProgram)->linkerInput = std::move(mockLinkerInput);
|
||||
static_cast<MockProgram *>(pProgram)->context = nullptr;
|
||||
|
||||
buildAndDecodeProgramPatchList();
|
||||
|
||||
static_cast<MockProgram *>(pProgram)->context = pContext;
|
||||
programInfo.linkerInput = std::move(mockLinkerInput);
|
||||
this->pProgram->processProgramInfo(programInfo);
|
||||
|
||||
ASSERT_NE(nullptr, pProgram->getConstantSurface());
|
||||
EXPECT_EQ(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast<const void *>(pProgram->getConstantSurface()->getGpuAddress())));
|
||||
@@ -219,15 +221,19 @@ TEST_F(ProgramDataTest, whenGlobalConstantsAreExportedButContextUnavailableThenA
|
||||
return;
|
||||
}
|
||||
|
||||
setupConstantAllocation();
|
||||
char constantData[128] = {};
|
||||
ProgramInfo programInfo;
|
||||
programInfo.globalConstants.initData = constantData;
|
||||
programInfo.globalConstants.size = sizeof(constantData);
|
||||
std::unique_ptr<WhiteBox<NEO::LinkerInput>> mockLinkerInput = std::make_unique<WhiteBox<NEO::LinkerInput>>();
|
||||
mockLinkerInput->traits.exportsGlobalConstants = true;
|
||||
static_cast<MockProgram *>(pProgram)->linkerInput = std::move(mockLinkerInput);
|
||||
static_cast<MockProgram *>(pProgram)->context = nullptr;
|
||||
programInfo.linkerInput = std::move(mockLinkerInput);
|
||||
|
||||
buildAndDecodeProgramPatchList();
|
||||
pProgram->context = nullptr;
|
||||
|
||||
static_cast<MockProgram *>(pProgram)->context = pContext;
|
||||
this->pProgram->processProgramInfo(programInfo);
|
||||
|
||||
pProgram->context = pContext;
|
||||
|
||||
ASSERT_NE(nullptr, pProgram->getConstantSurface());
|
||||
EXPECT_EQ(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast<const void *>(pProgram->getConstantSurface()->getGpuAddress())));
|
||||
@@ -237,12 +243,14 @@ TEST_F(ProgramDataTest, whenGlobalVariablesAreExportedThenAllocateSurfacesAsSvm)
|
||||
if (this->pContext->getSVMAllocsManager() == nullptr) {
|
||||
return;
|
||||
}
|
||||
setupGlobalAllocation();
|
||||
char globalData[128] = {};
|
||||
ProgramInfo programInfo;
|
||||
programInfo.globalVariables.initData = globalData;
|
||||
programInfo.globalVariables.size = sizeof(globalData);
|
||||
std::unique_ptr<WhiteBox<NEO::LinkerInput>> mockLinkerInput = std::make_unique<WhiteBox<NEO::LinkerInput>>();
|
||||
mockLinkerInput->traits.exportsGlobalVariables = true;
|
||||
static_cast<MockProgram *>(pProgram)->linkerInput = std::move(mockLinkerInput);
|
||||
|
||||
buildAndDecodeProgramPatchList();
|
||||
programInfo.linkerInput = std::move(mockLinkerInput);
|
||||
this->pProgram->processProgramInfo(programInfo);
|
||||
|
||||
ASSERT_NE(nullptr, pProgram->getGlobalSurface());
|
||||
EXPECT_NE(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast<const void *>(pProgram->getGlobalSurface()->getGpuAddress())));
|
||||
@@ -253,15 +261,19 @@ TEST_F(ProgramDataTest, whenGlobalVariablesAreExportedButContextUnavailableThenA
|
||||
return;
|
||||
}
|
||||
|
||||
setupGlobalAllocation();
|
||||
char globalData[128] = {};
|
||||
ProgramInfo programInfo;
|
||||
programInfo.globalVariables.initData = globalData;
|
||||
programInfo.globalVariables.size = sizeof(globalData);
|
||||
std::unique_ptr<WhiteBox<NEO::LinkerInput>> mockLinkerInput = std::make_unique<WhiteBox<NEO::LinkerInput>>();
|
||||
mockLinkerInput->traits.exportsGlobalVariables = true;
|
||||
static_cast<MockProgram *>(pProgram)->linkerInput = std::move(mockLinkerInput);
|
||||
static_cast<MockProgram *>(pProgram)->context = nullptr;
|
||||
programInfo.linkerInput = std::move(mockLinkerInput);
|
||||
|
||||
buildAndDecodeProgramPatchList();
|
||||
pProgram->context = nullptr;
|
||||
|
||||
static_cast<MockProgram *>(pProgram)->context = pContext;
|
||||
this->pProgram->processProgramInfo(programInfo);
|
||||
|
||||
pProgram->context = pContext;
|
||||
|
||||
ASSERT_NE(nullptr, pProgram->getGlobalSurface());
|
||||
EXPECT_EQ(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast<const void *>(pProgram->getGlobalSurface()->getGpuAddress())));
|
||||
@@ -272,15 +284,14 @@ TEST_F(ProgramDataTest, whenGlobalVariablesAreNotExportedThenAllocateSurfacesAsN
|
||||
return;
|
||||
}
|
||||
|
||||
setupGlobalAllocation();
|
||||
char globalData[128] = {};
|
||||
ProgramInfo programInfo;
|
||||
programInfo.globalVariables.initData = globalData;
|
||||
programInfo.globalVariables.size = sizeof(globalData);
|
||||
std::unique_ptr<WhiteBox<NEO::LinkerInput>> mockLinkerInput = std::make_unique<WhiteBox<NEO::LinkerInput>>();
|
||||
mockLinkerInput->traits.exportsGlobalVariables = false;
|
||||
static_cast<MockProgram *>(pProgram)->linkerInput = std::move(mockLinkerInput);
|
||||
static_cast<MockProgram *>(pProgram)->context = nullptr;
|
||||
|
||||
buildAndDecodeProgramPatchList();
|
||||
|
||||
static_cast<MockProgram *>(pProgram)->context = pContext;
|
||||
programInfo.linkerInput = std::move(mockLinkerInput);
|
||||
this->pProgram->processProgramInfo(programInfo);
|
||||
|
||||
ASSERT_NE(nullptr, pProgram->getGlobalSurface());
|
||||
EXPECT_EQ(nullptr, this->pContext->getSVMAllocsManager()->getSVMAlloc(reinterpret_cast<const void *>(pProgram->getGlobalSurface()->getGpuAddress())));
|
||||
@@ -342,167 +353,6 @@ TEST_F(ProgramDataTest, AllocateGlobalMemorySurfaceProgramBinaryInfo) {
|
||||
EXPECT_EQ(0, memcmp(globalValue, pProgram->getGlobalSurface()->getUnderlyingBuffer(), globalSize));
|
||||
}
|
||||
|
||||
TEST_F(ProgramDataTest, GlobalPointerProgramBinaryInfo) {
|
||||
char globalValue;
|
||||
char *pGlobalPointerValue = &globalValue;
|
||||
size_t globalPointerSize = sizeof(pGlobalPointerValue);
|
||||
char *ptr;
|
||||
|
||||
// simulate case when global surface was not allocated
|
||||
EXPECT_EQ(nullptr, pProgram->getGlobalSurface());
|
||||
|
||||
SPatchGlobalPointerProgramBinaryInfo globalPointer;
|
||||
globalPointer.Token = PATCH_TOKEN_GLOBAL_POINTER_PROGRAM_BINARY_INFO;
|
||||
globalPointer.Size = sizeof(SPatchGlobalPointerProgramBinaryInfo);
|
||||
|
||||
globalPointer.GlobalBufferIndex = 0;
|
||||
globalPointer.GlobalPointerOffset = 0;
|
||||
globalPointer.BufferIndex = 0;
|
||||
globalPointer.BufferType = PROGRAM_SCOPE_GLOBAL_BUFFER;
|
||||
|
||||
cl_char *pGlobalPointer = new cl_char[globalPointer.Size];
|
||||
memcpy_s(pGlobalPointer,
|
||||
sizeof(SPatchGlobalPointerProgramBinaryInfo),
|
||||
&globalPointer,
|
||||
sizeof(SPatchGlobalPointerProgramBinaryInfo));
|
||||
pProgramPatchList = (void *)pGlobalPointer;
|
||||
programPatchListSize = globalPointer.Size;
|
||||
|
||||
this->allowDecodeFailure = true;
|
||||
buildAndDecodeProgramPatchList();
|
||||
EXPECT_EQ(nullptr, pProgram->getGlobalSurface());
|
||||
EXPECT_EQ(CL_INVALID_BINARY, this->patchlistDecodeErrorCode);
|
||||
this->allowDecodeFailure = false;
|
||||
|
||||
delete[] pGlobalPointer;
|
||||
|
||||
// regular case - global surface exists
|
||||
SPatchAllocateGlobalMemorySurfaceProgramBinaryInfo allocateGlobalMemorySurface;
|
||||
allocateGlobalMemorySurface.Token = PATCH_TOKEN_ALLOCATE_GLOBAL_MEMORY_SURFACE_PROGRAM_BINARY_INFO;
|
||||
allocateGlobalMemorySurface.Size = static_cast<uint32_t>(sizeof(SPatchAllocateGlobalMemorySurfaceProgramBinaryInfo));
|
||||
allocateGlobalMemorySurface.GlobalBufferIndex = 0;
|
||||
allocateGlobalMemorySurface.InlineDataSize = static_cast<uint32_t>(globalPointerSize);
|
||||
|
||||
cl_char *pAllocateGlobalMemorySurface = new cl_char[allocateGlobalMemorySurface.Size + globalPointerSize];
|
||||
|
||||
memcpy_s(pAllocateGlobalMemorySurface,
|
||||
sizeof(SPatchAllocateGlobalMemorySurfaceProgramBinaryInfo),
|
||||
&allocateGlobalMemorySurface,
|
||||
sizeof(SPatchAllocateGlobalMemorySurfaceProgramBinaryInfo));
|
||||
memcpy_s((cl_char *)pAllocateGlobalMemorySurface + sizeof(allocateGlobalMemorySurface), globalPointerSize, &pGlobalPointerValue, globalPointerSize);
|
||||
|
||||
pProgramPatchList = pAllocateGlobalMemorySurface;
|
||||
programPatchListSize = static_cast<uint32_t>(allocateGlobalMemorySurface.Size + globalPointerSize);
|
||||
buildAndDecodeProgramPatchList();
|
||||
|
||||
EXPECT_NE(nullptr, pProgram->getGlobalSurface());
|
||||
|
||||
auto globalSurface = pProgram->getGlobalSurface();
|
||||
|
||||
globalSurface->setCpuPtrAndGpuAddress(globalSurface->getUnderlyingBuffer(), globalSurface->getGpuAddress() + 1);
|
||||
EXPECT_NE(reinterpret_cast<uint64_t>(globalSurface->getUnderlyingBuffer()), globalSurface->getGpuAddress());
|
||||
EXPECT_EQ(0, memcmp(&pGlobalPointerValue, globalSurface->getUnderlyingBuffer(), globalPointerSize));
|
||||
|
||||
delete[] pAllocateGlobalMemorySurface;
|
||||
|
||||
// global pointer to global surface - simulate invalid GlobalBufferIndex
|
||||
globalPointer.Token = PATCH_TOKEN_GLOBAL_POINTER_PROGRAM_BINARY_INFO;
|
||||
globalPointer.Size = sizeof(SPatchGlobalPointerProgramBinaryInfo);
|
||||
|
||||
globalPointer.GlobalBufferIndex = 10;
|
||||
globalPointer.GlobalPointerOffset = 0;
|
||||
globalPointer.BufferIndex = 0;
|
||||
globalPointer.BufferType = PROGRAM_SCOPE_GLOBAL_BUFFER;
|
||||
|
||||
pGlobalPointer = new cl_char[globalPointer.Size];
|
||||
memcpy_s(pGlobalPointer,
|
||||
sizeof(SPatchGlobalPointerProgramBinaryInfo),
|
||||
&globalPointer,
|
||||
sizeof(SPatchGlobalPointerProgramBinaryInfo));
|
||||
pProgramPatchList = (void *)pGlobalPointer;
|
||||
programPatchListSize = globalPointer.Size;
|
||||
this->allowDecodeFailure = true;
|
||||
buildAndDecodeProgramPatchList();
|
||||
|
||||
EXPECT_EQ(0, memcmp(&pGlobalPointerValue, globalSurface->getUnderlyingBuffer(), globalPointerSize));
|
||||
|
||||
delete[] pGlobalPointer;
|
||||
|
||||
// global pointer to global surface - simulate invalid BufferIndex
|
||||
globalPointer.Token = PATCH_TOKEN_GLOBAL_POINTER_PROGRAM_BINARY_INFO;
|
||||
globalPointer.Size = sizeof(SPatchGlobalPointerProgramBinaryInfo);
|
||||
|
||||
globalPointer.GlobalBufferIndex = 0;
|
||||
globalPointer.GlobalPointerOffset = 0;
|
||||
globalPointer.BufferIndex = 10;
|
||||
globalPointer.BufferType = PROGRAM_SCOPE_GLOBAL_BUFFER;
|
||||
|
||||
pGlobalPointer = new cl_char[globalPointer.Size];
|
||||
memcpy_s(pGlobalPointer,
|
||||
sizeof(SPatchGlobalPointerProgramBinaryInfo),
|
||||
&globalPointer,
|
||||
sizeof(SPatchGlobalPointerProgramBinaryInfo));
|
||||
pProgramPatchList = (void *)pGlobalPointer;
|
||||
programPatchListSize = globalPointer.Size;
|
||||
this->allowDecodeFailure = true;
|
||||
buildAndDecodeProgramPatchList();
|
||||
|
||||
EXPECT_EQ(0, memcmp(&pGlobalPointerValue, globalSurface->getUnderlyingBuffer(), globalPointerSize));
|
||||
|
||||
delete[] pGlobalPointer;
|
||||
|
||||
// global pointer to global surface - simulate invalid BufferType
|
||||
globalPointer.Token = PATCH_TOKEN_GLOBAL_POINTER_PROGRAM_BINARY_INFO;
|
||||
globalPointer.Size = sizeof(SPatchGlobalPointerProgramBinaryInfo);
|
||||
|
||||
globalPointer.GlobalBufferIndex = 0;
|
||||
globalPointer.GlobalPointerOffset = 0;
|
||||
globalPointer.BufferIndex = 0;
|
||||
globalPointer.BufferType = PROGRAM_SCOPE_CONSTANT_BUFFER;
|
||||
|
||||
pGlobalPointer = new cl_char[globalPointer.Size];
|
||||
memcpy_s(pGlobalPointer,
|
||||
sizeof(SPatchGlobalPointerProgramBinaryInfo),
|
||||
&globalPointer,
|
||||
sizeof(SPatchGlobalPointerProgramBinaryInfo));
|
||||
pProgramPatchList = (void *)pGlobalPointer;
|
||||
programPatchListSize = globalPointer.Size;
|
||||
|
||||
buildAndDecodeProgramPatchList();
|
||||
|
||||
EXPECT_EQ(0, memcmp(&pGlobalPointerValue, globalSurface->getUnderlyingBuffer(), globalPointerSize));
|
||||
|
||||
delete[] pGlobalPointer;
|
||||
|
||||
// regular case - global pointer to global surface - all parameters valid
|
||||
this->pProgram->skipValidationOfBinary = true;
|
||||
this->allowDecodeFailure = false;
|
||||
globalPointer.Token = PATCH_TOKEN_GLOBAL_POINTER_PROGRAM_BINARY_INFO;
|
||||
globalPointer.Size = sizeof(SPatchGlobalPointerProgramBinaryInfo);
|
||||
|
||||
globalPointer.GlobalBufferIndex = 0;
|
||||
globalPointer.GlobalPointerOffset = 0;
|
||||
globalPointer.BufferIndex = 0;
|
||||
globalPointer.BufferType = PROGRAM_SCOPE_GLOBAL_BUFFER;
|
||||
|
||||
pGlobalPointer = new cl_char[globalPointer.Size];
|
||||
memcpy_s(pGlobalPointer,
|
||||
sizeof(SPatchGlobalPointerProgramBinaryInfo),
|
||||
&globalPointer,
|
||||
sizeof(SPatchGlobalPointerProgramBinaryInfo));
|
||||
|
||||
pProgramPatchList = (void *)pGlobalPointer;
|
||||
programPatchListSize = globalPointer.Size;
|
||||
buildAndDecodeProgramPatchList();
|
||||
|
||||
if (!globalSurface->is32BitAllocation()) {
|
||||
EXPECT_NE(0, memcmp(&pGlobalPointerValue, globalSurface->getUnderlyingBuffer(), globalPointerSize));
|
||||
ptr = pGlobalPointerValue + (globalSurface->getGpuAddressToPatch());
|
||||
EXPECT_EQ(0, memcmp(&ptr, globalSurface->getUnderlyingBuffer(), globalPointerSize));
|
||||
}
|
||||
delete[] pGlobalPointer;
|
||||
}
|
||||
|
||||
TEST_F(ProgramDataTest, Given32BitDeviceWhenGlobalMemorySurfaceIsPresentThenItHas32BitStorage) {
|
||||
char globalValue[] = "55667788";
|
||||
size_t globalSize = strlen(globalValue) + 1;
|
||||
@@ -539,188 +389,6 @@ TEST_F(ProgramDataTest, Given32BitDeviceWhenGlobalMemorySurfaceIsPresentThenItHa
|
||||
delete[] pAllocateGlobalMemorySurface;
|
||||
}
|
||||
|
||||
TEST_F(ProgramDataTest, ConstantPointerProgramBinaryInfo) {
|
||||
const char *pConstantData = "01234567";
|
||||
size_t constantDataLen = strlen(pConstantData);
|
||||
|
||||
// simulate case when constant surface was not allocated
|
||||
EXPECT_EQ(nullptr, pProgram->getConstantSurface());
|
||||
|
||||
SPatchConstantPointerProgramBinaryInfo constantPointer;
|
||||
constantPointer.Token = PATCH_TOKEN_CONSTANT_POINTER_PROGRAM_BINARY_INFO;
|
||||
constantPointer.Size = sizeof(SPatchConstantPointerProgramBinaryInfo);
|
||||
constantPointer.ConstantBufferIndex = 0;
|
||||
constantPointer.ConstantPointerOffset = 0;
|
||||
constantPointer.BufferIndex = 0;
|
||||
constantPointer.BufferType = PROGRAM_SCOPE_CONSTANT_BUFFER;
|
||||
|
||||
cl_char *pConstantPointer = new cl_char[constantPointer.Size];
|
||||
memcpy_s(pConstantPointer,
|
||||
sizeof(SPatchConstantPointerProgramBinaryInfo),
|
||||
&constantPointer,
|
||||
sizeof(SPatchConstantPointerProgramBinaryInfo));
|
||||
pProgramPatchList = (void *)pConstantPointer;
|
||||
programPatchListSize = constantPointer.Size;
|
||||
|
||||
this->allowDecodeFailure = true;
|
||||
buildAndDecodeProgramPatchList();
|
||||
EXPECT_EQ(nullptr, pProgram->getConstantSurface());
|
||||
EXPECT_EQ(CL_INVALID_BINARY, this->patchlistDecodeErrorCode);
|
||||
this->allowDecodeFailure = false;
|
||||
|
||||
delete[] pConstantPointer;
|
||||
|
||||
// regular case - constant surface exists
|
||||
SPatchAllocateConstantMemorySurfaceProgramBinaryInfo allocateConstMemorySurface;
|
||||
allocateConstMemorySurface.Token = PATCH_TOKEN_ALLOCATE_CONSTANT_MEMORY_SURFACE_PROGRAM_BINARY_INFO;
|
||||
// note : + sizeof(uint64_t) is to accomodate for constant buffer offset
|
||||
allocateConstMemorySurface.Size = static_cast<uint32_t>(sizeof(SPatchAllocateConstantMemorySurfaceProgramBinaryInfo));
|
||||
|
||||
allocateConstMemorySurface.ConstantBufferIndex = 0;
|
||||
allocateConstMemorySurface.InlineDataSize = static_cast<uint32_t>(constantDataLen + sizeof(uint64_t));
|
||||
|
||||
auto pAllocateConstMemorySurface = std::unique_ptr<char>(new char[allocateConstMemorySurface.Size + allocateConstMemorySurface.InlineDataSize]);
|
||||
|
||||
// copy the token header
|
||||
memcpy_s(pAllocateConstMemorySurface.get(),
|
||||
sizeof(SPatchAllocateConstantMemorySurfaceProgramBinaryInfo),
|
||||
&allocateConstMemorySurface,
|
||||
sizeof(SPatchAllocateConstantMemorySurfaceProgramBinaryInfo));
|
||||
|
||||
// copy the constant data
|
||||
memcpy_s((char *)pAllocateConstMemorySurface.get() + sizeof(allocateConstMemorySurface), constantDataLen, pConstantData, constantDataLen);
|
||||
|
||||
// zero-out the constant buffer offset (will be patched during gen binary decoding)
|
||||
size_t constantBufferOffsetPatchOffset = constantDataLen;
|
||||
*(uint64_t *)((char *)pAllocateConstMemorySurface.get() + sizeof(allocateConstMemorySurface) + constantBufferOffsetPatchOffset) = 0U;
|
||||
|
||||
pProgramPatchList = (void *)pAllocateConstMemorySurface.get();
|
||||
programPatchListSize = allocateConstMemorySurface.Size + allocateConstMemorySurface.InlineDataSize;
|
||||
|
||||
buildAndDecodeProgramPatchList();
|
||||
|
||||
EXPECT_NE(nullptr, pProgram->getConstantSurface());
|
||||
|
||||
auto constantSurface = pProgram->getConstantSurface();
|
||||
constantSurface->setCpuPtrAndGpuAddress(constantSurface->getUnderlyingBuffer(), constantSurface->getGpuAddress() + 1);
|
||||
EXPECT_NE(reinterpret_cast<uint64_t>(constantSurface->getUnderlyingBuffer()), constantSurface->getGpuAddress());
|
||||
|
||||
EXPECT_EQ(0, memcmp(pConstantData, constantSurface->getUnderlyingBuffer(), constantDataLen));
|
||||
// there was no PATCH_TOKEN_CONSTANT_POINTER_PROGRAM_BINARY_INFO, so constant buffer offset should be still 0
|
||||
EXPECT_EQ(0U, *reinterpret_cast<uint64_t *>(static_cast<char *>(constantSurface->getUnderlyingBuffer()) + constantBufferOffsetPatchOffset));
|
||||
// once finally constant buffer offset gets patched - the patch value depends on the bitness of the compute kernel
|
||||
auto patchOffsetValueStorage = std::unique_ptr<uint64_t>(new uint64_t); // 4bytes for 32-bit compute kernel, full 8byte for 64-bit compute kernel
|
||||
uint64_t *patchOffsetValue = patchOffsetValueStorage.get();
|
||||
if (constantSurface->is32BitAllocation() || (sizeof(void *) == 4)) {
|
||||
reinterpret_cast<uint32_t *>(patchOffsetValue)[0] = static_cast<uint32_t>(constantSurface->getGpuAddressToPatch());
|
||||
reinterpret_cast<uint32_t *>(patchOffsetValue)[1] = 0; // just pad with 0
|
||||
} else {
|
||||
// full 8 bytes
|
||||
*reinterpret_cast<uint64_t *>(patchOffsetValue) = constantSurface->getGpuAddressToPatch();
|
||||
}
|
||||
|
||||
// constant pointer to constant surface - simulate invalid GlobalBufferIndex
|
||||
constantPointer.Token = PATCH_TOKEN_CONSTANT_POINTER_PROGRAM_BINARY_INFO;
|
||||
constantPointer.Size = sizeof(SPatchConstantPointerProgramBinaryInfo);
|
||||
constantPointer.ConstantBufferIndex = 10;
|
||||
constantPointer.ConstantPointerOffset = 0;
|
||||
constantPointer.BufferIndex = 0;
|
||||
constantPointer.BufferType = PROGRAM_SCOPE_CONSTANT_BUFFER;
|
||||
|
||||
pConstantPointer = new cl_char[constantPointer.Size];
|
||||
memcpy_s(pConstantPointer,
|
||||
sizeof(SPatchConstantPointerProgramBinaryInfo),
|
||||
&constantPointer,
|
||||
sizeof(SPatchConstantPointerProgramBinaryInfo));
|
||||
pProgramPatchList = (void *)pConstantPointer;
|
||||
programPatchListSize = constantPointer.Size;
|
||||
|
||||
this->allowDecodeFailure = true;
|
||||
buildAndDecodeProgramPatchList();
|
||||
EXPECT_EQ(0, memcmp(pConstantData, constantSurface->getUnderlyingBuffer(), constantDataLen));
|
||||
// check that constant pointer offset was not patched
|
||||
EXPECT_EQ(0U, *reinterpret_cast<uint64_t *>(static_cast<char *>(constantSurface->getUnderlyingBuffer()) + constantBufferOffsetPatchOffset));
|
||||
// reset the constant pointer offset
|
||||
*reinterpret_cast<uint64_t *>(static_cast<char *>(constantSurface->getUnderlyingBuffer()) + constantBufferOffsetPatchOffset) = 0U;
|
||||
|
||||
delete[] pConstantPointer;
|
||||
|
||||
// constant pointer to constant surface - simulate invalid BufferIndex
|
||||
constantPointer.Token = PATCH_TOKEN_CONSTANT_POINTER_PROGRAM_BINARY_INFO;
|
||||
constantPointer.Size = sizeof(SPatchConstantPointerProgramBinaryInfo);
|
||||
constantPointer.ConstantBufferIndex = 0;
|
||||
constantPointer.ConstantPointerOffset = 0;
|
||||
constantPointer.BufferIndex = 10;
|
||||
constantPointer.BufferType = PROGRAM_SCOPE_CONSTANT_BUFFER;
|
||||
|
||||
pConstantPointer = new cl_char[constantPointer.Size];
|
||||
memcpy_s(pConstantPointer,
|
||||
sizeof(SPatchConstantPointerProgramBinaryInfo),
|
||||
&constantPointer,
|
||||
sizeof(SPatchConstantPointerProgramBinaryInfo));
|
||||
pProgramPatchList = (void *)pConstantPointer;
|
||||
programPatchListSize = constantPointer.Size;
|
||||
|
||||
buildAndDecodeProgramPatchList();
|
||||
EXPECT_EQ(0, memcmp(pConstantData, constantSurface->getUnderlyingBuffer(), constantDataLen));
|
||||
// check that constant pointer offset was not patched
|
||||
EXPECT_EQ(0U, *reinterpret_cast<uint64_t *>(static_cast<char *>(constantSurface->getUnderlyingBuffer()) + constantBufferOffsetPatchOffset));
|
||||
// reset the constant pointer offset
|
||||
*(uint64_t *)((char *)constantSurface->getUnderlyingBuffer() + constantBufferOffsetPatchOffset) = 0U;
|
||||
|
||||
delete[] pConstantPointer;
|
||||
|
||||
// constant pointer to constant surface - simulate invalid BufferType
|
||||
constantPointer.Token = PATCH_TOKEN_CONSTANT_POINTER_PROGRAM_BINARY_INFO;
|
||||
constantPointer.Size = sizeof(SPatchConstantPointerProgramBinaryInfo);
|
||||
constantPointer.ConstantBufferIndex = 0;
|
||||
constantPointer.ConstantPointerOffset = 0;
|
||||
constantPointer.BufferIndex = 0;
|
||||
constantPointer.BufferType = PROGRAM_SCOPE_GLOBAL_BUFFER;
|
||||
|
||||
pConstantPointer = new cl_char[constantPointer.Size];
|
||||
memcpy_s(pConstantPointer,
|
||||
sizeof(SPatchConstantPointerProgramBinaryInfo),
|
||||
&constantPointer,
|
||||
sizeof(SPatchConstantPointerProgramBinaryInfo));
|
||||
pProgramPatchList = (void *)pConstantPointer;
|
||||
programPatchListSize = constantPointer.Size;
|
||||
|
||||
buildAndDecodeProgramPatchList();
|
||||
EXPECT_EQ(0, memcmp(pConstantData, constantSurface->getUnderlyingBuffer(), constantDataLen));
|
||||
// check that constant pointer offset was not patched
|
||||
EXPECT_EQ(0U, *reinterpret_cast<uint64_t *>(static_cast<char *>(constantSurface->getUnderlyingBuffer()) + constantBufferOffsetPatchOffset));
|
||||
// reset the constant pointer offset
|
||||
*reinterpret_cast<uint64_t *>(static_cast<char *>(constantSurface->getUnderlyingBuffer()) + constantBufferOffsetPatchOffset) = 0U;
|
||||
|
||||
delete[] pConstantPointer;
|
||||
|
||||
// regular case - constant pointer to constant surface - all parameters valid
|
||||
constantPointer.Token = PATCH_TOKEN_CONSTANT_POINTER_PROGRAM_BINARY_INFO;
|
||||
constantPointer.Size = sizeof(SPatchConstantPointerProgramBinaryInfo);
|
||||
constantPointer.ConstantBufferIndex = 0;
|
||||
constantPointer.ConstantPointerOffset = constantDataLen;
|
||||
constantPointer.BufferIndex = 0;
|
||||
constantPointer.BufferType = PROGRAM_SCOPE_CONSTANT_BUFFER;
|
||||
|
||||
pConstantPointer = new cl_char[constantPointer.Size];
|
||||
memcpy_s(pConstantPointer,
|
||||
sizeof(SPatchConstantPointerProgramBinaryInfo),
|
||||
&constantPointer,
|
||||
sizeof(SPatchConstantPointerProgramBinaryInfo));
|
||||
pProgramPatchList = (void *)pConstantPointer;
|
||||
programPatchListSize = constantPointer.Size;
|
||||
this->pProgram->skipValidationOfBinary = true;
|
||||
this->allowDecodeFailure = false;
|
||||
buildAndDecodeProgramPatchList();
|
||||
|
||||
EXPECT_EQ(0, memcmp(pConstantData, constantSurface->getUnderlyingBuffer(), constantDataLen));
|
||||
// check that constant pointer offset was patched
|
||||
EXPECT_EQ(*reinterpret_cast<uint64_t *>(patchOffsetValue), *reinterpret_cast<uint64_t *>(static_cast<char *>(constantSurface->getUnderlyingBuffer()) + constantBufferOffsetPatchOffset));
|
||||
|
||||
delete[] pConstantPointer;
|
||||
}
|
||||
|
||||
TEST(ProgramScopeMetadataTest, WhenPatchingGlobalSurfaceThenPickProperSourceBuffer) {
|
||||
MockExecutionEnvironment execEnv;
|
||||
MockClDevice device{new MockDevice};
|
||||
@@ -730,9 +398,11 @@ TEST(ProgramScopeMetadataTest, WhenPatchingGlobalSurfaceThenPickProperSourceBuff
|
||||
decodedProgram.constantPointerMutable->ConstantPointerOffset = 0U;
|
||||
memset(decodedProgram.globalSurfMutable + 1, 0U, sizeof(uintptr_t));
|
||||
memset(decodedProgram.constSurfMutable + 1, 0U, sizeof(uintptr_t));
|
||||
ProgramInfo programInfo;
|
||||
MockProgram program(execEnv);
|
||||
program.pDevice = &device;
|
||||
program.processProgramScopeMetadata(decodedProgram);
|
||||
NEO::populateProgramInfo(programInfo, decodedProgram, DeviceInfoKernelPayloadConstants{});
|
||||
program.processProgramInfo(programInfo);
|
||||
ASSERT_NE(nullptr, program.globalSurface);
|
||||
ASSERT_NE(nullptr, program.constantSurface);
|
||||
ASSERT_NE(nullptr, program.globalSurface->getUnderlyingBuffer());
|
||||
@@ -750,22 +420,15 @@ TEST_F(ProgramDataTest, GivenProgramWith32bitPointerOptWhenProgramScopeConstantB
|
||||
|
||||
// simulate case when constant surface was not allocated
|
||||
EXPECT_EQ(nullptr, prog->getConstantSurface());
|
||||
|
||||
SPatchConstantPointerProgramBinaryInfo constantPointer;
|
||||
constantPointer.Token = PATCH_TOKEN_CONSTANT_POINTER_PROGRAM_BINARY_INFO;
|
||||
constantPointer.Size = sizeof(SPatchConstantPointerProgramBinaryInfo);
|
||||
constantPointer.ConstantBufferIndex = 0;
|
||||
constantPointer.ConstantPointerOffset = 0;
|
||||
constantPointer.BufferIndex = 0;
|
||||
constantPointer.BufferType = PROGRAM_SCOPE_CONSTANT_BUFFER;
|
||||
|
||||
auto pConstantPointer = std::unique_ptr<char[]>(new char[constantPointer.Size]);
|
||||
memcpy_s(pConstantPointer.get(),
|
||||
sizeof(SPatchConstantPointerProgramBinaryInfo),
|
||||
&constantPointer,
|
||||
sizeof(SPatchConstantPointerProgramBinaryInfo));
|
||||
pProgramPatchList = (void *)pConstantPointer.get();
|
||||
programPatchListSize = constantPointer.Size;
|
||||
ProgramInfo programInfo;
|
||||
programInfo.prepareLinkerInputStorage();
|
||||
NEO::LinkerInput::RelocationInfo relocInfo;
|
||||
relocInfo.relocationSegment = NEO::SegmentType::GlobalConstants;
|
||||
relocInfo.symbolSegment = NEO::SegmentType::GlobalConstants;
|
||||
relocInfo.offset = 0U;
|
||||
relocInfo.type = NEO::LinkerInput::RelocationInfo::Type::Address;
|
||||
programInfo.linkerInput->addDataRelocationInfo(relocInfo);
|
||||
programInfo.linkerInput->setPointerSize(LinkerInput::Traits::PointerSize::Ptr32bit);
|
||||
|
||||
MockBuffer constantSurface;
|
||||
ASSERT_LT(8U, constantSurface.getSize());
|
||||
@@ -775,8 +438,9 @@ TEST_F(ProgramDataTest, GivenProgramWith32bitPointerOptWhenProgramScopeConstantB
|
||||
uint32_t sentinel = 0x17192329U;
|
||||
constantSurfaceStorage[0] = 0U;
|
||||
constantSurfaceStorage[1] = sentinel;
|
||||
this->pProgram->skipValidationOfBinary = true;
|
||||
buildAndDecodeProgramPatchList();
|
||||
|
||||
pProgram->linkerInput = std::move(programInfo.linkerInput);
|
||||
pProgram->linkBinary();
|
||||
uint32_t expectedAddr = static_cast<uint32_t>(constantSurface.getGraphicsAllocation()->getGpuAddressToPatch());
|
||||
EXPECT_EQ(expectedAddr, constantSurfaceStorage[0]);
|
||||
EXPECT_EQ(sentinel, constantSurfaceStorage[1]);
|
||||
@@ -794,21 +458,15 @@ TEST_F(ProgramDataTest, GivenProgramWith32bitPointerOptWhenProgramScopeGlobalPoi
|
||||
// simulate case when constant surface was not allocated
|
||||
EXPECT_EQ(nullptr, prog->getConstantSurface());
|
||||
|
||||
SPatchGlobalPointerProgramBinaryInfo globalPointer;
|
||||
globalPointer.Token = PATCH_TOKEN_GLOBAL_POINTER_PROGRAM_BINARY_INFO;
|
||||
globalPointer.Size = sizeof(SPatchConstantPointerProgramBinaryInfo);
|
||||
globalPointer.GlobalBufferIndex = 0;
|
||||
globalPointer.GlobalPointerOffset = 0;
|
||||
globalPointer.BufferIndex = 0;
|
||||
globalPointer.BufferType = PROGRAM_SCOPE_GLOBAL_BUFFER;
|
||||
|
||||
auto pGlobalPointer = std::unique_ptr<char[]>(new char[globalPointer.Size]);
|
||||
memcpy_s(pGlobalPointer.get(),
|
||||
sizeof(SPatchGlobalPointerProgramBinaryInfo),
|
||||
&globalPointer,
|
||||
sizeof(SPatchGlobalPointerProgramBinaryInfo));
|
||||
pProgramPatchList = (void *)pGlobalPointer.get();
|
||||
programPatchListSize = globalPointer.Size;
|
||||
ProgramInfo programInfo;
|
||||
programInfo.prepareLinkerInputStorage();
|
||||
NEO::LinkerInput::RelocationInfo relocInfo;
|
||||
relocInfo.relocationSegment = NEO::SegmentType::GlobalVariables;
|
||||
relocInfo.symbolSegment = NEO::SegmentType::GlobalVariables;
|
||||
relocInfo.offset = 0U;
|
||||
relocInfo.type = NEO::LinkerInput::RelocationInfo::Type::Address;
|
||||
programInfo.linkerInput->addDataRelocationInfo(relocInfo);
|
||||
programInfo.linkerInput->setPointerSize(LinkerInput::Traits::PointerSize::Ptr32bit);
|
||||
|
||||
MockBuffer globalSurface;
|
||||
ASSERT_LT(8U, globalSurface.getSize());
|
||||
@@ -819,7 +477,9 @@ TEST_F(ProgramDataTest, GivenProgramWith32bitPointerOptWhenProgramScopeGlobalPoi
|
||||
globalSurfaceStorage[0] = 0U;
|
||||
globalSurfaceStorage[1] = sentinel;
|
||||
this->pProgram->skipValidationOfBinary = true;
|
||||
buildAndDecodeProgramPatchList();
|
||||
|
||||
pProgram->linkerInput = std::move(programInfo.linkerInput);
|
||||
pProgram->linkBinary();
|
||||
uint32_t expectedAddr = static_cast<uint32_t>(globalSurface.getGraphicsAllocation()->getGpuAddressToPatch());
|
||||
EXPECT_EQ(expectedAddr, globalSurfaceStorage[0]);
|
||||
EXPECT_EQ(sentinel, globalSurfaceStorage[1]);
|
||||
@@ -882,22 +542,11 @@ TEST(ProgramLinkBinaryTest, whenLinkerUnresolvedExternalThenLinkFailedAndBuildLo
|
||||
EXPECT_THAT(buildLog, ::testing::HasSubstr(expectedError));
|
||||
}
|
||||
|
||||
TEST(ProgramLinkBinaryTest, whenPrepareLinkerInputStorageGetsCalledTwiceThenLinkerInputStorageIsReused) {
|
||||
ExecutionEnvironment execEnv;
|
||||
MockProgram program{execEnv};
|
||||
EXPECT_EQ(nullptr, program.linkerInput);
|
||||
program.prepareLinkerInputStorage();
|
||||
EXPECT_NE(nullptr, program.linkerInput);
|
||||
auto prevLinkerInput = program.getLinkerInput();
|
||||
program.prepareLinkerInputStorage();
|
||||
EXPECT_EQ(prevLinkerInput, program.linkerInput.get());
|
||||
}
|
||||
|
||||
TEST_F(ProgramDataTest, whenLinkerInputValidThenIsaIsProperlyPatched) {
|
||||
auto linkerInput = std::make_unique<WhiteBox<LinkerInput>>();
|
||||
linkerInput->symbols["A"] = NEO::SymbolInfo{4U, 4U, NEO::SymbolInfo::GlobalVariable};
|
||||
linkerInput->symbols["B"] = NEO::SymbolInfo{8U, 4U, NEO::SymbolInfo::GlobalConstant};
|
||||
linkerInput->symbols["C"] = NEO::SymbolInfo{16U, 4U, NEO::SymbolInfo::Function};
|
||||
linkerInput->symbols["A"] = NEO::SymbolInfo{4U, 4U, NEO::SegmentType::GlobalVariables};
|
||||
linkerInput->symbols["B"] = NEO::SymbolInfo{8U, 4U, NEO::SegmentType::GlobalConstants};
|
||||
linkerInput->symbols["C"] = NEO::SymbolInfo{16U, 4U, NEO::SegmentType::Instructions};
|
||||
|
||||
auto relocationType = NEO::LinkerInput::RelocationInfo::Type::Address;
|
||||
linkerInput->relocations.push_back({NEO::LinkerInput::RelocationInfo{"A", 8U, relocationType},
|
||||
@@ -951,8 +600,8 @@ TEST_F(ProgramDataTest, whenLinkerInputValidThenIsaIsProperlyPatched) {
|
||||
|
||||
TEST_F(ProgramDataTest, whenRelocationsAreNotNeededThenIsaIsPreserved) {
|
||||
auto linkerInput = std::make_unique<WhiteBox<LinkerInput>>();
|
||||
linkerInput->symbols["A"] = NEO::SymbolInfo{4U, 4U, NEO::SymbolInfo::GlobalVariable};
|
||||
linkerInput->symbols["B"] = NEO::SymbolInfo{8U, 4U, NEO::SymbolInfo::GlobalConstant};
|
||||
linkerInput->symbols["A"] = NEO::SymbolInfo{4U, 4U, NEO::SegmentType::GlobalVariables};
|
||||
linkerInput->symbols["B"] = NEO::SymbolInfo{8U, 4U, NEO::SegmentType::GlobalConstants};
|
||||
|
||||
NEO::ExecutionEnvironment env;
|
||||
MockProgram program{env};
|
||||
|
||||
Reference in New Issue
Block a user