Skip to content

Commit dc01d6e

Browse files
fixes and workaround
- shared memory: fix type deduction
1 parent d80b439 commit dc01d6e

File tree

3 files changed

+34
-37
lines changed

3 files changed

+34
-37
lines changed

include/picongpu/plugins/openPMD/openPMDWriter.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include <pmacc/mappings/simulation/GridController.hpp>
5959
#include <pmacc/mappings/simulation/SubGrid.hpp>
6060
#include <pmacc/math/Vector.hpp>
61+
#include <pmacc/meta/AllCombinations.hpp>
6162
#include <pmacc/particles/IdProvider.def>
6263
#include <pmacc/particles/frame_types.hpp>
6364
#include <pmacc/particles/memory/buffers/MallocMCBuffer.hpp>
@@ -258,7 +259,7 @@ make sure that environment variable OPENPMD_BP_BACKEND is not set to ADIOS1.
258259
pmacc::mp_at<T_TupleVector, pmacc::mp_int<1>>>;
259260

260261
using AllParticlesTimesAllFilters
261-
= AllCombinations<FileOutputParticles, particles::filter::AllParticleFilters>;
262+
= pmacc::AllCombinations<FileOutputParticles, particles::filter::AllParticleFilters>;
262263

263264
using AllSpeciesFilter = pmacc::mp_transform<CreateSpeciesFilter, AllParticlesTimesAllFilters>;
264265

include/pmacc/math/vector/compile-time/Int.hpp

+2-27
Original file line numberDiff line numberDiff line change
@@ -44,33 +44,8 @@ namespace pmacc
4444
* default parameter is used to distinguish between values given by
4545
* the user and unset values.
4646
*/
47-
template<
48-
int x = traits::limits::Max<int>::value,
49-
int y = traits::limits::Max<int>::value,
50-
int z = traits::limits::Max<int>::value>
51-
struct Int
52-
: public CT::Vector<
53-
std::integral_constant<int, x>,
54-
std::integral_constant<int, y>,
55-
std::integral_constant<int, z>>
56-
{
57-
};
58-
59-
template<>
60-
struct Int<> : public CT::Vector<>
61-
{
62-
};
63-
64-
template<int x>
65-
struct Int<x> : public CT::Vector<std::integral_constant<int, x>>
66-
{
67-
};
68-
69-
template<int x, int y>
70-
struct Int<x, y> : public CT::Vector<std::integral_constant<int, x>, std::integral_constant<int, y>>
71-
{
72-
};
73-
47+
template<int... T_values>
48+
using Int = CT::Vector<std::integral_constant<int, T_values>...>;
7449

7550
template<int dim, int val>
7651
struct make_Int;

include/pmacc/memory/boxes/SharedBox.hpp

+30-9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@
2828

2929
namespace pmacc
3030
{
31+
namespace detail
32+
{
33+
template<typename T_Vector, typename T_TYPE>
34+
HDINLINE auto& subscript(T_TYPE* p, int const idx, std::integral_constant<uint32_t, 1>)
35+
{
36+
return p[idx];
37+
}
38+
39+
template<typename T_Vector, typename T_TYPE>
40+
HDINLINE auto* subscript(T_TYPE* p, int const idx, std::integral_constant<uint32_t, 2>)
41+
{
42+
return p + idx * T_Vector::x::value;
43+
}
44+
45+
template<typename T_Vector, typename T_TYPE>
46+
HDINLINE auto* subscript(T_TYPE* p, int const idx, std::integral_constant<uint32_t, 3>)
47+
{
48+
return p + idx * (T_Vector::x::value * T_Vector::y::value);
49+
}
50+
} // namespace detail
51+
3152
/** create shared memory on gpu
3253
*
3354
* @tparam T_TYPE type of memory objects
@@ -52,16 +73,16 @@ namespace pmacc
5273

5374
HDINLINE SharedBox(SharedBox const&) = default;
5475

55-
HDINLINE decltype(auto) operator[](const int idx) const
76+
using ReducedType1D = T_TYPE&;
77+
using ReducedType2D = SharedBox<T_TYPE, typename math::CT::shrinkTo<T_Vector,1>::type, T_id>;
78+
using ReducedType3D = SharedBox<T_TYPE, typename math::CT::shrinkTo<T_Vector,2>::type, T_id>;
79+
using ReducedType
80+
= std::conditional_t<Dim == 1, ReducedType1D, std::conditional_t<Dim == 2, ReducedType2D, ReducedType3D>>;
81+
82+
HDINLINE ReducedType operator[](const int idx) const
5683
{
57-
if constexpr(Dim == 1)
58-
return fixedPointer[idx];
59-
else if constexpr(Dim == 2)
60-
return SharedBox<T_TYPE, math::CT::Int<T_Vector::x::value>, T_id>{
61-
fixedPointer + idx * T_Vector::x::value};
62-
else if constexpr(Dim == 3)
63-
return SharedBox<T_TYPE, math::CT::Int<T_Vector::x::value, T_Vector::y::value>, T_id>{
64-
fixedPointer + idx * (T_Vector::x::value * T_Vector::y::value)};
84+
///@todo(bgruber): inline and replace this by if constexpr in C++17
85+
return {detail::subscript<T_Vector>(fixedPointer, idx, std::integral_constant<uint32_t, T_dim>{})};
6586
}
6687

6788
/*!return the first value in the box (list)

0 commit comments

Comments
 (0)