-
Notifications
You must be signed in to change notification settings - Fork 64
User ScatterView #124
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
User ScatterView #124
Changes from all commits
Commits
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 |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| #define CABANA_COMMUNICATIONPLAN_HPP | ||
|
|
||
| #include <Kokkos_Core.hpp> | ||
| #include <Kokkos_ScatterView.hpp> | ||
|
|
||
| #include <mpi.h> | ||
|
|
||
|
|
@@ -250,19 +251,23 @@ class CommunicationPlan | |
| num_export_host( _num_export.data(), num_n ); | ||
| auto export_counts = Kokkos::create_mirror_view_and_copy( | ||
| memory_space(), num_export_host ); | ||
| auto export_counts_sv = | ||
| Kokkos::Experimental::create_scatter_view( export_counts ); | ||
| auto count_neighbor_func = | ||
| KOKKOS_LAMBDA( const int i ) | ||
| { | ||
| auto export_counts_data = export_counts_sv.access(); | ||
| for ( int n = 0; n < num_n; ++n ) | ||
| if ( topology(n) == element_export_ranks(i) ) | ||
| Kokkos::atomic_increment( &export_counts(n) ); | ||
| export_counts_data(n) += 1; | ||
|
Collaborator
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. Does it support prefix increment?
Collaborator
Author
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. yes |
||
| }; | ||
| Kokkos::RangePolicy<execution_space> count_neighbor_policy( | ||
| 0, _num_export_element ); | ||
| Kokkos::parallel_for( "Cabana::CommunicationPlan::count_neighbors", | ||
| count_neighbor_policy, | ||
| count_neighbor_func ); | ||
| Kokkos::fence(); | ||
| Kokkos::Experimental::contribute( export_counts, export_counts_sv ); | ||
|
|
||
| // Copy counts back to the host. | ||
| Kokkos::deep_copy( num_export_host, export_counts ); | ||
|
|
@@ -357,19 +362,24 @@ class CommunicationPlan | |
| // Count the number of sends this rank will do to other ranks. | ||
| Kokkos::View<int*,memory_space> neighbor_counts( | ||
| "neighbor_counts", comm_size ); | ||
| auto neighbor_counts_sv = | ||
| Kokkos::Experimental::create_scatter_view( neighbor_counts ); | ||
| auto count_sends_func = | ||
| KOKKOS_LAMBDA( const int i ) | ||
| { | ||
| if ( element_export_ranks(i) >= 0 ) | ||
| Kokkos::atomic_increment( | ||
| &neighbor_counts(element_export_ranks(i)) ); | ||
| { | ||
| auto neighbor_counts_data = neighbor_counts_sv.access(); | ||
| neighbor_counts_data(element_export_ranks(i)) += 1; | ||
| } | ||
| }; | ||
| Kokkos::RangePolicy<execution_space> count_sends_policy( | ||
| 0, _num_export_element ); | ||
| Kokkos::parallel_for( "Cabana::CommunicationPlan::count_sends", | ||
| count_sends_policy, | ||
| count_sends_func ); | ||
| Kokkos::fence(); | ||
| Kokkos::Experimental::contribute( neighbor_counts, neighbor_counts_sv ); | ||
|
|
||
| // Copy the counts to the host. | ||
| auto neighbor_counts_host = Kokkos::create_mirror_view_and_copy( | ||
|
|
||
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
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
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.
Are we worried about always having to create the views? Is it worth considering providing a fixed size allocation for us by experts with consistent/regular data patterns/sends?
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 guess then we have to be more careful about resetting the data too
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 guess I'm not sure what you mean 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.
Sorry, I should have been clearer. This makes a
ScatterViewper function invocation, right? And then throws it away at the end?For regular/structured apps, does this imply memory allocation/deallocation of the same size every timestep? Or is this somehow only ever done once and I'm missing a detail?
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 believe it would imply allocation/deallocation of the replicated views if replication is the scatter method of choice. Because we don't have information about the slice the user wants to scatter a priori I think it would be difficult to save the state of a scatter view somewhere unless we developed some type of container approach where the user would register the slices they are scattering.
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.
Yea, that's what I'm thinking. A second advance API where they provide more information. Something for down the road perhaps.