Merge pull request #3487 from bathmatt/kokkos-mliap-so3
Created a Kokkos version of the ML-IAP routines. Completed one model…
This commit is contained in:
@ -139,6 +139,12 @@ if(PKG_KSPACE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(PKG_ML-IAP)
|
||||
list(APPEND KOKKOS_PKG_SOURCES ${KOKKOS_PKG_SOURCES_DIR}/mliap_data_kokkos.cpp
|
||||
${KOKKOS_PKG_SOURCES_DIR}/mliap_descriptor_so3_kokkos.cpp
|
||||
${KOKKOS_PKG_SOURCES_DIR}/mliap_model_linear_kokkos.cpp
|
||||
${KOKKOS_PKG_SOURCES_DIR}/mliap_so3_kokkos.cpp)
|
||||
endif()
|
||||
|
||||
if(PKG_PHONON)
|
||||
list(APPEND KOKKOS_PKG_SOURCES ${KOKKOS_PKG_SOURCES_DIR}/dynamical_matrix_kokkos.cpp)
|
||||
|
||||
@ -205,7 +205,7 @@ OPT.
|
||||
* :doc:`mesont/tpm <pair_mesont_tpm>`
|
||||
* :doc:`mgpt <pair_mgpt>`
|
||||
* :doc:`mie/cut (g) <pair_mie>`
|
||||
* :doc:`mliap <pair_mliap>`
|
||||
* :doc:`mliap (k) <pair_mliap>`
|
||||
* :doc:`mm3/switch3/coulgauss/long <pair_lj_switch3_coulgauss_long>`
|
||||
* :doc:`momb <pair_momb>`
|
||||
* :doc:`morse (gkot) <pair_morse>`
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
.. index:: pair_style mliap
|
||||
.. index:: pair_style mliap/kk
|
||||
|
||||
pair_style mliap command
|
||||
========================
|
||||
|
||||
Accelerator Variants: *mliap/kk*
|
||||
|
||||
Syntax
|
||||
""""""
|
||||
|
||||
@ -207,6 +210,12 @@ cutoff manually, such as in the following example.
|
||||
on the active LAMMPS object before the pair style is defined. This call locates
|
||||
and loads the mliap-specific python module that is built into LAMMPS.
|
||||
|
||||
----------
|
||||
|
||||
.. include:: accel_styles.rst
|
||||
|
||||
----------
|
||||
|
||||
Mixing, shift, table, tail correction, restart, rRESPA info
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
|
||||
@ -190,6 +190,16 @@ action meam_funcs_kokkos.h meam_funcs.cpp
|
||||
action meam_impl_kokkos.h meam_impl.cpp
|
||||
action meam_setup_done_kokkos.h meam_setup_done.cpp
|
||||
action memory_kokkos.h
|
||||
action mliap_data_kokkos.cpp mliap_data.cpp
|
||||
action mliap_data_kokkos.h mliap_data.h
|
||||
action mliap_descriptor_kokkos.h mliap_descriptor.h
|
||||
action mliap_descriptor_so3_kokkos.cpp mliap_descriptor_so3.cpp
|
||||
action mliap_descriptor_so3_kokkos.h mliap_descriptor_so3.h
|
||||
action mliap_model_linear_kokkos.cpp mliap_model_linear.cpp
|
||||
action mliap_model_linear_kokkos.h mliap_model_linear.h
|
||||
action mliap_model_kokkos.h mliap_model.h
|
||||
action mliap_so3_kokkos.cpp mliap_so3.cpp
|
||||
action mliap_so3_kokkos.h mliap_so3.h
|
||||
action modify_kokkos.cpp
|
||||
action modify_kokkos.h
|
||||
action neigh_bond_kokkos.cpp
|
||||
@ -298,6 +308,8 @@ action pair_lj_spica_kokkos.cpp pair_lj_spica.cpp
|
||||
action pair_lj_spica_kokkos.h pair_lj_spica.h
|
||||
action pair_meam_kokkos.cpp pair_meam.cpp
|
||||
action pair_meam_kokkos.h pair_meam.h
|
||||
action pair_mliap_kokkos.cpp pair_mliap.cpp
|
||||
action pair_mliap_kokkos.h pair_mliap.h
|
||||
action pair_morse_kokkos.cpp
|
||||
action pair_morse_kokkos.h
|
||||
action pair_multi_lucy_rx_kokkos.cpp pair_multi_lucy_rx.cpp
|
||||
|
||||
@ -709,6 +709,15 @@ typedef tdual_float_2d::t_dev_um t_float_2d_um;
|
||||
typedef tdual_float_2d::t_dev_const_um t_float_2d_const_um;
|
||||
typedef tdual_float_2d::t_dev_const_randomread t_float_2d_randomread;
|
||||
|
||||
//3d float array n
|
||||
typedef Kokkos::DualView<LMP_FLOAT***, Kokkos::LayoutRight, LMPDeviceType> tdual_float_3d;
|
||||
typedef tdual_float_3d::t_dev t_float_3d;
|
||||
typedef tdual_float_3d::t_dev_const t_float_3d_const;
|
||||
typedef tdual_float_3d::t_dev_um t_float_3d_um;
|
||||
typedef tdual_float_3d::t_dev_const_um t_float_3d_const_um;
|
||||
typedef tdual_float_3d::t_dev_const_randomread t_float_3d_randomread;
|
||||
|
||||
|
||||
//Position Types
|
||||
//1d X_FLOAT array n
|
||||
typedef Kokkos::DualView<X_FLOAT*, LMPDeviceType::array_layout, LMPDeviceType> tdual_xfloat_1d;
|
||||
|
||||
@ -175,7 +175,7 @@ TYPE create_kokkos(TYPE &data, typename TYPE::value_type **&array,
|
||||
array = (typename TYPE::value_type **) smalloc(nbytes,name);
|
||||
|
||||
for (int i = 0; i < n1; i++) {
|
||||
if (n2==0)
|
||||
if (n2 == 0)
|
||||
array[i] = nullptr;
|
||||
else
|
||||
array[i] = &data.h_view(i,0);
|
||||
@ -194,7 +194,7 @@ template <typename TYPE, typename HTYPE>
|
||||
array = (typename TYPE::value_type **) smalloc(nbytes,name);
|
||||
|
||||
for (int i = 0; i < n1; i++) {
|
||||
if (n2==0)
|
||||
if (n2 == 0)
|
||||
array[i] = nullptr;
|
||||
else
|
||||
array[i] = &h_data(i,0);
|
||||
@ -202,6 +202,67 @@ template <typename TYPE, typename HTYPE>
|
||||
return data;
|
||||
}
|
||||
|
||||
template <typename TYPE, typename HTYPE>
|
||||
TYPE create_kokkos(TYPE &data, HTYPE &h_data, int n1, int n2, int n3,
|
||||
const char *name)
|
||||
{
|
||||
data = TYPE(std::string(name),n1,n2,n3);
|
||||
h_data = Kokkos::create_mirror_view(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
template <typename TYPE>
|
||||
TYPE create_kokkos(TYPE &data, typename TYPE::value_type ***&array,
|
||||
int n1, int n2, int n3, const char *name)
|
||||
{
|
||||
data = TYPE(std::string(name),n1,n2);
|
||||
bigint nbytes = ((bigint) sizeof(typename TYPE::value_type **)) * n1;
|
||||
array = (typename TYPE::value_type ***) smalloc(nbytes,name);
|
||||
|
||||
for (int i = 0; i < n1; i++) {
|
||||
if (n2 == 0) {
|
||||
array[i] = nullptr;
|
||||
} else {
|
||||
nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n2;
|
||||
array[i] = (typename TYPE::value_type **) smalloc(nbytes,name);
|
||||
for (int j = 0; j < n2; j++) {
|
||||
if (n3 == 0)
|
||||
array[i][j] = nullptr;
|
||||
else
|
||||
array[i][j] = &data.h_view(i,j,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
template <typename TYPE, typename HTYPE>
|
||||
TYPE create_kokkos(TYPE &data, HTYPE &h_data,
|
||||
typename TYPE::value_type ***&array, int n1, int n2, int n3,
|
||||
const char *name)
|
||||
{
|
||||
data = TYPE(std::string(name),n1,n2);
|
||||
h_data = Kokkos::create_mirror_view(data);
|
||||
bigint nbytes = ((bigint) sizeof(typename TYPE::value_type **)) * n1;
|
||||
array = (typename TYPE::value_type ***) smalloc(nbytes,name);
|
||||
|
||||
for (int i = 0; i < n1; i++) {
|
||||
if (n2 == 0) {
|
||||
array[i] = nullptr;
|
||||
} else {
|
||||
nbytes = ((bigint) sizeof(typename TYPE::value_type *)) * n2;
|
||||
array[i] = (typename TYPE::value_type **) smalloc(nbytes,name);
|
||||
for (int j = 0; j < n2; j++) {
|
||||
if (n3 == 0)
|
||||
array[i][j] = nullptr;
|
||||
else
|
||||
array[i][j] = &data.h_view(i,j,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
grow or shrink 1st dim of a 2d array
|
||||
last dim must stay the same
|
||||
@ -217,7 +278,7 @@ TYPE grow_kokkos(TYPE &data, typename TYPE::value_type **&array,
|
||||
array = (typename TYPE::value_type**) srealloc(array,nbytes,name);
|
||||
|
||||
for (int i = 0; i < n1; i++)
|
||||
if (n2==0)
|
||||
if (n2 == 0)
|
||||
array[i] = nullptr;
|
||||
else
|
||||
array[i] = &data.h_view(i,0);
|
||||
@ -234,7 +295,7 @@ TYPE create_kokkos(TYPE &data, typename TYPE::value_type **&array,
|
||||
array = (typename TYPE::value_type **) smalloc(nbytes,name);
|
||||
|
||||
for (int i = 0; i < n1; i++)
|
||||
if (data.h_view.extent(1)==0)
|
||||
if (data.h_view.extent(1) == 0)
|
||||
array[i] = nullptr;
|
||||
else
|
||||
array[i] = &data.h_view(i,0);
|
||||
@ -254,7 +315,7 @@ TYPE grow_kokkos(TYPE &data, typename TYPE::value_type **&array,
|
||||
array = (typename TYPE::value_type **) srealloc(array,nbytes,name);
|
||||
|
||||
for (int i = 0; i < n1; i++)
|
||||
if (data.h_view.extent(1)==0)
|
||||
if (data.h_view.extent(1) == 0)
|
||||
array[i] = nullptr;
|
||||
else
|
||||
array[i] = &data.h_view(i,0);
|
||||
@ -275,6 +336,22 @@ void destroy_kokkos(TYPE data, typename TYPE::value_type** &array)
|
||||
array = nullptr;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
destroy a 3d array
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
template <typename TYPE>
|
||||
void destroy_kokkos(TYPE data, typename TYPE::value_type*** &array)
|
||||
{
|
||||
if (array == nullptr) return;
|
||||
int n1 = data.extent(0);
|
||||
for (int i = 0; i < n1; ++i)
|
||||
sfree(array[i]);
|
||||
data = TYPE();
|
||||
sfree(array);
|
||||
array = nullptr;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
reallocate Kokkos views without initialization
|
||||
deallocate first to reduce memory use
|
||||
|
||||
341
src/KOKKOS/mliap_data_kokkos.cpp
Normal file
341
src/KOKKOS/mliap_data_kokkos.cpp
Normal file
@ -0,0 +1,341 @@
|
||||
// clang-format off
|
||||
/* -*- c++ -*- ----------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
LAMMPS Development team: developers@lammps.org
|
||||
|
||||
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.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Contributing author: Matt Bettencourt (NVIDIA)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "mliap_data_kokkos.h"
|
||||
|
||||
#include "atom_kokkos.h"
|
||||
#include "kokkos_type.h"
|
||||
#include "pair_mliap_kokkos.h"
|
||||
#include "atom_masks.h"
|
||||
#include "mliap_descriptor.h"
|
||||
#include "lammps.h"
|
||||
#include "kokkos.h"
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
template<class DeviceType>
|
||||
MLIAPDataKokkos<DeviceType>::MLIAPDataKokkos(LAMMPS *lmp_in, int gradgradflag_in, int *map_in,
|
||||
class MLIAPModel* model_in,
|
||||
class MLIAPDescriptor* descriptor_in,
|
||||
class PairMLIAPKokkos<DeviceType>* pairmliap_in) :
|
||||
MLIAPData(lmp_in, gradgradflag_in, map_in, model_in, descriptor_in, pairmliap_in),
|
||||
k_pairmliap(pairmliap_in),
|
||||
lmp(lmp_in)
|
||||
{
|
||||
execution_space = ExecutionSpaceFromDevice<DeviceType>::space;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
MLIAPDataKokkos<DeviceType>::~MLIAPDataKokkos() {
|
||||
memoryKK->destroy_kokkos(k_gradforce,gradforce);
|
||||
memoryKK->destroy_kokkos(k_betas,betas);
|
||||
memoryKK->destroy_kokkos(k_descriptors,descriptors);
|
||||
memoryKK->destroy_kokkos(k_eatoms,eatoms);
|
||||
memoryKK->destroy_kokkos(k_gamma_row_index,gamma_row_index);
|
||||
memoryKK->destroy_kokkos(k_gamma_col_index,gamma_col_index);
|
||||
memoryKK->destroy_kokkos(k_gamma,gamma);
|
||||
memoryKK->destroy_kokkos(k_iatoms,iatoms);
|
||||
memoryKK->destroy_kokkos(k_ielems,ielems);
|
||||
memoryKK->destroy_kokkos(k_numneighs,numneighs);
|
||||
memoryKK->destroy_kokkos(k_jatoms,jatoms);
|
||||
memoryKK->destroy_kokkos(k_jelems,jelems);
|
||||
memoryKK->destroy_kokkos(k_ij);
|
||||
memoryKK->destroy_kokkos(k_rij,rij);
|
||||
memoryKK->destroy_kokkos(k_graddesc,graddesc);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void MLIAPDataKokkos<DeviceType>::generate_neighdata(class NeighList *list_in, int eflag_in, int vflag_in) {
|
||||
|
||||
list = list_in;
|
||||
|
||||
// grow nmax gradforce array if necessary
|
||||
|
||||
if (atom->nmax > nmax) {
|
||||
nmax = atom->nmax;
|
||||
memoryKK->destroy_kokkos(k_gradforce,gradforce);
|
||||
memoryKK->create_kokkos(k_gradforce, gradforce, nmax, size_gradforce, "mliap_data:gradforce");
|
||||
}
|
||||
|
||||
// clear gradforce array
|
||||
|
||||
auto d_gradforce = k_gradforce.template view<DeviceType>();
|
||||
Kokkos::deep_copy(d_gradforce, 0.);
|
||||
|
||||
// grow arrays if necessary
|
||||
|
||||
nlistatoms = list->inum;
|
||||
if (nlistatoms_max < nlistatoms) {
|
||||
memoryKK->destroy_kokkos(k_betas,betas);
|
||||
memoryKK->create_kokkos(k_betas, betas, nlistatoms, ndescriptors, "mliap_data:betas");
|
||||
memoryKK->destroy_kokkos(k_descriptors,descriptors);
|
||||
memoryKK->create_kokkos(k_descriptors, descriptors, nlistatoms, ndescriptors, "mliap_data:descriptors");
|
||||
memoryKK->destroy_kokkos(k_eatoms,eatoms);
|
||||
memoryKK->create_kokkos(k_eatoms, eatoms, nlistatoms, "mliap_data:eatoms");
|
||||
nlistatoms_max = nlistatoms;
|
||||
}
|
||||
|
||||
// grow gamma arrays if necessary
|
||||
|
||||
if (gradgradflag == 1) {
|
||||
if (natomgamma_max < nlistatoms) {
|
||||
memoryKK->destroy_kokkos(k_gamma_row_index,gamma_row_index);
|
||||
memoryKK->create_kokkos(k_gamma_row_index, gamma_row_index, nlistatoms, gamma_nnz, "mliap_data:gamma_row_index");
|
||||
memoryKK->destroy_kokkos(k_gamma_col_index,gamma_col_index);
|
||||
memoryKK->create_kokkos(k_gamma_col_index, gamma_col_index, nlistatoms, gamma_nnz, "mliap_data:gamma_col_index");
|
||||
memoryKK->destroy_kokkos(k_gamma,gamma);
|
||||
memoryKK->create_kokkos(k_gamma, gamma, nlistatoms, gamma_nnz, "mliap_data:");
|
||||
natomgamma_max = nlistatoms;
|
||||
}
|
||||
}
|
||||
atomKK->sync(execution_space,X_MASK | V_MASK | F_MASK | TYPE_MASK);
|
||||
k_pairmliap->x = atomKK->k_x.view<DeviceType>();
|
||||
k_pairmliap->v = atomKK->k_v.view<DeviceType>();
|
||||
k_pairmliap->f = atomKK->k_f.view<DeviceType>();
|
||||
|
||||
grow_neigharrays();
|
||||
|
||||
// Use the ielems memory for prefix scan and set it at the end to the i type
|
||||
|
||||
auto d_iatoms = k_iatoms.template view<DeviceType>();
|
||||
auto d_ielems = k_ielems.template view<DeviceType>();
|
||||
auto d_ij = k_ij.template view<DeviceType>();
|
||||
auto d_numneighs = k_numneighs.template view<DeviceType>();
|
||||
auto d_jatoms = k_jatoms.template view<DeviceType>();
|
||||
auto d_jelems= k_jelems.template view<DeviceType>();
|
||||
auto d_rij= k_rij.template view<DeviceType>();
|
||||
|
||||
NeighListKokkos<DeviceType>* k_list = static_cast<NeighListKokkos<DeviceType>*>(list);
|
||||
auto d_numneigh = k_list->d_numneigh;
|
||||
auto d_neighbors = k_list->d_neighbors;
|
||||
auto d_ilist = k_list->d_ilist;
|
||||
auto d_cutsq=k_pairmliap->k_cutsq.template view<DeviceType>();
|
||||
|
||||
AtomKokkos *atomKK = (AtomKokkos *) atom;
|
||||
auto x = atomKK->k_x.view<DeviceType>();
|
||||
auto type = atomKK->k_type.view<DeviceType>();
|
||||
auto map=k_pairmliap->k_map.template view<DeviceType>();
|
||||
|
||||
Kokkos::parallel_scan(nlistatoms, KOKKOS_LAMBDA (int ii, int &update, const bool final) {
|
||||
if (final)
|
||||
d_ij(ii) = update;
|
||||
update += d_numneighs(ii);
|
||||
});
|
||||
|
||||
Kokkos::parallel_for(nlistatoms, KOKKOS_LAMBDA (int ii) {
|
||||
int ij = d_ij(ii);
|
||||
const int i = d_ilist[ii];
|
||||
const double xtmp = x(i, 0);
|
||||
const double ytmp = x(i, 1);
|
||||
const double ztmp = x(i, 2);
|
||||
const int itype = type(i);
|
||||
const int ielem = map(itype);
|
||||
const int jnum = d_numneigh(i);
|
||||
for (int jj = 0; jj < jnum; jj++) {
|
||||
int j = d_neighbors(i,jj);
|
||||
j &= NEIGHMASK;
|
||||
const double delx = x(j,0) - xtmp;
|
||||
const double dely = x(j,1) - ytmp;
|
||||
const double delz = x(j,2) - ztmp;
|
||||
const double rsq = delx*delx + dely*dely + delz*delz;
|
||||
int jtype = type(j);
|
||||
const int jelem = map(jtype);
|
||||
if (rsq < d_cutsq(itype,jtype)) {
|
||||
d_jatoms(ij) = j;
|
||||
d_jelems(ij) = jelem;
|
||||
d_rij(ij, 0) = delx;
|
||||
d_rij(ij, 1) = dely;
|
||||
d_rij(ij, 2) = delz;
|
||||
ij++;
|
||||
}
|
||||
}
|
||||
d_iatoms[ii] = i;
|
||||
d_ielems[ii] = ielem;
|
||||
});
|
||||
|
||||
modified(execution_space, NUMNEIGHS_MASK | IATOMS_MASK | IELEMS_MASK | JATOMS_MASK | JELEMS_MASK | RIJ_MASK | IJ_MASK );
|
||||
eflag = eflag_in;
|
||||
vflag = vflag_in;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void MLIAPDataKokkos<DeviceType>::grow_neigharrays() {
|
||||
AtomKokkos *atomKK = (AtomKokkos *) atom;
|
||||
|
||||
// grow neighbor arrays if necessary
|
||||
|
||||
if (natomneigh_max < nlistatoms) {
|
||||
natomneigh_max = nlistatoms;
|
||||
|
||||
memoryKK->destroy_kokkos(k_iatoms,iatoms);
|
||||
memoryKK->create_kokkos(k_iatoms, iatoms, natomneigh_max, "mliap_data:iatoms");
|
||||
memoryKK->destroy_kokkos(k_ielems,ielems);
|
||||
memoryKK->create_kokkos(k_ielems, ielems, natomneigh_max, "mliap_data:ielems");
|
||||
memoryKK->destroy_kokkos(k_ij);
|
||||
memoryKK->create_kokkos(k_ij, natomneigh_max, "mliap_data:ij");
|
||||
memoryKK->destroy_kokkos(k_numneighs,numneighs);
|
||||
memoryKK->create_kokkos(k_numneighs, numneighs, natomneigh_max, "mliap_data:numneighs");
|
||||
}
|
||||
|
||||
NeighListKokkos<DeviceType>* k_list = static_cast<NeighListKokkos<DeviceType>*>(list);
|
||||
auto d_numneigh = k_list->d_numneigh;
|
||||
auto d_neighbors = k_list->d_neighbors;
|
||||
auto d_ilist = k_list->d_ilist;
|
||||
|
||||
auto x = atomKK->k_x.view<DeviceType>();
|
||||
auto type = atomKK->k_type.view<DeviceType>();
|
||||
auto d_cutsq=k_pairmliap->k_cutsq.template view<DeviceType>();
|
||||
auto d_numneighs = k_numneighs.template view<DeviceType>();
|
||||
Kokkos::parallel_reduce(nlistatoms, KOKKOS_LAMBDA (int ii, int &contrib) {
|
||||
const int i = d_ilist[ii];
|
||||
int count=0;
|
||||
const double xtmp = x(i, 0);
|
||||
const double ytmp = x(i, 1);
|
||||
const double ztmp = x(i, 2);
|
||||
const int itype = type(i);
|
||||
const int jnum = d_numneigh(i);
|
||||
for (int jj = 0; jj < jnum; jj++) {
|
||||
int j = d_neighbors(i,jj);
|
||||
j &= NEIGHMASK;
|
||||
const double delx = x(j,0) - xtmp;
|
||||
const double dely = x(j,1) - ytmp;
|
||||
const double delz = x(j,2) - ztmp;
|
||||
const double rsq = delx*delx + dely*dely + delz*delz;
|
||||
int jtype = type(j);
|
||||
if (rsq < d_cutsq(itype,jtype))
|
||||
count++;
|
||||
}
|
||||
d_numneighs(ii) = count;
|
||||
contrib += count;
|
||||
}, nij_total);
|
||||
modified(execution_space, NUMNEIGHS_MASK);
|
||||
|
||||
if (nneigh_max < nij_total) {
|
||||
memoryKK->destroy_kokkos(k_jatoms,jatoms);
|
||||
memoryKK->create_kokkos(k_jatoms, jatoms, nij_total, "mliap_data:jatoms");
|
||||
memoryKK->destroy_kokkos(k_jelems,jelems);
|
||||
memoryKK->create_kokkos(k_jelems, jelems, nij_total, "mliap_data:jelems");
|
||||
memoryKK->destroy_kokkos(k_rij,rij);
|
||||
memoryKK->create_kokkos(k_rij, rij, nij_total, 3, "mliap_data:rij");
|
||||
|
||||
if (gradgradflag == 0){
|
||||
memoryKK->destroy_kokkos(k_graddesc,graddesc);
|
||||
memoryKK->create_kokkos(k_graddesc, graddesc, nij_total, ndescriptors,3, "mliap_data:graddesc");
|
||||
}
|
||||
nneigh_max = nij_total;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void MLIAPDataKokkos<DeviceType>::modified(ExecutionSpace space, unsigned int mask, bool ignore_auto_sync) {
|
||||
if (space == Device) {
|
||||
if (mask & IATOMS_MASK ) k_iatoms .modify<LMPDeviceType>();
|
||||
if (mask & IELEMS_MASK ) k_ielems .modify<LMPDeviceType>();
|
||||
if (mask & JATOMS_MASK ) k_jatoms .modify<LMPDeviceType>();
|
||||
if (mask & JELEMS_MASK ) k_jelems .modify<LMPDeviceType>();
|
||||
if (mask & IJ_MASK ) k_ij .modify<LMPDeviceType>();
|
||||
if (mask & BETAS_MASK ) k_betas .modify<LMPDeviceType>();
|
||||
if (mask & DESCRIPTORS_MASK ) k_descriptors .modify<LMPDeviceType>();
|
||||
if (mask & EATOMS_MASK ) k_eatoms .modify<LMPDeviceType>();
|
||||
if (mask & RIJ_MASK ) k_rij .modify<LMPDeviceType>();
|
||||
if (mask & GRADFORCE_MASK ) k_gradforce .modify<LMPDeviceType>();
|
||||
if (mask & GRADDESC_MASK ) k_graddesc .modify<LMPDeviceType>();
|
||||
if (mask & NUMNEIGHS_MASK ) k_numneighs .modify<LMPDeviceType>();
|
||||
if (mask & GAMMA_MASK_MASK ) k_gamma .modify<LMPDeviceType>();
|
||||
if (mask & GAMMA_ROW_MASK ) k_gamma_row_index.modify<LMPDeviceType>();
|
||||
if (mask & GAMMA_COL_MASK ) k_gamma_col_index.modify<LMPDeviceType>();
|
||||
|
||||
if (lmp->kokkos->auto_sync && !ignore_auto_sync) sync(Host, mask, true);
|
||||
} else {
|
||||
if (mask & IATOMS_MASK ) k_iatoms .modify<LMPHostType>();
|
||||
if (mask & IELEMS_MASK ) k_ielems .modify<LMPHostType>();
|
||||
if (mask & JATOMS_MASK ) k_jatoms .modify<LMPHostType>();
|
||||
if (mask & JELEMS_MASK ) k_jelems .modify<LMPHostType>();
|
||||
if (mask & IJ_MASK ) k_ij .modify<LMPHostType>();
|
||||
if (mask & BETAS_MASK ) k_betas .modify<LMPHostType>();
|
||||
if (mask & DESCRIPTORS_MASK ) k_descriptors .modify<LMPHostType>();
|
||||
if (mask & EATOMS_MASK ) k_eatoms .modify<LMPHostType>();
|
||||
if (mask & RIJ_MASK ) k_rij .modify<LMPHostType>();
|
||||
if (mask & GRADFORCE_MASK ) k_gradforce .modify<LMPHostType>();
|
||||
if (mask & GRADDESC_MASK ) k_graddesc .modify<LMPHostType>();
|
||||
if (mask & NUMNEIGHS_MASK ) k_numneighs .modify<LMPHostType>();
|
||||
if (mask & GAMMA_MASK_MASK ) k_gamma .modify<LMPHostType>();
|
||||
if (mask & GAMMA_ROW_MASK ) k_gamma_row_index.modify<LMPHostType>();
|
||||
if (mask & GAMMA_COL_MASK ) k_gamma_col_index.modify<LMPHostType>();
|
||||
if (lmp->kokkos->auto_sync && !ignore_auto_sync) sync(Device, mask, true);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void MLIAPDataKokkos<DeviceType>::sync(ExecutionSpace space, unsigned int mask, bool ignore_auto_sync) {
|
||||
|
||||
if (space == Device) {
|
||||
if (lmp->kokkos->auto_sync && !ignore_auto_sync) modified(Host, mask, true);
|
||||
if (mask & IATOMS_MASK ) k_iatoms .sync<LMPDeviceType>();
|
||||
if (mask & IELEMS_MASK ) k_ielems .sync<LMPDeviceType>();
|
||||
if (mask & JATOMS_MASK ) k_jatoms .sync<LMPDeviceType>();
|
||||
if (mask & JELEMS_MASK ) k_jelems .sync<LMPDeviceType>();
|
||||
if (mask & IJ_MASK ) k_ij .sync<LMPDeviceType>();
|
||||
if (mask & BETAS_MASK ) k_betas .sync<LMPDeviceType>();
|
||||
if (mask & DESCRIPTORS_MASK ) k_descriptors .sync<LMPDeviceType>();
|
||||
if (mask & EATOMS_MASK ) k_eatoms .sync<LMPDeviceType>();
|
||||
if (mask & RIJ_MASK ) k_rij .sync<LMPDeviceType>();
|
||||
if (mask & GRADFORCE_MASK ) k_gradforce .sync<LMPDeviceType>();
|
||||
if (mask & GRADDESC_MASK ) k_graddesc .sync<LMPDeviceType>();
|
||||
if (mask & NUMNEIGHS_MASK ) k_numneighs .sync<LMPDeviceType>();
|
||||
if (mask & GAMMA_MASK_MASK ) k_gamma .sync<LMPDeviceType>();
|
||||
if (mask & GAMMA_ROW_MASK ) k_gamma_row_index.sync<LMPDeviceType>();
|
||||
if (mask & GAMMA_COL_MASK ) k_gamma_col_index.sync<LMPDeviceType>();
|
||||
} else {
|
||||
if (lmp->kokkos->auto_sync && !ignore_auto_sync) modified(Device, mask, true);
|
||||
if (mask & IATOMS_MASK ) k_iatoms .sync<LMPHostType>();
|
||||
if (mask & IELEMS_MASK ) k_ielems .sync<LMPHostType>();
|
||||
if (mask & JATOMS_MASK ) k_jatoms .sync<LMPHostType>();
|
||||
if (mask & JELEMS_MASK ) k_jelems .sync<LMPHostType>();
|
||||
if (mask & IJ_MASK ) k_ij .sync<LMPHostType>();
|
||||
if (mask & BETAS_MASK ) k_betas .sync<LMPHostType>();
|
||||
if (mask & DESCRIPTORS_MASK ) k_descriptors .sync<LMPHostType>();
|
||||
if (mask & EATOMS_MASK ) k_eatoms .sync<LMPHostType>();
|
||||
if (mask & RIJ_MASK ) k_rij .sync<LMPHostType>();
|
||||
if (mask & GRADFORCE_MASK ) k_gradforce .sync<LMPHostType>();
|
||||
if (mask & GRADDESC_MASK ) k_graddesc .sync<LMPHostType>();
|
||||
if (mask & NUMNEIGHS_MASK ) k_numneighs .sync<LMPHostType>();
|
||||
if (mask & GAMMA_MASK_MASK ) k_gamma .sync<LMPHostType>();
|
||||
if (mask & GAMMA_ROW_MASK ) k_gamma_row_index.sync<LMPHostType>();
|
||||
if (mask & GAMMA_COL_MASK ) k_gamma_col_index.sync<LMPHostType>();
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template class MLIAPDataKokkos<LMPDeviceType>;
|
||||
#ifdef LMP_KOKKOS_GPU
|
||||
template class MLIAPDataKokkos<LMPHostType>;
|
||||
#endif
|
||||
}// namespace
|
||||
87
src/KOKKOS/mliap_data_kokkos.h
Normal file
87
src/KOKKOS/mliap_data_kokkos.h
Normal file
@ -0,0 +1,87 @@
|
||||
/* -*- c++ -*- ----------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
LAMMPS Development team: developers@lammps.org
|
||||
|
||||
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.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Contributing author: Matt Bettencourt (NVIDIA)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef LMP_MLIAP_DATA_KOKKOS_H
|
||||
#define LMP_MLIAP_DATA_KOKKOS_H
|
||||
|
||||
#include "mliap_data.h"
|
||||
|
||||
#include "kokkos_type.h"
|
||||
#include "memory_kokkos.h"
|
||||
#include "pair_mliap_kokkos.h"
|
||||
#include "pointers.h"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
// clang-format off
|
||||
enum {
|
||||
IATOMS_MASK = 0x00000001,
|
||||
IELEMS_MASK = 0x00000002,
|
||||
JATOMS_MASK = 0x00000004,
|
||||
JELEMS_MASK = 0x00000008,
|
||||
IJ_MASK = 0x00000010,
|
||||
BETAS_MASK = 0x00000020,
|
||||
DESCRIPTORS_MASK = 0x00000040,
|
||||
EATOMS_MASK = 0x00000080,
|
||||
RIJ_MASK = 0x00000100,
|
||||
GRADFORCE_MASK = 0x00000200,
|
||||
GRADDESC_MASK = 0x00000400,
|
||||
NUMNEIGHS_MASK = 0x00000800,
|
||||
GAMMA_MASK_MASK = 0x00001000,
|
||||
GAMMA_ROW_MASK = 0x00002000,
|
||||
GAMMA_COL_MASK = 0x00004000,
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
template <class DeviceType> class MLIAPDataKokkos : public MLIAPData {
|
||||
public:
|
||||
MLIAPDataKokkos(class LAMMPS *, int, int *, class MLIAPModel *, class MLIAPDescriptor *,
|
||||
class PairMLIAPKokkos<DeviceType> * = nullptr);
|
||||
~MLIAPDataKokkos() override;
|
||||
ExecutionSpace execution_space;
|
||||
|
||||
void generate_neighdata(class NeighList *, int = 0, int = 0) override;
|
||||
void grow_neigharrays() override;
|
||||
|
||||
void modified(ExecutionSpace space, unsigned int mask, bool ignore_auto_sync = false);
|
||||
|
||||
void sync(ExecutionSpace space, unsigned int mask, bool ignore_auto_sync = false);
|
||||
|
||||
PairMLIAPKokkos<DeviceType> *k_pairmliap;
|
||||
|
||||
DAT::tdual_int_1d k_iatoms; // index of each atom
|
||||
DAT::tdual_int_1d k_ielems; // element of each atom
|
||||
DAT::tdual_int_1d k_jatoms; // index of each neighbor
|
||||
DAT::tdual_int_1d k_jelems; // element of each neighbor
|
||||
DAT::tdual_int_1d k_ij; // Start location for each particle
|
||||
DAT::tdual_float_2d k_betas; // betas for all atoms in list
|
||||
DAT::tdual_float_2d k_descriptors; // descriptors for all atoms in list
|
||||
DAT::tdual_float_1d k_eatoms; // energies for all atoms in list
|
||||
DAT::tdual_float_2d k_rij; // distance vector of each neighbor
|
||||
DAT::tdual_float_2d k_gradforce;
|
||||
DAT::tdual_float_3d k_graddesc; // descriptor gradient w.r.t. each neighbor
|
||||
DAT::tdual_int_1d k_numneighs; // neighbors count for each atom
|
||||
DAT::tdual_float_2d k_gamma; // gamma element
|
||||
DAT::tdual_int_2d k_gamma_row_index; // row (parameter) index
|
||||
DAT::tdual_int_2d k_gamma_col_index; // column (descriptor) index
|
||||
|
||||
int nij_total;
|
||||
|
||||
protected:
|
||||
class LAMMPS *lmp;
|
||||
};
|
||||
} // namespace LAMMPS_NS
|
||||
#endif
|
||||
54
src/KOKKOS/mliap_descriptor_kokkos.h
Normal file
54
src/KOKKOS/mliap_descriptor_kokkos.h
Normal file
@ -0,0 +1,54 @@
|
||||
/* -*- c++ -*- ----------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
LAMMPS Development team: developers@lammps.org
|
||||
|
||||
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.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Contributing author: Matt Bettencourt (NVIDIA)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef LMP_MLIAP_DESCRIPTOR_KOKKOS_H
|
||||
#define LMP_MLIAP_DESCRIPTOR_KOKKOS_H
|
||||
|
||||
#include "kokkos_type.h"
|
||||
#include "memory_kokkos.h"
|
||||
#include "mliap_descriptor.h"
|
||||
#include "pointers.h"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
template <class DeviceType> class MLIAPDescriptorKokkos : virtual protected Pointers {
|
||||
public:
|
||||
MLIAPDescriptorKokkos(LAMMPS *lmp, MLIAPDescriptor *descriptor_in) :
|
||||
Pointers(lmp), descriptor(descriptor_in)
|
||||
{
|
||||
memoryKK->destroy_kokkos(k_wjelem);
|
||||
}
|
||||
|
||||
void init_data()
|
||||
{
|
||||
int num_elems = descriptor->nelements;
|
||||
memoryKK->destroy_kokkos(k_wjelem);
|
||||
memoryKK->create_kokkos(k_wjelem, num_elems, "MLIAPDescriptorKokkos::k_wjelem");
|
||||
for (int i = 0; i < num_elems; ++i) k_wjelem.h_view(i) = descriptor->wjelem[i];
|
||||
k_wjelem.modify<LMPHostType>();
|
||||
k_wjelem.sync<LMPDeviceType>();
|
||||
}
|
||||
|
||||
virtual ~MLIAPDescriptorKokkos()
|
||||
{
|
||||
memoryKK->destroy_kokkos(k_wjelem);
|
||||
}
|
||||
|
||||
MLIAPDescriptor *descriptor;
|
||||
DAT::tdual_float_1d k_wjelem;
|
||||
};
|
||||
} // namespace LAMMPS_NS
|
||||
#endif
|
||||
275
src/KOKKOS/mliap_descriptor_so3_kokkos.cpp
Normal file
275
src/KOKKOS/mliap_descriptor_so3_kokkos.cpp
Normal file
@ -0,0 +1,275 @@
|
||||
// clang-format off
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
LAMMPS Development team: developers@lammps.org
|
||||
|
||||
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.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Contributing author: Matt Bettencourt (NVIDIA)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "mliap_descriptor_so3_kokkos.h"
|
||||
|
||||
#include "atom_kokkos.h"
|
||||
#include "comm.h"
|
||||
#include "error.h"
|
||||
#include "memory.h"
|
||||
#include "mliap_data_kokkos.h"
|
||||
#include "mliap_so3_kokkos.h"
|
||||
#include "pair_mliap.h"
|
||||
#include "tokenizer.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
#define MAXLINE 1024
|
||||
#define MAXWORD 3
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
template <class DeviceType>
|
||||
MLIAPDescriptorSO3Kokkos<DeviceType>::MLIAPDescriptorSO3Kokkos(LAMMPS *lmp, char *paramfilename)
|
||||
// TODO: why take self as param, shouldn't be needed
|
||||
: Pointers(lmp), MLIAPDescriptorSO3(lmp, paramfilename), MLIAPDescriptorKokkos<DeviceType>(lmp, this)
|
||||
{
|
||||
// TODO: the MLIAP_SO3 object likely needs a kokkos-ified version
|
||||
so3ptr_kokkos = new MLIAP_SO3Kokkos<DeviceType>(lmp, rcutfac, lmax, nmax, alpha);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template <class DeviceType>
|
||||
MLIAPDescriptorSO3Kokkos<DeviceType>::~MLIAPDescriptorSO3Kokkos()
|
||||
{
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template <class DeviceType>
|
||||
void MLIAPDescriptorSO3Kokkos<DeviceType>::compute_descriptors(class MLIAPData *data_)
|
||||
{
|
||||
auto data = static_cast<MLIAPDataKokkos<DeviceType>*>(data_);
|
||||
so3ptr_kokkos->spectrum(data->nlistatoms, data->k_numneighs, data->k_jelems, this->k_wjelem, data->k_rij, data->k_ij,
|
||||
nmax, lmax, rcutfac, alpha, data->nij_total, data->ndescriptors);
|
||||
|
||||
Kokkos::deep_copy(data->k_descriptors.template view<DeviceType>(), so3ptr_kokkos->m_plist_r);
|
||||
Kokkos::deep_copy(data->k_descriptors.h_view, so3ptr_kokkos->m_plist_r);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template <class DeviceType>
|
||||
void MLIAPDescriptorSO3Kokkos<DeviceType>::compute_forces(class MLIAPData *data_)
|
||||
{
|
||||
auto data = static_cast<MLIAPDataKokkos<DeviceType>*>(data_);
|
||||
int npairs = data->nij_total;
|
||||
auto d_numneighs = data->k_numneighs.template view<DeviceType>();
|
||||
so3ptr_kokkos->spectrum_dxdr(data->nlistatoms, data->k_numneighs, data->k_jelems, this->k_wjelem, data->k_rij, data->k_ij,
|
||||
nmax, lmax, rcutfac, alpha, npairs, data->ndescriptors);
|
||||
|
||||
auto d_f = atomKK->k_f.view<DeviceType>();
|
||||
auto d_iatoms = data->k_iatoms.template view<DeviceType>();
|
||||
auto d_jatoms = data->k_jatoms.template view<DeviceType>();
|
||||
auto d_betas = data->k_betas.template view<DeviceType>();
|
||||
auto d_rij = data->k_rij.template view<DeviceType>();
|
||||
auto d_ij = data->k_ij.template view<DeviceType>();
|
||||
auto ndescriptors = data->ndescriptors;
|
||||
auto d_dplist_r = so3ptr_kokkos->k_dplist_r;
|
||||
auto vflag=data->vflag;
|
||||
int vflag_either=data->k_pairmliap->vflag_either, vflag_global=data->pairmliap->vflag_global, vflag_atom=data->pairmliap->vflag_atom;
|
||||
auto d_vatom = data->k_pairmliap->k_vatom.template view<DeviceType>();
|
||||
Kokkos::View<double[6], DeviceType> virial("virial");
|
||||
data->k_pairmliap->k_vatom.template modify<LMPHostType>();
|
||||
data->k_pairmliap->k_vatom.template sync<DeviceType>();
|
||||
Kokkos::parallel_for(data->nlistatoms, KOKKOS_LAMBDA(int ii) {
|
||||
double fij[3];
|
||||
const int i = d_iatoms(ii);
|
||||
|
||||
// ensure rij, inside, wj, and rcutij are of size jnum
|
||||
|
||||
const int jnum = d_numneighs(ii);
|
||||
int ij = d_ij(ii); // use precomputed ij to break loop dependency
|
||||
for (int jj = 0; jj < jnum; jj++) {
|
||||
int j = d_jatoms(ij);
|
||||
|
||||
for (int ir = 0; ir < 3; ir++) {
|
||||
fij[ir] = 0.0;
|
||||
for (int icoeff = 0; icoeff < ndescriptors; icoeff++) {
|
||||
fij[ir] += d_betas(ii, icoeff) *
|
||||
d_dplist_r(ij,icoeff, ir);
|
||||
}
|
||||
}
|
||||
|
||||
Kokkos::atomic_add(&d_f(i, 0),fij[0]);
|
||||
Kokkos::atomic_add(&d_f(i, 1),fij[1]);
|
||||
Kokkos::atomic_add(&d_f(i, 2),fij[2]);
|
||||
Kokkos::atomic_add(&d_f(j, 0),-fij[0]);
|
||||
Kokkos::atomic_add(&d_f(j, 1),-fij[1]);
|
||||
Kokkos::atomic_add(&d_f(j, 2),-fij[2]);
|
||||
|
||||
if (vflag) {
|
||||
v_tally(vflag_either, vflag_global, vflag_atom, i, j, ij, fij, d_rij, virial, d_vatom);
|
||||
}
|
||||
ij++;
|
||||
}
|
||||
});
|
||||
|
||||
if (vflag) {
|
||||
if (vflag_global) {
|
||||
Kokkos::View<double[6], LMPHostType> h_virial("h_virial");
|
||||
Kokkos::deep_copy(h_virial,virial);
|
||||
for (int i=0;i<6;++i)
|
||||
data->k_pairmliap->virial[i]+=h_virial[i];
|
||||
}
|
||||
if (vflag_atom) {
|
||||
data->k_pairmliap->k_vatom.template modify<DeviceType>();
|
||||
data->k_pairmliap->k_vatom.template sync<LMPHostType>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
add virial contribution into global and per-atom accumulators
|
||||
------------------------------------------------------------------------- */
|
||||
template <class DeviceType>
|
||||
template <typename ViewType>
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void MLIAPDescriptorSO3Kokkos<DeviceType>::v_tally(int vflag_either, int vflag_global, int vflag_atom, int i, int j, int ij,
|
||||
double *fij, ViewType rij, Kokkos::View<double[6],DeviceType> virial, ViewType vatom)
|
||||
{
|
||||
double v[6];
|
||||
if (vflag_either) {
|
||||
v[0] = -rij(ij,0)*fij[0];
|
||||
v[1] = -rij(ij,1)*fij[1];
|
||||
v[2] = -rij(ij,2)*fij[2];
|
||||
v[3] = -rij(ij,0)*fij[1];
|
||||
v[4] = -rij(ij,0)*fij[2];
|
||||
v[5] = -rij(ij,1)*fij[2];
|
||||
if (vflag_global) {
|
||||
Kokkos::atomic_add(&virial[0], v[0]);
|
||||
Kokkos::atomic_add(&virial[1], v[1]);
|
||||
Kokkos::atomic_add(&virial[2], v[2]);
|
||||
Kokkos::atomic_add(&virial[3], v[3]);
|
||||
Kokkos::atomic_add(&virial[4], v[4]);
|
||||
Kokkos::atomic_add(&virial[5], v[5]);
|
||||
}
|
||||
if (vflag_atom) {
|
||||
Kokkos::atomic_add(&vatom(i,0), 0.5*v[0]);
|
||||
Kokkos::atomic_add(&vatom(i,1), 0.5*v[1]);
|
||||
Kokkos::atomic_add(&vatom(i,2), 0.5*v[2]);
|
||||
Kokkos::atomic_add(&vatom(i,3), 0.5*v[3]);
|
||||
Kokkos::atomic_add(&vatom(i,4), 0.5*v[4]);
|
||||
Kokkos::atomic_add(&vatom(i,5), 0.5*v[5]);
|
||||
|
||||
Kokkos::atomic_add(&vatom(j,0), 0.5*v[0]);
|
||||
Kokkos::atomic_add(&vatom(j,1), 0.5*v[1]);
|
||||
Kokkos::atomic_add(&vatom(j,2), 0.5*v[2]);
|
||||
Kokkos::atomic_add(&vatom(j,3), 0.5*v[3]);
|
||||
Kokkos::atomic_add(&vatom(j,4), 0.5*v[4]);
|
||||
Kokkos::atomic_add(&vatom(j,5), 0.5*v[5]);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template <class DeviceType>
|
||||
void MLIAPDescriptorSO3Kokkos<DeviceType>::compute_force_gradients(class MLIAPData *data_)
|
||||
{
|
||||
error->all(FLERR,"This has not been tested in cuda/kokkos");
|
||||
|
||||
auto data = static_cast<MLIAPDataKokkos<DeviceType>*>(data_);
|
||||
int npairs = data->nij_total;
|
||||
so3ptr_kokkos->spectrum_dxdr(data->nlistatoms, data->k_numneighs, data->k_jelems, this->k_wjelem, data->k_rij, data->k_ij,
|
||||
nmax, lmax, rcutfac, alpha, npairs, data->ndescriptors);
|
||||
auto d_dplist_r = so3ptr_kokkos->k_dplist_r;
|
||||
auto d_gradforce = data->k_gradforce.template view<DeviceType>();
|
||||
auto d_gamma = data->k_gamma.template view<DeviceType>();
|
||||
auto d_gamma_row_index = data->k_gamma_row_index.template view<DeviceType>();
|
||||
auto d_gamma_col_index = data->k_gamma_col_index.template view<DeviceType>();
|
||||
auto d_jatoms = data->k_jatoms.template view<DeviceType>();
|
||||
auto d_ij = data->k_ij.template view<DeviceType>();
|
||||
auto d_numneighs = data->k_numneighs.template view<DeviceType>();
|
||||
auto d_iatoms = data->k_iatoms.template view<DeviceType>();
|
||||
|
||||
auto yoffset = data->yoffset, zoffset = data->zoffset, gamma_nnz = data->gamma_nnz;
|
||||
|
||||
Kokkos::parallel_for (data->nlistatoms, KOKKOS_LAMBDA (int ii) {
|
||||
const int i = d_iatoms(ii);
|
||||
|
||||
// insure rij, inside, wj, and rcutij are of size jnum
|
||||
|
||||
const int jnum = d_numneighs(ii);
|
||||
int ij = d_ij(ii);
|
||||
for (int jj = 0; jj < jnum; jj++) {
|
||||
int j = d_jatoms(ij);
|
||||
|
||||
for (int inz = 0; inz < gamma_nnz; inz++) {
|
||||
const int l = d_gamma_row_index(ii, inz);
|
||||
const int k = d_gamma_col_index(ii, inz);
|
||||
|
||||
Kokkos::atomic_add(&d_gradforce(i, l), +
|
||||
d_gamma(ii, inz) * d_dplist_r(ij, k, 0));
|
||||
Kokkos::atomic_add(&d_gradforce(i, l + yoffset), +
|
||||
d_gamma(ii, inz) * d_dplist_r(ij, k, 1));
|
||||
Kokkos::atomic_add(&d_gradforce(i, l + zoffset), +
|
||||
d_gamma(ii, inz) * d_dplist_r(ij, k, 2));
|
||||
Kokkos::atomic_add(&d_gradforce(j, l), -
|
||||
d_gamma(ii, inz) * d_dplist_r(ij, k, 0));
|
||||
Kokkos::atomic_add(&d_gradforce(j, l + yoffset), -
|
||||
d_gamma(ii, inz) * d_dplist_r(ij, k, 1));
|
||||
Kokkos::atomic_add(&d_gradforce(j, l + zoffset), -
|
||||
d_gamma(ii, inz) * d_dplist_r(ij, k, 2));
|
||||
}
|
||||
ij++;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template <class DeviceType>
|
||||
void MLIAPDescriptorSO3Kokkos<DeviceType>::compute_descriptor_gradients(class MLIAPData *data_)
|
||||
{
|
||||
auto data = static_cast<MLIAPDataKokkos<DeviceType>*>(data_);
|
||||
bigint npairs = data->nij_total;
|
||||
so3ptr_kokkos->spectrum_dxdr(data->nlistatoms, data->k_numneighs, data->k_jelems, this->k_wjelem, data->k_rij, data->k_ij,
|
||||
nmax, lmax, rcutfac, alpha, npairs, data->ndescriptors);
|
||||
auto graddesc = data->k_graddesc.template view<DeviceType>();
|
||||
Kokkos::deep_copy(graddesc, so3ptr_kokkos->k_dplist_r);
|
||||
Kokkos::deep_copy(data->k_graddesc.h_view, graddesc);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template <class DeviceType>
|
||||
void MLIAPDescriptorSO3Kokkos<DeviceType>::init()
|
||||
{
|
||||
so3ptr_kokkos->init();
|
||||
MLIAPDescriptorKokkos<DeviceType>::init_data();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template <class DeviceType>
|
||||
double MLIAPDescriptorSO3Kokkos<DeviceType>::memory_usage()
|
||||
{
|
||||
double bytes = MLIAPDescriptor::memory_usage();
|
||||
bytes += so3ptr_kokkos->memory_usage();
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
template class MLIAPDescriptorSO3Kokkos<LMPDeviceType>;
|
||||
#ifdef LMP_KOKKOS_GPU
|
||||
template class MLIAPDescriptorSO3Kokkos<LMPHostType>;
|
||||
#endif
|
||||
}
|
||||
51
src/KOKKOS/mliap_descriptor_so3_kokkos.h
Normal file
51
src/KOKKOS/mliap_descriptor_so3_kokkos.h
Normal file
@ -0,0 +1,51 @@
|
||||
/* -*- c++ -*- ----------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/ Sandia National Laboratories
|
||||
LAMMPS Development team: developers@lammps.org
|
||||
|
||||
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.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Contributing author: Matt Bettencourt (NVIDIA)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef LMP_MLIAP_DESCRIPTOR_SO3_KOKKOS_H
|
||||
#define LMP_MLIAP_DESCRIPTOR_SO3_KOKKOS_H
|
||||
|
||||
#include "mliap_descriptor_kokkos.h"
|
||||
#include "mliap_descriptor_so3.h"
|
||||
#include "mliap_so3_kokkos.h"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
template <class DeviceType>
|
||||
class MLIAPDescriptorSO3Kokkos :
|
||||
public MLIAPDescriptorSO3,
|
||||
public MLIAPDescriptorKokkos<DeviceType> {
|
||||
public:
|
||||
MLIAPDescriptorSO3Kokkos(LAMMPS *, char *);
|
||||
~MLIAPDescriptorSO3Kokkos() override;
|
||||
|
||||
void compute_descriptors(class MLIAPData *) override;
|
||||
void compute_forces(class MLIAPData *) override;
|
||||
void compute_force_gradients(class MLIAPData *) override;
|
||||
void compute_descriptor_gradients(class MLIAPData *) override;
|
||||
void init() override;
|
||||
double memory_usage() override;
|
||||
|
||||
protected:
|
||||
template <typename ViewType>
|
||||
KOKKOS_FUNCTION static void v_tally(int vflag_either, int vflag_global, int vflag_atom, int i,
|
||||
int j, int ij, double *fij, ViewType rij,
|
||||
Kokkos::View<double[6], DeviceType> virial, ViewType vatom);
|
||||
class MLIAP_SO3Kokkos<DeviceType> *so3ptr_kokkos;
|
||||
|
||||
// inherited from non-Kokkos class
|
||||
};
|
||||
} // namespace LAMMPS_NS
|
||||
#endif
|
||||
54
src/KOKKOS/mliap_model_kokkos.h
Normal file
54
src/KOKKOS/mliap_model_kokkos.h
Normal file
@ -0,0 +1,54 @@
|
||||
/* -*- c++ -*- ----------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
LAMMPS Development team: developers@lammps.org
|
||||
|
||||
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.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Contributing author: Matt Bettencourt (NVIDIA)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef LMP_MLIAP_MODEL_KOKKOS_H
|
||||
#define LMP_MLIAP_MODEL_KOKKOS_H
|
||||
|
||||
#include "kokkos_type.h"
|
||||
#include "memory_kokkos.h"
|
||||
#include "pointers.h"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
template <class DeviceType> class MLIAPModelKokkos : protected Pointers {
|
||||
public:
|
||||
MLIAPModelKokkos(LAMMPS *lmp, MLIAPModel *model_in) : Pointers(lmp), model(model_in) {}
|
||||
virtual ~MLIAPModelKokkos()
|
||||
{
|
||||
memoryKK->destroy_kokkos(k_coeffelem);
|
||||
model->coeffelem = nullptr;
|
||||
}
|
||||
|
||||
void set_k_coeffelem()
|
||||
{
|
||||
double **tmp = nullptr;
|
||||
memoryKK->destroy_kokkos(k_coeffelem);
|
||||
memoryKK->create_kokkos(k_coeffelem, tmp, model->nelements, model->nparams,
|
||||
"MLIAPModelKokkos::coeffelem");
|
||||
for (int i = 0; i < model->nelements; ++i)
|
||||
for (int j = 0; j < model->nparams; ++j) tmp[i][j] = model->coeffelem[i][j];
|
||||
delete model->coeffelem;
|
||||
model->coeffelem = tmp;
|
||||
k_coeffelem.modify<LMPHostType>();
|
||||
k_coeffelem.sync<LMPDeviceType>();
|
||||
}
|
||||
|
||||
MLIAPModel *model;
|
||||
DAT::tdual_float_2d k_coeffelem;
|
||||
};
|
||||
} // namespace LAMMPS_NS
|
||||
#endif
|
||||
99
src/KOKKOS/mliap_model_linear_kokkos.cpp
Normal file
99
src/KOKKOS/mliap_model_linear_kokkos.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
// clang-format off
|
||||
/* -*- c++ -*- ----------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
LAMMPS Development team: developers@lammps.org
|
||||
|
||||
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.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Contributing author: Matt Bettencourt (NVIDIA)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "mliap_model_linear_kokkos.h"
|
||||
|
||||
#include "mliap_data_kokkos.h"
|
||||
#include "error.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
template<class DeviceType>
|
||||
MLIAPModelLinearKokkos<DeviceType>::MLIAPModelLinearKokkos(LAMMPS *lmp, char *args) :
|
||||
MLIAPModelLinear(lmp,args),
|
||||
MLIAPModelKokkos<DeviceType>(lmp, this)
|
||||
{
|
||||
if (args) MLIAPModelKokkos<DeviceType>::set_k_coeffelem();
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void MLIAPModelLinearKokkos<DeviceType>::compute_gradients(class MLIAPData *data)
|
||||
{
|
||||
MLIAPDataKokkos<DeviceType> *k_data = (MLIAPDataKokkos<DeviceType>*)(data);
|
||||
|
||||
// read but never changes
|
||||
auto d_coeffelem = this->k_coeffelem.template view<DeviceType>();
|
||||
|
||||
// read
|
||||
auto d_ielems = k_data->k_ielems.template view<DeviceType>();
|
||||
auto d_descriptors = k_data->k_descriptors.template view<DeviceType>();
|
||||
|
||||
// written
|
||||
auto d_betas = k_data->k_betas.template view<DeviceType>();
|
||||
auto d_eatoms = k_data->k_eatoms.template view<DeviceType>();
|
||||
|
||||
const auto eflag = data->eflag;
|
||||
const int ndescriptors=data->ndescriptors;
|
||||
|
||||
Kokkos::parallel_reduce(data->nlistatoms, KOKKOS_LAMBDA (int ii, double &update) {
|
||||
const int ielem = d_ielems(ii);
|
||||
|
||||
for (int icoeff = 0; icoeff < ndescriptors; icoeff++)
|
||||
d_betas(ii,icoeff) = d_coeffelem(ielem,icoeff+1);
|
||||
|
||||
// add in contributions to global and per-atom energy
|
||||
// this is optional and has no effect on force calculation
|
||||
if (eflag) {
|
||||
// energy of atom I
|
||||
double etmp = d_coeffelem(ielem,0);
|
||||
|
||||
// E_i = beta.B_i
|
||||
for (int icoeff = 0; icoeff < ndescriptors; icoeff++)
|
||||
etmp += d_coeffelem(ielem,icoeff+1)*d_descriptors(ii, icoeff);
|
||||
update += etmp;
|
||||
d_eatoms(ii) = etmp;
|
||||
}
|
||||
}, data->energy);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void MLIAPModelLinearKokkos<DeviceType>::compute_gradgrads(class MLIAPData *data)
|
||||
{
|
||||
MLIAPModelLinear::compute_gradgrads(data);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void MLIAPModelLinearKokkos<DeviceType>::compute_force_gradients(class MLIAPData *data)
|
||||
{
|
||||
MLIAPModelLinear::compute_force_gradients(data);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
template class MLIAPModelLinearKokkos<LMPDeviceType>;
|
||||
#ifdef LMP_KOKKOS_GPU
|
||||
template class MLIAPModelLinearKokkos<LMPHostType>;
|
||||
#endif
|
||||
}
|
||||
37
src/KOKKOS/mliap_model_linear_kokkos.h
Normal file
37
src/KOKKOS/mliap_model_linear_kokkos.h
Normal file
@ -0,0 +1,37 @@
|
||||
/* -*- c++ -*- ----------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
LAMMPS Development team: developers@lammps.org
|
||||
|
||||
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.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Contributing author: Matt Bettencourt (NVIDIA)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef LMP_MLIAP_MODEL_LINEAR_KOKKOS_H
|
||||
#define LMP_MLIAP_MODEL_LINEAR_KOKKOS_H
|
||||
|
||||
#include "mliap_model_linear.h"
|
||||
|
||||
#include "mliap_model_kokkos.h"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
template <class DeviceType>
|
||||
class MLIAPModelLinearKokkos : public MLIAPModelLinear, public MLIAPModelKokkos<DeviceType> {
|
||||
public:
|
||||
MLIAPModelLinearKokkos(LAMMPS *, char * = nullptr);
|
||||
|
||||
void compute_gradients(class MLIAPData *) override;
|
||||
void compute_gradgrads(class MLIAPData *) override;
|
||||
void compute_force_gradients(class MLIAPData *) override;
|
||||
};
|
||||
} // namespace LAMMPS_NS
|
||||
#endif
|
||||
1194
src/KOKKOS/mliap_so3_kokkos.cpp
Normal file
1194
src/KOKKOS/mliap_so3_kokkos.cpp
Normal file
File diff suppressed because it is too large
Load Diff
142
src/KOKKOS/mliap_so3_kokkos.h
Normal file
142
src/KOKKOS/mliap_so3_kokkos.h
Normal file
@ -0,0 +1,142 @@
|
||||
/* -*- c++ -*- ----------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
LAMMPS Development team: developers@lammps.org
|
||||
|
||||
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.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Contributing author: Matt Bettencourt (NVIDIA)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef LMP_MLIAP_SO3_KOKKOS_H
|
||||
#define LMP_MLIAP_SO3_KOKKOS_H
|
||||
|
||||
#include "kokkos_type.h"
|
||||
#include "pointers.h"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
template <class DeviceType> class MLIAP_SO3Kokkos : protected Pointers {
|
||||
public:
|
||||
MLIAP_SO3Kokkos(LAMMPS *, double vrcut, int vlmax, int vnmax, double valpha);
|
||||
MLIAP_SO3Kokkos(LAMMPS *_lmp) : Pointers(_lmp){};
|
||||
~MLIAP_SO3Kokkos() override;
|
||||
|
||||
void init();
|
||||
double memory_usage();
|
||||
|
||||
using MemoryDeviceType = typename KKDevice<DeviceType>::value;
|
||||
using float_1d = Kokkos::View<double *, Kokkos::LayoutRight, MemoryDeviceType>;
|
||||
using float_2d = Kokkos::View<double **, Kokkos::LayoutRight, MemoryDeviceType>;
|
||||
using float_3d = Kokkos::View<double ***, Kokkos::LayoutRight, MemoryDeviceType>;
|
||||
using float_4d = Kokkos::View<double ****, Kokkos::LayoutRight, MemoryDeviceType>;
|
||||
using int_1d = Kokkos::View<int *, MemoryDeviceType>;
|
||||
|
||||
int ncoeff;
|
||||
float_2d m_plist_r;
|
||||
float_3d k_dplist_r;
|
||||
|
||||
private:
|
||||
double alloc_init, alloc_arrays;
|
||||
int_1d m_ellpl1, m_ellm1;
|
||||
float_1d m_pfac, m_Ylms;
|
||||
int m_pfac_l1, m_pfac_l2;
|
||||
float_1d m_dfac0, m_dfac1, m_dfac2, m_dfac3, m_dfac4, m_dfac5;
|
||||
int m_dfac_l1, m_dfac_l2;
|
||||
double m_rcut, m_alpha;
|
||||
int m_lmax, m_nmax, m_Nmax;
|
||||
float_1d m_g_array, m_w;
|
||||
float_1d m_rootpq;
|
||||
int_1d m_idxu_block, m_idxylm;
|
||||
int m_idxu_count, m_idxy_count;
|
||||
int m_numYlms;
|
||||
|
||||
float_3d m_clisttot_r, m_clisttot_i;
|
||||
float_1d m_rip_array, m_rip_darray;
|
||||
float_1d m_sbes_array, m_sbes_darray;
|
||||
int m_init_arrays;
|
||||
|
||||
float_2d m_ulist_r, m_ulist_i;
|
||||
|
||||
float_3d m_dYlm_r, m_dYlm_i;
|
||||
float_4d m_dclist;
|
||||
|
||||
// arguments for operators.
|
||||
int_1d t_numneighs;
|
||||
int_1d t_jelems;
|
||||
float_1d t_wjelem;
|
||||
float_2d t_rij;
|
||||
int t_nmax;
|
||||
int t_lmax;
|
||||
double t_rcut;
|
||||
double t_alpha;
|
||||
int_1d t_ij;
|
||||
|
||||
static constexpr bigint m_temp_memory_size = 512 * 1024 * 1024;
|
||||
int m_chunk_size;
|
||||
|
||||
public:
|
||||
void spectrum(int nlocal, DAT::tdual_int_1d numneighs, DAT::tdual_int_1d jelems,
|
||||
DAT::tdual_float_1d wjelem, DAT::tdual_float_2d rij, DAT::tdual_int_1d k_ij,
|
||||
int nmax, int lmax, double rcut, double alpha, int totaln, int ncoefs);
|
||||
struct MLIAPSO3SpectrumTag {};
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const MLIAPSO3SpectrumTag &, int ii) const;
|
||||
|
||||
void spectrum_dxdr(int nlocal, DAT::tdual_int_1d numneighs, DAT::tdual_int_1d jelems,
|
||||
DAT::tdual_float_1d wjelem, DAT::tdual_float_2d rij, DAT::tdual_int_1d k_ij,
|
||||
int nmax, int lmax, double rcut, double alpha, bigint npairs, int ncoefs);
|
||||
struct MLIAPSO3SpectrumDXDRTag {};
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const MLIAPSO3SpectrumDXDRTag &, int ii) const;
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
double Cosine(double Rij, double Rc) const;
|
||||
KOKKOS_FUNCTION
|
||||
double CosinePrime(double Rij, double Rc) const;
|
||||
KOKKOS_FUNCTION
|
||||
double compute_sfac(double r, double rcut) const;
|
||||
KOKKOS_FUNCTION
|
||||
double compute_dsfac(double r, double rcut) const;
|
||||
|
||||
struct MLIAPSO3GetSBESArrayTag {};
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const MLIAPSO3GetSBESArrayTag &, int ii) const;
|
||||
|
||||
struct MLIAPSO3GetRipArrayTag {};
|
||||
KOKKOS_FUNCTION
|
||||
void operator()(const MLIAPSO3GetRipArrayTag &, int ii) const;
|
||||
|
||||
void init_arrays(int nlocal, int ncoefs);
|
||||
void init_garray(int nmax, int lmax, double rcut, double alpha, double *w, int lw1,
|
||||
double *g_array, int lg2);
|
||||
|
||||
template <typename UlistView>
|
||||
KOKKOS_FUNCTION void compute_uarray_recursive(double x, double y, double z, double r, int twol,
|
||||
UlistView ulist_r, UlistView ulist_i,
|
||||
int_1d idxu_block, float_1d rootpqarray) const;
|
||||
void compute_ncoeff();
|
||||
|
||||
KOKKOS_FUNCTION
|
||||
static int get_sum(int istart, int iend, int id, int imult);
|
||||
|
||||
double compute_g(double r, int n, int nmax, double rcut, double *w, int lw1);
|
||||
double phi(double r, int alpha, double rcut);
|
||||
|
||||
template <typename ViewType>
|
||||
KOKKOS_FUNCTION void compute_pi(int nmax, int lmax, ViewType clisttot_r, ViewType clisttot_i,
|
||||
int lcl2, float_2d plist_r, int indpl) const;
|
||||
|
||||
void compute_W(int nmax, double *arr);
|
||||
};
|
||||
|
||||
} // namespace LAMMPS_NS
|
||||
|
||||
#endif
|
||||
288
src/KOKKOS/pair_mliap_kokkos.cpp
Normal file
288
src/KOKKOS/pair_mliap_kokkos.cpp
Normal file
@ -0,0 +1,288 @@
|
||||
/* -*- c++ -*- ----------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
LAMMPS Development team: developers@lammps.org
|
||||
|
||||
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.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Contributing author: Matt Bettencourt (NVIDIA)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "pair_mliap_kokkos.h"
|
||||
#include "memory_kokkos.h"
|
||||
#include "atom_kokkos.h"
|
||||
#include "atom_masks.h"
|
||||
#include "mliap_data_kokkos.h"
|
||||
#include "mliap_descriptor_so3_kokkos.h"
|
||||
#include "mliap_model_linear_kokkos.h"
|
||||
#include "error.h"
|
||||
#include "neigh_request.h"
|
||||
#include "lammps.h"
|
||||
#include "kokkos.h"
|
||||
#include "pointers.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
PairMLIAPKokkos<DeviceType>::PairMLIAPKokkos(class LAMMPS* l) : PairMLIAP(l)
|
||||
{
|
||||
kokkosable = 1;
|
||||
execution_space = ExecutionSpaceFromDevice<DeviceType>::space;
|
||||
datamask_modify = 0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
PairMLIAPKokkos<DeviceType>::~PairMLIAPKokkos()
|
||||
{
|
||||
memoryKK->destroy_kokkos(k_map, map);
|
||||
memoryKK->destroy_kokkos(k_cutsq, cutsq);
|
||||
memoryKK->destroy_kokkos(k_setflag, setflag);
|
||||
memoryKK->destroy_kokkos(k_eatom,eatom);
|
||||
memoryKK->destroy_kokkos(k_vatom,vatom);
|
||||
allocated = 0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void PairMLIAPKokkos<DeviceType>::compute(int eflag, int vflag)
|
||||
{
|
||||
atomKK->sync(Host,F_MASK | ENERGY_MASK | VIRIAL_MASK);
|
||||
atomKK->sync(execution_space,X_MASK | TYPE_MASK );
|
||||
MLIAPDataKokkos<DeviceType> *k_data = (MLIAPDataKokkos<DeviceType>*)(data);
|
||||
|
||||
int is_kokkos_model = (dynamic_cast<MLIAPModelKokkos<DeviceType>*>(model)) != nullptr;
|
||||
int is_kokkos_descriptor = (dynamic_cast<MLIAPDescriptorKokkos<DeviceType>*>(descriptor)) != nullptr;
|
||||
auto model_space = is_kokkos_model ? execution_space : Host;
|
||||
auto descriptor_space = is_kokkos_descriptor? execution_space : Host;
|
||||
|
||||
// consistency checks
|
||||
if (data->ndescriptors != model->ndescriptors)
|
||||
error->all(FLERR, "Incompatible model and descriptor descriptor count");
|
||||
|
||||
if (data->nelements != model->nelements)
|
||||
error->all(FLERR, "Incompatible model and descriptor element count");
|
||||
|
||||
ev_init(eflag, vflag);
|
||||
if (eflag_atom && (int)k_eatom.h_view.extent(0) < maxeatom) {
|
||||
memoryKK->destroy_kokkos(k_eatom,eatom);
|
||||
memoryKK->create_kokkos(k_eatom,eatom,maxeatom,"pair:eatom");
|
||||
}
|
||||
|
||||
if (vflag_atom && (int)k_vatom.h_view.extent(0) < maxeatom) {
|
||||
memoryKK->destroy_kokkos(k_vatom,vatom);
|
||||
memoryKK->create_kokkos(k_vatom,vatom,maxeatom,6,"pair:eatom");
|
||||
}
|
||||
|
||||
data->generate_neighdata(list, eflag, vflag);
|
||||
|
||||
// compute descriptors, if needed
|
||||
if (model->nonlinearflag || eflag) {
|
||||
k_data->sync(descriptor_space, NUMNEIGHS_MASK | IATOMS_MASK | IELEMS_MASK | JATOMS_MASK | JELEMS_MASK | RIJ_MASK );
|
||||
descriptor->compute_descriptors(data);
|
||||
if (!is_kokkos_descriptor)
|
||||
k_data->modified(descriptor_space, DESCRIPTORS_MASK);
|
||||
}
|
||||
|
||||
// compute E_i and beta_i = dE_i/dB_i for all i in list
|
||||
k_data->sync(model_space, IELEMS_MASK | DESCRIPTORS_MASK);
|
||||
model->compute_gradients(data);
|
||||
k_data->modified(model_space, BETAS_MASK);
|
||||
if (eflag_atom)
|
||||
k_data->modified(model_space, EATOMS_MASK);
|
||||
e_tally(data);
|
||||
|
||||
// calculate force contributions beta_i*dB_i/dR_j
|
||||
k_data->sync(descriptor_space, NUMNEIGHS_MASK | IATOMS_MASK | IELEMS_MASK | BETAS_MASK | JATOMS_MASK | JELEMS_MASK | RIJ_MASK );
|
||||
descriptor->compute_forces(data);
|
||||
|
||||
if (evflag) {
|
||||
atomKK->modified(descriptor_space,F_MASK | ENERGY_MASK | VIRIAL_MASK);
|
||||
atomKK->sync(execution_space,F_MASK | ENERGY_MASK | VIRIAL_MASK);
|
||||
} else {
|
||||
atomKK->modified(descriptor_space,F_MASK);
|
||||
atomKK->sync(execution_space,F_MASK);
|
||||
}
|
||||
|
||||
// calculate stress
|
||||
if (vflag_fdotr) {
|
||||
pair_virial_fdotr_compute(this);
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void PairMLIAPKokkos<DeviceType>::allocate()
|
||||
{
|
||||
int n = atom->ntypes;
|
||||
memoryKK->destroy_kokkos(k_map, map);
|
||||
memoryKK->destroy_kokkos(k_cutsq, cutsq);
|
||||
memoryKK->destroy_kokkos(k_setflag, setflag);
|
||||
memoryKK->create_kokkos(k_map, map, n+1, "pair_mliap:map");
|
||||
memoryKK->create_kokkos(k_cutsq, cutsq, n+1, n+1, "pair_mliap:cutsq");
|
||||
memoryKK->create_kokkos(k_setflag, setflag, n+1, n+1, "pair_mliap:setflag");
|
||||
|
||||
// this is for the base class so it doesn't double delete
|
||||
allocated = 1;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void PairMLIAPKokkos<DeviceType>::settings(int narg, char ** arg)
|
||||
{
|
||||
PairMLIAP::settings(narg, arg);
|
||||
int iarg=0;
|
||||
while (iarg < narg) {
|
||||
if (strcmp(arg[iarg],"model") == 0) {
|
||||
if (strcmp(arg[iarg+1],"linear") == 0) {
|
||||
if (iarg+3 > narg) error->all(FLERR,"Illegal pair_style mliap command");
|
||||
delete model;
|
||||
model = new MLIAPModelLinearKokkos<DeviceType>(lmp,arg[iarg+2]);
|
||||
iarg += 3;
|
||||
} else
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"descriptor") == 0) {
|
||||
if (strcmp(arg[iarg+1],"so3") == 0) {
|
||||
if (iarg+3 > narg) error->all(FLERR,"Illegal pair_style mliap command");
|
||||
delete descriptor;
|
||||
descriptor = new MLIAPDescriptorSO3Kokkos<DeviceType>(lmp,arg[iarg+2]);
|
||||
iarg += 3;
|
||||
} else
|
||||
iarg ++;
|
||||
} else
|
||||
iarg++;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void PairMLIAPKokkos<DeviceType>::coeff(int narg, char **arg) {
|
||||
if (narg < 3) error->all(FLERR,"Incorrect args for pair coefficients");
|
||||
if (!allocated) {
|
||||
PairMLIAP::allocate();
|
||||
allocate();
|
||||
}
|
||||
|
||||
char* type1 = arg[0];
|
||||
char* type2 = arg[1];
|
||||
char** elemtypes = &arg[2];
|
||||
|
||||
// insure I,J args are * *
|
||||
|
||||
if (strcmp(type1,"*") != 0 || strcmp(type2,"*") != 0)
|
||||
error->all(FLERR,"Incorrect args for pair coefficients");
|
||||
|
||||
// read args that map atom types to elements
|
||||
// map[i] = which element the Ith atom type is, -1 if not mapped
|
||||
// map[0] is not used
|
||||
|
||||
for (int i = 1; i <= atom->ntypes; i++) {
|
||||
char* elemname = elemtypes[i-1];
|
||||
int jelem;
|
||||
for (jelem = 0; jelem < descriptor->nelements; jelem++)
|
||||
if (strcmp(elemname,descriptor->elements[jelem]) == 0)
|
||||
break;
|
||||
|
||||
if (jelem < descriptor->nelements)
|
||||
map[i] = jelem;
|
||||
else if (strcmp(elemname,"NULL") == 0) map[i] = -1;
|
||||
else error->all(FLERR,"Incorrect args for pair coefficients");
|
||||
}
|
||||
k_map.modify<LMPHostType>();
|
||||
k_map.sync<LMPDeviceType>();
|
||||
|
||||
auto h_cutsq=k_cutsq.template view<LMPHostType>();
|
||||
for (int itype=1; itype <= atom->ntypes; ++itype)
|
||||
for (int jtype=1; jtype <= atom->ntypes; ++jtype)
|
||||
h_cutsq(itype,jtype) = descriptor->cutsq[map[itype]][map[jtype]];
|
||||
k_cutsq.modify<LMPHostType>();
|
||||
k_cutsq.sync<DeviceType>();
|
||||
|
||||
// clear setflag since coeff() called once with I,J = * *
|
||||
|
||||
int n = atom->ntypes;
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = i; j <= n; j++)
|
||||
setflag[i][j] = 0;
|
||||
|
||||
// set setflag i,j for type pairs where both are mapped to elements
|
||||
|
||||
int count = 0;
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = i; j <= n; j++)
|
||||
if (map[i] >= 0 && map[j] >= 0) {
|
||||
setflag[i][j] = 1;
|
||||
count++;
|
||||
}
|
||||
k_setflag.modify<LMPHostType>();
|
||||
k_setflag.sync<LMPDeviceType>();
|
||||
|
||||
if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients");
|
||||
|
||||
// set up model, descriptor, and mliap data structures
|
||||
model->init();
|
||||
descriptor->init();
|
||||
int gradgradflag = -1;
|
||||
delete data;
|
||||
data = new MLIAPDataKokkos<DeviceType>(lmp, gradgradflag, map, model, descriptor, this);
|
||||
data->init();
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
add energies to eng_vdwl and per-atom energy
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void PairMLIAPKokkos<DeviceType>::e_tally(MLIAPData* data)
|
||||
{
|
||||
if (eflag_global) eng_vdwl += data->energy;
|
||||
if (eflag_atom) {
|
||||
MLIAPDataKokkos<DeviceType> *k_data = static_cast<MLIAPDataKokkos<DeviceType>*>(data);
|
||||
k_data->sync(execution_space, IATOMS_MASK | EATOMS_MASK);
|
||||
auto d_iatoms = k_data->k_iatoms.template view<DeviceType>();
|
||||
auto d_eatoms = k_data->k_eatoms.template view<DeviceType>();
|
||||
auto d_eatom = k_eatom.template view<DeviceType>();
|
||||
Kokkos::parallel_for(data->nlistatoms, KOKKOS_LAMBDA (int ii) {
|
||||
d_eatom(d_iatoms(ii)) = d_eatoms(ii);
|
||||
});
|
||||
k_eatom.modify<DeviceType>();
|
||||
// This sync has to be here for the hybrid pair type
|
||||
k_eatom.sync<LMPHostType>();
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
template<class DeviceType>
|
||||
void PairMLIAPKokkos<DeviceType>::init_style()
|
||||
{
|
||||
|
||||
PairMLIAP::init_style();
|
||||
auto request = neighbor->find_request(this);
|
||||
request->set_kokkos_host(std::is_same<DeviceType,LMPHostType>::value &&
|
||||
!std::is_same<DeviceType,LMPDeviceType>::value);
|
||||
request->set_kokkos_device(std::is_same<DeviceType,LMPDeviceType>::value);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
template class PairMLIAPKokkos<LMPDeviceType>;
|
||||
#ifdef LMP_KOKKOS_GPU
|
||||
template class PairMLIAPKokkos<LMPHostType>;
|
||||
#endif
|
||||
}
|
||||
67
src/KOKKOS/pair_mliap_kokkos.h
Normal file
67
src/KOKKOS/pair_mliap_kokkos.h
Normal file
@ -0,0 +1,67 @@
|
||||
/* -*- c++ -*- ----------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
LAMMPS Development team: developers@lammps.org
|
||||
|
||||
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.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Contributing author: Matt Bettencourt (NVIDIA)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef PAIR_CLASS
|
||||
// clang-format off
|
||||
PairStyle(mliap/kk,PairMLIAPKokkos<LMPDeviceType>);
|
||||
PairStyle(mliap/kk/device,PairMLIAPKokkos<LMPDeviceType>);
|
||||
PairStyle(mliap/kk/host,PairMLIAPKokkos<LMPHostType>);
|
||||
// clang-format off
|
||||
#else
|
||||
|
||||
#ifndef LMP_PAIR_MLIAP_KOKKOS_H
|
||||
#define LMP_PAIR_MLIAP_KOKKOS_H
|
||||
|
||||
#include "pair_mliap.h"
|
||||
#include "pair_kokkos.h"
|
||||
#include "kokkos_type.h"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
template<class DeviceType>
|
||||
class PairMLIAPKokkos : public PairMLIAP {
|
||||
public:
|
||||
typedef DeviceType device_type;
|
||||
typedef ArrayTypes<DeviceType> AT;
|
||||
|
||||
PairMLIAPKokkos(class LAMMPS*);
|
||||
~PairMLIAPKokkos();
|
||||
void settings(int narg, char ** arg);
|
||||
void init_style();
|
||||
|
||||
void compute(int, int);
|
||||
void e_tally(MLIAPData* data);
|
||||
|
||||
void allocate();
|
||||
|
||||
void coeff(int narg, char **arg);
|
||||
typename AT::t_x_array_randomread x;
|
||||
typename AT::t_x_array_randomread v;
|
||||
typename AT::t_f_array f;
|
||||
DAT::tdual_int_1d k_map;
|
||||
DAT::tdual_double_2d k_cutsq;
|
||||
DAT::tdual_int_2d k_setflag;
|
||||
DAT::tdual_efloat_1d k_eatom;
|
||||
DAT::tdual_double_2d k_vatom;
|
||||
|
||||
|
||||
friend void pair_virial_fdotr_compute<PairMLIAPKokkos>(PairMLIAPKokkos*);
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@ -26,8 +26,8 @@ class MLIAPData : protected Pointers {
|
||||
~MLIAPData() override;
|
||||
|
||||
void init();
|
||||
void generate_neighdata(class NeighList *, int = 0, int = 0);
|
||||
void grow_neigharrays();
|
||||
virtual void generate_neighdata(class NeighList *, int = 0, int = 0);
|
||||
virtual void grow_neigharrays();
|
||||
double memory_usage();
|
||||
|
||||
int size_array_rows, size_array_cols;
|
||||
@ -77,7 +77,7 @@ class MLIAPData : protected Pointers {
|
||||
int vflag; // indicates if virial is needed
|
||||
class PairMLIAP *pairmliap; // access to pair tally functions
|
||||
|
||||
private:
|
||||
protected:
|
||||
class MLIAPModel *model;
|
||||
class MLIAPDescriptor *descriptor;
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
class MLIAPDescriptor : protected Pointers {
|
||||
class MLIAPDescriptor : virtual protected Pointers {
|
||||
public:
|
||||
MLIAPDescriptor(LAMMPS *);
|
||||
~MLIAPDescriptor() override;
|
||||
|
||||
@ -36,7 +36,7 @@ using namespace LAMMPS_NS;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
MLIAPDescriptorSNAP::MLIAPDescriptorSNAP(LAMMPS *_lmp, char *paramfilename) : MLIAPDescriptor(_lmp)
|
||||
MLIAPDescriptorSNAP::MLIAPDescriptorSNAP(LAMMPS *_lmp, char *paramfilename) : Pointers(_lmp), MLIAPDescriptor(_lmp)
|
||||
{
|
||||
radelem = nullptr;
|
||||
wjelem = nullptr;
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Contributing authors: Byungkyun Kang (University of Nevada, Las Vegas)
|
||||
------------------------------------------------------------------------- */
|
||||
@ -34,7 +35,7 @@ using namespace LAMMPS_NS;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
MLIAPDescriptorSO3::MLIAPDescriptorSO3(LAMMPS *lmp, char *paramfilename) : MLIAPDescriptor(lmp)
|
||||
MLIAPDescriptorSO3::MLIAPDescriptorSO3(LAMMPS *lmp, char *paramfilename) : Pointers(lmp), MLIAPDescriptor(lmp)
|
||||
{
|
||||
radelem = nullptr;
|
||||
wjelem = nullptr;
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
class MLIAPDescriptorSO3 : public MLIAPDescriptor {
|
||||
class MLIAPDescriptorSO3 : public MLIAPDescriptor, virtual protected Pointers {
|
||||
|
||||
public:
|
||||
MLIAPDescriptorSO3(LAMMPS *, char *);
|
||||
|
||||
@ -57,22 +57,17 @@ void MLIAPModelLinear::compute_gradients(MLIAPData* data)
|
||||
for (int ii = 0; ii < data->nlistatoms; ii++) {
|
||||
const int ielem = data->ielems[ii];
|
||||
|
||||
double* coeffi = coeffelem[ielem];
|
||||
double const* coeffi = coeffelem[ielem];
|
||||
for (int icoeff = 0; icoeff < data->ndescriptors; icoeff++)
|
||||
data->betas[ii][icoeff] = coeffi[icoeff+1];
|
||||
|
||||
// add in contributions to global and per-atom energy
|
||||
// this is optional and has no effect on force calculation
|
||||
|
||||
if (data->eflag) {
|
||||
|
||||
// energy of atom I
|
||||
|
||||
double* coeffi = coeffelem[ielem];
|
||||
double etmp = coeffi[0];
|
||||
|
||||
// E_i = beta.B_i
|
||||
|
||||
for (int icoeff = 0; icoeff < data->ndescriptors; icoeff++)
|
||||
etmp += coeffi[icoeff+1]*data->descriptors[ii][icoeff];
|
||||
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
LAMMPS development team: developers@lammps.org
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
LAMMPS development team: developers@lammps.org
|
||||
|
||||
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.
|
||||
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.
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Contributing authors: Byungkyun Kang (University of Nevada, Las Vegas)
|
||||
Contributing authors: Byungkyun Kang (University of Nevada, Las Vegas)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "mliap_so3.h"
|
||||
@ -84,7 +84,6 @@ MLIAP_SO3::MLIAP_SO3(LAMMPS *lmp, double vrcut, int vlmax, int vnmax, double val
|
||||
m_dYlm_i = nullptr;
|
||||
|
||||
m_dplist_r = nullptr;
|
||||
m_dplist_i = nullptr;
|
||||
|
||||
m_dclist_r = nullptr;
|
||||
m_dclist_i = nullptr;
|
||||
@ -145,7 +144,6 @@ MLIAP_SO3::~MLIAP_SO3()
|
||||
memory->destroy(m_dYlm_i);
|
||||
|
||||
memory->destroy(m_dplist_r);
|
||||
memory->destroy(m_dplist_i);
|
||||
|
||||
memory->destroy(m_dclist_r);
|
||||
memory->destroy(m_dclist_i);
|
||||
@ -846,8 +844,6 @@ void MLIAP_SO3::spectrum(int nlocal, int *numneighs, int *jelems, double *wjelem
|
||||
totali = totaln * ncoefs * 3;
|
||||
memory->destroy(m_dplist_r);
|
||||
memory->create(m_dplist_r, totali, "MLIAP_SO3:m_dplist_r");
|
||||
memory->destroy(m_dplist_i);
|
||||
memory->create(m_dplist_i, totali, "MLIAP_SO3:m_dplist_i");
|
||||
alloc_arrays += 2.0 * totali * sizeof(double);
|
||||
|
||||
get_sbes_array(nlocal, numneighs, rij, lmax, rcut, alpha);
|
||||
@ -977,14 +973,11 @@ void MLIAP_SO3::spectrum_dxdr(int nlocal, int *numneighs, int *jelems, double *w
|
||||
totali = totaln * ncoefs * 3;
|
||||
memory->destroy(m_dplist_r);
|
||||
memory->create(m_dplist_r, totali, "MLIAP_SO3:m_dplist_r");
|
||||
memory->destroy(m_dplist_i);
|
||||
memory->create(m_dplist_i, totali, "MLIAP_SO3:m_dplist_i");
|
||||
|
||||
totali = npairs * ncoefs * 3;
|
||||
|
||||
for (int i = 0; i < totali; i++) {
|
||||
m_dplist_r[i] = 0.0;
|
||||
m_dplist_i[i] = 0.0;
|
||||
}
|
||||
|
||||
numps = nmax * (nmax + 1) * (lmax + 1) / 2;
|
||||
|
||||
@ -14,7 +14,6 @@ class MLIAP_SO3 : protected Pointers {
|
||||
~MLIAP_SO3() override;
|
||||
|
||||
void init();
|
||||
|
||||
double memory_usage();
|
||||
|
||||
int ncoeff;
|
||||
@ -46,7 +45,7 @@ class MLIAP_SO3 : protected Pointers {
|
||||
double *m_ulist_r, *m_ulist_i;
|
||||
|
||||
double *m_Ylms_r, *m_Ylms_i, *m_dYlm_r, *m_dYlm_i;
|
||||
double *m_dplist_i, *m_dclist_r, *m_dclist_i, *m_tempdp_r;
|
||||
double *m_dclist_r, *m_dclist_i, *m_tempdp_r;
|
||||
|
||||
public:
|
||||
void spectrum(int nlocal, int *numneighs, int *jelems, double *wjelem, double **rij, int nmax,
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#define LMP_MLIAP_SO3_MATH_H
|
||||
|
||||
#include "math_eigen_impl.h"
|
||||
#include <cmath>
|
||||
|
||||
namespace SO3Math {
|
||||
|
||||
@ -22,7 +23,7 @@ void LUPSolve(int n, double *A, double *B, int *P);
|
||||
using namespace MathEigen;
|
||||
|
||||
typedef Jacobi<double, double *, double **, double const *const *> Jacobi_v2;
|
||||
int SO3Math::jacobin(int n, double const *const *mat, double *eval, double **evec)
|
||||
inline int SO3Math::jacobin(int n, double const *const *mat, double *eval, double **evec)
|
||||
{
|
||||
int *midx = new int[n];
|
||||
double **M = new double *[n];
|
||||
@ -48,7 +49,7 @@ int SO3Math::jacobin(int n, double const *const *mat, double *eval, double **eve
|
||||
return ierror;
|
||||
}
|
||||
|
||||
int SO3Math::invert_matrix(int n, double *A, double *Ainv)
|
||||
inline int SO3Math::invert_matrix(int n, double *A, double *Ainv)
|
||||
{
|
||||
|
||||
int i, j;
|
||||
@ -85,7 +86,7 @@ int SO3Math::invert_matrix(int n, double *A, double *Ainv)
|
||||
return rv;
|
||||
}
|
||||
|
||||
int SO3Math::LUPdecompose(int n, double dtol, double *A, int *P)
|
||||
inline int SO3Math::LUPdecompose(int n, double dtol, double *A, int *P)
|
||||
{
|
||||
int i, j, k, maxi;
|
||||
double maxA, Atemp;
|
||||
@ -148,7 +149,7 @@ int SO3Math::LUPdecompose(int n, double dtol, double *A, int *P)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SO3Math::LUPSolve(int n, double *A, double *B, int *P)
|
||||
inline void SO3Math::LUPSolve(int n, double *A, double *B, int *P)
|
||||
{
|
||||
int i, j;
|
||||
double dtemp;
|
||||
|
||||
@ -33,7 +33,7 @@ using namespace LAMMPS_NS;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
MLIAPDummyDescriptor::MLIAPDummyDescriptor(LAMMPS *_lmp) : MLIAPDescriptor(_lmp) {}
|
||||
MLIAPDummyDescriptor::MLIAPDummyDescriptor(LAMMPS *_lmp) : Pointers(_lmp), MLIAPDescriptor(_lmp) {}
|
||||
|
||||
MLIAPDummyDescriptor::~MLIAPDummyDescriptor()
|
||||
{
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
class MLIAPDummyDescriptor : public MLIAPDescriptor {
|
||||
class MLIAPDummyDescriptor : public MLIAPDescriptor, virtual protected Pointers {
|
||||
public:
|
||||
MLIAPDummyDescriptor(LAMMPS *);
|
||||
~MLIAPDummyDescriptor() override;
|
||||
|
||||
@ -135,10 +135,10 @@ void PairMLIAP::settings(int narg, char ** arg)
|
||||
|
||||
// set flags for required keywords
|
||||
|
||||
int modelflag = 0;
|
||||
int descriptorflag = 0;
|
||||
delete model;
|
||||
model = nullptr;
|
||||
delete descriptor;
|
||||
descriptor = nullptr;
|
||||
|
||||
// process keywords
|
||||
|
||||
@ -147,7 +147,7 @@ void PairMLIAP::settings(int narg, char ** arg)
|
||||
while (iarg < narg) {
|
||||
if (strcmp(arg[iarg],"model") == 0) {
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "pair_style mliap model", error);
|
||||
if (modelflag) error->all(FLERR,"Illegal multiple pair_style mliap model definition");
|
||||
if (model != nullptr) error->all(FLERR,"Illegal multiple pair_style mliap model definition");
|
||||
if (strcmp(arg[iarg+1],"linear") == 0) {
|
||||
if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "pair_style mliap model linear", error);
|
||||
model = new MLIAPModelLinear(lmp,arg[iarg+2]);
|
||||
@ -169,10 +169,9 @@ void PairMLIAP::settings(int narg, char ** arg)
|
||||
error->all(FLERR,"Using pair_style mliap model mliappy requires ML-IAP with python support");
|
||||
#endif
|
||||
} else error->all(FLERR,"Unknown pair_style mliap model keyword: {}", arg[iarg]);
|
||||
modelflag = 1;
|
||||
} else if (strcmp(arg[iarg],"descriptor") == 0) {
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "pair_style mliap descriptor", error);
|
||||
if (descriptorflag) error->all(FLERR,"Illegal multiple pair_style mliap descriptor definition");
|
||||
if (descriptor != nullptr) error->all(FLERR,"Illegal multiple pair_style mliap descriptor definition");
|
||||
if (strcmp(arg[iarg+1],"sna") == 0) {
|
||||
if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "pair_style mliap descriptor sna", error);
|
||||
descriptor = new MLIAPDescriptorSNAP(lmp,arg[iarg+2]);
|
||||
@ -183,11 +182,10 @@ void PairMLIAP::settings(int narg, char ** arg)
|
||||
iarg += 3;
|
||||
|
||||
} else error->all(FLERR,"Illegal pair_style mliap command");
|
||||
descriptorflag = 1;
|
||||
} else if (strcmp(arg[iarg], "unified") == 0) {
|
||||
#ifdef MLIAP_PYTHON
|
||||
if (modelflag) error->all(FLERR,"Illegal multiple pair_style mliap model definitions");
|
||||
if (descriptorflag) error->all(FLERR,"Illegal multiple pair_style mliap descriptor definitions");
|
||||
if (model != nullptr) error->all(FLERR,"Illegal multiple pair_style mliap model definitions");
|
||||
if (descriptor != nullptr) error->all(FLERR,"Illegal multiple pair_style mliap descriptor definitions");
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "pair_style mliap unified", error);
|
||||
MLIAPBuildUnified_t build = build_unified(arg[iarg+1], data, lmp);
|
||||
if (iarg+3 > narg) {
|
||||
@ -199,8 +197,6 @@ void PairMLIAP::settings(int narg, char ** arg)
|
||||
iarg += 3;
|
||||
model = build.model;
|
||||
descriptor = build.descriptor;
|
||||
modelflag = 1;
|
||||
descriptorflag = 1;
|
||||
#else
|
||||
error->all(FLERR,"Using pair_style mliap unified requires ML-IAP with python support");
|
||||
#endif
|
||||
@ -208,7 +204,7 @@ void PairMLIAP::settings(int narg, char ** arg)
|
||||
error->all(FLERR,"Unknown pair_style mliap keyword: {}", arg[iarg]);
|
||||
}
|
||||
|
||||
if (modelflag == 0 || descriptorflag == 0)
|
||||
if (model == nullptr || descriptor == nullptr)
|
||||
error->all(FLERR,"Incomplete pair_style mliap setup: need model and descriptor, or unified");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user