Skip to content

Commit bcfcf8b

Browse files
Add DPCTLDevice_GetPartionMaxSubDevices requested in #1004
1 parent a2edadb commit bcfcf8b

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

libsyclinterface/include/dpctl_sycl_device_interface.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,18 @@ DPCTL_API
597597
__dpctl_give DPCTLSyclDeviceRef
598598
DPCTLDevice_GetParentDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef);
599599

600+
/*!
601+
* @brief Wrapper over
602+
* device.get_info<info::device::partition_max_sub_devices>
603+
*
604+
* @param DRef Opaque pointer to a sycl::device
605+
* @return Returns the maximum number of sub-devices that can be created
606+
* when this device is partitioned.
607+
*/
608+
DPCTL_API
609+
uint32_t DPCTLDevice_GetPartitionMaxSubDevices(
610+
__dpctl_keep const DPCTLSyclDeviceRef DRef);
611+
600612
/*!
601613
* @brief Wrapper over
602614
* std::hash<sycl::device>'s operator()

libsyclinterface/source/dpctl_sycl_device_interface.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,24 @@ DPCTLDevice_GetParentDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef)
573573
return nullptr;
574574
}
575575

576+
uint32_t DPCTLDevice_GetPartitionMaxSubDevices(
577+
__dpctl_keep const DPCTLSyclDeviceRef DRef)
578+
{
579+
auto D = unwrap<device>(DRef);
580+
if (D) {
581+
try {
582+
uint32_t part_max_sub_devs =
583+
D->get_info<info::device::partition_max_sub_devices>();
584+
return part_max_sub_devs;
585+
} catch (std::exception const &e) {
586+
error_handler(e, __FILE__, __func__, __LINE__);
587+
return 0;
588+
}
589+
}
590+
else
591+
return 0;
592+
}
593+
576594
__dpctl_give DPCTLDeviceVectorRef
577595
DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef,
578596
size_t count)

libsyclinterface/tests/test_sycl_device_interface.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,17 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkGetParentDevice)
415415
EXPECT_TRUE(pDRef == nullptr);
416416
}
417417

418+
TEST_P(TestDPCTLSyclDeviceInterface, ChkGetPartitionMaxSubDevices)
419+
{
420+
uint32_t max_part = 0;
421+
size_t max_cu = 0;
422+
EXPECT_NO_FATAL_FAILURE(max_part =
423+
DPCTLDevice_GetPartitionMaxSubDevices(DRef));
424+
EXPECT_TRUE(max_part >= 0);
425+
EXPECT_NO_FATAL_FAILURE(max_cu = DPCTLDevice_GetMaxComputeUnits(DRef));
426+
EXPECT_TRUE(max_part <= max_cu);
427+
}
428+
418429
TEST_P(TestDPCTLSyclDeviceInterface, ChkGetProfilingTimerResolution)
419430
{
420431
size_t res = 0;
@@ -705,6 +716,14 @@ TEST_F(TestDPCTLSyclDeviceNullArgs, ChkGetParentDevice)
705716
ASSERT_TRUE(pDRef == nullptr);
706717
}
707718

719+
TEST_F(TestDPCTLSyclDeviceNullArgs, ChkGetPartitionMaxSubDevices)
720+
{
721+
uint32_t max_part = 0;
722+
EXPECT_NO_FATAL_FAILURE(
723+
max_part = DPCTLDevice_GetPartitionMaxSubDevices(Null_DRef));
724+
ASSERT_TRUE(max_part == 0);
725+
}
726+
708727
TEST_F(TestDPCTLSyclDeviceNullArgs, ChkCreateSubDevicesEqually)
709728
{
710729
DPCTLDeviceVectorRef DVRef = nullptr;

0 commit comments

Comments
 (0)