Reuse old build options if new ones are NULL

Change-Id: I435e7ec8554b0429dcf4f6f8d9d4fd80e70b68c6
This commit is contained in:
Jaroslaw Chodor
2020-10-04 11:43:24 +02:00
committed by sys_ocldev
parent cd85bcffdb
commit 746cf7fd33
6 changed files with 47 additions and 4 deletions

View File

@ -68,7 +68,9 @@ bool ModuleTranslationUnit::buildFromSpirV(const char *input, uint32_t inputSize
UNRECOVERABLE_IF(nullptr == compilerInterface);
UNRECOVERABLE_IF((nullptr == device) || (nullptr == device->getNEODevice()));
std::string options = buildOptions;
if (nullptr != buildOptions) {
options = buildOptions;
}
std::string internalOptions = NEO::CompilerOptions::concatenate(internalBuildOptions, BuildOptions::hasBufferOffsetArg);
if (device->getNEODevice()->getDeviceInfo().debuggerActive) {

View File

@ -491,6 +491,26 @@ HWTEST_F(ModuleTranslationUnitTest, WhenCreatingFromNativeBinaryThenSetsUpRequir
EXPECT_FALSE(success);
}
HWTEST_F(ModuleTranslationUnitTest, WhenBuildOptionsAreNullThenReuseExistingOptions) {
struct MockCompilerInterface : CompilerInterface {
TranslationOutput::ErrorCode build(const NEO::Device &device,
const TranslationInput &input,
TranslationOutput &output) override {
receivedApiOptions = input.apiOptions.begin();
return TranslationOutput::ErrorCode::BuildFailure;
}
std::string receivedApiOptions;
} mockCompilerInterface;
L0::ModuleTranslationUnit moduleTu(this->device);
moduleTu.options = "abcd";
this->neoDevice->mockCompilerInterface = &mockCompilerInterface;
auto ret = moduleTu.buildFromSpirV("", 0U, nullptr, "", nullptr);
EXPECT_FALSE(ret);
EXPECT_STREQ("abcd", moduleTu.options.c_str());
EXPECT_STREQ("abcd", mockCompilerInterface.receivedApiOptions.c_str());
}
TEST(BuildOptions, givenNoSrcOptionNameInSrcNamesWhenMovingBuildOptionsThenFalseIsReturned) {
std::string srcNames = NEO::CompilerOptions::concatenate(NEO::CompilerOptions::fastRelaxedMath, NEO::CompilerOptions::finiteMathOnly);
std::string dstNames;

View File

@ -66,7 +66,9 @@ cl_int Program::build(
if (isCreatedFromBinary == false) {
buildStatus = CL_BUILD_IN_PROGRESS;
options = (buildOptions) ? buildOptions : "";
if (nullptr != buildOptions) {
options = buildOptions;
}
extractInternalOptions(options);
applyAdditionalOptions();

View File

@ -970,8 +970,17 @@ TEST_P(ProgramFromSourceTest, GivenDifferentCommpilerOptionsWhenBuildingProgramT
auto hash4 = pProgram->getCachedFileName();
auto kernel4 = pProgram->getKernelInfo("CopyBuffer");
EXPECT_NE(nullptr, kernel4);
EXPECT_EQ(hash1, hash4);
EXPECT_EQ(hash3, hash4);
Callback::unwatch(kernel3);
Callback::watch(kernel4);
retVal = pProgram->build(0, nullptr, "", nullptr, nullptr, true);
EXPECT_EQ(CL_SUCCESS, retVal);
auto hash5 = pProgram->getCachedFileName();
auto kernel5 = pProgram->getKernelInfo("CopyBuffer");
EXPECT_NE(nullptr, kernel5);
EXPECT_EQ(hash1, hash5);
Callback::unwatch(kernel4);
}
TEST_P(ProgramFromSourceTest, GivenEmptyProgramWhenCreatingProgramThenInvalidValueErrorIsReturned) {

View File

@ -84,7 +84,7 @@ class Device : public ReferenceTrackedObject<Device> {
SpecializedDeviceT *getSpecializedDevice() const {
return reinterpret_cast<SpecializedDeviceT *>(specializedDevice);
}
CompilerInterface *getCompilerInterface() const;
MOCKABLE_VIRTUAL CompilerInterface *getCompilerInterface() const;
BuiltIns *getBuiltIns() const;
virtual uint32_t getRootDeviceIndex() const = 0;

View File

@ -126,6 +126,16 @@ class MockDevice : public RootDevice {
static decltype(&createCommandStream) createCommandStreamReceiverFunc;
std::unique_ptr<MemoryManager> mockMemoryManager;
NEO::CompilerInterface *getCompilerInterface() const override {
if (mockCompilerInterface != nullptr) {
return mockCompilerInterface;
} else {
return Device::getCompilerInterface();
}
}
NEO::CompilerInterface *mockCompilerInterface = nullptr;
};
template <>