From 94d38b7739507646a502289e6c7aaa83dccb31d4 Mon Sep 17 00:00:00 2001 From: Han Wang Date: Mon, 15 Mar 2021 20:19:22 +0800 Subject: [PATCH 01/23] add model version support. implemented python interface. --- deepmd/entrypoints/freeze.py | 2 + deepmd/infer/deep_dipole.py | 6 +- deepmd/infer/deep_eval.py | 211 ++++++---------------------- deepmd/infer/deep_polar.py | 8 +- deepmd/infer/deep_pot.py | 55 ++++++-- deepmd/infer/deep_tensor.py | 172 +++++++++++++++++++++++ deepmd/infer/deep_wfc.py | 5 +- source/api_cc/include/version.h.in | 1 + source/tests/infer/deepdipole.pbtxt | 21 +++ source/tests/infer/deeppolar.pbtxt | 21 +++ source/tests/infer/deeppot-1.pbtxt | 21 +++ source/tests/infer/deeppot-r.pbtxt | 21 +++ source/tests/infer/deeppot.pbtxt | 21 +++ source/tests/test_deeppot_a.py | 59 ++++++++ source/train/MODEL_VER | 1 + source/train/model.py | 9 +- source/train/run_config.ini | 3 +- source/train/run_options.py | 2 + 18 files changed, 445 insertions(+), 194 deletions(-) create mode 100644 deepmd/infer/deep_tensor.py create mode 100644 source/train/MODEL_VER diff --git a/deepmd/entrypoints/freeze.py b/deepmd/entrypoints/freeze.py index d47dffaf87..e11ac0c906 100755 --- a/deepmd/entrypoints/freeze.py +++ b/deepmd/entrypoints/freeze.py @@ -43,6 +43,7 @@ def _make_node_names(model_type: str, modifier_type: Optional[str] = None) -> Li "descrpt_attr/ntypes", "model_attr/tmap", "model_attr/model_type", + "model_attr/model_version", ] if model_type == "ener": @@ -59,6 +60,7 @@ def _make_node_names(model_type: str, modifier_type: Optional[str] = None) -> Li nodes += [ "o_wfc", "model_attr/sel_type", + "model_attr/output_dim", ] elif model_type == "dipole": nodes += [ diff --git a/deepmd/infer/deep_dipole.py b/deepmd/infer/deep_dipole.py index 7ad3ee49a5..d158cbafac 100644 --- a/deepmd/infer/deep_dipole.py +++ b/deepmd/infer/deep_dipole.py @@ -1,6 +1,6 @@ -from typing import TYPE_CHECKING +from deepmd.infer.deep_tensor import DeepTensor -from deepmd.infer.deep_eval import DeepTensor +from typing import TYPE_CHECKING if TYPE_CHECKING: from pathlib import Path @@ -33,7 +33,6 @@ def __init__( # instance namespace self.tensors = dict( { - "t_sel_type": "model_attr/sel_type:0", # output tensor "t_tensor": "o_dipole:0", }, @@ -43,7 +42,6 @@ def __init__( DeepTensor.__init__( self, model_file, - 3, load_prefix=load_prefix, default_tf_graph=default_tf_graph, ) diff --git a/deepmd/infer/deep_eval.py b/deepmd/infer/deep_eval.py index 2c52644eb1..dc31995e58 100644 --- a/deepmd/infer/deep_eval.py +++ b/deepmd/infer/deep_eval.py @@ -4,6 +4,7 @@ import numpy as np from deepmd.common import make_default_mesh from deepmd.env import default_tf_session_config, tf +from deepmd.run_options import MODEL_VERSION if TYPE_CHECKING: from pathlib import Path @@ -13,6 +14,7 @@ class DeepEval: """Common methods for DeepPot, DeepWFC, DeepPolar, ...""" _model_type: Optional[str] = None + _model_version: Optional[str] = None load_prefix: str # set by subclass def __init__( @@ -26,6 +28,12 @@ def __init__( ) self.load_prefix = load_prefix + if not self._graph_compatable(): + raise RuntimeError( + f"model in graph (version {self.model_version}) is incompatible" + f"with the model (version {MODEL_VERSION}) supported by the current code." + ) + @property def model_type(self) -> str: """Get type of model. @@ -37,9 +45,44 @@ def model_type(self) -> str: sess = tf.Session(graph=self.graph, config=default_tf_session_config) [mt] = sess.run([t_mt], feed_dict={}) self._model_type = mt.decode("utf-8") - return self._model_type + @property + def model_version(self) -> str: + """Get type of model. + + :type:str + """ + if not self._model_version: + try: + t_mt = self._get_tensor("model_attr/model_version:0") + sess = tf.Session(graph=self.graph, config=default_tf_session_config) + [mt] = sess.run([t_mt], feed_dict={}) + self._model_version = mt.decode("utf-8") + except KeyError: + # For deepmd-kit version 0.x - 1.x, set model version to 0.0 + self._model_version = "0.0" + return self._model_version + + def _graph_compatable( + self + ) -> bool : + """ Check the model compatability + + Return + bool + If the model stored in the graph file is compatable with the current code + """ + model_version_major = int(self.model_version.split('.')[0]) + model_version_minor = int(self.model_version.split('.')[1]) + MODEL_VERSION_MAJOR = int(MODEL_VERSION.split('.')[0]) + MODEL_VERSION_MINOR = int(MODEL_VERSION.split('.')[1]) + if (model_version_major != MODEL_VERSION_MAJOR) or \ + (model_version_minor > MODEL_VERSION_MINOR) : + return False + else: + return True + def _get_tensor( self, tensor_name: str, attr_name: Optional[str] = None ) -> tf.Tensor: @@ -70,8 +113,6 @@ def _get_tensor( def _load_graph( frozen_graph_filename: "Path", prefix: str = "load", default_tf_graph: bool = False ): - - # We load the protobuf file from the disk and parse it to retrieve the # unserialized graph_def with tf.gfile.GFile(str(frozen_graph_filename), "rb") as f: @@ -101,168 +142,6 @@ def _load_graph( return graph -class DeepTensor(DeepEval): - """Evaluates a tensor model. - - Constructor - - Parameters - ---------- - model_file: str - The name of the frozen model file. - variable_dof: int - The DOF of the variable to evaluate. - load_prefix: str - The prefix in the load computational graph - default_tf_graph : bool - If uses the default tf graph, otherwise build a new tf graph for evaluation - """ - - tensors = { - "t_ntypes": "descrpt_attr/ntypes:0", - "t_rcut": "descrpt_attr/rcut:0", - "t_tmap": "model_attr/tmap:0", - # inputs - "t_coord": "t_coord:0", - "t_type": "t_type:0", - "t_natoms": "t_natoms:0", - "t_box": "t_box:0", - "t_mesh": "t_mesh:0", - } - - def __init__( - self, - model_file: "Path", - variable_dof: Optional[int], - load_prefix: str = 'load', - default_tf_graph: bool = False - ) -> None: - DeepEval.__init__( - self, - model_file, - load_prefix=load_prefix, - default_tf_graph=default_tf_graph - ) - self.variable_dof = variable_dof - - # now load tensors to object attributes - for attr_name, tensor_name in self.tensors.items(): - self._get_tensor(tensor_name, attr_name) - - # start a tf session associated to the graph - self.sess = tf.Session(graph=self.graph, config=default_tf_session_config) - self._run_default_sess() - self.tmap = self.tmap.decode('UTF-8').split() - - def _run_default_sess(self): - [self.ntypes, self.rcut, self.tmap, self.tselt] = self.sess.run( - [self.t_ntypes, self.t_rcut, self.t_tmap, self.t_sel_type] - ) - - def get_ntypes(self) -> int: - """Get the number of atom types of this model.""" - return self.ntypes - - def get_rcut(self) -> float: - """Get the cut-off radius of this model.""" - return self.rcut - - def get_type_map(self) -> List[int]: - """Get the type map (element name of the atom types) of this model.""" - return self.tmap - - def get_sel_type(self) -> List[int]: - """Get the selected atom types of this model.""" - return self.tselt - - def get_dim_fparam(self) -> int: - """Get the number (dimension) of frame parameters of this DP.""" - return self.dfparam - - def get_dim_aparam(self) -> int: - """Get the number (dimension) of atomic parameters of this DP.""" - return self.daparam - - def eval( - self, - coords: np.array, - cells: np.array, - atom_types: List[int], - atomic: bool = True, - fparam: Optional[np.array] = None, - aparam: Optional[np.array] = None, - efield: Optional[np.array] = None - ) -> np.array: - """Evaluate the model. - - Parameters - ---------- - coords - The coordinates of atoms. - The array should be of size nframes x natoms x 3 - cells - The cell of the region. - If None then non-PBC is assumed, otherwise using PBC. - The array should be of size nframes x 9 - atom_types - The atom types - The list should contain natoms ints - atomic - Calculate the atomic energy and virial - fparam - Not used in this model - aparam - Not used in this model - efield - Not used in this model - - Returns - ------- - tensor - The returned tensor - If atomic == False then of size nframes x variable_dof - else of size nframes x natoms x variable_dof - """ - # standarize the shape of inputs - coords = np.array(coords) - cells = np.array(cells) - atom_types = np.array(atom_types, dtype = int) - - # reshape the inputs - cells = np.reshape(cells, [-1, 9]) - nframes = cells.shape[0] - coords = np.reshape(coords, [nframes, -1]) - natoms = coords.shape[1] // 3 - - # sort inputs - coords, atom_types, imap, sel_at, sel_imap = self.sort_input(coords, atom_types, sel_atoms = self.get_sel_type()) - - # make natoms_vec and default_mesh - natoms_vec = self.make_natoms_vec(atom_types) - assert(natoms_vec[0] == natoms) - - # evaluate - tensor = [] - feed_dict_test = {} - feed_dict_test[self.t_natoms] = natoms_vec - feed_dict_test[self.t_type ] = np.tile(atom_types, [nframes,1]).reshape([-1]) - t_out = [self.t_tensor] - feed_dict_test[self.t_coord] = np.reshape(coords, [-1]) - feed_dict_test[self.t_box ] = np.reshape(cells , [-1]) - feed_dict_test[self.t_mesh ] = make_default_mesh(cells) - v_out = self.sess.run (t_out, feed_dict = feed_dict_test) - tensor = v_out[0] - - # reverse map of the outputs - if atomic: - tensor = np.array(tensor) - tensor = self.reverse_map(np.reshape(tensor, [nframes,-1,self.variable_dof]), sel_imap) - tensor = np.reshape(tensor, [nframes, len(sel_at), self.variable_dof]) - else: - tensor = np.reshape(tensor, [nframes, self.variable_dof]) - - return tensor - @staticmethod def sort_input( coord : np.array, atom_type : np.array, sel_atoms : List[int] = None @@ -339,6 +218,7 @@ def reverse_map(vec : np.ndarray, imap : List[int]) -> np.ndarray: ret[:,ii,:] = vec[:,idx,:] return ret + def make_natoms_vec(self, atom_types : np.ndarray) -> np.ndarray : """Make the natom vector used by deepmd-kit. @@ -363,4 +243,3 @@ def make_natoms_vec(self, atom_types : np.ndarray) -> np.ndarray : for ii in range (self.ntypes) : natoms_vec[ii+2] = np.count_nonzero(atom_types == ii) return natoms_vec - diff --git a/deepmd/infer/deep_polar.py b/deepmd/infer/deep_polar.py index 48f565faa2..7ee02cf1c8 100644 --- a/deepmd/infer/deep_polar.py +++ b/deepmd/infer/deep_polar.py @@ -1,7 +1,7 @@ -from typing import TYPE_CHECKING, List, Optional - +from deepmd.infer.deep_tensor import DeepTensor import numpy as np -from deepmd.infer.deep_eval import DeepTensor + +from typing import TYPE_CHECKING, List, Optional if TYPE_CHECKING: from pathlib import Path @@ -34,7 +34,6 @@ def __init__( # instance namespace self.tensors = dict( { - "t_sel_type": "model_attr/sel_type:0", # output tensor "t_tensor": "o_polar:0", }, @@ -44,7 +43,6 @@ def __init__( DeepTensor.__init__( self, model_file, - 9, load_prefix=load_prefix, default_tf_graph=default_tf_graph, ) diff --git a/deepmd/infer/deep_pot.py b/deepmd/infer/deep_pot.py index 8fefe843d5..a8e70d5a72 100644 --- a/deepmd/infer/deep_pot.py +++ b/deepmd/infer/deep_pot.py @@ -3,8 +3,9 @@ import numpy as np from deepmd.common import make_default_mesh +from deepmd.env import default_tf_session_config, tf from deepmd.infer.data_modifier import DipoleChargeModifier -from deepmd.infer.deep_eval import DeepEval, DeepTensor +from deepmd.infer.deep_eval import DeepEval if TYPE_CHECKING: from pathlib import Path @@ -12,7 +13,7 @@ log = logging.getLogger(__name__) -class DeepPot(DeepTensor): +class DeepPot(DeepEval): """Constructor. Parameters @@ -43,9 +44,20 @@ def __init__( # instance namespace self.tensors = dict( { - # general + # descrpt attrs + "t_ntypes": "descrpt_attr/ntypes:0", + "t_rcut": "descrpt_attr/rcut:0", + # fitting attrs "t_dfparam": "fitting_attr/dfparam:0", "t_daparam": "fitting_attr/daparam:0", + # model attrs + "t_tmap": "model_attr/tmap:0", + # inputs + "t_coord": "t_coord:0", + "t_type": "t_type:0", + "t_natoms": "t_natoms:0", + "t_box": "t_box:0", + "t_mesh": "t_mesh:0", # add output tensors "t_energy": "o_energy:0", "t_force": "o_force:0", @@ -53,7 +65,6 @@ def __init__( "t_ae": "o_atom_energy:0", "t_av": "o_atom_virial:0" }, - **self.tensors ) DeepEval.__init__( self, @@ -90,15 +101,14 @@ def __init__( self.t_aparam = None self.has_aparam = False - # now when tensors are set initialize DeepTensor which will load them all - # to class attributes, the run session assciated with the graph - DeepTensor.__init__( - self, - model_file, - None, - load_prefix=load_prefix, - default_tf_graph=default_tf_graph - ) + # now load tensors to object attributes + for attr_name, tensor_name in self.tensors.items(): + self._get_tensor(tensor_name, attr_name) + + # start a tf session associated to the graph + self.sess = tf.Session(graph=self.graph, config=default_tf_session_config) + self._run_default_sess() + self.tmap = self.tmap.decode('UTF-8').split() # setup modifier try: @@ -123,9 +133,28 @@ def _run_default_sess(self): [self.t_ntypes, self.t_rcut, self.t_dfparam, self.t_daparam, self.t_tmap] ) + def get_ntypes(self) -> int: + """Get the number of atom types of this model.""" + return self.ntypes + + def get_rcut(self) -> float: + """Get the cut-off radius of this model.""" + return self.rcut + + def get_type_map(self) -> List[int]: + """Get the type map (element name of the atom types) of this model.""" + return self.tmap + def get_sel_type(self) -> List[int]: """Unsupported in this model.""" raise NotImplementedError("This model type does not support this attribute") + def get_dim_fparam(self) -> int: + """Get the number (dimension) of frame parameters of this DP.""" + return self.dfparam + + def get_dim_aparam(self) -> int: + """Get the number (dimension) of atomic parameters of this DP.""" + return self.daparam def eval( self, diff --git a/deepmd/infer/deep_tensor.py b/deepmd/infer/deep_tensor.py new file mode 100644 index 0000000000..24a7832a32 --- /dev/null +++ b/deepmd/infer/deep_tensor.py @@ -0,0 +1,172 @@ +import os +from typing import List, Optional, TYPE_CHECKING + +import numpy as np +from deepmd.common import make_default_mesh +from deepmd.env import default_tf_session_config, tf +from deepmd.infer.deep_eval import DeepEval + +if TYPE_CHECKING: + from pathlib import Path + +class DeepTensor(DeepEval): + """Evaluates a tensor model. + + Constructor + + Parameters + ---------- + model_file: str + The name of the frozen model file. + load_prefix: str + The prefix in the load computational graph + default_tf_graph : bool + If uses the default tf graph, otherwise build a new tf graph for evaluation + """ + + tensors = { + # descriptor attrs + "t_ntypes": "descrpt_attr/ntypes:0", + "t_rcut": "descrpt_attr/rcut:0", + # model attrs + "t_tmap": "model_attr/tmap:0", + "t_sel_type": "model_attr/sel_type:0", + "t_ouput_dim": "model_attr/output_dim:0", + # inputs + "t_coord": "t_coord:0", + "t_type": "t_type:0", + "t_natoms": "t_natoms:0", + "t_box": "t_box:0", + "t_mesh": "t_mesh:0", + } + + def __init__( + self, + model_file: "Path", + load_prefix: str = 'load', + default_tf_graph: bool = False + ) -> None: + DeepEval.__init__( + self, + model_file, + load_prefix=load_prefix, + default_tf_graph=default_tf_graph + ) + # now load tensors to object attributes + for attr_name, tensor_name in self.tensors.items(): + self._get_tensor(tensor_name, attr_name) + + # start a tf session associated to the graph + self.sess = tf.Session(graph=self.graph, config=default_tf_session_config) + self._run_default_sess() + self.tmap = self.tmap.decode('UTF-8').split() + + def _run_default_sess(self): + [self.ntypes, self.rcut, self.tmap, self.tselt, self.output_dim] \ + = self.sess.run( + [self.t_ntypes, self.t_rcut, self.t_tmap, self.t_sel_type, self.t_ouput_dim] + ) + + def get_ntypes(self) -> int: + """Get the number of atom types of this model.""" + return self.ntypes + + def get_rcut(self) -> float: + """Get the cut-off radius of this model.""" + return self.rcut + + def get_type_map(self) -> List[int]: + """Get the type map (element name of the atom types) of this model.""" + return self.tmap + + def get_sel_type(self) -> List[int]: + """Get the selected atom types of this model.""" + return self.tselt + + def get_dim_fparam(self) -> int: + """Get the number (dimension) of frame parameters of this DP.""" + return self.dfparam + + def get_dim_aparam(self) -> int: + """Get the number (dimension) of atomic parameters of this DP.""" + return self.daparam + + def eval( + self, + coords: np.array, + cells: np.array, + atom_types: List[int], + atomic: bool = True, + fparam: Optional[np.array] = None, + aparam: Optional[np.array] = None, + efield: Optional[np.array] = None + ) -> np.array: + """Evaluate the model. + + Parameters + ---------- + coords + The coordinates of atoms. + The array should be of size nframes x natoms x 3 + cells + The cell of the region. + If None then non-PBC is assumed, otherwise using PBC. + The array should be of size nframes x 9 + atom_types + The atom types + The list should contain natoms ints + atomic + Calculate the atomic energy and virial + fparam + Not used in this model + aparam + Not used in this model + efield + Not used in this model + + Returns + ------- + tensor + The returned tensor + If atomic == False then of size nframes x output_dim + else of size nframes x natoms x output_dim + """ + # standarize the shape of inputs + coords = np.array(coords) + cells = np.array(cells) + atom_types = np.array(atom_types, dtype = int) + + # reshape the inputs + cells = np.reshape(cells, [-1, 9]) + nframes = cells.shape[0] + coords = np.reshape(coords, [nframes, -1]) + natoms = coords.shape[1] // 3 + + # sort inputs + coords, atom_types, imap, sel_at, sel_imap = self.sort_input(coords, atom_types, sel_atoms = self.get_sel_type()) + + # make natoms_vec and default_mesh + natoms_vec = self.make_natoms_vec(atom_types) + assert(natoms_vec[0] == natoms) + + # evaluate + tensor = [] + feed_dict_test = {} + feed_dict_test[self.t_natoms] = natoms_vec + feed_dict_test[self.t_type ] = np.tile(atom_types, [nframes,1]).reshape([-1]) + t_out = [self.t_tensor] + feed_dict_test[self.t_coord] = np.reshape(coords, [-1]) + feed_dict_test[self.t_box ] = np.reshape(cells , [-1]) + feed_dict_test[self.t_mesh ] = make_default_mesh(cells) + v_out = self.sess.run (t_out, feed_dict = feed_dict_test) + tensor = v_out[0] + + # reverse map of the outputs + if atomic: + tensor = np.array(tensor) + tensor = self.reverse_map(np.reshape(tensor, [nframes,-1,self.output_dim]), sel_imap) + tensor = np.reshape(tensor, [nframes, len(sel_at), self.output_dim]) + else: + tensor = np.reshape(tensor, [nframes, self.output_dim]) + + return tensor diff --git a/deepmd/infer/deep_wfc.py b/deepmd/infer/deep_wfc.py index 1f976af04a..40d3cd6a5c 100644 --- a/deepmd/infer/deep_wfc.py +++ b/deepmd/infer/deep_wfc.py @@ -1,4 +1,5 @@ -from deepmd.infer.deep_eval import DeepTensor +from deepmd.infer.deep_tensor import DeepTensor + from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -32,7 +33,6 @@ def __init__( # instance namespace self.tensors = dict( { - "t_sel_type": "model_attr/sel_type:0", # output tensor "t_tensor": "o_wfc:0", }, @@ -41,7 +41,6 @@ def __init__( DeepTensor.__init__( self, model_file, - 12, load_prefix=load_prefix, default_tf_graph=default_tf_graph, ) diff --git a/source/api_cc/include/version.h.in b/source/api_cc/include/version.h.in index d3acbf5aff..23c22ae588 100644 --- a/source/api_cc/include/version.h.in +++ b/source/api_cc/include/version.h.in @@ -16,3 +16,4 @@ const std::string global_git_date="@GIT_DATE@"; const std::string global_git_branch="@GIT_BRANCH@"; const std::string global_tf_include_dir="@TensorFlow_INCLUDE_DIRS@"; const std::string global_tf_lib="@TensorFlow_LIBRARY@"; +const std::string global_model_version="@MODEL_VERSION@"; diff --git a/source/tests/infer/deepdipole.pbtxt b/source/tests/infer/deepdipole.pbtxt index a8f09a3331..b503c29336 100644 --- a/source/tests/infer/deepdipole.pbtxt +++ b/source/tests/infer/deepdipole.pbtxt @@ -5950,6 +5950,27 @@ node { } } } +node { + name: "model_attr/model_version" + op: "Const" + attr { + key: "dtype" + value { + type: DT_STRING + } + } + attr { + key: "value" + value { + tensor { + dtype: DT_STRING + tensor_shape { + } + string_val: "1.0" + } + } + } +} node { name: "model_attr/sel_type" op: "Const" diff --git a/source/tests/infer/deeppolar.pbtxt b/source/tests/infer/deeppolar.pbtxt index d7f29bdd87..49b9645b68 100644 --- a/source/tests/infer/deeppolar.pbtxt +++ b/source/tests/infer/deeppolar.pbtxt @@ -6178,6 +6178,27 @@ node { } } } +node { + name: "model_attr/model_version" + op: "Const" + attr { + key: "dtype" + value { + type: DT_STRING + } + } + attr { + key: "value" + value { + tensor { + dtype: DT_STRING + tensor_shape { + } + string_val: "1.0" + } + } + } +} node { name: "model_attr/sel_type" op: "Const" diff --git a/source/tests/infer/deeppot-1.pbtxt b/source/tests/infer/deeppot-1.pbtxt index 3f8034de55..0819df4b9e 100644 --- a/source/tests/infer/deeppot-1.pbtxt +++ b/source/tests/infer/deeppot-1.pbtxt @@ -8875,6 +8875,27 @@ node { } } } +node { + name: "model_attr/model_version" + op: "Const" + attr { + key: "dtype" + value { + type: DT_STRING + } + } + attr { + key: "value" + value { + tensor { + dtype: DT_STRING + tensor_shape { + } + string_val: "1.0" + } + } + } +} node { name: "model_attr/tmap" op: "Const" diff --git a/source/tests/infer/deeppot-r.pbtxt b/source/tests/infer/deeppot-r.pbtxt index 3ddd2effe4..c307be00f0 100644 --- a/source/tests/infer/deeppot-r.pbtxt +++ b/source/tests/infer/deeppot-r.pbtxt @@ -8529,6 +8529,27 @@ node { } } } +node { + name: "model_attr/model_version" + op: "Const" + attr { + key: "dtype" + value { + type: DT_STRING + } + } + attr { + key: "value" + value { + tensor { + dtype: DT_STRING + tensor_shape { + } + string_val: "1.0" + } + } + } +} node { name: "model_attr/tmap" op: "Const" diff --git a/source/tests/infer/deeppot.pbtxt b/source/tests/infer/deeppot.pbtxt index 7a5ba00f78..c7c49e2483 100644 --- a/source/tests/infer/deeppot.pbtxt +++ b/source/tests/infer/deeppot.pbtxt @@ -8875,6 +8875,27 @@ node { } } } +node { + name: "model_attr/model_version" + op: "Const" + attr { + key: "dtype" + value { + type: DT_STRING + } + } + attr { + key: "value" + value { + tensor { + dtype: DT_STRING + tensor_shape { + } + string_val: "1.0" + } + } + } +} node { name: "model_attr/tmap" op: "Const" diff --git a/source/tests/test_deeppot_a.py b/source/tests/test_deeppot_a.py index 8dee81df75..b9a519672d 100644 --- a/source/tests/test_deeppot_a.py +++ b/source/tests/test_deeppot_a.py @@ -4,6 +4,7 @@ from infer.convert2pb import convert_pbtxt_to_pb from deepmd.infer import DeepPot +from deepmd.run_options import MODEL_VERSION from common import tests_path from deepmd.run_options import GLOBAL_NP_FLOAT_PRECISION @@ -12,6 +13,64 @@ else : default_places = 10 +class TestModelMajorCompatability(unittest.TestCase) : + def setUp(self): + model_file = str(tests_path / os.path.join("infer","deeppot.pbtxt")) + with open(model_file, 'r') as fp: + # data = fp.read().replace('\n', '') + data = fp.read().split("\n") + for ii in range(len(data)): + if "model_attr/model_version" in data[ii]: + for jj in range(ii, len(data)): + if "string_val:" in data[jj]: + data[jj] = data[jj].replace(MODEL_VERSION, "0.0") + break + with open("deeppot-ver.pbtxt", "w") as fp: + fp.write("\n".join(data)) + + convert_pbtxt_to_pb(str(tests_path / os.path.join("deeppot-ver.pbtxt")), "deeppot.pb") + + def tearDown(self): + os.remove("deeppot-ver.pbtxt") + os.remove("deeppot.pb") + + def test(self): + with self.assertRaises(RuntimeError) as context: + DeepPot("deeppot.pb") + self.assertTrue('incompatible' in str(context.exception)) + self.assertTrue(MODEL_VERSION in str(context.exception)) + self.assertTrue('0.0' in str(context.exception)) + + +class TestModelMinorCompatability(unittest.TestCase) : + def setUp(self): + model_file = str(tests_path / os.path.join("infer","deeppot.pbtxt")) + with open(model_file, 'r') as fp: + # data = fp.read().replace('\n', '') + data = fp.read().split("\n") + for ii in range(len(data)): + if "model_attr/model_version" in data[ii]: + for jj in range(ii, len(data)): + if "string_val:" in data[jj]: + data[jj] = data[jj].replace(MODEL_VERSION, "0.1000000") + break + with open("deeppot-ver.pbtxt", "w") as fp: + fp.write("\n".join(data)) + + convert_pbtxt_to_pb(str(tests_path / os.path.join("deeppot-ver.pbtxt")), "deeppot.pb") + + def tearDown(self): + os.remove("deeppot-ver.pbtxt") + os.remove("deeppot.pb") + + def test(self): + with self.assertRaises(RuntimeError) as context: + DeepPot("deeppot.pb") + self.assertTrue('incompatible' in str(context.exception)) + self.assertTrue(MODEL_VERSION in str(context.exception)) + self.assertTrue('0.1000000' in str(context.exception)) + + class TestDeepPotAPBC(unittest.TestCase) : def setUp(self): convert_pbtxt_to_pb(str(tests_path / os.path.join("infer","deeppot.pbtxt")), "deeppot.pb") diff --git a/source/train/MODEL_VER b/source/train/MODEL_VER new file mode 100644 index 0000000000..d3827e75a5 --- /dev/null +++ b/source/train/MODEL_VER @@ -0,0 +1 @@ +1.0 diff --git a/source/train/model.py b/source/train/model.py index d56d390204..8ccee419bf 100644 --- a/source/train/model.py +++ b/source/train/model.py @@ -4,7 +4,7 @@ from deepmd.utils.pair_tab import PairTab from deepmd.common import ClassArg -from deepmd.run_options import global_cvt_2_ener_float +from deepmd.run_options import global_cvt_2_ener_float, MODEL_VERSION from deepmd.env import op_module @@ -146,6 +146,9 @@ def build (self, t_mt = tf.constant(self.model_type, name = 'model_type', dtype = tf.string) + t_ver = tf.constant(MODEL_VERSION, + name = 'model_version', + dtype = tf.string) if self.srtab is not None : tab_info, tab_data = self.srtab.get() @@ -335,11 +338,13 @@ def build (self, t_mt = tf.constant(self.model_type, name = 'model_type', dtype = tf.string) + t_ver = tf.constant(MODEL_VERSION, + name = 'model_version', + dtype = tf.string) t_od = tf.constant(self.get_out_size(), name = 'output_dim', dtype = tf.int32) - dout \ = self.descrpt.build(coord_, atype_, diff --git a/source/train/run_config.ini b/source/train/run_config.ini index 5579f13134..3f2e8cc86a 100644 --- a/source/train/run_config.ini +++ b/source/train/run_config.ini @@ -6,4 +6,5 @@ GIT_DATE = @GIT_DATE@ GIT_BRANCH = @GIT_BRANCH@ TF_INCLUDE_DIR = @TensorFlow_INCLUDE_DIRS@ TF_LIBS = @TensorFlow_LIBRARY@ -PRECISION = @PREC_DEF@ \ No newline at end of file +PRECISION = @PREC_DEF@ +MODEL_VERSION=@MODEL_VERSION@ diff --git a/source/train/run_options.py b/source/train/run_options.py index 632c18af63..0ef39a7e95 100644 --- a/source/train/run_options.py +++ b/source/train/run_options.py @@ -36,6 +36,7 @@ class TFServerV1(Protocol): "global_cvt_2_tf_float", "global_cvt_2_ener_float", "RunOptions", + "MODEL_VERSION", ] log = logging.getLogger(__name__) @@ -62,6 +63,7 @@ def _get_package_constants( GLOBAL_CONFIG = _get_package_constants() +MODEL_VERSION = GLOBAL_CONFIG["model_version"] if GLOBAL_CONFIG["precision"] == "-DHIGH_PREC": GLOBAL_TF_FLOAT_PRECISION = tf.float64 From 3c307f73014b41106f704d3e94ddab051345f1c7 Mon Sep 17 00:00:00 2001 From: Han Wang Date: Tue, 16 Mar 2021 10:36:01 +0800 Subject: [PATCH 02/23] support model version check in c++ interface --- source/CMakeLists.txt | 5 +++ source/api_cc/include/DeepPot.h | 4 +++ source/api_cc/include/DeepTensor.h | 1 + source/api_cc/include/common.h | 5 +++ source/api_cc/src/DeepPot.cc | 18 ++++++++++- source/api_cc/src/DeepTensor.cc | 9 +++++- source/api_cc/src/common.cc | 40 +++++++++++++++++++++++ source/api_cc/tests/CMakeLists.txt | 6 ++-- source/tests/infer/dipolecharge_d.pbtxt | 21 +++++++++++++ source/tests/infer/dipolecharge_e.pbtxt | 42 +++++++++++++++++++++++++ 10 files changed, 147 insertions(+), 4 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 1803a10f5d..3aa8373aba 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -46,6 +46,11 @@ endif(GIT_FOUND) list (APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-ignored-attributes") +# model version +file(READ ${PROJECT_SOURCE_DIR}/train/MODEL_VER MODEL_VERSION) +string(REPLACE "\n" " " MODEL_VERSION ${MODEL_VERSION}) +message(STATUS "Current model version: ${MODEL_VERSION}") + # define USE_CUDA_TOOLKIT if (DEFINED USE_CUDA_TOOLKIT) if (USE_CUDA_TOOLKIT) diff --git a/source/api_cc/include/DeepPot.h b/source/api_cc/include/DeepPot.h index ba6162a62b..53996903c1 100644 --- a/source/api_cc/include/DeepPot.h +++ b/source/api_cc/include/DeepPot.h @@ -70,6 +70,8 @@ class DeepPot // int get_ntypes () const; VALUETYPE rcut; VALUETYPE cell_size; + std::string model_type; + std::string model_version; int ntypes; int dfparam; int daparam; @@ -163,6 +165,8 @@ class DeepPotModelDevi // int get_ntypes () const; VALUETYPE rcut; VALUETYPE cell_size; + std::string model_type; + std::string model_version; int ntypes; int dfparam; int daparam; diff --git a/source/api_cc/include/DeepTensor.h b/source/api_cc/include/DeepTensor.h index 786908f295..a60c6e1ed9 100644 --- a/source/api_cc/include/DeepTensor.h +++ b/source/api_cc/include/DeepTensor.h @@ -38,6 +38,7 @@ class DeepTensor VALUETYPE cell_size; int ntypes; std::string model_type; + std::string model_version; int odim; std::vector sel_type; template VT get_scalar(const std::string & name) const; diff --git a/source/api_cc/include/common.h b/source/api_cc/include/common.h index 698ebe04ed..46eb076d4f 100644 --- a/source/api_cc/include/common.h +++ b/source/api_cc/include/common.h @@ -42,6 +42,10 @@ struct NeighborListData void make_inlist(InputNlist & inlist); }; +bool +model_compatable( + std::string & model_version); + void select_by_type(std::vector & fwd_map, std::vector & bkw_map, @@ -204,3 +208,4 @@ select_map(std::vector & out, } } + diff --git a/source/api_cc/src/DeepPot.cc b/source/api_cc/src/DeepPot.cc index 71ca3226e9..f122f1173d 100644 --- a/source/api_cc/src/DeepPot.cc +++ b/source/api_cc/src/DeepPot.cc @@ -224,6 +224,14 @@ init (const std::string & model, const int & gpu_rank, const std::string & file_ daparam = get_scalar("fitting_attr/daparam"); if (dfparam < 0) dfparam = 0; if (daparam < 0) daparam = 0; + model_type = get_scalar("model_attr/model_type"); + model_version = get_scalar("model_attr/model_version"); + if(! model_compatable(model_version)){ + throw std::runtime_error( + "incompatable model: version " + model_version + + " in graph, but version " + global_model_version + + " supported "); + } inited = true; init_nbor = false; @@ -547,6 +555,14 @@ init (const std::vector & models, const int & gpu_rank, const std:: daparam = get_scalar("fitting_attr/daparam"); if (dfparam < 0) dfparam = 0; if (daparam < 0) daparam = 0; + model_type = get_scalar("model_attr/model_type"); + model_version = get_scalar("model_attr/model_version"); + if(! model_compatable(model_version)){ + throw std::runtime_error( + "incompatable model: version " + model_version + + " in graph, but version " + global_model_version + + " supported "); + } // rcut = get_rcut(); // cell_size = rcut; // ntypes = get_ntypes(); @@ -560,7 +576,7 @@ VT DeepPotModelDevi:: get_scalar(const std::string name) const { - VT myrcut = 0; + VT myrcut; for (unsigned ii = 0; ii < numb_models; ++ii){ VT ret = session_get_scalar(sessions[ii], name); if (ii == 0){ diff --git a/source/api_cc/src/DeepTensor.cc b/source/api_cc/src/DeepTensor.cc index 270d307013..e701c044f9 100644 --- a/source/api_cc/src/DeepTensor.cc +++ b/source/api_cc/src/DeepTensor.cc @@ -36,9 +36,16 @@ init (const std::string & model, rcut = get_scalar("descrpt_attr/rcut"); cell_size = rcut; ntypes = get_scalar("descrpt_attr/ntypes"); - model_type = get_scalar("model_attr/model_type"); odim = get_scalar("model_attr/output_dim"); get_vector(sel_type, "model_attr/sel_type"); + model_type = get_scalar("model_attr/model_type"); + model_version = get_scalar("model_attr/model_version"); + if(! model_compatable(model_version)){ + throw std::runtime_error( + "incompatable model: version " + model_version + + " in graph, but version " + global_model_version + + " supported "); + } inited = true; } diff --git a/source/api_cc/src/common.cc b/source/api_cc/src/common.cc index 4a431602d3..560790c1a1 100644 --- a/source/api_cc/src/common.cc +++ b/source/api_cc/src/common.cc @@ -2,6 +2,46 @@ #include "AtomMap.h" #include "device.h" +static std::vector +split(const std::string &input_, + const std::string &delimiter) +{ + std::string input = input_; + size_t pos = 0; + std::vector res; + while ((pos = input.find(delimiter)) != std::string::npos) { + res.push_back(input.substr(0, pos)); + input.erase(0, pos + delimiter.length()); + } + res.push_back(input); + return res; +} + +bool +model_compatable( + std::string & model_version) +{ + std::vector words_mv = split(model_version, "."); + std::vector words_gmv = split(global_model_version, "."); + if(words_mv.size() != 2){ + throw std::runtime_error("invalid graph model version string " + model_version); + } + if(words_gmv.size() != 2){ + throw std::runtime_error("invalid supported model version string " + global_model_version); + } + int model_version_major = atoi(words_mv[0].c_str()); + int model_version_minor = atoi(words_mv[1].c_str()); + int MODEL_VERSION_MAJOR = atoi(words_gmv[0].c_str()); + int MODEL_VERSION_MINOR = atoi(words_gmv[1].c_str()); + if(model_version_major != MODEL_VERSION_MAJOR || + model_version_minor > MODEL_VERSION_MINOR){ + return false; + } + else{ + return true; + } +} + void select_by_type(std::vector & fwd_map, std::vector & bkw_map, diff --git a/source/api_cc/tests/CMakeLists.txt b/source/api_cc/tests/CMakeLists.txt index aedb5b0f20..8f4bef0492 100644 --- a/source/api_cc/tests/CMakeLists.txt +++ b/source/api_cc/tests/CMakeLists.txt @@ -11,8 +11,10 @@ enable_testing() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") -message(${PROJECT_SOURCE_DIR}) -message(${CMAKE_SOURCE_DIR}) +# model version +file(READ ${PROJECT_SOURCE_DIR}/../../train/MODEL_VER MODEL_VERSION) +string(REPLACE "\n" " " MODEL_VERSION ${MODEL_VERSION}) +message(STATUS "Current model version: ${MODEL_VERSION}") set(libname "deepmd") set(LIB_BASE_DIR ${CMAKE_SOURCE_DIR}/../../lib) diff --git a/source/tests/infer/dipolecharge_d.pbtxt b/source/tests/infer/dipolecharge_d.pbtxt index 6bd2b430e3..6be963119f 100644 --- a/source/tests/infer/dipolecharge_d.pbtxt +++ b/source/tests/infer/dipolecharge_d.pbtxt @@ -7103,6 +7103,27 @@ node { } } } +node { + name: "model_attr/model_version" + op: "Const" + attr { + key: "dtype" + value { + type: DT_STRING + } + } + attr { + key: "value" + value { + tensor { + dtype: DT_STRING + tensor_shape { + } + string_val: "1.0" + } + } + } +} node { name: "model_attr/sel_type" op: "Const" diff --git a/source/tests/infer/dipolecharge_e.pbtxt b/source/tests/infer/dipolecharge_e.pbtxt index 61326137aa..ec9412a111 100644 --- a/source/tests/infer/dipolecharge_e.pbtxt +++ b/source/tests/infer/dipolecharge_e.pbtxt @@ -12402,6 +12402,27 @@ node { } } } +node { + name: "model_attr/model_version" + op: "Const" + attr { + key: "dtype" + value { + type: DT_STRING + } + } + attr { + key: "value" + value { + tensor { + dtype: DT_STRING + tensor_shape { + } + string_val: "1.0" + } + } + } +} node { name: "model_attr/tmap" op: "Const" @@ -56014,6 +56035,27 @@ node { } } } +node { + name: "dipole_charge/model_attr/model_version" + op: "Const" + attr { + key: "dtype" + value { + type: DT_STRING + } + } + attr { + key: "value" + value { + tensor { + dtype: DT_STRING + tensor_shape { + } + string_val: "1.0" + } + } + } +} node { name: "dipole_charge/model_attr/sel_type" op: "Const" From 8d57dc3446e877e9047d18abf90e26c48029d815 Mon Sep 17 00:00:00 2001 From: Han Wang Date: Tue, 16 Mar 2021 11:37:26 +0800 Subject: [PATCH 03/23] improved cmake message for model version --- source/CMakeLists.txt | 2 +- source/api_cc/tests/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 3aa8373aba..07f5bf7760 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -49,7 +49,7 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-ignored-attributes") # model version file(READ ${PROJECT_SOURCE_DIR}/train/MODEL_VER MODEL_VERSION) string(REPLACE "\n" " " MODEL_VERSION ${MODEL_VERSION}) -message(STATUS "Current model version: ${MODEL_VERSION}") +message(STATUS "Supported model version: ${MODEL_VERSION}") # define USE_CUDA_TOOLKIT if (DEFINED USE_CUDA_TOOLKIT) diff --git a/source/api_cc/tests/CMakeLists.txt b/source/api_cc/tests/CMakeLists.txt index 8f4bef0492..aabf452038 100644 --- a/source/api_cc/tests/CMakeLists.txt +++ b/source/api_cc/tests/CMakeLists.txt @@ -14,7 +14,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # model version file(READ ${PROJECT_SOURCE_DIR}/../../train/MODEL_VER MODEL_VERSION) string(REPLACE "\n" " " MODEL_VERSION ${MODEL_VERSION}) -message(STATUS "Current model version: ${MODEL_VERSION}") +message(STATUS "Supported model version: ${MODEL_VERSION}") set(libname "deepmd") set(LIB_BASE_DIR ${CMAKE_SOURCE_DIR}/../../lib) From bf775f7051dbcde8a205be40ac023a0769a23ee9 Mon Sep 17 00:00:00 2001 From: Han Wang Date: Tue, 16 Mar 2021 11:41:17 +0800 Subject: [PATCH 04/23] print model version on summary string --- source/api_cc/src/DeepPot.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/source/api_cc/src/DeepPot.cc b/source/api_cc/src/DeepPot.cc index f122f1173d..a5b9e6db8e 100644 --- a/source/api_cc/src/DeepPot.cc +++ b/source/api_cc/src/DeepPot.cc @@ -246,6 +246,7 @@ print_summary(const std::string &pre) const std::cout << pre << "source brach: " + global_git_branch << std::endl; std::cout << pre << "source commit: " + global_git_hash << std::endl; std::cout << pre << "source commit at: " + global_git_date << std::endl; + std::cout << pre << "surpport model ver.:" + global_model_version << std::endl; std::cout << pre << "build float prec: " + global_float_prec << std::endl; std::cout << pre << "build with tf inc: " + global_tf_include_dir << std::endl; std::cout << pre << "build with tf lib: " + global_tf_lib << std::endl; From 26b24cdf8ab3601f998d04d270adaf2459647dfd Mon Sep 17 00:00:00 2001 From: Han Wang Date: Tue, 16 Mar 2021 14:17:28 +0800 Subject: [PATCH 05/23] fix bugs in UT --- deepmd/infer/deep_eval.py | 1 + source/tests/test_data_modifier.py | 4 ++-- source/tests/test_data_modifier_shuffle.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/deepmd/infer/deep_eval.py b/deepmd/infer/deep_eval.py index dc31995e58..83f9a7aa6d 100644 --- a/deepmd/infer/deep_eval.py +++ b/deepmd/infer/deep_eval.py @@ -28,6 +28,7 @@ def __init__( ) self.load_prefix = load_prefix + # graph_compatable should be called after graph and prefix are set if not self._graph_compatable(): raise RuntimeError( f"model in graph (version {self.model_version}) is incompatible" diff --git a/source/tests/test_data_modifier.py b/source/tests/test_data_modifier.py index 70999f5734..9c47fa15dd 100644 --- a/source/tests/test_data_modifier.py +++ b/source/tests/test_data_modifier.py @@ -79,7 +79,7 @@ def _setUp(self): sess.run(init_op) graph = tf.get_default_graph() input_graph_def = graph.as_graph_def() - nodes = "o_dipole,o_rmat,o_rmat_deriv,o_nlist,o_rij,descrpt_attr/rcut,descrpt_attr/ntypes,descrpt_attr/sel,descrpt_attr/ndescrpt,model_attr/tmap,model_attr/sel_type,model_attr/model_type" + nodes = "o_dipole,o_rmat,o_rmat_deriv,o_nlist,o_rij,descrpt_attr/rcut,descrpt_attr/ntypes,descrpt_attr/sel,descrpt_attr/ndescrpt,model_attr/tmap,model_attr/sel_type,model_attr/model_type,model_attr/output_dim,model_attr/model_version" output_graph_def = tf.graph_util.convert_variables_to_constants( sess, input_graph_def, @@ -150,7 +150,7 @@ def _test_fv (self): num_deriv = np.transpose(num_deriv, [0,2,1]) t_esti = np.matmul(num_deriv, box3) - print(t_esti, '\n', vv.reshape([-1, 3, 3])) + # print(t_esti, '\n', vv.reshape([-1, 3, 3])) for ff in range(nframes): for ii in range(3): for jj in range(3): diff --git a/source/tests/test_data_modifier_shuffle.py b/source/tests/test_data_modifier_shuffle.py index 39269c2ff5..36ebfef35a 100644 --- a/source/tests/test_data_modifier_shuffle.py +++ b/source/tests/test_data_modifier_shuffle.py @@ -83,7 +83,7 @@ def _setUp(self): sess.run(init_op) graph = tf.get_default_graph() input_graph_def = graph.as_graph_def() - nodes = "o_dipole,o_rmat,o_rmat_deriv,o_nlist,o_rij,descrpt_attr/rcut,descrpt_attr/ntypes,descrpt_attr/sel,descrpt_attr/ndescrpt,model_attr/tmap,model_attr/sel_type,model_attr/model_type" + nodes = "o_dipole,o_rmat,o_rmat_deriv,o_nlist,o_rij,descrpt_attr/rcut,descrpt_attr/ntypes,descrpt_attr/sel,descrpt_attr/ndescrpt,model_attr/tmap,model_attr/sel_type,model_attr/model_type,model_attr/output_dim,model_attr/model_version" output_graph_def = tf.graph_util.convert_variables_to_constants( sess, input_graph_def, From 91971a2585ea2df5a686d7741bd1ac5dae34efa6 Mon Sep 17 00:00:00 2001 From: Han Wang Date: Tue, 16 Mar 2021 15:02:20 +0800 Subject: [PATCH 06/23] fix bug of model path in UT --- source/tests/test_deeppot_a.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/source/tests/test_deeppot_a.py b/source/tests/test_deeppot_a.py index b9a519672d..8541cb8fa3 100644 --- a/source/tests/test_deeppot_a.py +++ b/source/tests/test_deeppot_a.py @@ -25,18 +25,19 @@ def setUp(self): if "string_val:" in data[jj]: data[jj] = data[jj].replace(MODEL_VERSION, "0.0") break - with open("deeppot-ver.pbtxt", "w") as fp: + self.version_pbtxt = str(tests_path / "deeppot-ver.pbtxt") + self.version_pb = str(tests_path / "deeppot.pb") + with open(self.version_pbtxt, "w") as fp: fp.write("\n".join(data)) - - convert_pbtxt_to_pb(str(tests_path / os.path.join("deeppot-ver.pbtxt")), "deeppot.pb") + convert_pbtxt_to_pb(self.version_pbtxt, self.version_pb) def tearDown(self): - os.remove("deeppot-ver.pbtxt") - os.remove("deeppot.pb") + os.remove(self.version_pbtxt) + os.remove(self.version_pb) def test(self): with self.assertRaises(RuntimeError) as context: - DeepPot("deeppot.pb") + DeepPot(str(self.version_pb)) self.assertTrue('incompatible' in str(context.exception)) self.assertTrue(MODEL_VERSION in str(context.exception)) self.assertTrue('0.0' in str(context.exception)) @@ -54,18 +55,19 @@ def setUp(self): if "string_val:" in data[jj]: data[jj] = data[jj].replace(MODEL_VERSION, "0.1000000") break - with open("deeppot-ver.pbtxt", "w") as fp: + self.version_pbtxt = str(tests_path / "deeppot-ver.pbtxt") + self.version_pb = str(tests_path / "deeppot.pb") + with open(self.version_pbtxt, "w") as fp: fp.write("\n".join(data)) - - convert_pbtxt_to_pb(str(tests_path / os.path.join("deeppot-ver.pbtxt")), "deeppot.pb") + convert_pbtxt_to_pb(self.version_pbtxt, self.version_pb) def tearDown(self): - os.remove("deeppot-ver.pbtxt") - os.remove("deeppot.pb") + os.remove(self.version_pbtxt) + os.remove(self.version_pb) def test(self): with self.assertRaises(RuntimeError) as context: - DeepPot("deeppot.pb") + DeepPot(self.version_pb) self.assertTrue('incompatible' in str(context.exception)) self.assertTrue(MODEL_VERSION in str(context.exception)) self.assertTrue('0.1000000' in str(context.exception)) From 8d6a29f80d6374f831f627fa6f28583b2b9937a1 Mon Sep 17 00:00:00 2001 From: Han Wang Date: Tue, 16 Mar 2021 15:59:57 +0800 Subject: [PATCH 07/23] include the c++ api with deepmd prefix --- source/lmp/env.sh.in | 2 +- source/lmp/fix_dplr.h | 4 ++-- source/lmp/pair_deepmd.h.in | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/lmp/env.sh.in b/source/lmp/env.sh.in index 4baf835aff..a59ad84960 100644 --- a/source/lmp/env.sh.in +++ b/source/lmp/env.sh.in @@ -6,6 +6,6 @@ TF_INCLUDE_DIRS=`echo $TENSORFLOW_INCLUDE_DIRS | sed "s/;/ -I/g"` TF_LIBRARY_PATH=`echo $TENSORFLOW_LIBRARY_PATH | sed "s/;/ -L/g"` TF_RPATH=`echo $TENSORFLOW_LIBRARY_PATH | sed "s/;/ -Wl,-rpath=/g"` -NNP_INC=" -std=c++11 @PREC_DEF@ @TTM_DEF@ @OLD_LMP_PPPM_DEF@ -I$TF_INCLUDE_DIRS -I$DEEPMD_ROOT/include/deepmd " +NNP_INC=" -std=c++11 @PREC_DEF@ @TTM_DEF@ @OLD_LMP_PPPM_DEF@ -I$TF_INCLUDE_DIRS -I$DEEPMD_ROOT/include/ " NNP_PATH=" -L$TF_LIBRARY_PATH -L$DEEPMD_ROOT/lib" NNP_LIB=" -Wl,--no-as-needed -l@LIB_DEEPMD_OP_CUDA@ -l@LIB_DEEPMD_OP@ -l@LIB_DEEPMD_CC@ -l@LIB_DEEPMD@ -ltensorflow_cc -ltensorflow_framework -Wl,-rpath=$TF_RPATH -Wl,-rpath=$DEEPMD_ROOT/lib" diff --git a/source/lmp/fix_dplr.h b/source/lmp/fix_dplr.h index d81d8bd3db..aa8c95dd09 100644 --- a/source/lmp/fix_dplr.h +++ b/source/lmp/fix_dplr.h @@ -10,8 +10,8 @@ FixStyle(dplr,FixDPLR) #include #include "fix.h" #include "pair_deepmd.h" -#include "DeepTensor.h" -#include "DataModifier.h" +#include "deepmd/DeepTensor.h" +#include "deepmd/DataModifier.h" #ifdef HIGH_PREC #define FLOAT_PREC double diff --git a/source/lmp/pair_deepmd.h.in b/source/lmp/pair_deepmd.h.in index 6a5c24444a..25d950c948 100644 --- a/source/lmp/pair_deepmd.h.in +++ b/source/lmp/pair_deepmd.h.in @@ -21,7 +21,7 @@ PairStyle(deepmd,PairDeepMD) #define LMP_PAIR_NNP_H #include "pair.h" -#include "DeepPot.h" +#include "deepmd/DeepPot.h" #include #include From 48962fb70b02709cb374edd46a14a346ead05eba Mon Sep 17 00:00:00 2001 From: Han Wang Date: Tue, 16 Mar 2021 19:56:14 +0800 Subject: [PATCH 08/23] add deepmd namespace for the c++ interface --- source/api_cc/include/AtomMap.h | 2 + source/api_cc/include/DataModifier.h | 10 +- source/api_cc/include/DeepPot.h | 17 +- source/api_cc/include/DeepTensor.h | 13 +- source/api_cc/include/common.h | 126 ++------- source/api_cc/src/AtomMap.cc | 2 + source/api_cc/src/DataModifier.cc | 11 +- source/api_cc/src/DeepPot.cc | 26 +- source/api_cc/src/DeepTensor.cc | 11 +- source/api_cc/src/common.cc | 244 +++++++++++++++--- source/api_cc/tests/test_deepdipole.cc | 10 +- source/api_cc/tests/test_deeppolar.cc | 10 +- source/api_cc/tests/test_deeppot_a.cc | 22 +- .../api_cc/tests/test_deeppot_model_devi.cc | 18 +- source/api_cc/tests/test_deeppot_r.cc | 22 +- source/api_cc/tests/test_dipolecharge.cc | 20 +- source/ipi/driver.cc | 14 +- source/lmp/fix_dplr.cpp | 6 +- source/lmp/fix_dplr.h | 4 +- source/lmp/pair_deepmd.cpp | 2 +- source/lmp/pair_deepmd.h.in | 4 +- 21 files changed, 344 insertions(+), 250 deletions(-) diff --git a/source/api_cc/include/AtomMap.h b/source/api_cc/include/AtomMap.h index 32c4ed7c99..bf9a8c650c 100644 --- a/source/api_cc/include/AtomMap.h +++ b/source/api_cc/include/AtomMap.h @@ -4,6 +4,7 @@ // using namespace std; +namespace deepmd{ template class AtomMap { @@ -25,3 +26,4 @@ class AtomMap std::vector fwd_idx_map; std::vector atype; }; +} diff --git a/source/api_cc/include/DataModifier.h b/source/api_cc/include/DataModifier.h index 822812621b..114abfd889 100644 --- a/source/api_cc/include/DataModifier.h +++ b/source/api_cc/include/DataModifier.h @@ -2,6 +2,7 @@ #include "DeepPot.h" +namespace deepmd{ class DipoleChargeModifier { public: @@ -28,10 +29,10 @@ class DipoleChargeModifier int numb_types () const {assert(inited); return ntypes;}; std::vector sel_types () const {assert(inited); return sel_type;}; private: - Session* session; + tensorflow::Session* session; std::string name_scope, name_prefix; int num_intra_nthreads, num_inter_nthreads; - GraphDef graph_def; + tensorflow::GraphDef graph_def; bool inited; VALUETYPE rcut; VALUETYPE cell_size; @@ -42,9 +43,10 @@ class DipoleChargeModifier template void get_vector(std::vector & vec, const std::string & name) const; void run_model (std::vector & dforce, std::vector & dvirial, - Session * session, - const std::vector> & input_tensors, + tensorflow::Session * session, + const std::vector> & input_tensors, const AtomMap & atommap, const int nghost); }; +} diff --git a/source/api_cc/include/DeepPot.h b/source/api_cc/include/DeepPot.h index 53996903c1..63cf568376 100644 --- a/source/api_cc/include/DeepPot.h +++ b/source/api_cc/include/DeepPot.h @@ -2,8 +2,8 @@ #include "common.h" #include "neighbor_list.h" -typedef double compute_t; +namespace deepmd{ class DeepPot { public: @@ -61,9 +61,9 @@ class DeepPot int dim_aparam () const {assert(inited); return daparam;}; void get_type_map (std::string & type_map); private: - Session* session; + tensorflow::Session* session; int num_intra_nthreads, num_inter_nthreads; - GraphDef graph_def; + tensorflow::GraphDef graph_def; bool inited; template VT get_scalar(const std::string & name) const; // VALUETYPE get_rcut () const; @@ -92,7 +92,6 @@ class DeepPot // copy neighbor list info from host bool init_nbor; std::vector sec_a; - compute_t *array_double; NeighborListData nlist_data; InputNlist nlist; AtomMap atommap; @@ -156,9 +155,9 @@ class DeepPotModelDevi const VALUETYPE eps); private: unsigned numb_models; - std::vector sessions; + std::vector sessions; int num_intra_nthreads, num_inter_nthreads; - std::vector graph_defs; + std::vector graph_defs; bool inited; template VT get_scalar(const std::string name) const; // VALUETYPE get_rcut () const; @@ -176,15 +175,15 @@ class DeepPotModelDevi // copy neighbor list info from host bool init_nbor; - compute_t *array_double; std::vector > sec; - AtomMap atommap; + deepmd::AtomMap atommap; NeighborListData nlist_data; InputNlist nlist; // function used for nborlist copy std::vector > get_sel() const; - void cum_sum(const std::vector > n_sel); + void cum_sum(const std::vector > n_sel); }; +} diff --git a/source/api_cc/include/DeepTensor.h b/source/api_cc/include/DeepTensor.h index a60c6e1ed9..bfa5cd1ba8 100644 --- a/source/api_cc/include/DeepTensor.h +++ b/source/api_cc/include/DeepTensor.h @@ -1,7 +1,9 @@ #pragma once -#include "DeepPot.h" +#include "common.h" +#include "neighbor_list.h" +namespace deepmd{ class DeepTensor { public: @@ -29,10 +31,10 @@ class DeepTensor int output_dim () const {assert(inited); return odim;}; const std::vector & sel_types () const {assert(inited); return sel_type;}; private: - Session* session; + tensorflow::Session* session; std::string name_scope; int num_intra_nthreads, num_inter_nthreads; - GraphDef graph_def; + tensorflow::GraphDef graph_def; bool inited; VALUETYPE rcut; VALUETYPE cell_size; @@ -44,8 +46,8 @@ class DeepTensor template VT get_scalar(const std::string & name) const; template void get_vector (std::vector & vec, const std::string & name) const; void run_model (std::vector & d_tensor_, - Session * session, - const std::vector> & input_tensors, + tensorflow::Session * session, + const std::vector> & input_tensors, const AtomMap & atommap, const int nghost = 0); void compute_inner (std::vector & value, @@ -59,4 +61,5 @@ class DeepTensor const int nghost, const InputNlist& inlist); }; +} diff --git a/source/api_cc/include/common.h b/source/api_cc/include/common.h index 46eb076d4f..c489053b6c 100644 --- a/source/api_cc/include/common.h +++ b/source/api_cc/include/common.h @@ -13,7 +13,9 @@ #include #include -using namespace tensorflow; + +namespace deepmd{ + #if TF_MAJOR_VERSION >= 2 && TF_MINOR_VERSION >= 2 typedef tensorflow::tstring STRINGTYPE; #else @@ -37,7 +39,7 @@ struct NeighborListData public: void copy_from_nlist(const InputNlist & inlist); void shuffle(const std::vector & fwd_map); - void shuffle(const AtomMap & map); + void shuffle(const deepmd::AtomMap & map); void shuffle_exclude_empty(const std::vector & fwd_map); void make_inlist(InputNlist & inlist); }; @@ -76,20 +78,30 @@ get_env_nthreads(int & num_intra_nthreads, int & num_inter_nthreads); void -checkStatus(const tensorflow::Status& status); +check_status( + const tensorflow::Status& status); -std::string name_prefix(const std::string & name_scope); +std::string +name_prefix( + const std::string & name_scope); template VT -session_get_scalar(Session* session, const std::string name, const std::string scope = ""); +session_get_scalar( + tensorflow::Session* session, + const std::string name, + const std::string scope = ""); template void -session_get_vector(std::vector & o_vec, Session* session, const std::string name_, const std::string scope = ""); +session_get_vector( + std::vector & o_vec, + tensorflow::Session* session, + const std::string name_, + const std::string scope = ""); int -session_input_tensors (std::vector> & input_tensors, +session_input_tensors (std::vector> & input_tensors, const std::vector & dcoord_, const int & ntypes, const std::vector & datype_, @@ -97,11 +109,11 @@ session_input_tensors (std::vector> & input_tenso const VALUETYPE & cell_size, const std::vector & fparam_, const std::vector & aparam_, - const AtomMap& atommap, + const deepmd::AtomMap&atommap, const std::string scope = ""); int -session_input_tensors (std::vector> & input_tensors, +session_input_tensors (std::vector> & input_tensors, const std::vector & dcoord_, const int & ntypes, const std::vector & datype_, @@ -109,103 +121,9 @@ session_input_tensors (std::vector> & input_tenso InputNlist & dlist, const std::vector & fparam_, const std::vector & aparam_, - const AtomMap& atommap, + const deepmd::AtomMap&atommap, const int nghost, const int ago, const std::string scope = ""); - -// int -// session_input_tensors (std::vector> & input_tensors, -// const std::vector & dcoord_, -// const int & ntypes, -// const std::vector & datype_, -// const std::vector & dbox, -// InputNlist & dlist, -// const std::vector & fparam_, -// const std::vector & aparam_, -// const AtomMap& atommap, -// const int nghost, -// const std::string scope = ""); - -// int -// session_input_tensors (std::vector>& input_tensors, -// const std::vector & dcoord_, -// const int & ntypes, -// const std::vector & atype_, -// const std::vector & dbox, -// const int * ilist, -// const int * jrange, -// const int * jlist, -// const std::vector & fparam_, -// const std::vector & aparam_, -// const AtomMap & atommap, -// const int & nghost); - - -template -VT -session_get_scalar(Session* session, const std::string name_, const std::string scope) -{ - std::string name = name_; - if (scope != "") { - name = scope + "/" + name; - } - std::vector output_tensors; - checkStatus (session->Run(std::vector> ({}), - {name.c_str()}, - {}, - &output_tensors)); - Tensor output_rc = output_tensors[0]; - auto orc = output_rc.flat (); - return orc(0); -} - -template -void -session_get_vector(std::vector & o_vec, Session* session, const std::string name_, const std::string scope) -{ - std::string name = name_; - if (scope != "") { - name = scope + "/" + name; - } - std::vector output_tensors; - checkStatus (session->Run(std::vector> ({}), - {name.c_str()}, - {}, - &output_tensors)); - Tensor output_rc = output_tensors[0]; - assert(1 == output_rc.shape().dims()); - int dof = output_rc.shape().dim_size(0); - o_vec.resize(dof); - auto orc = output_rc.flat (); - for (int ii = 0; ii < dof; ++ii){ - o_vec[ii] = orc(ii); - } -} - - -template -void -select_map(std::vector & out, - const std::vector & in, - const std::vector & idx_map, - const int & stride) -{ -#ifdef DEBUG - assert(in.size() / stride * stride == in.size()), "in size should be multiples of stride" -#endif - for (int ii = 0; ii < in.size() / stride; ++ii){ -#ifdef DEBUG - assert(ii < idx_map.size()), "idx goes over the idx map size"; - assert(idx_map[ii] < out.size()), "mappped idx goes over the out size"; -#endif - if (idx_map[ii] >= 0) { - int to_ii = idx_map[ii]; - for (int dd = 0; dd < stride; ++dd){ - out[to_ii * stride + dd] = in[ii * stride + dd]; - } - } - } } - diff --git a/source/api_cc/src/AtomMap.cc b/source/api_cc/src/AtomMap.cc index dc37669fa6..8e7e82a1ce 100644 --- a/source/api_cc/src/AtomMap.cc +++ b/source/api_cc/src/AtomMap.cc @@ -3,6 +3,8 @@ #include #include +using namespace deepmd; + template AtomMap:: AtomMap() {} diff --git a/source/api_cc/src/DataModifier.cc b/source/api_cc/src/DataModifier.cc index 94ebadf724..f704ba599e 100644 --- a/source/api_cc/src/DataModifier.cc +++ b/source/api_cc/src/DataModifier.cc @@ -1,5 +1,8 @@ #include "DataModifier.h" +using namespace deepmd; +using namespace tensorflow; + DipoleChargeModifier:: DipoleChargeModifier() : inited (false) @@ -30,9 +33,9 @@ init (const std::string & model, get_env_nthreads(num_intra_nthreads, num_inter_nthreads); options.config.set_inter_op_parallelism_threads(num_inter_nthreads); options.config.set_intra_op_parallelism_threads(num_intra_nthreads); - checkStatus(NewSession(options, &session)); - checkStatus(ReadBinaryProto(Env::Default(), model, &graph_def)); - checkStatus(session->Create(graph_def)); + deepmd::check_status(NewSession(options, &session)); + deepmd::check_status(ReadBinaryProto(Env::Default(), model, &graph_def)); + deepmd::check_status(session->Create(graph_def)); // int nnodes = graph_def.node_size(); // for (int ii = 0; ii < nnodes; ++ii){ // cout << ii << " \t " << graph_def.node(ii).name() << endl; @@ -80,7 +83,7 @@ run_model (std::vector & dforce, } std::vector output_tensors; - checkStatus (session->Run(input_tensors, + deepmd::check_status (session->Run(input_tensors, {"o_dm_force", "o_dm_virial", "o_dm_av"}, {}, &output_tensors)); diff --git a/source/api_cc/src/DeepPot.cc b/source/api_cc/src/DeepPot.cc index a5b9e6db8e..9a3e8d7a10 100644 --- a/source/api_cc/src/DeepPot.cc +++ b/source/api_cc/src/DeepPot.cc @@ -2,6 +2,8 @@ #include "AtomMap.h" #include +using namespace tensorflow; +using namespace deepmd; #if GOOGLE_CUDA #include "cuda_runtime.h" @@ -54,7 +56,7 @@ run_model (ENERGYTYPE & dener, } std::vector output_tensors; - checkStatus (session->Run(input_tensors, + check_status (session->Run(input_tensors, {"o_energy", "o_force", "o_atom_virial"}, {}, &output_tensors)); @@ -95,7 +97,7 @@ static void run_model (ENERGYTYPE & dener, std::vector& datom_virial_, Session* session, const std::vector> & input_tensors, - const AtomMap & atommap, + const deepmd::AtomMap & atommap, const int& nghost = 0) { unsigned nloc = atommap.get_type().size(); @@ -119,7 +121,7 @@ static void run_model (ENERGYTYPE & dener, } std::vector output_tensors; - checkStatus (session->Run(input_tensors, + check_status (session->Run(input_tensors, {"o_energy", "o_force", "o_atom_energy", "o_atom_virial"}, {}, &output_tensors)); @@ -199,7 +201,7 @@ init (const std::string & model, const int & gpu_rank, const std::string & file_ options.config.set_intra_op_parallelism_threads(num_intra_nthreads); if(file_content.size() == 0) - checkStatus (ReadBinaryProto(Env::Default(), model, &graph_def)); + check_status (ReadBinaryProto(Env::Default(), model, &graph_def)); else graph_def.ParseFromString(file_content); int gpu_num = -1; @@ -215,8 +217,8 @@ init (const std::string & model, const int & gpu_rank, const std::string & file_ graph::SetDefaultDevice(str, &graph_def); } #endif // GOOGLE_CUDA - checkStatus (NewSession(options, &session)); - checkStatus (session->Create(graph_def)); + check_status (NewSession(options, &session)); + check_status (session->Create(graph_def)); rcut = get_scalar("descrpt_attr/rcut"); cell_size = rcut; ntypes = get_scalar("descrpt_attr/ntypes"); @@ -334,7 +336,7 @@ compute (ENERGYTYPE & dener, { int nall = dcoord_.size() / 3; int nloc = nall; - atommap = AtomMap (datype_.begin(), datype_.begin() + nloc); + atommap = deepmd::AtomMap (datype_.begin(), datype_.begin() + nloc); assert (nloc == atommap.get_type().size()); validate_fparam_aparam(nloc, fparam, aparam); @@ -406,7 +408,7 @@ compute_inner (ENERGYTYPE & dener, // agp == 0 means that the LAMMPS nbor list has been updated if (ago == 0) { - atommap = AtomMap (datype_.begin(), datype_.begin() + nloc); + atommap = deepmd::AtomMap (datype_.begin(), datype_.begin() + nloc); assert (nloc == atommap.get_type().size()); nlist_data.shuffle(atommap); nlist_data.make_inlist(nlist); @@ -430,7 +432,7 @@ compute (ENERGYTYPE & dener, const std::vector & fparam, const std::vector & aparam) { - atommap = AtomMap (datype_.begin(), datype_.end()); + atommap = deepmd::AtomMap (datype_.begin(), datype_.end()); validate_fparam_aparam(atommap.get_type().size(), fparam, aparam); std::vector> input_tensors; @@ -527,7 +529,7 @@ init (const std::vector & models, const int & gpu_rank, const std:: options.config.set_intra_op_parallelism_threads(num_intra_nthreads); for (unsigned ii = 0; ii < numb_models; ++ii){ if (file_contents.size() == 0) - checkStatus (ReadBinaryProto(Env::Default(), models[ii], &graph_defs[ii])); + check_status (ReadBinaryProto(Env::Default(), models[ii], &graph_defs[ii])); else graph_defs[ii].ParseFromString(file_contents[ii]); } @@ -546,8 +548,8 @@ init (const std::vector & models, const int & gpu_rank, const std:: str += std::to_string(gpu_rank % gpu_num); graph::SetDefaultDevice(str, &graph_defs[ii]); } - checkStatus (NewSession(options, &(sessions[ii]))); - checkStatus (sessions[ii]->Create(graph_defs[ii])); + check_status (NewSession(options, &(sessions[ii]))); + check_status (sessions[ii]->Create(graph_defs[ii])); } rcut = get_scalar("descrpt_attr/rcut"); cell_size = rcut; diff --git a/source/api_cc/src/DeepTensor.cc b/source/api_cc/src/DeepTensor.cc index e701c044f9..a907ae0e19 100644 --- a/source/api_cc/src/DeepTensor.cc +++ b/source/api_cc/src/DeepTensor.cc @@ -1,5 +1,8 @@ #include "DeepTensor.h" +using namespace deepmd; +using namespace tensorflow; + DeepTensor:: DeepTensor() : inited (false) @@ -30,9 +33,9 @@ init (const std::string & model, get_env_nthreads(num_intra_nthreads, num_inter_nthreads); options.config.set_inter_op_parallelism_threads(num_inter_nthreads); options.config.set_intra_op_parallelism_threads(num_intra_nthreads); - checkStatus (NewSession(options, &session)); - checkStatus (ReadBinaryProto(Env::Default(), model, &graph_def)); - checkStatus (session->Create(graph_def)); + deepmd::check_status (NewSession(options, &session)); + deepmd::check_status (ReadBinaryProto(Env::Default(), model, &graph_def)); + deepmd::check_status (session->Create(graph_def)); rcut = get_scalar("descrpt_attr/rcut"); cell_size = rcut; ntypes = get_scalar("descrpt_attr/ntypes"); @@ -82,7 +85,7 @@ run_model (std::vector & d_tensor_, } std::vector output_tensors; - checkStatus (session->Run(input_tensors, + deepmd::check_status (session->Run(input_tensors, {name_prefix(name_scope) + "o_" + model_type}, {}, &output_tensors)); diff --git a/source/api_cc/src/common.cc b/source/api_cc/src/common.cc index 560790c1a1..74c317529e 100644 --- a/source/api_cc/src/common.cc +++ b/source/api_cc/src/common.cc @@ -2,6 +2,8 @@ #include "AtomMap.h" #include "device.h" +using namespace tensorflow; + static std::vector split(const std::string &input_, const std::string &delimiter) @@ -18,6 +20,7 @@ split(const std::string &input_, } bool +deepmd:: model_compatable( std::string & model_version) { @@ -43,10 +46,11 @@ model_compatable( } void +deepmd:: select_by_type(std::vector & fwd_map, std::vector & bkw_map, int & nghost_real, - const std::vector & dcoord_, + const std::vector & dcoord_, const std::vector & datype_, const int & nghost, const std::vector & sel_type_) @@ -84,10 +88,11 @@ select_by_type(std::vector & fwd_map, void +deepmd:: select_real_atoms(std::vector & fwd_map, std::vector & bkw_map, int & nghost_real, - const std::vector & dcoord_, + const std::vector & dcoord_, const std::vector & datype_, const int & nghost, const int & ntypes) @@ -96,12 +101,12 @@ select_real_atoms(std::vector & fwd_map, for (int ii = 0; ii < ntypes; ++ii){ sel_type.push_back(ii); } - select_by_type(fwd_map, bkw_map, nghost_real, dcoord_, datype_, nghost, sel_type); + deepmd::select_by_type(fwd_map, bkw_map, nghost_real, dcoord_, datype_, nghost, sel_type); } void -NeighborListData:: +deepmd::NeighborListData:: copy_from_nlist(const InputNlist & inlist) { int inum = inlist.inum; @@ -117,15 +122,15 @@ copy_from_nlist(const InputNlist & inlist) void -NeighborListData:: -shuffle(const AtomMap & map) +deepmd::NeighborListData:: +shuffle(const AtomMap & map) { const std::vector & fwd_map = map.get_fwd_map(); shuffle(fwd_map); } void -NeighborListData:: +deepmd::NeighborListData:: shuffle(const std::vector & fwd_map) { int nloc = fwd_map.size(); @@ -144,7 +149,7 @@ shuffle(const std::vector & fwd_map) } void -NeighborListData:: +deepmd::NeighborListData:: shuffle_exclude_empty (const std::vector & fwd_map) { shuffle(fwd_map); @@ -175,7 +180,7 @@ shuffle_exclude_empty (const std::vector & fwd_map) } void -NeighborListData:: +deepmd::NeighborListData:: make_inlist(InputNlist & inlist) { int nloc = ilist.size(); @@ -192,7 +197,8 @@ make_inlist(InputNlist & inlist) } void -checkStatus(const tensorflow::Status& status) { +deepmd:: +check_status(const tensorflow::Status& status) { if (!status.ok()) { std::cout << status.ToString() << std::endl; exit(1); @@ -200,6 +206,7 @@ checkStatus(const tensorflow::Status& status) { } void +deepmd:: get_env_nthreads(int & num_intra_nthreads, int & num_inter_nthreads) { @@ -222,6 +229,7 @@ get_env_nthreads(int & num_intra_nthreads, } std::string +deepmd:: name_prefix(const std::string & scope) { std::string prefix = ""; @@ -232,16 +240,18 @@ name_prefix(const std::string & scope) } int -session_input_tensors (std::vector> & input_tensors, - const std::vector & dcoord_, - const int & ntypes, - const std::vector & datype_, - const std::vector & dbox, - const VALUETYPE & cell_size, - const std::vector & fparam_, - const std::vector & aparam_, - const AtomMap& atommap, - const std::string scope) +deepmd:: +session_input_tensors ( + std::vector> & input_tensors, + const std::vector & dcoord_, + const int & ntypes, + const std::vector & datype_, + const std::vector & dbox, + const deepmd::VALUETYPE & cell_size, + const std::vector & fparam_, + const std::vector & aparam_, + const deepmd::AtomMap& atommap, + const std::string scope) { bool b_pbc = (dbox.size() == 9); @@ -297,15 +307,15 @@ session_input_tensors (std::vector> & input_tenso Tensor mesh_tensor (DT_INT32, mesh_shape); Tensor natoms_tensor (DT_INT32, natoms_shape); - auto coord = coord_tensor.matrix (); + auto coord = coord_tensor.matrix (); auto type = type_tensor.matrix (); - auto box = box_tensor.matrix (); + auto box = box_tensor.matrix (); auto mesh = mesh_tensor.flat (); auto natoms = natoms_tensor.flat (); - auto fparam = fparam_tensor.matrix (); - auto aparam = aparam_tensor.matrix (); + auto fparam = fparam_tensor.matrix (); + auto aparam = aparam_tensor.matrix (); - std::vector dcoord (dcoord_); + std::vector dcoord (dcoord_); atommap.forward (dcoord.begin(), dcoord_.begin(), 3); for (int ii = 0; ii < nframes; ++ii){ @@ -365,18 +375,20 @@ session_input_tensors (std::vector> & input_tenso } int -session_input_tensors (std::vector> & input_tensors, - const std::vector & dcoord_, - const int & ntypes, - const std::vector & datype_, - const std::vector & dbox, - InputNlist & dlist, - const std::vector & fparam_, - const std::vector & aparam_, - const AtomMap& atommap, - const int nghost, - const int ago, - const std::string scope) +deepmd:: +session_input_tensors ( + std::vector> & input_tensors, + const std::vector & dcoord_, + const int & ntypes, + const std::vector & datype_, + const std::vector & dbox, + InputNlist & dlist, + const std::vector & fparam_, + const std::vector & aparam_, + const deepmd::AtomMap& atommap, + const int nghost, + const int ago, + const std::string scope) { assert (dbox.size() == 9); @@ -427,15 +439,15 @@ session_input_tensors (std::vector> & input_tenso Tensor mesh_tensor (DT_INT32, mesh_shape); Tensor natoms_tensor (DT_INT32, natoms_shape); - auto coord = coord_tensor.matrix (); + auto coord = coord_tensor.matrix (); auto type = type_tensor.matrix (); - auto box = box_tensor.matrix (); + auto box = box_tensor.matrix (); auto mesh = mesh_tensor.flat (); auto natoms = natoms_tensor.flat (); - auto fparam = fparam_tensor.matrix (); - auto aparam = aparam_tensor.matrix (); + auto fparam = fparam_tensor.matrix (); + auto aparam = aparam_tensor.matrix (); - std::vector dcoord (dcoord_); + std::vector dcoord (dcoord_); atommap.forward (dcoord.begin(), dcoord_.begin(), 3); for (int ii = 0; ii < nframes; ++ii){ @@ -493,3 +505,151 @@ session_input_tensors (std::vector> & input_tenso return nloc; } +template +VT +deepmd:: +session_get_scalar(Session* session, const std::string name_, const std::string scope) +{ + std::string name = name_; + if (scope != "") { + name = scope + "/" + name; + } + std::vector output_tensors; + deepmd::check_status (session->Run(std::vector> ({}), + {name.c_str()}, + {}, + &output_tensors)); + Tensor output_rc = output_tensors[0]; + auto orc = output_rc.flat (); + return orc(0); +} + +template +void +deepmd:: +session_get_vector(std::vector & o_vec, Session* session, const std::string name_, const std::string scope) +{ + std::string name = name_; + if (scope != "") { + name = scope + "/" + name; + } + std::vector output_tensors; + deepmd::check_status (session->Run(std::vector> ({}), + {name.c_str()}, + {}, + &output_tensors)); + Tensor output_rc = output_tensors[0]; + assert(1 == output_rc.shape().dims()); + int dof = output_rc.shape().dim_size(0); + o_vec.resize(dof); + auto orc = output_rc.flat (); + for (int ii = 0; ii < dof; ++ii){ + o_vec[ii] = orc(ii); + } +} + + +template +void +deepmd:: +select_map(std::vector & out, + const std::vector & in, + const std::vector & idx_map, + const int & stride) +{ +#ifdef DEBUG + assert(in.size() / stride * stride == in.size()), "in size should be multiples of stride" +#endif + for (int ii = 0; ii < in.size() / stride; ++ii){ +#ifdef DEBUG + assert(ii < idx_map.size()), "idx goes over the idx map size"; + assert(idx_map[ii] < out.size()), "mappped idx goes over the out size"; +#endif + if (idx_map[ii] >= 0) { + int to_ii = idx_map[ii]; + for (int dd = 0; dd < stride; ++dd){ + out[to_ii * stride + dd] = in[ii * stride + dd]; + } + } + } +} + + +template +int +deepmd:: +session_get_scalar(Session*, const std::string, const std::string); + +template +void +deepmd:: +session_get_vector(std::vector &, Session*, const std::string, const std::string); + +template +void +deepmd:: +select_map( + std::vector & out, + const std::vector & in, + const std::vector & idx_map, + const int & stride); + + +template +float +deepmd:: +session_get_scalar(Session*, const std::string, const std::string); + +template +void +deepmd:: +session_get_vector(std::vector &, Session*, const std::string, const std::string); + +template +void +deepmd:: +select_map( + std::vector & out, + const std::vector & in, + const std::vector & idx_map, + const int & stride); + + +template +double +deepmd:: +session_get_scalar(Session*, const std::string, const std::string); + +template +void +deepmd:: +session_get_vector(std::vector &, Session*, const std::string, const std::string); + +template +void +deepmd:: +select_map( + std::vector & out, + const std::vector & in, + const std::vector & idx_map, + const int & stride); + + +template +deepmd::STRINGTYPE +deepmd:: +session_get_scalar(Session*, const std::string, const std::string); + +template +void +deepmd:: +session_get_vector(std::vector &, Session*, const std::string, const std::string); + +template +void +deepmd:: +select_map( + std::vector & out, + const std::vector & in, + const std::vector & idx_map, + const int & stride); diff --git a/source/api_cc/tests/test_deepdipole.cc b/source/api_cc/tests/test_deepdipole.cc index 04d068ddfb..bfdcc1de17 100644 --- a/source/api_cc/tests/test_deepdipole.cc +++ b/source/api_cc/tests/test_deepdipole.cc @@ -35,20 +35,20 @@ class TestInferDeepDipole : public ::testing::Test }; int natoms; - DeepTensor dp; + deepmd::DeepTensor dp; void SetUp() override { std::string file_name = "../../tests/infer/deepdipole.pbtxt"; int fd = open(file_name.c_str(), O_RDONLY); - protobuf::io::ZeroCopyInputStream* input = new protobuf::io::FileInputStream(fd); - GraphDef graph_def; - protobuf::TextFormat::Parse(input, &graph_def); + tensorflow::protobuf::io::ZeroCopyInputStream* input = new tensorflow::protobuf::io::FileInputStream(fd); + tensorflow::GraphDef graph_def; + tensorflow::protobuf::TextFormat::Parse(input, &graph_def); delete input; std::fstream output("deepdipole.pb", std::ios::out | std::ios::trunc | std::ios::binary); graph_def.SerializeToOstream(&output); // check the string by the following commands // string txt; - // protobuf::TextFormat::PrintToString(graph_def, &txt); + // tensorflow::protobuf::TextFormat::PrintToString(graph_def, &txt); dp.init("deepdipole.pb"); diff --git a/source/api_cc/tests/test_deeppolar.cc b/source/api_cc/tests/test_deeppolar.cc index acae6e13e0..19e9b8af7c 100644 --- a/source/api_cc/tests/test_deeppolar.cc +++ b/source/api_cc/tests/test_deeppolar.cc @@ -35,20 +35,20 @@ class TestInferDeepPolar : public ::testing::Test }; int natoms; - DeepTensor dp; + deepmd::DeepTensor dp; void SetUp() override { std::string file_name = "../../tests/infer/deeppolar.pbtxt"; int fd = open(file_name.c_str(), O_RDONLY); - protobuf::io::ZeroCopyInputStream* input = new protobuf::io::FileInputStream(fd); - GraphDef graph_def; - protobuf::TextFormat::Parse(input, &graph_def); + tensorflow::protobuf::io::ZeroCopyInputStream* input = new tensorflow::protobuf::io::FileInputStream(fd); + tensorflow::GraphDef graph_def; + tensorflow::protobuf::TextFormat::Parse(input, &graph_def); delete input; std::fstream output("deeppolar.pb", std::ios::out | std::ios::trunc | std::ios::binary); graph_def.SerializeToOstream(&output); // check the string by the following commands // string txt; - // protobuf::TextFormat::PrintToString(graph_def, &txt); + // tensorflow::protobuf::TextFormat::PrintToString(graph_def, &txt); dp.init("deeppolar.pb"); diff --git a/source/api_cc/tests/test_deeppot_a.cc b/source/api_cc/tests/test_deeppot_a.cc index 01f5d6f421..77b343f91e 100644 --- a/source/api_cc/tests/test_deeppot_a.cc +++ b/source/api_cc/tests/test_deeppot_a.cc @@ -43,20 +43,20 @@ class TestInferDeepPotA : public ::testing::Test double expected_tot_e; std::vectorexpected_tot_v; - DeepPot dp; + deepmd::DeepPot dp; void SetUp() override { std::string file_name = "../../tests/infer/deeppot.pbtxt"; int fd = open(file_name.c_str(), O_RDONLY); - protobuf::io::ZeroCopyInputStream* input = new protobuf::io::FileInputStream(fd); - GraphDef graph_def; - protobuf::TextFormat::Parse(input, &graph_def); + tensorflow::protobuf::io::ZeroCopyInputStream* input = new tensorflow::protobuf::io::FileInputStream(fd); + tensorflow::GraphDef graph_def; + tensorflow::protobuf::TextFormat::Parse(input, &graph_def); delete input; std::fstream output("deeppot.pb", std::ios::out | std::ios::trunc | std::ios::binary); graph_def.SerializeToOstream(&output); // check the string by the following commands // string txt; - // protobuf::TextFormat::PrintToString(graph_def, &txt); + // tensorflow::protobuf::TextFormat::PrintToString(graph_def, &txt); dp.init("deeppot.pb"); @@ -103,11 +103,11 @@ TEST_F(TestInferDeepPotA, cpu_build_nlist_numfv) { class MyModel : public EnergyModelTest { - DeepPot & mydp; + deepmd::DeepPot & mydp; const std::vector atype; public: MyModel( - DeepPot & dp_, + deepmd::DeepPot & dp_, const std::vector & atype_ ) : mydp(dp_), atype(atype_) {}; virtual void compute ( @@ -426,14 +426,14 @@ class TestInferDeepPotANoPbc : public ::testing::Test double expected_tot_e; std::vectorexpected_tot_v; - DeepPot dp; + deepmd::DeepPot dp; void SetUp() override { std::string file_name = "../../tests/infer/deeppot.pbtxt"; int fd = open(file_name.c_str(), O_RDONLY); - protobuf::io::ZeroCopyInputStream* input = new protobuf::io::FileInputStream(fd); - GraphDef graph_def; - protobuf::TextFormat::Parse(input, &graph_def); + tensorflow::protobuf::io::ZeroCopyInputStream* input = new tensorflow::protobuf::io::FileInputStream(fd); + tensorflow::GraphDef graph_def; + tensorflow::protobuf::TextFormat::Parse(input, &graph_def); delete input; std::fstream output("deeppot.pb", std::ios::out | std::ios::trunc | std::ios::binary); graph_def.SerializeToOstream(&output); diff --git a/source/api_cc/tests/test_deeppot_model_devi.cc b/source/api_cc/tests/test_deeppot_model_devi.cc index fc5c116924..f70b66a9eb 100644 --- a/source/api_cc/tests/test_deeppot_model_devi.cc +++ b/source/api_cc/tests/test_deeppot_model_devi.cc @@ -32,17 +32,17 @@ class TestInferDeepPotModeDevi : public ::testing::Test }; int natoms; - DeepPot dp0; - DeepPot dp1; - DeepPotModelDevi dp_md; + deepmd::DeepPot dp0; + deepmd::DeepPot dp1; + deepmd::DeepPotModelDevi dp_md; void SetUp() override { { std::string file_name = "../../tests/infer/deeppot.pbtxt"; int fd = open(file_name.c_str(), O_RDONLY); - protobuf::io::ZeroCopyInputStream* input = new protobuf::io::FileInputStream(fd); - GraphDef graph_def; - protobuf::TextFormat::Parse(input, &graph_def); + tensorflow::protobuf::io::ZeroCopyInputStream* input = new tensorflow::protobuf::io::FileInputStream(fd); + tensorflow::GraphDef graph_def; + tensorflow::protobuf::TextFormat::Parse(input, &graph_def); delete input; std::fstream output("deeppot.pb", std::ios::out | std::ios::trunc | std::ios::binary); graph_def.SerializeToOstream(&output); @@ -51,9 +51,9 @@ class TestInferDeepPotModeDevi : public ::testing::Test { std::string file_name = "../../tests/infer/deeppot-1.pbtxt"; int fd = open(file_name.c_str(), O_RDONLY); - protobuf::io::ZeroCopyInputStream* input = new protobuf::io::FileInputStream(fd); - GraphDef graph_def; - protobuf::TextFormat::Parse(input, &graph_def); + tensorflow::protobuf::io::ZeroCopyInputStream* input = new tensorflow::protobuf::io::FileInputStream(fd); + tensorflow::GraphDef graph_def; + tensorflow::protobuf::TextFormat::Parse(input, &graph_def); delete input; std::fstream output("deeppot-1.pb", std::ios::out | std::ios::trunc | std::ios::binary); graph_def.SerializeToOstream(&output); diff --git a/source/api_cc/tests/test_deeppot_r.cc b/source/api_cc/tests/test_deeppot_r.cc index 7002a07f5a..e9b1c45c85 100644 --- a/source/api_cc/tests/test_deeppot_r.cc +++ b/source/api_cc/tests/test_deeppot_r.cc @@ -43,20 +43,20 @@ class TestInferDeepPotR : public ::testing::Test double expected_tot_e; std::vectorexpected_tot_v; - DeepPot dp; + deepmd::DeepPot dp; void SetUp() override { std::string file_name = "../../tests/infer/deeppot-r.pbtxt"; int fd = open(file_name.c_str(), O_RDONLY); - protobuf::io::ZeroCopyInputStream* input = new protobuf::io::FileInputStream(fd); - GraphDef graph_def; - protobuf::TextFormat::Parse(input, &graph_def); + tensorflow::protobuf::io::ZeroCopyInputStream* input = new tensorflow::protobuf::io::FileInputStream(fd); + tensorflow::GraphDef graph_def; + tensorflow::protobuf::TextFormat::Parse(input, &graph_def); delete input; std::fstream output("deeppot.pb", std::ios::out | std::ios::trunc | std::ios::binary); graph_def.SerializeToOstream(&output); // check the string by the following commands // string txt; - // protobuf::TextFormat::PrintToString(graph_def, &txt); + // tensorflow::protobuf::TextFormat::PrintToString(graph_def, &txt); dp.init("deeppot.pb"); @@ -104,11 +104,11 @@ TEST_F(TestInferDeepPotR, cpu_build_nlist_numfv) { class MyModel : public EnergyModelTest { - DeepPot & mydp; + deepmd::DeepPot & mydp; const std::vector & atype; public: MyModel( - DeepPot & dp_, + deepmd::DeepPot & dp_, const std::vector & atype_ ) : mydp(dp_), atype(atype_) {}; virtual void compute ( @@ -426,14 +426,14 @@ class TestInferDeepPotRNoPbc : public ::testing::Test double expected_tot_e; std::vectorexpected_tot_v; - DeepPot dp; + deepmd::DeepPot dp; void SetUp() override { std::string file_name = "../../tests/infer/deeppot-r.pbtxt"; int fd = open(file_name.c_str(), O_RDONLY); - protobuf::io::ZeroCopyInputStream* input = new protobuf::io::FileInputStream(fd); - GraphDef graph_def; - protobuf::TextFormat::Parse(input, &graph_def); + tensorflow::protobuf::io::ZeroCopyInputStream* input = new tensorflow::protobuf::io::FileInputStream(fd); + tensorflow::GraphDef graph_def; + tensorflow::protobuf::TextFormat::Parse(input, &graph_def); delete input; std::fstream output("deeppot.pb", std::ios::out | std::ios::trunc | std::ios::binary); graph_def.SerializeToOstream(&output); diff --git a/source/api_cc/tests/test_dipolecharge.cc b/source/api_cc/tests/test_dipolecharge.cc index 87fd2f4a78..9ce16b9442 100644 --- a/source/api_cc/tests/test_dipolecharge.cc +++ b/source/api_cc/tests/test_dipolecharge.cc @@ -53,22 +53,22 @@ class TestDipoleCharge : public ::testing::Test double expected_tot_e; std::vectorexpected_tot_v; - DeepTensor dp; - DipoleChargeModifier dm; + deepmd::DeepTensor dp; + deepmd::DipoleChargeModifier dm; void SetUp() override { std::string file_name = "../../tests/infer/dipolecharge_e.pbtxt"; int fd = open(file_name.c_str(), O_RDONLY); - protobuf::io::ZeroCopyInputStream* input = new protobuf::io::FileInputStream(fd); - GraphDef graph_def; - protobuf::TextFormat::Parse(input, &graph_def); + tensorflow::protobuf::io::ZeroCopyInputStream* input = new tensorflow::protobuf::io::FileInputStream(fd); + tensorflow::GraphDef graph_def; + tensorflow::protobuf::TextFormat::Parse(input, &graph_def); delete input; - string model = "dipolecharge_e.pb"; + std::string model = "dipolecharge_e.pb"; std::fstream output(model.c_str(), std::ios::out | std::ios::trunc | std::ios::binary); graph_def.SerializeToOstream(&output); // check the string by the following commands // string txt; - // protobuf::TextFormat::PrintToString(graph_def, &txt); + // tensorflow::protobuf::TextFormat::PrintToString(graph_def, &txt); // dp.init("dipolecharge_d.pb"); // dm.init("dipolecharge_d.pb"); @@ -128,12 +128,12 @@ TEST_F(TestDipoleCharge, cpu_lmp_nlist) std::vector sel_types = dp.sel_types(); std::vector sel_fwd, sel_bwd; int sel_nghost; - select_by_type(sel_fwd, sel_bwd, sel_nghost, coord_cpy, atype_cpy, nghost, sel_types); + deepmd::select_by_type(sel_fwd, sel_bwd, sel_nghost, coord_cpy, atype_cpy, nghost, sel_types); int sel_nall = sel_bwd.size(); int sel_nloc = sel_nall - sel_nghost; std::vector sel_atype(sel_bwd.size()); - select_map(sel_atype, atype, sel_fwd, 1); - AtomMap nnp_map(sel_atype.begin(), sel_atype.begin() + sel_nloc); + deepmd::select_map(sel_atype, atype, sel_fwd, 1); + deepmd::AtomMap nnp_map(sel_atype.begin(), sel_atype.begin() + sel_nloc); const std::vector & sort_fwd_map(nnp_map.get_fwd_map()); // // add coords diff --git a/source/ipi/driver.cc b/source/ipi/driver.cc index 605a26a1e0..2732b9b990 100644 --- a/source/ipi/driver.cc +++ b/source/ipi/driver.cc @@ -75,14 +75,14 @@ int main(int argc, char * argv[]) inet = 0; } int port = jdata["port"]; - string host_str = jdata["host"]; + std::string host_str = jdata["host"]; const char * host = host_str.c_str(); - string graph_file = jdata["graph_file"]; - string coord_file = jdata["coord_file"]; - std::map name_type_map = jdata["atom_type"]; + std::string graph_file = jdata["graph_file"]; + std::string coord_file = jdata["coord_file"]; + std::map name_type_map = jdata["atom_type"]; bool b_verb = jdata["verbose"]; - std::vector atom_name; + std::vector atom_name; { std::vector > posi; std::vector > velo; @@ -91,7 +91,7 @@ int main(int argc, char * argv[]) } Convert cvt (atom_name, name_type_map); - DeepPot nnp_inter (graph_file); + deepmd::DeepPot nnp_inter (graph_file); enum { _MSGLEN = 12 }; int MSGLEN = _MSGLEN; @@ -126,7 +126,7 @@ int main(int argc, char * argv[]) while (true) { readbuffer_ (&socket, header, MSGLEN); - string header_str (trimwhitespace(header)); + std::string header_str (trimwhitespace(header)); if (b_verb) std::cout << "# get header " << header_str << std::endl; if (header_str == "STATUS"){ diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index 5d89ff8dad..2a5826aa84 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -299,13 +299,13 @@ void FixDPLR::pre_force(int vflag) } vector sel_fwd, sel_bwd; int sel_nghost; - select_by_type(sel_fwd, sel_bwd, sel_nghost, dcoord, dtype, nghost, sel_type); + deepmd::select_by_type(sel_fwd, sel_bwd, sel_nghost, dcoord, dtype, nghost, sel_type); int sel_nall = sel_bwd.size(); int sel_nloc = sel_nall - sel_nghost; vector sel_type(sel_bwd.size()); - select_map(sel_type, dtype, sel_fwd, 1); + deepmd::select_map(sel_type, dtype, sel_fwd, 1); - AtomMap atom_map(sel_type.begin(), sel_type.begin() + sel_nloc); + deepmd::AtomMap atom_map(sel_type.begin(), sel_type.begin() + sel_nloc); const vector & sort_fwd_map(atom_map.get_fwd_map()); vector > valid_pairs; diff --git a/source/lmp/fix_dplr.h b/source/lmp/fix_dplr.h index aa8c95dd09..6de055529b 100644 --- a/source/lmp/fix_dplr.h +++ b/source/lmp/fix_dplr.h @@ -36,8 +36,8 @@ namespace LAMMPS_NS { double compute_vector(int); private: PairDeepMD * pair_deepmd; - DeepTensor dpt; - DipoleChargeModifier dtm; + deepmd::DeepTensor dpt; + deepmd::DipoleChargeModifier dtm; std::string model; int ntypes; std::vector sel_type; diff --git a/source/lmp/pair_deepmd.cpp b/source/lmp/pair_deepmd.cpp index 859c7be34e..593e6a4246 100644 --- a/source/lmp/pair_deepmd.cpp +++ b/source/lmp/pair_deepmd.cpp @@ -111,7 +111,7 @@ std::string PairDeepMD::get_file_content(const std::string & model) { int nchar = 0; std::string file_content; if (myrank == root) { - checkStatus (ReadFileToString(Env::Default(), model, &file_content)); + deepmd::check_status(tensorflow::ReadFileToString(tensorflow::Env::Default(), model, &file_content)); nchar = file_content.size(); } MPI_Bcast(&nchar, 1, MPI_INT, root, MPI_COMM_WORLD); diff --git a/source/lmp/pair_deepmd.h.in b/source/lmp/pair_deepmd.h.in index 25d950c948..a54f45c2f3 100644 --- a/source/lmp/pair_deepmd.h.in +++ b/source/lmp/pair_deepmd.h.in @@ -71,8 +71,8 @@ class PairDeepMD : public Pair { double **scale; private: - DeepPot deep_pot; - DeepPotModelDevi deep_pot_model_devi; + deepmd::DeepPot deep_pot; + deepmd::DeepPotModelDevi deep_pot_model_devi; unsigned numb_models; double cutoff; int numb_types; From 3017ab7c7c2ec305ec7e97f64d7a188c0838e53e Mon Sep 17 00:00:00 2001 From: Han Wang Date: Wed, 17 Mar 2021 08:46:48 +0800 Subject: [PATCH 09/23] add deepmd namespace for lib --- source/lib/include/ComputeDescriptor.h | 6 +- source/lib/include/Stopwatch.h | 54 -------------- source/lib/include/coord.h | 8 +- source/lib/include/env_mat.h | 61 ++++++++------- source/lib/include/ewald.h | 5 +- source/lib/include/fmt_nlist.h | 33 +++------ source/lib/include/gelu.h | 4 + source/lib/include/map_aparam.h | 3 + source/lib/include/neighbor_list.h | 28 ++++--- source/lib/include/pair_tab.h | 3 + source/lib/include/prod_env_mat.h | 4 + source/lib/include/prod_force.h | 6 +- source/lib/include/prod_force_grad.h | 3 + source/lib/include/prod_virial.h | 4 + source/lib/include/prod_virial_grad.h | 3 + source/lib/include/region.h | 4 + source/lib/include/soft_min_switch.h | 4 + source/lib/include/soft_min_switch_force.h | 4 + .../lib/include/soft_min_switch_force_grad.h | 4 + source/lib/include/soft_min_switch_virial.h | 3 + .../lib/include/soft_min_switch_virial_grad.h | 3 + source/lib/include/switcher.h | 28 +------ source/lib/src/coord.cc | 16 +++- source/lib/src/env_mat.cc | 32 +++++--- source/lib/src/ewald.cc | 5 ++ source/lib/src/fmt_nlist.cc | 40 ++++++++-- source/lib/src/gelu.cc | 18 ++--- source/lib/src/map_aparam.cc | 6 +- source/lib/src/neighbor_list.cc | 8 +- source/lib/src/pair_tab.cc | 7 +- source/lib/src/prod_env_mat.cc | 26 +++++-- source/lib/src/prod_force.cc | 24 ++++-- source/lib/src/prod_force_grad.cc | 24 ++++-- source/lib/src/prod_virial.cc | 24 ++++-- source/lib/src/prod_virial_grad.cc | 24 ++++-- source/lib/src/region.cc | 36 ++++++--- source/lib/src/soft_min_switch.cc | 8 +- source/lib/src/soft_min_switch_force.cc | 6 +- source/lib/src/soft_min_switch_force_grad.cc | 6 +- source/lib/src/soft_min_switch_virial.cc | 6 +- source/lib/src/soft_min_switch_virial_grad.cc | 6 +- source/lib/tests/test_coord.cc | 10 +-- source/lib/tests/test_env_mat_a.cc | 26 +++---- source/lib/tests/test_env_mat_r.cc | 18 ++--- source/lib/tests/test_ewald.cc | 4 +- source/lib/tests/test_fmt_nlist.cc | 4 +- source/lib/tests/test_gelu.cc | 8 +- source/lib/tests/test_map_aparam.cc | 2 +- source/lib/tests/test_neighbor_list.cc | 4 +- source/lib/tests/test_pair_tab.cc | 74 +++++++++---------- source/lib/tests/test_prod_force_a.cc | 6 +- source/lib/tests/test_prod_force_grad_a.cc | 4 +- source/lib/tests/test_prod_force_grad_r.cc | 4 +- source/lib/tests/test_prod_force_r.cc | 4 +- source/lib/tests/test_prod_virial_a.cc | 6 +- source/lib/tests/test_prod_virial_grad_a.cc | 4 +- source/lib/tests/test_prod_virial_grad_r.cc | 4 +- source/lib/tests/test_prod_virial_r.cc | 6 +- source/lib/tests/test_simulation_region.cc | 2 +- source/lib/tests/test_soft_min_switch.cc | 14 ++-- .../lib/tests/test_soft_min_switch_force.cc | 6 +- .../tests/test_soft_min_switch_force_grad.cc | 6 +- .../lib/tests/test_soft_min_switch_virial.cc | 6 +- .../tests/test_soft_min_switch_virial_grad.cc | 6 +- source/lmp/fix_dplr.cpp | 4 +- source/lmp/pair_deepmd.cpp | 2 +- source/lmp/pair_deepmd.h.in | 13 ---- source/lmp/pppm_dplr.cpp | 13 ---- source/lmp/pppm_dplr.h | 13 ---- source/op/ewald_recp.cc | 4 +- source/op/gelu_multi_device.cc | 8 +- source/op/map_aparam.cc | 2 +- source/op/pair_tab.cc | 2 +- source/op/prod_env_mat_multi_device.cc | 20 ++--- source/op/prod_force_se_a.cc | 15 ++-- source/op/prod_force_se_a_grad.cc | 13 ++-- source/op/prod_force_se_r.cc | 15 ++-- source/op/prod_force_se_r_grad.cc | 2 +- source/op/prod_virial_se_a.cc | 19 ++--- source/op/prod_virial_se_a_grad.cc | 15 ++-- source/op/prod_virial_se_r.cc | 2 +- source/op/prod_virial_se_r_grad.cc | 2 +- source/op/soft_min.cc | 2 +- source/op/soft_min_force.cc | 2 +- source/op/soft_min_force_grad.cc | 2 +- source/op/soft_min_virial.cc | 2 +- source/op/soft_min_virial_grad.cc | 2 +- 87 files changed, 547 insertions(+), 452 deletions(-) delete mode 100644 source/lib/include/Stopwatch.h diff --git a/source/lib/include/ComputeDescriptor.h b/source/lib/include/ComputeDescriptor.h index aaac53b657..7d4d6e0c3a 100644 --- a/source/lib/include/ComputeDescriptor.h +++ b/source/lib/include/ComputeDescriptor.h @@ -826,7 +826,7 @@ void compute_descriptor_se_a_extf (std::vector & descrpt_a, double inr4 = inr2 * inr2; double inr3 = inr4 * nr; double sw, dsw; - spline5_switch(sw, dsw, nr, rmin, rmax); + deepmd::spline5_switch(sw, dsw, nr, rmin, rmax); int idx_deriv = nei_iter * 4 * 3; // 4 components time 3 directions int idx_value = nei_iter * 4; // 4 components // projections @@ -935,7 +935,7 @@ void compute_descriptor_se_a_ef_para (std::vector & descrpt_a, double inr4 = inr2 * inr2; double inr3 = inr4 * nr; double sw, dsw; - spline5_switch(sw, dsw, nr, rmin, rmax); + deepmd::spline5_switch(sw, dsw, nr, rmin, rmax); int idx_deriv = nei_iter * 4 * 3; // 4 components time 3 directions int idx_value = nei_iter * 4; // 4 components // projections @@ -1043,7 +1043,7 @@ void compute_descriptor_se_a_ef_vert (std::vector & descrpt_a, double inr4 = inr2 * inr2; double inr3 = inr4 * nr; double sw, dsw; - spline5_switch(sw, dsw, nr, rmin, rmax); + deepmd::spline5_switch(sw, dsw, nr, rmin, rmax); int idx_deriv = nei_iter * 4 * 3; // 4 components time 3 directions int idx_value = nei_iter * 4; // 4 components // projections diff --git a/source/lib/include/Stopwatch.h b/source/lib/include/Stopwatch.h deleted file mode 100644 index 0abd73bcf1..0000000000 --- a/source/lib/include/Stopwatch.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef __Stopwatch_h_wanghan__ -#define __Stopwatch_h_wanghan__ - -#include -#include -#include - -class Stopwatch -{ -public: - Stopwatch(): HZi (1./HZ) {}; - - void start(); - void stop(); - double system() const; - double user() const; - double real() const; - - static double resolution() {return 1./HZ;}; -private: - struct tms tic, toc; - long r1, r0; - double HZi; -}; - -inline double Stopwatch::user () const -{ - return (double)(toc.tms_utime - tic.tms_utime) * HZi; -} - -inline double Stopwatch::system () const -{ - return (double)(toc.tms_stime - tic.tms_stime) * HZi; -} - -inline double Stopwatch::real () const -{ - return (double)(r1 - r0) * HZi; -} - -inline void Stopwatch::stop () -{ - r1 = times (&toc); -} - -inline void Stopwatch::start() -{ - r0 = times (&tic); -} - - -#endif -// end of file - diff --git a/source/lib/include/coord.h b/source/lib/include/coord.h index dc81efc1b2..0da8eedd23 100644 --- a/source/lib/include/coord.h +++ b/source/lib/include/coord.h @@ -2,13 +2,15 @@ #include "region.h" +namespace deepmd{ + // normalize coords template void normalize_coord_cpu( FPTYPE * coord, const int natom, - const Region & region); + const deepmd::Region & region); // copy coordinates // outputs: @@ -32,4 +34,6 @@ copy_coord_cpu( const int & nloc, const int & mem_nall, const float & rcut, - const Region & region); + const deepmd::Region & region); + +} diff --git a/source/lib/include/env_mat.h b/source/lib/include/env_mat.h index 1217051f70..b94e683027 100644 --- a/source/lib/include/env_mat.h +++ b/source/lib/include/env_mat.h @@ -1,6 +1,41 @@ #pragma once #include + +namespace deepmd{ + +template +void env_mat_a_cpu ( + std::vector & descrpt_a, + std::vector & descrpt_a_deriv, + std::vector & rij_a, + const std::vector & posi, + const std::vector & type, + const int & i_idx, + const std::vector & fmt_nlist, + const std::vector & sec, + const float & rmin, + const float & rmax) ; + +template +void env_mat_r_cpu ( + std::vector & descrpt_a, + std::vector & descrpt_a_deriv, + std::vector & rij_a, + const std::vector & posi, + const std::vector & type, + const int & i_idx, + const std::vector & fmt_nlist_a, + const std::vector & sec_a, + const float & rmin, + const float & rmax); + +} + +//////////////////////////////////////////////////////// +// legacy code +//////////////////////////////////////////////////////// + #include "SimulationRegion.h" void env_mat_a ( @@ -18,19 +53,6 @@ void env_mat_a ( const double & rmin, const double & rmax); -template -void env_mat_a_cpu ( - std::vector & descrpt_a, - std::vector & descrpt_a_deriv, - std::vector & rij_a, - const std::vector & posi, - const std::vector & type, - const int & i_idx, - const std::vector & fmt_nlist, - const std::vector & sec, - const float & rmin, - const float & rmax) ; - void env_mat_r ( std::vector & descrpt_r, std::vector & descrpt_r_deriv, @@ -46,16 +68,3 @@ void env_mat_r ( const double & rmin, const double & rmax); -template -void env_mat_r_cpu ( - std::vector & descrpt_a, - std::vector & descrpt_a_deriv, - std::vector & rij_a, - const std::vector & posi, - const std::vector & type, - const int & i_idx, - const std::vector & fmt_nlist_a, - const std::vector & sec_a, - const float & rmin, - const float & rmax); - diff --git a/source/lib/include/ewald.h b/source/lib/include/ewald.h index 10d400e62a..bce151365a 100644 --- a/source/lib/include/ewald.h +++ b/source/lib/include/ewald.h @@ -7,6 +7,8 @@ #include "utilities.h" #include "region.h" +namespace deepmd{ + // 8.988e9 / pc.electron_volt / pc.angstrom * (1.602e-19)**2 const double ElectrostaticConvertion = 14.39964535475696995031; @@ -29,6 +31,7 @@ ewald_recp( std::vector & virial, const std::vector& coord, const std::vector& charge, - const Region& region, + const deepmd::Region& region, const EwaldParameters& param); +} diff --git a/source/lib/include/fmt_nlist.h b/source/lib/include/fmt_nlist.h index 3b8a30eefe..13c9082240 100644 --- a/source/lib/include/fmt_nlist.h +++ b/source/lib/include/fmt_nlist.h @@ -2,7 +2,8 @@ #include #include "neighbor_list.h" -#include "SimulationRegion.h" + +namespace deepmd{ template void format_nlist_cpu( @@ -15,6 +16,15 @@ void format_nlist_cpu( const float rcut, const std::vector sec); +} + + +//////////////////////////////////////////////////////// +// legacy code +//////////////////////////////////////////////////////// + +#include "SimulationRegion.h" + // return: -1 OK // > 0 the type of unsuccessful neighbor list int format_nlist_i_fill_a ( @@ -45,24 +55,3 @@ int format_nlist_i_cpu ( -struct NeighborInfo -{ - int type; - double dist; - int index; - NeighborInfo () - : type (0), dist(0), index(0) - { - } - NeighborInfo (int tt, double dd, int ii) - : type (tt), dist(dd), index(ii) - { - } - bool operator < (const NeighborInfo & b) const - { - return (type < b.type || - (type == b.type && - (dist < b.dist || - (dist == b.dist && index < b.index) ) ) ); - } -}; diff --git a/source/lib/include/gelu.h b/source/lib/include/gelu.h index edf1729c4f..20f2d96de5 100644 --- a/source/lib/include/gelu.h +++ b/source/lib/include/gelu.h @@ -1,5 +1,7 @@ #pragma once +namespace deepmd{ + template void gelu_cpu( FPTYPE * out, @@ -43,3 +45,5 @@ void gelu_grad_grad_gpu_cuda( const FPTYPE * dy_2, const int size); #endif // GOOGLE_CUDA + +} diff --git a/source/lib/include/map_aparam.h b/source/lib/include/map_aparam.h index b209d8314a..3ee3d1dc12 100644 --- a/source/lib/include/map_aparam.h +++ b/source/lib/include/map_aparam.h @@ -1,5 +1,7 @@ #pragma once +namespace deepmd{ + template void map_aparam_cpu ( FPTYPE * output, @@ -10,3 +12,4 @@ void map_aparam_cpu ( const int & numb_aparam ); +} diff --git a/source/lib/include/neighbor_list.h b/source/lib/include/neighbor_list.h index ef4013c7d7..ddcf64846c 100644 --- a/source/lib/include/neighbor_list.h +++ b/source/lib/include/neighbor_list.h @@ -9,6 +9,8 @@ #include "utilities.h" #include "SimulationRegion.h" +namespace deepmd{ + // format of the input neighbor list struct InputNlist { @@ -61,6 +63,22 @@ build_nlist_cpu( const int & mem_size, const float & rcut); +#if GOOGLE_CUDA +void convert_nlist_gpu_cuda( + InputNlist & gpu_nlist, + InputNlist & cpu_nlist, + int* & gpu_memory, + const int & max_nbor_size); + +void free_nlist_gpu_cuda(InputNlist & gpu_nlist); +#endif // GOOGLE_CUDA + +} // namespace deepmd + + +//////////////////////////////////////////////////////// +// legacy code +//////////////////////////////////////////////////////// // build nlist by an extended grid void @@ -121,13 +139,3 @@ copy_coord (std::vector & out_c, const std::vector & in_t, const double & rc, const SimulationRegion & region); - -#if GOOGLE_CUDA -void convert_nlist_gpu_cuda( - InputNlist & gpu_nlist, - InputNlist & cpu_nlist, - int* & gpu_memory, - const int & max_nbor_size); - -void free_nlist_gpu_cuda(InputNlist & gpu_nlist); -#endif // GOOGLE_CUDA diff --git a/source/lib/include/pair_tab.h b/source/lib/include/pair_tab.h index 9176b43c0c..db05b68df2 100644 --- a/source/lib/include/pair_tab.h +++ b/source/lib/include/pair_tab.h @@ -1,5 +1,7 @@ #pragma once +namespace deepmd{ + template void pair_tab_cpu( FPTYPE * energy, @@ -16,3 +18,4 @@ void pair_tab_cpu( const std::vector & sel_r ); +} diff --git a/source/lib/include/prod_env_mat.h b/source/lib/include/prod_env_mat.h index 6b866c5590..0789bf75a6 100644 --- a/source/lib/include/prod_env_mat.h +++ b/source/lib/include/prod_env_mat.h @@ -3,6 +3,8 @@ #include "device.h" #include "neighbor_list.h" +namespace deepmd{ + template void prod_env_mat_a_cpu( FPTYPE * em, @@ -89,3 +91,5 @@ void env_mat_nbor_update( const int size); #endif // GOOGLE_CUDA +} + diff --git a/source/lib/include/prod_force.h b/source/lib/include/prod_force.h index 9236f7802f..1667edb61c 100644 --- a/source/lib/include/prod_force.h +++ b/source/lib/include/prod_force.h @@ -1,5 +1,7 @@ #pragma once +namespace deepmd{ + template void prod_force_a_cpu( FPTYPE * force, @@ -40,4 +42,6 @@ void prod_force_r_gpu_cuda( const int nloc, const int nall, const int nnei); -#endif // GOOGLE_CUDA \ No newline at end of file +#endif // GOOGLE_CUDA + +} diff --git a/source/lib/include/prod_force_grad.h b/source/lib/include/prod_force_grad.h index d191fe76fa..b4b95f2ac3 100644 --- a/source/lib/include/prod_force_grad.h +++ b/source/lib/include/prod_force_grad.h @@ -1,5 +1,7 @@ #pragma once +namespace deepmd{ + template void prod_force_grad_a_cpu( FPTYPE * grad_net, @@ -18,3 +20,4 @@ void prod_force_grad_r_cpu( const int nloc, const int nnei); +} diff --git a/source/lib/include/prod_virial.h b/source/lib/include/prod_virial.h index 5a5c9ad996..6655059e12 100644 --- a/source/lib/include/prod_virial.h +++ b/source/lib/include/prod_virial.h @@ -1,5 +1,7 @@ #pragma once +namespace deepmd{ + template void prod_virial_a_cpu( FPTYPE * virial, @@ -49,3 +51,5 @@ void prod_virial_r_gpu_cuda( const int nall, const int nnei); #endif // GOOGLE_CUDA + +} //namespace deepmd diff --git a/source/lib/include/prod_virial_grad.h b/source/lib/include/prod_virial_grad.h index 2ba8c01a44..ab0f84ffec 100644 --- a/source/lib/include/prod_virial_grad.h +++ b/source/lib/include/prod_virial_grad.h @@ -1,5 +1,7 @@ #pragma once +namespace deepmd{ + template void prod_virial_grad_a_cpu( FPTYPE * grad_net, @@ -20,3 +22,4 @@ void prod_virial_grad_r_cpu( const int nloc, const int nnei); +} diff --git a/source/lib/include/region.h b/source/lib/include/region.h index 049ef882cc..fd24bd6b4d 100644 --- a/source/lib/include/region.h +++ b/source/lib/include/region.h @@ -1,5 +1,7 @@ #pragma once +namespace deepmd{ + template struct Region { @@ -34,3 +36,5 @@ convert_to_phys_cpu( const Region & region, const FPTYPE * ri); +} + diff --git a/source/lib/include/soft_min_switch.h b/source/lib/include/soft_min_switch.h index 9d0b20a1c5..4b382cde93 100644 --- a/source/lib/include/soft_min_switch.h +++ b/source/lib/include/soft_min_switch.h @@ -1,5 +1,7 @@ #pragma once +namespace deepmd{ + template void soft_min_switch_cpu( FPTYPE * sw_value, @@ -11,3 +13,5 @@ void soft_min_switch_cpu( const FPTYPE & alpha, const FPTYPE & rmin, const FPTYPE & rmax); + +} diff --git a/source/lib/include/soft_min_switch_force.h b/source/lib/include/soft_min_switch_force.h index dfcb47ca52..854458a3c7 100644 --- a/source/lib/include/soft_min_switch_force.h +++ b/source/lib/include/soft_min_switch_force.h @@ -1,5 +1,7 @@ #pragma once +namespace deepmd{ + template void soft_min_switch_force_cpu( FPTYPE * force, @@ -9,3 +11,5 @@ void soft_min_switch_force_cpu( const int nloc, const int nall, const int nnei); + +} diff --git a/source/lib/include/soft_min_switch_force_grad.h b/source/lib/include/soft_min_switch_force_grad.h index 329ca6e66d..afe4c3b36e 100644 --- a/source/lib/include/soft_min_switch_force_grad.h +++ b/source/lib/include/soft_min_switch_force_grad.h @@ -1,5 +1,7 @@ #pragma once +namespace deepmd{ + template void soft_min_switch_force_grad_cpu( FPTYPE * grad_net, @@ -8,3 +10,5 @@ void soft_min_switch_force_grad_cpu( const int * nlist, const int nloc, const int nnei); + +} diff --git a/source/lib/include/soft_min_switch_virial.h b/source/lib/include/soft_min_switch_virial.h index 8e2dd1de04..4833eec262 100644 --- a/source/lib/include/soft_min_switch_virial.h +++ b/source/lib/include/soft_min_switch_virial.h @@ -1,5 +1,7 @@ #pragma once +namespace deepmd{ + template void soft_min_switch_virial_cpu( FPTYPE * virial, @@ -12,3 +14,4 @@ void soft_min_switch_virial_cpu( const int nall, const int nnei); +} diff --git a/source/lib/include/soft_min_switch_virial_grad.h b/source/lib/include/soft_min_switch_virial_grad.h index 4e4ed1514e..1b1ec0da44 100644 --- a/source/lib/include/soft_min_switch_virial_grad.h +++ b/source/lib/include/soft_min_switch_virial_grad.h @@ -1,5 +1,7 @@ #pragma once +namespace deepmd{ + template void soft_min_switch_virial_grad_cpu( FPTYPE * grad_net, @@ -10,3 +12,4 @@ void soft_min_switch_virial_grad_cpu( const int nloc, const int nnei); +} diff --git a/source/lib/include/switcher.h b/source/lib/include/switcher.h index 671c8be137..606b3c3196 100644 --- a/source/lib/include/switcher.h +++ b/source/lib/include/switcher.h @@ -1,5 +1,7 @@ #pragma once +namespace deepmd{ + inline double cos_switch (const double & xx, const double & rmin, @@ -64,30 +66,6 @@ spline3_switch (double & vv, } } -// template -// inline void -// spline5_switch (TYPE & vv, -// TYPE & dd, -// const TYPE & xx, -// const TYPE & rmin, -// const TYPE & rmax) -// { -// if (xx < rmin) { -// dd = 0; -// vv = 1; -// } -// else if (xx < rmax) { -// double uu = (xx - rmin) / (rmax - rmin) ; -// double du = 1. / (rmax - rmin) ; -// vv = uu*uu*uu * (-6 * uu*uu + 15 * uu - 10) + 1; -// dd = ( 3 * uu*uu * (-6 * uu*uu + 15 * uu - 10) + uu*uu*uu * (-12 * uu + 15) ) * du; -// } -// else { -// dd = 0; -// vv = 0; -// } -// } - template inline void spline5_switch ( @@ -112,3 +90,5 @@ spline5_switch ( vv = 0; } } + +} diff --git a/source/lib/src/coord.cc b/source/lib/src/coord.cc index fb57b2c403..81c44f4925 100644 --- a/source/lib/src/coord.cc +++ b/source/lib/src/coord.cc @@ -3,9 +3,12 @@ #include "SimulationRegion.h" #include +using namespace deepmd; + // normalize coords template void +deepmd:: normalize_coord_cpu( FPTYPE * coord, const int natom, @@ -25,6 +28,7 @@ normalize_coord_cpu( template int +deepmd:: copy_coord_cpu( FPTYPE * out_c, int * out_t, @@ -67,20 +71,23 @@ copy_coord_cpu( template void +deepmd:: normalize_coord_cpu( double * coord, const int natom, - const Region & region); + const deepmd::Region & region); template void +deepmd:: normalize_coord_cpu( float * coord, const int natom, - const Region & region); + const deepmd::Region & region); template int +deepmd:: copy_coord_cpu( double * out_c, int * out_t, @@ -91,10 +98,11 @@ copy_coord_cpu( const int & nloc, const int & mem_nall, const float & rcut, - const Region & region); + const deepmd::Region & region); template int +deepmd:: copy_coord_cpu( float * out_c, int * out_t, @@ -105,7 +113,7 @@ copy_coord_cpu( const int & nloc, const int & mem_nall, const float & rcut, - const Region & region); + const deepmd::Region & region); diff --git a/source/lib/src/env_mat.cc b/source/lib/src/env_mat.cc index c9cadb4b0d..52398a17a8 100644 --- a/source/lib/src/env_mat.cc +++ b/source/lib/src/env_mat.cc @@ -57,7 +57,7 @@ void env_mat_a ( double inr4 = inr2 * inr2; double inr3 = inr4 * nr; double sw, dsw; - spline5_switch(sw, dsw, nr, rmin, rmax); + deepmd::spline5_switch(sw, dsw, nr, rmin, rmax); int idx_deriv = nei_iter * 4 * 3; // 4 components time 3 directions int idx_value = nei_iter * 4; // 4 components // 4 value components @@ -92,7 +92,9 @@ void env_mat_a ( template -void env_mat_a_cpu ( +void +deepmd:: +env_mat_a_cpu ( std::vector & descrpt_a, std::vector & descrpt_a_deriv, std::vector & rij_a, @@ -134,7 +136,7 @@ void env_mat_a_cpu ( FPTYPE inr4 = inr2 * inr2; FPTYPE inr3 = inr4 * nr; FPTYPE sw, dsw; - spline5_switch(sw, dsw, nr, rmin, rmax); + deepmd::spline5_switch(sw, dsw, nr, rmin, rmax); int idx_deriv = nei_iter * 4 * 3; // 4 components time 3 directions int idx_value = nei_iter * 4; // 4 components // 4 value components @@ -222,7 +224,7 @@ void env_mat_r ( double inr4 = inr2 * inr2; double inr3 = inr4 * nr; double sw, dsw; - spline5_switch(sw, dsw, nr, rmin, rmax); + deepmd::spline5_switch(sw, dsw, nr, rmin, rmax); int idx_deriv = nei_iter * 3; // 1 components time 3 directions int idx_value = nei_iter; // 1 components // value components @@ -238,7 +240,9 @@ void env_mat_r ( } template -void env_mat_r_cpu ( +void +deepmd:: +env_mat_r_cpu ( std::vector & descrpt_a, std::vector & descrpt_a_deriv, std::vector & rij_a, @@ -281,7 +285,7 @@ void env_mat_r_cpu ( FPTYPE inr4 = inr2 * inr2; FPTYPE inr3 = inr4 * nr; FPTYPE sw, dsw; - spline5_switch(sw, dsw, nr, rmin, rmax); + deepmd::spline5_switch(sw, dsw, nr, rmin, rmax); int idx_deriv = nei_iter * 3; // 1 components time 3 directions int idx_value = nei_iter; // 1 components // 4 value components @@ -298,7 +302,9 @@ void env_mat_r_cpu ( template -void env_mat_a_cpu ( +void +deepmd:: +env_mat_a_cpu ( std::vector & descrpt_a, std::vector & descrpt_a_deriv, std::vector & rij_a, @@ -312,7 +318,9 @@ void env_mat_a_cpu ( template -void env_mat_a_cpu ( +void +deepmd:: +env_mat_a_cpu ( std::vector & descrpt_a, std::vector & descrpt_a_deriv, std::vector & rij_a, @@ -326,7 +334,9 @@ void env_mat_a_cpu ( template -void env_mat_r_cpu ( +void +deepmd:: +env_mat_r_cpu ( std::vector & descrpt_r, std::vector & descrpt_r_deriv, std::vector & rij_r, @@ -340,7 +350,9 @@ void env_mat_r_cpu ( template -void env_mat_r_cpu ( +void +deepmd:: +env_mat_r_cpu ( std::vector & descrpt_r, std::vector & descrpt_r_deriv, std::vector & rij_r, diff --git a/source/lib/src/ewald.cc b/source/lib/src/ewald.cc index b12a4757e7..5942f6fedc 100644 --- a/source/lib/src/ewald.cc +++ b/source/lib/src/ewald.cc @@ -1,6 +1,8 @@ #include "ewald.h" #include "SimulationRegion.h" +using namespace deepmd; + template VALUETYPE dir_err_esti(const VALUETYPE & test_q, @@ -86,6 +88,7 @@ cmpt_k(std::vector & KK, // inputs: coordinates charges region template void +deepmd:: ewald_recp( VALUETYPE & ener, std::vector & force, @@ -266,6 +269,7 @@ ewald_recp( template void +deepmd:: ewald_recp( float & ener, std::vector & force, @@ -277,6 +281,7 @@ ewald_recp( template void +deepmd:: ewald_recp( double & ener, std::vector & force, diff --git a/source/lib/src/fmt_nlist.cc b/source/lib/src/fmt_nlist.cc index 0d9b921b1b..2c577c2f05 100644 --- a/source/lib/src/fmt_nlist.cc +++ b/source/lib/src/fmt_nlist.cc @@ -5,6 +5,30 @@ #include "SimulationRegion.h" #include +using namespace deepmd; + +struct NeighborInfo +{ + int type; + double dist; + int index; + NeighborInfo () + : type (0), dist(0), index(0) + { + } + NeighborInfo (int tt, double dd, int ii) + : type (tt), dist(dd), index(ii) + { + } + bool operator < (const NeighborInfo & b) const + { + return (type < b.type || + (type == b.type && + (dist < b.dist || + (dist == b.dist && index < b.index) ) ) ); + } +}; + int format_nlist_i_fill_a ( std::vector & fmt_nei_idx_a, std::vector & fmt_nei_idx_r, @@ -123,7 +147,9 @@ int format_nlist_i_cpu ( } template -void format_nlist_cpu ( +void +deepmd:: +format_nlist_cpu ( int * nlist, const InputNlist & in_nlist, const FPTYPE * coord, @@ -187,9 +213,11 @@ int format_nlist_i_cpu ( const std::vector & sec_a); template -void format_nlist_cpu ( +void +deepmd:: +format_nlist_cpu ( int * nlist, - const InputNlist & in_nlist, + const deepmd::InputNlist & in_nlist, const double * coord, const int * type, const int nloc, @@ -199,9 +227,11 @@ void format_nlist_cpu ( template -void format_nlist_cpu ( +void +deepmd:: +format_nlist_cpu ( int * nlist, - const InputNlist & in_nlist, + const deepmd::InputNlist & in_nlist, const float * coord, const int * type, const int nloc, diff --git a/source/lib/src/gelu.cc b/source/lib/src/gelu.cc index b887df89de..c554da0578 100644 --- a/source/lib/src/gelu.cc +++ b/source/lib/src/gelu.cc @@ -3,7 +3,7 @@ #include "device.h" template -void gelu_cpu( +void deepmd::gelu_cpu( FPTYPE * out, const FPTYPE * xx, const int size) @@ -14,7 +14,7 @@ void gelu_cpu( } template -void gelu_grad_cpu( +void deepmd::gelu_grad_cpu( FPTYPE * out, const FPTYPE * xx, const FPTYPE * dy, @@ -27,7 +27,7 @@ void gelu_grad_cpu( } template -void gelu_grad_grad_cpu( +void deepmd::gelu_grad_grad_cpu( FPTYPE * out, const FPTYPE * xx, const FPTYPE * dy, @@ -41,9 +41,9 @@ void gelu_grad_grad_cpu( } } -template void gelu_cpu(float * out, const float * x, const int size); -template void gelu_cpu(double * out, const double * x, const int size); -template void gelu_grad_cpu(float * out, const float * x, const float * dy, const int size); -template void gelu_grad_cpu(double * out, const double * x, const double * dy, const int size); -template void gelu_grad_grad_cpu(float * out, const float * x, const float * dy, const float * dy_2, const int size); -template void gelu_grad_grad_cpu(double * out, const double * x, const double * dy, const double * dy_2, const int size); +template void deepmd::gelu_cpu(float * out, const float * x, const int size); +template void deepmd::gelu_cpu(double * out, const double * x, const int size); +template void deepmd::gelu_grad_cpu(float * out, const float * x, const float * dy, const int size); +template void deepmd::gelu_grad_cpu(double * out, const double * x, const double * dy, const int size); +template void deepmd::gelu_grad_grad_cpu(float * out, const float * x, const float * dy, const float * dy_2, const int size); +template void deepmd::gelu_grad_grad_cpu(double * out, const double * x, const double * dy, const double * dy_2, const int size); diff --git a/source/lib/src/map_aparam.cc b/source/lib/src/map_aparam.cc index b7e9973d5f..7e60f1c3b8 100644 --- a/source/lib/src/map_aparam.cc +++ b/source/lib/src/map_aparam.cc @@ -1,7 +1,7 @@ #include "map_aparam.h" template -void map_aparam_cpu ( +void deepmd::map_aparam_cpu ( FPTYPE * output, const FPTYPE * aparam, const int * nlist, @@ -38,7 +38,7 @@ void map_aparam_cpu ( } template -void map_aparam_cpu ( +void deepmd::map_aparam_cpu ( double * output, const double * aparam, const int * nlist, @@ -48,7 +48,7 @@ void map_aparam_cpu ( ); template -void map_aparam_cpu ( +void deepmd::map_aparam_cpu ( float * output, const float * aparam, const int * nlist, diff --git a/source/lib/src/neighbor_list.cc b/source/lib/src/neighbor_list.cc index 4223b50fe6..e426d63906 100644 --- a/source/lib/src/neighbor_list.cc +++ b/source/lib/src/neighbor_list.cc @@ -743,8 +743,10 @@ copy_coord (std::vector & out_c, } } +using namespace deepmd; void +deepmd:: convert_nlist( InputNlist & to_nlist, std::vector > & from_nlist @@ -759,6 +761,7 @@ convert_nlist( } int +deepmd:: max_numneigh( const InputNlist & nlist ) @@ -772,6 +775,7 @@ max_numneigh( template int +deepmd:: build_nlist_cpu( InputNlist & nlist, int * max_list_size, @@ -817,6 +821,7 @@ build_nlist_cpu( template int +deepmd:: build_nlist_cpu( InputNlist & nlist, int * max_list_size, @@ -828,6 +833,7 @@ build_nlist_cpu( template int +deepmd:: build_nlist_cpu( InputNlist & nlist, int * max_list_size, @@ -868,4 +874,4 @@ void free_nlist_gpu_cuda( delete_device_memory(gpu_nlist.numneigh); delete_device_memory(gpu_nlist.firstneigh); } -#endif // GOOGLE_CUDA \ No newline at end of file +#endif // GOOGLE_CUDA diff --git a/source/lib/src/pair_tab.cc b/source/lib/src/pair_tab.cc index d0a435b1b1..5137e17ac9 100644 --- a/source/lib/src/pair_tab.cc +++ b/source/lib/src/pair_tab.cc @@ -122,7 +122,8 @@ _cum_sum ( } template -void pair_tab_cpu( +void +deepmd::pair_tab_cpu( FPTYPE * energy, FPTYPE * force, FPTYPE * virial, @@ -211,7 +212,7 @@ void pair_tab_cpu( template -void pair_tab_cpu( +void deepmd::pair_tab_cpu( float * energy, float * force, float * virial, @@ -227,7 +228,7 @@ void pair_tab_cpu( ); template -void pair_tab_cpu( +void deepmd::pair_tab_cpu( double * energy, double * force, double * virial, diff --git a/source/lib/src/prod_env_mat.cc b/source/lib/src/prod_env_mat.cc index a900b99a5c..597473021d 100644 --- a/source/lib/src/prod_env_mat.cc +++ b/source/lib/src/prod_env_mat.cc @@ -5,8 +5,12 @@ #include "fmt_nlist.h" #include "env_mat.h" +using namespace deepmd; + template -void prod_env_mat_a_cpu( +void +deepmd:: +prod_env_mat_a_cpu( FPTYPE * em, FPTYPE * em_deriv, FPTYPE * rij, @@ -88,7 +92,9 @@ void prod_env_mat_a_cpu( } template -void prod_env_mat_r_cpu( +void +deepmd:: +prod_env_mat_r_cpu( FPTYPE * em, FPTYPE * em_deriv, FPTYPE * rij, @@ -171,7 +177,9 @@ void prod_env_mat_r_cpu( template -void prod_env_mat_a_cpu( +void +deepmd:: +prod_env_mat_a_cpu( double * em, double * em_deriv, double * rij, @@ -189,7 +197,9 @@ void prod_env_mat_a_cpu( const std::vector sec); template -void prod_env_mat_a_cpu( +void +deepmd:: +prod_env_mat_a_cpu( float * em, float * em_deriv, float * rij, @@ -207,7 +217,9 @@ void prod_env_mat_a_cpu( const std::vector sec); template -void prod_env_mat_r_cpu( +void +deepmd:: +prod_env_mat_r_cpu( double * em, double * em_deriv, double * rij, @@ -225,7 +237,9 @@ void prod_env_mat_r_cpu( const std::vector sec); template -void prod_env_mat_r_cpu( +void +deepmd:: +prod_env_mat_r_cpu( float * em, float * em_deriv, float * rij, diff --git a/source/lib/src/prod_force.cc b/source/lib/src/prod_force.cc index 16d153f9e1..ffe177e16c 100644 --- a/source/lib/src/prod_force.cc +++ b/source/lib/src/prod_force.cc @@ -20,7 +20,9 @@ make_index_range ( template -void prod_force_a_cpu( +void +deepmd:: +prod_force_a_cpu( FPTYPE * force, const FPTYPE * net_deriv, const FPTYPE * env_deriv, @@ -56,7 +58,9 @@ void prod_force_a_cpu( } template -void prod_force_a_cpu( +void +deepmd:: +prod_force_a_cpu( double * force, const double * net_deriv, const double * env_deriv, @@ -66,7 +70,9 @@ void prod_force_a_cpu( const int nnei); template -void prod_force_a_cpu( +void +deepmd:: +prod_force_a_cpu( float * force, const float * net_deriv, const float * env_deriv, @@ -77,7 +83,9 @@ void prod_force_a_cpu( template -void prod_force_r_cpu( +void +deepmd:: +prod_force_r_cpu( FPTYPE * force, const FPTYPE * net_deriv, const FPTYPE * env_deriv, @@ -117,7 +125,9 @@ void prod_force_r_cpu( } template -void prod_force_r_cpu( +void +deepmd:: +prod_force_r_cpu( double * force, const double * net_deriv, const double * env_deriv, @@ -127,7 +137,9 @@ void prod_force_r_cpu( const int nnei); template -void prod_force_r_cpu( +void +deepmd:: +prod_force_r_cpu( float * force, const float * net_deriv, const float * env_deriv, diff --git a/source/lib/src/prod_force_grad.cc b/source/lib/src/prod_force_grad.cc index 49c510c8b5..7872ea5c55 100644 --- a/source/lib/src/prod_force_grad.cc +++ b/source/lib/src/prod_force_grad.cc @@ -21,7 +21,9 @@ make_index_range ( template -void prod_force_grad_a_cpu( +void +deepmd:: +prod_force_grad_a_cpu( FPTYPE * grad_net, const FPTYPE * grad, const FPTYPE * env_deriv, @@ -67,7 +69,9 @@ void prod_force_grad_a_cpu( template -void prod_force_grad_a_cpu( +void +deepmd:: +prod_force_grad_a_cpu( double * grad_net, const double * grad, const double * env_deriv, @@ -76,7 +80,9 @@ void prod_force_grad_a_cpu( const int nnei) ; template -void prod_force_grad_a_cpu( +void +deepmd:: +prod_force_grad_a_cpu( float * grad_net, const float * grad, const float * env_deriv, @@ -87,7 +93,9 @@ void prod_force_grad_a_cpu( template -void prod_force_grad_r_cpu( +void +deepmd:: +prod_force_grad_r_cpu( FPTYPE * grad_net, const FPTYPE * grad, const FPTYPE * env_deriv, @@ -134,7 +142,9 @@ void prod_force_grad_r_cpu( } template -void prod_force_grad_r_cpu( +void +deepmd:: +prod_force_grad_r_cpu( double * grad_net, const double * grad, const double * env_deriv, @@ -143,7 +153,9 @@ void prod_force_grad_r_cpu( const int nnei) ; template -void prod_force_grad_r_cpu( +void +deepmd:: +prod_force_grad_r_cpu( float * grad_net, const float * grad, const float * env_deriv, diff --git a/source/lib/src/prod_virial.cc b/source/lib/src/prod_virial.cc index 89c8f46185..086bc94245 100644 --- a/source/lib/src/prod_virial.cc +++ b/source/lib/src/prod_virial.cc @@ -20,7 +20,9 @@ make_index_range ( } template -void prod_virial_a_cpu( +void +deepmd:: +prod_virial_a_cpu( FPTYPE * virial, FPTYPE * atom_virial, const FPTYPE * net_deriv, @@ -65,7 +67,9 @@ void prod_virial_a_cpu( } template -void prod_virial_a_cpu( +void +deepmd:: +prod_virial_a_cpu( double * virial, double * atom_virial, const double * net_deriv, @@ -77,7 +81,9 @@ void prod_virial_a_cpu( const int nnei) ; template -void prod_virial_a_cpu( +void +deepmd:: +prod_virial_a_cpu( float * virial, float * atom_virial, const float * net_deriv, @@ -90,7 +96,9 @@ void prod_virial_a_cpu( template -void prod_virial_r_cpu( +void +deepmd:: +prod_virial_r_cpu( FPTYPE * virial, FPTYPE * atom_virial, const FPTYPE * net_deriv, @@ -131,7 +139,9 @@ void prod_virial_r_cpu( } template -void prod_virial_r_cpu( +void +deepmd:: +prod_virial_r_cpu( double * virial, double * atom_virial, const double * net_deriv, @@ -143,7 +153,9 @@ void prod_virial_r_cpu( const int nnei); template -void prod_virial_r_cpu( +void +deepmd:: +prod_virial_r_cpu( float * virial, float * atom_virial, const float * net_deriv, diff --git a/source/lib/src/prod_virial_grad.cc b/source/lib/src/prod_virial_grad.cc index 3a53692417..59c3192fc0 100644 --- a/source/lib/src/prod_virial_grad.cc +++ b/source/lib/src/prod_virial_grad.cc @@ -19,7 +19,9 @@ make_index_range ( } template -void prod_virial_grad_a_cpu( +void +deepmd:: +prod_virial_grad_a_cpu( FPTYPE * grad_net, const FPTYPE * grad, const FPTYPE * env_deriv, @@ -61,7 +63,9 @@ void prod_virial_grad_a_cpu( template -void prod_virial_grad_a_cpu( +void +deepmd:: +prod_virial_grad_a_cpu( double * grad_net, const double * grad, const double * env_deriv, @@ -71,7 +75,9 @@ void prod_virial_grad_a_cpu( const int nnei); template -void prod_virial_grad_a_cpu( +void +deepmd:: +prod_virial_grad_a_cpu( float * grad_net, const float * grad, const float * env_deriv, @@ -82,7 +88,9 @@ void prod_virial_grad_a_cpu( template -void prod_virial_grad_r_cpu( +void +deepmd:: +prod_virial_grad_r_cpu( FPTYPE * grad_net, const FPTYPE * grad, const FPTYPE * env_deriv, @@ -127,7 +135,9 @@ void prod_virial_grad_r_cpu( template -void prod_virial_grad_r_cpu( +void +deepmd:: +prod_virial_grad_r_cpu( double * grad_net, const double * grad, const double * env_deriv, @@ -137,7 +147,9 @@ void prod_virial_grad_r_cpu( const int nnei); template -void prod_virial_grad_r_cpu( +void +deepmd:: +prod_virial_grad_r_cpu( float * grad_net, const float * grad, const float * env_deriv, diff --git a/source/lib/src/region.cc b/source/lib/src/region.cc index b8ab55d1a8..62dcdb9b68 100644 --- a/source/lib/src/region.cc +++ b/source/lib/src/region.cc @@ -3,6 +3,8 @@ #include "region.h" #define BOXT_DIM 9 +using namespace deepmd; + template Region:: Region() @@ -80,6 +82,7 @@ tensor_t_dot_vec ( template void +deepmd:: init_region_cpu( Region & region, const FPTYPE * boxt) @@ -90,6 +93,7 @@ init_region_cpu( template void +deepmd:: convert_to_inter_cpu( FPTYPE * ri, const Region & region, @@ -100,6 +104,7 @@ convert_to_inter_cpu( template void +deepmd:: convert_to_phys_cpu( FPTYPE * rp, const Region & region, @@ -110,6 +115,7 @@ convert_to_phys_cpu( template FPTYPE +deepmd:: volume_cpu( const Region & region) { @@ -117,49 +123,59 @@ volume_cpu( } template -void init_region_cpu( - Region & region, +void +deepmd:: +init_region_cpu( + deepmd::Region & region, const double * boxt); template -void init_region_cpu( - Region & region, +void +deepmd:: +init_region_cpu( + deepmd::Region & region, const float * boxt); template void +deepmd:: convert_to_inter_cpu( double * ri, - const Region & region, + const deepmd::Region & region, const double * rp); template void +deepmd:: convert_to_inter_cpu( float * ri, - const Region & region, + const deepmd::Region & region, const float * rp); template void +deepmd:: convert_to_phys_cpu( double * ri, - const Region & region, + const deepmd::Region & region, const double * rp); template void +deepmd:: convert_to_phys_cpu( float * ri, - const Region & region, + const deepmd::Region & region, const float * rp); template double +deepmd:: volume_cpu( - const Region & region); + const deepmd::Region & region); template float +deepmd:: volume_cpu( - const Region & region); + const deepmd::Region & region); diff --git a/source/lib/src/soft_min_switch.cc b/source/lib/src/soft_min_switch.cc index fbbf8bbbdd..88471a3d4b 100644 --- a/source/lib/src/soft_min_switch.cc +++ b/source/lib/src/soft_min_switch.cc @@ -4,7 +4,7 @@ #include "switcher.h" template -void soft_min_switch_cpu( +void deepmd::soft_min_switch_cpu( FPTYPE * sw_value, FPTYPE * sw_deriv, const FPTYPE * rij, @@ -46,7 +46,7 @@ void soft_min_switch_cpu( } FPTYPE smin = bb / aa; FPTYPE vv, dd; - spline5_switch(vv, dd, smin, static_cast(rmin), static_cast(rmax)); + spline5_switch(vv, dd, smin, rmin, rmax); // value of switch sw_value[i_idx] = vv; // deriv of switch distributed as force @@ -80,7 +80,7 @@ void soft_min_switch_cpu( } template -void soft_min_switch_cpu( +void deepmd::soft_min_switch_cpu( double * sw_value, double * sw_deriv, const double * rij, @@ -92,7 +92,7 @@ void soft_min_switch_cpu( const double & rmax); template -void soft_min_switch_cpu( +void deepmd::soft_min_switch_cpu( float * sw_value, float * sw_deriv, const float * rij, diff --git a/source/lib/src/soft_min_switch_force.cc b/source/lib/src/soft_min_switch_force.cc index e189276c6e..724952493d 100644 --- a/source/lib/src/soft_min_switch_force.cc +++ b/source/lib/src/soft_min_switch_force.cc @@ -2,7 +2,7 @@ #include template -void soft_min_switch_force_cpu( +void deepmd::soft_min_switch_force_cpu( FPTYPE * force, const FPTYPE * du, const FPTYPE * sw_deriv, @@ -41,7 +41,7 @@ void soft_min_switch_force_cpu( } template -void soft_min_switch_force_cpu( +void deepmd::soft_min_switch_force_cpu( double * force, const double * du, const double * sw_deriv, @@ -51,7 +51,7 @@ void soft_min_switch_force_cpu( const int nnei); template -void soft_min_switch_force_cpu( +void deepmd::soft_min_switch_force_cpu( float * force, const float * du, const float * sw_deriv, diff --git a/source/lib/src/soft_min_switch_force_grad.cc b/source/lib/src/soft_min_switch_force_grad.cc index 63d388b174..31e46e9d6d 100644 --- a/source/lib/src/soft_min_switch_force_grad.cc +++ b/source/lib/src/soft_min_switch_force_grad.cc @@ -2,7 +2,7 @@ #include template -void soft_min_switch_force_grad_cpu( +void deepmd::soft_min_switch_force_grad_cpu( FPTYPE * grad_net, const FPTYPE * grad, const FPTYPE * sw_deriv, @@ -41,7 +41,7 @@ void soft_min_switch_force_grad_cpu( } template -void soft_min_switch_force_grad_cpu( +void deepmd::soft_min_switch_force_grad_cpu( double * grad_net, const double * grad, const double * sw_deriv, @@ -50,7 +50,7 @@ void soft_min_switch_force_grad_cpu( const int nnei); template -void soft_min_switch_force_grad_cpu( +void deepmd::soft_min_switch_force_grad_cpu( float * grad_net, const float * grad, const float * sw_deriv, diff --git a/source/lib/src/soft_min_switch_virial.cc b/source/lib/src/soft_min_switch_virial.cc index 9ceacc5d72..a93ab3c1fb 100644 --- a/source/lib/src/soft_min_switch_virial.cc +++ b/source/lib/src/soft_min_switch_virial.cc @@ -2,7 +2,7 @@ #include template -void soft_min_switch_virial_cpu( +void deepmd::soft_min_switch_virial_cpu( FPTYPE * virial, FPTYPE * atom_virial, const FPTYPE * du, @@ -47,7 +47,7 @@ void soft_min_switch_virial_cpu( template -void soft_min_switch_virial_cpu( +void deepmd::soft_min_switch_virial_cpu( double * virial, double * atom_virial, const double * du, @@ -59,7 +59,7 @@ void soft_min_switch_virial_cpu( const int nnei); template -void soft_min_switch_virial_cpu( +void deepmd::soft_min_switch_virial_cpu( float * virial, float * atom_virial, const float * du, diff --git a/source/lib/src/soft_min_switch_virial_grad.cc b/source/lib/src/soft_min_switch_virial_grad.cc index 3718810dfd..1bb28a7c63 100644 --- a/source/lib/src/soft_min_switch_virial_grad.cc +++ b/source/lib/src/soft_min_switch_virial_grad.cc @@ -1,7 +1,7 @@ #include "soft_min_switch_virial_grad.h" template -void soft_min_switch_virial_grad_cpu( +void deepmd::soft_min_switch_virial_grad_cpu( FPTYPE * grad_net, const FPTYPE * grad, const FPTYPE * sw_deriv, @@ -41,7 +41,7 @@ void soft_min_switch_virial_grad_cpu( } template -void soft_min_switch_virial_grad_cpu( +void deepmd::soft_min_switch_virial_grad_cpu( double * grad_net, const double * grad, const double * sw_deriv, @@ -51,7 +51,7 @@ void soft_min_switch_virial_grad_cpu( const int nnei); template -void soft_min_switch_virial_grad_cpu( +void deepmd::soft_min_switch_virial_grad_cpu( float * grad_net, const float * grad, const float * sw_deriv, diff --git a/source/lib/tests/test_coord.cc b/source/lib/tests/test_coord.cc index 111b66bb06..3706874b55 100644 --- a/source/lib/tests/test_coord.cc +++ b/source/lib/tests/test_coord.cc @@ -37,7 +37,7 @@ class TestNormCoord : public ::testing::Test TEST_F(TestNormCoord, cpu_case0) { - Region region; + deepmd::Region region; init_region_cpu(region, &boxt[0]); std::vector out_c(r0); normalize_coord_cpu(&out_c[0], natoms, region); @@ -48,7 +48,7 @@ TEST_F(TestNormCoord, cpu_case0) TEST_F(TestNormCoord, cpu_case1) { - Region region; + deepmd::Region region; init_region_cpu(region, &boxt[0]); std::vector out_c(r1); normalize_coord_cpu(&out_c[0], natoms, region); @@ -59,7 +59,7 @@ TEST_F(TestNormCoord, cpu_case1) TEST_F(TestNormCoord, cpu_case2) { - Region region; + deepmd::Region region; init_region_cpu(region, &boxt[0]); std::vector out_c(r2); normalize_coord_cpu(&out_c[0], natoms, region); @@ -167,7 +167,7 @@ TEST_F(TestCopyCoord, cpu) std::vector out_t(mem_size); std::vector mapping(mem_size); int nall; - Region region; + deepmd::Region region; init_region_cpu(region, &boxt[0]); int ret = copy_coord_cpu( @@ -211,7 +211,7 @@ TEST_F(TestCopyCoord, cpu_lessmem) std::vector out_t(mem_size); std::vector mapping(mem_size); int nall; - Region region; + deepmd::Region region; init_region_cpu(region, &boxt[0]); int ret = copy_coord_cpu( diff --git a/source/lib/tests/test_env_mat_a.cc b/source/lib/tests/test_env_mat_a.cc index 25fab3e59d..c08a4f4705 100644 --- a/source/lib/tests/test_env_mat_a.cc +++ b/source/lib/tests/test_env_mat_a.cc @@ -239,7 +239,7 @@ TEST_F(TestEnvMatA, cpu) for(int ii = 0; ii < nloc; ++ii){ int ret = format_nlist_i_cpu(fmt_nlist_a, posi_cpy, atype_cpy, ii, nlist_a_cpy[ii], rc, sec_a); EXPECT_EQ(ret, -1); - env_mat_a_cpu(env, env_deriv, rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(env, env_deriv, rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); EXPECT_EQ(env.size(), sec_a[2]*4); EXPECT_EQ(env.size(), env_deriv.size()/3); EXPECT_EQ(rij_a.size(), sec_a[2]*3); @@ -265,7 +265,7 @@ TEST_F(TestEnvMatA, cpu_equal_orig_cpy) int ret_1 = format_nlist_i_cpu(fmt_nlist_a_1, posi_cpy, atype_cpy, ii, nlist_a_cpy[ii], rc, sec_a); EXPECT_EQ(ret_1, -1); - env_mat_a_cpu(env_1, env_deriv_1, rij_a_1, posi_cpy, atype_cpy, ii, fmt_nlist_a_1, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(env_1, env_deriv_1, rij_a_1, posi_cpy, atype_cpy, ii, fmt_nlist_a_1, sec_a, rc_smth, rc); EXPECT_EQ(env_0.size(), env_1.size()); EXPECT_EQ(env_deriv_0.size(), env_deriv_1.size()); @@ -291,7 +291,7 @@ TEST_F(TestEnvMatA, cpu_num_deriv) for(int ii = 0; ii < nloc; ++ii){ int ret = format_nlist_i_cpu(fmt_nlist_a, posi_cpy, atype_cpy, ii, nlist_a_cpy[ii], rc, sec_a); EXPECT_EQ(ret, -1); - env_mat_a_cpu(env, env_deriv, rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(env, env_deriv, rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); EXPECT_EQ(env.size(), sec_a[2]*4); EXPECT_EQ(env.size(), env_deriv.size()/3); EXPECT_EQ(rij_a.size(), sec_a[2]*3); @@ -373,7 +373,7 @@ TEST_F(TestEnvMatAShortSel, cpu) for(int ii = 0; ii < nloc; ++ii){ int ret = format_nlist_i_cpu(fmt_nlist_a, posi_cpy, atype_cpy, ii, nlist_a_cpy[ii], rc, sec_a); EXPECT_EQ(ret, 1); - env_mat_a_cpu(env, env_deriv, rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(env, env_deriv, rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); EXPECT_EQ(env.size(), sec_a[2]*4); EXPECT_EQ(env.size(), env_deriv.size()/3); EXPECT_EQ(rij_a.size(), sec_a[2]*3); @@ -399,14 +399,14 @@ TEST_F(TestEnvMatA, prod_cpu) } std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); - convert_nlist(inlist, nlist_a_cpy); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::convert_nlist(inlist, nlist_a_cpy); std::vector em(nloc * ndescrpt), em_deriv(nloc * ndescrpt * 3), rij(nloc * nnei * 3); std::vector nlist(nloc * nnei); std::vector avg(ntypes * ndescrpt, 0); std::vector std(ntypes * ndescrpt, 1); - prod_env_mat_a_cpu( + deepmd::prod_env_mat_a_cpu( &em[0], &em_deriv[0], &rij[0], @@ -448,13 +448,13 @@ TEST_F(TestEnvMatA, prod_cpu_equal_cpu) } std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_a_cpy); std::vector em(nloc * ndescrpt), em_deriv(nloc * ndescrpt * 3), rij(nloc * nnei * 3); std::vector nlist(nloc * nnei); std::vector avg(ntypes * ndescrpt, 0); std::vector std(ntypes * ndescrpt, 1); - prod_env_mat_a_cpu( + deepmd::prod_env_mat_a_cpu( &em[0], &em_deriv[0], &rij[0], @@ -476,7 +476,7 @@ TEST_F(TestEnvMatA, prod_cpu_equal_cpu) for(int ii = 0; ii < nloc; ++ii){ int ret_1 = format_nlist_i_cpu(fmt_nlist_a_1, posi_cpy, atype_cpy, ii, nlist_a_cpy[ii], rc, sec_a); EXPECT_EQ(ret_1, -1); - env_mat_a_cpu(env_1, env_deriv_1, rij_a_1, posi_cpy, atype_cpy, ii, fmt_nlist_a_1, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(env_1, env_deriv_1, rij_a_1, posi_cpy, atype_cpy, ii, fmt_nlist_a_1, sec_a, rc_smth, rc); EXPECT_EQ(env_1.size(), nnei * 4); EXPECT_EQ(env_deriv_1.size(), nnei * 4 * 3); EXPECT_EQ(rij_a_1.size(), nnei * 3); @@ -535,7 +535,7 @@ TEST_F(TestEnvMatA, prod_gpu_cuda) } std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]), gpu_inlist; + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]), gpu_inlist; convert_nlist(inlist, nlist_a_cpy); std::vector em(nloc * ndescrpt, 0.0), em_deriv(nloc * ndescrpt * 3, 0.0), rij(nloc * nnei * 3, 0.0); std::vector nlist(nloc * nnei, 0); @@ -625,7 +625,7 @@ TEST_F(TestEnvMatA, prod_gpu_cuda_equal_cpu) } std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]), gpu_inlist; + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]), gpu_inlist; convert_nlist(inlist, nlist_a_cpy); std::vector em(nloc * ndescrpt, 0.0), em_deriv(nloc * ndescrpt * 3, 0.0), rij(nloc * nnei * 3, 0.0); std::vector nlist(nloc * nnei, 0); @@ -689,7 +689,7 @@ TEST_F(TestEnvMatA, prod_gpu_cuda_equal_cpu) for(int ii = 0; ii < nloc; ++ii){ int ret_1 = format_nlist_i_cpu(fmt_nlist_a_1, posi_cpy, atype_cpy, ii, nlist_a_cpy[ii], rc, sec_a); EXPECT_EQ(ret_1, -1); - env_mat_a_cpu(env_1, env_deriv_1, rij_a_1, posi_cpy, atype_cpy, ii, fmt_nlist_a_1, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(env_1, env_deriv_1, rij_a_1, posi_cpy, atype_cpy, ii, fmt_nlist_a_1, sec_a, rc_smth, rc); EXPECT_EQ(env_1.size(), nnei * 4); EXPECT_EQ(env_deriv_1.size(), nnei * 4 * 3); EXPECT_EQ(rij_a_1.size(), nnei * 3); diff --git a/source/lib/tests/test_env_mat_r.cc b/source/lib/tests/test_env_mat_r.cc index 4dfd369c1a..f571dbdaf1 100644 --- a/source/lib/tests/test_env_mat_r.cc +++ b/source/lib/tests/test_env_mat_r.cc @@ -168,7 +168,7 @@ TEST_F(TestEnvMatR, cpu) for(int ii = 0; ii < nloc; ++ii){ int ret = format_nlist_i_cpu(fmt_nlist_a, posi_cpy, atype_cpy, ii, nlist_a_cpy[ii], rc, sec_a); EXPECT_EQ(ret, -1); - env_mat_r_cpu(env, env_deriv, rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_r_cpu(env, env_deriv, rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); for (int jj = 0; jj < sec_a[2]; ++jj){ EXPECT_LT(fabs(env[jj] - expected_env[ii*sec_a[2] + jj]) , 1e-5); } @@ -188,7 +188,7 @@ TEST_F(TestEnvMatR, cpu_equal_orig_cpy) int ret_1 = format_nlist_i_cpu(fmt_nlist_a_1, posi_cpy, atype_cpy, ii, nlist_a_cpy[ii], rc, sec_a); EXPECT_EQ(ret_1, -1); - env_mat_r_cpu(env_1, env_deriv_1, rij_a_1, posi_cpy, atype_cpy, ii, fmt_nlist_a_1, sec_a, rc_smth, rc); + deepmd::env_mat_r_cpu(env_1, env_deriv_1, rij_a_1, posi_cpy, atype_cpy, ii, fmt_nlist_a_1, sec_a, rc_smth, rc); EXPECT_EQ(env_0.size(), env_1.size()); EXPECT_EQ(env_deriv_0.size(), env_deriv_1.size()); @@ -214,7 +214,7 @@ TEST_F(TestEnvMatR, cpu_num_deriv) for(int ii = 0; ii < nloc; ++ii){ int ret = format_nlist_i_cpu(fmt_nlist_a, posi_cpy, atype_cpy, ii, nlist_a_cpy[ii], rc, sec_a); EXPECT_EQ(ret, -1); - env_mat_r_cpu(env, env_deriv, rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_r_cpu(env, env_deriv, rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); for (int jj = 0; jj < sec_a[2]; ++jj){ int j_idx = fmt_nlist_a[jj]; @@ -251,14 +251,14 @@ TEST_F(TestEnvMatR, prod_cpu) } std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_a_cpy); std::vector em(nloc * ndescrpt), em_deriv(nloc * ndescrpt * 3), rij(nloc * nnei * 3); std::vector nlist(nloc * nnei); std::vector avg(ntypes * ndescrpt, 0); std::vector std(ntypes * ndescrpt, 1); - prod_env_mat_r_cpu( + deepmd::prod_env_mat_r_cpu( &em[0], &em_deriv[0], &rij[0], @@ -300,13 +300,13 @@ TEST_F(TestEnvMatR, prod_cpu_equal_cpu) } std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_a_cpy); std::vector em(nloc * ndescrpt), em_deriv(nloc * ndescrpt * 3), rij(nloc * nnei * 3); std::vector nlist(nloc * nnei); std::vector avg(ntypes * ndescrpt, 0); std::vector std(ntypes * ndescrpt, 1); - prod_env_mat_r_cpu( + deepmd::prod_env_mat_r_cpu( &em[0], &em_deriv[0], &rij[0], @@ -328,7 +328,7 @@ TEST_F(TestEnvMatR, prod_cpu_equal_cpu) for(int ii = 0; ii < nloc; ++ii){ int ret_1 = format_nlist_i_cpu(fmt_nlist_a_1, posi_cpy, atype_cpy, ii, nlist_a_cpy[ii], rc, sec_a); EXPECT_EQ(ret_1, -1); - env_mat_r_cpu(env_1, env_deriv_1, rij_a_1, posi_cpy, atype_cpy, ii, fmt_nlist_a_1, sec_a, rc_smth, rc); + deepmd::env_mat_r_cpu(env_1, env_deriv_1, rij_a_1, posi_cpy, atype_cpy, ii, fmt_nlist_a_1, sec_a, rc_smth, rc); EXPECT_EQ(env_1.size(), nnei * 1); EXPECT_EQ(env_deriv_1.size(), nnei * 1 * 3); EXPECT_EQ(rij_a_1.size(), nnei * 3); @@ -531,7 +531,7 @@ TEST_F(TestEnvMatR, prod_gpu_cuda_equal_cpu) for(int ii = 0; ii < nloc; ++ii){ int ret_1 = format_nlist_i_cpu(fmt_nlist_a_1, posi_cpy, atype_cpy, ii, nlist_a_cpy[ii], rc, sec_a); EXPECT_EQ(ret_1, -1); - env_mat_r_cpu(env_1, env_deriv_1, rij_a_1, posi_cpy, atype_cpy, ii, fmt_nlist_a_1, sec_a, rc_smth, rc); + deepmd::env_mat_r_cpu(env_1, env_deriv_1, rij_a_1, posi_cpy, atype_cpy, ii, fmt_nlist_a_1, sec_a, rc_smth, rc); EXPECT_EQ(env_1.size(), nnei * 1); EXPECT_EQ(env_deriv_1.size(), nnei * 1 * 3); EXPECT_EQ(rij_a_1.size(), nnei * 3); diff --git a/source/lib/tests/test_ewald.cc b/source/lib/tests/test_ewald.cc index 44cb758273..cb8e59e1d9 100644 --- a/source/lib/tests/test_ewald.cc +++ b/source/lib/tests/test_ewald.cc @@ -20,7 +20,7 @@ class TestEwald : public ::testing::Test std::vector boxt = { 13., 0., 0., 0., 13., 0., 0., 0., 13. }; - EwaldParameters eparam; + deepmd::EwaldParameters eparam; double expected_e = 4.7215808340392229e+00; std::vector expected_f = { -5.4937025715874448e+00,5.6659817006308417e+00,3.8059426028301313e-01,2.5210962791915938e+00,-2.6383552457553545e+00,-4.8998411247787405e-01,2.7390037416771147e+00,-3.2890571945143514e+00,3.8057620258450320e-01,6.7561832843578351e+00,-1.3707287681111919e+00,2.7733203842981604e+00,-3.3297964389679557e+00,1.0404967238120841e+00,-1.8035649784287722e+00,-3.1927842946711418e+00,5.9166278393797123e-01,-1.2409417562590299e+00, @@ -38,7 +38,7 @@ TEST_F(TestEwald, cpu) { double ener; std::vector force, virial; - Region region; + deepmd::Region region; init_region_cpu(region, &boxt[0]); ewald_recp(ener, force, virial, coord, charge, region, eparam); EXPECT_LT(fabs(ener - expected_e), 1e-10); diff --git a/source/lib/tests/test_fmt_nlist.cc b/source/lib/tests/test_fmt_nlist.cc index a37562a230..6dc539b7d6 100644 --- a/source/lib/tests/test_fmt_nlist.cc +++ b/source/lib/tests/test_fmt_nlist.cc @@ -212,7 +212,7 @@ TEST_F(TestFormatNlist, cpu) std::vector ilist(inum); std::vector numneigh(inum); std::vector firstneigh(inum); - InputNlist in_nlist(inum, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist in_nlist(inum, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(in_nlist, nlist_a_0); // allocate the mem for the result std::vector nlist(inum * sec_a.back()); @@ -280,7 +280,7 @@ TEST_F(TestFormatNlistShortSel, cpu) std::vector ilist(inum); std::vector numneigh(inum); std::vector firstneigh(inum); - InputNlist in_nlist(inum, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist in_nlist(inum, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(in_nlist, nlist_a_0); // mem std::vector nlist(inum * sec_a.back()); diff --git a/source/lib/tests/test_gelu.cc b/source/lib/tests/test_gelu.cc index f8a65ae308..0b05dd71d5 100644 --- a/source/lib/tests/test_gelu.cc +++ b/source/lib/tests/test_gelu.cc @@ -112,7 +112,7 @@ class TestGelu : public ::testing::Test TEST_F(TestGelu, gelu_cpu) { std::vector gelu(nloc); - gelu_cpu (&gelu[0], &xx[0], nloc); + deepmd::gelu_cpu (&gelu[0], &xx[0], nloc); EXPECT_EQ(gelu.size(), nloc); EXPECT_EQ(gelu.size(), expected_gelu.size()); for (int jj = 0; jj < gelu.size(); ++jj){ @@ -124,7 +124,7 @@ TEST_F(TestGelu, gelu_grad_cpu) { std::vector dy(100, 1.0); std::vector gelu_grad(nloc); - gelu_grad_cpu (&gelu_grad[0], &xx[0], &dy[0], nloc); + deepmd::gelu_grad_cpu (&gelu_grad[0], &xx[0], &dy[0], nloc); EXPECT_EQ(gelu_grad.size(), nloc); EXPECT_EQ(gelu_grad.size(), expected_gelu_grad.size()); for (int jj = 0; jj < gelu_grad.size(); ++jj){ @@ -137,7 +137,7 @@ TEST_F(TestGelu, gelu_grad_grad_cpu) std::vector dy(100, 1.0); std::vector dy_2(100, 1.0); std::vector gelu_grad_grad(nloc); - gelu_grad_grad_cpu (&gelu_grad_grad[0], &xx[0], &dy[0], &dy_2[0], nloc); + deepmd::gelu_grad_grad_cpu (&gelu_grad_grad[0], &xx[0], &dy[0], &dy_2[0], nloc); EXPECT_EQ(gelu_grad_grad.size(), nloc); EXPECT_EQ(gelu_grad_grad.size(), expected_gelu_grad_grad.size()); for (int jj = 0; jj < gelu_grad_grad.size(); ++jj){ @@ -211,4 +211,4 @@ TEST_F(TestGelu, gelu_grad_grad_gpu_cuda) EXPECT_LT(fabs(gelu_grad_grad[jj] - expected_gelu_grad_grad[jj]) , 1e-5); } } -#endif // GOOGLE_CUDA \ No newline at end of file +#endif // GOOGLE_CUDA diff --git a/source/lib/tests/test_map_aparam.cc b/source/lib/tests/test_map_aparam.cc index 286f878ffe..a393345eb0 100644 --- a/source/lib/tests/test_map_aparam.cc +++ b/source/lib/tests/test_map_aparam.cc @@ -71,7 +71,7 @@ class TestMapAparam : public ::testing::Test TEST_F(TestMapAparam, cpu) { std::vector output(nloc * nnei * numb_aparam); - map_aparam_cpu( + deepmd::map_aparam_cpu( &output[0], &aparam[0], &nlist[0], diff --git a/source/lib/tests/test_neighbor_list.cc b/source/lib/tests/test_neighbor_list.cc index a0962cecbf..cd8211fb09 100644 --- a/source/lib/tests/test_neighbor_list.cc +++ b/source/lib/tests/test_neighbor_list.cc @@ -54,7 +54,7 @@ TEST_F(TestNeighborList, cpu) firstneigh[ii] = new int[mem_size]; } - InputNlist nlist(nloc, ilist, numneigh, firstneigh); + deepmd::InputNlist nlist(nloc, ilist, numneigh, firstneigh); int max_list_size; int ret = build_nlist_cpu( nlist, @@ -94,7 +94,7 @@ TEST_F(TestNeighborList, cpu_lessmem) firstneigh[ii] = new int[mem_size]; } - InputNlist nlist(nloc, ilist, numneigh, firstneigh); + deepmd::InputNlist nlist(nloc, ilist, numneigh, firstneigh); int max_list_size; int ret = build_nlist_cpu( nlist, diff --git a/source/lib/tests/test_pair_tab.cc b/source/lib/tests/test_pair_tab.cc index 0c7cf5ea6f..c55e96369f 100644 --- a/source/lib/tests/test_pair_tab.cc +++ b/source/lib/tests/test_pair_tab.cc @@ -98,7 +98,7 @@ class TestPairTab : public ::testing::Test } std::vector t_env, t_env_deriv, t_rij; // compute env_mat and its deriv, record - env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); for (int jj = 0; jj < ndescrpt; ++jj){ env[ii*ndescrpt+jj] = t_env[jj]; for (int dd = 0; dd < 3; ++dd){ @@ -134,7 +134,7 @@ TEST_F(TestPairTab, cpu) std::vector virial(nall * 9); std::vector scale(nloc, 1.0); - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy[0], &force[0], &virial[0], @@ -197,7 +197,7 @@ TEST_F(TestPairTab, cpu_f_num_deriv) std::vector virial(9, 0.); std::vector atom_virial(nall * 9); std::vector scale(nloc, 1.0); - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy[0], &force[0], &atom_virial[0], @@ -242,8 +242,8 @@ TEST_F(TestPairTab, cpu_f_num_deriv) build_nlist(nlist_cpy_1, t_nlist, posi_cpy_1, nloc, rc, rc, nat_stt, ncell, ext_stt, ext_end, region, ncell); std::vector ilist_0(nloc), numneigh_0(nloc), ilist_1(nloc), numneigh_1(nloc);; std::vector firstneigh_0(nloc), firstneigh_1(nloc); - InputNlist inlist_0(nloc, &ilist_0[0], &numneigh_0[0], &firstneigh_0[0]); - InputNlist inlist_1(nloc, &ilist_1[0], &numneigh_1[0], &firstneigh_1[0]); + deepmd::InputNlist inlist_0(nloc, &ilist_0[0], &numneigh_0[0], &firstneigh_0[0]); + deepmd::InputNlist inlist_1(nloc, &ilist_1[0], &numneigh_1[0], &firstneigh_1[0]); convert_nlist(inlist_0, nlist_cpy_0); convert_nlist(inlist_1, nlist_cpy_1); int max_nnei_0 = max_numneigh(inlist_0); @@ -254,11 +254,11 @@ TEST_F(TestPairTab, cpu_f_num_deriv) std::vector nlist_0(nloc * nnei), nlist_1(nloc * nnei); std::vector avg(ntypes * ndescrpt, 0); std::vector std(ntypes * ndescrpt, 1); - prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_0[0], &nlist_0[0], &posi_cpy_0[0], &atype_cpy_0[0], inlist_0, max_nnei_0, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); - prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_1[0], &nlist_1[0], &posi_cpy_1[0], &atype_cpy_1[0], inlist_1, max_nnei_1, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); + deepmd::prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_0[0], &nlist_0[0], &posi_cpy_0[0], &atype_cpy_0[0], inlist_0, max_nnei_0, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); + deepmd::prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_1[0], &nlist_1[0], &posi_cpy_1[0], &atype_cpy_1[0], inlist_1, max_nnei_1, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); std::vector energy_0(nloc), energy_1(nloc); std::vector t_force(nall * 3), t_virial(nall * 9); - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy_0[0], &t_force[0], &t_virial[0], @@ -271,7 +271,7 @@ TEST_F(TestPairTab, cpu_f_num_deriv) &natoms[0], sel_a, sel_r); - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy_1[0], &t_force[0], &t_virial[0], @@ -305,7 +305,7 @@ TEST_F(TestPairTab, cpu_f_num_deriv_scale) std::vector virial(9, 0.); std::vector atom_virial(nall * 9); std::vector scale(nloc, new_scale); - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy[0], &force[0], &atom_virial[0], @@ -350,8 +350,8 @@ TEST_F(TestPairTab, cpu_f_num_deriv_scale) build_nlist(nlist_cpy_1, t_nlist, posi_cpy_1, nloc, rc, rc, nat_stt, ncell, ext_stt, ext_end, region, ncell); std::vector ilist_0(nloc), numneigh_0(nloc), ilist_1(nloc), numneigh_1(nloc);; std::vector firstneigh_0(nloc), firstneigh_1(nloc); - InputNlist inlist_0(nloc, &ilist_0[0], &numneigh_0[0], &firstneigh_0[0]); - InputNlist inlist_1(nloc, &ilist_1[0], &numneigh_1[0], &firstneigh_1[0]); + deepmd::InputNlist inlist_0(nloc, &ilist_0[0], &numneigh_0[0], &firstneigh_0[0]); + deepmd::InputNlist inlist_1(nloc, &ilist_1[0], &numneigh_1[0], &firstneigh_1[0]); convert_nlist(inlist_0, nlist_cpy_0); convert_nlist(inlist_1, nlist_cpy_1); int max_nnei_0 = max_numneigh(inlist_0); @@ -362,11 +362,11 @@ TEST_F(TestPairTab, cpu_f_num_deriv_scale) std::vector nlist_0(nloc * nnei), nlist_1(nloc * nnei); std::vector avg(ntypes * ndescrpt, 0); std::vector std(ntypes * ndescrpt, 1); - prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_0[0], &nlist_0[0], &posi_cpy_0[0], &atype_cpy_0[0], inlist_0, max_nnei_0, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); - prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_1[0], &nlist_1[0], &posi_cpy_1[0], &atype_cpy_1[0], inlist_1, max_nnei_1, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); + deepmd::prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_0[0], &nlist_0[0], &posi_cpy_0[0], &atype_cpy_0[0], inlist_0, max_nnei_0, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); + deepmd::prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_1[0], &nlist_1[0], &posi_cpy_1[0], &atype_cpy_1[0], inlist_1, max_nnei_1, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); std::vector energy_0(nloc), energy_1(nloc); std::vector t_force(nall * 3), t_virial(nall * 9); - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy_0[0], &t_force[0], &t_virial[0], @@ -379,7 +379,7 @@ TEST_F(TestPairTab, cpu_f_num_deriv_scale) &natoms[0], sel_a, sel_r); - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy_1[0], &t_force[0], &t_virial[0], @@ -411,7 +411,7 @@ TEST_F(TestPairTab, cpu_v_num_deriv) std::vector virial(9, 0.); std::vector atom_virial(nall * 9); std::vector scale(nloc, 1.0); - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy[0], &force[0], &atom_virial[0], @@ -471,8 +471,8 @@ TEST_F(TestPairTab, cpu_v_num_deriv) build_nlist(nlist_cpy_1, t_nlist, posi_cpy_1, nloc, rc, rc, nat_stt, ncell, ext_stt, ext_end, region_1, ncell); std::vector ilist_0(nloc), numneigh_0(nloc), ilist_1(nloc), numneigh_1(nloc);; std::vector firstneigh_0(nloc), firstneigh_1(nloc); - InputNlist inlist_0(nloc, &ilist_0[0], &numneigh_0[0], &firstneigh_0[0]); - InputNlist inlist_1(nloc, &ilist_1[0], &numneigh_1[0], &firstneigh_1[0]); + deepmd::InputNlist inlist_0(nloc, &ilist_0[0], &numneigh_0[0], &firstneigh_0[0]); + deepmd::InputNlist inlist_1(nloc, &ilist_1[0], &numneigh_1[0], &firstneigh_1[0]); convert_nlist(inlist_0, nlist_cpy_0); convert_nlist(inlist_1, nlist_cpy_1); int max_nnei_0 = max_numneigh(inlist_0); @@ -483,11 +483,11 @@ TEST_F(TestPairTab, cpu_v_num_deriv) std::vector nlist_0(nloc * nnei), nlist_1(nloc * nnei); std::vector avg(ntypes * ndescrpt, 0); std::vector std(ntypes * ndescrpt, 1); - prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_0[0], &nlist_0[0], &posi_cpy_0[0], &atype_cpy_0[0], inlist_0, max_nnei_0, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); - prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_1[0], &nlist_1[0], &posi_cpy_1[0], &atype_cpy_1[0], inlist_1, max_nnei_1, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); + deepmd::prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_0[0], &nlist_0[0], &posi_cpy_0[0], &atype_cpy_0[0], inlist_0, max_nnei_0, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); + deepmd::prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_1[0], &nlist_1[0], &posi_cpy_1[0], &atype_cpy_1[0], inlist_1, max_nnei_1, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); std::vector energy_0(nloc), energy_1(nloc); std::vector t_force(nall * 3), t_virial(nall * 9); - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy_0[0], &t_force[0], &t_virial[0], @@ -500,7 +500,7 @@ TEST_F(TestPairTab, cpu_v_num_deriv) &natoms[0], sel_a, sel_r); - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy_1[0], &t_force[0], &t_virial[0], @@ -543,7 +543,7 @@ TEST_F(TestPairTab, cpu_v_num_deriv_scale) std::vector virial(9, 0.); std::vector atom_virial(nall * 9); std::vector scale(nloc, new_scale); - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy[0], &force[0], &atom_virial[0], @@ -603,8 +603,8 @@ TEST_F(TestPairTab, cpu_v_num_deriv_scale) build_nlist(nlist_cpy_1, t_nlist, posi_cpy_1, nloc, rc, rc, nat_stt, ncell, ext_stt, ext_end, region_1, ncell); std::vector ilist_0(nloc), numneigh_0(nloc), ilist_1(nloc), numneigh_1(nloc);; std::vector firstneigh_0(nloc), firstneigh_1(nloc); - InputNlist inlist_0(nloc, &ilist_0[0], &numneigh_0[0], &firstneigh_0[0]); - InputNlist inlist_1(nloc, &ilist_1[0], &numneigh_1[0], &firstneigh_1[0]); + deepmd::InputNlist inlist_0(nloc, &ilist_0[0], &numneigh_0[0], &firstneigh_0[0]); + deepmd::InputNlist inlist_1(nloc, &ilist_1[0], &numneigh_1[0], &firstneigh_1[0]); convert_nlist(inlist_0, nlist_cpy_0); convert_nlist(inlist_1, nlist_cpy_1); int max_nnei_0 = max_numneigh(inlist_0); @@ -615,11 +615,11 @@ TEST_F(TestPairTab, cpu_v_num_deriv_scale) std::vector nlist_0(nloc * nnei), nlist_1(nloc * nnei); std::vector avg(ntypes * ndescrpt, 0); std::vector std(ntypes * ndescrpt, 1); - prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_0[0], &nlist_0[0], &posi_cpy_0[0], &atype_cpy_0[0], inlist_0, max_nnei_0, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); - prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_1[0], &nlist_1[0], &posi_cpy_1[0], &atype_cpy_1[0], inlist_1, max_nnei_1, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); + deepmd::prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_0[0], &nlist_0[0], &posi_cpy_0[0], &atype_cpy_0[0], inlist_0, max_nnei_0, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); + deepmd::prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_1[0], &nlist_1[0], &posi_cpy_1[0], &atype_cpy_1[0], inlist_1, max_nnei_1, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); std::vector energy_0(nloc), energy_1(nloc); std::vector t_force(nall * 3), t_virial(nall * 9); - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy_0[0], &t_force[0], &t_virial[0], @@ -632,7 +632,7 @@ TEST_F(TestPairTab, cpu_v_num_deriv_scale) &natoms[0], sel_a, sel_r); - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy_1[0], &t_force[0], &t_virial[0], @@ -675,7 +675,7 @@ TEST_F(TestPairTabTriBox, cpu_v_num_deriv) std::vector virial(9, 0.); std::vector atom_virial(nall * 9); std::vector scale(nloc, 1.0); - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy[0], &force[0], &atom_virial[0], @@ -735,8 +735,8 @@ TEST_F(TestPairTabTriBox, cpu_v_num_deriv) build_nlist(nlist_cpy_1, t_nlist, posi_cpy_1, nloc, rc, rc, nat_stt, ncell, ext_stt, ext_end, region_1, ncell); std::vector ilist_0(nloc), numneigh_0(nloc), ilist_1(nloc), numneigh_1(nloc);; std::vector firstneigh_0(nloc), firstneigh_1(nloc); - InputNlist inlist_0(nloc, &ilist_0[0], &numneigh_0[0], &firstneigh_0[0]); - InputNlist inlist_1(nloc, &ilist_1[0], &numneigh_1[0], &firstneigh_1[0]); + deepmd::InputNlist inlist_0(nloc, &ilist_0[0], &numneigh_0[0], &firstneigh_0[0]); + deepmd::InputNlist inlist_1(nloc, &ilist_1[0], &numneigh_1[0], &firstneigh_1[0]); convert_nlist(inlist_0, nlist_cpy_0); convert_nlist(inlist_1, nlist_cpy_1); int max_nnei_0 = max_numneigh(inlist_0); @@ -747,11 +747,11 @@ TEST_F(TestPairTabTriBox, cpu_v_num_deriv) std::vector nlist_0(nloc * nnei), nlist_1(nloc * nnei); std::vector avg(ntypes * ndescrpt, 0); std::vector std(ntypes * ndescrpt, 1); - prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_0[0], &nlist_0[0], &posi_cpy_0[0], &atype_cpy_0[0], inlist_0, max_nnei_0, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); - prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_1[0], &nlist_1[0], &posi_cpy_1[0], &atype_cpy_1[0], inlist_1, max_nnei_1, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); + deepmd::prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_0[0], &nlist_0[0], &posi_cpy_0[0], &atype_cpy_0[0], inlist_0, max_nnei_0, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); + deepmd::prod_env_mat_a_cpu(&t_em[0], &t_em_deriv[0], &rij_1[0], &nlist_1[0], &posi_cpy_1[0], &atype_cpy_1[0], inlist_1, max_nnei_1, &avg[0], &std[0], nloc, nall, rc, rc_smth, sec_a); std::vector energy_0(nloc), energy_1(nloc); std::vector t_force(nall * 3), t_virial(nall * 9); - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy_0[0], &t_force[0], &t_virial[0], @@ -764,7 +764,7 @@ TEST_F(TestPairTabTriBox, cpu_v_num_deriv) &natoms[0], sel_a, sel_r); - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy_1[0], &t_force[0], &t_virial[0], diff --git a/source/lib/tests/test_prod_force_a.cc b/source/lib/tests/test_prod_force_a.cc index 7cd76e6ed7..7aeb9ca99f 100644 --- a/source/lib/tests/test_prod_force_a.cc +++ b/source/lib/tests/test_prod_force_a.cc @@ -65,7 +65,7 @@ class TestProdForceA : public ::testing::Test } std::vector t_env, t_env_deriv, t_rij_a; // compute env_mat and its deriv, record - env_mat_a_cpu(t_env, t_env_deriv, t_rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(t_env, t_env_deriv, t_rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); for (int jj = 0; jj < ndescrpt; ++jj){ env[ii*ndescrpt+jj] = t_env[jj]; for (int dd = 0; dd < 3; ++dd){ @@ -86,7 +86,7 @@ TEST_F(TestProdForceA, cpu) { std::vector force(nall * 3); int n_a_sel = nnei; - prod_force_a_cpu (&force[0], &net_deriv[0], &env_deriv[0], &nlist[0], nloc, nall, nnei); + deepmd::prod_force_a_cpu (&force[0], &net_deriv[0], &env_deriv[0], &nlist[0], nloc, nall, nnei); EXPECT_EQ(force.size(), nall * 3); EXPECT_EQ(force.size(), expected_force.size()); for (int jj = 0; jj < force.size(); ++jj){ @@ -126,4 +126,4 @@ TEST_F(TestProdForceA, gpu_cuda) EXPECT_LT(fabs(force[jj] - expected_force[jj]) , 1e-5); } } -#endif // GOOGLE_CUDA \ No newline at end of file +#endif // GOOGLE_CUDA diff --git a/source/lib/tests/test_prod_force_grad_a.cc b/source/lib/tests/test_prod_force_grad_a.cc index b52c1c951e..82ab484616 100644 --- a/source/lib/tests/test_prod_force_grad_a.cc +++ b/source/lib/tests/test_prod_force_grad_a.cc @@ -64,7 +64,7 @@ class TestProdForceGradA : public ::testing::Test } std::vector t_env, t_env_deriv, t_rij_a; // compute env_mat and its deriv, record - env_mat_a_cpu(t_env, t_env_deriv, t_rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(t_env, t_env_deriv, t_rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); for (int jj = 0; jj < ndescrpt; ++jj){ env[ii*ndescrpt+jj] = t_env[jj]; for (int dd = 0; dd < 3; ++dd){ @@ -84,7 +84,7 @@ class TestProdForceGradA : public ::testing::Test TEST_F(TestProdForceGradA, cpu) { std::vector grad_net(nloc * ndescrpt); - prod_force_grad_a_cpu(&grad_net[0], &grad[0], &env_deriv[0], &nlist[0], nloc, nnei); + deepmd::prod_force_grad_a_cpu(&grad_net[0], &grad[0], &env_deriv[0], &nlist[0], nloc, nnei); EXPECT_EQ(grad_net.size(), nloc * ndescrpt); EXPECT_EQ(grad_net.size(), expected_grad_net.size()); for (int jj = 0; jj < grad_net.size(); ++jj){ diff --git a/source/lib/tests/test_prod_force_grad_r.cc b/source/lib/tests/test_prod_force_grad_r.cc index c32ce150e8..37534db7f8 100644 --- a/source/lib/tests/test_prod_force_grad_r.cc +++ b/source/lib/tests/test_prod_force_grad_r.cc @@ -64,7 +64,7 @@ class TestProdForceGradR : public ::testing::Test } std::vector t_env, t_env_deriv, t_rij_a; // compute env_mat and its deriv, record - env_mat_a_cpu(t_env, t_env_deriv, t_rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(t_env, t_env_deriv, t_rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); for (int jj = 0; jj < ndescrpt; ++jj){ env[ii*ndescrpt+jj] = t_env[jj]; for (int dd = 0; dd < 3; ++dd){ @@ -84,7 +84,7 @@ class TestProdForceGradR : public ::testing::Test TEST_F(TestProdForceGradR, cpu) { std::vector grad_net(nloc * ndescrpt); - prod_force_grad_r_cpu(&grad_net[0], &grad[0], &env_deriv[0], &nlist[0], nloc, nnei); + deepmd::prod_force_grad_r_cpu(&grad_net[0], &grad[0], &env_deriv[0], &nlist[0], nloc, nnei); EXPECT_EQ(grad_net.size(), nloc * ndescrpt); EXPECT_EQ(grad_net.size(), expected_grad_net.size()); for (int jj = 0; jj < grad_net.size(); ++jj){ diff --git a/source/lib/tests/test_prod_force_r.cc b/source/lib/tests/test_prod_force_r.cc index 6a3d68576b..033c41a7fe 100644 --- a/source/lib/tests/test_prod_force_r.cc +++ b/source/lib/tests/test_prod_force_r.cc @@ -65,7 +65,7 @@ class TestProdForceR : public ::testing::Test } std::vector t_env, t_env_deriv, t_rij_a; // compute env_mat and its deriv, record - env_mat_r_cpu(t_env, t_env_deriv, t_rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_r_cpu(t_env, t_env_deriv, t_rij_a, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); for (int jj = 0; jj < ndescrpt; ++jj){ env[ii*ndescrpt+jj] = t_env[jj]; for (int dd = 0; dd < 3; ++dd){ @@ -86,7 +86,7 @@ TEST_F(TestProdForceR, cpu) { std::vector force(nall * 3); int n_a_sel = nnei; - prod_force_r_cpu (&force[0], &net_deriv[0], &env_deriv[0], &nlist[0], nloc, nall, nnei); + deepmd::prod_force_r_cpu (&force[0], &net_deriv[0], &env_deriv[0], &nlist[0], nloc, nall, nnei); EXPECT_EQ(force.size(), nall * 3); EXPECT_EQ(force.size(), expected_force.size()); for (int jj = 0; jj < force.size(); ++jj){ diff --git a/source/lib/tests/test_prod_virial_a.cc b/source/lib/tests/test_prod_virial_a.cc index aa0e7bfac9..f1d4ee619a 100644 --- a/source/lib/tests/test_prod_virial_a.cc +++ b/source/lib/tests/test_prod_virial_a.cc @@ -68,7 +68,7 @@ class TestProdVirialA : public ::testing::Test } std::vector t_env, t_env_deriv, t_rij; // compute env_mat and its deriv, record - env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); for (int jj = 0; jj < ndescrpt; ++jj){ env[ii*ndescrpt+jj] = t_env[jj]; for (int dd = 0; dd < 3; ++dd){ @@ -93,7 +93,7 @@ TEST_F(TestProdVirialA, cpu) std::vector virial(9); std::vector atom_virial(nall * 9); int n_a_sel = nnei; - prod_virial_a_cpu (&virial[0], &atom_virial[0], &net_deriv[0], &env_deriv[0], &rij[0], &nlist[0], nloc, nall, nnei); + deepmd::prod_virial_a_cpu (&virial[0], &atom_virial[0], &net_deriv[0], &env_deriv[0], &rij[0], &nlist[0], nloc, nall, nnei); EXPECT_EQ(virial.size(), 9); EXPECT_EQ(virial.size(), expected_virial.size()); EXPECT_EQ(atom_virial.size(), nall * 9); @@ -159,4 +159,4 @@ TEST_F(TestProdVirialA, gpu_cuda) EXPECT_LT(fabs(atom_virial[jj] - expected_atom_virial[jj]) , 1e-5); } } -#endif // GOOGLE_CUDA \ No newline at end of file +#endif // GOOGLE_CUDA diff --git a/source/lib/tests/test_prod_virial_grad_a.cc b/source/lib/tests/test_prod_virial_grad_a.cc index cba31a10a8..53ad63e965 100644 --- a/source/lib/tests/test_prod_virial_grad_a.cc +++ b/source/lib/tests/test_prod_virial_grad_a.cc @@ -64,7 +64,7 @@ class TestProdVirialGradA : public ::testing::Test } std::vector t_env, t_env_deriv, t_rij; // compute env_mat and its deriv, record - env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); for (int jj = 0; jj < ndescrpt; ++jj){ env[ii*ndescrpt+jj] = t_env[jj]; for (int dd = 0; dd < 3; ++dd){ @@ -88,7 +88,7 @@ TEST_F(TestProdVirialGradA, cpu) { std::vector grad_net(nloc * ndescrpt); int n_a_sel = nnei; - prod_virial_grad_a_cpu (&grad_net[0], &grad[0], &env_deriv[0], &rij[0], &nlist[0], nloc, nnei); + deepmd::prod_virial_grad_a_cpu (&grad_net[0], &grad[0], &env_deriv[0], &rij[0], &nlist[0], nloc, nnei); EXPECT_EQ(grad_net.size(), nloc * ndescrpt); EXPECT_EQ(grad_net.size(), expected_grad_net.size()); for (int jj = 0; jj < grad_net.size(); ++jj){ diff --git a/source/lib/tests/test_prod_virial_grad_r.cc b/source/lib/tests/test_prod_virial_grad_r.cc index 45e6944590..2cb0c91038 100644 --- a/source/lib/tests/test_prod_virial_grad_r.cc +++ b/source/lib/tests/test_prod_virial_grad_r.cc @@ -64,7 +64,7 @@ class TestProdVirialGradR : public ::testing::Test } std::vector t_env, t_env_deriv, t_rij; // compute env_mat and its deriv, record - env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); for (int jj = 0; jj < ndescrpt; ++jj){ env[ii*ndescrpt+jj] = t_env[jj]; for (int dd = 0; dd < 3; ++dd){ @@ -88,7 +88,7 @@ TEST_F(TestProdVirialGradR, cpu) { std::vector grad_net(nloc * ndescrpt); int n_a_sel = nnei; - prod_virial_grad_r_cpu (&grad_net[0], &grad[0], &env_deriv[0], &rij[0], &nlist[0], nloc, nnei); + deepmd::prod_virial_grad_r_cpu (&grad_net[0], &grad[0], &env_deriv[0], &rij[0], &nlist[0], nloc, nnei); EXPECT_EQ(grad_net.size(), nloc * ndescrpt); EXPECT_EQ(grad_net.size(), expected_grad_net.size()); for (int jj = 0; jj < grad_net.size(); ++jj){ diff --git a/source/lib/tests/test_prod_virial_r.cc b/source/lib/tests/test_prod_virial_r.cc index c09a2f04ad..101b1659f8 100644 --- a/source/lib/tests/test_prod_virial_r.cc +++ b/source/lib/tests/test_prod_virial_r.cc @@ -68,7 +68,7 @@ class TestProdVirialR : public ::testing::Test } std::vector t_env, t_env_deriv, t_rij; // compute env_mat and its deriv, record - env_mat_r_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_r_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); for (int jj = 0; jj < ndescrpt; ++jj){ env[ii*ndescrpt+jj] = t_env[jj]; for (int dd = 0; dd < 3; ++dd){ @@ -93,7 +93,7 @@ TEST_F(TestProdVirialR, cpu) std::vector virial(9); std::vector atom_virial(nall * 9); int n_a_sel = nnei; - prod_virial_r_cpu (&virial[0], &atom_virial[0], &net_deriv[0], &env_deriv[0], &rij[0], &nlist[0], nloc, nall, nnei); + deepmd::prod_virial_r_cpu (&virial[0], &atom_virial[0], &net_deriv[0], &env_deriv[0], &rij[0], &nlist[0], nloc, nall, nnei); EXPECT_EQ(virial.size(), 9); EXPECT_EQ(atom_virial.size(), nall * 9); EXPECT_EQ(virial.size(), expected_virial.size()); @@ -159,4 +159,4 @@ TEST_F(TestProdVirialR, gpu_cuda) EXPECT_LT(fabs(atom_virial[jj] - expected_atom_virial[jj]) , 1e-5); } } -#endif // GOOGLE_CUDA \ No newline at end of file +#endif // GOOGLE_CUDA diff --git a/source/lib/tests/test_simulation_region.cc b/source/lib/tests/test_simulation_region.cc index dbd65d2883..674c505c02 100644 --- a/source/lib/tests/test_simulation_region.cc +++ b/source/lib/tests/test_simulation_region.cc @@ -41,7 +41,7 @@ TEST_F(TestRegion, orig) TEST_F(TestRegion, cpu) { // check rec_box - Region region; + deepmd::Region region; init_region_cpu(region, &ref_boxt[0]); for(int ii = 0; ii < 9; ++ii){ EXPECT_LT(fabs(region.rec_boxt[ii] - ref_rec_boxt[ii]), 1e-10); diff --git a/source/lib/tests/test_soft_min_switch.cc b/source/lib/tests/test_soft_min_switch.cc index 0e9319c183..e8e1a0eddc 100644 --- a/source/lib/tests/test_soft_min_switch.cc +++ b/source/lib/tests/test_soft_min_switch.cc @@ -65,7 +65,7 @@ class TestSoftMinSwitch : public ::testing::Test } std::vector t_env, t_env_deriv, t_rij; // compute env_mat and its deriv, record - env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); for (int jj = 0; jj < nnei * 3; ++jj){ rij[ii*nnei*3 + jj] = t_rij[jj]; } @@ -79,7 +79,7 @@ TEST_F(TestSoftMinSwitch, cpu) { std::vector sw_value(nloc); std::vector sw_deriv(nloc * nnei * 3); - soft_min_switch_cpu (&sw_value[0], &sw_deriv[0], &rij[0], &nlist[0], nloc, nnei, alpha, rmin, rmax); + deepmd::soft_min_switch_cpu (&sw_value[0], &sw_deriv[0], &rij[0], &nlist[0], nloc, nnei, alpha, rmin, rmax); EXPECT_EQ(sw_value.size(), nloc); EXPECT_EQ(sw_value.size(), expected_value.size()); EXPECT_EQ(sw_deriv.size(), nloc * nnei * 3); @@ -106,7 +106,7 @@ TEST_F(TestSoftMinSwitch, cpu_num_deriv) std::vector fmt_nlist_a; double hh = 1e-5; - soft_min_switch_cpu (&sw_value[0], &sw_deriv[0], &rij[0], &nlist[0], nloc, nnei, alpha, rmin, rmax); + deepmd::soft_min_switch_cpu (&sw_value[0], &sw_deriv[0], &rij[0], &nlist[0], nloc, nnei, alpha, rmin, rmax); EXPECT_EQ(sw_value.size(), nloc); EXPECT_EQ(sw_deriv.size(), nloc * nnei * 3); @@ -123,8 +123,8 @@ TEST_F(TestSoftMinSwitch, cpu_num_deriv) std::vector posi_1 = posi_cpy; posi_0[j_idx*3+dd] -= hh; posi_1[j_idx*3+dd] += hh; - env_mat_a_cpu(env, env_deriv, t_rij_0, posi_0, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); - env_mat_a_cpu(env, env_deriv, t_rij_1, posi_1, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(env, env_deriv, t_rij_0, posi_0, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(env, env_deriv, t_rij_1, posi_1, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); EXPECT_EQ(t_rij_0.size(), nnei * 3); EXPECT_EQ(t_rij_1.size(), nnei * 3); rij_0 = rij; @@ -133,8 +133,8 @@ TEST_F(TestSoftMinSwitch, cpu_num_deriv) rij_0[ii*nnei*3 + jj*3 + dd] = t_rij_0[jj*3 + dd]; rij_1[ii*nnei*3 + jj*3 + dd] = t_rij_1[jj*3 + dd]; } - soft_min_switch_cpu (&sw_value_0[0], &sw_deriv_0[0], &rij_0[0], &nlist[0], nloc, nnei, alpha, rmin, rmax); - soft_min_switch_cpu (&sw_value_1[0], &sw_deriv_1[0], &rij_1[0], &nlist[0], nloc, nnei, alpha, rmin, rmax); + deepmd::soft_min_switch_cpu (&sw_value_0[0], &sw_deriv_0[0], &rij_0[0], &nlist[0], nloc, nnei, alpha, rmin, rmax); + deepmd::soft_min_switch_cpu (&sw_value_1[0], &sw_deriv_1[0], &rij_1[0], &nlist[0], nloc, nnei, alpha, rmin, rmax); double ana_deriv = sw_deriv[ii*nnei*3 + jj*3 + dd]; double num_deriv = (sw_value_1[ii] - sw_value_0[ii]) / (2. * hh); EXPECT_LT(fabs(num_deriv - ana_deriv), 1e-5); diff --git a/source/lib/tests/test_soft_min_switch_force.cc b/source/lib/tests/test_soft_min_switch_force.cc index ebe1b62dfe..da40ab662b 100644 --- a/source/lib/tests/test_soft_min_switch_force.cc +++ b/source/lib/tests/test_soft_min_switch_force.cc @@ -66,14 +66,14 @@ class TestSoftMinSwitchForce : public ::testing::Test } std::vector t_env, t_env_deriv, t_rij; // compute env_mat and its deriv, record - env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); for (int jj = 0; jj < nnei * 3; ++jj){ rij[ii*nnei*3 + jj] = t_rij[jj]; } } sw_value.resize(nloc); sw_deriv.resize(nloc * nnei * 3); - soft_min_switch_cpu (&sw_value[0], &sw_deriv[0], &rij[0], &nlist[0], nloc, + deepmd::soft_min_switch_cpu (&sw_value[0], &sw_deriv[0], &rij[0], &nlist[0], nloc, nnei, alpha, rmin, rmax); du.resize(nloc); for (int ii = 0; ii < nloc; ++ii){ @@ -87,7 +87,7 @@ class TestSoftMinSwitchForce : public ::testing::Test TEST_F(TestSoftMinSwitchForce, cpu) { std::vector force(nall * 3); - soft_min_switch_force_cpu( + deepmd::soft_min_switch_force_cpu( &force[0], &du[0], &sw_deriv[0], diff --git a/source/lib/tests/test_soft_min_switch_force_grad.cc b/source/lib/tests/test_soft_min_switch_force_grad.cc index 66faf0801a..0591b91e3f 100644 --- a/source/lib/tests/test_soft_min_switch_force_grad.cc +++ b/source/lib/tests/test_soft_min_switch_force_grad.cc @@ -66,14 +66,14 @@ class TestSoftMinSwitchForceGrad : public ::testing::Test } std::vector t_env, t_env_deriv, t_rij; // compute env_mat and its deriv, record - env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); for (int jj = 0; jj < nnei * 3; ++jj){ rij[ii*nnei*3 + jj] = t_rij[jj]; } } sw_value.resize(nloc); sw_deriv.resize(nloc * nnei * 3); - soft_min_switch_cpu (&sw_value[0], &sw_deriv[0], &rij[0], &nlist[0], nloc, + deepmd::soft_min_switch_cpu (&sw_value[0], &sw_deriv[0], &rij[0], &nlist[0], nloc, nnei, alpha, rmin, rmax); grad.resize(nloc * 3); for (int ii = 0; ii < nloc; ++ii){ @@ -87,7 +87,7 @@ class TestSoftMinSwitchForceGrad : public ::testing::Test TEST_F(TestSoftMinSwitchForceGrad, cpu) { std::vector grad_net(nloc); - soft_min_switch_force_grad_cpu( + deepmd::soft_min_switch_force_grad_cpu( &grad_net[0], &grad[0], &sw_deriv[0], diff --git a/source/lib/tests/test_soft_min_switch_virial.cc b/source/lib/tests/test_soft_min_switch_virial.cc index 6132590adf..69471eb9ce 100644 --- a/source/lib/tests/test_soft_min_switch_virial.cc +++ b/source/lib/tests/test_soft_min_switch_virial.cc @@ -69,14 +69,14 @@ class TestSoftMinSwitchVirial : public ::testing::Test } std::vector t_env, t_env_deriv, t_rij; // compute env_mat and its deriv, record - env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); for (int jj = 0; jj < nnei * 3; ++jj){ rij[ii*nnei*3 + jj] = t_rij[jj]; } } sw_value.resize(nloc); sw_deriv.resize(nloc * nnei * 3); - soft_min_switch_cpu (&sw_value[0], &sw_deriv[0], &rij[0], &nlist[0], nloc, + deepmd::soft_min_switch_cpu (&sw_value[0], &sw_deriv[0], &rij[0], &nlist[0], nloc, nnei, alpha, rmin, rmax); du.resize(nloc); for (int ii = 0; ii < nloc; ++ii){ @@ -91,7 +91,7 @@ TEST_F(TestSoftMinSwitchVirial, cpu) { std::vector virial(9); std::vector atom_virial(nall * 9); - soft_min_switch_virial_cpu( + deepmd::soft_min_switch_virial_cpu( &virial[0], &atom_virial[0], &du[0], diff --git a/source/lib/tests/test_soft_min_switch_virial_grad.cc b/source/lib/tests/test_soft_min_switch_virial_grad.cc index 540e846f73..db5b05fe26 100644 --- a/source/lib/tests/test_soft_min_switch_virial_grad.cc +++ b/source/lib/tests/test_soft_min_switch_virial_grad.cc @@ -66,14 +66,14 @@ class TestSoftMinSwitchVirialGrad : public ::testing::Test } std::vector t_env, t_env_deriv, t_rij; // compute env_mat and its deriv, record - env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); + deepmd::env_mat_a_cpu(t_env, t_env_deriv, t_rij, posi_cpy, atype_cpy, ii, fmt_nlist_a, sec_a, rc_smth, rc); for (int jj = 0; jj < nnei * 3; ++jj){ rij[ii*nnei*3 + jj] = t_rij[jj]; } } sw_value.resize(nloc); sw_deriv.resize(nloc * nnei * 3); - soft_min_switch_cpu (&sw_value[0], &sw_deriv[0], &rij[0], &nlist[0], nloc, + deepmd::soft_min_switch_cpu (&sw_value[0], &sw_deriv[0], &rij[0], &nlist[0], nloc, nnei, alpha, rmin, rmax); grad.resize(nloc * 3); for (int ii = 0; ii < nloc; ++ii){ @@ -87,7 +87,7 @@ class TestSoftMinSwitchVirialGrad : public ::testing::Test TEST_F(TestSoftMinSwitchVirialGrad, cpu) { std::vector grad_net(nloc); - soft_min_switch_virial_grad_cpu( + deepmd::soft_min_switch_virial_grad_cpu( &grad_net[0], &grad[0], &sw_deriv[0], diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index 2a5826aa84..5ce85490fc 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -263,7 +263,7 @@ void FixDPLR::pre_force(int vflag) } // get lammps nlist NeighList * list = pair_deepmd->list; - InputNlist lmp_list (list->inum, list->ilist, list->numneigh, list->firstneigh); + deepmd::InputNlist lmp_list (list->inum, list->ilist, list->numneigh, list->firstneigh); // declear output vector tensor; // compute @@ -417,7 +417,7 @@ void FixDPLR::post_force(int vflag) } // lmp nlist NeighList * list = pair_deepmd->list; - InputNlist lmp_list (list->inum, list->ilist, list->numneigh, list->firstneigh); + deepmd::InputNlist lmp_list (list->inum, list->ilist, list->numneigh, list->firstneigh); // bonded pairs vector > valid_pairs; get_valid_pairs(valid_pairs); diff --git a/source/lmp/pair_deepmd.cpp b/source/lmp/pair_deepmd.cpp index 593e6a4246..8e2d691562 100644 --- a/source/lmp/pair_deepmd.cpp +++ b/source/lmp/pair_deepmd.cpp @@ -360,7 +360,7 @@ void PairDeepMD::compute(int eflag, int vflag) multi_models_no_mod_devi = (numb_models > 1 && (out_freq == 0 || update->ntimestep % out_freq != 0)); multi_models_mod_devi = (numb_models > 1 && (out_freq > 0 && update->ntimestep % out_freq == 0)); if (do_ghost) { - InputNlist lmp_list (list->inum, list->ilist, list->numneigh, list->firstneigh); + deepmd::InputNlist lmp_list (list->inum, list->ilist, list->numneigh, list->firstneigh); if (single_model || multi_models_no_mod_devi) { if ( ! (eflag_atom || vflag_atom) ) { #ifdef HIGH_PREC diff --git a/source/lmp/pair_deepmd.h.in b/source/lmp/pair_deepmd.h.in index a54f45c2f3..ee20de13c6 100644 --- a/source/lmp/pair_deepmd.h.in +++ b/source/lmp/pair_deepmd.h.in @@ -1,16 +1,3 @@ -/* -*- c++ -*- ---------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - http://lammps.sandia.gov, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov - - Copyright (2003) Sandia Corporation. Under the terms of Contract - DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains - certain rights in this software. This software is distributed under - the GNU General Public License. - - See the README file in the top-level LAMMPS directory. -------------------------------------------------------------------------- */ - #ifdef PAIR_CLASS PairStyle(deepmd,PairDeepMD) diff --git a/source/lmp/pppm_dplr.cpp b/source/lmp/pppm_dplr.cpp index da95f58c9d..7b2fbe6e65 100644 --- a/source/lmp/pppm_dplr.cpp +++ b/source/lmp/pppm_dplr.cpp @@ -1,16 +1,3 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://lammps.sandia.gov/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov - - Copyright (2003) Sandia Corporation. Under the terms of Contract - DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains - certain rights in this software. This software is distributed under - the GNU General Public License. - - See the README file in the top-level LAMMPS directory. -------------------------------------------------------------------------- */ - #include #include "pppm_dplr.h" #include "atom.h" diff --git a/source/lmp/pppm_dplr.h b/source/lmp/pppm_dplr.h index d9752583d5..4f22a9c621 100644 --- a/source/lmp/pppm_dplr.h +++ b/source/lmp/pppm_dplr.h @@ -1,16 +1,3 @@ -/* -*- c++ -*- ---------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - http://lammps.sandia.gov, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov - - Copyright (2003) Sandia Corporation. Under the terms of Contract - DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains - certain rights in this software. This software is distributed under - the GNU General Public License. - - See the README file in the top-level LAMMPS directory. -------------------------------------------------------------------------- */ - #ifdef KSPACE_CLASS KSpaceStyle(pppm/dplr,PPPMDPLR) diff --git a/source/op/ewald_recp.cc b/source/op/ewald_recp.cc index 21ac163b5c..ae3aa84bc1 100644 --- a/source/op/ewald_recp.cc +++ b/source/op/ewald_recp.cc @@ -79,7 +79,7 @@ class EwaldRecpOp : public OpKernel { int coord_iter = kk * nloc * 3; int charge_iter = kk * nloc; // set region - Region region; + deepmd::Region region; init_region_cpu(region, &box(box_iter)); // set & normalize coord @@ -117,7 +117,7 @@ class EwaldRecpOp : public OpKernel { } } private: - EwaldParameters ep; + deepmd::EwaldParameters ep; }; #define REGISTER_CPU(T) \ diff --git a/source/op/gelu_multi_device.cc b/source/op/gelu_multi_device.cc index 4ea7afad17..5923ee5675 100644 --- a/source/op/gelu_multi_device.cc +++ b/source/op/gelu_multi_device.cc @@ -51,7 +51,7 @@ class GeluOp : public OpKernel { #endif // GOOGLE_CUDA } else if (device == "CPU") { - gelu_cpu( + deepmd::gelu_cpu( out, x, size); } @@ -94,7 +94,7 @@ class GeluGradOp : public OpKernel { #endif // GOOGLE_CUDA } else if (device == "CPU") { - gelu_grad_cpu( + deepmd::gelu_grad_cpu( out, x, dy, size); } @@ -135,7 +135,7 @@ class GeluGradGradOp : public OpKernel { #endif // GOOGLE_CUDA } else if (device == "CPU") { - gelu_grad_grad_cpu( + deepmd::gelu_grad_grad_cpu( out, x, dy, dy_2, size); } @@ -170,4 +170,4 @@ REGISTER_KERNEL_BUILDER( \ GeluGradGradOp); REGISTER_GPU(float); REGISTER_GPU(double); -#endif // GOOGLE_CUDA \ No newline at end of file +#endif // GOOGLE_CUDA diff --git a/source/op/map_aparam.cc b/source/op/map_aparam.cc index 1a08b678c3..3eba13990a 100644 --- a/source/op/map_aparam.cc +++ b/source/op/map_aparam.cc @@ -62,7 +62,7 @@ class MapAparamOp : public OpKernel { int output_iter = kk * nloc * nnei * numb_aparam; int aparam_iter = kk * nall * numb_aparam; int nlist_iter = kk * nloc * nnei; - map_aparam_cpu( + deepmd::map_aparam_cpu( &output(output_iter), &aparam(aparam_iter), &nlist(nlist_iter), diff --git a/source/op/pair_tab.cc b/source/op/pair_tab.cc index 31c2083cf7..fb3689b5a8 100644 --- a/source/op/pair_tab.cc +++ b/source/op/pair_tab.cc @@ -126,7 +126,7 @@ class PairTabOp : public OpKernel { // loop over samples #pragma omp parallel for for (int kk = 0; kk < nframes; ++kk){ - pair_tab_cpu( + deepmd::pair_tab_cpu( &energy(kk,0), &force(kk,0), &virial(kk,0), diff --git a/source/op/prod_env_mat_multi_device.cc b/source/op/prod_env_mat_multi_device.cc index e12fa73017..c0423db358 100644 --- a/source/op/prod_env_mat_multi_device.cc +++ b/source/op/prod_env_mat_multi_device.cc @@ -89,7 +89,7 @@ _prepare_coord_nlist_cpu( int const** type, std::vector & type_cpy, std::vector & idx_mapping, - InputNlist & inlist, + deepmd::InputNlist & inlist, std::vector & ilist, std::vector & numneigh, std::vector & firstneigh, @@ -271,7 +271,7 @@ class ProdEnvMatAOp : public OpKernel { array_longlong = uint64_temp.flat().data(); // update nbor list - InputNlist inlist; + deepmd::InputNlist inlist; inlist.inum = nloc; env_mat_nbor_update( inlist, gpu_inlist, max_nbor_size, nbor_list_dev, @@ -284,7 +284,7 @@ class ProdEnvMatAOp : public OpKernel { #endif //GOOGLE_CUDA } else if (device == "CPU") { - InputNlist inlist; + deepmd::InputNlist inlist; // some buffers, be freed after the evaluation of this frame std::vector idx_mapping; std::vector ilist(nloc), numneigh(nloc); @@ -325,7 +325,7 @@ class ProdEnvMatAOp : public OpKernel { std::string device; int * array_int = NULL; unsigned long long * array_longlong = NULL; - InputNlist gpu_inlist; + deepmd::InputNlist gpu_inlist; int * nbor_list_dev = NULL; }; @@ -481,7 +481,7 @@ class ProdEnvMatROp : public OpKernel { array_longlong = uint64_temp.flat().data(); // update nbor list - InputNlist inlist; + deepmd::InputNlist inlist; inlist.inum = nloc; env_mat_nbor_update( inlist, gpu_inlist, max_nbor_size, nbor_list_dev, @@ -494,7 +494,7 @@ class ProdEnvMatROp : public OpKernel { #endif //GOOGLE_CUDA } else if (device == "CPU") { - InputNlist inlist; + deepmd::InputNlist inlist; // some buffers, be freed after the evaluation of this frame std::vector idx_mapping; std::vector ilist(nloc), numneigh(nloc); @@ -533,7 +533,7 @@ class ProdEnvMatROp : public OpKernel { std::string device; int * array_int = NULL; unsigned long long * array_longlong = NULL; - InputNlist gpu_inlist; + deepmd::InputNlist gpu_inlist; int * nbor_list_dev = NULL; }; @@ -557,7 +557,7 @@ _norm_copy_coord_cpu( { std::vector tmp_coord(nall*3); std::copy(coord, coord+nall*3, tmp_coord.begin()); - Region region; + deepmd::Region region; init_region_cpu(region, box); normalize_coord_cpu(&tmp_coord[0], nall, region); int tt; @@ -599,7 +599,7 @@ _build_nlist_cpu( jlist[ii].resize(mem_nnei); firstneigh[ii] = &jlist[ii][0]; } - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); int ret = build_nlist_cpu( inlist, &max_nnei, coord, nloc, new_nall, mem_nnei, rcut_r); @@ -639,7 +639,7 @@ _prepare_coord_nlist_cpu( int const** type, std::vector & type_cpy, std::vector & idx_mapping, - InputNlist & inlist, + deepmd::InputNlist & inlist, std::vector & ilist, std::vector & numneigh, std::vector & firstneigh, diff --git a/source/op/prod_force_se_a.cc b/source/op/prod_force_se_a.cc index d286326c76..a07cd1d02d 100644 --- a/source/op/prod_force_se_a.cc +++ b/source/op/prod_force_se_a.cc @@ -90,13 +90,14 @@ class ProdForceSeAOp : public OpKernel { int in_iter = kk * nloc * ndescrpt * 3; int nlist_iter = kk * nloc * nnei; - prod_force_a_cpu(&force(force_iter), - &net_deriv(net_iter), - &in_deriv(in_iter), - &nlist(nlist_iter), - nloc, - nall, - nnei); + deepmd::prod_force_a_cpu( + &force(force_iter), + &net_deriv(net_iter), + &in_deriv(in_iter), + &nlist(nlist_iter), + nloc, + nall, + nnei); } } private: diff --git a/source/op/prod_force_se_a_grad.cc b/source/op/prod_force_se_a_grad.cc index aa8dd4e62b..59878bf7d9 100644 --- a/source/op/prod_force_se_a_grad.cc +++ b/source/op/prod_force_se_a_grad.cc @@ -87,12 +87,13 @@ class ProdForceSeAGradOp : public OpKernel int nlist_iter = kk * nloc * nnei; int grad_net_iter = kk * nloc * ndescrpt; - prod_force_grad_a_cpu(&grad_net(grad_net_iter), - &grad(grad_iter), - &in_deriv(in_iter), - &nlist(nlist_iter), - nloc, - nnei); + deepmd::prod_force_grad_a_cpu( + &grad_net(grad_net_iter), + &grad(grad_iter), + &in_deriv(in_iter), + &nlist(nlist_iter), + nloc, + nnei); } } private: diff --git a/source/op/prod_force_se_r.cc b/source/op/prod_force_se_r.cc index 8ce34a1489..1aa6d76760 100644 --- a/source/op/prod_force_se_r.cc +++ b/source/op/prod_force_se_r.cc @@ -81,13 +81,14 @@ class ProdForceSeROp : public OpKernel { int in_iter = kk * nloc * ndescrpt * 3; int nlist_iter = kk * nloc * nnei; - prod_force_r_cpu(&force(force_iter), - &net_deriv(net_iter), - &in_deriv(in_iter), - &nlist(nlist_iter), - nloc, - nall, - nnei); + deepmd::prod_force_r_cpu( + &force(force_iter), + &net_deriv(net_iter), + &in_deriv(in_iter), + &nlist(nlist_iter), + nloc, + nall, + nnei); } } }; diff --git a/source/op/prod_force_se_r_grad.cc b/source/op/prod_force_se_r_grad.cc index 039a452e94..be8ebec213 100644 --- a/source/op/prod_force_se_r_grad.cc +++ b/source/op/prod_force_se_r_grad.cc @@ -81,7 +81,7 @@ class ProdForceSeRGradOp : public OpKernel int nlist_iter = kk * nloc * nnei; int grad_net_iter = kk * nloc * ndescrpt; - prod_force_grad_r_cpu( + deepmd::prod_force_grad_r_cpu( &grad_net(grad_net_iter), &grad(grad_iter), &in_deriv(in_iter), diff --git a/source/op/prod_virial_se_a.cc b/source/op/prod_virial_se_a.cc index 454edb2fbd..80223f5e67 100644 --- a/source/op/prod_virial_se_a.cc +++ b/source/op/prod_virial_se_a.cc @@ -91,15 +91,16 @@ class ProdVirialSeAOp : public OpKernel { int virial_iter = kk * 9; int atom_virial_iter = kk * nall * 9; - prod_virial_a_cpu(&virial(virial_iter), - &atom_virial(atom_virial_iter), - &net_deriv(net_iter), - &in_deriv(in_iter), - &rij(rij_iter), - &nlist(nlist_iter), - nloc, - nall, - nnei); + deepmd::prod_virial_a_cpu( + &virial(virial_iter), + &atom_virial(atom_virial_iter), + &net_deriv(net_iter), + &in_deriv(in_iter), + &rij(rij_iter), + &nlist(nlist_iter), + nloc, + nall, + nnei); } } private: diff --git a/source/op/prod_virial_se_a_grad.cc b/source/op/prod_virial_se_a_grad.cc index d1366baf6f..2e6056c09c 100644 --- a/source/op/prod_virial_se_a_grad.cc +++ b/source/op/prod_virial_se_a_grad.cc @@ -95,13 +95,14 @@ class ProdVirialSeAGradOp : public OpKernel int nlist_iter = kk * nloc * nnei; int grad_net_iter = kk * nloc * ndescrpt; - prod_virial_grad_a_cpu(&grad_net(grad_net_iter), - &grad(grad_iter), - &in_deriv(in_iter), - &rij(rij_iter), - &nlist(nlist_iter), - nloc, - nnei); + deepmd::prod_virial_grad_a_cpu( + &grad_net(grad_net_iter), + &grad(grad_iter), + &in_deriv(in_iter), + &rij(rij_iter), + &nlist(nlist_iter), + nloc, + nnei); } } private: diff --git a/source/op/prod_virial_se_r.cc b/source/op/prod_virial_se_r.cc index 4b6285ff48..d063de03a3 100644 --- a/source/op/prod_virial_se_r.cc +++ b/source/op/prod_virial_se_r.cc @@ -84,7 +84,7 @@ class ProdVirialSeROp : public OpKernel { int virial_iter = kk * 9; int atom_virial_iter = kk * nall * 9; - prod_virial_r_cpu( + deepmd::prod_virial_r_cpu( &virial(virial_iter), &atom_virial(atom_virial_iter), &net_deriv(net_iter), diff --git a/source/op/prod_virial_se_r_grad.cc b/source/op/prod_virial_se_r_grad.cc index d900781709..57482f0f8a 100644 --- a/source/op/prod_virial_se_r_grad.cc +++ b/source/op/prod_virial_se_r_grad.cc @@ -89,7 +89,7 @@ class ProdVirialSeRGradOp : public OpKernel int nlist_iter = kk * nloc * nnei; int grad_net_iter = kk * nloc * ndescrpt; - prod_virial_grad_r_cpu( + deepmd::prod_virial_grad_r_cpu( &grad_net(grad_net_iter), &grad(grad_iter), &in_deriv(in_iter), diff --git a/source/op/soft_min.cc b/source/op/soft_min.cc index 4dcedbaea1..cae371fc70 100644 --- a/source/op/soft_min.cc +++ b/source/op/soft_min.cc @@ -91,7 +91,7 @@ class SoftMinSwitchOp : public OpKernel { // loop over samples #pragma omp parallel for for (int kk = 0; kk < nframes; ++kk){ - soft_min_switch_cpu( + deepmd::soft_min_switch_cpu( &sw_value(kk, 0), &sw_deriv(kk, 0), &rij(kk, 0), diff --git a/source/op/soft_min_force.cc b/source/op/soft_min_force.cc index 143d70d5ae..15e5e3b41d 100644 --- a/source/op/soft_min_force.cc +++ b/source/op/soft_min_force.cc @@ -68,7 +68,7 @@ class SoftMinForceOp : public OpKernel { // loop over samples #pragma omp parallel for for (int kk = 0; kk < nframes; ++kk){ - soft_min_switch_force_cpu( + deepmd::soft_min_switch_force_cpu( &force(kk,0), &du(kk,0), &sw_deriv(kk,0), diff --git a/source/op/soft_min_force_grad.cc b/source/op/soft_min_force_grad.cc index 59ccb32351..6a161e4f4d 100644 --- a/source/op/soft_min_force_grad.cc +++ b/source/op/soft_min_force_grad.cc @@ -80,7 +80,7 @@ class SoftMinForceGradOp : public OpKernel // loop over frames #pragma omp parallel for for (int kk = 0; kk < nframes; ++kk){ - soft_min_switch_force_grad_cpu( + deepmd::soft_min_switch_force_grad_cpu( &grad_net(kk,0), &grad(kk,0), &sw_deriv(kk,0), diff --git a/source/op/soft_min_virial.cc b/source/op/soft_min_virial.cc index 05e76d2741..3dcc2e6daa 100644 --- a/source/op/soft_min_virial.cc +++ b/source/op/soft_min_virial.cc @@ -82,7 +82,7 @@ class SoftMinVirialOp : public OpKernel { // loop over samples #pragma omp parallel for for (int kk = 0; kk < nframes; ++kk){ - soft_min_switch_virial_cpu( + deepmd::soft_min_switch_virial_cpu( &virial(kk,0), &atom_virial(kk,0), &du(kk,0), diff --git a/source/op/soft_min_virial_grad.cc b/source/op/soft_min_virial_grad.cc index a115c461e3..c5c5399195 100644 --- a/source/op/soft_min_virial_grad.cc +++ b/source/op/soft_min_virial_grad.cc @@ -87,7 +87,7 @@ class SoftMinVirialGradOp : public OpKernel // loop over frames #pragma omp parallel for for (int kk = 0; kk < nframes; ++kk){ - soft_min_switch_virial_grad_cpu( + deepmd::soft_min_switch_virial_grad_cpu( &grad_net(kk, 0), &grad(kk, 0), &sw_deriv(kk, 0), From cccefd7ca957e1617e89c105c8bfc21601c19be6 Mon Sep 17 00:00:00 2001 From: Han Wang Date: Wed, 17 Mar 2021 08:56:52 +0800 Subject: [PATCH 10/23] fix bug in tests --- source/api_cc/tests/test_deepdipole.cc | 2 +- source/api_cc/tests/test_deeppolar.cc | 2 +- source/api_cc/tests/test_deeppot_a.cc | 8 ++++---- source/api_cc/tests/test_deeppot_model_devi.cc | 4 ++-- source/api_cc/tests/test_deeppot_r.cc | 8 ++++---- source/api_cc/tests/test_dipolecharge.cc | 6 +++--- source/api_cc/tests/test_ewald.cc | 4 ++-- source/api_cc/tests/test_utils.h | 4 ++-- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/source/api_cc/tests/test_deepdipole.cc b/source/api_cc/tests/test_deepdipole.cc index bfdcc1de17..fbc7388f7a 100644 --- a/source/api_cc/tests/test_deepdipole.cc +++ b/source/api_cc/tests/test_deepdipole.cc @@ -88,7 +88,7 @@ TEST_F(TestInferDeepDipole, cpu_lmp_nlist) std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); std::vector > nlist_data; - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); _build_nlist(nlist_data, coord_cpy, atype_cpy, mapping, coord, atype, box, rc); int nall = coord_cpy.size() / 3; diff --git a/source/api_cc/tests/test_deeppolar.cc b/source/api_cc/tests/test_deeppolar.cc index 19e9b8af7c..a76e84179a 100644 --- a/source/api_cc/tests/test_deeppolar.cc +++ b/source/api_cc/tests/test_deeppolar.cc @@ -88,7 +88,7 @@ TEST_F(TestInferDeepPolar, cpu_lmp_nlist) std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); std::vector > nlist_data; - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); _build_nlist(nlist_data, coord_cpy, atype_cpy, mapping, coord, atype, box, rc); int nall = coord_cpy.size() / 3; diff --git a/source/api_cc/tests/test_deeppot_a.cc b/source/api_cc/tests/test_deeppot_a.cc index 77b343f91e..61336c4e33 100644 --- a/source/api_cc/tests/test_deeppot_a.cc +++ b/source/api_cc/tests/test_deeppot_a.cc @@ -183,7 +183,7 @@ TEST_F(TestInferDeepPotA, cpu_lmp_nlist) int nall = coord_cpy.size() / 3; std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_data); double ener; @@ -234,7 +234,7 @@ TEST_F(TestInferDeepPotA, cpu_lmp_nlist_atomic) int nall = coord_cpy.size() / 3; std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_data); double ener; @@ -307,7 +307,7 @@ TEST_F(TestInferDeepPotA, cpu_lmp_nlist_2rc) int nall = coord_cpy.size() / 3; std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_data); double ener; @@ -373,7 +373,7 @@ TEST_F(TestInferDeepPotA, cpu_lmp_nlist_type_sel) int nall = coord_cpy.size() / 3; std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_data); // dp compute diff --git a/source/api_cc/tests/test_deeppot_model_devi.cc b/source/api_cc/tests/test_deeppot_model_devi.cc index f70b66a9eb..678b30a2ea 100644 --- a/source/api_cc/tests/test_deeppot_model_devi.cc +++ b/source/api_cc/tests/test_deeppot_model_devi.cc @@ -93,7 +93,7 @@ TEST_F(TestInferDeepPotModeDevi, cpu_lmp_list) int nall = coord_cpy.size() / 3; std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_data); int nmodel = 2; @@ -170,7 +170,7 @@ TEST_F(TestInferDeepPotModeDevi, cpu_lmp_list_atomic) int nall = coord_cpy.size() / 3; std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_data); int nmodel = 2; diff --git a/source/api_cc/tests/test_deeppot_r.cc b/source/api_cc/tests/test_deeppot_r.cc index e9b1c45c85..2d6af9f6ae 100644 --- a/source/api_cc/tests/test_deeppot_r.cc +++ b/source/api_cc/tests/test_deeppot_r.cc @@ -183,7 +183,7 @@ TEST_F(TestInferDeepPotR, cpu_lmp_nlist) int nall = coord_cpy.size() / 3; std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_data); double ener; @@ -234,7 +234,7 @@ TEST_F(TestInferDeepPotR, cpu_lmp_nlist_atomic) int nall = coord_cpy.size() / 3; std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_data); double ener; @@ -307,7 +307,7 @@ TEST_F(TestInferDeepPotR, cpu_lmp_nlist_2rc) int nall = coord_cpy.size() / 3; std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_data); double ener; @@ -373,7 +373,7 @@ TEST_F(TestInferDeepPotR, cpu_lmp_nlist_type_sel) int nall = coord_cpy.size() / 3; std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_data); // dp compute diff --git a/source/api_cc/tests/test_dipolecharge.cc b/source/api_cc/tests/test_dipolecharge.cc index 9ce16b9442..b13c3c7d7a 100644 --- a/source/api_cc/tests/test_dipolecharge.cc +++ b/source/api_cc/tests/test_dipolecharge.cc @@ -116,7 +116,7 @@ TEST_F(TestDipoleCharge, cpu_lmp_nlist) int nghost = nall - nloc; std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]); convert_nlist(inlist, nlist_data); // evaluate dipole @@ -174,9 +174,9 @@ TEST_F(TestDipoleCharge, cpu_lmp_nlist) // compute the recp part of the ele interaction double eener; std::vector eforce, evirial; - Region region; + deepmd::Region region; init_region_cpu(region, &box[0]); - EwaldParameters eparam; + deepmd::EwaldParameters eparam; eparam.beta = 0.2; eparam.spacing = 4; ewald_recp(eener, eforce, evirial, coord, charge, region, eparam); diff --git a/source/api_cc/tests/test_ewald.cc b/source/api_cc/tests/test_ewald.cc index 73dcbe686e..e27b1087e3 100644 --- a/source/api_cc/tests/test_ewald.cc +++ b/source/api_cc/tests/test_ewald.cc @@ -35,7 +35,7 @@ TEST_F(TestInferEwald, cpu_numfv) class MyModel : public EnergyModelTest { const std::vector & charge; - EwaldParameters eparam; + deepmd::EwaldParameters eparam; public: MyModel( const std::vector & charge_ @@ -48,7 +48,7 @@ TEST_F(TestInferEwald, cpu_numfv) std::vector & virial, const std::vector & coord, const std::vector & box) { - Region region; + deepmd::Region region; init_region_cpu(region, &box[0]); ewald_recp(ener, force, virial, coord, charge, region, eparam); } diff --git a/source/api_cc/tests/test_utils.h b/source/api_cc/tests/test_utils.h index ed4b40b5ff..e6a496e374 100644 --- a/source/api_cc/tests/test_utils.h +++ b/source/api_cc/tests/test_utils.h @@ -90,13 +90,13 @@ class EnergyModelTest VALUETYPE ener; std::vector force, virial; compute(ener, force, virial, coord, box); - Region region; + deepmd::Region region; init_region_cpu(region, &box[0]); for(int ii = 0; ii < 9; ++ii){ std::vector box0(box), box1(box); box0[ii] += hh; box1[ii] -= hh; - Region region0, region1; + deepmd::Region region0, region1; init_region_cpu(region0, &box0[0]); init_region_cpu(region1, &box1[0]); std::vector coord0(coord), coord1(coord); From 122875771b81ea0663ac538507c27791f88b8efa Mon Sep 17 00:00:00 2001 From: Han Wang Date: Wed, 17 Mar 2021 09:52:38 +0800 Subject: [PATCH 11/23] fix bugs in multi_device ops --- source/op/gelu_multi_device.cc | 6 +++--- source/op/prod_env_mat_multi_device.cc | 10 +++++----- source/op/prod_force_multi_device.cc | 8 ++++---- source/op/prod_virial_multi_device.cc | 10 +++++----- source/op/tabulate_multi_device.cc | 8 ++++---- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/source/op/gelu_multi_device.cc b/source/op/gelu_multi_device.cc index 5923ee5675..ece0d07ab3 100644 --- a/source/op/gelu_multi_device.cc +++ b/source/op/gelu_multi_device.cc @@ -45,7 +45,7 @@ class GeluOp : public OpKernel { if (device == "GPU") { #if GOOGLE_CUDA - gelu_gpu_cuda( + deepmd::gelu_gpu_cuda( out, x, size); #endif // GOOGLE_CUDA @@ -88,7 +88,7 @@ class GeluGradOp : public OpKernel { if (device == "GPU") { #if GOOGLE_CUDA - gelu_grad_gpu_cuda( + deepmd::gelu_grad_gpu_cuda( out, x, dy, size); #endif // GOOGLE_CUDA @@ -129,7 +129,7 @@ class GeluGradGradOp : public OpKernel { if (device == "GPU") { #if GOOGLE_CUDA - gelu_grad_grad_gpu_cuda( + deepmd::gelu_grad_grad_gpu_cuda( out, x, dy, dy_2, size); #endif // GOOGLE_CUDA diff --git a/source/op/prod_env_mat_multi_device.cc b/source/op/prod_env_mat_multi_device.cc index c0423db358..10b3f837b0 100644 --- a/source/op/prod_env_mat_multi_device.cc +++ b/source/op/prod_env_mat_multi_device.cc @@ -273,12 +273,12 @@ class ProdEnvMatAOp : public OpKernel { // update nbor list deepmd::InputNlist inlist; inlist.inum = nloc; - env_mat_nbor_update( + deepmd::env_mat_nbor_update( inlist, gpu_inlist, max_nbor_size, nbor_list_dev, mesh_tensor.flat().data(), static_cast(mesh_tensor.NumElements())); OP_REQUIRES (context, (max_numneigh(inlist) <= GPU_MAX_NBOR_SIZE), errors::InvalidArgument ("Assert failed, max neighbor size of atom(lammps) " + std::to_string(max_numneigh(inlist)) + " is larger than " + std::to_string(GPU_MAX_NBOR_SIZE) + ", which currently is not supported by deepmd-kit.")); // launch the gpu(nv) compute function - prod_env_mat_a_gpu_cuda( + deepmd::prod_env_mat_a_gpu_cuda( em, em_deriv, rij, nlist, coord, type, gpu_inlist, array_int, array_longlong, max_nbor_size, avg, std, nloc, nall, rcut_r, rcut_r_smth, sec_a); #endif //GOOGLE_CUDA @@ -300,7 +300,7 @@ class ProdEnvMatAOp : public OpKernel { frame_nall, mem_cpy, mem_nnei, max_nbor_size, box, mesh_tensor.flat().data(), nloc, nei_mode, rcut_r, max_cpy_trial, max_nnei_trial); // launch the cpu compute function - prod_env_mat_a_cpu( + deepmd::prod_env_mat_a_cpu( em, em_deriv, rij, nlist, coord, type, inlist, max_nbor_size, avg, std, nloc, frame_nall, rcut_r, rcut_r_smth, sec_a); // do nlist mapping if coords were copied @@ -483,12 +483,12 @@ class ProdEnvMatROp : public OpKernel { // update nbor list deepmd::InputNlist inlist; inlist.inum = nloc; - env_mat_nbor_update( + deepmd::env_mat_nbor_update( inlist, gpu_inlist, max_nbor_size, nbor_list_dev, mesh_tensor.flat().data(), static_cast(mesh_tensor.NumElements())); OP_REQUIRES (context, (max_numneigh(inlist) <= GPU_MAX_NBOR_SIZE), errors::InvalidArgument ("Assert failed, max neighbor size of atom(lammps) " + std::to_string(max_numneigh(inlist)) + " is larger than " + std::to_string(GPU_MAX_NBOR_SIZE) + ", which currently is not supported by deepmd-kit.")); // launch the gpu(nv) compute function - prod_env_mat_r_gpu_cuda( + deepmd::prod_env_mat_r_gpu_cuda( em, em_deriv, rij, nlist, coord, type, gpu_inlist, array_int, array_longlong, max_nbor_size, avg, std, nloc, nall, rcut, rcut_smth, sec); #endif //GOOGLE_CUDA diff --git a/source/op/prod_force_multi_device.cc b/source/op/prod_force_multi_device.cc index 209a12639f..29af42379a 100644 --- a/source/op/prod_force_multi_device.cc +++ b/source/op/prod_force_multi_device.cc @@ -78,13 +78,13 @@ class ProdForceSeAOp : public OpKernel { if (device == "GPU") { #if GOOGLE_CUDA - prod_force_a_gpu_cuda( + deepmd::prod_force_a_gpu_cuda( force, net_deriv, in_deriv, nlist, nloc, nall, nnei); #endif // GOOGLE_CUDA } else if (device == "CPU") { - prod_force_a_cpu( + deepmd::prod_force_a_cpu( force, net_deriv, in_deriv, nlist, nloc, nall, nnei); } @@ -151,13 +151,13 @@ class ProdForceSeROp : public OpKernel { if (device == "GPU") { #if GOOGLE_CUDA - prod_force_r_gpu_cuda( + deepmd::prod_force_r_gpu_cuda( force, net_deriv, in_deriv, nlist, nloc, nall, nnei); #endif // GOOGLE_CUDA } else if (device == "CPU") { - prod_force_r_cpu( + deepmd::prod_force_r_cpu( force, net_deriv, in_deriv, nlist, nloc, nall, nnei); } diff --git a/source/op/prod_virial_multi_device.cc b/source/op/prod_virial_multi_device.cc index 9aab65443c..9e16437b44 100644 --- a/source/op/prod_virial_multi_device.cc +++ b/source/op/prod_virial_multi_device.cc @@ -86,13 +86,13 @@ class ProdVirialSeAOp : public OpKernel { if (device == "GPU") { #if GOOGLE_CUDA - prod_virial_a_gpu_cuda( + deepmd::prod_virial_a_gpu_cuda( virial, atom_virial, net_deriv, in_deriv, rij, nlist, nloc, nall, nnei); #endif // GOOGLE_CUDA } else if (device == "CPU") { - prod_virial_a_cpu( + deepmd::prod_virial_a_cpu( virial, atom_virial, net_deriv, in_deriv, rij, nlist, nloc, nall, nnei); } @@ -164,13 +164,13 @@ class ProdVirialSeROp : public OpKernel { if (device == "GPU") { #if GOOGLE_CUDA - prod_virial_r_gpu_cuda( + deepmd::prod_virial_r_gpu_cuda( virial, atom_virial, net_deriv, in_deriv, rij, nlist, nloc, nall, nnei); #endif // GOOGLE_CUDA } else if (device == "CPU") { - prod_virial_r_cpu( + deepmd::prod_virial_r_cpu( virial, atom_virial, net_deriv, in_deriv, rij, nlist, nloc, nall, nnei); } @@ -200,4 +200,4 @@ REGISTER_KERNEL_BUILDER( ProdVirialSeROp); REGISTER_GPU(float); REGISTER_GPU(double); -#endif // GOOGLE_CUDA \ No newline at end of file +#endif // GOOGLE_CUDA diff --git a/source/op/tabulate_multi_device.cc b/source/op/tabulate_multi_device.cc index b4e891518d..8d8f9e82d6 100644 --- a/source/op/tabulate_multi_device.cc +++ b/source/op/tabulate_multi_device.cc @@ -63,13 +63,13 @@ class TabulateFusionOp : public OpKernel { if (device == "GPU") { #if GOOGLE_CUDA - tabulate_fusion_gpu_cuda( + deepmd::tabulate_fusion_gpu_cuda( descriptor, table, table_info, em_x, em, nloc, nnei, last_layer_size); #endif // GOOGLE_CUDA } else if (device == "CPU") { - tabulate_fusion_cpu( + deepmd::tabulate_fusion_cpu( descriptor, table, table_info, em_x, em, nloc, nnei, last_layer_size); } @@ -125,13 +125,13 @@ class TabulateFusionGradOp : public OpKernel { if (device == "GPU") { #if GOOGLE_CUDA - tabulate_fusion_grad_gpu_cuda( + deepmd::tabulate_fusion_grad_gpu_cuda( dy_dem_x, dy_dem, table, table_info, em_x, em, dy, nloc, nnei, last_layer_size); #endif // GOOGLE_CUDA } else if (device == "CPU") { - tabulate_fusion_grad_cpu( + deepmd::tabulate_fusion_grad_cpu( dy_dem_x, dy_dem, table, table_info, em_x, em, dy, nloc, nnei, last_layer_size); } From 9ec178631ea4475f053da657c6fa7247a2c9c491 Mon Sep 17 00:00:00 2001 From: Han Wang Date: Wed, 17 Mar 2021 10:19:00 +0800 Subject: [PATCH 12/23] namespace for tabulate and utilities --- source/api_cc/src/DeepPot.cc | 4 +- source/lib/include/ComputeDescriptor.h | 92 +++++++++++----------- source/lib/include/SimulationRegion_Impl.h | 12 +-- source/lib/include/tabulate.h | 5 ++ source/lib/include/utilities.h | 3 + source/lib/src/env_mat.cc | 8 +- source/lib/src/ewald.cc | 2 +- source/lib/src/fmt_nlist.cc | 4 +- source/lib/src/neighbor_list.cc | 8 +- source/lib/src/tabulate.cc | 12 +-- source/lib/src/utilities.cc | 4 +- source/lib/tests/test_tabulate.cc | 10 +-- source/op/descrpt.cc | 10 +-- source/op/prod_env_mat_multi_device.cc | 8 +- 14 files changed, 95 insertions(+), 87 deletions(-) diff --git a/source/api_cc/src/DeepPot.cc b/source/api_cc/src/DeepPot.cc index 9a3e8d7a10..b9412a505b 100644 --- a/source/api_cc/src/DeepPot.cc +++ b/source/api_cc/src/DeepPot.cc @@ -908,7 +908,7 @@ compute_std_f (std::vector & std, vdiff[0] = tmp_f[0] - tmp_avg[0]; vdiff[1] = tmp_f[1] - tmp_avg[1]; vdiff[2] = tmp_f[2] - tmp_avg[2]; - std[jj] += dot3(vdiff, vdiff); + std[jj] += deepmd::dot3(vdiff, vdiff); } } @@ -931,7 +931,7 @@ compute_relative_std_f (std::vector &std, vdiff[0] = tmp_avg[0]; vdiff[1] = tmp_avg[1]; vdiff[2] = tmp_avg[2]; - VALUETYPE f_norm = sqrt(dot3(vdiff, vdiff)); + VALUETYPE f_norm = sqrt(deepmd::dot3(vdiff, vdiff)); // relative std = std/(abs(f)+eps) std[ii] /= f_norm + eps; } diff --git a/source/lib/include/ComputeDescriptor.h b/source/lib/include/ComputeDescriptor.h index 7d4d6e0c3a..8bc246881a 100644 --- a/source/lib/include/ComputeDescriptor.h +++ b/source/lib/include/ComputeDescriptor.h @@ -110,11 +110,11 @@ compute_dRdT (double (* dRdT)[9], const double *xx = rot; const double *yy = rot+3; - double nr1 = sqrt(dot3(r1, r1)); + double nr1 = sqrt(deepmd::dot3(r1, r1)); double nr12 = nr1 * nr1; double nr13 = nr1 * nr12; double nr14 = nr12 * nr12; - double r1dr2 = dot3(r1, r2); + double r1dr2 = deepmd::dot3(r1, r2); // dRdT0 for (int ii = 0; ii < 3; ++ii){ @@ -137,7 +137,7 @@ compute_dRdT (double (* dRdT)[9], } double tmpy[3]; for (int dd = 0; dd < 3; ++dd) tmpy[dd] = r2[dd] - r1dr2 / nr12 * r1[dd]; - double ntmpy = sqrt(dot3(tmpy, tmpy)); + double ntmpy = sqrt(deepmd::dot3(tmpy, tmpy)); double ydRdy [3] = {0}; for (int ii = 0; ii < 3; ++ii){ for (int jj = 0; jj < 3; ++jj){ @@ -153,8 +153,8 @@ compute_dRdT (double (* dRdT)[9], // dRdT2 for (int ii = 0; ii < 3; ++ii){ double res[3]; - cprod(dRdT0 + ii*3, yy, dRdT2 + ii*3); - cprod(xx, dRdT1 + ii*3, res); + deepmd::cprod(dRdT0 + ii*3, yy, dRdT2 + ii*3); + deepmd::cprod(xx, dRdT1 + ii*3, res); for (int dd = 0; dd < 3; ++dd) dRdT2[ii*3+dd] += res[dd]; } } @@ -171,11 +171,11 @@ compute_dRdT_1 (double (* dRdT)[9], const double *xx = rot; const double *yy = rot+3; - double nr1 = sqrt(dot3(r1, r1)); + double nr1 = sqrt(deepmd::dot3(r1, r1)); double nr12 = nr1 * nr1; double nr13 = nr1 * nr12; double nr14 = nr12 * nr12; - double r1dr2 = dot3(r1, r2); + double r1dr2 = deepmd::dot3(r1, r2); // dRdT0 for (int ii = 0; ii < 3; ++ii){ @@ -198,7 +198,7 @@ compute_dRdT_1 (double (* dRdT)[9], } double tmpy[3]; for (int dd = 0; dd < 3; ++dd) tmpy[dd] = r2[dd] - r1dr2 / nr12 * r1[dd]; - double ntmpy = sqrt(dot3(tmpy, tmpy)); + double ntmpy = sqrt(deepmd::dot3(tmpy, tmpy)); double ydRdy [3] = {0}; for (int ii = 0; ii < 3; ++ii){ for (int jj = 0; jj < 3; ++jj){ @@ -214,8 +214,8 @@ compute_dRdT_1 (double (* dRdT)[9], // dRdT2 for (int ii = 0; ii < 3; ++ii){ double res[3]; - cprod(dRdT0 + ii*3, yy, dRdT2 + ii*3); - cprod(xx, dRdT1 + ii*3, res); + deepmd::cprod(dRdT0 + ii*3, yy, dRdT2 + ii*3); + deepmd::cprod(xx, dRdT1 + ii*3, res); for (int dd = 0; dd < 3; ++dd) dRdT2[ii*3+dd] += res[dd]; } } @@ -233,9 +233,9 @@ compute_dRdT_2 (double (* dRdT)[9], const double *xx = rot; const double *yy = rot+3; - double nr1 = sqrt(dot3(r1, r1)); + double nr1 = sqrt(deepmd::dot3(r1, r1)); double nr12 = nr1 * nr1; - double r1dr2 = dot3(r1, r2); + double r1dr2 = deepmd::dot3(r1, r2); // dRdT0 for (int ii = 0; ii < 3; ++ii){ @@ -256,7 +256,7 @@ compute_dRdT_2 (double (* dRdT)[9], } double tmpy[3]; for (int dd = 0; dd < 3; ++dd) tmpy[dd] = r2[dd] - r1dr2 / nr12 * r1[dd]; - double ntmpy = sqrt(dot3(tmpy, tmpy)); + double ntmpy = sqrt(deepmd::dot3(tmpy, tmpy)); double ydRdy [3] = {0}; for (int ii = 0; ii < 3; ++ii){ for (int jj = 0; jj < 3; ++jj){ @@ -272,8 +272,8 @@ compute_dRdT_2 (double (* dRdT)[9], // dRdT2 for (int ii = 0; ii < 3; ++ii){ double res[3]; - cprod(dRdT0 + ii*3, yy, dRdT2 + ii*3); - cprod(xx, dRdT1 + ii*3, res); + deepmd::cprod(dRdT0 + ii*3, yy, dRdT2 + ii*3); + deepmd::cprod(xx, dRdT1 + ii*3, res); for (int dd = 0; dd < 3; ++dd) dRdT2[ii*3+dd] += res[dd]; } } @@ -353,7 +353,7 @@ void compute_descriptor (std::vector & descrpt_a, // cout << jj << "\t jidx " << j_idx; // if (j_idx >= 0){ // cout << "\t type " << type[j_idx]; - // cout << "\t " << sqrt(dot3(&sel_a_diff[jj][0], &sel_a_diff[jj][0])); + // cout << "\t " << sqrt(deepmd::dot3(&sel_a_diff[jj][0], &sel_a_diff[jj][0])); // } // cout << endl; // } @@ -365,7 +365,7 @@ void compute_descriptor (std::vector & descrpt_a, // cout << jj << "\t jidx " << j_idx; // if (j_idx >= 0){ // cout << "\t type " << type[j_idx]; - // cout << "\t " << sqrt(dot3(&sel_r_diff[jj][0], &sel_r_diff[jj][0])); + // cout << "\t " << sqrt(deepmd::dot3(&sel_r_diff[jj][0], &sel_r_diff[jj][0])); // } // cout << endl; // } @@ -402,13 +402,13 @@ void compute_descriptor (std::vector & descrpt_a, xx[dd] = r1[dd]; yy[dd] = r2[dd]; } - double norm_xx = sqrt(dot3(xx, xx)); + double norm_xx = sqrt(deepmd::dot3(xx, xx)); for (unsigned dd = 0; dd < 3; ++dd) xx[dd] /= norm_xx; - double dxy = dot3(xx, yy); + double dxy = deepmd::dot3(xx, yy); for (unsigned dd = 0; dd < 3; ++dd) yy[dd] -= dxy * xx[dd]; - double norm_yy = sqrt(dot3(yy, yy)); + double norm_yy = sqrt(deepmd::dot3(yy, yy)); for (unsigned dd = 0; dd < 3; ++dd) yy[dd] /= norm_yy; - cprod(xx, yy, zz); + deepmd::cprod(xx, yy, zz); rot_mat.resize (9); for (int dd = 0; dd < 9; ++dd) rot_mat[dd] = rot[dd]; @@ -419,8 +419,8 @@ void compute_descriptor (std::vector & descrpt_a, for (int jj = sec_a[ii]; jj < sec_a[ii+1]; ++jj){ if (fmt_nlist_a[jj] < 0) break; double rdiff[3] ; - dotmv3(rdiff, rot, &sel_a_diff[jj][0]); - double rr2 = dot3(rdiff, rdiff); + deepmd::dotmv3(rdiff, rot, &sel_a_diff[jj][0]); + double rr2 = deepmd::dot3(rdiff, rdiff); double rr = sqrt(rr2); #ifdef DESCRPT_THETAPHI double cos_theta = rdiff[2] / rr; @@ -445,7 +445,7 @@ void compute_descriptor (std::vector & descrpt_a, for (int jj = sec_r[ii]; jj < sec_r[ii+1]; ++jj){ if (fmt_nlist_r[jj] < 0) break; const double *rdiff = &sel_r_diff[jj][0]; - double rr = sqrt (dot3(rdiff, rdiff)); + double rr = sqrt (deepmd::dot3(rdiff, rdiff)); descrpt_r[jj] = 1./rr; } } @@ -474,8 +474,8 @@ void compute_descriptor (std::vector & descrpt_a, double dtrdST[4][3]; double * rr = &sel_a_diff[nei_iter][0]; double tr[3] ; - dotmv3(tr, rot, rr); - double nr2 = dot3(tr, tr); + deepmd::dotmv3(tr, rot, rr); + double nr2 = deepmd::dot3(tr, tr); double nr = sqrt(nr2); double nr3 = nr * nr2; for (int dd = 0; dd < 3; ++dd){ @@ -601,7 +601,7 @@ void compute_descriptor (std::vector & descrpt_a, if (fmt_nlist_r[nei_iter] < 0) break; const double * rr = &sel_r_diff[nei_iter][0]; - double nr = sqrt(dot3(rr, rr)); + double nr = sqrt(deepmd::dot3(rr, rr)); double nr3 = nr * nr * nr; int idx = nei_iter * 12; @@ -699,13 +699,13 @@ void compute_descriptor (std::vector & descrpt_a, xx[dd] = r1[dd]; yy[dd] = r2[dd]; } - double norm_xx = sqrt(dot3(xx, xx)); + double norm_xx = sqrt(deepmd::dot3(xx, xx)); for (unsigned dd = 0; dd < 3; ++dd) xx[dd] /= norm_xx; - double dxy = dot3(xx, yy); + double dxy = deepmd::dot3(xx, yy); for (unsigned dd = 0; dd < 3; ++dd) yy[dd] -= dxy * xx[dd]; - double norm_yy = sqrt(dot3(yy, yy)); + double norm_yy = sqrt(deepmd::dot3(yy, yy)); for (unsigned dd = 0; dd < 3; ++dd) yy[dd] /= norm_yy; - cprod(xx, yy, zz); + deepmd::cprod(xx, yy, zz); rot_mat.resize (9); for (int dd = 0; dd < 9; ++dd) rot_mat[dd] = rot[dd]; @@ -716,8 +716,8 @@ void compute_descriptor (std::vector & descrpt_a, for (int jj = sec_a[ii]; jj < sec_a[ii+1]; ++jj){ if (fmt_nlist_a[jj] < 0) break; double rdiff[3] ; - dotmv3(rdiff, rot, &sel_a_diff[jj][0]); - double rr2 = dot3(rdiff, rdiff); + deepmd::dotmv3(rdiff, rot, &sel_a_diff[jj][0]); + double rr2 = deepmd::dot3(rdiff, rdiff); double rr = sqrt(rr2); #ifdef DESCRPT_THETAPHI double cos_theta = rdiff[2] / rr; @@ -742,8 +742,8 @@ void compute_descriptor (std::vector & descrpt_a, for (int jj = sec_r[ii]; jj < sec_r[ii+1]; ++jj){ if (fmt_nlist_r[jj] < 0) break; double rdiff[3] ; - dotmv3(rdiff, rot, &sel_r_diff[jj][0]); - double rr = sqrt (dot3(rdiff, rdiff)); + deepmd::dotmv3(rdiff, rot, &sel_r_diff[jj][0]); + double rr = sqrt (deepmd::dot3(rdiff, rdiff)); descrpt_r[jj] = 1./rr; } } @@ -784,7 +784,7 @@ void compute_descriptor_se_a_extf (std::vector & descrpt_a, ef[ii] = ef_[ii]; } } - assert( fabs(dot3(ef, ef) - 1.0) < 1e-12 ), "ef should be a normalized std::vector"; + assert( fabs(deepmd::dot3(ef, ef) - 1.0) < 1e-12 ), "ef should be a normalized std::vector"; // compute the diff of the neighbors std::vector > sel_a_diff (sec_a.back()); @@ -819,7 +819,7 @@ void compute_descriptor_se_a_extf (std::vector & descrpt_a, if (fmt_nlist_a[nei_iter] < 0) break; const double * rr = &sel_a_diff[nei_iter][0]; // check validity of ef - double nr2 = dot3(rr, rr); + double nr2 = deepmd::dot3(rr, rr); double inr = 1./sqrt(nr2); double nr = nr2 * inr; double inr2 = inr * inr; @@ -830,7 +830,7 @@ void compute_descriptor_se_a_extf (std::vector & descrpt_a, int idx_deriv = nei_iter * 4 * 3; // 4 components time 3 directions int idx_value = nei_iter * 4; // 4 components // projections - double rp = dot3(rr, ef); + double rp = deepmd::dot3(rr, ef); double rv[3]; rv[0] = rr[0] - rp * ef[0]; rv[1] = rr[1] - rp * ef[1]; @@ -893,7 +893,7 @@ void compute_descriptor_se_a_ef_para (std::vector & descrpt_a, ef[ii] = ef_[ii]; } } - assert( fabs(dot3(ef, ef) - 1.0) < 1e-12 ), "ef should be a normalized vector"; + assert( fabs(deepmd::dot3(ef, ef) - 1.0) < 1e-12 ), "ef should be a normalized vector"; // compute the diff of the neighbors std::vector > sel_a_diff (sec_a.back()); @@ -928,7 +928,7 @@ void compute_descriptor_se_a_ef_para (std::vector & descrpt_a, if (fmt_nlist_a[nei_iter] < 0) break; const double * rr = &sel_a_diff[nei_iter][0]; // check validity of ef - double nr2 = dot3(rr, rr); + double nr2 = deepmd::dot3(rr, rr); double inr = 1./sqrt(nr2); double nr = nr2 * inr; double inr2 = inr * inr; @@ -940,9 +940,9 @@ void compute_descriptor_se_a_ef_para (std::vector & descrpt_a, int idx_value = nei_iter * 4; // 4 components // projections double rp[3]; - rp[0] = dot3(rr, ef) * ef[0]; - rp[1] = dot3(rr, ef) * ef[1]; - rp[2] = dot3(rr, ef) * ef[2]; + rp[0] = deepmd::dot3(rr, ef) * ef[0]; + rp[1] = deepmd::dot3(rr, ef) * ef[1]; + rp[2] = deepmd::dot3(rr, ef) * ef[2]; // 4 value components descrpt_a[idx_value + 0] = 1 / nr; descrpt_a[idx_value + 1] = rp[0] / nr2; @@ -1001,7 +1001,7 @@ void compute_descriptor_se_a_ef_vert (std::vector & descrpt_a, ef[ii] = ef_[ii]; } } - assert( fabs(dot3(ef, ef) - 1.0) < 1e-12 ), "ef should be a normalized vector"; + assert( fabs(deepmd::dot3(ef, ef) - 1.0) < 1e-12 ), "ef should be a normalized vector"; // compute the diff of the neighbors std::vector > sel_a_diff (sec_a.back()); @@ -1036,7 +1036,7 @@ void compute_descriptor_se_a_ef_vert (std::vector & descrpt_a, if (fmt_nlist_a[nei_iter] < 0) break; const double * rr = &sel_a_diff[nei_iter][0]; // check validity of ef - double nr2 = dot3(rr, rr); + double nr2 = deepmd::dot3(rr, rr); double inr = 1./sqrt(nr2); double nr = nr2 * inr; double inr2 = inr * inr; @@ -1047,7 +1047,7 @@ void compute_descriptor_se_a_ef_vert (std::vector & descrpt_a, int idx_deriv = nei_iter * 4 * 3; // 4 components time 3 directions int idx_value = nei_iter * 4; // 4 components // projections - double rp = dot3(rr, ef); + double rp = deepmd::dot3(rr, ef); double rv[3]; rv[0] = rr[0] - rp * ef[0]; rv[1] = rr[1] - rp * ef[1]; diff --git a/source/lib/include/SimulationRegion_Impl.h b/source/lib/include/SimulationRegion_Impl.h index d19f1a5650..5b7b8248fd 100644 --- a/source/lib/include/SimulationRegion_Impl.h +++ b/source/lib/include/SimulationRegion_Impl.h @@ -417,12 +417,12 @@ SimulationRegion:: toFaceDistance (double * dd) const { double tmp[3]; - cprod(boxt+3, boxt+6, tmp); - dd[0] = volume * invsqrt(dot3(tmp,tmp)); - cprod(boxt+6, boxt+0, tmp); - dd[1] = volume * invsqrt(dot3(tmp,tmp)); - cprod(boxt+0, boxt+3, tmp); - dd[2] = volume * invsqrt(dot3(tmp,tmp)); + deepmd::cprod(boxt+3, boxt+6, tmp); + dd[0] = volume * deepmd::invsqrt(deepmd::dot3(tmp,tmp)); + deepmd::cprod(boxt+6, boxt+0, tmp); + dd[1] = volume * deepmd::invsqrt(deepmd::dot3(tmp,tmp)); + deepmd::cprod(boxt+0, boxt+3, tmp); + dd[2] = volume * deepmd::invsqrt(deepmd::dot3(tmp,tmp)); } // static int tmp_count = 0; diff --git a/source/lib/include/tabulate.h b/source/lib/include/tabulate.h index 77507ec8eb..b684be3c4c 100644 --- a/source/lib/include/tabulate.h +++ b/source/lib/include/tabulate.h @@ -1,5 +1,7 @@ #pragma once +namespace deepmd{ + template void tabulate_fusion_cpu( FPTYPE * out, @@ -49,3 +51,6 @@ void tabulate_fusion_grad_gpu_cuda( const int nnei, const int last_layer_size); #endif // GOOGLE_CUDA + +} + diff --git a/source/lib/include/utilities.h b/source/lib/include/utilities.h index 08a808ac11..e95ca3e684 100644 --- a/source/lib/include/utilities.h +++ b/source/lib/include/utilities.h @@ -5,6 +5,8 @@ #include #include +namespace deepmd{ + void cum_sum( std::vector & sec, const std::vector & n_sel); @@ -74,3 +76,4 @@ invsqrt (const float x) return 1./sqrtf (x); } +} diff --git a/source/lib/src/env_mat.cc b/source/lib/src/env_mat.cc index 52398a17a8..7b0d3e4140 100644 --- a/source/lib/src/env_mat.cc +++ b/source/lib/src/env_mat.cc @@ -50,7 +50,7 @@ void env_mat_a ( for (int nei_iter = sec_a[sec_iter]; nei_iter < sec_a[sec_iter+1]; ++nei_iter) { if (fmt_nlist_a[nei_iter] < 0) break; const double * rr = &sel_a_diff[nei_iter][0]; - double nr2 = dot3(rr, rr); + double nr2 = deepmd::dot3(rr, rr); double inr = 1./sqrt(nr2); double nr = nr2 * inr; double inr2 = inr * inr; @@ -129,7 +129,7 @@ env_mat_a_cpu ( for (int nei_iter = sec_a[sec_iter]; nei_iter < sec_a[sec_iter+1]; ++nei_iter) { if (fmt_nlist_a[nei_iter] < 0) break; const FPTYPE * rr = &rij_a[nei_iter * 3]; - FPTYPE nr2 = dot3(rr, rr); + FPTYPE nr2 = deepmd::dot3(rr, rr); FPTYPE inr = 1./sqrt(nr2); FPTYPE nr = nr2 * inr; FPTYPE inr2 = inr * inr; @@ -217,7 +217,7 @@ void env_mat_r ( for (int nei_iter = sec[sec_iter]; nei_iter < sec[sec_iter+1]; ++nei_iter) { if (fmt_nlist[nei_iter] < 0) break; const double * rr = &sel_diff[nei_iter][0]; - double nr2 = dot3(rr, rr); + double nr2 = deepmd::dot3(rr, rr); double inr = 1./sqrt(nr2); double nr = nr2 * inr; double inr2 = inr * inr; @@ -278,7 +278,7 @@ env_mat_r_cpu ( for (int nei_iter = sec[sec_iter]; nei_iter < sec[sec_iter+1]; ++nei_iter) { if (fmt_nlist[nei_iter] < 0) break; const FPTYPE * rr = &rij_a[nei_iter * 3]; - FPTYPE nr2 = dot3(rr, rr); + FPTYPE nr2 = deepmd::dot3(rr, rr); FPTYPE inr = 1./sqrt(nr2); FPTYPE nr = nr2 * inr; FPTYPE inr2 = inr * inr; diff --git a/source/lib/src/ewald.cc b/source/lib/src/ewald.cc index 5942f6fedc..486d2cbb73 100644 --- a/source/lib/src/ewald.cc +++ b/source/lib/src/ewald.cc @@ -72,7 +72,7 @@ cmpt_k(std::vector & KK, { KK.resize(3); for (int dd = 0; dd < 3; ++dd){ - VALUETYPE ll = sqrt(dot3(boxt+dd*3, boxt+dd*3)); + VALUETYPE ll = sqrt(deepmd::dot3(boxt+dd*3, boxt+dd*3)); KK[dd] = ll / param.spacing; // KK[dd] should be large enough if (KK[dd] * param.spacing < ll) KK[dd] += 1; diff --git a/source/lib/src/fmt_nlist.cc b/source/lib/src/fmt_nlist.cc index 2c577c2f05..add83dadcf 100644 --- a/source/lib/src/fmt_nlist.cc +++ b/source/lib/src/fmt_nlist.cc @@ -72,7 +72,7 @@ int format_nlist_i_fill_a ( else { for (int dd = 0; dd < 3; ++dd) diff[dd] = posi[j_idx*3+dd] - posi[i_idx*3+dd]; } - double rr = sqrt(dot3(diff, diff)); + double rr = sqrt(deepmd::dot3(diff, diff)); if (rr <= rcut) { sel_nei.push_back(NeighborInfo (type[j_idx], rr, j_idx)); } @@ -125,7 +125,7 @@ int format_nlist_i_cpu ( for (int dd = 0; dd < 3; ++dd) { diff[dd] = posi[j_idx * 3 + dd] - posi[i_idx * 3 + dd]; } - FPTYPE rr = sqrt(dot3(diff, diff)); + FPTYPE rr = sqrt(deepmd::dot3(diff, diff)); if (rr <= rcut) { sel_nei.push_back(NeighborInfo(type[j_idx], rr, j_idx)); } diff --git a/source/lib/src/neighbor_list.cc b/source/lib/src/neighbor_list.cc index e426d63906..e0ceae4a38 100644 --- a/source/lib/src/neighbor_list.cc +++ b/source/lib/src/neighbor_list.cc @@ -213,7 +213,7 @@ build_nlist_cell (std::vector > & nlist0, diff[dd0] += shift[dd1] * boxt[3*dd1+dd0]; } } - double r2 = dot3(diff, diff); + double r2 = deepmd::dot3(diff, diff); if (r2 < rc02) { if (i_idx < nloc) nlist0[i_idx].push_back (j_idx); if (j_idx < nloc) nlist0[j_idx].push_back (i_idx); @@ -254,7 +254,7 @@ build_nlist_cell (std::vector > & nlist0, diff[dd0] += shift[dd1] * boxt[3*dd1+dd0]; } } - double r2 = dot3(diff, diff); + double r2 = deepmd::dot3(diff, diff); if (r2 < rc02) { nlist0[i_idx].push_back (j_idx); } @@ -612,7 +612,7 @@ build_nlist (std::vector > & nlist0, diff[1] = posi3[jj*3+1] - posi3[ii*3+1]; diff[2] = posi3[jj*3+2] - posi3[ii*3+2]; } - double r2 = dot3(diff, diff); + double r2 = deepmd::dot3(diff, diff); if (r2 < rc02) { nlist0[ii].push_back (jj); nlist0[jj].push_back (ii); @@ -800,7 +800,7 @@ build_nlist_cpu( for(int dd = 0; dd < 3; ++dd){ diff[dd] = c_cpy[ii*3+dd] - c_cpy[jj*3+dd]; } - FPTYPE diff2 = dot3(diff, diff); + FPTYPE diff2 = deepmd::dot3(diff, diff); if(diff2 < rcut2){ jlist.push_back(jj); } diff --git a/source/lib/src/tabulate.cc b/source/lib/src/tabulate.cc index 98b561a348..b1049226d3 100644 --- a/source/lib/src/tabulate.cc +++ b/source/lib/src/tabulate.cc @@ -51,7 +51,7 @@ inline FPTYPE dot( } template -void tabulate_fusion_cpu( +void deepmd::tabulate_fusion_cpu( FPTYPE * out, const FPTYPE * table, const FPTYPE * table_info, @@ -112,7 +112,7 @@ void tabulate_fusion_cpu( } template -void tabulate_fusion_grad_cpu( +void deepmd::tabulate_fusion_grad_cpu( FPTYPE * dy_dem_x, FPTYPE * dy_dem, const FPTYPE * table, @@ -186,7 +186,7 @@ void tabulate_fusion_grad_cpu( } } -template void tabulate_fusion_cpu(float * out, const float * table, const float * table_info, const float * em_x, const float * em, const int nloc, const int nnei, const int last_layer_size); -template void tabulate_fusion_cpu(double * out, const double * table, const double * table_info, const double * em_x, const double * em, const int nloc, const int nnei, const int last_layer_size); -template void tabulate_fusion_grad_cpu (float * dy_dem_x, float * dy_dem, const float * table, const float * table_info, const float * em_x, const float * em, const float * dy, const int nloc, const int nnei, const int last_layer_size); -template void tabulate_fusion_grad_cpu (double * dy_dem_x, double * dy_dem, const double * table, const double * table_info, const double * em_x, const double * em, const double * dy, const int nloc, const int nnei, const int last_layer_size); +template void deepmd::tabulate_fusion_cpu(float * out, const float * table, const float * table_info, const float * em_x, const float * em, const int nloc, const int nnei, const int last_layer_size); +template void deepmd::tabulate_fusion_cpu(double * out, const double * table, const double * table_info, const double * em_x, const double * em, const int nloc, const int nnei, const int last_layer_size); +template void deepmd::tabulate_fusion_grad_cpu (float * dy_dem_x, float * dy_dem, const float * table, const float * table_info, const float * em_x, const float * em, const float * dy, const int nloc, const int nnei, const int last_layer_size); +template void deepmd::tabulate_fusion_grad_cpu (double * dy_dem_x, double * dy_dem, const double * table, const double * table_info, const double * em_x, const double * em, const double * dy, const int nloc, const int nnei, const int last_layer_size); diff --git a/source/lib/src/utilities.cc b/source/lib/src/utilities.cc index 2176715938..df7bac98f5 100644 --- a/source/lib/src/utilities.cc +++ b/source/lib/src/utilities.cc @@ -1,7 +1,7 @@ #include "utilities.h" // functions used in custom ops -void cum_sum( +void deepmd::cum_sum( std::vector & sec, const std::vector & n_sel) { @@ -10,4 +10,4 @@ void cum_sum( for (int ii = 1; ii < sec.size(); ++ii) { sec[ii] = sec[ii-1] + n_sel[ii-1]; } -} \ No newline at end of file +} diff --git a/source/lib/tests/test_tabulate.cc b/source/lib/tests/test_tabulate.cc index a17f2474b7..f92629efb4 100644 --- a/source/lib/tests/test_tabulate.cc +++ b/source/lib/tests/test_tabulate.cc @@ -147,7 +147,7 @@ class TestTabulate : public ::testing::Test TEST_F(TestTabulate, tabulate_fusion_cpu) { std::vector xyz_scatter(nloc * nnei * last_layer_size); - tabulate_fusion_cpu(&xyz_scatter[0], &table[0], &info[0], &em_x[0], &em[0], nloc, nnei, last_layer_size); + deepmd::tabulate_fusion_cpu(&xyz_scatter[0], &table[0], &info[0], &em_x[0], &em[0], nloc, nnei, last_layer_size); EXPECT_EQ(xyz_scatter.size(), nloc * nnei * last_layer_size); EXPECT_EQ(xyz_scatter.size(), expected_xyz_scatter.size()); for (int jj = 0; jj < xyz_scatter.size(); ++jj){ @@ -160,7 +160,7 @@ TEST_F(TestTabulate, tabulate_fusion_grad_cpu) std::vector dy_dem_x(em_x.size()); std::vector dy_dem(em.size()); std::vector dy(nloc * nnei * last_layer_size, 1.0); - tabulate_fusion_grad_cpu(&dy_dem_x[0], &dy_dem[0], &table[0], &info[0], &em_x[0], &em[0], &dy[0], nloc, nnei, last_layer_size); + deepmd::tabulate_fusion_grad_cpu(&dy_dem_x[0], &dy_dem[0], &table[0], &info[0], &em_x[0], &em[0], &dy[0], nloc, nnei, last_layer_size); EXPECT_EQ(dy_dem_x.size(), nloc * nnei); EXPECT_EQ(dy_dem.size(), nloc * nnei * 4); EXPECT_EQ(dy_dem_x.size(), expected_dy_dem_x.size()); @@ -183,7 +183,7 @@ TEST_F(TestTabulate, tabulate_fusion_gpu_cuda) malloc_device_memory_sync(table_dev, table); malloc_device_memory_sync(em_x_dev, em_x); malloc_device_memory_sync(em_dev, em); - tabulate_fusion_gpu_cuda(xyz_scatter_dev, table_dev, &info[0], em_x_dev, em_dev, nloc, nnei, last_layer_size); + deepmd::tabulate_fusion_gpu_cuda(xyz_scatter_dev, table_dev, &info[0], em_x_dev, em_dev, nloc, nnei, last_layer_size); memcpy_device_to_host(xyz_scatter_dev, xyz_scatter); delete_device_memory(xyz_scatter_dev); delete_device_memory(table_dev); @@ -210,7 +210,7 @@ TEST_F(TestTabulate, tabulate_fusion_grad_gpu_cuda) malloc_device_memory_sync(em_x_dev, em_x); malloc_device_memory_sync(em_dev, em); malloc_device_memory_sync(dy_dev, dy); - tabulate_fusion_grad_gpu_cuda(dy_dem_x_dev, dy_dem_dev, table_dev, &info[0], em_x_dev, em_dev, dy_dev, nloc, nnei, last_layer_size); + deepmd::tabulate_fusion_grad_gpu_cuda(dy_dem_x_dev, dy_dem_dev, table_dev, &info[0], em_x_dev, em_dev, dy_dev, nloc, nnei, last_layer_size); memcpy_device_to_host(dy_dem_x_dev, dy_dem_x); memcpy_device_to_host(dy_dem_dev, dy_dem); delete_device_memory(dy_dem_x_dev); @@ -231,4 +231,4 @@ TEST_F(TestTabulate, tabulate_fusion_grad_gpu_cuda) EXPECT_LT(fabs(dy_dem[jj] - expected_dy_dem[jj]) , 1e-5); } } -#endif // GOOGLE_CUDA \ No newline at end of file +#endif // GOOGLE_CUDA diff --git a/source/op/descrpt.cc b/source/op/descrpt.cc index 1cbfb96574..48fc4f3943 100644 --- a/source/op/descrpt.cc +++ b/source/op/descrpt.cc @@ -495,7 +495,7 @@ class DescrptOp : public OpKernel { } } sort_info.push_back (std::pair - (dot3(diff, diff), list_idx) ); + (deepmd::dot3(diff, diff), list_idx) ); } } sort (sort_info.begin(), sort_info.end()); @@ -527,7 +527,7 @@ class DescrptOp : public OpKernel { } } sort_info.push_back (std::pair - (dot3(diff, diff), list_idx) ); + (deepmd::dot3(diff, diff), list_idx) ); } } sort (sort_info.begin(), sort_info.end()); @@ -580,9 +580,9 @@ class DescrptOp : public OpKernel { } } } - compute_t rij = dot3(diff[0], diff[1]); - compute_t rii = dot3(diff[0], diff[0]); - compute_t rjj = dot3(diff[1], diff[1]); + compute_t rij = deepmd::dot3(diff[0], diff[1]); + compute_t rii = deepmd::dot3(diff[0], diff[0]); + compute_t rjj = deepmd::dot3(diff[1], diff[1]); if ( fabs (rij / sqrt(rii * rjj) + 1) < 1e-4 ) { return false; } diff --git a/source/op/prod_env_mat_multi_device.cc b/source/op/prod_env_mat_multi_device.cc index 10b3f837b0..7a26ce2b41 100644 --- a/source/op/prod_env_mat_multi_device.cc +++ b/source/op/prod_env_mat_multi_device.cc @@ -120,8 +120,8 @@ class ProdEnvMatAOp : public OpKernel { OP_REQUIRES_OK(context, context->GetAttr("sel_r", &sel_r)); // OP_REQUIRES_OK(context, context->GetAttr("nloc", &nloc_f)); // OP_REQUIRES_OK(context, context->GetAttr("nall", &nall_f)); - cum_sum (sec_a, sel_a); - cum_sum (sec_r, sel_r); + deepmd::cum_sum (sec_a, sel_a); + deepmd::cum_sum (sec_r, sel_r); ndescrpt_a = sec_a.back() * 4; ndescrpt_r = sec_r.back() * 1; ndescrpt = ndescrpt_a + ndescrpt_r; @@ -336,9 +336,9 @@ class ProdEnvMatROp : public OpKernel { OP_REQUIRES_OK(context, context->GetAttr("rcut", &rcut)); OP_REQUIRES_OK(context, context->GetAttr("rcut_smth", &rcut_smth)); OP_REQUIRES_OK(context, context->GetAttr("sel", &sel)); - cum_sum (sec, sel); + deepmd::cum_sum (sec, sel); sel_null.resize(3, 0); - cum_sum (sec_null, sel_null); + deepmd::cum_sum (sec_null, sel_null); ndescrpt = sec.back() * 1; nnei = sec.back(); max_nbor_size = 1024; From f38678f320a76e463893e898cb18c9fea6030b3f Mon Sep 17 00:00:00 2001 From: Han Wang Date: Wed, 17 Mar 2021 10:27:36 +0800 Subject: [PATCH 13/23] fix bug : namespace in cuda compiling --- source/lib/src/cuda/prod_env_mat.cu | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/lib/src/cuda/prod_env_mat.cu b/source/lib/src/cuda/prod_env_mat.cu index d26e089efa..febdc093f4 100644 --- a/source/lib/src/cuda/prod_env_mat.cu +++ b/source/lib/src/cuda/prod_env_mat.cu @@ -4,6 +4,8 @@ #include #include +using namespace deepmd; + // common part of prod_env_mat template < typename Key, From ebdb4043fbd0ee7d716921828ffd0dc74f7b747c Mon Sep 17 00:00:00 2001 From: denghuilu Date: Fri, 19 Mar 2021 04:26:31 +0800 Subject: [PATCH 14/23] fix bugs of single precision training and transfer --- deepmd/entrypoints/transfer.py | 30 ++++++++++++------------------ deepmd/loss/ener.py | 2 +- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/deepmd/entrypoints/transfer.py b/deepmd/entrypoints/transfer.py index 3e1aa1b5f2..0af45a4244 100644 --- a/deepmd/entrypoints/transfer.py +++ b/deepmd/entrypoints/transfer.py @@ -72,7 +72,7 @@ def transfer(*, old_model: str, raw_model: str, output: str, **kwargs): new_graph_def = transform_graph(raw_graph, old_graph) with tf.gfile.GFile(output, mode="wb") as f: f.write(new_graph_def.SerializeToString()) - log.info("the output model is saved in {output:s}") + log.info("the output model is saved in " + output) def load_graph(graph_name: str) -> tf.Graph: @@ -136,22 +136,20 @@ def transform_graph(raw_graph: tf.Graph, old_graph: tf.Graph) -> tf.Graph: if raw_graph_dtype == np.float16: if old_graph_dtype == np.float64 or old_graph_dtype == np.float32: if (len(tensor_shape) != 1) or (tensor_shape[0] != 1): - tensor = np.frombuffer(old_node.tensor_content, dtype=np.float16) - cp_attr.from_array(tensor, tf.float16, shape=tensor_shape) + tensor = np.frombuffer(old_node.tensor_content).astype(raw_graph_dtype) + cp_attr.from_array(tensor, tf.float16, shape = tensor_shape) else: - tensor = load_tensor(old_node, old_graph_dtype, np.float16) + tensor = load_tensor(old_node, old_graph_dtype, raw_graph_dtype) cp_attr.from_array(tensor, tf.float16, [1]) - elif old_graph_dtype == np.float16: - tensor = convert_matrix(np.array(old_node.half_val), tensor_shape) - cp_attr.from_array(tensor, tf.float16) + elif old_graph_dtype[1] == "float16": + tensor = convertMatrix(np.array(old_node.half_val), tensor_shape) + cp_attr.from_array(tensor, raw_graph_dtype) elif raw_graph_dtype == np.float64 or raw_graph_dtype == np.float32: if old_graph_dtype == np.float64 or old_graph_dtype == np.float32: if (len(tensor_shape) != 1) or (tensor_shape[0] != 1): - tensor = np.frombuffer( - old_node.tensor_content, dtype=raw_graph_dtype - ) + tensor = np.frombuffer(old_node.tensor_content).astype(raw_graph_dtype) cp_attr.from_str(tensor) else: tensor = load_tensor(old_node, old_graph_dtype, raw_graph_dtype) @@ -159,14 +157,10 @@ def transform_graph(raw_graph: tf.Graph, old_graph: tf.Graph) -> tf.Graph: elif old_graph_dtype == np.float16: if (len(tensor_shape) != 1) or (tensor_shape[0] != 1): - tensor = convert_matrix( - np.array(old_node.half_val), tensor_shape, dtype=raw_graph_dtype - ) + tensor = convertMatrix(np.array(old_node.half_val), tensor_shape).astype(raw_graph_dtype) cp_attr.from_str(tensor) else: - tensor = convert_matrix( - np.array(old_node.half_val), tensor_shape, dtype=raw_graph_dtype - ) + tensor = convertMatrix(np.array(old_node.half_val), tensor_shape).astype(raw_graph_dtype) cp_attr.from_array(tensor, raw_graph_dtype) return raw_graph_def @@ -191,9 +185,9 @@ def from_str(self, tensor: np.ndarray): def load_tensor(node: tf.Tensor, dtype_old: type, dtype_new: type) -> np.ndarray: if dtype_old == np.float64: - tensor = np.array(node.double_val, dtype=dtype_new) + tensor = np.array(node.double_val).astype(dtype_new) elif dtype_old == np.float32: - tensor = np.array(node.float_val, dtype=dtype_new) + tensor = np.array(node.float_val).astype(dtype_new) return tensor diff --git a/deepmd/loss/ener.py b/deepmd/loss/ener.py index 08e631bc0b..89d15b3add 100644 --- a/deepmd/loss/ener.py +++ b/deepmd/loss/ener.py @@ -119,7 +119,7 @@ def build (self, # only used when tensorboard was set as true self.l2_loss_summary = tf.summary.scalar('l2_loss', tf.sqrt(l2_loss)) - self.l2_loss_ener_summary = tf.summary.scalar('l2_ener_loss', tf.sqrt(l2_ener_loss) / global_cvt_2_tf_float(natoms[0])) + self.l2_loss_ener_summary = tf.summary.scalar('l2_ener_loss', global_cvt_2_tf_float(tf.sqrt(l2_ener_loss)) / global_cvt_2_tf_float(natoms[0])) self.l2_loss_force_summary = tf.summary.scalar('l2_force_loss', tf.sqrt(l2_force_loss)) self.l2_loss_virial_summary = tf.summary.scalar('l2_virial_loss', tf.sqrt(l2_virial_loss) / global_cvt_2_tf_float(natoms[0])) From 3dc97689feca7a3e74c8acefe5c16a38eac66daf Mon Sep 17 00:00:00 2001 From: denghuilu Date: Fri, 19 Mar 2021 07:50:23 +0800 Subject: [PATCH 15/23] fix bug of nbor sorting --- source/lib/src/cuda/prod_env_mat.cu | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/lib/src/cuda/prod_env_mat.cu b/source/lib/src/cuda/prod_env_mat.cu index d26e089efa..1e38d45f4b 100644 --- a/source/lib/src/cuda/prod_env_mat.cu +++ b/source/lib/src/cuda/prod_env_mat.cu @@ -114,7 +114,7 @@ __global__ void format_nlist_fill_a( } FPTYPE rr = sqrt(dev_dot(diff, diff)); if (rr <= rcut) { - key_in[idy] = type[j_idx] * 1E15+ (int_64)(rr * 1.0E13) / 100000 * 100000 + j_idx; + key_in[idy] = type[j_idx] * 1E15+ (int_64)(rr * 1.0E13) / 10000000 * 10000000 + j_idx; } } @@ -144,7 +144,7 @@ __global__ void format_nlist_fill_b( for (unsigned int kk = 0; key_out[kk] != key_out[max_nbor_size - 1]; kk++) { const int & nei_type = key_out[kk] / 1E15; if (nei_iter[nei_type] < sec[nei_type + 1]) { - row_nlist[nei_iter[nei_type]++] = key_out[kk] % 100000; + row_nlist[nei_iter[nei_type]++] = key_out[kk] % 10000000; } } } From 53de560b81cd6ed81d2fdfc41f2ec4a799b94c87 Mon Sep 17 00:00:00 2001 From: denghuilu Date: Fri, 19 Mar 2021 16:47:26 +0800 Subject: [PATCH 16/23] fix bug of gpu namespace --- source/lib/include/gpu_cuda.h | 26 ++++++++++++++++++++++++++ source/lib/src/cuda/gelu.cu | 3 ++- source/lib/src/cuda/prod_env_mat.cu | 12 ++++++------ source/lib/src/cuda/prod_force.cu | 19 ++----------------- source/lib/src/cuda/prod_virial.cu | 19 ++----------------- source/lib/src/cuda/tabulate.cu | 4 ++-- source/lib/src/neighbor_list.cc | 4 ++-- source/lib/src/prod_env_mat.cc | 2 +- source/lib/tests/test_env_mat_a.cc | 8 ++++---- source/lib/tests/test_env_mat_r.cc | 8 ++++---- source/lib/tests/test_gelu.cc | 6 +++--- source/lib/tests/test_prod_force_a.cc | 2 +- source/lib/tests/test_prod_force_r.cc | 2 +- source/lib/tests/test_prod_virial_a.cc | 2 +- source/lib/tests/test_prod_virial_r.cc | 2 +- 15 files changed, 58 insertions(+), 61 deletions(-) diff --git a/source/lib/include/gpu_cuda.h b/source/lib/include/gpu_cuda.h index 845e0b9d9f..6ccbbb9356 100644 --- a/source/lib/include/gpu_cuda.h +++ b/source/lib/include/gpu_cuda.h @@ -13,6 +13,23 @@ inline void cudaAssert(cudaError_t code, const char *file, int line, bool abort= } } +#if defined(__CUDA_ARCH__) && __CUDA_ARCH__ < 600 +static __inline__ __device__ double atomicAdd( + double* address, + double val) +{ + unsigned long long int* address_as_ull = (unsigned long long int*)address; + unsigned long long int old = *address_as_ull, assumed; + do { + assumed = old; + old = atomicCAS(address_as_ull, assumed, + __double_as_longlong(val + __longlong_as_double(assumed))); + // Note: uses integer comparison to avoid hang in case of NaN (since NaN != NaN) } while (assumed != old); + } while (assumed != old); + return __longlong_as_double(old); +} +#endif + template void memcpy_host_to_device( FPTYPE * device, @@ -70,4 +87,13 @@ void delete_device_memory( if (device != NULL) { cudaErrcheck(cudaFree(device)); } +} + +template +void memset_device_memory( + FPTYPE * device, + const FPTYPE var, + const int size) +{ + cudaErrcheck(cudaMemset(device, var, sizeof(FPTYPE) * size)); } \ No newline at end of file diff --git a/source/lib/src/cuda/gelu.cu b/source/lib/src/cuda/gelu.cu index cd4cfa0541..2b5b3074bb 100644 --- a/source/lib/src/cuda/gelu.cu +++ b/source/lib/src/cuda/gelu.cu @@ -1,6 +1,5 @@ #include "gelu.h" #include "device.h" -#include "gpu_cuda.h" template __global__ void gelu( @@ -49,6 +48,7 @@ __global__ void gelu_grad_grad( out[idx] = dy[idx] * dy_2[idx] * (0.134145 * SQRT_2_PI * xx[idx] * xx[idx] * (1 - var1 * var1) - SQRT_2_PI * xx[idx] * var2 * (0.134145 * xx[idx] * xx[idx] + 1) * var1 + var2); } +namespace deepmd { template void gelu_gpu_cuda( FPTYPE * out, @@ -94,3 +94,4 @@ template void gelu_grad_gpu_cuda(float * out, const float * x, const floa template void gelu_grad_gpu_cuda(double * out, const double * x, const double * dy, const int size); template void gelu_grad_grad_gpu_cuda(float * out, const float * x, const float * dy, const float * dy_2, const int size); template void gelu_grad_grad_gpu_cuda(double * out, const double * x, const double * dy, const double * dy_2, const int size); +} \ No newline at end of file diff --git a/source/lib/src/cuda/prod_env_mat.cu b/source/lib/src/cuda/prod_env_mat.cu index febdc093f4..00a7401f85 100644 --- a/source/lib/src/cuda/prod_env_mat.cu +++ b/source/lib/src/cuda/prod_env_mat.cu @@ -4,8 +4,6 @@ #include #include -using namespace deepmd; - // common part of prod_env_mat template < typename Key, @@ -156,7 +154,7 @@ void format_nbor_list_1024 ( int_64 * key, const FPTYPE* coord, const int* type, - const InputNlist & gpu_inlist, + const deepmd::InputNlist & gpu_inlist, const int& nloc, const float& rcut, int * i_idx) @@ -182,7 +180,7 @@ void format_nbor_list_2048 ( int_64 * key, const FPTYPE* coord, const int* type, - const InputNlist & gpu_inlist, + const deepmd::InputNlist & gpu_inlist, const int& nloc, const float& rcut, int * i_idx) @@ -208,7 +206,7 @@ void format_nbor_list_4096 ( int_64 * key, const FPTYPE* coord, const int* type, - const InputNlist & gpu_inlist, + const deepmd::InputNlist & gpu_inlist, const int& nloc, const float& rcut, int * i_idx) @@ -234,7 +232,7 @@ void format_nbor_list( int * nlist, const FPTYPE * coord, const int * type, - const InputNlist & gpu_inlist, + const deepmd::InputNlist & gpu_inlist, int * array_int, int_64 * array_longlong, const int max_nbor_size, @@ -433,6 +431,7 @@ __global__ void compute_env_mat_r( } } +namespace deepmd { template void prod_env_mat_a_gpu_cuda( FPTYPE * em, @@ -505,3 +504,4 @@ template void prod_env_mat_a_gpu_cuda(float * em, float * em_deriv, float template void prod_env_mat_a_gpu_cuda(double * em, double * em_deriv, double * rij, int * nlist, const double * coord, const int * type, const InputNlist & gpu_inlist, int * array_int, unsigned long long * array_longlong, const int max_nbor_size, const double * avg, const double * std, const int nloc, const int nall, const float rcut, const float rcut_smth, const std::vector sec); template void prod_env_mat_r_gpu_cuda(float * em, float * em_deriv, float * rij, int * nlist, const float * coord, const int * type, const InputNlist & gpu_inlist, int * array_int, unsigned long long * array_longlong, const int max_nbor_size, const float * avg, const float * std, const int nloc, const int nall, const float rcut, const float rcut_smth, const std::vector sec); template void prod_env_mat_r_gpu_cuda(double * em, double * em_deriv, double * rij, int * nlist, const double * coord, const int * type, const InputNlist & gpu_inlist, int * array_int, unsigned long long * array_longlong, const int max_nbor_size, const double * avg, const double * std, const int nloc, const int nall, const float rcut, const float rcut_smth, const std::vector sec); +} diff --git a/source/lib/src/cuda/prod_force.cu b/source/lib/src/cuda/prod_force.cu index d440d3b153..97321e74e8 100644 --- a/source/lib/src/cuda/prod_force.cu +++ b/source/lib/src/cuda/prod_force.cu @@ -2,23 +2,6 @@ #include "gpu_cuda.h" #include "prod_force.h" -#if defined(__CUDA_ARCH__) && __CUDA_ARCH__ < 600 -static __inline__ __device__ double atomicAdd( - double* address, - double val) -{ - unsigned long long int* address_as_ull = (unsigned long long int*)address; - unsigned long long int old = *address_as_ull, assumed; - do { - assumed = old; - old = atomicCAS(address_as_ull, assumed, - __double_as_longlong(val + __longlong_as_double(assumed))); - // Note: uses integer comparison to avoid hang in case of NaN (since NaN != NaN) } while (assumed != old); - } while (assumed != old); - return __longlong_as_double(old); -} -#endif - template < typename FPTYPE, int THREADS_PER_BLOCK> @@ -112,6 +95,7 @@ __global__ void force_deriv_wrt_neighbors_r( net_deriv[idx * ndescrpt + idy] * in_deriv[idx * ndescrpt * 3 + idy * 3 + idz]); } +namespace deepmd { template void prod_force_a_gpu_cuda( FPTYPE * force, @@ -172,3 +156,4 @@ template void prod_force_a_gpu_cuda(float * force, const float * net_deri template void prod_force_a_gpu_cuda(double * force, const double * net_deriv, const double * in_deriv, const int * nlist, const int nloc, const int nall, const int nnei); template void prod_force_r_gpu_cuda(float * force, const float * net_deriv, const float * in_deriv, const int * nlist, const int nloc, const int nall, const int nnei); template void prod_force_r_gpu_cuda(double * force, const double * net_deriv, const double * in_deriv, const int * nlist, const int nloc, const int nall, const int nnei); +} diff --git a/source/lib/src/cuda/prod_virial.cu b/source/lib/src/cuda/prod_virial.cu index 19fb6c1b2f..032e1b1c09 100644 --- a/source/lib/src/cuda/prod_virial.cu +++ b/source/lib/src/cuda/prod_virial.cu @@ -1,23 +1,6 @@ #include "gpu_cuda.h" #include "prod_virial.h" -#if defined(__CUDA_ARCH__) && __CUDA_ARCH__ < 600 -static __inline__ __device__ double atomicAdd( - double* address, - double val) -{ - unsigned long long int* address_as_ull = (unsigned long long int*)address; - unsigned long long int old = *address_as_ull, assumed; - do { - assumed = old; - old = atomicCAS(address_as_ull, assumed, - __double_as_longlong(val + __longlong_as_double(assumed))); - // Note: uses integer comparison to avoid hang in case of NaN (since NaN != NaN) } while (assumed != old); - } while (assumed != old); - return __longlong_as_double(old); -} -#endif - template __global__ void virial_deriv_wrt_neighbors_a( FPTYPE * virial, @@ -90,6 +73,7 @@ __global__ void virial_deriv_wrt_neighbors_r( net_deriv[idx * ndescrpt + idy] * rij[idx * nnei * 3 + idy * 3 + idz % 3] * in_deriv[idx * ndescrpt * 3 + idy * 3 + idz / 3]); } +namespace deepmd { template void prod_virial_a_gpu_cuda( FPTYPE * virial, @@ -152,3 +136,4 @@ template void prod_virial_a_gpu_cuda(float * virial, float * atom_virial, template void prod_virial_a_gpu_cuda(double * virial, double * atom_virial, const double * net_deriv, const double * in_deriv, const double * rij, const int * nlist, const int nloc, const int nall, const int nnei); template void prod_virial_r_gpu_cuda(float * virial, float * atom_virial, const float * net_deriv, const float * in_deriv, const float * rij, const int * nlist, const int nloc, const int nall, const int nnei); template void prod_virial_r_gpu_cuda(double * virial, double * atom_virial, const double * net_deriv, const double * in_deriv, const double * rij, const int * nlist, const int nloc, const int nall, const int nnei); +} diff --git a/source/lib/src/cuda/tabulate.cu b/source/lib/src/cuda/tabulate.cu index 83803733ff..281c8adbc2 100644 --- a/source/lib/src/cuda/tabulate.cu +++ b/source/lib/src/cuda/tabulate.cu @@ -1,5 +1,3 @@ -#include -#include #include "tabulate.h" #include "gpu_cuda.h" @@ -193,6 +191,7 @@ __global__ void tabulate_fusion_grad_fifth_order_polynomial( } } +namespace deepmd { template void tabulate_fusion_gpu_cuda( FPTYPE * out, @@ -238,3 +237,4 @@ template void tabulate_fusion_gpu_cuda(float * out, const float * table, template void tabulate_fusion_gpu_cuda(double * out, const double * table, const double * table_info, const double * em_x, const double * em, const int nloc, const int nnei, const int last_layer_size); template void tabulate_fusion_grad_gpu_cuda (float * dy_dem_x, float * dy_dem, const float * table, const float * table_info, const float * em_x, const float * em, const float * dy, const int nloc, const int nnei, const int last_layer_size); template void tabulate_fusion_grad_gpu_cuda (double * dy_dem_x, double * dy_dem, const double * table, const double * table_info, const double * em_x, const double * em, const double * dy, const int nloc, const int nnei, const int last_layer_size); +} diff --git a/source/lib/src/neighbor_list.cc b/source/lib/src/neighbor_list.cc index e0ceae4a38..89e8552524 100644 --- a/source/lib/src/neighbor_list.cc +++ b/source/lib/src/neighbor_list.cc @@ -844,7 +844,7 @@ build_nlist_cpu( const float & rcut); #if GOOGLE_CUDA -void convert_nlist_gpu_cuda( +void deepmd::convert_nlist_gpu_cuda( InputNlist & gpu_nlist, InputNlist & cpu_nlist, int* & gpu_memory, @@ -867,7 +867,7 @@ void convert_nlist_gpu_cuda( free(_firstneigh); } -void free_nlist_gpu_cuda( +void deepmd::free_nlist_gpu_cuda( InputNlist & gpu_nlist) { delete_device_memory(gpu_nlist.ilist); diff --git a/source/lib/src/prod_env_mat.cc b/source/lib/src/prod_env_mat.cc index 597473021d..c5e3223e9e 100644 --- a/source/lib/src/prod_env_mat.cc +++ b/source/lib/src/prod_env_mat.cc @@ -257,7 +257,7 @@ prod_env_mat_r_cpu( const std::vector sec); #if GOOGLE_CUDA -void env_mat_nbor_update( +void deepmd::env_mat_nbor_update( InputNlist &inlist, InputNlist &gpu_inlist, int &max_nbor_size, diff --git a/source/lib/tests/test_env_mat_a.cc b/source/lib/tests/test_env_mat_a.cc index c08a4f4705..369d09d872 100644 --- a/source/lib/tests/test_env_mat_a.cc +++ b/source/lib/tests/test_env_mat_a.cc @@ -557,9 +557,9 @@ TEST_F(TestEnvMatA, prod_gpu_cuda) malloc_device_memory(array_int_dev, sec_a.size() + nloc * sec_a.size() + nloc); malloc_device_memory(array_longlong_dev, nloc * GPU_MAX_NBOR_SIZE * 2); malloc_device_memory(memory_dev, nloc * max_nbor_size); - convert_nlist_gpu_cuda(gpu_inlist, inlist, memory_dev, max_nbor_size); + deepmd::convert_nlist_gpu_cuda(gpu_inlist, inlist, memory_dev, max_nbor_size); - prod_env_mat_a_gpu_cuda( + deepmd::prod_env_mat_a_gpu_cuda( em_dev, em_deriv_dev, rij_dev, @@ -648,9 +648,9 @@ TEST_F(TestEnvMatA, prod_gpu_cuda_equal_cpu) malloc_device_memory(array_int_dev, sec_a.size() + nloc * sec_a.size() + nloc); malloc_device_memory(array_longlong_dev, nloc * GPU_MAX_NBOR_SIZE * 2); malloc_device_memory(memory_dev, nloc * max_nbor_size); - convert_nlist_gpu_cuda(gpu_inlist, inlist, memory_dev, max_nbor_size); + deepmd::convert_nlist_gpu_cuda(gpu_inlist, inlist, memory_dev, max_nbor_size); - prod_env_mat_a_gpu_cuda( + deepmd::prod_env_mat_a_gpu_cuda( em_dev, em_deriv_dev, rij_dev, diff --git a/source/lib/tests/test_env_mat_r.cc b/source/lib/tests/test_env_mat_r.cc index f571dbdaf1..3a50a892ff 100644 --- a/source/lib/tests/test_env_mat_r.cc +++ b/source/lib/tests/test_env_mat_r.cc @@ -377,7 +377,7 @@ TEST_F(TestEnvMatR, prod_gpu_cuda) } std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]), gpu_inlist; + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]), gpu_inlist; convert_nlist(inlist, nlist_a_cpy); std::vector em(nloc * ndescrpt, 0.0), em_deriv(nloc * ndescrpt * 3, 0.0), rij(nloc * nnei * 3, 0.0); std::vector nlist(nloc * nnei, 0); @@ -402,7 +402,7 @@ TEST_F(TestEnvMatR, prod_gpu_cuda) malloc_device_memory(memory_dev, nloc * max_nbor_size); convert_nlist_gpu_cuda(gpu_inlist, inlist, memory_dev, max_nbor_size); - prod_env_mat_r_gpu_cuda( + deepmd::prod_env_mat_r_gpu_cuda( em_dev, em_deriv_dev, rij_dev, @@ -467,7 +467,7 @@ TEST_F(TestEnvMatR, prod_gpu_cuda_equal_cpu) } std::vector ilist(nloc), numneigh(nloc); std::vector firstneigh(nloc); - InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]), gpu_inlist; + deepmd::InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]), gpu_inlist; convert_nlist(inlist, nlist_a_cpy); std::vector em(nloc * ndescrpt, 0.0), em_deriv(nloc * ndescrpt * 3, 0.0), rij(nloc * nnei * 3, 0.0); std::vector nlist(nloc * nnei, 0); @@ -492,7 +492,7 @@ TEST_F(TestEnvMatR, prod_gpu_cuda_equal_cpu) malloc_device_memory(memory_dev, nloc * max_nbor_size); convert_nlist_gpu_cuda(gpu_inlist, inlist, memory_dev, max_nbor_size); - prod_env_mat_r_gpu_cuda( + deepmd::prod_env_mat_r_gpu_cuda( em_dev, em_deriv_dev, rij_dev, diff --git a/source/lib/tests/test_gelu.cc b/source/lib/tests/test_gelu.cc index 0b05dd71d5..9becbcac47 100644 --- a/source/lib/tests/test_gelu.cc +++ b/source/lib/tests/test_gelu.cc @@ -153,7 +153,7 @@ TEST_F(TestGelu, gelu_gpu_cuda) double * gelu_dev = NULL, * xx_dev = NULL; malloc_device_memory_sync(gelu_dev, gelu); malloc_device_memory_sync(xx_dev, xx); - gelu_gpu_cuda (gelu_dev, xx_dev, nloc); + deepmd::gelu_gpu_cuda (gelu_dev, xx_dev, nloc); memcpy_device_to_host(gelu_dev, gelu); delete_device_memory(gelu_dev); delete_device_memory(xx_dev); @@ -174,7 +174,7 @@ TEST_F(TestGelu, gelu_grad_gpu_cuda) malloc_device_memory_sync(gelu_grad_dev, gelu_grad); malloc_device_memory_sync(xx_dev, xx); malloc_device_memory_sync(dy_dev, dy); - gelu_grad_gpu_cuda (gelu_grad_dev, xx_dev, dy_dev, nloc); + deepmd::gelu_grad_gpu_cuda (gelu_grad_dev, xx_dev, dy_dev, nloc); memcpy_device_to_host(gelu_grad_dev, gelu_grad); delete_device_memory(gelu_grad_dev); delete_device_memory(xx_dev); @@ -198,7 +198,7 @@ TEST_F(TestGelu, gelu_grad_grad_gpu_cuda) malloc_device_memory_sync(xx_dev, xx); malloc_device_memory_sync(dy_dev, dy); malloc_device_memory_sync(dy_2_dev, dy_2); - gelu_grad_grad_gpu_cuda (gelu_grad_grad_dev, xx_dev, dy_dev, dy_2_dev, nloc); + deepmd::gelu_grad_grad_gpu_cuda (gelu_grad_grad_dev, xx_dev, dy_dev, dy_2_dev, nloc); memcpy_device_to_host(gelu_grad_grad_dev, gelu_grad_grad); delete_device_memory(gelu_grad_grad_dev); delete_device_memory(xx_dev); diff --git a/source/lib/tests/test_prod_force_a.cc b/source/lib/tests/test_prod_force_a.cc index 7aeb9ca99f..3318714aff 100644 --- a/source/lib/tests/test_prod_force_a.cc +++ b/source/lib/tests/test_prod_force_a.cc @@ -112,7 +112,7 @@ TEST_F(TestProdForceA, gpu_cuda) malloc_device_memory_sync(net_deriv_dev, net_deriv); malloc_device_memory_sync(env_deriv_dev, env_deriv); - prod_force_a_gpu_cuda (force_dev, net_deriv_dev, env_deriv_dev, nlist_dev, nloc, nall, nnei); + deepmd::prod_force_a_gpu_cuda (force_dev, net_deriv_dev, env_deriv_dev, nlist_dev, nloc, nall, nnei); memcpy_device_to_host(force_dev, force); delete_device_memory(nlist_dev); diff --git a/source/lib/tests/test_prod_force_r.cc b/source/lib/tests/test_prod_force_r.cc index 033c41a7fe..1247a94dda 100644 --- a/source/lib/tests/test_prod_force_r.cc +++ b/source/lib/tests/test_prod_force_r.cc @@ -112,7 +112,7 @@ TEST_F(TestProdForceR, gpu_cuda) malloc_device_memory_sync(net_deriv_dev, net_deriv); malloc_device_memory_sync(env_deriv_dev, env_deriv); - prod_force_r_gpu_cuda (force_dev, net_deriv_dev, env_deriv_dev, nlist_dev, nloc, nall, nnei); + deepmd::prod_force_r_gpu_cuda (force_dev, net_deriv_dev, env_deriv_dev, nlist_dev, nloc, nall, nnei); memcpy_device_to_host(force_dev, force); delete_device_memory(nlist_dev); diff --git a/source/lib/tests/test_prod_virial_a.cc b/source/lib/tests/test_prod_virial_a.cc index f1d4ee619a..1eb7d0f0f9 100644 --- a/source/lib/tests/test_prod_virial_a.cc +++ b/source/lib/tests/test_prod_virial_a.cc @@ -130,7 +130,7 @@ TEST_F(TestProdVirialA, gpu_cuda) malloc_device_memory_sync(env_deriv_dev, env_deriv); malloc_device_memory_sync(rij_dev, rij); - prod_virial_a_gpu_cuda (virial_dev, atom_virial_dev, net_deriv_dev, env_deriv_dev, rij_dev, nlist_dev, nloc, nall, nnei); + deepmd::prod_virial_a_gpu_cuda (virial_dev, atom_virial_dev, net_deriv_dev, env_deriv_dev, rij_dev, nlist_dev, nloc, nall, nnei); memcpy_device_to_host(virial_dev, virial); memcpy_device_to_host(atom_virial_dev, atom_virial); diff --git a/source/lib/tests/test_prod_virial_r.cc b/source/lib/tests/test_prod_virial_r.cc index 101b1659f8..4780d9358d 100644 --- a/source/lib/tests/test_prod_virial_r.cc +++ b/source/lib/tests/test_prod_virial_r.cc @@ -130,7 +130,7 @@ TEST_F(TestProdVirialR, gpu_cuda) malloc_device_memory_sync(env_deriv_dev, env_deriv); malloc_device_memory_sync(rij_dev, rij); - prod_virial_r_gpu_cuda (virial_dev, atom_virial_dev, net_deriv_dev, env_deriv_dev, rij_dev, nlist_dev, nloc, nall, nnei); + deepmd::prod_virial_r_gpu_cuda (virial_dev, atom_virial_dev, net_deriv_dev, env_deriv_dev, rij_dev, nlist_dev, nloc, nall, nnei); memcpy_device_to_host(virial_dev, virial); memcpy_device_to_host(atom_virial_dev, atom_virial); From a8ada896734b9443b3dbeb5e371870ea2ad28d99 Mon Sep 17 00:00:00 2001 From: denghuilu Date: Fri, 19 Mar 2021 18:33:33 +0800 Subject: [PATCH 17/23] add namespace deepmd for gpu_cuda.h --- source/lib/include/gpu_cuda.h | 4 +- source/lib/tests/test_env_mat_a.cc | 100 ++++++++++++------------ source/lib/tests/test_env_mat_r.cc | 102 ++++++++++++------------- source/lib/tests/test_gelu.cc | 42 +++++----- source/lib/tests/test_prod_force_a.cc | 18 ++--- source/lib/tests/test_prod_force_r.cc | 18 ++--- source/lib/tests/test_prod_virial_a.cc | 28 +++---- source/lib/tests/test_prod_virial_r.cc | 28 +++---- source/lib/tests/test_tabulate.cc | 46 +++++------ 9 files changed, 194 insertions(+), 192 deletions(-) diff --git a/source/lib/include/gpu_cuda.h b/source/lib/include/gpu_cuda.h index 6ccbbb9356..48db721436 100644 --- a/source/lib/include/gpu_cuda.h +++ b/source/lib/include/gpu_cuda.h @@ -30,6 +30,7 @@ static __inline__ __device__ double atomicAdd( } #endif +namespace deepmd { template void memcpy_host_to_device( FPTYPE * device, @@ -96,4 +97,5 @@ void memset_device_memory( const int size) { cudaErrcheck(cudaMemset(device, var, sizeof(FPTYPE) * size)); -} \ No newline at end of file +} +} // end of namespace deepmd \ No newline at end of file diff --git a/source/lib/tests/test_env_mat_a.cc b/source/lib/tests/test_env_mat_a.cc index 369d09d872..d32203c692 100644 --- a/source/lib/tests/test_env_mat_a.cc +++ b/source/lib/tests/test_env_mat_a.cc @@ -546,17 +546,17 @@ TEST_F(TestEnvMatA, prod_gpu_cuda) double * posi_cpy_dev = NULL, * avg_dev = NULL, * std_dev = NULL; int * atype_cpy_dev = NULL, * nlist_dev = NULL, * array_int_dev = NULL, * memory_dev = NULL; int_64 * array_longlong_dev = NULL; - malloc_device_memory_sync(em_dev, em); - malloc_device_memory_sync(em_deriv_dev, em_deriv); - malloc_device_memory_sync(rij_dev, rij); - malloc_device_memory_sync(posi_cpy_dev, posi_cpy); - malloc_device_memory_sync(avg_dev, avg); - malloc_device_memory_sync(std_dev, std); - malloc_device_memory_sync(atype_cpy_dev, atype_cpy); - malloc_device_memory_sync(nlist_dev, nlist); - malloc_device_memory(array_int_dev, sec_a.size() + nloc * sec_a.size() + nloc); - malloc_device_memory(array_longlong_dev, nloc * GPU_MAX_NBOR_SIZE * 2); - malloc_device_memory(memory_dev, nloc * max_nbor_size); + deepmd::malloc_device_memory_sync(em_dev, em); + deepmd::malloc_device_memory_sync(em_deriv_dev, em_deriv); + deepmd::malloc_device_memory_sync(rij_dev, rij); + deepmd::malloc_device_memory_sync(posi_cpy_dev, posi_cpy); + deepmd::malloc_device_memory_sync(avg_dev, avg); + deepmd::malloc_device_memory_sync(std_dev, std); + deepmd::malloc_device_memory_sync(atype_cpy_dev, atype_cpy); + deepmd::malloc_device_memory_sync(nlist_dev, nlist); + deepmd::malloc_device_memory(array_int_dev, sec_a.size() + nloc * sec_a.size() + nloc); + deepmd::malloc_device_memory(array_longlong_dev, nloc * GPU_MAX_NBOR_SIZE * 2); + deepmd::malloc_device_memory(memory_dev, nloc * max_nbor_size); deepmd::convert_nlist_gpu_cuda(gpu_inlist, inlist, memory_dev, max_nbor_size); deepmd::prod_env_mat_a_gpu_cuda( @@ -577,18 +577,18 @@ TEST_F(TestEnvMatA, prod_gpu_cuda) rc, rc_smth, sec_a); - memcpy_device_to_host(em_dev, em); - delete_device_memory(em_dev); - delete_device_memory(em_deriv_dev); - delete_device_memory(nlist_dev); - delete_device_memory(posi_cpy_dev); - delete_device_memory(atype_cpy_dev); - delete_device_memory(array_int_dev); - delete_device_memory(array_longlong_dev); - delete_device_memory(avg_dev); - delete_device_memory(std_dev); - delete_device_memory(memory_dev); - free_nlist_gpu_cuda(gpu_inlist); + deepmd::memcpy_device_to_host(em_dev, em); + deepmd::delete_device_memory(em_dev); + deepmd::delete_device_memory(em_deriv_dev); + deepmd::delete_device_memory(nlist_dev); + deepmd::delete_device_memory(posi_cpy_dev); + deepmd::delete_device_memory(atype_cpy_dev); + deepmd::delete_device_memory(array_int_dev); + deepmd::delete_device_memory(array_longlong_dev); + deepmd::delete_device_memory(avg_dev); + deepmd::delete_device_memory(std_dev); + deepmd::delete_device_memory(memory_dev); + deepmd::free_nlist_gpu_cuda(gpu_inlist); for(int ii = 0; ii < nloc; ++ii){ for (int jj = 0; jj < nnei; ++jj){ @@ -636,18 +636,18 @@ TEST_F(TestEnvMatA, prod_gpu_cuda_equal_cpu) double * posi_cpy_dev = NULL, * avg_dev = NULL, * std_dev = NULL; int * atype_cpy_dev = NULL, * nlist_dev = NULL, * array_int_dev = NULL, * memory_dev = NULL; int_64 * array_longlong_dev = NULL; - malloc_device_memory_sync(em_dev, em); - malloc_device_memory_sync(em_deriv_dev, em_deriv); - malloc_device_memory_sync(rij_dev, rij); - malloc_device_memory_sync(posi_cpy_dev, posi_cpy); - malloc_device_memory_sync(avg_dev, avg); - malloc_device_memory_sync(std_dev, std); - - malloc_device_memory_sync(atype_cpy_dev, atype_cpy); - malloc_device_memory_sync(nlist_dev, nlist); - malloc_device_memory(array_int_dev, sec_a.size() + nloc * sec_a.size() + nloc); - malloc_device_memory(array_longlong_dev, nloc * GPU_MAX_NBOR_SIZE * 2); - malloc_device_memory(memory_dev, nloc * max_nbor_size); + deepmd::malloc_device_memory_sync(em_dev, em); + deepmd::malloc_device_memory_sync(em_deriv_dev, em_deriv); + deepmd::malloc_device_memory_sync(rij_dev, rij); + deepmd::malloc_device_memory_sync(posi_cpy_dev, posi_cpy); + deepmd::malloc_device_memory_sync(avg_dev, avg); + deepmd::malloc_device_memory_sync(std_dev, std); + + deepmd::malloc_device_memory_sync(atype_cpy_dev, atype_cpy); + deepmd::malloc_device_memory_sync(nlist_dev, nlist); + deepmd::malloc_device_memory(array_int_dev, sec_a.size() + nloc * sec_a.size() + nloc); + deepmd::malloc_device_memory(array_longlong_dev, nloc * GPU_MAX_NBOR_SIZE * 2); + deepmd::malloc_device_memory(memory_dev, nloc * max_nbor_size); deepmd::convert_nlist_gpu_cuda(gpu_inlist, inlist, memory_dev, max_nbor_size); deepmd::prod_env_mat_a_gpu_cuda( @@ -668,21 +668,21 @@ TEST_F(TestEnvMatA, prod_gpu_cuda_equal_cpu) rc, rc_smth, sec_a); - memcpy_device_to_host(em_dev, em); - memcpy_device_to_host(em_deriv_dev, em_deriv); - memcpy_device_to_host(rij_dev, rij); - memcpy_device_to_host(nlist_dev, nlist); - delete_device_memory(em_dev); - delete_device_memory(em_deriv_dev); - delete_device_memory(nlist_dev); - delete_device_memory(posi_cpy_dev); - delete_device_memory(atype_cpy_dev); - delete_device_memory(array_int_dev); - delete_device_memory(array_longlong_dev); - delete_device_memory(avg_dev); - delete_device_memory(std_dev); - delete_device_memory(memory_dev); - free_nlist_gpu_cuda(gpu_inlist); + deepmd::memcpy_device_to_host(em_dev, em); + deepmd::memcpy_device_to_host(em_deriv_dev, em_deriv); + deepmd::memcpy_device_to_host(rij_dev, rij); + deepmd::memcpy_device_to_host(nlist_dev, nlist); + deepmd::delete_device_memory(em_dev); + deepmd::delete_device_memory(em_deriv_dev); + deepmd::delete_device_memory(nlist_dev); + deepmd::delete_device_memory(posi_cpy_dev); + deepmd::delete_device_memory(atype_cpy_dev); + deepmd::delete_device_memory(array_int_dev); + deepmd::delete_device_memory(array_longlong_dev); + deepmd::delete_device_memory(avg_dev); + deepmd::delete_device_memory(std_dev); + deepmd::delete_device_memory(memory_dev); + deepmd::free_nlist_gpu_cuda(gpu_inlist); std::vector fmt_nlist_a_1, fmt_nlist_r_1; std::vector env_1, env_deriv_1, rij_a_1; diff --git a/source/lib/tests/test_env_mat_r.cc b/source/lib/tests/test_env_mat_r.cc index 3a50a892ff..aac71eff8c 100644 --- a/source/lib/tests/test_env_mat_r.cc +++ b/source/lib/tests/test_env_mat_r.cc @@ -388,19 +388,19 @@ TEST_F(TestEnvMatR, prod_gpu_cuda) double * posi_cpy_dev = NULL, * avg_dev = NULL, * std_dev = NULL; int * atype_cpy_dev = NULL, * nlist_dev = NULL, * array_int_dev = NULL, * memory_dev = NULL; int_64 * array_longlong_dev = NULL; - malloc_device_memory_sync(em_dev, em); - malloc_device_memory_sync(em_deriv_dev, em_deriv); - malloc_device_memory_sync(rij_dev, rij); - malloc_device_memory_sync(posi_cpy_dev, posi_cpy); - malloc_device_memory_sync(avg_dev, avg); - malloc_device_memory_sync(std_dev, std); + deepmd::malloc_device_memory_sync(em_dev, em); + deepmd::malloc_device_memory_sync(em_deriv_dev, em_deriv); + deepmd::malloc_device_memory_sync(rij_dev, rij); + deepmd::malloc_device_memory_sync(posi_cpy_dev, posi_cpy); + deepmd::malloc_device_memory_sync(avg_dev, avg); + deepmd::malloc_device_memory_sync(std_dev, std); - malloc_device_memory_sync(atype_cpy_dev, atype_cpy); - malloc_device_memory_sync(nlist_dev, nlist); - malloc_device_memory(array_int_dev, sec_a.size() + nloc * sec_a.size() + nloc); - malloc_device_memory(array_longlong_dev, nloc * GPU_MAX_NBOR_SIZE * 2); - malloc_device_memory(memory_dev, nloc * max_nbor_size); - convert_nlist_gpu_cuda(gpu_inlist, inlist, memory_dev, max_nbor_size); + deepmd::malloc_device_memory_sync(atype_cpy_dev, atype_cpy); + deepmd::malloc_device_memory_sync(nlist_dev, nlist); + deepmd::malloc_device_memory(array_int_dev, sec_a.size() + nloc * sec_a.size() + nloc); + deepmd::malloc_device_memory(array_longlong_dev, nloc * GPU_MAX_NBOR_SIZE * 2); + deepmd::malloc_device_memory(memory_dev, nloc * max_nbor_size); + deepmd::convert_nlist_gpu_cuda(gpu_inlist, inlist, memory_dev, max_nbor_size); deepmd::prod_env_mat_r_gpu_cuda( em_dev, @@ -420,18 +420,18 @@ TEST_F(TestEnvMatR, prod_gpu_cuda) rc, rc_smth, sec_a); - memcpy_device_to_host(em_dev, em); - delete_device_memory(em_dev); - delete_device_memory(em_deriv_dev); - delete_device_memory(nlist_dev); - delete_device_memory(posi_cpy_dev); - delete_device_memory(atype_cpy_dev); - delete_device_memory(array_int_dev); - delete_device_memory(array_longlong_dev); - delete_device_memory(avg_dev); - delete_device_memory(std_dev); - delete_device_memory(memory_dev); - free_nlist_gpu_cuda(gpu_inlist); + deepmd::memcpy_device_to_host(em_dev, em); + deepmd::delete_device_memory(em_dev); + deepmd::delete_device_memory(em_deriv_dev); + deepmd::delete_device_memory(nlist_dev); + deepmd::delete_device_memory(posi_cpy_dev); + deepmd::delete_device_memory(atype_cpy_dev); + deepmd::delete_device_memory(array_int_dev); + deepmd::delete_device_memory(array_longlong_dev); + deepmd::delete_device_memory(avg_dev); + deepmd::delete_device_memory(std_dev); + deepmd::delete_device_memory(memory_dev); + deepmd::free_nlist_gpu_cuda(gpu_inlist); for(int ii = 0; ii < nloc; ++ii){ for (int jj = 0; jj < nnei; ++jj){ @@ -478,19 +478,19 @@ TEST_F(TestEnvMatR, prod_gpu_cuda_equal_cpu) double * posi_cpy_dev = NULL, * avg_dev = NULL, * std_dev = NULL; int * atype_cpy_dev = NULL, * nlist_dev = NULL, * array_int_dev = NULL, * memory_dev = NULL; int_64 * array_longlong_dev = NULL; - malloc_device_memory_sync(em_dev, em); - malloc_device_memory_sync(em_deriv_dev, em_deriv); - malloc_device_memory_sync(rij_dev, rij); - malloc_device_memory_sync(posi_cpy_dev, posi_cpy); - malloc_device_memory_sync(avg_dev, avg); - malloc_device_memory_sync(std_dev, std); + deepmd::malloc_device_memory_sync(em_dev, em); + deepmd::malloc_device_memory_sync(em_deriv_dev, em_deriv); + deepmd::malloc_device_memory_sync(rij_dev, rij); + deepmd::malloc_device_memory_sync(posi_cpy_dev, posi_cpy); + deepmd::malloc_device_memory_sync(avg_dev, avg); + deepmd::malloc_device_memory_sync(std_dev, std); - malloc_device_memory_sync(atype_cpy_dev, atype_cpy); - malloc_device_memory_sync(nlist_dev, nlist); - malloc_device_memory(array_int_dev, sec_a.size() + nloc * sec_a.size() + nloc); - malloc_device_memory(array_longlong_dev, nloc * GPU_MAX_NBOR_SIZE * 2); - malloc_device_memory(memory_dev, nloc * max_nbor_size); - convert_nlist_gpu_cuda(gpu_inlist, inlist, memory_dev, max_nbor_size); + deepmd::malloc_device_memory_sync(atype_cpy_dev, atype_cpy); + deepmd::malloc_device_memory_sync(nlist_dev, nlist); + deepmd::malloc_device_memory(array_int_dev, sec_a.size() + nloc * sec_a.size() + nloc); + deepmd::malloc_device_memory(array_longlong_dev, nloc * GPU_MAX_NBOR_SIZE * 2); + deepmd::malloc_device_memory(memory_dev, nloc * max_nbor_size); + deepmd::convert_nlist_gpu_cuda(gpu_inlist, inlist, memory_dev, max_nbor_size); deepmd::prod_env_mat_r_gpu_cuda( em_dev, @@ -510,21 +510,21 @@ TEST_F(TestEnvMatR, prod_gpu_cuda_equal_cpu) rc, rc_smth, sec_a); - memcpy_device_to_host(em_dev, em); - memcpy_device_to_host(em_deriv_dev, em_deriv); - memcpy_device_to_host(rij_dev, rij); - memcpy_device_to_host(nlist_dev, nlist); - delete_device_memory(em_dev); - delete_device_memory(em_deriv_dev); - delete_device_memory(nlist_dev); - delete_device_memory(posi_cpy_dev); - delete_device_memory(atype_cpy_dev); - delete_device_memory(array_int_dev); - delete_device_memory(array_longlong_dev); - delete_device_memory(avg_dev); - delete_device_memory(std_dev); - delete_device_memory(memory_dev); - free_nlist_gpu_cuda(gpu_inlist); + deepmd::memcpy_device_to_host(em_dev, em); + deepmd::memcpy_device_to_host(em_deriv_dev, em_deriv); + deepmd::memcpy_device_to_host(rij_dev, rij); + deepmd::memcpy_device_to_host(nlist_dev, nlist); + deepmd::delete_device_memory(em_dev); + deepmd::delete_device_memory(em_deriv_dev); + deepmd::delete_device_memory(nlist_dev); + deepmd::delete_device_memory(posi_cpy_dev); + deepmd::delete_device_memory(atype_cpy_dev); + deepmd::delete_device_memory(array_int_dev); + deepmd::delete_device_memory(array_longlong_dev); + deepmd::delete_device_memory(avg_dev); + deepmd::delete_device_memory(std_dev); + deepmd::delete_device_memory(memory_dev); + deepmd::free_nlist_gpu_cuda(gpu_inlist); std::vector fmt_nlist_a_1, fmt_nlist_r_1; std::vector env_1, env_deriv_1, rij_a_1; diff --git a/source/lib/tests/test_gelu.cc b/source/lib/tests/test_gelu.cc index 9becbcac47..4d85b2dd27 100644 --- a/source/lib/tests/test_gelu.cc +++ b/source/lib/tests/test_gelu.cc @@ -151,12 +151,12 @@ TEST_F(TestGelu, gelu_gpu_cuda) std::vector gelu(nloc, 0.0); double * gelu_dev = NULL, * xx_dev = NULL; - malloc_device_memory_sync(gelu_dev, gelu); - malloc_device_memory_sync(xx_dev, xx); + deepmd::malloc_device_memory_sync(gelu_dev, gelu); + deepmd::malloc_device_memory_sync(xx_dev, xx); deepmd::gelu_gpu_cuda (gelu_dev, xx_dev, nloc); - memcpy_device_to_host(gelu_dev, gelu); - delete_device_memory(gelu_dev); - delete_device_memory(xx_dev); + deepmd::memcpy_device_to_host(gelu_dev, gelu); + deepmd::delete_device_memory(gelu_dev); + deepmd::delete_device_memory(xx_dev); EXPECT_EQ(gelu.size(), nloc); EXPECT_EQ(gelu.size(), expected_gelu.size()); @@ -171,14 +171,14 @@ TEST_F(TestGelu, gelu_grad_gpu_cuda) std::vector gelu_grad(nloc, 0.0); double * gelu_grad_dev = NULL, * xx_dev = NULL, * dy_dev = NULL; - malloc_device_memory_sync(gelu_grad_dev, gelu_grad); - malloc_device_memory_sync(xx_dev, xx); - malloc_device_memory_sync(dy_dev, dy); + deepmd::malloc_device_memory_sync(gelu_grad_dev, gelu_grad); + deepmd::malloc_device_memory_sync(xx_dev, xx); + deepmd::malloc_device_memory_sync(dy_dev, dy); deepmd::gelu_grad_gpu_cuda (gelu_grad_dev, xx_dev, dy_dev, nloc); - memcpy_device_to_host(gelu_grad_dev, gelu_grad); - delete_device_memory(gelu_grad_dev); - delete_device_memory(xx_dev); - delete_device_memory(dy_dev); + deepmd::memcpy_device_to_host(gelu_grad_dev, gelu_grad); + deepmd::delete_device_memory(gelu_grad_dev); + deepmd::delete_device_memory(xx_dev); + deepmd::delete_device_memory(dy_dev); EXPECT_EQ(gelu_grad.size(), nloc); EXPECT_EQ(gelu_grad.size(), expected_gelu_grad.size()); @@ -194,16 +194,16 @@ TEST_F(TestGelu, gelu_grad_grad_gpu_cuda) std::vector gelu_grad_grad(nloc, 0.0); double * gelu_grad_grad_dev = NULL, * xx_dev = NULL, * dy_dev = NULL, * dy_2_dev = NULL; - malloc_device_memory_sync(gelu_grad_grad_dev, gelu_grad_grad); - malloc_device_memory_sync(xx_dev, xx); - malloc_device_memory_sync(dy_dev, dy); - malloc_device_memory_sync(dy_2_dev, dy_2); + deepmd::malloc_device_memory_sync(gelu_grad_grad_dev, gelu_grad_grad); + deepmd::malloc_device_memory_sync(xx_dev, xx); + deepmd::malloc_device_memory_sync(dy_dev, dy); + deepmd::malloc_device_memory_sync(dy_2_dev, dy_2); deepmd::gelu_grad_grad_gpu_cuda (gelu_grad_grad_dev, xx_dev, dy_dev, dy_2_dev, nloc); - memcpy_device_to_host(gelu_grad_grad_dev, gelu_grad_grad); - delete_device_memory(gelu_grad_grad_dev); - delete_device_memory(xx_dev); - delete_device_memory(dy_dev); - delete_device_memory(dy_2_dev); + deepmd::memcpy_device_to_host(gelu_grad_grad_dev, gelu_grad_grad); + deepmd::delete_device_memory(gelu_grad_grad_dev); + deepmd::delete_device_memory(xx_dev); + deepmd::delete_device_memory(dy_dev); + deepmd::delete_device_memory(dy_2_dev); EXPECT_EQ(gelu_grad_grad.size(), nloc); EXPECT_EQ(gelu_grad_grad.size(), expected_gelu_grad_grad.size()); diff --git a/source/lib/tests/test_prod_force_a.cc b/source/lib/tests/test_prod_force_a.cc index 3318714aff..d9c7c1319d 100644 --- a/source/lib/tests/test_prod_force_a.cc +++ b/source/lib/tests/test_prod_force_a.cc @@ -107,18 +107,18 @@ TEST_F(TestProdForceA, gpu_cuda) int * nlist_dev = NULL; double * force_dev = NULL, * net_deriv_dev = NULL, * env_deriv_dev = NULL; - malloc_device_memory_sync(nlist_dev, nlist); - malloc_device_memory_sync(force_dev, force); - malloc_device_memory_sync(net_deriv_dev, net_deriv); - malloc_device_memory_sync(env_deriv_dev, env_deriv); + deepmd::malloc_device_memory_sync(nlist_dev, nlist); + deepmd::malloc_device_memory_sync(force_dev, force); + deepmd::malloc_device_memory_sync(net_deriv_dev, net_deriv); + deepmd::malloc_device_memory_sync(env_deriv_dev, env_deriv); deepmd::prod_force_a_gpu_cuda (force_dev, net_deriv_dev, env_deriv_dev, nlist_dev, nloc, nall, nnei); - memcpy_device_to_host(force_dev, force); - delete_device_memory(nlist_dev); - delete_device_memory(force_dev); - delete_device_memory(net_deriv_dev); - delete_device_memory(env_deriv_dev); + deepmd::memcpy_device_to_host(force_dev, force); + deepmd::delete_device_memory(nlist_dev); + deepmd::delete_device_memory(force_dev); + deepmd::delete_device_memory(net_deriv_dev); + deepmd::delete_device_memory(env_deriv_dev); EXPECT_EQ(force.size(), nall * 3); EXPECT_EQ(force.size(), expected_force.size()); diff --git a/source/lib/tests/test_prod_force_r.cc b/source/lib/tests/test_prod_force_r.cc index 1247a94dda..e77cafdace 100644 --- a/source/lib/tests/test_prod_force_r.cc +++ b/source/lib/tests/test_prod_force_r.cc @@ -107,18 +107,18 @@ TEST_F(TestProdForceR, gpu_cuda) int * nlist_dev = NULL; double * force_dev = NULL, * net_deriv_dev = NULL, * env_deriv_dev = NULL; - malloc_device_memory_sync(nlist_dev, nlist); - malloc_device_memory_sync(force_dev, force); - malloc_device_memory_sync(net_deriv_dev, net_deriv); - malloc_device_memory_sync(env_deriv_dev, env_deriv); + deepmd::malloc_device_memory_sync(nlist_dev, nlist); + deepmd::malloc_device_memory_sync(force_dev, force); + deepmd::malloc_device_memory_sync(net_deriv_dev, net_deriv); + deepmd::malloc_device_memory_sync(env_deriv_dev, env_deriv); deepmd::prod_force_r_gpu_cuda (force_dev, net_deriv_dev, env_deriv_dev, nlist_dev, nloc, nall, nnei); - memcpy_device_to_host(force_dev, force); - delete_device_memory(nlist_dev); - delete_device_memory(force_dev); - delete_device_memory(net_deriv_dev); - delete_device_memory(env_deriv_dev); + deepmd::memcpy_device_to_host(force_dev, force); + deepmd::delete_device_memory(nlist_dev); + deepmd::delete_device_memory(force_dev); + deepmd::delete_device_memory(net_deriv_dev); + deepmd::delete_device_memory(env_deriv_dev); EXPECT_EQ(force.size(), nall * 3); EXPECT_EQ(force.size(), expected_force.size()); diff --git a/source/lib/tests/test_prod_virial_a.cc b/source/lib/tests/test_prod_virial_a.cc index 1eb7d0f0f9..4cade7c771 100644 --- a/source/lib/tests/test_prod_virial_a.cc +++ b/source/lib/tests/test_prod_virial_a.cc @@ -123,23 +123,23 @@ TEST_F(TestProdVirialA, gpu_cuda) int * nlist_dev = NULL; double * virial_dev = NULL, *atom_virial_dev = NULL, * net_deriv_dev = NULL, * env_deriv_dev = NULL, * rij_dev = NULL; - malloc_device_memory_sync(nlist_dev, nlist); - malloc_device_memory_sync(virial_dev, virial); - malloc_device_memory_sync(atom_virial_dev, atom_virial); - malloc_device_memory_sync(net_deriv_dev, net_deriv); - malloc_device_memory_sync(env_deriv_dev, env_deriv); - malloc_device_memory_sync(rij_dev, rij); + deepmd::malloc_device_memory_sync(nlist_dev, nlist); + deepmd::malloc_device_memory_sync(virial_dev, virial); + deepmd::malloc_device_memory_sync(atom_virial_dev, atom_virial); + deepmd::malloc_device_memory_sync(net_deriv_dev, net_deriv); + deepmd::malloc_device_memory_sync(env_deriv_dev, env_deriv); + deepmd::malloc_device_memory_sync(rij_dev, rij); deepmd::prod_virial_a_gpu_cuda (virial_dev, atom_virial_dev, net_deriv_dev, env_deriv_dev, rij_dev, nlist_dev, nloc, nall, nnei); - memcpy_device_to_host(virial_dev, virial); - memcpy_device_to_host(atom_virial_dev, atom_virial); - delete_device_memory(nlist_dev); - delete_device_memory(virial_dev); - delete_device_memory(atom_virial_dev); - delete_device_memory(net_deriv_dev); - delete_device_memory(env_deriv_dev); - delete_device_memory(rij_dev); + deepmd::memcpy_device_to_host(virial_dev, virial); + deepmd::memcpy_device_to_host(atom_virial_dev, atom_virial); + deepmd::delete_device_memory(nlist_dev); + deepmd::delete_device_memory(virial_dev); + deepmd::delete_device_memory(atom_virial_dev); + deepmd::delete_device_memory(net_deriv_dev); + deepmd::delete_device_memory(env_deriv_dev); + deepmd::delete_device_memory(rij_dev); // virial are not calculated in gpu currently; for (int ii = 0; ii < 9; ii++) { virial[ii] = 0; diff --git a/source/lib/tests/test_prod_virial_r.cc b/source/lib/tests/test_prod_virial_r.cc index 4780d9358d..b321454b8e 100644 --- a/source/lib/tests/test_prod_virial_r.cc +++ b/source/lib/tests/test_prod_virial_r.cc @@ -123,23 +123,23 @@ TEST_F(TestProdVirialR, gpu_cuda) int * nlist_dev = NULL; double * virial_dev = NULL, *atom_virial_dev = NULL, * net_deriv_dev = NULL, * env_deriv_dev = NULL, * rij_dev = NULL; - malloc_device_memory_sync(nlist_dev, nlist); - malloc_device_memory_sync(virial_dev, virial); - malloc_device_memory_sync(atom_virial_dev, atom_virial); - malloc_device_memory_sync(net_deriv_dev, net_deriv); - malloc_device_memory_sync(env_deriv_dev, env_deriv); - malloc_device_memory_sync(rij_dev, rij); + deepmd::malloc_device_memory_sync(nlist_dev, nlist); + deepmd::malloc_device_memory_sync(virial_dev, virial); + deepmd::malloc_device_memory_sync(atom_virial_dev, atom_virial); + deepmd::malloc_device_memory_sync(net_deriv_dev, net_deriv); + deepmd::malloc_device_memory_sync(env_deriv_dev, env_deriv); + deepmd::malloc_device_memory_sync(rij_dev, rij); deepmd::prod_virial_r_gpu_cuda (virial_dev, atom_virial_dev, net_deriv_dev, env_deriv_dev, rij_dev, nlist_dev, nloc, nall, nnei); - memcpy_device_to_host(virial_dev, virial); - memcpy_device_to_host(atom_virial_dev, atom_virial); - delete_device_memory(nlist_dev); - delete_device_memory(virial_dev); - delete_device_memory(atom_virial_dev); - delete_device_memory(net_deriv_dev); - delete_device_memory(env_deriv_dev); - delete_device_memory(rij_dev); + deepmd::memcpy_device_to_host(virial_dev, virial); + deepmd::memcpy_device_to_host(atom_virial_dev, atom_virial); + deepmd::delete_device_memory(nlist_dev); + deepmd::delete_device_memory(virial_dev); + deepmd::delete_device_memory(atom_virial_dev); + deepmd::delete_device_memory(net_deriv_dev); + deepmd::delete_device_memory(env_deriv_dev); + deepmd::delete_device_memory(rij_dev); // virial are not calculated in gpu currently; for (int ii = 0; ii < 9; ii++) { virial[ii] = 0; diff --git a/source/lib/tests/test_tabulate.cc b/source/lib/tests/test_tabulate.cc index f92629efb4..b22cca03d8 100644 --- a/source/lib/tests/test_tabulate.cc +++ b/source/lib/tests/test_tabulate.cc @@ -179,16 +179,16 @@ TEST_F(TestTabulate, tabulate_fusion_gpu_cuda) std::vector xyz_scatter(nloc * nnei * last_layer_size, 0.0); double * xyz_scatter_dev = NULL, * table_dev = NULL, * em_x_dev = NULL, * em_dev = NULL; - malloc_device_memory_sync(xyz_scatter_dev, xyz_scatter); - malloc_device_memory_sync(table_dev, table); - malloc_device_memory_sync(em_x_dev, em_x); - malloc_device_memory_sync(em_dev, em); + deepmd::malloc_device_memory_sync(xyz_scatter_dev, xyz_scatter); + deepmd::malloc_device_memory_sync(table_dev, table); + deepmd::malloc_device_memory_sync(em_x_dev, em_x); + deepmd::malloc_device_memory_sync(em_dev, em); deepmd::tabulate_fusion_gpu_cuda(xyz_scatter_dev, table_dev, &info[0], em_x_dev, em_dev, nloc, nnei, last_layer_size); - memcpy_device_to_host(xyz_scatter_dev, xyz_scatter); - delete_device_memory(xyz_scatter_dev); - delete_device_memory(table_dev); - delete_device_memory(em_x_dev); - delete_device_memory(em_dev); + deepmd::memcpy_device_to_host(xyz_scatter_dev, xyz_scatter); + deepmd::delete_device_memory(xyz_scatter_dev); + deepmd::delete_device_memory(table_dev); + deepmd::delete_device_memory(em_x_dev); + deepmd::delete_device_memory(em_dev); EXPECT_EQ(xyz_scatter.size(), nloc * nnei * last_layer_size); EXPECT_EQ(xyz_scatter.size(), expected_xyz_scatter.size()); @@ -204,21 +204,21 @@ TEST_F(TestTabulate, tabulate_fusion_grad_gpu_cuda) std::vector dy(nloc * nnei * last_layer_size, 1.0); double * dy_dem_x_dev = NULL, * dy_dem_dev = NULL, * table_dev = NULL, * em_x_dev = NULL, * em_dev = NULL, * dy_dev = NULL; - malloc_device_memory_sync(dy_dem_x_dev, dy_dem_x); - malloc_device_memory_sync(dy_dem_dev, dy_dem); - malloc_device_memory_sync(table_dev, table); - malloc_device_memory_sync(em_x_dev, em_x); - malloc_device_memory_sync(em_dev, em); - malloc_device_memory_sync(dy_dev, dy); + deepmd::malloc_device_memory_sync(dy_dem_x_dev, dy_dem_x); + deepmd::malloc_device_memory_sync(dy_dem_dev, dy_dem); + deepmd::malloc_device_memory_sync(table_dev, table); + deepmd::malloc_device_memory_sync(em_x_dev, em_x); + deepmd::malloc_device_memory_sync(em_dev, em); + deepmd::malloc_device_memory_sync(dy_dev, dy); deepmd::tabulate_fusion_grad_gpu_cuda(dy_dem_x_dev, dy_dem_dev, table_dev, &info[0], em_x_dev, em_dev, dy_dev, nloc, nnei, last_layer_size); - memcpy_device_to_host(dy_dem_x_dev, dy_dem_x); - memcpy_device_to_host(dy_dem_dev, dy_dem); - delete_device_memory(dy_dem_x_dev); - delete_device_memory(dy_dem_dev); - delete_device_memory(table_dev); - delete_device_memory(em_x_dev); - delete_device_memory(em_dev); - delete_device_memory(dy_dev); + deepmd::memcpy_device_to_host(dy_dem_x_dev, dy_dem_x); + deepmd::memcpy_device_to_host(dy_dem_dev, dy_dem); + deepmd::delete_device_memory(dy_dem_x_dev); + deepmd::delete_device_memory(dy_dem_dev); + deepmd::delete_device_memory(table_dev); + deepmd::delete_device_memory(em_x_dev); + deepmd::delete_device_memory(em_dev); + deepmd::delete_device_memory(dy_dev); EXPECT_EQ(dy_dem_x.size(), nloc * nnei); EXPECT_EQ(dy_dem.size(), nloc * nnei * 4); From 708de6ceb9c17983dc3430bad830f20b2eb2af2f Mon Sep 17 00:00:00 2001 From: Han Wang Date: Sat, 20 Mar 2021 00:32:28 +0800 Subject: [PATCH 18/23] better output format during training, testing and in lcurve.out --- deepmd/entrypoints/test.py | 34 +++++++++++++++++----------------- deepmd/loggers/loggers.py | 6 ++++-- deepmd/loss/ener.py | 16 ++++++++-------- deepmd/loss/tensor.py | 6 +++--- deepmd/utils/data_system.py | 24 +++++++++++++----------- 5 files changed, 45 insertions(+), 41 deletions(-) diff --git a/deepmd/entrypoints/test.py b/deepmd/entrypoints/test.py index 6d4a2c4ad8..5c91547866 100644 --- a/deepmd/entrypoints/test.py +++ b/deepmd/entrypoints/test.py @@ -292,13 +292,13 @@ def test_ener( # print ("# energies: %s" % energy) log.info(f"# number of test data : {numb_test:d} ") - log.info(f"Energy L2err : {l2e:e} eV") - log.info(f"Energy L2err/Natoms : {l2ea:e} eV") - log.info(f"Force L2err : {l2f:e} eV/A") - log.info(f"Virial L2err : {l2v:e} eV") - log.info(f"Virial L2err/Natoms : {l2va:e} eV") + log.info(f"Energy RMSE : {l2e:e} eV") + log.info(f"Energy RMSE/Natoms : {l2ea:e} eV") + log.info(f"Force RMSE : {l2f:e} eV/A") + log.info(f"Virial RMSE : {l2v:e} eV") + log.info(f"Virial RMSE/Natoms : {l2va:e} eV") if has_atom_ener: - log.info(f"Atomic ener L2err : {l2ae:e} eV") + log.info(f"Atomic ener RMSE : {l2ae:e} eV") if detail_file is not None: detail_path = Path(detail_file) @@ -355,9 +355,9 @@ def print_ener_sys_avg(avg: np.ndarray): avg : np.ndarray array with summaries """ - log.info(f"Energy L2err/Natoms : {avg[0]:e} eV") - log.info(f"Force L2err : {avg[1]:e} eV/A") - log.info(f"Virial L2err/Natoms : {avg[2]:e} eV") + log.info(f"Energy RMSE/Natoms : {avg[0]:e} eV") + log.info(f"Force RMSE : {avg[1]:e} eV/A") + log.info(f"Virial RMSE/Natoms : {avg[2]:e} eV") def run_test(dp: "DeepTensor", test_data: dict, numb_test: int): @@ -420,7 +420,7 @@ def test_wfc( l2f = l2err(wfc - test_data["wfc"][:numb_test]) log.info("# number of test data : {numb_test:d} ") - log.info("WFC L2err : {l2f:e} eV/A") + log.info("WFC RMSE : {l2f:e} eV/A") if detail_file is not None: detail_path = Path(detail_file) @@ -447,7 +447,7 @@ def print_wfc_sys_avg(avg): avg : np.ndarray array with summaries """ - log.info(f"WFC L2err : {avg[0]:e} eV/A") + log.info(f"WFC RMSE : {avg[0]:e} eV/A") def test_polar( @@ -509,10 +509,10 @@ def test_polar( l2fa = l2f / sel_natoms log.info(f"# number of test data : {numb_test:d} ") - log.info(f"Polarizability L2err : {l2f:e} eV/A") + log.info(f"Polarizability RMSE : {l2f:e} eV/A") if global_polar: - log.info(f"Polarizability L2err/sqrtN : {l2fs:e} eV/A") - log.info(f"Polarizability L2err/N : {l2fa:e} eV/A") + log.info(f"Polarizability RMSE/sqrtN : {l2fs:e} eV/A") + log.info(f"Polarizability RMSE/N : {l2fa:e} eV/A") if detail_file is not None: detail_path = Path(detail_file) @@ -542,7 +542,7 @@ def print_polar_sys_avg(avg): avg : np.ndarray array with summaries """ - log.info(f"Polarizability L2err : {avg[0]:e} eV/A") + log.info(f"Polarizability RMSE : {avg[0]:e} eV/A") def test_dipole( @@ -577,7 +577,7 @@ def test_dipole( l2f = l2err(dipole - test_data["dipole"][:numb_test]) log.info(f"# number of test data : {numb_test:d}") - log.info(f"Dipole L2err : {l2f:e} eV/A") + log.info(f"Dipole RMSE : {l2f:e} eV/A") if detail_file is not None: detail_path = Path(detail_file) @@ -605,4 +605,4 @@ def print_dipole_sys_avg(avg): avg : np.ndarray array with summaries """ - log.info(f"Dipole L2err : {avg[0]:e} eV/A") + log.info(f"Dipole RMSE : {avg[0]:e} eV/A") diff --git a/deepmd/loggers/loggers.py b/deepmd/loggers/loggers.py index 6400cb0a15..f787ff1e1a 100644 --- a/deepmd/loggers/loggers.py +++ b/deepmd/loggers/loggers.py @@ -20,13 +20,15 @@ "[%(asctime)s] %(app_name)s %(levelname)-7s %(name)-45s %(message)s" ) CFORMATTER = logging.Formatter( - "%(app_name)s %(levelname)-7s |-> %(name)-45s %(message)s" +# "%(app_name)s %(levelname)-7s |-> %(name)-45s %(message)s" + "%(app_name)s %(levelname)-7s %(message)s" ) FFORMATTER_MPI = logging.Formatter( "[%(asctime)s] %(app_name)s rank:%(rank)-2s %(levelname)-7s %(name)-45s %(message)s" ) CFORMATTER_MPI = logging.Formatter( - "%(app_name)s rank:%(rank)-2s %(levelname)-7s |-> %(name)-45s %(message)s" +# "%(app_name)s rank:%(rank)-2s %(levelname)-7s |-> %(name)-45s %(message)s" + "%(app_name)s rank:%(rank)-2s %(levelname)-7s %(message)s" ) diff --git a/deepmd/loss/ener.py b/deepmd/loss/ener.py index 89d15b3add..d4a5b11509 100644 --- a/deepmd/loss/ener.py +++ b/deepmd/loss/ener.py @@ -128,19 +128,19 @@ def build (self, return l2_loss, more_loss def print_header(self): - prop_fmt = ' %9s %9s' + prop_fmt = ' %11s %11s' print_str = '' - print_str += prop_fmt % ('l2_tst', 'l2_trn') + print_str += prop_fmt % ('rmse_tst', 'rmse_trn') if self.has_e : - print_str += prop_fmt % ('l2_e_tst', 'l2_e_trn') + print_str += prop_fmt % ('rmse_e_tst', 'rmse_e_trn') if self.has_ae : - print_str += prop_fmt % ('l2_ae_tst', 'l2_ae_trn') + print_str += prop_fmt % ('rmse_ae_tst', 'rmse_ae_trn') if self.has_f : - print_str += prop_fmt % ('l2_f_tst', 'l2_f_trn') + print_str += prop_fmt % ('rmse_f_tst', 'rmse_f_trn') if self.has_v : - print_str += prop_fmt % ('l2_v_tst', 'l2_v_trn') + print_str += prop_fmt % ('rmse_v_tst', 'rmse_v_trn') if self.has_pf : - print_str += prop_fmt % ('l2_pf_tst', 'l2_pf_trn') + print_str += prop_fmt % ('rmse_pf_tst', 'rmse_pf_trn') return print_str def print_on_training(self, @@ -180,7 +180,7 @@ def print_on_training(self, print_str = "" - prop_fmt = " %9.2e %9.2e" + prop_fmt = " %11.2e %11.2e" print_str += prop_fmt % (np.sqrt(error_test), np.sqrt(error_train)) if self.has_e : print_str += prop_fmt % (np.sqrt(error_e_test) / natoms[0], np.sqrt(error_e_train) / natoms[0]) diff --git a/deepmd/loss/tensor.py b/deepmd/loss/tensor.py index 8784427808..3327c418d5 100644 --- a/deepmd/loss/tensor.py +++ b/deepmd/loss/tensor.py @@ -52,9 +52,9 @@ def build (self, @staticmethod def print_header(): - prop_fmt = ' %9s %9s' + prop_fmt = ' %11s %11s' print_str = '' - print_str += prop_fmt % ('l2_tst', 'l2_trn') + print_str += prop_fmt % ('rmse_tst', 'rmse_trn') return print_str def print_on_training(self, @@ -85,7 +85,7 @@ def print_on_training(self, error_test = test_out[0] print_str = "" - prop_fmt = " %9.2e %9.2e" + prop_fmt = " %11.2e %11.2e" print_str += prop_fmt % (np.sqrt(error_test), np.sqrt(error_train)) return print_str diff --git a/deepmd/utils/data_system.py b/deepmd/utils/data_system.py index e9d07a51ad..557a2c6bd0 100644 --- a/deepmd/utils/data_system.py +++ b/deepmd/utils/data_system.py @@ -404,20 +404,22 @@ def print_summary(self, prob = self._get_sys_probs(sys_probs, auto_prob_style) # width 65 sys_width = 42 - log.info("---Summary of DataSystem------------------------------------------------") + log.info("---Summary of DataSystem--------------------------------------------------------------") log.info("found %d system(s):" % self.nsystems) - log.info("%s " % self._format_name_length('system', sys_width)) - log.info("%s %s %s %s %5s" % ('natoms', 'bch_sz', 'n_bch', "n_test", 'prob')) + log.info(("%s " % self._format_name_length('system', sys_width)) + + ("%6s %6s %6s %6s %5s %3s" % ('natoms', 'bch_sz', 'n_bch', "n_test", 'prob', 'pbc'))) for ii in range(self.nsystems) : - log.info("%s %6d %6d %6d %6d %5.3f" % + log.info("%s %6d %6d %6d %6d %5.3f %3s" % (self._format_name_length(self.system_dirs[ii], sys_width), - self.natoms[ii], - # TODO batch size * nbatches = number of structures - self.batch_size[ii], - self.nbatches[ii], - self.test_size[ii], - prob[ii]) ) - log.info("------------------------------------------------------------------------\n") + self.natoms[ii], + # TODO batch size * nbatches = number of structures + self.batch_size[ii], + self.nbatches[ii], + self.test_size[ii], + prob[ii], + "T" if self.data_systems[ii].pbc else "F" + ) ) + log.info("--------------------------------------------------------------------------------------") def _make_auto_bs(self, rule) : bs = [] From c3e9292dc97586ef497d36bf682f2ca7c3438d28 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 21 Mar 2021 20:34:25 -0400 Subject: [PATCH 19/23] fix bugs of ase calculator and add tests --- source/tests/test_deeppot_a.py | 14 ++++++++++++++ source/train/calculator.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/source/tests/test_deeppot_a.py b/source/tests/test_deeppot_a.py index 8541cb8fa3..6f8c800d16 100644 --- a/source/tests/test_deeppot_a.py +++ b/source/tests/test_deeppot_a.py @@ -324,4 +324,18 @@ def test_1frame_atm(self): for ii in range(nframes, 9): self.assertAlmostEqual(vv.reshape([-1])[ii], expected_sv.reshape([-1])[ii], places = default_places) + def test_ase(self): + from ase import Atoms + from deepmd.calculator import DP + water = Atoms('OHHOHH', + positions=self.coords.reshape((-1,3)), + cell=self.box.reshpae((3,3)), + calculator=self.dp) + ee = water.get_potential_energy() + ff = water.get_forces() + for ii in range(ff.size): + self.assertAlmostEqual(ff.reshape([-1])[ii], self.expected_f.reshape([-1])[ii], places = default_places) + expected_se = np.sum(self.expected_e.reshape([nframes, -1]), axis = 1) + for ii in range(nframes): + self.assertAlmostEqual(ee.reshape([-1])[ii], expected_se.reshape([-1])[ii], places = default_places) diff --git a/source/train/calculator.py b/source/train/calculator.py index e9c8e63c7d..b70305a26c 100644 --- a/source/train/calculator.py +++ b/source/train/calculator.py @@ -62,7 +62,7 @@ def __init__( **kwargs ) -> None: Calculator.__init__(self, label=label, **kwargs) - self.dp = DeepPot(str(Path(model).resolve())) + self.dp = DeepPotential(str(Path(model).resolve())) if type_dict: self.type_dict = type_dict else: From 373349c231da586b3830e8df5938f79645df2dc6 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 21 Mar 2021 20:37:06 -0400 Subject: [PATCH 20/23] add ase to tests --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index cf83e4955f..729d62650d 100644 --- a/setup.py +++ b/setup.py @@ -104,7 +104,7 @@ cmake_source_dir="source", cmake_minimum_required_version="3.0", extras_require={ - "test": ["dpdata>=0.1.9", "pytest", "pytest-cov", "pytest-sugar"], + "test": ["dpdata>=0.1.9", "ase", "pytest", "pytest-cov", "pytest-sugar"], "docs": ["sphinx", "recommonmark", "sphinx_rtd_theme"], **extras_require, }, From c5eef2f8182b0e858059b467989e541afc1abeb6 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 21 Mar 2021 21:03:56 -0400 Subject: [PATCH 21/23] fix typo --- source/tests/test_deeppot_a.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/tests/test_deeppot_a.py b/source/tests/test_deeppot_a.py index 6f8c800d16..ed24fa5875 100644 --- a/source/tests/test_deeppot_a.py +++ b/source/tests/test_deeppot_a.py @@ -329,7 +329,7 @@ def test_ase(self): from deepmd.calculator import DP water = Atoms('OHHOHH', positions=self.coords.reshape((-1,3)), - cell=self.box.reshpae((3,3)), + cell=self.box.reshape((3,3)), calculator=self.dp) ee = water.get_potential_energy() ff = water.get_forces() From d5354fdd383ecb8e8589fbb4762407232b05641c Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 21 Mar 2021 21:19:57 -0400 Subject: [PATCH 22/23] fix bug --- source/tests/test_deeppot_a.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/tests/test_deeppot_a.py b/source/tests/test_deeppot_a.py index ed24fa5875..f4e73682f3 100644 --- a/source/tests/test_deeppot_a.py +++ b/source/tests/test_deeppot_a.py @@ -330,9 +330,10 @@ def test_ase(self): water = Atoms('OHHOHH', positions=self.coords.reshape((-1,3)), cell=self.box.reshape((3,3)), - calculator=self.dp) + calculator=DP("deeppot.pb")) ee = water.get_potential_energy() ff = water.get_forces() + nframes = 1 for ii in range(ff.size): self.assertAlmostEqual(ff.reshape([-1])[ii], self.expected_f.reshape([-1])[ii], places = default_places) expected_se = np.sum(self.expected_e.reshape([nframes, -1]), axis = 1) From c7475d731347c2e9921a9f5afbf8d327b3b8bdbf Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 22 Mar 2021 23:30:25 -0400 Subject: [PATCH 23/23] import Path for runtime --- source/train/calculator.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/train/calculator.py b/source/train/calculator.py index b70305a26c..7ca7943d7a 100644 --- a/source/train/calculator.py +++ b/source/train/calculator.py @@ -1,13 +1,12 @@ """ASE calculator interface module.""" from typing import TYPE_CHECKING, Dict, List, Optional, Union +from pathlib import Path from deepmd import DeepPotential from ase.calculators.calculator import Calculator, all_changes if TYPE_CHECKING: - from pathlib import Path - from ase import Atoms __all__ = ["DP"]