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
28template<
typename T,
unsigned int impl = MEMORY_C_STANDARD,
typename D = memory>
44template<
typename T,
typename D>
52 bool manage_memory =
true;
80 if (this->mem != NULL)
84 if (this->mem->
ref() == 0 && &mem != this->mem)
145 bool allocate(
const size_t sz,
bool skip_initialization =
false)
150 mem->
resize( sz*
sizeof(T) );
160 :manage_memory(manage_memory),mem(NULL){}
184 manage_memory =
false;
196 void * mem_tmp =
static_cast<void*
>(mem);
198 mem_obj.mem =
static_cast<memory*
>(mem_tmp);
200 mem_obj.mem_r.swap(mem_r);
208 template<
typename Mem_type>
221 Mem_type * mem_tmp =
static_cast<Mem_type*
>(mem);
222 mem_tmp->swap(*
static_cast<Mem_type*
>(mem_obj.mem));
224 mem_obj.mem_r.swap(mem_r);
250template<
typename T,
unsigned int N>
253 enum { value =
mult<T,N-1>::value * boost::mpl::at<T,boost::mpl::int_<N>>::type::value };
259 enum { value = boost::mpl::at<T,boost::mpl::int_<1>>::type::value };
262template<
typename size_type,
unsigned int dim>
263static inline std::array<size_type ,dim> zero_dims()
265 std::array<size_type ,dim> dimensions;
268 for (
size_t i = 0 ; i < dim ; i++)
274template<
unsigned int dim,
typename size_type>
279template<
typename size_type>
282 static constexpr size_type data[4] = {0,3,2,1};
285template<
typename size_type>
288 static constexpr size_type data[3] = {0,2,1};
291template<
typename size_type>
294 static constexpr size_type data[2] = {0,1};
297template<
unsigned int dim>
305 static constexpr bool data[4] = {
true,
true,
true,
true};
311 static constexpr bool data[3] = {
true,
true,
true};
317 static constexpr bool data[2] = {
true,
true};
335template<
typename T,
typename D>
343 bool manage_memory =
true;
352 template<
size_t index,
size_t N>
struct ascending
354 enum { value =
true };
358 typedef typename boost::mpl::push_front<typename boost::mpl::pop_front<T>::type,boost::mpl::int_<-1>>::type
Tv;
361 template<
int S>
using int_ = boost::mpl::int_<S>;
364 typedef typename boost::mpl::size<T>
size_p;
367 template<
typename S,
unsigned int n>
using at = boost::mpl::at<S,boost::mpl::int_<n> >;
372 typedef typename openfpm::multi_array_ref_openfpm<base,size_p::value,Tv>::size_type
size_type;
386 if (this->mem != NULL)
390 if (this->mem->
ref() == 0 && &mem != this->mem)
415 {mem_r.set_pointer(mem->getDevicePointer());}
443 bool allocate(
const size_t sz,
bool skip_initialization =
false)
462 typedef boost::multi_array<base,size_p::value>
type;
472 :manage_memory(manage_memory),mem(NULL),
473 mem_r(static_cast<base *>(NULL),0,
openfpm::ofp_storage_order())
496 manage_memory =
false;
514 void * mem_tmp =
static_cast<void*
>(mem);
516 mem_obj.mem =
static_cast<D*
>(mem_tmp);
518 mem_r.swap(mem_obj.mem_r);
531 template<
typename Mem_type>
544 Mem_type * mem_tmp =
static_cast<Mem_type*
>(mem);
545 mem_tmp->swap(*
static_cast<Mem_type*
>(mem_obj.mem));
547 mem_obj.mem_r.swap(mem_r);
559template<
typename T,
size_t N1>
563 typedef boost::mpl::vector<T,boost::mpl::int_<N1>>
prim_vmpl;
568template<
typename T,
size_t N1,
size_t N2>
572 typedef boost::mpl::vector<T,boost::mpl::int_<N1>,
595 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 set_pointer(void *ptr_)
Set the internal pointer to the indicated chunk of memory.
void initialize(void *ptr, size_t sz, bool init)
Initialize the memory array.
void deinit()
Deinitialize the memory.
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.
const memory & getMemory() const
This function get the object that allocate memory.
__host__ void swap_nomode(memory_c &mem_obj)
swap the memory
void switchToDevicePtr()
Switch the pointer to device pointer (if the memory has been already set)
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
void switchToDevicePtr()
Switch the pointer to device pointer.
openfpm::multi_array_ref_openfpm< base, boost::mpl::size< T >::value, Tv > mem_r
object that represent the memory as a multi-dimensional array of objects T
__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)
D * mem
Reference to an object to allocate memory.
boost::mpl::push_front< typenameboost::mpl::pop_front< T >::type, boost::mpl::int_<-1 > >::type Tv
Remove the first element.
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
memory & getMemory()
This function get 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::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 void * getDevicePointer()=0
Return the device pointer of the memory.
virtual bool isInitialized()=0
Return if the actual memory that is going to be allocated is already initialized.
virtual void incRef()=0
Increment the internal reference counter.
virtual void decRef()=0
Decrement the internal reference counter.
virtual void * getPointer()=0
return a data pointer
This class is a trick to indicate the compiler a specific specialization pattern.
convert a type into constant type
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< typenameboost::mpl::pop_front< prim_vmpl >::type, boost::mpl::int_<-1 > >::type vmpl
Remove the first element (this is the Tv parameter of )