Skip to content

Commit 2db1a4f

Browse files
authored
Initial support for ext_oneapi_composite_device. (#12178)
Initial implementation to support `sycl_ext_oneapi_composite_device` specified in #11846. Depends on oneapi-src/unified-runtime#1192. --------- Signed-off-by: Maronas, Marcos <[email protected]> Signed-off-by: Marcos Maronas <[email protected]>
1 parent 34ec82d commit 2db1a4f

22 files changed

+566
-9
lines changed

llvm/include/llvm/SYCLLowerIR/DeviceConfigFile.td

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def AspectExt_oneapi_fixed_size_group : Aspect<"ext_oneapi_fixed_size_group">;
6767
def AspectExt_oneapi_opportunistic_group : Aspect<"ext_oneapi_opportunistic_group">;
6868
def AspectExt_oneapi_tangle_group : Aspect<"ext_oneapi_tangle_group">;
6969
def AspectExt_intel_matrix : Aspect<"ext_intel_matrix">;
70+
def AspectExt_oneapi_is_composite : Aspect<"ext_oneapi_is_composite">;
71+
def AspectExt_oneapi_is_component : Aspect<"ext_oneapi_is_component">;
7072
// Deprecated aspects
7173
def AspectInt64_base_atomics : Aspect<"int64_base_atomics">;
7274
def AspectInt64_extended_atomics : Aspect<"int64_extended_atomics">;
@@ -116,7 +118,8 @@ def : TargetInfo<"__TestAspectList",
116118
AspectExt_oneapi_interop_memory_import, AspectExt_oneapi_interop_memory_export,
117119
AspectExt_oneapi_interop_semaphore_import, AspectExt_oneapi_interop_semaphore_export,
118120
AspectExt_oneapi_mipmap, AspectExt_oneapi_mipmap_anisotropy, AspectExt_oneapi_mipmap_level_reference, AspectExt_intel_esimd,
119-
AspectExt_oneapi_ballot_group, AspectExt_oneapi_fixed_size_group, AspectExt_oneapi_opportunistic_group, AspectExt_oneapi_tangle_group, AspectExt_intel_matrix],
121+
AspectExt_oneapi_ballot_group, AspectExt_oneapi_fixed_size_group, AspectExt_oneapi_opportunistic_group,
122+
AspectExt_oneapi_tangle_group, AspectExt_intel_matrix, AspectExt_oneapi_is_composite, AspectExt_oneapi_is_component],
120123
[]>;
121124
// This definition serves the only purpose of testing whether the deprecated aspect list defined in here and in SYCL RT
122125
// match.

sycl/doc/extensions/proposed/sycl_ext_oneapi_composite_device.asciidoc renamed to sycl/doc/extensions/experimental/sycl_ext_oneapi_composite_device.asciidoc

+6-5
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ SYCL specification refer to that revision.
4343

4444
== Status
4545

46-
This is a proposed extension specification, intended to gather community
47-
feedback. Interfaces defined in this specification may not be implemented yet
48-
or may be in a preliminary state. The specification itself may also change in
49-
incompatible ways before it is finalized. *Shipping software products should
50-
not rely on APIs defined in this specification.*
46+
This is an experimental extension specification, intended to provide early
47+
access to features and gather community feedback. Interfaces defined in this
48+
specification are implemented in {dpcpp}, but they are not finalized and may
49+
change incompatibly in future versions of {dpcpp} without prior notice.
50+
*Shipping software products should not rely on APIs defined in this
51+
specification.*
5152

5253

5354
== Backend support status

sycl/include/sycl/detail/pi.h

+4
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,10 @@ typedef enum {
437437
PI_EXT_ONEAPI_DEVICE_INFO_INTEROP_SEMAPHORE_EXPORT_SUPPORT = 0x2010F,
438438

439439
PI_EXT_ONEAPI_DEVICE_INFO_MATRIX_COMBINATIONS = 0x20110,
440+
441+
// Composite device
442+
PI_EXT_ONEAPI_DEVICE_INFO_COMPONENT_DEVICES = 0x20111,
443+
PI_EXT_ONEAPI_DEVICE_INFO_COMPOSITE_DEVICE = 0x20112,
440444
} _pi_device_info;
441445

442446
typedef enum {

sycl/include/sycl/device_aspect_macros.hpp

+20
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,16 @@
303303
#define __SYCL_ALL_DEVICES_HAVE_ext_intel_matrix__ 0
304304
#endif
305305

306+
#ifndef __SYCL_ALL_DEVICES_HAVE_ext_oneapi_is_composite__
307+
// __SYCL_ASPECT(ext_oneapi_is_composite, 59)
308+
#define __SYCL_ALL_DEVICES_HAVE_ext_oneapi_is_composite__ 0
309+
#endif
310+
311+
#ifndef __SYCL_ALL_DEVICES_HAVE_ext_oneapi_is_component__
312+
// __SYCL_ASPECT(ext_oneapi_is_component, 60)
313+
#define __SYCL_ALL_DEVICES_HAVE_ext_oneapi_is_component__ 0
314+
#endif
315+
306316
#ifndef __SYCL_ANY_DEVICE_HAS_host__
307317
// __SYCL_ASPECT(host, 0)
308318
#define __SYCL_ANY_DEVICE_HAS_host__ 0
@@ -597,3 +607,13 @@
597607
// __SYCL_ASPECT(ext_intel_matrix, 58)
598608
#define __SYCL_ANY_DEVICE_HAS_ext_intel_matrix__ 0
599609
#endif
610+
611+
#ifndef __SYCL_ANY_DEVICE_HAS_ext_oneapi_is_composite__
612+
// __SYCL_ASPECT(ext_oneapi_is_composite, 59)
613+
#define __SYCL_ANY_DEVICE_HAS_ext_oneapi_is_composite__ 0
614+
#endif
615+
616+
#ifndef __SYCL_ANY_DEVICE_HAS_ext_oneapi_is_component__
617+
// __SYCL_ASPECT(ext_oneapi_is_component, 60)
618+
#define __SYCL_ANY_DEVICE_HAS_ext_oneapi_is_component__ 0
619+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//==---------- composite_device.hpp - SYCL Composite Device ----------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <sycl/device.hpp>
12+
13+
#include <vector>
14+
15+
namespace sycl {
16+
inline namespace _V1 {
17+
namespace ext::oneapi::experimental {
18+
__SYCL_EXPORT std::vector<device> get_composite_devices();
19+
} // namespace ext::oneapi::experimental
20+
} // namespace _V1
21+
} // namespace sycl

sycl/include/sycl/info/aspects.def

+2
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ __SYCL_ASPECT(ext_oneapi_fixed_size_group, 55)
5353
__SYCL_ASPECT(ext_oneapi_opportunistic_group, 56)
5454
__SYCL_ASPECT(ext_oneapi_tangle_group, 57)
5555
__SYCL_ASPECT(ext_intel_matrix, 58)
56+
__SYCL_ASPECT(ext_oneapi_is_composite, 59)
57+
__SYCL_ASPECT(ext_oneapi_is_component, 60)

sycl/include/sycl/info/ext_oneapi_device_traits.def

+9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ __SYCL_PARAM_TRAITS_SPEC(ext::oneapi::experimental, device,
3636
__SYCL_PARAM_TRAITS_SPEC(ext::oneapi::experimental, device,
3737
mipmap_max_anisotropy, float,
3838
PI_EXT_ONEAPI_DEVICE_INFO_MIPMAP_MAX_ANISOTROPY)
39+
40+
// Composite devices
41+
__SYCL_PARAM_TRAITS_SPEC(ext::oneapi::experimental, device,
42+
component_devices, std::vector<sycl::device>,
43+
PI_EXT_ONEAPI_DEVICE_INFO_COMPONENT_DEVICES)
44+
__SYCL_PARAM_TRAITS_SPEC(ext::oneapi::experimental, device,
45+
composite_device, sycl::device,
46+
PI_EXT_ONEAPI_DEVICE_INFO_COMPOSITE_DEVICE)
47+
3948
#ifdef __SYCL_PARAM_TRAITS_TEMPLATE_SPEC_NEEDS_UNDEF
4049
#undef __SYCL_PARAM_TRAITS_TEMPLATE_SPEC
4150
#undef __SYCL_PARAM_TRAITS_TEMPLATE_SPEC_NEEDS_UNDEF

sycl/include/sycl/platform.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase<platform> {
188188
/// \return the default context
189189
context ext_oneapi_get_default_context() const;
190190

191+
std::vector<device> ext_oneapi_get_composite_devices() const;
192+
191193
private:
192194
pi_native_handle getNative() const;
193195

sycl/include/sycl/sycl.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#include <sycl/ext/oneapi/experimental/ballot_group.hpp>
8686
#include <sycl/ext/oneapi/experimental/bfloat16_math.hpp>
8787
#include <sycl/ext/oneapi/experimental/builtins.hpp>
88+
#include <sycl/ext/oneapi/experimental/composite_device.hpp>
8889
#include <sycl/ext/oneapi/experimental/cuda/barrier.hpp>
8990
#include <sycl/ext/oneapi/experimental/fixed_size_group.hpp>
9091
#include <sycl/ext/oneapi/experimental/opportunistic_group.hpp>

sycl/plugins/level_zero/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if (NOT DEFINED LEVEL_ZERO_LIBRARY OR NOT DEFINED LEVEL_ZERO_INCLUDE_DIR)
44
message(STATUS "Download Level Zero loader and headers from github.com")
55

66
set(LEVEL_ZERO_LOADER_REPO "https://github.com/oneapi-src/level-zero.git")
7-
set(LEVEL_ZERO_LOADER_TAG v1.11.0)
7+
set(LEVEL_ZERO_LOADER_TAG v1.15.1)
88

99
# Disable due to a bug https://github.com/oneapi-src/level-zero/issues/104
1010
set(CMAKE_INCLUDE_CURRENT_DIR OFF)

sycl/plugins/unified_runtime/pi2ur.hpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,12 @@ inline pi_result ur2piDeviceInfoValue(ur_device_info_t ParamName,
608608
* No need to convert since types are compatible
609609
*/
610610
*ParamValueSizeRet = sizeof(pi_device_fp_config);
611+
} else if (ParamName == UR_DEVICE_INFO_COMPONENT_DEVICES) {
612+
if (ParamValueSizeRet && *ParamValueSizeRet != 0) {
613+
const uint32_t UrNumberElements =
614+
*ParamValueSizeRet / sizeof(ur_device_handle_t);
615+
*ParamValueSizeRet = UrNumberElements * sizeof(pi_device);
616+
}
611617
} else {
612618

613619
// TODO: what else needs a UR-PI translation?
@@ -974,7 +980,6 @@ inline pi_result piDevicesGet(pi_platform Platform, pi_device_type DeviceType,
974980

975981
inline pi_result piDeviceRetain(pi_device Device) {
976982
PI_ASSERT(Device, PI_ERROR_INVALID_DEVICE);
977-
978983
auto UrDevice = reinterpret_cast<ur_device_handle_t>(Device);
979984
HANDLE_ERRORS(urDeviceRetain(UrDevice));
980985
return PI_SUCCESS;
@@ -1008,7 +1013,6 @@ inline pi_result piPluginGetLastError(char **Message) {
10081013
inline pi_result piDeviceGetInfo(pi_device Device, pi_device_info ParamName,
10091014
size_t ParamValueSize, void *ParamValue,
10101015
size_t *ParamValueSizeRet) {
1011-
10121016
ur_device_info_t InfoType;
10131017
switch (ParamName) {
10141018
#define PI_TO_UR_MAP_DEVICE_INFO(FROM, TO) \
@@ -1270,6 +1274,10 @@ inline pi_result piDeviceGetInfo(pi_device Device, pi_device_info ParamName,
12701274
UR_DEVICE_INFO_INTEROP_SEMAPHORE_EXPORT_SUPPORT_EXP)
12711275
PI_TO_UR_MAP_DEVICE_INFO(PI_EXT_INTEL_DEVICE_INFO_ESIMD_SUPPORT,
12721276
UR_DEVICE_INFO_ESIMD_SUPPORT)
1277+
PI_TO_UR_MAP_DEVICE_INFO(PI_EXT_ONEAPI_DEVICE_INFO_COMPONENT_DEVICES,
1278+
UR_DEVICE_INFO_COMPONENT_DEVICES)
1279+
PI_TO_UR_MAP_DEVICE_INFO(PI_EXT_ONEAPI_DEVICE_INFO_COMPOSITE_DEVICE,
1280+
UR_DEVICE_INFO_COMPOSITE_DEVICE)
12731281
#undef PI_TO_UR_MAP_DEVICE_INFO
12741282
default:
12751283
return PI_ERROR_UNKNOWN;

sycl/source/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ set(SYCL_COMMON_SOURCES
171171
"detail/buffer_impl.cpp"
172172
"detail/pi.cpp"
173173
"detail/common.cpp"
174+
"detail/composite_device/composite_device.cpp"
174175
"detail/config.cpp"
175176
"detail/context_impl.cpp"
176177
"detail/device_binary_image.cpp"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//==---------- composite_device.cpp - SYCL Composite Device ----------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <sycl/ext/oneapi/experimental/composite_device.hpp>
10+
#include <sycl/platform.hpp>
11+
12+
#include <unordered_set>
13+
14+
namespace sycl {
15+
inline namespace _V1 {
16+
namespace ext::oneapi::experimental {
17+
std::vector<device> get_composite_devices() {
18+
// We use set to filter out duplicates, and unordered because we don't need it
19+
// to be sorted, and unordered provides faster insertion.
20+
std::unordered_set<device> Composites;
21+
auto Devs = sycl::device::get_devices();
22+
for (const auto &D : Devs) {
23+
if (D.has(sycl::aspect::ext_oneapi_is_component)) {
24+
auto Composite = D.get_info<info::device::composite_device>();
25+
Composites.insert(Composite);
26+
}
27+
}
28+
std::vector<device> Result;
29+
std::copy_if(
30+
Composites.begin(), Composites.end(), std::back_inserter(Result),
31+
[&](const device &Composite) {
32+
auto Components = Composite.get_info<info::device::component_devices>();
33+
// Only return composite devices if all of its component
34+
// devices are available.
35+
return std::all_of(
36+
Components.begin(), Components.end(), [&](const device &d) {
37+
return std::find(Devs.begin(), Devs.end(), d) != Devs.end();
38+
});
39+
});
40+
return Result;
41+
}
42+
} // namespace ext::oneapi::experimental
43+
} // namespace _V1
44+
} // namespace sycl

sycl/source/detail/device_impl.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,26 @@ bool device_impl::has(aspect Aspect) const {
582582
return false;
583583
}
584584
}
585+
case aspect::ext_oneapi_is_composite: {
586+
auto components = get_info<
587+
sycl::ext::oneapi::experimental::info::device::component_devices>();
588+
// Any device with ext_oneapi_is_composite aspect will have at least two
589+
// constituent component devices.
590+
return components.size() >= 2;
591+
}
592+
case aspect::ext_oneapi_is_component: {
593+
if (getBackend() != backend::ext_oneapi_level_zero)
594+
return false;
595+
596+
typename sycl_to_pi<device>::type Result;
597+
getPlugin()->call<PiApiKind::piDeviceGetInfo>(
598+
getHandleRef(),
599+
PiInfoCode<
600+
ext::oneapi::experimental::info::device::composite_device>::value,
601+
sizeof(Result), &Result, nullptr);
602+
603+
return Result != nullptr;
604+
}
585605
}
586606
throw runtime_error("This device aspect has not been implemented yet.",
587607
PI_ERROR_INVALID_DEVICE);

sycl/source/detail/device_info.hpp

+75
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,67 @@ struct get_device_info_impl<
10851085
}
10861086
};
10871087

1088+
// Specialization for composite devices extension.
1089+
template <>
1090+
struct get_device_info_impl<
1091+
std::vector<sycl::device>,
1092+
ext::oneapi::experimental::info::device::component_devices> {
1093+
static std::vector<sycl::device> get(const DeviceImplPtr &Dev) {
1094+
if (Dev->getBackend() != backend::ext_oneapi_level_zero)
1095+
return {};
1096+
size_t ResultSize = 0;
1097+
// First call to get DevCount.
1098+
Dev->getPlugin()->call<PiApiKind::piDeviceGetInfo>(
1099+
Dev->getHandleRef(),
1100+
PiInfoCode<
1101+
ext::oneapi::experimental::info::device::component_devices>::value,
1102+
0, nullptr, &ResultSize);
1103+
size_t DevCount = ResultSize / sizeof(pi_device);
1104+
// Second call to get the list.
1105+
std::vector<pi_device> Devs(DevCount);
1106+
Dev->getPlugin()->call<PiApiKind::piDeviceGetInfo>(
1107+
Dev->getHandleRef(),
1108+
PiInfoCode<
1109+
ext::oneapi::experimental::info::device::component_devices>::value,
1110+
ResultSize, Devs.data(), nullptr);
1111+
std::vector<sycl::device> Result;
1112+
const auto &Platform = Dev->getPlatformImpl();
1113+
for (const auto &d : Devs)
1114+
Result.push_back(createSyclObjFromImpl<device>(
1115+
Platform->getOrMakeDeviceImpl(d, Platform)));
1116+
1117+
return Result;
1118+
}
1119+
};
1120+
template <>
1121+
struct get_device_info_impl<
1122+
sycl::device, ext::oneapi::experimental::info::device::composite_device> {
1123+
static sycl::device get(const DeviceImplPtr &Dev) {
1124+
if (Dev->getBackend() != backend::ext_oneapi_level_zero)
1125+
return {};
1126+
if (!Dev->has(sycl::aspect::ext_oneapi_is_component))
1127+
throw sycl::exception(make_error_code(errc::invalid),
1128+
"Only devices with aspect::ext_oneapi_is_component "
1129+
"can call this function.");
1130+
1131+
typename sycl_to_pi<device>::type Result;
1132+
Dev->getPlugin()->call<PiApiKind::piDeviceGetInfo>(
1133+
Dev->getHandleRef(),
1134+
PiInfoCode<
1135+
ext::oneapi::experimental::info::device::composite_device>::value,
1136+
sizeof(Result), &Result, nullptr);
1137+
1138+
if (Result) {
1139+
const auto &Platform = Dev->getPlatformImpl();
1140+
return createSyclObjFromImpl<device>(
1141+
Platform->getOrMakeDeviceImpl(Result, Platform));
1142+
}
1143+
throw sycl::exception(make_error_code(errc::invalid),
1144+
"A component with aspect::ext_oneapi_is_component "
1145+
"must have a composite device.");
1146+
}
1147+
};
1148+
10881149
template <typename Param>
10891150
typename Param::return_type get_device_info(const DeviceImplPtr &Dev) {
10901151
static_assert(is_device_info_desc<Param>::value,
@@ -2041,6 +2102,20 @@ inline float get_device_info_host<
20412102
PI_ERROR_INVALID_DEVICE);
20422103
}
20432104

2105+
template <>
2106+
inline std::vector<sycl::device> get_device_info_host<
2107+
ext::oneapi::experimental::info::device::component_devices>() {
2108+
throw runtime_error("Host devices cannot be component devices.",
2109+
PI_ERROR_INVALID_DEVICE);
2110+
}
2111+
2112+
template <>
2113+
inline sycl::device get_device_info_host<
2114+
ext::oneapi::experimental::info::device::composite_device>() {
2115+
throw runtime_error("Host devices cannot be composite devices.",
2116+
PI_ERROR_INVALID_DEVICE);
2117+
}
2118+
20442119
} // namespace detail
20452120
} // namespace _V1
20462121
} // namespace sycl

sycl/source/feature_test.hpp.in

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ inline namespace _V1 {
5555
#define SYCL_EXT_ONEAPI_PROPERTIES 1
5656
#define SYCL_EXT_ONEAPI_NATIVE_MATH 1
5757
#define SYCL_EXT_ONEAPI_BFLOAT16_MATH_FUNCTIONS 1
58+
#define SYCL_EXT_ONEAPI_COMPOSITE_DEVICE 1
5859
#define SYCL_EXT_INTEL_DATAFLOW_PIPES 1
5960
#ifdef __clang__
6061
#if __has_extension(sycl_extended_atomics)

0 commit comments

Comments
 (0)