xref: /freebsd-src/contrib/llvm-project/libcxx/include/__pstl/cpu_algos/cpu_traits.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1*0fca6ea1SDimitry Andric //===----------------------------------------------------------------------===//
2*0fca6ea1SDimitry Andric //
3*0fca6ea1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0fca6ea1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0fca6ea1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0fca6ea1SDimitry Andric //
7*0fca6ea1SDimitry Andric //===----------------------------------------------------------------------===//
8*0fca6ea1SDimitry Andric 
9*0fca6ea1SDimitry Andric #ifndef _LIBCPP___PSTL_CPU_ALGOS_CPU_TRAITS_H
10*0fca6ea1SDimitry Andric #define _LIBCPP___PSTL_CPU_ALGOS_CPU_TRAITS_H
11*0fca6ea1SDimitry Andric 
12*0fca6ea1SDimitry Andric #include <__config>
13*0fca6ea1SDimitry Andric #include <cstddef>
14*0fca6ea1SDimitry Andric 
15*0fca6ea1SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16*0fca6ea1SDimitry Andric #  pragma GCC system_header
17*0fca6ea1SDimitry Andric #endif
18*0fca6ea1SDimitry Andric 
19*0fca6ea1SDimitry Andric _LIBCPP_PUSH_MACROS
20*0fca6ea1SDimitry Andric #include <__undef_macros>
21*0fca6ea1SDimitry Andric 
22*0fca6ea1SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
23*0fca6ea1SDimitry Andric namespace __pstl {
24*0fca6ea1SDimitry Andric 
25*0fca6ea1SDimitry Andric // __cpu_traits
26*0fca6ea1SDimitry Andric //
27*0fca6ea1SDimitry Andric // This traits class encapsulates the basis operations for a CPU-based implementation of the PSTL.
28*0fca6ea1SDimitry Andric // All the operations in the PSTL can be implemented from these basis operations, so a pure CPU backend
29*0fca6ea1SDimitry Andric // only needs to customize these traits in order to get an implementation of the whole PSTL.
30*0fca6ea1SDimitry Andric //
31*0fca6ea1SDimitry Andric // Basis operations
32*0fca6ea1SDimitry Andric // ================
33*0fca6ea1SDimitry Andric //
34*0fca6ea1SDimitry Andric //  template <class _RandomAccessIterator, class _Functor>
35*0fca6ea1SDimitry Andric //  optional<__empty> __for_each(_RandomAccessIterator __first, _RandomAccessIterator __last, _Functor __func);
36*0fca6ea1SDimitry Andric //    - __func must take a subrange of [__first, __last) that should be executed in serial
37*0fca6ea1SDimitry Andric //
38*0fca6ea1SDimitry Andric //  template <class _Iterator, class _UnaryOp, class _Tp, class _BinaryOp, class _Reduction>
39*0fca6ea1SDimitry Andric //  optional<_Tp> __transform_reduce(_Iterator __first, _Iterator __last, _UnaryOp, _Tp __init, _BinaryOp, _Reduction);
40*0fca6ea1SDimitry Andric //
41*0fca6ea1SDimitry Andric //  template <class _RandomAccessIterator1,
42*0fca6ea1SDimitry Andric //            class _RandomAccessIterator2,
43*0fca6ea1SDimitry Andric //            class _RandomAccessIterator3,
44*0fca6ea1SDimitry Andric //            class _Compare,
45*0fca6ea1SDimitry Andric //            class _LeafMerge>
46*0fca6ea1SDimitry Andric //  optional<_RandomAccessIterator3> __merge(_RandomAccessIterator1 __first1,
47*0fca6ea1SDimitry Andric //                                           _RandomAccessIterator1 __last1,
48*0fca6ea1SDimitry Andric //                                           _RandomAccessIterator2 __first2,
49*0fca6ea1SDimitry Andric //                                           _RandomAccessIterator2 __last2,
50*0fca6ea1SDimitry Andric //                                           _RandomAccessIterator3 __outit,
51*0fca6ea1SDimitry Andric //                                           _Compare __comp,
52*0fca6ea1SDimitry Andric //                                           _LeafMerge __leaf_merge);
53*0fca6ea1SDimitry Andric //
54*0fca6ea1SDimitry Andric //  template <class _RandomAccessIterator, class _Comp, class _LeafSort>
55*0fca6ea1SDimitry Andric //  optional<__empty> __stable_sort(_RandomAccessIterator __first,
56*0fca6ea1SDimitry Andric //                                  _RandomAccessIterator __last,
57*0fca6ea1SDimitry Andric //                                  _Comp __comp,
58*0fca6ea1SDimitry Andric //                                  _LeafSort __leaf_sort);
59*0fca6ea1SDimitry Andric //
60*0fca6ea1SDimitry Andric //   void __cancel_execution();
61*0fca6ea1SDimitry Andric //      Cancel the execution of other jobs - they aren't needed anymore. This is not a binding request,
62*0fca6ea1SDimitry Andric //      some backends may not actually be able to cancel jobs.
63*0fca6ea1SDimitry Andric //
64*0fca6ea1SDimitry Andric //   constexpr size_t __lane_size;
65*0fca6ea1SDimitry Andric //      Size of SIMD lanes.
66*0fca6ea1SDimitry Andric //      TODO: Merge this with __native_vector_size from __algorithm/simd_utils.h
67*0fca6ea1SDimitry Andric //
68*0fca6ea1SDimitry Andric //
69*0fca6ea1SDimitry Andric // Exception handling
70*0fca6ea1SDimitry Andric // ==================
71*0fca6ea1SDimitry Andric //
72*0fca6ea1SDimitry Andric // CPU backends are expected to report errors (i.e. failure to allocate) by returning a disengaged `optional` from their
73*0fca6ea1SDimitry Andric // implementation. Exceptions shouldn't be used to report an internal failure-to-allocate, since all exceptions are
74*0fca6ea1SDimitry Andric // turned into a program termination at the front-end level. When a backend returns a disengaged `optional` to the
75*0fca6ea1SDimitry Andric // frontend, the frontend will turn that into a call to `std::__throw_bad_alloc();` to report the internal failure to
76*0fca6ea1SDimitry Andric // the user.
77*0fca6ea1SDimitry Andric 
78*0fca6ea1SDimitry Andric template <class _Backend>
79*0fca6ea1SDimitry Andric struct __cpu_traits;
80*0fca6ea1SDimitry Andric 
81*0fca6ea1SDimitry Andric } // namespace __pstl
82*0fca6ea1SDimitry Andric _LIBCPP_END_NAMESPACE_STD
83*0fca6ea1SDimitry Andric 
84*0fca6ea1SDimitry Andric _LIBCPP_POP_MACROS
85*0fca6ea1SDimitry Andric 
86*0fca6ea1SDimitry Andric #endif // _LIBCPP___PSTL_CPU_ALGOS_CPU_TRAITS_H
87