From 7f880430cc8e2eb5cb70aef1303f3ba64debddb3 Mon Sep 17 00:00:00 2001 From: Helen Schottenhamml <helen.schottenhamml@fau.de> Date: Tue, 9 Nov 2021 10:22:31 +0000 Subject: [PATCH] Clean CUDA communication module --- src/cuda/communication/CustomMemoryBuffer.h | 8 ++++---- src/cuda/communication/CustomMemoryBuffer.impl.h | 14 ++++++-------- src/cuda/communication/MemcpyPackInfo.h | 8 ++++---- src/cuda/communication/MemcpyPackInfo.impl.h | 6 +++--- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/cuda/communication/CustomMemoryBuffer.h b/src/cuda/communication/CustomMemoryBuffer.h index d0e8bdff9..2caab2a41 100644 --- a/src/cuda/communication/CustomMemoryBuffer.h +++ b/src/cuda/communication/CustomMemoryBuffer.h @@ -100,13 +100,13 @@ namespace communication { static void *allocate( size_t size ) { void *p; - WALBERLA_CUDA_CHECK( cudaMallocHost( &p, size )); + WALBERLA_CUDA_CHECK( cudaMallocHost( &p, size )) return p; } static void deallocate( void *ptr ) { - WALBERLA_CUDA_CHECK( cudaFreeHost( ptr )); + WALBERLA_CUDA_CHECK( cudaFreeHost( ptr )) } static void memcpy( void *dst, void *src, size_t count ) @@ -120,13 +120,13 @@ namespace communication { static void *allocate( size_t size ) { void *p; - WALBERLA_CUDA_CHECK( cudaMalloc( &p, size )); + WALBERLA_CUDA_CHECK( cudaMalloc( &p, size )) return p; } static void deallocate( void *ptr ) { - WALBERLA_CUDA_CHECK( cudaFree( ptr )); + WALBERLA_CUDA_CHECK( cudaFree( ptr )) } static void memcpy( void *dst, void *src, size_t count ) diff --git a/src/cuda/communication/CustomMemoryBuffer.impl.h b/src/cuda/communication/CustomMemoryBuffer.impl.h index 3d7715f89..21d70e4cc 100644 --- a/src/cuda/communication/CustomMemoryBuffer.impl.h +++ b/src/cuda/communication/CustomMemoryBuffer.impl.h @@ -26,14 +26,10 @@ namespace communication { template<typename Allocator> - CustomMemoryBuffer<Allocator>::CustomMemoryBuffer() - : begin_( nullptr ), cur_( nullptr ), end_( nullptr ) - { - } + CustomMemoryBuffer<Allocator>::CustomMemoryBuffer() = default; template<typename Allocator> CustomMemoryBuffer<Allocator>::CustomMemoryBuffer( std::size_t initSize ) - : begin_( nullptr ), cur_( nullptr ), end_( nullptr ) { if( initSize > 0 ) { @@ -45,7 +41,6 @@ namespace communication { template<typename Allocator> CustomMemoryBuffer<Allocator>::CustomMemoryBuffer( const CustomMemoryBuffer &pb ) - : begin_( nullptr ), cur_( nullptr ), end_( nullptr ) { if( pb.begin_ != nullptr ) { @@ -59,7 +54,10 @@ namespace communication { template<typename Allocator> CustomMemoryBuffer<Allocator> &CustomMemoryBuffer<Allocator>::operator=( const CustomMemoryBuffer<Allocator> &pb ) { - auto copy( pb ); + if( this == &pb ) + return *this; + + CustomMemoryBuffer<Allocator> copy( pb ); std::swap( cur_, copy.cur_ ); std::swap( begin_, copy.begin_ ); std::swap( end_, copy.end_ ); @@ -105,7 +103,7 @@ namespace communication { resize( size() + bytes ); auto result = cur_; cur_ += bytes; - WALBERLA_ASSERT_LESS_EQUAL( cur_, end_ ); + WALBERLA_ASSERT_LESS_EQUAL( cur_, end_ ) return result; } diff --git a/src/cuda/communication/MemcpyPackInfo.h b/src/cuda/communication/MemcpyPackInfo.h index 8d85b7f1a..20637b51a 100644 --- a/src/cuda/communication/MemcpyPackInfo.h +++ b/src/cuda/communication/MemcpyPackInfo.h @@ -19,11 +19,11 @@ public: MemcpyPackInfo( BlockDataID pdfsID_ ) : pdfsID(pdfsID_), numberOfGhostLayers_(0), communicateAllGhostLayers_(true) {}; - virtual ~MemcpyPackInfo() {}; + virtual ~MemcpyPackInfo() = default; - virtual void pack (stencil::Direction dir, unsigned char * buffer, IBlock * block, cudaStream_t stream); - virtual void unpack(stencil::Direction dir, unsigned char * buffer, IBlock * block, cudaStream_t stream); - virtual uint_t size(stencil::Direction dir, IBlock * block); + void pack (stencil::Direction dir, unsigned char * buffer, IBlock * block, cudaStream_t stream) override; + void unpack(stencil::Direction dir, unsigned char * buffer, IBlock * block, cudaStream_t stream) override; + uint_t size(stencil::Direction dir, IBlock * block) override; private: BlockDataID pdfsID; diff --git a/src/cuda/communication/MemcpyPackInfo.impl.h b/src/cuda/communication/MemcpyPackInfo.impl.h index 166a76112..b75587c5b 100644 --- a/src/cuda/communication/MemcpyPackInfo.impl.h +++ b/src/cuda/communication/MemcpyPackInfo.impl.h @@ -20,7 +20,7 @@ void MemcpyPackInfo< GPUFieldType >::pack(stencil::Direction dir, unsigned char { // Extract field data pointer from the block const GPUFieldType * fieldPtr = block->getData< GPUFieldType >( pdfsID ); - WALBERLA_ASSERT_NOT_NULLPTR( fieldPtr ); + WALBERLA_ASSERT_NOT_NULLPTR( fieldPtr ) // cell_idx_t nrOfGhostLayers = cell_idx_c( numberOfGhostLayersToCommunicate( fieldPtr ) ); CellInterval fieldCi = field::getGhostRegion( *fieldPtr, dir, nrOfGhostLayers, false ); @@ -70,7 +70,7 @@ void MemcpyPackInfo< GPUFieldType >::unpack(stencil::Direction dir, unsigned cha IBlock * block, cudaStream_t stream) { GPUFieldType * fieldPtr = block->getData< GPUFieldType >( pdfsID ); - WALBERLA_ASSERT_NOT_NULLPTR(fieldPtr); + WALBERLA_ASSERT_NOT_NULLPTR(fieldPtr) cell_idx_t nrOfGhostLayers = cell_idx_c( numberOfGhostLayersToCommunicate( fieldPtr ) ); @@ -221,7 +221,7 @@ uint_t MemcpyPackInfo< GPUFieldType >::numberOfGhostLayersToCommunicate( const G } else { - WALBERLA_ASSERT_LESS_EQUAL( numberOfGhostLayers_, field->nrOfGhostLayers() ); + WALBERLA_ASSERT_LESS_EQUAL( numberOfGhostLayers_, field->nrOfGhostLayers() ) return numberOfGhostLayers_; } } -- GitLab