Skip to content

Print the backend as part of print_device_info. #409

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 2 commits into from
May 4, 2021
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
18 changes: 18 additions & 0 deletions dpctl-capi/helper/include/dpctl_utils_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,21 @@ DPCTL_DPCTLPartitionAffinityDomainTypeToSycl(
DPCTL_API
DPCTLPartitionAffinityDomainType DPCTL_SyclPartitionAffinityDomainToDPCTLType(
sycl::info::partition_affinity_domain PartitionAffinityDomain);

/*!
* @brief Gives the index of the given device with respective to all the other
* devices of the same type in the device's platform.
*
* The relative device id of a device (Device) is computed by looking up the
* position of Device in the ``std::vector`` returned by calling the
* ``get_devices(Device.get_info<sycl::info::device::device_type>())`` function
* for Device's platform. A relative device id of -1 indicates that the relative
* id could not be computed.
*
* @param Device A ``sycl::device`` object whose relative id is to be
* computed.
* @return A relative id corresponding to the device, -1 indicates that a
* relative id value could not be computed.
*/
DPCTL_API
int64_t DPCTL_GetRelativeDeviceId(const sycl::device &Device);
63 changes: 39 additions & 24 deletions dpctl-capi/helper/source/dpctl_utils_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ std::string DPCTL_DeviceTypeToStr(info::device_type devTy)
std::stringstream ss;
switch (devTy) {
case info::device_type::cpu:
ss << "cpu" << '\n';
ss << "cpu";
break;
case info::device_type::gpu:
ss << "gpu" << '\n';
ss << "gpu";
break;
case info::device_type::accelerator:
ss << "accelerator" << '\n';
ss << "accelerator";
break;
case info::device_type::custom:
ss << "custom" << '\n';
ss << "custom";
break;
case info::device_type::host:
ss << "host" << '\n';
ss << "host";
break;
default:
ss << "unknown" << '\n';
ss << "unknown";
}
return ss.str();
}
Expand Down Expand Up @@ -169,58 +169,58 @@ std::string DPCTL_AspectToStr(aspect aspectTy)
std::stringstream ss;
switch (aspectTy) {
case aspect::host:
ss << "host" << '\n';
ss << "host";
break;
case aspect::cpu:
ss << "cpu" << '\n';
ss << "cpu";
break;
case aspect::gpu:
ss << "gpu" << '\n';
ss << "gpu";
break;
case aspect::accelerator:
ss << "accelerator" << '\n';
ss << "accelerator";
break;
case aspect::custom:
ss << "custom" << '\n';
ss << "custom";
break;
case aspect::fp16:
ss << "fp16" << '\n';
ss << "fp16";
break;
case aspect::fp64:
ss << "fp64" << '\n';
ss << "fp64";
break;
case aspect::int64_base_atomics:
ss << "int64_base_atomics" << '\n';
ss << "int64_base_atomics";
break;
case aspect::int64_extended_atomics:
ss << "int64_extended_atomics" << '\n';
ss << "int64_extended_atomics";
break;
case aspect::image:
ss << "image" << '\n';
ss << "image";
break;
case aspect::online_compiler:
ss << "online_compiler" << '\n';
ss << "online_compiler";
break;
case aspect::online_linker:
ss << "online_linker" << '\n';
ss << "online_linker";
break;
case aspect::queue_profiling:
ss << "queue_profiling" << '\n';
ss << "queue_profiling";
break;
case aspect::usm_device_allocations:
ss << "usm_device_allocations" << '\n';
ss << "usm_device_allocations";
break;
case aspect::usm_host_allocations:
ss << "usm_host_allocations" << '\n';
ss << "usm_host_allocations";
break;
case aspect::usm_shared_allocations:
ss << "usm_shared_allocations" << '\n';
ss << "usm_shared_allocations";
break;
case aspect::usm_restricted_shared_allocations:
ss << "usm_restricted_shared_allocations" << '\n';
ss << "usm_restricted_shared_allocations";
break;
case aspect::usm_system_allocator:
ss << "usm_system_allocator" << '\n';
ss << "usm_system_allocator";
break;
default:
throw runtime_error("Unsupported aspect type", -1);
Expand Down Expand Up @@ -428,3 +428,18 @@ DPCTLPartitionAffinityDomainType DPCTL_SyclPartitionAffinityDomainToDPCTLType(
throw runtime_error("Unsupported partition_affinity_domain type", -1);
}
}

int64_t DPCTL_GetRelativeDeviceId(const device &Device)
{
auto relid = -1;
auto p = Device.get_platform();
auto dt = Device.get_info<sycl::info::device::device_type>();
auto dev_vec = p.get_devices(dt);
int64_t id = 0;
for (const auto &d_i : dev_vec) {
if (Device == d_i)
relid = id;
++id;
}
return relid;
}
12 changes: 10 additions & 2 deletions dpctl-capi/include/dpctl_sycl_device_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,18 @@ DPCTL_API
void DPCTLDeviceMgr_PrintDeviceInfo(__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Gives the index of the given device in the vector returned get_devices
* for the platform associated with DRef for the device type of DRef.
* @brief Gives the index of the given device with respective to all the other
* devices of the same type in the device's platform.
*
* The relative device id of a device (Device) is computed by looking up the
* position of Device in the ``std::vector`` returned by calling the
* ``get_devices(Device.get_info<sycl::info::device::device_type>())`` function
* for Device's platform. A relative device id of -1 indicates that the relative
* id could not be computed.
*
* @param DRef A #DPCTLSyclDeviceRef opaque pointer.
* @return A relative id corresponding to the device, -1 indicates that a
* relative id value could not be computed.
* @ingroup DeviceManager
*/
DPCTL_API
Expand Down
16 changes: 15 additions & 1 deletion dpctl-capi/include/dpctl_sycl_platform_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,24 @@ DPCTL_DECLARE_VECTOR(Platform)

/*!
* @brief Prints out information about the sycl::platform argument.
*
* The helper function is used to print metadata about a given platform. The
* amount of information printed out is controlled by the verbosity level.
*
* Verbosity level 0: Prints only the name of the platform.
* Verbosity level 1: Prints the name, version, vendor, backend, number of
* devices in the platform.
* Verbosity level 2: Prints everything in level 1 and also prints the name,
* version, and filter string for each device in the
* platform.
*
* @param PRef A #DPCTLSyclPlatformRef opaque pointer.
* @param verbosity Verbosilty level to control how much information is
* printed out.
*/
DPCTL_API
void DPCTLPlatformMgr_PrintInfo(__dpctl_keep const DPCTLSyclPlatformRef PRef);
void DPCTLPlatformMgr_PrintInfo(__dpctl_keep const DPCTLSyclPlatformRef PRef,
size_t verbosity);

/*! @} */

Expand Down
57 changes: 24 additions & 33 deletions dpctl-capi/source/dpctl_sycl_device_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,34 @@ void print_device_info(const device &Device)
std::stringstream ss;

ss << std::setw(4) << " " << std::left << std::setw(16) << "Name"
<< Device.get_info<info::device::name>() << '\n';
ss << std::setw(4) << " " << std::left << std::setw(16) << "Driver version"
<< Device.get_info<info::device::driver_version>() << '\n';
ss << std::setw(4) << " " << std::left << std::setw(16) << "Vendor"
<< Device.get_info<info::device::vendor>() << '\n';
ss << std::setw(4) << " " << std::left << std::setw(16) << "Profile"
<< Device.get_info<info::device::profile>() << '\n';
ss << std::setw(4) << " " << std::left << std::setw(16) << "Device type";

auto devTy = Device.get_info<info::device::device_type>();
ss << DPCTL_DeviceTypeToStr(devTy);
<< 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'
<< 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';

std::cout << ss.str();
}

struct DeviceCacheBuilder
{
using DeviceCache = std::unordered_map<device, context>;
/* This function implements a workaround to the current lack of a default
* context per root device in DPC++. The map stores a "default" context for
* each root device, and the QMgrHelper uses the map whenever it creates a
* new queue for a root device. By doing so, we avoid the performance
* overhead of context creation for every queue.
/* This function implements a workaround to the current lack of a
* default context per root device in DPC++. The map stores a "default"
* context for each root device, and the QMgrHelper uses the map
* whenever it creates a new queue for a root device. By doing so, we
* avoid the performance overhead of context creation for every queue.
*
* The singleton pattern implemented here ensures that the map is created
* once in a thread-safe manner. Since, the map is ony read post-creation we
* do not need any further protection to ensure thread-safety.
* The singleton pattern implemented here ensures that the map is
* created once in a thread-safe manner. Since, the map is ony read
* post-creation we do not need any further protection to ensure
* thread-safety.
*/
static const DeviceCache &getDeviceCache()
{
Expand Down Expand Up @@ -190,26 +191,16 @@ void DPCTLDeviceMgr_PrintDeviceInfo(__dpctl_keep const DPCTLSyclDeviceRef DRef)
auto Device = unwrap(DRef);
if (Device)
print_device_info(*Device);
else {
else
std::cout << "Device is not valid (NULL). Cannot print device info.\n";
}
}

int64_t DPCTLDeviceMgr_GetRelativeId(__dpctl_keep const DPCTLSyclDeviceRef DRef)
{
auto Device = unwrap(DRef);

if (Device) {
auto p = Device->get_platform();
auto dt = Device->get_info<sycl::info::device::device_type>();
auto dev_vec = p.get_devices(dt);
int64_t id = 0;
for (auto &d_i : dev_vec) {
if (*Device == d_i)
return id;
++id;
}
return -1;
}
if (Device)
return DPCTL_GetRelativeDeviceId(*Device);

return -1;
}
Loading