Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions deepmd/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,25 @@ def _get_package_constants(
op_module = get_module("libop_abi")
op_grads_module = get_module("libop_grads")

if GLOBAL_CONFIG["precision"] == "-DHIGH_PREC":
# FLOAT_PREC
dp_float_prec = os.environ.get("DP_INTERFACE_PREC", "high").lower()
if dp_float_prec in ("high", ""):
# default is high
GLOBAL_TF_FLOAT_PRECISION = tf.float64
GLOBAL_NP_FLOAT_PRECISION = np.float64
GLOBAL_ENER_FLOAT_PRECISION = np.float64
global_float_prec = "double"
else:
elif dp_float_prec == "low":
GLOBAL_TF_FLOAT_PRECISION = tf.float32
GLOBAL_NP_FLOAT_PRECISION = np.float32
GLOBAL_ENER_FLOAT_PRECISION = np.float64
global_float_prec = "float"
else:
raise RuntimeError(
"Unsupported float precision option: %s. Supported: high,"
"low. Please set precision with environmental variable "
"DP_INTERFACE_PREC." % dp_float_prec
)


def global_cvt_2_tf_float(xx: tf.Tensor) -> tf.Tensor:
Expand Down
8 changes: 7 additions & 1 deletion doc/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ export TF_INTER_OP_PARALLELISM_THREADS=2
dp train input.json
```

One can set other environmental variables:

| Environment variables | Allowed value | Default value | Usage |
| --------------------- | ---------------------- | ------------- | -------------------------- |
| DP_INTERFACE_PREC | `high`, `low` | `high` | Control high (double) or low (float) precision of training. |

### Training analysis with Tensorboard

If enbled in json/yaml input file DeePMD-kit will create log files which can be
Expand Down Expand Up @@ -425,7 +431,7 @@ kspace_modify gewald 0.45
Please notice that the DeePMD does nothing to the direct space part of the electrostatic interaction, because this part is assumed to be fitted in the DeePMD model (the direct space cut-off is thus the cut-off of the DeePMD model). The splitting parameter `gewald` is modified by the `kspace_modify` command.

### Run path-integral MD with i-PI
The i-PI works in a client-server model. The i-PI provides the server for integrating the replica positions of atoms, while the DeePMD-kit provides a client named `dp_ipi` that computes the interactions (including energy, force and virial). The server and client communicates via the Unix domain socket or the Internet socket. Installation instructions of i-PI can be found [here](install.md#install-i-pi). The client can be started by
The i-PI works in a client-server model. The i-PI provides the server for integrating the replica positions of atoms, while the DeePMD-kit provides a client named `dp_ipi` (or `dp_ipi_low` for low precision) that computes the interactions (including energy, force and virial). The server and client communicates via the Unix domain socket or the Internet socket. Installation instructions of i-PI can be found [here](install.md#install-i-pi). The client can be started by
```bash
i-pi input.xml &
dp_ipi water.json
Expand Down
4 changes: 1 addition & 3 deletions doc/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ One may set the following environment variables before executing `pip`:
| Environment variables | Allowed value | Default value | Usage |
| --------------------- | ---------------------- | ------------- | -------------------------- |
| DP_VARIANT | `cpu`, `cuda`, `rocm` | `cpu` | Build CPU variant or GPU variant with CUDA or ROCM support. |
| DP_FLOAT_PREC | `high`, `low` | `high` | Build high (double) or low (float) precision. |
| CUDA_TOOLKIT_ROOT_DIR | Path | Detected automatically | The path to the CUDA toolkit directory. |
| ROCM_ROOT | Path | Detected automatically | The path to the ROCM toolkit directory. |

Expand Down Expand Up @@ -201,7 +200,6 @@ One may add the following arguments to `cmake`:
| ------------------------ | ------------------- | ------------- | ------------------------|
| -DTENSORFLOW_ROOT=<value> | Path | - | The Path to TensorFlow's C++ interface. |
| -DCMAKE_INSTALL_PREFIX=<value> | Path | - | The Path where DeePMD-kit will be installed. |
| -DFLOAT_PREC=<value> | `high` or `low` | `high` | Build high (double) or low (float) precision. |
| -DUSE_CUDA_TOOLKIT=<value> | `TRUE` or `FALSE` | `FALSE` | If `TRUE`, Build GPU support with CUDA toolkit. |
| -DCUDA_TOOLKIT_ROOT_DIR=<value> | Path | Detected automatically | The path to the CUDA toolkit directory. |
| -DUSE_ROCM_TOOLKIT=<value> | `TRUE` or `FALSE` | `FALSE` | If `TRUE`, Build GPU support with ROCM toolkit. |
Expand All @@ -228,7 +226,7 @@ DeePMD-kit provide module for running MD simulation with LAMMPS. Now make the De
cd $deepmd_source_dir/source/build
make lammps
```
DeePMD-kit will generate a module called `USER-DEEPMD` in the `build` directory. Now download the LAMMPS code (`29Oct2020` or later), and uncompress it:
DeePMD-kit will generate a module called `USER-DEEPMD` in the `build` directory. If you need low precision version, move `env_low.sh` to `env.sh` in the directory. Now download the LAMMPS code (`29Oct2020` or later), and uncompress it:
```bash
cd /some/workspace
wget https://github.com/lammps/lammps/archive/stable_29Oct2020.tar.gz
Expand Down
10 changes: 0 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@
else:
raise RuntimeError("Unsupported DP_VARIANT option: %s" % dp_variant)

# FLOAT_PREC
dp_float_prec = os.environ.get("DP_FLOAT_PREC", "").lower()
if dp_float_prec in ["high", "low"]:
cmake_args.append("-DFLOAT_PREC:STRING=%s" % dp_float_prec)
elif dp_float_prec == "":
# default is high
cmake_args.append("-DFLOAT_PREC:STRING=high")
else:
raise RuntimeError("Unsupported float precision option: %s" % dp_float_prec)

# get tensorflow spec
tf_spec = find_spec("tensorflow")
if not tf_spec:
Expand Down
16 changes: 5 additions & 11 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,11 @@ if ((NOT DEFINED CMAKE_BUILD_TYPE) OR CMAKE_BUILD_TYPE STREQUAL "")
endif ()

# set op prec
if (DEFINED FLOAT_PREC)
string ( TOLOWER ${FLOAT_PREC} lower_float_prec )
if (lower_float_prec STREQUAL "high")
set(PREC_DEF "-DHIGH_PREC")
else ()
set(PREC_DEF "")
endif ()
else ()
set(PREC_DEF "-DHIGH_PREC")
endif()
add_definitions (${PREC_DEF})
set(HIGH_PREC_DEF "HIGH_PREC")
# this defination doesn't work, but leaving it empty will cause error
set(LOW_PREC_DEF "LOW_PREC")
set(HIGH_PREC_VARIANT "")
set(LOW_PREC_VARIANT "_low")

# find openmp
find_package(OpenMP)
Expand Down
14 changes: 13 additions & 1 deletion source/api_cc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# libmd
set (libname ${LIB_DEEPMD_CC})

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/version.h.in
Expand All @@ -18,6 +17,10 @@ endif()
file(GLOB LIB_SRC src/*.cc src/*.cpp)
file(GLOB INC_SRC include/*.h ${CMAKE_CURRENT_BINARY_DIR}/version.h)


function(_add_libapicc_variant variant_name prec_def)
set (libname "${LIB_DEEPMD_CC}${variant_name}")

add_library(${libname} SHARED ${LIB_SRC})

if (USE_CUDA_TOOLKIT)
Expand All @@ -28,6 +31,11 @@ if (USE_ROCM_TOOLKIT)
target_link_libraries (${libname} ${ROCM_LIBRARIES})
endif()

set_target_properties(
${libname}
PROPERTIES
COMPILE_DEFINITIONS ${prec_def}
)

install(TARGETS ${libname} DESTINATION lib/)

Expand All @@ -36,3 +44,7 @@ install(
DESTINATION include/deepmd
)

endfunction()

_add_libapicc_variant("${HIGH_PREC_VARIANT}" "${HIGH_PREC_DEF}")
_add_libapicc_variant("${LOW_PREC_VARIANT}" "${LOW_PREC_DEF}")
7 changes: 6 additions & 1 deletion source/cmake/cmake_lammps.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ endforeach ()
file (
INSTALL DESTINATION "${LMP_INSTALL_PREFIX}"
TYPE FILE
FILES "@CMAKE_BINARY_DIR@/lmp/env.sh"
FILES "@CMAKE_BINARY_DIR@/lmp/env@HIGH_PREC_VARIANT@.sh"
)
file (
INSTALL DESTINATION "${LMP_INSTALL_PREFIX}"
TYPE FILE
FILES "@CMAKE_BINARY_DIR@/lmp/env@LOW_PREC_VARIANT@.sh"
)

file (
Expand Down
1 change: 0 additions & 1 deletion source/config/run_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ TF_INCLUDE_DIR = @TensorFlow_INCLUDE_DIRS@
TF_LIBS = @TensorFlow_LIBRARY@
TF_VERSION = @TENSORFLOW_VERSION@
TF_CXX11_ABI_FLAG = @OP_CXX_ABI@
PRECISION = @PREC_DEF@
MODEL_VERSION=@MODEL_VERSION@
7 changes: 1 addition & 6 deletions source/install/build_cc.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
set -e

if [ -z "$FLOAT_PREC" ]
then
FLOAT_PREC=high
fi

if [ "$DP_VARIANT" == "cuda" ]
then
CUDA_ARGS="-DUSE_CUDA_TOOLKIT=TRUE"
Expand All @@ -25,7 +20,7 @@ NPROC=$(nproc --all)
BUILD_TMP_DIR=${SCRIPT_PATH}/../build
mkdir -p ${BUILD_TMP_DIR}
cd ${BUILD_TMP_DIR}
cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DFLOAT_PREC=${FLOAT_PREC} -DINSTALL_TENSORFLOW=TRUE ${CUDA_ARGS} ..
cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DINSTALL_TENSORFLOW=TRUE ${CUDA_ARGS} ..
make -j${NPROC}
make install

Expand Down
13 changes: 9 additions & 4 deletions source/install/build_lammps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ if [ -z "$FLOAT_PREC" ]
then
FLOAT_PREC=high
fi

if [ ${FLOAT_PREC} == "high" ]; then
PREC_DEF="-DHIGH_PREC"
PREC_SUFFIX=""
else
PREC_DEF="-DLOW_PREC"
PREC_SUFFIX="_low"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better if I changed this to LOW?
When I compile LAMMPS I need to manually change the "_low" to "_LOW"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the specific name do you mean you need to change? _low is used in 3 names, including -ldeepmd_cc_low, USER-DEEPMD_low, and ipi_low.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean USER-DEEPMD_low.
Otherwise, the following error occurs

[ludh@login09 src]$ make yes-user-deepmd_Low
Package USER-DEEPMD_LOW does not exist
make: *** [Makefile:364: yes-user-deepmd_Low] Error 1
I have to do this:
mv USER-DEEPMD_low USER-DEEPMD_LOW
then
make yes-user-deepmd_low
Installing package user-deepmd_low

fi
#------------------

SCRIPT_PATH=$(dirname $(realpath -s $0))
Expand Down Expand Up @@ -43,10 +51,7 @@ cp -r ${BUILD_TMP_DIR2}/USER-DEEPMD/* ${BUILD_TMP_DIR}/lammps-${LAMMPS_VERSION}/

mkdir -p ${BUILD_TMP_DIR}/lammps-${LAMMPS_VERSION}/build
cd ${BUILD_TMP_DIR}/lammps-${LAMMPS_VERSION}/build
if [ ${FLOAT_PREC} == "high" ]; then
export PREC_DEF="-DHIGH_PREC"
fi
cmake -C ../cmake/presets/all_off.cmake -D PKG_USER-DEEPMD=ON -D PKG_KSPACE=ON -D CMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -D CMAKE_CXX_FLAGS="${PREC_DEF} -I${INSTALL_PREFIX}/include -L${INSTALL_PREFIX}/lib -Wl,--no-as-needed -lrt -ldeepmd_op -ldeepmd -ldeepmd_cc -ltensorflow_cc -ltensorflow_framework -Wl,-rpath=${INSTALL_PREFIX}/lib" ../cmake
cmake -C ../cmake/presets/all_off.cmake -D PKG_USER-DEEPMD=ON -D PKG_KSPACE=ON -D CMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -D CMAKE_CXX_FLAGS="${PREC_DEF} -I${INSTALL_PREFIX}/include -L${INSTALL_PREFIX}/lib -Wl,--no-as-needed -lrt -ldeepmd_op -ldeepmd -ldeepmd_cc${PREC_SUFFIX} -ltensorflow_cc -ltensorflow_framework -Wl,-rpath=${INSTALL_PREFIX}/lib" ../cmake

make -j${NPROC}
make install
Expand Down
20 changes: 14 additions & 6 deletions source/ipi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,32 @@ list (APPEND MD_INCLUDE_PATH "include")
include_directories (${MD_INCLUDE_PATH})

file(GLOB IN_SRC src/*.cc src/*.c)
add_library(${LIB_DEEPMD_IPI} SHARED ${IN_SRC})

function(_add_ipi_variant variant_name prec_def)
set (ipiname "dp_ipi${variant_name}")
set (libipiname "${LIB_DEEPMD_IPI}${variant_name}")
add_library(${libipiname} SHARED ${IN_SRC})

set(DRIVER_SOURCE_FILES driver.cc)
add_executable(dp_ipi ${DRIVER_SOURCE_FILES})
target_link_libraries(dp_ipi ${LIB_DEEPMD_IPI} ${LIB_DEEPMD_OP} ${LIB_DEEPMD_CC} ${LIB_DEEPMD} ${TensorFlow_LIBRARY})
add_executable(${ipiname} ${DRIVER_SOURCE_FILES})
target_link_libraries(${ipiname} ${libipiname} ${LIB_DEEPMD_OP} ${LIB_DEEPMD_CC}${variant_name} ${LIB_DEEPMD} ${TensorFlow_LIBRARY})

set_target_properties(
dp_ipi
${ipiname}
PROPERTIES
LINK_FLAGS "-Wl,-rpath,'$ORIGIN'/../lib -Wl,-z,defs"
INSTALL_RPATH "$ORIGIN/../lib:${TensorFlow_LIBRARY_PATH}"
COMPILE_DEFINITIONS ${prec_def}
)

install(
TARGETS ${LIB_DEEPMD_IPI}
TARGETS ${libipiname}
DESTINATION lib/
)
install(
TARGETS dp_ipi
TARGETS ${ipiname}
DESTINATION bin/
)
endfunction()
_add_ipi_variant("${HIGH_PREC_VARIANT}" "${HIGH_PREC_DEF}")
_add_ipi_variant("${LOW_PREC_VARIANT}" "${LOW_PREC_DEF}")
7 changes: 6 additions & 1 deletion source/lmp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ list (APPEND LMP_INSTALL_FILES ${LMP_HEADER})
list (APPEND LMP_INSTALL_FILES ${LMP_SRC})
list (APPEND LMP_INSTALL_FILES ${LMP_SHSCRIPT})

configure_file("env.sh.in" "env.sh" @ONLY)
function(_add_lmp_variant variant_name prec_def)
configure_file("env.sh.in" "env${variant_name}.sh" @ONLY)
endfunction()
_add_lmp_variant("${HIGH_PREC_VARIANT}" "${HIGH_PREC_DEF}")
_add_lmp_variant("${LOW_PREC_VARIANT}" "${LOW_PREC_DEF}")

configure_file("pair_deepmd.h.in" "pair_deepmd.h" @ONLY)
configure_file("lammps_install_list.txt.in" "lammps_install_list.txt" @ONLY)
4 changes: 2 additions & 2 deletions source/lmp/env.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -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/ "
NNP_INC=" -std=c++11 -D@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_DEVICE@ -l@LIB_DEEPMD_OP@ -l@LIB_DEEPMD_CC@ -l@LIB_DEEPMD@ -ltensorflow_cc -ltensorflow_framework -Wl,-rpath=$TF_RPATH -Wl,-rpath=$DEEPMD_ROOT/lib"
NNP_LIB=" -Wl,--no-as-needed -l@LIB_DEEPMD_OP_DEVICE@ -l@LIB_DEEPMD_OP@ -l@LIB_DEEPMD_CC@@variant_name@ -l@LIB_DEEPMD@ -ltensorflow_cc -ltensorflow_framework -Wl,-rpath=$TF_RPATH -Wl,-rpath=$DEEPMD_ROOT/lib"
32 changes: 20 additions & 12 deletions source/md/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,38 @@ if (MAKE_FF_AD)
set(MDFF_SOURCE_FILES mdff.cc)
endif()

add_executable(dp_mdnn ${MDNN_SOURCE_FILES})
function(_add_md_variant variant_name prec_def)
set (dp_mdnn_name "dp_mdnn${variant_name}")
set (dp_mdff_name "dp_mdff${variant_name}")
set (dp_mdad_name "dp_mdad${variant_name}")

add_executable(${dp_mdnn_name} ${MDNN_SOURCE_FILES})
if (MAKE_FF_AD)
add_executable(dp_mdff ${MDFF_SOURCE_FILES})
add_executable(dp_mdad ${MDAD_SOURCE_FILES})
add_executable(${dp_mdff_name} ${MDFF_SOURCE_FILES})
add_executable(${dp_mdad_name} ${MDAD_SOURCE_FILES})
endif()

target_link_libraries(dp_mdnn ${LIB_DEEPMD_NATIVE} ${LIB_DEEPMD_OP} ${LIB_DEEPMD} ${XDRFILE_LIBRARIES} ${TensorFlow_LIBRARY})
target_link_libraries(${dp_mdnn_name} ${LIB_DEEPMD_NATIVE} ${LIB_DEEPMD_OP} ${LIB_DEEPMD} ${XDRFILE_LIBRARIES} ${TensorFlow_LIBRARY})
if (MAKE_FF_AD)
target_link_libraries(dp_mdad ${LIB_DEEPMD_NATIVE} ${LIB_DEEPMD_OP} ${LIB_DEEPMD} ${XDRFILE_LIBRARIES} ${TensorFlow_LIBRARY})
target_link_libraries(dp_mdff ${LIB_DEEPMD_NATIVE} ${LIB_DEEPMD} ${XDRFILE_LIBRARIES} ${TensorFlow_LIBRARY})
target_link_libraries(${dp_mdad_name} ${LIB_DEEPMD_NATIVE} ${LIB_DEEPMD_OP} ${LIB_DEEPMD} ${XDRFILE_LIBRARIES} ${TensorFlow_LIBRARY})
target_link_libraries(${dp_mdff_name} ${LIB_DEEPMD_NATIVE} ${LIB_DEEPMD} ${XDRFILE_LIBRARIES} ${TensorFlow_LIBRARY})
endif()

set_target_properties(
dp_mdnn
${dp_mdnn_name}
PROPERTIES
LINK_FLAGS "-Wl,-rpath,'$ORIGIN'/../lib -Wl,-z,defs"
INSTALL_RPATH "$ORIGIN/../lib:${TensorFlow_LIBRARY_PATH}"
)
if (MAKE_FF_AD)
set_target_properties(
dp_mdad
${dp_mdad_name}
PROPERTIES
LINK_FLAGS "-Wl,-rpath,'$ORIGIN'/../lib -Wl,-z,defs"
INSTALL_RPATH "$ORIGIN/../lib:${TensorFlow_LIBRARY_PATH}"
)
set_target_properties(
dp_mdff
${dp_mdff_name}
PROPERTIES
LINK_FLAGS "-Wl,-rpath,'$ORIGIN'/../lib -Wl,-z,defs"
INSTALL_RPATH "$ORIGIN/../lib:${TensorFlow_LIBRARY_PATH}"
Expand All @@ -55,16 +60,19 @@ install(
DESTINATION lib/
)
install(
TARGETS dp_mdnn
TARGETS ${dp_mdnn_name}
DESTINATION bin/
)
if (MAKE_FF_AD)
install(
TARGETS dp_mdad
TARGETS ${dp_mdad_name}
DESTINATION bin/
)
install(
TARGETS dp_mdff
TARGETS ${dp_mdff_name}
DESTINATION bin/
)
endif()
endfunction()
_add_md_variant("${HIGH_PREC_VARIANT}" "${HIGH_PREC_DEF}")
_add_md_variant("${LOW_PREC_VARIANT}" "${LOW_PREC_DEF}")