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

Improve neighbor loads in horizontal_shift of gtfn #1779

Closed

Conversation

iomaganaris
Copy link
Contributor

  • Define separately neighbor variable to avoid extra memory loads in horizontal_shift()

@iomaganaris iomaganaris requested a review from havogt June 4, 2024 07:42
@gridtoolsjenkins
Copy link
Collaborator

Hi there, this is jenkins continuous integration...
Do you want me to verify this patch?

@iomaganaris
Copy link
Contributor Author

launch jenkins

@iomaganaris iomaganaris changed the base branch from try_remove_cuda_arch to master June 4, 2024 08:00
@iomaganaris
Copy link
Contributor Author

launch perftests

@iomaganaris iomaganaris force-pushed the neighbor_read_perf_improvement branch from ca10767 to d302b0b Compare June 6, 2024 08:22
@@ -84,7 +84,8 @@ namespace gridtools::fn {
template <class Tag, class Ptr, class Strides, class Domain, class Conn, class Offset>
GT_FUNCTION constexpr auto horizontal_shift(iterator<Tag, Ptr, Strides, Domain> const &it, Conn, Offset) {
auto const &table = host_device::at_key<Conn>(it.m_domain.m_tables);
auto new_index = it.m_index == -1 ? -1 : get<Offset::value>(neighbor_table::neighbors(table, it.m_index));
const auto neighbor = get<Offset::value>(neighbor_table::neighbors(table, it.m_index));
Copy link
Contributor

Choose a reason for hiding this comment

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

This gives an out-of-bounds access if it.m_index is indeed -1, doesn’t it? (Which is a functional change to the previous code, so it makes sense that the compiler can apply different optimizations, e.g., load the neighbor table independently of the value of it.m_index).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that's true so it makes sense. Is there any case that the m_index check can be avoided? I'm wondering what is special with the nabla kernels that they were the only ones that benefited from this change. Also if the total runtime of the nabla kernels in the production case is small it's probably not worth to try and improve this part.
@havogt since this change alters the behavior and is possibly problematic should there be a test in the CI for a breaking case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, I guess we should go for the compile time has_skip_value check to achieve this and possibly even better performance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I can try it out and launch the perftests CI to check

@fthaler
Copy link
Contributor

fthaler commented Jun 10, 2024

Another thing I noticed: the data layout of the ‘default’ neighbor tables (that is, arrays of tuples) is actually pretty bad: it does not allow for coalesced loads in a reasonable way and does not guarantee any alignment.

@iomaganaris
Copy link
Contributor Author

launch perftests

@iomaganaris
Copy link
Contributor Author

launch jenkins

havogt added a commit that referenced this pull request Jun 18, 2024
Credits to @lukasm91 for hinting to `__builtin_assume` in `deref`. 

On more recent compilers (than 11.2 what we have in CI on daint), will
improve codegen to the level of #1779, but is save.

---------

Co-authored-by: Felix Thaler <[email protected]>
@iomaganaris
Copy link
Contributor Author

Superseded by #1785 since this PR is problematic

havogt added a commit that referenced this pull request Jun 18, 2024
Credits to @lukasm91 for hinting to `__builtin_assume` in `deref`. 

On more recent compilers (than 11.2 what we have in CI on daint), will
improve codegen to the level of #1779, but is save.

---------

Co-authored-by: Felix Thaler <[email protected]>
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