Skip to content

Commit

Permalink
Remove use of device type in Cabana classes
Browse files Browse the repository at this point in the history
Some type/variable style changes
  • Loading branch information
streeve committed Sep 25, 2024
1 parent 448833d commit 5d3e3c6
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 163 deletions.
6 changes: 3 additions & 3 deletions src/binning_cabana_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ void Binning<t_System>::create_binning( T_X_FLOAT dx_in, T_X_FLOAT dy_in,
system->slice_x();
auto x = system->x;

using device_type = typename t_System::device_type;
Cabana::LinkedCellList<device_type> cell_list( x, begin, end, delta,
min, max );
using memory_space = typename t_System::memory_space;
Cabana::LinkedCellList<memory_space> cell_list( x, begin, end, delta,
min, max );

if ( sort )
{
Expand Down
44 changes: 19 additions & 25 deletions src/cabanamd_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,39 +135,33 @@ void CbnMD<t_System, t_Neighbor>::init( InputCL commandline )
"for the neural network potential." );
else
{
using t_device = typename t_System::device_type;
using device_type = typename t_System::device_type;
#if ( CabanaMD_LAYOUT_NNP == 1 )
if ( serial_neigh )
force =
new ForceNNP<t_System, System_NNP<t_device, 1>, t_Neighbor,
Cabana::SerialOpTag, Cabana::SerialOpTag>(
system );
force = new ForceNNP<t_System, System_NNP<device_type, 1>,
t_Neighbor, Cabana::SerialOpTag,
Cabana::SerialOpTag>( system );
if ( team_neigh )
force =
new ForceNNP<t_System, System_NNP<t_device, 1>, t_Neighbor,
Cabana::TeamOpTag, Cabana::TeamOpTag>(
system );
force = new ForceNNP<t_System, System_NNP<device_type, 1>,
t_Neighbor, Cabana::TeamOpTag,
Cabana::TeamOpTag>( system );
if ( vector_angle )
force =
new ForceNNP<t_System, System_NNP<t_device, 1>, t_Neighbor,
Cabana::TeamOpTag, Cabana::TeamVectorOpTag>(
system );
force = new ForceNNP<t_System, System_NNP<device_type, 1>,
t_Neighbor, Cabana::TeamOpTag,
Cabana::TeamVectorOpTag>( system );
#elif ( CabanaMD_LAYOUT_NNP == 3 )
if ( serial_neigh )
force =
new ForceNNP<t_System, System_NNP<t_device, 3>, t_Neighbor,
Cabana::SerialOpTag, Cabana::SerialOpTag>(
system );
force = new ForceNNP<t_System, System_NNP<device_type, 3>,
t_Neighbor, Cabana::SerialOpTag,
Cabana::SerialOpTag>( system );
if ( team_neigh )
force =
new ForceNNP<t_System, System_NNP<t_device, 3>, t_Neighbor,
Cabana::TeamOpTag, Cabana::TeamOpTag>(
system );
force = new ForceNNP<t_System, System_NNP<device_type, 3>,
t_Neighbor, Cabana::TeamOpTag,
Cabana::TeamOpTag>( system );
if ( vector_angle )
force =
new ForceNNP<t_System, System_NNP<t_device, 3>, t_Neighbor,
Cabana::TeamOpTag, Cabana::TeamVectorOpTag>(
system );
force = new ForceNNP<t_System, System_NNP<device_type, 3>,
t_Neighbor, Cabana::TeamOpTag,
Cabana::TeamVectorOpTag>( system );
#endif
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/comm_mpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Comm
{
// Variables Comm doesn't own but requires for computations

typedef typename t_System::device_type device_type;
using memory_space = typename t_System::memory_space;

T_INT N_local;
T_INT N_ghost;
Expand All @@ -85,20 +85,20 @@ class Comm
int proc_size; // Number of processes
int max_local;

Kokkos::View<int, Kokkos::LayoutRight, device_type,
Kokkos::View<int, Kokkos::LayoutRight, memory_space,
Kokkos::MemoryTraits<Kokkos::Atomic>>
pack_count;

Kokkos::View<T_INT **, Kokkos::LayoutRight, device_type> pack_indicies_all;
Kokkos::View<T_INT *, Kokkos::LayoutRight, device_type> pack_indicies;
Kokkos::View<T_INT **, Kokkos::LayoutRight, device_type> pack_ranks_all;
Kokkos::View<T_INT *, Kokkos::LayoutRight, device_type> pack_ranks;
Kokkos::View<T_INT *, Kokkos::LayoutRight, device_type>
Kokkos::View<T_INT **, Kokkos::LayoutRight, memory_space> pack_indicies_all;
Kokkos::View<T_INT *, Kokkos::LayoutRight, memory_space> pack_indicies;
Kokkos::View<T_INT **, Kokkos::LayoutRight, memory_space> pack_ranks_all;
Kokkos::View<T_INT *, Kokkos::LayoutRight, memory_space> pack_ranks;
Kokkos::View<T_INT *, Kokkos::LayoutRight, memory_space>
pack_ranks_migrate_all;
Kokkos::View<T_INT *, Kokkos::LayoutRight, device_type> pack_ranks_migrate;
Kokkos::View<T_INT *, Kokkos::LayoutRight, memory_space> pack_ranks_migrate;
std::vector<std::vector<int>> neighbors_halo, neighbors_dist;

std::vector<std::shared_ptr<Cabana::Halo<device_type>>> halo_all;
std::vector<std::shared_ptr<Cabana::Halo<memory_space>>> halo_all;

using exe_space = typename t_System::execution_space;

Expand Down
14 changes: 7 additions & 7 deletions src/comm_mpi_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ Comm<t_System>::Comm( t_System *s, T_X_FLOAT comm_depth_ )
MPI_Comm_size( MPI_COMM_WORLD, &proc_size );
MPI_Comm_rank( MPI_COMM_WORLD, &proc_rank );

pack_count = Kokkos::View<int, Kokkos::LayoutRight, device_type>(
pack_count = Kokkos::View<int, Kokkos::LayoutRight, memory_space>(
"CommMPI::pack_count" );
pack_indicies_all =
Kokkos::View<T_INT **, Kokkos::LayoutRight, device_type>(
Kokkos::View<T_INT **, Kokkos::LayoutRight, memory_space>(
"CommMPI::pack_indicies_all", 6, 200 );
pack_ranks_all = Kokkos::View<T_INT **, Kokkos::LayoutRight, device_type>(
pack_ranks_all = Kokkos::View<T_INT **, Kokkos::LayoutRight, memory_space>(
"CommMPI::pack_ranks_all", 6, 200 );
}

Expand Down Expand Up @@ -202,10 +202,10 @@ void Comm<t_System>::exchange()

max_local = x.size() * 1.1;

std::shared_ptr<Cabana::Distributor<device_type>> distributor;
std::shared_ptr<Cabana::Distributor<memory_space>> distributor;

pack_ranks_migrate_all =
Kokkos::View<T_INT *, Kokkos::LayoutRight, device_type>(
Kokkos::View<T_INT *, Kokkos::LayoutRight, memory_space>(
"pack_ranks_migrate", max_local );
Kokkos::parallel_for(
"CommMPI::exchange_self",
Expand Down Expand Up @@ -247,7 +247,7 @@ void Comm<t_System>::exchange()
Kokkos::deep_copy( count, pack_count );
proc_num_send[phase] = count;

distributor = std::make_shared<Cabana::Distributor<device_type>>(
distributor = std::make_shared<Cabana::Distributor<memory_space>>(
MPI_COMM_WORLD, pack_ranks_migrate, neighbors_dist[phase] );
system->migrate( distributor );
system->resize(
Expand Down Expand Up @@ -330,7 +330,7 @@ void Comm<t_System>::exchange_halo()
pack_ranks = Kokkos::subview(
pack_ranks, std::pair<size_t, size_t>( 0, proc_num_send[phase] ) );

halo_all[phase] = std::make_shared<Cabana::Halo<device_type>>(
halo_all[phase] = std::make_shared<Cabana::Halo<memory_space>>(
MPI_COMM_WORLD, N_local + N_ghost, pack_indicies, pack_ranks,
neighbors_halo[phase] );
system->resize( halo_all[phase]->numLocal() +
Expand Down
8 changes: 4 additions & 4 deletions src/inputFile_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ std::vector<std::string> split( const std::string &line )
std::sregex_token_iterator first{ line.begin(), line.end(), re, -1 }, last;
std::vector<std::string> words{ first, last };
// Remove empty
words.erase(
std::remove_if( words.begin(), words.end(),
[]( std::string const &s ) { return s.empty(); } ),
words.end() );
words.erase( std::remove_if( words.begin(), words.end(),
[]( std::string const &s )
{ return s.empty(); } ),
words.end() );
return words;
}

Expand Down
2 changes: 0 additions & 2 deletions src/neighbor_types/neighbor_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ template <class t_System, class t_iteration>
class NeighborTree<t_System, t_iteration, Cabana::VerletLayoutCSR>
: public Neighbor<t_System>
{
using device_type = typename t_System::device_type;
using memory_space = typename t_System::memory_space;

public:
Expand Down Expand Up @@ -73,7 +72,6 @@ template <class t_System, class t_iteration>
class NeighborTree<t_System, t_iteration, Cabana::VerletLayout2D>
: public Neighbor<t_System>
{
using device_type = typename t_System::device_type;
using memory_space = typename t_System::memory_space;

public:
Expand Down
25 changes: 12 additions & 13 deletions src/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@
#include <stdexcept>
#include <string>

template <class t_device>
template <class DeviceType>
class SystemCommon
{
public:
using device_type = t_device;
using device_type = DeviceType;
using memory_space = typename device_type::memory_space;
using execution_space = typename device_type::execution_space;

Expand All @@ -79,9 +79,8 @@ class SystemCommon
std::string atom_style;

// Per Type Property
// typedef typename t_device::array_layout layout;
typedef Kokkos::View<T_V_FLOAT *, t_device> t_mass;
typedef Kokkos::View<const T_V_FLOAT *, t_device> t_mass_const;
typedef Kokkos::View<T_V_FLOAT *, memory_space> t_mass;
typedef Kokkos::View<const T_V_FLOAT *, memory_space> t_mass_const;
typedef typename t_mass::HostMirror h_t_mass;
t_mass mass;

Expand Down Expand Up @@ -241,18 +240,18 @@ class SystemCommon

virtual void init() = 0;
virtual void resize( T_INT N_new ) = 0;
virtual void permute( Cabana::LinkedCellList<t_device> cell_list ) = 0;
virtual void
migrate( std::shared_ptr<Cabana::Distributor<t_device>> distributor ) = 0;
virtual void gather( std::shared_ptr<Cabana::Halo<t_device>> halo ) = 0;
virtual void permute( Cabana::LinkedCellList<memory_space> cell_list ) = 0;
virtual void migrate(
std::shared_ptr<Cabana::Distributor<memory_space>> distributor ) = 0;
virtual void gather( std::shared_ptr<Cabana::Halo<memory_space>> halo ) = 0;
virtual const char *name() { return "SystemNone"; }

private:
// Update local_mesh_* and ghost_mesh* info from global grid
void update_mesh_info()
{
auto local_mesh =
Cabana::Grid::createLocalMesh<t_device>( *local_grid );
Cabana::Grid::createLocalMesh<memory_space>( *local_grid );

local_mesh_lo_x = local_mesh.lowCorner( Cabana::Grid::Own(), 0 );
local_mesh_lo_y = local_mesh.lowCorner( Cabana::Grid::Own(), 1 );
Expand All @@ -272,11 +271,11 @@ class SystemCommon
}
};

template <class t_device, int layout>
class System : public SystemCommon<t_device>
template <class DeviceType, int layout>
class System : public SystemCommon<DeviceType>
{
public:
using SystemCommon<t_device>::SystemCommon;
using SystemCommon<DeviceType>::SystemCommon;
};

#include <modules_system.h>
Expand Down
36 changes: 20 additions & 16 deletions src/system_types/system_1aosoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,37 @@

#include <system.h>

template <class t_device>
class System<t_device, 1> : public SystemCommon<t_device>
template <class DeviceType>
class System<DeviceType, 1> : public SystemCommon<DeviceType>
{
public:
using memory_space = typename DeviceType::memory_space;
using execution_space = typename DeviceType::execution_space;
using SystemCommon<DeviceType>::SystemCommon;

protected:
using t_tuple = Cabana::MemberTypes<T_FLOAT[3], T_FLOAT[3], T_FLOAT[3],
T_INT, T_INT, T_FLOAT>;
using AoSoA_1 =
typename Cabana::AoSoA<t_tuple, t_device, CabanaMD_VECTORLENGTH_0>;
typename Cabana::AoSoA<t_tuple, memory_space, CabanaMD_VECTORLENGTH_0>;
AoSoA_1 aosoa_0;

using SystemCommon<t_device>::N_max;
using SystemCommon<DeviceType>::N_max;

public:
using SystemCommon<t_device>::SystemCommon;

// Per Particle Property
using t_x =
typename System<t_device, 1>::AoSoA_1::template member_slice_type<0>;
typename System<DeviceType, 1>::AoSoA_1::template member_slice_type<0>;
using t_v =
typename System<t_device, 1>::AoSoA_1::template member_slice_type<1>;
typename System<DeviceType, 1>::AoSoA_1::template member_slice_type<1>;
using t_f =
typename System<t_device, 1>::AoSoA_1::template member_slice_type<2>;
typename System<DeviceType, 1>::AoSoA_1::template member_slice_type<2>;
using t_type =
typename System<t_device, 1>::AoSoA_1::template member_slice_type<3>;
typename System<DeviceType, 1>::AoSoA_1::template member_slice_type<3>;
using t_id =
typename System<t_device, 1>::AoSoA_1::template member_slice_type<4>;
typename System<DeviceType, 1>::AoSoA_1::template member_slice_type<4>;
using t_q =
typename System<t_device, 1>::AoSoA_1::template member_slice_type<5>;
typename System<DeviceType, 1>::AoSoA_1::template member_slice_type<5>;
t_x x;
t_v v;
t_f f;
Expand Down Expand Up @@ -75,18 +79,18 @@ class System<t_device, 1> : public SystemCommon<t_device>
void slice_id() override { id = Cabana::slice<4>( aosoa_0 ); }
void slice_q() override { q = Cabana::slice<5>( aosoa_0 ); }

void permute( Cabana::LinkedCellList<t_device> cell_list ) override
void permute( Cabana::LinkedCellList<memory_space> cell_list ) override
{
Cabana::permute( cell_list, aosoa_0 );
}

void migrate(
std::shared_ptr<Cabana::Distributor<t_device>> distributor ) override
void migrate( std::shared_ptr<Cabana::Distributor<memory_space>>
distributor ) override
{
Cabana::migrate( *distributor, aosoa_0 );
}

void gather( std::shared_ptr<Cabana::Halo<t_device>> halo ) override
void gather( std::shared_ptr<Cabana::Halo<memory_space>> halo ) override
{
Cabana::gather( *halo, aosoa_0 );
}
Expand Down
Loading

0 comments on commit 5d3e3c6

Please sign in to comment.