8#ifndef OPENFPM_DATA_SRC_GRID_GRID_BASE_IMPLEMENTATION_HPP_
9#define OPENFPM_DATA_SRC_GRID_GRID_BASE_IMPLEMENTATION_HPP_
11#include "grid_base_impl_layout.hpp"
12#include "util/cuda_util.hpp"
13#include "cuda/cuda_grid_gpu_funcs.cuh"
14#include "util/create_vmpl_sequence.hpp"
15#include "util/cuda_launch.hpp"
16#include "util/object_si_di.hpp"
18constexpr int DATA_ON_HOST = 32;
19constexpr int DATA_ON_DEVICE = 64;
20constexpr int EXACT_RESIZE = 128;
22template<
bool np,
typename T>
36 return T::noPointers();
43struct copy_ndim_grid_device_active_impl
45 template<
typename gr
id_type1,
typename gr
id_type2,
typename ite_gpu_type>
46 static inline void copy(grid_type1 & g1, grid_type2 & g2, ite_gpu_type & ite)
51 template<
typename gr
id_type1,
typename gr
id_type2,
typename ite_gpu_type>
52 static inline void copy_block(grid_type1 & g1, grid_type2 & g2, ite_gpu_type & ite)
58struct copy_ndim_grid_device_active_impl<true>
60 template<
typename gr
id_type1,
typename gr
id_type2,
typename ite_gpu_type>
61 static inline void copy(grid_type1 & g1, grid_type2 & g2, ite_gpu_type & ite)
63 CUDA_LAUNCH((copy_ndim_grid_device<grid_type1::dims,
decltype(g1.toKernel())>),ite,g2.toKernel(),g1.toKernel());
66 template<
typename gr
id_type1,
typename gr
id_type2,
typename ite_gpu_type>
67 static inline void copy_block(grid_type1 & g1, grid_type2 & g2, ite_gpu_type & ite)
69 CUDA_LAUNCH((copy_ndim_grid_block_device<grid_type1::dims,
decltype(g1.toKernel())>),ite,g2.toKernel(),g1.toKernel());
73template<
typename S,
typename gr
id_dst_type,
typename gr
id_src_type>
74void copy_grid_to_grid(grid_dst_type & gdst,
const grid_src_type & gsrc,
78 if (grid_dst_type::dims <= 3)
80 auto ite = gsrc.getGPUIterator(start,stop);
81 bool has_work = has_work_gpu(ite);
87 copy_ndim_grid_device_active_impl<S::isDeviceHostSame() ==
false>::copy(gdst,gsrc,ite);
91 move_work_to_blocks(ite);
93 ite.thr.x = blockSize;
95 copy_ndim_grid_device_active_impl<S::isDeviceHostSame() ==
false>::copy_block(gdst,gsrc,ite);
104 stop.
set_d(0,gsrc.getGrid().size());
107 sz[0]= gsrc.getGrid().size();
111 auto ite = getGPUIterator_impl<1>(g_sm_copy,start,stop);
113 copy_ndim_grid_device_active_impl<S::isDeviceHostSame() ==
false>::copy(gdst,gsrc,ite);
119template<
typename dest_type,
typename src_type,
unsigned int ... prp>
122 #ifdef CUDIFY_USE_OPENMP
123 auto lamb = [&dst,&src,&ite] __device__ (dim3 & blockIdx, dim3 & threadIdx)
127 if (dest_type::dims == 1)
129 i.
set_d(0,blockIdx.x*blockDim.x + threadIdx.x + ite.start.get(0));
130 if (i.
get(0) >= src.size(0)) {
return;}
132 else if (dest_type::dims == 2)
134 i.
set_d(0,blockIdx.x*blockDim.x + threadIdx.x + ite.start.get(0));
135 i.
set_d(1,blockIdx.y*blockDim.y + threadIdx.y + ite.start.get(1));
136 if (i.
get(0) >= src.size(0) || i.
get(1) >= src.size(1)) {
return;}
138 else if (dest_type::dims == 3)
140 i.
set_d(0,blockIdx.x*blockDim.x + threadIdx.x + ite.start.get(0));
141 i.
set_d(1,blockIdx.y*blockDim.y + threadIdx.y + ite.start.get(1));
142 i.
set_d(2,blockIdx.z*blockDim.z + threadIdx.z + ite.start.get(2));
143 if (i.
get(0) >= src.size(0) || i.
get(1) >= src.size(1) || i.
get(2) >= src.size(2)) {
return;}
146 object_si_di<
decltype(src.get_o(i)),
decltype(dst.get_o(i)),OBJ_ENCAP,prp ...>(src.get_o(i),dst.get_o(i));
149 CUDA_LAUNCH_LAMBDA(ite,lamb);
151 std::cout << __FILE__ <<
":" << __LINE__ <<
" error CUDA on back end is disabled" << std::endl;
158#define GRID_ID_3_RAW(start,stop) int x[3] = {threadIdx.x + blockIdx.x * blockDim.x + start.get(0),\
159 threadIdx.y + blockIdx.y * blockDim.y + start.get(1),\
160 threadIdx.z + blockIdx.z * blockDim.z + start.get(2)};\
162 if (x[0] > stop.get(0) || x[1] > stop.get(1) || x[2] > stop.get(2))\
165#define GRID_ID_3_TRAW(start,stop) int tx = threadIdx.x + blockIdx.x * blockDim.x + start.get(0);\
166 int ty = threadIdx.y + blockIdx.y * blockDim.y + start.get(1);\
167 int tz = threadIdx.z + blockIdx.z * blockDim.z + start.get(2);\
169 if (tx > stop.get(0) || ty > stop.get(1) || tz > stop.get(2))\
172#define GRID_ID_3(ite_gpu) grid_key_dx<3,int> key;\
173 key.set_d(0,threadIdx.x + blockIdx.x * blockDim.x + ite_gpu.start.get(0));\
174 key.set_d(1,threadIdx.y + blockIdx.y * blockDim.y + ite_gpu.start.get(1));\
175 key.set_d(2,threadIdx.z + blockIdx.z * blockDim.z + ite_gpu.start.get(2));\
177 if (key.get(0) > ite_gpu.stop.get(0) || key.get(1) > ite_gpu.stop.get(1) || key.get(2) > ite_gpu.stop.get(2))\
180#define GRID_ID_2(ite_gpu) grid_key_dx<2,int> key;\
181 key.set_d(0,threadIdx.x + blockIdx.x * blockDim.x + ite_gpu.start.get(0));\
182 key.set_d(1,threadIdx.y + blockIdx.y * blockDim.y + ite_gpu.start.get(1));\
184 if (key.get(0) > ite_gpu.stop.get(0) || key.get(1) > ite_gpu.stop.get(1))\
190template<
unsigned int dim,
typename ids_type =
int>
197 key.
set_d(0,blockIdx.x * blockDim.x + threadIdx.x);
198 key.
set_d(1,blockIdx.y * blockDim.y + threadIdx.y);
200 unsigned int bz = blockIdx.z * blockDim.z + threadIdx.z;
203 for (
unsigned int i = 3 ; i < dim ; i++)
216 key.
set_d(0,blockIdx.x * blockDim.x + threadIdx.x);
217 key.
set_d(1,blockIdx.y * blockDim.y + threadIdx.y);
219 unsigned int bz = blockIdx.z * blockDim.z + threadIdx.z;
220 key.
set_d(2,bz % g[2]);
222 for (
unsigned int i = 3 ; i < dim ; i++)
225 key.
set_d(i,bz % g[i]);
232template<
typename ids_type>
233struct grid_p<3,ids_type>
239 key.
set_d(0,blockIdx.x * blockDim.x + threadIdx.x);
240 key.
set_d(1,blockIdx.y * blockDim.y + threadIdx.y);
241 key.
set_d(2,blockIdx.z * blockDim.z + threadIdx.z);
250 key.
set_d(0,blockIdx.x * blockDim.x + threadIdx.x);
251 key.
set_d(1,blockIdx.y * blockDim.y + threadIdx.y);
252 key.
set_d(2,blockIdx.z * blockDim.z + threadIdx.z);
258template<
typename ids_type>
259struct grid_p<2,ids_type>
265 key.
set_d(0,blockIdx.x * blockDim.x + threadIdx.x);
266 key.
set_d(1,blockIdx.y * blockDim.y + threadIdx.y);
275 key.
set_d(0,blockIdx.x * blockDim.x + threadIdx.x);
276 key.
set_d(1,blockIdx.y * blockDim.y + threadIdx.y);
282template<
typename ids_type>
283struct grid_p<1,ids_type>
289 key.
set_d(0,blockIdx.x * blockDim.x + threadIdx.x);
298template<
unsigned int dim>
303 ite.wthr.x = ite.wthr.x * ite.thr.x;
308 ite.wthr.x = ite.wthr.x * ite.thr.x;
309 ite.wthr.y = ite.wthr.y * ite.thr.y;
316 ite.wthr.x = ite.wthr.x * ite.thr.x;
317 ite.wthr.x = ite.wthr.y * ite.thr.y;
318 ite.wthr.x = ite.wthr.z * ite.thr.z;
327#include "copy_grid_fast.hpp"
332 template<
typename gr
id_type>
335 std::cout <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" copy_grid_fast_caller failure" << std::endl;
342 template<
typename gr
id_type>
348 typedef typename std::remove_reference<
decltype(gd)>::type grid_cp;
349 typedef typename std::remove_reference<
decltype(gd.getGrid())>::type grid_info_cp;
356 grid_info_cp>::copy(gs.getGrid(),
374template<
unsigned int dim,
377 template<
typename>
class layout_base,
382 typedef typename layout_base<T>::type
layout;
384 typedef typename apply_transform<layout_base,T>::type T_;
392 static constexpr unsigned int dims = dim;
403 typedef ord_type linearizer_type;
405 typedef T background_type;
429 inline void check_init()
const
434 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" you must call SetMemory before access the grid\n";
435 ACTION_ON_ERROR(GRID_ERROR_OBJECT);
448 for (
long int i = 0 ; i < dim ; i++)
452 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " <<
"x=[" << i <<
"]=" << v1.
get(i) <<
" >= " <<
getGrid().size(i) <<
"\n";
453 ACTION_ON_ERROR(GRID_ERROR_OBJECT);
455 else if (v1.
get(i) < 0)
457 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " <<
"x=[" << i <<
"]=" << v1.
get(i) <<
" is negative " <<
"\n";
458 ACTION_ON_ERROR(GRID_ERROR_OBJECT);
469 inline void check_bound(
size_t v1)
const
474 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " << v1<<
" >= " <<
getGrid().size() <<
"\n";
475 ACTION_ON_ERROR(GRID_ERROR_OBJECT);
491 for (
size_t i = 0 ; i < dim ; i++)
493 if (key2.
get(i) >= (
long int)g.
getGrid().size(i))
495 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " <<
"x=[" << i <<
"]=" << key2.
get(i) <<
" >= " << g.
getGrid().size(i) <<
"\n";
496 ACTION_ON_ERROR(GRID_ERROR_OBJECT);
498 else if (key2.
get(i) < 0)
500 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " <<
"x=[" << i <<
"]=" << key2.
get(i) <<
" is negative " <<
"\n";
501 ACTION_ON_ERROR(GRID_ERROR_OBJECT);
515 template<
typename Mem,
template <
typename>
class layout_base2>
519 for (
size_t i = 0 ; i < dim ; i++)
521 if (key2.
get(i) >= (
long int)g.
getGrid().size(i))
523 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " <<
"x=[" << i <<
"]=" << key2.
get(i) <<
" >= " << g.
getGrid().size(i) <<
"\n";
524 ACTION_ON_ERROR(GRID_ERROR_OBJECT);
526 else if (key2.
get(i) < 0)
528 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " <<
"x=[" << i <<
"]=" << key2.
get(i) <<
" is negative " <<
"\n";
529 ACTION_ON_ERROR(GRID_ERROR_OBJECT);
546 if (key2 >= g.
getGrid().size())
548 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " << key2 <<
" >= " <<
getGrid().size() <<
"\n";
549 ACTION_ON_ERROR(GRID_ERROR_OBJECT);
558#if defined(CUDA_GPU) && defined(__NVCC__)
566 for (
size_t i = 0 ; i < dim ; i++)
571 if (grid_new.
g1.size(i) < sz[i])
572 {stop.
set_d(i,grid_new.
g1.size(i)-1);}
574 {stop.
set_d(i,sz[i]-1);}
577 copy_grid_to_grid<S>(grid_new,*
this,start,stop,blockSize);
581 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: the function resize require the launch of a kernel, but it seem that this" <<
582 " file (grid_base_implementation.hpp) has not been compiled with NVCC " << std::endl;
590 for (
size_t i = 0 ; i < dim ; i++)
591 {sz_c[i] = (
g1.size(i) < sz[i])?
g1.size(i):sz[i];}
616 mem_setext<
typename std::remove_reference<
decltype(grid_new)>::type,S,layout_base<T>,
decltype(
data_)>
::set(grid_new,*
this,this->data_);
621#if defined(CUDIFY_USE_SEQUENTIAL) || defined(CUDIFY_USE_OPENMP)
631 #include "grid_pack_unpack.ipp"
706#if defined(CUDIFY_USE_SEQUENTIAL) || defined(CUDIFY_USE_OPENMP)
727#if defined(CUDIFY_USE_SEQUENTIAL) || defined(CUDIFY_USE_OPENMP)
814 return getGPUIterator_impl<dim>(
g1,key1,key2,n_thr);
851#if defined(CUDIFY_USE_SEQUENTIAL) || defined(CUDIFY_USE_OPENMP)
866 template<
unsigned int p>
869 return boost::fusion::at_c<p>(
data_).getMemory();
894#if defined(CUDIFY_USE_SEQUENTIAL) || defined(CUDIFY_USE_OPENMP)
923#if defined(CUDIFY_USE_SEQUENTIAL) || defined(CUDIFY_USE_OPENMP)
964 template <
unsigned int p,
typename r_type=decltype(layout_base<T>::
template get<p>(
data_,
g1,
grid_key_dx<dim>()))>
971 return this->get<p>(v1);
982 template <
unsigned int p,
typename r_type=decltype(layout_base<T>::
template get<p>(
data_,
g1,
grid_key_dx<dim>()))>
988 return layout_base<T>::template get<p>(
data_,
g1,v1);
1016 template <
unsigned int p,
typename r_type=decltype(layout_base<T>::
template get_c<p>(
data_,
g1,
grid_key_dx<dim>()))>
1022 return layout_base<T>::template get_c<p>(
data_,
g1,v1);
1032 template <
unsigned int p,
typename r_type=decltype(layout_base<T>::
template get<p>(
data_,
g1,
grid_key_dx<dim>()))>
1039 return layout_base<T>::template get<p>(
data_,
g1,v1);
1061 template <
unsigned int p,
typename r_type=decltype(layout_base<T>::
template get_c<p>(
data_,
g1,
grid_key_dx<dim>()))>
1068 return layout_base<T>::template get_c<p>(
data_,
g1,v1);
1078 template <
unsigned int p,
typename r_type=decltype(layout_base<T>::
template get_lin<p>(
data_,
g1,0))>
1079 __device__ __host__
inline r_type
get(
const size_t lin_id)
1083 check_bound(lin_id);
1085 return layout_base<T>::template get_lin<p>(
data_,
g1,lin_id);
1095 template <
unsigned int p,
typename r_type=decltype(layout_base<T>::
template get_lin<p>(
data_,
g1,0))>
1096 __device__ __host__
inline const r_type
get(
size_t lin_id)
const
1100 check_bound(lin_id);
1102 return layout_base<T>::template get_lin_const(
data_,
g1,lin_id);
1144 ::get(
const_cast<typename std::add_lvalue_reference<decltype(this-
>data_)>::type>(
data_),
1207 ::get_lin(
const_cast<typename std::add_lvalue_reference<decltype(this-
>data_)>::type>(
data_),v1);
1220 if (prp != 0 ||
is_layout_mlin<layout_base<T>>::type::value ==
false)
1222 std::cout <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" unsupported fill operation " << std::endl;
1278 for (
size_t i = 0 ; i < dim ; i++)
1280 if (box_dst.
getHigh(i) >= (
long int)
g1.size(i))
1292 if (box_dst.
getLow(i) < 0)
1331 template<
unsigned int ... prp>
1336 typedef typename std::remove_reference<
decltype(grid_src)>::type grid_cp;
1337 typedef typename std::remove_reference<
decltype(grid_src.
getGrid())>::type grid_info_cp;
1345 grid_info_cp>::copy(grid_src.
getGrid(),
1349 grid_src,*
this,cnt);
1370 template<
template<
typename,
typename>
class op,
unsigned int ... prp>
1410 void resize(
const size_t (& sz)[dim],
size_t opt = DATA_ON_HOST | DATA_ON_DEVICE,
unsigned int blockSize = 1)
1420 if (opt & DATA_ON_HOST)
1423 if (opt & DATA_ON_DEVICE && S::isDeviceHostSame() ==
false)
1424 {resize_impl_device(sz,grid_new,blockSize);}
1430 this->
swap(grid_new);
1453 this->
swap(grid_new);
1466 std::cerr <<
"Error: " << __FILE__ <<
" " << __LINE__ <<
" remove work only on dimension == 1 " <<
"\n";
1473 data_.move(&this->
template get<0>());
1518 grid.is_mem_init = exg;
1520#if defined(CUDIFY_USE_SEQUENTIAL) || defined(CUDIFY_USE_OPENMP)
1543 grid.is_mem_init = exg;
1548 grid.isExternal = exg;
1550#if defined(CUDIFY_USE_SEQUENTIAL) || defined(CUDIFY_USE_OPENMP)
1578 template<
unsigned int ... prp>
1581 auto edest = this->
get_o(key1);
1582 auto esrc = g.
get_o(key2);
1586 boost::mpl::for_each_ref<boost::mpl::range_c<int,0,
sizeof...(prp)>>(ec);
1608 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop> >(cp);
1627 this->
get_o(dx) = obj;
1646 check_bound(g,key2);
1660 inline void set(
const size_t key1,
1667 check_bound(g,key2);
1686 check_bound(g,key2);
1707 check_bound(g,key2);
1735 return g1.getSubIterator(start,stop);
1763 for (
int i = 0 ; i < dim ; i++)
1764 {sz[i] =
g1.size(i);}
1784 template<
unsigned int ... prp>
void deviceToHost(
size_t start,
size_t stop)
1795 #ifdef CUDIFY_USE_OPENMP
1799 for (
size_t i = 0 ; i < dim ; i++)
1801 start_.
set_d(i,start);
1802 stop_.
set_d(i,stop);
1805 auto ite = this->getGPUIterator(start_,stop_);
1808 copy_with_openmp_prp<
decltype(this->
toKernel()),
typename std::remove_reference<
decltype(*
this)>::type,prp ...>(this->
toKernel(),*
this,ite);
1820 #ifdef CUDIFY_USE_OPENMP
1825 for (
size_t i = 0 ; i < dim ; i++)
1828 stop_.
set_d(i,this->g1.size() - 1);
1831 auto ite = this->getGPUIterator(start_,stop_);
1834 copy_with_openmp_prp<
decltype(this->
toKernel()),
typename std::remove_reference<
decltype(*
this)>::type,prp ...>(this->
toKernel(),*
this,ite);
1844 template<
unsigned int ... prp>
void hostToDevice(
size_t start,
size_t stop)
1859#if defined(CUDIFY_USE_SEQUENTIAL) || defined(CUDIFY_USE_OPENMP)
1914 template<
unsigned int Np>
1937 for (
int i = 0 ; i < dim ; i++)
1938 {sz[i] =
g1.size(i);}
1981 template<
unsigned int ... prp,
typename context_type>
1992 template<
unsigned int ... prp,
typename context_type>
This class represent an N-dimensional box.
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
__device__ __host__ T getHigh(int i) const
get the high interval of the box
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
grid_key_dx< dim > getKP2() const
Get the point p12 as grid_key_dx.
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
grid_key_dx< dim > getKP1() const
Get the point p1 as grid_key_dx.
Implementation of a N-dimensional grid.
void removeAddUnpackFinalize(const context_type &ctx, int opt)
In this case it does nothing.
size_t size() const
return the size of the grid
layout layout_type
memory layout
void set(const grid_key_dx< dim > &key1, const grid_base_impl< dim, T, Mem, layout_base > &g, const grid_key_dx< dim > &key2)
Set an element of the grid from another element of another grid.
const ord_type & getGrid() const
Return the internal grid information.
encapc< dim, T, layout > container
Object container for T, it is the return type of get_o it return a object type trough.
void remove(size_t key)
Remove one element valid only on 1D.
void hostToDeviceNUMA(size_t start, size_t stop)
Synchronize the memory buffer in the device with the memory in the host (respecting the NUMA domains)
__device__ __host__ r_type get_usafe(const grid_key_dx< dim > &v1)
Get the reference of the selected element.
void swap_nomode(grid_base_impl< dim, T, S, layout_base > &grid)
It swap the objects A become B and B become A using A.swap(B);.
bool operator==(const grid_base_impl< dim, T, S, layout_base > &g)
Compare two grids.
encapc< dim, T, layout > insert_o(const grid_key_dx< dim > &v1)
Get the of the selected element as a boost::fusion::vector.
void set(grid_key_dx< dim > dx, const T &obj)
set an element of the grid
T::type T_type
boost::vector that describe the data type
void deviceToHost()
Synchronize the memory buffer in the device with the memory in the host.
grid_key_dx_iterator< dim > getIterator() const
Return a grid iterator.
void set(const size_t key1, const grid_base_impl< dim, T, S, layout_base > &g, const size_t key2)
Set an element of the grid from another element of another grid.
__device__ __host__ const r_type get(size_t lin_id) const
Get the const reference of the selected element.
void resetFlush()
It does nothing.
layout data_
Memory layout specification + memory chunk pointer.
void resize(const size_t(&sz)[dim], size_t opt=DATA_ON_HOST|DATA_ON_DEVICE, unsigned int blockSize=1)
Resize the grid.
ord_type g1
This is a structure that store all information related to the grid and how indexes are linearized.
__device__ __host__ r_type get_unsafe(const grid_key_dx< dim > &v1) const
Get the const reference of the selected element.
bool isSkipLabellingPossible()
This function check if keep geometry is possible for this grid.
bool isExternal
The memory allocator is not internally created.
grid_gpu_ker< dim, T_, layout_base, linearizer_type > toKernel()
Convert the grid into a data-structure compatible for computing into GPU.
grid_base_impl(const grid_base_impl &g) THROW
create a grid from another grid
__device__ __host__ r_type get(const grid_key_dx< dim > &v1) const
Get the const reference of the selected element.
layout & get_internal_data_()
return the internal data_
auto getMemory() -> decltype(boost::fusion::at_c< p >(data_).getMemory())
Return the memory object.
r_type insert(const grid_key_dx< dim > &v1)
In this case insert is equivalent to get.
~grid_base_impl() THROW
Destructor.
const layout & get_internal_data_() const
return the internal data_
void copy_to_op(const grid_base_impl< dim, T, S, layout_base > &gs, const Box< dim, size_t > &bx_src, const Box< dim, size_t > &bx_dst)
copy an external grid into a specific place into this grid
int yes_i_am_grid
it define that this data-structure is a grid
void removeCopyToFinalize(const context_type &ctx, int opt)
In this case it does nothing.
void set(const grid_key_dx< dim > &key1, const grid_base_impl< dim, T, S, layout_base > &g, const grid_key_dx< dim > &key2)
Set an element of the grid from another element of another grid.
T value_type
The object type the grid is storing.
void resize_impl_host(const size_t(&sz)[dim], grid_base_impl< dim, T, S, layout_base, ord_type > &grid_new)
__device__ __host__ void set(const grid_key_dx< dim > &key1, const grid_base_impl &g, const grid_key_dx< dim > &key2)
set only some properties
void setMemory()
Create the object that provide memory.
grid_base_impl< dim, T, S, layout_base > duplicate() const THROW
create a duplicated version of the grid
void hostToDevice()
Copy the memory from host to device.
int size(int i) const
Get the size if the grid in the direction i.
const encapc< dim, T, layout > get_o(const grid_key_dx< dim > &v1) const
Get the of the selected element as a boost::fusion::vector.
__device__ __host__ r_type get(const grid_key_dx< dim > &v1)
Get the reference of the selected element.
grid_key_dx_iterator_sub< dim > getSubIterator(const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop) const
Return a sub-grid iterator.
grid_base_impl() THROW
Default constructor.
const grid_gpu_ker< dim, T_, layout_base, linearizer_type > toKernel() const
Convert the grid into a data-structure compatible for computing into GPU.
const void * getPointer() const
Return a plain pointer to the internal data.
grid_key_dx_iterator_sub< dim > getSubIterator(size_t m)
Return a sub-grid iterator.
encapc< dim, T, layout > get_o(const grid_key_dx< dim > &v1)
Get the of the selected element as a boost::fusion::vector.
grid_key_dx_iterator_sub< dim > getIterator(const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop, bool to_init=false) const
Return a grid iterator over all points included between start and stop point.
void remove(Box< dim, long int > §ion_to_delete)
Remove all the points in this region.
encapc< dim, T, layout > get_o(size_t v1)
Get the of the selected element as a boost::fusion::vector.
void copy_to_prp(const grid_base_impl< dim, T, S, layout_base > &grid_src, const Box< dim, size_t > &box_src, const Box< dim, size_t > &box_dst)
copy an external grid into a specific place into this grid
void swap(grid_base_impl< dim, T, S, layout_base, ord_type > &grid)
It swap the objects A become B and B become A using A.swap(B);.
grid_base_impl< dim, T, S, layout_base > & operator=(const grid_base_impl< dim, T, S, layout_base > &g)
It copy a grid.
void removeAddUnpackReset()
In this case it does nothing.
void copyRemoveReset()
Reset the queue to remove and copy section of grids.
void setMemory(S &m)
Set the object that provide memory from outside.
layout_base< T > layout_base_
base layout type
grid_key_dx< dim > access_key
Access key.
void set(grid_key_dx< dim > dx, const encapc< 1, T, Memory > &obj)
set an element of the grid
void setGPUInsertBuffer(unsigned int nb, unsigned int nt)
No blocks here, it does nothing.
memory_traits_lin< typenameT::type >::type memory_lin
Definition of the layout.
void set_general(const grid_key_dx< dim > &key1, const grid_base_impl< dim, T, Mem, layout_base2 > &g, const grid_key_dx< dim > &key2)
Set an element of the grid from another element of another grid.
int getBlockEdgeSize()
No blocks here, it return 1.
bool is_mem_init
Is the memory initialized.
grid_base_impl< dim, T, S, layout_base > & operator=(grid_base_impl< dim, T, S, layout_base > &&g)
It copy a grid.
void swap(grid_base_impl< dim, T, S, layout_base > &&grid)
It move the allocated object from one grid to another.
grid_base_impl(const size_t &sz) THROW
create a grid of size sz on each direction
grid_key_dx_iterator< dim, stencil_offset_compute< dim, Np > > getIteratorStencil(const grid_key_dx< dim >(&stencil_pnt)[Np]) const
Return a grid iterator.
void fill(unsigned char fl)
Fill the memory with the selected byte.
void clear()
It does nothing.
__device__ __host__ r_type get(const size_t lin_id)
Get the reference of the selected element.
void hostToDeviceNUMA()
Synchronize the memory buffer in the device with the memory in the host (respecting the NUMA domains)
void * getPointer()
Return a plain pointer to the internal data.
void hostToDevice(size_t start, size_t stop)
Synchronize the memory buffer in the device with the memory in the host.
void copy_to(const grid_base_impl< dim, T, S, layout_base > &grid_src, const Box< dim, long int > &box_src, const Box< dim, long int > &box_dst)
copy an external grid into a specific place into this grid
void setMemoryArray(S *m)
Set the object that provide memory from outside.
layout_base< T >::type layout
memory layout
void resize_impl_memset(grid_base_impl< dim, T, S, layout_base, ord_type > &grid_new)
void resize_no_device(const size_t(&sz)[dim])
Resize the space.
__device__ __host__ unsigned char getFlag(const grid_key_dx< dim > &v1) const
Get the point flag (in this case just return 0)
void deviceToHost(size_t start, size_t stop)
Synchronize the memory buffer in the device with the memory in the host.
static bool is_unpack_header_supported()
Indicate that unpacking the header is supported.
static constexpr unsigned int dims
expose the dimansionality as a static const
grid_base_impl(const size_t(&sz)[dim]) THROW
Constructor.
const encapc< dim, T, layout > get_o(size_t v1) const
Get the of the selected element as a boost::fusion::vector.
This is a distributed grid.
static const unsigned int dims
Number of dimensions.
grid interface available when on gpu
Declaration grid_key_dx_iterator_sub.
grid_key_dx< dim > get() const
Return the actual grid key iterator.
bool isNext()
Check if there is the next element.
const grid_key_dx< dim > & get() const
Get the actual key.
bool isNext()
Check if there is the next element.
grid_key_dx is the key to access any element in the grid
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.
__device__ __host__ index_type get(index_type i) const
Get the i index.
__device__ __host__ size_t size() const
Return the size of the grid.
this class is a functor for "for_each" algorithm
this class is a functor for "for_each" algorithm
This is a way to quickly copy a grid into another grid.
It return true if the object T require complex serialization.
It copy the properties from one object to another applying an operation.
It copy the properties from one object to another applying an operation.
to_variadic_impl< N+1, M, exit_::value, N >::type type
generate the boost::fusion::vector apply H on each term