Commit e57d9bd5 authored by incardon's avatar incardon

Working

parents 90080116 98033dea
......@@ -47,8 +47,8 @@ fi
prefix="$prefix/openfpm_devices"
echo "Installation dir is: $prefix"
AC_PROG_RANLIB
AM_PROG_AR
LT_INIT
AC_SUBST([LIBTOOL_DEPS])
# Checks for programs.
AC_PROG_CXX
......
......@@ -7,6 +7,10 @@ endif
LINKLIBS = $(PTHREAD_LIBS) $(OPT_LIBS) $(BOOST_LDFLAGS) $(BOOST_PROGRAM_OPTIONS_LIB) $(CUDA_LIBS) $(BOOST_THREAD_LIB)
LIBTOOL_DEPS = @LIBTOOL_DEPS@
libtool: $(LIBTOOL_DEPS)
$(SHELL) ./config.status libtool
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
......@@ -22,6 +26,16 @@ libofpmmemory_se2_a_SOURCES = memory/HeapMemory.cpp $(CUDA_SOURCES) memory/PtrMe
libofpmmemory_se2_a_CXXFLAGS = $(INCLUDES_PATH) $(BOOST_CPPFLAGS) -I/usr/local/include -DSE_CLASS2
libofpmmemory_se2_a_CFLAGS =
lib_LTLIBRARIES = libofpmmemory.la libofpmmemory_se2.la
libofpmmemory_la_SOURCES = memory/HeapMemory.cpp $(CUDA_SOURCES) memory/PtrMemory.cpp Memleak_check.cpp
libofpmmemory_la_CXXFLAGS = $(INCLUDES_PATH) $(BOOST_CPPFLAGS) -I/usr/local/include
libofpmmemory_la_CFLAGS =
libofpmmemory_se2_la_SOURCES = memory/HeapMemory.cpp $(CUDA_SOURCES) memory/PtrMemory.cpp Memleak_check.cpp
libofpmmemory_se2_la_CXXFLAGS = $(INCLUDES_PATH) $(BOOST_CPPFLAGS) -I/usr/local/include -DSE_CLASS2
libofpmmemory_se2_la_CFLAGS =
nobase_include_HEADERS = memory/ExtPreAlloc.hpp memory/BHeapMemory.hpp memory/HeapMemory.hpp memory/memory.hpp memory/PtrMemory.hpp \
Memleak_check.hpp util/print_stack.hpp ptr_info.hpp \
util/se_util.hpp
......
......@@ -275,8 +275,13 @@ void CudaMemory::deviceToHost()
CUDA_SAFE_CALL(cudaMemcpy(hm,dm,sz,cudaMemcpyDeviceToHost));
}
<<<<<<< HEAD
=======
>>>>>>> 98033dea8fd01877d50de6bb96078f8b373a4c5a
/*! \brief Return a readable pointer with your data
*
* \return a readable pointer with your data
......@@ -314,6 +319,7 @@ void * CudaMemory::getDevicePointer()
return dm;
}
<<<<<<< HEAD
/*! \brief Return the CUDA device pointer (Do not copy to device)
*
* \return CUDA device pointer
......@@ -323,4 +329,6 @@ void * CudaMemory::getDevicePointerNoCopy()
{
return dm;
}
=======
>>>>>>> 98033dea8fd01877d50de6bb96078f8b373a4c5a
......@@ -8,6 +8,8 @@
#define EXTPREALLOC_HPP_
#include <stddef.h>
#include "memory.hpp"
#include <iostream>
/*! Preallocated memory sequence
*
......@@ -24,14 +26,15 @@
template<typename Mem>
class ExtPreAlloc : public memory
{
// Actual allocation pointer
//! Actual allocation pointer
size_t a_seq ;
// Last allocation size
//! Last allocation size
size_t l_size;
// Main class for memory allocation
//! Main class for memory allocation
Mem * mem;
//! Reference counter
long int ref_cnt;
......@@ -92,11 +95,10 @@ public:
if (sz == 0)
return true;
// Check that the size match
a_seq = l_size;
l_size += sz;
// Check we do not overflow the allocated memory
#ifdef SE_CLASS1
if (l_size > mem->size())
......@@ -107,6 +109,25 @@ public:
return true;
}
/*! \brief Allocate a chunk of memory
*
* Allocate a chunk of memory
*
* \param sz size of the chunk of memory to allocate in byte
*
*/
bool allocate_nocheck(size_t sz)
{
// Zero sized allocation are ignored
if (sz == 0)
return true;
a_seq = l_size;
l_size += sz;
return true;
}
/*! \brief Return the end pointer of the previous allocated memory
*
* \return the pointer
......@@ -250,6 +271,63 @@ public:
return s;
}
/*! \brief shift the pointer backward
*
* \warning when you shift backward the pointer, the last allocation is lost
* this mean that you have to do again an allocation.
*
* This function is useful to go ahead in memory and fill the memory later on
*
* \code
mem.allocate(16); <------ Here we allocate 16 byte but we do not fill it because
subsequently we do another allocation without using mem
unsigned char * start = (unsigned char *)mem.getPointer()
mem.allocate(100)
// ...
// ...
// Code that fill mem in some way and do other mem.allocate(...)
// ...
// ...
unsigned char * final = (unsigned char *)mem.getPointer()
mem.shift_backward(final - start);
mem.allocate(16); <------ Here I am getting the same memory that I request for the
first allocate
// we now fill the memory
\endcode
*
*
*
* \param how many byte to shift
*
*/
void shift_backward(size_t sz)
{
a_seq -= sz;
l_size = a_seq;
}
/*! \brief shift the pointer forward
*
* The same as shift backward, but in this case it move the pointer forward
*
* In general you use this function after the you went back with shift_backward
* and you have to move forward again
*
* \warning when you shift forward the pointer, the last allocation is lost
* this mean that you have to do again an allocation.
*
*/
void shift_forward(size_t sz)
{
a_seq += sz;
l_size = a_seq;
}
};
#endif /* PREALLOCHEAPMEMORY_HPP_ */
......@@ -11,6 +11,8 @@
#include <iostream>
#include <cstdint>
static const int extra_pad = 512;
// If debugging mode include memory leak check
#ifdef SE_CLASS2
#include "Memleak_check.hpp"
......@@ -26,7 +28,7 @@ bool HeapMemory::allocate(size_t sz)
{
//! Allocate the device memory
if (dm == NULL)
dmOrig = new byte[sz+alignement];
dmOrig = new byte[sz+alignement+extra_pad];
else
std::cerr << __FILE__ << ":" << __LINE__ << " error memory already allocated\n";
......@@ -180,7 +182,7 @@ bool HeapMemory::resize(size_t sz)
//! Create a new buffer if sz is bigger than the actual size
byte * tdm;
byte * tdmOrig;
tdmOrig = new byte[sz+alignement];
tdmOrig = new byte[sz+alignement+extra_pad];
#ifdef SE_CLASS2
check_new(tdmOrig,sz+alignement,HEAPMEMORY_EVENT,0);
#endif
......@@ -242,7 +244,6 @@ void * HeapMemory::getDevicePointerNoCopy()
* Return a readable pointer with your data
*
*/
void * HeapMemory::getPointer()
{
return dm;
......
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