Skip to content

Commit

Permalink
Fix: Pinned Allocators First
Browse files Browse the repository at this point in the history
They are used in methods that copy from device to host and thus
need to be known first, before other allocator flavors.
  • Loading branch information
ax3l committed Oct 19, 2023
1 parent ee6537d commit dbffc34
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/Particle/ArrayOfStructs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void make_ArrayOfStructs(py::module &m, std::string allocstr)
.def("__getitem__", [](AOSType &aos, int const v){ return aos[v]; }, py::return_value_policy::reference)

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

// first, because used as copy target in methods in containers with other allocators
make_ArrayOfStructs<ParticleType, amrex::PinnedArenaAllocator> (m, "pinned");

// see Src/Base/AMReX_GpuContainers.H
// !AMREX_USE_GPU: DefaultAllocator = std::allocator
// AMREX_USE_GPU: DefaultAllocator = amrex::ArenaAllocator
Expand All @@ -173,7 +176,6 @@ void make_ArrayOfStructs(py::module &m)
make_ArrayOfStructs<ParticleType, amrex::ArenaAllocator> (m, "arena");
#endif
// end work-around
make_ArrayOfStructs<ParticleType, amrex::PinnedArenaAllocator> (m, "pinned");
#ifdef AMREX_USE_GPU
make_ArrayOfStructs<ParticleType, amrex::DeviceArenaAllocator> (m, "device");
make_ArrayOfStructs<ParticleType, amrex::ManagedArenaAllocator> (m, "managed");
Expand Down
6 changes: 4 additions & 2 deletions src/Particle/ParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ void make_ParticleContainer_and_Iterators (py::module &m)
if constexpr (!T_ParticleType::is_soa_particle)
make_ParticleInitData<T_ParticleType, T_NArrayReal, T_NArrayInt>(m);

// first, because used as copy target in methods in containers with other allocators
make_ParticleContainer_and_Iterators<T_ParticleType, T_NArrayReal, T_NArrayInt,
amrex::PinnedArenaAllocator>(m, "pinned");

// see Src/Base/AMReX_GpuContainers.H
// !AMREX_USE_GPU: DefaultAllocator = std::allocator
// AMREX_USE_GPU: DefaultAllocator = amrex::ArenaAllocator
Expand All @@ -415,8 +419,6 @@ void make_ParticleContainer_and_Iterators (py::module &m)
amrex::ArenaAllocator>(m, "arena");
#endif
// end work-around
make_ParticleContainer_and_Iterators<T_ParticleType, T_NArrayReal, T_NArrayInt,
amrex::PinnedArenaAllocator>(m, "pinned");
#ifdef AMREX_USE_GPU
make_ParticleContainer_and_Iterators<T_ParticleType, T_NArrayReal, T_NArrayInt,
amrex::DeviceArenaAllocator>(m, "device");
Expand Down
6 changes: 4 additions & 2 deletions src/Particle/ParticleTile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ void make_ParticleTile(py::module &m)
make_ParticleTileData<T_ParticleType, NArrayReal, NArrayInt>(m);
}

// first, because used as copy target in methods in containers with other allocators
make_ParticleTile<T_ParticleType, NArrayReal, NArrayInt,
amrex::PinnedArenaAllocator>(m, "pinned");

// see Src/Base/AMReX_GpuContainers.H
// !AMREX_USE_GPU: DefaultAllocator = std::allocator
// AMREX_USE_GPU: DefaultAllocator = amrex::ArenaAllocator
Expand All @@ -164,8 +168,6 @@ void make_ParticleTile(py::module &m)
amrex::ArenaAllocator>(m, "arena");
#endif
// end work-around
make_ParticleTile<T_ParticleType, NArrayReal, NArrayInt,
amrex::PinnedArenaAllocator>(m, "pinned");
#ifdef AMREX_USE_GPU
make_ParticleTile<T_ParticleType, NArrayReal, NArrayInt,
amrex::DeviceArenaAllocator>(m, "device");
Expand Down
4 changes: 3 additions & 1 deletion src/Particle/StructOfArrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ void make_StructOfArrays(py::module &m, std::string allocstr)
template <int NReal, int NInt>
void make_StructOfArrays(py::module &m)
{
// first, because used as copy target in methods in containers with other allocators
make_StructOfArrays<NReal, NInt, amrex::PinnedArenaAllocator>(m, "pinned");

// see Src/Base/AMReX_GpuContainers.H
// !AMREX_USE_GPU: DefaultAllocator = std::allocator
// AMREX_USE_GPU: DefaultAllocator = amrex::ArenaAllocator
Expand All @@ -77,7 +80,6 @@ void make_StructOfArrays(py::module &m)
make_StructOfArrays<NReal, NInt, amrex::ArenaAllocator>(m, "arena");
#endif
// end work-around
make_StructOfArrays<NReal, NInt, amrex::PinnedArenaAllocator>(m, "pinned");
#ifdef AMREX_USE_GPU
make_StructOfArrays<NReal, NInt, amrex::DeviceArenaAllocator>(m, "device");
make_StructOfArrays<NReal, NInt, amrex::ManagedArenaAllocator>(m, "managed");
Expand Down

0 comments on commit dbffc34

Please sign in to comment.