Skip to content

Commit cea8fa9

Browse files
author
Diptorup Deb
committed
Improvements to the print info functions.
- print_device_info now prints the filter string. Device type is no longer separately printed out. Device profile is not printed any more. - print_platform_info now has various verbosity levels to control amount of information that is printed.
1 parent 6d8d8df commit cea8fa9

10 files changed

+274
-121
lines changed

dpctl-capi/helper/include/dpctl_utils_helper.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,21 @@ DPCTL_DPCTLPartitionAffinityDomainTypeToSycl(
178178
DPCTL_API
179179
DPCTLPartitionAffinityDomainType DPCTL_SyclPartitionAffinityDomainToDPCTLType(
180180
sycl::info::partition_affinity_domain PartitionAffinityDomain);
181+
182+
/*!
183+
* @brief Gives the index of the given device with respective to all the other
184+
* devices of the same type in the device's platform.
185+
*
186+
* The relative device id of a device (Device) is computed by looking up the
187+
* position of Device in the ``std::vector`` returned by calling the
188+
* ``get_devices(Device.get_info<sycl::info::device::device_type>())`` function
189+
* for Device's platform. A relative device id of -1 indicates that the relative
190+
* id could not be computed.
191+
*
192+
* @param Device A ``sycl::device`` object whose relative id is to be
193+
* computed.
194+
* @return A relative id corresponding to the device, -1 indicates that a
195+
* relative id value could not be computed.
196+
*/
197+
DPCTL_API
198+
int64_t DPCTL_GetRelativeDeviceId(const sycl::device &Device);

dpctl-capi/helper/source/dpctl_utils_helper.cpp

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,22 @@ std::string DPCTL_DeviceTypeToStr(info::device_type devTy)
3737
std::stringstream ss;
3838
switch (devTy) {
3939
case info::device_type::cpu:
40-
ss << "cpu" << '\n';
40+
ss << "cpu";
4141
break;
4242
case info::device_type::gpu:
43-
ss << "gpu" << '\n';
43+
ss << "gpu";
4444
break;
4545
case info::device_type::accelerator:
46-
ss << "accelerator" << '\n';
46+
ss << "accelerator";
4747
break;
4848
case info::device_type::custom:
49-
ss << "custom" << '\n';
49+
ss << "custom";
5050
break;
5151
case info::device_type::host:
52-
ss << "host" << '\n';
52+
ss << "host";
5353
break;
5454
default:
55-
ss << "unknown" << '\n';
55+
ss << "unknown";
5656
}
5757
return ss.str();
5858
}
@@ -169,58 +169,58 @@ std::string DPCTL_AspectToStr(aspect aspectTy)
169169
std::stringstream ss;
170170
switch (aspectTy) {
171171
case aspect::host:
172-
ss << "host" << '\n';
172+
ss << "host";
173173
break;
174174
case aspect::cpu:
175-
ss << "cpu" << '\n';
175+
ss << "cpu";
176176
break;
177177
case aspect::gpu:
178-
ss << "gpu" << '\n';
178+
ss << "gpu";
179179
break;
180180
case aspect::accelerator:
181-
ss << "accelerator" << '\n';
181+
ss << "accelerator";
182182
break;
183183
case aspect::custom:
184-
ss << "custom" << '\n';
184+
ss << "custom";
185185
break;
186186
case aspect::fp16:
187-
ss << "fp16" << '\n';
187+
ss << "fp16";
188188
break;
189189
case aspect::fp64:
190-
ss << "fp64" << '\n';
190+
ss << "fp64";
191191
break;
192192
case aspect::int64_base_atomics:
193-
ss << "int64_base_atomics" << '\n';
193+
ss << "int64_base_atomics";
194194
break;
195195
case aspect::int64_extended_atomics:
196-
ss << "int64_extended_atomics" << '\n';
196+
ss << "int64_extended_atomics";
197197
break;
198198
case aspect::image:
199-
ss << "image" << '\n';
199+
ss << "image";
200200
break;
201201
case aspect::online_compiler:
202-
ss << "online_compiler" << '\n';
202+
ss << "online_compiler";
203203
break;
204204
case aspect::online_linker:
205-
ss << "online_linker" << '\n';
205+
ss << "online_linker";
206206
break;
207207
case aspect::queue_profiling:
208-
ss << "queue_profiling" << '\n';
208+
ss << "queue_profiling";
209209
break;
210210
case aspect::usm_device_allocations:
211-
ss << "usm_device_allocations" << '\n';
211+
ss << "usm_device_allocations";
212212
break;
213213
case aspect::usm_host_allocations:
214-
ss << "usm_host_allocations" << '\n';
214+
ss << "usm_host_allocations";
215215
break;
216216
case aspect::usm_shared_allocations:
217-
ss << "usm_shared_allocations" << '\n';
217+
ss << "usm_shared_allocations";
218218
break;
219219
case aspect::usm_restricted_shared_allocations:
220-
ss << "usm_restricted_shared_allocations" << '\n';
220+
ss << "usm_restricted_shared_allocations";
221221
break;
222222
case aspect::usm_system_allocator:
223-
ss << "usm_system_allocator" << '\n';
223+
ss << "usm_system_allocator";
224224
break;
225225
default:
226226
throw runtime_error("Unsupported aspect type", -1);
@@ -428,3 +428,18 @@ DPCTLPartitionAffinityDomainType DPCTL_SyclPartitionAffinityDomainToDPCTLType(
428428
throw runtime_error("Unsupported partition_affinity_domain type", -1);
429429
}
430430
}
431+
432+
int64_t DPCTL_GetRelativeDeviceId(const device &Device)
433+
{
434+
auto relid = -1;
435+
auto p = Device.get_platform();
436+
auto dt = Device.get_info<sycl::info::device::device_type>();
437+
auto dev_vec = p.get_devices(dt);
438+
int64_t id = 0;
439+
for (const auto &d_i : dev_vec) {
440+
if (Device == d_i)
441+
relid = id;
442+
++id;
443+
}
444+
return relid;
445+
}

dpctl-capi/include/dpctl_sycl_device_manager.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,18 @@ DPCTL_API
116116
void DPCTLDeviceMgr_PrintDeviceInfo(__dpctl_keep const DPCTLSyclDeviceRef DRef);
117117

118118
/*!
119-
* @brief Gives the index of the given device in the vector returned get_devices
120-
* for the platform associated with DRef for the device type of DRef.
119+
* @brief Gives the index of the given device with respective to all the other
120+
* devices of the same type in the device's platform.
121+
*
122+
* The relative device id of a device (Device) is computed by looking up the
123+
* position of Device in the ``std::vector`` returned by calling the
124+
* ``get_devices(Device.get_info<sycl::info::device::device_type>())`` function
125+
* for Device's platform. A relative device id of -1 indicates that the relative
126+
* id could not be computed.
121127
*
122128
* @param DRef A #DPCTLSyclDeviceRef opaque pointer.
129+
* @return A relative id corresponding to the device, -1 indicates that a
130+
* relative id value could not be computed.
123131
* @ingroup DeviceManager
124132
*/
125133
DPCTL_API

dpctl-capi/include/dpctl_sycl_platform_manager.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,24 @@ DPCTL_DECLARE_VECTOR(Platform)
4545

4646
/*!
4747
* @brief Prints out information about the sycl::platform argument.
48+
*
49+
* The helper function is used to print metadata about a given platform. The
50+
* amount of information printed out is controlled by the verbosity level.
51+
*
52+
* Verbosity level 0: Prints only the name of the platform.
53+
* Verbosity level 1: Prints the name, version, vendor, backend, number of
54+
* devices in the platform.
55+
* Verbosity level 2: Prints everything in level 1 and also prints the name,
56+
* version, and filter string for each device in the
57+
* platform.
58+
*
4859
* @param PRef A #DPCTLSyclPlatformRef opaque pointer.
60+
* @param verbosity Verbosilty level to control how much information is
61+
* printed out.
4962
*/
5063
DPCTL_API
51-
void DPCTLPlatformMgr_PrintInfo(__dpctl_keep const DPCTLSyclPlatformRef PRef);
64+
void DPCTLPlatformMgr_PrintInfo(__dpctl_keep const DPCTLSyclPlatformRef PRef,
65+
size_t verbosity);
5266

5367
/*! @} */
5468

dpctl-capi/source/dpctl_sycl_device_manager.cpp

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -49,33 +49,34 @@ void print_device_info(const device &Device)
4949
std::stringstream ss;
5050

5151
ss << std::setw(4) << " " << std::left << std::setw(16) << "Name"
52-
<< Device.get_info<info::device::name>() << '\n';
53-
ss << std::setw(4) << " " << std::left << std::setw(16) << "Driver version"
54-
<< Device.get_info<info::device::driver_version>() << '\n';
55-
ss << std::setw(4) << " " << std::left << std::setw(16) << "Vendor"
56-
<< Device.get_info<info::device::vendor>() << '\n';
57-
ss << std::setw(4) << " " << std::left << std::setw(16) << "Profile"
58-
<< Device.get_info<info::device::profile>() << '\n';
59-
ss << std::setw(4) << " " << std::left << std::setw(16) << "Device type";
60-
61-
auto devTy = Device.get_info<info::device::device_type>();
62-
ss << DPCTL_DeviceTypeToStr(devTy);
52+
<< Device.get_info<info::device::name>() << '\n'
53+
<< std::setw(4) << " " << std::left << std::setw(16) << "Driver version"
54+
<< Device.get_info<info::device::driver_version>() << '\n'
55+
<< std::setw(4) << " " << std::left << std::setw(16) << "Vendor"
56+
<< Device.get_info<info::device::vendor>() << '\n'
57+
<< std::setw(4) << " " << std::left << std::setw(16) << "Profile"
58+
<< Device.get_info<info::device::profile>() << '\n'
59+
<< std::setw(4) << " " << std::left << std::setw(16) << "Filter string"
60+
<< Device.get_platform().get_backend() << ":"
61+
<< DPCTL_DeviceTypeToStr(Device.get_info<info::device::device_type>())
62+
<< ":" << DPCTL_GetRelativeDeviceId(Device) << '\n';
6363

6464
std::cout << ss.str();
6565
}
6666

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

198198
int64_t DPCTLDeviceMgr_GetRelativeId(__dpctl_keep const DPCTLSyclDeviceRef DRef)
199199
{
200200
auto Device = unwrap(DRef);
201201

202-
if (Device) {
203-
auto p = Device->get_platform();
204-
auto dt = Device->get_info<sycl::info::device::device_type>();
205-
auto dev_vec = p.get_devices(dt);
206-
int64_t id = 0;
207-
for (auto &d_i : dev_vec) {
208-
if (*Device == d_i)
209-
return id;
210-
++id;
211-
}
212-
return -1;
213-
}
202+
if (Device)
203+
return DPCTL_GetRelativeDeviceId(*Device);
204+
214205
return -1;
215206
}

0 commit comments

Comments
 (0)