Skip to content

Commit de92299

Browse files
JackAKirkgmlueck
andauthored
[SYCL] Added ext_oneapi_non_uniform_groups aspect (#10902)
The errors that you get if you try to e.g. create a `ballot_group` in e.g. HIP backend are not instructive. This PR introduces `ext_oneapi_non_uniform_groups` and uses the `[[__sycl_detail__::__uses_aspects__(aspect::foo)]]` annotations detailed in: https://github.com/intel/llvm/blob/sycl/sycl/doc/design/OptionalDeviceFeatures.md#changes-to-dpc-headers to give a clear runtime error in the case that a programmer tries to execute a kernel that uses non-uniform groups on a device that does not supported the non-uniform group extension. --------- Signed-off-by: Jack Kirk <[email protected]> Co-authored-by: Greg Lueck <[email protected]>
1 parent a691817 commit de92299

File tree

10 files changed

+75
-11
lines changed

10 files changed

+75
-11
lines changed

llvm/include/llvm/SYCLLowerIR/DeviceConfigFile.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def AspectExt_oneapi_mipmap : Aspect<"ext_oneapi_mipmap">;
6262
def AspectExt_oneapi_mipmap_anisotropy : Aspect<"ext_oneapi_mipmap_anisotropy">;
6363
def AspectExt_oneapi_mipmap_level_reference : Aspect<"ext_oneapi_mipmap_level_reference">;
6464
def AspectExt_intel_esimd : Aspect<"ext_intel_esimd">;
65+
def AspectExt_oneapi_non_uniform_groups : Aspect<"ext_oneapi_non_uniform_groups">;
6566
// Deprecated aspects
6667
def AspectInt64_base_atomics : Aspect<"int64_base_atomics">;
6768
def AspectInt64_extended_atomics : Aspect<"int64_extended_atomics">;
@@ -110,7 +111,7 @@ def : TargetInfo<"__TestAspectList",
110111
AspectExt_oneapi_bindless_images_shared_usm, AspectExt_oneapi_bindless_images_1d_usm, AspectExt_oneapi_bindless_images_2d_usm,
111112
AspectExt_oneapi_interop_memory_import, AspectExt_oneapi_interop_memory_export,
112113
AspectExt_oneapi_interop_semaphore_import, AspectExt_oneapi_interop_semaphore_export,
113-
AspectExt_oneapi_mipmap, AspectExt_oneapi_mipmap_anisotropy, AspectExt_oneapi_mipmap_level_reference, AspectExt_intel_esimd],
114+
AspectExt_oneapi_mipmap, AspectExt_oneapi_mipmap_anisotropy, AspectExt_oneapi_mipmap_level_reference, AspectExt_intel_esimd, AspectExt_oneapi_non_uniform_groups],
114115
[]>;
115116
// This definition serves the only purpose of testing whether the deprecated aspect list defined in here and in SYCL RT
116117
// match.

sycl/doc/extensions/proposed/sycl_ext_oneapi_non_uniform_groups.asciidoc

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,10 @@ https://github.com/intel/llvm/issues
3737

3838
== Dependencies
3939

40-
This extension is written against the SYCL 2020 revision 6 specification. All
40+
This extension is written against the SYCL 2020 revision 7 specification. All
4141
references below to the "core SYCL specification" or to section numbers in the
4242
SYCL specification refer to that revision.
4343

44-
This extension also depends on the following other SYCL extensions:
45-
46-
* link:https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_root_group.asciidoc[sycl_ext_oneapi_root_group]
47-
4844

4945
== Status
5046

@@ -55,6 +51,15 @@ incompatible ways before it is finalized. *Shipping software products should
5551
not rely on APIs defined in this specification.*
5652

5753

54+
== Backend support status
55+
56+
The APIs in this extension may be used only on a device that has
57+
`aspect::ext_oneapi_non_uniform_groups`. The application must check that the
58+
device has this aspect before submitting a kernel using any of the APIs in this
59+
extension. If the application fails to do this, the implementation throws a
60+
synchronous exception with the `errc::kernel_not_supported` error code when the
61+
kernel is submitted to the queue.
62+
5863
== Overview
5964

6065
Many modern hardware architectures support flexible sub-divisions of
@@ -73,8 +78,9 @@ needed in function documentation.
7378

7479
NOTE: The first version of this extension only supports partitioning of
7580
sub-groups. It is expected that in the future, these functions will be expanded
76-
to also allow partitioning of root-groups, work-groups and user-constructed
77-
groups.
81+
to also allow partitioning of
82+
link:https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_root_group.asciidoc[root-groups],
83+
work-groups and user-constructed groups.
7884

7985

8086
== Specification
@@ -99,6 +105,21 @@ implementation supports.
99105
feature-test macro always has this value.
100106
|===
101107

108+
=== Extension to `enum class aspect`
109+
110+
[source]
111+
----
112+
namespace sycl {
113+
enum class aspect {
114+
...
115+
ext_oneapi_non_uniform_groups
116+
}
117+
}
118+
----
119+
120+
If a SYCL device has the `ext_oneapi_non_uniform_groups` aspect,
121+
then it supports the non-uniform groups described in the next sections.
122+
102123
=== Control Flow
103124

104125
The SYCL specification defines
@@ -130,7 +151,7 @@ model topology used by SYCL kernels. These groups are implicitly created by an
130151
implementation when a SYCL kernel function is enqueued. The following group
131152
types are fixed topology groups:
132153

133-
- `root_group` (if sycl_ext_oneapi_root_group is supported)
154+
- `root_group` (if link:https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_root_group.asciidoc[sycl_ext_oneapi_root_group] is supported)
134155
- `group`
135156
- `sub_group`
136157

sycl/include/sycl/device_aspect_macros.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@
278278
#define __SYCL_ALL_DEVICES_HAVE_ext_intel_esimd__ 0
279279
#endif
280280

281+
#ifndef __SYCL_ALL_DEVICES_HAVE_ext_oneapi_non_uniform_groups__
282+
// __SYCL_ASPECT(ext_oneapi_non_uniform_groups, 54)
283+
#define __SYCL_ALL_DEVICES_HAVE_ext_oneapi_non_uniform_groups__ 0
284+
#endif
285+
281286
#ifndef __SYCL_ANY_DEVICE_HAS_host__
282287
// __SYCL_ASPECT(host, 0)
283288
#define __SYCL_ANY_DEVICE_HAS_host__ 0
@@ -547,3 +552,8 @@
547552
//__SYCL_ASPECT(ext_intel_esimd, 53)
548553
#define __SYCL_ANY_DEVICE_HAS_ext_intel_esimd__ 0
549554
#endif
555+
556+
#ifndef __SYCL_ANY_DEVICE_HAS_ext_oneapi_non_uniform_groups__
557+
// __SYCL_ASPECT(ext_oneapi_non_uniform_groups, 54)
558+
#define __SYCL_ANY_DEVICE_HAS_ext_oneapi_non_uniform_groups__ 0
559+
#endif

sycl/include/sycl/ext/oneapi/experimental/ballot_group.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#pragma once
1010

11+
#include <sycl/aspects.hpp>
1112
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_DEVICE
1213
#include <sycl/detail/type_traits.hpp> // for is_group, is_user_cons...
1314
#include <sycl/exception.hpp> // for runtime_error
@@ -27,6 +28,10 @@ namespace ext::oneapi::experimental {
2728
template <typename ParentGroup> class ballot_group;
2829

2930
template <typename Group>
31+
#ifdef __SYCL_DEVICE_ONLY__
32+
[[__sycl_detail__::__uses_aspects__(
33+
sycl::aspect::ext_oneapi_non_uniform_groups)]]
34+
#endif
3035
inline std::enable_if_t<sycl::is_group_v<std::decay_t<Group>> &&
3136
std::is_same_v<Group, sycl::sub_group>,
3237
ballot_group<Group>>
@@ -142,6 +147,7 @@ inline std::enable_if_t<sycl::is_group_v<std::decay_t<Group>> &&
142147
get_ballot_group(Group group, bool predicate) {
143148
(void)group;
144149
#ifdef __SYCL_DEVICE_ONLY__
150+
#if defined(__SPIR__) || defined(__NVPTX__)
145151
// ballot_group partitions into two groups using the predicate
146152
// Membership mask for one group is negation of the other
147153
sub_group_mask mask = sycl::ext::oneapi::group_ballot(group, predicate);
@@ -150,6 +156,7 @@ get_ballot_group(Group group, bool predicate) {
150156
} else {
151157
return ballot_group<sycl::sub_group>(~mask, predicate);
152158
}
159+
#endif
153160
#else
154161
(void)predicate;
155162
throw runtime_error("Non-uniform groups are not supported on host device.",

sycl/include/sycl/ext/oneapi/experimental/fixed_size_group.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#pragma once
1010

11+
#include <sycl/aspects.hpp>
1112
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_DEVICE
1213
#include <sycl/detail/type_traits.hpp> // for is_fixed_size_group, is_group
1314
#include <sycl/exception.hpp> // for runtime_error
@@ -27,6 +28,10 @@ namespace ext::oneapi::experimental {
2728
template <size_t PartitionSize, typename ParentGroup> class fixed_size_group;
2829

2930
template <size_t PartitionSize, typename Group>
31+
#ifdef __SYCL_DEVICE_ONLY__
32+
[[__sycl_detail__::__uses_aspects__(
33+
sycl::aspect::ext_oneapi_non_uniform_groups)]]
34+
#endif
3035
inline std::enable_if_t<sycl::is_group_v<std::decay_t<Group>> &&
3136
std::is_same_v<Group, sycl::sub_group>,
3237
fixed_size_group<PartitionSize, Group>>

sycl/include/sycl/ext/oneapi/experimental/opportunistic_group.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#pragma once
1010

11+
#include <sycl/aspects.hpp>
1112
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_DEVICE
1213
#include <sycl/detail/type_traits.hpp> // for is_group, is_user_cons...
1314
#include <sycl/exception.hpp> // for runtime_error
@@ -26,8 +27,13 @@ namespace ext::oneapi::experimental {
2627
class opportunistic_group;
2728

2829
namespace this_kernel {
29-
inline opportunistic_group get_opportunistic_group();
30-
}
30+
#ifdef __SYCL_DEVICE_ONLY__
31+
[[__sycl_detail__::__uses_aspects__(
32+
sycl::aspect::ext_oneapi_non_uniform_groups)]]
33+
#endif
34+
inline opportunistic_group
35+
get_opportunistic_group();
36+
} // namespace this_kernel
3137

3238
class opportunistic_group {
3339
public:

sycl/include/sycl/ext/oneapi/experimental/tangle_group.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#pragma once
1010

11+
#include <sycl/aspects.hpp>
1112
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_DEVICE
1213
#include <sycl/detail/type_traits.hpp> // for is_group, is_user_cons...
1314
#include <sycl/exception.hpp> // for runtime_error
@@ -26,6 +27,10 @@ namespace ext::oneapi::experimental {
2627
template <typename ParentGroup> class tangle_group;
2728

2829
template <typename Group>
30+
#ifdef __SYCL_DEVICE_ONLY__
31+
[[__sycl_detail__::__uses_aspects__(
32+
sycl::aspect::ext_oneapi_non_uniform_groups)]]
33+
#endif
2934
inline std::enable_if_t<sycl::is_group_v<std::decay_t<Group>> &&
3035
std::is_same_v<Group, sycl::sub_group>,
3136
tangle_group<Group>>
@@ -148,6 +153,8 @@ get_tangle_group(Group group) {
148153
return tangle_group<sycl::sub_group>(mask);
149154
#elif defined(__NVPTX__)
150155
// TODO: Construct from compiler-generated mask
156+
static_assert(false,
157+
"tangle_group is not currently supported on this platform.");
151158
#endif
152159
#else
153160
throw runtime_error("Non-uniform groups are not supported on host device.",

sycl/include/sycl/info/aspects.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ __SYCL_ASPECT(ext_oneapi_mipmap, 50)
4848
__SYCL_ASPECT(ext_oneapi_mipmap_anisotropy, 51)
4949
__SYCL_ASPECT(ext_oneapi_mipmap_level_reference, 52)
5050
__SYCL_ASPECT(ext_intel_esimd, 53)
51+
__SYCL_ASPECT(ext_oneapi_non_uniform_groups, 54)

sycl/source/detail/device_impl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,11 @@ bool device_impl::has(aspect Aspect) const {
554554
&support, nullptr) == PI_SUCCESS;
555555
return call_successful && support;
556556
}
557+
case aspect::ext_oneapi_non_uniform_groups: {
558+
return (this->getBackend() == backend::ext_oneapi_level_zero) ||
559+
(this->getBackend() == backend::opencl) ||
560+
(this->getBackend() == backend::ext_oneapi_cuda);
561+
}
557562
}
558563
throw runtime_error("This device aspect has not been implemented yet.",
559564
PI_ERROR_INVALID_DEVICE);

sycl/test-e2e/NonUniformGroups/fixed_size_group.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %{run} %t.out
33

44
// REQUIRES: gpu
5+
// UNSUPPORTED: hip
56
// REQUIRES: sg-32
67

78
#include <sycl/sycl.hpp>

0 commit comments

Comments
 (0)