Skip to content

Commit

Permalink
Merge pull request #30 from streeve/split_aosoa
Browse files Browse the repository at this point in the history
Flexible number of AoSoA and vector lengths
  • Loading branch information
streeve authored Apr 2, 2020
2 parents 25ef3b2 + 6ad6c93 commit 74a470b
Show file tree
Hide file tree
Showing 49 changed files with 1,757 additions and 977 deletions.
12 changes: 4 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,16 @@ foreach(_device ${CABANAMD_SUPPORTED_DEVICES})
endif()
endforeach()


##---------------------------------------------------------------------------##
# Set up optional libraries
# Set up neural network options
##---------------------------------------------------------------------------##

option(CabanaMD_ENABLE_NNP "Build CabanaMD with neural network potential (and n2p2 libnnp)" OFF)
if(NOT DEFINED N2P2_DIR)
set(N2P2_DIR ~/n2p2/)
endif()

##---------------------------------------------------------------------------##
## Print the revision number to stdout
## Print the Git revision number to stdout
##---------------------------------------------------------------------------##
FIND_PACKAGE(Git)
IF(GIT_FOUND AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.git)
Expand All @@ -60,26 +58,24 @@ MESSAGE(STATUS "CabanaMD Revision = '${CabanaMD_GIT_COMMIT_HASH}'")
##---------------------------------------------------------------------------##
## Build CabanaMD
##---------------------------------------------------------------------------##

add_subdirectory(src)
add_subdirectory(bin)

##---------------------------------------------------------------------------##
## Enable Tests?
##---------------------------------------------------------------------------##

option(CabanaMD_ENABLE_TESTING "Build tests" OFF)
if(CabanaMD_ENABLE_TESTING)
enable_testing()
add_subdirectory(unit_test)
endif()

##---------------------------------------------------------------------------##
## Pretty-printing wizardry:
## Clang format
##---------------------------------------------------------------------------##
find_package(CLANG_FORMAT)
if(CLANG_FORMAT_FOUND)
file(GLOB_RECURSE FORMAT_SOURCES src/*.cpp src/*.h)
file(GLOB_RECURSE FORMAT_SOURCES src/*.cpp src/*.h bin/*.cpp)
add_custom_target(format
COMMAND ${CLANG_FORMAT_EXECUTABLE} -i -style=file ${FORMAT_SOURCES}
DEPENDS ${FORMAT_SOURCES})
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ cmake \
-D CabanaMD_ENABLE_Serial=OFF \
-D CabanaMD_ENABLE_OpenMP=ON \
-D CabanaMD_ENABLE_Cuda=OFF \
-D CabanaMD_VECTORLENGTH=1 \
\
.. ;
make install
Expand All @@ -67,15 +68,17 @@ cmake \
-D CabanaMD_ENABLE_Serial=OFF \
-D CabanaMD_ENABLE_OpenMP=OFF \
-D CabanaMD_ENABLE_Cuda=ON \
-D CabanaMD_VECTORLENGTH=32 \
\
.. ;
```

## Neural network potential build
If using the optional neural network potential, additional flags for the
If using the optional neural network potential, additional CMake flags for the
location of the libnnp library (https://github.com/CompPhysVienna/n2p2)
and enabling the potential are needed for CMake:
and enabling the potential are needed (with one additional optional setting):
```
-D N2P2_DIR=$N2P2_INSTALL_DIR \
-D CabanaMD_ENABLE_NNP=ON \
-D CabanaMD_VECTORLENGTH_NNP=1 \
```
20 changes: 10 additions & 10 deletions bin/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,29 @@
//************************************************************************

#include <cabanamd.h>

// CabanaMD can be used as a library
// This main file is simply a driver
#include <mdfactory.h>
#include <types.h>

#include "mpi.h"

// CabanaMD can be used as a library
// This main file is simply a driver
int main( int argc, char *argv[] )
{

MPI_Init( &argc, &argv );

Kokkos::ScopeGuard scope_guard( argc, argv );

CabanaMD cabanamd;
cabanamd.init( argc, argv );

cabanamd.run( cabanamd.input->nsteps );
InputCL commandline;
commandline.read_args( argc, argv );

// cabanamd.check_correctness();
CabanaMD *cabanamd = MDfactory::create( commandline );

cabanamd.print_performance();
cabanamd->init( commandline );
cabanamd->run();

cabanamd.shutdown();
// cabanamd.check_correctness();

MPI_Finalize();
}
33 changes: 30 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
configure_file(CabanaMD_config.hpp.cmakein CabanaMD_config.hpp)
#------------------------------------------------------------
# Set up vector length options
#------------------------------------------------------------
if(NOT CabanaMD_VECTORLENGTH)
if(Kokkos_ENABLE_CUDA)
set(CabanaMD_VECTORLENGTH 32)
else()
set(CabanaMD_VECTORLENGTH 1)
endif()
endif()
message( STATUS "Using vector length: ${CabanaMD_VECTORLENGTH}" )

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)" )
endif()

#------------------------------------------------------------

configure_file(CabanaMD_config.hpp.cmakein CabanaMD_config.hpp @ONLY)

#------------------------------------------------------------

file(GLOB HEADERS_PUBLIC
GLOB *.h force_types/*.h
GLOB *.h force_types/*.h system_types/*.h
)

file(GLOB SOURCES
Expand All @@ -15,7 +40,8 @@ if(CabanaMD_ENABLE_NNP)
else()
file(GLOB FORCE_TYPES force_types/force_lj*.cpp)
endif()
list(APPEND SOURCES ${FORCE_TYPES})

list(APPEND SOURCES ${FORCE_TYPES} ${SYSTEM_TYPES} ${SYSNNP_TYPES})

install(FILES ${HEADERS_PUBLIC} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CabanaMD_config.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
Expand All @@ -27,6 +53,7 @@ add_library(CabanaMD ${SOURCES})
# Sources linking against CabanaMD will implicitly include these directories:
target_include_directories(CabanaMD PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/force_types
${CMAKE_CURRENT_SOURCE_DIR}/system_types
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)

Expand Down
10 changes: 10 additions & 0 deletions src/CabanaMD_config.hpp.cmakein
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
#cmakedefine CabanaMD_ENABLE_Threads
#cmakedefine CabanaMD_ENABLE_OpenMP
#cmakedefine CabanaMD_ENABLE_Cuda

#cmakedefine CabanaMD_ENABLE_NNP

#cmakedefine CabanaMD_LAYOUT_1AoSoA
#cmakedefine CabanaMD_LAYOUT_2AoSoA
#cmakedefine CabanaMD_LAYOUT_6AoSoA
#cmakedefine CabanaMD_VECTORLENGTH @CabanaMD_VECTORLENGTH@

#cmakedefine CabanaMD_LAYOUT_NNP_1AoSoA
#cmakedefine CabanaMD_LAYOUT_NNP_3AoSoA
#cmakedefine CabanaMD_VECTORLENGTH_NNP @CabanaMD_VECTORLENGTH_NNP@

#endif
8 changes: 5 additions & 3 deletions src/binning_cabana.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,21 @@

#include <Cabana_Core.hpp>

template <class t_System>
class Binning
{
System *system;
t_System *system;

public:
T_INT nbinx, nbiny, nbinz, nhalo;
T_X_FLOAT minx, maxx, miny, maxy, minz, maxz;
typename AoSoA::member_slice_type<Positions> x;

Binning( System *s );
Binning( t_System *s );
void create_binning( T_X_FLOAT dx, T_X_FLOAT dy, T_X_FLOAT dz,
int halo_depth, bool do_local, bool do_ghost,
bool sort );
const char *name();
};

#include <binning_cabana_impl.h>
#endif
24 changes: 15 additions & 9 deletions src/binning_cabana.cpp → src/binning_cabana_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@
//
//************************************************************************

#include <binning_cabana.h>

Binning::Binning( System *s )
template <class t_System>
Binning<t_System>::Binning( t_System *s )
: system( s )
{
}

void Binning::create_binning( T_X_FLOAT dx_in, T_X_FLOAT dy_in, T_X_FLOAT dz_in,
int halo_depth, bool do_local, bool do_ghost,
bool sort )
template <class t_System>
void Binning<t_System>::create_binning( T_X_FLOAT dx_in, T_X_FLOAT dy_in,
T_X_FLOAT dz_in, int halo_depth,
bool do_local, bool do_ghost,
bool sort )
{
if ( do_local || do_ghost )
{
Expand Down Expand Up @@ -91,15 +92,20 @@ void Binning::create_binning( T_X_FLOAT dx_in, T_X_FLOAT dy_in, T_X_FLOAT dz_in,
T_X_FLOAT min[3] = {minx, miny, minz};
T_X_FLOAT max[3] = {maxx, maxy, maxz};

x = Cabana::slice<Positions>( system->xvf );
system->slice_x();
auto x = system->x;

t_linkedcell cell_list( x, begin, end, delta, min, max );

if ( sort )
{
Cabana::permute( cell_list, system->xvf );
system->permute( cell_list );
}
}
}

const char *Binning::name() { return "Binning:CabanaLinkedCell"; }
template <class t_System>
const char *Binning<t_System>::name()
{
return "Binning:CabanaLinkedCell";
}
43 changes: 28 additions & 15 deletions src/cabanamd.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@
//
//************************************************************************

#ifndef CABANAMD_H
#define CABANAMD_H

#include <binning_cabana.h>
#include <comm_mpi.h>
#include <force.h>
#include <input.h>
#include <inputCL.h>
#include <inputFile.h>
#include <integrator_nve.h>
#include <system.h>
#include <types.h>
Expand All @@ -62,23 +66,32 @@
class CabanaMD
{
public:
System *system;
Integrator *integrator;
Force *force;
Comm *comm;
Input *input;
Binning *binning;

CabanaMD();
int nsteps;

void init( int argc, char *argv[] );
virtual void init( InputCL cl ) = 0;
virtual void run() = 0;

void run( int nsteps );
virtual void dump_binary( int ) = 0;
virtual void check_correctness( int ) = 0;
};

void dump_binary( int );
void check_correctness( int );
template <class t_System>
class CbnMD : public CabanaMD
{
public:
t_System *system;
Integrator<t_System> *integrator;
Force<t_System> *force;
Comm<t_System> *comm;
InputFile<t_System> *input;
Binning<t_System> *binning;

void print_performance();
void init( InputCL cl ) override;
void run() override;

void shutdown();
void dump_binary( int ) override;
void check_correctness( int ) override;
};

#include <cabanamd_impl.h>
#endif
Loading

0 comments on commit 74a470b

Please sign in to comment.