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

Data Alignment for Kernel Parameters: 16 Byte #1566

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
27 changes: 13 additions & 14 deletions src/libPMacc/include/pmacc_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#pragma once

#include "debug/PMaccVerbose.hpp"
#include "ppFunctions.hpp"

#define BOOST_MPL_LIMIT_VECTOR_SIZE 20
#define BOOST_MPL_LIMIT_MAP_SIZE 20
Expand Down Expand Up @@ -172,20 +173,18 @@ enum EventType

#define CUDA_CHECK_NO_EXCEP(cmd) {cudaError_t error = cmd; if(error!=cudaSuccess){ PMACC_PRINT_CUDA_ERROR(""); }}

/* calculate and set the optimal alignment for data
* you must align all array and structs which can used on device
* @param byte byte of data which must aligned
*/
#define __optimal_align__(byte) \
__align__( \
((byte)==1?1: \
((byte)<=2?2: \
((byte)<=4?4: \
((byte)<=8?8: \
((byte)<=16?16: \
((byte)<=32?32: \
((byte)<=64?64:128 \
))))))))
/** calculate and set the optimal alignment for data
*
* you must align all arrays and structs that are used on the device
* @param byte size of data in bytes
*/
#define __optimal_align__(byte) \
__align__( \
/** \bug avoid bug if alignment is >16 byte \
* https://github.com/ComputationalRadiationPhysics/picongpu/issues/1563 \
*/ \
PMACC_MIN(PMACC_ROUND_UP_NEXT_POW2(byte),16) \
)

#define PMACC_ALIGN(var,...) __optimal_align__(sizeof(__VA_ARGS__)) __VA_ARGS__ var
#define PMACC_ALIGN8(var,...) __align__(8) __VA_ARGS__ var
Expand Down
19 changes: 19 additions & 0 deletions src/libPMacc/include/ppFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,22 @@
* @return false if no arguments are given, else true
*/
#define PMACC_HAS_ARGS(...) ((sizeof((int[]){0, ##__VA_ARGS__}))==sizeof(int)?false:true)

/** round up to next higher pow 2 value
*
* - if value is pow2, value is returned
* - maximal pow 2 value is 128
* - negative values are not supported
*
* @param value integral number between [1,Inf]
* @return next higher pow 2 value
*/
#define PMACC_ROUND_UP_NEXT_POW2(value) \
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to mention, that this is for UNSIGNED numbers only.

Copy link
Member Author

Choose a reason for hiding this comment

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

thx I will extent the description

((value)==1?1: \
((value)<=2?2: \
((value)<=4?4: \
((value)<=8?8: \
((value)<=16?16: \
((value)<=32?32: \
((value)<=64?64:128 \
)))))))