Skip to content

Commit 00d21ef

Browse files
authored
Fix: Pinned Allocators First (#209)
* 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. * Update Stub Files --------- Co-authored-by: ax3l <ax3l@users.noreply.github.com>
1 parent 53b3cf0 commit 00d21ef

File tree

7 files changed

+42
-34
lines changed

7 files changed

+42
-34
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");

src/amrex/space1d/amrex_1d_pybind/__init__.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,7 +2773,7 @@ class ArrayOfStructs_0_0_arena:
27732773
Raises an exception if cupy is not installed
27742774
27752775
"""
2776-
def to_host(self) -> ArrayOfStructs_0_0_default: ...
2776+
def to_host(self) -> ArrayOfStructs_0_0_pinned: ...
27772777
def to_numpy(self, copy=False):
27782778
"""
27792779
@@ -2845,7 +2845,7 @@ class ArrayOfStructs_0_0_default:
28452845
Raises an exception if cupy is not installed
28462846
28472847
"""
2848-
def to_host(self) -> ArrayOfStructs_0_0_default: ...
2848+
def to_host(self) -> ArrayOfStructs_0_0_pinned: ...
28492849
def to_numpy(self, copy=False):
28502850
"""
28512851
@@ -2917,7 +2917,7 @@ class ArrayOfStructs_0_0_pinned:
29172917
Raises an exception if cupy is not installed
29182918
29192919
"""
2920-
def to_host(self) -> ArrayOfStructs_0_0_default: ...
2920+
def to_host(self) -> ArrayOfStructs_0_0_pinned: ...
29212921
def to_numpy(self, copy=False):
29222922
"""
29232923
@@ -2989,7 +2989,7 @@ class ArrayOfStructs_1_1_arena:
29892989
Raises an exception if cupy is not installed
29902990
29912991
"""
2992-
def to_host(self) -> ArrayOfStructs_1_1_default: ...
2992+
def to_host(self) -> ArrayOfStructs_1_1_pinned: ...
29932993
def to_numpy(self, copy=False):
29942994
"""
29952995
@@ -3061,7 +3061,7 @@ class ArrayOfStructs_1_1_default:
30613061
Raises an exception if cupy is not installed
30623062
30633063
"""
3064-
def to_host(self) -> ArrayOfStructs_1_1_default: ...
3064+
def to_host(self) -> ArrayOfStructs_1_1_pinned: ...
30653065
def to_numpy(self, copy=False):
30663066
"""
30673067
@@ -3133,7 +3133,7 @@ class ArrayOfStructs_1_1_pinned:
31333133
Raises an exception if cupy is not installed
31343134
31353135
"""
3136-
def to_host(self) -> ArrayOfStructs_1_1_default: ...
3136+
def to_host(self) -> ArrayOfStructs_1_1_pinned: ...
31373137
def to_numpy(self, copy=False):
31383138
"""
31393139
@@ -3205,7 +3205,7 @@ class ArrayOfStructs_2_1_arena:
32053205
Raises an exception if cupy is not installed
32063206
32073207
"""
3208-
def to_host(self) -> ArrayOfStructs_2_1_default: ...
3208+
def to_host(self) -> ArrayOfStructs_2_1_pinned: ...
32093209
def to_numpy(self, copy=False):
32103210
"""
32113211
@@ -3277,7 +3277,7 @@ class ArrayOfStructs_2_1_default:
32773277
Raises an exception if cupy is not installed
32783278
32793279
"""
3280-
def to_host(self) -> ArrayOfStructs_2_1_default: ...
3280+
def to_host(self) -> ArrayOfStructs_2_1_pinned: ...
32813281
def to_numpy(self, copy=False):
32823282
"""
32833283
@@ -3349,7 +3349,7 @@ class ArrayOfStructs_2_1_pinned:
33493349
Raises an exception if cupy is not installed
33503350
33513351
"""
3352-
def to_host(self) -> ArrayOfStructs_2_1_default: ...
3352+
def to_host(self) -> ArrayOfStructs_2_1_pinned: ...
33533353
def to_numpy(self, copy=False):
33543354
"""
33553355

src/amrex/space2d/amrex_2d_pybind/__init__.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,7 +2773,7 @@ class ArrayOfStructs_0_0_arena:
27732773
Raises an exception if cupy is not installed
27742774
27752775
"""
2776-
def to_host(self) -> ArrayOfStructs_0_0_default: ...
2776+
def to_host(self) -> ArrayOfStructs_0_0_pinned: ...
27772777
def to_numpy(self, copy=False):
27782778
"""
27792779
@@ -2845,7 +2845,7 @@ class ArrayOfStructs_0_0_default:
28452845
Raises an exception if cupy is not installed
28462846
28472847
"""
2848-
def to_host(self) -> ArrayOfStructs_0_0_default: ...
2848+
def to_host(self) -> ArrayOfStructs_0_0_pinned: ...
28492849
def to_numpy(self, copy=False):
28502850
"""
28512851
@@ -2917,7 +2917,7 @@ class ArrayOfStructs_0_0_pinned:
29172917
Raises an exception if cupy is not installed
29182918
29192919
"""
2920-
def to_host(self) -> ArrayOfStructs_0_0_default: ...
2920+
def to_host(self) -> ArrayOfStructs_0_0_pinned: ...
29212921
def to_numpy(self, copy=False):
29222922
"""
29232923
@@ -2989,7 +2989,7 @@ class ArrayOfStructs_1_1_arena:
29892989
Raises an exception if cupy is not installed
29902990
29912991
"""
2992-
def to_host(self) -> ArrayOfStructs_1_1_default: ...
2992+
def to_host(self) -> ArrayOfStructs_1_1_pinned: ...
29932993
def to_numpy(self, copy=False):
29942994
"""
29952995
@@ -3061,7 +3061,7 @@ class ArrayOfStructs_1_1_default:
30613061
Raises an exception if cupy is not installed
30623062
30633063
"""
3064-
def to_host(self) -> ArrayOfStructs_1_1_default: ...
3064+
def to_host(self) -> ArrayOfStructs_1_1_pinned: ...
30653065
def to_numpy(self, copy=False):
30663066
"""
30673067
@@ -3133,7 +3133,7 @@ class ArrayOfStructs_1_1_pinned:
31333133
Raises an exception if cupy is not installed
31343134
31353135
"""
3136-
def to_host(self) -> ArrayOfStructs_1_1_default: ...
3136+
def to_host(self) -> ArrayOfStructs_1_1_pinned: ...
31373137
def to_numpy(self, copy=False):
31383138
"""
31393139
@@ -3205,7 +3205,7 @@ class ArrayOfStructs_2_1_arena:
32053205
Raises an exception if cupy is not installed
32063206
32073207
"""
3208-
def to_host(self) -> ArrayOfStructs_2_1_default: ...
3208+
def to_host(self) -> ArrayOfStructs_2_1_pinned: ...
32093209
def to_numpy(self, copy=False):
32103210
"""
32113211
@@ -3277,7 +3277,7 @@ class ArrayOfStructs_2_1_default:
32773277
Raises an exception if cupy is not installed
32783278
32793279
"""
3280-
def to_host(self) -> ArrayOfStructs_2_1_default: ...
3280+
def to_host(self) -> ArrayOfStructs_2_1_pinned: ...
32813281
def to_numpy(self, copy=False):
32823282
"""
32833283
@@ -3349,7 +3349,7 @@ class ArrayOfStructs_2_1_pinned:
33493349
Raises an exception if cupy is not installed
33503350
33513351
"""
3352-
def to_host(self) -> ArrayOfStructs_2_1_default: ...
3352+
def to_host(self) -> ArrayOfStructs_2_1_pinned: ...
33533353
def to_numpy(self, copy=False):
33543354
"""
33553355

src/amrex/space3d/amrex_3d_pybind/__init__.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,7 +2773,7 @@ class ArrayOfStructs_0_0_arena:
27732773
Raises an exception if cupy is not installed
27742774
27752775
"""
2776-
def to_host(self) -> ArrayOfStructs_0_0_default: ...
2776+
def to_host(self) -> ArrayOfStructs_0_0_pinned: ...
27772777
def to_numpy(self, copy=False):
27782778
"""
27792779
@@ -2845,7 +2845,7 @@ class ArrayOfStructs_0_0_default:
28452845
Raises an exception if cupy is not installed
28462846
28472847
"""
2848-
def to_host(self) -> ArrayOfStructs_0_0_default: ...
2848+
def to_host(self) -> ArrayOfStructs_0_0_pinned: ...
28492849
def to_numpy(self, copy=False):
28502850
"""
28512851
@@ -2917,7 +2917,7 @@ class ArrayOfStructs_0_0_pinned:
29172917
Raises an exception if cupy is not installed
29182918
29192919
"""
2920-
def to_host(self) -> ArrayOfStructs_0_0_default: ...
2920+
def to_host(self) -> ArrayOfStructs_0_0_pinned: ...
29212921
def to_numpy(self, copy=False):
29222922
"""
29232923
@@ -2989,7 +2989,7 @@ class ArrayOfStructs_1_1_arena:
29892989
Raises an exception if cupy is not installed
29902990
29912991
"""
2992-
def to_host(self) -> ArrayOfStructs_1_1_default: ...
2992+
def to_host(self) -> ArrayOfStructs_1_1_pinned: ...
29932993
def to_numpy(self, copy=False):
29942994
"""
29952995
@@ -3061,7 +3061,7 @@ class ArrayOfStructs_1_1_default:
30613061
Raises an exception if cupy is not installed
30623062
30633063
"""
3064-
def to_host(self) -> ArrayOfStructs_1_1_default: ...
3064+
def to_host(self) -> ArrayOfStructs_1_1_pinned: ...
30653065
def to_numpy(self, copy=False):
30663066
"""
30673067
@@ -3133,7 +3133,7 @@ class ArrayOfStructs_1_1_pinned:
31333133
Raises an exception if cupy is not installed
31343134
31353135
"""
3136-
def to_host(self) -> ArrayOfStructs_1_1_default: ...
3136+
def to_host(self) -> ArrayOfStructs_1_1_pinned: ...
31373137
def to_numpy(self, copy=False):
31383138
"""
31393139
@@ -3205,7 +3205,7 @@ class ArrayOfStructs_2_1_arena:
32053205
Raises an exception if cupy is not installed
32063206
32073207
"""
3208-
def to_host(self) -> ArrayOfStructs_2_1_default: ...
3208+
def to_host(self) -> ArrayOfStructs_2_1_pinned: ...
32093209
def to_numpy(self, copy=False):
32103210
"""
32113211
@@ -3277,7 +3277,7 @@ class ArrayOfStructs_2_1_default:
32773277
Raises an exception if cupy is not installed
32783278
32793279
"""
3280-
def to_host(self) -> ArrayOfStructs_2_1_default: ...
3280+
def to_host(self) -> ArrayOfStructs_2_1_pinned: ...
32813281
def to_numpy(self, copy=False):
32823282
"""
32833283
@@ -3349,7 +3349,7 @@ class ArrayOfStructs_2_1_pinned:
33493349
Raises an exception if cupy is not installed
33503350
33513351
"""
3352-
def to_host(self) -> ArrayOfStructs_2_1_default: ...
3352+
def to_host(self) -> ArrayOfStructs_2_1_pinned: ...
33533353
def to_numpy(self, copy=False):
33543354
"""
33553355

0 commit comments

Comments
 (0)