Skip to content

Commit f7c0598

Browse files
committed
[Bindless][Exp] Create mapping of host and device handle
Creates a mapping between the host and device handle in the L0 backend to be able to retrieve the host handle when destroying the image.
1 parent 7e38af7 commit f7c0598

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

source/adapters/level_zero/device.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,8 @@ struct ur_device_handle_t_ : _ur_object {
219219
ZeCache<struct ze_global_memsize> ZeGlobalMemSize;
220220
ZeCache<ZeStruct<ze_mutable_command_list_exp_properties_t>>
221221
ZeDeviceMutableCmdListsProperties;
222+
223+
// Map device bindless image offset to corresponding host image handle.
224+
std::unordered_map<ur_exp_image_native_handle_t, ze_image_handle_t>
225+
ZeOffsetToImageHandleMap;
222226
};

source/adapters/level_zero/image.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ ur_result_t bindlessImagesCreateImpl(ur_context_handle_t hContext,
496496
(ZeImageTranslated, &DeviceOffset));
497497
*phImage = DeviceOffset;
498498

499+
hDevice->ZeOffsetToImageHandleMap[*phImage] = ZeImage;
500+
499501
return UR_RESULT_SUCCESS;
500502
}
501503

@@ -675,9 +677,16 @@ UR_APIEXPORT ur_result_t UR_APICALL
675677
urBindlessImagesUnsampledImageHandleDestroyExp(
676678
ur_context_handle_t hContext, ur_device_handle_t hDevice,
677679
ur_exp_image_native_handle_t hImage) {
678-
std::ignore = hContext;
679-
std::ignore = hDevice;
680-
std::ignore = hImage;
680+
UR_ASSERT(hContext && hDevice && hImage, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
681+
682+
auto item = hDevice->ZeOffsetToImageHandleMap.find(hImage);
683+
684+
if (item != hDevice->ZeOffsetToImageHandleMap.end()) {
685+
ZE2UR_CALL(zeImageDestroy, (item->second));
686+
hDevice->ZeOffsetToImageHandleMap.erase(item);
687+
} else {
688+
return UR_RESULT_ERROR_INVALID_NULL_HANDLE;
689+
}
681690

682691
return UR_RESULT_SUCCESS;
683692
}

0 commit comments

Comments
 (0)