Skip to content

Commit

Permalink
[UR][CTS] Adds CTS coverage for urVirtualMemGranularityGetInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Vesely committed Jun 28, 2023
1 parent ec72d28 commit 95bfbeb
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -3063,6 +3063,18 @@ typedef enum ur_virtual_mem_granularity_info_t {
/// + `NULL == hContext`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_VIRTUAL_MEM_GRANULARITY_INFO_RECOMMENDED < propName`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `propSize == 0 && pPropValue != NULL`
/// + If `propSize` is less than the real number of bytes needed to return the info.
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `propSize != 0 && pPropValue == NULL`
/// + `pPropValue == NULL && pPropSizeRet == NULL`
/// - ::UR_RESULT_ERROR_INVALID_DEVICE
/// - ::UR_RESULT_ERROR_INVALID_CONTEXT
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
UR_APIEXPORT ur_result_t UR_APICALL
urVirtualMemGranularityGetInfo(
ur_context_handle_t hContext, ///< [in] handle of the context object.
Expand Down
13 changes: 13 additions & 0 deletions scripts/core/virtual_memory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ params:
desc: >
[out][optional] pointer to the actual size in bytes of the queried
propName."
returns:
- $X_RESULT_ERROR_UNSUPPORTED_ENUMERATION:
- "If `propName` is not supported by the adapter."
- $X_RESULT_ERROR_INVALID_SIZE:
- "`propSize == 0 && pPropValue != NULL`"
- "If `propSize` is less than the real number of bytes needed to return the info."
- $X_RESULT_ERROR_INVALID_NULL_POINTER:
- "`propSize != 0 && pPropValue == NULL`"
- "`pPropValue == NULL && pPropSizeRet == NULL`"
- $X_RESULT_ERROR_INVALID_DEVICE
- $X_RESULT_ERROR_INVALID_CONTEXT
- $X_RESULT_ERROR_OUT_OF_RESOURCES
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY

--- #--------------------------------------------------------------------------
type: function
Expand Down
12 changes: 12 additions & 0 deletions source/loader/layers/validation/ur_valddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1890,9 +1890,21 @@ __urdlllocal ur_result_t UR_APICALL urVirtualMemGranularityGetInfo(
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
}

if (propSize != 0 && pPropValue == NULL) {
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
}

if (pPropValue == NULL && pPropSizeRet == NULL) {
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
}

if (UR_VIRTUAL_MEM_GRANULARITY_INFO_RECOMMENDED < propName) {
return UR_RESULT_ERROR_INVALID_ENUMERATION;
}

if (propSize == 0 && pPropValue != NULL) {
return UR_RESULT_ERROR_INVALID_SIZE;
}
}

ur_result_t result = pfnGranularityGetInfo(
Expand Down
12 changes: 12 additions & 0 deletions source/loader/ur_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,18 @@ ur_result_t UR_APICALL urUSMPoolGetInfo(
/// + `NULL == hContext`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_VIRTUAL_MEM_GRANULARITY_INFO_RECOMMENDED < propName`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `propSize == 0 && pPropValue != NULL`
/// + If `propSize` is less than the real number of bytes needed to return the info.
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `propSize != 0 && pPropValue == NULL`
/// + `pPropValue == NULL && pPropSizeRet == NULL`
/// - ::UR_RESULT_ERROR_INVALID_DEVICE
/// - ::UR_RESULT_ERROR_INVALID_CONTEXT
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
ur_result_t UR_APICALL urVirtualMemGranularityGetInfo(
ur_context_handle_t hContext, ///< [in] handle of the context object.
ur_device_handle_t
Expand Down
12 changes: 12 additions & 0 deletions source/ur_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,18 @@ ur_result_t UR_APICALL urUSMPoolGetInfo(
/// + `NULL == hContext`
/// - ::UR_RESULT_ERROR_INVALID_ENUMERATION
/// + `::UR_VIRTUAL_MEM_GRANULARITY_INFO_RECOMMENDED < propName`
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
/// + If `propName` is not supported by the adapter.
/// - ::UR_RESULT_ERROR_INVALID_SIZE
/// + `propSize == 0 && pPropValue != NULL`
/// + If `propSize` is less than the real number of bytes needed to return the info.
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
/// + `propSize != 0 && pPropValue == NULL`
/// + `pPropValue == NULL && pPropSizeRet == NULL`
/// - ::UR_RESULT_ERROR_INVALID_DEVICE
/// - ::UR_RESULT_ERROR_INVALID_CONTEXT
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
ur_result_t UR_APICALL urVirtualMemGranularityGetInfo(
ur_context_handle_t hContext, ///< [in] handle of the context object.
ur_device_handle_t
Expand Down
96 changes: 96 additions & 0 deletions test/conformance/virtual_memory/urVirtualMemGranularityGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,99 @@
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include <uur/fixtures.h>

using urVirtualMemGranularityGetInfoTest =
uur::urContextTestWithParam<ur_virtual_mem_granularity_info_t>;

UUR_TEST_SUITE_P(
urVirtualMemGranularityGetInfoTest,
::testing::Values(UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM,
UR_VIRTUAL_MEM_GRANULARITY_INFO_RECOMMENDED),
uur::deviceTestWithParamPrinter<ur_virtual_mem_granularity_info_t>);

TEST_P(urVirtualMemGranularityGetInfoTest, Success) {
size_t size = 0;
ur_virtual_mem_granularity_info_t info = getParam();
ASSERT_SUCCESS(urVirtualMemGranularityGetInfo(context, device, info, 0,
nullptr, &size));
ASSERT_NE(size, 0);

std::vector<uint8_t> infoData(size);
ASSERT_SUCCESS(urVirtualMemGranularityGetInfo(
context, device, info, infoData.size(), infoData.data(), nullptr));

switch (info) {
case UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM: {
ASSERT_EQ(size, sizeof(size_t));
size_t minimum = *reinterpret_cast<size_t *>(infoData.data());
ASSERT_GT(minimum, 0);
} break;
case UR_VIRTUAL_MEM_GRANULARITY_INFO_RECOMMENDED: {
ASSERT_EQ(size, sizeof(size_t));
size_t recommended = *reinterpret_cast<size_t *>(infoData.data());
ASSERT_GT(recommended, 0);
} break;
default:
FAIL() << "Unhandled ur_virtual_mem_granularity_info_t enumeration: "
<< info;
break;
}
}

using urVirtualMemGranularityGetInfoNegativeTest = uur::urContextTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urVirtualMemGranularityGetInfoNegativeTest);

TEST_P(urVirtualMemGranularityGetInfoNegativeTest, InvalidNullHandleContext) {
size_t size = 0;
ASSERT_EQ_RESULT(
urVirtualMemGranularityGetInfo(nullptr, device,
UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM,
0, nullptr, &size),
UR_RESULT_ERROR_INVALID_NULL_HANDLE);
}

TEST_P(urVirtualMemGranularityGetInfoNegativeTest, InvalidEnumeration) {
size_t size = 0;
ASSERT_EQ_RESULT(urVirtualMemGranularityGetInfo(
context, device,
UR_VIRTUAL_MEM_GRANULARITY_INFO_FORCE_UINT32, 0,
nullptr, &size),
UR_RESULT_ERROR_INVALID_NULL_HANDLE);
}

TEST_P(urVirtualMemGranularityGetInfoNegativeTest,
InvalidNullPointerPropSizeRet) {
ASSERT_EQ_RESULT(
urVirtualMemGranularityGetInfo(context, device,
UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM,
0, nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

TEST_P(urVirtualMemGranularityGetInfoNegativeTest,
InvalidNullPointerPropValue) {
ASSERT_EQ_RESULT(
urVirtualMemGranularityGetInfo(context, device,
UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM,
sizeof(size_t), nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

TEST_P(urVirtualMemGranularityGetInfoNegativeTest, InvalidPropSizeZero) {
size_t minimum = 0;
ASSERT_EQ_RESULT(
urVirtualMemGranularityGetInfo(context, device,
UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM,
0, &minimum, nullptr),
UR_RESULT_ERROR_INVALID_SIZE);
}

TEST_P(urVirtualMemGranularityGetInfoNegativeTest, InvalidSizePropSizeSmall) {
size_t minimum = 0;
ASSERT_EQ_RESULT(
urVirtualMemGranularityGetInfo(context, device,
UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM,
sizeof(size_t) - 1, &minimum, nullptr),
UR_RESULT_ERROR_INVALID_SIZE);
}

0 comments on commit 95bfbeb

Please sign in to comment.