Skip to content

Commit ab74b60

Browse files
jchodorCompute-Runtime-Automation
authored andcommitted
Fixing regression in progvar_prog_scope_init
Change-Id: I20424ce9e0c9a295bb8b9d5608252c3d4802e9da
1 parent f7e04a8 commit ab74b60

File tree

2 files changed

+47
-30
lines changed

2 files changed

+47
-30
lines changed

runtime/program/process_gen_binary.cpp

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -881,14 +881,17 @@ GraphicsAllocation *allocateGlobalsSurface(NEO::Context *ctx, NEO::Device *devic
881881
svmProps.readOnly = constant;
882882
svmProps.hostPtrReadOnly = constant;
883883
auto ptr = ctx->getSVMAllocsManager()->createSVMAlloc(size, svmProps);
884-
UNRECOVERABLE_IF(device == nullptr);
884+
UNRECOVERABLE_IF(ptr == nullptr);
885885
auto gpuAlloc = ctx->getSVMAllocsManager()->getSVMAlloc(ptr)->gpuAllocation;
886+
UNRECOVERABLE_IF(gpuAlloc == nullptr);
887+
UNRECOVERABLE_IF(device == nullptr);
886888
device->getMemoryManager()->copyMemoryToAllocation(gpuAlloc, initData, static_cast<uint32_t>(size));
887889
return ctx->getSVMAllocsManager()->getSVMAlloc(ptr)->gpuAllocation;
888890
} else {
889891
UNRECOVERABLE_IF(device == nullptr);
890892
auto allocationType = constant ? GraphicsAllocation::AllocationType::CONSTANT_SURFACE : GraphicsAllocation::AllocationType::GLOBAL_SURFACE;
891893
auto gpuAlloc = device->getMemoryManager()->allocateGraphicsMemoryWithProperties({size, allocationType});
894+
UNRECOVERABLE_IF(gpuAlloc == nullptr);
892895
memcpy_s(gpuAlloc->getUnderlyingBuffer(), gpuAlloc->getUnderlyingBufferSize(), initData, size);
893896
return gpuAlloc;
894897
}
@@ -952,26 +955,24 @@ cl_int Program::parseProgramScopePatchList() {
952955
};
953956
break;
954957

955-
case PATCH_TOKEN_GLOBAL_POINTER_PROGRAM_BINARY_INFO:
956-
if (globalSurface != nullptr) {
957-
auto patch = *(SPatchGlobalPointerProgramBinaryInfo *)pPatch;
958-
if ((patch.GlobalBufferIndex == 0) && (patch.BufferIndex == 0) && (patch.BufferType == PROGRAM_SCOPE_GLOBAL_BUFFER)) {
959-
globalVariablesSelfPatches.push_back(readMisalignedUint64(&patch.GlobalPointerOffset));
960-
} else {
961-
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "Program::parseProgramScopePatchList. Unhandled Data parameter: %d\n", pPatch->Token);
962-
}
963-
DBG_LOG(LogPatchTokens,
964-
"\n .GLOBAL_POINTER_PROGRAM_BINARY_INFO", pPatch->Token,
965-
"\n .Size", pPatch->Size,
966-
"\n .GlobalBufferIndex", patch.GlobalBufferIndex,
967-
"\n .GlobalPointerOffset", patch.GlobalPointerOffset,
968-
"\n .BufferType", patch.BufferType,
969-
"\n .BufferIndex", patch.BufferIndex);
958+
case PATCH_TOKEN_GLOBAL_POINTER_PROGRAM_BINARY_INFO: {
959+
auto patch = *(SPatchGlobalPointerProgramBinaryInfo *)pPatch;
960+
if ((patch.GlobalBufferIndex == 0) && (patch.BufferIndex == 0) && (patch.BufferType == PROGRAM_SCOPE_GLOBAL_BUFFER)) {
961+
globalVariablesSelfPatches.push_back(readMisalignedUint64(&patch.GlobalPointerOffset));
962+
} else {
963+
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "Program::parseProgramScopePatchList. Unhandled Data parameter: %d\n", pPatch->Token);
964+
}
965+
DBG_LOG(LogPatchTokens,
966+
"\n .GLOBAL_POINTER_PROGRAM_BINARY_INFO", pPatch->Token,
967+
"\n .Size", pPatch->Size,
968+
"\n .GlobalBufferIndex", patch.GlobalBufferIndex,
969+
"\n .GlobalPointerOffset", patch.GlobalPointerOffset,
970+
"\n .BufferType", patch.BufferType,
971+
"\n .BufferIndex", patch.BufferIndex);
970972
}
971973
break;
972974

973-
case PATCH_TOKEN_CONSTANT_POINTER_PROGRAM_BINARY_INFO:
974-
if (constantSurface != nullptr) {
975+
case PATCH_TOKEN_CONSTANT_POINTER_PROGRAM_BINARY_INFO: {
975976
auto patch = *(SPatchConstantPointerProgramBinaryInfo *)pPatch;
976977
if ((patch.ConstantBufferIndex == 0) && (patch.BufferIndex == 0) && (patch.BufferType == PROGRAM_SCOPE_CONSTANT_BUFFER)) {
977978
globalConstantsSelfPatches.push_back(readMisalignedUint64(&patch.ConstantPointerOffset));
@@ -1021,22 +1022,28 @@ cl_int Program::parseProgramScopePatchList() {
10211022
}
10221023

10231024
for (auto offset : globalVariablesSelfPatches) {
1024-
UNRECOVERABLE_IF(globalSurface == nullptr);
1025-
void *pPtr = ptrOffset(globalSurface->getUnderlyingBuffer(), static_cast<size_t>(offset));
1026-
if (globalSurface->is32BitAllocation()) {
1027-
*reinterpret_cast<uint32_t *>(pPtr) += static_cast<uint32_t>(globalSurface->getGpuAddressToPatch());
1025+
if (globalSurface == nullptr) {
1026+
retVal = CL_INVALID_BINARY;
10281027
} else {
1029-
*reinterpret_cast<uintptr_t *>(pPtr) += static_cast<uintptr_t>(globalSurface->getGpuAddressToPatch());
1028+
void *pPtr = ptrOffset(globalSurface->getUnderlyingBuffer(), static_cast<size_t>(offset));
1029+
if (globalSurface->is32BitAllocation()) {
1030+
*reinterpret_cast<uint32_t *>(pPtr) += static_cast<uint32_t>(globalSurface->getGpuAddressToPatch());
1031+
} else {
1032+
*reinterpret_cast<uintptr_t *>(pPtr) += static_cast<uintptr_t>(globalSurface->getGpuAddressToPatch());
1033+
}
10301034
}
10311035
}
10321036

10331037
for (auto offset : globalConstantsSelfPatches) {
1034-
UNRECOVERABLE_IF(constantSurface == nullptr);
1035-
void *pPtr = ptrOffset(constantSurface->getUnderlyingBuffer(), static_cast<size_t>(offset));
1036-
if (constantSurface->is32BitAllocation()) {
1037-
*reinterpret_cast<uint32_t *>(pPtr) += static_cast<uint32_t>(constantSurface->getGpuAddressToPatch());
1038+
if (constantSurface == nullptr) {
1039+
retVal = CL_INVALID_BINARY;
10381040
} else {
1039-
*reinterpret_cast<uintptr_t *>(pPtr) += static_cast<uintptr_t>(constantSurface->getGpuAddressToPatch());
1041+
void *pPtr = ptrOffset(constantSurface->getUnderlyingBuffer(), static_cast<size_t>(offset));
1042+
if (constantSurface->is32BitAllocation()) {
1043+
*reinterpret_cast<uint32_t *>(pPtr) += static_cast<uint32_t>(constantSurface->getGpuAddressToPatch());
1044+
} else {
1045+
*reinterpret_cast<uintptr_t *>(pPtr) += static_cast<uintptr_t>(constantSurface->getGpuAddressToPatch());
1046+
}
10401047
}
10411048
}
10421049

unit_tests/program/program_data_tests.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class ProgramDataTestBase : public testing::Test,
4343

4444
void buildAndDecodeProgramPatchList();
4545

46-
protected:
4746
void SetUp() override {
4847
PlatformFixture::SetUp();
4948
cl_device_id device = pPlatform->getDevice(0);
@@ -120,6 +119,8 @@ class ProgramDataTestBase : public testing::Test,
120119
SProgramBinaryHeader programBinaryHeader;
121120
void *pProgramPatchList;
122121
uint32_t programPatchListSize;
122+
cl_int patchlistDecodeErrorCode = 0;
123+
bool allowDecodeFailure = false;
123124
};
124125

125126
template <typename ProgramType>
@@ -153,7 +154,10 @@ void ProgramDataTestBase<ProgramType>::buildAndDecodeProgramPatchList() {
153154
pProgram->storeGenBinary(pProgramData, headerSize + programBinaryHeader.PatchListSize);
154155

155156
error = pProgram->processGenBinary();
156-
EXPECT_EQ(CL_SUCCESS, error);
157+
patchlistDecodeErrorCode = error;
158+
if (allowDecodeFailure == false) {
159+
EXPECT_EQ(CL_SUCCESS, error);
160+
}
157161
delete[] pProgramData;
158162
}
159163

@@ -363,8 +367,11 @@ TEST_F(ProgramDataTest, GlobalPointerProgramBinaryInfo) {
363367
pProgramPatchList = (void *)pGlobalPointer;
364368
programPatchListSize = globalPointer.Size;
365369

370+
this->allowDecodeFailure = true;
366371
buildAndDecodeProgramPatchList();
367372
EXPECT_EQ(nullptr, pProgram->getGlobalSurface());
373+
EXPECT_EQ(CL_INVALID_BINARY, this->patchlistDecodeErrorCode);
374+
this->allowDecodeFailure = false;
368375

369376
delete[] pGlobalPointer;
370377

@@ -552,8 +559,11 @@ TEST_F(ProgramDataTest, ConstantPointerProgramBinaryInfo) {
552559
pProgramPatchList = (void *)pConstantPointer;
553560
programPatchListSize = constantPointer.Size;
554561

562+
this->allowDecodeFailure = true;
555563
buildAndDecodeProgramPatchList();
556564
EXPECT_EQ(nullptr, pProgram->getConstantSurface());
565+
EXPECT_EQ(CL_INVALID_BINARY, this->patchlistDecodeErrorCode);
566+
this->allowDecodeFailure = false;
557567

558568
delete[] pConstantPointer;
559569

0 commit comments

Comments
 (0)