Skip to content

Commit 0f2b879

Browse files
committed
Store and resize to avoid particle/linked cell reallocation
1 parent 9b58ea3 commit 0f2b879

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

src/ParticleActions.cxx

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,27 @@ float FGridEvalPoly(float r2)
2727
namespace HACCabana
2828
{
2929

30-
ParticleActions::ParticleActions() {};
30+
ParticleActions::ParticleActions()
31+
{
32+
aosoa_device = aosoa_device_type("aosoa_device", 0);
33+
};
3134

32-
ParticleActions::ParticleActions(Particles *P_) : P(P_)
35+
ParticleActions::ParticleActions(Particles *P_, const float cm_size, const float min_pos, const float max_pos ) : P(P_)
3336
{
34-
;
37+
aosoa_device = aosoa_device_type("aosoa_device", P->num_p);
38+
auto position = Cabana::slice<HACCabana::Particles::Fields::Position>(aosoa_device, "position");
39+
40+
// create the cell list on the GPU
41+
// NOTE: fuzz particles (outside of overload) are not included
42+
float dx = cm_size;
43+
float x_min = min_pos;
44+
float x_max = max_pos;
45+
46+
float grid_delta[3] = {dx, dx, dx};
47+
float grid_min[3] = {x_min, x_min, x_min};
48+
float grid_max[3] = {x_max, x_max, x_max};
49+
50+
cell_list = neighbor_type(position, P->begin, P->end, grid_delta, grid_min, grid_max);
3551
};
3652

3753
ParticleActions::~ParticleActions()
@@ -136,25 +152,14 @@ void ParticleActions::updateVel(\
136152
Kokkos::fence();
137153
}
138154

139-
void ParticleActions::subCycle(TimeStepper &ts, const int nsub, const float gpscal, const float rmax2, const float rsm2,
140-
const float cm_size, const float min_pos, const float max_pos)
155+
void ParticleActions::subCycle(TimeStepper &ts, const int nsub, const float gpscal, const float rmax2, const float rsm2)
141156
{
142157
// copy particles to GPU
143-
Cabana::AoSoA<HACCabana::Particles::data_types, device_type, VECTOR_LENGTH> aosoa_device("aosoa_device", P->num_p);
158+
aosoa_device.resize(P->num_p);
144159
Cabana::deep_copy(aosoa_device, P->aosoa_host);
145160

146-
// create the cell list on the GPU
147-
// NOTE: fuzz particles (outside of overload) are not included
148-
float dx = cm_size;
149-
float x_min = min_pos;
150-
float x_max = max_pos;
151-
152-
float grid_delta[3] = {dx, dx, dx};
153-
float grid_min[3] = {x_min, x_min, x_min};
154-
float grid_max[3] = {x_max, x_max, x_max};
155-
156161
auto position = Cabana::slice<HACCabana::Particles::Fields::Position>(aosoa_device, "position");
157-
Cabana::LinkedCellList<device_type> cell_list(position, P->begin, P->end, grid_delta, grid_min, grid_max);
162+
cell_list.build(position);
158163
Cabana::permute(cell_list, aosoa_device);
159164
Kokkos::fence();
160165

src/ParticleActions.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,23 @@ namespace HACCabana
1818
{
1919
private:
2020
Particles *P;
21+
aosoa_device_type aosoa_device;
2122

2223
public:
2324
using device_exec = Kokkos::DefaultExecutionSpace::execution_space;
2425
using device_mem = Kokkos::DefaultExecutionSpace::memory_space;
2526
using device_type = Kokkos::Device<device_exec, device_mem>;
27+
using aosoa_device_type = Cabana::AoSoA<typename Particles::data_types, device_type, VECTOR_LENGTH>;
28+
using neighbor_type = Cabana::LinkedCellList<device_type>;
2629
//using device_scratch = Kokkos::ScratchMemorySpace<device_exec>;
2730

31+
neighbor_type cell_list;
32+
2833
ParticleActions();
29-
ParticleActions(Particles *P_);
34+
ParticleActions(Particles *P_, const float cm_size, const float min_pos, const float max_pos);
3035
~ParticleActions();
3136
void setParticles(Particles *P_);
32-
void subCycle(TimeStepper &ts, const int nsub, const float gpscal, const float rmax2, const float rsm2,\
33-
const float cm_size, const float min_pos, const float max_pos);
37+
void subCycle(TimeStepper &ts, const int nsub, const float gpscal, const float rmax2, const float rsm2);
3438
void updatePos(Cabana::AoSoA<HACCabana::Particles::data_types, device_type, VECTOR_LENGTH> aosoa_device,\
3539
float prefactor);
3640
void updateVel(Cabana::AoSoA<HACCabana::Particles::data_types, device_type, VECTOR_LENGTH> aosoa_device,\

src/driver_gpu.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ int main( int argc, char* argv[] )
152152
P.reorder(min_alive_pos, max_alive_pos); // TODO:assumes local extent equals the global extent
153153
cout << "\t" << P.end-P.begin << " particles in [" << min_alive_pos << "," << max_alive_pos << "]" << endl;
154154

155-
HACCabana::ParticleActions PA(&P);
156-
PA.subCycle(ts, Params.nsub, Params.gpscal, Params.rmax*Params.rmax, Params.rsm*Params.rsm, Params.cm_size, Params.oL, Params.rL+Params.oL);
155+
HACCabana::ParticleActions PA(&P, Params.cm_size, Params.oL, Params.rL+Params.oL);
156+
PA.subCycle(ts, Params.nsub, Params.gpscal, Params.rmax*Params.rmax, Params.rsm*Params.rsm);
157157

158158
// verify against the answer from the simulation
159159
// --------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)