[llvm] Adding Separate OpenMP Offloading Backend to `libcxx/include/__algorithm/pstl_backends` (PR #66968)

Louis Dionne via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 4 10:28:29 PDT 2023


================
@@ -0,0 +1,120 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___ALGORITHM_PSTL_BACKENDS_GPU_BACKENDS_TRANSFORM_REDUCE_H
+#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_GPU_BACKENDS_TRANSFORM_REDUCE_H
+
+#include <__algorithm/pstl_backends/cpu_backends/backend.h>
+#include <__algorithm/pstl_backends/gpu_backends/backend.h>
+#include <__config>
+#include <__functional/operations.h>
+#include <__iterator/concepts.h>
+#include <__iterator/iterator_traits.h>
+#include <__numeric/transform_reduce.h>
+#include <__type_traits/integral_constant.h>
+#include <__type_traits/is_arithmetic.h>
+#include <__type_traits/is_execution_policy.h>
+#include <__type_traits/operation_traits.h>
+#include <__utility/move.h>
+#include <__utility/terminate_on_exception.h>
+#include <new>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _T1, class _T2, class _T3>
+struct _LIBCPP_HIDE_FROM_ABI __is_supported_reduction : std::false_type {};
+
+#  define __PSTL_IS_SUPPORTED_REDUCTION(funname)                                                                       \
----------------
ldionne wrote:

There's something trying to emerge here. We already have `libcxx/include/__type_traits/predicate_traits.h` and `libcxx/include/__type_traits/operation_traits.h`. IMO we could unify those into something like:

```
template <>
struct __desugars_to<__equal_to, std::equal_to<>> : true_type {};

template <>
struct __desugars_to<ranges::equal_to, std::equal_to<>> : true_type {};

template <>
struct __desugars_to<ranges::plus, std::plus<>> : std::true_type {};

// etc...
```

Then, this becomes simply:

```
template <class _Func>
struct __is_supported_reduction : bool_constant<
    __desugars_to<_Func, std::minus<>>::value ||
    __desugars_to<_Func, std::multiplies<>>::value ||
    __desugars_to<_Func, std::logical_and<>>::value ||
    __desugars_to<_Func, std::logical_or<>>::value ||
    __desugars_to<_Func, std::bit_and<>>::value ||
    __desugars_to<_Func, std::bit_or<>>::value ||
    __desugars_to<_Func, std::bit_xor<>>::value
> {};
```

This would mandate some prior refactoring, but it would be quite nice.

https://github.com/llvm/llvm-project/pull/66968


More information about the llvm-commits mailing list