[libcxx-commits] [PATCH] D149686: [libc++][DISCUSSION] Exploring PSTL backend customization points
Nikolas Klauser via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue May 2 14:41:21 PDT 2023
philnik added a comment.
In D149686#4313646 <https://reviews.llvm.org/D149686#4313646>, @crtrott wrote:
> I generally feel that we are better served with a overload set based on internal execution policy types. One problem I see is that we very, very fast are gonna get asked how to for example choose either SIMD or OpenMP based parallelism on a per invocation basis.
I don't understand what distinction you are making here. You can use OpenMP to generate SIMD instructions or you can use it to multi-thread your code, but there is no SIMD //or// OpenMP.
> The overload set based approach makes it easy to support this. Note we ARE allowed to ship implementation defined execution policies: "The semantics of parallel algorithms invoked with an execution policy object of implementation-defined type are implementation-defined." This is not undefined behavior, we just need to say what it does. That means for example we could ship std::omp_par std::omp_par_simd, std::gcd etc.. Or rather the LLVM-OpenMP project could ship std::omp_par together with a customization implementation of the algorithms. And AMD in their ROCm toolchain could add std::par_hip or something like that.
That's a lot more complicated than it seems to be at first. There are a few problems I see:
- `is_execution_policy_v<std::omp_par>` has to return true for implementation-defined execution policies, so we wouldn't be able to use it inside the implementation of the algorithms
- We would have to push/pop macros everywhere to avoid users `#define`ing our implementation non-conforming
- using OpenMP, `std::thread`s, GCD and whatever other mechanism together seems to defeat the purpose of the interface. At least as I understand it, the idea is to have an interface which brings you >90% of the way compared to writing it by hand.
- I don't really see the purpose of having the choice of selecting the backend. If there is a significant performance improvement, the implementation should be tuned instead of having the user try out X different backends to find the best one.
- This kind of customization is there in the PSTL, but it never materialized, so I don't think it's actually asked for that much
BTW the "implementation-defined" only forces us to document this. If it weren't mentioned, it would still be allowed for an implementation to support other execution policies, it just wouldn't have to be documented.
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