Skip to content

Commit 67ecdee

Browse files
committed
Fixed almost all test cases that failed during ninja check-cxx
1 parent 065f52d commit 67ecdee

File tree

11 files changed

+292
-187
lines changed

11 files changed

+292
-187
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,14 @@ set(files
8686
__algorithm/pstl_backends/cpu_backends/transform.h
8787
__algorithm/pstl_backends/cpu_backends/transform_reduce.h
8888
__algorithm/pstl_backends/gpu_backend.h
89+
__algorithm/pstl_backends/gpu_backends/any_of.h
8990
__algorithm/pstl_backends/gpu_backends/backend.h
9091
__algorithm/pstl_backends/gpu_backends/fill.h
92+
__algorithm/pstl_backends/gpu_backends/find_if.h
9193
__algorithm/pstl_backends/gpu_backends/for_each.h
94+
__algorithm/pstl_backends/gpu_backends/merge.h
9295
__algorithm/pstl_backends/gpu_backends/omp_offload.h
96+
__algorithm/pstl_backends/gpu_backends/stable_sort.h
9397
__algorithm/pstl_backends/gpu_backends/transform.h
9498
__algorithm/pstl_backends/gpu_backends/transform_reduce.h
9599
__algorithm/pstl_copy.h

libcxx/include/__algorithm/pstl_backends/gpu_backend.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
#include <__algorithm/pstl_backends/gpu_backends/backend.h>
1515

1616
#if defined(_LIBCPP_PSTL_GPU_OFFLOAD)
17+
# include <__algorithm/pstl_backends/gpu_backends/any_of.h>
1718
# include <__algorithm/pstl_backends/gpu_backends/fill.h>
19+
# include <__algorithm/pstl_backends/gpu_backends/find_if.h>
1820
# include <__algorithm/pstl_backends/gpu_backends/for_each.h>
21+
# include <__algorithm/pstl_backends/gpu_backends/merge.h>
22+
# include <__algorithm/pstl_backends/gpu_backends/stable_sort.h>
1923
# include <__algorithm/pstl_backends/gpu_backends/transform.h>
2024
# include <__algorithm/pstl_backends/gpu_backends/transform_reduce.h>
2125
#endif
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___ALGORITHM_PSTL_BACKENDS_GPU_BACKEND_ANY_OF_H
10+
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_GPU_BACKEND_ANY_OF_H
11+
12+
#include <__algorithm/any_of.h>
13+
#include <__algorithm/find_if.h>
14+
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
15+
#include <__algorithm/pstl_backends/gpu_backends/backend.h>
16+
#include <__atomic/atomic.h>
17+
#include <__atomic/memory_order.h>
18+
#include <__config>
19+
#include <__functional/operations.h>
20+
#include <__iterator/concepts.h>
21+
#include <__type_traits/is_execution_policy.h>
22+
#include <__utility/pair.h>
23+
#include <__utility/terminate_on_exception.h>
24+
#include <cstdint>
25+
26+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
27+
28+
_LIBCPP_BEGIN_NAMESPACE_STD
29+
30+
template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
31+
_LIBCPP_HIDE_FROM_ABI bool
32+
__pstl_any_of(__gpu_backend_tag, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
33+
// TODO: Implement GPU backend
34+
return std::__pstl_any_of<_ExecutionPolicy>(__cpu_backend_tag{}, __first, __last, __pred);
35+
}
36+
37+
_LIBCPP_END_NAMESPACE_STD
38+
39+
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
40+
41+
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_GPU_BACKEND_ANY_OF_H

libcxx/include/__algorithm/pstl_backends/gpu_backends/fill.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <__algorithm/pstl_backends/gpu_backends/backend.h>
1515
#include <__config>
1616
#include <__iterator/concepts.h>
17+
#include <__iterator/iterator_traits.h>
1718
#include <__type_traits/is_execution_policy.h>
1819
#include <__utility/terminate_on_exception.h>
1920
#include <stdio.h>
@@ -33,23 +34,12 @@ __pstl_fill(__gpu_backend_tag, _ForwardIterator __first, _ForwardIterator __last
3334
// parallel unsequenced, as it is the only execution policy prohibiting throwing
3435
// exceptions and allowing SIMD instructions
3536
if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
36-
__has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
37+
__has_random_access_iterator_category_or_concept<_ForwardIterator>::value &&
38+
__libcpp_is_contiguous_iterator<_ForwardIterator>::value) {
3739
std::__par_backend::__parallel_for_simd_val_1(__first, __last - __first, __value);
3840
}
39-
// Else if the excution policy is parallel, we execute for_each on the CPU instead
40-
else if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
41-
__has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
42-
std::__terminate_on_exception([&] {
43-
__par_backend::__parallel_for(
44-
__first, __last, [&__value](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
45-
std::__pstl_fill<__remove_parallel_policy_t<_ExecutionPolicy>>(
46-
__cpu_backend_tag{}, __brick_first, __brick_last, __value);
47-
});
48-
});
49-
// Else we execute for_each in serial
50-
} else {
51-
std::fill(__first, __last, __value);
52-
}
41+
// Otherwise, we execute for_each on the CPU instead
42+
return std::__pstl_fill<_ExecutionPolicy>(__cpu_backend_tag{}, __first, __last, __value);
5343
}
5444

5545
_LIBCPP_END_NAMESPACE_STD
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___ALGORITHM_PSTL_BACKENDS_GPU_BACKENDS_FIND_IF_H
10+
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_GPU_BACKENDS_FIND_IF_H
11+
12+
#include <__algorithm/find_if.h>
13+
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
14+
#include <__algorithm/pstl_backends/gpu_backends/backend.h>
15+
#include <__atomic/atomic.h>
16+
#include <__config>
17+
#include <__functional/operations.h>
18+
#include <__iterator/concepts.h>
19+
#include <__iterator/iterator_traits.h>
20+
#include <__type_traits/is_execution_policy.h>
21+
#include <__utility/pair.h>
22+
#include <__utility/terminate_on_exception.h>
23+
#include <cstddef>
24+
25+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26+
# pragma GCC system_header
27+
#endif
28+
29+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
30+
31+
_LIBCPP_BEGIN_NAMESPACE_STD
32+
33+
template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
34+
_LIBCPP_HIDE_FROM_ABI _ForwardIterator
35+
__pstl_find_if(__gpu_backend_tag, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
36+
// TODO: Implement the GPU backend
37+
return std::__pstl_find_if<_ExecutionPolicy>(__cpu_backend_tag{}, __first, __last, __pred);
38+
}
39+
40+
_LIBCPP_END_NAMESPACE_STD
41+
42+
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
43+
44+
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_GPU_BACKENDS_FIND_IF_H

libcxx/include/__algorithm/pstl_backends/gpu_backends/for_each.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,12 @@ __pstl_for_each(__gpu_backend_tag, _ForwardIterator __first, _ForwardIterator __
3333
// parallel unsequenced, as it is the only execution policy prohibiting throwing
3434
// exceptions and allowing SIMD instructions
3535
if constexpr (__is_unsequenced_execution_policy_v<_ExecutionPolicy> &&
36-
__has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
36+
__has_random_access_iterator_category_or_concept<_ForwardIterator>::value &&
37+
__libcpp_is_contiguous_iterator<_ForwardIterator>::value) {
3738
std::__par_backend::__parallel_for_simd_1(__first, __last - __first, __func);
3839
}
3940
// Else if the excution policy is parallel, we execute for_each on the CPU instead
40-
else if constexpr (__is_parallel_execution_policy_v<_ExecutionPolicy> &&
41-
__has_random_access_iterator_category_or_concept<_ForwardIterator>::value) {
42-
std::__terminate_on_exception([&] {
43-
std::__par_backend::__parallel_for(
44-
__first, __last, [__func](_ForwardIterator __brick_first, _ForwardIterator __brick_last) {
45-
std::__pstl_for_each<__remove_parallel_policy_t<_ExecutionPolicy>>(
46-
__cpu_backend_tag{}, __brick_first, __brick_last, __func);
47-
});
48-
});
49-
// Else we execute for_each in serial
50-
} else {
51-
std::for_each(__first, __last, __func);
52-
}
41+
return std::__pstl_for_each<_ExecutionPolicy>(__cpu_backend_tag{}, __first, __last, __func);
5342
}
5443

5544
_LIBCPP_END_NAMESPACE_STD
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___ALGORITHM_PSTL_BACKENDS_GPU_BACKENDS_MERGE_H
10+
#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_GPU_BACKENDS_MERGE_H
11+
12+
#include <__algorithm/merge.h>
13+
#include <__algorithm/pstl_backends/cpu_backends/backend.h>
14+
#include <__algorithm/pstl_backends/gpu_backends/backend.h>
15+
#include <__config>
16+
#include <__iterator/concepts.h>
17+
#include <__type_traits/is_execution_policy.h>
18+
#include <__utility/move.h>
19+
#include <__utility/terminate_on_exception.h>
20+
21+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22+
# pragma GCC system_header
23+
#endif
24+
25+
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
26+
27+
_LIBCPP_BEGIN_NAMESPACE_STD
28+
29+
template <class _ExecutionPolicy,
30+
class _ForwardIterator1,
31+
class _ForwardIterator2,
32+
class _ForwardOutIterator,
33+
class _Comp>
34+
_LIBCPP_HIDE_FROM_ABI _ForwardOutIterator __pstl_merge(
35+
__gpu_backend_tag,
36+
_ForwardIterator1 __first1,
37+
_ForwardIterator1 __last1,
38+
_ForwardIterator2 __first2,
39+
_ForwardIterator2 __last2,
40+
_ForwardOutIterator __result,
41+
_Comp __comp) {
42+
// TODO: Implement GPU backend
43+
return std::__pstl_merge<_ExecutionPolicy>(
44+
__cpu_backend_tag{}, __first1, __last1, __first2, __last2, __result, __comp);
45+
}
46+
47+
_LIBCPP_END_NAMESPACE_STD
48+
49+
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
50+
51+
#endif // _LIBCPP___ALGORITHM_PSTL_BACKENDS_GPU_BACKENDS_MERGE_H

0 commit comments

Comments
 (0)