Skip to content

Commit f3b5aa6

Browse files
Added max_work_item_sizes1d, 2d, 3d properties
dpctl.SyclDevice.max_work_iterm_sizes is deprecated.
1 parent 52254ea commit f3b5aa6

File tree

6 files changed

+172
-30
lines changed

6 files changed

+172
-30
lines changed

dpctl/_backend.pxd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ cdef extern from "syclinterface/dpctl_sycl_device_interface.h":
157157
cdef uint32_t DPCTLDevice_GetMaxNumSubGroups(const DPCTLSyclDeviceRef DRef)
158158
cdef size_t DPCTLDevice_GetMaxWorkGroupSize(const DPCTLSyclDeviceRef DRef)
159159
cdef uint32_t DPCTLDevice_GetMaxWorkItemDims(const DPCTLSyclDeviceRef DRef)
160-
cdef size_t *DPCTLDevice_GetMaxWorkItemSizes(const DPCTLSyclDeviceRef DRef)
160+
cdef size_t *DPCTLDevice_GetMaxWorkItemSizes1d(const DPCTLSyclDeviceRef DRef)
161+
cdef size_t *DPCTLDevice_GetMaxWorkItemSizes2d(const DPCTLSyclDeviceRef DRef)
162+
cdef size_t *DPCTLDevice_GetMaxWorkItemSizes3d(const DPCTLSyclDeviceRef DRef)
161163
cdef const char *DPCTLDevice_GetName(const DPCTLSyclDeviceRef DRef)
162164
cdef DPCTLSyclPlatformRef DPCTLDevice_GetPlatform(
163165
const DPCTLSyclDeviceRef DRef)

dpctl/_sycl_device.pyx

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ from ._backend cimport ( # noqa: E211
4646
DPCTLDevice_GetMaxReadImageArgs,
4747
DPCTLDevice_GetMaxWorkGroupSize,
4848
DPCTLDevice_GetMaxWorkItemDims,
49-
DPCTLDevice_GetMaxWorkItemSizes,
49+
DPCTLDevice_GetMaxWorkItemSizes1d,
50+
DPCTLDevice_GetMaxWorkItemSizes2d,
51+
DPCTLDevice_GetMaxWorkItemSizes3d,
5052
DPCTLDevice_GetMaxWriteImageArgs,
5153
DPCTLDevice_GetName,
5254
DPCTLDevice_GetParentDevice,
@@ -185,7 +187,7 @@ cdef void _init_helper(_SyclDevice device, DPCTLSyclDeviceRef DRef):
185187
device._name = DPCTLDevice_GetName(DRef)
186188
device._driver_version = DPCTLDevice_GetDriverVersion(DRef)
187189
device._vendor = DPCTLDevice_GetVendor(DRef)
188-
device._max_work_item_sizes = DPCTLDevice_GetMaxWorkItemSizes(DRef)
190+
device._max_work_item_sizes = DPCTLDevice_GetMaxWorkItemSizes3d(DRef)
189191

190192

191193
cdef class SyclDevice(_SyclDevice):
@@ -263,7 +265,7 @@ cdef class SyclDevice(_SyclDevice):
263265
self._name = DPCTLDevice_GetName(self._device_ref)
264266
self._driver_version = DPCTLDevice_GetDriverVersion(self._device_ref)
265267
self._max_work_item_sizes = (
266-
DPCTLDevice_GetMaxWorkItemSizes(self._device_ref)
268+
DPCTLDevice_GetMaxWorkItemSizes3d(self._device_ref)
267269
)
268270
self._vendor = DPCTLDevice_GetVendor(self._device_ref)
269271
return 0
@@ -648,13 +650,62 @@ cdef class SyclDevice(_SyclDevice):
648650
max_work_item_dims = DPCTLDevice_GetMaxWorkItemDims(self._device_ref)
649651
return max_work_item_dims
650652

653+
@property
654+
def max_work_item_sizes1d(self):
655+
""" Returns the maximum number of work-items that are permitted in each
656+
dimension of the work-group of the nd_range<1>. The minimum value is
657+
`(1 )` for devices that are not of device type
658+
``info::device_type::custom``.
659+
"""
660+
cdef size_t *max_work_item_sizes1d = NULL
661+
max_work_item_sizes1d = DPCTLDevice_GetMaxWorkItemSizes1d(
662+
self._device_ref
663+
)
664+
res = (max_work_item_sizes1d[0], )
665+
DPCTLSize_t_Array_Delete(max_work_item_sizes1d)
666+
return res
667+
668+
@property
669+
def max_work_item_sizes2d(self):
670+
""" Returns the maximum number of work-items that are permitted in each
671+
dimension of the work-group of the nd_range<2>. The minimum value is
672+
`(1; 1)` for devices that are not of device type
673+
``info::device_type::custom``.
674+
"""
675+
cdef size_t *max_work_item_sizes2d = NULL
676+
max_work_item_sizes2d = DPCTLDevice_GetMaxWorkItemSizes2d(
677+
self._device_ref
678+
)
679+
res = (max_work_item_sizes2d[0], max_work_item_sizes2d[1],)
680+
DPCTLSize_t_Array_Delete(max_work_item_sizes2d)
681+
return res
682+
683+
@property
684+
def max_work_item_sizes3d(self):
685+
""" Returns the maximum number of work-items that are permitted in each
686+
dimension of the work-group of the nd_range<3>. The minimum value is
687+
`(1; 1; 1)` for devices that are not of device type
688+
``info::device_type::custom``.
689+
"""
690+
return (
691+
self._max_work_item_sizes[0],
692+
self._max_work_item_sizes[1],
693+
self._max_work_item_sizes[2],
694+
)
695+
651696
@property
652697
def max_work_item_sizes(self):
653698
""" Returns the maximum number of work-items that are permitted in each
654699
dimension of the work-group of the nd_range. The minimum value is
655700
`(1; 1; 1)` for devices that are not of device type
656701
``info::device_type::custom``.
657702
"""
703+
import warnings
704+
warnings.warn(
705+
"Use dpctl.SyclDevice.max_work_item_sizes3d",
706+
DeprecationWarning,
707+
stacklevel=2
708+
)
658709
return (
659710
self._max_work_item_sizes[0],
660711
self._max_work_item_sizes[1],

dpctl/tests/test_sycl_device.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,20 @@ def check_get_max_work_item_dims(device):
7676
assert max_work_item_dims > 0
7777

7878

79-
def check_get_max_work_item_sizes(device):
80-
max_work_item_sizes = device.max_work_item_sizes
79+
def check_get_max_work_item_sizes1d(device):
80+
max_work_item_sizes = device.max_work_item_sizes1d
81+
for size in max_work_item_sizes:
82+
assert size is not None
83+
84+
85+
def check_get_max_work_item_sizes2d(device):
86+
max_work_item_sizes = device.max_work_item_sizes2d
87+
for size in max_work_item_sizes:
88+
assert size is not None
89+
90+
91+
def check_get_max_work_item_sizes3d(device):
92+
max_work_item_sizes = device.max_work_item_sizes3d
8193
for size in max_work_item_sizes:
8294
assert size is not None
8395

@@ -518,7 +530,9 @@ def check_platform(device):
518530
list_of_checks = [
519531
check_get_max_compute_units,
520532
check_get_max_work_item_dims,
521-
check_get_max_work_item_sizes,
533+
check_get_max_work_item_sizes1d,
534+
check_get_max_work_item_sizes2d,
535+
check_get_max_work_item_sizes3d,
522536
check_get_max_work_group_size,
523537
check_get_max_num_sub_groups,
524538
check_is_accelerator,

dpctl/tests/test_sycl_queue.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,20 @@ def check_get_max_work_item_dims(device):
6868
assert max_work_item_dims > 0
6969

7070

71-
def check_get_max_work_item_sizes(device):
72-
max_work_item_sizes = device.max_work_item_sizes
71+
def check_get_max_work_item_sizes1d(device):
72+
max_work_item_sizes = device.max_work_item_sizes1d
73+
for size in max_work_item_sizes:
74+
assert size is not None
75+
76+
77+
def check_get_max_work_item_sizes2d(device):
78+
max_work_item_sizes = device.max_work_item_sizes2d
79+
for size in max_work_item_sizes:
80+
assert size is not None
81+
82+
83+
def check_get_max_work_item_sizes3d(device):
84+
max_work_item_sizes = device.max_work_item_sizes3d
7385
for size in max_work_item_sizes:
7486
assert size is not None
7587

@@ -263,7 +275,9 @@ def check_is_host(device):
263275
list_of_checks = [
264276
check_get_max_compute_units,
265277
check_get_max_work_item_dims,
266-
check_get_max_work_item_sizes,
278+
check_get_max_work_item_sizes1d,
279+
check_get_max_work_item_sizes2d,
280+
check_get_max_work_item_sizes3d,
267281
check_get_max_work_group_size,
268282
check_get_max_num_sub_groups,
269283
check_is_accelerator,

libsyclinterface/include/dpctl_sycl_device_interface.h

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,50 @@ uint32_t
211211
DPCTLDevice_GetMaxWorkItemDims(__dpctl_keep const DPCTLSyclDeviceRef DRef);
212212

213213
/*!
214-
* @brief Wrapper for get_info<info::device::max_work_item_sizes>().
214+
* @brief Wrapper for get_info<info::device::max_work_item_sizes<1>>().
215215
*
216216
* @param DRef Opaque pointer to a ``sycl::device``
217217
* @return Returns the valid result if device exists else returns NULL.
218218
* @ingroup DeviceInterface
219219
*/
220220
DPCTL_API
221221
__dpctl_keep size_t *
222-
DPCTLDevice_GetMaxWorkItemSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef);
222+
DPCTLDevice_GetMaxWorkItemSizes1d(__dpctl_keep const DPCTLSyclDeviceRef DRef);
223+
224+
/*!
225+
* @brief Wrapper for get_info<info::device::max_work_item_sizes<2>>().
226+
*
227+
* @param DRef Opaque pointer to a ``sycl::device``
228+
* @return Returns the valid result if device exists else returns NULL.
229+
* @ingroup DeviceInterface
230+
*/
231+
DPCTL_API
232+
__dpctl_keep size_t *
233+
DPCTLDevice_GetMaxWorkItemSizes2d(__dpctl_keep const DPCTLSyclDeviceRef DRef);
234+
235+
/*!
236+
* @brief Wrapper for get_info<info::device::max_work_item_sizes<3>>().
237+
*
238+
* @param DRef Opaque pointer to a ``sycl::device``
239+
* @return Returns the valid result if device exists else returns NULL.
240+
* @ingroup DeviceInterface
241+
*/
242+
DPCTL_API
243+
__dpctl_keep size_t *
244+
DPCTLDevice_GetMaxWorkItemSizes3d(__dpctl_keep const DPCTLSyclDeviceRef DRef);
245+
246+
/*!
247+
* @brief Wrapper for deprecated get_info<info::device::max_work_item_sizes>().
248+
*
249+
* @param DRef Opaque pointer to a ``sycl::device``
250+
* @return Returns the valid result if device exists else returns NULL.
251+
* @ingroup DeviceInterface
252+
*/
253+
DPCTL_API
254+
__dpctl_keep size_t *
255+
DPCTLDevice_GetMaxWorkItemSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef)
256+
__attribute__((deprecated("DPCTLDevice_GetMaxWorkItemSizes is deprecated ",
257+
"Use DPCTLDevice_WorkItemSizes3d instead")));
223258

224259
/*!
225260
* @brief Wrapper for get_info<info::device::max_work_group_size>().

libsyclinterface/source/dpctl_sycl_device_interface.cpp

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,31 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(platform, DPCTLSyclPlatformRef)
4646
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector<DPCTLSyclDeviceRef>,
4747
DPCTLDeviceVectorRef)
4848

49+
template <int dim>
50+
__dpctl_keep size_t *
51+
DPCTLDevice__GetMaxWorkItemSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef)
52+
{
53+
size_t *sizes = nullptr;
54+
auto D = unwrap(DRef);
55+
if (D) {
56+
try {
57+
#if __SYCL_COMPILER_VERSION >= 20220805
58+
auto id_sizes =
59+
D->get_info<info::device::max_work_item_sizes<dim>>();
60+
#else
61+
auto id_sizes = D->get_info<info::device::max_work_item_sizes>();
62+
#endif
63+
sizes = new size_t[dim];
64+
for (auto i = 0ul; i < dim; ++i) {
65+
sizes[i] = id_sizes[i];
66+
}
67+
} catch (std::exception const &e) {
68+
error_handler(e, __FILE__, __func__, __LINE__);
69+
}
70+
}
71+
return sizes;
72+
}
73+
4974
} /* end of anonymous namespace */
5075

5176
__dpctl_give DPCTLSyclDeviceRef
@@ -225,27 +250,28 @@ DPCTLDevice_GetMaxWorkItemDims(__dpctl_keep const DPCTLSyclDeviceRef DRef)
225250
return maxWorkItemDims;
226251
}
227252

253+
__dpctl_keep size_t *
254+
DPCTLDevice_GetMaxWorkItemSizes1d(__dpctl_keep const DPCTLSyclDeviceRef DRef)
255+
{
256+
return DPCTLDevice__GetMaxWorkItemSizes<1>(DRef);
257+
}
258+
259+
__dpctl_keep size_t *
260+
DPCTLDevice_GetMaxWorkItemSizes2d(__dpctl_keep const DPCTLSyclDeviceRef DRef)
261+
{
262+
return DPCTLDevice__GetMaxWorkItemSizes<2>(DRef);
263+
}
264+
265+
__dpctl_keep size_t *
266+
DPCTLDevice_GetMaxWorkItemSizes3d(__dpctl_keep const DPCTLSyclDeviceRef DRef)
267+
{
268+
return DPCTLDevice__GetMaxWorkItemSizes<3>(DRef);
269+
}
270+
228271
__dpctl_keep size_t *
229272
DPCTLDevice_GetMaxWorkItemSizes(__dpctl_keep const DPCTLSyclDeviceRef DRef)
230273
{
231-
size_t *sizes = nullptr;
232-
auto D = unwrap(DRef);
233-
if (D) {
234-
try {
235-
#if __SYCL_COMPILER_VERSION >= 20220805
236-
auto id_sizes = D->get_info<info::device::max_work_item_sizes<3>>();
237-
#else
238-
auto id_sizes = D->get_info<info::device::max_work_item_sizes>();
239-
#endif
240-
sizes = new size_t[3];
241-
for (auto i = 0ul; i < 3; ++i) {
242-
sizes[i] = id_sizes[i];
243-
}
244-
} catch (std::exception const &e) {
245-
error_handler(e, __FILE__, __func__, __LINE__);
246-
}
247-
}
248-
return sizes;
274+
return DPCTLDevice__GetMaxWorkItemSizes<3>(DRef);
249275
}
250276

251277
size_t

0 commit comments

Comments
 (0)