From c43ddf8eb9983b4f86305faa79b3e84c8f8e7869 Mon Sep 17 00:00:00 2001 From: omarahmed1111 Date: Tue, 26 Mar 2024 14:34:25 +0000 Subject: [PATCH] [SPEC] Add more clarification to invalid size return code --- include/ur_api.h | 3 +++ scripts/core/memory.yml | 7 +++++-- source/loader/layers/validation/ur_valddi.cpp | 8 ++++++++ source/loader/ur_libapi.cpp | 3 +++ source/ur_api.cpp | 3 +++ test/conformance/memory/memory_adapter_level_zero.match | 5 ----- test/conformance/memory/memory_adapter_native_cpu.match | 1 - 7 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/ur_api.h b/include/ur_api.h index 19ba599c7d..8638179805 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -2645,6 +2645,7 @@ typedef struct ur_buffer_alloc_location_properties_t { /// - ::UR_RESULT_ERROR_INVALID_CONTEXT /// - ::UR_RESULT_ERROR_INVALID_VALUE /// - ::UR_RESULT_ERROR_INVALID_BUFFER_SIZE +/// + `size == 0` /// - ::UR_RESULT_ERROR_INVALID_HOST_PTR /// + `pProperties == NULL && (flags & (UR_MEM_FLAG_USE_HOST_POINTER | UR_MEM_FLAG_ALLOC_COPY_HOST_POINTER)) != 0` /// + `pProperties != NULL && pProperties->pHost == NULL && (flags & (UR_MEM_FLAG_USE_HOST_POINTER | UR_MEM_FLAG_ALLOC_COPY_HOST_POINTER)) != 0` @@ -2753,6 +2754,8 @@ typedef enum ur_buffer_create_type_t { /// - ::UR_RESULT_ERROR_OBJECT_ALLOCATION_FAILURE /// - ::UR_RESULT_ERROR_INVALID_VALUE /// - ::UR_RESULT_ERROR_INVALID_BUFFER_SIZE +/// + `pRegion && pRegion->size == 0` +/// + hBuffer allocation size < (pRegion->origin + pRegion->size) /// - ::UR_RESULT_ERROR_INVALID_HOST_PTR /// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY /// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES diff --git a/scripts/core/memory.yml b/scripts/core/memory.yml index 644832f1a3..6f88b10cdc 100644 --- a/scripts/core/memory.yml +++ b/scripts/core/memory.yml @@ -319,7 +319,8 @@ params: returns: - $X_RESULT_ERROR_INVALID_CONTEXT - $X_RESULT_ERROR_INVALID_VALUE - - $X_RESULT_ERROR_INVALID_BUFFER_SIZE + - $X_RESULT_ERROR_INVALID_BUFFER_SIZE: + - "`size == 0`" - $X_RESULT_ERROR_INVALID_HOST_PTR: - "`pProperties == NULL && (flags & (UR_MEM_FLAG_USE_HOST_POINTER | UR_MEM_FLAG_ALLOC_COPY_HOST_POINTER)) != 0`" - "`pProperties != NULL && pProperties->pHost == NULL && (flags & (UR_MEM_FLAG_USE_HOST_POINTER | UR_MEM_FLAG_ALLOC_COPY_HOST_POINTER)) != 0`" @@ -411,7 +412,9 @@ returns: - $X_RESULT_ERROR_INVALID_MEM_OBJECT - $X_RESULT_ERROR_OBJECT_ALLOCATION_FAILURE - $X_RESULT_ERROR_INVALID_VALUE - - $X_RESULT_ERROR_INVALID_BUFFER_SIZE + - $X_RESULT_ERROR_INVALID_BUFFER_SIZE: + - "`pRegion && pRegion->size == 0`" + - "hBuffer allocation size < (pRegion->origin + pRegion->size)" - $X_RESULT_ERROR_INVALID_HOST_PTR - $X_RESULT_ERROR_OUT_OF_HOST_MEMORY - $X_RESULT_ERROR_OUT_OF_RESOURCES diff --git a/source/loader/layers/validation/ur_valddi.cpp b/source/loader/layers/validation/ur_valddi.cpp index fbdbbe45cf..54793995c4 100644 --- a/source/loader/layers/validation/ur_valddi.cpp +++ b/source/loader/layers/validation/ur_valddi.cpp @@ -1129,6 +1129,10 @@ __urdlllocal ur_result_t UR_APICALL urMemBufferCreate( return UR_RESULT_ERROR_INVALID_ENUMERATION; } + if (size == 0) { + return UR_RESULT_ERROR_INVALID_BUFFER_SIZE; + } + if (pProperties == NULL && (flags & (UR_MEM_FLAG_USE_HOST_POINTER | UR_MEM_FLAG_ALLOC_COPY_HOST_POINTER)) != 0) { @@ -1253,6 +1257,10 @@ __urdlllocal ur_result_t UR_APICALL urMemBufferPartition( if (UR_BUFFER_CREATE_TYPE_REGION < bufferCreateType) { return UR_RESULT_ERROR_INVALID_ENUMERATION; } + + if (pRegion && pRegion->size == 0) { + return UR_RESULT_ERROR_INVALID_BUFFER_SIZE; + } } if (context.enableLifetimeValidation && diff --git a/source/loader/ur_libapi.cpp b/source/loader/ur_libapi.cpp index 2165065097..1dfd293b07 100644 --- a/source/loader/ur_libapi.cpp +++ b/source/loader/ur_libapi.cpp @@ -1543,6 +1543,7 @@ ur_result_t UR_APICALL urMemImageCreate( /// - ::UR_RESULT_ERROR_INVALID_CONTEXT /// - ::UR_RESULT_ERROR_INVALID_VALUE /// - ::UR_RESULT_ERROR_INVALID_BUFFER_SIZE +/// + `size == 0` /// - ::UR_RESULT_ERROR_INVALID_HOST_PTR /// + `pProperties == NULL && (flags & (UR_MEM_FLAG_USE_HOST_POINTER | UR_MEM_FLAG_ALLOC_COPY_HOST_POINTER)) != 0` /// + `pProperties != NULL && pProperties->pHost == NULL && (flags & (UR_MEM_FLAG_USE_HOST_POINTER | UR_MEM_FLAG_ALLOC_COPY_HOST_POINTER)) != 0` @@ -1657,6 +1658,8 @@ ur_result_t UR_APICALL urMemRelease( /// - ::UR_RESULT_ERROR_OBJECT_ALLOCATION_FAILURE /// - ::UR_RESULT_ERROR_INVALID_VALUE /// - ::UR_RESULT_ERROR_INVALID_BUFFER_SIZE +/// + `pRegion && pRegion->size == 0` +/// + hBuffer allocation size < (pRegion->origin + pRegion->size) /// - ::UR_RESULT_ERROR_INVALID_HOST_PTR /// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY /// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES diff --git a/source/ur_api.cpp b/source/ur_api.cpp index cbc51a437e..51e9d787cc 100644 --- a/source/ur_api.cpp +++ b/source/ur_api.cpp @@ -1331,6 +1331,7 @@ ur_result_t UR_APICALL urMemImageCreate( /// - ::UR_RESULT_ERROR_INVALID_CONTEXT /// - ::UR_RESULT_ERROR_INVALID_VALUE /// - ::UR_RESULT_ERROR_INVALID_BUFFER_SIZE +/// + `size == 0` /// - ::UR_RESULT_ERROR_INVALID_HOST_PTR /// + `pProperties == NULL && (flags & (UR_MEM_FLAG_USE_HOST_POINTER | UR_MEM_FLAG_ALLOC_COPY_HOST_POINTER)) != 0` /// + `pProperties != NULL && pProperties->pHost == NULL && (flags & (UR_MEM_FLAG_USE_HOST_POINTER | UR_MEM_FLAG_ALLOC_COPY_HOST_POINTER)) != 0` @@ -1427,6 +1428,8 @@ ur_result_t UR_APICALL urMemRelease( /// - ::UR_RESULT_ERROR_OBJECT_ALLOCATION_FAILURE /// - ::UR_RESULT_ERROR_INVALID_VALUE /// - ::UR_RESULT_ERROR_INVALID_BUFFER_SIZE +/// + `pRegion && pRegion->size == 0` +/// + hBuffer allocation size < (pRegion->origin + pRegion->size) /// - ::UR_RESULT_ERROR_INVALID_HOST_PTR /// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY /// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES diff --git a/test/conformance/memory/memory_adapter_level_zero.match b/test/conformance/memory/memory_adapter_level_zero.match index 9aebbe1c67..ceec328721 100644 --- a/test/conformance/memory/memory_adapter_level_zero.match +++ b/test/conformance/memory/memory_adapter_level_zero.match @@ -1,8 +1,3 @@ -urMemBufferCreateWithFlagsTest.InvalidBufferSizeZero/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_UR_MEM_FLAG_READ_WRITE -urMemBufferCreateWithFlagsTest.InvalidBufferSizeZero/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_UR_MEM_FLAG_WRITE_ONLY -urMemBufferCreateWithFlagsTest.InvalidBufferSizeZero/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_UR_MEM_FLAG_READ_ONLY -urMemBufferCreateWithFlagsTest.InvalidBufferSizeZero/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_UR_MEM_FLAG_ALLOC_HOST_POINTER -urMemBufferPartitionTest.InvalidBufferSize/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ urMemBufferPartitionTest.InvalidValueCreateType/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ urMemBufferPartitionTest.InvalidValueBufferCreateInfoOutOfBounds/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ urMemGetInfoImageTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_INFO_SIZE diff --git a/test/conformance/memory/memory_adapter_native_cpu.match b/test/conformance/memory/memory_adapter_native_cpu.match index 75850127af..c2a49a5c70 100644 --- a/test/conformance/memory/memory_adapter_native_cpu.match +++ b/test/conformance/memory/memory_adapter_native_cpu.match @@ -1,4 +1,3 @@ -urMemBufferPartitionTest.InvalidBufferSize/SYCL_NATIVE_CPU___SYCL_Native_CPU_ urMemBufferPartitionTest.InvalidValueCreateType/SYCL_NATIVE_CPU___SYCL_Native_CPU_ urMemBufferPartitionTest.InvalidValueBufferCreateInfoOutOfBounds/SYCL_NATIVE_CPU___SYCL_Native_CPU_ urMemGetInfoTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU___UR_MEM_INFO_SIZE