Skip to content

Commit

Permalink
Added 3 new device attributes per gh-886
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
oleksandr-pavlyk committed Aug 26, 2022
1 parent 8414053 commit 6a457f0
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 0 deletions.
33 changes: 33 additions & 0 deletions libsyclinterface/include/dpctl_sycl_device_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,3 +631,36 @@ size_t DPCTLDevice_Hash(__dpctl_keep const DPCTLSyclDeviceRef DRef);
DPCTL_API
size_t DPCTLDevice_GetProfilingTimerResolution(
__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Wrapper over
* device.get_info<info::device::global_mem_cache_line_size>
*
* @param DRef Opaque pointer to a sycl::device
* @return Returns the size of global memory cache line in bytes as uint32_t.
*/
DPCTL_API
uint32_t DPCTLDevice_GetGlobalMemCacheLineSize(
__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Wrapper over
* device.get_info<info::device::global_mem_cache_size>
*
* @param DRef Opaque pointer to a sycl::device
* @return Returns the size of global memory cache in bytes as uint64_t.
*/
DPCTL_API
uint64_t
DPCTLDevice_GetGlobalMemCacheSize(__dpctl_keep const DPCTLSyclDeviceRef DRef);

/*!
* @brief Wrapper over
* device.get_info<info::device::global_mem_cache_type>
*
* @param DRef Opaque pointer to a sycl::device
* @return Returns the type of global memory cache supported.
*/
DPCTL_API
DPCTLGlobalMemCacheType
DPCTLDevice_GetGlobalMemCacheType(__dpctl_keep const DPCTLSyclDeviceRef DRef);
8 changes: 8 additions & 0 deletions libsyclinterface/include/dpctl_sycl_enum_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,12 @@ typedef enum
DPCTL_COMPLETE
} DPCTLSyclEventStatusType;

typedef enum
{
DPCTL_MEM_CACHE_TYPE_INDETERMINATE,
DPCTL_MEM_CACHE_TYPE_NONE,
DPCTL_MEM_CACHE_TYPE_READ_ONLY,
DPCTL_MEM_CACHE_TYPE_READ_WRITE
} DPCTLGlobalMemCacheType;

DPCTL_C_EXTERN_C_END
51 changes: 51 additions & 0 deletions libsyclinterface/source/dpctl_sycl_device_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,3 +691,54 @@ size_t DPCTLDevice_GetProfilingTimerResolution(
return 0;
}
}

uint32_t DPCTLDevice_GetGlobalMemCacheLineSize(
__dpctl_keep const DPCTLSyclDeviceRef DRef)
{
if (DRef) {
auto D = unwrap(DRef);
return D->get_info<info::device::global_mem_cache_line_size>();
}
else {
error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
return 0;
}
}

uint64_t
DPCTLDevice_GetGlobalMemCacheSize(__dpctl_keep const DPCTLSyclDeviceRef DRef)
{
if (DRef) {
auto D = unwrap(DRef);
return D->get_info<info::device::global_mem_cache_size>();
}
else {
error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
return 0;
}
}

DPCTLGlobalMemCacheType
DPCTLDevice_GetGlobalMemCacheType(__dpctl_keep const DPCTLSyclDeviceRef DRef)
{
if (DRef) {
auto D = unwrap(DRef);
auto mem_type = D->get_info<info::device::global_mem_cache_type>();
switch (mem_type) {
case info::global_mem_cache_type::none:
return DPCTL_MEM_CACHE_TYPE_NONE;
case info::global_mem_cache_type::read_only:
return DPCTL_MEM_CACHE_TYPE_READ_ONLY;
case info::global_mem_cache_type::read_write:
return DPCTL_MEM_CACHE_TYPE_READ_WRITE;
}
// If execution reaches here unrecognized mem_type was returned. Check
// values in the enumeration `info::global_mem_cache_type` in SYCL specs
assert(false);
return DPCTL_MEM_CACHE_TYPE_INDETERMINATE;
}
else {
error_handler("Argument DRef is null", __FILE__, __func__, __LINE__);
return DPCTL_MEM_CACHE_TYPE_INDETERMINATE;
}
}
47 changes: 47 additions & 0 deletions libsyclinterface/tests/test_sycl_device_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,30 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkGetProfilingTimerResolution)
EXPECT_TRUE(res != 0);
}

TEST_P(TestDPCTLSyclDeviceInterface, ChkGetGlobalMemCacheSize)
{
uint64_t res = 0;
EXPECT_NO_FATAL_FAILURE(res = DPCTLDevice_GetGlobalMemCacheSize(DRef));
EXPECT_TRUE(res != 0);
}

TEST_P(TestDPCTLSyclDeviceInterface, ChkGetGlobalMemCacheLineSize)
{
uint32_t res = 0;
EXPECT_NO_FATAL_FAILURE(res = DPCTLDevice_GetGlobalMemCacheLineSize(DRef));
EXPECT_TRUE(res != 0);
}

TEST_P(TestDPCTLSyclDeviceInterface, ChkGetGlobalMemCacheType)
{
DPCTLGlobalMemCacheType res = DPCTL_MEM_CACHE_TYPE_INDETERMINATE;
EXPECT_NO_FATAL_FAILURE(res = DPCTLDevice_GetGlobalMemCacheLineSize(DRef));
EXPECT_TRUE(res != DPCTL_MEM_CACHE_TYPE_INDETERMINATE);
EXPECT_TRUE((res == DPCTL_MEM_CACHE_TYPE_NONE ||
res == DCPTL_MEM_CACHE_TYPE_READ_ONLY ||
res == DPCTL_MEM_CACHE_TYPE_READ_WRITE));
}

INSTANTIATE_TEST_SUITE_P(DPCTLDeviceFns,
TestDPCTLSyclDeviceInterface,
::testing::Values("opencl",
Expand Down Expand Up @@ -713,3 +737,26 @@ TEST_F(TestDPCTLSyclDeviceNullArgs, ChkGetProfilingTimerResolution)
res = DPCTLDevice_GetProfilingTimerResolution(Null_DRef));
ASSERT_TRUE(res == 0);
}

TEST_F(TestDPCTLSyclDeviceNullArgs, ChkGetGlobalMemCacheSize)
{
uint64_t res = 1;
EXPECT_NO_FATAL_FAILURE(res = DPCTLDevice_GetGlobalMemCacheSize(Null_DRef));
ASSERT_TRUE(res == 0);
}

TEST_F(TestDPCTLSyclDeviceNullArgs, ChkGetGlobalMemCacheLineSize)
{
uint32_t res = 1;
EXPECT_NO_FATAL_FAILURE(
res = DPCTLDevice_GetGlobalMemCacheLineSize(Null_DRef));
ASSERT_TRUE(res == 0);
}

TEST_F(TestDPCTLSyclDeviceNullArgs, ChkGetGlobalMemCacheLineSize)
{
DPCTLGlobalMemCacheType res = DCPTL_MEM_CACHE_TYPE_NONE;
EXPECT_NO_FATAL_FAILURE(
res = DPCTLDevice_GetGlobalMemCacheLineSize(Null_DRef));
ASSERT_TRUE(res == DCPTL_MEM_CACHE_TYPE_INDETERMINATE);
}

0 comments on commit 6a457f0

Please sign in to comment.