Skip to content

Commit 7869c17

Browse files
author
Andrew Lamzed-Short
authored
[SYCL] Add device::get_info<info::device::aspects> specialisation (#7937)
Specialised function to get a vector of the complete list of supported aspects for the current device, as per [Table 25 of the spec](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#_device_information_descriptors). Initial implementation uses the list of aspects, inserts them into an initial vector with a macro, and tests each using the existing `::has()` functionality, removing them form the list if not applicable, returning only what is supported on the device. Thought this would reduce code duplication and could reuse the aspect definition list file. If this isn't appropriate, please do suggest alternatives. The current test works but if it needs further development, do let me know.
1 parent 8759d07 commit 7869c17

File tree

10 files changed

+79
-2
lines changed

10 files changed

+79
-2
lines changed

sycl/include/sycl/detail/info_desc_helpers.hpp

Lines changed: 1 addition & 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.hpp>
1213
#include <sycl/info/info_desc.hpp>
1314

sycl/include/sycl/device.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class device_impl;
3535
auto getDeviceComparisonLambda();
3636
} // namespace detail
3737

38+
enum class aspect;
39+
3840
namespace ext::oneapi {
3941
// Forward declaration
4042
class filter_selector;

sycl/include/sycl/info/device_traits.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ __SYCL_PARAM_TRAITS_SPEC(device, partition_type_affinity_domain,
167167
// Has custom specialization.
168168
__SYCL_PARAM_TRAITS_SPEC_SPECIALIZED(device, parent_device, sycl::device,
169169
PI_DEVICE_INFO_PARENT_DEVICE)
170+
__SYCL_PARAM_TRAITS_SPEC_SPECIALIZED(device, aspects, std::vector<sycl::aspect>, 0)
170171

171172
// Extensions/deprecated
172173
__SYCL_PARAM_TRAITS_SPEC(device, atomic64, bool, PI_DEVICE_INFO_ATOMIC_64)

sycl/include/sycl/info/device_traits_deprecated.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ __SYCL_PARAM_TRAITS_DEPRECATED(is_linker_available, "deprecated in SYCL 2020, us
1212
__SYCL_PARAM_TRAITS_DEPRECATED(queue_profiling, "deprecated in SYCL 2020, use device::has(aspect::queue_profiling) instead")
1313
__SYCL_PARAM_TRAITS_DEPRECATED(built_in_kernels,"deprecated in SYCL 2020, use info::device::built_in_kernel_ids instead")
1414
__SYCL_PARAM_TRAITS_DEPRECATED(profile,"deprecated in SYCL 2020")
15-
// TODO Despite giving this deprecation warning, we're still yet to implement
16-
// info::device::aspects.
1715
__SYCL_PARAM_TRAITS_DEPRECATED(extensions,"deprecated in SYCL 2020, use info::device::aspects instead")
1816
__SYCL_PARAM_TRAITS_DEPRECATED(printf_buffer_size,"deprecated in SYCL 2020")
1917
__SYCL_PARAM_TRAITS_DEPRECATED(preferred_interop_user_sync,"deprecated in SYCL 2020")

sycl/include/sycl/info/info_desc.hpp

Lines changed: 1 addition & 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/common.hpp>
1213
#include <sycl/detail/pi.hpp>
1314
#include <sycl/id.hpp>

sycl/source/device.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <sycl/device_selector.hpp>
1616
#include <sycl/info/info_desc.hpp>
1717

18+
#include <algorithm>
19+
1820
namespace sycl {
1921
__SYCL_INLINE_VER_NAMESPACE(_V1) {
2022
namespace detail {
@@ -150,6 +152,31 @@ __SYCL_EXPORT device device::get_info<info::device::parent_device>() const {
150152
return impl->template get_info<info::device::parent_device>();
151153
}
152154

155+
template <>
156+
__SYCL_EXPORT std::vector<sycl::aspect>
157+
device::get_info<info::device::aspects>() const {
158+
std::vector<sycl::aspect> DeviceAspects{
159+
#define __SYCL_ASPECT(ASPECT, ID) aspect::ASPECT,
160+
#include <sycl/info/aspects.def>
161+
#undef __SYCL_ASPECT
162+
};
163+
164+
auto UnsupportedAspects = std::remove_if(
165+
DeviceAspects.begin(), DeviceAspects.end(), [&](aspect Aspect) {
166+
try {
167+
return !impl->has(Aspect);
168+
} catch (const runtime_error &ex) {
169+
if (ex.get_cl_code() == PI_ERROR_INVALID_DEVICE)
170+
return true;
171+
throw;
172+
}
173+
});
174+
175+
DeviceAspects.erase(UnsupportedAspects, DeviceAspects.end());
176+
177+
return DeviceAspects;
178+
}
179+
153180
#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
154181
template __SYCL_EXPORT ReturnT device::get_info<info::device::Desc>() const;
155182

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4323,6 +4323,7 @@ _ZNK4sycl3_V16device8get_infoINS0_4info6device7versionEEENS0_6detail19is_device_
43234323
_ZNK4sycl3_V16device8get_infoINS0_4info6device8atomic64EEENS0_6detail19is_device_info_descIT_E11return_typeEv
43244324
_ZNK4sycl3_V16device8get_infoINS0_4info6device8platformEEENS0_6detail19is_device_info_descIT_E11return_typeEv
43254325
_ZNK4sycl3_V16device8get_infoINS0_4info6device9vendor_idEEENS0_6detail19is_device_info_descIT_E11return_typeEv
4326+
_ZNK4sycl3_V16device8get_infoINS0_4info6device7aspectsEEENS0_6detail19is_device_info_descIT_E11return_typeEv
43264327
_ZNK4sycl3_V16device9getNativeEv
43274328
_ZNK4sycl3_V16kernel11get_backendEv
43284329
_ZNK4sycl3_V16kernel11get_contextEv

sycl/test/abi/sycl_symbols_windows.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
??$get_info@Uversion@device@info@_V1@sycl@@@device@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ
174174
??$get_info@Uversion@platform@info@_V1@sycl@@@platform@_V1@sycl@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ
175175
??$get_info@Uwork_group_size@kernel_device_specific@info@_V1@sycl@@@kernel@_V1@sycl@@QEBA_KAEBVdevice@12@@Z
176+
??$get_info@Uaspects@device@info@_V1@sycl@@@device@_V1@sycl@@QEBA?AV?$vector@W4aspect@_V1@sycl@@V?$allocator@W4aspect@_V1@sycl@@@std@@@std@@XZ
176177
??$get_profiling_info@Ucommand_end@event_profiling@info@_V1@sycl@@@event@_V1@sycl@@QEBA_KXZ
177178
??$get_profiling_info@Ucommand_start@event_profiling@info@_V1@sycl@@@event@_V1@sycl@@QEBA_KXZ
178179
??$get_profiling_info@Ucommand_submit@event_profiling@info@_V1@sycl@@@event@_V1@sycl@@QEBA_KXZ

sycl/unittests/SYCL2020/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ add_sycl_unittest(SYCL2020Tests OBJECT
77
KernelID.cpp
88
HasExtension.cpp
99
IsCompatible.cpp
10+
DeviceGetInfoAspects.cpp
1011
)
1112

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//==----- DeviceGetInfoAspects.cpp --- info::device::aspects unit test -----==//
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/sycl.hpp>
10+
11+
#include <helpers/PiImage.hpp>
12+
#include <helpers/PiMock.hpp>
13+
14+
#include <gtest/gtest.h>
15+
16+
#include <algorithm>
17+
18+
using namespace sycl;
19+
20+
static bool containsAspect(const std::vector<sycl::aspect> &DeviceAspects,
21+
const aspect Aspect) {
22+
return std::find(DeviceAspects.begin(), DeviceAspects.end(), Aspect) !=
23+
DeviceAspects.end();
24+
}
25+
26+
TEST(DeviceGetInfo, SupportedDeviceAspects) {
27+
sycl::unittest::PiMock Mock;
28+
29+
sycl::platform Plt = Mock.getPlatform();
30+
sycl::device Dev = Plt.get_devices()[0];
31+
32+
std::vector<sycl::aspect> DeviceAspects =
33+
Dev.get_info<info::device::aspects>();
34+
35+
// Tests to examine aspects of default mock device, as defined in
36+
// helpers/PiMockPlugin.hpp so these tests all need to be kept in sync with
37+
// changes to that file.
38+
EXPECT_TRUE(containsAspect(DeviceAspects, aspect::gpu));
39+
EXPECT_TRUE(containsAspect(DeviceAspects, aspect::fp16));
40+
EXPECT_TRUE(containsAspect(DeviceAspects, aspect::fp64));
41+
42+
EXPECT_FALSE(containsAspect(DeviceAspects, aspect::host));
43+
EXPECT_FALSE(containsAspect(DeviceAspects, aspect::cpu));
44+
}

0 commit comments

Comments
 (0)