Skip to content

Commit b2662e2

Browse files
authored
Merge pull request #256 from deepmodeling/devel
merge recent changes on devel back to master
2 parents e098369 + 385c847 commit b2662e2

30 files changed

+988
-271
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
- CXX=g++-7
8484
- TENSORFLOW_VERSION=2.1
8585
install:
86-
- python -m pip install twine cibuildwheel==1.1.0 scikit-build
86+
- python -m pip install twine cibuildwheel==1.1.0 scikit-build setuptools_scm
8787
script:
8888
- python -m cibuildwheel --output-dir wheelhouse
8989
- python setup.py sdist

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[build-system]
2-
requires = ["setuptools", "wheel", "scikit-build", "cmake", "ninja", "m2r"]
2+
requires = ["setuptools", "setuptools_scm", "wheel", "scikit-build", "cmake", "ninja", "m2r"]
33

setup.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
from skbuild import setup
22
from skbuild.exceptions import SKBuildError
33
from skbuild.cmaker import get_cmake_version
4+
from setuptools_scm import get_version
45
from packaging.version import LegacyVersion
56
from os import path, makedirs
6-
import imp
7+
import imp, sys, platform
8+
9+
def get_dp_install_path() :
10+
site_packages_path = path.join(path.dirname(path.__file__), 'site-packages')
11+
dp_scm_version = get_version(root="./", relative_to=__file__)
12+
python_version = 'py' + str(sys.version_info.major + sys.version_info.minor * 0.1)
13+
os_info = sys.platform
14+
machine_info = platform.machine()
15+
dp_pip_install_path = site_packages_path + '/deepmd'
16+
dp_setup_install_path = site_packages_path + '/deepmd_kit-' + dp_scm_version + '-' + python_version + '-' + os_info + '-' + machine_info + '.egg/deepmd'
17+
18+
return dp_pip_install_path, dp_setup_install_path
719

820
readme_file = path.join(path.dirname(path.abspath(__file__)), 'README.md')
921
try:
@@ -34,6 +46,8 @@
3446
except OSError:
3547
pass
3648

49+
dp_pip_install_path, dp_setup_install_path = get_dp_install_path()
50+
3751
setup(
3852
name="deepmd-kit",
3953
setup_requires=setup_requires,
@@ -56,6 +70,8 @@
5670
'-DBUILD_PY_IF:BOOL=TRUE',
5771
'-DBUILD_CPP_IF:BOOL=FALSE',
5872
'-DFLOAT_PREC:STRING=high',
73+
'-DDP_PIP_INSTALL_PATH=%s' % dp_pip_install_path,
74+
'-DDP_SETUP_INSTALL_PATH=%s' % dp_setup_install_path,
5975
],
6076
cmake_source_dir='source',
6177
cmake_minimum_required_version='3.0',

source/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ if (BUILD_CPP_IF)
186186
set (LIB_DEEPMD_OP "deepmd_op")
187187
if (USE_CUDA_TOOLKIT)
188188
set (LIB_DEEPMD_OP_CUDA "deepmd_op_cuda")
189-
else()
189+
else ()
190190
set (LIB_DEEPMD_OP_CUDA "deepmd_op")
191191
endif()
192192
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.9)

source/lib/include/NNPInter.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,8 @@ class NNPInter
9393
compute_t *array_double;
9494
InternalNeighborList nlist;
9595
NNPAtomMap<VALUETYPE> nnpmap;
96-
unsigned long long *array_longlong;
97-
int *ilist, *jrange, *jlist, *array_int;
96+
int *ilist, *jrange, *jlist;
9897
int ilist_size, jrange_size, jlist_size;
99-
int arr_int_size, arr_ll_size, arr_dou_size;
10098

10199
// function used for neighbor list copy
102100
vector<int> get_sel_a() const;
@@ -191,13 +189,10 @@ class NNPInterModelDevi
191189
vector<vector<int> > sec;
192190
InternalNeighborList nlist;
193191
NNPAtomMap<VALUETYPE> nnpmap;
194-
unsigned long long *array_longlong;
195-
int max_sec_size = 0, max_sec_back = 0;
196-
int *ilist, *jrange, *jlist, *array_int;
197-
int ilist_size, jrange_size, jlist_size, arr_int_size, arr_ll_size, arr_dou_size;
192+
int *ilist, *jrange, *jlist;
193+
int ilist_size, jrange_size, jlist_size;
198194

199195
// function used for nborlist copy
200-
void get_max_sec();
201196
vector<vector<int> > get_sel() const;
202197
void cum_sum(const std::vector<std::vector<int32> > n_sel);
203198
#ifdef USE_CUDA_TOOLKIT

source/lib/include/SimulationRegion_Impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <iostream>
66
#include <limits>
77
#include <typeinfo>
8+
#include <stdexcept>
89

910
using namespace std;
1011

@@ -500,6 +501,9 @@ computeVolume()
500501
boxt[0*3+1] * (boxt[1*3+0]*boxt[2*3+2] - boxt[2*3+0]*boxt[1*3+2]) +
501502
boxt[0*3+2] * (boxt[1*3+0]*boxt[2*3+1] - boxt[2*3+0]*boxt[1*3+1]);
502503
volumei = static_cast<double>(1.)/volume;
504+
if (volume < 0) {
505+
throw std::runtime_error("Negative volume detected. Please make sure the simulation cell obeys the right-hand rule.");
506+
}
503507
}
504508

505509
template<typename VALUETYPE>

source/lib/include/common.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ session_input_tensors (vector<std::pair<string, Tensor>>& input_tensors,
144144
const int * ilist,
145145
const int * jrange,
146146
const int * jlist,
147-
int * array_int,
148-
unsigned long long * array_longlong,
149-
double * array_double,
150147
const vector<VALUETYPE> & fparam_,
151148
const vector<VALUETYPE> & aparam_,
152149
const NNPAtomMap<VALUETYPE> & nnpmap,

source/lib/src/NNPInter.cc

Lines changed: 10 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "SimulationRegion.h"
44
#include <stdexcept>
55

6-
#define MAGIC_NUMBER 1024
76

87
#ifdef USE_CUDA_TOOLKIT
98
#include "cuda_runtime.h"
@@ -14,7 +13,7 @@
1413
#define cudaErrcheck(res) { cudaAssert((res), __FILE__, __LINE__); }
1514
inline void cudaAssert(cudaError_t code, const char *file, int line, bool abort=true)
1615
{
17-
if (code != cudaSuccess)
16+
if (code != cudaSuccess)
1817
{
1918
fprintf(stderr,"cuda assert: %s %s %d\n", cudaGetErrorString(code), file, line);
2019
if (abort) exit(code);
@@ -273,33 +272,19 @@ NNPInter::~NNPInter() {
273272
cudaErrcheck(cudaFree(ilist));
274273
cudaErrcheck(cudaFree(jrange));
275274
cudaErrcheck(cudaFree(jlist));
276-
cudaErrcheck(cudaFree(array_int));
277-
cudaErrcheck(cudaFree(array_longlong));
278-
cudaErrcheck(cudaFree(array_double));
279275
}
280276
#endif
281277
}
282278

283279
#ifdef USE_CUDA_TOOLKIT
284280
void NNPInter::update_nbor(const InternalNeighborList & nlist, const int nloc) {
285281
if (!init_nbor) {
286-
sec_a = cum_sum(get_sel_a());
287282
cudaErrcheck(cudaMalloc((void**)&ilist, sizeof(int) * nlist.ilist.size()));
288283
cudaErrcheck(cudaMalloc((void**)&jrange, sizeof(int) * nlist.jrange.size()));
289284
cudaErrcheck(cudaMalloc((void**)&jlist, sizeof(int) * nlist.jlist.size()));
290-
cudaErrcheck(cudaMalloc((void**)&array_int, sizeof(int) * (sec_a.size() + nloc * sec_a.size() + nloc)));
291-
cudaErrcheck(cudaMalloc((void**)&array_longlong, sizeof(unsigned long long) * nloc * MAGIC_NUMBER * 2));
292-
#ifdef HIGH_PREC
293-
cudaErrcheck(cudaMalloc((void**)&array_double, sizeof(compute_t) * nloc * sec_a.back() * 3));
294-
#else
295-
cudaErrcheck(cudaMalloc((void**)&array_double, sizeof(compute_t) * nloc * sec_a.back() * 3));
296-
#endif
297285
ilist_size = nlist.ilist.size();
298286
jrange_size = nlist.jrange.size();
299287
jlist_size = nlist.jlist.size();
300-
arr_int_size = sec_a.size() + nloc * sec_a.size() + nloc;
301-
arr_ll_size = nloc * MAGIC_NUMBER * 2;
302-
arr_dou_size = nloc * sec_a.back() * 3;
303288
init_nbor = true;
304289
}
305290
if (ilist_size < nlist.ilist.size()) {
@@ -317,25 +302,7 @@ void NNPInter::update_nbor(const InternalNeighborList & nlist, const int nloc) {
317302
cudaErrcheck(cudaMalloc((void**)&jlist, sizeof(int) * nlist.jlist.size()));
318303
jlist_size = nlist.jlist.size();
319304
}
320-
if (arr_int_size < sec_a.size() + nloc * sec_a.size() + nloc) {
321-
cudaErrcheck(cudaFree(array_int));
322-
cudaErrcheck(cudaMalloc((void**)&array_int, sizeof(int) * (sec_a.size() + nloc * sec_a.size() + nloc)));
323-
arr_int_size = sec_a.size() + nloc * sec_a.size() + nloc;
324-
}
325-
if (arr_ll_size < nloc * MAGIC_NUMBER * 2) {
326-
cudaErrcheck(cudaFree(array_longlong));
327-
cudaErrcheck(cudaMalloc((void**)&array_longlong, sizeof(unsigned long long) * nloc * MAGIC_NUMBER * 2));
328-
arr_ll_size = nloc * MAGIC_NUMBER * 2;
329-
}
330-
if (arr_dou_size < nloc * sec_a.back() * 3) {
331-
cudaErrcheck(cudaFree(array_double));
332-
#ifdef HIGH_PREC
333-
cudaErrcheck(cudaMalloc((void**)&array_double, sizeof(compute_t) * nloc * sec_a.back() * 3));
334-
#else
335-
cudaErrcheck(cudaMalloc((void**)&array_double, sizeof(compute_t) * nloc * sec_a.back() * 3));
336-
#endif
337-
arr_dou_size = nloc * sec_a.back() * 3;
338-
}
305+
339306
cudaErrcheck(cudaMemcpy(ilist, &nlist.ilist[0], sizeof(int) * nlist.ilist.size(), cudaMemcpyHostToDevice));
340307
cudaErrcheck(cudaMemcpy(jrange, &nlist.jrange[0], sizeof(int) * nlist.jrange.size(), cudaMemcpyHostToDevice));
341308
cudaErrcheck(cudaMemcpy(jlist, &nlist.jlist[0], sizeof(int) * nlist.jlist.size(), cudaMemcpyHostToDevice));
@@ -378,14 +345,10 @@ init (const string & model, const int & gpu_rank)
378345
if (dfparam < 0) dfparam = 0;
379346
if (daparam < 0) daparam = 0;
380347
inited = true;
381-
348+
382349
init_nbor = false;
383-
array_int = NULL;
384-
array_double = NULL;
385-
array_longlong = NULL;
386350
ilist = NULL; jrange = NULL; jlist = NULL;
387351
ilist_size = 0; jrange_size = 0; jlist_size = 0;
388-
arr_int_size = 0; arr_ll_size = 0; arr_dou_size = 0;
389352
}
390353
#else
391354
void
@@ -415,12 +378,8 @@ init (const string & model, const int & gpu_rank)
415378
inited = true;
416379

417380
init_nbor = false;
418-
array_int = NULL;
419-
array_double = NULL;
420-
array_longlong = NULL;
421381
ilist = NULL; jrange = NULL; jlist = NULL;
422382
ilist_size = 0; jrange_size = 0; jlist_size = 0;
423-
arr_int_size = 0; arr_ll_size = 0; arr_dou_size = 0;
424383
}
425384
#endif
426385

@@ -602,7 +561,7 @@ compute_inner (ENERGYTYPE & dener,
602561
}
603562

604563
#ifdef USE_CUDA_TOOLKIT
605-
int ret = session_input_tensors (input_tensors, dcoord_, ntypes, datype_, dbox, ilist, jrange, jlist, array_int, array_longlong, array_double, fparam, aparam, nnpmap, nghost);
564+
int ret = session_input_tensors (input_tensors, dcoord_, ntypes, datype_, dbox, ilist, jrange, jlist, fparam, aparam, nnpmap, nghost);
606565
#else
607566
int ret = session_input_tensors (input_tensors, dcoord_, ntypes, datype_, dbox, nlist, fparam, aparam, nnpmap, nghost);
608567
#endif
@@ -669,7 +628,7 @@ compute (ENERGYTYPE & dener,
669628
}
670629

671630
#ifdef USE_CUDA_TOOLKIT
672-
int ret = session_input_tensors (input_tensors, dcoord_, ntypes, datype_, dbox, ilist, jrange, jlist, array_int, array_longlong, array_double, fparam, aparam, nnpmap, nghost);
631+
int ret = session_input_tensors (input_tensors, dcoord_, ntypes, datype_, dbox, ilist, jrange, jlist, fparam, aparam, nnpmap, nghost);
673632
#else
674633
int ret = session_input_tensors (input_tensors, dcoord_, ntypes, datype_, dbox, nlist, fparam, aparam, nnpmap, nghost);
675634
#endif
@@ -710,9 +669,6 @@ NNPInterModelDevi::~NNPInterModelDevi() {
710669
cudaErrcheck(cudaFree(ilist));
711670
cudaErrcheck(cudaFree(jrange));
712671
cudaErrcheck(cudaFree(jlist));
713-
cudaErrcheck(cudaFree(array_int));
714-
cudaErrcheck(cudaFree(array_longlong));
715-
cudaErrcheck(cudaFree(array_double));
716672
}
717673
#endif
718674
}
@@ -761,14 +717,10 @@ init (const vector<string> & models, const int & gpu_rank)
761717
// cell_size = rcut;
762718
// ntypes = get_ntypes();
763719
inited = true;
764-
720+
765721
init_nbor = false;
766-
array_int = NULL;
767-
array_double = NULL;
768-
array_longlong = NULL;
769722
ilist = NULL; jrange = NULL; jlist = NULL;
770723
ilist_size = 0; jrange_size = 0; jlist_size = 0;
771-
arr_int_size = 0; arr_ll_size = 0; arr_dou_size = 0;
772724
}
773725
#else
774726
void
@@ -798,14 +750,10 @@ init (const vector<string> & models, const int & gpu_rank)
798750
// cell_size = rcut;
799751
// ntypes = get_ntypes();
800752
inited = true;
801-
753+
802754
init_nbor = false;
803-
array_int = NULL;
804-
array_double = NULL;
805-
array_longlong = NULL;
806755
ilist = NULL; jrange = NULL; jlist = NULL;
807756
ilist_size = 0; jrange_size = 0; jlist_size = 0;
808-
arr_int_size = 0; arr_ll_size = 0; arr_dou_size = 0;
809757
}
810758
#endif
811759

@@ -873,40 +821,18 @@ cum_sum (const std::vector<std::vector<int32> > n_sel)
873821
}
874822
}
875823

876-
void
877-
NNPInterModelDevi::
878-
get_max_sec()
879-
{
880-
for (int ii = 0; ii < numb_models; ii++) {
881-
this->max_sec_size = max_sec_size < sec[ii].size() ? sec[ii].size() : max_sec_size;
882-
this->max_sec_back = max_sec_back < sec[ii].back() ? sec[ii].back() : max_sec_back;
883-
}
884-
}
885-
886824
#ifdef USE_CUDA_TOOLKIT
887825
void
888826
NNPInterModelDevi::
889827
update_nbor(const InternalNeighborList & nlist, const int nloc)
890828
{
891829
if (!init_nbor) {
892-
cum_sum(get_sel());
893-
get_max_sec();
894830
cudaErrcheck(cudaMalloc((void**)&ilist, sizeof(int) * nlist.ilist.size()));
895831
cudaErrcheck(cudaMalloc((void**)&jrange, sizeof(int) * nlist.jrange.size()));
896832
cudaErrcheck(cudaMalloc((void**)&jlist, sizeof(int) * nlist.jlist.size()));
897-
cudaErrcheck(cudaMalloc((void**)&array_int, sizeof(int) * (max_sec_size + nloc * max_sec_size + nloc)));
898-
cudaErrcheck(cudaMalloc((void**)&array_longlong, sizeof(unsigned long long) * nloc * MAGIC_NUMBER * 2));
899-
#ifdef HIGH_PREC
900-
cudaErrcheck(cudaMalloc((void**)&array_double, sizeof(compute_t) * nloc * max_sec_back * 3));
901-
#else
902-
cudaErrcheck(cudaMalloc((void**)&array_double, sizeof(compute_t) * nloc * max_sec_back * 3));
903-
#endif
904833
ilist_size = nlist.ilist.size();
905834
jrange_size = nlist.jrange.size();
906835
jlist_size = nlist.jlist.size();
907-
arr_int_size = max_sec_size + nloc * max_sec_size + nloc;
908-
arr_ll_size = nloc * MAGIC_NUMBER * 2;
909-
arr_dou_size = nloc * max_sec_back * 3;
910836
init_nbor = true;
911837
}
912838
if (ilist_size < nlist.ilist.size()) {
@@ -924,25 +850,7 @@ update_nbor(const InternalNeighborList & nlist, const int nloc)
924850
cudaErrcheck(cudaMalloc((void**)&jlist, sizeof(int) * nlist.jlist.size()));
925851
jlist_size = nlist.jlist.size();
926852
}
927-
if (arr_int_size < max_sec_size + nloc * max_sec_size + nloc) {
928-
cudaErrcheck(cudaFree(array_int));
929-
cudaErrcheck(cudaMalloc((void**)&array_int, sizeof(int) * (max_sec_size + nloc * max_sec_size + nloc)));
930-
arr_int_size = max_sec_size + nloc * max_sec_size + nloc;
931-
}
932-
if (arr_ll_size < nloc * MAGIC_NUMBER * 2) {
933-
cudaErrcheck(cudaFree(array_longlong));
934-
cudaErrcheck(cudaMalloc((void**)&array_longlong, sizeof(unsigned long long) * nloc * MAGIC_NUMBER * 2));
935-
arr_ll_size = nloc * MAGIC_NUMBER * 2;
936-
}
937-
if (arr_dou_size < nloc * max_sec_back * 3) {
938-
cudaErrcheck(cudaFree(array_double));
939-
#ifdef HIGH_PREC
940-
cudaErrcheck(cudaMalloc((void**)&array_double, sizeof(compute_t) * nloc * max_sec_back * 3));
941-
#else
942-
cudaErrcheck(cudaMalloc((void**)&array_double, sizeof(compute_t) * nloc * max_sec_back * 3));
943-
#endif
944-
arr_dou_size = nloc * max_sec_back * 3;
945-
}
853+
946854
cudaErrcheck(cudaMemcpy(ilist, &nlist.ilist[0], sizeof(int) * nlist.ilist.size(), cudaMemcpyHostToDevice));
947855
cudaErrcheck(cudaMemcpy(jrange, &nlist.jrange[0], sizeof(int) * nlist.jrange.size(), cudaMemcpyHostToDevice));
948856
cudaErrcheck(cudaMemcpy(jlist, &nlist.jlist[0], sizeof(int) * nlist.jlist.size(), cudaMemcpyHostToDevice));
@@ -1044,7 +952,7 @@ compute (vector<ENERGYTYPE> & all_energy,
1044952

1045953
}
1046954
#ifdef USE_CUDA_TOOLKIT
1047-
int ret = session_input_tensors (input_tensors, dcoord_, ntypes, datype_, dbox, ilist, jrange, jlist, array_int, array_longlong, array_double, fparam, aparam, nnpmap, nghost);
955+
int ret = session_input_tensors (input_tensors, dcoord_, ntypes, datype_, dbox, ilist, jrange, jlist, fparam, aparam, nnpmap, nghost);
1048956
#else
1049957
int ret = session_input_tensors (input_tensors, dcoord_, ntypes, datype_, dbox, nlist, fparam, aparam, nnpmap, nghost);
1050958
#endif
@@ -1094,7 +1002,7 @@ compute (vector<ENERGYTYPE> & all_energy,
10941002

10951003
}
10961004
#ifdef USE_CUDA_TOOLKIT
1097-
int ret = session_input_tensors (input_tensors, dcoord_, ntypes, datype_, dbox, ilist, jrange, jlist, array_int, array_longlong, array_double, fparam, aparam, nnpmap, nghost);
1005+
int ret = session_input_tensors (input_tensors, dcoord_, ntypes, datype_, dbox, ilist, jrange, jlist, fparam, aparam, nnpmap, nghost);
10981006
#else
10991007
int ret = session_input_tensors (input_tensors, dcoord_, ntypes, datype_, dbox, nlist, fparam, aparam, nnpmap, nghost);
11001008
#endif

0 commit comments

Comments
 (0)