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
4 changes: 2 additions & 2 deletions deepmd/descriptor/se_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__ (self,
self.place_holders['natoms_vec'] = tf.placeholder(tf.int32, [self.ntypes+2], name=name_pfx+'t_natoms')
self.place_holders['default_mesh'] = tf.placeholder(tf.int32, [None], name=name_pfx+'t_mesh')
self.stat_descrpt, descrpt_deriv, rij, nlist \
= op_module.descrpt_se_a(self.place_holders['coord'],
= op_module.prod_env_mat_a(self.place_holders['coord'],
self.place_holders['type'],
self.place_holders['natoms_vec'],
self.place_holders['box'],
Expand Down Expand Up @@ -340,7 +340,7 @@ def build (self,
atype = tf.reshape (atype_, [-1, natoms[1]])

self.descrpt, self.descrpt_deriv, self.rij, self.nlist \
= op_module.descrpt_se_a (coord,
= op_module.prod_env_mat_a (coord,
atype,
natoms,
box,
Expand Down
9 changes: 7 additions & 2 deletions source/lib/include/neighbor_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,30 @@ struct InputNlist
int * ilist;
int * numneigh;
int ** firstneigh;
InputNlist ()
: inum(0), ilist(NULL), numneigh(NULL), firstneigh(NULL)
{};
InputNlist (
int inum_,
int * ilist_,
int * numneigh_,
int ** firstneigh_
)
: inum(inum_), ilist(ilist_), numneigh(numneigh_), firstneigh(firstneigh_)
{}
{};
};

void convert_nlist(
InputNlist & to_nlist,
std::vector<std::vector<int> > & from_nlist
);

int max_numneigh(
const InputNlist & to_nlist
);

// build neighbor list.
// outputs

// nlist, max_list_size
// max_list_size is the maximal size of jlist.
// inputs
Expand Down
9 changes: 3 additions & 6 deletions source/lib/include/prod_env_mat.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <vector>
#include "device.h"
#include "neighbor_list.h"

template<typename FPTYPE>
void prod_env_mat_a_cpu(
Expand All @@ -10,9 +11,7 @@ void prod_env_mat_a_cpu(
int * nlist,
const FPTYPE * coord,
const int * type,
const int * ilist,
const int * jrange,
const int * jlist,
const InputNlist & inlist,
const int max_nbor_size,
const FPTYPE * avg,
const FPTYPE * std,
Expand All @@ -30,9 +29,7 @@ void prod_env_mat_r_cpu(
int * nlist,
const FPTYPE * coord,
const int * type,
const int * ilist,
const int * jrange,
const int * jlist,
const InputNlist & inlist,
const int max_nbor_size,
const FPTYPE * avg,
const FPTYPE * std,
Expand Down
3 changes: 2 additions & 1 deletion source/lib/src/coord.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ copy_coord_cpu(
const FPTYPE * in_c,
const int * in_t,
const int & nloc,
const int & mem_nall,
const int & mem_nall_,
const float & rcut,
const Region<FPTYPE> & region)
{
const int mem_nall = mem_nall_;
std::vector<double> coord(nloc * 3);
std::vector<int> atype(nloc);
std::copy(in_c, in_c+nloc*3, coord.begin());
Expand Down
15 changes: 14 additions & 1 deletion source/lib/src/neighbor_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,18 @@ convert_nlist(
}
}

int
max_numneigh(
const InputNlist & nlist
)
{
int max_num = 0;
for(int ii = 0; ii < nlist.inum; ++ii){
if(nlist.numneigh[ii] > max_num) max_num = nlist.numneigh[ii];
}
return max_num;
}

template <typename FPTYPE>
int
build_nlist_cpu(
Expand All @@ -765,9 +777,10 @@ build_nlist_cpu(
const FPTYPE * c_cpy,
const int & nloc,
const int & nall,
const int & mem_size,
const int & mem_size_,
const float & rcut)
{
const int mem_size = mem_size_;
*max_list_size = 0;
nlist.inum = nloc;
FPTYPE rcut2 = rcut * rcut;
Expand Down
42 changes: 16 additions & 26 deletions source/lib/src/prod_env_mat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ void prod_env_mat_a_cpu(
int * nlist,
const FPTYPE * coord,
const int * type,
const int * ilist,
const int * jrange,
const int * jlist,
const InputNlist & inlist,
const int max_nbor_size,
const FPTYPE * avg,
const FPTYPE * std,
Expand Down Expand Up @@ -45,13 +43,14 @@ void prod_env_mat_a_cpu(
// build nlist
std::vector<std::vector<int > > d_nlist_a(nloc);

assert(nloc == inlist.inum);
for (unsigned ii = 0; ii < nloc; ++ii) {
d_nlist_a.reserve (jrange[nloc] / nloc + 10);
d_nlist_a[ii].reserve(max_nbor_size);
}
for (unsigned ii = 0; ii < nloc; ++ii) {
int i_idx = ilist[ii];
for (unsigned jj = jrange[ii]; jj < jrange[ii+1]; ++jj) {
int j_idx = jlist[jj];
int i_idx = inlist.ilist[ii];
for(unsigned jj = 0; jj < inlist.numneigh[ii]; ++jj){
int j_idx = inlist.firstneigh[ii][jj];
d_nlist_a[i_idx].push_back (j_idx);
}
}
Expand Down Expand Up @@ -96,9 +95,7 @@ void prod_env_mat_r_cpu(
int * nlist,
const FPTYPE * coord,
const int * type,
const int * ilist,
const int * jrange,
const int * jlist,
const InputNlist & inlist,
const int max_nbor_size,
const FPTYPE * avg,
const FPTYPE * std,
Expand Down Expand Up @@ -128,13 +125,14 @@ void prod_env_mat_r_cpu(
// build nlist
std::vector<std::vector<int > > d_nlist_a(nloc);

assert(nloc == inlist.inum);
for (unsigned ii = 0; ii < nloc; ++ii) {
d_nlist_a.reserve (jrange[nloc] / nloc + 10);
d_nlist_a[ii].reserve(max_nbor_size);
}
for (unsigned ii = 0; ii < nloc; ++ii) {
int i_idx = ilist[ii];
for (unsigned jj = jrange[ii]; jj < jrange[ii+1]; ++jj) {
int j_idx = jlist[jj];
int i_idx = inlist.ilist[ii];
for(unsigned jj = 0; jj < inlist.numneigh[ii]; ++jj){
int j_idx = inlist.firstneigh[ii][jj];
d_nlist_a[i_idx].push_back (j_idx);
}
}
Expand Down Expand Up @@ -180,9 +178,7 @@ void prod_env_mat_a_cpu<double>(
int * nlist,
const double * coord,
const int * type,
const int * ilist,
const int * jrange,
const int * jlist,
const InputNlist & inlist,
const int max_nbor_size,
const double * avg,
const double * std,
Expand All @@ -200,9 +196,7 @@ void prod_env_mat_a_cpu<float>(
int * nlist,
const float * coord,
const int * type,
const int * ilist,
const int * jrange,
const int * jlist,
const InputNlist & inlist,
const int max_nbor_size,
const float * avg,
const float * std,
Expand All @@ -220,9 +214,7 @@ void prod_env_mat_r_cpu<double>(
int * nlist,
const double * coord,
const int * type,
const int * ilist,
const int * jrange,
const int * jlist,
const InputNlist & inlist,
const int max_nbor_size,
const double * avg,
const double * std,
Expand All @@ -240,9 +232,7 @@ void prod_env_mat_r_cpu<float>(
int * nlist,
const float * coord,
const int * type,
const int * ilist,
const int * jrange,
const int * jlist,
const InputNlist & inlist,
const int max_nbor_size,
const float * avg,
const float * std,
Expand Down
35 changes: 11 additions & 24 deletions source/lib/tests/test_env_mat_a.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,11 @@ TEST_F(TestEnvMatA, prod_cpu)
max_nbor_size = nlist_a_cpy[ii].size();
}
}
std::vector<int> ilist(nloc), jlist(tot_nnei), jrange(nloc+1, 0);
for (int ii = 0; ii < nloc; ++ii){
ilist[ii] = ii;
jrange[ii+1] = jrange[ii] + nlist_a_cpy[ii].size();
int jj, cc;
for (jj = jrange[ii], cc = 0; jj < jrange[ii+1]; ++jj, ++cc){
jlist[jj] = nlist_a_cpy[ii][cc];
}
}
std::vector<int> ilist(nloc), numneigh(nloc);
std::vector<int*> firstneigh(nloc);
InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]);
convert_nlist(inlist, nlist_a_cpy);

std::vector<double > em(nloc * ndescrpt), em_deriv(nloc * ndescrpt * 3), rij(nloc * nnei * 3);
std::vector<int> nlist(nloc * nnei);
std::vector<double > avg(ntypes * ndescrpt, 0);
Expand All @@ -417,9 +413,7 @@ TEST_F(TestEnvMatA, prod_cpu)
&nlist[0],
&posi_cpy[0],
&atype_cpy[0],
&ilist[0],
&jrange[0],
&jlist[0],
inlist,
max_nbor_size,
&avg[0],
&std[0],
Expand Down Expand Up @@ -452,15 +446,10 @@ TEST_F(TestEnvMatA, prod_cpu_equal_cpu)
max_nbor_size = nlist_a_cpy[ii].size();
}
}
std::vector<int> ilist(nloc), jlist(tot_nnei), jrange(nloc+1, 0);
for (int ii = 0; ii < nloc; ++ii){
ilist[ii] = ii;
jrange[ii+1] = jrange[ii] + nlist_a_cpy[ii].size();
int jj, cc;
for (jj = jrange[ii], cc = 0; jj < jrange[ii+1]; ++jj, ++cc){
jlist[jj] = nlist_a_cpy[ii][cc];
}
}
std::vector<int> ilist(nloc), numneigh(nloc);
std::vector<int*> firstneigh(nloc);
InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]);
convert_nlist(inlist, nlist_a_cpy);
std::vector<double > em(nloc * ndescrpt), em_deriv(nloc * ndescrpt * 3), rij(nloc * nnei * 3);
std::vector<int> nlist(nloc * nnei);
std::vector<double > avg(ntypes * ndescrpt, 0);
Expand All @@ -472,9 +461,7 @@ TEST_F(TestEnvMatA, prod_cpu_equal_cpu)
&nlist[0],
&posi_cpy[0],
&atype_cpy[0],
&ilist[0],
&jrange[0],
&jlist[0],
inlist,
max_nbor_size,
&avg[0],
&std[0],
Expand Down
35 changes: 11 additions & 24 deletions source/lib/tests/test_env_mat_r.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,11 @@ TEST_F(TestEnvMatR, prod_cpu)
max_nbor_size = nlist_a_cpy[ii].size();
}
}
std::vector<int> ilist(nloc), jlist(tot_nnei), jrange(nloc+1, 0);
for (int ii = 0; ii < nloc; ++ii){
ilist[ii] = ii;
jrange[ii+1] = jrange[ii] + nlist_a_cpy[ii].size();
int jj, cc;
for (jj = jrange[ii], cc = 0; jj < jrange[ii+1]; ++jj, ++cc){
jlist[jj] = nlist_a_cpy[ii][cc];
}
}
std::vector<int> ilist(nloc), numneigh(nloc);
std::vector<int*> firstneigh(nloc);
InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]);
convert_nlist(inlist, nlist_a_cpy);

std::vector<double > em(nloc * ndescrpt), em_deriv(nloc * ndescrpt * 3), rij(nloc * nnei * 3);
std::vector<int> nlist(nloc * nnei);
std::vector<double > avg(ntypes * ndescrpt, 0);
Expand All @@ -269,9 +265,7 @@ TEST_F(TestEnvMatR, prod_cpu)
&nlist[0],
&posi_cpy[0],
&atype_cpy[0],
&ilist[0],
&jrange[0],
&jlist[0],
inlist,
max_nbor_size,
&avg[0],
&std[0],
Expand Down Expand Up @@ -304,15 +298,10 @@ TEST_F(TestEnvMatR, prod_cpu_equal_cpu)
max_nbor_size = nlist_a_cpy[ii].size();
}
}
std::vector<int> ilist(nloc), jlist(tot_nnei), jrange(nloc+1, 0);
for (int ii = 0; ii < nloc; ++ii){
ilist[ii] = ii;
jrange[ii+1] = jrange[ii] + nlist_a_cpy[ii].size();
int jj, cc;
for (jj = jrange[ii], cc = 0; jj < jrange[ii+1]; ++jj, ++cc){
jlist[jj] = nlist_a_cpy[ii][cc];
}
}
std::vector<int> ilist(nloc), numneigh(nloc);
std::vector<int*> firstneigh(nloc);
InputNlist inlist(nloc, &ilist[0], &numneigh[0], &firstneigh[0]);
convert_nlist(inlist, nlist_a_cpy);
std::vector<double > em(nloc * ndescrpt), em_deriv(nloc * ndescrpt * 3), rij(nloc * nnei * 3);
std::vector<int> nlist(nloc * nnei);
std::vector<double > avg(ntypes * ndescrpt, 0);
Expand All @@ -324,9 +313,7 @@ TEST_F(TestEnvMatR, prod_cpu_equal_cpu)
&nlist[0],
&posi_cpy[0],
&atype_cpy[0],
&ilist[0],
&jrange[0],
&jlist[0],
inlist,
max_nbor_size,
&avg[0],
&std[0],
Expand Down
Loading