1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___PSTL_CPU_ALGOS_CPU_TRAITS_H
10 #define _LIBCPP___PSTL_CPU_ALGOS_CPU_TRAITS_H
14 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
15 # pragma GCC system_header
19 #include <__undef_macros>
21 #if _LIBCPP_STD_VER >= 17
23 _LIBCPP_BEGIN_NAMESPACE_STD
28 // This traits class encapsulates the basis operations for a CPU-based implementation of the PSTL.
29 // All the operations in the PSTL can be implemented from these basis operations, so a pure CPU backend
30 // only needs to customize these traits in order to get an implementation of the whole PSTL.
35 // template <class _RandomAccessIterator, class _Functor>
36 // optional<__empty> __for_each(_RandomAccessIterator __first, _RandomAccessIterator __last, _Functor __func);
37 // - __func must take a subrange of [__first, __last) that should be executed in serial
39 // template <class _Iterator, class _UnaryOp, class _Tp, class _BinaryOp, class _Reduction>
40 // optional<_Tp> __transform_reduce(_Iterator __first, _Iterator __last, _UnaryOp, _Tp __init, _BinaryOp, _Reduction);
42 // template <class _RandomAccessIterator1,
43 // class _RandomAccessIterator2,
44 // class _RandomAccessIterator3,
47 // optional<_RandomAccessIterator3> __merge(_RandomAccessIterator1 __first1,
48 // _RandomAccessIterator1 __last1,
49 // _RandomAccessIterator2 __first2,
50 // _RandomAccessIterator2 __last2,
51 // _RandomAccessIterator3 __outit,
53 // _LeafMerge __leaf_merge);
55 // template <class _RandomAccessIterator, class _Comp, class _LeafSort>
56 // optional<__empty> __stable_sort(_RandomAccessIterator __first,
57 // _RandomAccessIterator __last,
59 // _LeafSort __leaf_sort);
61 // void __cancel_execution();
62 // Cancel the execution of other jobs - they aren't needed anymore. This is not a binding request,
63 // some backends may not actually be able to cancel jobs.
65 // constexpr size_t __lane_size;
66 // Size of SIMD lanes.
67 // TODO: Merge this with __native_vector_size from __algorithm/simd_utils.h
73 // CPU backends are expected to report errors (i.e. failure to allocate) by returning a disengaged `optional` from their
74 // implementation. Exceptions shouldn't be used to report an internal failure-to-allocate, since all exceptions are
75 // turned into a program termination at the front-end level. When a backend returns a disengaged `optional` to the
76 // frontend, the frontend will turn that into a call to `std::__throw_bad_alloc();` to report the internal failure to
79 template <class _Backend
>
83 _LIBCPP_END_NAMESPACE_STD
85 #endif // _LIBCPP_STD_VER >= 17
89 #endif // _LIBCPP___PSTL_CPU_ALGOS_CPU_TRAITS_H