Skip to content

Commit 9fcb4c6

Browse files
authored
[SYCL][Doc] Non semantic changes to sycl_ext_oneapi_private_alloca (#12908)
- Rename some C++ names used in the text for clarification - Minor rephrasing - Add example creating a `sycl::span` out of the returned pointer --------- Signed-off-by: Victor Perez <[email protected]>
1 parent acce3b7 commit 9fcb4c6

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

sycl/doc/extensions/experimental/sycl_ext_oneapi_private_alloca.asciidoc

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,29 +120,29 @@ using the `private_alloca` API defined in the following sections.
120120
[source,c++]
121121
----
122122
namespace sycl::ext::oneapi::experimental {
123-
template <typename ElementType, auto &SpecName,
123+
template <typename ElementType, auto &SizeSpecName,
124124
access::decorated DecorateAddress>
125125
private_ptr<ElementType, DecorateAddress>
126126
private_alloca(kernel_handler &kh);
127127
128-
template <typename ElementType, std::size_t Alignment, auto &SpecName,
128+
template <typename ElementType, std::size_t Alignment, auto &SizeSpecName,
129129
access::decorated DecorateAddress>
130130
private_ptr<ElementType, DecorateAddress>
131131
aligned_private_alloca(kernel_handler &kh);
132132
} // namespace sycl::ext::oneapi::experimental
133133
----
134134

135-
_Mandates_: `ElementType` must be a cv-unqualified trivial type and `SpecName`
136-
must be a reference to a specialization constant of integral `value_type`. In
137-
the case of `aligned_private_alloca`, `Alignment` must be an alignment value and
138-
must be a positive multiple of `alignof(ElementType)`. If `Alignment` is an
139-
extended alignment, it must be supported by the implementation.
135+
_Mandates_: `ElementType` must be a cv-unqualified trivial type and
136+
`SizeSpecName` must be a reference to a specialization constant of integral
137+
type. In the case of `aligned_private_alloca`, `Alignment` must be an alignment
138+
value and must be a positive multiple of `alignof(ElementType)`. If `Alignment`
139+
is an extended alignment, it must be supported by the implementation.
140140

141-
_Effects_: `h.get_specialization_constant<size>()` elements of type
141+
_Effects_: `kh.get_specialization_constant<SizeSpecName>()` elements of type
142142
`ElementType` are allocated and default initialized in private memory.
143143

144144
_Returns_: A pointer to a default initialized region of private memory of
145-
`h.get_specialization_constant<size>()` elements of type
145+
`kh.get_specialization_constant<SizeSpecName>()` elements of type
146146
`ElementType`. `DecorateAddress` defines whether the returned `multi_ptr` is
147147
decorated. In the case of `private_alloca`, the pointer is suitably aligned for
148148
an object of type `ElementType`. In the case of `aligned_private_alloca`, the
@@ -151,7 +151,7 @@ pointer is aligned to the specified `Alignment`.
151151
_Remarks_: In case of private memory exhaustion, the implementation must report
152152
an error in the same fashion as if the allocation size were static. In case of a
153153
successful call, allocated memory has automatic storage duration. Additionally,
154-
`SpecName` must have a default value of at least 1 and not be set to a value
154+
`SizeSpecName` must have a default value of at least 1 and not be set to a value
155155
less than 1 during program execution. Violation of these conditions results in
156156
undefined behaviour.
157157

@@ -213,6 +213,35 @@ void run(queue q, const float *in, float *out, size_t n) {
213213
});
214214
----
215215

216+
=== Usage with `sycl::span`
217+
218+
In this section, we show an example of how users could use this extension with
219+
`sycl::span` as a `std::array` replacement:
220+
221+
[source,c++]
222+
----
223+
constexpr specialization_id<std::size_t> size(1);
224+
225+
class Kernel;
226+
227+
// Counterpart to 'impl' in the first example using 'sycl::span'
228+
SYCL_EXTERNAL void impl(const float *in, float *out,
229+
sycl::span<float> ptr);
230+
231+
void run(queue q, const float *in, float *out, size_t n) {
232+
q.submit([&](handler &h) {
233+
h.set_specialization_constant<size>(n);
234+
h.parallel_for<Kernel>(n, [=](id<1> i, kernel_handler kh) {
235+
// Create sycl::span with the returned pointer and the specialization
236+
// constant used as size.
237+
sycl::span<float> tmp{
238+
private_alloca<float, size, access::decorated::no>(kh).get_raw(),
239+
kh.get_specialization_constant<size>()};
240+
impl(in, out, tmp);
241+
});
242+
});
243+
----
244+
216245
== Design constraints
217246

218247
The big design constraint stems from the unknown allocation size at compile

0 commit comments

Comments
 (0)