Skip to content

Commit

Permalink
[SPEC] Add more clarification to invalid size return code
Browse files Browse the repository at this point in the history
  • Loading branch information
omarahmed1111 committed Mar 28, 2024
1 parent 8dba1fd commit c43ddf8
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions scripts/core/memory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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`"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions source/loader/layers/validation/ur_valddi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 &&
Expand Down
3 changes: 3 additions & 0 deletions source/loader/ur_libapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions source/ur_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions test/conformance/memory/memory_adapter_level_zero.match
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion test/conformance/memory/memory_adapter_native_cpu.match
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit c43ddf8

Please sign in to comment.