Skip to content

Commit

Permalink
Addin an openACC interface to ParallelTaskManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Iximiel committed Feb 25, 2025
1 parent d758b7a commit 1b0ab69
Show file tree
Hide file tree
Showing 45 changed files with 1,336 additions and 109 deletions.
172 changes: 172 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ enable_af_cuda
enable_af_cpu
enable_libtorch
enable_metatensor
enable_openacc
enable_openmp
'
ac_precious_vars='build_alias
Expand Down Expand Up @@ -1454,6 +1455,7 @@ Optional Features:
--enable-af_cpu enable search for arrayfire_cpu, default: no
--enable-libtorch enable search for libtorch, default: no
--enable-metatensor enable search for metatensor, default: no
--enable-openacc enable search for openacc, default: no
--disable-openmp do not use OpenMP
Some influential environment variables:
Expand Down Expand Up @@ -3240,6 +3242,24 @@ fi



openacc=
# Check whether --enable-openacc was given.
if test "${enable_openacc+set}" = set; then :
enableval=$enable_openacc; case "${enableval}" in
(yes) openacc=true ;;
(no) openacc=false ;;
(*) as_fn_error $? "wrong argument to --enable-openacc" "$LINENO" 5 ;;
esac
else
case "no" in
(yes) openacc=true ;;
(no) openacc=false ;;
esac

fi






Expand Down Expand Up @@ -10156,6 +10176,158 @@ $as_echo "$as_me: WARNING: cannot enable __PLUMED_HAS_METATENSOR" >&2;}

fi

if test $openacc = true; then
#this is here just to compile with openacc
#no PLUMED_HAS_OPENACC until pbcs are done
#test if we can compile with openacc

save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -acc"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -acc" >&5
$as_echo_n "checking whether $CXX accepts -acc... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_compile "$LINENO"; then :

cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_link "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not linking" >&5
$as_echo "not linking" >&6; }; CXXFLAGS="$save_CXXFLAGS"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext

else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }; CXXFLAGS="$save_CXXFLAGS"

fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext


save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -acc=gpu"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -acc=gpu" >&5
$as_echo_n "checking whether $CXX accepts -acc=gpu... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_compile "$LINENO"; then :

cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_link "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not linking" >&5
$as_echo "not linking" >&6; }; CXXFLAGS="$save_CXXFLAGS"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext

else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }; CXXFLAGS="$save_CXXFLAGS"

fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

#the cc must be an user input!!!!!!!!!!!!!!!!!!!!!11

save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -gpu=cc75"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -gpu=cc75" >&5
$as_echo_n "checking whether $CXX accepts -gpu=cc75... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_compile "$LINENO"; then :

cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_link "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not linking" >&5
$as_echo "not linking" >&6; }; CXXFLAGS="$save_CXXFLAGS"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext

else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }; CXXFLAGS="$save_CXXFLAGS"

fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

#PLUMED_CHECK_CXXFLAG([-gpu=ccall])
#PLUMED_CHECK_CXXFLAG([-gpu=rdc])
#PLUMED_CHECK_CXXFLAG([-stdpar])
#PLUMED_CHECK_CXXFLAG([-gpu=managed])
#PLUMED_CHECK_LDFLAGS([-static-nvidia])
#PLUMED_CHECK_LDFLAGS([-acc])
LDSHARED="$LDSHARED -acc -static-nvidia"
fi

# in non-debug mode, add -DNDEBUG
if test "$debug" = false ; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: Release mode, adding -DNDEBUG" >&5
Expand Down
18 changes: 18 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ PLUMED_CONFIG_ENABLE([af_cuda],[search for arrayfire_cuda],[no])
PLUMED_CONFIG_ENABLE([af_cpu],[search for arrayfire_cpu],[no])
PLUMED_CONFIG_ENABLE([libtorch],[search for libtorch],[no]) #added by luigibonati
PLUMED_CONFIG_ENABLE([metatensor],[search for metatensor],[no])
PLUMED_CONFIG_ENABLE([openacc],[search for openacc],[no])

AC_ARG_VAR(SOEXT,[extension of dynamic libraries (so/dylib)])
AC_ARG_VAR(STATIC_LIBS,[variables that should be linked statically directly to MD code - configure will add here -ldl if necessary ])
Expand Down Expand Up @@ -998,6 +999,23 @@ if test $metatensor = true ; then
], [__PLUMED_HAS_METATENSOR], [metatensor metatensor_torch], [true])
fi

if test $openacc = true; then
#this is here just to compile with openacc
#no PLUMED_HAS_OPENACC until pbcs are done
#test if we can compile with openacc
PLUMED_CHECK_CXXFLAG([-acc])
PLUMED_CHECK_CXXFLAG([-acc=gpu])
#the cc must be an user input!!!!!!!!!!!!!!!!!!!!!11
PLUMED_CHECK_CXXFLAG([-gpu=cc75])
#PLUMED_CHECK_CXXFLAG([-gpu=ccall])
#PLUMED_CHECK_CXXFLAG([-gpu=rdc])
#PLUMED_CHECK_CXXFLAG([-stdpar])
#PLUMED_CHECK_CXXFLAG([-gpu=managed])
#PLUMED_CHECK_LDFLAGS([-static-nvidia])
#PLUMED_CHECK_LDFLAGS([-acc])
LDSHARED="$LDSHARED -acc -static-nvidia"
fi

# in non-debug mode, add -DNDEBUG
if test "$debug" = false ; then
AC_MSG_NOTICE([Release mode, adding -DNDEBUG])
Expand Down
3 changes: 3 additions & 0 deletions regtest/targetGPU/rt-PBC/COLVAR.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! FIELDS time d2
0.000000 1.000000
0.050000 9.000000
4 changes: 4 additions & 0 deletions regtest/targetGPU/rt-PBC/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=driver
plumed_needs="dlopen"
arg="--plumed plumed.dat --trajectory-stride 10 --timestep 0.005 --ixyz trajectory.xyz"
export NVCOMPILER_ACC_NOTIFY=31
138 changes: 138 additions & 0 deletions regtest/targetGPU/rt-PBC/pbctest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Copyright (c) 2013 The plumed team
(see the PEOPLE file at the root of the distribution for a list of names)
See http://www.plumed-code.org for more information.
This file is part of plumed, version 2.0.
plumed is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
plumed is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with plumed. If not, see <http://www.gnu.org/licenses/>.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
#include "colvar/Colvar.h"
#include "core/ActionRegister.h"

#include <string>
#include <cmath>

using namespace std;

namespace PLMD{

class Distance : public colvar::Colvar {
bool components;
bool pbc;

public:
static void registerKeywords( Keywords& keys );
Distance(const ActionOptions&);
// active methods:
virtual void calculate();
};

PLUMED_REGISTER_ACTION(Distance,"TESTPBCS")

void Distance::registerKeywords( Keywords& keys ){
Colvar::registerKeywords( keys );
keys.add("atoms","ATOMS","the pair of atom that we are calculating the distance between");
keys.addFlag("COMPONENTS",false,"calculate the x, y and z components of the distance separately and store them as label.x, label.y and label.z");
}

Distance::Distance(const ActionOptions&ao):
PLUMED_COLVAR_INIT(ao),
components(false),
pbc(true)
{
vector<AtomNumber> atoms;
parseAtomList("ATOMS",atoms);
if(atoms.size()!=2)
error("Number of specified atoms should be 2");
parseFlag("COMPONENTS",components);
pbc=true;
checkRead();

log.printf(" between atoms %d %d\n",atoms[0].serial(),atoms[1].serial());
if(pbc) log.printf(" using periodic boundary conditions\n");
else log.printf(" without periodic boundary conditions\n");


if(!components){

addValueWithDerivatives(); setNotPeriodic();

} else{
addComponentWithDerivatives("x"); componentIsNotPeriodic("x");
addComponentWithDerivatives("y"); componentIsNotPeriodic("y");
addComponentWithDerivatives("z"); componentIsNotPeriodic("z");
}

requestAtoms(atoms);
}

void Distance::calculate(){


Vector a=getPosition(0);
Vector b=getPosition(1);
std::vector<Vector> d(1);
auto & pbc=getPbc();



//doing this on the GPU losing A lot of time, to check if pbc is correcly there
#pragma acc data copyin(a[0:3],b[0:3]) copyout(d[0:1])
{

#pragma acc kernels present(pbc)
{
d[0]=delta(a,b);
pbc.apply(d);
}

}
auto distance=d[0];

const double value=distance.modulo();
const double invvalue=1.0/value;

if(!components){

setAtomsDerivatives(0,-invvalue*distance);
setAtomsDerivatives(1,invvalue*distance);
setBoxDerivatives (-invvalue*Tensor(distance,distance));
setValue (value);

}else{

Value* valuex=getPntrToComponent("x");
Value* valuey=getPntrToComponent("y");
Value* valuez=getPntrToComponent("z");

setAtomsDerivatives (valuex,0,Vector(-1,0,0));
setAtomsDerivatives (valuex,1,Vector(+1,0,0));
setBoxDerivatives (valuex,Tensor(distance,Vector(-1,0,0)));
valuex->set(distance[0]);

setAtomsDerivatives (valuey,0,Vector(0,-1,0));
setAtomsDerivatives (valuey,1,Vector(0,+1,0));
setBoxDerivatives (valuey,Tensor(distance,Vector(0,-1,0)));
valuey->set(distance[1]);

setAtomsDerivatives (valuez,0,Vector(0,0,-1));
setAtomsDerivatives (valuez,1,Vector(0,0,+1));
setBoxDerivatives (valuez,Tensor(distance,Vector(0,0,-1)));
valuez->set(distance[2]);
};
}

}
8 changes: 8 additions & 0 deletions regtest/targetGPU/rt-PBC/plumed.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is loading a collective variable on the fly:
LOAD FILE=./pbctest.cpp

d2: TESTPBCS ATOMS=1,2

PRINT FILE=COLVAR ARG=d2

ENDPLUMED
Loading

0 comments on commit 1b0ab69

Please sign in to comment.