8 #ifndef VECTOR_DIST_OPERATORS_CUDA_CUH_
9 #define VECTOR_DIST_OPERATORS_CUDA_CUH_
11 #include "Space/Shape/Point.hpp"
12 #include "util/cuda_util.hpp"
16 template<
bool is_subset>
17 struct SubsetSelector_impl{
18 template<
typename particle_type,
typename subset_type>
25 struct SubsetSelector_impl<true>
27 template<
typename particle_type,
typename subset_type>
45 template <
typename vector,
unsigned int prp>
48 typedef typename boost::mpl::at<typename vector::value_type::type, boost::mpl::int_<prp>>::type property_act;
51 __device__ __host__
static inline auto value(vector & v,
const vect_dist_key_dx & k) -> decltype(v.template getProp<prp>(k))
53 return v.template getProp<prp>(k);
59 return v.template getProp<prp>(k);
70 template <
typename vector,
unsigned int prp>
74 __device__
static inline auto value(vector & v,
const unsigned int & k) -> decltype(v.template getProp<prp>(k))
76 return v.template getProp<prp>(k);
88 template <
typename vector>
91 typedef typename Point<vector::dims,typename vector::stype>::type_native property_act;
96 static inline auto value(vector & v,
const vect_dist_key_dx & k) -> decltype(getExprL(v.getPos(k).getReference()))
98 return getExprL(v.getPos(k).getReference());
125 template <
typename vector>
131 static inline auto value(vector & v,
const vect_dist_key_dx & k) -> decltype(getExprL(v.getPos(k).getReference()))
133 return getExprL(v.getPos(k).getReference());
154 template <
typename vector,
unsigned int prp>
158 __device__ __host__
static inline auto value(vector & v,
const vect_dist_key_dx & k) -> decltype(v.template getProp<prp>(k))
160 return v.template getProp<prp>(k);
164 __device__ __host__
static inline auto value(vector & v,
const unsigned int & k) -> decltype(v.template getProp<prp>(k))
166 return v.template getProp<prp>(k);
178 template <
typename vector>
194 template<
unsigned int prp,
int impl>
197 template<
typename vector,
typename expr>
198 static void compute_expr(vector & v,expr & v_exp)
201 template<
unsigned int n,
typename vector,
typename expr>
202 static void compute_expr_slice(vector & v,expr & v_exp,
int (& comp)[n])
205 template<
typename vector>
206 static void compute_const(vector & v,
double d)
212 template<
unsigned int,
bool is_val
id>
215 template<
typename exp_type>
218 return o1.value(key);
221 template<
unsigned int prop,
typename exp_type,
typename vector_type>
227 template<
unsigned int prop,
typename exp_type,
typename vector_type>
228 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key)
233 template<
unsigned int prop,
typename vector_type>
243 template<
typename exp_type>
244 __device__ __host__
static int get(exp_type & o1,
const vect_dist_key_dx & key,
const int (& comp)[1])
246 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
250 template<
unsigned int prop,
typename exp_type,
typename vector_type>
253 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
256 template<
unsigned int prop,
typename exp_type,
typename vector_type>
257 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const int (& comp)[1])
259 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
262 template<
unsigned int prop,
typename exp_type,
typename vector_type>
265 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
268 template<
unsigned int prop,
typename exp_type,
typename vector_type>
269 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const Point<1,int> & comp)
271 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
274 template<
unsigned int prop,
typename vector_type>
277 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
284 template<
typename exp_type>
285 __device__ __host__
static int get(exp_type & o1,
const vect_dist_key_dx & key,
const int (& comp)[2])
287 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
291 template<
unsigned int prop,
typename exp_type,
typename vector_type>
294 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
297 template<
unsigned int prop,
typename exp_type,
typename vector_type>
298 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const int (& comp)[2])
300 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
303 template<
unsigned int prop,
typename exp_type,
typename vector_type>
306 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
309 template<
unsigned int prop,
typename exp_type,
typename vector_type>
310 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const Point<2,int> & comp)
312 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
315 template<
unsigned int prop,
typename vector_type>
318 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
325 template<
typename exp_type>
328 return o1.value(key)[comp[0]];
331 template<
unsigned int prop,
typename exp_type,
typename vector_type>
337 template<
unsigned int prop,
typename exp_type,
typename vector_type>
338 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const int (& comp)[1])
343 template<
unsigned int prop,
typename exp_type,
typename vector_type>
349 template<
unsigned int prop,
typename exp_type,
typename vector_type>
350 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const Point<1,int> & comp)
355 template<
unsigned int prop,
typename vector_type>
365 template<
typename exp_type>
368 return o1.value(key)[comp[0]][comp[1]];
371 template<
unsigned int prop,
typename exp_type,
typename vector_type>
377 template<
unsigned int prop,
typename exp_type,
typename vector_type>
383 template<
unsigned int prop,
typename exp_type,
typename vector_type>
384 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const int (& comp)[2])
389 template<
unsigned int prop,
typename exp_type,
typename vector_type>
390 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const Point<2,int> & comp)
395 template<
unsigned int prop,
typename vector_type>
405 template<
typename exp_type>
408 return o1.value(key)[comp[0]][comp[1]][comp[2]];
411 template<
unsigned int prop,
typename exp_type,
typename vector_type>
417 template<
unsigned int prop,
typename exp_type,
typename vector_type>
423 template<
unsigned int prop,
typename exp_type,
typename vector_type>
424 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const int (& comp)[3])
429 template<
unsigned int prop,
typename exp_type,
typename vector_type>
430 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const Point<3,int> & comp)
435 template<
unsigned int prop,
typename vector_type>
444 template<
unsigned int prp>
447 template<
typename vector,
typename expr>
448 static void compute_expr(vector & v,expr & v_exp)
452 auto it = v.getDomainIterator();
464 template<
unsigned int n,
typename vector,
typename expr>
465 static void compute_expr_slice(vector & v,expr & v_exp,
int (& comp)[n])
467 typedef typename pos_or_propL<vector,prp>::property_act property_act;
472 auto &v2=v_exp.getVector();
474 SubsetSelector_impl<std::remove_reference<decltype(v)>::type::is_it_a_subset::value>::check(v2,v);
477 auto it = v.getDomainIterator();
489 template<
typename vector>
490 static void compute_const(vector & v,
double d)
492 auto it = v.getDomainIterator();
509 template<
unsigned int prp,
unsigned int dim ,
typename vector,
typename expr>
510 __global__
void compute_expr_ker_vv(vector vd, expr v_exp)
512 unsigned int p = threadIdx.x + blockIdx.x * blockDim.x;
514 if (p >= vd.size()) {
return;}
516 for (
unsigned int i = 0 ; i < dim ; i++)
518 vd.template get<prp>(p)[i] = v_exp.value(p).get(i);
522 template<
unsigned int prp,
typename vector,
typename expr>
523 __global__
void compute_expr_ker_v(vector vd, expr v_exp)
525 unsigned int p = threadIdx.x + blockIdx.x * blockDim.x;
527 if (p >= vd.size()) {
return;}
529 vd.template get<prp>(p) = v_exp.value(p);
532 template<
unsigned int prp,
typename vector,
typename expr>
533 __global__
void compute_expr_ker(vector vd, expr v_exp)
535 unsigned int p = threadIdx.x + blockIdx.x * blockDim.x;
537 if (p >= vd.size_local()) {
return;}
545 template<
typename _Tp,
typename _Up = _Tp&&>
546 __device__ __host__ _Up
549 template<
typename _Tp>
550 __device__ __host__ _Tp
553 template<
typename _Tp>
554 __device__ __host__
auto declval() noexcept -> decltype(__declval<_Tp>(0))
556 return __declval<_Tp>(0);
560 template<
unsigned int prp,
unsigned int n,
typename vector,
typename expr>
561 __global__
void compute_expr_ker_slice(vector vd, expr v_exp,
Point<n,int> comp)
565 unsigned int p = threadIdx.x + blockIdx.x * blockDim.x;
567 if (p >= vd.size_local()) {
return;}
572 template<
unsigned int prp,
typename vector>
573 __global__
void compute_double_ker(vector vd,
double d)
575 unsigned int p = threadIdx.x + blockIdx.x * blockDim.x;
577 if (p >= vd.size_local()) {
return;}
582 template<
unsigned int prp>
585 template<
typename vector,
typename expr>
586 static void compute_expr(vector & v,expr & v_exp)
590 auto ite = v.getDomainIteratorGPU(256);
592 CUDA_LAUNCH((compute_expr_ker<prp>),ite,v,v_exp);
595 template<
unsigned int n,
typename vector,
typename expr>
596 static void compute_expr_slice(vector & v,expr & v_exp,
int (& comp)[n])
600 auto ite = v.getDomainIteratorGPU(256);
603 for (
int i = 0 ; i < n ; i++) {comp_[i] = comp[i];}
605 CUDA_LAUNCH((compute_expr_ker_slice<prp,n>),ite,v,v_exp,comp_);
608 template<
typename vector,
typename expr>
609 static void compute_expr_v(vector & v,expr & v_exp)
613 auto ite = v.getGPUIterator(256);
615 CUDA_LAUNCH((compute_expr_ker_v<prp>),ite,v,v_exp);
618 template<
unsigned int dim,
typename vector,
typename expr>
619 static void compute_expr_vv(vector & v,expr & v_exp)
623 auto ite = v.getGPUIterator(256);
625 CUDA_LAUNCH((compute_expr_ker_vv<prp,dim>),ite,v,v_exp);
628 template<
typename vector>
629 static void compute_const(vector & v,
double d)
631 auto ite = v.getDomainIteratorGPU(256);
633 CUDA_LAUNCH((compute_double_ker<prp>),ite,v,d);
This class implement the point shape in an N-dimensional space.
Grid key for a distributed grid.
convert a type into constant type
__device__ static __host__ auto value(vector &v, const vect_dist_key_dx &k) -> decltype(ger< vector::dims, typename vector::stype >::getExprL(v.getPos(k)))
return the value (position or property) of the particle k in the vector v
static auto value_type(vector &&v, const vect_dist_key_dx &k) -> decltype(v.getPos(k))
return the value (position or property) of the particle k in the vector v
static __device__ auto value(vector &v, const unsigned int &k) -> decltype(ger< vector::dims, typename vector::stype >::getExprL(v.getPos(k)))
return the value (position or property) of the particle k in the vector v
selector for position or properties left side expression
static __device__ auto value(vector &v, const unsigned int &k) -> decltype(v.template getProp< prp >(k))
return the value (position or property) of the particle k in the vector v
selector for position or properties left side expression
__device__ static __host__ auto value(vector &v, const vect_dist_key_dx &k) -> decltype(v.template getProp< prp >(k))
return the value (position or property) of the particle k in the vector v
__device__ static __host__ auto value_type(vector &&v, const vect_dist_key_dx &k) -> decltype(v.template getProp< prp >(k))
return the value (position or property) of the particle k in the vector v
__device__ static __host__ auto value(vector &v, const unsigned int &k) -> decltype(ger< vector::dims, typename vector::stype >::getExprR(v.getPos(k)))
return the value (position or property) of the particle k in the vector v
__device__ static __host__ auto value(vector &v, const vect_dist_key_dx &k) -> decltype(ger< vector::dims, typename vector::stype >::getExprR(v.getPos(k)))
return the value (position or property) of the particle k in the vector v
selector for position or properties right side position
__device__ static __host__ auto value(vector &v, const unsigned int &k) -> decltype(v.template getProp< prp >(k))
return the value (position or property) of the particle k in the vector v
__device__ static __host__ auto value(vector &v, const vect_dist_key_dx &k) -> decltype(v.template getProp< prp >(k))
return the value (position or property) of the particle k in the vector v