Skip to content

Commit 68a62a6

Browse files
author
Petr Vesely
committed
[UR] Verify USM GetInfo
1 parent 7528b73 commit 68a62a6

File tree

6 files changed

+66
-10
lines changed

6 files changed

+66
-10
lines changed

include/ur_api.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2885,7 +2885,15 @@ typedef enum ur_usm_pool_info_t {
28852885
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
28862886
/// + `NULL == pPropValue`
28872887
/// + `NULL == pPropSizeRet`
2888-
/// - ::UR_RESULT_ERROR_INVALID_VALUE
2888+
/// + `propSize != 0 && pPropValue == NULL`
2889+
/// + `pPropValue == NULL && pPropSizeRet == NULL`
2890+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
2891+
/// + If `propName` is not supported by the adapter.
2892+
/// - ::UR_RESULT_ERROR_INVALID_SIZE
2893+
/// + `propSize == 0 && pPropValue != NULL`
2894+
/// + If `propSize` is less than the real number of bytes needed to return the info.
2895+
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
2896+
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
28892897
UR_APIEXPORT ur_result_t UR_APICALL
28902898
urUSMPoolGetInfo(
28912899
ur_usm_pool_handle_t hPool, ///< [in] handle of the USM memory pool

scripts/core/usm.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,13 @@ params:
461461
name: pPropSizeRet
462462
desc: "[out] size in bytes returned in pool property value"
463463
returns:
464-
- $X_RESULT_ERROR_INVALID_NULL_HANDLE
465-
- $X_RESULT_ERROR_INVALID_ENUMERATION
466-
- $X_RESULT_ERROR_INVALID_VALUE
464+
- $X_RESULT_ERROR_UNSUPPORTED_ENUMERATION:
465+
- "If `propName` is not supported by the adapter."
466+
- $X_RESULT_ERROR_INVALID_SIZE:
467+
- "`propSize == 0 && pPropValue != NULL`"
468+
- "If `propSize` is less than the real number of bytes needed to return the info."
469+
- $X_RESULT_ERROR_INVALID_NULL_POINTER:
470+
- "`propSize != 0 && pPropValue == NULL`"
471+
- "`pPropValue == NULL && pPropSizeRet == NULL`"
472+
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
473+
- $X_RESULT_ERROR_OUT_OF_RESOURCES

source/loader/layers/validation/ur_valddi.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,9 +1822,21 @@ __urdlllocal ur_result_t UR_APICALL urUSMPoolGetInfo(
18221822
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
18231823
}
18241824

1825+
if (propSize != 0 && pPropValue == NULL) {
1826+
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
1827+
}
1828+
1829+
if (pPropValue == NULL && pPropSizeRet == NULL) {
1830+
return UR_RESULT_ERROR_INVALID_NULL_POINTER;
1831+
}
1832+
18251833
if (UR_USM_POOL_INFO_CONTEXT < propName) {
18261834
return UR_RESULT_ERROR_INVALID_ENUMERATION;
18271835
}
1836+
1837+
if (propSize == 0 && pPropValue != NULL) {
1838+
return UR_RESULT_ERROR_INVALID_SIZE;
1839+
}
18281840
}
18291841

18301842
ur_result_t result =

source/loader/ur_libapi.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,15 @@ ur_result_t UR_APICALL urUSMPoolRelease(
20232023
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
20242024
/// + `NULL == pPropValue`
20252025
/// + `NULL == pPropSizeRet`
2026-
/// - ::UR_RESULT_ERROR_INVALID_VALUE
2026+
/// + `propSize != 0 && pPropValue == NULL`
2027+
/// + `pPropValue == NULL && pPropSizeRet == NULL`
2028+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
2029+
/// + If `propName` is not supported by the adapter.
2030+
/// - ::UR_RESULT_ERROR_INVALID_SIZE
2031+
/// + `propSize == 0 && pPropValue != NULL`
2032+
/// + If `propSize` is less than the real number of bytes needed to return the info.
2033+
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
2034+
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
20272035
ur_result_t UR_APICALL urUSMPoolGetInfo(
20282036
ur_usm_pool_handle_t hPool, ///< [in] handle of the USM memory pool
20292037
ur_usm_pool_info_t propName, ///< [in] name of the pool property to query

source/ur_api.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,15 @@ ur_result_t UR_APICALL urUSMPoolRelease(
16911691
/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER
16921692
/// + `NULL == pPropValue`
16931693
/// + `NULL == pPropSizeRet`
1694-
/// - ::UR_RESULT_ERROR_INVALID_VALUE
1694+
/// + `propSize != 0 && pPropValue == NULL`
1695+
/// + `pPropValue == NULL && pPropSizeRet == NULL`
1696+
/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION
1697+
/// + If `propName` is not supported by the adapter.
1698+
/// - ::UR_RESULT_ERROR_INVALID_SIZE
1699+
/// + `propSize == 0 && pPropValue != NULL`
1700+
/// + If `propSize` is less than the real number of bytes needed to return the info.
1701+
/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY
1702+
/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES
16951703
ur_result_t UR_APICALL urUSMPoolGetInfo(
16961704
ur_usm_pool_handle_t hPool, ///< [in] handle of the USM memory pool
16971705
ur_usm_pool_info_t propName, ///< [in] name of the pool property to query

test/conformance/usm/urUSMPoolGetInfo.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,30 @@ TEST_P(urUSMPoolGetInfoTest, InvalidEnumerationProperty) {
5252
nullptr));
5353
}
5454

55-
TEST_P(urUSMPoolGetInfoTest, InvalidValueSizeTooSmall) {
55+
TEST_P(urUSMPoolGetInfoTest, InvalidSizeZero) {
5656
ur_context_handle_t context = nullptr;
57-
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_VALUE,
57+
ASSERT_EQ_RESULT(
58+
UR_RESULT_ERROR_INVALID_SIZE,
59+
urUSMPoolGetInfo(pool, UR_USM_POOL_INFO_CONTEXT, 0, &context, nullptr));
60+
}
61+
62+
TEST_P(urUSMPoolGetInfoTest, InvalidSizeTooSmall) {
63+
ur_context_handle_t context = nullptr;
64+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
5865
urUSMPoolGetInfo(pool, UR_USM_POOL_INFO_CONTEXT,
5966
sizeof(ur_context_handle_t) - 1, &context,
6067
nullptr));
6168
}
6269

63-
TEST_P(urUSMPoolGetInfoTest, InvalidValueNullPropValue) {
64-
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_VALUE,
70+
TEST_P(urUSMPoolGetInfoTest, InvalidNullPointerPropValue) {
71+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER,
6572
urUSMPoolGetInfo(pool, UR_USM_POOL_INFO_CONTEXT,
6673
sizeof(ur_context_handle_t), nullptr,
6774
nullptr));
6875
}
76+
77+
TEST_P(urUSMPoolGetInfoTest, InvalidNullPointerPropSizeRet) {
78+
ASSERT_EQ_RESULT(
79+
UR_RESULT_ERROR_INVALID_NULL_POINTER,
80+
urUSMPoolGetInfo(pool, UR_USM_POOL_INFO_CONTEXT, 0, nullptr, nullptr));
81+
}

0 commit comments

Comments
 (0)