Skip to content

Commit 7d0451c

Browse files
[NFCI][SYCL] Refactor reductions implementations (#7322)
The purpose of this change is 1) Make it clear that sycl::range version always delegates to some sycl::nd_range implementation. 2) Flatten all existing implementations. That required splitting reduction_parallel_for_basic_impl depending on Reduction::has_fast_reduce. However, I also inlined its helper routines (that now had unambigious branches for "if constexpr (Reduction::*)") so the ratio between duplicate/unique code isn't bad at all. 3) Make a unique dispatching entry and have all the implementations provide the same interface. I plan to use it in unit-tests to bypass the dispatch and test all the implementation directly (when applicable based on nd_range/BinOp/HW/etc.). I'd say 90% of the change is straightforward code movement with the exceptions of - Inlining described above - Simplifying __sycl_reduction_kernel helper enabled by this change - Factoring out forward declarations in handler.hpp into a separate reduction_fordward.hpp - Rewriting dispatcher routine - caused by changes in the interfaces, not logic updates.
1 parent 62dd13d commit 7d0451c

File tree

7 files changed

+950
-916
lines changed

7 files changed

+950
-916
lines changed

sycl/include/sycl/handler.hpp

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <sycl/nd_item.hpp>
3131
#include <sycl/nd_range.hpp>
3232
#include <sycl/property_list.hpp>
33+
#include <sycl/reduction_forward.hpp>
3334
#include <sycl/sampler.hpp>
3435
#include <sycl/stl.hpp>
3536

@@ -268,43 +269,9 @@ class RoundedRangeKernelWithKH {
268269
KernelType KernelFunc;
269270
};
270271

271-
template <typename T, class BinaryOperation, int Dims, size_t Extent,
272-
typename RedOutVar>
273-
class reduction_impl_algo;
274-
275272
using sycl::detail::enable_if_t;
276273
using sycl::detail::queue_impl;
277274

278-
// Reductions implementation need access to private members of handler. Those
279-
// are limited to those below.
280-
namespace reduction {
281-
inline void finalizeHandler(handler &CGH);
282-
template <class FunctorTy> void withAuxHandler(handler &CGH, FunctorTy Func);
283-
} // namespace reduction
284-
285-
template <typename KernelName, int Dims, typename PropertiesT,
286-
typename KernelType, typename Reduction>
287-
void reduction_parallel_for(handler &CGH,
288-
std::shared_ptr<detail::queue_impl> Queue,
289-
range<Dims> Range, PropertiesT Properties,
290-
Reduction Redu, KernelType KernelFunc);
291-
292-
template <typename KernelName, int Dims, typename PropertiesT,
293-
typename KernelType, typename Reduction>
294-
void reduction_parallel_for(handler &CGH,
295-
std::shared_ptr<detail::queue_impl> Queue,
296-
nd_range<Dims> Range, PropertiesT Properties,
297-
Reduction Redu, KernelType KernelFunc);
298-
299-
template <typename KernelName, int Dims, typename PropertiesT,
300-
typename... RestT>
301-
void reduction_parallel_for(handler &CGH,
302-
std::shared_ptr<detail::queue_impl> Queue,
303-
nd_range<Dims> Range, PropertiesT Properties,
304-
RestT... Rest);
305-
306-
template <typename T> struct IsReduction;
307-
template <typename FirstT, typename... RestT> struct AreAllButLastReductions;
308275
} // namespace detail
309276

310277
/// Command group handler class.

0 commit comments

Comments
 (0)