From 95bfbeb08ca9f4b8a973a3ad515eeee2a481738d Mon Sep 17 00:00:00 2001 From: Petr Vesely Date: Wed, 28 Jun 2023 12:06:46 +0100 Subject: [PATCH] [UR][CTS] Adds CTS coverage for urVirtualMemGranularityGetInfo --- include/ur_api.h | 12 +++ scripts/core/virtual_memory.yml | 13 +++ source/loader/layers/validation/ur_valddi.cpp | 12 +++ source/loader/ur_libapi.cpp | 12 +++ source/ur_api.cpp | 12 +++ .../urVirtualMemGranularityGetInfo.cpp | 96 +++++++++++++++++++ 6 files changed, 157 insertions(+) diff --git a/include/ur_api.h b/include/ur_api.h index bd31448845..5c001e9c22 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -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. diff --git a/scripts/core/virtual_memory.yml b/scripts/core/virtual_memory.yml index 774890d8f5..c6f707697d 100644 --- a/scripts/core/virtual_memory.yml +++ b/scripts/core/virtual_memory.yml @@ -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 diff --git a/source/loader/layers/validation/ur_valddi.cpp b/source/loader/layers/validation/ur_valddi.cpp index 3c0c079e4e..46ba1e9379 100644 --- a/source/loader/layers/validation/ur_valddi.cpp +++ b/source/loader/layers/validation/ur_valddi.cpp @@ -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( diff --git a/source/loader/ur_libapi.cpp b/source/loader/ur_libapi.cpp index 9a22630002..8e095d05ba 100644 --- a/source/loader/ur_libapi.cpp +++ b/source/loader/ur_libapi.cpp @@ -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 diff --git a/source/ur_api.cpp b/source/ur_api.cpp index 4920aae5c2..89c1271a54 100644 --- a/source/ur_api.cpp +++ b/source/ur_api.cpp @@ -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 diff --git a/test/conformance/virtual_memory/urVirtualMemGranularityGetInfo.cpp b/test/conformance/virtual_memory/urVirtualMemGranularityGetInfo.cpp index 281aa8badb..d4feccd6dc 100644 --- a/test/conformance/virtual_memory/urVirtualMemGranularityGetInfo.cpp +++ b/test/conformance/virtual_memory/urVirtualMemGranularityGetInfo.cpp @@ -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 + +using urVirtualMemGranularityGetInfoTest = + uur::urContextTestWithParam; + +UUR_TEST_SUITE_P( + urVirtualMemGranularityGetInfoTest, + ::testing::Values(UR_VIRTUAL_MEM_GRANULARITY_INFO_MINIMUM, + UR_VIRTUAL_MEM_GRANULARITY_INFO_RECOMMENDED), + uur::deviceTestWithParamPrinter); + +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 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(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(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); +}