NAMD
CudaGlobalMasterClient.h
Go to the documentation of this file.
1 #ifndef CUDAGLOBALMASTERCLIENT_H
2 #define CUDAGLOBALMASTERCLIENT_H
3 
4 #include "CudaUtils.h"
5 #include "NamdTypes.h"
6 #include <memory>
7 #include <string>
8 #include <vector>
9 
11 class Lattice;
12 class SubmitReduction;
13 class Molecule;
14 class SimParameters;
15 class Controller;
16 class ScriptTcl;
17 
18 // Use inline namespace to force the user to recompile if we change the interface
19 // and increase the version. (see https://www.foonathan.net/2018/11/inline-namespaces/)
20 namespace CudaGlobalMaster {
21  inline namespace CUDAGM_NS {
27  : public std::enable_shared_from_this<CudaGlobalMasterClient> {
28  #if (defined(NAMD_CUDA) || defined(NAMD_HIP)) && defined(NODEGROUP_FORCE_REGISTER)
29  public:
38  virtual ~CudaGlobalMasterClient();
45  virtual void initialize(
46  const std::vector<std::string>& arguments,
47  int deviceID, cudaStream_t stream);
52  virtual void setStep(int64_t step) { m_step = step; }
57  void setMaster(std::shared_ptr<CudaGlobalMasterServer> master) {
58  m_master = master;
59  }
64  void subscribe(std::shared_ptr<CudaGlobalMasterServer> master);
68  void unsubscribe();
72  std::string name() { return m_name; }
82  virtual void onBuffersUpdated() {}
86  virtual void calculate() {}
93  virtual bool requestedAtomsChanged() = 0;
100  virtual bool requestedTotalForcesAtomsChanged() = 0;
107  virtual bool requestedForcedAtomsChanged() = 0;
115  virtual bool requestUpdateAtomPositions() = 0;
123  virtual bool requestUpdateAtomTotalForces() = 0;
131  virtual bool requestUpdateForcedAtoms() = 0;
140  virtual bool requestUpdateMasses() = 0;
150  virtual bool requestUpdateCharges() = 0;
155  virtual bool requestUpdateLattice() = 0;
165  virtual bool requestUpdateTransforms() { return false; }
174  virtual bool requestUpdateVelocities() { return false; }
190  virtual double *getAppliedForces() const = 0;
206  virtual double *getPositions() = 0;
222  virtual float *getMasses() = 0;
238  virtual float *getCharges() = 0;
254  virtual double *getTotalForces() = 0;
269  virtual double *getLattice() = 0;
287  virtual char *getTransforms() { return nullptr; }
303  virtual double *getVelocities() { return nullptr; }
309  virtual int updateFromTCLCommand(const std::vector<std::string>& arguments);
314  virtual std::string getTCLUpdateResult();
318  bool tclAvailable() const;
330  void finishReductions(bool doEnergy, bool doVirial, SubmitReduction *reduction);
335  virtual const std::vector<AtomID> &getRequestedAtoms() const = 0;
339  virtual const std::vector<AtomID> &getRequestedTotalForcesAtoms() const = 0;
344  virtual const std::vector<AtomID> &getRequestedForcedAtoms() const = 0;
345 
346  protected:
350  virtual cudaStream_t getStream() = 0;
354  virtual bool hasEnergy() const { return true; }
359  virtual double getEnergy() const { return 0; }
363  virtual bool hasVirial() const { return false; }
368  virtual cudaTensor getVirial() const { return cudaTensor{0}; };
376  virtual bool hasExtForce() const { return false; }
381  virtual Vector getExtForce() const { return Vector{0}; };
387  virtual bool useDefaultExtForceAndVirial() const { return true; };
391  SimParameters* getSimParameters() const;
395  Molecule* getMolecule() const;
399  const Controller* getController() const;
403  ScriptTcl* getScript();
404 
405  // APIs for future use for replica exchange
406  bool replica_enabled() const;
407  int replica_index() const;
408  int num_replicas() const;
409  void replica_comm_barrier();
410  int replica_comm_recv(char* msg_data, int buf_len, int src_rep);
411  int replica_comm_send(char* msg_data, int msg_len, int dest_rep);
412 
413  protected:
414  std::weak_ptr<CudaGlobalMasterServer> m_master;
415  std::string m_name;
416  int m_device_id;
417  int64_t m_step;
418  cudaTensor *m_d_ExtVirial;
419  Vector *m_d_ExtForce;
420  cudaTensor *m_h_virial;
421  Vector *m_h_ExtForce;
422  #else
423  public:
425  #endif // (defined(NAMD_CUDA) || defined(NAMD_HIP)) && defined(NODEGROUP_FORCE_REGISTER)
426  };
427  }
428 }
429 
430 #endif // CUDAGLOBALMASTERCLIENT_H
A class for performing calculations on specific atoms selected by atom serial numbers.
Definition: Vector.h:72
Molecule stores the structural information for the system.
Definition: Molecule.h:174
#define CUDAGM_NS
Definition: common.h:280
A class for copying atom information from SequencerCUDA to CudaGlobalMasterClient.