Skip to content

Commit c09ac88

Browse files
Merge pull request #866 from IntelPython/fix-filter-string-construction-in-lsplatform
Fixed filter-selector-string output by lsplatform and print_device_info
2 parents 8e04e06 + 7b5b4c1 commit c09ac88

File tree

4 files changed

+65
-27
lines changed

4 files changed

+65
-27
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: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,18 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef)
5050
std::string get_device_info_str(const device &Device)
5151
{
5252
std::stringstream ss;
53+
static constexpr const char *_endl = "\n";
5354

5455
ss << std::setw(4) << " " << std::left << std::setw(16) << "Name"
55-
<< Device.get_info<info::device::name>() << '\n'
56-
<< std::setw(4) << " " << std::left << std::setw(16) << "Driver version"
57-
<< Device.get_info<info::device::driver_version>() << '\n'
56+
<< Device.get_info<info::device::name>() << _endl << std::setw(4) << " "
57+
<< std::left << std::setw(16) << "Driver version"
58+
<< Device.get_info<info::device::driver_version>() << _endl
5859
<< std::setw(4) << " " << std::left << std::setw(16) << "Vendor"
59-
<< Device.get_info<info::device::vendor>() << '\n'
60-
<< std::setw(4) << " " << std::left << std::setw(16) << "Profile"
61-
<< Device.get_info<info::device::profile>() << '\n'
62-
<< 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';
60+
<< Device.get_info<info::device::vendor>() << _endl << std::setw(4)
61+
<< " " << std::left << std::setw(16) << "Profile"
62+
<< Device.get_info<info::device::profile>() << _endl << std::setw(4)
63+
<< " " << std::left << std::setw(16) << "Filter string"
64+
<< DPCTL_GetDeviceFilterString(Device) << _endl;
6665

6766
return ss.str();
6867
}

libsyclinterface/source/dpctl_sycl_platform_manager.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(platform, DPCTLSyclPlatformRef);
4545
std::string platform_print_info_impl(const platform &p, size_t verbosity)
4646
{
4747
std::stringstream ss;
48+
static constexpr const char *_endl = "\n";
4849

4950
if (verbosity > 2) {
5051
error_handler("Illegal verbosity level. Accepted values are 0, 1, or 2."
@@ -55,45 +56,39 @@ std::string platform_print_info_impl(const platform &p, size_t verbosity)
5556

5657
if (verbosity == 0)
5758
ss << p.get_info<info::platform::name>() << " "
58-
<< p.get_info<info::platform::version>() << '\n';
59+
<< p.get_info<info::platform::version>() << _endl;
5960

6061
if (verbosity > 0) {
6162
auto vendor = p.get_info<info::platform::vendor>();
6263
if (vendor.empty())
6364
vendor = "unknown";
6465

6566
ss << std::setw(4) << " " << std::left << std::setw(12) << "Name"
66-
<< p.get_info<info::platform::name>() << '\n'
67-
<< std::setw(4) << " " << std::left << std::setw(12) << "Version"
68-
<< p.get_info<info::platform::version>() << '\n'
69-
<< std::setw(4) << " " << std::left << std::setw(12) << "Vendor"
70-
<< vendor << '\n'
67+
<< p.get_info<info::platform::name>() << _endl << std::setw(4) << " "
68+
<< std::left << std::setw(12) << "Version"
69+
<< p.get_info<info::platform::version>() << _endl << std::setw(4)
70+
<< " " << std::left << std::setw(12) << "Vendor" << vendor << _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 << _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() << _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 << _endl
8484
<< std::setw(8) << " " << std::left << std::setw(20)
8585
<< "Name" << devices[dn].get_info<info::device::name>()
86-
<< '\n'
87-
<< std::setw(8) << " " << std::left << std::setw(20)
86+
<< _endl << std::setw(8) << " " << std::left << std::setw(20)
8887
<< "Version"
8988
<< devices[dn].get_info<info::device::driver_version>()
90-
<< '\n'
91-
<< std::setw(8) << " " << std::left << std::setw(20)
89+
<< _endl << std::setw(8) << " " << std::left << std::setw(20)
9290
<< "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';
91+
<< DPCTL_GetDeviceFilterString(devices[dn]) << _endl;
9792
}
9893
}
9994

0 commit comments

Comments
 (0)