Skip to content

Commit 73ba29b

Browse files
cppchedyProGTX
authored andcommitted
[CUDA][Bindless] Fix memory leak in interop mapping
* added a map to ur_device_handle_t_. * Capture the leaking Cumipmappedarray in urBindlessImagesMapExternalArrayExp into map. * Update urBindlessImagesImageFreeExp to check if the Cuarray is derived, then destroy the corresponding Cumipmappedarray.
1 parent daa0b11 commit 73ba29b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

source/adapters/cuda/device.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ struct ur_device_handle_t_ {
114114
bool maxLocalMemSizeChosen() { return MaxLocalMemSizeChosen; };
115115

116116
uint32_t getNumComputeUnits() const noexcept { return NumComputeUnits; };
117+
118+
// bookkeeping for mipmappedArray leaks in Mapping external Memory
119+
std::map<CUarray, CUmipmappedArray> ChildCuarrayFromMipmapMap;
117120
};
118121

119122
int getAttribute(ur_device_handle_t Device, CUdevice_attribute Attribute);

source/adapters/cuda/image.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageFreeExp(
430430
ScopedContext Active(hDevice);
431431
try {
432432
UR_CHECK_ERROR(cuArrayDestroy((CUarray)hImageMem));
433+
if (auto it = hDevice->ChildCuarrayFromMipmapMap.find((CUarray)hImageMem);
434+
it != hDevice->ChildCuarrayFromMipmapMap.end()) {
435+
UR_CHECK_ERROR(cuMipmappedArrayDestroy((CUmipmappedArray)it->second));
436+
hDevice->ChildCuarrayFromMipmapMap.erase(it);
437+
}
433438
} catch (ur_result_t Err) {
434439
return Err;
435440
} catch (...) {
@@ -1104,6 +1109,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesMapExternalArrayExp(
11041109
CUarray memArray;
11051110
UR_CHECK_ERROR(cuMipmappedArrayGetLevel(&memArray, memMipMap, 0));
11061111

1112+
hDevice->ChildCuarrayFromMipmapMap.emplace(memArray, memMipMap);
1113+
11071114
*phImageMem = (ur_exp_image_mem_native_handle_t)memArray;
11081115
}
11091116

0 commit comments

Comments
 (0)