Skip to content
Snippets Groups Projects
Commit b54b65c2 authored by Markus Holzer's avatar Markus Holzer
Browse files

Merge branch 'codegen' into 'master'

Fix memory alignment bug in PackInfo codegen

See merge request walberla/walberla!698
parents e564829f bd5adb91
No related merge requests found
......@@ -25,6 +25,8 @@
#include "domain_decomposition/IBlock.h"
#include "communication/UniformPackInfo.h"
#include <memory>
#define FUNC_PREFIX
#ifdef __GNUC__
......@@ -52,7 +54,10 @@ public:
void unpackData(IBlock * receiver, stencil::Direction dir, mpi::RecvBuffer & buffer) {
const auto dataSize = size(dir, receiver);
unpack(dir, buffer.skip(dataSize), receiver);
auto bufferSize = dataSize + sizeof({{dtype}});
auto bufferPtr = reinterpret_cast<void*>(buffer.skip(bufferSize));
std::align(alignof({{dtype}}), dataSize, bufferPtr, bufferSize);
unpack(dir, reinterpret_cast<unsigned char*>(bufferPtr), receiver);
}
void communicateLocal(const IBlock * sender, IBlock * receiver, stencil::Direction dir) {
......@@ -65,7 +70,10 @@ public:
void packDataImpl(const IBlock * sender, stencil::Direction dir, mpi::SendBuffer & outBuffer) const {
const auto dataSize = size(dir, sender);
pack(dir, outBuffer.forward(dataSize), const_cast<IBlock*>(sender));
auto bufferSize = dataSize + sizeof({{dtype}});
auto bufferPtr = reinterpret_cast<void*>(outBuffer.forward(bufferSize));
std::align(alignof({{dtype}}), dataSize, bufferPtr, bufferSize);
pack(dir, reinterpret_cast<unsigned char*>(bufferPtr), const_cast<IBlock *>(sender));
}
void pack (stencil::Direction dir, unsigned char * buffer, IBlock * block) const;
......
......@@ -59,7 +59,7 @@ public:
void pack (stencil::Direction dir, unsigned char * buffer, IBlock * block, gpuStream_t stream) override;
void communicateLocal ( stencil::Direction /*dir*/, const IBlock* /* sender */, IBlock* /* receiver */, gpuStream_t /* stream */ ) override
{
WALBERLA_ABORT("Local Communication not implemented yet for standard PackInfos. To run your application turn of local communication in the Communication class")
WALBERLA_ABORT("Local Communication not implemented yet for standard PackInfos. To run your application, turn off local communication in the communication class, e.g. with useLocalCommunication=false")
}
void unpack(stencil::Direction dir, unsigned char * buffer, IBlock * block, gpuStream_t stream) override;
uint_t size (stencil::Direction dir, IBlock * block) override;
......
......@@ -100,6 +100,10 @@ public:
*
* If NOT thread-safe, \ref threadsafeReceiving must return false!
*
* Implementations must reserve extra space and advance the send buffer
* pointer according to the alignment of the ghost layer data type!
* The buffer is char-aligned.
*
* @param receiver the block where the unpacked data should be stored into
* @param dir receive data from neighbor in this direction
* @param buffer buffer for reading the data from
......@@ -145,6 +149,10 @@ protected:
*
* Must be thread-safe!
*
* Implementations must reserve extra space and advance the send buffer
* pointer according to the alignment of the ghost layer data type!
* The buffer is char-aligned.
*
* @param sender the block whose data should be packed into a buffer
* @param dir pack data for neighbor in this direction
* @param buffer buffer for writing the data into
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment