Commit d88f0b1f authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Added serialize/deserialize for GPU fields

parent 599a2fe8
Pipeline #32014 failed with stages
in 347 minutes and 2 seconds
......@@ -28,9 +28,12 @@
#include "core/math/Vector2.h"
#include "core/math/Vector3.h"
#include "cuda/GPUCopy.h"
#include "domain_decomposition/BlockDataHandling.h"
#include "field/FlagField.h"
#include "field/Layout.h"
#include <type_traits>
......@@ -43,7 +46,7 @@ template< typename GpuField_T >
class GPUBlockDataHandling : public domain_decomposition::BlockDataHandling< GpuField_T >
{
public:
using Value_T = typename GpuField_T::value_type;
using value_type = typename GpuField_T::value_type;
typedef std::function< void(GpuField_T* field, IBlock* const block) > InitializationFunction_T;
virtual ~GPUBlockDataHandling() = default;
......@@ -73,19 +76,52 @@ class GPUBlockDataHandling : public domain_decomposition::BlockDataHandling< Gpu
}; // class GPUBlockDataHandling
template< typename GpuField_T >
void GPUBlockDataHandling< GpuField_T >::serialize(IBlock* const /*block*/, const BlockDataID& /*id*/,
mpi::SendBuffer& /*buffer*/)
void GPUBlockDataHandling< GpuField_T >::serialize(IBlock* const block, const BlockDataID& id, mpi::SendBuffer& buffer)
{
// TODO: Serialize to CPU buffer
WALBERLA_ABORT("Serialization of GPU fields not yet implemented.");
GpuField_T* gpuField = block->getData< GpuField_T >(id);
uint_t fieldBytes = gpuField->sizeWithGhostLayer() * sizeof(value_type);
cudaPitchedPtr src = gpuField->pitchedPtr();
unsigned char* dst = buffer.forward(fieldBytes);
std::tuple< uint_t, uint_t, uint_t > copyInterval =
std::make_tuple(gpuField->xSizeWithGhostLayer(), gpuField->ySizeWithGhostLayer(), gpuField->zSizeWithGhostLayer(),
gpuField->fSize());
if (gpuField->layout() == field::Layout::fzyx)
{
cuda::copyDevToHostFZYX(dst, src, std::make_tuple(uint_t(0), uint_t(0), uint_t(0)),
std::make_tuple(uint_t(0), uint_t(0), uint_t(0)), gpuField->zSizeWithGhostLayer(),
gpuField->zAllocSize(), sizeof(value_type), copyInterval, nullptr);
}
else
{
cuda::copyDevToHostZYXF(dst, src, std::make_tuple(uint_t(0), uint_t(0), uint_t(0)),
std::make_tuple(uint_t(0), uint_t(0), uint_t(0)), gpuField->ySizeWithGhostLayer(),
gpuField->yAllocSize(), sizeof(value_type), copyInterval, nullptr);
}
}
template< typename GpuField_T >
void GPUBlockDataHandling< GpuField_T >::deserialize(IBlock* const /*block*/, const BlockDataID& /*id*/,
mpi::RecvBuffer& /*buffer*/)
void GPUBlockDataHandling< GpuField_T >::deserialize(IBlock* const block, const BlockDataID& id,
mpi::RecvBuffer& buffer)
{
// TODO: Deserialize from CPU buffer
WALBERLA_ABORT("Deserialization of GPU fields not yet implemented.");
GpuField_T* gpuField = block->getData< GpuField_T >(id);
uint_t fieldBytes = gpuField->sizeWithGhostLayer() * sizeof(value_type);
unsigned char* src = buffer.skip(fieldBytes);
cudaPitchedPtr dst = gpuField->pitchedPtr();
std::tuple< uint_t, uint_t, uint_t > copyInterval =
std::make_tuple(gpuField->xSizeWithGhostLayer(), gpuField->ySizeWithGhostLayer(), gpuField->zSizeWithGhostLayer(),
gpuField->fSize());
if (gpuField->layout() == field::Layout::fzyx)
{
cuda::copyHostToDevFZYX(dst, src, std::make_tuple(uint_t(0), uint_t(0), uint_t(0)),
std::make_tuple(uint_t(0), uint_t(0), uint_t(0)), gpuField->zAllocSize(),
gpuField->zSizeWithGhostLayer(), sizeof(value_type), copyInterval, nullptr);
}
else
{
cuda::copyHostToDevZYXF(dst, src, std::make_tuple(uint_t(0), uint_t(0), uint_t(0)),
std::make_tuple(uint_t(0), uint_t(0), uint_t(0)), gpuField->yAllocSize(),
gpuField->ySizeWithGhostLayer(), sizeof(value_type), copyInterval, nullptr);
}
}
} // namespace cuda
......
Markdown is supported
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