Skip to content

Commit 653af67

Browse files
authored
[SYCL][DOC] Add an overload for memory_required in joint_sorter (#11727)
From the implementation perspective it's important to have `memory_required` in `default_sorters` dependent on the SYCL device. It happens because `default_sorters` has no specified algorithm inside it can depend on the specific SYCL device. `radix_sorters` has specific algorithm (radix sorter) that doesn't depend on the backend. Removed `constexpr` for default sorters since it's extra there. It's still fine for radix sorters since the algorithm is fixed and can't depend on the backend Signed-off-by: Fedorov, Andrey <[email protected]> --------- Signed-off-by: Fedorov, Andrey <[email protected]>
1 parent 774a662 commit 653af67

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

sycl/doc/extensions/proposed/sycl_ext_oneapi_group_sort.asciidoc

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,8 @@ namespace sycl::ext::oneapi::experimental {
514514
void operator()(Group g, Ptr first, Ptr last); // (2)
515515
516516
template<typename T>
517-
static constexpr size_t
518-
memory_required(sycl::memory_scope scope, std::size_t range_size); // (3)
517+
static size_t
518+
memory_required(sycl::device d, sycl::memory_scope scope, std::size_t range_size); // (3)
519519
};
520520
521521
template<typename T,
@@ -534,8 +534,8 @@ namespace sycl::ext::oneapi::experimental {
534534
sycl::span<T, ElementsPerWorkItem> values,
535535
Properties properties); // (6)
536536
537-
static constexpr size_t
538-
memory_required(sycl::memory_scope scope, std::size_t range_size); // (7)
537+
static size_t
538+
memory_required(sycl::device d, sycl::memory_scope scope, std::size_t range_size); // (7)
539539
};
540540
541541
template<typename T,
@@ -557,8 +557,8 @@ namespace sycl::ext::oneapi::experimental {
557557
sycl::span<U, ElementsPerWorkItem> values,
558558
Properties property); // (10)
559559
560-
static constexpr std::size_t
561-
memory_required(sycl::memory_scope scope, std::size_t range_size); // (11)
560+
static std::size_t
561+
memory_required(sycl::device d, sycl::memory_scope scope, std::size_t range_size); // (11)
562562
};
563563
}
564564
@@ -671,9 +671,11 @@ the `joint_sort` algorithm.
671671
_Complexity_: Let `N` be `last - first`. `O(N*log(N)*log(N))` comparisons.
672672

673673
(3) Returns size of temporary memory (in bytes) that is required by
674-
the default sorting algorithm defined by the sorter calling by `joint_sort`.
674+
the default sorting algorithm defined by the sorter calling by `joint_sort`
675+
depending on `d`.
675676
`range_size` represents a range size for sorting,
676677
e.g. `last-first` from `operator()` arguments.
678+
It mustn't be called within a SYCL kernel, only on host.
677679
Result depends on the `scope` parameter:
678680
use `sycl::memory_scope::work_group` to get memory size required
679681
for each work-group;
@@ -694,9 +696,11 @@ _Complexity_: Let `N` be the `Group` size multiplied by `ElementsPerWorkItem`.
694696
`O(N*log(N)*log(N))` comparisons.
695697

696698
(7) Returns the size of temporary memory (in bytes) that is required by the default
697-
sorting algorithm defined by the sorter calling by `sort_over_group`.
699+
sorting algorithm defined by the sorter calling by `sort_over_group`
700+
depending on `d`.
698701
`ElementsPerWorkItem` is the extent parameter for `sycl::span`
699702
that is an input parameter for `sort_over_group`.
703+
It mustn't be called within a SYCL kernel, only on host.
700704
If `scope == sycl::memory_scope::work_group`,
701705
`range_size` is the size of the local range for `sycl::nd_range`
702706
that was used to run the kernel;
@@ -719,7 +723,9 @@ _Complexity_: Let `N` be the `Group` size multiplied by `ElementsPerWorkItem`.
719723

720724
(11) Returns size of temporary memory (in bytes) that is required by
721725
the default key-value
722-
sorting algorithm defined by the sorter calling by `sort_key_value_over_group`.
726+
sorting algorithm defined by the sorter calling by `sort_key_value_over_group`
727+
depending on `d`.
728+
It mustn't be called within a SYCL kernel, only on host.
723729
If `scope == sycl::memory_scope::work_group`,
724730
`range_size` is the size of the local range for `sycl::nd_range`
725731
that was used to run the kernel;
@@ -998,7 +1004,7 @@ namespace my_sycl = sycl::ext::oneapi::experimental;
9981004
// calculate required local memory size
9991005
size_t temp_memory_size =
10001006
my_sycl::default_sorters::joint_sorter<>::memory_required<T>(
1001-
sycl::memory_scope::work_group, n);
1007+
d, sycl::memory_scope::work_group, n);
10021008
10031009
q.submit([&](sycl::handler& h) {
10041010
auto acc = sycl::accessor(buf, h);
@@ -1075,7 +1081,7 @@ using TupleType =
10751081
// calculate required local memory size
10761082
size_t temp_memory_size =
10771083
my_sycl::default_sorters::joint_sorter<>::memory_required<TupleType>(
1078-
sycl::memory_scope::work_group, n);
1084+
d, sycl::memory_scope::work_group, n);
10791085
10801086
q.submit([&](sycl::handler& h) {
10811087
auto keys_acc = sycl::accessor(keys_buf, h);
@@ -1185,8 +1191,6 @@ because it's easy to pass different comparator types.
11851191
. Think about reducing overloads for sorting functions. The thing is that
11861192
overloads with `Compare` objects seems extra and overloads with sorters,
11871193
without sorters are enough.
1188-
. It would be better if `memory_required` methods had a `sycl::device` parameter
1189-
because different devices can require different amount of memory.
11901194

11911195
== Non-implemented features
11921196
Please, note that following is not inplemented yet for the open-source repo:
@@ -1206,4 +1210,5 @@ Please, note that following is not inplemented yet for the open-source repo:
12061210
|3|2021-12-16|Andrey Fedorov|Some refactoring, sections reordering,
12071211
making the entire extension experimental
12081212
|4|2022-11-14|Andrey Fedorov|Fixed size arrays, key-value sorting and properties
1213+
|5|2023-11-09|Andrey Fedorov|Changed `memory_required` functions for default sorters
12091214
|========================================

0 commit comments

Comments
 (0)