-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Python Migration] Separated common IPEX and PyTorch rules #2654
base: SYCLomatic
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OKay for the current refactor, pls make sure the CI run passed for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to merge, besides the file specified, a extra yaml file will be load, it it not clear behavior for user.
The Linux & Win CPU CI have an expected failure in help_option_check.cpp (PR#2665 is already raised) |
} | ||
|
||
// Get the directory path of the rule file. | ||
llvm::SmallString<128> directoryPath(ruleFilePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the variable naming styles, please use the camel case style, just like the other code style in the DPCT folder.
|
||
// Get the directory path of the rule file. | ||
llvm::SmallString<128> directoryPath(ruleFilePath); | ||
llvm::sys::path::remove_filename(directoryPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above.
// Split the file content into lines using newline as the delimiter. | ||
llvm::StringRef buffContent = std::move(*Buffer)->getBuffer(); | ||
llvm::SmallVector<StringRef, 16> lines; | ||
buffContent.split(lines, "\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using '\n' to split the file, we should make sure the content of the YAML file is ended with '\n' for each line.
// Extract the filename following !include. | ||
std::istringstream iss(lineStr); | ||
std::string incDirective, incRuleFilePath; | ||
// iss >> incDirective >> incRuleFilePath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
// Extract the filename following !include. | ||
std::istringstream iss(lineStr); | ||
std::string incDirective, incRuleFilePath; | ||
// iss >> incDirective >> incRuleFilePath; | ||
iss >> incDirective; | ||
std::getline(iss >> std::ws, incRuleFilePath); | ||
|
||
// Trim trailing spaces from incRuleFilePath | ||
incRuleFilePath.erase(incRuleFilePath.find_last_not_of(" \t\n\r\f\v") + 1); | ||
|
||
if (incDirective == "!include") { | ||
if (!incRuleFilePath.empty()) { | ||
// Remove surrounding quotes if they exist. | ||
if (incRuleFilePath.front() == '"' && incRuleFilePath.back() == '"') { | ||
incRuleFilePath = | ||
incRuleFilePath.substr(1, incRuleFilePath.size() - 2); | ||
} | ||
|
||
// Calculate the absolute path of the included file based on its parent | ||
// rule file | ||
llvm::SmallString<128> incRuleFileAbsPath = directoryPath; | ||
llvm::sys::path::append(incRuleFileAbsPath, incRuleFilePath); | ||
|
||
// Recursively process the included file. | ||
if (llvm::sys::fs::exists(incRuleFileAbsPath)) { | ||
output << readYAMLFile(incRuleFileAbsPath.str())->getBuffer().str() | ||
<< "\n"; | ||
} else { | ||
output << readYAMLFile(incRuleFilePath)->getBuffer().str() << "\n"; | ||
} | ||
} else { | ||
continue; | ||
} | ||
} else { | ||
output << lineStr << "\n"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a single for-loop is enough to handle this.
This PR separates common rules from IPEX & PyTorch rule files into a new rule file and appends them to the user selected rule file