Skip to content

Commit 8506b90

Browse files
Merge pull request #1005 from IntelPython/add-partition-max-sub-devices
2 parents d8704f0 + fc24fe9 commit 8506b90

File tree

9 files changed

+94
-1
lines changed

9 files changed

+94
-1
lines changed

dpctl/_backend.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ cdef extern from "syclinterface/dpctl_sycl_device_interface.h":
206206
const DPCTLSyclDeviceRef DRef)
207207
cdef size_t *DPCTLDevice_GetSubGroupSizes(const DPCTLSyclDeviceRef DRef,
208208
size_t *res_len)
209+
cdef uint32_t DPCTLDevice_GetPartitionMaxSubDevices(const DPCTLSyclDeviceRef DRef)
209210

210211

211212
cdef extern from "syclinterface/dpctl_sycl_device_manager.h":

dpctl/_sycl_device.pyx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ from ._backend cimport ( # noqa: E211
5555
DPCTLDevice_GetMaxWriteImageArgs,
5656
DPCTLDevice_GetName,
5757
DPCTLDevice_GetParentDevice,
58+
DPCTLDevice_GetPartitionMaxSubDevices,
5859
DPCTLDevice_GetPlatform,
5960
DPCTLDevice_GetPreferredVectorWidthChar,
6061
DPCTLDevice_GetPreferredVectorWidthDouble,
@@ -1292,9 +1293,25 @@ cdef class SyclDevice(_SyclDevice):
12921293
"""
12931294
cdef uint64_t cache_line_sz = DPCTLDevice_GetGlobalMemCacheLineSize(
12941295
self._device_ref
1295-
)
1296+
)
12961297
return cache_line_sz
12971298

1299+
@property
1300+
def partition_max_sub_devices(self):
1301+
""" The maximum number of sub-devices this :class:`dpctl.SyclDevice`
1302+
instance can be partitioned into. The value returned cannot exceed the
1303+
value returned by :attr:`dpctl.SyclDevice.max_compute_units`.
1304+
1305+
Returns:
1306+
int: The maximum number of sub-devices that can be created when this
1307+
device is partitioned. Zero value indicates that device can not
1308+
be partitioned.
1309+
"""
1310+
cdef uint32_t max_part = DPCTLDevice_GetPartitionMaxSubDevices(
1311+
self._device_ref
1312+
)
1313+
return max_part
1314+
12981315
cdef cpp_bool equals(self, SyclDevice other):
12991316
""" Returns ``True`` if the :class:`dpctl.SyclDevice` argument has the
13001317
same _device_ref as this SyclDevice.

dpctl/tests/_device_attributes_checks.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,13 @@ def check_parent_device(device):
540540
assert pd is None or isinstance(pd, dpctl.SyclDevice)
541541

542542

543+
def check_partition_max_sub_devices(device):
544+
max_part = device.partition_max_sub_devices
545+
assert isinstance(max_part, int)
546+
assert max_part >= 0
547+
assert max_part <= device.max_compute_units
548+
549+
543550
def check_filter_string(device):
544551
try:
545552
fs = device.filter_string
@@ -670,6 +677,7 @@ def check_global_mem_cache_line_size(device):
670677
check_profiling_timer_resolution,
671678
check_platform,
672679
check_parent_device,
680+
check_partition_max_sub_devices,
673681
check_filter_string,
674682
check_vendor,
675683
check_driver_version,

examples/pybind11/use_dpctl_syclqueue/tests/test_queue_device.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,11 @@ def test_get_sub_group_sizes():
6363
assert type(szs) is list
6464
assert all(type(el) is int for el in szs)
6565
szs == d.sub_group_sizes
66+
67+
68+
def test_get_partition_max_sub_devices():
69+
d = dpctl.SyclDevice()
70+
mt = uqd.get_partition_max_sub_devices(d)
71+
assert type(mt) is int
72+
assert mt >= 0
73+
assert mt <= d.max_compute_units

examples/pybind11/use_dpctl_syclqueue/use_queue_device/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
get_device_global_mem_size,
2121
get_device_local_mem_size,
2222
get_max_compute_units,
23+
get_partition_max_sub_devices,
2324
get_sub_group_sizes,
2425
offloaded_array_mod,
2526
)
@@ -30,6 +31,7 @@
3031
"get_device_local_mem_size",
3132
"offloaded_array_mod",
3233
"get_sub_group_sizes",
34+
"get_partition_max_sub_devices",
3335
]
3436

3537
__doc__ = """

examples/pybind11/use_dpctl_syclqueue/use_queue_device/_example.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ std::vector<std::size_t> get_sub_group_sizes(const sycl::device &d)
9090
return d.get_info<sycl::info::device::sub_group_sizes>();
9191
}
9292

93+
std::uint32_t get_partition_max_sub_devices(const sycl::device &d)
94+
{
95+
return d.get_info<sycl::info::device::partition_max_sub_devices>();
96+
}
97+
9398
PYBIND11_MODULE(_use_queue_device, m)
9499
{
95100
m.def(
@@ -108,4 +113,7 @@ PYBIND11_MODULE(_use_queue_device, m)
108113
"Compute offloaded modular reduction of integer-valued NumPy array");
109114
m.def("get_sub_group_sizes", &get_sub_group_sizes,
110115
"Gets info::device::sub_group_sizes property of given device");
116+
m.def("get_partition_max_sub_devices", &get_partition_max_sub_devices,
117+
"Gets info::device::partition_max_sub_devices for given "
118+
"dpctl.SyclDevice");
111119
}

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)