Skip to content

Commit

Permalink
Using __select_backend in __pattern_walk1 calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Kopienko committed Jan 31, 2024
1 parent 1da80ed commit 2cf29f9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 48 deletions.
6 changes: 4 additions & 2 deletions include/oneapi/dpl/pstl/algorithm_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,10 @@ __pattern_walk1_n(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _Siz
_IsVector __is_vector,
/*is_parallel=*/::std::true_type)
{
oneapi::dpl::__internal::__pattern_walk1(::std::forward<_ExecutionPolicy>(__exec), __first, __first + __n, __f,
__is_vector, ::std::true_type());
constexpr auto __dispatch_tag = oneapi::dpl::__internal::__select_backend<_ExecutionPolicy, _RandomAccessIterator>();

oneapi::dpl::__internal::__pattern_walk1(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
__first + __n, __f);
return __first + __n;
}

Expand Down
69 changes: 33 additions & 36 deletions include/oneapi/dpl/pstl/glue_memory_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,25 +164,24 @@ uninitialized_fill(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Forward
typedef typename ::std::iterator_traits<_ForwardIterator>::value_type _ValueType;
typedef ::std::decay_t<_ExecutionPolicy> _DecayedExecutionPolicy;

constexpr auto __is_parallel =
oneapi::dpl::__internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator>();

if constexpr (::std::is_arithmetic_v<_ValueType>)
{
constexpr auto __is_parallel =
oneapi::dpl::__internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator>();

oneapi::dpl::__internal::__pattern_walk_brick(
::std::forward<_ExecutionPolicy>(__exec), __first, __last,
oneapi::dpl::__internal::__brick_fill<_ValueType, _DecayedExecutionPolicy>{_ValueType(__value)},
__is_parallel);
}
else
{
constexpr auto __is_vector =
oneapi::dpl::__internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator>();
constexpr auto __dispatch_tag = oneapi::dpl::__internal::__select_backend<_ExecutionPolicy, _ForwardIterator>();

oneapi::dpl::__internal::__pattern_walk1(
__dispatch_tag,
::std::forward<_ExecutionPolicy>(__exec), __first, __last,
oneapi::dpl::__internal::__op_uninitialized_fill<_Tp, _DecayedExecutionPolicy>{__value}, __is_vector,
__is_parallel);
oneapi::dpl::__internal::__op_uninitialized_fill<_Tp, _DecayedExecutionPolicy>{__value});
}
}

Expand Down Expand Up @@ -224,25 +223,29 @@ destroy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __
typedef typename ::std::iterator_traits<_ForwardIterator>::value_type _ValueType;
typedef typename ::std::iterator_traits<_ForwardIterator>::reference _ReferenceType;

constexpr auto __is_parallel =
oneapi::dpl::__internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator>();

if constexpr (!::std::is_trivially_destructible_v<_ValueType>)
{
using _is_vector_type =
#if (_PSTL_ICPX_OMP_SIMD_DESTROY_WINDOWS_BROKEN || _ONEDPL_ICPX_OMP_SIMD_DESTROY_WINDOWS_BROKEN)
::std::conditional_t<
oneapi::dpl::__internal::__is_host_execution_policy<::std::decay_t<_ExecutionPolicy>>::value,
::std::false_type,
decltype(oneapi::dpl::__internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator>())>;
#else
decltype(oneapi::dpl::__internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator>());
if constexpr (oneapi::dpl::__internal::__is_host_execution_policy<::std::decay_t<_ExecutionPolicy>>::value)
{
constexpr auto __is_parallel =
oneapi::dpl::__internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator>();

constexpr auto __is_vector = ::std::false_type{};

// TODO required to rewrite oneapi::dpl::__internal::__pattern_walk1 call by using tag
oneapi::dpl::__internal::__pattern_walk1(
::std::forward<_ExecutionPolicy>(__exec), __first, __last,
[](_ReferenceType __val) { __val.~_ValueType(); }, __is_vector, __is_parallel);
}
else
#endif // _PSTL_ICPX_OMP_SIMD_DESTROY_WINDOWS_BROKEN || _ONEDPL_ICPX_OMP_SIMD_DESTROY_WINDOWS_BROKEN
constexpr _is_vector_type __is_vector;
{
constexpr auto __dispatch_tag = oneapi::dpl::__internal::__select_backend<_ExecutionPolicy, _ForwardIterator>();

oneapi::dpl::__internal::__pattern_walk1(
::std::forward<_ExecutionPolicy>(__exec), __first, __last,
[](_ReferenceType __val) { __val.~_ValueType(); }, __is_vector, __is_parallel);
oneapi::dpl::__internal::__pattern_walk1(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
__last, [](_ReferenceType __val) { __val.~_ValueType(); });
}
}
}

Expand Down Expand Up @@ -289,15 +292,11 @@ uninitialized_default_construct(_ExecutionPolicy&& __exec, _ForwardIterator __fi

if constexpr (!::std::is_trivial_v<_ValueType>)
{
constexpr auto __is_parallel =
oneapi::dpl::__internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator>();
constexpr auto __is_vector =
oneapi::dpl::__internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator>();
constexpr auto __dispatch_tag = oneapi::dpl::__internal::__select_backend<_ExecutionPolicy, _ForwardIterator>();

oneapi::dpl::__internal::__pattern_walk1(
::std::forward<_ExecutionPolicy>(__exec), __first, __last,
oneapi::dpl::__internal::__op_uninitialized_default_construct<_DecayedExecutionPolicy>{}, __is_vector,
__is_parallel);
__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
oneapi::dpl::__internal::__op_uninitialized_default_construct<_DecayedExecutionPolicy>{});
}
}

Expand Down Expand Up @@ -335,25 +334,23 @@ uninitialized_value_construct(_ExecutionPolicy&& __exec, _ForwardIterator __firs
typedef typename ::std::iterator_traits<_ForwardIterator>::value_type _ValueType;
typedef ::std::decay_t<_ExecutionPolicy> _DecayedExecutionPolicy;

constexpr auto __is_parallel =
oneapi::dpl::__internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator>();

if constexpr (::std::is_trivial_v<_ValueType>)
{
constexpr auto __is_parallel =
oneapi::dpl::__internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator>();

oneapi::dpl::__internal::__pattern_walk_brick(
::std::forward<_ExecutionPolicy>(__exec), __first, __last,
oneapi::dpl::__internal::__brick_fill<_ValueType, _DecayedExecutionPolicy>{_ValueType()},
__is_parallel);
}
else
{
constexpr auto __is_vector =
oneapi::dpl::__internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator>();
constexpr auto __dispatch_tag = oneapi::dpl::__internal::__select_backend<_ExecutionPolicy, _ForwardIterator>();

oneapi::dpl::__internal::__pattern_walk1(
::std::forward<_ExecutionPolicy>(__exec), __first, __last,
oneapi::dpl::__internal::__op_uninitialized_value_construct<_DecayedExecutionPolicy>{}, __is_vector,
__is_parallel);
__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
oneapi::dpl::__internal::__op_uninitialized_value_construct<_DecayedExecutionPolicy>{});
}
}

Expand Down
29 changes: 19 additions & 10 deletions include/oneapi/dpl/pstl/hetero/algorithm_impl_hetero.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ oneapi::dpl::__internal::__enable_if_hetero_execution_policy<_ExecutionPolicy, _
__pattern_walk1_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n, _Function __f,
/*vector=*/::std::true_type, /*parallel=*/::std::true_type)
{
__pattern_walk1(::std::forward<_ExecutionPolicy>(__exec), __first, __first + __n, __f,
/*vector=*/::std::true_type(), /*parallel=*/::std::true_type());
constexpr auto __dispatch_tag = oneapi::dpl::__internal::__select_backend<_ExecutionPolicy, _ForwardIterator>();

__pattern_walk1(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __first + __n, __f);
return __first + __n;
}

Expand Down Expand Up @@ -201,10 +202,12 @@ __pattern_walk_brick(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Forwa
if (__last - __first <= 0)
return;

constexpr auto __dispatch_tag = oneapi::dpl::__internal::__select_backend<_ExecutionPolicy, _ForwardIterator>();

__pattern_walk1(
__dispatch_tag,
__par_backend_hetero::make_wrapped_policy<__walk_brick_wrapper>(::std::forward<_ExecutionPolicy>(__exec)),
__first, __last, __f,
/*vector=*/::std::true_type{}, /*parallel=*/::std::true_type{});
__first, __last, __f);
}

template <typename _Name>
Expand All @@ -217,10 +220,12 @@ oneapi::dpl::__internal::__enable_if_hetero_execution_policy<_ExecutionPolicy, _
__pattern_walk_brick_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n, _Function __f,
/*parallel=*/::std::true_type)
{
constexpr auto __dispatch_tag = oneapi::dpl::__internal::__select_backend<_ExecutionPolicy, _ForwardIterator>();

__pattern_walk1(
__dispatch_tag,
__par_backend_hetero::make_wrapped_policy<__walk_brick_n_wrapper>(::std::forward<_ExecutionPolicy>(__exec)),
__first, __first + __n, __f,
/*vector=*/::std::true_type{}, /*parallel=*/::std::true_type{});
__first, __first + __n, __f);
return __first + __n;
}

Expand Down Expand Up @@ -332,10 +337,12 @@ oneapi::dpl::__internal::__enable_if_hetero_execution_policy<_ExecutionPolicy, _
__pattern_fill(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _T& __value,
/*vector=*/::std::true_type, /*parallel=*/::std::true_type)
{
__pattern_walk1(::std::forward<_ExecutionPolicy>(__exec),
constexpr auto __dispatch_tag = oneapi::dpl::__internal::__select_backend<_ExecutionPolicy, _ForwardIterator>();

__pattern_walk1(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
__par_backend_hetero::make_iter_mode<__par_backend_hetero::access_mode::write>(__first),
__par_backend_hetero::make_iter_mode<__par_backend_hetero::access_mode::write>(__last),
fill_functor<_T>{__value}, ::std::true_type{}, ::std::true_type{});
fill_functor<_T>{__value});
return __last;
}

Expand All @@ -361,10 +368,12 @@ oneapi::dpl::__internal::__enable_if_hetero_execution_policy<_ExecutionPolicy, _
__pattern_generate(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Generator __g,
/*vector=*/::std::true_type, /*parallel=*/::std::true_type)
{
__pattern_walk1(::std::forward<_ExecutionPolicy>(__exec),
constexpr auto __dispatch_tag = oneapi::dpl::__internal::__select_backend<_ExecutionPolicy, _ForwardIterator>();

__pattern_walk1(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
__par_backend_hetero::make_iter_mode<__par_backend_hetero::access_mode::write>(__first),
__par_backend_hetero::make_iter_mode<__par_backend_hetero::access_mode::write>(__last),
generate_functor<_Generator>{__g}, ::std::true_type{}, ::std::true_type{});
generate_functor<_Generator>{__g});
return __last;
}

Expand Down

0 comments on commit 2cf29f9

Please sign in to comment.