Skip to content
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

Fix a warning for 64-bit 2D Morton codes #640

Merged
merged 1 commit into from
Feb 23, 2022
Merged

Conversation

aprokop
Copy link
Contributor

@aprokop aprokop commented Feb 22, 2022

Introduced in #635.

We do (1 << 31). The problem is that MAX_INT (which is 2147483647) is one smaller than that, which leads to overflow.

NVCC correctly warns about that. But we don't catch Nvidia warnings in CI (see #272), so we missed this.
Not sure why none of the host compilers produced a warning.

This is the only place where it is necessary, all other places shift by less than 31.

This bug potentially leads to construction of a wrong hierarchy.

@aprokop aprokop added the bug Something isn't working label Feb 22, 2022
Copy link
Contributor

@dalg24 dalg24 left a comment

Choose a reason for hiding this comment

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

Can you think of a test that would catch that issue?

src/details/ArborX_DetailsMortonCode.hpp Show resolved Hide resolved
@aprokop
Copy link
Contributor Author

aprokop commented Feb 23, 2022

Can you think of a test that would catch that issue?

So far, no. In fact, unsigned int N = 1 << 31; and unsigned int N = 1u << 31; produce the same value on CPU. However, I had a severe performance degradation when running 2D hacked code on a real problem. I think it may only manifest on a GPU.

@aprokop aprokop removed the bug Something isn't working label Feb 23, 2022
@aprokop
Copy link
Contributor Author

aprokop commented Feb 23, 2022

OK, after careful examination, this is not a bug. It works correctly despite doing a weird thing. The slowdown I observed on GPU was actually caused by a different issue. So this PR is now solely to fix the warning.

We do (1 << 31). The problem is that MAX_INT (which is 2147483647) is
smaller than that, which leads to overflow.

Despite that, `unsigned int N = 1 << 31;` produces correct result, same
as `unsigned int N = 1u << 31;`.
@aprokop aprokop changed the title Fix a bug for 64-bit 2D Morton codes Fix a warning for 64-bit 2D Morton codes Feb 23, 2022
@aprokop aprokop added the build Build and installation label Feb 23, 2022
Copy link
Collaborator

@masterleinad masterleinad left a comment

Choose a reason for hiding this comment

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

I think this is much better even if it's not a bug. The bit shift here really is understood as multiplication that should not overflow.

@aprokop
Copy link
Contributor Author

aprokop commented Feb 23, 2022

Builds passed, only warnings from the SYCL container build.

@aprokop aprokop merged commit f8d122e into arborx:master Feb 23, 2022
@aprokop aprokop deleted the bugfix branch February 23, 2022 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Build and installation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants