Skip to content

Commit 03cd9d1

Browse files
authored
Merge pull request #1314 from kbenzie/benie/cuda-fix-resource-leaks
[CUDA] Fix resource leaks in adapter tests
2 parents be849b2 + f914307 commit 03cd9d1

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

test/adapters/cuda/context_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ TEST_P(cudaUrContextCreateTest, ContextLifetimeExisting) {
9696
ASSERT_EQ(context, queue->getContext());
9797

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

103103
// check that context is now the active cuda context
104104
ASSERT_SUCCESS_CUDA(cuCtxGetCurrent(&current));

test/adapters/cuda/urEventCreateWithNativeHandle.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,27 @@
99
using urCudaEventCreateWithNativeHandleTest = uur::urQueueTest;
1010
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urCudaEventCreateWithNativeHandleTest);
1111

12+
struct RAIICUevent {
13+
CUevent handle = nullptr;
14+
15+
~RAIICUevent() {
16+
if (handle) {
17+
cuEventDestroy(handle);
18+
}
19+
}
20+
21+
CUevent *ptr() { return &handle; }
22+
CUevent get() { return handle; }
23+
};
24+
1225
TEST_P(urCudaEventCreateWithNativeHandleTest, Success) {
13-
CUevent cuda_event;
14-
ASSERT_SUCCESS_CUDA(cuEventCreate(&cuda_event, CU_EVENT_DEFAULT));
26+
RAIICUevent cuda_event;
27+
ASSERT_SUCCESS_CUDA(cuEventCreate(cuda_event.ptr(), CU_EVENT_DEFAULT));
1528

1629
ur_native_handle_t native_event =
17-
reinterpret_cast<ur_native_handle_t>(cuda_event);
30+
reinterpret_cast<ur_native_handle_t>(cuda_event.get());
1831

1932
uur::raii::Event event = nullptr;
2033
EXPECT_SUCCESS(urEventCreateWithNativeHandle(native_event, context, nullptr,
2134
event.ptr()));
22-
23-
ASSERT_SUCCESS_CUDA(cuEventDestroy(cuda_event));
2435
}

0 commit comments

Comments
 (0)