8#ifndef VECTOR_DIST_OPERATORS_CUDA_CUH_
9#define VECTOR_DIST_OPERATORS_CUDA_CUH_
11#include "Space/Shape/Point.hpp"
12#include "util/cuda_launch.hpp"
16template<
bool is_subset>
17struct SubsetSelector_impl{
18 template<
typename particle_type,
typename subset_type>
25struct SubsetSelector_impl<true>
27 template<
typename particle_type,
typename subset_type>
38constexpr unsigned int PROP_POS =(
unsigned int)-1;
47template <
typename vector,
unsigned int prp>
50 typedef typename boost::mpl::at<typename vector::value_type::type, boost::mpl::int_<prp>>::type property_act;
53 __device__ __host__
static inline auto value(vector & v,
const vect_dist_key_dx & k) ->
decltype(v.template getProp<prp>(k))
55 return v.template getProp<prp>(k);
61 return v.template getProp<prp>(k);
72template <
typename vector,
unsigned int prp>
76 __device__
static inline auto value(vector & v,
const unsigned int & k) ->
decltype(v.template getProp<prp>(k))
78 return v.template getProp<prp>(k);
90template <
typename vector>
93 typedef typename Point<vector::dims,typename vector::stype>::type_native property_act;
98 static inline auto value(vector & v,
const vect_dist_key_dx & k) ->
decltype(getExprL(v.getPos(k).getReference()))
100 return getExprL(v.getPos(k).getReference());
127template <
typename vector>
133 static inline auto value(vector & v,
const vect_dist_key_dx & k) ->
decltype(getExprL(v.getPos(k).getReference()))
135 return getExprL(v.getPos(k).getReference());
156template <
typename vector,
unsigned int prp>
160 __device__ __host__
static inline auto value(vector & v,
const vect_dist_key_dx & k) ->
decltype(v.template getProp<prp>(k))
162 return v.template getProp<prp>(k);
166 __device__ __host__
static inline auto value(vector & v,
const unsigned int & k) ->
decltype(v.template getProp<prp>(k))
168 return v.template getProp<prp>(k);
180template <
typename vector>
196template<
unsigned int prp ,
bool is_sort,
int impl>
199 template<
typename vector,
typename expr>
200 static void compute_expr(vector & v,expr & v_exp)
203 template<
unsigned int n,
typename vector,
typename expr>
204 static void compute_expr_slice(vector & v,expr & v_exp,
int (& comp)[n])
207 template<
typename vector>
208 static void compute_const(vector & v,
double d)
214template<
unsigned int,
bool is_val
id>
217 template<
typename exp_type>
220 return o1.value(key);
223 template<
unsigned int prop,
typename exp_type,
typename vector_type>
229 template<
unsigned int prop,
typename exp_type,
typename vector_type>
230 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const unsigned int & key_orig)
235 template<
unsigned int prop,
typename vector_type>
245 template<
typename exp_type>
246 __device__ __host__
static int get(exp_type & o1,
const vect_dist_key_dx & key,
const int (& comp)[1])
248 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
252 template<
unsigned int prop,
typename exp_type,
typename vector_type>
255 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
258 template<
unsigned int prop,
typename exp_type,
typename vector_type>
259 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const vect_dist_key_dx & key_orig,
const int (& comp)[1])
261 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
264 template<
unsigned int prop,
typename exp_type,
typename vector_type>
267 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
270 template<
unsigned int prop,
typename exp_type,
typename vector_type>
271 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const unsigned int & key_orig,
const Point<1,int> & comp)
273 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
276 template<
unsigned int prop,
typename vector_type>
279 printf(
"ERROR: Slicer, the expression is incorrect, please check it\n");
286 template<
typename exp_type>
289 return o1.value(key)[comp[0]];
292 template<
unsigned int prop,
typename exp_type,
typename vector_type>
298 template<
unsigned int prop,
typename exp_type,
typename vector_type>
299 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const unsigned int & key_orig,
const int (& comp)[1])
304 template<
unsigned int prop,
typename exp_type,
typename vector_type>
310 template<
unsigned int prop,
typename exp_type,
typename vector_type>
311 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const unsigned int & key_orig,
const Point<1,int> & comp)
316 template<
unsigned int prop,
typename vector_type>
326 template<
typename exp_type>
329 return o1.value(key)[comp[0]][comp[1]];
332 template<
unsigned int prop,
typename exp_type,
typename vector_type>
338 template<
unsigned int prop,
typename exp_type,
typename vector_type>
344 template<
unsigned int prop,
typename exp_type,
typename vector_type>
345 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const unsigned int & key_orig,
const int (& comp)[2])
350 template<
unsigned int prop,
typename exp_type,
typename vector_type>
351 __device__ __host__
inline static void assign(exp_type & o1,
vector_type & v,
const unsigned int & key,
const unsigned int & key_orig,
const Point<2,int> & comp)
356 template<
unsigned int prop,
typename vector_type>
365template<
unsigned int prp>
368 template<
typename vector,
typename expr>
369 static void compute_expr(vector & v,expr & v_exp)
373 auto it = v.getDomainIterator();
378 auto key_orig = v.getOriginKey(key);
386 template<
unsigned int n,
typename vector,
typename expr>
387 static void compute_expr_slice(vector & v,expr & v_exp,
int (& comp)[n])
389 typedef typename pos_or_propL<vector,prp>::property_act property_act;
394 auto &v2=v_exp.getVector();
396 SubsetSelector_impl<std::remove_reference<
decltype(v)>::type::is_it_a_subset::value>::check(v2,v);
399 auto it = v.getDomainIterator();
404 auto key_orig = v.getOriginKey(key);
412 template<
typename vector>
413 static void compute_const(vector & v,
double d)
415 auto it = v.getDomainIterator();
420 auto key_orig = v.getOriginKey(key);
433template<
unsigned int prp,
unsigned int dim ,
typename vector,
typename expr>
434__global__
void compute_expr_ker_vv(vector vd, expr v_exp)
436 unsigned int p = threadIdx.x + blockIdx.x * blockDim.x;
438 if (p >= vd.size()) {
return;}
440 for (
unsigned int i = 0 ; i < dim ; i++)
442 vd.template get<prp>(p)[i] = v_exp.value(p).get(i);
446template<
unsigned int prp,
typename vector,
typename expr>
447__global__
void compute_expr_ker_v(vector vd, expr v_exp)
449 unsigned int p = threadIdx.x + blockIdx.x * blockDim.x;
451 if (p >= vd.size()) {
return;}
453 vd.template get<prp>(p) = v_exp.value(p);
456template<
unsigned int prp,
typename vector,
typename expr>
457__global__
void compute_expr_ker(vector vd, expr v_exp)
459 unsigned int p = threadIdx.x + blockIdx.x * blockDim.x;
461 if (p >= vd.size_local()) {
return;}
469 template<
typename _Tp,
typename _Up = _Tp&&>
470 __device__ __host__ _Up
473 template<
typename _Tp>
474 __device__ __host__ _Tp
477 template<
typename _Tp>
478 __device__ __host__
auto declval() noexcept -> decltype(__declval<_Tp>(0))
480 return __declval<_Tp>(0);
484template<
unsigned int prp,
unsigned int n,
typename vector,
typename expr>
485__global__
void compute_expr_ker_slice(vector vd, expr v_exp,
Point<n,int> comp)
489 unsigned int p = threadIdx.x + blockIdx.x * blockDim.x;
491 if (p >= vd.size_local()) {
return;}
496template<
unsigned int prp,
typename vector>
497__global__
void compute_double_ker(vector vd,
double d)
499 unsigned int p = threadIdx.x + blockIdx.x * blockDim.x;
501 if (p >= vd.size_local()) {
return;}
508template<
unsigned int prp,
unsigned int dim ,
typename vector,
typename NN_type,
typename expr>
509__global__
void compute_expr_ker_sort_vv(vector vd, NN_type NN, expr v_exp)
513 GET_PARTICLE_SORT(p,NN);
515 for (
unsigned int i = 0 ; i < dim ; i++)
517 vd.template get<prp>(p)[i] = v_exp.value(p).get(i);
521template<
unsigned int prp,
typename vector,
typename NN_type,
typename expr>
522__global__
void compute_expr_ker_sort_v(vector vd, NN_type NN, expr v_exp)
526 GET_PARTICLE_SORT(p,NN);
528 vd.template get<prp>(p) = v_exp.value(p);
531template<
unsigned int prp,
typename vector,
typename expr,
typename NN_type>
532__global__
void compute_expr_ker_sort(vector vd, NN_type NN, expr v_exp)
536 GET_PARTICLE_SORT(p,NN);
544template<
unsigned int prp>
547 template<
typename vector,
typename expr>
548 static void compute_expr(vector & v,expr & v_exp)
552 auto ite = v.getDomainIteratorGPU(256);
554 CUDA_LAUNCH((compute_expr_ker<prp>),ite,v,v_exp);
557 template<
unsigned int n,
typename vector,
typename expr>
558 static void compute_expr_slice(vector & v,expr & v_exp,
int (& comp)[n])
562 auto ite = v.getDomainIteratorGPU(256);
565 for (
int i = 0 ; i < n ; i++) {comp_[i] = comp[i];}
567 CUDA_LAUNCH((compute_expr_ker_slice<prp,n>),ite,v,v_exp,comp);
570 template<
typename vector,
typename expr>
571 static void compute_expr_v(vector & v,expr & v_exp)
575 auto ite = v.getGPUIterator(256);
577 CUDA_LAUNCH((compute_expr_ker_v<prp>),ite,v,v_exp);
580 template<
unsigned int dim,
typename vector,
typename expr>
581 static void compute_expr_vv(vector & v,expr & v_exp)
585 auto ite = v.getGPUIterator(256);
587 CUDA_LAUNCH((compute_expr_ker_vv<prp,dim>),ite,v,v_exp);
590 template<
typename vector>
591 static void compute_const(vector & v,
double d)
593 auto ite = v.getDomainIteratorGPU(256);
595 CUDA_LAUNCH((compute_double_ker<prp>),ite,v,d);
599template<
unsigned int prp>
602 template<
typename vector,
typename expr>
603 static void compute_expr(vector & v,expr & v_exp)
607 auto ite = v.getDomainIteratorGPU(256);
609 auto NN = v_exp.getNN();
611 CUDA_LAUNCH((compute_expr_ker_sort<prp>),ite,v,*NN,v_exp);
614 template<
typename vector,
typename expr>
615 static void compute_expr_v(vector & v,expr & v_exp)
619 auto ite = v.getGPUIterator(256);
621 auto NN = v_exp.getNN();
623 CUDA_LAUNCH((compute_expr_ker_sort_v<prp>),ite,v,*NN,v_exp);
626 template<
unsigned int dim,
typename vector,
typename expr>
627 static void compute_expr_vv(vector & v,expr & v_exp)
631 auto ite = v.getGPUIterator(256);
633 auto NN = v_exp.getNN();
635 CUDA_LAUNCH((compute_expr_ker_sort_vv<prp,dim>),ite,v,*NN,v_exp);
This class implement the point shape in an N-dimensional space.
Grid key for a distributed grid.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
convert a type into constant type
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
__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 __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 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
__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
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