From 5df3d68aa869f2566bd82bf5627a32476154bfa3 Mon Sep 17 00:00:00 2001 From: Pietro Incardona Date: Tue, 21 Aug 2018 11:34:35 +0200 Subject: [PATCH] GitLab CI test --- .gitlab-ci.yml | 45 +++++ src/main.cpp | 2 +- src/memory/BHeapMemory.hpp | 35 ++-- src/memory/CudaMemory.cu | 31 ++++ src/memory/CudaMemory.cuh | 18 +- src/memory/ExtPreAlloc.hpp | 19 ++- src/memory/HeapMemory.hpp | 16 +- src/memory/HeapMemory_unit_tests.hpp | 245 --------------------------- src/memory/PtrMemory.hpp | 16 +- src/memory/memory.hpp | 1 + 10 files changed, 154 insertions(+), 274 deletions(-) create mode 100644 .gitlab-ci.yml delete mode 100644 src/memory/HeapMemory_unit_tests.hpp diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..1e81267 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,45 @@ +centos_build: + stage: build + tags: + - centos + script: + - sh "./build.sh $CI_PROJECT_DIR $CI_SERVER_NAME" + +centos_run: + stage: run + tags: + - centos + script: + - sh "./src/mem" + - sh "./success.sh 2 centos openfpm_devices" + +mac_build: + stage: build + tags: + - mac + script: + - sh "./build.sh $CI_PROJECT_DIR $CI_SERVER_NAME" + +mac_run: + stage: run + tags: + - mac + script: + - sh "./src/mem" + - sh "./success.sh 2 mac openfpm_devices" + +ubuntu_build: + stage: build + tags: + - ubuntu + script: + - sh "./build.sh $CI_PROJECT_DIR $CI_SERVER_NAME" + +ubuntu_run: + stage: run + tags: + - ubuntu + script: + - sh "./src/mem" + - sh "./success.sh 2 ubuntu openfpm_devices" + diff --git a/src/main.cpp b/src/main.cpp index 22b7076..02c7bda 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,5 +3,5 @@ #include #include "config.h" -#include "memory/HeapMemory_unit_tests.hpp" +#include "memory/Memory_unit_tests.hpp" diff --git a/src/memory/BHeapMemory.hpp b/src/memory/BHeapMemory.hpp index 23220b4..3775775 100644 --- a/src/memory/BHeapMemory.hpp +++ b/src/memory/BHeapMemory.hpp @@ -44,7 +44,8 @@ typedef unsigned char byte; * \snippet HeapMemory_unit_tests.hpp BShrink memory * */ -class BHeapMemory : public HeapMemory +template +class BMemory : public Memory { //! size of the memory size_t buf_sz; @@ -56,7 +57,7 @@ public: * \param mem memory to copy * */ - BHeapMemory(const BHeapMemory & mem) + BMemory(const BMemory & mem) :HeapMemory(mem),buf_sz(mem.size()) { } @@ -66,18 +67,18 @@ public: * \param mem memory to copy * */ - BHeapMemory(BHeapMemory && mem) noexcept - :HeapMemory((HeapMemory &&)mem),buf_sz(mem.size()) + BMemory(BMemory && mem) noexcept + :Memory((Memory &&)mem),buf_sz(mem.size()) { } //! Constructor, we choose a default alignment of 32 for avx - BHeapMemory() - :HeapMemory(),buf_sz(0) + BMemory() + :Memory(),buf_sz(0) {}; //! Destructor - virtual ~BHeapMemory() noexcept + virtual ~BMemory() noexcept { }; @@ -92,7 +93,7 @@ public: */ virtual bool allocate(size_t sz) { - bool ret = HeapMemory::allocate(sz); + bool ret = Memory::allocate(sz); if (ret == true) buf_sz = sz; @@ -111,7 +112,7 @@ public: */ virtual bool resize(size_t sz) { - bool ret = HeapMemory::resize(sz); + bool ret = Memory::resize(sz); // if the allocated memory is enough, do not resize if (ret == true) @@ -138,7 +139,7 @@ public: */ size_t msize() { - return HeapMemory::size(); + return Memory::size(); } /*! \brief Copy the memory @@ -148,10 +149,10 @@ public: * \return itself * */ - BHeapMemory & operator=(const BHeapMemory & mem) + BMemory & operator=(const BMemory & mem) { buf_sz = mem.buf_sz; - static_cast(this)->operator=(mem); + static_cast(this)->operator=(mem); return *this; } @@ -163,10 +164,10 @@ public: * \return itself * */ - BHeapMemory & operator=(BHeapMemory && mem) + BMemory & operator=(BMemory && mem) { buf_sz = mem.buf_sz; - static_cast(this)->operator=(mem); + static_cast(this)->operator=(mem); return *this; } @@ -177,7 +178,7 @@ public: */ void destroy() { - HeapMemory::destroy(); + Memory::destroy(); buf_sz = 0; } @@ -186,9 +187,9 @@ public: * \param mem Memory to swap with * */ - void swap(BHeapMemory & mem) + void swap(BMemory & mem) { - HeapMemory::swap(mem); + Memory::swap(mem); size_t buf_sz_t = mem.buf_sz; mem.buf_sz = buf_sz; diff --git a/src/memory/CudaMemory.cu b/src/memory/CudaMemory.cu index 5553824..522f66a 100644 --- a/src/memory/CudaMemory.cu +++ b/src/memory/CudaMemory.cu @@ -353,3 +353,34 @@ void * CudaMemory::getDevicePointerNoCopy() return dm; } +/*! \brief Swap the memory + * + * \param mem memory to swap + * + */ +void CudaMemory::swap(CudaMemory & mem) +{ + size_t sz_tmp; + void * dm_tmp; + long int ref_cnt_tmp; + bool is_hm_sync_tmp; + void * hm_tmp; + + hm_tmp = hm; + is_hm_sync_tmp = is_hm_sync; + sz_tmp = sz; + dm_tmp = dm; + ref_cnt_tmp = ref_cnt; + + hm = mem.hm; + is_hm_sync = mem.is_hm_sync; + sz = mem.sz; + dm = mem.dm; + ref_cnt = mem.ref_cnt; + + mem.hm = hm_tmp; + mem.is_hm_sync = is_hm_sync_tmp; + mem.sz = sz_tmp; + mem.dm = dm_tmp; + mem.ref_cnt = ref_cnt_tmp; +} diff --git a/src/memory/CudaMemory.cuh b/src/memory/CudaMemory.cuh index cdc0d21..a6a6502 100644 --- a/src/memory/CudaMemory.cuh +++ b/src/memory/CudaMemory.cuh @@ -60,14 +60,14 @@ class CudaMemory : public memory //! Allocate an host buffer void allocate_host(size_t sz) const; - //! copy from GPU to GPU buffer directly - bool copyDeviceToDevice(const CudaMemory & m); - //! copy from Pointer to GPU bool copyFromPointer(const void * ptr); public: + //! copy from GPU to GPU buffer directly + bool copyDeviceToDevice(const CudaMemory & m); + //! flush the memory virtual bool flush(); //! allocate memory @@ -180,6 +180,18 @@ public: else std::cerr << "Error: " << __FILE__ << " " << __LINE__ << " destroying a live object" << "\n"; }; + + void swap(CudaMemory & mem); + + /*! \brief Return true if the device and the host pointer are the same + * + * \return true if they are the same + * + */ + static bool isDeviceHostSame() + { + return false; + } }; #endif diff --git a/src/memory/ExtPreAlloc.hpp b/src/memory/ExtPreAlloc.hpp index 94bf807..06d8c65 100644 --- a/src/memory/ExtPreAlloc.hpp +++ b/src/memory/ExtPreAlloc.hpp @@ -65,6 +65,21 @@ public: mem.resize(size); } + /*! \brief Copy the memory from device to device + * + * \param m memory from where to copy + * + */ + bool copyDeviceToDevice(const ExtPreAlloc & m) + { + return mem->copyDeviceToDevice(*m.mem); + } + + static bool isDeviceHostSame() + { + return Mem::isDeviceHostSame(); + } + //! Increment the reference counter virtual void incRef() {ref_cnt++;} @@ -164,7 +179,7 @@ public: */ virtual void * getDevicePointer() { - return getDevicePointer(); + return mem->getDevicePointer(); } /*! \brief Return the pointer of the last allocation @@ -174,7 +189,7 @@ public: */ virtual void * getDevicePointerNoCopy() { - return getDevicePointerNoCopy(); + return mem->getDevicePointerNoCopy(); } //! Do nothing diff --git a/src/memory/HeapMemory.hpp b/src/memory/HeapMemory.hpp index a1dfc81..903edff 100644 --- a/src/memory/HeapMemory.hpp +++ b/src/memory/HeapMemory.hpp @@ -51,9 +51,6 @@ class HeapMemory : public memory //! Reference counter long int ref_cnt; - //! copy from same Heap to Heap - bool copyDeviceToDevice(const HeapMemory & m); - //! copy from Pointer to Heap bool copyFromPointer(const void * ptr, size_t sz); @@ -62,6 +59,9 @@ class HeapMemory : public memory public: + //! copy from same Heap to Heap + bool copyDeviceToDevice(const HeapMemory & m); + //! flush the memory virtual bool flush() {return true;}; //! allocate memory @@ -196,6 +196,16 @@ public: mem.dmOrig = dmOrig_tmp; mem.ref_cnt = ref_cnt_tmp; } + + /*! \brief Return true if the device and the host pointer are the same + * + * \return true if they are the same + * + */ + static bool isDeviceHostSame() + { + return true; + } }; diff --git a/src/memory/HeapMemory_unit_tests.hpp b/src/memory/HeapMemory_unit_tests.hpp deleted file mode 100644 index 06e09f4..0000000 --- a/src/memory/HeapMemory_unit_tests.hpp +++ /dev/null @@ -1,245 +0,0 @@ -/* - * HeapMemory_unit_tests.hpp - * - * Created on: Jul 9, 2015 - * Author: i-bird - */ - -#ifndef HEAPMEMORY_UNIT_TESTS_HPP_ -#define HEAPMEMORY_UNIT_TESTS_HPP_ - -#include "config.h" - -#include "memory/HeapMemory.hpp" -#include "memory/BHeapMemory.hpp" -#ifdef NVCC -#include "memory/CudaMemory.cuh" -#endif - -BOOST_AUTO_TEST_SUITE( HeapMemory_test ) - -//! [Memory test constants] -#define FIRST_ALLOCATION 1024ul -#define SECOND_ALLOCATION 4096ul -//! [Memory test constants] - -template void test() -{ - //! [Allocate some memory and fill with data] - T mem; - - BOOST_REQUIRE_EQUAL(mem.size(),0ul); - - mem.allocate(FIRST_ALLOCATION); - - BOOST_REQUIRE_EQUAL(mem.size(),FIRST_ALLOCATION); - - // get the pointer of the allocated memory and fill - - unsigned char * ptr = (unsigned char *)mem.getPointer(); - for (size_t i = 0 ; i < mem.size() ; i++) - {ptr[i] = i;} - - mem.flush(); - - //! [Allocate some memory and fill with data] - - //! [Resize the memory] - mem.resize(SECOND_ALLOCATION); - - unsigned char * ptr2 = (unsigned char *)mem.getPointer(); - - BOOST_REQUIRE_EQUAL(mem.size(),SECOND_ALLOCATION); - BOOST_REQUIRE_EQUAL(mem.isInitialized(),false); - - //! [Resize the memory] - - // check that the data are retained - for (size_t i = 0 ; i < FIRST_ALLOCATION ; i++) - { - unsigned char c = i; - BOOST_REQUIRE_EQUAL(ptr2[i],c); - } - - //! [Shrink memory] - - mem.resize(1); - BOOST_REQUIRE_EQUAL(mem.size(),SECOND_ALLOCATION); - - //! [Shrink memory] - - - { - //! [Copy memory] - T src; - T dst; - - src.allocate(FIRST_ALLOCATION); - dst.allocate(SECOND_ALLOCATION); - - unsigned char * ptr = (unsigned char *)src.getPointer(); - for (size_t i = 0 ; i < src.size() ; i++) - ptr[i] = i; - - dst.copy(src); - - for (size_t i = 0 ; i < FIRST_ALLOCATION ; i++) - { - unsigned char c=i; - BOOST_REQUIRE_EQUAL(ptr2[i],c); - } - - //! [Copy Memory] - } - - { - T src; - src.allocate(FIRST_ALLOCATION); - - unsigned char * ptr = (unsigned char *)src.getPointer(); - for (size_t i = 0 ; i < src.size() ; i++) - ptr[i] = i; - - src.flush(); - - T dst = src; - - unsigned char * ptr2 = (unsigned char *)dst.getPointer(); - - BOOST_REQUIRE(src.getPointer() != dst.getPointer()); - for (size_t i = 0 ; i < FIRST_ALLOCATION ; i++) - { - unsigned char c=i; - BOOST_REQUIRE_EQUAL(ptr2[i],c); - } - - mem.destroy(); - - BOOST_REQUIRE_EQUAL(mem.size(),0ul); - - mem.allocate(FIRST_ALLOCATION); - - BOOST_REQUIRE_EQUAL(mem.size(),FIRST_ALLOCATION); - - } -} - -template void Btest() -{ - //! [BAllocate some memory and fill with data] - T mem; - - mem.allocate(FIRST_ALLOCATION); - - BOOST_REQUIRE_EQUAL(mem.size(),FIRST_ALLOCATION); - - // get the pointer of the allocated memory and fill - - unsigned char * ptr = (unsigned char *)mem.getPointer(); - for (size_t i = 0 ; i < mem.size() ; i++) - ptr[i] = i; - - //! [BAllocate some memory and fill with data] - - //! [BResize the memory] - mem.resize(SECOND_ALLOCATION); - - unsigned char * ptr2 = (unsigned char *)mem.getPointer(); - - BOOST_REQUIRE_EQUAL(mem.size(),SECOND_ALLOCATION); - BOOST_REQUIRE_EQUAL(mem.isInitialized(),false); - - //! [BResize the memory] - - // check that the data are retained - for (size_t i = 0 ; i < FIRST_ALLOCATION ; i++) - { - unsigned char c = i; - BOOST_REQUIRE_EQUAL(ptr2[i],c); - } - - //! [BShrink memory] - - mem.resize(1); - BOOST_REQUIRE_EQUAL(mem.size(),1ul); - - //! [BShrink memory] - - mem.destroy(); - - BOOST_REQUIRE_EQUAL(mem.size(),0ul); - - mem.allocate(FIRST_ALLOCATION); - - BOOST_REQUIRE_EQUAL(mem.size(),FIRST_ALLOCATION); -} - - -template void Stest() -{ - T mem1; - T mem2; - - mem1.allocate(5*sizeof(size_t)); - mem2.allocate(6*sizeof(size_t)); - - BOOST_REQUIRE_EQUAL(mem1.size(),5*sizeof(size_t)); - BOOST_REQUIRE_EQUAL(mem2.size(),6*sizeof(size_t)); - - // get the pointer of the allocated memory and fill - - size_t * ptr1 = (size_t *)mem1.getPointer(); - size_t * ptr2 = (size_t *)mem2.getPointer(); - for (size_t i = 0 ; i < 5 ; i++) - ptr1[i] = i; - - for (size_t i = 0 ; i < 6 ; i++) - ptr2[i] = i+100; - - mem1.swap(mem2); - - bool ret = true; - ptr1 = (size_t *)mem2.getPointer(); - ptr2 = (size_t *)mem1.getPointer(); - for (size_t i = 0 ; i < 5 ; i++) - ret &= ptr1[i] == i; - - for (size_t i = 0 ; i < 6 ; i++) - ret &= ptr2[i] == i+100; - - BOOST_REQUIRE_EQUAL(ret,true); - - BOOST_REQUIRE_EQUAL(mem1.size(),6*sizeof(size_t)); - BOOST_REQUIRE_EQUAL(mem2.size(),5*sizeof(size_t)); -} - -BOOST_AUTO_TEST_CASE( use_heap_memory ) -{ - test(); -#ifdef CUDA_GPU - test(); -#endif -} - -BOOST_AUTO_TEST_CASE( use_memory ) -{ - test(); -#ifdef CUDA_GPU - test(); -#endif -} - -BOOST_AUTO_TEST_CASE( use_bheap_memory ) -{ - Btest(); -} - -BOOST_AUTO_TEST_CASE( swap_heap_memory ) -{ - Stest(); -} - -BOOST_AUTO_TEST_SUITE_END() - - -#endif /* HEAPMEMORY_UNIT_TESTS_HPP_ */ diff --git a/src/memory/PtrMemory.hpp b/src/memory/PtrMemory.hpp index f4c74b6..968a32a 100644 --- a/src/memory/PtrMemory.hpp +++ b/src/memory/PtrMemory.hpp @@ -50,9 +50,6 @@ class PtrMemory : public memory //! Reference counter long int ref_cnt; - //! copy from same Heap to Heap - bool copyDeviceToDevice(const PtrMemory & m); - //! copy from Pointer to Heap bool copyFromPointer(const void * ptr, size_t sz); @@ -61,6 +58,9 @@ class PtrMemory : public memory public: + //! copy from same Heap to Heap + bool copyDeviceToDevice(const PtrMemory & m); + //! flush the memory virtual bool flush() {return true;}; //! allocate memory @@ -111,6 +111,16 @@ public: return ref_cnt; } + /*! \brief Return true if the device and the host pointer are the same + * + * \return true if they are the same + * + */ + static bool isDeviceHostSame() + { + return true; + } + /*! \brief Allocated Memory is already initialized * * \return true diff --git a/src/memory/memory.hpp b/src/memory/memory.hpp index 333d1e4..1f3d48f 100644 --- a/src/memory/memory.hpp +++ b/src/memory/memory.hpp @@ -150,6 +150,7 @@ class memory * */ virtual void fill(unsigned char c) = 0; + }; #endif -- GitLab