Skip to content

Commit 9394f57

Browse files
Create structure for per root device build info in program
define build log per root device Related-To: NEO-5001 Change-Id: Id507485e7f2bdd4e0d96948450da49a9f67dd2a8 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
1 parent ba35333 commit 9394f57

13 files changed

+79
-80
lines changed

opencl/source/program/build.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ cl_int Program::build(
120120
inputArgs.allowCaching = enableCaching;
121121
NEO::TranslationOutput compilerOuput = {};
122122
auto compilerErr = pCompilerInterface->build(*this->pDevice, inputArgs, compilerOuput);
123-
this->updateBuildLog(this->pDevice, compilerOuput.frontendCompilerLog.c_str(), compilerOuput.frontendCompilerLog.size());
124-
this->updateBuildLog(this->pDevice, compilerOuput.backendCompilerLog.c_str(), compilerOuput.backendCompilerLog.size());
123+
this->updateBuildLog(this->pDevice->getRootDeviceIndex(), compilerOuput.frontendCompilerLog.c_str(), compilerOuput.frontendCompilerLog.size());
124+
this->updateBuildLog(this->pDevice->getRootDeviceIndex(), compilerOuput.backendCompilerLog.c_str(), compilerOuput.backendCompilerLog.size());
125125
retVal = asClError(compilerErr);
126126
if (retVal != CL_SUCCESS) {
127127
break;

opencl/source/program/compile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ cl_int Program::compile(
151151

152152
TranslationOutput compilerOuput;
153153
auto compilerErr = pCompilerInterface->compile(*this->pDevice, inputArgs, compilerOuput);
154-
this->updateBuildLog(this->pDevice, compilerOuput.frontendCompilerLog.c_str(), compilerOuput.frontendCompilerLog.size());
155-
this->updateBuildLog(this->pDevice, compilerOuput.backendCompilerLog.c_str(), compilerOuput.backendCompilerLog.size());
154+
this->updateBuildLog(this->pDevice->getRootDeviceIndex(), compilerOuput.frontendCompilerLog.c_str(), compilerOuput.frontendCompilerLog.size());
155+
this->updateBuildLog(this->pDevice->getRootDeviceIndex(), compilerOuput.backendCompilerLog.c_str(), compilerOuput.backendCompilerLog.size());
156156
retVal = asClError(compilerErr);
157157
if (retVal != CL_SUCCESS) {
158158
break;

opencl/source/program/get_info.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,10 @@ cl_int Program::getBuildInfo(cl_device_id device, cl_program_build_info paramNam
184184
break;
185185

186186
case CL_PROGRAM_BUILD_LOG: {
187-
const char *pBuildLog = getBuildLog(&pClDev->getDevice());
187+
const char *pBuildLog = getBuildLog(pClDev->getRootDeviceIndex());
188188

189-
if (pBuildLog != nullptr) {
190-
pSrc = pBuildLog;
191-
srcSize = retSize = strlen(pBuildLog) + 1;
192-
} else {
193-
pSrc = "";
194-
srcSize = retSize = 1;
195-
}
189+
pSrc = pBuildLog;
190+
srcSize = retSize = strlen(pBuildLog) + 1;
196191
} break;
197192

198193
case CL_PROGRAM_BINARY_TYPE:

opencl/source/program/link.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ cl_int Program::link(
149149
inputArgs.outType = IGC::CodeType::oclGenBin;
150150
NEO::TranslationOutput compilerOuput = {};
151151
auto compilerErr = pCompilerInterface->link(this->getDevice(), inputArgs, compilerOuput);
152-
this->updateBuildLog(this->pDevice, compilerOuput.frontendCompilerLog.c_str(), compilerOuput.frontendCompilerLog.size());
153-
this->updateBuildLog(this->pDevice, compilerOuput.backendCompilerLog.c_str(), compilerOuput.backendCompilerLog.size());
152+
this->updateBuildLog(this->pDevice->getRootDeviceIndex(), compilerOuput.frontendCompilerLog.c_str(), compilerOuput.frontendCompilerLog.size());
153+
this->updateBuildLog(this->pDevice->getRootDeviceIndex(), compilerOuput.backendCompilerLog.c_str(), compilerOuput.backendCompilerLog.size());
154154
retVal = asClError(compilerErr);
155155
if (retVal != CL_SUCCESS) {
156156
break;
@@ -181,8 +181,8 @@ cl_int Program::link(
181181
inputArgs.outType = IGC::CodeType::llvmBc;
182182
NEO::TranslationOutput compilerOuput = {};
183183
auto compilerErr = pCompilerInterface->createLibrary(*this->pDevice, inputArgs, compilerOuput);
184-
this->updateBuildLog(this->pDevice, compilerOuput.frontendCompilerLog.c_str(), compilerOuput.frontendCompilerLog.size());
185-
this->updateBuildLog(this->pDevice, compilerOuput.backendCompilerLog.c_str(), compilerOuput.backendCompilerLog.size());
184+
this->updateBuildLog(this->pDevice->getRootDeviceIndex(), compilerOuput.frontendCompilerLog.c_str(), compilerOuput.frontendCompilerLog.size());
185+
this->updateBuildLog(this->pDevice->getRootDeviceIndex(), compilerOuput.backendCompilerLog.c_str(), compilerOuput.backendCompilerLog.size());
186186
retVal = asClError(compilerErr);
187187
if (retVal != CL_SUCCESS) {
188188
break;

opencl/source/program/process_device_binary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ cl_int Program::linkBinary(Device *pDevice, const void *constantsInitData, const
100100
kernelNames.push_back("kernel : " + kernelInfo->name);
101101
}
102102
auto error = constructLinkerErrorMessage(unresolvedExternalsInfo, kernelNames);
103-
updateBuildLog(pDevice, error.c_str(), error.size());
103+
updateBuildLog(pDevice->getRootDeviceIndex(), error.c_str(), error.size());
104104
return CL_INVALID_BINARY;
105105
} else if (linkerInput->getTraits().requiresPatchingOfInstructionSegments) {
106106
for (const auto &kernelInfo : this->kernelInfoArray) {

opencl/source/program/program.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ Program::Program(ExecutionEnvironment &executionEnvironment, Context *context, b
5858
numDevices = 1;
5959
bool force32BitAddressess = false;
6060

61+
uint32_t maxRootDeviceIndex = 0u;
62+
if (device) {
63+
maxRootDeviceIndex = device->getRootDeviceIndex();
64+
}
65+
buildInfos.resize(maxRootDeviceIndex + 1);
66+
6167
if (pClDevice) {
6268
auto enabledClVersion = pClDevice->getEnabledClVersion();
6369
if (enabledClVersion == 30) {
@@ -280,7 +286,7 @@ cl_int Program::getSource(std::string &binary) const {
280286
return retVal;
281287
}
282288

283-
void Program::updateBuildLog(const Device *pDevice, const char *pErrorString,
289+
void Program::updateBuildLog(uint32_t rootDeviceIndex, const char *pErrorString,
284290
size_t errorStringSize) {
285291
if ((pErrorString == nullptr) || (errorStringSize == 0) || (pErrorString[0] == '\0')) {
286292
return;
@@ -290,27 +296,20 @@ void Program::updateBuildLog(const Device *pDevice, const char *pErrorString,
290296
--errorStringSize;
291297
}
292298

293-
auto it = buildLog.find(pDevice);
299+
auto &currentLog = buildInfos[rootDeviceIndex].buildLog;
294300

295-
if (it == buildLog.end()) {
296-
buildLog[pDevice].assign(pErrorString, pErrorString + errorStringSize);
301+
if (currentLog.empty()) {
302+
currentLog.assign(pErrorString, pErrorString + errorStringSize);
297303
return;
298304
}
299305

300-
buildLog[pDevice].append("\n");
301-
buildLog[pDevice].append(pErrorString, pErrorString + errorStringSize);
306+
currentLog.append("\n");
307+
currentLog.append(pErrorString, pErrorString + errorStringSize);
302308
}
303309

304-
const char *Program::getBuildLog(const Device *pDevice) const {
305-
const char *entry = nullptr;
306-
307-
auto it = buildLog.find(pDevice);
308-
309-
if (it != buildLog.end()) {
310-
entry = it->second.c_str();
311-
}
312-
313-
return entry;
310+
const char *Program::getBuildLog(uint32_t rootDeviceIndex) const {
311+
auto &currentLog = buildInfos[rootDeviceIndex].buildLog;
312+
return currentLog.c_str();
314313
}
315314

316315
void Program::separateBlockKernels() {

opencl/source/program/program.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ class Program : public BaseObject<_cl_program> {
187187

188188
void processDebugData();
189189

190-
void updateBuildLog(const Device *pDevice, const char *pErrorString, const size_t errorStringSize);
190+
void updateBuildLog(uint32_t rootDeviceIndex, const char *pErrorString, const size_t errorStringSize);
191191

192-
const char *getBuildLog(const Device *pDevice) const;
192+
const char *getBuildLog(uint32_t rootDeviceIndex) const;
193193

194194
cl_uint getProgramBinaryType() const {
195195
return programBinaryType;
@@ -322,7 +322,11 @@ class Program : public BaseObject<_cl_program> {
322322
std::unique_ptr<LinkerInput> linkerInput;
323323
Linker::RelocatedSymbolsMap symbols;
324324

325-
std::map<const Device *, std::string> buildLog;
325+
struct BuildInfo {
326+
std::string buildLog{};
327+
};
328+
329+
StackVec<BuildInfo, 1> buildInfos;
326330

327331
bool areSpecializationConstantsInitialized = false;
328332
CIF::RAII::UPtr_t<CIF::Builtins::BufferSimple> specConstantsIds;

opencl/test/unit_test/api/cl_create_kernel_tests.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ TEST_F(clCreateKernelTests, GivenInvalidProgramWhenCreatingNewKernelThenInvalidP
168168
TEST_F(clCreateKernelTests, GivenProgramWithBuildErrorWhenCreatingNewKernelThenInvalidProgramExecutableErrorIsReturned) {
169169
cl_kernel kernel = nullptr;
170170
std::unique_ptr<MockProgram> pMockProg = std::make_unique<MockProgram>(*pDevice->getExecutionEnvironment(), pContext, false, nullptr);
171-
pMockProg->SetBuildStatus(CL_BUILD_ERROR);
171+
pMockProg->setBuildStatus(CL_BUILD_ERROR);
172172

173173
kernel = clCreateKernel(
174174
pMockProg.get(),

opencl/test/unit_test/api/cl_link_program_tests.inl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ TEST_F(clLinkProgramTests, GivenProgramsWithSpecConstantsThenSpecConstantsAreEmb
175175
uint32_t prog2Keys[1] = {11};
176176
uint64_t prog2Values[1] = {13};
177177

178-
auto progSrc1 = clUniquePtr(new MockProgram(*pProgram->getDevice().getExecutionEnvironment()));
178+
auto progSrc1 = clUniquePtr(new MockProgram(*pProgram->getDevice().getExecutionEnvironment(), pContext, false, pProgram->pDevice));
179179
progSrc1->pDevice = pProgram->pDevice;
180180
progSrc1->specConstantsValues[prog1Keys[0]] = prog1Values[0];
181181
progSrc1->specConstantsValues[prog1Keys[1]] = prog1Values[1];
@@ -184,21 +184,21 @@ TEST_F(clLinkProgramTests, GivenProgramsWithSpecConstantsThenSpecConstantsAreEmb
184184
progSrc1->irBinarySize = sizeof(ir1);
185185
progSrc1->isSpirV = true;
186186

187-
auto progSrc2 = clUniquePtr(new MockProgram(*pProgram->getDevice().getExecutionEnvironment()));
187+
auto progSrc2 = clUniquePtr(new MockProgram(*pProgram->getDevice().getExecutionEnvironment(), pContext, false, pProgram->pDevice));
188188
progSrc2->pDevice = pProgram->pDevice;
189189
progSrc2->specConstantsValues[prog2Keys[0]] = prog2Values[0];
190190
progSrc2->areSpecializationConstantsInitialized = true;
191191
progSrc2->irBinary = makeCopy(ir2, sizeof(ir2));
192192
progSrc2->irBinarySize = sizeof(ir2);
193193
progSrc2->isSpirV = true;
194194

195-
auto progSrc3 = clUniquePtr(new MockProgram(*pProgram->getDevice().getExecutionEnvironment()));
195+
auto progSrc3 = clUniquePtr(new MockProgram(*pProgram->getDevice().getExecutionEnvironment(), pContext, false, pProgram->pDevice));
196196
progSrc3->pDevice = pProgram->pDevice;
197197
progSrc3->irBinary = makeCopy(ir3, sizeof(ir3));
198198
progSrc3->irBinarySize = sizeof(ir3);
199199
progSrc3->isSpirV = true;
200200

201-
auto progDst = clUniquePtr(new MockProgram(*pProgram->getDevice().getExecutionEnvironment()));
201+
auto progDst = clUniquePtr(new MockProgram(*pProgram->getDevice().getExecutionEnvironment(), pContext, false, pProgram->pDevice));
202202
progDst->pDevice = pProgram->pDevice;
203203
cl_program inputPrograms[3] = {progSrc1.get(), progSrc2.get(), progSrc3.get()};
204204

opencl/test/unit_test/mocks/mock_program.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class MockProgram : public Program {
6565
using Program::unpackedDeviceBinary;
6666
using Program::unpackedDeviceBinarySize;
6767

68-
MockProgram(ExecutionEnvironment &executionEnvironment) : Program(executionEnvironment, nullptr, false, nullptr) {}
68+
MockProgram(ExecutionEnvironment &executionEnvironment) : Program(executionEnvironment, nullptr, false, nullptr) {
69+
}
6970

7071
~MockProgram() override {
7172
if (contextSet)
@@ -102,18 +103,17 @@ class MockProgram : public Program {
102103
contextSet = true;
103104
}
104105

105-
void SetBuildStatus(cl_build_status st) { buildStatus = st; }
106-
void SetSourceCode(const char *ptr) { sourceCode = ptr; }
107-
void ClearOptions() { options = ""; }
108-
void SetCreatedFromBinary(bool createdFromBin) { isCreatedFromBinary = createdFromBin; }
109-
void ClearLog() { buildLog.clear(); }
110-
void SetDevice(Device *pDev) { pDevice = pDev; }
106+
void setBuildStatus(cl_build_status st) { buildStatus = st; }
107+
void setSourceCode(const char *ptr) { sourceCode = ptr; }
108+
void clearOptions() { options = ""; }
109+
void setCreatedFromBinary(bool createdFromBin) { isCreatedFromBinary = createdFromBin; }
110+
void clearLog(uint32_t rootDeviceIndex) { buildInfos[rootDeviceIndex].buildLog.clear(); }
111111

112-
void SetIrBinary(char *ptr, bool isSpirv) {
112+
void setIrBinary(char *ptr, bool isSpirv) {
113113
irBinary.reset(ptr);
114114
this->isSpirV = isSpirV;
115115
}
116-
void SetIrBinarySize(size_t bsz, bool isSpirv) {
116+
void setIrBinarySize(size_t bsz, bool isSpirv) {
117117
irBinarySize = bsz;
118118
this->isSpirV = isSpirV;
119119
}

opencl/test/unit_test/program/process_spir_binary_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ TEST_F(ProcessSpirBinaryTests, WhenProcessingSpirBinaryThenIrBinaryIsSetCorrectl
5151
EXPECT_EQ(binarySize, program->irBinarySize);
5252

5353
// Verify no built log is available
54-
auto pBuildLog = program->getBuildLog(program->getDevicePtr());
55-
EXPECT_EQ(nullptr, pBuildLog);
54+
std::string buildLog = program->getBuildLog(0);
55+
EXPECT_TRUE(buildLog.empty());
5656
}
5757

5858
TEST_F(ProcessSpirBinaryTests, WhenProcessingSpirBinaryThenIsSpirvIsSetBasedonPassedValue) {

opencl/test/unit_test/program/program_data_tests.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ TEST(ProgramLinkBinaryTest, whenLinkerUnresolvedExternalThenLinkFailedAndBuildLo
546546
relocation.offset = 0;
547547
linkerInput->relocations.push_back(NEO::LinkerInput::Relocations{relocation});
548548
linkerInput->traits.requiresPatchingOfInstructionSegments = true;
549-
NEO::ExecutionEnvironment env;
550-
MockProgram program{env};
549+
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
550+
MockProgram program{*device->getExecutionEnvironment(), nullptr, false, device.get()};
551551
KernelInfo kernelInfo = {};
552552
kernelInfo.name = "onlyKernel";
553553
std::vector<char> kernelHeap;
@@ -557,16 +557,17 @@ TEST(ProgramLinkBinaryTest, whenLinkerUnresolvedExternalThenLinkFailedAndBuildLo
557557
program.getKernelInfoArray().push_back(&kernelInfo);
558558
program.linkerInput = std::move(linkerInput);
559559

560-
EXPECT_EQ(nullptr, program.getBuildLog(nullptr));
560+
std::string buildLog = program.getBuildLog(device->getRootDeviceIndex());
561+
EXPECT_TRUE(buildLog.empty());
561562
auto ret = program.linkBinary(program.pDevice, nullptr, nullptr);
562563
EXPECT_NE(CL_SUCCESS, ret);
563564
program.getKernelInfoArray().clear();
564-
auto buildLog = program.getBuildLog(nullptr);
565-
ASSERT_NE(nullptr, buildLog);
565+
buildLog = program.getBuildLog(device->getRootDeviceIndex());
566+
EXPECT_FALSE(buildLog.empty());
566567
Linker::UnresolvedExternals expectedUnresolvedExternals;
567568
expectedUnresolvedExternals.push_back(Linker::UnresolvedExternal{relocation, 0, false});
568569
auto expectedError = constructLinkerErrorMessage(expectedUnresolvedExternals, std::vector<std::string>{"kernel : " + kernelInfo.name});
569-
EXPECT_THAT(buildLog, ::testing::HasSubstr(expectedError));
570+
EXPECT_THAT(buildLog.c_str(), ::testing::HasSubstr(expectedError));
570571
}
571572

572573
TEST_F(ProgramDataTest, whenLinkerInputValidThenIsaIsProperlyPatched) {

0 commit comments

Comments
 (0)