14
14
namespace urinfo {
15
15
struct app {
16
16
bool verbose = false ;
17
+ bool linear_ids = true ;
18
+ bool ignore_device_selector = false ;
17
19
ur_loader_config_handle_t loaderConfig = nullptr ;
18
20
std::vector<ur_adapter_handle_t > adapters;
19
21
std::unordered_map<ur_adapter_handle_t , std::vector<ur_platform_handle_t >>
@@ -23,6 +25,16 @@ struct app {
23
25
24
26
app (int argc, const char **argv) {
25
27
parseArgs (argc, argv);
28
+ if (!ignore_device_selector) {
29
+ if (auto device_selector = std::getenv (" ONEAPI_DEVICE_SELECTOR" )) {
30
+ std::fprintf (stderr,
31
+ " info: Output filtered by ONEAPI_DEVICE_SELECTOR "
32
+ " environment variable, which is set to \" %s\" .\n "
33
+ " To see all devices, use the "
34
+ " --ignore-device-selector CLI option.\n\n " ,
35
+ device_selector);
36
+ }
37
+ }
26
38
UR_CHECK (urLoaderConfigCreate (&loaderConfig));
27
39
UR_CHECK (urLoaderConfigEnableLayer (loaderConfig,
28
40
" UR_LAYER_FULL_VALIDATION" ));
@@ -40,6 +52,10 @@ devices which are currently visible in the local execution environment.
40
52
-h, --help show this help message and exit
41
53
--version show version number and exit
42
54
-v, --verbose print additional information
55
+ --no-linear-ids do not show linear device ids
56
+ --ignore-device-selector
57
+ do not use ONEAPI_DEVICE_SELECTOR to filter list of
58
+ devices
43
59
)" ;
44
60
for (int argi = 1 ; argi < argc; argi++) {
45
61
std::string_view arg{argv[argi]};
@@ -51,6 +67,10 @@ devices which are currently visible in the local execution environment.
51
67
std::exit (0 );
52
68
} else if (arg == " -v" || arg == " --verbose" ) {
53
69
verbose = true ;
70
+ } else if (arg == " --no-linear-ids" ) {
71
+ linear_ids = false ;
72
+ } else if (arg == " --ignore-device-selector" ) {
73
+ ignore_device_selector = true ;
54
74
} else {
55
75
std::fprintf (stderr, " error: invalid argument: %s\n " ,
56
76
argv[argi]);
@@ -65,21 +85,21 @@ devices which are currently visible in the local execution environment.
65
85
uint32_t numAdapters = 0 ;
66
86
UR_CHECK (urAdapterGet (0 , nullptr , &numAdapters));
67
87
if (numAdapters == 0 ) {
68
- std::cout << " No adapters found.\n " ;
69
88
std::exit (0 );
70
89
}
71
90
adapters.resize (numAdapters);
72
91
UR_CHECK (urAdapterGet (numAdapters, adapters.data (), nullptr ));
73
92
93
+ auto urDeviceGetFn =
94
+ ignore_device_selector ? urDeviceGet : urDeviceGetSelected;
95
+
74
96
for (size_t adapterIndex = 0 ; adapterIndex < adapters.size ();
75
97
adapterIndex++) {
76
98
auto adapter = adapters[adapterIndex];
77
99
// Enumerate platforms
78
100
uint32_t numPlatforms = 0 ;
79
101
UR_CHECK (urPlatformGet (&adapter, 1 , 0 , nullptr , &numPlatforms));
80
102
if (numPlatforms == 0 ) {
81
- std::cout << " No platforms found in adapter " << adapterIndex
82
- << " .\n " ;
83
103
continue ;
84
104
}
85
105
adapterPlatformsMap[adapter].resize (numPlatforms);
@@ -92,17 +112,15 @@ devices which are currently visible in the local execution environment.
92
112
auto platform = adapterPlatformsMap[adapter][platformIndex];
93
113
// Enumerate devices
94
114
uint32_t numDevices = 0 ;
95
- UR_CHECK (urDeviceGet (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr ,
96
- &numDevices));
115
+ UR_CHECK (urDeviceGetFn (platform, UR_DEVICE_TYPE_ALL, 0 , nullptr ,
116
+ &numDevices));
97
117
if (numDevices == 0 ) {
98
- std::cout << " No devices found platform " << platformIndex
99
- << " .\n " ;
100
118
continue ;
101
119
}
102
120
platformDevicesMap[platform].resize (numDevices);
103
- UR_CHECK (urDeviceGet (platform, UR_DEVICE_TYPE_ALL, numDevices,
104
- platformDevicesMap[platform].data (),
105
- nullptr ));
121
+ UR_CHECK (urDeviceGetFn (platform, UR_DEVICE_TYPE_ALL, numDevices,
122
+ platformDevicesMap[platform].data (),
123
+ nullptr ));
106
124
}
107
125
}
108
126
}
@@ -112,23 +130,37 @@ devices which are currently visible in the local execution environment.
112
130
adapterIndex++) {
113
131
auto adapter = adapters[adapterIndex];
114
132
auto &platforms = adapterPlatformsMap[adapter];
133
+ size_t adapter_device_id = 0 ;
134
+ std::string adapter_backend = urinfo::getAdapterBackend (adapter);
115
135
for (size_t platformIndex = 0 ; platformIndex < platforms.size ();
116
136
platformIndex++) {
117
137
auto platform = platforms[platformIndex];
118
138
auto &devices = platformDevicesMap[platform];
119
139
for (size_t deviceIndex = 0 ; deviceIndex < devices.size ();
120
140
deviceIndex++) {
121
141
auto device = devices[deviceIndex];
122
- std::cout << " [adapter(" << adapterIndex << " ,"
123
- << urinfo::getAdapterBackend (adapter) << " ):"
124
- << " platform(" << platformIndex << " ):"
125
- << " device(" << deviceIndex << " ,"
126
- << urinfo::getDeviceType (device) << " )] "
127
- << urinfo::getPlatformName (platform) << " , "
128
- << urinfo::getDeviceName (device) << " "
142
+ auto device_type = urinfo::getDeviceType (device);
143
+
144
+ if (linear_ids) {
145
+ std::cout << " [" << adapter_backend << " :"
146
+ << device_type << " ]" ;
147
+ std::cout << " [" << adapter_backend << " :"
148
+ << adapter_device_id << " ]" ;
149
+ } else {
150
+ std::cout << " [adapter(" << adapterIndex << " ,"
151
+ << adapter_backend << " ):"
152
+ << " platform(" << platformIndex << " ):"
153
+ << " device(" << deviceIndex << " ,"
154
+ << device_type << " )]" ;
155
+ }
156
+
157
+ std::cout << " " << urinfo::getPlatformName (platform)
158
+ << " , " << urinfo::getDeviceName (device) << " "
129
159
<< urinfo::getDeviceVersion (device) << " "
130
160
<< " [" << urinfo::getDeviceDriverVersion (device)
131
161
<< " ]\n " ;
162
+
163
+ adapter_device_id++;
132
164
}
133
165
}
134
166
}
0 commit comments