Skip to content
Snippets Groups Projects
Commit 5df3d68a authored by Pietro Incardona's avatar Pietro Incardona
Browse files

GitLab CI test

parent c751d466
No related branches found
No related tags found
No related merge requests found
Pipeline #303 failed
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"
......@@ -3,5 +3,5 @@
#include <boost/test/included/unit_test.hpp>
#include "config.h"
#include "memory/HeapMemory_unit_tests.hpp"
#include "memory/Memory_unit_tests.hpp"
......@@ -44,7 +44,8 @@ typedef unsigned char byte;
* \snippet HeapMemory_unit_tests.hpp BShrink memory
*
*/
class BHeapMemory : public HeapMemory
template<typename Memory>
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<Memory> & 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<Memory> && 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<Memory> & mem)
{
buf_sz = mem.buf_sz;
static_cast<HeapMemory *>(this)->operator=(mem);
static_cast<Memory *>(this)->operator=(mem);
return *this;
}
......@@ -163,10 +164,10 @@ public:
* \return itself
*
*/
BHeapMemory & operator=(BHeapMemory && mem)
BMemory & operator=(BMemory<Memory> && mem)
{
buf_sz = mem.buf_sz;
static_cast<HeapMemory *>(this)->operator=(mem);
static_cast<Memory *>(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<Memory> & mem)
{
HeapMemory::swap(mem);
Memory::swap(mem);
size_t buf_sz_t = mem.buf_sz;
mem.buf_sz = buf_sz;
......
......@@ -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;
}
......@@ -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
......
......@@ -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<Mem> & 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
......
......@@ -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;
}
};
......
/*
* 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<typename T> 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<typename T> 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<typename T> 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<HeapMemory>();
#ifdef CUDA_GPU
test<CudaMemory>();
#endif
}
BOOST_AUTO_TEST_CASE( use_memory )
{
test<HeapMemory>();
#ifdef CUDA_GPU
test<CudaMemory>();
#endif
}
BOOST_AUTO_TEST_CASE( use_bheap_memory )
{
Btest<BHeapMemory>();
}
BOOST_AUTO_TEST_CASE( swap_heap_memory )
{
Stest<HeapMemory>();
}
BOOST_AUTO_TEST_SUITE_END()
#endif /* HEAPMEMORY_UNIT_TESTS_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
......
......@@ -150,6 +150,7 @@ class memory
*
*/
virtual void fill(unsigned char c) = 0;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment