Skip to content

Commit 700f2c8

Browse files
committed
Revert "get rid of single_bond_grad, attempted transpose (unhelpful), added off-diagonal setflag, need cleaning"
This reverts commit 25e94b3.
1 parent 25e94b3 commit 700f2c8

File tree

3 files changed

+35
-121
lines changed

3 files changed

+35
-121
lines changed

lammps_plugins/kokkos/pair_flare_kokkos.cpp

Lines changed: 33 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ void PairFLAREKokkos<DeviceType>::compute(int eflag_in, int vflag_in)
193193
+ 2 // evdwls, B2_norm2s
194194
+ 0.5 // numneigh_short
195195
+ max_neighs * (
196-
n_max*4 // g and gT
197-
+ n_harmonics*4 // Y and YT
198-
//+ n_max*n_harmonics*3 // single_bond_grad
196+
n_max*4 // g
197+
+ n_harmonics*4 // Y
198+
+ n_max*n_harmonics*3 // single_bond_grad
199199
+ 3 // partial_forces
200200
+ 0.5 // neighs_short
201201
)
@@ -258,12 +258,8 @@ void PairFLAREKokkos<DeviceType>::compute(int eflag_in, int vflag_in)
258258
g_ra = g;
259259
Y_ra = Y;
260260

261-
//gT = View4D(); YT = View4D();
262-
//gT = View4D(Kokkos::ViewAllocateWithoutInitializing("FLARE: gT"), batch_size, max_neighs, 4, n_max);
263-
//YT = View4D(Kokkos::ViewAllocateWithoutInitializing("FLARE: YT"), batch_size, max_neighs, 4, n_harmonics);
264-
265-
// single_bond_grad = View5D();
266-
// single_bond_grad = View5D(Kokkos::ViewAllocateWithoutInitializing("FLARE: single_bond_grad"), batch_size, max_neighs, 3, n_max, n_harmonics);
261+
single_bond_grad = View5D();
262+
single_bond_grad = View5D(Kokkos::ViewAllocateWithoutInitializing("FLARE: single_bond_grad"), batch_size, max_neighs, 3, n_max, n_harmonics);
267263
partial_forces = View3D();
268264
partial_forces = View3D(Kokkos::ViewAllocateWithoutInitializing("FLARE: partial forces"), batch_size, max_neighs, 3);
269265

@@ -281,25 +277,14 @@ void PairFLAREKokkos<DeviceType>::compute(int eflag_in, int vflag_in)
281277
*this
282278
);
283279

284-
// transpose R and Y for later use
285-
int g_size = ScratchView3D::shmem_size(n_max, 4, max_neighs);
286-
int Y_size = ScratchView3D::shmem_size(n_harmonics, 4, max_neighs);
287-
/*
288-
auto transpolicy = Kokkos::TeamPolicy<DeviceType, TagTransposeRY>(batch_size, SINGLE_BOND_TEAM_SIZE, vector_length).set_scratch_size(
289-
0, Kokkos::PerTeam(g_size + Y_size));
290-
Kokkos::parallel_for("FLARE: transpose R and Y",
291-
transpolicy,
292-
*this
293-
);
294-
*/
295-
296280
// compute single bond and its gradient
297281
// dnlm, dnlmj
298-
g_size = ScratchView1D::shmem_size(n_max);
299-
Y_size = ScratchView1D::shmem_size(n_harmonics);
282+
int g_size = ScratchView2D::shmem_size(n_max, 4);
283+
int Y_size = ScratchView2D::shmem_size(n_harmonics, 4);
300284
auto policy = Kokkos::TeamPolicy<DeviceType, TagSingleBond>(batch_size, SINGLE_BOND_TEAM_SIZE, vector_length).set_scratch_size(
301285
0, Kokkos::PerThread(g_size + Y_size));
302286
Kokkos::deep_copy(single_bond, 0.0);
287+
//Kokkos::deep_copy(single_bond_grad, 0.0);
303288
Kokkos::parallel_for("FLARE: single bond",
304289
policy,
305290
*this
@@ -343,15 +328,11 @@ void PairFLAREKokkos<DeviceType>::compute(int eflag_in, int vflag_in)
343328
);
344329

345330
// compute partial forces
346-
g_size = ScratchView2D::shmem_size(4, n_max);
347-
Y_size = ScratchView2D::shmem_size(4, n_harmonics);
348331
int u_size = ScratchView2D::shmem_size(n_radial, n_harmonics);
349332
Kokkos::parallel_for("FLARE: partial forces",
350333
Kokkos::TeamPolicy<DeviceType, TagF>(batch_size, TEAM_SIZE, vector_length).set_scratch_size(
351334
0, Kokkos::PerTeam(u_size)
352-
)/*.set_scratch_size(
353-
0, Kokkos::PerThread(g_size + Y_size)
354-
)*/,
335+
),
355336
*this
356337
);
357338

@@ -430,113 +411,63 @@ void PairFLAREKokkos<DeviceType>::operator()(const int ii, const int jj) const {
430411

431412
template <class DeviceType>
432413
KOKKOS_INLINE_FUNCTION
433-
void PairFLAREKokkos<DeviceType>::operator()(TagTransposeRY, const MemberType team_member) const{
414+
void PairFLAREKokkos<DeviceType>::operator()(TagSingleBond, const MemberType team_member) const{
434415
int ii = team_member.league_rank();
435416

436417
const int jnum = d_numneigh_short(ii);
437418

438-
ScratchView3D gscratch(team_member.team_scratch(0), 4, n_max, max_neighs);
439-
ScratchView3D Yscratch(team_member.team_scratch(0), 4, n_harmonics, max_neighs);
419+
ScratchView2D gscratch(team_member.thread_scratch(0), 4, n_max);
420+
ScratchView2D Yscratch(team_member.thread_scratch(0), 4, n_harmonics);
440421

422+
Kokkos::parallel_for(Kokkos::TeamThreadRange(team_member, jnum), [&] (int jj){
441423

442-
Kokkos::parallel_for(Kokkos::TeamThreadRange(team_member, 4*n_max), [&] (int nc){
443-
Kokkos::parallel_for(Kokkos::ThreadVectorRange(team_member, jnum), [&] (int jj){
444-
//int n = nc / 4;
445-
//int c = nc -4*n;
446-
int c = nc / n_max;
447-
int n = nc - c*n_max;
448-
gscratch(c, n, jj) = g(ii, jj, n, c);
449-
});
450-
});
451-
Kokkos::parallel_for(Kokkos::TeamThreadRange(team_member, 4*n_harmonics), [&] (int lmc){
452-
Kokkos::parallel_for(Kokkos::ThreadVectorRange(team_member, jnum), [&] (int jj){
453-
//int lm = lmc / 4;
454-
//int c = lmc - 4 * lm;
455-
int c = lmc / n_harmonics;
456-
int lm = lmc - c*n_harmonics;
457-
Yscratch(c, lm, jj) = Y(ii, jj, lm, c);
458-
});
459-
});
460-
team_member.team_barrier();
424+
int j = d_neighbors_short(ii,jj);
425+
j &= NEIGHMASK;
426+
int s = type[j] - 1;
461427

462-
Kokkos::parallel_for(Kokkos::TeamThreadRange(team_member, jnum), [&] (int jj){
463428

464429
Kokkos::parallel_for(Kokkos::ThreadVectorRange(team_member, 4*n_max), [&] (int nc){
465430
//int n = nc / 4;
466431
//int c = nc -4*n;
467432
int c = nc / n_max;
468433
int n = nc - c*n_max;
469-
gT(ii, jj, c, n) = gscratch(c, n, jj);
434+
gscratch(c, n) = g_ra(ii, jj, n, c);
470435
});
471436
Kokkos::parallel_for(Kokkos::ThreadVectorRange(team_member, 4*n_harmonics), [&] (int lmc){
472437
//int lm = lmc / 4;
473438
//int c = lmc - 4 * lm;
474439
int c = lmc / n_harmonics;
475440
int lm = lmc - c*n_harmonics;
476-
YT(ii, jj, c, lm) = Yscratch(c, lm, jj);
477-
});
478-
});
479-
}
480-
481-
template <class DeviceType>
482-
KOKKOS_INLINE_FUNCTION
483-
void PairFLAREKokkos<DeviceType>::operator()(TagSingleBond, const MemberType team_member) const{
484-
int ii = team_member.league_rank();
485-
486-
const int jnum = d_numneigh_short(ii);
487-
488-
ScratchView1D gscratch(team_member.thread_scratch(0), n_max);
489-
ScratchView1D Yscratch(team_member.thread_scratch(0), n_harmonics);
490-
491-
Kokkos::parallel_for(Kokkos::TeamThreadRange(team_member, jnum), [&] (int jj){
492-
493-
int j = d_neighbors_short(ii,jj);
494-
j &= NEIGHMASK;
495-
int s = type[j] - 1;
496-
497-
498-
Kokkos::parallel_for(Kokkos::ThreadVectorRange(team_member, n_max), [&] (int n){
499-
//int n = nc / 4;
500-
//int c = nc -4*n;
501-
// int c = nc / n_max;
502-
// int n = nc - c*n_max;
503-
gscratch(n) = g(ii, jj, n, 0);
504-
});
505-
Kokkos::parallel_for(Kokkos::ThreadVectorRange(team_member, n_harmonics), [&] (int lm){
506-
//int lm = lmc / 4;
507-
//int c = lmc - 4 * lm;
508-
// int c = lmc / n_harmonics;
509-
// int lm = lmc - c*n_harmonics;
510-
Yscratch(lm) = Y(ii, jj, lm, 0);
441+
Yscratch(c, lm) = Y_ra(ii, jj, lm, c);
511442
});
512443

513444
Kokkos::parallel_for(Kokkos::ThreadVectorRange(team_member, n_max*n_harmonics), [&] (int nlm){
514445
int n = nlm / n_harmonics;
515446
int lm = nlm - n_harmonics*n;
516447

517448
int radial_index = s*n_max + n;
518-
double g_val = gscratch(n);
519-
// double gx_val = gscratch(1,n);
520-
// double gy_val = gscratch(2,n);
521-
// double gz_val = gscratch(3,n);
449+
double g_val = gscratch(0,n);
450+
double gx_val = gscratch(1,n);
451+
double gy_val = gscratch(2,n);
452+
double gz_val = gscratch(3,n);
522453

523454

524-
double h_val = Yscratch(lm);
525-
// double hx_val = Yscratch(1,lm);
526-
// double hy_val = Yscratch(2,lm);
527-
// double hz_val = Yscratch(3,lm);
455+
double h_val = Yscratch(0,lm);
456+
double hx_val = Yscratch(1,lm);
457+
double hy_val = Yscratch(2,lm);
458+
double hz_val = Yscratch(3,lm);
528459

529460
double bond = g_val * h_val;
530-
// double bond_x = gx_val * h_val + g_val * hx_val;
531-
// double bond_y = gy_val * h_val + g_val * hy_val;
532-
// double bond_z = gz_val * h_val + g_val * hz_val;
461+
double bond_x = gx_val * h_val + g_val * hx_val;
462+
double bond_y = gy_val * h_val + g_val * hy_val;
463+
double bond_z = gz_val * h_val + g_val * hz_val;
533464

534465
// Update single bond basis arrays.
535466
Kokkos::atomic_add(&single_bond(ii, radial_index, lm),bond); // TODO: bad?
536467

537-
// single_bond_grad(ii,jj,0,n,lm) = bond_x;
538-
// single_bond_grad(ii,jj,1,n,lm) = bond_y;
539-
// single_bond_grad(ii,jj,2,n,lm) = bond_z;
468+
single_bond_grad(ii,jj,0,n,lm) = bond_x;
469+
single_bond_grad(ii,jj,1,n,lm) = bond_y;
470+
single_bond_grad(ii,jj,2,n,lm) = bond_z;
540471
});
541472
});
542473
}
@@ -659,9 +590,6 @@ void PairFLAREKokkos<DeviceType>::operator()(TagF, const MemberType team_member)
659590
const int i = ilist_curr_type[ii+startatom];
660591
const int jnum = d_numneigh_short(ii);
661592

662-
//ScratchView2D gscratch(team_member.thread_scratch(0), 4, n_max);
663-
//ScratchView2D Yscratch(team_member.thread_scratch(0), 4, n_harmonics);
664-
665593
ScratchView2D uscratch(team_member.team_scratch(0), n_radial, n_harmonics);
666594
Kokkos::parallel_for(Kokkos::TeamVectorRange(team_member, n_bond), [&] (int nlm){
667595
int n = nlm / n_harmonics;
@@ -683,16 +611,7 @@ void PairFLAREKokkos<DeviceType>::operator()(TagF, const MemberType team_member)
683611
int n = nlm / n_harmonics;
684612
int lm = nlm - n*n_harmonics;
685613
int radial_index = s*n_max + n;
686-
687-
double gval = g(ii, jj, n, 0);
688-
double gg = g(ii, jj, n, c+1);
689-
690-
double Yval = Y(ii, jj, lm, 0);
691-
double Yg = Y(ii, jj, lm, c+1);
692-
693-
tmp += (gg*Yval + gval*Yg) * uscratch(radial_index, lm);
694-
695-
// tmp += single_bond_grad(ii, jj, c, n, lm)*uscratch(radial_index, lm);
614+
tmp += single_bond_grad(ii, jj, c, n, lm)*uscratch(radial_index, lm);
696615
}, tmp);
697616
partial_forces(ii,jj,c) = tmp;
698617
});

lammps_plugins/kokkos/pair_flare_kokkos.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ struct Tagw{};
3535
struct Tagu{};
3636
struct TagF{};
3737
struct TagStoreF{};
38-
struct TagTransposeRY{};
3938

4039
namespace LAMMPS_NS {
4140

@@ -58,9 +57,6 @@ class PairFLAREKokkos : public PairFLARE {
5857
KOKKOS_INLINE_FUNCTION
5958
void operator()(TagFindCurrType, const int) const;
6059

61-
KOKKOS_INLINE_FUNCTION
62-
void operator()(TagTransposeRY, const MemberType) const;
63-
6460
KOKKOS_INLINE_FUNCTION
6561
void operator()(TagSingleBond, const MemberType) const;
6662

@@ -140,7 +136,6 @@ class PairFLAREKokkos : public PairFLARE {
140136
View3D beta, single_bond, u, partial_forces;
141137
gYView4D g, Y;
142138
gYView4DRA g_ra, Y_ra;
143-
View4D gT, YT;
144139
View5D single_bond_grad;
145140

146141
int B2_chunk_size;

lammps_plugins/pair_flare.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ void PairFLARE::allocate() {
195195

196196
// Set the diagonal of setflag to 1 (otherwise pair.cpp will throw an error)
197197
for (int i = 1; i <= n; i++)
198-
for(int j = 1; j <= n; j++)
199-
setflag[i][j] = 1;
198+
setflag[i][i] = 1;
200199
}
201200

202201
/* ----------------------------------------------------------------------
@@ -211,6 +210,7 @@ void PairFLARE::settings(int narg, char ** /*arg*/) {
211210

212211
/* ----------------------------------------------------------------------
213212
set coeffs for one or more type pairs
213+
read DYNAMO funcfl file
214214
------------------------------------------------------------------------- */
215215

216216
void PairFLARE::coeff(int narg, char **arg) {

0 commit comments

Comments
 (0)