1
- // ==----------- lspi .cpp --- ------------------------------------------------==//
1
+ // ==----------- sycl-ls .cpp ------------------------------------------------==//
2
2
//
3
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
4
// See https://llvm.org/LICENSE.txt for license information.
5
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
8
//
9
- // The "lspi" utility lists all platforms/devices discovered by PI similar to
10
- // how lscl prints this for OpenCL devices. It can probably be eventually merged
11
- // with the more complex "check-sycl" utility.
9
+ // The "sycl-ls" utility lists all platforms/devices discovered by PI similar to
10
+ // how lscl prints this for OpenCL devices.
12
11
//
13
12
// There are two types of output:
14
13
// concise (default) and
15
- // verbose (enabled with any argument ).
14
+ // verbose (enabled with --verbose ).
16
15
//
17
- // In verbose mode it also prints, which devices would be chose by various SYCL
16
+ // In verbose mode it also prints, which devices would be chosen by various SYCL
18
17
// device selectors.
19
18
//
20
19
#include < CL/sycl.hpp>
24
23
#include < stdlib.h>
25
24
26
25
using namespace cl ::sycl;
27
- using namespace std ;
28
26
29
27
// Controls verbose output vs. concise.
30
- bool verbose = false ;
28
+ bool verbose;
31
29
32
30
// Trivial custom selector that selects a device of the given type.
33
31
class custom_selector : public device_selector {
@@ -40,9 +38,9 @@ class custom_selector : public device_selector {
40
38
}
41
39
};
42
40
43
- static void printDeviceInfo (const device &Device, const string &Prepend) {
41
+ static void printDeviceInfo (const device &Device, const std:: string &Prepend) {
44
42
auto DeviceType = Device.get_info <info::device::device_type>();
45
- string DeviceTypeName;
43
+ std:: string DeviceTypeName;
46
44
switch (DeviceType) {
47
45
case info::device_type::cpu:
48
46
DeviceTypeName = " CPU " ;
@@ -57,7 +55,7 @@ static void printDeviceInfo(const device &Device, const string &Prepend) {
57
55
DeviceTypeName = " ACC " ;
58
56
break ;
59
57
default :
60
- DeviceTypeName = " ??? " ;
58
+ DeviceTypeName = " UNKNOWN " ;
61
59
break ;
62
60
}
63
61
@@ -67,14 +65,14 @@ static void printDeviceInfo(const device &Device, const string &Prepend) {
67
65
auto DeviceDriverVersion = Device.get_info <info::device::driver_version>();
68
66
69
67
if (verbose) {
70
- cout << Prepend << " Type : " << DeviceTypeName << std::endl;
71
- cout << Prepend << " Version : " << DeviceVersion << std::endl;
72
- cout << Prepend << " Name : " << DeviceName << std::endl;
73
- cout << Prepend << " Vendor : " << DeviceVendor << std::endl;
74
- cout << Prepend << " Driver : " << DeviceDriverVersion << std::endl;
68
+ std:: cout << Prepend << " Type : " << DeviceTypeName << std::endl;
69
+ std:: cout << Prepend << " Version : " << DeviceVersion << std::endl;
70
+ std:: cout << Prepend << " Name : " << DeviceName << std::endl;
71
+ std:: cout << Prepend << " Vendor : " << DeviceVendor << std::endl;
72
+ std:: cout << Prepend << " Driver : " << DeviceDriverVersion << std::endl;
75
73
} else {
76
- cout << Prepend << DeviceTypeName << " : " << DeviceVersion << " [ "
77
- << DeviceDriverVersion << " ]" << std::endl;
74
+ std:: cout << Prepend << DeviceTypeName << " : " << DeviceVersion << " [ "
75
+ << DeviceDriverVersion << " ]" << std::endl;
78
76
}
79
77
}
80
78
@@ -89,33 +87,25 @@ static void printSelectorChoice(const device_selector &Selector,
89
87
std::string What = Exception.what ();
90
88
if (What.length () > 50 )
91
89
What = What.substr (0 , 50 ) + " ..." ;
92
-
93
- if (verbose) {
94
- cout << Prepend << " Type : " << What << std::endl;
95
- cout << Prepend << " Version : " << What << std::endl;
96
- cout << Prepend << " Name : " << What << std::endl;
97
- cout << Prepend << " Vendor : " << What << std::endl;
98
- cout << Prepend << " Driver : " << What << std::endl;
99
- } else {
100
- cout << Prepend << What << std::endl;
101
- }
90
+ std::cout << Prepend << What << std::endl;
102
91
}
103
92
}
104
93
105
94
int main (int argc, char **argv) {
106
95
107
- // Any options trigger verbose output.
108
- if (argc > 1 ) {
96
+ // See if verbose output is requested
97
+ if (argc == 1 )
98
+ verbose = false ;
99
+ else if (argc == 2 && std::string (argv[1 ]) == " --verbose" )
109
100
verbose = true ;
110
- if (!std::getenv (" SYCL_PI_TRACE" )) {
111
- // Enable trace of PI discovery.
112
- // setenv("SYCL_PI_TRACE", "1", true);
113
- }
101
+ else {
102
+ std::cout << " Usage: sycl-ls [--verbose]" << std::endl;
103
+ return -1 ;
114
104
}
115
105
116
106
auto Platforms = platform::get_platforms ();
117
107
if (verbose)
118
- cout << " Platforms: " << Platforms.size () << std::endl;
108
+ std:: cout << " Platforms: " << Platforms.size () << std::endl;
119
109
120
110
uint32_t PlatformNum = 0 ;
121
111
for (const auto &Platform : Platforms) {
@@ -124,19 +114,19 @@ int main(int argc, char **argv) {
124
114
auto PlatformVersion = Platform.get_info <info::platform::version>();
125
115
auto PlatformName = Platform.get_info <info::platform::name>();
126
116
auto PlatformVendor = Platform.get_info <info::platform::vendor>();
127
- cout << " Platform [#" << PlatformNum << " ]:" << std::endl;
128
- cout << " Version : " << PlatformVersion << std::endl;
129
- cout << " Name : " << PlatformName << std::endl;
130
- cout << " Vendor : " << PlatformVendor << std::endl;
117
+ std:: cout << " Platform [#" << PlatformNum << " ]:" << std::endl;
118
+ std:: cout << " Version : " << PlatformVersion << std::endl;
119
+ std:: cout << " Name : " << PlatformName << std::endl;
120
+ std:: cout << " Vendor : " << PlatformVendor << std::endl;
131
121
}
132
122
auto Devices = Platform.get_devices ();
133
123
if (verbose)
134
- cout << " Devices : " << Devices.size () << std::endl;
124
+ std:: cout << " Devices : " << Devices.size () << std::endl;
135
125
uint32_t DeviceNum = 0 ;
136
126
for (const auto &Device : Devices) {
137
127
++DeviceNum;
138
128
if (verbose)
139
- cout << " Device [#" << DeviceNum << " ]:" << std::endl;
129
+ std:: cout << " Device [#" << DeviceNum << " ]:" << std::endl;
140
130
printDeviceInfo (Device, verbose ? " " : " " );
141
131
}
142
132
}
0 commit comments