Skip to content

Commit

Permalink
[CUDA] Fix resource leaks in adapter tests
Browse files Browse the repository at this point in the history
Fix issues missed by oneapi-src#1284:

* Use RAII wrapper for CUevent in
  `urCudaEventCreateWithNativeHandleTest.Success`.
* Use `uur::raii::Mem` in the
  `cudaUrContextCreateTest.ContextLifetimeExisting`.
  • Loading branch information
kbenzie committed Feb 2, 2024
1 parent cd97e17 commit f914307
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions test/adapters/cuda/context_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ TEST_P(cudaUrContextCreateTest, ContextLifetimeExisting) {
ASSERT_EQ(context, queue->getContext());

// create a buffer in the context to set the context as active
ur_mem_handle_t buffer;
uur::raii::Mem buffer;
ASSERT_SUCCESS(urMemBufferCreate(context, UR_MEM_FLAG_READ_WRITE, 1024,
nullptr, &buffer));
nullptr, buffer.ptr()));

// check that context is now the active cuda context
ASSERT_SUCCESS_CUDA(cuCtxGetCurrent(&current));
Expand Down
21 changes: 16 additions & 5 deletions test/adapters/cuda/urEventCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,27 @@
using urCudaEventCreateWithNativeHandleTest = uur::urQueueTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urCudaEventCreateWithNativeHandleTest);

struct RAIICUevent {
CUevent handle = nullptr;

~RAIICUevent() {
if (handle) {
cuEventDestroy(handle);
}
}

CUevent *ptr() { return &handle; }
CUevent get() { return handle; }
};

TEST_P(urCudaEventCreateWithNativeHandleTest, Success) {
CUevent cuda_event;
ASSERT_SUCCESS_CUDA(cuEventCreate(&cuda_event, CU_EVENT_DEFAULT));
RAIICUevent cuda_event;
ASSERT_SUCCESS_CUDA(cuEventCreate(cuda_event.ptr(), CU_EVENT_DEFAULT));

ur_native_handle_t native_event =
reinterpret_cast<ur_native_handle_t>(cuda_event);
reinterpret_cast<ur_native_handle_t>(cuda_event.get());

uur::raii::Event event = nullptr;
EXPECT_SUCCESS(urEventCreateWithNativeHandle(native_event, context, nullptr,
event.ptr()));

ASSERT_SUCCESS_CUDA(cuEventDestroy(cuda_event));
}

0 comments on commit f914307

Please sign in to comment.