Skip to content

Commit 4191dfd

Browse files
Prepend -s option when -cmc is not used
Related-To: NEO-5582 - "-s filename" is added to build options based on filename returned from debugger - when "-cmc" is passed as first option, do not modify user options. Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
1 parent 042e971 commit 4191dfd

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

opencl/source/program/build.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -99,10 +99,7 @@ cl_int Program::build(
9999
}
100100
appendKernelDebugOptions(*clDevice, internalOptions);
101101
notifyDebuggerWithSourceCode(*clDevice, filename);
102-
if (!filename.empty()) {
103-
// Add "-s" flag first so it will be ignored by clang in case the options already have this flag set.
104-
options = std::string("-s ") + filename + " " + options;
105-
}
102+
prependFilePathToOptions(filename);
106103

107104
phaseReached[clDevice->getRootDeviceIndex()] = BuildPhase::SourceCodeNotification;
108105
}

opencl/source/program/compile.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -129,12 +129,10 @@ cl_int Program::compile(
129129
if (sourceLevelDebuggerNotified[device->getRootDeviceIndex()]) {
130130
continue;
131131
}
132-
appendKernelDebugOptions(*device, internalOptions);
133132
std::string filename;
133+
appendKernelDebugOptions(*device, internalOptions);
134134
notifyDebuggerWithSourceCode(*device, filename);
135-
if (!filename.empty()) {
136-
options = std::string("-s ") + filename + " " + options;
137-
}
135+
prependFilePathToOptions(filename);
138136

139137
sourceLevelDebuggerNotified[device->getRootDeviceIndex()] = true;
140138
}

opencl/source/program/program.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,4 +546,13 @@ cl_int Program::processInputDevices(ClDeviceVector *&deviceVectorPtr, cl_uint nu
546546
}
547547
return CL_SUCCESS;
548548
}
549+
550+
void Program::prependFilePathToOptions(const std::string &filename) {
551+
ConstStringRef cmcOption = "-cmc";
552+
if (!filename.empty() && options.compare(0, cmcOption.size(), cmcOption.data())) {
553+
// Add "-s" flag first so it will be ignored by clang in case the options already have this flag set.
554+
options = std::string("-s ") + filename + " " + options;
555+
}
556+
}
557+
549558
} // namespace NEO

opencl/source/program/program.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2020 Intel Corporation
2+
* Copyright (C) 2017-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -296,6 +296,7 @@ class Program : public BaseObject<_cl_program> {
296296

297297
MOCKABLE_VIRTUAL bool appendKernelDebugOptions(ClDevice &clDevice, std::string &internalOptions);
298298
void notifyDebuggerWithSourceCode(ClDevice &clDevice, std::string &filename);
299+
void prependFilePathToOptions(const std::string &filename);
299300

300301
void setBuildStatus(cl_build_status status);
301302
void setBuildStatusSuccess(const ClDeviceVector &deviceVector, cl_program_binary_type binaryType);

opencl/test/unit_test/program/program_with_kernel_debug_tests.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2020 Intel Corporation
2+
* Copyright (C) 2018-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -129,6 +129,19 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompi
129129
EXPECT_THAT(pProgram->getOptions(), ::testing::StartsWith("-s debugFileName"));
130130
}
131131

132+
TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompiledWithCmCOptionThenDashSFilenameIsNotPrepended) {
133+
MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger;
134+
sourceLevelDebugger->sourceCodeFilename = "debugFileName";
135+
pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger);
136+
137+
char options[] = "-cmc -cl-opt-disable";
138+
cl_int retVal = pProgram->compile(pProgram->getDevices(), options,
139+
0, nullptr, nullptr);
140+
EXPECT_EQ(CL_SUCCESS, retVal);
141+
EXPECT_THAT(pProgram->getOptions(), ::testing::Not(::testing::StartsWith("-s debugFileName")));
142+
EXPECT_THAT(pProgram->getOptions(), ::testing::HasSubstr(CompilerOptions::optDisable.data()));
143+
}
144+
132145
TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsBuiltThenInternalOptionsIncludeDebugFlag) {
133146
std::string receivedInternalOptions;
134147

@@ -169,6 +182,17 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsBuilt
169182
EXPECT_THAT(pProgram->getOptions(), ::testing::StartsWith("-s debugFileName"));
170183
}
171184

185+
TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsBuiltWithCmCOptionThenDashSFilenameIsNotPrepended) {
186+
MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger;
187+
sourceLevelDebugger->sourceCodeFilename = "debugFileName";
188+
pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger);
189+
190+
char options[] = "-cmc -cl-opt-disable";
191+
cl_int retVal = pProgram->build(pProgram->getDevices(), options, false);
192+
EXPECT_EQ(CL_SUCCESS, retVal);
193+
EXPECT_THAT(pProgram->getOptions(), ::testing::Not(::testing::StartsWith("-s debugFileName")));
194+
}
195+
172196
TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsLinkedThenKernelDebugOptionsAreAppended) {
173197
MockActiveSourceLevelDebugger *sourceLevelDebugger = new MockActiveSourceLevelDebugger;
174198
pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->debugger.reset(sourceLevelDebugger);

0 commit comments

Comments
 (0)