Skip to content

Commit 2207666

Browse files
Pass options to compiler during program linking
"-cl-intel-gtpin-rera" and "-cl-intel-greater-than-4GB-buffer-required" passed to compiler as internal options Resolves: NEO-4723 Change-Id: I059027880e9a98aa063f4cd64e84e28311663f46 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
1 parent 4324b01 commit 2207666

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

opencl/source/program/link.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ cl_int Program::link(
6868

6969
options = (buildOptions != nullptr) ? buildOptions : "";
7070

71+
for (const auto &optionString : {CompilerOptions::gtpinRera, CompilerOptions::greaterThan4gbBuffersRequired}) {
72+
size_t pos = options.find(optionString);
73+
if (pos != std::string::npos) {
74+
options.erase(pos, optionString.length());
75+
CompilerOptions::concatenateAppend(internalOptions, optionString);
76+
}
77+
}
78+
7179
if (isKernelDebugEnabled()) {
7280
appendKernelDebugOptions();
7381
}

opencl/test/unit_test/program/program_tests.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,34 @@ TEST_P(ProgramFromSourceTest, GivenFlagsWhenCompilingProgramThenBuildOptionsHave
10921092
EXPECT_TRUE(CompilerOptions::contains(cip->buildInternalOptions, pPlatform->getClDevice(0)->peekCompilerExtensions())) << cip->buildInternalOptions;
10931093
}
10941094

1095+
TEST_F(ProgramTests, GivenFlagsWhenLinkingProgramThenBuildOptionsHaveBeenApplied) {
1096+
auto cip = new MockCompilerInterfaceCaptureBuildOptions();
1097+
auto pProgram = std::make_unique<SucceedingGenBinaryProgram>(*pDevice->getExecutionEnvironment());
1098+
pProgram->setDevice(pDevice);
1099+
pProgram->sourceCode = "__kernel mock() {}";
1100+
pProgram->createdFrom = Program::CreatedFrom::SOURCE;
1101+
1102+
cl_program program = pProgram.get();
1103+
1104+
// compile successfully a kernel to be linked later
1105+
cl_int retVal = pProgram->compile(0, nullptr, nullptr, 0, nullptr, nullptr, nullptr, nullptr);
1106+
EXPECT_EQ(CL_SUCCESS, retVal);
1107+
1108+
// Ask to link created program with NEO::CompilerOptions::gtpinRera and NEO::CompilerOptions::greaterThan4gbBuffersRequired flags.
1109+
auto options = CompilerOptions::concatenate(CompilerOptions::greaterThan4gbBuffersRequired, CompilerOptions::gtpinRera, CompilerOptions::finiteMathOnly);
1110+
1111+
pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->compilerInterface.reset(cip);
1112+
1113+
retVal = pProgram->link(0, nullptr, options.c_str(), 1, &program, nullptr, nullptr);
1114+
EXPECT_EQ(CL_SUCCESS, retVal);
1115+
1116+
// Check build options that were applied
1117+
EXPECT_FALSE(CompilerOptions::contains(cip->buildOptions, CompilerOptions::fastRelaxedMath)) << cip->buildOptions;
1118+
EXPECT_TRUE(CompilerOptions::contains(cip->buildOptions, CompilerOptions::finiteMathOnly)) << cip->buildOptions;
1119+
EXPECT_TRUE(CompilerOptions::contains(cip->buildInternalOptions, CompilerOptions::gtpinRera)) << cip->buildInternalOptions;
1120+
EXPECT_TRUE(CompilerOptions::contains(cip->buildInternalOptions, CompilerOptions::greaterThan4gbBuffersRequired)) << cip->buildInternalOptions;
1121+
}
1122+
10951123
TEST_P(ProgramFromSourceTest, GivenAdvancedOptionsWhenCreatingProgramThenSuccessIsReturned) {
10961124
std::string testFile;
10971125
size_t sourceSize = 0;

shared/test/unit_test/mocks/mock_compiler_interface.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ struct MockCompilerInterfaceCaptureBuildOptions : CompilerInterface {
168168
return this->MockCompilerInterfaceCaptureBuildOptions::compile(device, input, out);
169169
}
170170

171+
TranslationOutput::ErrorCode link(const NEO::Device &device,
172+
const TranslationInput &input,
173+
TranslationOutput &output) override {
174+
return this->MockCompilerInterfaceCaptureBuildOptions::compile(device, input, output);
175+
}
176+
171177
std::string buildOptions;
172178
std::string buildInternalOptions;
173179
};

0 commit comments

Comments
 (0)