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 boost::fusion::at_c<T::value>(
dst).disable_manage_memory();
60 boost::fusion::at_c<T::value>(
dst).mem = boost::fusion::at_c<T::value>(
src).mem;
62 boost::fusion::at_c<T::value>(
dst).mem_r.bind_ref(boost::fusion::at_c<T::value>(
src).mem_r);
63 boost::fusion::at_c<T::value>(
dst).switchToDevicePtr();
67 template<
bool inte_or_lin,
typename T>
70 template<
typename ggk_type>
static inline void construct(
const ggk_type & cpy,ggk_type & this_)
74 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop> >(bp_mc);
81 template<
typename ggk_type>
static inline void construct(
const ggk_type & cpy,ggk_type & this_)
83 this_.get_data_().disable_manage_memory();
84 this_.get_data_().mem = cpy.get_data_().mem;
86 this_.get_data_().mem_r.bind_ref(cpy.get_data_().mem_r);
87 this_.get_data_().switchToDevicePtr();
91 template<
unsigned int dim,
int prp,
typename ids_type>
96 int * ptr = (
int *)&global_cuda_error_array[0];
99 ptr[1] = ((size_t)sptr) & 0xFFFFFFFF;
100 ptr[2] = (((size_t)sptr) & 0xFFFFFFFF00000000) >> 32;
104 for (
int i = 0 ; i < dim ; i++)
105 {ptr[i+5] = key.
get(i);}
109 ptr[5+dim] = blockIdx.x;
110 ptr[6+dim] = blockIdx.y;
111 ptr[7+dim] = blockIdx.z;
113 ptr[8+dim] = blockDim.x;
114 ptr[9+dim] = blockDim.y;
115 ptr[10+dim] = blockDim.z;
117 ptr[11+dim] = threadIdx.x;
118 ptr[12+dim] = threadIdx.y;
119 ptr[13+dim] = threadIdx.z;
126 template<
unsigned int dim>
127 __device__
void fill_grid_error_array(
size_t lin_id)
131 int * ptr = (
int *)&global_cuda_error_array[0];
140 template<
unsigned int dim,
typename T,
template <
typename>
class layout_base,
typename linearizer>
148 template<
unsigned int dim,
typename T,
template <
typename>
class layout_base,
typename linearizer>
152 typedef typename apply_transform<layout_base,T>::type
T_;
158 typedef typename layout_base<T_>::type
layout;
174 for (
long int i = 0 ; i < dim ; i++)
178 else if (v1.
get(i) < 0)
218 __device__ __host__
void constructor_impl(
const grid_gpu_ker & cpy)
249 template <
unsigned int p,
typename ids_type,
typename r_type=decltype(layout_base<T_>::
template get<p>(
data_,
g1,
grid_key_dx<dim>()))>
254 {fill_grid_error_array_overflow<dim,p>(this->
template getPointer<p>(),v1);}
257 return layout_base<T_>::template get<p>(
data_,
g1,v1);
267 template <
unsigned int p,
typename ids_type,
typename r_type=decltype(layout_base<T_>::
template get<p>(
data_,
g1,
grid_key_dx<dim>()))>
272 {fill_grid_error_array_overflow<dim,p>(this->
template getPointer<p>(),v1);}
275 return layout_base<T_>::template get<p>(
data_,
g1,v1);
285 template <
unsigned int p,
typename ids_type,
typename r_type=decltype(layout_base<T_>::
template get<p>(
data_,
g1,
grid_key_dx<dim>()))>
290 {fill_grid_error_array_overflow<dim,p>(this->
template getPointer<p>(),v1);}
292 return layout_base<T_>::template get<p>(
data_,
g1,v1);
302 template <
unsigned int p,
typename r_type=decltype(layout_base<T_>::
template get_lin<p>(
data_,
g1,0))>
303 __device__ __host__
inline r_type
get(
const size_t lin_id)
307 {fill_grid_error_array_overflow<p>(this->
getPointer(),lin_id);}
309 return layout_base<T_>::template get_lin<p>(
data_,
g1,lin_id);
319 template <
unsigned int p,
typename r_type=decltype(layout_base<T_>::
template get_lin<p>(
data_,
g1,0))>
320 __device__ __host__
inline const r_type
get(
size_t lin_id)
const 324 {fill_grid_error_array_overflow<p>(this->
getPointer(),lin_id);}
326 return layout_base<T_>::template get_lin<p>(
data_,
g1,lin_id);
340 template<
typename Tk>
345 {fill_grid_error_array_overflow<dim,-1>(this->
template getPointer<0>(),v1);}
361 template<
typename Tk>
366 {fill_grid_error_array_overflow<dim,-1>(this->
template getPointer<0>(),v1);}
376 {fill_grid_error_array_overflow<dim,-1>(this->
template getPointer<0>(),key1);}
379 {fill_grid_error_array_overflow<dim,-1>(g.template getPointer<0>(),key2);}
390 {fill_grid_error_array_overflow<dim,-1>(this->
template getPointer<0>(),key1);}
393 {fill_grid_error_array_overflow<dim,-1>(g.template getPointer<0>(),key2);}
397 auto edest = this->
get_o(key1);
398 auto esrc = g.
get_o(key2);
402 boost::mpl::for_each_ref<boost::mpl::range_c<
int,0,
sizeof...(prp)>>(ec);
417 {fill_grid_error_array_overflow<dim,-1>(this->
template getPointer<0>(),key1);}
420 this->
get_o(key1) = obj;
428 template<
unsigned int p> __device__ __host__
void *
getPointer()
438 template<
unsigned int p> __device__ __host__
const void *
getPointer()
const 465 return getGPUIterator_impl<dim>(
g1,key1,key2,n_thr);
492 template<
unsigned int dim,
typename T,
template <
typename>
class layout_base,
typename linearizer>
497 typedef typename apply_transform<layout_base,T>::type T_;
499 typedef typename layout_base<T_>::type layout;
510 static constexpr
unsigned int dims = dim;
522 return ggk.getGrid();
525 __device__ __host__
size_t size()
const 527 return ggk.getGrid().size();
530 template <
unsigned int p,
typename ids_type>
533 return ggk.template get<p>(v1);
536 template <
unsigned int p,
typename ids_type>
539 return ggk.template get<p>(v1);
542 template <
unsigned int p>
543 __device__ __host__
inline auto get(
const size_t lin_id) -> decltype(ggk.template get<p>(lin_id))
545 return ggk.template get<p>(lin_id);
548 template <
unsigned int p>
549 __device__ __host__
inline auto get(
size_t lin_id)
const -> decltype(ggk.template get<p>(lin_id))
551 return ggk.template get<p>(lin_id);
554 template<
typename Tk>
557 return ggk.get_o(v1);
560 template<
typename Tk>
561 __device__
inline auto get_o(
const grid_key_dx<dim,Tk> & v1)
const -> decltype(ggk.get_o(v1))
563 return ggk.get_o(v1);
569 ggk.set(key1,g,key2);
574 ggk.template set<prp ...>(key1,g,key2);
582 template<
unsigned int p> __device__ __host__
void * getPointer()
584 return ggk.template getPointer<p>();
587 template<
unsigned int p> __device__ __host__
const void * getPointer()
const 589 return ggk.template getPointer<p>();
601 return ggk.getGPUIterator(key1,key2,n_thr);
604 __device__ __host__
inline layout & get_data_()
606 return ggk.get_data_();
609 __device__ __host__
inline const layout & get_data_()
const 611 return ggk.get_data_();
619 friend class grid_gpu_ker<dim,T,layout_base,linearizer>;
T value_type
Type of the value the vector is storing.
__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.
void operator()(T &t)
It call the copy function for each property.
this class is a functor for "for_each" algorithm
__device__ __host__ const layout & get_data_() const
Get the internal data_ structure.
const T_type_src & src
encapsulated source object
__device__ __host__ size_t size() const
Return the size of the grid.
static constexpr unsigned int dims
expose the dimansionality as a static const
__device__ __host__ index_type get(index_type i) const
Get the i index.
__device__ void set(grid_key_dx< dim > key1, const encapc< 1, T, Memory > &obj)
set an element of the grid
grid interface available when on gpu
__device__ __host__ bool check_bound(size_t v1) const
Check that the key is inside the grid.
T_type_dst & dst
encapsulated destination object
__device__ __host__ const grid_sm< dim, void > & getGrid() const
Return the internal grid information.
layout_base< T_ >::type layout
type of layout of the structure
__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.
copy_switch_memory_c_no_cpy(const T_type_src &src, T_type_dst &dst)
constructor
this class is a functor for "for_each" algorithm
linearizer g1
grid information
__device__ __host__ const r_type get(size_t lin_id) const
Get the const reference of the selected element.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
__device__ __host__ r_type get_debug(const grid_key_dx< dim, ids_type > &v1) const
Get the const reference of the selected element.
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.
__device__ __host__ const void * getPointer() const
Get the pointer for the property p.
__device__ __host__ r_type get(const grid_key_dx< dim, ids_type > &v1)
Get the 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
int yes_i_am_grid
it define that it is a grid
int yes_i_am_grid
it define that it is a grid
T value_type
Type of the value the vector is storing.
__device__ __host__ layout & get_data_()
Get the internal data_ structure.
__device__ __host__ r_type get(const size_t lin_id)
Get the reference of the selected element.
__device__ __host__ bool check_bound(const grid_key_dx< dim, ids_type > &v1) const
Check that the key is inside the grid.
__device__ __host__ void * getPointer()
Get the pointer for the property p.
apply_transform< layout_base, T >::type T_
Type T.
__device__ __host__ r_type get(const grid_key_dx< dim, ids_type > &v1) const
Get the const reference of the selected element.