From a955bec2507f7d3aba353f1fd148456e9bf48fec Mon Sep 17 00:00:00 2001 From: Aaron Greig Date: Mon, 14 Oct 2024 12:16:26 +0100 Subject: [PATCH] Fix CTS tests --- source/adapters/cuda/queue.cpp | 20 ++++++------ source/adapters/hip/memory.cpp | 3 ++ source/adapters/hip/queue.cpp | 20 ++++++------ source/adapters/level_zero/kernel.cpp | 6 ++-- source/adapters/level_zero/program.cpp | 9 +++--- .../adapters/opencl/ur_interface_loader.cpp | 1 + .../event/event_adapter_native_cpu.match | 1 + .../kernel/kernel_adapter_native_cpu.match | 1 + .../program/program_adapter_level_zero.match | 4 --- .../program/program_adapter_native_cpu.match | 1 + .../testing/include/uur/fixtures.h | 32 +++++++++---------- 11 files changed, 52 insertions(+), 46 deletions(-) diff --git a/source/adapters/cuda/queue.cpp b/source/adapters/cuda/queue.cpp index 548940f853..b9779f37be 100644 --- a/source/adapters/cuda/queue.cpp +++ b/source/adapters/cuda/queue.cpp @@ -284,17 +284,19 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle( std::vector ComputeCuStreams(1, CuStream); std::vector TransferCuStreams(0); + auto isNativeHandleOwned = + pProperties ? pProperties->isNativeHandleOwned : false; + // Create queue and set num_compute_streams to 1, as computeCuStreams has // valid stream - *phQueue = - new ur_queue_handle_t_{std::move(ComputeCuStreams), - std::move(TransferCuStreams), - hContext, - hDevice, - CuFlags, - Flags, - /*priority*/ 0, - /*backend_owns*/ pProperties->isNativeHandleOwned}; + *phQueue = new ur_queue_handle_t_{std::move(ComputeCuStreams), + std::move(TransferCuStreams), + hContext, + hDevice, + CuFlags, + Flags, + /*priority*/ 0, + /*backend_owns*/ isNativeHandleOwned}; (*phQueue)->NumComputeStreams = 1; return UR_RESULT_SUCCESS; diff --git a/source/adapters/hip/memory.cpp b/source/adapters/hip/memory.cpp index aa7b5f4040..3f567da1ab 100644 --- a/source/adapters/hip/memory.cpp +++ b/source/adapters/hip/memory.cpp @@ -302,6 +302,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemGetNativeHandle(ur_mem_handle_t hMem, ur_device_handle_t Device, ur_native_handle_t *phNativeMem) { UR_ASSERT(Device != nullptr, UR_RESULT_ERROR_INVALID_NULL_HANDLE); + if (hMem->isImage()) { + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; + } #if defined(__HIP_PLATFORM_NVIDIA__) if (sizeof(BufferMem::native_type) > sizeof(ur_native_handle_t)) { // Check that all the upper bits that cannot be represented by diff --git a/source/adapters/hip/queue.cpp b/source/adapters/hip/queue.cpp index 5ab28d45ba..94177e097d 100644 --- a/source/adapters/hip/queue.cpp +++ b/source/adapters/hip/queue.cpp @@ -318,17 +318,19 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle( std::vector ComputeHIPStreams(1, HIPStream); std::vector TransferHIPStreams(0); + auto isNativeHandleOwned = + pProperties ? pProperties->isNativeHandleOwned : false; + // Create queue and set num_compute_streams to 1, as computeHIPStreams has // valid stream - *phQueue = - new ur_queue_handle_t_{std::move(ComputeHIPStreams), - std::move(TransferHIPStreams), - hContext, - hDevice, - HIPFlags, - Flags, - /*priority*/ 0, - /*backend_owns*/ pProperties->isNativeHandleOwned}; + *phQueue = new ur_queue_handle_t_{std::move(ComputeHIPStreams), + std::move(TransferHIPStreams), + hContext, + hDevice, + HIPFlags, + Flags, + /*priority*/ 0, + /*backend_owns*/ isNativeHandleOwned}; (*phQueue)->NumComputeStreams = 1; return UR_RESULT_SUCCESS; diff --git a/source/adapters/level_zero/kernel.cpp b/source/adapters/level_zero/kernel.cpp index c77bb22b8c..463ea415ab 100644 --- a/source/adapters/level_zero/kernel.cpp +++ b/source/adapters/level_zero/kernel.cpp @@ -1100,9 +1100,9 @@ ur_result_t urKernelCreateWithNativeHandle( ze_kernel_handle_t ZeKernel = ur_cast(NativeKernel); ur_kernel_handle_t_ *Kernel = nullptr; try { - Kernel = new ur_kernel_handle_t_(ZeKernel, Properties->isNativeHandleOwned, - Context); - if (Properties->isNativeHandleOwned) { + auto OwnNativeHandle = Properties ? Properties->isNativeHandleOwned : false; + Kernel = new ur_kernel_handle_t_(ZeKernel, OwnNativeHandle, Context); + if (OwnNativeHandle) { // If ownership is passed to the adapter we need to pass the kernel // to this vector which is then used during ZeKernelRelease. Kernel->ZeKernels.push_back(ZeKernel); diff --git a/source/adapters/level_zero/program.cpp b/source/adapters/level_zero/program.cpp index 5f5ec387a0..7669f2516c 100644 --- a/source/adapters/level_zero/program.cpp +++ b/source/adapters/level_zero/program.cpp @@ -933,7 +933,8 @@ ur_result_t urProgramGetNativeHandle( } default: - return UR_RESULT_ERROR_INVALID_OPERATION; + // L0 only supprts returning native handle from built programs. + return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } return UR_RESULT_SUCCESS; @@ -959,9 +960,9 @@ ur_result_t urProgramCreateWithNativeHandle( // executable (state Object). try { - ur_program_handle_t_ *UrProgram = - new ur_program_handle_t_(ur_program_handle_t_::Exe, Context, ZeModule, - Properties->isNativeHandleOwned); + auto OwnNativeHandle = Properties ? Properties->isNativeHandleOwned : false; + ur_program_handle_t_ *UrProgram = new ur_program_handle_t_( + ur_program_handle_t_::Exe, Context, ZeModule, OwnNativeHandle); *Program = reinterpret_cast(UrProgram); } catch (const std::bad_alloc &) { return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; diff --git a/source/adapters/opencl/ur_interface_loader.cpp b/source/adapters/opencl/ur_interface_loader.cpp index cbdab6e003..2f9834d8f3 100644 --- a/source/adapters/opencl/ur_interface_loader.cpp +++ b/source/adapters/opencl/ur_interface_loader.cpp @@ -158,6 +158,7 @@ urGetMemProcAddrTable(ur_api_version_t Version, ur_mem_dditable_t *pDdiTable) { pDdiTable->pfnGetNativeHandle = urMemGetNativeHandle; pDdiTable->pfnImageCreate = urMemImageCreate; pDdiTable->pfnImageGetInfo = urMemImageGetInfo; + pDdiTable->pfnImageCreateWithNativeHandle = urMemImageCreateWithNativeHandle; pDdiTable->pfnRelease = urMemRelease; pDdiTable->pfnRetain = urMemRetain; return UR_RESULT_SUCCESS; diff --git a/test/conformance/event/event_adapter_native_cpu.match b/test/conformance/event/event_adapter_native_cpu.match index 17066b6d52..c8bd637ed2 100644 --- a/test/conformance/event/event_adapter_native_cpu.match +++ b/test/conformance/event/event_adapter_native_cpu.match @@ -25,6 +25,7 @@ urEventReleaseTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} urEventGetNativeHandleTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} urEventGetNativeHandleTest.InvalidNullPointerNativeEvent/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} urEventCreateWithNativeHandleTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} +urEventCreateWithNativeHandleTest.SuccessWithProperties/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} urEventSetCallbackTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} urEventSetCallbackTest.ValidateParameters/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} urEventSetCallbackTest.AllStates/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} diff --git a/test/conformance/kernel/kernel_adapter_native_cpu.match b/test/conformance/kernel/kernel_adapter_native_cpu.match index 368f4ad358..ffdabbafc9 100644 --- a/test/conformance/kernel/kernel_adapter_native_cpu.match +++ b/test/conformance/kernel/kernel_adapter_native_cpu.match @@ -5,6 +5,7 @@ urKernelCreateTest.InvalidNullPointerName/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{. urKernelCreateTest.InvalidNullPointerKernel/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} urKernelCreateTest.InvalidKernelName/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} urKernelCreateWithNativeHandleTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} +urKernelCreateWithNativeHandleTest.SuccessWithProperties/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} urKernelCreateWithNativeHandleTest.InvalidNullHandleContext/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} urKernelCreateWithNativeHandleTest.InvalidNullPointerNativeKernel/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} urKernelGetGroupInfoTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}__UR_KERNEL_GROUP_INFO_GLOBAL_WORK_SIZE diff --git a/test/conformance/program/program_adapter_level_zero.match b/test/conformance/program/program_adapter_level_zero.match index 445f7e6fbd..e725765d76 100644 --- a/test/conformance/program/program_adapter_level_zero.match +++ b/test/conformance/program/program_adapter_level_zero.match @@ -1,10 +1,6 @@ {{NONDETERMINISTIC}} -urProgramCreateWithNativeHandleTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ -urProgramCreateWithNativeHandleTest.InvalidNullHandleContext/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ -urProgramCreateWithNativeHandleTest.InvalidNullPointerProgram/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ urProgramGetBuildInfoTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_UR_PROGRAM_BUILD_INFO_STATUS urProgramGetFunctionPointerTest.InvalidKernelName/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ -urProgramGetNativeHandleTest.Success/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ {{OPT}}urProgramLinkErrorTest.LinkFailure/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ {{OPT}}urProgramLinkErrorTest.SetOutputOnLinkError/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}}_ urProgramSetSpecializationConstantsTest.InvalidValueSize/Intel_R__oneAPI_Unified_Runtime_over_Level_Zero___{{.*}} diff --git a/test/conformance/program/program_adapter_native_cpu.match b/test/conformance/program/program_adapter_native_cpu.match index 55f467c42b..97ad83f987 100644 --- a/test/conformance/program/program_adapter_native_cpu.match +++ b/test/conformance/program/program_adapter_native_cpu.match @@ -23,6 +23,7 @@ {{OPT}}urProgramCreateWithILTest.InvalidNullPointerProgram/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} {{OPT}}urProgramCreateWithILTest.BuildInvalidProgram/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} {{OPT}}urProgramCreateWithNativeHandleTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} +{{OPT}}urProgramCreateWithNativeHandleTest.SuccessWithProperties/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} {{OPT}}urProgramCreateWithNativeHandleTest.InvalidNullHandleContext/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} {{OPT}}urProgramCreateWithNativeHandleTest.InvalidNullPointerProgram/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}} {{OPT}}urProgramGetBuildInfoTest.Success/SYCL_NATIVE_CPU___SYCL_Native_CPU__{{.*}}__UR_PROGRAM_BUILD_INFO_STATUS diff --git a/test/conformance/testing/include/uur/fixtures.h b/test/conformance/testing/include/uur/fixtures.h index 0aeee2d909..dbcd46cd33 100644 --- a/test/conformance/testing/include/uur/fixtures.h +++ b/test/conformance/testing/include/uur/fixtures.h @@ -205,6 +205,8 @@ struct urMemImageTest : urContextTest { if (!imageSupported) { GTEST_SKIP(); } + ASSERT_SUCCESS(urMemImageCreate(context, 0, &image_format, &image_desc, + nullptr, &image)); } void TearDown() override { @@ -214,23 +216,19 @@ struct urMemImageTest : urContextTest { UUR_RETURN_ON_FATAL_FAILURE(urContextTest::TearDown()); } - ur_image_format_t image_format = { - /*.channelOrder =*/UR_IMAGE_CHANNEL_ORDER_ARGB, - /*.channelType =*/UR_IMAGE_CHANNEL_TYPE_UNORM_INT8, - }; - ur_image_desc_t image_desc = { - /*.stype =*/UR_STRUCTURE_TYPE_IMAGE_DESC, - /*.pNext =*/nullptr, - /*.type =*/UR_MEM_TYPE_IMAGE2D, - /*.width =*/16, - /*.height =*/16, - /*.depth =*/1, - /*.arraySize =*/1, - /*.rowPitch =*/16 * sizeof(char[4]), - /*.slicePitch =*/16 * 16 * sizeof(char[4]), - /*.numMipLevel =*/0, - /*.numSamples =*/0, - }; + ur_image_format_t image_format = {UR_IMAGE_CHANNEL_ORDER_RGBA, + UR_IMAGE_CHANNEL_TYPE_FLOAT}; + ur_image_desc_t image_desc = {UR_STRUCTURE_TYPE_IMAGE_DESC, // stype + nullptr, // pNext + UR_MEM_TYPE_IMAGE1D, // mem object type + 1024, // image width + 1, // image height + 1, // image depth + 1, // array size + 0, // row pitch + 0, // slice pitch + 0, // mip levels + 0}; // num samples ur_mem_handle_t image = nullptr; };