Skip to content

Commit 33db95c

Browse files
[NFC][SYCL][Reduction] Make detail::reduction_parallel_for "callable" by tests (#7405)
Eliminate "std::shared_ptr<detail::queue_impl> Queue" param and make them handler's friends instead, so that I can write tests/benchmarks referencing those directly to bypass reduction strategy auto-selection.
1 parent 4bebb35 commit 33db95c

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

sycl/include/sycl/handler.hpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,8 +2036,8 @@ class __SYCL_EXPORT handler {
20362036
ext::oneapi::experimental::is_property_list<PropertiesT>::value>
20372037
parallel_for(range<Dims> Range, PropertiesT Properties, Reduction Redu,
20382038
_KERNELFUNCPARAM(KernelFunc)) {
2039-
detail::reduction_parallel_for<KernelName>(*this, MQueue, Range, Properties,
2040-
Redu, std::move(KernelFunc));
2039+
detail::reduction_parallel_for<KernelName>(*this, Range, Properties, Redu,
2040+
std::move(KernelFunc));
20412041
}
20422042

20432043
template <typename KernelName = detail::auto_name, typename KernelType,
@@ -2057,7 +2057,7 @@ class __SYCL_EXPORT handler {
20572057
detail::AreAllButLastReductions<RestT...>::value &&
20582058
ext::oneapi::experimental::is_property_list<PropertiesT>::value>
20592059
parallel_for(nd_range<Dims> Range, PropertiesT Properties, RestT &&...Rest) {
2060-
detail::reduction_parallel_for<KernelName>(*this, MQueue, Range, Properties,
2060+
detail::reduction_parallel_for<KernelName>(*this, Range, Properties,
20612061
std::forward<RestT>(Rest)...);
20622062
}
20632063

@@ -2519,6 +2519,19 @@ class __SYCL_EXPORT handler {
25192519
template <class FunctorTy>
25202520
friend void detail::reduction::withAuxHandler(handler &CGH, FunctorTy Func);
25212521

2522+
template <typename KernelName, detail::reduction::strategy Strategy, int Dims,
2523+
typename PropertiesT, typename KernelType, typename Reduction>
2524+
friend void detail::reduction_parallel_for(handler &CGH, range<Dims> Range,
2525+
PropertiesT Properties,
2526+
Reduction Redu,
2527+
KernelType KernelFunc);
2528+
2529+
template <typename KernelName, detail::reduction::strategy Strategy, int Dims,
2530+
typename PropertiesT, typename... RestT>
2531+
friend void
2532+
detail::reduction_parallel_for(handler &CGH, nd_range<Dims> NDRange,
2533+
PropertiesT Properties, RestT... Rest);
2534+
25222535
#ifndef __SYCL_DEVICE_ONLY__
25232536
friend void detail::associateWithHandler(handler &,
25242537
detail::AccessorBaseHost *,

sycl/include/sycl/reduction.hpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,11 +2304,9 @@ template <> struct NDRangeReduction<reduction::strategy::auto_select> {
23042304

23052305
template <typename KernelName, reduction::strategy Strategy, int Dims,
23062306
typename PropertiesT, typename... RestT>
2307-
void reduction_parallel_for(handler &CGH,
2308-
std::shared_ptr<detail::queue_impl> Queue,
2309-
nd_range<Dims> NDRange, PropertiesT Properties,
2310-
RestT... Rest) {
2311-
NDRangeReduction<Strategy>::template run<KernelName>(CGH, Queue, NDRange,
2307+
void reduction_parallel_for(handler &CGH, nd_range<Dims> NDRange,
2308+
PropertiesT Properties, RestT... Rest) {
2309+
NDRangeReduction<Strategy>::template run<KernelName>(CGH, CGH.MQueue, NDRange,
23122310
Properties, Rest...);
23132311
}
23142312

@@ -2317,10 +2315,9 @@ reduGetMaxNumConcurrentWorkGroups(std::shared_ptr<queue_impl> Queue);
23172315

23182316
template <typename KernelName, reduction::strategy Strategy, int Dims,
23192317
typename PropertiesT, typename KernelType, typename Reduction>
2320-
void reduction_parallel_for(handler &CGH,
2321-
std::shared_ptr<detail::queue_impl> Queue,
2322-
range<Dims> Range, PropertiesT Properties,
2323-
Reduction Redu, KernelType KernelFunc) {
2318+
void reduction_parallel_for(handler &CGH, range<Dims> Range,
2319+
PropertiesT Properties, Reduction Redu,
2320+
KernelType KernelFunc) {
23242321
// Before running the kernels, check that device has enough local memory
23252322
// to hold local arrays required for the tree-reduction algorithm.
23262323
constexpr bool IsTreeReduction =
@@ -2331,13 +2328,13 @@ void reduction_parallel_for(handler &CGH,
23312328
#ifdef __SYCL_REDUCTION_NUM_CONCURRENT_WORKGROUPS
23322329
__SYCL_REDUCTION_NUM_CONCURRENT_WORKGROUPS;
23332330
#else
2334-
reduGetMaxNumConcurrentWorkGroups(Queue);
2331+
reduGetMaxNumConcurrentWorkGroups(CGH.MQueue);
23352332
#endif
23362333

23372334
// TODO: currently the preferred work group size is determined for the given
23382335
// queue/device, while it is safer to use queries to the kernel pre-compiled
23392336
// for the device.
2340-
size_t PrefWGSize = reduGetPreferredWGSize(Queue, OneElemSize);
2337+
size_t PrefWGSize = reduGetPreferredWGSize(CGH.MQueue, OneElemSize);
23412338

23422339
size_t NWorkItems = Range.size();
23432340
size_t WGSize = std::min(NWorkItems, PrefWGSize);
@@ -2387,8 +2384,8 @@ void reduction_parallel_for(handler &CGH,
23872384
return reduction::strategy::range_basic;
23882385
}();
23892386

2390-
reduction_parallel_for<KernelName, StrategyToUse>(
2391-
CGH, Queue, NDRange, Properties, Redu, UpdatedKernelFunc);
2387+
reduction_parallel_for<KernelName, StrategyToUse>(CGH, NDRange, Properties,
2388+
Redu, UpdatedKernelFunc);
23922389
}
23932390
} // namespace detail
23942391

sycl/include/sycl/reduction_forward.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,15 @@ template <typename KernelName,
4848
reduction::strategy Strategy = reduction::strategy::auto_select,
4949
int Dims, typename PropertiesT, typename KernelType,
5050
typename Reduction>
51-
void reduction_parallel_for(handler &CGH,
52-
std::shared_ptr<detail::queue_impl> Queue,
53-
range<Dims> Range, PropertiesT Properties,
54-
Reduction Redu, KernelType KernelFunc);
51+
void reduction_parallel_for(handler &CGH, range<Dims> Range,
52+
PropertiesT Properties, Reduction Redu,
53+
KernelType KernelFunc);
5554

5655
template <typename KernelName,
5756
reduction::strategy Strategy = reduction::strategy::auto_select,
5857
int Dims, typename PropertiesT, typename... RestT>
59-
void reduction_parallel_for(handler &CGH,
60-
std::shared_ptr<detail::queue_impl> Queue,
61-
nd_range<Dims> NDRange, PropertiesT Properties,
62-
RestT... Rest);
58+
void reduction_parallel_for(handler &CGH, nd_range<Dims> NDRange,
59+
PropertiesT Properties, RestT... Rest);
6360

6461
template <typename T> struct IsReduction;
6562
template <typename FirstT, typename... RestT> struct AreAllButLastReductions;

0 commit comments

Comments
 (0)