Skip to content

Commit fc0e4b2

Browse files
Added 3 new device attributes per gh-886
These are DPCTLDevice_GetGlobalMemCacheSize, DPCTLDevice_GlobalMemCacheLineSize, and DPCTLDevice_GetGlobalMemCacheType. To support the latter, introduced DPCTLGlobalMemCacheType enum in dpctl_sycl_enum_types.h Tests are added to test_capi target.
1 parent 5b3a819 commit fc0e4b2

File tree

4 files changed

+140
-3
lines changed

4 files changed

+140
-3
lines changed

libsyclinterface/include/dpctl_sycl_device_interface.h

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,6 @@ DPCTL_API
492492
__dpctl_give DPCTLDeviceVectorRef DPCTLDevice_CreateSubDevicesByAffinity(
493493
__dpctl_keep const DPCTLSyclDeviceRef DRef,
494494
DPCTLPartitionAffinityDomainType PartAffDomTy);
495-
496-
DPCTL_C_EXTERN_C_END
497-
498495
/*!
499496
* @brief Wrapper over
500497
* device.get_info<info::device::sub_group_independent_forward_progress>.
@@ -631,3 +628,38 @@ size_t DPCTLDevice_Hash(__dpctl_keep const DPCTLSyclDeviceRef DRef);
631628
DPCTL_API
632629
size_t DPCTLDevice_GetProfilingTimerResolution(
633630
__dpctl_keep const DPCTLSyclDeviceRef DRef);
631+
632+
/*!
633+
* @brief Wrapper over
634+
* device.get_info<info::device::global_mem_cache_line_size>
635+
*
636+
* @param DRef Opaque pointer to a sycl::device
637+
* @return Returns the size of global memory cache line in bytes as uint32_t.
638+
*/
639+
DPCTL_API
640+
uint32_t DPCTLDevice_GetGlobalMemCacheLineSize(
641+
__dpctl_keep const DPCTLSyclDeviceRef DRef);
642+
643+
/*!
644+
* @brief Wrapper over
645+
* device.get_info<info::device::global_mem_cache_size>
646+
*
647+
* @param DRef Opaque pointer to a sycl::device
648+
* @return Returns the size of global memory cache in bytes as uint64_t.
649+
*/
650+
DPCTL_API
651+
uint64_t
652+
DPCTLDevice_GetGlobalMemCacheSize(__dpctl_keep const DPCTLSyclDeviceRef DRef);
653+
654+
/*!
655+
* @brief Wrapper over
656+
* device.get_info<info::device::global_mem_cache_type>
657+
*
658+
* @param DRef Opaque pointer to a sycl::device
659+
* @return Returns the type of global memory cache supported.
660+
*/
661+
DPCTL_API
662+
DPCTLGlobalMemCacheType
663+
DPCTLDevice_GetGlobalMemCacheType(__dpctl_keep const DPCTLSyclDeviceRef DRef);
664+
665+
DPCTL_C_EXTERN_C_END

libsyclinterface/include/dpctl_sycl_enum_types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,12 @@ typedef enum
161161
DPCTL_COMPLETE
162162
} DPCTLSyclEventStatusType;
163163

164+
typedef enum
165+
{
166+
DPCTL_MEM_CACHE_TYPE_INDETERMINATE,
167+
DPCTL_MEM_CACHE_TYPE_NONE,
168+
DPCTL_MEM_CACHE_TYPE_READ_ONLY,
169+
DPCTL_MEM_CACHE_TYPE_READ_WRITE
170+
} DPCTLGlobalMemCacheType;
171+
164172
DPCTL_C_EXTERN_C_END

libsyclinterface/source/dpctl_sycl_device_interface.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,3 +691,54 @@ size_t DPCTLDevice_GetProfilingTimerResolution(
691691
return 0;
692692
}
693693
}
694+
695+
uint32_t DPCTLDevice_GetGlobalMemCacheLineSize(
696+
__dpctl_keep const DPCTLSyclDeviceRef DRef)
697+
{
698+
if (DRef) {
699+
auto D = unwrap(DRef);
700+
return D->get_info<info::device::global_mem_cache_line_size>();
701+
}
702+
else {
703+
error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
704+
return 0;
705+
}
706+
}
707+
708+
uint64_t
709+
DPCTLDevice_GetGlobalMemCacheSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
710+
{
711+
if (DRef) {
712+
auto D = unwrap(DRef);
713+
return D->get_info<info::device::global_mem_cache_size>();
714+
}
715+
else {
716+
error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
717+
return 0;
718+
}
719+
}
720+
721+
DPCTLGlobalMemCacheType
722+
DPCTLDevice_GetGlobalMemCacheType(__dpctl_keep const DPCTLSyclDeviceRef DRef)
723+
{
724+
if (DRef) {
725+
auto D = unwrap(DRef);
726+
auto mem_type = D->get_info<info::device::global_mem_cache_type>();
727+
switch (mem_type) {
728+
case info::global_mem_cache_type::none:
729+
return DPCTL_MEM_CACHE_TYPE_NONE;
730+
case info::global_mem_cache_type::read_only:
731+
return DPCTL_MEM_CACHE_TYPE_READ_ONLY;
732+
case info::global_mem_cache_type::read_write:
733+
return DPCTL_MEM_CACHE_TYPE_READ_WRITE;
734+
}
735+
// If execution reaches here unrecognized mem_type was returned. Check
736+
// values in the enumeration `info::global_mem_cache_type` in SYCL specs
737+
assert(false);
738+
return DPCTL_MEM_CACHE_TYPE_INDETERMINATE;
739+
}
740+
else {
741+
error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
742+
return DPCTL_MEM_CACHE_TYPE_INDETERMINATE;
743+
}
744+
}

libsyclinterface/tests/test_sycl_device_interface.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,30 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkGetProfilingTimerResolution)
407407
EXPECT_TRUE(res != 0);
408408
}
409409

410+
TEST_P(TestDPCTLSyclDeviceInterface, ChkGetGlobalMemCacheSize)
411+
{
412+
uint64_t res = 0;
413+
EXPECT_NO_FATAL_FAILURE(res = DPCTLDevice_GetGlobalMemCacheSize(DRef));
414+
EXPECT_TRUE(res != 0);
415+
}
416+
417+
TEST_P(TestDPCTLSyclDeviceInterface, ChkGetGlobalMemCacheLineSize)
418+
{
419+
uint32_t res = 0;
420+
EXPECT_NO_FATAL_FAILURE(res = DPCTLDevice_GetGlobalMemCacheLineSize(DRef));
421+
EXPECT_TRUE(res != 0);
422+
}
423+
424+
TEST_P(TestDPCTLSyclDeviceInterface, ChkGetGlobalMemCacheType)
425+
{
426+
DPCTLGlobalMemCacheType res = DPCTL_MEM_CACHE_TYPE_INDETERMINATE;
427+
EXPECT_NO_FATAL_FAILURE(res = DPCTLDevice_GetGlobalMemCacheType(DRef));
428+
EXPECT_TRUE(res != DPCTL_MEM_CACHE_TYPE_INDETERMINATE);
429+
EXPECT_TRUE((res == DPCTL_MEM_CACHE_TYPE_NONE ||
430+
res == DPCTL_MEM_CACHE_TYPE_READ_ONLY ||
431+
res == DPCTL_MEM_CACHE_TYPE_READ_WRITE));
432+
}
433+
410434
INSTANTIATE_TEST_SUITE_P(DPCTLDeviceFns,
411435
TestDPCTLSyclDeviceInterface,
412436
::testing::Values("opencl",
@@ -713,3 +737,25 @@ TEST_F(TestDPCTLSyclDeviceNullArgs, ChkGetProfilingTimerResolution)
713737
res = DPCTLDevice_GetProfilingTimerResolution(Null_DRef));
714738
ASSERT_TRUE(res == 0);
715739
}
740+
741+
TEST_F(TestDPCTLSyclDeviceNullArgs, ChkGetGlobalMemCacheSize)
742+
{
743+
uint64_t res = 1;
744+
EXPECT_NO_FATAL_FAILURE(res = DPCTLDevice_GetGlobalMemCacheSize(Null_DRef));
745+
ASSERT_TRUE(res == 0);
746+
}
747+
748+
TEST_F(TestDPCTLSyclDeviceNullArgs, ChkGetGlobalMemCacheLineSize)
749+
{
750+
uint32_t res = 1;
751+
EXPECT_NO_FATAL_FAILURE(
752+
res = DPCTLDevice_GetGlobalMemCacheLineSize(Null_DRef));
753+
ASSERT_TRUE(res == 0);
754+
}
755+
756+
TEST_F(TestDPCTLSyclDeviceNullArgs, ChkGetGlobalMemCacheType)
757+
{
758+
DPCTLGlobalMemCacheType res = DPCTL_MEM_CACHE_TYPE_NONE;
759+
EXPECT_NO_FATAL_FAILURE(res = DPCTLDevice_GetGlobalMemCacheType(Null_DRef));
760+
ASSERT_TRUE(res == DPCTL_MEM_CACHE_TYPE_INDETERMINATE);
761+
}

0 commit comments

Comments
 (0)