Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unroll interpolation #3859

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not throw a warning, the typical user does not know what this means and this is only about performance.
Maybe we should activate it only if someone is compiling in debug mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This warning is displayed if we did not yet think about a particular compiler. It is not triggered when there is no implementation. So e.g. for MSVC and g++, there is no implementation for this pragma, but you will not get a warning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK that's fine I thought you will remove the GCC part fully but how it is implemented now it's IMO fine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK great! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I filed a bugreport to GCC, asking to have the feature implemented: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102855

# endif
#endif