Skip to content

Commit 4443eff

Browse files
authored
[SYCL] List unsupported platforms in sycl-ls verbose mode (#15166)
The runtime is able to recognised [banned platforms](https://intel.github.io/llvm-docs/doxygen/namespacesycl_1_1__V1_1_1detail.html#af47bb6df075ff6aa60fc6855d59f6fe6), this patch provides a way to list them using `sycl-ls`' `verbose` switch.
1 parent 603dcd6 commit 4443eff

File tree

8 files changed

+148
-58
lines changed

8 files changed

+148
-58
lines changed

sycl/include/sycl/platform.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase<platform> {
194194
/// \return a vector of all available SYCL platforms.
195195
static std::vector<platform> get_platforms();
196196

197+
/// Returns all unsupported (non-SYCL) platforms in the system.
198+
///
199+
/// \return a vector of all unsupported non-SYCL platforms.
200+
static std::vector<platform> get_unsupported_platforms();
201+
197202
/// Returns the backend associated with this platform.
198203
///
199204
/// \return the backend associated with this platform

sycl/source/detail/platform_impl.cpp

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,40 +96,69 @@ static bool IsBannedPlatform(platform Platform) {
9696
IsMatchingOpenCL(Platform, "AMD Accelerated Parallel Processing");
9797
}
9898

99-
// This routine has the side effect of registering each platform's last device
100-
// id into each plugin, which is used for device counting.
101-
std::vector<platform> platform_impl::get_platforms() {
99+
// Get the vector of platforms supported by a given UR plugin
100+
// replace uses of this with a helper in plugin object, the plugin
101+
// objects will own the ur adapter handles and they'll need to pass them to
102+
// urPlatformsGet - so urPlatformsGet will need to be wrapped with a helper
103+
std::vector<platform> platform_impl::getPluginPlatforms(PluginPtr &Plugin,
104+
bool Supported) {
105+
std::vector<platform> Platforms;
102106

103-
// Get the vector of platforms supported by a given UR plugin
104-
// replace uses of this with with a helper in plugin object, the plugin
105-
// objects will own the ur adapter handles and they'll need to pass them to
106-
// urPlatformsGet - so urPlatformsGet will need to be wrapped with a helper
107-
auto getPluginPlatforms = [](PluginPtr &Plugin) {
108-
std::vector<platform> Platforms;
107+
auto UrPlatforms = Plugin->getUrPlatforms();
109108

110-
auto UrPlatforms = Plugin->getUrPlatforms();
109+
if (UrPlatforms.empty()) {
110+
return Platforms;
111+
}
111112

112-
if (UrPlatforms.empty()) {
113-
return Platforms;
114-
}
113+
for (const auto &UrPlatform : UrPlatforms) {
114+
platform Platform = detail::createSyclObjFromImpl<platform>(
115+
getOrMakePlatformImpl(UrPlatform, Plugin));
116+
const bool IsBanned = IsBannedPlatform(Platform);
117+
const bool HasAnyDevices =
118+
!Platform.get_devices(info::device_type::all).empty();
115119

116-
for (const auto &UrPlatform : UrPlatforms) {
117-
platform Platform = detail::createSyclObjFromImpl<platform>(
118-
getOrMakePlatformImpl(UrPlatform, Plugin));
119-
if (IsBannedPlatform(Platform)) {
120+
if (!Supported) {
121+
if (IsBanned || !HasAnyDevices) {
122+
Platforms.push_back(Platform);
123+
}
124+
} else {
125+
if (IsBanned) {
120126
continue; // bail as early as possible, otherwise banned platforms may
121127
// mess up device counting
122128
}
123129

124130
// The SYCL spec says that a platform has one or more devices. ( SYCL
125131
// 2020 4.6.2 ) If we have an empty platform, we don't report it back
126132
// from platform::get_platforms().
127-
if (!Platform.get_devices(info::device_type::all).empty()) {
133+
if (HasAnyDevices) {
128134
Platforms.push_back(Platform);
129135
}
130136
}
131-
return Platforms;
132-
};
137+
}
138+
return Platforms;
139+
}
140+
141+
std::vector<platform> platform_impl::get_unsupported_platforms() {
142+
std::vector<platform> UnsupportedPlatforms;
143+
144+
std::vector<PluginPtr> &Plugins = sycl::detail::ur::initializeUr();
145+
// Ignore UR as it has to be supported.
146+
for (auto &Plugin : Plugins) {
147+
if (Plugin->hasBackend(backend::all)) {
148+
continue; // skip UR
149+
}
150+
std::vector<platform> PluginPlatforms =
151+
getPluginPlatforms(Plugin, /*Supported=*/false);
152+
std::copy(PluginPlatforms.begin(), PluginPlatforms.end(),
153+
std::back_inserter(UnsupportedPlatforms));
154+
}
155+
156+
return UnsupportedPlatforms;
157+
}
158+
159+
// This routine has the side effect of registering each platform's last device
160+
// id into each plugin, which is used for device counting.
161+
std::vector<platform> platform_impl::get_platforms() {
133162

134163
// See which platform we want to be served by which plugin.
135164
// There should be just one plugin serving each backend.

sycl/source/detail/platform_impl.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ class platform_impl {
122122
/// \return a vector of all available SYCL platforms.
123123
static std::vector<platform> get_platforms();
124124

125+
/// Returns all unsupported (non-SYCL) platforms in the system.
126+
///
127+
/// \return a vector of all unsupported (non-SYCL) platforms.
128+
static std::vector<platform> get_unsupported_platforms();
129+
125130
// \return the Plugin associated with this platform.
126131
const PluginPtr &getPlugin() const { return MPlugin; }
127132

@@ -200,6 +205,10 @@ class platform_impl {
200205
private:
201206
std::shared_ptr<device_impl> getDeviceImplHelper(ur_device_handle_t UrDevice);
202207

208+
// Helper to get the vector of platforms supported by a given UR plugin
209+
static std::vector<platform> getPluginPlatforms(PluginPtr &Plugin,
210+
bool Supported = true);
211+
203212
// Helper to filter reportable devices in the platform
204213
template <typename ListT, typename FilterT>
205214
std::vector<int>

sycl/source/platform.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ std::vector<platform> platform::get_platforms() {
5252
return detail::platform_impl::get_platforms();
5353
}
5454

55+
std::vector<platform> platform::get_unsupported_platforms() {
56+
return detail::platform_impl::get_unsupported_platforms();
57+
}
58+
5559
backend platform::get_backend() const noexcept { return impl->getBackend(); }
5660

5761
template <typename Param>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// REQUIRES: cuda
2+
3+
// RUN: sycl-ls --verbose >%t.cuda.out
4+
// RUN: FileCheck %s --input-file %t.cuda.out
5+
6+
//==---- sycl-ls-banned.cpp - Check sycl-ls output of banned platforms. --==//
7+
//
8+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
9+
// See https://llvm.org/LICENSE.txt for license information.
10+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
// CHECK: Unsupported Platforms:
15+
// CHECK-NEXT: Platform [#1]:
16+
// CHECK-NEXT: Version : OpenCL

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3544,6 +3544,7 @@ _ZN4sycl3_V17samplerC1EP11_cl_samplerRKNS0_7contextE
35443544
_ZN4sycl3_V17samplerC2ENS0_29coordinate_normalization_modeENS0_15addressing_modeENS0_14filtering_modeERKNS0_13property_listE
35453545
_ZN4sycl3_V17samplerC2EP11_cl_samplerRKNS0_7contextE
35463546
_ZN4sycl3_V18platform13get_platformsEv
3547+
_ZN4sycl3_V18platform25get_unsupported_platformsEv
35473548
_ZN4sycl3_V18platformC1EP15_cl_platform_id
35483549
_ZN4sycl3_V18platformC1ERKNS0_15device_selectorE
35493550
_ZN4sycl3_V18platformC1ERKNS0_6deviceE

sycl/test/abi/sycl_symbols_windows.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4032,6 +4032,7 @@
40324032
?get_platform@context@_V1@sycl@@QEBA?AVplatform@23@XZ
40334033
?get_platform@device@_V1@sycl@@QEBA?AVplatform@23@XZ
40344034
?get_platforms@platform@_V1@sycl@@SA?AV?$vector@Vplatform@_V1@sycl@@V?$allocator@Vplatform@_V1@sycl@@@std@@@std@@XZ
4035+
?get_unsupported_platforms@platform@_V1@sycl@@SA?AV?$vector@Vplatform@_V1@sycl@@V?$allocator@Vplatform@_V1@sycl@@@std@@@std@@XZ
40354036
?get_pointer_device@_V1@sycl@@YA?AVdevice@12@PEBXAEBVcontext@12@@Z
40364037
?get_pointer_type@_V1@sycl@@YA?AW4alloc@usm@12@PEBXAEBVcontext@12@@Z
40374038
?get_precision@stream@_V1@sycl@@QEBA_KXZ

sycl/tools/sycl-ls/sycl-ls.cpp

Lines changed: 63 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
// verbose (enabled with --verbose).
1515
//
1616
// In verbose mode it also prints, which devices would be chosen by various SYCL
17-
// device selectors.
17+
// device selectors. If the system has unsupported platforms (for instance
18+
// CUDA's OpenCL) those will also be listed in verbose mode, under "Unsupported
19+
// Platforms".
1820
//
1921
#include <sycl/sycl.hpp>
2022

@@ -122,7 +124,8 @@ std::array<int, 2> GetNumberOfSubAndSubSubDevices(const device &Device) {
122124
}
123125

124126
static void printDeviceInfo(const device &Device, bool Verbose,
125-
const std::string &Prepend) {
127+
const std::string &Prepend,
128+
bool IsUnsupported = false) {
126129
auto DeviceVersion = Device.get_info<info::device::version>();
127130
auto DeviceName = Device.get_info<info::device::name>();
128131
auto DeviceVendor = Device.get_info<info::device::vendor>();
@@ -157,19 +160,23 @@ static void printDeviceInfo(const device &Device, bool Verbose,
157160
<< std::endl;
158161
}
159162

160-
std::cout << Prepend << "Aspects :";
163+
// We don't expect to find info on aspects, device's sub-group size or
164+
// architecture on non supported devices.
165+
if (!IsUnsupported) {
166+
std::cout << Prepend << "Aspects :";
161167
#define __SYCL_ASPECT(ASPECT, ID) \
162168
if (Device.has(aspect::ASPECT)) \
163169
std::cout << " " << #ASPECT;
164170
#include <sycl/info/aspects.def>
165-
std::cout << std::endl;
166-
auto sg_sizes = Device.get_info<info::device::sub_group_sizes>();
167-
std::cout << Prepend << "info::device::sub_group_sizes:";
168-
for (auto size : sg_sizes)
169-
std::cout << " " << size;
170-
std::cout << std::endl;
171-
std::cout << Prepend << "Architecture: " << getArchName(Device)
172-
<< std::endl;
171+
std::cout << std::endl;
172+
auto sg_sizes = Device.get_info<info::device::sub_group_sizes>();
173+
std::cout << Prepend << "info::device::sub_group_sizes:";
174+
for (auto size : sg_sizes)
175+
std::cout << " " << size;
176+
std::cout << std::endl;
177+
std::cout << Prepend << "Architecture: " << getArchName(Device)
178+
<< std::endl;
179+
}
173180
} else {
174181
std::cout << Prepend << ", " << DeviceName << " " << DeviceVersion << " ["
175182
<< DeviceDriverVersion << "]" << std::endl;
@@ -201,8 +208,11 @@ static int printUsageAndExit() {
201208
<< std::endl;
202209
std::cout << "\n Options:" << std::endl;
203210
std::cout
204-
<< "\t --verbose " << "\t Verbosely prints all the discovered platforms. "
205-
<< "It also lists the device chosen by various SYCL device selectors."
211+
<< "\t --verbose "
212+
<< "\t Verbosely prints all the discovered platforms. "
213+
<< "It also lists the device chosen by various SYCL device "
214+
"selectors. If the system contains unsupported platforms, those will "
215+
"also be listed in verbose mode, under \"Unsupported Platforms\"."
206216
<< std::endl;
207217
std::cout
208218
<< "\t --ignore-device-selectors "
@@ -317,6 +327,38 @@ static int unsetFilterEnvVarsAndFork() {
317327
}
318328
#endif
319329

330+
// NOTE: This function can update DeviceNums.
331+
static void printVerbosePlatformInfo(const std::vector<platform> &Platforms,
332+
std::map<backend, size_t> &DeviceNums,
333+
const bool SuppressNumberPrinting,
334+
bool IsUnsupported = false) {
335+
uint32_t PlatformNum = 0;
336+
if (!SuppressNumberPrinting)
337+
DeviceNums.clear();
338+
for (const auto &Platform : Platforms) {
339+
backend Backend = Platform.get_backend();
340+
++PlatformNum;
341+
auto PlatformVersion = Platform.get_info<info::platform::version>();
342+
auto PlatformName = Platform.get_info<info::platform::name>();
343+
auto PlatformVendor = Platform.get_info<info::platform::vendor>();
344+
std::cout << "Platform [#" << PlatformNum << "]:" << std::endl;
345+
std::cout << " Version : " << PlatformVersion << std::endl;
346+
std::cout << " Name : " << PlatformName << std::endl;
347+
std::cout << " Vendor : " << PlatformVendor << std::endl;
348+
349+
const auto &Devices = Platform.get_devices();
350+
std::cout << " Devices : " << Devices.size() << std::endl;
351+
for (const auto &Device : Devices) {
352+
if (!SuppressNumberPrinting) {
353+
std::cout << " Device [#" << DeviceNums[Backend]
354+
<< "]:" << std::endl;
355+
++DeviceNums[Backend];
356+
}
357+
printDeviceInfo(Device, true, " ", IsUnsupported);
358+
}
359+
}
360+
}
361+
320362
int main(int argc, char **argv) {
321363

322364
if (argc == 1) {
@@ -386,31 +428,14 @@ int main(int argc, char **argv) {
386428

387429
if (verbose) {
388430
std::cout << "\nPlatforms: " << Platforms.size() << std::endl;
389-
uint32_t PlatformNum = 0;
390-
if (!SuppressNumberPrinting)
391-
DeviceNums.clear();
392-
for (const auto &Platform : Platforms) {
393-
backend Backend = Platform.get_backend();
394-
++PlatformNum;
395-
auto PlatformVersion = Platform.get_info<info::platform::version>();
396-
auto PlatformName = Platform.get_info<info::platform::name>();
397-
auto PlatformVendor = Platform.get_info<info::platform::vendor>();
398-
std::cout << "Platform [#" << PlatformNum << "]:" << std::endl;
399-
std::cout << " Version : " << PlatformVersion << std::endl;
400-
std::cout << " Name : " << PlatformName << std::endl;
401-
std::cout << " Vendor : " << PlatformVendor << std::endl;
402-
403-
const auto &Devices = Platform.get_devices();
404-
std::cout << " Devices : " << Devices.size() << std::endl;
405-
for (const auto &Device : Devices) {
406-
if (!SuppressNumberPrinting) {
407-
std::cout << " Device [#" << DeviceNums[Backend]
408-
<< "]:" << std::endl;
409-
++DeviceNums[Backend];
410-
}
411-
printDeviceInfo(Device, true, " ");
412-
}
413-
}
431+
printVerbosePlatformInfo(Platforms, DeviceNums, SuppressNumberPrinting);
432+
433+
const auto &UnsupportedPlatforms = platform::get_unsupported_platforms();
434+
std::cout << "\nUnsupported Platforms: " << UnsupportedPlatforms.size()
435+
<< std::endl;
436+
printVerbosePlatformInfo(UnsupportedPlatforms, DeviceNums,
437+
SuppressNumberPrinting, true);
438+
std::cout << std::endl;
414439
} else {
415440
return EXIT_SUCCESS;
416441
}

0 commit comments

Comments
 (0)