8 #ifndef MAP_GRID_CUDA_KER_HPP_
9 #define MAP_GRID_CUDA_KER_HPP_
12 #include "Grid/grid_base_impl_layout.hpp"
13 #include "util/tokernel_transformation.hpp"
15 #include "memory/CudaMemory.cuh"
32 template<
typename T_type_src,
typename T_type_dst>
36 const T_type_src &
src;
58 auto &grid_layout = boost::fusion::at_c<T::value>(
dst);
60 grid_layout.disable_manage_memory();
61 grid_layout.mem = boost::fusion::at_c<T::value>(
src).mem;
62 grid_layout.mem_r.bind_ref(boost::fusion::at_c<T::value>(
src).mem_r);
65 {grid_layout.mem_r.set_pointer(((
CudaMemory*)grid_layout.mem)->getDevicePointer());}
70 template<
bool inte_or_lin,
typename T>
73 template<
typename ggk_type>
static inline void construct(
const ggk_type & cpy,ggk_type & this_)
77 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop> >(bp_mc);
84 template<
typename ggk_type>
static inline void construct(
const ggk_type & cpy,ggk_type & this_)
86 auto &grid_layout = this_.get_data_();
88 grid_layout.disable_manage_memory();
89 grid_layout.mem = cpy.get_data_().mem;
90 grid_layout.mem_r.bind_ref(cpy.get_data_().mem_r);
94 {grid_layout.mem_r.set_pointer(((
CudaMemory*)grid_layout.mem)->getDevicePointer());}
99 template<
unsigned int dim,
int prp,
typename ids_type>
104 int * ptr = (
int *)&global_cuda_error_array[0];
107 ptr[1] = ((size_t)sptr) & 0xFFFFFFFF;
108 ptr[2] = (((size_t)sptr) & 0xFFFFFFFF00000000) >> 32;
112 for (
int i = 0 ; i < dim ; i++)
113 {ptr[i+5] = key.
get(i);}
117 ptr[5+dim] = blockIdx.x;
118 ptr[6+dim] = blockIdx.y;
119 ptr[7+dim] = blockIdx.z;
121 ptr[8+dim] = blockDim.x;
122 ptr[9+dim] = blockDim.y;
123 ptr[10+dim] = blockDim.z;
125 ptr[11+dim] = threadIdx.x;
126 ptr[12+dim] = threadIdx.y;
127 ptr[13+dim] = threadIdx.z;
134 template<
unsigned int dim>
135 __device__
void fill_grid_error_array(
size_t lin_id)
139 int * ptr = (
int *)&global_cuda_error_array[0];
148 template<
unsigned int dim,
typename T,
template <
typename>
class layout_base,
typename linearizer>
156 template<
unsigned int dim,
typename T,
template <
typename>
class layout_base,
typename linearizer>
160 typedef typename apply_transform<layout_base,T>::type
T_;
166 typedef typename layout_base<T_>::type
layout;
182 for (
long int i = 0 ; i < dim ; i++)
186 else if (v1.
get(i) < 0)
226 __device__ __host__
void constructor_impl(
const grid_gpu_ker & cpy)
257 template <
unsigned int p,
typename ids_type,
typename r_type=decltype(layout_base<T_>::
template get<p>(
data_,
g1,
grid_key_dx<dim>()))>
262 {fill_grid_error_array_overflow<dim,p>(this->
template getPointer<p>(),v1);}
265 return layout_base<T_>::template get<p>(
data_,
g1,v1);
275 template <
unsigned int p,
typename ids_type,
typename r_type=decltype(layout_base<T_>::
template get<p>(
data_,
g1,
grid_key_dx<dim>()))>
280 {fill_grid_error_array_overflow<dim,p>(this->
template getPointer<p>(),v1);}
283 return layout_base<T_>::template get<p>(
data_,
g1,v1);
293 template <
unsigned int p,
typename ids_type,
typename r_type=decltype(layout_base<T_>::
template get<p>(
data_,
g1,
grid_key_dx<dim>()))>
298 {fill_grid_error_array_overflow<dim,p>(this->
template getPointer<p>(),v1);}
300 return layout_base<T_>::template get<p>(
data_,
g1,v1);
310 template <
unsigned int p,
typename r_type=decltype(layout_base<T_>::
template get_lin<p>(
data_,
g1,0))>
311 __device__ __host__
inline r_type
get(
const size_t lin_id)
315 {fill_grid_error_array_overflow<p>(this->
getPointer(),lin_id);}
317 return layout_base<T_>::template get_lin<p>(
data_,
g1,lin_id);
327 template <
unsigned int p,
typename r_type=decltype(layout_base<T_>::
template get_lin<p>(
data_,
g1,0))>
328 __device__ __host__
inline const r_type
get(
size_t lin_id)
const
332 {fill_grid_error_array_overflow<p>(this->
getPointer(),lin_id);}
334 return layout_base<T_>::template get_lin<p>(
data_,
g1,lin_id);
348 template<
typename Tk>
353 {fill_grid_error_array_overflow<dim,-1>(this->
template getPointer<0>(),v1);}
369 template<
typename Tk>
374 {fill_grid_error_array_overflow<dim,-1>(this->
template getPointer<0>(),v1);}
384 {fill_grid_error_array_overflow<dim,-1>(this->
template getPointer<0>(),key1);}
387 {fill_grid_error_array_overflow<dim,-1>(g.template getPointer<0>(),key2);}
398 {fill_grid_error_array_overflow<dim,-1>(this->
template getPointer<0>(),key1);}
401 {fill_grid_error_array_overflow<dim,-1>(g.template getPointer<0>(),key2);}
405 auto edest = this->
get_o(key1);
406 auto esrc = g.
get_o(key2);
410 boost::mpl::for_each_ref<boost::mpl::range_c<
int,0,
sizeof...(prp)>>(ec);
425 {fill_grid_error_array_overflow<dim,-1>(this->
template getPointer<0>(),key1);}
428 this->
get_o(key1) = obj;
436 template<
unsigned int p> __device__ __host__
void *
getPointer()
446 template<
unsigned int p> __device__ __host__
const void *
getPointer()
const
473 return getGPUIterator_impl<dim>(
g1,key1,key2,n_thr);
500 template<
unsigned int dim,
typename T,
template <
typename>
class layout_base,
typename linearizer>
505 typedef typename apply_transform<layout_base,T>::type T_;
507 typedef typename layout_base<T_>::type layout;
518 static constexpr
unsigned int dims = dim;
533 __device__ __host__
size_t size()
const
538 template <
unsigned int p,
typename ids_type>
541 return ggk.template get<p>(v1);
544 template <
unsigned int p,
typename ids_type>
547 return ggk.template get<p>(v1);
550 template <
unsigned int p>
551 __device__ __host__
inline auto get(
const size_t lin_id) -> decltype(ggk.template get<p>(lin_id))
553 return ggk.template get<p>(lin_id);
556 template <
unsigned int p>
557 __device__ __host__
inline auto get(
size_t lin_id)
const -> decltype(ggk.template get<p>(lin_id))
559 return ggk.template get<p>(lin_id);
562 template<
typename Tk>
565 return ggk.
get_o(v1);
568 template<
typename Tk>
571 return ggk.
get_o(v1);
577 ggk.set(key1,g,key2);
582 ggk.template set<prp ...>(key1,g,key2);
590 template<
unsigned int p> __device__ __host__
void * getPointer()
592 return ggk.template getPointer<p>();
595 template<
unsigned int p> __device__ __host__
const void * getPointer()
const
597 return ggk.template getPointer<p>();
612 __device__ __host__
inline layout & get_data_()
617 __device__ __host__
inline const layout & get_data_()
const
627 friend class grid_gpu_ker<dim,T,layout_base,linearizer>;
T value_type
Type of the value the vector is storing.
int yes_i_am_grid
it define that it is a grid
static constexpr unsigned int dims
expose the dimansionality as a static const
grid interface available when on gpu
__device__ __host__ bool check_bound(size_t v1) const
Check that the key is inside the grid.
__device__ __host__ r_type get(const size_t lin_id)
Get the reference of the selected element.
__device__ __host__ const layout & get_data_() const
Get the internal data_ structure.
__device__ __host__ bool check_bound(const grid_key_dx< dim, ids_type > &v1) const
Check that the key is inside the grid.
__device__ __host__ layout & get_data_()
Get the internal data_ structure.
__device__ __host__ r_type get(const grid_key_dx< dim, ids_type > &v1)
Get the reference of the selected element.
apply_transform< layout_base, T >::type T_
Type T.
__device__ __host__ void * getPointer()
Get the pointer for the property p.
int yes_i_am_grid
it define that it is a grid
__device__ __host__ const void * getPointer() const
Get the pointer for the property p.
__device__ const encapc< dim, T_, layout > get_o(const grid_key_dx< dim, Tk > &v1) const
Get the of the selected element as a boost::fusion::vector.
__device__ __host__ const r_type get(size_t lin_id) const
Get the const reference of the selected element.
__device__ encapc< dim, T_, layout > get_o(const grid_key_dx< dim, Tk > &v1)
Get the of the selected element as a boost::fusion::vector.
__device__ void set(grid_key_dx< dim > key1, const encapc< 1, T, Memory > &obj)
set an element of the grid
__device__ __host__ r_type get_debug(const grid_key_dx< dim, ids_type > &v1) const
Get the const reference of the selected element.
grid_gpu_ker< dim, T_, layout_base, linearizer > & operator=(const grid_gpu_ker< dim, T_, layout_base, linearizer > &g)
operator= this operator absorb the pointers, consider that this object wrap device pointers
__device__ __host__ r_type get(const grid_key_dx< dim, ids_type > &v1) const
Get the const reference of the selected element.
__device__ __host__ const grid_sm< dim, void > & getGrid() const
Return the internal grid information.
struct ite_gpu< dim > getGPUIterator(grid_key_dx< dim > &key1, grid_key_dx< dim > &key2, size_t n_thr=default_kernel_wg_threads_) const
Get an iterator for the GPU.
layout_base< T_ >::type layout
type of layout of the structure
T value_type
Type of the value the vector is storing.
linearizer g1
grid information
grid_key_dx is the key to access any element in the grid
__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.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
this class is a functor for "for_each" algorithm
this class is a functor for "for_each" algorithm
copy_switch_memory_c_no_cpy(const T_type_src &src, T_type_dst &dst)
constructor
const T_type_src & src
encapsulated source object
void operator()(T &t)
It call the copy function for each property.
T_type_dst & dst
encapsulated destination object