[libcxx-commits] [PATCH] D149686: [libc++][DISCUSSION] Exploring PSTL backend customization points

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue May 9 10:38:37 PDT 2023


ldionne added a comment.

I like this. I think this answers all the constraints we had determined yesterday.



================
Comment at: libcxx/include/__algorithm/pstl_backend.h:29-41
+  template <class _ExecutionPolicy, class _Iterator, class _Func>
+  void __for_each(_Backend, _ExecutionPolicy&&, _Iterator __first, _Iterator __last, _Func __f);
+
+  template <class _ExecutionPolicy, class _Iterator, class _Tp, class _BinOp>
+  _Tp __reduce(_Backend, _ExecutionPolicy&&, _Iterator __first, _Iterator __last, _Tp const& __value, _BinOp __op);
+
+  etc...
----------------



================
Comment at: libcxx/include/__algorithm/pstl_backend.h:66-90
+#  if defined(_PSTL_PAR_BACKEND_STD_THREAD)
+#    include <__algorithm/pstl_backends/thread.h>
+template <> struct __select_backend<std::parallel_policy> { using type = __std_thread_backend; };
+template <> struct __select_backend<std::parallel_unsequenced_policy> { using type = __std_thread_backend; };
+
+#  elif defined(_PSTL_PAR_BACKEND_GCD)
+#    include <__algorithm/pstl_backends/gcd.h>
----------------
```
#  if defined(_PSTL_PAR_BACKEND_STD_THREAD) || defined(_PSTL_PAR_BACKEND_GCD) || defined(_PSTL_PAR_BACKEND_TBB) || defined(_PSTL_PAR_BACKEND_SERIAL)
#    include <__algorithm/pstl_backends/cpu_backend.h>
template <> struct __select_backend<std::parallel_policy> { using type = __cpu_backend; };
template <> struct __select_backend<std::parallel_unsequenced_policy> { using type = __cpu_backend; };

#elif defined(_PSTL_PAR_BACKEND_SOME_FUNKY_GPU)
#    include <__algorithm/pstl_backends/funky_gpu_backend.h>
template <> struct __select_backend<std::parallel_policy> { using type = __funky_gpu_backend; };
template <> struct __select_backend<std::parallel_unsequenced_policy> { using type = __funky_gpu_backend; };

#  else

// ...New vendors can add parallel backends here...

#    error "Invalid choice of a PSTL parallel backend"
#  endif
```


================
Comment at: libcxx/include/__algorithm/pstl_backends/cpu_backend.h:18-22
+#ifdef _LIBCPP_HAS_NO_THREADS
+#  include <__algorithm/pstl_backends/cpu_backends/thread.h>
+#else
+#  include <__algorithm/pstl_backends/cpu_backends/serial.h>
+#endif
----------------
```
#ifdef _LIBCPP_HAS_NO_THREADS
#  include <__algorithm/pstl_backends/cpu_backends/serial.h>
#elif defined(_PSTL_PAR_BACKEND_STD_THREAD)
#  include <__algorithm/pstl_backends/cpu_backends/thread.h>
#elif defined(_PSTL_PAR_BACKEND_GCD)
#  include <__algorithm/pstl_backends/cpu_backends/gcd.h>
#elif defined(_PSTL_PAR_BACKEND_TBB)
#  include <__algorithm/pstl_backends/cpu_backends/tbb.h>
#elif defined(_PSTL_PAR_BACKEND_SERIAL)
#  include <__algorithm/pstl_backends/cpu_backends/serial.h>
#else
#  error "Invalid backend choice for a CPU backend"
#endif
```


================
Comment at: libcxx/include/__algorithm/pstl_for_each.h:53
+  if constexpr (requires {std::__pstl_for_each_n(_Backend{}, __first, __size, __func); }) {
+    __pstl_for_each_n<_RawPolicy>(_Backend{}, std::move(__first), __size, std::move(__func));
   } else {
----------------



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149686/new/

https://reviews.llvm.org/D149686



More information about the libcxx-commits mailing list