Skip to content

Commit 023ea80

Browse files
committed
Work-Around: explicitly have default
... and skip what it stands for.
1 parent 8741b6a commit 023ea80

File tree

8 files changed

+82
-44
lines changed

8 files changed

+82
-44
lines changed

src/Particle/ArrayOfStructs.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#include <AMReX_Config.H>
77
#include <AMReX_ArrayOfStructs.H>
8+
#include <AMReX_GpuAllocators.H>
89

910
#include <pybind11/pybind11.h>
1011
#include <pybind11/stl.h>
@@ -124,18 +125,26 @@ template <int NReal, int NInt>
124125
void make_ArrayOfStructs(py::module &m)
125126
{
126127
// see Src/Base/AMReX_GpuContainers.H
128+
// !AMREX_USE_GPU: DefaultAllocator = std::allocator
129+
// AMREX_USE_GPU: DefaultAllocator = amrex::ArenaAllocator
130+
131+
// work-around for https://github.com/pybind/pybind11/pull/4581
132+
//make_ArrayOfStructs<NReal, NInt, std::allocator> (m, "std");
133+
//make_ArrayOfStructs<NReal, NInt, amrex::ArenaAllocator> (m, "arena");
134+
#ifdef AMREX_USE_GPU
127135
make_ArrayOfStructs<NReal, NInt, std::allocator> (m, "std");
136+
make_ArrayOfStructs<NReal, NInt, amrex::DefaultAllocator> (m, "default"); // amrex::ArenaAllocator
137+
#else
138+
make_ArrayOfStructs<NReal, NInt, amrex::DefaultAllocator> (m, "default"); // std::allocator
128139
make_ArrayOfStructs<NReal, NInt, amrex::ArenaAllocator> (m, "arena");
140+
#endif
141+
// end work-around
129142
make_ArrayOfStructs<NReal, NInt, amrex::PinnedArenaAllocator> (m, "pinned");
130143
#ifdef AMREX_USE_GPU
131144
make_ArrayOfStructs<NReal, NInt, amrex::DeviceArenaAllocator> (m, "device");
132145
make_ArrayOfStructs<NReal, NInt, amrex::ManagedArenaAllocator> (m, "managed");
133146
make_ArrayOfStructs<NReal, NInt, amrex::AsyncArenaAllocator> (m, "async");
134147
#endif
135-
#ifdef _WIN32
136-
// work-around for https://github.com/pybind/pybind11/pull/4319
137-
make_ArrayOfStructs<NReal, NInt, amrex::DefaultAllocator> (m, "default");
138-
#endif
139148
}
140149

141150
void init_ArrayOfStructs(py::module& m) {

src/Particle/ParticleContainer.H

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,24 @@ void make_ParticleContainer_and_Iterators (py::module &m)
354354
// see Src/Base/AMReX_GpuContainers.H
355355
// !AMREX_USE_GPU: DefaultAllocator = std::allocator
356356
// AMREX_USE_GPU: DefaultAllocator = amrex::ArenaAllocator
357+
358+
// work-around for https://github.com/pybind/pybind11/pull/4581
359+
//make_ParticleContainer_and_Iterators<T_NStructReal, T_NStructInt, T_NArrayReal, T_NArrayInt,
360+
// std::allocator>(m, "std"); // CPU DefaultAllocator
361+
//make_ParticleContainer_and_Iterators<T_NStructReal, T_NStructInt, T_NArrayReal, T_NArrayInt,
362+
// amrex::ArenaAllocator>(m, "arena"); // GPU DefaultAllocator
363+
#ifdef AMREX_USE_GPU
364+
make_ParticleContainer_and_Iterators<T_NStructReal, T_NStructInt, T_NArrayReal, T_NArrayInt,
365+
std::allocator>(m, "std");
366+
make_ParticleContainer_and_Iterators<T_NStructReal, T_NStructInt, T_NArrayReal, T_NArrayInt,
367+
amrex::DefaultAllocator>(m, "default"); // amrex::ArenaAllocator
368+
#else
357369
make_ParticleContainer_and_Iterators<T_NStructReal, T_NStructInt, T_NArrayReal, T_NArrayInt,
358-
std::allocator>(m, "std"); // CPU DefaultAllocator
370+
amrex::DefaultAllocator>(m, "default"); // std::allocator
359371
make_ParticleContainer_and_Iterators<T_NStructReal, T_NStructInt, T_NArrayReal, T_NArrayInt,
360-
amrex::ArenaAllocator>(m, "arena"); // GPU DefaultAllocator
372+
amrex::ArenaAllocator>(m, "arena");
373+
#endif
374+
// end work-around
361375
make_ParticleContainer_and_Iterators<T_NStructReal, T_NStructInt, T_NArrayReal, T_NArrayInt,
362376
amrex::PinnedArenaAllocator>(m, "pinned");
363377
#ifdef AMREX_USE_GPU
@@ -368,10 +382,4 @@ void make_ParticleContainer_and_Iterators (py::module &m)
368382
make_ParticleContainer_and_Iterators<T_NStructReal, T_NStructInt, T_NArrayReal, T_NArrayInt,
369383
amrex::AsyncArenaAllocator>(m, "async");
370384
#endif
371-
372-
#ifdef _WIN32
373-
// work-around for https://github.com/pybind/pybind11/pull/4319
374-
make_ParticleContainer_and_Iterators<T_NStructReal, T_NStructInt, T_NArrayReal, T_NArrayInt,
375-
amrex::DefaultAllocator>(m, "default");
376-
#endif
377385
}

src/Particle/ParticleTile.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#include <AMReX_Config.H>
77
#include <AMReX_BoxArray.H>
8+
#include <AMReX_GpuAllocators.H>
89
#include <AMReX_IntVect.H>
910
#include <AMReX_ParticleTile.H>
1011

@@ -112,10 +113,26 @@ void make_ParticleTile(py::module &m)
112113
make_ParticleTileData<NStructReal, NStructInt, NArrayReal, NArrayInt>(m);
113114

114115
// see Src/Base/AMReX_GpuContainers.H
116+
// !AMREX_USE_GPU: DefaultAllocator = std::allocator
117+
// AMREX_USE_GPU: DefaultAllocator = amrex::ArenaAllocator
118+
119+
// work-around for https://github.com/pybind/pybind11/pull/4581
120+
//make_ParticleTile<NStructReal, NStructInt, NArrayReal, NArrayInt,
121+
// std::allocator>(m, "std");
122+
//make_ParticleTile<NStructReal, NStructInt, NArrayReal, NArrayInt,
123+
// amrex::ArenaAllocator>(m, "arena");
124+
#ifdef AMREX_USE_GPU
115125
make_ParticleTile<NStructReal, NStructInt, NArrayReal, NArrayInt,
116126
std::allocator>(m, "std");
127+
make_ParticleTile<NStructReal, NStructInt, NArrayReal, NArrayInt,
128+
amrex::DefaultAllocator>(m, "default"); // amrex::ArenaAllocator
129+
#else
130+
make_ParticleTile<NStructReal, NStructInt, NArrayReal, NArrayInt,
131+
amrex::DefaultAllocator>(m, "default"); // std::allocator
117132
make_ParticleTile<NStructReal, NStructInt, NArrayReal, NArrayInt,
118133
amrex::ArenaAllocator>(m, "arena");
134+
#endif
135+
// end work-around
119136
make_ParticleTile<NStructReal, NStructInt, NArrayReal, NArrayInt,
120137
amrex::PinnedArenaAllocator>(m, "pinned");
121138
#ifdef AMREX_USE_GPU
@@ -126,11 +143,6 @@ void make_ParticleTile(py::module &m)
126143
make_ParticleTile<NStructReal, NStructInt, NArrayReal, NArrayInt,
127144
amrex::AsyncArenaAllocator>(m, "async");
128145
#endif
129-
#ifdef _WIN32
130-
// work-around for https://github.com/pybind/pybind11/pull/4319
131-
make_ParticleTile<NStructReal, NStructInt, NArrayReal, NArrayInt,
132-
amrex::DefaultAllocator>(m, "default");
133-
#endif
134146
}
135147

136148
void init_ParticleTile(py::module& m) {

src/Particle/StructOfArrays.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* License: BSD-3-Clause-LBNL
55
*/
66
#include <AMReX_Config.H>
7+
#include <AMReX_GpuAllocators.H>
78
#include <AMReX_StructOfArrays.H>
89

910
#include <pybind11/pybind11.h>
@@ -46,18 +47,26 @@ template <int NReal, int NInt>
4647
void make_StructOfArrays(py::module &m)
4748
{
4849
// see Src/Base/AMReX_GpuContainers.H
50+
// !AMREX_USE_GPU: DefaultAllocator = std::allocator
51+
// AMREX_USE_GPU: DefaultAllocator = amrex::ArenaAllocator
52+
53+
// work-around for https://github.com/pybind/pybind11/pull/4581
54+
//make_StructOfArrays<NReal, NInt, std::allocator>(m, "std");
55+
//make_StructOfArrays<NReal, NInt, amrex::ArenaAllocator>(m, "arena");
56+
#ifdef AMREX_USE_GPU
4957
make_StructOfArrays<NReal, NInt, std::allocator>(m, "std");
58+
make_StructOfArrays<NReal, NInt, amrex::DefaultAllocator> (m, "default"); // amrex::ArenaAllocator
59+
#else
60+
make_StructOfArrays<NReal, NInt, amrex::DefaultAllocator> (m, "default"); // std::allocator
5061
make_StructOfArrays<NReal, NInt, amrex::ArenaAllocator>(m, "arena");
62+
#endif
63+
// end work-around
5164
make_StructOfArrays<NReal, NInt, amrex::PinnedArenaAllocator>(m, "pinned");
5265
#ifdef AMREX_USE_GPU
5366
make_StructOfArrays<NReal, NInt, amrex::DeviceArenaAllocator>(m, "device");
5467
make_StructOfArrays<NReal, NInt, amrex::ManagedArenaAllocator>(m, "managed");
5568
make_StructOfArrays<NReal, NInt, amrex::AsyncArenaAllocator>(m, "async");
5669
#endif
57-
#ifdef _WIN32
58-
// work-around for https://github.com/pybind/pybind11/pull/4319
59-
make_StructOfArrays<NReal, NInt, amrex::DefaultAllocator>(m, "default");
60-
#endif
6170
}
6271

6372
void init_StructOfArrays(py::module& m) {

tests/test_aos.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88

99
def test_aos_init():
10-
aos = amrex.ArrayOfStructs_2_1_std()
10+
aos = amrex.ArrayOfStructs_2_1_default()
1111

1212
assert aos.numParticles() == 0
1313
assert aos.numTotalParticles() == aos.numRealParticles() == 0
1414
assert aos.empty()
1515

1616

1717
def test_aos_push_pop():
18-
aos = amrex.ArrayOfStructs_2_1_std()
18+
aos = amrex.ArrayOfStructs_2_1_default()
1919
p1 = amrex.Particle_2_1()
2020
p1.set_rdata([1.5, 2.2])
2121
p1.set_idata([3])
@@ -50,7 +50,7 @@ def test_aos_push_pop():
5050

5151

5252
def test_array_interface():
53-
aos = amrex.ArrayOfStructs_2_1_std()
53+
aos = amrex.ArrayOfStructs_2_1_default()
5454
p1 = amrex.Particle_2_1()
5555
p1.setPos([1, 2, 3])
5656
p1.set_rdata([4.5, 5.2])

tests/test_particleContainer.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def Npart():
1313

1414
@pytest.fixture(scope="function")
1515
def empty_particle_container(std_geometry, distmap, boxarr):
16-
pc = amrex.ParticleContainer_1_1_2_1_std(std_geometry, distmap, boxarr)
16+
pc = amrex.ParticleContainer_1_1_2_1_default(std_geometry, distmap, boxarr)
1717
return pc
1818

1919

@@ -29,7 +29,7 @@ def std_particle():
2929

3030
@pytest.fixture(scope="function")
3131
def particle_container(Npart, std_geometry, distmap, boxarr, std_real_box):
32-
pc = amrex.ParticleContainer_1_1_2_1_std(std_geometry, distmap, boxarr)
32+
pc = amrex.ParticleContainer_1_1_2_1_default(std_geometry, distmap, boxarr)
3333
myt = amrex.ParticleInitType_1_1_2_1()
3434
myt.real_struct_data = [0.5]
3535
myt.int_struct_data = [5]
@@ -62,17 +62,17 @@ def test_particleInitType():
6262
def test_n_particles(particle_container, Npart):
6363
pc = particle_container
6464
assert pc.OK()
65-
assert pc.NStructReal == amrex.ParticleContainer_1_1_2_1_std.NStructReal == 1
66-
assert pc.NStructInt == amrex.ParticleContainer_1_1_2_1_std.NStructInt == 1
67-
assert pc.NArrayReal == amrex.ParticleContainer_1_1_2_1_std.NArrayReal == 2
68-
assert pc.NArrayInt == amrex.ParticleContainer_1_1_2_1_std.NArrayInt == 1
65+
assert pc.NStructReal == amrex.ParticleContainer_1_1_2_1_default.NStructReal == 1
66+
assert pc.NStructInt == amrex.ParticleContainer_1_1_2_1_default.NStructInt == 1
67+
assert pc.NArrayReal == amrex.ParticleContainer_1_1_2_1_default.NArrayReal == 2
68+
assert pc.NArrayInt == amrex.ParticleContainer_1_1_2_1_default.NArrayInt == 1
6969
assert (
7070
pc.NumberOfParticlesAtLevel(0) == np.sum(pc.NumberOfParticlesInGrid(0)) == Npart
7171
)
7272

7373

7474
def test_pc_init():
75-
pc = amrex.ParticleContainer_1_1_2_1_std()
75+
pc = amrex.ParticleContainer_1_1_2_1_default()
7676

7777
print("bytespread", pc.ByteSpread())
7878
print("capacity", pc.PrintCapacity())
@@ -93,10 +93,10 @@ def test_pc_init():
9393
print("define particle container")
9494
pc.Define(gm, dm, ba)
9595
assert pc.OK()
96-
assert pc.NStructReal == amrex.ParticleContainer_1_1_2_1_std.NStructReal == 1
97-
assert pc.NStructInt == amrex.ParticleContainer_1_1_2_1_std.NStructInt == 1
98-
assert pc.NArrayReal == amrex.ParticleContainer_1_1_2_1_std.NArrayReal == 2
99-
assert pc.NArrayInt == amrex.ParticleContainer_1_1_2_1_std.NArrayInt == 1
96+
assert pc.NStructReal == amrex.ParticleContainer_1_1_2_1_default.NStructReal == 1
97+
assert pc.NStructInt == amrex.ParticleContainer_1_1_2_1_default.NStructInt == 1
98+
assert pc.NArrayReal == amrex.ParticleContainer_1_1_2_1_default.NArrayReal == 2
99+
assert pc.NArrayInt == amrex.ParticleContainer_1_1_2_1_default.NArrayInt == 1
100100

101101
print("bytespread", pc.ByteSpread())
102102
print("capacity", pc.PrintCapacity())
@@ -123,7 +123,7 @@ def test_pc_init():
123123

124124
print("Iterate particle boxes & set values")
125125
lvl = 0
126-
for pti in amrex.ParIter_1_1_2_1_std(pc, level=lvl):
126+
for pti in amrex.ParIter_1_1_2_1_default(pc, level=lvl):
127127
print("...")
128128
assert pti.num_particles == 1
129129
assert pti.num_real_particles == 1
@@ -151,7 +151,7 @@ def test_pc_init():
151151
assert np.allclose(int_arrays[0], np.array([2]))
152152

153153
# read-only
154-
for pti in amrex.ParConstIter_1_1_2_1_std(pc, level=lvl):
154+
for pti in amrex.ParConstIter_1_1_2_1_default(pc, level=lvl):
155155
assert pti.num_particles == 1
156156
assert pti.num_real_particles == 1
157157
assert pti.num_neighbor_particles == 0

tests/test_particleTile.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_ptile_data():
1515

1616

1717
def test_ptile_funs():
18-
pt = amrex.ParticleTile_1_1_2_1_std()
18+
pt = amrex.ParticleTile_1_1_2_1_default()
1919

2020
assert pt.empty() and pt.size() == 0
2121
assert pt.numParticles() == pt.numRealParticles() == pt.numNeighborParticles() == 0
@@ -35,7 +35,7 @@ def test_ptile_funs():
3535

3636
################
3737
def test_ptile_pushback_ptiledata():
38-
pt = amrex.ParticleTile_1_1_2_1_std()
38+
pt = amrex.ParticleTile_1_1_2_1_default()
3939
p = amrex.Particle_1_1(1.0, 2.0, 3, 4.0, 5)
4040
sp = amrex.Particle_3_2(5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11, 12)
4141
pt.push_back(p)
@@ -62,7 +62,7 @@ def test_ptile_pushback_ptiledata():
6262

6363
@pytest.mark.skipif(amrex.Config.spacedim != 3, reason="Requires AMREX_SPACEDIM = 3")
6464
def test_ptile_access():
65-
pt = amrex.ParticleTile_1_1_2_1_std()
65+
pt = amrex.ParticleTile_1_1_2_1_default()
6666
sp1 = amrex.Particle_3_2()
6767
pt.push_back(sp1)
6868
pt.push_back(sp1)
@@ -81,7 +81,7 @@ def test_ptile_access():
8181

8282

8383
def test_ptile_soa():
84-
pt = amrex.ParticleTile_1_1_2_1_std()
84+
pt = amrex.ParticleTile_1_1_2_1_default()
8585

8686
pt.push_back_real(1, 2.1)
8787
pt.push_back_real([1.1, 1.3])
@@ -120,7 +120,7 @@ def test_ptile_soa():
120120

121121
@pytest.mark.skipif(amrex.Config.spacedim != 3, reason="Requires AMREX_SPACEDIM = 3")
122122
def test_ptile_aos():
123-
pt = amrex.ParticleTile_1_1_2_1_std()
123+
pt = amrex.ParticleTile_1_1_2_1_default()
124124
p1 = amrex.Particle_1_1()
125125
p2 = amrex.Particle_1_1()
126126
p1.x = 3.0

tests/test_soa.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def test_soa_init():
10-
soa = amrex.StructOfArrays_2_1_std()
10+
soa = amrex.StructOfArrays_2_1_default()
1111
print("--test init --")
1212
print("num real components", soa.NumRealComps())
1313
print("num int components", soa.NumIntComps())
@@ -51,7 +51,7 @@ def test_soa_init():
5151

5252

5353
def test_soa_from_tile():
54-
pt = amrex.ParticleTile_1_1_2_1_std()
54+
pt = amrex.ParticleTile_1_1_2_1_default()
5555
p = amrex.Particle_1_1(1.0, 2.0, 3, rdata_0=4.0, idata_1=5)
5656
sp = amrex.Particle_3_2(
5757
5.0, 6.0, 7.0, rdata_0=8.0, rdata_1=9.0, rdata_2=10.0, idata_0=11, idata_1=12

0 commit comments

Comments
 (0)