Skip to content

Fixed filter-selector-string output by lsplatform and print_device_info #866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions libsyclinterface/helper/include/dpctl_utils_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,18 @@ DPCTLPartitionAffinityDomainType DPCTL_SyclPartitionAffinityDomainToDPCTLType(
DPCTL_API
int64_t DPCTL_GetRelativeDeviceId(const sycl::device &Device);

/*!
* @brief Gives the filter string which would select given root device if
* used as argument to ``sycl::ext::oneapi::filter_selector``. Throws exception
* if filter string can not be constructed.
*
* @param Device A ``sycl::device`` object whose filter selector
* needs to be computed.
* @return Filter selector for the device.
*/
DPCTL_API
std::string DPCTL_GetDeviceFilterString(const sycl::device &Device);

/*!
* @brief Converts a ``sycl::info::event_command_status`` enum value to
* corresponding DPCTLSyclEventStatusType enum value.
Expand Down
32 changes: 32 additions & 0 deletions libsyclinterface/helper/source/dpctl_utils_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,38 @@ int64_t DPCTL_GetRelativeDeviceId(const device &Device)
return relid;
}

std::string DPCTL_GetDeviceFilterString(const device &Device)
{
std::stringstream ss;
static constexpr const char *filter_string_separator = ":";

auto be = Device.get_platform().get_backend();

switch (be) {
case backend::ext_oneapi_level_zero:
ss << "level_zero";
break;
case backend::ext_oneapi_cuda:
ss << "cuda";
break;
case backend::opencl:
ss << "opencl";
break;
case backend::host:
ss << "host";
break;
default:
ss << "unknown";
};

ss << filter_string_separator;
ss << DPCTL_DeviceTypeToStr(Device.get_info<info::device::device_type>());
ss << filter_string_separator;
ss << DPCTL_GetRelativeDeviceId(Device);

return ss.str();
}

DPCTLSyclEventStatusType
DPCTL_SyclEventStatusToDPCTLEventStatusType(info::event_command_status E)
{
Expand Down
19 changes: 9 additions & 10 deletions libsyclinterface/source/dpctl_sycl_device_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,18 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(context, DPCTLSyclContextRef)
std::string get_device_info_str(const device &Device)
{
std::stringstream ss;
static constexpr const char *_endl = "\n";

ss << std::setw(4) << " " << std::left << std::setw(16) << "Name"
<< Device.get_info<info::device::name>() << '\n'
<< std::setw(4) << " " << std::left << std::setw(16) << "Driver version"
<< Device.get_info<info::device::driver_version>() << '\n'
<< Device.get_info<info::device::name>() << _endl << std::setw(4) << " "
<< std::left << std::setw(16) << "Driver version"
<< Device.get_info<info::device::driver_version>() << _endl
<< std::setw(4) << " " << std::left << std::setw(16) << "Vendor"
<< Device.get_info<info::device::vendor>() << '\n'
<< std::setw(4) << " " << std::left << std::setw(16) << "Profile"
<< Device.get_info<info::device::profile>() << '\n'
<< std::setw(4) << " " << std::left << std::setw(16) << "Filter string"
<< Device.get_platform().get_backend() << ":"
<< DPCTL_DeviceTypeToStr(Device.get_info<info::device::device_type>())
<< ":" << DPCTL_GetRelativeDeviceId(Device) << '\n';
<< Device.get_info<info::device::vendor>() << _endl << std::setw(4)
<< " " << std::left << std::setw(16) << "Profile"
<< Device.get_info<info::device::profile>() << _endl << std::setw(4)
<< " " << std::left << std::setw(16) << "Filter string"
<< DPCTL_GetDeviceFilterString(Device) << _endl;

return ss.str();
}
Expand Down
29 changes: 12 additions & 17 deletions libsyclinterface/source/dpctl_sycl_platform_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(platform, DPCTLSyclPlatformRef);
std::string platform_print_info_impl(const platform &p, size_t verbosity)
{
std::stringstream ss;
static constexpr const char *_endl = "\n";

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

if (verbosity == 0)
ss << p.get_info<info::platform::name>() << " "
<< p.get_info<info::platform::version>() << '\n';
<< p.get_info<info::platform::version>() << _endl;

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

ss << std::setw(4) << " " << std::left << std::setw(12) << "Name"
<< p.get_info<info::platform::name>() << '\n'
<< std::setw(4) << " " << std::left << std::setw(12) << "Version"
<< p.get_info<info::platform::version>() << '\n'
<< std::setw(4) << " " << std::left << std::setw(12) << "Vendor"
<< vendor << '\n'
<< p.get_info<info::platform::name>() << _endl << std::setw(4) << " "
<< std::left << std::setw(12) << "Version"
<< p.get_info<info::platform::version>() << _endl << std::setw(4)
<< " " << std::left << std::setw(12) << "Vendor" << vendor << _endl
<< std::setw(4) << " " << std::left << std::setw(12) << "Backend";
p.is_host() ? (ss << "unknown") : (ss << p.get_backend());
ss << '\n';
ss << _endl;

// Get number of devices on the platform
auto devices = p.get_devices();
ss << std::setw(4) << " " << std::left << std::setw(12) << "Num Devices"
<< devices.size() << '\n';
<< devices.size() << _endl;

if (verbosity == 2)
// Print some of the device information
for (auto dn = 0ul; dn < devices.size(); ++dn) {
ss << std::setw(6) << " " << std::left << "# " << dn << '\n'
ss << std::setw(6) << " " << std::left << "# " << dn << _endl
<< std::setw(8) << " " << std::left << std::setw(20)
<< "Name" << devices[dn].get_info<info::device::name>()
<< '\n'
<< std::setw(8) << " " << std::left << std::setw(20)
<< _endl << std::setw(8) << " " << std::left << std::setw(20)
<< "Version"
<< devices[dn].get_info<info::device::driver_version>()
<< '\n'
<< std::setw(8) << " " << std::left << std::setw(20)
<< _endl << std::setw(8) << " " << std::left << std::setw(20)
<< "Filter string"
<< devices[dn].get_platform().get_backend() << ":"
<< DPCTL_DeviceTypeToStr(
devices[dn].get_info<info::device::device_type>())
<< ":" << DPCTL_GetRelativeDeviceId(devices[dn]) << '\n';
<< DPCTL_GetDeviceFilterString(devices[dn]) << _endl;
}
}

Expand Down