Skip to content

Commit

Permalink
Avid temporary __future instances, directly created on stack
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Kopienko <sergey.kopienko@intel.com>
  • Loading branch information
SergeyKopienko committed Sep 16, 2024
1 parent ccadcd3 commit 4f889d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
28 changes: 13 additions & 15 deletions include/oneapi/dpl/internal/async_impl/async_impl_hetero.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ __pattern_walk2_async(__hetero_tag<_BackendTag>, _ExecutionPolicy&& __exec, _For
auto __keep2 = oneapi::dpl::__ranges::__get_sycl_range<__acc_mode2, _ForwardIterator2>();
auto __buf2 = __keep2(__first2, __first2 + __n);

auto __future = oneapi::dpl::__par_backend_hetero::__parallel_for(
_BackendTag{}, ::std::forward<_ExecutionPolicy>(__exec),
unseq_backend::walk_n<_ExecutionPolicy, _Function>{__f}, __n, __buf1.all_view(), __buf2.all_view());

return __future.__make_future(__first2 + __n);
return oneapi::dpl::__par_backend_hetero::__parallel_for(_BackendTag{}, ::std::forward<_ExecutionPolicy>(__exec),
unseq_backend::walk_n<_ExecutionPolicy, _Function>{__f},
__n, __buf1.all_view(), __buf2.all_view())
.__make_future(__first2 + __n);
}

template <typename _BackendTag, typename _ExecutionPolicy, typename _ForwardIterator1, typename _ForwardIterator2,
Expand All @@ -91,12 +90,11 @@ __pattern_walk3_async(__hetero_tag<_BackendTag>, _ExecutionPolicy&& __exec, _For
oneapi::dpl::__ranges::__get_sycl_range<__par_backend_hetero::access_mode::write, _ForwardIterator3>();
auto __buf3 = __keep3(__first3, __first3 + __n);

auto __future =
oneapi::dpl::__par_backend_hetero::__parallel_for(_BackendTag{}, ::std::forward<_ExecutionPolicy>(__exec),
unseq_backend::walk_n<_ExecutionPolicy, _Function>{__f}, __n,
__buf1.all_view(), __buf2.all_view(), __buf3.all_view());

return __future.__make_future(__first3 + __n);
return oneapi::dpl::__par_backend_hetero::__parallel_for(_BackendTag{}, ::std::forward<_ExecutionPolicy>(__exec),
unseq_backend::walk_n<_ExecutionPolicy, _Function>{__f},
__n, __buf1.all_view(), __buf2.all_view(),
__buf3.all_view())
.__make_future(__first3 + __n);
}

template <typename _BackendTag, typename _ExecutionPolicy, typename _ForwardIterator1, typename _ForwardIterator2,
Expand Down Expand Up @@ -201,10 +199,10 @@ __pattern_transform_scan_base_async(__hetero_tag<_BackendTag>, _ExecutionPolicy&
auto __keep2 = oneapi::dpl::__ranges::__get_sycl_range<__par_backend_hetero::access_mode::write, _Iterator2>();
auto __buf2 = __keep2(__result, __result + __n);

auto __res = oneapi::dpl::__par_backend_hetero::__parallel_transform_scan(
_BackendTag{}, ::std::forward<_ExecutionPolicy>(__exec), __buf1.all_view(), __buf2.all_view(), __n, __unary_op,
__init, __binary_op, _Inclusive{});
return __res.__make_future(__result + __n);
return oneapi::dpl::__par_backend_hetero::__parallel_transform_scan(
_BackendTag{}, ::std::forward<_ExecutionPolicy>(__exec), __buf1.all_view(), __buf2.all_view(), __n,
__unary_op, __init, __binary_op, _Inclusive{})
.__make_future(__result + __n);
}

template <typename _BackendTag, typename _ExecutionPolicy, typename _Iterator1, typename _Iterator2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,12 @@ class __future : private std::tuple<_Args...>
}
};

template <typename _TData>
inline __make_future(sycl::event&& __event, _TData&& __data)
{
return __future<sycl::event, _TData>(std::move(__event), std::forward<_TData>(__data));
}

// Invoke a callable and pass a compile-time integer based on a provided run-time integer.
// The compile-time integer that will be provided to the callable is defined as the smallest
// value in the integer_sequence not less than the run-time integer. For example:
Expand Down

0 comments on commit 4f889d4

Please sign in to comment.