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

Fixing low level bug on ExtPreAlloc and HeapMemory + adding detection of such mistake

parent 52cee143
No related branches found
No related tags found
No related merge requests found
SUBDIRS = src
LINKLIBS = $(PTHREAD_LIBS) $(OPT_LIBS) $(BOOST_LDFLAGS) $(BOOST_PROGRAM_OPTIONS_LIB) $(CUDA_LIBS) $(BOOST_THREAD_LIB)
if BUILDCUDA
CUDA_SOURCES=memory/CudaMemory.cu
else
CUDA_SOURCES=
endif
noinst_PROGRAMS = mem
mem_SOURCES = main.cpp memory/HeapMemory.cpp $(CUDA_SOURCES) Memleak_check.cpp
mem_CXXFLAGS = $(INCLUDES_PATH) $(BOOST_CPPFLAGS) -I/usr/local/include
mem_CFLAGS =
mem_LDADD = $(LINKLIBS) -L/usr/lib64/nvidia-bumblebee/
lib_LIBRARIES = libofpmmemory.a libofpmmemory_se2.a
libofpmmemory_a_SOURCES = memory/HeapMemory.cpp $(CUDA_SOURCES) memory/PtrMemory.cpp Memleak_check.cpp
libofpmmemory_a_CXXFLAGS = $(INCLUDES_PATH) $(BOOST_CPPFLAGS) -I/usr/local/include
libofpmmemory_a_CFLAGS =
libofpmmemory_se2_a_SOURCES = memory/HeapMemory.cpp $(CUDA_SOURCES) memory/PtrMemory.cpp Memleak_check.cpp
libofpmmemory_se2_a_CXXFLAGS = $(INCLUDES_PATH) $(BOOST_CPPFLAGS) -I/usr/local/include -DSE_CLASS2
libofpmmemory_se2_a_CFLAGS =
nobase_include_HEADERS = memory/ExtPreAlloc.hpp memory/HeapMemory.hpp memory/memory.hpp memory/PreAllocHeapMemory.hpp memory/PtrMemory.hpp \
Memleak_check.hpp ptr_info.hpp \
util/se_util.hpp
.cu.o :
$(NVCC) $(NVCCFLAGS) -I. $(INCLUDES_PATH) -o $@ -c $<
bin_PROGRAMS =
\ No newline at end of file
......@@ -44,7 +44,7 @@ class ExtPreAlloc : public memory
public:
~ExtPreAlloc()
virtual ~ExtPreAlloc()
{
if (ref_cnt != 0)
std::cerr << "Error: " << __FILE__ << " " << __LINE__ << " destroying a live object" << "\n";
......@@ -94,7 +94,7 @@ public:
sequence_c[j] = total_size;
// Allocate the total size of memory
mem.allocate(total_size);
mem.resize(total_size);
}
//! Increment the reference counter
......
......@@ -27,6 +27,9 @@ bool HeapMemory::allocate(size_t sz)
//! Allocate the device memory
if (dm == NULL)
dmOrig = new byte[sz+alignement];
else
std::cerr << "Error memory already allocated\n";
dm = dmOrig;
#ifdef SE_CLASS2
......@@ -58,12 +61,12 @@ void HeapMemory::setAlignment(size_t align)
*/
void HeapMemory::destroy()
{
if (dmOrig != NULL)
delete [] dmOrig;
#ifdef SE_CLASS2
check_delete(dmOrig);
#endif
if (dmOrig != NULL)
delete [] dmOrig;
}
......@@ -76,6 +79,10 @@ bool HeapMemory::copyFromPointer(void * ptr,size_t sz)
{
// memory copy
#ifdef SE_CLASS2
check_valid(dm,sz);
check_valid(ptr,sz);
#endif
memcpy(dm,ptr,sz);
return true;
......@@ -98,6 +105,10 @@ bool HeapMemory::copyDeviceToDevice(HeapMemory & m)
return false;
}
#ifdef SE_CLASS2
check_valid(dm,sz);
check_valid(m.dm,sz);
#endif
// Copy the memory from m
memcpy(dm,m.dm,m.sz);
return true;
......@@ -176,15 +187,19 @@ bool HeapMemory::resize(size_t sz)
//! size plus alignment
size_t sz_a = sz+alignement;
this->sz = sz;
//! align it
align(alignement,1,(void *&)tdm,sz_a);
//! copy from the old buffer to the new one
#ifdef SE_CLASS2
check_valid(tdm,size());
check_valid(dm,size());
#endif
memcpy(tdm,dm,size());
this->sz = sz;
//! free the old buffer
destroy();
......
......@@ -100,7 +100,7 @@ public:
//! Constructor, we choose a default alignment of 32 for avx
HeapMemory():alignement(MEM_ALIGNMENT),sz(0),dm(NULL),dmOrig(NULL),ref_cnt(0) {};
~HeapMemory()
virtual ~HeapMemory()
{
if(ref_cnt == 0)
destroy();
......
......@@ -18,8 +18,8 @@
BOOST_AUTO_TEST_SUITE( HeapMemory_test )
//! [Memory test constants]
#define FIRST_ALLOCATION 1024
#define SECOND_ALLOCATION 4096
#define FIRST_ALLOCATION 1024ul
#define SECOND_ALLOCATION 4096ul
//! [Memory test constants]
template<typename T> void test()
......
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