Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions core/src/Cabana_CommunicationPlan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define CABANA_COMMUNICATIONPLAN_HPP

#include <Kokkos_Core.hpp>
#include <Kokkos_ScatterView.hpp>

#include <mpi.h>

Expand Down Expand Up @@ -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 );

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Collaborator Author

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.

Copy link
Copy Markdown
Collaborator

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 ScatterView per 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?

Copy link
Copy Markdown
Collaborator Author

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.

Copy link
Copy Markdown
Collaborator

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.

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;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does it support prefix increment?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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 );
Expand Down Expand Up @@ -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(
Expand Down
18 changes: 11 additions & 7 deletions core/src/Cabana_Halo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ namespace Cabana
number of exports is the number of exports in the gather and the number of
imports is the number of imports in the gather. The reverse *SCATTER*
operation sends the ghosted data back the the uniquely-owned decomposition
and resolves collisions with atomic addition. Based on input for the forward
communication plan (where local data will be sent) the local number of
ghosts is computed. Some nomenclature:
and resolves collisions. Based on input for the forward communication plan
(where local data will be sent) the local number of ghosts is computed. Some
nomenclature:

Export - the local data we uniquely own that we will send to other ranks for
those ranks to be used as ghosts. Export is used in the context of the
Expand Down Expand Up @@ -550,8 +550,12 @@ void scatter( const Halo_t& halo,
for ( int d = 2; d < slice.rank(); ++d )
num_comp *= slice.extent(d);

// Get the raw slice data.
auto slice_data = slice.data();
// Get the raw slice data. Wrap in a 1D Kokkos View so we can unroll the
// components of each slice element.
Kokkos::View<typename Slice_t::value_type*,
typename Slice_t::memory_space,
Kokkos::MemoryTraits<Kokkos::Unmanaged> >
slice_data( slice.data(), slice.numSoA() * slice.stride(0) );

// Allocate a send buffer. Note this one is layout right so the components
// are consecutive.
Expand All @@ -573,7 +577,7 @@ void scatter( const Halo_t& halo,
std::size_t slice_offset = s*slice.stride(0) + a;
for ( int n = 0; n < num_comp; ++n )
send_buffer( i, n ) =
slice_data[ slice_offset + Slice_t::vector_length * n ];
slice_data( slice_offset + Slice_t::vector_length * n );
};
Kokkos::RangePolicy<typename Halo_t::execution_space>
extract_send_buffer_policy( 0, halo.totalNumImport() );
Expand Down Expand Up @@ -650,7 +654,7 @@ void scatter( const Halo_t& halo,
std::size_t slice_offset = s*slice.stride(0) + a;
for ( int n = 0; n < num_comp; ++n )
Kokkos::atomic_add(
slice_data + slice_offset + Slice_t::vector_length * n,
&slice_data(slice_offset + Slice_t::vector_length * n),
recv_buffer(i,n) );
};
Kokkos::RangePolicy<typename Halo_t::execution_space>
Expand Down
7 changes: 5 additions & 2 deletions core/src/Cabana_LinkedCellList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <impl/Cabana_CartesianGrid.hpp>

#include <Kokkos_Core.hpp>
#include <Kokkos_ScatterView.hpp>

namespace Cabana
{
Expand Down Expand Up @@ -225,19 +226,21 @@ class LinkedCellList
Kokkos::RangePolicy<typename OffsetView::execution_space>
particle_range( begin, end );
Kokkos::deep_copy( counts, 0 );
auto counts_sv = Kokkos::Experimental::create_scatter_view( counts );
auto cell_count =
KOKKOS_LAMBDA( const std::size_t p )
{
int i, j, k;
grid.locatePoint(
positions(p,0), positions(p,1), positions(p,2), i , j, k );
Kokkos::atomic_increment(
&counts(grid.cardinalCellIndex(i,j,k)) );
auto counts_data = counts_sv.access();
counts_data(grid.cardinalCellIndex(i,j,k)) += 1;
};
Kokkos::parallel_for( "Cabana::LinkedCellList::build::cell_count",
particle_range,
cell_count );
Kokkos::fence();
Kokkos::Experimental::contribute( counts, counts_sv );

// Compute offsets.
Kokkos::RangePolicy<typename OffsetView::execution_space>
Expand Down