Skip to content

Commit

Permalink
Merge pull request #3859 from bernhardmgruber/unroll
Browse files Browse the repository at this point in the history
Unroll interpolation
  • Loading branch information
psychocoderHPC authored Oct 22, 2021
2 parents 5e2681b + 74d24df commit f180805
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#pragma once

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

Expand Down Expand Up @@ -67,13 +68,17 @@ namespace picongpu
{
using type = typename ::pmacc::result_of::Functor<AssignedTrilinearInterpolation, T_Cursor>::type;

constexpr auto iterations = T_end - T_begin + 1;
auto result_z = type(0.0);
PMACC_UNROLL(iterations)
for(int z = T_begin; z <= T_end; ++z)
{
auto result_y = type(0.0);
PMACC_UNROLL(iterations)
for(int y = T_begin; y <= T_end; ++y)
{
auto result_x = type(0.0);
PMACC_UNROLL(iterations)
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
Expand Down
2 changes: 2 additions & 0 deletions include/picongpu/algorithms/FieldToParticleInterpolation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "picongpu/algorithms/ShiftCoordinateSystem.hpp"

#include <pmacc/attribute/unroll.hpp>
#include <pmacc/cuSTL/algorithm/functor/GetComponent.hpp>
#include <pmacc/cuSTL/cursor/FunctorCursor.hpp>
#include <pmacc/math/Vector.hpp>
Expand Down Expand Up @@ -76,6 +77,7 @@ namespace picongpu
using Supports = typename pmacc::math::CT::make_Int<simDim, supp>::type;

typename Cursor::ValueType result;
PMACC_UNROLL(Cursor::ValueType::dim)
for(uint32_t i = 0; i < Cursor::ValueType::dim; i++)
{
auto fieldComponent
Expand Down
43 changes: 43 additions & 0 deletions include/pmacc/attribute/unroll.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Copyright 2021 Bernhard Manfred Gruber
*
* This file is part of PMacc.
*
* PMacc is free software: you can redistribute it and/or modify
* it under the terms of either the GNU General Public License or
* the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PMacc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU Lesser General Public License along with PMacc.
* If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#ifndef PMACC_UNROLL
# define PMACC_PRAGMA(x) _Pragma(# x)

# if defined(__clang__) || defined(__INTEL_LLVM_COMPILER) || defined(__NVCC__)
# define PMACC_UNROLL(var) PMACC_PRAGMA(unroll var)
# elif defined(__INTEL_COMPILER) // check Intel before g++, because Intel defines __GNUG__
# define PMACC_UNROLL(var) PMACC_PRAGMA(unroll(var))
# elif defined(__GNUG__)
// g++ does support an unroll pragma but it does not accept the value of a template argument (at least until g++-11.2)
// see also: https://stackoverflow.com/q/63404539/2406044
// #define PMACC_UNROLL(var) PMACC_PRAGMA(GCC unroll var)
# define PMACC_UNROLL(var)
# elif defined(_MSC_VER)
// MSVC does not support a pragma for unrolling
# define PMACC_UNROLL(var)
# else
# define PMACC_UNROLL(var)
# warning PMACC_UNROLL is not implemented for your compiler
# endif
#endif

0 comments on commit f180805

Please sign in to comment.