Skip to content

Commit

Permalink
Merge branch 'main' into dev/skopienko/tag_dispatching
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyKopienko committed Nov 16, 2023
2 parents efafbb2 + 53a4a2c commit 19a0f87
Show file tree
Hide file tree
Showing 170 changed files with 15,780 additions and 108 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ env:
TEST_TIMEOUT: 360
MACOS_ONEAPI_DOWNLOAD_LINK: https://registrationcenter-download.intel.com/akdlm/irc_nas/18358/m_cpp-compiler-classic_p_2022.0.0.62_offline.dmg

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
clang-format:
if: github.event_name == 'pull_request'
Expand Down
4 changes: 4 additions & 0 deletions documentation/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ New in This Release
``libstdc++`` version 8 or ``libc++``, ``oneapi::dpl::execution::par_unseq`` offloads
standard parallel algorithms to the SYCL device similarly to ``std::execution::par_unseq``
in accordance with the ``-fsycl-pstl-offload`` option value.
- When using the dpl modulefile to initialize the user's environment and compiling with ``-fsycl-pstl-offload``
option of Intel® oneAPI DPC++/C++ compiler, a linking issue or program crash may be encountered due to the directory
containing libpstloffload.so not being included in the search path. Use the env/vars.sh to configure the working
environment to avoid the issue.
- Compilation issues may be encountered when passing zip iterators to ``exclusive_scan_by_segment`` on Windows.
- Incorrect results may be produced by ``set_intersection`` with a DPC++ execution policy,
where elements are copied from the second input range rather than the first input range.
Expand Down
18 changes: 18 additions & 0 deletions include/oneapi/dpl/pstl/algorithm_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,24 @@ __pattern_walk3(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1, _Ran
_RandomAccessIterator2 __first2, _RandomAccessIterator3 __first3, _Function __f, _IsVector __is_vector,
/*parallel=*/::std::true_type);

//------------------------------------------------------------------------
// transform_if
//------------------------------------------------------------------------

template <typename _ExecutionPolicy, typename _ForwardIterator1, typename _ForwardIterator2, typename _Function,
class _IsVector, class _IsParallel>
oneapi::dpl::__internal::__enable_if_host_execution_policy<_ExecutionPolicy, _ForwardIterator2>
__pattern_walk2_transform_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _Function __func, _IsVector __is_vector,
_IsParallel __is_parallel) noexcept;

template <typename _ExecutionPolicy, typename _ForwardIterator1, typename _ForwardIterator2, typename _ForwardIterator3,
typename _Function, class _IsVector, class _IsParallel>
oneapi::dpl::__internal::__enable_if_host_execution_policy<_ExecutionPolicy, _ForwardIterator3>
__pattern_walk3_transform_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator3 __first3, _Function __func,
_IsVector __is_vector, _IsParallel __is_parallel) noexcept;

//------------------------------------------------------------------------
// equal
//------------------------------------------------------------------------
Expand Down
26 changes: 26 additions & 0 deletions include/oneapi/dpl/pstl/algorithm_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,32 @@ __pattern_walk3(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardI
});
}

//------------------------------------------------------------------------
// transform_if
//------------------------------------------------------------------------

template <typename _ExecutionPolicy, typename _ForwardIterator1, typename _ForwardIterator2, typename _Function,
class _IsVector, class _IsParallel>
oneapi::dpl::__internal::__enable_if_host_execution_policy<_ExecutionPolicy, _ForwardIterator2>
__pattern_walk2_transform_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _Function __func, _IsVector __is_vector,
_IsParallel __is_parallel) noexcept
{
return __pattern_walk2(::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __func, __is_vector,
__is_parallel);
}

template <typename _ExecutionPolicy, typename _ForwardIterator1, typename _ForwardIterator2, typename _ForwardIterator3,
typename _Function, class _IsVector, class _IsParallel>
oneapi::dpl::__internal::__enable_if_host_execution_policy<_ExecutionPolicy, _ForwardIterator3>
__pattern_walk3_transform_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator3 __first3, _Function __func,
_IsVector __is_vector, _IsParallel __is_parallel) noexcept
{
return __pattern_walk3(::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __first3, __func,
__is_vector, __is_parallel);
}

//------------------------------------------------------------------------
// equal
//------------------------------------------------------------------------
Expand Down
14 changes: 14 additions & 0 deletions include/oneapi/dpl/pstl/glue_algorithm_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ oneapi::dpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Forward
transform(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
_UnaryOperation __op);

// [alg.transform_if]

template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _UnaryOperation,
class _UnaryPredicate>
oneapi::dpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
transform_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
_UnaryOperation __op, _UnaryPredicate __pred);

template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator3,
class _BinaryOperation, class _BinaryPredicate>
oneapi::dpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator3>
transform_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator3 __result, _BinaryOperation __op, _BinaryPredicate __pred);

// [alg.replace]

template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate, class _Tp>
Expand Down
35 changes: 35 additions & 0 deletions include/oneapi/dpl/pstl/glue_algorithm_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ swap_ranges(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardItera
}

// [alg.transform]

template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _UnaryOperation>
oneapi::dpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
transform(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
Expand Down Expand Up @@ -356,6 +357,40 @@ transform(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterato
__exec.__allow_parallel());
}

// [alg.transform_if]

template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _UnaryOperation,
class _UnaryPredicate>
oneapi::dpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
transform_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
_UnaryOperation __op, _UnaryPredicate __pred)
{
return oneapi::dpl::__internal::__pattern_walk2_transform_if(
::std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
oneapi::dpl::__internal::__transform_if_unary_functor<_UnaryOperation, _UnaryPredicate>(::std::move(__op),
::std::move(__pred)),
oneapi::dpl::__internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator1, _ForwardIterator2>(
__exec),
oneapi::dpl::__internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator1, _ForwardIterator2>(
__exec));
}

template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator3,
class _BinaryOperation, class _BinaryPredicate>
oneapi::dpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator3>
transform_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator3 __result, _BinaryOperation __op, _BinaryPredicate __pred)
{
return oneapi::dpl::__internal::__pattern_walk3_transform_if(
::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __result,
oneapi::dpl::__internal::__transform_if_binary_functor<_BinaryOperation, _BinaryPredicate>(::std::move(__op),
::std::move(__pred)),
oneapi::dpl::__internal::__is_vectorization_preferred<_ExecutionPolicy, _ForwardIterator1, _ForwardIterator2,
_ForwardIterator3>(__exec),
oneapi::dpl::__internal::__is_parallelization_preferred<_ExecutionPolicy, _ForwardIterator1, _ForwardIterator2,
_ForwardIterator3>(__exec));
}

// [alg.replace]

template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate, class _Tp>
Expand Down
63 changes: 56 additions & 7 deletions include/oneapi/dpl/pstl/hetero/algorithm_impl_hetero.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ __pattern_swap(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIt
// walk3
//------------------------------------------------------------------------

template <typename _ExecutionPolicy, typename _ForwardIterator1, typename _ForwardIterator2, typename _ForwardIterator3,
template <__par_backend_hetero::access_mode __acc_mode1 = __par_backend_hetero::access_mode::read,
__par_backend_hetero::access_mode __acc_mode2 = __par_backend_hetero::access_mode::read,
__par_backend_hetero::access_mode __acc_mode3 = __par_backend_hetero::access_mode::write,
typename _ExecutionPolicy, typename _ForwardIterator1, typename _ForwardIterator2, typename _ForwardIterator3,
typename _Function>
oneapi::dpl::__internal::__enable_if_hetero_execution_policy<_ExecutionPolicy, _ForwardIterator3>
__pattern_walk3(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
Expand All @@ -166,14 +169,11 @@ __pattern_walk3(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardI
if (__n <= 0)
return __first3;

auto __keep1 =
oneapi::dpl::__ranges::__get_sycl_range<__par_backend_hetero::access_mode::read, _ForwardIterator1>();
auto __keep1 = oneapi::dpl::__ranges::__get_sycl_range<__acc_mode1, _ForwardIterator1>();
auto __buf1 = __keep1(__first1, __last1);
auto __keep2 =
oneapi::dpl::__ranges::__get_sycl_range<__par_backend_hetero::access_mode::read, _ForwardIterator2>();
auto __keep2 = oneapi::dpl::__ranges::__get_sycl_range<__acc_mode2, _ForwardIterator2>();
auto __buf2 = __keep2(__first2, __first2 + __n);
auto __keep3 =
oneapi::dpl::__ranges::__get_sycl_range<__par_backend_hetero::access_mode::write, _ForwardIterator3>();
auto __keep3 = oneapi::dpl::__ranges::__get_sycl_range<__acc_mode3, _ForwardIterator3>();
auto __buf3 = __keep3(__first3, __first3 + __n);

oneapi::dpl::__par_backend_hetero::__parallel_for(::std::forward<_ExecutionPolicy>(__exec),
Expand Down Expand Up @@ -262,6 +262,55 @@ __pattern_walk2_brick_n(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _
/*vector=*/::std::true_type{}, /*parallel*/ ::std::true_type{});
}

//------------------------------------------------------------------------
// transform_if
//------------------------------------------------------------------------

template <typename _Name>
struct __walk2_transform_if_wrapper
{
};

template <typename _ExecutionPolicy, typename _ForwardIterator1, typename _ForwardIterator2, typename _Function>
oneapi::dpl::__internal::__enable_if_hetero_execution_policy<_ExecutionPolicy, _ForwardIterator2>
__pattern_walk2_transform_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _Function __func,
/*vector=*/::std::true_type,
/*parallel=*/::std::true_type)
{
// Require `read_write` access mode for output sequence to force a copy in for host iterators to capture incoming
// values of the output sequence for elements where the predicate is false.
return __pattern_walk2</*_IsSync=*/::std::true_type, __par_backend_hetero::access_mode::read,
__par_backend_hetero::access_mode::read_write>(
__par_backend_hetero::make_wrapped_policy<__walk2_transform_if_wrapper>(
::std::forward<_ExecutionPolicy>(__exec)),
__first1, __last1, __first2, __func,
/*vector=*/::std::true_type{}, /*parallel*/ ::std::true_type{});
}

template <typename _Name>
struct __walk3_transform_if_wrapper
{
};

template <typename _ExecutionPolicy, typename _ForwardIterator1, typename _ForwardIterator2, typename _ForwardIterator3,
typename _Function>
oneapi::dpl::__internal::__enable_if_hetero_execution_policy<_ExecutionPolicy, _ForwardIterator3>
__pattern_walk3_transform_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator3 __first3, _Function __func,
/*vector=*/::std::true_type,
/*parallel=*/::std::true_type)
{
// Require `read_write` access mode for output sequence to force a copy in for host iterators to capture incoming
// values of the output sequence for elements where the predicate is false.
return __pattern_walk3<__par_backend_hetero::access_mode::read, __par_backend_hetero::access_mode::read,
__par_backend_hetero::access_mode::read_write>(
__par_backend_hetero::make_wrapped_policy<__walk3_transform_if_wrapper>(
::std::forward<_ExecutionPolicy>(__exec)),
__first1, __last1, __first2, __first3, __func,
/*vector=*/::std::true_type{}, /*parallel*/ ::std::true_type{});
}

//------------------------------------------------------------------------
// fill
//------------------------------------------------------------------------
Expand Down
42 changes: 42 additions & 0 deletions include/oneapi/dpl/pstl/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,48 @@ class __transform_functor
}
};

template <typename _UnaryOper, typename _UnaryPred>
class __transform_if_unary_functor
{
mutable _UnaryOper _M_oper;
mutable _UnaryPred _M_pred;

public:
explicit __transform_if_unary_functor(_UnaryOper&& __op, _UnaryPred&& __pred)
: _M_oper(::std::forward<_UnaryOper>(__op)), _M_pred(::std::forward<_UnaryPred>(__pred))
{
}

template <typename _Input1Type, typename _OutputType>
void
operator()(const _Input1Type& x, _OutputType& y) const
{
if (_M_pred(x))
y = _M_oper(x);
}
};

template <typename _BinaryOper, typename _BinaryPred>
class __transform_if_binary_functor
{
mutable _BinaryOper _M_oper;
mutable _BinaryPred _M_pred;

public:
explicit __transform_if_binary_functor(_BinaryOper&& __op, _BinaryPred&& __pred)
: _M_oper(::std::forward<_BinaryOper>(__op)), _M_pred(::std::forward<_BinaryPred>(__pred))
{
}

template <typename _Input1Type, typename _Input2Type, typename _OutputType>
void
operator()(const _Input1Type& x, const _Input2Type& y, _OutputType& z) const
{
if (_M_pred(x, y))
z = _M_oper(x, y);
}
};

template <typename _Tp, typename _Pred>
class __replace_functor
{
Expand Down
16 changes: 16 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@
set (ranlux_24_48_test.pass_timeout_debug "900") # 15min
set (ranlux_24_48_test.pass_timeout_release "720") # 12min

# If TBB headers are available, libstdc++ enables TBB backend; some TBB symbols become undefined unless it is linked.
# The undefined symbol error arises only with GCC compiler.
# There is no known way to limit the workaround to libstdc++ only.
if (CMAKE_CXX_COMPILER_ID STREQUAL GNU AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11)
if (ONEDPL_BACKEND MATCHES "^(serial|omp|dpcpp_only)$")
find_package(TBB 2021 QUIET COMPONENTS tbb OPTIONAL_COMPONENTS tbbmalloc)
if (TBB_FOUND)
message(STATUS "Tests are linked against TBB to avoid undefined symbol errors due to TBB usage in libstdc++")
set(_gcc_link_tbb TRUE)
endif()
endif()
endif()

# disable fast math for ALL TESTS
# icpx and dpcpp accept -fno-fast-math, but icx-cl and dpcpp-cl only accept /clang:-fno-fast-math
foreach(_fno_fast_math_flag -fno-fast-math /clang:-fno-fast-math)
Expand Down Expand Up @@ -91,6 +104,9 @@ macro(onedpl_add_test test_source_file switch_off_checked_iterators)

target_include_directories(${_test_name} PRIVATE "${CMAKE_CURRENT_LIST_DIR}")
target_link_libraries(${_test_name} PRIVATE oneDPL)
if (_gcc_link_tbb)
target_link_libraries(${_test_name} PRIVATE TBB::tbb)
endif()
set_target_properties(${_test_name} PROPERTIES CXX_EXTENSIONS NO)

add_test(NAME ${_test_name} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${_test_name})
Expand Down
Loading

0 comments on commit 19a0f87

Please sign in to comment.