Skip to content

Commit e898390

Browse files
committed
[SYCL] Add device_type into sycl-ls prefix
By adding the device_type into each device prefix listing in sycl-ls, the user can easily set SYCL_DEVICE_FILTER correctly. Signed-off-by: Byoungro So <[email protected]>
1 parent ea59c2b commit e898390

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

sycl/doc/EnvironmentVariables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Possible values of "device_type" are:
6565
- acc
6666
- \*
6767

68-
Device_num is an integer that indexes the enumeration of devices from the sycl-ls utility tool, where the first device in that enumeration has index zero in each backend. For example, SYCL_DEVICE_FILTER=2 will return all devices with index '2' from all different backends. If multiple devices satisfy this device number (e.g., GPU and CPU devices can be assigned device number '2'), then default_selector will choose the device with the highest heuristic point.
68+
Device_num is an integer that indexes the enumeration of devices from the sycl-ls utility tool, where the first device in that enumeration has index zero in each platform. For example, SYCL_DEVICE_FILTER=2 will return all devices with index '2' from all different platforms. If multiple devices satisfy this device number (e.g., GPU and CPU devices can be assigned device number '2'), then default_selector will choose the device with the highest heuristic point.
6969

7070
Assuming a filter has all three elements of the triple, it selects only those devices that come from the given backend, have the specified device type, AND have the given device index. If more than one filter is specified, the RT is restricted to the union of devices selected by all filters. The RT does not include the "host" backend and the host device automatically unless one of the filters explicitly specifies the "host" device type. Therefore, SYCL_DEVICE_FILTER=host should be set to enforce SYCL to use the host device only.
7171

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,24 @@ class custom_selector : public device_selector {
3838
}
3939
};
4040

41-
static void printDeviceInfo(const device &Device, const std::string &Prepend) {
41+
std::string getDeviceTypeName(const device &Device) {
4242
auto DeviceType = Device.get_info<info::device::device_type>();
43-
std::string DeviceTypeName;
4443
switch (DeviceType) {
4544
case info::device_type::cpu:
46-
DeviceTypeName = "CPU ";
47-
break;
45+
return "cpu";
4846
case info::device_type::gpu:
49-
DeviceTypeName = "GPU ";
50-
break;
47+
return "gpu";
5148
case info::device_type::host:
52-
DeviceTypeName = "HOST";
53-
break;
49+
return "host";
5450
case info::device_type::accelerator:
55-
DeviceTypeName = "ACC ";
56-
break;
51+
return "acc";
5752
default:
58-
DeviceTypeName = "UNKNOWN";
59-
break;
53+
return "unknown";
6054
}
55+
}
6156

57+
static void printDeviceInfo(const device &Device, const std::string &Prepend) {
58+
std::string DeviceTypeName = getDeviceTypeName(Device);
6259
auto DeviceVersion = Device.get_info<info::device::version>();
6360
auto DeviceName = Device.get_info<info::device::name>();
6461
auto DeviceVendor = Device.get_info<info::device::vendor>();
@@ -73,17 +70,16 @@ static void printDeviceInfo(const device &Device, const std::string &Prepend) {
7370
} else {
7471
auto DevicePlatform = Device.get_info<info::device::platform>();
7572
auto DevicePlatformName = DevicePlatform.get_info<info::platform::name>();
76-
std::cout << Prepend << DeviceTypeName << ": " << DevicePlatformName << " "
77-
<< DeviceVersion << " [" << DeviceDriverVersion << "]"
78-
<< std::endl;
73+
std::cout << Prepend << " : " << DevicePlatformName << " " << DeviceVersion
74+
<< " [" << DeviceDriverVersion << "]" << std::endl;
7975
}
8076
}
8177

8278
static void printSelectorChoice(const device_selector &Selector,
8379
const std::string &Prepend) {
8480
try {
8581
const auto &Dev = device(Selector);
86-
printDeviceInfo(Dev, Prepend);
82+
printDeviceInfo(Dev, Prepend + getDeviceTypeName(Dev));
8783

8884
} catch (const cl::sycl::runtime_error &Exception) {
8985
// Truncate long string so it can fit in one-line
@@ -132,7 +128,8 @@ int main(int argc, char **argv) {
132128
std::cout << " Device [#" << DeviceNum << "]:" << std::endl;
133129
else {
134130
backend Backend = Platform.get_backend();
135-
std::cout << "[" << Backend << ":" << DeviceNum << "] ";
131+
std::cout << "[" << Backend << ":" << getDeviceTypeName(Device) << ":"
132+
<< DeviceNum << "]";
136133
}
137134
++DeviceNum;
138135
printDeviceInfo(Device, verbose ? " " : "");

0 commit comments

Comments
 (0)