8 #include <boost/multi_array.hpp>
9 #include <boost/fusion/mpl.hpp>
10 #include <boost/fusion/include/mpl.hpp>
11 #include <boost/mpl/vector.hpp>
13 #include <boost/mpl/pop_front.hpp>
14 #include <boost/mpl/push_front.hpp>
17 #include "util/multi_array_openfpm/multi_array_ref_openfpm.hpp"
18 #include "util/ct_array.hpp"
19 #include "memory_array.hpp"
20 #include "memory/memory.hpp"
25 #define MEMORY_C_STANDARD 1
26 #define MEMORY_C_REDUCED 2
28 template<
typename T,
unsigned int impl = MEMORY_C_STANDARD,
typename D = memory>
44 template<
typename T,
typename D>
52 bool manage_memory =
true;
80 if (this->mem != NULL)
84 if (this->mem->
ref() == 0 && &mem != this->mem)
136 bool allocate(
const size_t sz,
bool skip_initialization =
false)
141 mem->
resize( sz*
sizeof(T) );
151 :manage_memory(manage_memory),mem(NULL){}
175 manage_memory =
false;
187 void * mem_tmp =
static_cast<void*
>(mem);
189 mem_obj.mem =
static_cast<memory*
>(mem_tmp);
191 mem_obj.mem_r.swap(mem_r);
199 template<
typename Mem_type>
212 Mem_type * mem_tmp =
static_cast<Mem_type*
>(mem);
213 mem_tmp->swap(*
static_cast<Mem_type*
>(mem_obj.mem));
215 mem_obj.mem_r.swap(mem_r);
241 template<
typename T,
unsigned int N>
244 enum { value =
mult<T,N-1>::value * boost::mpl::at<T,boost::mpl::int_<N>>::type::value };
247 template <
typename T>
250 enum { value = boost::mpl::at<T,boost::mpl::int_<1>>::type::value };
268 template<
typename T,
typename D>
276 bool manage_memory =
true;
285 template<
size_t index,
size_t N>
struct ascending
287 enum { value =
true };
291 typedef typename boost::mpl::push_front<typename boost::mpl::pop_front<T>::type,boost::mpl::int_<-1>>
::type Tv;
294 template<
int S>
using int_ = boost::mpl::int_<S>;
297 typedef typename boost::mpl::size<T>
size_p;
300 template<
typename S,
unsigned int n>
using at = boost::mpl::at<S,boost::mpl::int_<n> >;
305 typedef typename openfpm::multi_array_ref_openfpm<base,size_p::value,Tv>::size_type
size_type;
319 if (this->mem != NULL)
323 if (this->mem->
ref() == 0 && &mem != this->mem)
367 bool allocate(
const size_t sz,
bool skip_initialization =
false)
384 typedef boost::multi_array<base,size_p::value>
type;
387 typedef typename openfpm::ofp_storage_order<size_p::value>::value
storage_order;
397 :manage_memory(manage_memory),mem(NULL),
398 mem_r(static_cast<base *>(NULL),0)
421 manage_memory =
false;
439 void * mem_tmp =
static_cast<void*
>(mem);
441 mem_obj.mem =
static_cast<D*
>(mem_tmp);
443 mem_r.swap(mem_obj.mem_r);
456 template<
typename Mem_type>
469 Mem_type * mem_tmp =
static_cast<Mem_type*
>(mem);
470 mem_tmp->swap(*
static_cast<Mem_type*
>(mem_obj.mem));
472 mem_obj.mem_r.swap(mem_r);
484 template<
typename T,
size_t N1>
488 typedef boost::mpl::vector<T,boost::mpl::int_<N1>>
prim_vmpl;
493 template<
typename T,
size_t N1,
size_t N2>
497 typedef boost::mpl::vector<T,boost::mpl::int_<N1>,
520 typedef typename boost::mpl::push_front<typename boost::mpl::pop_front<prim_vmpl>::type,boost::mpl::int_<-1>>::type
vmpl;
Derivative second order on h (spacing)
This class give a representation to a chunk or memory.
void initialize(void *ptr, size_t sz, bool init)
Initialize the memory array.
void deinit()
Deinitialize the memory.
This class is a container for the memory interface like HeapMemory CudaMemory.
memory_array< T > mem_r
object that represent the memory as an array of objects T
bool bind_ref(const memory_c< T, MEMORY_C_STANDARD, D > &ref)
This function bind the memory_c to this memory_c as reference.
bool allocate(const size_t sz, bool skip_initialization=false)
This function allocate memory.
__host__ void swap_nomode(memory_c &mem_obj)
swap the memory
const memory & getMemory() const
This function get the object that allocate memory.
memory_c(bool manage_memory=true)
constructor
memory_c< T > type
define T
memory * mem
object that allocate memory like HeapMemory or CudaMemory
void setMemory(memory &mem)
This function set the object that allocate memory.
T & reference
define a reference to T
void disable_manage_memory()
Disable the management of memory (it is used for toKernel views)
memory & getMemory()
This function get the object that allocate memory.
void swap(memory_c &mem_obj)
swap the memory
openfpm::multi_array_ref_openfpm< base, size_p::value, Tv >::size_type size_type
define size_type
void swap(memory_c &mem_obj)
swap the memory
openfpm::ofp_storage_order< size_p::value >::value storage_order
define the storage order used to reference multidimensional arrays
__host__ void swap_nomode(memory_c &mem_obj)
swap the memory
bool allocate(const size_t sz, bool skip_initialization=false)
This function allocate memory and associate the representation to mem_r.
boost::multi_array< base, size_p::value > type
void disable_manage_memory()
Disable the management of memory (it is used for toKernel views)
openfpm::multi_array_ref_openfpm< base, boost::mpl::size< T >::value, Tv, storage_order > mem_r
object that represent the memory as a multi-dimensional array of objects T
D * mem
Reference to an object to allocate memory.
boost::mpl::at< S, boost::mpl::int_< n > > at
Define "at" meta function without boost::mpl.
void set_mem(memory &mem)
set the device memory interface, the object that allocate memory
boost::mpl::int_< S > int_
define boost::mpl::int_ without boost::mpl
memory_c(bool manage_memory=true)
constructor
void setMemory(memory &mem)
This function set the object that allocate memory.
bool bind_ref(const memory_c< multi_array< T >, MEMORY_C_STANDARD, D > &ref)
This function bind the memory_c to this memory_c as reference.
boost::mpl::push_front< typename boost::mpl::pop_front< T >::type, boost::mpl::int_<-1 > >::type Tv
Remove the first element.
memory & getMemory()
This function get the object that allocate memory.
boost::mpl::size< T > size_p
define the template vector size it give a number at compile time
virtual long int ref()=0
Return the actual reference counter.
virtual bool resize(size_t sz)=0
resize on device a buffer
virtual bool isInitialized()=0
Return if the actual memory that is going to be allocated is already initialized.
virtual void * getPointer()=0
return a data pointer
virtual void incRef()=0
Increment the internal reference counter.
virtual void decRef()=0
Decrement the internal reference counter.
This class is a trick to indicate the compiler a specific specialization pattern.
boost::mpl::vector< T, boost::mpl::int_< N1 >, boost::mpl::int_< N2 > > prim_vmpl
the internal array primitive information represented into a boost mpl vector
boost::mpl::vector< T, boost::mpl::int_< N1 > > prim_vmpl
the internal array primitive information represented into a boost mpl vector
Partial specialization for scalar N=0.
this class multiply all the elements in a boost::mpl::vector excluding the first element
OpenFPM use memory_c<multi_array<T> ..... > to implement the structure of array layout.
boost::mpl::push_front< typename boost::mpl::pop_front< prim_vmpl >::type, boost::mpl::int_<-1 > >::type vmpl
Remove the first element (this is the Tv parameter of )