17#include <TRUSTVect_tools.tpp>
20#include <View_Types.h>
23#include <MD_Vector_seq.h>
26#include <Perf_counters.h>
43template <
typename _SIZE_>
44Block_Iter<_SIZE_> determine_blocks(Mp_vect_options opt,
const MD_Vector& md,
const _SIZE_ vect_size_tot,
const int line_size,
int& nblocs_left)
54 const bool use_blocks = (opt != VECT_ALL_ITEMS && md && md->
use_blocks());
58 assert(opt == VECT_SEQUENTIAL_ITEMS || opt == VECT_REAL_ITEMS);
61 assert( (!std::is_same<_SIZE_,std::int64_t>::value) );
71 if (vect_size_tot > 0)
82template Block_Iter<int> determine_blocks(Mp_vect_options opt,
const MD_Vector& md,
const int vect_size_tot,
const int line_size,
int& nblocs_left);
84template Block_Iter<trustIdType> determine_blocks(Mp_vect_options opt,
const MD_Vector& md,
const trustIdType vect_size_tot,
const int line_size,
int& nblocs_left);
88template<
typename _TYPE_,
typename _SIZE_>
92 ToDo_Kokkos(
"critical");
107 Block_Iter<_SIZE_> bloc_itr = ::determine_blocks(opt, md, vect_size_tot, line_size, nblocs_left);
109 if (bloc_itr.
empty())
return;
111 _TYPE_ *resu_base = resu.
addr();
112 const _TYPE_ *x_base = vx.
addr();
113 const _TYPE_ *y_base = vy.
addr();
114 for (; nblocs_left; nblocs_left--)
117 const int begin_bloc = (*(bloc_itr++)) * line_size, end_bloc = (*(bloc_itr++)) * line_size;
118 assert(begin_bloc >= 0 && end_bloc <= vect_size_tot && end_bloc >= begin_bloc);
119 _TYPE_ *resu_ptr = resu_base + begin_bloc;
120 const _TYPE_ *x_ptr = x_base + begin_bloc;
121 const _TYPE_ *y_ptr = y_base + begin_bloc;
122 int count = end_bloc - begin_bloc;
123 for (; count; count--)
125 const _TYPE_ x = *x_ptr;
126 const _TYPE_ y = *(y_ptr++);
127 _TYPE_& p_resu = *(resu_ptr++);
128 p_resu += alpha * x * y;
134 invalidate_data(resu, opt);
150template<
typename ExecSpace,
typename _TYPE_,
typename _SIZE_,
bool IS_MUL>
152 Block_Iter<_SIZE_>& bloc_itr,
const int line_size_vx,
const _SIZE_ vect_size_tot,
const int delta_line_size)
154 auto vx_view= vx.template view_ro<1, ExecSpace>().
data();
155 auto resu_view= resu.template view_rw<1, ExecSpace>().
data();
157 if (nblocs_left>3) ToDo_Kokkos(
"nblocs_left too high, optimize by rewriting as local_operations_vect_bis_generic_kernel");
159 for (; nblocs_left; nblocs_left--)
162 const int begin_bloc = (*(bloc_itr++)) * line_size_vx;
163 const int end_bloc = (*(bloc_itr++)) * line_size_vx;
165 assert(begin_bloc >= 0 && end_bloc <= vect_size_tot && end_bloc >= begin_bloc);
168 const int resu_start_idx = begin_bloc * delta_line_size;
170 Kokkos::RangePolicy<ExecSpace> policy(begin_bloc, end_bloc);
171 if (statistics().get_use_gpu()) start_gpu_timer(__KERNEL_NAME__);
172 Kokkos::parallel_for(policy, KOKKOS_LAMBDA(
const int i)
174 const _TYPE_ x = vx_view[i];
177 for (
int j = 0; j < delta_line_size; ++j)
179 const int resu_idx = resu_start_idx + i * delta_line_size + j;
181 resu_view[resu_idx] *= x;
183 resu_view[resu_idx] *= ((_TYPE_)1 / x);
186 if (statistics().get_use_gpu()) end_gpu_timer(__KERNEL_NAME__, is_default_exec_space<ExecSpace>);
192template<TYPE_OPERATION_VECT_SPEC_GENERIC _TYPE_OP_,
typename _TYPE_,
typename _SIZE_>
198 static constexpr bool IS_MUL = (_TYPE_OP_ == TYPE_OPERATION_VECT_SPEC_GENERIC::MUL_);
204 assert(line_size > 0 && line_size_vx > 0 && line_size % line_size_vx == 0);
205 const int delta_line_size = line_size / line_size_vx;
206 assert(vx.
size_totale() * delta_line_size == vect_size_tot);
211 Block_Iter<_SIZE_> bloc_itr = ::determine_blocks(opt, md, vect_size_tot, line_size, nblocs_left);
213 if (bloc_itr.
empty())
220 operation_speciale_tres_generic_kernel<Kokkos::DefaultExecutionSpace, _TYPE_, _SIZE_, IS_MUL>(resu, vx, nblocs_left, bloc_itr, line_size_vx, vect_size_tot, delta_line_size);
222 operation_speciale_tres_generic_kernel<Kokkos::DefaultHostExecutionSpace, _TYPE_, _SIZE_, IS_MUL>(resu, vx, nblocs_left, bloc_itr, line_size_vx, vect_size_tot, delta_line_size);
226 invalidate_data(resu, opt);
230 Cerr <<
"Error! operation_speciale_tres_generic can't be called in your project!" << finl;
245template<
typename ExecSpace,
typename _TYPE_,
typename _SIZE_,
bool IS_ADD>
249 auto vx_view= vx.template view_ro<1, ExecSpace>().
data();
250 auto resu_view= resu.template view_rw<1, ExecSpace>().
data();
252 if (nblocs_left>3) ToDo_Kokkos(
"nblocs_left too high, optimize by rewriting as local_operations_vect_bis_generic_kernel");
254 for (; nblocs_left; nblocs_left--)
257 const _SIZE_ begin_bloc = (*(bloc_itr++)) * line_size;
258 const _SIZE_ end_bloc = (*(bloc_itr++)) * line_size;
260 assert(begin_bloc >= 0 && end_bloc <= vect_size_tot && end_bloc >= begin_bloc);
262 Kokkos::RangePolicy<ExecSpace> policy(begin_bloc, end_bloc);
263 if (statistics().get_use_gpu()) start_gpu_timer(__KERNEL_NAME__);
264 Kokkos::parallel_for(policy, KOKKOS_LAMBDA(
const int i)
266 const _TYPE_ x = vx_view[i];
269 resu_view[i] += alpha * x;
271 resu_view[i] += alpha * x * x;
273 if (statistics().get_use_gpu()) end_gpu_timer(__KERNEL_NAME__, is_default_exec_space<ExecSpace>);
279template <TYPE_OPERATION_VECT_SPEC _TYPE_OP_ ,
typename _TYPE_,
typename _SIZE_>
284 static constexpr bool IS_ADD = (_TYPE_OP_ == TYPE_OPERATION_VECT_SPEC::ADD_);
293 Block_Iter<_SIZE_> bloc_itr = ::determine_blocks(opt, md, vect_size_tot, line_size, nblocs_left);
295 if (bloc_itr.
empty())
return;
300 operation_speciale_generic_kernel<Kokkos::DefaultExecutionSpace, _TYPE_, _SIZE_, IS_ADD>(resu, vx, alpha, nblocs_left, bloc_itr, vect_size_tot, line_size);
302 operation_speciale_generic_kernel<Kokkos::DefaultHostExecutionSpace, _TYPE_, _SIZE_, IS_ADD>(resu, vx, alpha, nblocs_left, bloc_itr, vect_size_tot, line_size);
306 invalidate_data(resu, opt);
310 Cerr <<
"Error! ajoute_operation_speciale_generic can't be called in your project!" << finl;
324template<
typename ExecSpace,
typename _TYPE_,
typename _SIZE_, TYPE_OPERATOR_VECT _TYPE_OP_>
328 static constexpr bool IS_ADD = (_TYPE_OP_ == TYPE_OPERATOR_VECT::ADD_), IS_SUB = (_TYPE_OP_ == TYPE_OPERATOR_VECT::SUB_),
329 IS_MULT = (_TYPE_OP_ == TYPE_OPERATOR_VECT::MULT_), IS_DIV = (_TYPE_OP_ == TYPE_OPERATOR_VECT::DIV_),
330 IS_EGAL = (_TYPE_OP_ == TYPE_OPERATOR_VECT::EGAL_);
333 auto vx_view= vx.template view_ro<1, ExecSpace>().
data();
334 auto resu_view= resu.template view_rw<1, ExecSpace>().
data();
336 if (nblocs_left>3) ToDo_Kokkos(
"nblocs_left too high, optimize by rewriting as local_operations_vect_bis_generic_kernel");
338 for (; nblocs_left; nblocs_left--)
341 const _SIZE_ begin_bloc = (*(bloc_itr++)) * line_size;
342 const _SIZE_ end_bloc = (*(bloc_itr++)) * line_size;
344 assert(begin_bloc >= 0 && end_bloc <= vect_size_tot && end_bloc >= begin_bloc);
345 Kokkos::RangePolicy<ExecSpace> policy(begin_bloc, end_bloc);
346 if (statistics().get_use_gpu()) start_gpu_timer(__KERNEL_NAME__);
347 Kokkos::parallel_for(policy, KOKKOS_LAMBDA(
const _SIZE_ i)
349 const _TYPE_ x = vx_view[i];
350 if (IS_ADD) resu_view[i] += x;
351 if (IS_SUB) resu_view[i] -= x;
352 if (IS_MULT) resu_view[i] *= x;
353 if (IS_DIV) resu_view[i] /= x;
354 if (IS_EGAL) resu_view[i] = x;
356 if (statistics().get_use_gpu()) end_gpu_timer(__KERNEL_NAME__, is_default_exec_space<ExecSpace>);
360 _TYPE_ *resu_base = resu.
data();
361 const _TYPE_ *x_base = vx.
data();
362 for (; nblocs_left; nblocs_left--)
365 const _SIZE_ begin_bloc = (*(bloc_itr++)) * line_size, end_bloc = (*(bloc_itr++)) * line_size;
366 assert(begin_bloc >= 0 && end_bloc <= vect_size_tot && end_bloc >= begin_bloc);
367 _TYPE_ *resu_ptr = resu_base + begin_bloc;
368 const _TYPE_ *x_ptr = x_base + begin_bloc;
369 for (_SIZE_ count = 0; count < end_bloc - begin_bloc ; count++)
371 const _TYPE_& x = x_ptr[count];
372 _TYPE_ &p_resu = resu_ptr[count];
373 if (IS_ADD) p_resu += x;
374 if (IS_SUB) p_resu -= x;
375 if (IS_MULT) p_resu *= x;
376 if (IS_EGAL) p_resu = x;
377 if (IS_DIV) p_resu /= x;
386template <
typename _TYPE_,
typename _SIZE_, TYPE_OPERATOR_VECT _TYPE_OP_>
397 Block_Iter<_SIZE_> bloc_itr = ::determine_blocks(opt, md, vect_size_tot, line_size, nblocs_left);
399 if (bloc_itr.
empty())
return;
404 operator_vect_vect_generic_kernel<Kokkos::DefaultExecutionSpace, _TYPE_, _SIZE_, _TYPE_OP_>(resu, vx, nblocs_left, bloc_itr, vect_size_tot, line_size);
406 operator_vect_vect_generic_kernel<Kokkos::DefaultHostExecutionSpace, _TYPE_, _SIZE_, _TYPE_OP_>(resu, vx, nblocs_left, bloc_itr, vect_size_tot, line_size);
409 invalidate_data(resu, opt);
413 Cerr <<
"Error! operator_vect_vect_generic can't be called in your project!" << finl;
437template<
typename ExecSpace,
typename _TYPE_,
typename _SIZE_, TYPE_OPERATOR_SINGLE _TYPE_OP_>
441 static constexpr bool IS_ADD = (_TYPE_OP_ == TYPE_OPERATOR_SINGLE::ADD_), IS_SUB = (_TYPE_OP_ == TYPE_OPERATOR_SINGLE::SUB_),
442 IS_MULT = (_TYPE_OP_ == TYPE_OPERATOR_SINGLE::MULT_), IS_DIV = (_TYPE_OP_ == TYPE_OPERATOR_SINGLE::DIV_), IS_EGAL = (_TYPE_OP_ == TYPE_OPERATOR_SINGLE::EGAL_),
443 IS_NEGATE = (_TYPE_OP_ == TYPE_OPERATOR_SINGLE::NEGATE_), IS_INV = (_TYPE_OP_ == TYPE_OPERATOR_SINGLE::INV_), IS_ABS = (_TYPE_OP_ == TYPE_OPERATOR_SINGLE::ABS_),
444 IS_SQRT = (_TYPE_OP_ == TYPE_OPERATOR_SINGLE::SQRT_), IS_SQUARE = (_TYPE_OP_ == TYPE_OPERATOR_SINGLE::SQUARE_);
446 auto resu_view= resu.template view_rw<1, ExecSpace>().
data();
448 if (nblocs_left>3) ToDo_Kokkos(
"nblocs_left too high, optimize by rewriting as local_operations_vect_bis_generic_kernel");
450 for (; nblocs_left; nblocs_left--)
453 const _SIZE_ begin_bloc = (*(bloc_itr++)) * line_size;
454 const _SIZE_ end_bloc = (*(bloc_itr++)) * line_size;
456 assert(begin_bloc >= 0 && end_bloc <= vect_size_tot && end_bloc >= begin_bloc);
457 Kokkos::RangePolicy<ExecSpace> policy(begin_bloc, end_bloc);
458 if (statistics().get_use_gpu()) start_gpu_timer(__KERNEL_NAME__);
459 Kokkos::parallel_for(policy, KOKKOS_LAMBDA(
const _SIZE_ i)
461 if (IS_SUB) resu_view[i] -= x;
462 if (IS_ADD) resu_view[i] += x;
463 if (IS_MULT) resu_view[i] *= x;
464 if (IS_EGAL) resu_view[i] = x;
465 if (IS_NEGATE) resu_view[i] = -resu_view[i];
466 if (IS_ABS) resu_view[i] = (_TYPE_) Kokkos::abs(resu_view[i]);
467 if (IS_SQRT) resu_view[i] = (_TYPE_) Kokkos::sqrt(resu_view[i]);
468 if (IS_SQUARE) resu_view[i] = resu_view[i]*resu_view[i];
469 if (IS_DIV) resu_view[i] /= x;
470 if (IS_INV) resu_view[i] = (_TYPE_) ((_TYPE_)1 /resu_view[i]);
472 if (statistics().get_use_gpu()) end_gpu_timer(__KERNEL_NAME__, is_default_exec_space<ExecSpace>);
479template <
typename _TYPE_,
typename _SIZE_, TYPE_OPERATOR_SINGLE _TYPE_OP_ >
488 Block_Iter<_SIZE_> bloc_itr = ::determine_blocks(opt, md, vect_size_tot, line_size, nblocs_left);
490 if (bloc_itr.
empty())
return;
495 operator_vect_single_generic_kernel<Kokkos::DefaultExecutionSpace, _TYPE_, _SIZE_, _TYPE_OP_>(resu, x, nblocs_left, bloc_itr, vect_size_tot, line_size);
497 operator_vect_single_generic_kernel<Kokkos::DefaultHostExecutionSpace, _TYPE_, _SIZE_, _TYPE_OP_>(resu, x, nblocs_left, bloc_itr, vect_size_tot, line_size);
501 invalidate_data(resu, opt);
505 Cerr <<
"Error! operator_vect_single_generic can't be called in your project!" << finl;
510template void operator_vect_single_generic<double, int, TYPE_OPERATOR_SINGLE::ADD_>(
TRUSTVect<double, int>& resu,
const double x, Mp_vect_options opt);
511template void operator_vect_single_generic<int, int, TYPE_OPERATOR_SINGLE::ADD_>(
TRUSTVect<int, int>& resu,
const int x, Mp_vect_options opt);
512template void operator_vect_single_generic<float, int, TYPE_OPERATOR_SINGLE::ADD_>(
TRUSTVect<float, int>& resu,
const float x, Mp_vect_options opt);
513template void operator_vect_single_generic<double, int, TYPE_OPERATOR_SINGLE::SUB_>(
TRUSTVect<double, int>& resu,
const double x, Mp_vect_options opt);
514template void operator_vect_single_generic<int, int, TYPE_OPERATOR_SINGLE::SUB_>(
TRUSTVect<int, int>& resu,
const int x, Mp_vect_options opt);
515template void operator_vect_single_generic<float, int, TYPE_OPERATOR_SINGLE::SUB_>(
TRUSTVect<float, int>& resu,
const float x, Mp_vect_options opt);
516template void operator_vect_single_generic<double, int, TYPE_OPERATOR_SINGLE::MULT_>(
TRUSTVect<double, int>& resu,
const double x, Mp_vect_options opt);
517template void operator_vect_single_generic<int, int, TYPE_OPERATOR_SINGLE::MULT_>(
TRUSTVect<int, int>& resu,
const int x, Mp_vect_options opt);
518template void operator_vect_single_generic<float, int, TYPE_OPERATOR_SINGLE::MULT_>(
TRUSTVect<float, int>& resu,
const float x, Mp_vect_options opt);
519template void operator_vect_single_generic<double, int, TYPE_OPERATOR_SINGLE::DIV_>(
TRUSTVect<double, int>& resu,
const double x, Mp_vect_options opt);
520template void operator_vect_single_generic<int, int, TYPE_OPERATOR_SINGLE::DIV_>(
TRUSTVect<int, int>& resu,
const int x, Mp_vect_options opt);
521template void operator_vect_single_generic<float, int, TYPE_OPERATOR_SINGLE::DIV_>(
TRUSTVect<float, int>& resu,
const float x, Mp_vect_options opt);
522template void operator_vect_single_generic<double, int, TYPE_OPERATOR_SINGLE::EGAL_>(
TRUSTVect<double, int>& resu,
const double x, Mp_vect_options opt);
523template void operator_vect_single_generic<int, int, TYPE_OPERATOR_SINGLE::EGAL_>(
TRUSTVect<int, int>& resu,
const int x, Mp_vect_options opt);
524template void operator_vect_single_generic<float, int, TYPE_OPERATOR_SINGLE::EGAL_>(
TRUSTVect<float, int>& resu,
const float x, Mp_vect_options opt);
525template void operator_vect_single_generic<double, int, TYPE_OPERATOR_SINGLE::NEGATE_>(
TRUSTVect<double, int>& resu,
const double x, Mp_vect_options opt);
526template void operator_vect_single_generic<int, int, TYPE_OPERATOR_SINGLE::NEGATE_>(
TRUSTVect<int, int>& resu,
const int x, Mp_vect_options opt);
527template void operator_vect_single_generic<float, int, TYPE_OPERATOR_SINGLE::NEGATE_>(
TRUSTVect<float, int>& resu,
const float x, Mp_vect_options opt);
528template void operator_vect_single_generic<double, int, TYPE_OPERATOR_SINGLE::INV_>(
TRUSTVect<double, int>& resu,
const double x, Mp_vect_options opt);
529template void operator_vect_single_generic<int, int, TYPE_OPERATOR_SINGLE::INV_>(
TRUSTVect<int, int>& resu,
const int x, Mp_vect_options opt);
530template void operator_vect_single_generic<float, int, TYPE_OPERATOR_SINGLE::INV_>(
TRUSTVect<float, int>& resu,
const float x, Mp_vect_options opt);
531template void operator_vect_single_generic<double, int, TYPE_OPERATOR_SINGLE::ABS_>(
TRUSTVect<double, int>& resu,
const double x, Mp_vect_options opt);
532template void operator_vect_single_generic<int, int, TYPE_OPERATOR_SINGLE::ABS_>(
TRUSTVect<int, int>& resu,
const int x, Mp_vect_options opt);
533template void operator_vect_single_generic<float, int, TYPE_OPERATOR_SINGLE::ABS_>(
TRUSTVect<float, int>& resu,
const float x, Mp_vect_options opt);
534template void operator_vect_single_generic<double, int, TYPE_OPERATOR_SINGLE::SQRT_>(
TRUSTVect<double, int>& resu,
const double x, Mp_vect_options opt);
535template void operator_vect_single_generic<int, int, TYPE_OPERATOR_SINGLE::SQRT_>(
TRUSTVect<int, int>& resu,
const int x, Mp_vect_options opt);
536template void operator_vect_single_generic<float, int, TYPE_OPERATOR_SINGLE::SQRT_>(
TRUSTVect<float, int>& resu,
const float x, Mp_vect_options opt);
537template void operator_vect_single_generic<double, int, TYPE_OPERATOR_SINGLE::SQUARE_>(
TRUSTVect<double, int>& resu,
const double x, Mp_vect_options opt);
538template void operator_vect_single_generic<int, int, TYPE_OPERATOR_SINGLE::SQUARE_>(
TRUSTVect<int, int>& resu,
const int x, Mp_vect_options opt);
539template void operator_vect_single_generic<float, int, TYPE_OPERATOR_SINGLE::SQUARE_>(
TRUSTVect<float, int>& resu,
const float x, Mp_vect_options opt);
542template void operator_vect_single_generic<trustIdType, trustIdType, TYPE_OPERATOR_SINGLE::ADD_>(
TRUSTVect<trustIdType, trustIdType>& resu,
const trustIdType x, Mp_vect_options opt);
543template void operator_vect_single_generic<int, trustIdType, TYPE_OPERATOR_SINGLE::ADD_>(
TRUSTVect<int, trustIdType>& resu,
const int x, Mp_vect_options opt);
544template void operator_vect_single_generic<float, trustIdType, TYPE_OPERATOR_SINGLE::ADD_>(
TRUSTVect<float, trustIdType>& resu,
const float x, Mp_vect_options opt);
545template void operator_vect_single_generic<double, trustIdType, TYPE_OPERATOR_SINGLE::ADD_>(
TRUSTVect<double, trustIdType>& resu,
const double x, Mp_vect_options opt);
547template void operator_vect_single_generic<trustIdType, trustIdType, TYPE_OPERATOR_SINGLE::SUB_>(
TRUSTVect<trustIdType, trustIdType>& resu,
const trustIdType x, Mp_vect_options opt);
548template void operator_vect_single_generic<int, trustIdType, TYPE_OPERATOR_SINGLE::SUB_>(
TRUSTVect<int, trustIdType>& resu,
const int x, Mp_vect_options opt);
549template void operator_vect_single_generic<float, trustIdType, TYPE_OPERATOR_SINGLE::SUB_>(
TRUSTVect<float, trustIdType>& resu,
const float x, Mp_vect_options opt);
550template void operator_vect_single_generic<double, trustIdType, TYPE_OPERATOR_SINGLE::SUB_>(
TRUSTVect<double, trustIdType>& resu,
const double x, Mp_vect_options opt);
552template void operator_vect_single_generic<double, trustIdType, TYPE_OPERATOR_SINGLE::MULT_>(
TRUSTVect<double, trustIdType>& resu,
const double x, Mp_vect_options opt);
553template void operator_vect_single_generic<float, trustIdType, TYPE_OPERATOR_SINGLE::MULT_>(
TRUSTVect<float, trustIdType>& resu,
const float x, Mp_vect_options opt);
555template void operator_vect_single_generic<double, trustIdType, TYPE_OPERATOR_SINGLE::DIV_>(
TRUSTVect<double, trustIdType>& resu,
const double x, Mp_vect_options opt);
563template<
typename ExecSpace,
typename _TYPE_,
typename _SIZE_,
typename _TYPE_RETURN_, TYPE_OPERATION_VECT _TYPE_OP_>
565 const _SIZE_ vect_size_tot,
const int line_size, _TYPE_& min_max_val,
int& i_min_max)
568 if (bloc_itr.
empty()) return ;
570 static constexpr bool IS_IMAX = (_TYPE_OP_ == TYPE_OPERATION_VECT::IMAX_), IS_IMIN = (_TYPE_OP_ == TYPE_OPERATION_VECT::IMIN_), IS_MAX = (_TYPE_OP_ == TYPE_OPERATION_VECT::MAX_),
571 IS_MIN = (_TYPE_OP_ == TYPE_OPERATION_VECT::MIN_), IS_MAX_ABS = (_TYPE_OP_ == TYPE_OPERATION_VECT::MAX_ABS_), IS_MIN_ABS = (_TYPE_OP_ == TYPE_OPERATION_VECT::MIN_ABS_);
574 static constexpr bool IS_MAXS = (IS_MAX || IS_MAX_ABS || IS_IMAX);
575 static constexpr bool IS_MINS = (IS_MIN || IS_MIN_ABS || IS_IMIN);
576 static constexpr bool IS_ABS = (IS_MAX_ABS || IS_MIN_ABS);
579 using reducer =
typename std::conditional<IS_MAXS, Kokkos::MaxLoc<_TYPE_, int>, Kokkos::MinLoc<_TYPE_, int>>::type;
581 using reducer_value_type =
typename reducer::value_type;
583 if (not(IS_MAXS || IS_MINS)) {
Process::exit(
"Wrong operation type in local_extrema_vect_generic_kernel");}
585 auto vx_view= vx.template view_ro<1, ExecSpace>().
data();
587 if (nblocs_left>3) ToDo_Kokkos(
"nblocs_left too high, optimize by rewriting as local_operations_vect_bis_generic_kernel");
589 for (; nblocs_left; nblocs_left--)
592 const _SIZE_ begin_bloc = (*(bloc_itr++)) * line_size;
593 const _SIZE_ end_bloc = (*(bloc_itr++)) * line_size;
596 assert(begin_bloc >= 0 && end_bloc <= vect_size_tot && end_bloc >= begin_bloc);
599 Kokkos::RangePolicy<ExecSpace> policy(begin_bloc, end_bloc);
602 reducer_value_type bloc_min_max;
605 if (statistics().get_use_gpu()) start_gpu_timer(__KERNEL_NAME__);
606 Kokkos::parallel_reduce(policy,
607 KOKKOS_LAMBDA(
const int i, reducer_value_type& local_min_max)
609 const _TYPE_ val = (IS_ABS) ? Kokkos::abs(vx_view[i]) : vx_view[i];
611 if ( (IS_MAXS && val>local_min_max.val) || (IS_MINS && val<local_min_max.val) )
613 local_min_max.val=val;
617 ,reducer(bloc_min_max));
618 if (statistics().get_use_gpu()) end_gpu_timer(__KERNEL_NAME__, is_default_exec_space<ExecSpace>);
621 if ( (IS_MAXS && bloc_min_max.val > min_max_val) || (IS_MINS && bloc_min_max.val < min_max_val) )
623 min_max_val=bloc_min_max.val;
624 i_min_max= bloc_min_max.loc;
631template <
typename _TYPE_,
typename _SIZE_,
typename _TYPE_RETURN_, TYPE_OPERATION_VECT _TYPE_OP_ >
648 Block_Iter<_SIZE_> bloc_itr = ::determine_blocks(opt, md, vect_size_tot, line_size, nblocs_left);
651 _TYPE_ min_max_val = neutral_value<_TYPE_,_TYPE_OP_>();
659 local_extrema_vect_generic_kernel<Kokkos::DefaultExecutionSpace, _TYPE_, _SIZE_, _TYPE_RETURN_, _TYPE_OP_>(vx, nblocs_left, bloc_itr, vect_size_tot, line_size, min_max_val, i_min_max);
661 local_extrema_vect_generic_kernel<Kokkos::DefaultHostExecutionSpace, _TYPE_, _SIZE_, _TYPE_RETURN_, _TYPE_OP_>(vx, nblocs_left, bloc_itr, vect_size_tot, line_size, min_max_val, i_min_max);
664 static constexpr bool IS_IMAX = (_TYPE_OP_ == TYPE_OPERATION_VECT::IMAX_), IS_IMIN = (_TYPE_OP_ == TYPE_OPERATION_VECT::IMIN_);
666 return (IS_IMAX || IS_IMIN) ? (_TYPE_RETURN_)i_min_max : (_TYPE_RETURN_)min_max_val;
669 Cerr <<
"Error! local_extrema_vect_generic can't be called in your project!" << finl;
671 return (_TYPE_RETURN_)0;
675template double local_extrema_vect_generic<double, int, double, TYPE_OPERATION_VECT::IMAX_>(
const TRUSTVect<double, int>& vx, Mp_vect_options opt);
676template double local_extrema_vect_generic<double, int, double, TYPE_OPERATION_VECT::IMIN_>(
const TRUSTVect<double, int>& vx, Mp_vect_options opt);
677template double local_extrema_vect_generic<double, int, double, TYPE_OPERATION_VECT::MAX_>(
const TRUSTVect<double, int>& vx, Mp_vect_options opt);
678template double local_extrema_vect_generic<double, int, double, TYPE_OPERATION_VECT::MIN_>(
const TRUSTVect<double, int>& vx, Mp_vect_options opt);
679template double local_extrema_vect_generic<double, int, double, TYPE_OPERATION_VECT::MAX_ABS_>(
const TRUSTVect<double, int>& vx, Mp_vect_options opt);
680template double local_extrema_vect_generic<double, int, double, TYPE_OPERATION_VECT::MIN_ABS_>(
const TRUSTVect<double, int>& vx, Mp_vect_options opt);
681template int local_extrema_vect_generic<double, int, int, TYPE_OPERATION_VECT::IMAX_>(
const TRUSTVect<double, int>& vx, Mp_vect_options opt);
682template int local_extrema_vect_generic<double, int, int, TYPE_OPERATION_VECT::IMIN_>(
const TRUSTVect<double, int>& vx, Mp_vect_options opt);
683template int local_extrema_vect_generic<double, int, int, TYPE_OPERATION_VECT::MAX_>(
const TRUSTVect<double, int>& vx, Mp_vect_options opt);
684template int local_extrema_vect_generic<double, int, int, TYPE_OPERATION_VECT::MIN_>(
const TRUSTVect<double, int>& vx, Mp_vect_options opt);
685template int local_extrema_vect_generic<double, int, int, TYPE_OPERATION_VECT::MAX_ABS_>(
const TRUSTVect<double, int>& vx, Mp_vect_options opt);
686template int local_extrema_vect_generic<double, int, int, TYPE_OPERATION_VECT::MIN_ABS_>(
const TRUSTVect<double, int>& vx, Mp_vect_options opt);
687template int local_extrema_vect_generic<int, int, int, TYPE_OPERATION_VECT::IMAX_>(
const TRUSTVect<int, int>& vx, Mp_vect_options opt);
688template int local_extrema_vect_generic<int, int, int, TYPE_OPERATION_VECT::IMIN_>(
const TRUSTVect<int, int>& vx, Mp_vect_options opt);
689template int local_extrema_vect_generic<int, int, int, TYPE_OPERATION_VECT::MAX_>(
const TRUSTVect<int, int>& vx, Mp_vect_options opt);
690template int local_extrema_vect_generic<int, int, int, TYPE_OPERATION_VECT::MIN_>(
const TRUSTVect<int, int>& vx, Mp_vect_options opt);
691template int local_extrema_vect_generic<int, int, int, TYPE_OPERATION_VECT::MAX_ABS_>(
const TRUSTVect<int, int>& vx, Mp_vect_options opt);
692template int local_extrema_vect_generic<int, int, int, TYPE_OPERATION_VECT::MIN_ABS_>(
const TRUSTVect<int, int>& vx, Mp_vect_options opt);
695template double local_extrema_vect_generic<double, trustIdType, double, TYPE_OPERATION_VECT::MAX_ABS_>(
const TRUSTVect<double, trustIdType>& vx, Mp_vect_options opt);
696template int local_extrema_vect_generic<int, trustIdType, int, TYPE_OPERATION_VECT::MAX_>(
const TRUSTVect<int, trustIdType>& vx, Mp_vect_options opt);
697template trustIdType local_extrema_vect_generic<trustIdType, trustIdType, trustIdType, TYPE_OPERATION_VECT::MAX_>(
const TRUSTVect<trustIdType, trustIdType>& vx, Mp_vect_options opt);
703template<
typename ExecSpace,
typename _TYPE_,
typename _SIZE_, TYPE_OPERATION_VECT_BIS _TYPE_OP_>
705 Block_Iter<_SIZE_>& bloc_itr,
const _SIZE_ vect_size_tot,
const int line_size, _TYPE_& sum)
707 static constexpr bool IS_SQUARE = (_TYPE_OP_ == TYPE_OPERATION_VECT_BIS::SQUARE_), IS_SUM = (_TYPE_OP_ == TYPE_OPERATION_VECT_BIS::SOMME_);
710 auto vx_view = vx.template view_ro<1, ExecSpace>().
data();
714 auto items = bloc_itr.items_->template view_ro<1, ExecSpace>().data();
716 if (statistics().get_use_gpu()) start_gpu_timer(__KERNEL_NAME__);
717 Kokkos::parallel_reduce(__KERNEL_NAME__,
718 Kokkos::RangePolicy<ExecSpace>(0, bloc_itr.items_->size_array()),
719 KOKKOS_LAMBDA(
const int i, _TYPE_& local_sum)
721 _SIZE_ item = items[i] * line_size;
722 const _TYPE_ x = vx_view[item];
723 if (IS_SQUARE) local_sum += x * x;
724 if (IS_SUM) local_sum += x;
726 if (statistics().get_use_gpu()) end_gpu_timer(__KERNEL_NAME__, is_default_exec_space<ExecSpace>);
730 for (; nblocs_left; nblocs_left--)
733 const _SIZE_ begin_bloc = (*(bloc_itr++)) * line_size;
734 const _SIZE_ end_bloc = (*(bloc_itr++)) * line_size;
736 assert(begin_bloc >= 0 && end_bloc <= vect_size_tot && end_bloc >= begin_bloc);
738 Kokkos::RangePolicy <ExecSpace> policy(begin_bloc, end_bloc);
742 if (statistics().get_use_gpu()) start_gpu_timer(__KERNEL_NAME__);
743 Kokkos::parallel_reduce(policy, KOKKOS_LAMBDA(
744 const _SIZE_ i, _TYPE_
747 const _TYPE_ x = vx_view[i];
748 if (IS_SQUARE) local_sum += x * x;
749 if (IS_SUM) local_sum += x;
752 if (statistics().get_use_gpu()) end_gpu_timer(__KERNEL_NAME__, is_default_exec_space<ExecSpace>);
762template <
typename _TYPE_,
typename _SIZE_, TYPE_OPERATION_VECT_BIS _TYPE_OP_ >
769 const int line_size = master_vect.
line_size();
770 const _SIZE_ vect_size_tot = master_vect.
size_totale();
777 Block_Iter<_SIZE_> bloc_itr = ::determine_blocks(opt, md, vect_size_tot, line_size, nblocs_left);
779 if (bloc_itr.
empty())
return sum;
784 local_operations_vect_bis_generic_kernel<Kokkos::DefaultExecutionSpace, _TYPE_, _SIZE_, _TYPE_OP_>(vx, nblocs_left, bloc_itr, vect_size_tot, line_size, sum);
786 local_operations_vect_bis_generic_kernel<Kokkos::DefaultHostExecutionSpace, _TYPE_, _SIZE_, _TYPE_OP_>(vx, nblocs_left, bloc_itr, vect_size_tot, line_size, sum);
790 Cerr <<
"Error! local_operations_vect_bis_generic can't be called in your project!" << finl;
796template double local_operations_vect_bis_generic<double, int, TYPE_OPERATION_VECT_BIS::SQUARE_>(
const TRUSTVect<double, int>& vx,Mp_vect_options opt);
797template int local_operations_vect_bis_generic<int, int, TYPE_OPERATION_VECT_BIS::SQUARE_>(
const TRUSTVect<int, int>& vx,Mp_vect_options opt);
798template float local_operations_vect_bis_generic<float, int, TYPE_OPERATION_VECT_BIS::SQUARE_>(
const TRUSTVect<float, int>& vx,Mp_vect_options opt);
799template double local_operations_vect_bis_generic<double, int, TYPE_OPERATION_VECT_BIS::SOMME_>(
const TRUSTVect<double, int>& vx,Mp_vect_options opt);
800template int local_operations_vect_bis_generic<int, int, TYPE_OPERATION_VECT_BIS::SOMME_>(
const TRUSTVect<int, int>& vx,Mp_vect_options opt);
801template float local_operations_vect_bis_generic<float, int, TYPE_OPERATION_VECT_BIS::SOMME_>(
const TRUSTVect<float, int>& vx,Mp_vect_options opt);
804template double local_operations_vect_bis_generic<double, trustIdType, TYPE_OPERATION_VECT_BIS::SOMME_>(
const TRUSTVect<double, trustIdType>& vx,Mp_vect_options opt);
815template<
typename ExecSpace,
typename _TYPE_,
typename _SIZE_>
817 const ArrOfInt& items_blocs,
const int line_size,
const int blocs_size)
819 _TYPE_ invalid = (_TYPE_)-987654321;
820 auto resu_view= resu.template view_rw<1, ExecSpace>().
data();
823 for (
int blocs_idx = 0; blocs_idx < blocs_size; blocs_idx += 2)
825 const int bloc_end = line_size * items_blocs[blocs_idx];
827 Kokkos::RangePolicy<ExecSpace> policy(i, bloc_end);
829 if (statistics().get_use_gpu()) start_gpu_timer(__KERNEL_NAME__);
830 Kokkos::parallel_for(policy,KOKKOS_LAMBDA(
const int count)
832 resu_view[count]=invalid;
834 if (statistics().get_use_gpu()) end_gpu_timer(__KERNEL_NAME__, is_default_exec_space<ExecSpace>);
835 i = items_blocs[blocs_idx+1] * line_size;
839 Kokkos::RangePolicy<ExecSpace> policy(i, bloc_end);
841 if (statistics().get_use_gpu()) start_gpu_timer(__KERNEL_NAME__);
842 Kokkos::parallel_for(policy,KOKKOS_LAMBDA(
const int count)
844 resu_view[count]=invalid;
846 if (statistics().get_use_gpu()) end_gpu_timer(__KERNEL_NAME__, is_default_exec_space<ExecSpace>);
851template <
typename _TYPE_,
typename _SIZE_>
859 if (opt == VECT_ALL_ITEMS || (!md))
return;
860 assert(opt == VECT_SEQUENTIAL_ITEMS || opt == VECT_REAL_ITEMS);
862 const int blocs_size = items_blocs.
size_array();
867 invalidate_data_kernel<Kokkos::DefaultExecutionSpace, _TYPE_, _SIZE_>(resu, items_blocs, line_size, blocs_size);
869 invalidate_data_kernel<Kokkos::DefaultHostExecutionSpace, _TYPE_, _SIZE_>(resu, items_blocs, line_size, blocs_size);
871 Cerr <<
"Error! invalidate_data can't be called in your project!" << finl;
886template<
typename ExecSpace,
typename _TYPE_,
typename _SIZE_>
888 Block_Iter<_SIZE_>& bloc_itr,
const int vect_size_tot,
const int line_size, _TYPE_& sum)
890 auto vx_view= vx.template view_ro<1, ExecSpace>().
data();
891 auto vy_view= vy.template view_ro<1, ExecSpace>().
data();
893 if (nblocs_left>3) ToDo_Kokkos(
"nblocs_left too high, optimize by rewriting as local_operations_vect_bis_generic_kernel");
895 for (; nblocs_left; nblocs_left--)
898 const _SIZE_ begin_bloc = (*(bloc_itr++)) * line_size;
899 const _SIZE_ end_bloc = (*(bloc_itr++)) * line_size;
902 assert(begin_bloc >= 0 && end_bloc <= vect_size_tot && end_bloc >= begin_bloc);
905 Kokkos::RangePolicy<ExecSpace> policy(begin_bloc, end_bloc);
911 if (statistics().get_use_gpu()) start_gpu_timer(__KERNEL_NAME__);
912 Kokkos::parallel_reduce(policy, KOKKOS_LAMBDA(
const _SIZE_ i, _TYPE_& local_sum)
914 local_sum += vx_view[i]*vy_view[i];
916 , Kokkos::Sum<_TYPE_>(bloc_sum));
919 if (statistics().get_use_gpu()) end_gpu_timer(__KERNEL_NAME__, is_default_exec_space<ExecSpace>);
928template<
typename _TYPE_,
typename _SIZE_>
943 Block_Iter<_SIZE_> bloc_itr = ::determine_blocks(opt, md, vect_size_tot, line_size, nblocs_left);
945 if (bloc_itr.
empty())
return sum;
950 local_prodscal_kernel<Kokkos::DefaultExecutionSpace, _TYPE_, _SIZE_>(vx, vy, nblocs_left, bloc_itr, vect_size_tot,line_size, sum);
952 local_prodscal_kernel<Kokkos::DefaultHostExecutionSpace, _TYPE_, _SIZE_>(vx, vy, nblocs_left, bloc_itr, vect_size_tot,line_size, sum);
957 Cerr <<
"Error! local_prodscal can't be called in your project!" << finl;
virtual const ArrOfInt & get_blocs_items_to_sum() const =0
virtual const ArrOfInt & get_items_to_sum() const =0
virtual bool use_blocks() const =0
virtual const ArrOfInt & get_items_to_compute() const =0
virtual const ArrOfInt & get_blocs_items_to_compute() const =0
: This class is an OWN_PTR but the pointed object is shared among multiple
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
static bool is_sequential()
_SIZE_ size_array() const
_SIZE_ size_totale() const
virtual const MD_Vector & get_md_vector() const