From a66a42e5729ddfb96cc283e1aa6277471168d561 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 21:14:48 +0100 Subject: [PATCH] ALPHARMSD, ANTIBETARMSD, PARABETARMSD: USEGPU also for DISTANCE and LESS_THAN With USEGPU only SECONDARY_STRUCTURE_DRMSD ran on the GPU: the distances of STRANDS_CUTOFF and the switching functions (LESS_THAN, also with the mask) ran on the CPU, although the openaccPTM plugin provides DISTANCE_VECTORACC and LESS_THAN_VECTORACC. The shortcuts now pass USEGPU to them too. CUSTOM, LOWEST and SUM have no GPU version and stay on the CPU. Without USEGPU the expanded input is unchanged. Tested with the plugin built with g++ and the host stub of the OpenACC runtime: the 47 targetGPU regtests pass (rt-GPU-secondarystructure and rt-GPU-secondarystructure-DRMSD now use DISTANCE_VECTORACC and LESS_THAN_VECTORACC); regtest/secondarystructure passes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016vwxtV46v5FLckcMEcJrbt --- src/secondarystructure/AlphaRMSD.cpp | 6 ++--- src/secondarystructure/AntibetaRMSD.cpp | 10 +++---- src/secondarystructure/ParabetaRMSD.cpp | 10 +++---- .../SecondaryStructureBase.h | 26 +++++++++---------- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/secondarystructure/AlphaRMSD.cpp b/src/secondarystructure/AlphaRMSD.cpp index ddc5255201..e7156af8ed 100644 --- a/src/secondarystructure/AlphaRMSD.cpp +++ b/src/secondarystructure/AlphaRMSD.cpp @@ -182,8 +182,8 @@ AlphaRMSD::AlphaRMSD(const ActionOptions&ao): std::string structure; SecondaryStructureInput::addStructure( structure, 1, reference ); - bool nopbc=false; - std::string distanceAction = SecondaryStructureInput::readDistanceAction( this, nopbc ); + std::string nopbc, usegpu; + std::string distanceAction = SecondaryStructureInput::readDistanceAction( this, nopbc, usegpu ); std::string lab = getShortcutLabel() + "_rmsd"; if( uselessthan ) { lab = getShortcutLabel(); @@ -194,7 +194,7 @@ AlphaRMSD::AlphaRMSD(const ActionOptions&ao): } readInputLine( lab + ": " + distanceAction + seglist + structure + " " + atoms ); // Create the less than object - readInputLine( getShortcutLabel() + "_lt: LESS_THAN ARG=" + lab + " SWITCH={" + ltmap +"}"); + readInputLine( getShortcutLabel() + "_lt: LESS_THAN ARG=" + lab + " SWITCH={" + ltmap +"}" + usegpu ); SecondaryStructureInput::addSum( this, uselessthan ); } diff --git a/src/secondarystructure/AntibetaRMSD.cpp b/src/secondarystructure/AntibetaRMSD.cpp index a024ef4ef7..57a4d8227a 100644 --- a/src/secondarystructure/AntibetaRMSD.cpp +++ b/src/secondarystructure/AntibetaRMSD.cpp @@ -292,8 +292,8 @@ AntibetaRMSD::AntibetaRMSD(const ActionOptions&ao): std::string structure; SecondaryStructureInput::addStructure( structure, 1, reference ); - bool nopbc=false; - std::string distanceAction = SecondaryStructureInput::readDistanceAction( this, nopbc ); + std::string nopbc, usegpu; + std::string distanceAction = SecondaryStructureInput::readDistanceAction( this, nopbc, usegpu ); std::string lab = getShortcutLabel() + "_rmsd"; if( uselessthan ) { lab = getShortcutLabel(); @@ -306,7 +306,7 @@ AntibetaRMSD::AntibetaRMSD(const ActionOptions&ao): if( strands_cutoff>0 ) { // The distance used for the cutoff has to treat the periodic boundary conditions as the rest of the calculation - readInputLine( scutoff_action + (nopbc ? " NOPBC" : "") ); + readInputLine( scutoff_action + nopbc + usegpu ); std::string str_cut; Tools::convert( strands_cutoff, str_cut ); readInputLine( getShortcutLabel() + "_cut: CUSTOM ARG=" + getShortcutLabel() @@ -315,7 +315,7 @@ AntibetaRMSD::AntibetaRMSD(const ActionOptions&ao): readInputLine(inputLine); // Create the less than object readInputLine( getShortcutLabel() + "_ltu: LESS_THAN ARG=" + lab - + " SWITCH={" + ltmap +"} MASK=" + getShortcutLabel() + "_cut"); + + " SWITCH={" + ltmap +"} MASK=" + getShortcutLabel() + "_cut" + usegpu ); // Multiply by the strands cutoff readInputLine( getShortcutLabel() + "_lt: CUSTOM ARG=" + getShortcutLabel() + "_ltu," @@ -323,7 +323,7 @@ AntibetaRMSD::AntibetaRMSD(const ActionOptions&ao): " FUNC=x*y PERIODIC=NO"); } else { readInputLine(inputLine); - readInputLine( getShortcutLabel() + "_lt: LESS_THAN ARG=" + lab + " SWITCH={" + ltmap +"}"); + readInputLine( getShortcutLabel() + "_lt: LESS_THAN ARG=" + lab + " SWITCH={" + ltmap +"}" + usegpu ); } SecondaryStructureInput::addSum( this, uselessthan ); } diff --git a/src/secondarystructure/ParabetaRMSD.cpp b/src/secondarystructure/ParabetaRMSD.cpp index 8587b6e3e4..0342501f8a 100644 --- a/src/secondarystructure/ParabetaRMSD.cpp +++ b/src/secondarystructure/ParabetaRMSD.cpp @@ -330,8 +330,8 @@ ParabetaRMSD::ParabetaRMSD(const ActionOptions&ao): reference[29]=Vector( 0.486, 4.430, -0.415); // O SecondaryStructureInput::addStructure( structure, 2, reference ); - bool nopbc=false; - std::string distanceAction = SecondaryStructureInput::readDistanceAction( this, nopbc ); + std::string nopbc, usegpu; + std::string distanceAction = SecondaryStructureInput::readDistanceAction( this, nopbc, usegpu ); std::string lab = getShortcutLabel() + "_low"; if( uselessthan ) { lab = getShortcutLabel(); @@ -344,7 +344,7 @@ ParabetaRMSD::ParabetaRMSD(const ActionOptions&ao): if( strands_cutoff>0 ) { // The distance used for the cutoff has to treat the periodic boundary conditions as the rest of the calculation - readInputLine( scutoff_action + (nopbc ? " NOPBC" : "") ); + readInputLine( scutoff_action + nopbc + usegpu ); std::string str_cut; Tools::convert( strands_cutoff, str_cut ); readInputLine( getShortcutLabel() + "_cut: CUSTOM ARG=" + getShortcutLabel() @@ -356,7 +356,7 @@ ParabetaRMSD::ParabetaRMSD(const ActionOptions&ao): + getShortcutLabel() + "_both.struct-2 MASK=" + getShortcutLabel() + "_cut"); // Create the less than object readInputLine( getShortcutLabel() + "_ltu: LESS_THAN ARG=" + lab - + " SWITCH={" + ltmap +"} MASK=" + getShortcutLabel() + "_cut"); + + " SWITCH={" + ltmap +"} MASK=" + getShortcutLabel() + "_cut" + usegpu ); // Multiply by the strands cutoff readInputLine( getShortcutLabel() + "_lt: CUSTOM ARG=" + getShortcutLabel() + "_ltu," @@ -368,7 +368,7 @@ ParabetaRMSD::ParabetaRMSD(const ActionOptions&ao): readInputLine( lab + ": LOWEST ARG=" + getShortcutLabel() + "_both.struct-1," + getShortcutLabel() + "_both.struct-2" ); // Create the less than object - readInputLine( getShortcutLabel() + "_lt: LESS_THAN ARG=" + lab + " SWITCH={" + ltmap +"}"); + readInputLine( getShortcutLabel() + "_lt: LESS_THAN ARG=" + lab + " SWITCH={" + ltmap +"}" + usegpu ); } SecondaryStructureInput::addSum( this, uselessthan ); } diff --git a/src/secondarystructure/SecondaryStructureBase.h b/src/secondarystructure/SecondaryStructureBase.h index 2744f65727..c9d378f316 100644 --- a/src/secondarystructure/SecondaryStructureBase.h +++ b/src/secondarystructure/SecondaryStructureBase.h @@ -84,8 +84,9 @@ class SecondaryStructureBase: public ActionWithVector { static void registerKeywords( Keywords& keys ); static void readBackboneAtoms( ActionShortcut* action, PlumedMain& plumed, const std::string& backnames, std::vector& chain_lengths, std::vector& all_atoms ); static bool readShortcutWords( std::string& ltmap, ActionShortcut* action ); - /// Read TYPE, NOPBC and USEGPU in a shortcut: returns the name and the keywords of the action that computes the distances - static std::string readDistanceAction( ActionShortcut* action, bool& nopbc ); + /// Read TYPE, NOPBC and USEGPU in a shortcut: returns the name and the keywords of the action that computes the distances. + /// nopbc and usegpu are set to " NOPBC" and " USEGPU" (or empty) for the other actions of the shortcut + static std::string readDistanceAction( ActionShortcut* action, std::string& nopbc, std::string& usegpu ); /// Append " SEGMENTnum=nlist[0],nlist[1],..." to line static void addSegment( std::string& line, unsigned num, const std::vector& nlist ); /// Append " STRUCTUREnum=x0,y0,z0,x1,..." (in Angstrom) to line @@ -131,25 +132,22 @@ bool SecondaryStructureBase::readShortcutWords( std::string& ltmap, Act } template -std::string SecondaryStructureBase::readDistanceAction( ActionShortcut* action, bool& nopbc ) { +std::string SecondaryStructureBase::readDistanceAction( ActionShortcut* action, std::string& nopbc, std::string& usegpu ) { std::string type; action->parse("TYPE",type); // RMSD only accepts upper case names std::transform( type.begin(), type.end(), type.begin(), [](unsigned char c) { return std::toupper(c); } ); + bool flag=false; + action->parseFlag("NOPBC",flag); + nopbc = flag ? " NOPBC" : ""; + // with USEGPU the shortcuts also run on the GPU the actions that the openaccPTM plugin provides (DISTANCE and LESS_THAN) + flag=false; + action->parseFlag("USEGPU",flag); + usegpu = flag ? " USEGPU" : ""; // BONDLENGTH is in nm, see the constructor - std::string line = type=="DRMSD" ? "SECONDARY_STRUCTURE_DRMSD BONDLENGTH=0.17" : "SECONDARY_STRUCTURE_RMSD TYPE=" + type; - action->parseFlag("NOPBC",nopbc); - if( nopbc ) { - line += " NOPBC"; - } - bool usegpu=false; - action->parseFlag("USEGPU",usegpu); - if( usegpu ) { - line += " USEGPU"; - } - return line; + return (type=="DRMSD" ? "SECONDARY_STRUCTURE_DRMSD BONDLENGTH=0.17" : "SECONDARY_STRUCTURE_RMSD TYPE=" + type) + nopbc + usegpu; } template