-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Fix integer type overflow in SYCLDeviceRequirements #10614
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
358b149
[SYCL] Fix integer type overflow in SYCLDeviceRequirements
againull ab6d106
Fix format
againull 546b073
Remove unnecessary static_cast
againull 0b01171
Explicit return types and remove redundant assert
againull db4285a
Format
againull 35636f5
Merge remote-tracking branch 'origin/sycl' into fix_overflow
againull File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,18 @@ using namespace llvm; | |
void llvm::getSYCLDeviceRequirements( | ||
const module_split::ModuleDesc &MD, | ||
std::map<StringRef, util::PropertyValue> &Requirements) { | ||
auto ExtractIntegerFromMDNodeOperand = [=](const MDNode *N, | ||
unsigned OpNo) -> int32_t { | ||
auto ExtractSignedIntegerFromMDNodeOperand = [=](const MDNode *N, | ||
unsigned OpNo) -> int64_t { | ||
Constant *C = | ||
cast<ConstantAsMetadata>(N->getOperand(OpNo).get())->getValue(); | ||
return static_cast<int32_t>(C->getUniqueInteger().getSExtValue()); | ||
return C->getUniqueInteger().getSExtValue(); | ||
}; | ||
|
||
auto ExtractUnsignedIntegerFromMDNodeOperand = | ||
[=](const MDNode *N, unsigned OpNo) -> uint64_t { | ||
Constant *C = | ||
cast<ConstantAsMetadata>(N->getOperand(OpNo).get())->getValue(); | ||
return C->getUniqueInteger().getZExtValue(); | ||
}; | ||
|
||
// { LLVM-IR metadata name , [SYCL/Device requirements] property name }, see: | ||
|
@@ -42,11 +49,15 @@ void llvm::getSYCLDeviceRequirements( | |
for (const Function &F : MD.getModule()) { | ||
if (const MDNode *MDN = F.getMetadata(MDName)) { | ||
for (size_t I = 0, E = MDN->getNumOperands(); I < E; ++I) { | ||
// Don't put internal aspects (with negative integer value) into the | ||
// requirements, they are used only for device image splitting. | ||
auto Val = ExtractIntegerFromMDNodeOperand(MDN, I); | ||
if (Val >= 0) | ||
Values.insert(Val); | ||
if (std::string(MDName) == "sycl_used_aspects") { | ||
// Don't put internal aspects (with negative integer value) into the | ||
// requirements, they are used only for device image splitting. | ||
auto Val = ExtractSignedIntegerFromMDNodeOperand(MDN, I); | ||
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, where do these internal aspects with negative values come from? I am unfamiliar with them There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added them in scope of this PR: #10140 |
||
if (Val >= 0) | ||
Values.insert(Val); | ||
} else { | ||
Values.insert(ExtractUnsignedIntegerFromMDNodeOperand(MDN, I)); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -69,8 +80,7 @@ void llvm::getSYCLDeviceRequirements( | |
for (const Function *F : MD.entries()) { | ||
if (auto *MDN = F->getMetadata("intel_reqd_sub_group_size")) { | ||
assert(MDN->getNumOperands() == 1); | ||
auto MDValue = ExtractIntegerFromMDNodeOperand(MDN, 0); | ||
assert(MDValue >= 0); | ||
auto MDValue = ExtractUnsignedIntegerFromMDNodeOperand(MDN, 0); | ||
if (!SubGroupSize) | ||
SubGroupSize = MDValue; | ||
else | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we really need 64-bit integers here?
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.
getSExtValue() returns int64_t https://llvm.org/doxygen/classllvm_1_1ConstantInt.html#aa8f4be0661aa64f5b1f20b15e93bb403, so that seemed logically correct to me, otherwise we will need cast to smaller type.
Also removed unnecessary static_cast. from both lambdas.