Skip to content

Commit

Permalink
Clean up FunctorAnalysis
Browse files Browse the repository at this point in the history
  • Loading branch information
masterleinad committed Jun 2, 2023
1 parent ab6f756 commit 2bc7b96
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 133 deletions.
5 changes: 2 additions & 3 deletions core/src/HIP/Kokkos_HIP_Parallel_MDRange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,8 @@ class ParallelReduce<CombinedFunctorReducerType,

template <typename Policy, typename Functor>
static int max_tile_size_product(const Policy&, const Functor&) {
using closure_type =
ParallelReduce<FunctorType, Kokkos::MDRangePolicy<Traits...>,
ReducerType, HIP>;
using closure_type = ParallelReduce<CombinedFunctorReducerType,
Kokkos::MDRangePolicy<Traits...>, HIP>;
unsigned block_size = hip_get_max_blocksize<closure_type, LaunchBounds>();
if (block_size == 0) {
Kokkos::Impl::throw_runtime_exception(
Expand Down
11 changes: 2 additions & 9 deletions core/src/Kokkos_Core_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,21 +326,14 @@ class ParallelFor;
///
/// This is an implementation detail of parallel_reduce. Users should
/// skip this and go directly to the nonmember function parallel_reduce.
template <class FunctorType, class ExecPolicy, class ReducerType = InvalidType,
class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
FunctorType, ExecPolicy>::execution_space>
template <typename CombinedFunctorReducerType, typename PolicyType,
typename ExecutionSpaceType>
class ParallelReduce;
// FIXME Remove once all backends implement the new interface
template <typename FunctorType, typename FunctorAnalysisReducerType,
typename Enable = void>
class CombinedFunctorReducer;
// FIXME Remove once all backends implement the new interface
template <typename CombinedFunctorReducerType, typename PolicyType,
typename ExecutionSpaceType, typename Enable = void>
class ParallelReduceWrapper;
/// \class ParallelScan
/// \brief Implementation detail of parallel_scan.
///
Expand Down
3 changes: 1 addition & 2 deletions core/src/Kokkos_ExecPolicy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,10 +1070,9 @@ template <class... Args>
struct PatternImplSpecializationFromTag<Kokkos::ParallelForTag, Args...>
: type_identity<ParallelFor<Args...>> {};

// FIXME Drop "Wrapper" when all backends implement the new reduce interface
template <class... Args>
struct PatternImplSpecializationFromTag<Kokkos::ParallelReduceTag, Args...>
: type_identity<ParallelReduceWrapper<Args...>> {};
: type_identity<ParallelReduce<Args...>> {};

template <class... Args>
struct PatternImplSpecializationFromTag<Kokkos::ParallelScanTag, Args...>
Expand Down
116 changes: 3 additions & 113 deletions core/src/Kokkos_Parallel_Reduce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1372,116 +1372,6 @@ class CombinedFunctorReducer<
FunctorAnalysisReducerType m_reducer;
};

// FIXME Remove once all backends implement the new interface
template <typename ExecutionSpace>
struct implements_new_reduce_interface : std::false_type {};

#ifdef KOKKOS_ENABLE_SERIAL
template <>
struct implements_new_reduce_interface<Kokkos::Serial> : std::true_type {};
#endif

#ifdef KOKKOS_ENABLE_HPX
template <>
struct implements_new_reduce_interface<Kokkos::Experimental::HPX>
: std::true_type {};
#endif

#ifdef KOKKOS_ENABLE_OPENMP
template <>
struct implements_new_reduce_interface<Kokkos::OpenMP> : std::true_type {};
#endif

#ifdef KOKKOS_ENABLE_THREADS
template <>
struct implements_new_reduce_interface<Kokkos::Threads> : std::true_type {};
#endif

#ifdef KOKKOS_ENABLE_OPENMPTARGET
template <>
struct implements_new_reduce_interface<Kokkos::Experimental::OpenMPTarget>
: std::true_type {};
#endif

#ifdef KOKKOS_ENABLE_CUDA
template <>
struct implements_new_reduce_interface<Kokkos::Cuda> : std::true_type {};
#endif

#ifdef KOKKOS_ENABLE_HIP
template <>
struct implements_new_reduce_interface<Kokkos::HIP> : std::true_type {};
#endif

#ifdef KOKKOS_ENABLE_OPENACC
template <>
struct implements_new_reduce_interface<Kokkos::Experimental::OpenACC>
: std::true_type {};
#endif

#ifdef KOKKOS_ENABLE_SYCL
template <>
struct implements_new_reduce_interface<Kokkos::Experimental::SYCL>
: std::true_type {};
#endif

template <typename CombinedFunctorReducerType, typename PolicyType,
typename ExecutionSpaceType, typename Enable>
class ParallelReduceWrapper {
using functor_type = typename CombinedFunctorReducerType::functor_type;
using helper_reducer_type =
typename CombinedFunctorReducerType::reducer_type::functor_type;

static constexpr bool has_reducer =
!std::is_same_v<functor_type, helper_reducer_type>;

using reducer_type =
std::conditional_t<has_reducer, helper_reducer_type, InvalidType>;

public:
using wrapped_type = Impl::ParallelReduce<functor_type, PolicyType,
reducer_type, ExecutionSpaceType>;

private:
wrapped_type m_parallel_reduce;

public:
template <typename ReturnValue>
ParallelReduceWrapper(
const CombinedFunctorReducerType& combined_functor_reducer,
const PolicyType& policy, const ReturnValue& return_value)
: m_parallel_reduce(
combined_functor_reducer.get_functor(), policy,
Kokkos::Impl::if_c<has_reducer, helper_reducer_type, ReturnValue>::
select(combined_functor_reducer.get_reducer().get_functor(),
return_value)) {}

void execute() { m_parallel_reduce.execute(); }
};

template <typename CombinedFunctorReducerType, typename PolicyType,
typename ExecutionSpaceType>
class ParallelReduceWrapper<
CombinedFunctorReducerType, PolicyType, ExecutionSpaceType,
std::enable_if_t<
implements_new_reduce_interface<ExecutionSpaceType>::value>> {
public:
using wrapped_type = Impl::ParallelReduce<CombinedFunctorReducerType,
PolicyType, ExecutionSpaceType>;

private:
wrapped_type m_parallel_reduce;

public:
template <typename ReturnValue>
ParallelReduceWrapper(
const CombinedFunctorReducerType& combined_functor_reducer,
const PolicyType& policy, const ReturnValue& return_value)
: m_parallel_reduce(combined_functor_reducer, policy, return_value) {}

void execute() { m_parallel_reduce.execute(); }
};

template <class T, class ReturnType, class ValueTraits>
struct ParallelReduceReturnValue;

Expand Down Expand Up @@ -1619,9 +1509,9 @@ struct ParallelReduceAdaptor {
ReducerSelector::select(functor, return_value)));

// FIXME Remove "Wrapper" once all backends implement the new interface
Impl::ParallelReduceWrapper<decltype(functor_reducer), PolicyType,
typename Impl::FunctorPolicyExecutionSpace<
FunctorType, PolicyType>::execution_space>
Impl::ParallelReduce<decltype(functor_reducer), PolicyType,
typename Impl::FunctorPolicyExecutionSpace<
FunctorType, PolicyType>::execution_space>
closure(functor_reducer, inner_policy,
return_value_adapter::return_value(return_value, functor));
Kokkos::Impl::shared_allocation_tracking_enable();
Expand Down
4 changes: 2 additions & 2 deletions core/src/impl/Kokkos_FunctorAnalysis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ struct DeduceFunctorPatternInterface<
using type = FunctorPatternInterface::FOR;
};

template <class FunctorType, class ExecPolicy, class ReducerType,
template <class CombinedFunctorReducerType, class ExecPolicy,
class ExecutionSpace>
struct DeduceFunctorPatternInterface<
ParallelReduce<FunctorType, ExecPolicy, ReducerType, ExecutionSpace>> {
ParallelReduce<CombinedFunctorReducerType, ExecPolicy, ExecutionSpace>> {
using type = FunctorPatternInterface::REDUCE;
};

Expand Down
8 changes: 4 additions & 4 deletions core/src/impl/Kokkos_Tools_Generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ struct SimpleTeamSizeCalculator {
using exec_space = typename Policy::execution_space;
using analysis = Kokkos::Impl::FunctorAnalysis<
Kokkos::Impl::FunctorPatternInterface::REDUCE, Policy, Functor, void>;
using driver = typename Kokkos::Impl::ParallelReduceWrapper<
using driver = typename Kokkos::Impl::ParallelReduce<
Kokkos::Impl::CombinedFunctorReducer<Functor,
typename analysis::Reducer>,
Policy, exec_space>::wrapped_type;
Policy, exec_space>;
return driver::max_tile_size_product(policy, functor);
}
};
Expand Down Expand Up @@ -154,10 +154,10 @@ struct ComplexReducerSizeCalculator {
using Analysis = Kokkos::Impl::FunctorAnalysis<
Kokkos::Impl::FunctorPatternInterface::REDUCE, Policy, ReducerType,
void>;
using driver = typename Kokkos::Impl::ParallelReduceWrapper<
using driver = typename Kokkos::Impl::ParallelReduce<
Kokkos::Impl::CombinedFunctorReducer<Functor,
typename Analysis::Reducer>,
Policy, exec_space>::wrapped_type;
Policy, exec_space>;
return driver::max_tile_size_product(policy, functor);
}
};
Expand Down

0 comments on commit 2bc7b96

Please sign in to comment.