From 924d74bccc2bb5e22198fb38019b7d976ba3bde6 Mon Sep 17 00:00:00 2001 From: Petr Vesely Date: Wed, 18 Oct 2023 13:18:03 +0100 Subject: [PATCH] [HIP] Fix segfaults --- source/adapters/hip/kernel.cpp | 8 ++++++-- test/conformance/enqueue/enqueue_adapter_hip.match | 1 + test/conformance/kernel/kernel_adapter_hip.match | 2 +- test/conformance/kernel/urKernelCreate.cpp | 8 ++++---- test/conformance/program/program_adapter_hip.match | 1 + 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/source/adapters/hip/kernel.cpp b/source/adapters/hip/kernel.cpp index b433d3a3b4..724a255cad 100644 --- a/source/adapters/hip/kernel.cpp +++ b/source/adapters/hip/kernel.cpp @@ -22,8 +22,12 @@ urKernelCreate(ur_program_handle_t hProgram, const char *pKernelName, ScopedContext Active(hProgram->getContext()->getDevice()); hipFunction_t HIPFunc; - UR_CHECK_ERROR( - hipModuleGetFunction(&HIPFunc, hProgram->get(), pKernelName)); + hipError_t KernelError = + hipModuleGetFunction(&HIPFunc, hProgram->get(), pKernelName); + if (KernelError == hipErrorNotFound) { + return UR_RESULT_ERROR_INVALID_KERNEL_NAME; + } + UR_CHECK_ERROR(KernelError); std::string KernelNameWoffset = std::string(pKernelName) + "_with_offset"; hipFunction_t HIPFuncWithOffsetParam; diff --git a/test/conformance/enqueue/enqueue_adapter_hip.match b/test/conformance/enqueue/enqueue_adapter_hip.match index 2985702bb4..cfbdec52de 100644 --- a/test/conformance/enqueue/enqueue_adapter_hip.match +++ b/test/conformance/enqueue/enqueue_adapter_hip.match @@ -1,3 +1,4 @@ +{{OPT}} Segmentation fault urEnqueueDeviceGetGlobalVariableReadTest.Success/AMD_HIP_BACKEND___{{.*}}_ urEnqueueDeviceGetGlobalVariableReadTest.InvalidEventWaitInvalidEvent/AMD_HIP_BACKEND___{{.*}}_ urEnqueueDeviceGetGlobalVariableWriteTest.InvalidEventWaitInvalidEvent/AMD_HIP_BACKEND___{{.*}}_ diff --git a/test/conformance/kernel/kernel_adapter_hip.match b/test/conformance/kernel/kernel_adapter_hip.match index 26ef160889..4cd7e8060b 100644 --- a/test/conformance/kernel/kernel_adapter_hip.match +++ b/test/conformance/kernel/kernel_adapter_hip.match @@ -1,4 +1,4 @@ -urKernelCreateTest.InvalidKernelName/AMD_HIP_BACKEND___{{.*}}_ +{{OPT}} Segmentation fault urKernelGetInfoTest.Success/AMD_HIP_BACKEND___{{.*}}___UR_KERNEL_INFO_NUM_REGS urKernelGetInfoTest.InvalidSizeSmall/AMD_HIP_BACKEND___{{.*}}___UR_KERNEL_INFO_FUNCTION_NAME urKernelGetInfoTest.InvalidSizeSmall/AMD_HIP_BACKEND___{{.*}}___UR_KERNEL_INFO_NUM_ARGS diff --git a/test/conformance/kernel/urKernelCreate.cpp b/test/conformance/kernel/urKernelCreate.cpp index f89eb2a72a..ac4f3fdf9f 100644 --- a/test/conformance/kernel/urKernelCreate.cpp +++ b/test/conformance/kernel/urKernelCreate.cpp @@ -28,12 +28,12 @@ struct urKernelCreateTest : uur::urProgramTest { UUR_INSTANTIATE_KERNEL_TEST_SUITE_P(urKernelCreateTest); TEST_P(urKernelCreateTest, Success) { - ASSERT_SUCCESS(urKernelCreate(program, kernel_name.data(), &kernel)); + ASSERT_SUCCESS(urKernelCreate(program, kernel_name.c_str(), &kernel)); } TEST_P(urKernelCreateTest, InvalidNullHandleProgram) { ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE, - urKernelCreate(nullptr, kernel_name.data(), &kernel)); + urKernelCreate(nullptr, kernel_name.c_str(), &kernel)); } TEST_P(urKernelCreateTest, InvalidNullPointerName) { @@ -43,11 +43,11 @@ TEST_P(urKernelCreateTest, InvalidNullPointerName) { TEST_P(urKernelCreateTest, InvalidNullPointerKernel) { ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_POINTER, - urKernelCreate(program, kernel_name.data(), nullptr)); + urKernelCreate(program, kernel_name.c_str(), nullptr)); } TEST_P(urKernelCreateTest, InvalidKernelName) { std::string invalid_name = "incorrect_kernel_name"; ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_KERNEL_NAME, - urKernelCreate(program, invalid_name.data(), &kernel)); + urKernelCreate(program, invalid_name.c_str(), &kernel)); } diff --git a/test/conformance/program/program_adapter_hip.match b/test/conformance/program/program_adapter_hip.match index d8b5730e5f..de40377a05 100644 --- a/test/conformance/program/program_adapter_hip.match +++ b/test/conformance/program/program_adapter_hip.match @@ -1,3 +1,4 @@ +{{OPT}} Segmentation fault urProgramCreateWithNativeHandleTest.InvalidNullHandleContext/AMD_HIP_BACKEND___{{.*}}_ urProgramCreateWithNativeHandleTest.InvalidNullPointerProgram/AMD_HIP_BACKEND___{{.*}}_ urProgramGetBuildInfoTest.Success/AMD_HIP_BACKEND___{{.*}}___UR_PROGRAM_BUILD_INFO_BINARY_TYPE