Skip to content

Commit

Permalink
Merge pull request #95 from streeve/variable_vl
Browse files Browse the repository at this point in the history
Variable vector length per atom property
  • Loading branch information
streeve authored Jan 25, 2021
2 parents b97ff88 + ab31b24 commit f46709a
Show file tree
Hide file tree
Showing 20 changed files with 226 additions and 231 deletions.
15 changes: 8 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ env:
- CCACHE_CPP2=yes
matrix:
- BACKENDS="OPENMP"
- BACKENDS="PTHREAD"
- BACKENDS="SERIAL"
- BACKENDS="OPENMP" ArborX=ON
- BACKENDS="OPENMP" NNP=ON
- BACKENDS="OPENMP" ArborX=ON NNP=ON
- BACKENDS="PTHREAD" ArborX=ON NNP=ON
- BACKENDS="PTHREAD" LAYOUT=1
- BACKENDS="SERIAL" LAYOUT=2
- BACKENDS="OPENMP" ArborX=ON LAYOUT=6
- BACKENDS="OPENMP" NNP=ON LAYOUT=1 LAYOUT_NNP=1
- BACKENDS="OPENMP" ArborX=ON NNP=ON LAYOUT=2 LAYOUT_NNP=3
- BACKENDS="PTHREAD" ArborX=ON NNP=ON LAYOUT=6
- BACKENDS="SERIAL" ArborX=ON NNP=ON

addons:
Expand All @@ -39,7 +39,8 @@ addons:
before_script:
- ccache -z
- for i in ${BACKENDS}; do KOKKOS_OPTS+=( -DKokkos_ENABLE_${i}=ON ); done
- for i in ${BACKENDS}; do CABANAMD_OPTS+=( -DCabanaMD_REQUIRE_${i}=ON ); done
- for i in ${LAYOUT}; do CABANAMD_OPTS+=( -DCabanaMD_LAYOUT=${i} ); done
- for i in ${LAYOUT_NNP}; do CABANAMD_OPTS+=( -DCabanaMD_LAYOUT_NNP=${i} ); done
# LD_LIBRARY_PATH workaround for libomp: https://github.com/travis-ci/travis-ci/issues/8613
- if [[ ${CC} = clang ]]; then export LD_LIBRARY_PATH=/usr/local/clang/lib:$LD_LIBRARY_PATH; fi
- if [[ ${CC} = gcc ]]; then export CXX=g++-6; export CC=gcc-6; export FC=gfortran-6; fi
Expand Down
57 changes: 42 additions & 15 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,56 @@
#------------------------------------------------------------
# Set up vector length options
#------------------------------------------------------------
if(NOT CabanaMD_VECTORLENGTH)
if(Kokkos_ENABLE_CUDA)
set(CabanaMD_VECTORLENGTH 32)
macro(CabanaMD_layout)
cmake_parse_arguments(LAYOUT "" "TYPE;PRINT" "ALLOWED" ${ARGN})
set(CabanaMD_${LAYOUT_TYPE} 1 CACHE STRING "Number of AoSoA for${LAYOUT_PRINT} atom properties")
set(_match 0)
foreach(_l ${LAYOUT_ALLOWED})
if(CabanaMD_${LAYOUT_TYPE} EQUAL _l)
set(_match 1)
message(STATUS "Number of AoSoA${LAYOUT_PRINT}: ${CabanaMD_${LAYOUT_TYPE}}")
endif()
endforeach()
if(NOT _match)
message(FATAL_ERROR "Layout${LAYOUT_PRINT} must be one of ${LAYOUT_ALLOWED}")
endif()
endmacro()

macro(CabanaMD_vector_length)
cmake_parse_arguments(VL "" "TYPE;LAYOUT;PRINT" "" ${ARGN})

set(CabanaMD_${VL_TYPE} 1 CACHE STRING "Vector length for all${VL_PRINT} atom AoSoA(s) or semi-colon separated list of vector lengths")
set(CabanaMD_${VL_TYPE}_0 1)

list(LENGTH CabanaMD_${VL_TYPE} _nv_list)
if(_nv_list EQUAL 1)
math(EXPR _nv_loop "${VL_LAYOUT}-1")
foreach(_v RANGE 0 ${_nv_loop})
set(CabanaMD_${VL_TYPE}_${_v} ${CabanaMD_${VL_TYPE}})
endforeach()
elseif(_nv_list EQUAL ${VL_LAYOUT})
set(_count 0)
foreach(_v ${CabanaMD_${VL_TYPE}})
set(CabanaMD_${VL_TYPE}_${_count} ${_v})
math(EXPR _count "${_count}+1")
endforeach()
else()
set(CabanaMD_VECTORLENGTH 1)
message(FATAL_ERROR "Vector length${VL_PRINT} list must be length 1 or match CabanaMD_LAYOUT length")
endif()
endif()
message( STATUS "Using vector length: ${CabanaMD_VECTORLENGTH}" )
message(STATUS "Using vector length(s)${VL_PRINT}: ${CabanaMD_${VL_TYPE}}")
endmacro()

CabanaMD_layout(TYPE LAYOUT ALLOWED "1;2;6")
CabanaMD_vector_length(TYPE VECTORLENGTH LAYOUT ${CabanaMD_LAYOUT})

if(CabanaMD_ENABLE_NNP)
if(NOT CabanaMD_VECTORLENGTH_NNP)
if(Kokkos_ENABLE_CUDA)
set(CabanaMD_VECTORLENGTH_NNP 32)
else()
set(CabanaMD_VECTORLENGTH_NNP 1)
endif()
endif()
message( STATUS "Using vector length: ${CabanaMD_VECTORLENGTH_NNP} (NNP)" )
CabanaMD_layout(TYPE LAYOUT_NNP PRINT " NNP" ALLOWED "1;3")
CabanaMD_vector_length(TYPE VECTORLENGTH_NNP PRINT " NNP" LAYOUT ${CabanaMD_LAYOUT_NNP})

if(NOT CabanaMD_MAXSYMMFUNC_NNP)
set(CabanaMD_MAXSYMMFUNC_NNP 30)
endif()
message( STATUS "Maximum symmetry functions: ${CabanaMD_MAXSYMMFUNC_NNP} (NNP)" )
message(STATUS "Maximum symmetry functions NNP: ${CabanaMD_MAXSYMMFUNC_NNP}")
endif()

#------------------------------------------------------------
Expand Down
20 changes: 13 additions & 7 deletions src/CabanaMD_config.hpp.cmakein
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@

#cmakedefine CabanaMD_ENABLE_NNP

#cmakedefine CabanaMD_LAYOUT_1AoSoA
#cmakedefine CabanaMD_LAYOUT_2AoSoA
#cmakedefine CabanaMD_LAYOUT_6AoSoA
#cmakedefine CabanaMD_VECTORLENGTH @CabanaMD_VECTORLENGTH@
#cmakedefine CabanaMD_LAYOUT @CabanaMD_LAYOUT@
#cmakedefine CabanaMD_VECTORLENGTH "@CabanaMD_VECTORLENGTH@"
#cmakedefine CabanaMD_VECTORLENGTH_0 @CabanaMD_VECTORLENGTH_0@
#cmakedefine CabanaMD_VECTORLENGTH_1 @CabanaMD_VECTORLENGTH_1@
#cmakedefine CabanaMD_VECTORLENGTH_2 @CabanaMD_VECTORLENGTH_2@
#cmakedefine CabanaMD_VECTORLENGTH_3 @CabanaMD_VECTORLENGTH_3@
#cmakedefine CabanaMD_VECTORLENGTH_4 @CabanaMD_VECTORLENGTH_4@
#cmakedefine CabanaMD_VECTORLENGTH_5 @CabanaMD_VECTORLENGTH_5@

#cmakedefine CabanaMD_LAYOUT_NNP_1AoSoA
#cmakedefine CabanaMD_LAYOUT_NNP_3AoSoA
#cmakedefine CabanaMD_VECTORLENGTH_NNP @CabanaMD_VECTORLENGTH_NNP@
#cmakedefine CabanaMD_LAYOUT_NNP @CabanaMD_LAYOUT_NNP@
#cmakedefine CabanaMD_VECTORLENGTH_NNP "@CabanaMD_VECTORLENGTH_NNP@"
#cmakedefine CabanaMD_VECTORLENGTH_NNP_0 @CabanaMD_VECTORLENGTH_NNP_0@
#cmakedefine CabanaMD_VECTORLENGTH_NNP_1 @CabanaMD_VECTORLENGTH_NNP_1@
#cmakedefine CabanaMD_VECTORLENGTH_NNP_2 @CabanaMD_VECTORLENGTH_NNP_2@
#cmakedefine CabanaMD_MAXSYMMFUNC_NNP @CabanaMD_MAXSYMMFUNC_NNP@

#endif
63 changes: 33 additions & 30 deletions src/cabanamd_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,36 +132,39 @@ void CbnMD<t_System, t_Neighbor>::init( InputCL commandline )
else
{
using t_device = typename t_System::device_type;
if ( input->nnp_layout_type == AOSOA_1 )
{
if ( serial_neigh )
force = new ForceNNP<t_System, System_NNP<t_device, AoSoA1>,
t_Neighbor, Cabana::SerialOpTag,
Cabana::SerialOpTag>( system );
if ( team_neigh )
force = new ForceNNP<t_System, System_NNP<t_device, AoSoA1>,
t_Neighbor, Cabana::TeamOpTag,
Cabana::TeamOpTag>( system );
if ( vector_angle )
force = new ForceNNP<t_System, System_NNP<t_device, AoSoA1>,
t_Neighbor, Cabana::TeamOpTag,
Cabana::TeamVectorOpTag>( system );
}
if ( input->nnp_layout_type == AOSOA_3 )
{
if ( serial_neigh )
force = new ForceNNP<t_System, System_NNP<t_device, AoSoA3>,
t_Neighbor, Cabana::SerialOpTag,
Cabana::SerialOpTag>( system );
if ( team_neigh )
force = new ForceNNP<t_System, System_NNP<t_device, AoSoA3>,
t_Neighbor, Cabana::TeamOpTag,
Cabana::TeamOpTag>( system );
if ( vector_angle )
force = new ForceNNP<t_System, System_NNP<t_device, AoSoA3>,
t_Neighbor, Cabana::TeamOpTag,
Cabana::TeamVectorOpTag>( system );
}
#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 );
if ( team_neigh )
force =
new ForceNNP<t_System, System_NNP<t_device, 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 );
#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 );
if ( team_neigh )
force =
new ForceNNP<t_System, System_NNP<t_device, 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 );
#endif
}
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/force_types/modules_system_nnp.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/

#if ( CabanaMD_LAYOUT_NNP == 1 )
#include <system_nnp_1aosoa.h>
#elif ( CabanaMD_LAYOUT_NNP == 3 )
#include <system_nnp_3aosoa.h>
#endif
36 changes: 0 additions & 36 deletions src/inputCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
InputCL::InputCL()
{
device_type = DEFAULT;
layout_type = AOSOA_6;
nnp_layout_type = AOSOA_3;
neighbor_type = NEIGH_VERLET_2D;
force_iteration_type = FORCE_ITER_NEIGH_FULL;
set_force_iteration = false;
Expand Down Expand Up @@ -90,14 +88,6 @@ void InputCL::read_args( int argc, char *argv[] )
" --device-type [TYPE]: Kokkos device type to run ",
"with\n",
" (SERIAL, OPENMP, CUDA, HIP)" );
log( std::cout,
" --layout-type [TYPE]: Number of AoSoA for particle ",
"properties\n",
" (1AOSOA, 2AOSOA, 6AOSOA)" );
log( std::cout,
" --nnp-layout-type [TYPE]: Number of AoSoA for neural ",
"network potential particle properties\n",
" (1AOSOA, 3AOSOA)" );
log( std::cout,
" --force-iteration [TYPE]: Specify iteration style for ",
"force calculations\n",
Expand Down Expand Up @@ -168,32 +158,6 @@ void InputCL::read_args( int argc, char *argv[] )
++i;
}

// AoSoA layout type
else if ( ( strcmp( argv[i], "--layout-type" ) == 0 ) )
{
if ( ( strcmp( argv[i + 1], "1AOSOA" ) == 0 ) )
layout_type = AOSOA_1;
else if ( ( strcmp( argv[i + 1], "2AOSOA" ) == 0 ) )
layout_type = AOSOA_2;
else if ( ( strcmp( argv[i + 1], "6AOSOA" ) == 0 ) )
layout_type = AOSOA_6;
else
log_err( std::cout, "Unknown commandline option: ", argv[i],
" ", argv[i + 1] );
++i;
}
else if ( ( strcmp( argv[i], "--nnp-layout-type" ) == 0 ) )
{
if ( ( strcmp( argv[i + 1], "1AOSOA" ) == 0 ) )
nnp_layout_type = AOSOA_1;
else if ( ( strcmp( argv[i + 1], "3AOSOA" ) == 0 ) )
nnp_layout_type = AOSOA_3;
else
log_err( std::cout, "Unknown commandline option: ", argv[i],
" ", argv[i + 1] );
++i;
}

// Force Iteration Type Related
else if ( ( strcmp( argv[i], "--force-iteration" ) == 0 ) )
{
Expand Down
5 changes: 1 addition & 4 deletions src/inputFile_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ InputFile<t_System>::InputFile( InputCL commandline_, t_System *system_ )
force_type = FORCE_LJ;
binning_type = BINNING_LINKEDCELL;

layout_type = commandline.layout_type;
nnp_layout_type = commandline.nnp_layout_type;
neighbor_type = commandline.neighbor_type;
force_iteration_type = commandline.force_iteration_type;
force_neigh_parallel_type = commandline.force_neigh_parallel_type;
Expand Down Expand Up @@ -487,9 +485,8 @@ void InputFile<t_System>::create_lattice( Comm<t_System> *comm )
std::ofstream out( output_file, std::ofstream::app );

t_System s = *system;
using t_layout = typename t_System::layout_type;
System<Kokkos::Device<Kokkos::DefaultHostExecutionSpace, Kokkos::HostSpace>,
t_layout>
CabanaMD_LAYOUT>
host_system;

using h_t_mass = typename t_System::h_t_mass;
Expand Down
13 changes: 3 additions & 10 deletions src/mdfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,13 @@ class MDfactory
template <typename t_device>
static CabanaMD *createImpl( InputCL commandline )
{
int layout = commandline.layout_type;
int neigh = commandline.neighbor_type;
bool half_neigh =
commandline.force_iteration_type == FORCE_ITER_NEIGH_HALF;

if ( layout == AOSOA_1 )
return createImplSystem<System<t_device, AoSoA1>>( neigh,
half_neigh );
else if ( layout == AOSOA_2 )
return createImplSystem<System<t_device, AoSoA2>>( neigh,
half_neigh );
else if ( layout == AOSOA_6 )
return createImplSystem<System<t_device, AoSoA6>>( neigh,
half_neigh );
return createImplSystem<System<t_device, CabanaMD_LAYOUT>>(
neigh, half_neigh );

return nullptr;
}

Expand Down
4 changes: 4 additions & 0 deletions src/modules_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/

#if ( CabanaMD_LAYOUT == 1 )
#include <system_1aosoa.h>
#elif ( CabanaMD_LAYOUT == 2 )
#include <system_2aosoa.h>
#elif ( CabanaMD_LAYOUT == 6 )
#include <system_6aosoa.h>
#endif
6 changes: 2 additions & 4 deletions src/read_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,8 @@ void read_lammps_data_file( InputFile<t_System> *input, t_System *s,
read_lammps_header<t_System>( file, err, s );

// Use a host mirror for reading from data file
using t_layout = typename t_System::layout_type;
System<Kokkos::Device<Kokkos::DefaultHostExecutionSpace, Kokkos::HostSpace>,
t_layout>
CabanaMD_LAYOUT>
host_system;
// Assume near load balance and resize as necessary
host_system.resize( s->N / comm->num_processes() );
Expand Down Expand Up @@ -384,9 +383,8 @@ void write_data( t_System *s, std::string data_file )
{
std::ofstream data( data_file );

using t_layout = typename t_System::layout_type;
System<Kokkos::Device<Kokkos::DefaultHostExecutionSpace, Kokkos::HostSpace>,
t_layout>
CabanaMD_LAYOUT>
host_s;
s->slice_x();
auto x = s->x;
Expand Down
2 changes: 1 addition & 1 deletion src/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class SystemCommon
virtual const char *name() { return "SystemNone"; }
};

template <class t_device, class t_layout>
template <class t_device, int layout>
class System : public SystemCommon<t_device>
{
public:
Expand Down
28 changes: 12 additions & 16 deletions src/system_types/system_1aosoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,32 @@
#include <system.h>

template <class t_device>
class System<t_device, AoSoA1> : public SystemCommon<t_device>
class System<t_device, 1> : public SystemCommon<t_device>
{
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>;
typename Cabana::AoSoA<t_tuple, t_device, CabanaMD_VECTORLENGTH_0>;
AoSoA_1 aosoa_0;

using SystemCommon<t_device>::N_max;

public:
using SystemCommon<t_device>::SystemCommon;

using layout_type = AoSoA1;

// Per Particle Property
using t_x = typename System<t_device,
AoSoA1>::AoSoA_1::template member_slice_type<0>;
using t_v = typename System<t_device,
AoSoA1>::AoSoA_1::template member_slice_type<1>;
using t_f = typename System<t_device,
AoSoA1>::AoSoA_1::template member_slice_type<2>;
using t_x =
typename System<t_device, 1>::AoSoA_1::template member_slice_type<0>;
using t_v =
typename System<t_device, 1>::AoSoA_1::template member_slice_type<1>;
using t_f =
typename System<t_device, 1>::AoSoA_1::template member_slice_type<2>;
using t_type =
typename System<t_device,
AoSoA1>::AoSoA_1::template member_slice_type<3>;
typename System<t_device, 1>::AoSoA_1::template member_slice_type<3>;
using t_id =
typename System<t_device,
AoSoA1>::AoSoA_1::template member_slice_type<4>;
using t_q = typename System<t_device,
AoSoA1>::AoSoA_1::template member_slice_type<5>;
typename System<t_device, 1>::AoSoA_1::template member_slice_type<4>;
using t_q =
typename System<t_device, 1>::AoSoA_1::template member_slice_type<5>;
t_x x;
t_v v;
t_f f;
Expand Down
Loading

0 comments on commit f46709a

Please sign in to comment.