Skip to content

Commit

Permalink
Merge pull request #4398 from psychocoderHPC/topic-moveAndMarkRemoveC…
Browse files Browse the repository at this point in the history
…USTL

remove CUstl from particle push

I will merge and perform a test afterwards.
  • Loading branch information
PrometheusPi authored Dec 20, 2022
2 parents 036c682 + a5fb528 commit 697e553
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 56 deletions.
23 changes: 12 additions & 11 deletions include/picongpu/algorithms/AssignedTrilinearInterpolation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#pragma once

#include <pmacc/attribute/unroll.hpp>
#include <pmacc/result_of_Functor.hpp>
#include <pmacc/types.hpp>

#include <type_traits>
Expand Down Expand Up @@ -54,9 +53,11 @@ namespace picongpu
*
* @tparam T_begin lower margin for interpolation
* @tparam T_end upper margin for interpolation
* @tparam T_FieldAccessorFunctor type of the field access functor supporting a initializer list of simdDim
* indices
* @tparam T_AssignmentFunction type of shape functors
*
* @param cursor cursor pointing to the field
* @param fieldAccess field access method pointing to the particle located cell
* @param shapeFunctors Array with d shape functors, where d is the dimensionality of the field represented by
* cursor. The shape functor must have the interface to call
* `operator()(relative_grid_point)` and return the assignment value for the given grid
Expand All @@ -67,14 +68,14 @@ namespace picongpu
*
* @{
*/
template<int T_begin, int T_end, typename T_Cursor, typename T_AssignmentFunction>
template<int T_begin, int T_end, typename T_FieldAccessorFunctor, typename T_AssignmentFunction>
HDINLINE static auto interpolate(
const T_Cursor& cursor,
const pmacc::memory::Array<T_AssignmentFunction, 3>& shapeFunctors)
T_FieldAccessorFunctor const& fieldAccess,
pmacc::memory::Array<T_AssignmentFunction, 3> const& shapeFunctors)
{
[[maybe_unused]] constexpr auto iterations = T_end - T_begin + 1;

using type = decltype(*cursor(0, 0, 0) * shapeFunctors[0](0));
using type = decltype(fieldAccess({0, 0, 0}) * shapeFunctors[0](0));

/* The implementation assumes that x is the fastest moving index to iterate over contiguous memory
* e.g. a row, to optimize memory fetch operations.
Expand All @@ -93,7 +94,7 @@ namespace picongpu
/* a form factor is the "amount of particle" that is affected by this cell
* so we have to sum over: cell_value * form_factor
*/
result_x += *cursor(x, y, z) * shapeFunctors[0](x);
result_x += fieldAccess({x, y, z}) * shapeFunctors[0](x);

result_y += result_x * shapeFunctors[1](y);
}
Expand All @@ -103,14 +104,14 @@ namespace picongpu
}

/** Implementation for 2D position*/
template<int T_begin, int T_end, class T_Cursor, class T_AssignmentFunction>
template<int T_begin, int T_end, class T_FieldAccessorFunctor, class T_AssignmentFunction>
HDINLINE static auto interpolate(
T_Cursor const& cursor,
T_FieldAccessorFunctor const& fieldAccess,
const pmacc::memory::Array<T_AssignmentFunction, 2>& shapeFunctors)
{
[[maybe_unused]] constexpr int iterations = T_end - T_begin + 1;

using type = decltype(*cursor(0, 0) * shapeFunctors[0](0));
using type = decltype(fieldAccess({0, 0}) * shapeFunctors[0](0));
/* The implementation assumes that x is the fastest moving index to iterate over contiguous memory
* e.g. a row, to optimize memory fetch operations.
*/
Expand All @@ -123,7 +124,7 @@ namespace picongpu
for(int x = T_begin; x <= T_end; ++x)
// a form factor is the "amount of particle" that is affected by this cell
// so we have to sum over: cell_value * form_factor
result_x += *cursor(x, y) * shapeFunctors[0](x);
result_x += fieldAccess({x, y}) * shapeFunctors[0](x);

result_y += result_x * shapeFunctors[1](y);
}
Expand Down
29 changes: 15 additions & 14 deletions include/picongpu/algorithms/FieldToParticleInterpolation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#include "picongpu/particles/shapes.hpp"

#include <pmacc/attribute/unroll.hpp>
#include <pmacc/cuSTL/algorithm/functor/GetComponent.hpp>
#include <pmacc/cuSTL/cursor/FunctorCursor.hpp>
#include <pmacc/math/Vector.hpp>

namespace picongpu
Expand Down Expand Up @@ -95,28 +93,31 @@ namespace picongpu
return result;
};

template<class Cursor, class VecVector>
HDINLINE typename Cursor::ValueType operator()(
Cursor field,
const floatD_X& particlePos,
const VecVector& fieldPos)
template<class T_FieldDataBox, class VecVector>
HDINLINE auto operator()(T_FieldDataBox const& field, const floatD_X& particlePos, const VecVector& fieldPos)
{
/**\brief:
* The following calls seperate the vector interpolation into
* independent scalar interpolations.
*/
using Supports = typename pmacc::math::CT::make_Int<simDim, supp>::type;
using ResultType = typename T_FieldDataBox::ValueType;

typename Cursor::ValueType result;
PMACC_UNROLL(Cursor::ValueType::dim)
for(uint32_t i = 0; i < Cursor::ValueType::dim; i++)
ResultType result;
PMACC_UNROLL(ResultType::dim)
for(uint32_t i = 0; i < ResultType::dim; i++)
{
auto fieldComponent
= pmacc::cursor::make_FunctorCursor(field, pmacc::algorithm::functor::GetComponent<float_X>(i));
// work on a copy to shift the field for each loop round separate
auto shiftedField = field;
floatD_X particlePosShifted = particlePos;
ShiftCoordinateSystem<Supports>()(fieldComponent, particlePosShifted, fieldPos[i]);
ShiftCoordinateSystem<Supports>()(shiftedField, particlePosShifted, fieldPos[i]);

auto accessFunctor = [&](DataSpace<simDim> const& idx) constexpr
{
return shiftedField(idx)[i];
};
result[i] = InterpolationMethod::template interpolate<begin, end>(
fieldComponent,
accessFunctor,
getShapeFunctors(particlePosShifted));
}

Expand Down
21 changes: 9 additions & 12 deletions include/picongpu/algorithms/ShiftCoordinateSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ namespace picongpu
template<typename T_Component, typename T_Supports>
struct AssignToDim
{
template<typename T_Type, typename T_Vector, typename T_FieldType>
HDINLINE void operator()(T_Type& cursor, T_Vector& pos, const T_FieldType& fieldPos)
template<typename T_DataBox, typename T_Vector, typename T_FieldType>
HDINLINE void operator()(T_DataBox& dataBox, T_Vector& pos, const T_FieldType& fieldPos)
{
const uint32_t dim = T_Vector::dim;
using ValueType = typename T_Vector::type;
Expand All @@ -59,7 +59,7 @@ namespace picongpu
const ValueType v_pos = pos[component] - fieldPos[component];
DataSpace<dim> intShift;
intShift[component] = GetOffsetToStaticShapeSystem<isEven>()(v_pos);
cursor = cursor(intShift);
dataBox = dataBox.shift(intShift);
pos[component] = v_pos - ValueType(intShift[component]);
}
};
Expand All @@ -73,8 +73,8 @@ namespace picongpu
{
/** shift to new coordinate system
*
* shift cursor and vector to new coordinate system
* @param[in,out] cursor cursor to memory
* shift DataBox and vector to new coordinate system
* @param[in,out] dataBox DataBox pointing to the particle located cell
* @param[in,out] vector short vector with coordinates in old system
* - defined for [0.0;1.0) per dimension
* @param fieldPos vector with relative coordinates for shift ( value range [0.0;0.5] )
Expand All @@ -85,19 +85,16 @@ namespace picongpu
* - Even Support: vector is always [0.0;1.0)
* - Odd Support: vector is always [-0.5;0.5)
*/
template<typename T_Cursor, typename T_Vector, typename T_FieldType>
HDINLINE void operator()(T_Cursor& cursor, T_Vector& vector, const T_FieldType& fieldPos)
template<typename T_DataBox, typename T_Vector, typename T_FieldType>
HDINLINE void operator()(T_DataBox& dataBox, T_Vector& vector, const T_FieldType& fieldPos)
{
/** \todo check if a static assert on
* "T_Cursor::dim" == T_Vector::dim == T_FieldType::dim is possible
* and does not waste registers */
const uint32_t dim = T_Vector::dim;
constexpr uint32_t dim = T_DataBox::Dim;

using Size = boost::mpl::vector1<boost::mpl::range_c<uint32_t, 0, dim>>;
using CombiTypes = typename AllCombinations<Size>::type;

meta::ForEach<CombiTypes, AssignToDim<bmpl::_1, T_supports>> shift;
shift(cursor, vector, fieldPos);
shift(dataBox, vector, fieldPos);
}
};

Expand Down
10 changes: 4 additions & 6 deletions include/picongpu/particles/Particles.kernel
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,10 @@ namespace picongpu
const traits::FieldPosition<fields::CellType, FieldE> fieldPosE;
const traits::FieldPosition<fields::CellType, FieldB> fieldPosB;

auto functorEfield = CreateInterpolationForPusher<Field2ParticleInterpolation>()(
eBox.shift(localCell).toCursor(),
fieldPosE());
auto functorBfield = CreateInterpolationForPusher<Field2ParticleInterpolation>()(
bBox.shift(localCell).toCursor(),
fieldPosB());
auto functorEfield
= CreateInterpolationForPusher<Field2ParticleInterpolation>()(eBox.shift(localCell), fieldPosE());
auto functorBfield
= CreateInterpolationForPusher<Field2ParticleInterpolation>()(bBox.shift(localCell), fieldPosB());

/** @todo this functor should only manipulate the momentum and all changes
* in position and cell below need to go into a separate kernel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace picongpu
HDINLINE T_MemoryType memory(const T_MemoryType& mem, const T_PosType& pos) const
{
const T_PosType pos_floor = math::floor(pos);
return mem(precisionCast<int>(pos_floor));
return mem.shift(precisionCast<int>(pos_floor));
}

template<typename T_PosType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ namespace picongpu
/* interpolation of density */
const picongpu::traits::FieldPosition<fields::CellType, FieldTmp> fieldPosRho;
ValueType_Rho densityV
= Field2ParticleInterpolation()(cachedRho.shift(localCell).toCursor(), pos, fieldPosRho());
= Field2ParticleInterpolation()(cachedRho.shift(localCell), pos, fieldPosRho());
/* and energy density field on the particle position */
const picongpu::traits::FieldPosition<fields::CellType, FieldTmp> fieldPosEne;
ValueType_Ene kinEnergyV
= Field2ParticleInterpolation()(cachedEne.shift(localCell).toCursor(), pos, fieldPosEne());
= Field2ParticleInterpolation()(cachedEne.shift(localCell), pos, fieldPosEne());

/* density in sim units */
float_X const density = densityV[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,10 @@ namespace picongpu
DataSpaceOperations<TVec::dim>::template map<TVec>(particleCellIdx));
/* interpolation of E- */
const picongpu::traits::FieldPosition<fields::CellType, FieldE> fieldPosE;
ValueType_E eField
= Field2ParticleInterpolation()(cachedE.shift(localCell).toCursor(), pos, fieldPosE());
ValueType_E eField = Field2ParticleInterpolation()(cachedE.shift(localCell), pos, fieldPosE());
/* and B-field on the particle position */
const picongpu::traits::FieldPosition<fields::CellType, FieldB> fieldPosB;
ValueType_B bField
= Field2ParticleInterpolation()(cachedB.shift(localCell).toCursor(), pos, fieldPosB());
ValueType_B bField = Field2ParticleInterpolation()(cachedB.shift(localCell), pos, fieldPosB());

IonizationAlgorithm ionizeAlgo;
/* determine number of new macro electrons to be created and energy used for ionization */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ namespace picongpu
DataSpaceOperations<TVec::dim>::template map<TVec>(particleCellIdx));
/* interpolation of E */
const picongpu::traits::FieldPosition<fields::CellType, FieldE> fieldPosE;
ValueType_E eField
= Field2ParticleInterpolation()(cachedE.shift(localCell).toCursor(), pos, fieldPosE());
ValueType_E eField = Field2ParticleInterpolation()(cachedE.shift(localCell), pos, fieldPosE());

/* this is the point where actual ionization takes place */
IonizationAlgorithm ionizeAlgo{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,10 @@ namespace picongpu
DataSpaceOperations<TVec::dim>::template map<TVec>(particleCellIdx));
/* interpolation of E- */
const picongpu::traits::FieldPosition<fields::CellType, FieldE> fieldPosE;
ValueType_E eField
= Field2ParticleInterpolation()(cachedE.shift(localCell).toCursor(), pos, fieldPosE());
ValueType_E eField = Field2ParticleInterpolation()(cachedE.shift(localCell), pos, fieldPosE());
/* and B-field on the particle position */
const picongpu::traits::FieldPosition<fields::CellType, FieldB> fieldPosB;
ValueType_B bField
= Field2ParticleInterpolation()(cachedB.shift(localCell).toCursor(), pos, fieldPosB());
ValueType_B bField = Field2ParticleInterpolation()(cachedB.shift(localCell), pos, fieldPosB());

IonizationAlgorithm ionizeAlgo;
/* determine number of new macro electrons to be created and energy used for ionization */
Expand Down

0 comments on commit 697e553

Please sign in to comment.