|
| 1 | + |
| 2 | +#pragma once |
| 3 | + |
| 4 | +#include <alpaka/alpaka.hpp> |
| 5 | + |
| 6 | +#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) and not defined(ALPAKA_HOST_ONLY) |
| 7 | +#include <thrust/count.h> |
| 8 | +#include <thrust/execution_policy.h> |
| 9 | +#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) and not defined(ALPAKA_HOST_ONLY) |
| 10 | +#include <thrust/count.h> |
| 11 | +#include <thrust/execution_policy.h> |
| 12 | +#elif defined(ALPAKA_ACC_SYCL_ENABLED) |
| 13 | +#include <oneapi/dpl/algorithm> |
| 14 | +#include <oneapi/dpl/execution> |
| 15 | +#else |
| 16 | +#include <algorithm> |
| 17 | +#endif |
| 18 | + |
| 19 | +namespace clue::internal::algorithm { |
| 20 | + |
| 21 | + template <typename InputIterator, typename Predicate> |
| 22 | + ALPAKA_FN_HOST inline constexpr auto count_if(InputIterator first, |
| 23 | + InputIterator last, |
| 24 | + Predicate pred) { |
| 25 | +#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) and not defined(ALPAKA_HOST_ONLY) |
| 26 | + return thrust::count_if(thrust::device, first, last, pred); |
| 27 | +#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) and not defined(ALPAKA_HOST_ONLY) |
| 28 | + return thrust::count_if(thrust::hip::par, first, last, pred); |
| 29 | +#elif defined(ALPAKA_ACC_SYCL_ENABLED) |
| 30 | + return oneapi::dpl::count_if(oneapi::dpl::execution::dpcpp_default, first, last, pred); |
| 31 | +#else |
| 32 | + return std::count_if(first, last, pred); |
| 33 | +#endif |
| 34 | + } |
| 35 | + |
| 36 | + template <typename ExecutionPolicy, typename InputIterator, typename Predicate> |
| 37 | + ALPAKA_FN_HOST inline constexpr auto count_if(ExecutionPolicy&& policy, |
| 38 | + InputIterator first, |
| 39 | + InputIterator last, |
| 40 | + Predicate pred) { |
| 41 | +#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) and not defined(ALPAKA_HOST_ONLY) |
| 42 | + return thrust::count_if(std::forward<ExecutionPolicy>(policy), first, last, pred); |
| 43 | +#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) and not defined(ALPAKA_HOST_ONLY) |
| 44 | + return thrust::count_if(std::forward<ExecutionPolicy>(policy), first, last, pred); |
| 45 | +#elif defined(ALPAKA_ACC_SYCL_ENABLED) |
| 46 | + return oneapi::dpl::count_if(std::forward<ExecutionPolicy>(policy), first, last, pred); |
| 47 | +#else |
| 48 | + return std::count_if(std::forward<ExecutionPolicy>(policy), first, last, pred); |
| 49 | +#endif |
| 50 | + } |
| 51 | + |
| 52 | +} // namespace clue::internal::algorithm |
0 commit comments