Skip to content

Commit 654e556

Browse files
authored
Merge pull request #1389 from kbenzie/benie/urinfo-ods
[urinfo] Use urDeviceGetSelected
2 parents 252a3cc + 198b7c2 commit 654e556

File tree

2 files changed

+68
-40
lines changed

2 files changed

+68
-40
lines changed

source/loader/ur_lib.cpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,6 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
224224
if (!hPlatform) {
225225
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
226226
}
227-
// NumEntries is max number of devices wanted by the caller (max usable length of phDevices)
228-
if (NumEntries < 0) {
229-
return UR_RESULT_ERROR_INVALID_SIZE;
230-
}
231227
if (NumEntries > 0 && !phDevices) {
232228
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
233229
}
@@ -426,8 +422,10 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
426422

427423
for (auto &termPair : mapODS) {
428424
std::string backend = termPair.first;
429-
if (backend
430-
.empty()) { // FIXME: never true because getenv_to_map rejects this case
425+
// TODO: Figure out how to process all ODS errors rather than returning
426+
// on the first error.
427+
if (backend.empty()) {
428+
// FIXME: never true because getenv_to_map rejects this case
431429
// malformed term: missing backend -- output ERROR, then continue
432430
logger::error("ERROR: missing backend, format of filter = "
433431
"'[!]backend:filterStrings'");
@@ -459,20 +457,19 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
459457
std::tolower(static_cast<unsigned char>(b));
460458
})) {
461459
// irrelevant term for current request: different backend -- silently ignore
462-
logger::warning(
463-
"WARNING: ignoring term with irrelevant backend '{}'", backend);
464-
continue;
460+
logger::error("unrecognised backend '{}'", backend);
461+
return UR_RESULT_ERROR_INVALID_VALUE;
465462
}
466463
if (termPair.second.size() == 0) {
467-
// malformed term: missing filterStrings -- output ERROR, then continue
468-
logger::error("ERROR missing filterStrings, format of filter = "
464+
// malformed term: missing filterStrings -- output ERROR
465+
logger::error("missing filterStrings, format of filter = "
469466
"'[!]backend:filterStrings'");
470-
continue;
467+
return UR_RESULT_ERROR_INVALID_VALUE;
471468
}
472469
if (std::find_if(termPair.second.cbegin(), termPair.second.cend(),
473470
[](const auto &s) { return s.empty(); }) !=
474-
termPair.second
475-
.cend()) { // FIXME: never true because getenv_to_map rejects this case
471+
termPair.second.cend()) {
472+
// FIXME: never true because getenv_to_map rejects this case
476473
// malformed term: missing filterString -- output warning, then continue
477474
logger::warning(
478475
"WARNING: empty filterString, format of filterStrings "
@@ -483,10 +480,10 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
483480
[](const auto &s) {
484481
return std::count(s.cbegin(), s.cend(), '.') > 2;
485482
}) != termPair.second.cend()) {
486-
// malformed term: too many dots in filterString -- output warning, then continue
487-
logger::warning("WARNING: too many dots in filterString, format of "
488-
"filterString = 'root[.sub[.subsub]]'");
489-
continue;
483+
// malformed term: too many dots in filterString
484+
logger::error("too many dots in filterString, format of "
485+
"filterString = 'root[.sub[.subsub]]'");
486+
return UR_RESULT_ERROR_INVALID_VALUE;
490487
}
491488
if (std::find_if(
492489
termPair.second.cbegin(), termPair.second.cend(),
@@ -504,10 +501,9 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
504501
}
505502
return false; // no BAD things, so must be okay
506503
}) != termPair.second.cend()) {
507-
// malformed term: star dot no-star in filterString -- output warning, then continue
508-
logger::warning(
509-
"WARNING: invalid wildcard in filterString, '*.' => '*.*'");
510-
continue;
504+
// malformed term: star dot no-star in filterString
505+
logger::error("invalid wildcard in filterString, '*.' => '*.*'");
506+
return UR_RESULT_ERROR_INVALID_VALUE;
511507
}
512508

513509
// TODO -- use regex validation_pattern to catch all other syntax errors in the ODS string
@@ -552,7 +548,7 @@ ur_result_t urDeviceGetSelected(ur_platform_handle_t hPlatform,
552548

553549
if (acceptDeviceList.size() == 0 && discardDeviceList.size() == 0) {
554550
// nothing in env var was understood as a valid term
555-
return UR_RESULT_ERROR_INVALID_VALUE;
551+
return UR_RESULT_SUCCESS;
556552
} else if (acceptDeviceList.size() == 0) {
557553
// no accept terms were understood, but at least one discard term was
558554
// we are magnanimous to the user when there were bad/ignored accept terms

tools/urinfo/urinfo.cpp

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
namespace urinfo {
1515
struct app {
1616
bool verbose = false;
17+
bool linear_ids = true;
18+
bool ignore_device_selector = false;
1719
ur_loader_config_handle_t loaderConfig = nullptr;
1820
std::vector<ur_adapter_handle_t> adapters;
1921
std::unordered_map<ur_adapter_handle_t, std::vector<ur_platform_handle_t>>
@@ -23,6 +25,16 @@ struct app {
2325

2426
app(int argc, const char **argv) {
2527
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+
}
2638
UR_CHECK(urLoaderConfigCreate(&loaderConfig));
2739
UR_CHECK(urLoaderConfigEnableLayer(loaderConfig,
2840
"UR_LAYER_FULL_VALIDATION"));
@@ -40,6 +52,10 @@ devices which are currently visible in the local execution environment.
4052
-h, --help show this help message and exit
4153
--version show version number and exit
4254
-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
4359
)";
4460
for (int argi = 1; argi < argc; argi++) {
4561
std::string_view arg{argv[argi]};
@@ -51,6 +67,10 @@ devices which are currently visible in the local execution environment.
5167
std::exit(0);
5268
} else if (arg == "-v" || arg == "--verbose") {
5369
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;
5474
} else {
5575
std::fprintf(stderr, "error: invalid argument: %s\n",
5676
argv[argi]);
@@ -65,21 +85,21 @@ devices which are currently visible in the local execution environment.
6585
uint32_t numAdapters = 0;
6686
UR_CHECK(urAdapterGet(0, nullptr, &numAdapters));
6787
if (numAdapters == 0) {
68-
std::cout << "No adapters found.\n";
6988
std::exit(0);
7089
}
7190
adapters.resize(numAdapters);
7291
UR_CHECK(urAdapterGet(numAdapters, adapters.data(), nullptr));
7392

93+
auto urDeviceGetFn =
94+
ignore_device_selector ? urDeviceGet : urDeviceGetSelected;
95+
7496
for (size_t adapterIndex = 0; adapterIndex < adapters.size();
7597
adapterIndex++) {
7698
auto adapter = adapters[adapterIndex];
7799
// Enumerate platforms
78100
uint32_t numPlatforms = 0;
79101
UR_CHECK(urPlatformGet(&adapter, 1, 0, nullptr, &numPlatforms));
80102
if (numPlatforms == 0) {
81-
std::cout << "No platforms found in adapter " << adapterIndex
82-
<< ".\n";
83103
continue;
84104
}
85105
adapterPlatformsMap[adapter].resize(numPlatforms);
@@ -92,17 +112,15 @@ devices which are currently visible in the local execution environment.
92112
auto platform = adapterPlatformsMap[adapter][platformIndex];
93113
// Enumerate devices
94114
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));
97117
if (numDevices == 0) {
98-
std::cout << "No devices found platform " << platformIndex
99-
<< ".\n";
100118
continue;
101119
}
102120
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));
106124
}
107125
}
108126
}
@@ -112,23 +130,37 @@ devices which are currently visible in the local execution environment.
112130
adapterIndex++) {
113131
auto adapter = adapters[adapterIndex];
114132
auto &platforms = adapterPlatformsMap[adapter];
133+
size_t adapter_device_id = 0;
134+
std::string adapter_backend = urinfo::getAdapterBackend(adapter);
115135
for (size_t platformIndex = 0; platformIndex < platforms.size();
116136
platformIndex++) {
117137
auto platform = platforms[platformIndex];
118138
auto &devices = platformDevicesMap[platform];
119139
for (size_t deviceIndex = 0; deviceIndex < devices.size();
120140
deviceIndex++) {
121141
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) << " "
129159
<< urinfo::getDeviceVersion(device) << " "
130160
<< "[" << urinfo::getDeviceDriverVersion(device)
131161
<< "]\n";
162+
163+
adapter_device_id++;
132164
}
133165
}
134166
}

0 commit comments

Comments
 (0)