Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8211ed8
checkpoint
njzjz Dec 15, 2022
385a40a
add entry points
njzjz Dec 16, 2022
a48d6aa
build lammps plugins into wheels
njzjz Dec 16, 2022
85ebc5f
Update pyproject.toml
njzjz Dec 16, 2022
558dc60
c: DeepTensor (#2184)
njzjz Dec 17, 2022
0a742df
build wheels for Linux ARM64 (#2179)
njzjz Dec 17, 2022
064f654
build_tf.py: export `LD_LIBRARY_PATH` when executing `configure` (#2185)
njzjz Dec 17, 2022
ae79021
fix errors
njzjz Dec 18, 2022
e2944e4
fix
njzjz Dec 18, 2022
3bf740a
fix before-all
njzjz Dec 18, 2022
c7fb321
fix win
njzjz Dec 18, 2022
fe2d9fb
fix before-all; add MPI for win
njzjz Dec 18, 2022
5ed164d
fix
njzjz Dec 18, 2022
a70dcf7
fix if fi
njzjz Dec 18, 2022
8fbd643
revert and fix
njzjz Dec 18, 2022
1f6c4ef
fix windows header
njzjz Dec 18, 2022
d922b1c
fix windows
njzjz Dec 18, 2022
abb3bd7
fix win
njzjz Dec 18, 2022
e0af610
fix win
njzjz Dec 18, 2022
5e727c5
fix "an explicit specialization or instantiation of a function templa…
njzjz Dec 18, 2022
f2a465c
skip win; add docs; test macos
njzjz Dec 18, 2022
f722d78
fix typo
njzjz Dec 18, 2022
bd43239
fix tests
njzjz Dec 18, 2022
baf2a50
fix tests
njzjz Dec 18, 2022
bc94053
fix loading library on macos
njzjz Dec 18, 2022
d3fd035
add op dir to lib path
njzjz Dec 18, 2022
a3e9ddb
fix linking python; enable linux
njzjz Dec 18, 2022
87e2d33
Merge branch 'devel' into wheel-lmp
njzjz Dec 18, 2022
6320ffd
fix find python
njzjz Dec 18, 2022
17eebaf
fix
njzjz Dec 18, 2022
285d78d
hack for cibuildwheel
njzjz Dec 18, 2022
b1ebeca
add mpi path
njzjz Dec 18, 2022
f22761b
fix test command
njzjz Dec 18, 2022
486e6a7
preload Python library
njzjz Dec 18, 2022
ede742e
fix env
njzjz Dec 18, 2022
907345a
fix test command
njzjz Dec 18, 2022
a7248ab
do not link MPI twice
njzjz Dec 18, 2022
5be12dd
target_include_directories
njzjz Dec 18, 2022
9df7078
fix dso_path for macos
njzjz Dec 18, 2022
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
2 changes: 1 addition & 1 deletion deepmd/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def _get_package_constants(
TF_VERSION = GLOBAL_CONFIG["tf_version"]
TF_CXX11_ABI_FLAG = int(GLOBAL_CONFIG["tf_cxx11_abi_flag"])

op_module = get_module("op_abi")
op_module = get_module("deepmd_op")
op_grads_module = get_module("op_grads")

# FLOAT_PREC
Expand Down
49 changes: 49 additions & 0 deletions deepmd/lmp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Register entry points for lammps-wheel."""
import os
import platform
from pathlib import Path
from typing import List, Optional

from find_libpython import find_libpython

from deepmd.env import tf


def get_env(paths: List[Optional[str]]) -> str:
"""Get the environment variable from given paths"""
return ":".join((p for p in paths if p is not None))


if platform.system() == "Linux":
lib_env = "LD_LIBRARY_PATH"
elif platform.system() == "Darwin":
lib_env = "DYLD_FALLBACK_LIBRARY_PATH"
else:
raise RuntimeError("Unsupported platform")

tf_dir = tf.sysconfig.get_lib()
op_dir = str((Path(__file__).parent / "op").absolute())
# set LD_LIBRARY_PATH
os.environ[lib_env] = get_env([
os.environ.get(lib_env),
tf_dir,
os.path.join(tf_dir, "python"),
op_dir,
])

# preload python library
libpython = find_libpython()
if platform.system() == "Linux":
preload_env = "LD_PRELOAD"
elif platform.system() == "Darwin":
preload_env = "DYLD_INSERT_LIBRARIES"
else:
raise RuntimeError("Unsupported platform")
os.environ[preload_env] = get_env([
os.environ.get(preload_env),
libpython,
])

def get_op_dir() -> str:
"""Get the directory of the deepmd-kit OP library"""
return op_dir
9 changes: 8 additions & 1 deletion doc/install/easy-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ docker pull deepmodeling/dpmdkit-rocm:dp2.0.3-rocm4.5.2-tf2.6-lmp29Sep2021

## Install Python interface with pip

If you only want to install the Python interface and have no existing TensorFlow installed, you can use `pip` to install the pre-built package of the Python interface with CUDA 11 supported:
If you have no existing TensorFlow installed, you can use `pip` to install the pre-built package of the Python interface with CUDA 11 supported:

```bash
pip install deepmd-kit[gpu]
Expand All @@ -95,6 +95,13 @@ Or install the CPU version without CUDA supported:
pip install deepmd-kit[cpu]
```

[LAMMPS module](../third-party/lammps-command.md) is only provided on Linux and macOS. To enable it, add `lmp` to extras:
```bash
pip install deepmd-kit[gpu,lmp]
```
MPICH is required for parallel running.

It is suggested to install the package into an isolated environment.
The supported platform includes Linux x86-64 and aarch64 with GNU C Library 2.28 or above, macOS x86-64, and Windows x86-64.
A specific version of TensorFlow which is compatible with DeePMD-kit will be also installed.

Expand Down
26 changes: 18 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,35 @@ repository = "https://github.com/deepmodeling/deepmd-kit"
write_to = "deepmd/_version.py"

[tool.cibuildwheel]
test-command = "dp -h"
test-requires = "tensorflow"
test-command = [
"dp -h",
]
test-extras = ["cpu"]
build = ["cp310-*"]
skip = ["*-win32", "*-manylinux_i686", "*-musllinux*"]
# TODO: bump to "latest" tag when CUDA supports GCC 12
manylinux-x86_64-image = "quay.io/pypa/manylinux_2_28_x86_64:2022-11-19-1b19e81"
manylinux-aarch64-image = "quay.io/pypa/manylinux_2_28_aarch64:2022-11-19-1b19e81"

[tool.cibuildwheel.macos]
environment = { DP_LAMMPS_VERSION="stable_23Jun2022_update2" }
before-all = ["brew install mpich"]
repair-wheel-command = "delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel} --ignore-missing-dependencies"
test-extras = ["cpu", "test", "lmp"]
test-command = [
"dp -h",
"pytest {project}/source/tests/test_lammps.py"
]

[tool.cibuildwheel.linux]
repair-wheel-command = "auditwheel repair --exclude libtensorflow_framework.so.2 --exclude libtensorflow_framework.so.1 --exclude libtensorflow_framework.so -w {dest_dir} {wheel}"
repair-wheel-command = "auditwheel repair --exclude libtensorflow_framework.so.2 --exclude libtensorflow_framework.so.1 --exclude libtensorflow_framework.so --exclude _pywrap_tensorflow_internal.so -w {dest_dir} {wheel}"
environment-pass = ["CIBW_BUILD", "DP_VARIANT"]
before-all = """
if [ "$(uname -m)" = "x86_64" ]; then
yum config-manager --add-repo http://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo && yum install -y cuda-11-8
fi
"""
environment = { DP_VARIANT="cuda", DP_LAMMPS_VERSION="stable_23Jun2022_update2", MPI_HOME="/usr/lib64/mpich", PATH="/usr/lib64/mpich/bin:$PATH" }
before-all = [
"""{ if [ "$(uname -m)" = "x86_64" ] ; then yum config-manager --add-repo http://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo && yum install -y cuda-11-8; fi }""",
"yum install -y mpich-devel",
]


# selectively turn of lintner warnings, always include reasoning why any warning should
# be silenced
Expand Down
18 changes: 16 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
cmake_args.append("-DBUILD_TESTING:BOOL=TRUE")
if os.environ.get("DP_ENABLE_NATIVE_OPTIMIZATION", "0") == "1":
cmake_args.append("-DENABLE_NATIVE_OPTIMIZATION:BOOL=TRUE")
dp_lammps_version = os.environ.get("DP_LAMMPS_VERSION", "")
if dp_lammps_version != "":
cmake_args.append("-DBUILD_CPP_IF:BOOL=TRUE")
cmake_args.append("-DUSE_TF_PYTHON_LIBS:BOOL=TRUE")
cmake_args.append(f"-DLAMMPS_VERSION={dp_lammps_version}")
else:
cmake_args.append("-DBUILD_CPP_IF:BOOL=FALSE")

tf_install_dir, _ = find_tensorflow()
tf_version = get_tf_version(tf_install_dir)
Expand Down Expand Up @@ -73,7 +80,6 @@ def get_tag(self):
cmake_args=[
f"-DTENSORFLOW_ROOT:PATH={tf_install_dir}",
"-DBUILD_PY_IF:BOOL=TRUE",
"-DBUILD_CPP_IF:BOOL=FALSE",
*cmake_args,
],
cmake_source_dir="source",
Expand All @@ -95,9 +101,17 @@ def get_tag(self):
"sphinx-argparse",
"pygments-lammps",
],
"lmp": [
"lammps-manylinux-2-28~=2022.6.23.2.2; platform_system=='Linux'",
"lammps~=2022.6.23.2.2; platform_system!='Linux'",
"find_libpython",
],
**get_tf_requirement(tf_version),
},
entry_points={"console_scripts": ["dp = deepmd.entrypoints.main:main"]},
entry_points={
"console_scripts": ["dp = deepmd.entrypoints.main:main"],
"lammps.plugins": ["deepmd = deepmd.lmp:get_op_dir"],
},
cmdclass = {
"bdist_wheel": bdist_wheel_abi3,
},
Expand Down
14 changes: 10 additions & 4 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ set(DEEPMD_SOURCE_DIR ${PROJECT_SOURCE_DIR}/..)

# setup tensorflow libraries by python
if (USE_TF_PYTHON_LIBS)
find_package (Python COMPONENTS Interpreter Development REQUIRED)
if(NOT $ENV{CIBUILDWHEEL} STREQUAL "1")
find_package (Python COMPONENTS Interpreter Development REQUIRED)
else()
set(Python_LIBRARIES ${Python_LIBRARY})
endif()
endif(USE_TF_PYTHON_LIBS)

# find tensorflow, I need tf abi info
Expand Down Expand Up @@ -149,8 +153,8 @@ endif()

# define names of libs
set (LIB_DEEPMD "deepmd")
set (LIB_DEEPMD_OP "deepmd_op")
if (BUILD_CPP_IF)
set (LIB_DEEPMD_OP "deepmd_op")
set (LIB_DEEPMD_CC "deepmd_cc")
set (LIB_DEEPMD_C "deepmd_c")
if (USE_CUDA_TOOLKIT)
Expand Down Expand Up @@ -181,8 +185,10 @@ if (BUILD_CPP_IF)
add_subdirectory (lmp/)
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8)
# add_subdirectory (md/)
if(NOT BUILD_PY_IF)
add_subdirectory (ipi/)
add_subdirectory (gmx/)
endif()
endif ()
endif (BUILD_CPP_IF)

Expand All @@ -205,7 +211,7 @@ add_custom_target(lammps
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_lammps.cmake)

# add configure file
if(BUILD_CPP_IF)
if(BUILD_CPP_IF AND NOT BUILD_PY_IF)
include(CMakePackageConfigHelpers)
set(targets_export_name ${CMAKE_PROJECT_NAME}Targets CACHE INTERNAL "")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated" CACHE INTERNAL "")
Expand All @@ -220,4 +226,4 @@ if(BUILD_CPP_IF)
"${config_file}" INSTALL_DESTINATION ${cmake_files_install_dir})
install(FILES ${version_file} ${config_file}
DESTINATION ${cmake_files_install_dir})
endif(BUILD_CPP_IF)
endif(BUILD_CPP_IF AND NOT BUILD_PY_IF)
7 changes: 7 additions & 0 deletions source/api_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ if (CMAKE_TESTING_ENABLED)
target_link_libraries(${libname} PRIVATE coverage_config)
endif()

if(BUILD_PY_IF)
install(
TARGETS ${libname}
DESTINATION deepmd/op/
)
else(BUILD_PY_IF)
install(
TARGETS ${libname}
EXPORT ${CMAKE_PROJECT_NAME}Targets
Expand All @@ -33,6 +39,7 @@ install(
FILES ${INC_SRC}
DESTINATION include/deepmd
)
endif(BUILD_PY_IF)

if (PACKAGE_C)
MESSAGE(STATUS "Packaging C API library")
Expand Down
7 changes: 7 additions & 0 deletions source/api_cc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ if (CMAKE_TESTING_ENABLED)
endif()
target_compile_features(${libname} PUBLIC cxx_std_11)

if(BUILD_PY_IF)
install(
TARGETS ${libname}
DESTINATION deepmd/op/
)
else(BUILD_PY_IF)
install(
TARGETS ${libname}
EXPORT ${CMAKE_PROJECT_NAME}Targets
Expand All @@ -64,3 +70,4 @@ ${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${LOW_PREC_V
if (CMAKE_TESTING_ENABLED)
add_subdirectory(tests)
endif()
endif(BUILD_PY_IF)
16 changes: 8 additions & 8 deletions source/api_cc/src/DeepPot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ run_model <double, double> (ENERGYTYPE & dener,
Session * session,
const std::vector<std::pair<std::string, Tensor>> & input_tensors,
const AtomMap& atommap,
const int nghost = 0);
const int nghost);

template
void
Expand All @@ -97,7 +97,7 @@ run_model <double, float> (ENERGYTYPE & dener,
Session * session,
const std::vector<std::pair<std::string, Tensor>> & input_tensors,
const AtomMap& atommap,
const int nghost = 0);
const int nghost);

template
void
Expand All @@ -107,7 +107,7 @@ run_model <float, double> (ENERGYTYPE & dener,
Session * session,
const std::vector<std::pair<std::string, Tensor>> & input_tensors,
const AtomMap& atommap,
const int nghost = 0);
const int nghost);

template
void
Expand All @@ -117,7 +117,7 @@ run_model <float, float> (ENERGYTYPE & dener,
Session * session,
const std::vector<std::pair<std::string, Tensor>> & input_tensors,
const AtomMap& atommap,
const int nghost = 0);
const int nghost);

template <typename MODELTYPE, typename VALUETYPE>
static void run_model (ENERGYTYPE & dener,
Expand Down Expand Up @@ -210,7 +210,7 @@ void run_model <double, double> (ENERGYTYPE & dener,
Session* session,
const std::vector<std::pair<std::string, Tensor>> & input_tensors,
const deepmd::AtomMap & atommap,
const int& nghost = 0);
const int& nghost);

template
void run_model <double, float> (ENERGYTYPE & dener,
Expand All @@ -221,7 +221,7 @@ void run_model <double, float> (ENERGYTYPE & dener,
Session* session,
const std::vector<std::pair<std::string, Tensor>> & input_tensors,
const deepmd::AtomMap & atommap,
const int& nghost = 0);
const int& nghost);

template
void run_model <float, double> (ENERGYTYPE & dener,
Expand All @@ -232,7 +232,7 @@ void run_model <float, double> (ENERGYTYPE & dener,
Session* session,
const std::vector<std::pair<std::string, Tensor>> & input_tensors,
const deepmd::AtomMap & atommap,
const int& nghost = 0);
const int& nghost);

template
void run_model <float, float> (ENERGYTYPE & dener,
Expand All @@ -243,7 +243,7 @@ void run_model <float, float> (ENERGYTYPE & dener,
Session* session,
const std::vector<std::pair<std::string, Tensor>> & input_tensors,
const deepmd::AtomMap & atommap,
const int& nghost = 0);
const int& nghost);

DeepPot::
DeepPot ()
Expand Down
19 changes: 17 additions & 2 deletions source/api_cc/src/common.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
#include "common.h"
#include "AtomMap.h"
#include "device.h"
#include <dlfcn.h>
#include <fcntl.h>
#if defined(_WIN32)
#if defined(_WIN32_WINNT)
#undef _WIN32_WINNT
#endif

// target Windows version is windows 7 and later
#define _WIN32_WINNT _WIN32_WINNT_WIN7
#define PSAPI_VERSION 2
#include <windows.h>
#include <io.h>
#define O_RDONLY _O_RDONLY
#else
// not windows
#include <dlfcn.h>
#endif
#include "google/protobuf/text_format.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"

Expand Down Expand Up @@ -299,10 +313,11 @@ deepmd::
load_op_library()
{
tensorflow::Env* env = tensorflow::Env::Default();
std::string dso_path = env->FormatLibraryFileName("deepmd_op", "");
#if defined(_WIN32)
std::string dso_path = "deepmd_op.dll";
void* dso_handle = LoadLibrary(dso_path.c_str());
#else
std::string dso_path = "libdeepmd_op.so";
void* dso_handle = dlopen(dso_path.c_str(), RTLD_NOW | RTLD_LOCAL);
#endif
if (!dso_handle) {
Expand Down
Loading