mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-04 15:53:45 +08:00
Ocloc: Add -s to options string for non-spirv input with -g option passed
Automatically add "-s" (source path) option if -g flag is present. This applies only to non-spirv input. - Due to conflict, do not automatically append source path when CMC compiler is used. - Minor code refactor: use defined compiler options instead of local strings; wrap filename in quotes (in case of space-separated filename string). Related-To: NEO-7285 Signed-off-by: Kacper Nowak kacper.nowak@intel.com
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
66f5af0fec
commit
65f7ff2027
@@ -491,10 +491,10 @@ cl_int Program::processInputDevices(ClDeviceVector *&deviceVectorPtr, cl_uint nu
|
||||
}
|
||||
|
||||
void Program::prependFilePathToOptions(const std::string &filename) {
|
||||
ConstStringRef cmcOption = "-cmc";
|
||||
if (!filename.empty() && options.compare(0, cmcOption.size(), cmcOption.data())) {
|
||||
auto isCMCOptionUsed = CompilerOptions::contains(options, CompilerOptions::useCMCompiler);
|
||||
if (!filename.empty() && false == isCMCOptionUsed) {
|
||||
// Add "-s" flag first so it will be ignored by clang in case the options already have this flag set.
|
||||
options = std::string("-s ") + filename + " " + options;
|
||||
options = CompilerOptions::generateSourcePath.str() + " " + CompilerOptions::wrapInQuotes(filename) + " " + options;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1244,6 +1244,123 @@ TEST_F(OfflineCompilerTests, givenDebugOptionThenInternalOptionShouldContainKern
|
||||
EXPECT_TRUE(hasSubstr(internalOptions, "-cl-kernel-debug-enable"));
|
||||
}
|
||||
|
||||
TEST_F(OfflineCompilerTests, givenDebugOptionAndNonSpirvInputThenOptionsShouldContainDashSOptionAppendedAutomatically) {
|
||||
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler());
|
||||
mockOfflineCompiler->uniqueHelper->callBaseFileExists = false;
|
||||
mockOfflineCompiler->uniqueHelper->callBaseLoadDataFromFile = false;
|
||||
mockOfflineCompiler->uniqueHelper->filesMap["some_input.cl"] = "";
|
||||
|
||||
std::vector<std::string> argv = {
|
||||
"ocloc",
|
||||
"-q",
|
||||
"-options",
|
||||
"-g",
|
||||
"-file",
|
||||
"some_input.cl",
|
||||
"-device",
|
||||
gEnvironment->devicePrefix.c_str()};
|
||||
|
||||
mockOfflineCompiler->initialize(argv.size(), argv);
|
||||
const auto &options = mockOfflineCompiler->options;
|
||||
std::string appendedOption{"-s \"some_input.cl\""};
|
||||
EXPECT_TRUE(hasSubstr(options, appendedOption));
|
||||
}
|
||||
|
||||
TEST_F(OfflineCompilerTests, givenDebugOptionAndNonSpirvInputWhenFilenameIsSeparatedWithSpacesThenAppendedSourcePathIsSetCorrectly) {
|
||||
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler());
|
||||
mockOfflineCompiler->uniqueHelper->callBaseFileExists = false;
|
||||
mockOfflineCompiler->uniqueHelper->callBaseLoadDataFromFile = false;
|
||||
mockOfflineCompiler->uniqueHelper->filesMap["filename with spaces.cl"] = "";
|
||||
|
||||
std::vector<std::string> argv = {
|
||||
"ocloc",
|
||||
"-q",
|
||||
"-options",
|
||||
"-g",
|
||||
"-file",
|
||||
"filename with spaces.cl",
|
||||
"-device",
|
||||
gEnvironment->devicePrefix.c_str()};
|
||||
|
||||
const auto result = mockOfflineCompiler->initialize(argv.size(), argv);
|
||||
EXPECT_EQ(OclocErrorCode::SUCCESS, result);
|
||||
const auto &options = mockOfflineCompiler->options;
|
||||
std::string appendedOption{"-s \"filename with spaces.cl\""};
|
||||
EXPECT_TRUE(hasSubstr(options, appendedOption));
|
||||
}
|
||||
|
||||
TEST_F(OfflineCompilerTests, givenDebugOptionAndSpirvInputThenDoNotAppendDashSOptionAutomatically) {
|
||||
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler());
|
||||
mockOfflineCompiler->uniqueHelper->callBaseFileExists = false;
|
||||
mockOfflineCompiler->uniqueHelper->callBaseLoadDataFromFile = false;
|
||||
mockOfflineCompiler->uniqueHelper->filesMap["some_input.spirv"] = "";
|
||||
|
||||
std::vector<std::string> argvSpirvInput = {
|
||||
"ocloc",
|
||||
"-q",
|
||||
"-spirv_input",
|
||||
"-options",
|
||||
"-g",
|
||||
"-file",
|
||||
"some_input.spirv",
|
||||
"-device",
|
||||
gEnvironment->devicePrefix.c_str()};
|
||||
|
||||
mockOfflineCompiler->initialize(argvSpirvInput.size(), argvSpirvInput);
|
||||
const auto &options = mockOfflineCompiler->options;
|
||||
std::string notAppendedOption{"-s \"some_input.spirv\""};
|
||||
EXPECT_FALSE(hasSubstr(options, notAppendedOption));
|
||||
}
|
||||
|
||||
TEST_F(OfflineCompilerTests, givenDebugOptionWhenCompilerIsCMCThenDoNotAppendDashSOptionAutomatically) {
|
||||
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler());
|
||||
mockOfflineCompiler->uniqueHelper->callBaseFileExists = false;
|
||||
mockOfflineCompiler->uniqueHelper->callBaseLoadDataFromFile = false;
|
||||
mockOfflineCompiler->uniqueHelper->filesMap["some_input.cl"] = "";
|
||||
|
||||
std::vector<std::string> argvSpirvInput = {
|
||||
"ocloc",
|
||||
"-q",
|
||||
"-options",
|
||||
"-g -cmc",
|
||||
"-file",
|
||||
"some_input.cl",
|
||||
"-device",
|
||||
gEnvironment->devicePrefix.c_str()};
|
||||
|
||||
mockOfflineCompiler->initialize(argvSpirvInput.size(), argvSpirvInput);
|
||||
const auto &options = mockOfflineCompiler->options;
|
||||
std::string notAppendedOption{"-s \"some_input.spirv\""};
|
||||
EXPECT_FALSE(hasSubstr(options, notAppendedOption));
|
||||
}
|
||||
|
||||
TEST_F(OfflineCompilerTests, givenDebugOptionAndDashSOptionPassedManuallyThenDoNotAppendDashSOptionAutomatically) {
|
||||
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler());
|
||||
mockOfflineCompiler->uniqueHelper->callBaseFileExists = false;
|
||||
mockOfflineCompiler->uniqueHelper->callBaseLoadDataFromFile = false;
|
||||
mockOfflineCompiler->uniqueHelper->filesMap["some_input.cl"] = "";
|
||||
std::vector<std::string> argvDashSPassed = {
|
||||
"ocloc",
|
||||
"-q",
|
||||
"-options",
|
||||
"-g -s \"mockPath/some_input.cl\"",
|
||||
"-file",
|
||||
"some_input.cl",
|
||||
"-device",
|
||||
gEnvironment->devicePrefix.c_str()};
|
||||
|
||||
mockOfflineCompiler->initialize(argvDashSPassed.size(), argvDashSPassed);
|
||||
const auto &options = mockOfflineCompiler->options;
|
||||
std::string appendedOption{"-s"};
|
||||
auto occurrences = 0u;
|
||||
size_t pos = 0u;
|
||||
while ((pos = options.find(appendedOption, pos)) != std::string::npos) {
|
||||
occurrences++;
|
||||
pos++;
|
||||
}
|
||||
EXPECT_EQ(1u, occurrences);
|
||||
}
|
||||
|
||||
TEST_F(OfflineCompilerTests, givenDashGInBiggerOptionStringWhenInitializingThenInternalOptionsShouldNotContainKernelDebugEnable) {
|
||||
|
||||
std::vector<std::string> argv = {
|
||||
|
||||
@@ -141,7 +141,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompi
|
||||
cl_int retVal = pProgram->compile(pProgram->getDevices(), nullptr,
|
||||
0, nullptr, nullptr);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
EXPECT_TRUE(startsWith(pProgram->getOptions(), "-s debugFileName"));
|
||||
EXPECT_TRUE(startsWith(pProgram->getOptions(), "-s \"debugFileName\""));
|
||||
}
|
||||
|
||||
TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsCompiledWithCmCOptionThenDashSFilenameIsNotPrepended) {
|
||||
@@ -194,7 +194,7 @@ TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsBuilt
|
||||
|
||||
cl_int retVal = pProgram->build(pProgram->getDevices(), nullptr, false);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
EXPECT_TRUE(startsWith(pProgram->getOptions(), "-s debugFileName"));
|
||||
EXPECT_TRUE(startsWith(pProgram->getOptions(), "-s \"debugFileName\""));
|
||||
}
|
||||
|
||||
TEST_F(ProgramWithKernelDebuggingTest, givenEnabledKernelDebugWhenProgramIsBuiltWithCmCOptionThenDashSFilenameIsNotPrepended) {
|
||||
|
||||
Reference in New Issue
Block a user