Skip to content

Commit 75aa0c1

Browse files
1e-toetotmeni
and
etotmeni
authored
Add device descriptors: sub_group_independent_forward_progress and preferred_vector_width (#308)
* Add sub_group_independent_forward_progress and preferred_vector_width_char * Add tests * Add python api * Fixes + tests * Add preferred_vector_width funcs * Added property Co-authored-by: etotmeni <[email protected]>
1 parent 064a6f3 commit 75aa0c1

File tree

6 files changed

+491
-0
lines changed

6 files changed

+491
-0
lines changed

dpctl-capi/include/dpctl_sycl_device_interface.h

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,99 @@ bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef,
266266
DPCTLSyclAspectType AT);
267267

268268
DPCTL_C_EXTERN_C_END
269+
270+
/*!
271+
* @brief Wrapper over
272+
* device.get_info<info::device::sub_group_independent_forward_progress>.
273+
*
274+
* @param DRef Opaque pointer to a sycl::device
275+
* @return Returns true if the device supports independent forward progress of
276+
* sub-groups with respect to other sub-groups in the same work-group.
277+
*/
278+
DPCTL_API
279+
bool DPCTLDevice_GetSubGroupIndependentForwardProgress(
280+
__dpctl_keep const DPCTLSyclDeviceRef DRef);
281+
282+
/*!
283+
* @brief Wrapper over
284+
* device.get_info<info::device::preferred_vector_width_char>.
285+
*
286+
* @param DRef Opaque pointer to a sycl::device
287+
* @return Returns the preferred native vector width size for built-in scalar
288+
* types that can be put into vectors.
289+
*/
290+
DPCTL_API
291+
uint32_t DPCTLDevice_GetPreferredVectorWidthChar(
292+
__dpctl_keep const DPCTLSyclDeviceRef DRef);
293+
294+
/*!
295+
* @brief Wrapper over
296+
* device.get_info<info::device::preferred_vector_width_short>.
297+
*
298+
* @param DRef Opaque pointer to a sycl::device
299+
* @return Returns the preferred native vector width size for built-in scalar
300+
* types that can be put into vectors.
301+
*/
302+
DPCTL_API
303+
uint32_t DPCTLDevice_GetPreferredVectorWidthShort(
304+
__dpctl_keep const DPCTLSyclDeviceRef DRef);
305+
306+
/*!
307+
* @brief Wrapper over
308+
* device.get_info<info::device::preferred_vector_width_int>.
309+
*
310+
* @param DRef Opaque pointer to a sycl::device
311+
* @return Returns the preferred native vector width size for built-in scalar
312+
* types that can be put into vectors.
313+
*/
314+
DPCTL_API
315+
uint32_t DPCTLDevice_GetPreferredVectorWidthInt(
316+
__dpctl_keep const DPCTLSyclDeviceRef DRef);
317+
318+
/*!
319+
* @brief Wrapper over
320+
* device.get_info<info::device::preferred_vector_width_long>.
321+
*
322+
* @param DRef Opaque pointer to a sycl::device
323+
* @return Returns the preferred native vector width size for built-in scalar
324+
* types that can be put into vectors.
325+
*/
326+
DPCTL_API
327+
uint32_t DPCTLDevice_GetPreferredVectorWidthLong(
328+
__dpctl_keep const DPCTLSyclDeviceRef DRef);
329+
330+
/*!
331+
* @brief Wrapper over
332+
* device.get_info<info::device::preferred_vector_width_float>.
333+
*
334+
* @param DRef Opaque pointer to a sycl::device
335+
* @return Returns the preferred native vector width size for built-in scalar
336+
* types that can be put into vectors.
337+
*/
338+
DPCTL_API
339+
uint32_t DPCTLDevice_GetPreferredVectorWidthFloat(
340+
__dpctl_keep const DPCTLSyclDeviceRef DRef);
341+
342+
/*!
343+
* @brief Wrapper over
344+
* device.get_info<info::device::preferred_vector_width_double>.
345+
*
346+
* @param DRef Opaque pointer to a sycl::device
347+
* @return Returns the preferred native vector width size for built-in scalar
348+
* types that can be put into vectors.
349+
*/
350+
DPCTL_API
351+
uint32_t DPCTLDevice_GetPreferredVectorWidthDouble(
352+
__dpctl_keep const DPCTLSyclDeviceRef DRef);
353+
354+
/*!
355+
* @brief Wrapper over
356+
* device.get_info<info::device::preferred_vector_width_half>.
357+
*
358+
* @param DRef Opaque pointer to a sycl::device
359+
* @return Returns the preferred native vector width size for built-in scalar
360+
* types that can be put into vectors.
361+
*/
362+
DPCTL_API
363+
uint32_t DPCTLDevice_GetPreferredVectorWidthHalf(
364+
__dpctl_keep const DPCTLSyclDeviceRef DRef);

dpctl-capi/source/dpctl_sycl_device_interface.cpp

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,139 @@ bool DPCTLDevice_HasAspect(__dpctl_keep const DPCTLSyclDeviceRef DRef,
387387
}
388388
return hasAspect;
389389
}
390+
391+
bool DPCTLDevice_GetSubGroupIndependentForwardProgress(
392+
__dpctl_keep const DPCTLSyclDeviceRef DRef)
393+
{
394+
bool SubGroupProgress = false;
395+
auto D = unwrap(DRef);
396+
if (D) {
397+
try {
398+
SubGroupProgress = D->get_info<
399+
info::device::sub_group_independent_forward_progress>();
400+
} catch (runtime_error const &re) {
401+
// \todo log error
402+
std::cerr << re.what() << '\n';
403+
}
404+
}
405+
return SubGroupProgress;
406+
}
407+
408+
uint32_t DPCTLDevice_GetPreferredVectorWidthChar(
409+
__dpctl_keep const DPCTLSyclDeviceRef DRef)
410+
{
411+
size_t vector_width_char = 0;
412+
auto D = unwrap(DRef);
413+
if (D) {
414+
try {
415+
vector_width_char =
416+
D->get_info<info::device::preferred_vector_width_char>();
417+
} catch (runtime_error const &re) {
418+
// \todo log error
419+
std::cerr << re.what() << '\n';
420+
}
421+
}
422+
return vector_width_char;
423+
}
424+
425+
uint32_t DPCTLDevice_GetPreferredVectorWidthShort(
426+
__dpctl_keep const DPCTLSyclDeviceRef DRef)
427+
{
428+
size_t vector_width_short = 0;
429+
auto D = unwrap(DRef);
430+
if (D) {
431+
try {
432+
vector_width_short =
433+
D->get_info<info::device::preferred_vector_width_short>();
434+
} catch (runtime_error const &re) {
435+
// \todo log error
436+
std::cerr << re.what() << '\n';
437+
}
438+
}
439+
return vector_width_short;
440+
}
441+
442+
uint32_t DPCTLDevice_GetPreferredVectorWidthInt(
443+
__dpctl_keep const DPCTLSyclDeviceRef DRef)
444+
{
445+
size_t vector_width_int = 0;
446+
auto D = unwrap(DRef);
447+
if (D) {
448+
try {
449+
vector_width_int =
450+
D->get_info<info::device::preferred_vector_width_int>();
451+
} catch (runtime_error const &re) {
452+
// \todo log error
453+
std::cerr << re.what() << '\n';
454+
}
455+
}
456+
return vector_width_int;
457+
}
458+
459+
uint32_t DPCTLDevice_GetPreferredVectorWidthLong(
460+
__dpctl_keep const DPCTLSyclDeviceRef DRef)
461+
{
462+
size_t vector_width_long = 0;
463+
auto D = unwrap(DRef);
464+
if (D) {
465+
try {
466+
vector_width_long =
467+
D->get_info<info::device::preferred_vector_width_long>();
468+
} catch (runtime_error const &re) {
469+
// \todo log error
470+
std::cerr << re.what() << '\n';
471+
}
472+
}
473+
return vector_width_long;
474+
}
475+
476+
uint32_t DPCTLDevice_GetPreferredVectorWidthFloat(
477+
__dpctl_keep const DPCTLSyclDeviceRef DRef)
478+
{
479+
size_t vector_width_float = 0;
480+
auto D = unwrap(DRef);
481+
if (D) {
482+
try {
483+
vector_width_float =
484+
D->get_info<info::device::preferred_vector_width_float>();
485+
} catch (runtime_error const &re) {
486+
// \todo log error
487+
std::cerr << re.what() << '\n';
488+
}
489+
}
490+
return vector_width_float;
491+
}
492+
493+
uint32_t DPCTLDevice_GetPreferredVectorWidthDouble(
494+
__dpctl_keep const DPCTLSyclDeviceRef DRef)
495+
{
496+
size_t vector_width_double = 0;
497+
auto D = unwrap(DRef);
498+
if (D) {
499+
try {
500+
vector_width_double =
501+
D->get_info<info::device::preferred_vector_width_double>();
502+
} catch (runtime_error const &re) {
503+
// \todo log error
504+
std::cerr << re.what() << '\n';
505+
}
506+
}
507+
return vector_width_double;
508+
}
509+
510+
uint32_t DPCTLDevice_GetPreferredVectorWidthHalf(
511+
__dpctl_keep const DPCTLSyclDeviceRef DRef)
512+
{
513+
size_t vector_width_half = 0;
514+
auto D = unwrap(DRef);
515+
if (D) {
516+
try {
517+
vector_width_half =
518+
D->get_info<info::device::preferred_vector_width_half>();
519+
} catch (runtime_error const &re) {
520+
// \todo log error
521+
std::cerr << re.what() << '\n';
522+
}
523+
}
524+
return vector_width_half;
525+
}

dpctl-capi/tests/test_sycl_device_interface.cpp

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
///
2525
//===----------------------------------------------------------------------===//
2626

27+
#include "../helper/include/dpctl_utils_helper.h"
2728
#include "dpctl_sycl_device_interface.h"
2829
#include "dpctl_sycl_device_selector_interface.h"
2930
#include "dpctl_sycl_platform_interface.h"
@@ -268,6 +269,128 @@ TEST_P(TestDPCTLSyclDeviceInterface, Chk_IsHost)
268269
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
269270
}
270271

272+
TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetSubGroupIndependentForwardProgress)
273+
{
274+
DPCTLSyclDeviceRef DRef = nullptr;
275+
bool sub_group_progress = 0;
276+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
277+
if (!DRef)
278+
GTEST_SKIP_("Device not found");
279+
EXPECT_NO_FATAL_FAILURE(
280+
sub_group_progress =
281+
DPCTLDevice_GetSubGroupIndependentForwardProgress(DRef));
282+
auto D = reinterpret_cast<device *>(DRef);
283+
auto get_sub_group_progress =
284+
D->get_info<info::device::sub_group_independent_forward_progress>();
285+
EXPECT_TRUE(get_sub_group_progress == sub_group_progress);
286+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
287+
}
288+
289+
TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetPreferredVectorWidthChar)
290+
{
291+
DPCTLSyclDeviceRef DRef = nullptr;
292+
size_t vector_width_char = 0;
293+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
294+
if (!DRef)
295+
GTEST_SKIP_("Device not found");
296+
EXPECT_NO_FATAL_FAILURE(vector_width_char =
297+
DPCTLDevice_GetPreferredVectorWidthChar(DRef));
298+
EXPECT_TRUE(vector_width_char != 0);
299+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
300+
}
301+
302+
TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetPreferredVectorWidthShort)
303+
{
304+
DPCTLSyclDeviceRef DRef = nullptr;
305+
size_t vector_width_short = 0;
306+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
307+
if (!DRef)
308+
GTEST_SKIP_("Device not found");
309+
EXPECT_NO_FATAL_FAILURE(vector_width_short =
310+
DPCTLDevice_GetPreferredVectorWidthShort(DRef));
311+
EXPECT_TRUE(vector_width_short != 0);
312+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
313+
}
314+
315+
TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetPreferredVectorWidthInt)
316+
{
317+
DPCTLSyclDeviceRef DRef = nullptr;
318+
size_t vector_width_int = 0;
319+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
320+
if (!DRef)
321+
GTEST_SKIP_("Device not found");
322+
EXPECT_NO_FATAL_FAILURE(vector_width_int =
323+
DPCTLDevice_GetPreferredVectorWidthInt(DRef));
324+
EXPECT_TRUE(vector_width_int != 0);
325+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
326+
}
327+
328+
TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetPreferredVectorWidthLong)
329+
{
330+
DPCTLSyclDeviceRef DRef = nullptr;
331+
size_t vector_width_long = 0;
332+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
333+
if (!DRef)
334+
GTEST_SKIP_("Device not found");
335+
EXPECT_NO_FATAL_FAILURE(vector_width_long =
336+
DPCTLDevice_GetPreferredVectorWidthLong(DRef));
337+
EXPECT_TRUE(vector_width_long != 0);
338+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
339+
}
340+
341+
TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetPreferredVectorWidthFloat)
342+
{
343+
DPCTLSyclDeviceRef DRef = nullptr;
344+
size_t vector_width_float = 0;
345+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
346+
if (!DRef)
347+
GTEST_SKIP_("Device not found");
348+
EXPECT_NO_FATAL_FAILURE(vector_width_float =
349+
DPCTLDevice_GetPreferredVectorWidthFloat(DRef));
350+
EXPECT_TRUE(vector_width_float != 0);
351+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
352+
}
353+
354+
TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetPreferredVectorWidthDouble)
355+
{
356+
DPCTLSyclDeviceRef DRef = nullptr;
357+
size_t vector_width_double = 0;
358+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
359+
if (!DRef)
360+
GTEST_SKIP_("Device not found");
361+
EXPECT_NO_FATAL_FAILURE(
362+
vector_width_double = DPCTLDevice_GetPreferredVectorWidthDouble(DRef));
363+
if (DPCTLDevice_HasAspect(DRef, DPCTL_SyclAspectToDPCTLAspectType(
364+
DPCTL_StrToAspectType("fp64"))))
365+
{
366+
EXPECT_TRUE(vector_width_double != 0);
367+
}
368+
else {
369+
EXPECT_TRUE(vector_width_double == 0);
370+
}
371+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
372+
}
373+
374+
TEST_P(TestDPCTLSyclDeviceInterface, Chk_GetPreferredVectorWidthHalf)
375+
{
376+
DPCTLSyclDeviceRef DRef = nullptr;
377+
size_t vector_width_half = 0;
378+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
379+
if (!DRef)
380+
GTEST_SKIP_("Device not found");
381+
EXPECT_NO_FATAL_FAILURE(vector_width_half =
382+
DPCTLDevice_GetPreferredVectorWidthHalf(DRef));
383+
if (DPCTLDevice_HasAspect(DRef, DPCTL_SyclAspectToDPCTLAspectType(
384+
DPCTL_StrToAspectType("fp16"))))
385+
{
386+
EXPECT_TRUE(vector_width_half != 0);
387+
}
388+
else {
389+
EXPECT_TRUE(vector_width_half == 0);
390+
}
391+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
392+
}
393+
271394
INSTANTIATE_TEST_SUITE_P(DPCTLDevice_Fns,
272395
TestDPCTLSyclDeviceInterface,
273396
::testing::Values("opencl",

dpctl/_backend.pxd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ cdef extern from "dpctl_sycl_device_interface.h":
153153
cdef bool DPCTLDevice_IsGPU(const DPCTLSyclDeviceRef DRef)
154154
cdef bool DPCTLDevice_IsHost(const DPCTLSyclDeviceRef DRef)
155155
cdef bool DPCTLDevice_IsHostUnifiedMemory(const DPCTLSyclDeviceRef DRef)
156+
cdef bool DPCTLDevice_GetSubGroupIndependentForwardProgress(const DPCTLSyclDeviceRef DRef)
157+
cdef uint32_t DPCTLDevice_GetPreferredVectorWidthChar(const DPCTLSyclDeviceRef DRef)
158+
cdef uint32_t DPCTLDevice_GetPreferredVectorWidthShort(const DPCTLSyclDeviceRef DRef)
159+
cdef uint32_t DPCTLDevice_GetPreferredVectorWidthInt(const DPCTLSyclDeviceRef DRef)
160+
cdef uint32_t DPCTLDevice_GetPreferredVectorWidthLong(const DPCTLSyclDeviceRef DRef)
161+
cdef uint32_t DPCTLDevice_GetPreferredVectorWidthFloat(const DPCTLSyclDeviceRef DRef)
162+
cdef uint32_t DPCTLDevice_GetPreferredVectorWidthDouble(const DPCTLSyclDeviceRef DRef)
163+
cdef uint32_t DPCTLDevice_GetPreferredVectorWidthHalf(const DPCTLSyclDeviceRef DRef)
156164
cpdef bool DPCTLDevice_HasAspect(
157165
const DPCTLSyclDeviceRef DRef, DPCTLSyclAspectType AT)
158166

0 commit comments

Comments
 (0)