Skip to content

Commit cb80117

Browse files
Fixed filter-selector-string output by lspltform and print_device_info
For example, now: ``` Platform 3 :: Name Intel(R) Level-Zero Version 1.3 Vendor Intel(R) Corporation Backend ext_oneapi_level_zero Num Devices 1 # 0 Name Intel(R) UHD Graphics [0x9bca] Version 1.3.23750 Filter string level_zero:gpu:0 ``` While previously the filter string was "ext_oneapi_level_zero:gpu:0". Similar change for print_device_info: ``` $ SYCL_FILTER_SELECTOR=level python -c "import dpctl; dpctl.SyclDevice().print_device_info()" Name Intel(R) UHD Graphics [0x9bca] Driver version 1.3.23750 Vendor Intel(R) Corporation Profile FULL_PROFILE Filter string level_zero:gpu:0 ``` Previously the filter string used to be "ext_oneapi_level_zero:gpu:0".
1 parent 299bd7e commit cb80117

File tree

4 files changed

+60
-20
lines changed

4 files changed

+60
-20
lines changed

libsyclinterface/helper/include/dpctl_utils_helper.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ DPCTLPartitionAffinityDomainType DPCTL_SyclPartitionAffinityDomainToDPCTLType(
197197
DPCTL_API
198198
int64_t DPCTL_GetRelativeDeviceId(const sycl::device &Device);
199199

200+
/*!
201+
* @brief Gives the filter string which would select given root device if
202+
* used as argument to ``sycl::ext::oneapi::filter_selector``. Throws exception
203+
* if filter string can not be constructed.
204+
*
205+
* @param Device A ``sycl::device`` object whose filter selector
206+
* needs to be computed.
207+
* @return Filter selector for the device.
208+
*/
209+
DPCTL_API
210+
std::string DPCTL_GetDeviceFilterString(const sycl::device &Device);
211+
200212
/*!
201213
* @brief Converts a ``sycl::info::event_command_status`` enum value to
202214
* corresponding DPCTLSyclEventStatusType enum value.

libsyclinterface/helper/source/dpctl_utils_helper.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,38 @@ int64_t DPCTL_GetRelativeDeviceId(const device &Device)
470470
return relid;
471471
}
472472

473+
std::string DPCTL_GetDeviceFilterString(const device &Device)
474+
{
475+
std::stringstream ss;
476+
static constexpr const char *filter_string_separator = ":";
477+
478+
auto be = Device.get_platform().get_backend();
479+
480+
switch (be) {
481+
case backend::ext_oneapi_level_zero:
482+
ss << "level_zero";
483+
break;
484+
case backend::ext_oneapi_cuda:
485+
ss << "cuda";
486+
break;
487+
case backend::opencl:
488+
ss << "opencl";
489+
break;
490+
case backend::host:
491+
ss << "host";
492+
break;
493+
default:
494+
ss << "unknown";
495+
};
496+
497+
ss << filter_string_separator;
498+
ss << DPCTL_DeviceTypeToStr(Device.get_info<info::device::device_type>());
499+
ss << filter_string_separator;
500+
ss << DPCTL_GetRelativeDeviceId(Device);
501+
502+
return ss.str();
503+
}
504+
473505
DPCTLSyclEventStatusType
474506
DPCTL_SyclEventStatusToDPCTLEventStatusType(info::event_command_status E)
475507
{

libsyclinterface/source/dpctl_sycl_device_manager.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,15 @@ std::string get_device_info_str(const device &Device)
5252
std::stringstream ss;
5353

5454
ss << std::setw(4) << " " << std::left << std::setw(16) << "Name"
55-
<< Device.get_info<info::device::name>() << '\n'
55+
<< Device.get_info<info::device::name>() << std::endl
5656
<< std::setw(4) << " " << std::left << std::setw(16) << "Driver version"
57-
<< Device.get_info<info::device::driver_version>() << '\n'
57+
<< Device.get_info<info::device::driver_version>() << std::endl
5858
<< std::setw(4) << " " << std::left << std::setw(16) << "Vendor"
59-
<< Device.get_info<info::device::vendor>() << '\n'
59+
<< Device.get_info<info::device::vendor>() << std::endl
6060
<< std::setw(4) << " " << std::left << std::setw(16) << "Profile"
61-
<< Device.get_info<info::device::profile>() << '\n'
61+
<< Device.get_info<info::device::profile>() << std::endl
6262
<< std::setw(4) << " " << std::left << std::setw(16) << "Filter string"
63-
<< Device.get_platform().get_backend() << ":"
64-
<< DPCTL_DeviceTypeToStr(Device.get_info<info::device::device_type>())
65-
<< ":" << DPCTL_GetRelativeDeviceId(Device) << '\n';
63+
<< DPCTL_GetDeviceFilterString(Device) << std::endl;
6664

6765
return ss.str();
6866
}

libsyclinterface/source/dpctl_sycl_platform_manager.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,45 +55,43 @@ std::string platform_print_info_impl(const platform &p, size_t verbosity)
5555

5656
if (verbosity == 0)
5757
ss << p.get_info<info::platform::name>() << " "
58-
<< p.get_info<info::platform::version>() << '\n';
58+
<< p.get_info<info::platform::version>() << std::endl;
5959

6060
if (verbosity > 0) {
6161
auto vendor = p.get_info<info::platform::vendor>();
6262
if (vendor.empty())
6363
vendor = "unknown";
6464

6565
ss << std::setw(4) << " " << std::left << std::setw(12) << "Name"
66-
<< p.get_info<info::platform::name>() << '\n'
66+
<< p.get_info<info::platform::name>() << std::endl
6767
<< std::setw(4) << " " << std::left << std::setw(12) << "Version"
68-
<< p.get_info<info::platform::version>() << '\n'
68+
<< p.get_info<info::platform::version>() << std::endl
6969
<< std::setw(4) << " " << std::left << std::setw(12) << "Vendor"
70-
<< vendor << '\n'
70+
<< vendor << std::endl
7171
<< std::setw(4) << " " << std::left << std::setw(12) << "Backend";
7272
p.is_host() ? (ss << "unknown") : (ss << p.get_backend());
73-
ss << '\n';
73+
ss << std::endl;
7474

7575
// Get number of devices on the platform
7676
auto devices = p.get_devices();
7777
ss << std::setw(4) << " " << std::left << std::setw(12) << "Num Devices"
78-
<< devices.size() << '\n';
78+
<< devices.size() << std::endl;
7979

8080
if (verbosity == 2)
8181
// Print some of the device information
8282
for (auto dn = 0ul; dn < devices.size(); ++dn) {
83-
ss << std::setw(6) << " " << std::left << "# " << dn << '\n'
83+
ss << std::setw(6) << " " << std::left << "# " << dn
84+
<< std::endl
8485
<< std::setw(8) << " " << std::left << std::setw(20)
8586
<< "Name" << devices[dn].get_info<info::device::name>()
86-
<< '\n'
87+
<< std::endl
8788
<< std::setw(8) << " " << std::left << std::setw(20)
8889
<< "Version"
8990
<< devices[dn].get_info<info::device::driver_version>()
90-
<< '\n'
91+
<< std::endl
9192
<< std::setw(8) << " " << std::left << std::setw(20)
9293
<< "Filter string"
93-
<< devices[dn].get_platform().get_backend() << ":"
94-
<< DPCTL_DeviceTypeToStr(
95-
devices[dn].get_info<info::device::device_type>())
96-
<< ":" << DPCTL_GetRelativeDeviceId(devices[dn]) << '\n';
94+
<< DPCTL_GetDeviceFilterString(devices[dn]) << std::endl;
9795
}
9896
}
9997

0 commit comments

Comments
 (0)