Skip to content

[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 6 commits into from
Aug 2, 2023

Conversation

againull
Copy link
Contributor

@againull againull commented Jul 28, 2023

For example, if reqd_workg_roup_size has max unsigned value then it doesn't fit into signed integer type.
So use signed integer type only for sycl_used_aspects which may have negative values.

If reqd_workg_roup_size has max unsigned value then it doesn't fit into
signed integer type.
@againull againull requested a review from a team as a code owner July 28, 2023 17:01
@againull againull temporarily deployed to aws July 28, 2023 17:28 — with GitHub Actions Inactive
@againull againull temporarily deployed to aws July 28, 2023 18:06 — with GitHub Actions Inactive
@AlexeySachkov
Copy link
Contributor

@jzc: FYI

auto ExtractIntegerFromMDNodeOperand = [=](const MDNode *N,
unsigned OpNo) -> int32_t {
auto ExtractSignedIntegerFromMDNodeOperand = [=](const MDNode *N,
unsigned OpNo) -> int64_t {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@againull againull requested a review from asudarsa July 31, 2023 17:22
@againull againull temporarily deployed to aws July 31, 2023 17:40 — with GitHub Actions Inactive
@againull againull temporarily deployed to aws July 31, 2023 18:24 — with GitHub Actions Inactive
auto ExtractIntegerFromMDNodeOperand = [=](const MDNode *N,
unsigned OpNo) -> int32_t {
auto ExtractSignedIntegerFromMDNodeOperand = [=](const MDNode *N,
unsigned OpNo) -> auto {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to list a concrete return type instead of -> auto here, because it affects readability of the code. Coding standards:

Use auto if and only if it makes the code more readable or easier to maintain. Don’t “almost always” use auto

In this particular case, I don't think that the return type is obvious from a context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, fixed.

@againull againull temporarily deployed to aws August 1, 2023 19:12 — with GitHub Actions Inactive
@againull againull temporarily deployed to aws August 1, 2023 20:33 — with GitHub Actions Inactive
@againull againull temporarily deployed to aws August 2, 2023 18:56 — with GitHub Actions Inactive
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);
Copy link
Contributor

@jzc jzc Aug 2, 2023

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added them in scope of this PR: #10140

@againull againull temporarily deployed to aws August 2, 2023 19:50 — with GitHub Actions Inactive
@againull againull merged commit cee07d3 into intel:sycl Aug 2, 2023
mdtoguchi pushed a commit to mdtoguchi/llvm that referenced this pull request Oct 18, 2023
For example, if reqd_workg_roup_size has max unsigned value then it
doesn't fit into signed integer type.
So use signed integer type only for sycl_used_aspects which may have
negative values.
@againull againull deleted the fix_overflow branch December 22, 2023 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants