Skip to content

Commit b52aec0

Browse files
Move symbols and linkerInput from Program to BuildInfo
these members should be kept per root device Related-To: NEO-5001 Change-Id: Ie5e06deed234706cc41943d3c5e932c7d877127b Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
1 parent 88ee484 commit b52aec0

File tree

8 files changed

+79
-67
lines changed

8 files changed

+79
-67
lines changed

opencl/source/api/api.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5320,14 +5320,15 @@ cl_int CL_API_CALL clGetDeviceGlobalVariablePointerINTEL(
53205320
DBG_LOG_INPUTS("device", device, "program", program,
53215321
"globalVariableName", globalVariableName,
53225322
"globalVariablePointerRet", globalVariablePointerRet);
5323-
retVal = validateObjects(device, program);
5323+
Program *pProgram = nullptr;
5324+
ClDevice *pDevice = nullptr;
5325+
retVal = validateObjects(WithCastToInternal(program, &pProgram), WithCastToInternal(device, &pDevice));
53245326
if (globalVariablePointerRet == nullptr) {
53255327
retVal = CL_INVALID_ARG_VALUE;
53265328
}
53275329

53285330
if (CL_SUCCESS == retVal) {
5329-
Program *pProgram = (Program *)(program);
5330-
const auto &symbols = pProgram->getSymbols();
5331+
const auto &symbols = pProgram->getSymbols(pDevice->getRootDeviceIndex());
53315332
auto symbolIt = symbols.find(globalVariableName);
53325333
if ((symbolIt == symbols.end()) || (symbolIt->second.symbol.segment == NEO::SegmentType::Instructions)) {
53335334
retVal = CL_INVALID_ARG_VALUE;
@@ -5352,14 +5353,16 @@ cl_int CL_API_CALL clGetDeviceFunctionPointerINTEL(
53525353
DBG_LOG_INPUTS("device", device, "program", program,
53535354
"functionName", functionName,
53545355
"functionPointerRet", functionPointerRet);
5355-
retVal = validateObjects(device, program);
5356+
5357+
Program *pProgram = nullptr;
5358+
ClDevice *pDevice = nullptr;
5359+
retVal = validateObjects(WithCastToInternal(program, &pProgram), WithCastToInternal(device, &pDevice));
53565360
if ((CL_SUCCESS == retVal) && (functionPointerRet == nullptr)) {
53575361
retVal = CL_INVALID_ARG_VALUE;
53585362
}
53595363

53605364
if (CL_SUCCESS == retVal) {
5361-
Program *pProgram = (Program *)(program);
5362-
const auto &symbols = pProgram->getSymbols();
5365+
const auto &symbols = pProgram->getSymbols(pDevice->getRootDeviceIndex());
53635366
auto symbolIt = symbols.find(functionName);
53645367
if ((symbolIt == symbols.end()) || (symbolIt->second.symbol.segment != NEO::SegmentType::Instructions)) {
53655368
retVal = CL_INVALID_ARG_VALUE;

opencl/source/program/process_device_binary.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const KernelInfo *Program::getKernelInfo(size_t ordinal) const {
5252
}
5353

5454
cl_int Program::linkBinary(Device *pDevice, const void *constantsInitData, const void *variablesInitData) {
55+
auto linkerInput = pDevice ? getLinkerInput(pDevice->getRootDeviceIndex()) : nullptr;
5556
if (linkerInput == nullptr) {
5657
return CL_SUCCESS;
5758
}
@@ -69,9 +70,9 @@ cl_int Program::linkBinary(Device *pDevice, const void *constantsInitData, const
6970
constants.gpuAddress = static_cast<uintptr_t>(constantsForPatching->getGpuAddress());
7071
constants.segmentSize = constantsForPatching->getUnderlyingBufferSize();
7172
}
72-
if (this->linkerInput->getExportedFunctionsSegmentId() >= 0) {
73+
if (linkerInput->getExportedFunctionsSegmentId() >= 0) {
7374
// Exported functions reside in instruction heap of one of kernels
74-
auto exportedFunctionHeapId = this->linkerInput->getExportedFunctionsSegmentId();
75+
auto exportedFunctionHeapId = linkerInput->getExportedFunctionsSegmentId();
7576
this->exportedFunctionsSurface = this->kernelInfoArray[exportedFunctionHeapId]->getGraphicsAllocation();
7677
exportedFunctions.gpuAddress = static_cast<uintptr_t>(exportedFunctionsSurface->getGpuAddressToPatch());
7778
exportedFunctions.segmentSize = exportedFunctionsSurface->getUnderlyingBufferSize();
@@ -93,7 +94,7 @@ cl_int Program::linkBinary(Device *pDevice, const void *constantsInitData, const
9394
globalsForPatching, constantsForPatching,
9495
isaSegmentsForPatching, unresolvedExternalsInfo,
9596
pDevice, constantsInitData, variablesInitData);
96-
this->symbols = linker.extractRelocatedSymbols();
97+
setSymbols(pDevice->getRootDeviceIndex(), linker.extractRelocatedSymbols());
9798
if (false == linkSuccess) {
9899
std::vector<std::string> kernelNames;
99100
for (const auto &kernelInfo : this->kernelInfoArray) {
@@ -114,7 +115,7 @@ cl_int Program::linkBinary(Device *pDevice, const void *constantsInitData, const
114115
kernHeapInfo.KernelHeapSize);
115116
}
116117
}
117-
DBG_LOG(PrintRelocations, NEO::constructRelocationsDebugMessage(this->symbols));
118+
DBG_LOG(PrintRelocations, NEO::constructRelocationsDebugMessage(this->getSymbols(pDevice->getRootDeviceIndex())));
118119
return CL_SUCCESS;
119120
}
120121

@@ -157,6 +158,7 @@ cl_int Program::processProgramInfo(ProgramInfo &src) {
157158
size_t slmNeeded = getMaxInlineSlmNeeded(src);
158159
size_t slmAvailable = 0U;
159160
NEO::DeviceInfoKernelPayloadConstants deviceInfoConstants;
161+
LinkerInput *linkerInput = nullptr;
160162
if (this->pDevice) {
161163
slmAvailable = static_cast<size_t>(this->pDevice->getDeviceInfo().localMemSize);
162164
deviceInfoConstants.maxWorkGroupSize = (uint32_t)this->pDevice->getDeviceInfo().maxWorkGroupSize;
@@ -165,24 +167,25 @@ cl_int Program::processProgramInfo(ProgramInfo &src) {
165167
if (requiresLocalMemoryWindowVA(src)) {
166168
deviceInfoConstants.slmWindow = this->executionEnvironment.memoryManager->getReservedMemory(MemoryConstants::slmWindowSize, MemoryConstants::slmWindowAlignment);
167169
}
170+
linkerInput = src.linkerInput.get();
171+
setLinkerInput(pDevice->getRootDeviceIndex(), std::move(src.linkerInput));
168172
}
169173
if (slmNeeded > slmAvailable) {
170174
return CL_OUT_OF_RESOURCES;
171175
}
172176

173-
this->linkerInput = std::move(src.linkerInput);
174177
this->kernelInfoArray = std::move(src.kernelInfos);
175178
auto svmAllocsManager = context ? context->getSVMAllocsManager() : nullptr;
176179
if (src.globalConstants.size != 0) {
177180
UNRECOVERABLE_IF(nullptr == pDevice);
178-
this->constantSurface = allocateGlobalsSurface(svmAllocsManager, *pDevice, src.globalConstants.size, true, linkerInput.get(), src.globalConstants.initData);
181+
this->constantSurface = allocateGlobalsSurface(svmAllocsManager, *pDevice, src.globalConstants.size, true, linkerInput, src.globalConstants.initData);
179182
}
180183

181184
this->globalVarTotalSize = src.globalVariables.size;
182185

183186
if (src.globalVariables.size != 0) {
184187
UNRECOVERABLE_IF(nullptr == pDevice);
185-
this->globalSurface = allocateGlobalsSurface(svmAllocsManager, *pDevice, src.globalVariables.size, false, linkerInput.get(), src.globalVariables.initData);
188+
this->globalSurface = allocateGlobalsSurface(svmAllocsManager, *pDevice, src.globalVariables.size, false, linkerInput, src.globalVariables.initData);
186189
if (pDevice->getSpecializedDevice<ClDevice>()->areOcl21FeaturesEnabled() == false) {
187190
this->globalVarTotalSize = 0u;
188191
}

opencl/source/program/program.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "shared/source/compiler_interface/compiler_interface.h"
1010
#include "shared/source/compiler_interface/linker.h"
1111
#include "shared/source/device_binary_format/elf/elf_encoder.h"
12+
#include "shared/source/helpers/non_copyable_or_moveable.h"
1213
#include "shared/source/program/program_info.h"
1314
#include "shared/source/utilities/const_stringref.h"
1415

@@ -254,12 +255,19 @@ class Program : public BaseObject<_cl_program> {
254255
return debugDataSize;
255256
}
256257

257-
const Linker::RelocatedSymbolsMap &getSymbols() const {
258-
return this->symbols;
258+
const Linker::RelocatedSymbolsMap &getSymbols(uint32_t rootDeviceIndex) const {
259+
return buildInfos[rootDeviceIndex].symbols;
259260
}
260261

261-
LinkerInput *getLinkerInput() const {
262-
return this->linkerInput.get();
262+
void setSymbols(uint32_t rootDeviceIndex, Linker::RelocatedSymbolsMap &&symbols) {
263+
buildInfos[rootDeviceIndex].symbols = std::move(symbols);
264+
}
265+
266+
LinkerInput *getLinkerInput(uint32_t rootDeviceIndex) const {
267+
return buildInfos[rootDeviceIndex].linkerInput.get();
268+
}
269+
void setLinkerInput(uint32_t rootDeviceIndex, std::unique_ptr<LinkerInput> &&linkerInput) {
270+
buildInfos[rootDeviceIndex].linkerInput = std::move(linkerInput);
263271
}
264272

265273
MOCKABLE_VIRTUAL void replaceDeviceBinary(std::unique_ptr<char[]> newBinary, size_t newBinarySize);
@@ -324,14 +332,13 @@ class Program : public BaseObject<_cl_program> {
324332
uint32_t programOptionVersion = 12U;
325333
bool allowNonUniform = false;
326334

327-
std::unique_ptr<LinkerInput> linkerInput;
328-
Linker::RelocatedSymbolsMap symbols;
329-
330-
struct BuildInfo {
335+
struct BuildInfo : public NonCopyableClass {
336+
std::unique_ptr<LinkerInput> linkerInput;
337+
Linker::RelocatedSymbolsMap symbols{};
331338
std::string buildLog{};
332339
};
333340

334-
StackVec<BuildInfo, 1> buildInfos;
341+
std::vector<BuildInfo> buildInfos;
335342

336343
bool areSpecializationConstantsInitialized = false;
337344
CIF::RAII::UPtr_t<CIF::Builtins::BufferSimple> specConstantsIds;

opencl/test/unit_test/api/cl_function_pointers_tests.inl

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ using clGetDeviceGlobalVariablePointer = api_tests;
1515
using clGetDeviceFunctionPointer = api_tests;
1616

1717
TEST_F(clGetDeviceGlobalVariablePointer, GivenNullMandatoryArgumentsThenReturnInvalidArgError) {
18-
this->pProgram->symbols["A"].gpuAddress = 7U;
19-
this->pProgram->symbols["A"].symbol.size = 64U;
20-
this->pProgram->symbols["A"].symbol.segment = NEO::SegmentType::GlobalVariables;
18+
auto &symbols = pProgram->buildInfos[testedRootDeviceIndex].symbols;
19+
symbols["A"].gpuAddress = 7U;
20+
symbols["A"].symbol.size = 64U;
21+
symbols["A"].symbol.segment = NEO::SegmentType::GlobalVariables;
2122

2223
void *globalRet = 0;
2324
auto ret = clGetDeviceGlobalVariablePointerINTEL(this->pContext->getDevice(0), this->pProgram, "A", nullptr, &globalRet);
@@ -35,9 +36,10 @@ TEST_F(clGetDeviceGlobalVariablePointer, GivenNullMandatoryArgumentsThenReturnIn
3536
}
3637

3738
TEST_F(clGetDeviceGlobalVariablePointer, GivenValidSymbolNameThenReturnProperAddressAndSize) {
38-
this->pProgram->symbols["A"].gpuAddress = 7U;
39-
this->pProgram->symbols["A"].symbol.size = 64U;
40-
this->pProgram->symbols["A"].symbol.segment = NEO::SegmentType::GlobalVariables;
39+
auto &symbols = pProgram->buildInfos[testedRootDeviceIndex].symbols;
40+
symbols["A"].gpuAddress = 7U;
41+
symbols["A"].symbol.size = 64U;
42+
symbols["A"].symbol.segment = NEO::SegmentType::GlobalVariables;
4143

4244
void *globalRet = 0;
4345
size_t sizeRet = 0;
@@ -48,9 +50,10 @@ TEST_F(clGetDeviceGlobalVariablePointer, GivenValidSymbolNameThenReturnProperAdd
4850
}
4951

5052
TEST_F(clGetDeviceGlobalVariablePointer, GivenFunctionSymbolNameThenReturnInvalidArgError) {
51-
this->pProgram->symbols["A"].gpuAddress = 7U;
52-
this->pProgram->symbols["A"].symbol.size = 64U;
53-
this->pProgram->symbols["A"].symbol.segment = NEO::SegmentType::Instructions;
53+
auto &symbols = pProgram->buildInfos[testedRootDeviceIndex].symbols;
54+
symbols["A"].gpuAddress = 7U;
55+
symbols["A"].symbol.size = 64U;
56+
symbols["A"].symbol.segment = NEO::SegmentType::Instructions;
5457

5558
void *globalRet = 0;
5659
auto ret = clGetDeviceGlobalVariablePointerINTEL(this->pContext->getDevice(0), this->pProgram, "A", nullptr, &globalRet);
@@ -64,9 +67,10 @@ TEST_F(clGetDeviceGlobalVariablePointer, GivenUnknownSymbolNameThenReturnInvalid
6467
}
6568

6669
TEST_F(clGetDeviceFunctionPointer, GivenNullMandatoryArgumentsThenReturnInvalidArgError) {
67-
this->pProgram->symbols["A"].gpuAddress = 7U;
68-
this->pProgram->symbols["A"].symbol.size = 64U;
69-
this->pProgram->symbols["A"].symbol.segment = NEO::SegmentType::Instructions;
70+
auto &symbols = pProgram->buildInfos[testedRootDeviceIndex].symbols;
71+
symbols["A"].gpuAddress = 7U;
72+
symbols["A"].symbol.size = 64U;
73+
symbols["A"].symbol.segment = NEO::SegmentType::Instructions;
7074

7175
cl_ulong fptrRet = 0;
7276
auto ret = clGetDeviceFunctionPointerINTEL(this->pContext->getDevice(0), this->pProgram, "A", &fptrRet);
@@ -84,9 +88,10 @@ TEST_F(clGetDeviceFunctionPointer, GivenNullMandatoryArgumentsThenReturnInvalidA
8488
}
8589

8690
TEST_F(clGetDeviceFunctionPointer, GivenValidSymbolNameThenReturnProperAddress) {
87-
this->pProgram->symbols["A"].gpuAddress = 7U;
88-
this->pProgram->symbols["A"].symbol.size = 64U;
89-
this->pProgram->symbols["A"].symbol.segment = NEO::SegmentType::Instructions;
91+
auto &symbols = pProgram->buildInfos[testedRootDeviceIndex].symbols;
92+
symbols["A"].gpuAddress = 7U;
93+
symbols["A"].symbol.size = 64U;
94+
symbols["A"].symbol.segment = NEO::SegmentType::Instructions;
9095

9196
cl_ulong fptrRet = 0;
9297
auto ret = clGetDeviceFunctionPointerINTEL(this->pContext->getDevice(0), this->pProgram, "A", &fptrRet);
@@ -95,12 +100,13 @@ TEST_F(clGetDeviceFunctionPointer, GivenValidSymbolNameThenReturnProperAddress)
95100
}
96101

97102
TEST_F(clGetDeviceFunctionPointer, GivenGlobalSymbolNameThenReturnInvalidArgError) {
98-
this->pProgram->symbols["A"].gpuAddress = 7U;
99-
this->pProgram->symbols["A"].symbol.size = 64U;
100-
this->pProgram->symbols["A"].symbol.segment = NEO::SegmentType::GlobalVariables;
101-
this->pProgram->symbols["B"].gpuAddress = 7U;
102-
this->pProgram->symbols["B"].symbol.size = 64U;
103-
this->pProgram->symbols["B"].symbol.segment = NEO::SegmentType::GlobalConstants;
103+
auto &symbols = pProgram->buildInfos[testedRootDeviceIndex].symbols;
104+
symbols["A"].gpuAddress = 7U;
105+
symbols["A"].symbol.size = 64U;
106+
symbols["A"].symbol.segment = NEO::SegmentType::GlobalVariables;
107+
symbols["B"].gpuAddress = 7U;
108+
symbols["B"].symbol.size = 64U;
109+
symbols["B"].symbol.segment = NEO::SegmentType::GlobalConstants;
104110

105111
cl_ulong fptrRet = 0;
106112
auto ret = clGetDeviceFunctionPointerINTEL(this->pContext->getDevice(0), this->pProgram, "A", &fptrRet);

opencl/test/unit_test/mocks/mock_program.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class MockProgram : public Program {
3737
using Program::applyAdditionalOptions;
3838
using Program::areSpecializationConstantsInitialized;
3939
using Program::blockKernelManager;
40+
using Program::buildInfos;
4041
using Program::constantSurface;
4142
using Program::context;
4243
using Program::createdFrom;
@@ -49,7 +50,6 @@ class MockProgram : public Program {
4950
using Program::irBinary;
5051
using Program::irBinarySize;
5152
using Program::isSpirV;
52-
using Program::linkerInput;
5353
using Program::options;
5454
using Program::packDeviceBinary;
5555
using Program::packedDeviceBinary;
@@ -61,7 +61,6 @@ class MockProgram : public Program {
6161
using Program::specConstantsIds;
6262
using Program::specConstantsSizes;
6363
using Program::specConstantsValues;
64-
using Program::symbols;
6564
using Program::unpackedDeviceBinary;
6665
using Program::unpackedDeviceBinarySize;
6766

opencl/test/unit_test/program/kernel_data.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ TEST_F(KernelDataTest, givenSymbolTablePatchTokenThenLinkerInputIsCreated) {
14611461

14621462
buildAndDecode();
14631463

1464-
EXPECT_NE(nullptr, program->linkerInput);
1464+
EXPECT_NE(nullptr, program->getLinkerInput(pContext->getDevice(0)->getRootDeviceIndex()));
14651465
}
14661466

14671467
TEST_F(KernelDataTest, givenRelocationTablePatchTokenThenLinkerInputIsCreated) {
@@ -1475,5 +1475,5 @@ TEST_F(KernelDataTest, givenRelocationTablePatchTokenThenLinkerInputIsCreated) {
14751475

14761476
buildAndDecode();
14771477

1478-
EXPECT_NE(nullptr, program->linkerInput);
1478+
EXPECT_NE(nullptr, program->getLinkerInput(pContext->getDevice(0)->getRootDeviceIndex()));
14791479
}

0 commit comments

Comments
 (0)