mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-04 07:14:10 +08:00
Add warning when device binary had to be recompiled
Introduced a new warning, which is printed to build log, when the binary needs to be recompiled. Added a new flag -Wno-recompiled-from-ir to allow suppression of that message. Removed a bug related to memcpy_s from ModuleBuildLogImp::getString() and aligned it with specification. Related-To: NEO-5819 Signed-off-by: Patryk Wrobel <patryk.wrobel@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
35f6cd00ee
commit
3599e7aeda
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "shared/source/compiler_interface/compiler_interface.h"
|
||||
#include "shared/source/compiler_interface/compiler_warnings/compiler_warnings.h"
|
||||
#include "shared/source/device/device.h"
|
||||
#include "shared/source/device_binary_format/device_binary_formats.h"
|
||||
#include "shared/source/execution_environment/execution_environment.h"
|
||||
@@ -69,6 +70,8 @@ cl_int Program::build(
|
||||
} else if (this->createdFrom != CreatedFrom::BINARY) {
|
||||
options = "";
|
||||
}
|
||||
|
||||
const bool shouldSuppressRebuildWarning{CompilerOptions::extract(CompilerOptions::noRecompiledFromIr, options)};
|
||||
extractInternalOptions(options, internalOptions);
|
||||
applyAdditionalOptions(internalOptions);
|
||||
|
||||
@@ -128,6 +131,9 @@ cl_int Program::build(
|
||||
NEO::TranslationOutput compilerOuput = {};
|
||||
|
||||
for (const auto &clDevice : deviceVector) {
|
||||
if (shouldWarnAboutRebuild && !shouldSuppressRebuildWarning) {
|
||||
this->updateBuildLog(clDevice->getRootDeviceIndex(), CompilerWarnings::recompiledFromIr.data(), CompilerWarnings::recompiledFromIr.length());
|
||||
}
|
||||
auto compilerErr = pCompilerInterface->build(clDevice->getDevice(), inputArgs, compilerOuput);
|
||||
this->updateBuildLog(clDevice->getRootDeviceIndex(), compilerOuput.frontendCompilerLog.c_str(), compilerOuput.frontendCompilerLog.size());
|
||||
this->updateBuildLog(clDevice->getRootDeviceIndex(), compilerOuput.backendCompilerLog.c_str(), compilerOuput.backendCompilerLog.size());
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "shared/source/compiler_interface/compiler_interface.h"
|
||||
#include "shared/source/compiler_interface/compiler_warnings/compiler_warnings.h"
|
||||
#include "shared/source/device/device.h"
|
||||
#include "shared/source/device_binary_format/elf/elf.h"
|
||||
#include "shared/source/device_binary_format/elf/elf_encoder.h"
|
||||
@@ -67,11 +68,11 @@ cl_int Program::compile(
|
||||
}
|
||||
|
||||
options = (buildOptions != nullptr) ? buildOptions : "";
|
||||
const auto shouldSuppressRebuildWarning{CompilerOptions::extract(CompilerOptions::noRecompiledFromIr, options)};
|
||||
|
||||
for (const auto &optionString : {CompilerOptions::gtpinRera, CompilerOptions::greaterThan4gbBuffersRequired}) {
|
||||
size_t pos = options.find(optionString.data());
|
||||
if (pos != std::string::npos) {
|
||||
options.erase(pos, optionString.length());
|
||||
const auto wasExtracted{CompilerOptions::extract(optionString, options)};
|
||||
if (wasExtracted) {
|
||||
CompilerOptions::concatenateAppend(internalOptions, optionString);
|
||||
}
|
||||
}
|
||||
@@ -149,6 +150,10 @@ cl_int Program::compile(
|
||||
TranslationOutput compilerOuput;
|
||||
auto compilerErr = pCompilerInterface->compile(defaultDevice, inputArgs, compilerOuput);
|
||||
for (const auto &device : deviceVector) {
|
||||
if (shouldWarnAboutRebuild && !shouldSuppressRebuildWarning) {
|
||||
this->updateBuildLog(device->getRootDeviceIndex(), CompilerWarnings::recompiledFromIr.data(), CompilerWarnings::recompiledFromIr.length());
|
||||
}
|
||||
|
||||
this->updateBuildLog(device->getRootDeviceIndex(), compilerOuput.frontendCompilerLog.c_str(), compilerOuput.frontendCompilerLog.size());
|
||||
this->updateBuildLog(device->getRootDeviceIndex(), compilerOuput.backendCompilerLog.c_str(), compilerOuput.backendCompilerLog.size());
|
||||
}
|
||||
|
||||
@@ -199,6 +199,7 @@ cl_int Program::createProgramFromBinary(
|
||||
this->buildInfos[rootDeviceIndex].packedDeviceBinarySize = archive.size();
|
||||
} else {
|
||||
this->isCreatedFromBinary = false;
|
||||
this->shouldWarnAboutRebuild = true;
|
||||
}
|
||||
|
||||
switch (singleDeviceBinary.format) {
|
||||
|
||||
@@ -324,6 +324,7 @@ class Program : public BaseObject<_cl_program> {
|
||||
|
||||
std::unordered_map<ClDevice *, DeviceBuildInfo> deviceBuildInfos;
|
||||
bool isCreatedFromBinary = false;
|
||||
bool shouldWarnAboutRebuild = false;
|
||||
|
||||
std::string sourceCode;
|
||||
std::string options;
|
||||
|
||||
@@ -53,6 +53,7 @@ class MockProgram : public Program {
|
||||
using Program::Program;
|
||||
using Program::separateBlockKernels;
|
||||
using Program::setBuildStatus;
|
||||
using Program::shouldWarnAboutRebuild;
|
||||
using Program::sourceCode;
|
||||
using Program::specConstantsIds;
|
||||
using Program::specConstantsSizes;
|
||||
@@ -144,11 +145,19 @@ class MockProgram : public Program {
|
||||
|
||||
cl_int rebuildProgramFromIr() {
|
||||
this->isCreatedFromBinary = false;
|
||||
this->shouldWarnAboutRebuild = true;
|
||||
setBuildStatus(CL_BUILD_NONE);
|
||||
std::unordered_map<std::string, BuiltinDispatchInfoBuilder *> builtins;
|
||||
return this->build(getDevices(), this->options.c_str(), false, builtins);
|
||||
}
|
||||
|
||||
cl_int recompile() {
|
||||
this->isCreatedFromBinary = false;
|
||||
this->shouldWarnAboutRebuild = true;
|
||||
setBuildStatus(CL_BUILD_NONE);
|
||||
return this->compile(getDevices(), this->options.c_str(), 0, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void replaceDeviceBinary(std::unique_ptr<char[]> &&newBinary, size_t newBinarySize, uint32_t rootDeviceIndex) override {
|
||||
if (replaceDeviceBinaryCalledPerRootDevice.find(rootDeviceIndex) == replaceDeviceBinaryCalledPerRootDevice.end()) {
|
||||
replaceDeviceBinaryCalledPerRootDevice.insert({rootDeviceIndex, 1});
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "opencl/test/unit_test/program/program_tests.h"
|
||||
|
||||
#include "shared/source/command_stream/command_stream_receiver_hw.h"
|
||||
#include "shared/source/compiler_interface/compiler_warnings/compiler_warnings.h"
|
||||
#include "shared/source/compiler_interface/intermediate_representations.h"
|
||||
#include "shared/source/device_binary_format/elf/elf_decoder.h"
|
||||
#include "shared/source/device_binary_format/elf/ocl_elf.h"
|
||||
@@ -2577,6 +2578,76 @@ TEST_F(ProgramTests, givenProgramWithSpirvWhenRebuildProgramIsCalledThenSpirvPat
|
||||
EXPECT_EQ(IGC::CodeType::oclGenBin, compilerInterface->requestedTranslationCtxs[0].second);
|
||||
}
|
||||
|
||||
TEST_F(ProgramTests, givenProgramWithSpirvWhenRebuildIsCalledThenRebuildWarningIsIssued) {
|
||||
const auto program{clUniquePtr(new MockProgram(toClDeviceVector(*pClDevice)))};
|
||||
uint32_t spirv[16] = {0x03022307, 0x23471113, 0x17192329};
|
||||
program->irBinary = makeCopy(spirv, sizeof(spirv));
|
||||
program->irBinarySize = sizeof(spirv);
|
||||
program->isSpirV = true;
|
||||
|
||||
const auto buildResult{program->rebuildProgramFromIr()};
|
||||
ASSERT_EQ(CL_SUCCESS, buildResult);
|
||||
|
||||
const std::string buildLog{program->getBuildLog(pClDevice->getRootDeviceIndex())};
|
||||
const auto containsWarning{buildLog.find(CompilerWarnings::recompiledFromIr.data()) != std::string::npos};
|
||||
|
||||
EXPECT_TRUE(containsWarning);
|
||||
}
|
||||
|
||||
TEST_F(ProgramTests, givenProgramWithSpirvWhenRebuildIsCalledButSuppressFlagIsEnabledThenRebuildWarningIsNotIssued) {
|
||||
const auto program{clUniquePtr(new MockProgram(toClDeviceVector(*pClDevice)))};
|
||||
uint32_t spirv[16] = {0x03022307, 0x23471113, 0x17192329};
|
||||
program->irBinary = makeCopy(spirv, sizeof(spirv));
|
||||
program->irBinarySize = sizeof(spirv);
|
||||
program->isSpirV = true;
|
||||
|
||||
const auto buildOptions{CompilerOptions::noRecompiledFromIr};
|
||||
program->setBuildOptions(buildOptions.data());
|
||||
|
||||
const auto buildResult{program->rebuildProgramFromIr()};
|
||||
ASSERT_EQ(CL_SUCCESS, buildResult);
|
||||
|
||||
const std::string buildLog{program->getBuildLog(pClDevice->getRootDeviceIndex())};
|
||||
const auto containsWarning{buildLog.find(CompilerWarnings::recompiledFromIr.data()) != std::string::npos};
|
||||
|
||||
EXPECT_FALSE(containsWarning);
|
||||
}
|
||||
|
||||
TEST_F(ProgramTests, givenProgramWithSpirvWhenRecompileIsCalledThenRebuildWarningIsIssued) {
|
||||
const auto program{clUniquePtr(new MockProgram(toClDeviceVector(*pClDevice)))};
|
||||
uint32_t spirv[16] = {0x03022307, 0x23471113, 0x17192329};
|
||||
program->irBinary = makeCopy(spirv, sizeof(spirv));
|
||||
program->irBinarySize = sizeof(spirv);
|
||||
program->isSpirV = true;
|
||||
|
||||
const auto compileResult{program->recompile()};
|
||||
ASSERT_EQ(CL_SUCCESS, compileResult);
|
||||
|
||||
const std::string buildLog{program->getBuildLog(pClDevice->getRootDeviceIndex())};
|
||||
const auto containsWarning{buildLog.find(CompilerWarnings::recompiledFromIr.data()) != std::string::npos};
|
||||
|
||||
EXPECT_TRUE(containsWarning);
|
||||
}
|
||||
|
||||
TEST_F(ProgramTests, givenProgramWithSpirvWhenRecompileIsCalledButSuppressFlagIsEnabledThenRebuildWarningIsNotIssued) {
|
||||
const auto program{clUniquePtr(new MockProgram(toClDeviceVector(*pClDevice)))};
|
||||
uint32_t spirv[16] = {0x03022307, 0x23471113, 0x17192329};
|
||||
program->irBinary = makeCopy(spirv, sizeof(spirv));
|
||||
program->irBinarySize = sizeof(spirv);
|
||||
program->isSpirV = true;
|
||||
|
||||
const auto buildOptions{CompilerOptions::noRecompiledFromIr};
|
||||
program->setBuildOptions(buildOptions.data());
|
||||
|
||||
const auto compileResult{program->recompile()};
|
||||
ASSERT_EQ(CL_SUCCESS, compileResult);
|
||||
|
||||
const std::string buildLog{program->getBuildLog(pClDevice->getRootDeviceIndex())};
|
||||
const auto containsWarning{buildLog.find(CompilerWarnings::recompiledFromIr.data()) != std::string::npos};
|
||||
|
||||
EXPECT_FALSE(containsWarning);
|
||||
}
|
||||
|
||||
TEST_F(ProgramTests, whenRebuildingProgramThenStoreDeviceBinaryProperly) {
|
||||
auto compilerInterface = new MockCompilerInterface();
|
||||
pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->compilerInterface.reset(compilerInterface);
|
||||
@@ -2766,6 +2837,25 @@ TEST(CreateProgramFromBinaryTests, givenBinaryProgramBuiltInWhenKernelRebulildIs
|
||||
EXPECT_EQ(nullptr, pProgram->buildInfos[rootDeviceIndex].packedDeviceBinary);
|
||||
EXPECT_EQ(0U, pProgram->buildInfos[rootDeviceIndex].packedDeviceBinarySize);
|
||||
}
|
||||
|
||||
TEST(CreateProgramFromBinaryTests, givenBinaryProgramBuiltInWhenKernelRebulildIsForcedThenRebuildWarningIsEnabled) {
|
||||
DebugManagerStateRestore dbgRestorer{};
|
||||
DebugManager.flags.RebuildPrecompiledKernels.set(true);
|
||||
|
||||
PatchTokensTestData::ValidEmptyProgram programTokens;
|
||||
cl_int retVal{CL_INVALID_BINARY};
|
||||
|
||||
const auto clDevice = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
||||
std::unique_ptr<MockProgram> pProgram(Program::createBuiltInFromGenBinary<MockProgram>(nullptr, toClDeviceVector(*clDevice), programTokens.storage.data(), programTokens.storage.size(), &retVal));
|
||||
ASSERT_NE(nullptr, pProgram.get());
|
||||
ASSERT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
retVal = pProgram->createProgramFromBinary(programTokens.storage.data(), programTokens.storage.size(), *clDevice);
|
||||
ASSERT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
ASSERT_TRUE(pProgram->shouldWarnAboutRebuild);
|
||||
}
|
||||
|
||||
TEST(CreateProgramFromBinaryTests, givenBinaryProgramNotBuiltInWhenBuiltInKernelRebulildIsForcedThenDeviceBinaryIsUsed) {
|
||||
DebugManagerStateRestore dbgRestorer;
|
||||
DebugManager.flags.RebuildPrecompiledKernels.set(true);
|
||||
|
||||
Reference in New Issue
Block a user