diff --git a/sycl/test-e2e/Plugin/sycl-ls-uuid-subdevs.cpp b/sycl/test-e2e/Plugin/sycl-ls-uuid-subdevs.cpp new file mode 100644 index 0000000000000..45650758bc756 --- /dev/null +++ b/sycl/test-e2e/Plugin/sycl-ls-uuid-subdevs.cpp @@ -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 + +// 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 : {{.*}} diff --git a/sycl/tools/sycl-ls/sycl-ls.cpp b/sycl/tools/sycl-ls/sycl-ls.cpp index a59b33c1de65d..f71221840d397 100644 --- a/sycl/tools/sycl-ls/sycl-ls.cpp +++ b/sycl/tools/sycl-ls/sycl-ls.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #ifdef _WIN32 @@ -68,6 +69,43 @@ std::string getDeviceTypeName(const device &Device) { } } +template +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(), Prop); +} + +std::array 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(); @@ -76,14 +114,35 @@ static void printDeviceInfo(const device &Device, bool Verbose, auto DeviceDriverVersion = Device.get_info(); 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(); + std::cout << Prepend << "UUID : "; + for (int i = 0; i < 16; i++) { + 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;