Skip to content

Commit 82ebc23

Browse files
[SYCL] Add UUID and sub-, sub-sub- device info in sycl-ls --verbose (intel#13999)
Example `sycl-ls --verbose` output: ``` ... Platform [#1]: Version : 1.3 Name : Intel(R) Level-Zero Vendor : Intel(R) Corporation Devices : 1 Type : gpu Version : 12.60.7 Name : Intel(R) Data Center GPU Max 1550 Vendor : Intel(R) Corporation Driver : 1.3.26918 UUID : 1341282141147000580000000 Num SubDevices : 2 Num SubSubDevices : 8 Aspects : gpu fp16 fp64 ... ```
1 parent 7439fb4 commit 82ebc23

File tree

2 files changed

+80
-6
lines changed

2 files changed

+80
-6
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* Test to check that sycl-ls is outputting UUID and number of sub and sub-sub
2+
* devices. */
3+
// REQUIRES: gpu, level_zero
4+
5+
// UNSUPPORTED: gpu-intel-pvc-1T
6+
7+
// As of now, ZEX_NUMBER_OF_CCS is not working with FLAT hierachy,
8+
// which is the new default on PVC.
9+
10+
// RUN: env ONEAPI_DEVICE_SELECTOR="level_zero:*" env ZE_FLAT_DEVICE_HIERARCHY=COMPOSITE env ZEX_NUMBER_OF_CCS=0:4 sycl-ls --verbose >%t.default.out
11+
// RUN: FileCheck %s --input-file %t.default.out
12+
13+
// CHECK: {{.*}}UUID : {{.*}}
14+
// CHECK: {{.*}}Num SubDevices : {{.*}}
15+
// CHECK-NEXT: {{.*}}Num SubSubDevices : {{.*}}

sycl/tools/sycl-ls/sycl-ls.cpp

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <iostream>
2323
#include <map>
2424
#include <stdlib.h>
25+
#include <string>
2526
#include <vector>
2627

2728
#ifdef _WIN32
@@ -68,6 +69,43 @@ std::string getDeviceTypeName(const device &Device) {
6869
}
6970
}
7071

72+
template <typename RangeTy, typename ElemTy>
73+
bool contains(RangeTy &&Range, const ElemTy &Elem) {
74+
return std::find(Range.begin(), Range.end(), Elem) != Range.end();
75+
}
76+
77+
bool isPartitionableBy(const device &Dev, info::partition_property Prop) {
78+
return contains(Dev.get_info<info::device::partition_properties>(), Prop);
79+
}
80+
81+
std::array<int, 2> GetNumberOfSubAndSubSubDevices(const device &Device) {
82+
int NumSubDevices = 0;
83+
int NumSubSubDevices = 0;
84+
85+
// Assume a composite device hierarchy and try to partition Device by
86+
// affinity.
87+
if (isPartitionableBy(
88+
Device, info::partition_property::partition_by_affinity_domain)) {
89+
auto SubDevs = Device.create_sub_devices<
90+
info::partition_property::partition_by_affinity_domain>(
91+
info::partition_affinity_domain::next_partitionable);
92+
NumSubDevices = SubDevs.size();
93+
NumSubSubDevices = GetNumberOfSubAndSubSubDevices(SubDevs[0])[0];
94+
} else if (isPartitionableBy(
95+
Device,
96+
info::partition_property::ext_intel_partition_by_cslice)) {
97+
auto SubDevs = Device.create_sub_devices<
98+
info::partition_property::ext_intel_partition_by_cslice>();
99+
NumSubDevices = SubDevs.size();
100+
// CCSs can't be divided further.
101+
NumSubSubDevices = 0;
102+
} else {
103+
// Not partitionable for OpenCL, CUDA, and HIP backends.
104+
}
105+
106+
return {NumSubDevices, NumSubDevices * NumSubSubDevices};
107+
}
108+
71109
static void printDeviceInfo(const device &Device, bool Verbose,
72110
const std::string &Prepend) {
73111
auto DeviceVersion = Device.get_info<info::device::version>();
@@ -76,14 +114,35 @@ static void printDeviceInfo(const device &Device, bool Verbose,
76114
auto DeviceDriverVersion = Device.get_info<info::device::driver_version>();
77115

78116
if (Verbose) {
79-
std::cout << Prepend << "Type : " << getDeviceTypeName(Device)
117+
std::cout << Prepend << "Type : " << getDeviceTypeName(Device)
118+
<< std::endl;
119+
std::cout << Prepend << "Version : " << DeviceVersion
80120
<< std::endl;
81-
std::cout << Prepend << "Version : " << DeviceVersion << std::endl;
82-
std::cout << Prepend << "Name : " << DeviceName << std::endl;
83-
std::cout << Prepend << "Vendor : " << DeviceVendor << std::endl;
84-
std::cout << Prepend << "Driver : " << DeviceDriverVersion << std::endl;
121+
std::cout << Prepend << "Name : " << DeviceName << std::endl;
122+
std::cout << Prepend << "Vendor : " << DeviceVendor << std::endl;
123+
std::cout << Prepend << "Driver : " << DeviceDriverVersion
124+
<< std::endl;
125+
126+
// Get and print device UUID, if it is available.
127+
if (Device.has(aspect::ext_intel_device_info_uuid)) {
128+
auto UUID = Device.get_info<sycl::ext::intel::info::device::uuid>();
129+
std::cout << Prepend << "UUID : ";
130+
for (int i = 0; i < 16; i++) {
131+
std::cout << std::to_string(UUID[i]);
132+
}
133+
std::cout << std::endl;
134+
}
135+
136+
// Print sub and sub-sub devices.
137+
{
138+
auto DevCount = GetNumberOfSubAndSubSubDevices(Device);
139+
std::cout << Prepend << "Num SubDevices : " << DevCount[0]
140+
<< std::endl;
141+
std::cout << Prepend << "Num SubSubDevices : " << DevCount[1]
142+
<< std::endl;
143+
}
85144

86-
std::cout << Prepend << "Aspects :";
145+
std::cout << Prepend << "Aspects :";
87146
#define __SYCL_ASPECT(ASPECT, ID) \
88147
if (Device.has(aspect::ASPECT)) \
89148
std::cout << " " << #ASPECT;

0 commit comments

Comments
 (0)