Skip to content

[SYCL] Add UUID and sub-, sub-sub- device info in sycl-ls --verbose #13999

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 4 commits into from
Jun 4, 2024
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
15 changes: 15 additions & 0 deletions sycl/test-e2e/Plugin/sycl-ls-uuid-subdevs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Test to check that sycl-ls is outputting UUID and number of sub and sub-sub
* devices. */
// REQUIRES: gpu, level_zero
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this work on Gen12 ? Or is it PVC only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should work on Gen12 as well. The test passes on Gen12 precommit: https://github.com/intel/llvm/actions/runs/9343215312/job/25714501971


// UNSUPPORTED: gpu-intel-pvc-1T

// As of now, ZEX_NUMBER_OF_CCS is not working with FLAT hierachy,
// which is the new default on PVC.

// 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
// RUN: FileCheck %s --input-file %t.default.out

// CHECK: {{.*}}UUID : {{.*}}
// CHECK: {{.*}}Num SubDevices : {{.*}}
// CHECK-NEXT: {{.*}}Num SubSubDevices : {{.*}}
71 changes: 65 additions & 6 deletions sycl/tools/sycl-ls/sycl-ls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <iostream>
#include <map>
#include <stdlib.h>
#include <string>
#include <vector>

#ifdef _WIN32
Expand Down Expand Up @@ -68,6 +69,43 @@ std::string getDeviceTypeName(const device &Device) {
}
}

template <typename RangeTy, typename ElemTy>
bool contains(RangeTy &&Range, const ElemTy &Elem) {
return std::find(Range.begin(), Range.end(), Elem) != Range.end();
}

bool isPartitionableBy(const device &Dev, info::partition_property Prop) {
return contains(Dev.get_info<info::device::partition_properties>(), Prop);
}

std::array<int, 2> GetNumberOfSubAndSubSubDevices(const device &Device) {
int NumSubDevices = 0;
int NumSubSubDevices = 0;

// Assume a composite device hierarchy and try to partition Device by
// affinity.
if (isPartitionableBy(
Device, info::partition_property::partition_by_affinity_domain)) {
auto SubDevs = Device.create_sub_devices<
info::partition_property::partition_by_affinity_domain>(
info::partition_affinity_domain::next_partitionable);
NumSubDevices = SubDevs.size();
NumSubSubDevices = GetNumberOfSubAndSubSubDevices(SubDevs[0])[0];
} else if (isPartitionableBy(
Device,
info::partition_property::ext_intel_partition_by_cslice)) {
auto SubDevs = Device.create_sub_devices<
info::partition_property::ext_intel_partition_by_cslice>();
NumSubDevices = SubDevs.size();
// CCSs can't be divided further.
NumSubSubDevices = 0;
} else {
// Not partitionable for OpenCL, CUDA, and HIP backends.
}

return {NumSubDevices, NumSubDevices * NumSubSubDevices};
}

static void printDeviceInfo(const device &Device, bool Verbose,
const std::string &Prepend) {
auto DeviceVersion = Device.get_info<info::device::version>();
Expand All @@ -76,14 +114,35 @@ static void printDeviceInfo(const device &Device, bool Verbose,
auto DeviceDriverVersion = Device.get_info<info::device::driver_version>();

if (Verbose) {
std::cout << Prepend << "Type : " << getDeviceTypeName(Device)
std::cout << Prepend << "Type : " << getDeviceTypeName(Device)
<< std::endl;
std::cout << Prepend << "Version : " << DeviceVersion
<< std::endl;
std::cout << Prepend << "Version : " << DeviceVersion << std::endl;
std::cout << Prepend << "Name : " << DeviceName << std::endl;
std::cout << Prepend << "Vendor : " << DeviceVendor << std::endl;
std::cout << Prepend << "Driver : " << DeviceDriverVersion << std::endl;
std::cout << Prepend << "Name : " << DeviceName << std::endl;
std::cout << Prepend << "Vendor : " << DeviceVendor << std::endl;
std::cout << Prepend << "Driver : " << DeviceDriverVersion
<< std::endl;

// Get and print device UUID, if it is available.
if (Device.has(aspect::ext_intel_device_info_uuid)) {
auto UUID = Device.get_info<sycl::ext::intel::info::device::uuid>();
std::cout << Prepend << "UUID : ";
for (int i = 0; i < 16; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you be using ZE_MAX_DEVICE_UUID_SIZE instead of assuming size is 16

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is documented as 16 then ok.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just use a range-based for loop on UUID

std::cout << std::to_string(UUID[i]);
}
std::cout << std::endl;
}

// Print sub and sub-sub devices.
{
auto DevCount = GetNumberOfSubAndSubSubDevices(Device);
std::cout << Prepend << "Num SubDevices : " << DevCount[0]
<< std::endl;
std::cout << Prepend << "Num SubSubDevices : " << DevCount[1]
<< std::endl;
}

std::cout << Prepend << "Aspects :";
std::cout << Prepend << "Aspects :";
#define __SYCL_ASPECT(ASPECT, ID) \
if (Device.has(aspect::ASPECT)) \
std::cout << " " << #ASPECT;
Expand Down