Skip to content

Commit 0cee18e

Browse files
authored
[SYCL] Fix sycl-ls device indexing (#4704)
This fixes two issues, first `backend::all` is not guaranteed to be the last entry in the backend types enum and shouldn't be used as such. This caused issues for newer backends such as HIP (see #4698). The second issue is that the `DeviceNums` vector wasn't being reset between the short output and the verbose output which meant that the device indices printed in the verbose output were incorrect.
1 parent bf7b02a commit 0cee18e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <cstdlib>
2222
#include <iostream>
23+
#include <map>
2324
#include <stdlib.h>
2425

2526
using namespace cl::sycl;
@@ -116,18 +117,17 @@ int main(int argc, char **argv) {
116117

117118
const auto &Platforms = platform::get_platforms();
118119

119-
// For each backend, device num starts at zero.
120-
std::vector<uint32_t> DeviceNums(static_cast<int>(backend::all), 0);
120+
// Keep track of the number of devices per backend
121+
std::map<backend, size_t> DeviceNums;
121122

122123
for (const auto &Platform : Platforms) {
123124
backend Backend = Platform.get_backend();
124125
auto PlatformName = Platform.get_info<info::platform::name>();
125126
const auto &Devices = Platform.get_devices();
126127
for (const auto &Device : Devices) {
127-
uint32_t DeviceNum = DeviceNums[(int)Backend]++;
128128
std::cout << "[" << Backend << ":" << getDeviceTypeName(Device) << ":"
129-
<< DeviceNum << "] ";
130-
++DeviceNum;
129+
<< DeviceNums[Backend] << "] ";
130+
++DeviceNums[Backend];
131131
// Verbose parameter is set to false to print regular devices output first
132132
printDeviceInfo(Device, false, PlatformName);
133133
}
@@ -136,6 +136,7 @@ int main(int argc, char **argv) {
136136
if (verbose) {
137137
std::cout << "\nPlatforms: " << Platforms.size() << std::endl;
138138
uint32_t PlatformNum = 0;
139+
DeviceNums.clear();
139140
for (const auto &Platform : Platforms) {
140141
backend Backend = Platform.get_backend();
141142
++PlatformNum;
@@ -150,9 +151,9 @@ int main(int argc, char **argv) {
150151
const auto &Devices = Platform.get_devices();
151152
std::cout << " Devices : " << Devices.size() << std::endl;
152153
for (const auto &Device : Devices) {
153-
uint32_t DeviceNum = DeviceNums[(int)Backend]++;
154-
std::cout << " Device [#" << DeviceNum << "]:" << std::endl;
155-
++DeviceNum;
154+
std::cout << " Device [#" << DeviceNums[Backend]
155+
<< "]:" << std::endl;
156+
++DeviceNums[Backend];
156157
printDeviceInfo(Device, true, " ");
157158
}
158159
}

0 commit comments

Comments
 (0)