Skip to content

Commit dbffc34

Browse files
committed
Fix: Pinned Allocators First
They are used in methods that copy from device to host and thus need to be known first, before other allocator flavors.
1 parent ee6537d commit dbffc34

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

src/Particle/ArrayOfStructs.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void make_ArrayOfStructs(py::module &m, std::string allocstr)
137137
.def("__getitem__", [](AOSType &aos, int const v){ return aos[v]; }, py::return_value_policy::reference)
138138

139139
.def("to_host", [](AOSType const & aos) {
140-
ArrayOfStructs<T_ParticleType, std::allocator> h_data;
140+
ArrayOfStructs<T_ParticleType, amrex::PinnedArenaAllocator> h_data;
141141
h_data.resize(aos.size());
142142
//py::array_t<T_ParticleType> h_data(aos.size());
143143
amrex::Gpu::copy(amrex::Gpu::deviceToHost,
@@ -158,6 +158,9 @@ void make_ArrayOfStructs(py::module &m)
158158
// AMReX legacy AoS position + id/cpu particle ype
159159
using ParticleType = Particle<NReal, NInt>;
160160

161+
// first, because used as copy target in methods in containers with other allocators
162+
make_ArrayOfStructs<ParticleType, amrex::PinnedArenaAllocator> (m, "pinned");
163+
161164
// see Src/Base/AMReX_GpuContainers.H
162165
// !AMREX_USE_GPU: DefaultAllocator = std::allocator
163166
// AMREX_USE_GPU: DefaultAllocator = amrex::ArenaAllocator
@@ -173,7 +176,6 @@ void make_ArrayOfStructs(py::module &m)
173176
make_ArrayOfStructs<ParticleType, amrex::ArenaAllocator> (m, "arena");
174177
#endif
175178
// end work-around
176-
make_ArrayOfStructs<ParticleType, amrex::PinnedArenaAllocator> (m, "pinned");
177179
#ifdef AMREX_USE_GPU
178180
make_ArrayOfStructs<ParticleType, amrex::DeviceArenaAllocator> (m, "device");
179181
make_ArrayOfStructs<ParticleType, amrex::ManagedArenaAllocator> (m, "managed");

src/Particle/ParticleContainer.H

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ void make_ParticleContainer_and_Iterators (py::module &m)
394394
if constexpr (!T_ParticleType::is_soa_particle)
395395
make_ParticleInitData<T_ParticleType, T_NArrayReal, T_NArrayInt>(m);
396396

397+
// first, because used as copy target in methods in containers with other allocators
398+
make_ParticleContainer_and_Iterators<T_ParticleType, T_NArrayReal, T_NArrayInt,
399+
amrex::PinnedArenaAllocator>(m, "pinned");
400+
397401
// see Src/Base/AMReX_GpuContainers.H
398402
// !AMREX_USE_GPU: DefaultAllocator = std::allocator
399403
// AMREX_USE_GPU: DefaultAllocator = amrex::ArenaAllocator
@@ -415,8 +419,6 @@ void make_ParticleContainer_and_Iterators (py::module &m)
415419
amrex::ArenaAllocator>(m, "arena");
416420
#endif
417421
// end work-around
418-
make_ParticleContainer_and_Iterators<T_ParticleType, T_NArrayReal, T_NArrayInt,
419-
amrex::PinnedArenaAllocator>(m, "pinned");
420422
#ifdef AMREX_USE_GPU
421423
make_ParticleContainer_and_Iterators<T_ParticleType, T_NArrayReal, T_NArrayInt,
422424
amrex::DeviceArenaAllocator>(m, "device");

src/Particle/ParticleTile.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ void make_ParticleTile(py::module &m)
143143
make_ParticleTileData<T_ParticleType, NArrayReal, NArrayInt>(m);
144144
}
145145

146+
// first, because used as copy target in methods in containers with other allocators
147+
make_ParticleTile<T_ParticleType, NArrayReal, NArrayInt,
148+
amrex::PinnedArenaAllocator>(m, "pinned");
149+
146150
// see Src/Base/AMReX_GpuContainers.H
147151
// !AMREX_USE_GPU: DefaultAllocator = std::allocator
148152
// AMREX_USE_GPU: DefaultAllocator = amrex::ArenaAllocator
@@ -164,8 +168,6 @@ void make_ParticleTile(py::module &m)
164168
amrex::ArenaAllocator>(m, "arena");
165169
#endif
166170
// end work-around
167-
make_ParticleTile<T_ParticleType, NArrayReal, NArrayInt,
168-
amrex::PinnedArenaAllocator>(m, "pinned");
169171
#ifdef AMREX_USE_GPU
170172
make_ParticleTile<T_ParticleType, NArrayReal, NArrayInt,
171173
amrex::DeviceArenaAllocator>(m, "device");

src/Particle/StructOfArrays.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ void make_StructOfArrays(py::module &m, std::string allocstr)
6262
template <int NReal, int NInt>
6363
void make_StructOfArrays(py::module &m)
6464
{
65+
// first, because used as copy target in methods in containers with other allocators
66+
make_StructOfArrays<NReal, NInt, amrex::PinnedArenaAllocator>(m, "pinned");
67+
6568
// see Src/Base/AMReX_GpuContainers.H
6669
// !AMREX_USE_GPU: DefaultAllocator = std::allocator
6770
// AMREX_USE_GPU: DefaultAllocator = amrex::ArenaAllocator
@@ -77,7 +80,6 @@ void make_StructOfArrays(py::module &m)
7780
make_StructOfArrays<NReal, NInt, amrex::ArenaAllocator>(m, "arena");
7881
#endif
7982
// end work-around
80-
make_StructOfArrays<NReal, NInt, amrex::PinnedArenaAllocator>(m, "pinned");
8183
#ifdef AMREX_USE_GPU
8284
make_StructOfArrays<NReal, NInt, amrex::DeviceArenaAllocator>(m, "device");
8385
make_StructOfArrays<NReal, NInt, amrex::ManagedArenaAllocator>(m, "managed");

0 commit comments

Comments
 (0)