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

Anton Rydahl via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 10:56:42 PDT 2023


================
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_OPENMP_BACKEND_ANY_OF_H
+#define _LIBCPP___ALGORITHM_PSTL_BACKENDS_OPENMP_BACKEND_ANY_OF_H
+
+#include <__algorithm/any_of.h>
+#include <__algorithm/pstl_backends/cpu_backends/backend.h>
+#include <__algorithm/pstl_backends/openmp/backend.h>
+#include <__config>
+#include <__type_traits/is_execution_policy.h>
+
+#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
+_LIBCPP_HIDE_FROM_ABI bool
+__pstl_any_of(__omp_backend_tag, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
----------------
AntonRydahl wrote:

I think I have fixed the issue with `optional`. Thanks for telling me about that! I did not notice that it had been introduced in the CPU backend. After fixing optional, I get the following error when removing any_of.h:
```
# .---command stderr------------
# | In file included from /g/g92/rydahl1/LLVM_FORK/llvm-project/libcxx/test/std/algorithms/alg.sorting/alg.partitions/pstl.is_partitioned.pass.cpp:17:
# | In file included from /dev/shm/rydahl1/LLVM/build/include/c++/v1/algorithm:1827:
# | In file included from /dev/shm/rydahl1/LLVM/build/include/c++/v1/__algorithm/pstl_any_all_none_of.h:12:
# | In file included from /dev/shm/rydahl1/LLVM/build/include/c++/v1/__algorithm/pstl_find.h:15:
# | /dev/shm/rydahl1/LLVM/build/include/c++/v1/__algorithm/pstl_frontend_dispatch.h:36:12: error: no matching function for call to object of type '(lambda at /dev/shm/rydahl1/LLVM/build/include/c++/v1/__algorithm/pstl_any_all_none_of.h:42:7)'
# |    36 |     return __generic_impl(std::forward<_Args>(__args)...);
# |       |            ^~~~~~~~~~~~~~
# | /dev/shm/rydahl1/LLVM/build/include/c++/v1/__algorithm/pstl_any_all_none_of.h:40:15: note: in instantiation of function template specialization 'std::__pstl_frontend_dispatch<(lambda at /dev/shm/rydahl1/LLVM/build/include/c++/v1/__algorithm/pstl_any_all_none_of.h:41:7), (lambda at /dev/shm/rydahl1/LLVM/build/include/c++/v1/__algorithm/pstl_any_all_none_of.h:42:7), int *, int *, (lambda at /g/g92/rydahl1/LLVM_FORK/llvm-project/libcxx/test/std/algorithms/alg.sorting/alg.partitions/pstl.is_partitioned.pass.cpp:30:7)>' requested here
# |    40 |   return std::__pstl_frontend_dispatch(
# |       |               ^
# | /dev/shm/rydahl1/LLVM/build/include/c++/v1/__algorithm/pstl_any_all_none_of.h:119:27: note: in instantiation of function template specialization 'std::__any_of<const std::execution::parallel_unsequenced_policy &, int *&, (lambda at /g/g92/rydahl1/LLVM_FORK/llvm-project/libcxx/test/std/algorithms/alg.sorting/alg.partitions/pstl.is_partitioned.pass.cpp:30:7) &, std::execution::parallel_unsequenced_policy, 0>' requested here
# |   119 |         auto __res = std::__any_of(__policy, __g_first, __g_last, __g_pred);
# |       |                           ^
# | /dev/shm/rydahl1/LLVM/build/include/c++/v1/__algorithm/pstl_any_all_none_of.h:137:21: note: in instantiation of function template specialization 'std::__none_of<const std::execution::parallel_unsequenced_policy &, int *, (lambda at /g/g92/rydahl1/LLVM_FORK/llvm-project/libcxx/test/std/algorithms/alg.sorting/alg.partitions/pstl.is_partitioned.pass.cpp:30:7), std::execution::parallel_unsequenced_policy, 0>' requested here
# |   137 |   auto __res = std::__none_of(__policy, std::move(__first), std::move(__last), std::move(__pred));
# |       |                     ^
# | /dev/shm/rydahl1/LLVM/build/include/c++/v1/__algorithm/pstl_is_partitioned.h:48:21: note: in instantiation of function template specialization 'std::none_of<const std::execution::parallel_unsequenced_policy &, int *, (lambda at /g/g92/rydahl1/LLVM_FORK/llvm-project/libcxx/test/std/algorithms/alg.sorting/alg.partitions/pstl.is_partitioned.pass.cpp:30:7), std::execution::parallel_unsequenced_policy, 0>' requested here
# |    48 |         return std::none_of(__policy, __g_first, __g_last, __g_pred);
# |       |                     ^
# | /dev/shm/rydahl1/LLVM/build/include/c++/v1/__algorithm/pstl_is_partitioned.h:62:21: note: in instantiation of function template specialization 'std::__is_partitioned<const std::execution::parallel_unsequenced_policy &, int *, (lambda at /g/g92/rydahl1/LLVM_FORK/llvm-project/libcxx/test/std/algorithms/alg.sorting/alg.partitions/pstl.is_partitioned.pass.cpp:30:7), std::execution::parallel_unsequenced_policy, 0>' requested here
# |    62 |   auto __res = std::__is_partitioned(__policy, std::move(__first), std::move(__last), std::move(__pred));
# |       |                     ^
# | /g/g92/rydahl1/LLVM_FORK/llvm-project/libcxx/test/std/algorithms/alg.sorting/alg.partitions/pstl.is_partitioned.pass.cpp:30:19: note: in instantiation of function template specialization 'std::is_partitioned<const std::execution::parallel_unsequenced_policy &, int *, (lambda at /g/g92/rydahl1/LLVM_FORK/llvm-project/libcxx/test/std/algorithms/alg.sorting/alg.partitions/pstl.is_partitioned.pass.cpp:30:7), std::execution::parallel_unsequenced_policy, 0>' requested here
# |    30 |       assert(std::is_partitioned(policy, Iter(std::begin(a)), Iter(std::end(a)), [](int i) { return i < 3; }));
# |       |                   ^
# | /g/g92/rydahl1/LLVM_FORK/llvm-project/libcxx/test/support/test_execution_policies.h:38:3: note: in instantiation of function template specialization 'Test<int *>::operator()<const std::execution::parallel_unsequenced_policy &>' requested here
# |    38 |   func(std::execution::par_unseq);
# |       |   ^
# | /g/g92/rydahl1/LLVM_FORK/llvm-project/libcxx/test/support/test_execution_policies.h:47:5: note: in instantiation of function template specialization 'test_execution_policies<Test<int *>>' requested here
# |    47 |     test_execution_policies(TestClass<Iter>{});
# |       |     ^
# | /g/g92/rydahl1/LLVM_FORK/llvm-project/libcxx/test/support/type_algorithms.h:52:23: note: in instantiation of function template specialization 'TestIteratorWithPolicies<Test>::operator()<int *>' requested here
# |    52 |   swallow((f.template operator()<Types>(), 0)...);
# |       |                       ^
# | /dev/shm/rydahl1/LLVM/build/include/c++/v1/__algorithm/pstl_any_all_none_of.h:42:7: note: candidate function not viable: expects an lvalue for 1st argument
# |    42 |       [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) -> optional<bool> {
# |       |       ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~
...
```

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


More information about the llvm-commits mailing list