@@ -38,11 +38,12 @@ _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_transform(
38
38
if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
39
39
__has_random_access_iterator_category_or_concept<_ForwardIterator>::value &&
40
40
__has_random_access_iterator_category_or_concept<_ForwardOutIterator>::value &&
41
- __libcpp_is_contiguous_iterator<_ForwardIterator>::value) {
42
- // While the CPU backend captures by reference, [&], that is not valid when
43
- // offloading to the GPU. Therefore we must capture by value, [=].
44
- return std::__par_backend::__parallel_for_simd_2 (__first, __last - __first, __result, __op );
41
+ __libcpp_is_contiguous_iterator<_ForwardIterator>::value &&
42
+ __libcpp_is_contiguous_iterator<_ForwardOutIterator>::value) {
43
+ std::__par_backend::__parallel_for_simd_2 (__first, __last - __first, __result, __op);
44
+ return __result + ( __last - __first);
45
45
}
46
+ // If it is not safe to offload to the GPU, we rely on the CPU backend.
46
47
return std::__pstl_transform<_ExecutionPolicy>(__cpu_backend_tag{}, __first, __last, __result, __op);
47
48
}
48
49
@@ -66,10 +67,10 @@ _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_transform(
66
67
__libcpp_is_contiguous_iterator<_ForwardIterator1>::value &&
67
68
__libcpp_is_contiguous_iterator<_ForwardIterator2>::value &&
68
69
__libcpp_is_contiguous_iterator<_ForwardOutIterator>::value) {
69
- // While the CPU backend captures by reference, [&], that is not valid when
70
- // offloading to the GPU. Therefore we must capture by value, [=].
71
- return std::__par_backend::__parallel_for_simd_3 (__first1, __last1 - __first1, __first2, __result, __op);
70
+ std::__par_backend::__parallel_for_simd_3 (__first1, __last1 - __first1, __first2, __result, __op);
71
+ return __result + (__last1 - __first1);
72
72
}
73
+ // If it is not safe to offload to the GPU, we rely on the CPU backend.
73
74
return std::__pstl_transform<_ExecutionPolicy>(__cpu_backend_tag{}, __first1, __last1, __first2, __result, __op);
74
75
}
75
76
0 commit comments