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)
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);
250 template<
typename T,
unsigned int N>
253 enum { value =
mult<T,N-1>::value * boost::mpl::at<T,boost::mpl::int_<N>>::type::value };
256 template <
typename T>
259 enum { value = boost::mpl::at<T,boost::mpl::int_<1>>::type::value };
262 template<
typename size_type,
unsigned int dim>
263 static inline std::array<size_type ,dim> zero_dims()
265 std::array<size_type ,dim> dimensions;
268 for (
size_t i = 0 ; i < dim ; i++)
274 template<
unsigned int dim,
typename size_type>
279 template<
typename size_type>
282 static constexpr size_type data[4] = {0,3,2,1};
285 template<
typename size_type>
288 static constexpr size_type data[3] = {0,2,1};
291 template<
typename size_type>
294 static constexpr size_type data[2] = {0,1};
297 template<
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};
335 template<
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);
559 template<
typename T,
size_t N1>
563 typedef boost::mpl::vector<T,boost::mpl::int_<N1>>
prim_vmpl;
568 template<
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;
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::multi_array< base, size_p::value > type
convert a type into constant type
boost::mpl::vector< T, boost::mpl::int_< N1 > > prim_vmpl
the internal array primitive information represented into a boost mpl vector
Derivative second order on h (spacing)
virtual bool resize(size_t sz)=0
resize on device a buffer
memory_c< T > type
define T
memory_c(bool manage_memory=true)
constructor
OpenFPM use memory_c<multi_array<T> ..... > to implement the structure of array layout.
virtual long int ref()=0
Return the actual reference counter.
void set_pointer(void *ptr_)
Set the internal pointer to the indicated chunk of 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.
void disable_manage_memory()
Disable the management of memory (it is used for toKernel views)
memory_array< T > mem_r
object that represent the memory as an array of objects T
virtual void * getDevicePointer()=0
Return the device pointer of the memory.
This class is a container for the memory interface like HeapMemory CudaMemory.
__host__ void swap_nomode(memory_c &mem_obj)
swap the memory
void deinit()
Deinitialize the memory.
T & reference
define a reference to T
void swap(memory_c &mem_obj)
swap the memory
memory & getMemory()
This function get the object that allocate memory.
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
this class multiply all the elements in a boost::mpl::vector excluding the first element
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 )
boost::mpl::size< T > size_p
define the template vector size it give a number at compile time
void disable_manage_memory()
Disable the management of memory (it is used for toKernel views)
Partial specialization for scalar N=0.
D * mem
Reference to an object to allocate memory.
void setMemory(memory &mem)
This function set the object that allocate memory.
bool allocate(const size_t sz, bool skip_initialization=false)
This function allocate memory.
openfpm::multi_array_ref_openfpm< base, size_p::value, Tv >::size_type size_type
define size_type
memory_c(bool manage_memory=true)
constructor
void initialize(void *ptr, size_t sz, bool init)
Initialize the memory array.
void switchToDevicePtr()
Switch the pointer to device pointer (if the memory has been already set)
void setMemory(memory &mem)
This function set the object that allocate memory.
bool bind_ref(const memory_c< T, MEMORY_C_STANDARD, D > &ref)
This function bind the memory_c to this memory_c as reference.
memory & getMemory()
This function get the object that allocate memory.
void set_mem(memory &mem)
set the device memory interface, the object that allocate memory
virtual void decRef()=0
Decrement the internal reference counter.
const memory & getMemory() const
This function get the object that allocate memory.
virtual bool isInitialized()=0
Return if the actual memory that is going to be allocated is already initialized.
bool allocate(const size_t sz, bool skip_initialization=false)
This function allocate memory and associate the representation to mem_r.
void swap(memory_c &mem_obj)
swap the memory
void switchToDevicePtr()
Switch the pointer to device pointer.
This class give a representation to a chunk or memory.
boost::mpl::at< S, boost::mpl::int_< n > > at
Define "at" meta function without boost::mpl.
virtual void * getPointer()=0
return a data pointer
boost::mpl::int_< S > int_
define boost::mpl::int_ without boost::mpl
boost::mpl::push_front< typename boost::mpl::pop_front< T >::type, boost::mpl::int_<-1 > >::type Tv
Remove the first element.
virtual void incRef()=0
Increment the internal reference counter.
memory * mem
object that allocate memory like HeapMemory or CudaMemory
This class is a trick to indicate the compiler a specific specialization pattern.
__host__ void swap_nomode(memory_c &mem_obj)
swap the memory