Skip to content

Commit

Permalink
<execution>: parallel scans should avoid passing output values to t…
Browse files Browse the repository at this point in the history
…he binary (reduce) operation (#4701)

Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
Co-authored-by: Casey Carter <cacarter@microsoft.com>
  • Loading branch information
3 people committed Aug 15, 2024
1 parent 7f0f35d commit 041f584
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 88 deletions.
210 changes: 154 additions & 56 deletions stl/inc/execution

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions stl/inc/vector
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ private:
if constexpr (conjunction_v<is_nothrow_constructible<_Ty, _Valty...>,
_Uses_default_construct<_Alloc, _Ty*, _Valty...>>) {
_ASAN_VECTOR_MODIFY(1);
_Construct_in_place(*_Mylast, _STD forward<_Valty>(_Val)...);
_STD _Construct_in_place(*_Mylast, _STD forward<_Valty>(_Val)...);
} else {
_ASAN_VECTOR_EXTEND_GUARD(static_cast<size_type>(_Mylast - _My_data._Myfirst) + 1);
_Alty_traits::construct(_Getal(), _Unfancy(_Mylast), _STD forward<_Valty>(_Val)...);
Expand Down Expand Up @@ -822,27 +822,27 @@ private:
const size_type _Newsize = _Oldsize + 1;
size_type _Newcapacity = _Calculate_growth(_Newsize);

const pointer _Newvec = _Allocate_at_least_helper(_Al, _Newcapacity);
const pointer _Newvec = _STD _Allocate_at_least_helper(_Al, _Newcapacity);
const pointer _Constructed_last = _Newvec + _Whereoff + 1;
pointer _Constructed_first = _Constructed_last;

_TRY_BEGIN
_Alty_traits::construct(_Al, _Unfancy(_Newvec + _Whereoff), _STD forward<_Valty>(_Val)...);
_Alty_traits::construct(_Al, _STD _Unfancy(_Newvec + _Whereoff), _STD forward<_Valty>(_Val)...);
_Constructed_first = _Newvec + _Whereoff;

if (_Whereptr == _Mylast) { // at back, provide strong guarantee
if constexpr (is_nothrow_move_constructible_v<_Ty> || !is_copy_constructible_v<_Ty>) {
_Uninitialized_move(_Myfirst, _Mylast, _Newvec, _Al);
_STD _Uninitialized_move(_Myfirst, _Mylast, _Newvec, _Al);
} else {
_Uninitialized_copy(_Myfirst, _Mylast, _Newvec, _Al);
_STD _Uninitialized_copy(_Myfirst, _Mylast, _Newvec, _Al);
}
} else { // provide basic guarantee
_Uninitialized_move(_Myfirst, _Whereptr, _Newvec, _Al);
_STD _Uninitialized_move(_Myfirst, _Whereptr, _Newvec, _Al);
_Constructed_first = _Newvec;
_Uninitialized_move(_Whereptr, _Mylast, _Newvec + _Whereoff + 1, _Al);
_STD _Uninitialized_move(_Whereptr, _Mylast, _Newvec + _Whereoff + 1, _Al);
}
_CATCH_ALL
_Destroy_range(_Constructed_first, _Constructed_last, _Al);
_STD _Destroy_range(_Constructed_first, _Constructed_last, _Al);
_Al.deallocate(_Newvec, _Newcapacity);
_RERAISE;
_CATCH_END
Expand Down Expand Up @@ -2024,7 +2024,7 @@ private:
_My_data._Orphan_all();

if (_Myfirst) { // destroy and deallocate old array
_Destroy_range(_Myfirst, _Mylast, _Al);
_STD _Destroy_range(_Myfirst, _Mylast, _Al);
_ASAN_VECTOR_REMOVE;
_Al.deallocate(_Myfirst, static_cast<size_type>(_Myend - _Myfirst));
}
Expand Down
6 changes: 3 additions & 3 deletions stl/inc/xmemory
Original file line number Diff line number Diff line change
Expand Up @@ -1905,15 +1905,15 @@ _CONSTEXPR20 _Alloc_ptr_t<_Alloc> _Uninitialized_move(
// move [_First, _Last) to raw _Dest, using _Al
// note: only called internally from elsewhere in the STL
using _Ptrval = typename _Alloc::value_type*;
auto _UFirst = _Get_unwrapped(_First);
const auto _ULast = _Get_unwrapped(_Last);
auto _UFirst = _STD _Get_unwrapped(_First);
const auto _ULast = _STD _Get_unwrapped(_Last);
if constexpr (conjunction_v<bool_constant<_Iter_move_cat<decltype(_UFirst), _Ptrval>::_Bitcopy_constructible>,
_Uses_default_construct<_Alloc, _Ptrval, decltype(_STD move(*_UFirst))>>) {
#if _HAS_CXX20
if (!_STD is_constant_evaluated())
#endif // _HAS_CXX20
{
_Copy_memmove(_UFirst, _ULast, _Unfancy(_Dest));
_STD _Copy_memmove(_UFirst, _ULast, _STD _Unfancy(_Dest));
return _Dest + (_ULast - _UFirst);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,6 @@ struct typesBop {
bopResult operator()(intermediateType&&, intermediateType&&) {
return 0;
}

// *result = binary_op(tmp, move(*result))
bopResult operator()(intermediateType&, outputType&&) {
return 0;
}
};

void test_case_exclusive_scan_init_writes_intermediate_type() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,6 @@ struct typesBop {
bopResult operator()(intermediateType&&, intermediateType&&) {
return 0;
}

// *result = binary_op(tmp, move(*result))
bopResult operator()(intermediateType&, outputType&&) {
return 0;
}
};

void test_case_inclusive_scan_init_writes_intermediate_type() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,6 @@ struct typesBop {
bopResult operator()(intermediateType&&, intermediateType&&) {
return 0;
}

// *result = binary_op(tmp, move(*result))
bopResult operator()(intermediateType&, outputType&&) {
return 0;
}
};

void test_case_transform_exclusive_scan_init_writes_intermediate_type() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,6 @@ struct typesBop {
bopResult operator()(intermediateType&&, intermediateType&&) {
return 0;
}

// *result = binary_op(tmp, move(*result))
bopResult operator()(intermediateType&, outputType&&) {
return 0;
}
};

void test_case_transform_inclusive_scan_init_writes_intermediate_type() {
Expand Down

0 comments on commit 041f584

Please sign in to comment.