Commit 88943949 authored by incardon's avatar incardon

Added shared memory support

parent 6e1c547e
......@@ -119,15 +119,48 @@ struct mem_get<p,layout,data_type,g1_type,key_type,1>
}
};
template<typename layout, typename data_type, bool is_empty, unsigned int sel = 2*is_layout_mlin<layout>::value + is_layout_inte<layout>::value>
struct mem_shmem
{
__host__ static inline void set_shmem_key(data_type & data_,key_t key)
{}
__host__ static inline key_t get_shmem_key(data_type & data_)
{
return -1;
}
};
template<typename layout, typename data_type>
struct mem_shmem<layout,data_type,false,2>
{
__host__ static inline void set_shmem_key(data_type & data_,key_t key)
{
data_.mem->set_shmem_key(key);
}
__host__ static inline key_t get_shmem_key(data_type & data_)
{
return data_.mem->get_shmem_key();
}
};
//! Case memory_traits_lin
template<typename S, typename layout, typename data_type, typename g1_type, unsigned int sel = 2*is_layout_mlin<layout>::value + is_layout_inte<layout>::value >
struct mem_setm
{
static inline void setMemory(data_type & data_, const g1_type & g1, bool & is_mem_init)
static inline void init_shmem(data_type & data_,const char * name, int proj_id)
{
data_.set_memory_name(name,proj_id);
}
static inline void setMemory(data_type & data_, const g1_type & g1, bool & is_mem_init, key_t key)
{
S * mem = new S();
mem->set_shmem_key(key);
//! Create and set the memory allocator
data_.setMemory(*mem);
......@@ -142,7 +175,12 @@ struct mem_setm
template<typename S, typename layout, typename data_type, typename g1_type>
struct mem_setm<S,layout,data_type,g1_type,1>
{
static inline void setMemory(data_type & data_, const g1_type & g1, bool & is_mem_init)
static inline void init_shmem(data_type & data_,const char * name, int proj_id)
{
// TODO implement shared memory implementation
}
static inline void setMemory(data_type & data_, const g1_type & g1, bool & is_mem_init, key_t key)
{
//! Create an allocate object
allocate<S> all(g1.size());
......
......@@ -233,6 +233,9 @@ private:
//! The memory allocator is not internally created
bool isExternal;
// shared_memory key
key_t key = -1;
#ifdef SE_CLASS1
/*! \brief Check that the key is inside the grid
......@@ -683,7 +686,7 @@ public:
check_valid(this,8);
#endif
mem_setm<S,layout_base<T>,decltype(this->data_),decltype(this->g1)>::setMemory(data_,g1,is_mem_init);
mem_setm<S,layout_base<T>,decltype(this->data_),decltype(this->g1)>::setMemory(data_,g1,is_mem_init,key);
}
/*! \brief Get the object that provide memory
......@@ -705,12 +708,6 @@ public:
//! Is external
isExternal = true;
//! Create and set the memory allocator
// data_.setMemory(m);
//! Allocate the memory and create the reppresentation
// if (g1.size() != 0) data_.allocate(g1.size());
bool skip_ini = skip_init<has_noPointers<T>::value,T>::skip_();
mem_setmemory<decltype(data_),S,layout_base<T>>::template setMemory<p>(data_,m,g1.size(),skip_ini);
......@@ -995,6 +992,8 @@ public:
grid_base_impl<dim,T,S,layout,layout_base> grid_new(sz);
grid_new.set_shmem_key(this->get_shmem_key());
resize_impl_memset(grid_new);
......@@ -1328,6 +1327,16 @@ public:
return grid_key_dx_iterator_sub<dim>(g1,m);
}
inline key_t get_shmem_key()
{
return mem_shmem<layout_base<T>,decltype(this->data_),boost::mpl::size<typename T::type>::type::value == 0>::get_shmem_key(data_);
}
inline void set_shmem_key(key_t k)
{
this->key = k;
}
/*! \brief Return a grid iterator
*
* Return a grid iterator, to iterate through the grid
......@@ -1440,6 +1449,16 @@ public:
return -1;
#endif
}
/*! \brief give a path for key generation for shared memory
*
* \
*
*/
void init_shmem(const char * pathname, int proj_id)
{
mem_setm<S,layout_base<T>,decltype(this->data_),decltype(this->g1)>::init_shmem(data_,pathname,proj_id);
}
};
......
......@@ -1823,6 +1823,16 @@ namespace openfpm
return v;
}
/*! \brief give a path for key generation for shared memory
*
* \
*
*/
void init_shmem(const char * pathname, int proj_id)
{
base.init_shmem(pathname,proj_id);
}
void * internal_get_size_pointer() {return &v_size;}
void print_size()
......
......@@ -204,6 +204,11 @@ class memory_c<T,MEMORY_C_STANDARD,D>
mem_obj.mem_r.swap(mem_r);
}
void set_memory_name(const char * pathname, int proj_id)
{
mem->set_memory_name(pathname,proj_id);
}
};
......
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