From d39870be4d06824fe191e7b8d1c341d76316b195 Mon Sep 17 00:00:00 2001 From: Martin Morrison-Grant Date: Wed, 16 Oct 2024 11:44:53 +0100 Subject: [PATCH 1/4] Improvements to align CTS and Spec for Memory: - Add tests for UR_RESULT_ERROR_INVALID_NULL/HOST_POINTER for urMemImageCreate and urMemBufferCreate - Add missing error condition to spec for urMemImageCreate for checking type of image description struct - Add tests for UR_RESULT_ERROR_INVALID_NULL_HANDLE/POINTER for urMemBuffer/ImageCreateWithnativeHandle - Remove skip for urMemImageCreateWithNativeHandle - buffer was invalid as it was never instantiated in fixture struct - Update image format used in urMemImageTest fixture as it was invalid and likely to cause previously skipped test to fail (which now pass) - Add missing DDI table entry for urMemImageCreateWithNativeHandle for OpenCL - Add test for using different ur_mem_flag_t flags with urMemBufferPartition - Add missing UR_MEM_INFO_REFERENCE_COUNT to spec for urMemGetInfo and added test for this in urMemRetain/Release - Removed assert in L0 urMemGetInfo which would fail if mem type is not image or the query is not a context query - Fixed potential bug with HIP urMemGetNativeHandle which would fail if the mem handle was an image because use of std::variant --- include/ur_api.h | 11 ++- include/ur_print.hpp | 15 +++ scripts/core/memory.yml | 6 ++ source/adapters/cuda/memory.cpp | 3 + source/adapters/hip/memory.cpp | 23 +++-- source/adapters/level_zero/memory.cpp | 8 +- source/adapters/level_zero/v2/memory.cpp | 3 + source/adapters/opencl/memory.cpp | 2 + .../adapters/opencl/ur_interface_loader.cpp | 1 + source/loader/layers/validation/ur_valddi.cpp | 6 +- source/loader/ur_libapi.cpp | 3 +- source/ur_api.cpp | 3 +- .../memory/memory_adapter_cuda.match | 3 + .../memory/memory_adapter_hip.match | 4 + .../memory/memory_adapter_level_zero.match | 2 + .../memory/memory_adapter_level_zero_v2.match | 14 +++ .../memory/memory_adapter_native_cpu.match | 17 +++- .../memory/memory_adapter_opencl.match | 2 - test/conformance/memory/urMemBufferCreate.cpp | 64 +++++++++---- .../urMemBufferCreateWithNativeHandle.cpp | 93 +++++++++++++++---- .../memory/urMemBufferPartition.cpp | 25 +++-- test/conformance/memory/urMemGetInfo.cpp | 39 ++++++-- test/conformance/memory/urMemImageCreate.cpp | 27 ++++-- .../urMemImageCreateWithNativeHandle.cpp | 31 +++++-- test/conformance/memory/urMemRelease.cpp | 21 +++++ test/conformance/memory/urMemRetain.cpp | 24 ++++- .../testing/include/uur/fixtures.h | 9 +- 27 files changed, 362 insertions(+), 97 deletions(-) delete mode 100644 test/conformance/memory/memory_adapter_opencl.match diff --git a/include/ur_api.h b/include/ur_api.h index cfa122deb4..60d6fc2f70 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -2515,8 +2515,12 @@ typedef enum ur_mem_type_t { /////////////////////////////////////////////////////////////////////////////// /// @brief Memory Information type typedef enum ur_mem_info_t { - UR_MEM_INFO_SIZE = 0, ///< [size_t] actual size of of memory object in bytes - UR_MEM_INFO_CONTEXT = 1, ///< [::ur_context_handle_t] context in which the memory object was created + UR_MEM_INFO_SIZE = 0, ///< [size_t] actual size of of memory object in bytes + UR_MEM_INFO_CONTEXT = 1, ///< [::ur_context_handle_t] context in which the memory object was created + UR_MEM_INFO_REFERENCE_COUNT = 2, ///< [uint32_t] Reference count of the memory object. + ///< The reference count returned should be considered immediately stale. + ///< It is unsuitable for general use in applications. This feature is + ///< provided for identifying memory leaks. /// @cond UR_MEM_INFO_FORCE_UINT32 = 0x7fffffff /// @endcond @@ -2650,6 +2654,7 @@ typedef struct ur_image_desc_t { /// - ::UR_RESULT_ERROR_INVALID_CONTEXT /// - ::UR_RESULT_ERROR_INVALID_VALUE /// - ::UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR +/// + `pImageDesc && UR_STRUCTURE_TYPE_IMAGE_DESC != pImageDesc->stype` /// + `pImageDesc && UR_MEM_TYPE_IMAGE1D_ARRAY < pImageDesc->type` /// + `pImageDesc && pImageDesc->numMipLevel != 0` /// + `pImageDesc && pImageDesc->numSamples != 0` @@ -2990,7 +2995,7 @@ urMemImageCreateWithNativeHandle( /// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE /// + `NULL == hMemory` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION -/// + `::UR_MEM_INFO_CONTEXT < propName` +/// + `::UR_MEM_INFO_REFERENCE_COUNT < propName` /// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION /// + If `propName` is not supported by the adapter. /// - ::UR_RESULT_ERROR_INVALID_SIZE diff --git a/include/ur_print.hpp b/include/ur_print.hpp index cfb077177e..09431d4352 100644 --- a/include/ur_print.hpp +++ b/include/ur_print.hpp @@ -5631,6 +5631,9 @@ inline std::ostream &operator<<(std::ostream &os, enum ur_mem_info_t value) { case UR_MEM_INFO_CONTEXT: os << "UR_MEM_INFO_CONTEXT"; break; + case UR_MEM_INFO_REFERENCE_COUNT: + os << "UR_MEM_INFO_REFERENCE_COUNT"; + break; default: os << "unknown enumerator"; break; @@ -5672,6 +5675,18 @@ inline ur_result_t printTagged(std::ostream &os, const void *ptr, ur_mem_info_t os << ")"; } break; + case UR_MEM_INFO_REFERENCE_COUNT: { + const uint32_t *tptr = (const uint32_t *)ptr; + if (sizeof(uint32_t) > size) { + os << "invalid size (is: " << size << ", expected: >=" << sizeof(uint32_t) << ")"; + return UR_RESULT_ERROR_INVALID_SIZE; + } + os << (const void *)(tptr) << " ("; + + os << *tptr; + + os << ")"; + } break; default: os << "unknown enumerator"; return UR_RESULT_ERROR_INVALID_ENUMERATION; diff --git a/scripts/core/memory.yml b/scripts/core/memory.yml index 0fde537f37..7cc7467da4 100644 --- a/scripts/core/memory.yml +++ b/scripts/core/memory.yml @@ -62,6 +62,11 @@ etors: desc: "[size_t] actual size of of memory object in bytes" - name: CONTEXT desc: "[$x_context_handle_t] context in which the memory object was created" + - name: REFERENCE_COUNT + desc: | + [uint32_t] Reference count of the memory object. + The reference count returned should be considered immediately stale. + It is unsuitable for general use in applications. This feature is provided for identifying memory leaks. --- #-------------------------------------------------------------------------- type: enum desc: "Image channel order info: number of channels and the channel layout" @@ -241,6 +246,7 @@ returns: - $X_RESULT_ERROR_INVALID_CONTEXT - $X_RESULT_ERROR_INVALID_VALUE - $X_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR: + - "`pImageDesc && UR_STRUCTURE_TYPE_IMAGE_DESC != pImageDesc->stype`" - "`pImageDesc && UR_MEM_TYPE_IMAGE1D_ARRAY < pImageDesc->type`" - "`pImageDesc && pImageDesc->numMipLevel != 0`" - "`pImageDesc && pImageDesc->numSamples != 0`" diff --git a/source/adapters/cuda/memory.cpp b/source/adapters/cuda/memory.cpp index ea55c1669a..8b4db742ac 100644 --- a/source/adapters/cuda/memory.cpp +++ b/source/adapters/cuda/memory.cpp @@ -171,6 +171,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemGetInfo(ur_mem_handle_t hMemory, case UR_MEM_INFO_CONTEXT: { return ReturnValue(hMemory->getContext()); } + case UR_MEM_INFO_REFERENCE_COUNT: { + return ReturnValue(hMemory->getReferenceCount()); + } default: return UR_RESULT_ERROR_INVALID_ENUMERATION; diff --git a/source/adapters/hip/memory.cpp b/source/adapters/hip/memory.cpp index aa7b5f4040..93d8450862 100644 --- a/source/adapters/hip/memory.cpp +++ b/source/adapters/hip/memory.cpp @@ -231,10 +231,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemGetInfo(ur_mem_handle_t hMemory, size_t propSize, void *pMemInfo, size_t *pPropSizeRet) { - - UR_ASSERT(MemInfoType <= UR_MEM_INFO_CONTEXT, - UR_RESULT_ERROR_INVALID_ENUMERATION); - // FIXME: Only getting info for the first device in the context. This // should be fine in general auto Device = hMemory->getContext()->getDevices()[0]; @@ -286,6 +282,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemGetInfo(ur_mem_handle_t hMemory, case UR_MEM_INFO_CONTEXT: { return ReturnValue(hMemory->getContext()); } + case UR_MEM_INFO_REFERENCE_COUNT: { + return ReturnValue(hMemory->getReferenceCount()); + } default: return UR_RESULT_ERROR_INVALID_ENUMERATION; @@ -316,14 +315,18 @@ urMemGetNativeHandle(ur_mem_handle_t hMem, ur_device_handle_t Device, return UR_RESULT_ERROR_INVALID_MEM_OBJECT; } } - *phNativeMem = reinterpret_cast( - std::get(hMem->Mem).getPtr(Device)); -#elif defined(__HIP_PLATFORM_AMD__) - *phNativeMem = reinterpret_cast( - std::get(hMem->Mem).getPtr(Device)); -#else +#elif !defined(__HIP_PLATFORM_AMD__) #error("Must define exactly one of __HIP_PLATFORM_AMD__ or __HIP_PLATFORM_NVIDIA__"); #endif + if (std::holds_alternative(hMem->Mem)) { + *phNativeMem = reinterpret_cast( + std::get(hMem->Mem).getPtr(Device)); + } else if (std::holds_alternative(hMem->Mem)) { + *phNativeMem = reinterpret_cast( + std::get(hMem->Mem).getSurface(Device)); + } else { + return UR_RESULT_ERROR_INVALID_MEM_OBJECT; + } return UR_RESULT_SUCCESS; } diff --git a/source/adapters/level_zero/memory.cpp b/source/adapters/level_zero/memory.cpp index 706a3f1364..cd12800bdd 100644 --- a/source/adapters/level_zero/memory.cpp +++ b/source/adapters/level_zero/memory.cpp @@ -1844,9 +1844,6 @@ ur_result_t urMemGetInfo( size_t *PropSizeRet ///< [out][optional] pointer to the actual size in ///< bytes of data queried by pMemInfo. ) { - UR_ASSERT(MemInfoType == UR_MEM_INFO_CONTEXT || !Memory->isImage(), - UR_RESULT_ERROR_INVALID_VALUE); - auto Buffer = reinterpret_cast<_ur_buffer *>(Memory); std::shared_lock Lock(Buffer->Mutex); UrReturnHelper ReturnValue(PropSize, MemInfo, PropSizeRet); @@ -1859,8 +1856,11 @@ ur_result_t urMemGetInfo( // Get size of the allocation return ReturnValue(size_t{Buffer->Size}); } + case UR_MEM_INFO_REFERENCE_COUNT: { + return ReturnValue(Buffer->RefCount.load()); + } default: { - die("urMemGetInfo: Parameter is not implemented"); + return UR_RESULT_ERROR_INVALID_ENUMERATION; } } diff --git a/source/adapters/level_zero/v2/memory.cpp b/source/adapters/level_zero/v2/memory.cpp index a70792969b..05a25aa256 100644 --- a/source/adapters/level_zero/v2/memory.cpp +++ b/source/adapters/level_zero/v2/memory.cpp @@ -522,6 +522,9 @@ ur_result_t urMemGetInfo(ur_mem_handle_t hMemory, ur_mem_info_t propName, // Get size of the allocation return returnValue(size_t{hMemory->getSize()}); } + case UR_MEM_INFO_REFERENCE_COUNT: { + return returnValue(hMemory->RefCount.load()); + } default: { return UR_RESULT_ERROR_INVALID_ENUMERATION; } diff --git a/source/adapters/opencl/memory.cpp b/source/adapters/opencl/memory.cpp index b2476fc420..201df1f678 100644 --- a/source/adapters/opencl/memory.cpp +++ b/source/adapters/opencl/memory.cpp @@ -186,6 +186,8 @@ cl_int mapURMemInfoToCL(ur_mem_info_t URPropName) { return CL_MEM_SIZE; case UR_MEM_INFO_CONTEXT: return CL_MEM_CONTEXT; + case UR_MEM_INFO_REFERENCE_COUNT: + return CL_MEM_REFERENCE_COUNT; default: return -1; } diff --git a/source/adapters/opencl/ur_interface_loader.cpp b/source/adapters/opencl/ur_interface_loader.cpp index da0b659bec..cba90ee152 100644 --- a/source/adapters/opencl/ur_interface_loader.cpp +++ b/source/adapters/opencl/ur_interface_loader.cpp @@ -154,6 +154,7 @@ urGetMemProcAddrTable(ur_api_version_t Version, ur_mem_dditable_t *pDdiTable) { pDdiTable->pfnBufferPartition = urMemBufferPartition; pDdiTable->pfnBufferCreateWithNativeHandle = urMemBufferCreateWithNativeHandle; + pDdiTable->pfnImageCreateWithNativeHandle = urMemImageCreateWithNativeHandle; pDdiTable->pfnGetInfo = urMemGetInfo; pDdiTable->pfnGetNativeHandle = urMemGetNativeHandle; pDdiTable->pfnImageCreate = urMemImageCreate; diff --git a/source/loader/layers/validation/ur_valddi.cpp b/source/loader/layers/validation/ur_valddi.cpp index ef7bb019ea..fdfce7951b 100644 --- a/source/loader/layers/validation/ur_valddi.cpp +++ b/source/loader/layers/validation/ur_valddi.cpp @@ -1108,6 +1108,10 @@ __urdlllocal ur_result_t UR_APICALL urMemImageCreate( return UR_RESULT_ERROR_INVALID_ENUMERATION; } + if (pImageDesc && UR_STRUCTURE_TYPE_IMAGE_DESC != pImageDesc->stype) { + return UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR; + } + if (pImageDesc && UR_MEM_TYPE_IMAGE1D_ARRAY < pImageDesc->type) { return UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR; } @@ -1507,7 +1511,7 @@ __urdlllocal ur_result_t UR_APICALL urMemGetInfo( return UR_RESULT_ERROR_INVALID_NULL_POINTER; } - if (UR_MEM_INFO_CONTEXT < propName) { + if (UR_MEM_INFO_REFERENCE_COUNT < propName) { return UR_RESULT_ERROR_INVALID_ENUMERATION; } diff --git a/source/loader/ur_libapi.cpp b/source/loader/ur_libapi.cpp index 45ee5e7531..9a8e4c2e12 100644 --- a/source/loader/ur_libapi.cpp +++ b/source/loader/ur_libapi.cpp @@ -1541,6 +1541,7 @@ ur_result_t UR_APICALL urContextSetExtendedDeleter( /// - ::UR_RESULT_ERROR_INVALID_CONTEXT /// - ::UR_RESULT_ERROR_INVALID_VALUE /// - ::UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR +/// + `pImageDesc && UR_STRUCTURE_TYPE_IMAGE_DESC != pImageDesc->stype` /// + `pImageDesc && UR_MEM_TYPE_IMAGE1D_ARRAY < pImageDesc->type` /// + `pImageDesc && pImageDesc->numMipLevel != 0` /// + `pImageDesc && pImageDesc->numSamples != 0` @@ -1890,7 +1891,7 @@ ur_result_t UR_APICALL urMemImageCreateWithNativeHandle( /// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE /// + `NULL == hMemory` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION -/// + `::UR_MEM_INFO_CONTEXT < propName` +/// + `::UR_MEM_INFO_REFERENCE_COUNT < propName` /// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION /// + If `propName` is not supported by the adapter. /// - ::UR_RESULT_ERROR_INVALID_SIZE diff --git a/source/ur_api.cpp b/source/ur_api.cpp index 140a20135b..92b02b7176 100644 --- a/source/ur_api.cpp +++ b/source/ur_api.cpp @@ -1342,6 +1342,7 @@ ur_result_t UR_APICALL urContextSetExtendedDeleter( /// - ::UR_RESULT_ERROR_INVALID_CONTEXT /// - ::UR_RESULT_ERROR_INVALID_VALUE /// - ::UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR +/// + `pImageDesc && UR_STRUCTURE_TYPE_IMAGE_DESC != pImageDesc->stype` /// + `pImageDesc && UR_MEM_TYPE_IMAGE1D_ARRAY < pImageDesc->type` /// + `pImageDesc && pImageDesc->numMipLevel != 0` /// + `pImageDesc && pImageDesc->numSamples != 0` @@ -1636,7 +1637,7 @@ ur_result_t UR_APICALL urMemImageCreateWithNativeHandle( /// - ::UR_RESULT_ERROR_INVALID_NULL_HANDLE /// + `NULL == hMemory` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION -/// + `::UR_MEM_INFO_CONTEXT < propName` +/// + `::UR_MEM_INFO_REFERENCE_COUNT < propName` /// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION /// + If `propName` is not supported by the adapter. /// - ::UR_RESULT_ERROR_INVALID_SIZE diff --git a/test/conformance/memory/memory_adapter_cuda.match b/test/conformance/memory/memory_adapter_cuda.match index c5b70e8559..bc36329e55 100644 --- a/test/conformance/memory/memory_adapter_cuda.match +++ b/test/conformance/memory/memory_adapter_cuda.match @@ -2,3 +2,6 @@ urMemImageCreateTest.InvalidSize/NVIDIA_CUDA_BACKEND___{{.*}}_ {{OPT}}urMemImageCremBufferCrateTestWith1DMemoryTypeParam.Success/NVIDIA_CUDA_BACKEND___{{.*}}___UR_MEM_TYPE_IMAGE1D_ARRAY {{OPT}}urMemImageCreateTestWith2DMemoryTypeParam.Success/NVIDIA_CUDA_BACKEND___{{.*}}___UR_MEM_TYPE_IMAGE2D_ARRAY +urMemBufferCreateWithNativeHandleTest.Success/NVIDIA_CUDA_BACKEND___{{.*}} +urMemBufferCreateWithNativeHandleTest.SuccessWithOwnedNativeHandle/NVIDIA_CUDA_BACKEND___{{.*}} +urMemBufferCreateWithNativeHandleTest.SuccessWithUnOwnedNativeHandle/NVIDIA_CUDA_BACKEND___{{.*}} diff --git a/test/conformance/memory/memory_adapter_hip.match b/test/conformance/memory/memory_adapter_hip.match index 589542df7f..4c83995b4f 100644 --- a/test/conformance/memory/memory_adapter_hip.match +++ b/test/conformance/memory/memory_adapter_hip.match @@ -2,3 +2,7 @@ urMemImageCreateTest.InvalidSize/AMD_HIP_BACKEND___{{.*}} urMemImageGetInfoTest.Success/AMD_HIP_BACKEND___{{.*}} urMemImageGetInfoTest.Success/AMD_HIP_BACKEND___{{.*}} +urMemBufferCreateWithNativeHandleTest.Success/AMD_HIP_BACKEND___{{.*}} +urMemBufferCreateWithNativeHandleTest.SuccessWithOwnedNativeHandle/AMD_HIP_BACKEND___{{.*}} +urMemBufferCreateWithNativeHandleTest.SuccessWithUnOwnedNativeHandle/AMD_HIP_BACKEND___{{.*}} +urMemImageCreateWithNativeHandleTest.Success/AMD_HIP_BACKEND___{{.*}} diff --git a/test/conformance/memory/memory_adapter_level_zero.match b/test/conformance/memory/memory_adapter_level_zero.match index 8dbd2ac9db..f25d8f23f3 100644 --- a/test/conformance/memory/memory_adapter_level_zero.match +++ b/test/conformance/memory/memory_adapter_level_zero.match @@ -1,5 +1,7 @@ # Note: This file is only for use with cts_exe.py {{OPT}}urMemBufferMultiQueueMemBufferTest.WriteBack +urMemBufferPartitionWithFlagsTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}__UR_MEM_FLAG_WRITE_ONLY +urMemBufferPartitionWithFlagsTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}__UR_MEM_FLAG_READ_ONLY urMemBufferPartitionTest.InvalidValueCreateType/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ urMemBufferPartitionTest.InvalidValueBufferCreateInfoOutOfBounds/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ {{OPT}}urMemGetInfoImageTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_INFO_SIZE diff --git a/test/conformance/memory/memory_adapter_level_zero_v2.match b/test/conformance/memory/memory_adapter_level_zero_v2.match index 89f708aae1..a0a5823fbc 100644 --- a/test/conformance/memory/memory_adapter_level_zero_v2.match +++ b/test/conformance/memory/memory_adapter_level_zero_v2.match @@ -1,6 +1,12 @@ {{NONDETERMINISTIC}} +urMemBufferPartitionWithFlagsTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_FLAG_WRITE_ONLY +urMemBufferPartitionWithFlagsTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_FLAG_READ_ONLY +urMemBufferPartitionWithFlagsTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_FLAG_READ_WRITE +urMemBufferPartitionTest.InvalidValueCreateType/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ +urMemBufferPartitionTest.InvalidValueBufferCreateInfoOutOfBounds/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ {{OPT}}urMemGetInfoImageTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_INFO_SIZE {{OPT}}urMemGetInfoImageTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_INFO_CONTEXT +{{OPT}}urMemGetInfoImageTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_INFO_REFERENCE_COUNT {{OPT}}urMemImageCreateTestWithImageFormatParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_CHANNEL_ORDER_A__UR_IMAGE_CHANNEL_TYPE_SNORM_INT8 {{OPT}}urMemImageCreateTestWithImageFormatParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_CHANNEL_ORDER_A__UR_IMAGE_CHANNEL_TYPE_SNORM_INT16 {{OPT}}urMemImageCreateTestWithImageFormatParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_CHANNEL_ORDER_A__UR_IMAGE_CHANNEL_TYPE_UNORM_INT8 @@ -275,3 +281,11 @@ {{OPT}}urMemImageGetInfoTest.InvalidNullPointerPropSizeRet/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_INFO_WIDTH {{OPT}}urMemImageGetInfoTest.InvalidNullPointerPropSizeRet/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_INFO_HEIGHT {{OPT}}urMemImageGetInfoTest.InvalidNullPointerPropSizeRet/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_INFO_DEPTH +urMemBufferCreateWithNativeHandleTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} +urMemBufferCreateWithNativeHandleTest.SuccessWithOwnedNativeHandle/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} +urMemBufferCreateWithNativeHandleTest.SuccessWithUnOwnedNativeHandle/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} +urMemBufferCreateWithNativeHandleTest.InvalidNullHandle/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} +urMemBufferCreateWithNativeHandleTest.InvalidNullPointer/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} +{{OPT}}urMemImageCreateWithNativeHandleTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} +{{OPT}}urMemImageCreateWithNativeHandleTest.InvalidNullHandle/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} +{{OPT}}urMemImageCreateWithNativeHandleTest.InvalidNullPointer/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} diff --git a/test/conformance/memory/memory_adapter_native_cpu.match b/test/conformance/memory/memory_adapter_native_cpu.match index 5bdd88804b..f22ebcc2e9 100644 --- a/test/conformance/memory/memory_adapter_native_cpu.match +++ b/test/conformance/memory/memory_adapter_native_cpu.match @@ -1,10 +1,12 @@ {{NONDETERMINISTIC}} +urMemBufferPartitionWithFlagsTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}__UR_MEM_FLAG_WRITE_ONLY +urMemBufferPartitionWithFlagsTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}__UR_MEM_FLAG_READ_ONLY 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 -urMemGetInfoTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}__UR_MEM_INFO_CONTEXT -urMemGetInfoTest.InvalidSizeSmall/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}__UR_MEM_INFO_SIZE -urMemGetInfoTest.InvalidSizeSmall/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}__UR_MEM_INFO_CONTEXT +urMemGetInfoTestWithParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}__UR_MEM_INFO_SIZE +urMemGetInfoTestWithParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}__UR_MEM_INFO_CONTEXT +urMemGetInfoTestWithParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}__UR_MEM_INFO_REFERENCE_COUNT +urMemGetInfoTest.InvalidSizeSmall/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} urMemImageCreateTestWithImageFormatParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}__UR_IMAGE_CHANNEL_ORDER_A__UR_IMAGE_CHANNEL_TYPE_SNORM_INT8 urMemImageCreateTestWithImageFormatParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}__UR_IMAGE_CHANNEL_ORDER_A__UR_IMAGE_CHANNEL_TYPE_SNORM_INT16 urMemImageCreateTestWithImageFormatParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}__UR_IMAGE_CHANNEL_ORDER_A__UR_IMAGE_CHANNEL_TYPE_UNORM_INT8 @@ -232,3 +234,10 @@ urMemImageCreateTestWithImageFormatParam.Success/SYCL_NATIVE_CPU___SYCL_Native_C urMemImageCreateTestWithImageFormatParam.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}__UR_IMAGE_CHANNEL_ORDER_SRGBA__UR_IMAGE_CHANNEL_TYPE_FLOAT urMemReleaseTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} urMemRetainTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} +urMemReleaseTest.CheckReferenceCount/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} +urMemRetainTest.CheckReferenceCount/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} +urMemBufferCreateWithNativeHandleTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} +urMemBufferCreateWithNativeHandleTest.SuccessWithOwnedNativeHandle/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} +urMemBufferCreateWithNativeHandleTest.SuccessWithUnOwnedNativeHandle/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} +urMemBufferCreateWithNativeHandleTest.InvalidNullHandle/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} +urMemBufferCreateWithNativeHandleTest.InvalidNullPointer/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} diff --git a/test/conformance/memory/memory_adapter_opencl.match b/test/conformance/memory/memory_adapter_opencl.match deleted file mode 100644 index b57e3876d0..0000000000 --- a/test/conformance/memory/memory_adapter_opencl.match +++ /dev/null @@ -1,2 +0,0 @@ -{{NONDETERMINISTIC}} -urMemImageCreateTest.InvalidImageDescStype/Intel_R__OpenCL___{{.*}} diff --git a/test/conformance/memory/urMemBufferCreate.cpp b/test/conformance/memory/urMemBufferCreate.cpp index 2e9b46114d..df90c4b63a 100644 --- a/test/conformance/memory/urMemBufferCreate.cpp +++ b/test/conformance/memory/urMemBufferCreate.cpp @@ -31,6 +31,19 @@ TEST_P(urMemBufferCreateWithFlagsTest, InvalidNullHandleContext) { urMemBufferCreate(nullptr, getParam(), 4096, nullptr, buffer.ptr())); } +TEST_P(urMemBufferCreateWithFlagsTest, InvalidNullPointerBuffer) { + ASSERT_EQ_RESULT( + UR_RESULT_ERROR_INVALID_NULL_POINTER, + urMemBufferCreate(context, getParam(), 4096, nullptr, nullptr)); +} + +TEST_P(urMemBufferCreateWithFlagsTest, InvalidBufferSizeZero) { + uur::raii::Mem buffer = nullptr; + ASSERT_EQ_RESULT( + UR_RESULT_ERROR_INVALID_BUFFER_SIZE, + urMemBufferCreate(context, getParam(), 0, nullptr, buffer.ptr())); +} + using urMemBufferCreateTest = uur::urContextTest; UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemBufferCreateTest); @@ -41,6 +54,37 @@ TEST_P(urMemBufferCreateTest, InvalidEnumerationFlags) { nullptr, buffer.ptr())); } +TEST_P(urMemBufferCreateTest, InvalidHostPtrNullProperties) { + uur::raii::Mem buffer = nullptr; + ur_mem_flags_t flags = + UR_MEM_FLAG_USE_HOST_POINTER | UR_MEM_FLAG_ALLOC_COPY_HOST_POINTER; + ASSERT_EQ_RESULT( + UR_RESULT_ERROR_INVALID_HOST_PTR, + urMemBufferCreate(context, flags, 4096, nullptr, buffer.ptr())); +} + +TEST_P(urMemBufferCreateTest, InvalidHostPtrNullHost) { + uur::raii::Mem buffer = nullptr; + ur_mem_flags_t flags = + UR_MEM_FLAG_USE_HOST_POINTER | UR_MEM_FLAG_ALLOC_COPY_HOST_POINTER; + ur_buffer_properties_t properties; + properties.pHost = nullptr; + ASSERT_EQ_RESULT( + UR_RESULT_ERROR_INVALID_HOST_PTR, + urMemBufferCreate(context, flags, 4096, &properties, buffer.ptr())); +} + +TEST_P(urMemBufferCreateTest, InvalidHostPtrValidHost) { + uur::raii::Mem buffer = nullptr; + ur_mem_flags_t flags = 0; + ur_buffer_properties_t properties; + int data = 42; + properties.pHost = &data; + ASSERT_EQ_RESULT( + UR_RESULT_ERROR_INVALID_HOST_PTR, + urMemBufferCreate(context, flags, 4096, &properties, buffer.ptr())); +} + using urMemBufferCreateWithHostPtrFlagsTest = urMemBufferCreateTestWithFlagsParam; UUR_TEST_SUITE_P(urMemBufferCreateWithHostPtrFlagsTest, @@ -59,23 +103,3 @@ TEST_P(urMemBufferCreateWithHostPtrFlagsTest, SUCCESS) { ASSERT_SUCCESS(urMemBufferCreate(context, getParam(), 4096, &properties, buffer.ptr())); } - -TEST_P(urMemBufferCreateWithHostPtrFlagsTest, InvalidHostPtr) { - uur::raii::Mem buffer = nullptr; - ASSERT_EQ_RESULT( - UR_RESULT_ERROR_INVALID_HOST_PTR, - urMemBufferCreate(context, getParam(), 4096, nullptr, buffer.ptr())); -} - -TEST_P(urMemBufferCreateWithFlagsTest, InvalidNullPointerBuffer) { - ASSERT_EQ_RESULT( - UR_RESULT_ERROR_INVALID_NULL_POINTER, - urMemBufferCreate(context, getParam(), 4096, nullptr, nullptr)); -} - -TEST_P(urMemBufferCreateWithFlagsTest, InvalidBufferSizeZero) { - uur::raii::Mem buffer = nullptr; - ASSERT_EQ_RESULT( - UR_RESULT_ERROR_INVALID_BUFFER_SIZE, - urMemBufferCreate(context, getParam(), 0, nullptr, buffer.ptr())); -} diff --git a/test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp b/test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp index 8b98076cf6..78e2510369 100644 --- a/test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp +++ b/test/conformance/memory/urMemBufferCreateWithNativeHandle.cpp @@ -11,23 +11,15 @@ UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemBufferCreateWithNativeHandleTest); TEST_P(urMemBufferCreateWithNativeHandleTest, Success) { ur_native_handle_t hNativeMem = 0; - { - UUR_ASSERT_SUCCESS_OR_UNSUPPORTED( - urMemGetNativeHandle(buffer, device, &hNativeMem)); - } + ASSERT_SUCCESS(urMemGetNativeHandle(buffer, device, &hNativeMem)); // We cannot assume anything about a native_handle, not even if it's // `nullptr` since this could be a valid representation within a backend. // We can however convert the native_handle back into a unified-runtime handle // and perform some query on it to verify that it works. ur_mem_handle_t mem = nullptr; - ur_mem_native_properties_t props = { - /*.stype =*/UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES, - /*.pNext =*/nullptr, - /*.isNativeHandleOwned =*/false, - }; - UUR_ASSERT_SUCCESS_OR_UNSUPPORTED( - urMemBufferCreateWithNativeHandle(hNativeMem, context, &props, &mem)); + ASSERT_SUCCESS( + urMemBufferCreateWithNativeHandle(hNativeMem, context, nullptr, &mem)); ASSERT_NE(mem, nullptr); size_t alloc_size = 0; @@ -37,12 +29,81 @@ TEST_P(urMemBufferCreateWithNativeHandleTest, Success) { ASSERT_SUCCESS(urMemRelease(mem)); } -using urMemBufferMultiQueueMemBufferTest = uur::urMultiDeviceMemBufferQueueTest; +TEST_P(urMemBufferCreateWithNativeHandleTest, SuccessWithOwnedNativeHandle) { + ur_native_handle_t native_handle = 0; + ASSERT_SUCCESS(urMemGetNativeHandle(buffer, device, &native_handle)); + + ur_mem_handle_t mem = nullptr; + ur_mem_native_properties_t props = { + /*.stype =*/UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES, + /*.pNext =*/nullptr, + /*.isNativeHandleOwned =*/true, + }; + ASSERT_SUCCESS(urMemBufferCreateWithNativeHandle(native_handle, context, + &props, &mem)); + ASSERT_NE(nullptr, mem); + ur_context_handle_t mem_context = nullptr; + ASSERT_SUCCESS(urMemGetInfo(mem, UR_MEM_INFO_CONTEXT, + sizeof(ur_context_handle_t), &mem_context, + nullptr)); + ASSERT_EQ(context, mem_context); +} + +TEST_P(urMemBufferCreateWithNativeHandleTest, SuccessWithUnOwnedNativeHandle) { + ur_native_handle_t native_handle = 0; + ASSERT_SUCCESS(urMemGetNativeHandle(buffer, device, &native_handle)); + + ur_mem_handle_t mem = nullptr; + ur_mem_native_properties_t props = { + /*.stype =*/UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES, + /*.pNext =*/nullptr, + /*.isNativeHandleOwned =*/false, + }; + ASSERT_SUCCESS(urMemBufferCreateWithNativeHandle(native_handle, context, + &props, &mem)); + ASSERT_NE(nullptr, mem); + + ur_context_handle_t mem_context = nullptr; + ASSERT_SUCCESS(urMemGetInfo(mem, UR_MEM_INFO_CONTEXT, + sizeof(ur_context_handle_t), &mem_context, + nullptr)); + ASSERT_EQ(context, mem_context); +} + +TEST_P(urMemBufferCreateWithNativeHandleTest, InvalidNullHandle) { + ur_native_handle_t hNativeMem = 0; + ASSERT_SUCCESS(urMemGetNativeHandle(buffer, device, &hNativeMem)); + + ur_mem_handle_t mem = nullptr; + ur_mem_native_properties_t props = { + /*.stype =*/UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES, + /*.pNext =*/nullptr, + /*.isNativeHandleOwned =*/false, + }; + ASSERT_EQ( + urMemBufferCreateWithNativeHandle(hNativeMem, nullptr, &props, &mem), + UR_RESULT_ERROR_INVALID_NULL_HANDLE); +} + +TEST_P(urMemBufferCreateWithNativeHandleTest, InvalidNullPointer) { + ur_native_handle_t hNativeMem = 0; + ASSERT_SUCCESS(urMemGetNativeHandle(buffer, device, &hNativeMem)); + + ur_mem_native_properties_t props = { + /*.stype =*/UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES, + /*.pNext =*/nullptr, + /*.isNativeHandleOwned =*/false, + }; + ASSERT_EQ( + urMemBufferCreateWithNativeHandle(hNativeMem, context, &props, nullptr), + UR_RESULT_ERROR_INVALID_NULL_POINTER); +} + +using urMemBufferMultiQueueMemBufferTest = uur::urMultiDeviceMemBufferQueueTest; TEST_F(urMemBufferMultiQueueMemBufferTest, WriteBack) { void *ptr; ASSERT_SUCCESS(urUSMHostAlloc(context, nullptr, nullptr, size, &ptr)); - ur_mem_handle_t mem = nullptr; ur_mem_native_properties_t props = { /*.stype =*/UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES, @@ -54,26 +115,20 @@ TEST_F(urMemBufferMultiQueueMemBufferTest, WriteBack) { reinterpret_cast(ptr), context, &props, &mem)); } ASSERT_NE(mem, nullptr); - const uint8_t pattern = 0x11; std::vector src(size, pattern); - // write data to the buffer and destroy the buffer ASSERT_SUCCESS(urEnqueueMemBufferWrite(queues[1], mem, true, 0, size, src.data(), 0, nullptr, nullptr)); ASSERT_SUCCESS(urMemRelease(mem)); - // Create the buffer again and read back the data, data should have been written to the // memory behind the native handle. Use different queue to test data migration logic. ASSERT_SUCCESS(urMemBufferCreateWithNativeHandle( reinterpret_cast(ptr), context, &props, &mem)); ASSERT_NE(mem, nullptr); - std::vector dst(size, 0); ASSERT_SUCCESS(urEnqueueMemBufferRead(queues[0], mem, true, 0, size, dst.data(), 0, nullptr, nullptr)); - ASSERT_EQ(src, dst); - ASSERT_SUCCESS(urMemRelease(mem)); } diff --git a/test/conformance/memory/urMemBufferPartition.cpp b/test/conformance/memory/urMemBufferPartition.cpp index 01ab7f8c62..fca20693c7 100644 --- a/test/conformance/memory/urMemBufferPartition.cpp +++ b/test/conformance/memory/urMemBufferPartition.cpp @@ -6,19 +6,32 @@ #include "uur/fixtures.h" #include "uur/raii.h" -using urMemBufferPartitionTest = uur::urMemBufferTest; -UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemBufferPartitionTest); +using urMemBufferPartitionWithFlagsTest = + uur::urContextTestWithParam; +UUR_TEST_SUITE_P(urMemBufferPartitionWithFlagsTest, + ::testing::Values(UR_MEM_FLAG_READ_WRITE, + UR_MEM_FLAG_WRITE_ONLY, + UR_MEM_FLAG_READ_ONLY), + uur::deviceTestWithParamPrinter); -TEST_P(urMemBufferPartitionTest, Success) { - ur_buffer_region_t region{UR_STRUCTURE_TYPE_BUFFER_REGION, nullptr, 0, - 1024}; +TEST_P(urMemBufferPartitionWithFlagsTest, Success) { + uur::raii::Mem buffer = nullptr; + + ASSERT_SUCCESS( + urMemBufferCreate(context, getParam(), 1024, nullptr, buffer.ptr())); + ASSERT_NE(nullptr, buffer); + + ur_buffer_region_t region{UR_STRUCTURE_TYPE_BUFFER_REGION, nullptr, 0, 512}; uur::raii::Mem partition = nullptr; - ASSERT_SUCCESS(urMemBufferPartition(buffer, UR_MEM_FLAG_READ_WRITE, + ASSERT_SUCCESS(urMemBufferPartition(buffer, getParam(), UR_BUFFER_CREATE_TYPE_REGION, ®ion, partition.ptr())); ASSERT_NE(partition, nullptr); } +using urMemBufferPartitionTest = uur::urMemBufferTest; +UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemBufferPartitionTest); + TEST_P(urMemBufferPartitionTest, InvalidNullHandleBuffer) { ur_buffer_region_t region{UR_STRUCTURE_TYPE_BUFFER_REGION, nullptr, 0, 1024}; diff --git a/test/conformance/memory/urMemGetInfo.cpp b/test/conformance/memory/urMemGetInfo.cpp index a28b581a26..3f933d39a9 100644 --- a/test/conformance/memory/urMemGetInfo.cpp +++ b/test/conformance/memory/urMemGetInfo.cpp @@ -6,19 +6,21 @@ #include #include -using urMemGetInfoTest = uur::urMemBufferTestWithParam; +using urMemGetInfoTestWithParam = uur::urMemBufferTestWithParam; -static constexpr std::array mem_info_values{ - UR_MEM_INFO_SIZE, UR_MEM_INFO_CONTEXT}; +static constexpr std::array mem_info_values{ + UR_MEM_INFO_SIZE, UR_MEM_INFO_CONTEXT, UR_MEM_INFO_REFERENCE_COUNT}; static std::unordered_map mem_info_size_map = { {UR_MEM_INFO_SIZE, sizeof(size_t)}, {UR_MEM_INFO_CONTEXT, sizeof(ur_context_handle_t)}, + {UR_MEM_INFO_REFERENCE_COUNT, sizeof(uint32_t)}, }; -UUR_TEST_SUITE_P(urMemGetInfoTest, ::testing::ValuesIn(mem_info_values), +UUR_TEST_SUITE_P(urMemGetInfoTestWithParam, + ::testing::ValuesIn(mem_info_values), uur::deviceTestWithParamPrinter); -TEST_P(urMemGetInfoTest, Success) { +TEST_P(urMemGetInfoTestWithParam, Success) { ur_mem_info_t info = getParam(); size_t size; ASSERT_SUCCESS(urMemGetInfo(buffer, info, 0, nullptr, &size)); @@ -44,11 +46,20 @@ TEST_P(urMemGetInfoTest, Success) { ASSERT_GE(*returned_size, allocation_size); break; } + case UR_MEM_INFO_REFERENCE_COUNT: { + const size_t ReferenceCount = + *reinterpret_cast(info_data.data()); + ASSERT_GT(ReferenceCount, 0); + break; + } default: break; } } +using urMemGetInfoTest = uur::urMemBufferTest; +UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemGetInfoTest); + TEST_P(urMemGetInfoTest, InvalidNullHandleMemory) { size_t mem_size = 0; ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE, @@ -108,16 +119,30 @@ TEST_P(urMemGetInfoImageTest, Success) { std::vector info_data(size); ASSERT_SUCCESS(urMemGetInfo(image, info, size, info_data.data(), nullptr)); - if (info == UR_MEM_INFO_SIZE) { + switch (info) { + case UR_MEM_INFO_SIZE: { const size_t ExpectedPixelSize = sizeof(float) * 4 /*NumChannels*/; const size_t ExpectedImageSize = ExpectedPixelSize * desc.arraySize * desc.width * desc.height * desc.depth; const size_t ImageSizeBytes = *reinterpret_cast(info_data.data()); ASSERT_EQ(ImageSizeBytes, ExpectedImageSize); - } else if (info == UR_MEM_INFO_CONTEXT) { + break; + } + case UR_MEM_INFO_CONTEXT: { ur_context_handle_t InfoContext = *reinterpret_cast(info_data.data()); ASSERT_EQ(InfoContext, context); + break; + } + case UR_MEM_INFO_REFERENCE_COUNT: { + const size_t ReferenceCount = + *reinterpret_cast(info_data.data()); + ASSERT_GT(ReferenceCount, 0); + break; + } + + default: + break; } } diff --git a/test/conformance/memory/urMemImageCreate.cpp b/test/conformance/memory/urMemImageCreate.cpp index 28d5d9c4e3..bfb4f6e719 100644 --- a/test/conformance/memory/urMemImageCreate.cpp +++ b/test/conformance/memory/urMemImageCreate.cpp @@ -286,6 +286,25 @@ TEST_P(urMemImageCreateTest, InvalidImageDescSlicePitch) { nullptr, image_handle.ptr())); } +TEST_P(urMemImageCreateTest, InvalidHostPtrNullHost) { + uur::raii::Mem image_handle = nullptr; + ur_mem_flags_t flags = + UR_MEM_FLAG_USE_HOST_POINTER | UR_MEM_FLAG_ALLOC_COPY_HOST_POINTER; + ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_HOST_PTR, + urMemImageCreate(context, flags, &image_format, + &image_desc, nullptr, + image_handle.ptr())); +} + +TEST_P(urMemImageCreateTest, InvalidHostPtrValidHost) { + uur::raii::Mem image_handle = nullptr; + ur_mem_flags_t flags = 0; + int data = 42; + ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_HOST_PTR, + urMemImageCreate(context, flags, &image_format, + &image_desc, &data, image_handle.ptr())); +} + using urMemImageCreateWithHostPtrFlagsTest = urMemImageCreateTestWithParam; @@ -306,11 +325,3 @@ TEST_P(urMemImageCreateWithHostPtrFlagsTest, Success) { image_handle.ptr())); ASSERT_NE(nullptr, image_handle.ptr()); } - -TEST_P(urMemImageCreateWithHostPtrFlagsTest, InvalidHostPtr) { - uur::raii::Mem image_handle = nullptr; - ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_HOST_PTR, - urMemImageCreate(context, getParam(), &image_format, - &image_desc, nullptr, - image_handle.ptr())); -} diff --git a/test/conformance/memory/urMemImageCreateWithNativeHandle.cpp b/test/conformance/memory/urMemImageCreateWithNativeHandle.cpp index 3404b4203f..c33cc814a3 100644 --- a/test/conformance/memory/urMemImageCreateWithNativeHandle.cpp +++ b/test/conformance/memory/urMemImageCreateWithNativeHandle.cpp @@ -10,15 +10,11 @@ UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemImageCreateWithNativeHandleTest); TEST_P(urMemImageCreateWithNativeHandleTest, Success) { ur_native_handle_t native_handle = 0; - if (urMemGetNativeHandle(image, device, &native_handle)) { - GTEST_SKIP(); - } + ASSERT_SUCCESS(urMemGetNativeHandle(image, device, &native_handle)); ur_mem_handle_t mem = nullptr; - ASSERT_EQ_RESULT( - UR_RESULT_ERROR_INVALID_NULL_HANDLE, - urMemImageCreateWithNativeHandle(native_handle, context, &image_format, - &image_desc, nullptr, &mem)); + ASSERT_SUCCESS(urMemImageCreateWithNativeHandle( + native_handle, context, &image_format, &image_desc, nullptr, &mem)); ASSERT_NE(nullptr, mem); ur_context_handle_t mem_context = nullptr; @@ -27,3 +23,24 @@ TEST_P(urMemImageCreateWithNativeHandleTest, Success) { nullptr)); ASSERT_EQ(context, mem_context); } + +TEST_P(urMemImageCreateWithNativeHandleTest, InvalidNullHandle) { + ur_native_handle_t native_handle = 0; + ASSERT_SUCCESS(urMemGetNativeHandle(image, device, &native_handle)); + + ur_mem_handle_t mem = nullptr; + ASSERT_EQ_RESULT( + UR_RESULT_ERROR_INVALID_NULL_HANDLE, + urMemImageCreateWithNativeHandle(native_handle, nullptr, &image_format, + &image_desc, nullptr, &mem)); +} + +TEST_P(urMemImageCreateWithNativeHandleTest, InvalidNullPointer) { + ur_native_handle_t native_handle = 0; + ASSERT_SUCCESS(urMemGetNativeHandle(image, device, &native_handle)); + + ASSERT_EQ_RESULT( + UR_RESULT_ERROR_INVALID_NULL_POINTER, + urMemImageCreateWithNativeHandle(native_handle, context, &image_format, + &image_desc, nullptr, nullptr)); +} diff --git a/test/conformance/memory/urMemRelease.cpp b/test/conformance/memory/urMemRelease.cpp index 3e84142638..730b6aa854 100644 --- a/test/conformance/memory/urMemRelease.cpp +++ b/test/conformance/memory/urMemRelease.cpp @@ -16,3 +16,24 @@ TEST_P(urMemReleaseTest, InvalidNullHandleMem) { ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE, urMemRelease(nullptr)); } + +TEST_P(urMemReleaseTest, CheckReferenceCount) { + uint32_t referenceCount = 0; + ASSERT_SUCCESS(urMemGetInfo(buffer, UR_MEM_INFO_REFERENCE_COUNT, + sizeof(referenceCount), &referenceCount, + nullptr)); + ASSERT_EQ(referenceCount, 1); + + ASSERT_SUCCESS(urMemRetain(buffer)); + ASSERT_SUCCESS(urMemGetInfo(buffer, UR_MEM_INFO_REFERENCE_COUNT, + sizeof(referenceCount), &referenceCount, + nullptr)); + ASSERT_EQ(referenceCount, 2); + + ASSERT_SUCCESS(urMemRelease(buffer)); + + ASSERT_SUCCESS(urMemGetInfo(buffer, UR_MEM_INFO_REFERENCE_COUNT, + sizeof(referenceCount), &referenceCount, + nullptr)); + ASSERT_EQ(referenceCount, 1); +} diff --git a/test/conformance/memory/urMemRetain.cpp b/test/conformance/memory/urMemRetain.cpp index 895d68097e..a58896a91b 100644 --- a/test/conformance/memory/urMemRetain.cpp +++ b/test/conformance/memory/urMemRetain.cpp @@ -9,9 +9,31 @@ UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemRetainTest); TEST_P(urMemRetainTest, Success) { ASSERT_SUCCESS(urMemRetain(buffer)); - EXPECT_SUCCESS(urMemRelease(buffer)); + ASSERT_SUCCESS(urMemRelease(buffer)); } TEST_P(urMemRetainTest, InvalidNullHandleMem) { ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE, urMemRetain(nullptr)); } + +TEST_P(urMemRetainTest, CheckReferenceCount) { + uint32_t referenceCount = 0; + ASSERT_SUCCESS(urMemGetInfo(buffer, UR_MEM_INFO_REFERENCE_COUNT, + sizeof(referenceCount), &referenceCount, + nullptr)); + ASSERT_EQ(referenceCount, 1); + + { ASSERT_SUCCESS(urMemRetain(buffer)); } + + ASSERT_SUCCESS(urMemGetInfo(buffer, UR_MEM_INFO_REFERENCE_COUNT, + sizeof(referenceCount), &referenceCount, + nullptr)); + ASSERT_EQ(referenceCount, 2); + + ASSERT_SUCCESS(urMemRelease(buffer)); + + ASSERT_SUCCESS(urMemGetInfo(buffer, UR_MEM_INFO_REFERENCE_COUNT, + sizeof(referenceCount), &referenceCount, + nullptr)); + ASSERT_EQ(referenceCount, 1); +} diff --git a/test/conformance/testing/include/uur/fixtures.h b/test/conformance/testing/include/uur/fixtures.h index d1b373af84..80b6db5268 100644 --- a/test/conformance/testing/include/uur/fixtures.h +++ b/test/conformance/testing/include/uur/fixtures.h @@ -205,6 +205,9 @@ struct urMemImageTest : urContextTest { if (!imageSupported) { GTEST_SKIP(); } + ASSERT_SUCCESS(urMemImageCreate(context, UR_MEM_FLAG_READ_WRITE, + &image_format, &image_desc, nullptr, + &image)); } void TearDown() override { @@ -215,7 +218,7 @@ struct urMemImageTest : urContextTest { } ur_image_format_t image_format = { - /*.channelOrder =*/UR_IMAGE_CHANNEL_ORDER_ARGB, + /*.channelOrder =*/UR_IMAGE_CHANNEL_ORDER_RGBA, /*.channelType =*/UR_IMAGE_CHANNEL_TYPE_UNORM_INT8, }; ur_image_desc_t image_desc = { @@ -226,8 +229,8 @@ struct urMemImageTest : urContextTest { /*.height =*/16, /*.depth =*/1, /*.arraySize =*/1, - /*.rowPitch =*/16 * sizeof(char[4]), - /*.slicePitch =*/16 * 16 * sizeof(char[4]), + /*.rowPitch =*/0, + /*.slicePitch =*/0, /*.numMipLevel =*/0, /*.numSamples =*/0, }; From 65edd6b88855960d8c350e28505f438a71275946 Mon Sep 17 00:00:00 2001 From: Martin Morrison-Grant Date: Fri, 25 Oct 2024 17:43:27 +0100 Subject: [PATCH 2/4] Check if properties param is null in L0 urMemBufferCreateWithNativeHandle and set OwnNativeHandle to false by default. --- source/adapters/level_zero/memory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/adapters/level_zero/memory.cpp b/source/adapters/level_zero/memory.cpp index cd12800bdd..456ad56b80 100644 --- a/source/adapters/level_zero/memory.cpp +++ b/source/adapters/level_zero/memory.cpp @@ -1746,7 +1746,7 @@ ur_result_t urMemBufferCreateWithNativeHandle( ur_mem_handle_t *Mem ///< [out] pointer to handle of buffer memory object created. ) { - bool OwnNativeHandle = Properties->isNativeHandleOwned; + bool OwnNativeHandle = Properties ? Properties->isNativeHandleOwned : false; std::shared_lock Lock(Context->Mutex); From 827e857162f6ae0f6e7749b55195f1cfba14c4b2 Mon Sep 17 00:00:00 2001 From: Martin Morrison-Grant Date: Mon, 28 Oct 2024 09:26:56 +0000 Subject: [PATCH 3/4] Add urMemImageCreateWithNativeHandleTest.Success to L0 match file. --- source/adapters/level_zero/v2/memory.cpp | 2 +- test/conformance/memory/memory_adapter_level_zero.match | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/source/adapters/level_zero/v2/memory.cpp b/source/adapters/level_zero/v2/memory.cpp index 05a25aa256..52bfea42a4 100644 --- a/source/adapters/level_zero/v2/memory.cpp +++ b/source/adapters/level_zero/v2/memory.cpp @@ -523,7 +523,7 @@ ur_result_t urMemGetInfo(ur_mem_handle_t hMemory, ur_mem_info_t propName, return returnValue(size_t{hMemory->getSize()}); } case UR_MEM_INFO_REFERENCE_COUNT: { - return returnValue(hMemory->RefCount.load()); + return returnValue(hMemory->getRefCount().load()); } default: { return UR_RESULT_ERROR_INVALID_ENUMERATION; diff --git a/test/conformance/memory/memory_adapter_level_zero.match b/test/conformance/memory/memory_adapter_level_zero.match index f25d8f23f3..bce63823cc 100644 --- a/test/conformance/memory/memory_adapter_level_zero.match +++ b/test/conformance/memory/memory_adapter_level_zero.match @@ -4,6 +4,7 @@ urMemBufferPartitionWithFlagsTest.Success/Intel_R__oneAPI_Unified_Runtime_over_L urMemBufferPartitionWithFlagsTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}__UR_MEM_FLAG_READ_ONLY urMemBufferPartitionTest.InvalidValueCreateType/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ urMemBufferPartitionTest.InvalidValueBufferCreateInfoOutOfBounds/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ +{{OPT}}urMemImageCreateWithNativeHandleTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} {{OPT}}urMemGetInfoImageTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_INFO_SIZE {{OPT}}urMemImageCreateTestWithImageFormatParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_CHANNEL_ORDER_RGBA__UR_IMAGE_CHANNEL_TYPE_SNORM_INT8 {{OPT}}urMemImageCreateTestWithImageFormatParam.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_CHANNEL_ORDER_RGBA__UR_IMAGE_CHANNEL_TYPE_SNORM_INT16 From dd920712a37c17fada6a64d4736350905faf6023 Mon Sep 17 00:00:00 2001 From: Martin Morrison-Grant Date: Wed, 6 Nov 2024 11:39:24 +0000 Subject: [PATCH 4/4] Add {{OPT}} to various L0V2 match entries --- .../memory/memory_adapter_level_zero_v2.match | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/conformance/memory/memory_adapter_level_zero_v2.match b/test/conformance/memory/memory_adapter_level_zero_v2.match index a0a5823fbc..3ff57fc1e5 100644 --- a/test/conformance/memory/memory_adapter_level_zero_v2.match +++ b/test/conformance/memory/memory_adapter_level_zero_v2.match @@ -1,9 +1,9 @@ {{NONDETERMINISTIC}} -urMemBufferPartitionWithFlagsTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_FLAG_WRITE_ONLY -urMemBufferPartitionWithFlagsTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_FLAG_READ_ONLY -urMemBufferPartitionWithFlagsTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_FLAG_READ_WRITE -urMemBufferPartitionTest.InvalidValueCreateType/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ -urMemBufferPartitionTest.InvalidValueBufferCreateInfoOutOfBounds/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ +{{OPT}}urMemBufferPartitionWithFlagsTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_FLAG_WRITE_ONLY +{{OPT}}urMemBufferPartitionWithFlagsTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_FLAG_READ_ONLY +{{OPT}}urMemBufferPartitionWithFlagsTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_FLAG_READ_WRITE +{{OPT}}urMemBufferPartitionTest.InvalidValueCreateType/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ +{{OPT}}urMemBufferPartitionTest.InvalidValueBufferCreateInfoOutOfBounds/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ {{OPT}}urMemGetInfoImageTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_INFO_SIZE {{OPT}}urMemGetInfoImageTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_INFO_CONTEXT {{OPT}}urMemGetInfoImageTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_MEM_INFO_REFERENCE_COUNT @@ -281,11 +281,11 @@ urMemBufferPartitionTest.InvalidValueBufferCreateInfoOutOfBounds/Intel_R__oneAPI {{OPT}}urMemImageGetInfoTest.InvalidNullPointerPropSizeRet/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_INFO_WIDTH {{OPT}}urMemImageGetInfoTest.InvalidNullPointerPropSizeRet/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_INFO_HEIGHT {{OPT}}urMemImageGetInfoTest.InvalidNullPointerPropSizeRet/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}___UR_IMAGE_INFO_DEPTH -urMemBufferCreateWithNativeHandleTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} -urMemBufferCreateWithNativeHandleTest.SuccessWithOwnedNativeHandle/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} -urMemBufferCreateWithNativeHandleTest.SuccessWithUnOwnedNativeHandle/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} -urMemBufferCreateWithNativeHandleTest.InvalidNullHandle/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} -urMemBufferCreateWithNativeHandleTest.InvalidNullPointer/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} +{{OPT}}urMemBufferCreateWithNativeHandleTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} +{{OPT}}urMemBufferCreateWithNativeHandleTest.SuccessWithOwnedNativeHandle/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} +{{OPT}}urMemBufferCreateWithNativeHandleTest.SuccessWithUnOwnedNativeHandle/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} +{{OPT}}urMemBufferCreateWithNativeHandleTest.InvalidNullHandle/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} +{{OPT}}urMemBufferCreateWithNativeHandleTest.InvalidNullPointer/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} {{OPT}}urMemImageCreateWithNativeHandleTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} {{OPT}}urMemImageCreateWithNativeHandleTest.InvalidNullHandle/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} {{OPT}}urMemImageCreateWithNativeHandleTest.InvalidNullPointer/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}