Skip to content

Commit acfc905

Browse files
authored
[SYCL][DOC] Allow captures in "if_device_has", etc (#8840)
Lift the restrictions in `if_device_has` and `if_architecture_is` disallowing captures in the lamdba expressions. I originally added these restrictions because I thought we could not implement these APIs in the JIT case if they had captures. However, I have an outline for the JIT design now, which will support captures. Since we allow captures now, there isn't any need for the lambdas to accept user-supplied parameters because the user can just capture whatever variables they need. Therefore, this PR also removes support for the parameters.
1 parent 615bed4 commit acfc905

File tree

3 files changed

+34
-39
lines changed

3 files changed

+34
-39
lines changed

sycl/doc/design/DeviceIf.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ listed architectures. The following code snippet illustrates the technique:
207207

208208
```
209209
namespace sycl {
210-
namespace ext::oneapi::exprimental {
210+
namespace ext::oneapi::experimental {
211211
212212
enum class architecture {
213213
x86_64,
@@ -217,7 +217,7 @@ enum class architecture {
217217
// ...
218218
};
219219
220-
} // namespace ext::oneapi::exprimental
220+
} // namespace ext::oneapi::experimental
221221
222222
namespace detail {
223223
@@ -281,44 +281,43 @@ constexpr static bool device_architecture_is() {
281281
template<bool MakeCall>
282282
class if_architecture_helper {
283283
public:
284-
template<ext::oneapi::exprimental::architecture ...Archs, typename T,
285-
typename ...Args>
286-
constexpr auto else_if_architecture_is(T fnTrue, Args ...args) {
284+
template<ext::oneapi::experimental::architecture ...Archs, typename T>
285+
constexpr auto else_if_architecture_is(T fnTrue) {
287286
if constexpr (MakeCall && device_architecture_is<Archs...>()) {
288-
fnTrue(args...);
287+
fnTrue();
289288
return if_architecture_helper<false>{};
290289
} else {
291290
return if_architecture_helper<MakeCall>{};
292291
}
293292
}
294293
295-
template<typename T, typename ...Args>
296-
constexpr void otherwise(T fn, Args ...args) {
294+
template<typename T>
295+
constexpr void otherwise(T fn) {
297296
if constexpr (MakeCall) {
298-
fn(args...);
297+
fn();
299298
}
300299
}
301300
};
302301
303302
} // namespace detail
304303
305-
namespace ext::oneapi::exprimental {
304+
namespace ext::oneapi::experimental {
306305
307-
template<architecture ...Archs, typename T, typename ...Args>
308-
constexpr static auto if_architecture_is(T fnTrue, Args ...args) {
306+
template<architecture ...Archs, typename T>
307+
constexpr static auto if_architecture_is(T fnTrue) {
309308
static_assert(detail::allowable_aot_mode<Archs...>(),
310309
"The if_architecture_is function may only be used when AOT "
311310
"compiling with '-fsycl-targets=spir64_x86_64' or "
312311
"'-fsycl-targets=intel_gpu_*'");
313312
if constexpr (detail::device_architecture_is<Archs...>()) {
314-
fnTrue(args...);
313+
fnTrue();
315314
return detail::if_architecture_helper<false>{};
316315
} else {
317316
return detail::if_architecture_helper<true>{};
318317
}
319318
}
320319
321-
} // namespace ext::oneapi::exprimental
320+
} // namespace ext::oneapi::experimental
322321
} // namespace sycl
323322
```
324323

sycl/doc/extensions/experimental/sycl_ext_oneapi_device_architecture.asciidoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,8 @@ code. This function is not available in host code.
485485
```
486486
namespace sycl::ext::oneapi::experimental {
487487

488-
template<architecture ...Archs, typename ...Args, typename T>
489-
/* unspecified */ if_architecture_is(T fn, Args ...args);
488+
template<architecture ...Archs, typename T>
489+
/* unspecified */ if_architecture_is(T fn);
490490

491491
} // namespace sycl::ext::oneapi::experimental
492492
```
@@ -504,11 +504,11 @@ type, which provides the following member functions:
504504
```
505505
class /* unspecified */ {
506506
public:
507-
template<architecture ...Archs, typename ...Args, typename T>
508-
/* unspecified */ else_if_architecture_is(T fn, Args ...args);
507+
template<architecture ...Archs, typename T>
508+
/* unspecified */ else_if_architecture_is(T fn);
509509

510-
template<typename T, typename ...Args>
511-
void otherwise(T fn, Args ...args);
510+
template<typename T>
511+
void otherwise(T fn);
512512
};
513513
```
514514

sycl/doc/extensions/proposed/sycl_ext_oneapi_device_if.asciidoc

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
== Notice
2121

2222
[%hardbreaks]
23-
Copyright (C) 2021-2022 Intel Corporation. All rights reserved.
23+
Copyright (C) 2021-2023 Intel Corporation. All rights reserved.
2424

2525
Khronos(R) is a registered trademark and SYCL(TM) and SPIR(TM) are trademarks
2626
of The Khronos Group Inc. OpenCL(TM) is a trademark of Apple Inc. used by
@@ -135,20 +135,16 @@ code. This function is not available in host code.
135135
```
136136
namespace sycl::ext::oneapi::experimental {
137137

138-
template<aspect ...Aspects, typename ...Args, typename T>
139-
/* unspecified */ if_device_has(T fn, Args ...args);
138+
template<aspect ...Aspects, typename T>
139+
/* unspecified */ if_device_has(T fn);
140140

141141
} // namespace sycl::ext::oneapi::experimental
142142
```
143143

144-
The parameter `fn` must be a C++ `Callable` object which is invocable with the
145-
parameters specified in `args`. Normal SYCL restrictions apply, so `fn` must
146-
not be a function pointer or a pointer to a member function. (The expectation
147-
is that most applications will pass a lambda expression for this parameter.)
148-
149-
If `fn` is a lambda expression, it must not have any captures. Applications
150-
can work around this limitation by passing variables referenced by the lambda
151-
as function arguments.
144+
The parameter `fn` must be a C++ `Callable` object which is invocable with an
145+
empty parameter list. Normal SYCL restrictions apply, so `fn` must not be a
146+
function pointer or a pointer to a member function. (The expectation is that
147+
most applications will pass a lambda expression for this parameter.)
152148

153149
The `Aspects` parameter pack identifies the condition that gates execution of
154150
the callable object `fn`. This condition is `true` only if the device which
@@ -164,11 +160,11 @@ which provides the following member functions:
164160
```
165161
class /* unspecified */ {
166162
public:
167-
template<aspect ...Aspects, typename ...Args, typename T>
168-
/* unspecified */ else_if_device_has(T fn, Args ...args);
163+
template<aspect ...Aspects, typename T>
164+
/* unspecified */ else_if_device_has(T fn);
169165

170-
template<typename T, typename ...Args>
171-
void otherwise(T fn, Args ...args);
166+
template<typename T>
167+
void otherwise(T fn);
172168
};
173169
```
174170

@@ -214,10 +210,10 @@ void frob() {
214210
As specified above, the function `fn` may be discarded if the condition
215211
associated with the call to `if_device_has`, `else_if_device_has`, or
216212
`otherwise` is `false`. More formally, this means that `fn` is potentially
217-
discarded (if `fn` is a function) or `+operator(Args...)+` of `fn` is
218-
potentially discarded (if `fn` is a callable object). In addition, any other
219-
functions they call (and functions called by those functions etc.) are
220-
potentially discarded.
213+
discarded (if `fn` is a function) or `operator()()` of `fn` is potentially
214+
discarded (if `fn` is a callable object). In addition, any other functions
215+
they call (and functions called by those functions etc.) are potentially
216+
discarded.
221217

222218
These functions are discarded if all calls to them are reachable only from
223219
`if_device_has`, `else_if_device_has`, or `otherwise` whose associated

0 commit comments

Comments
 (0)