Skip to content

Commit 47ab963

Browse files
Merge pull request #1790 from DBDuncan/duncan/host-to-device-img-map
[Bindless][Exp] Create mapping of host and device handle
2 parents 50806b9 + 1a5e3f1 commit 47ab963

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
@@ -221,6 +221,10 @@ struct ur_device_handle_t_ : _ur_object {
221221
ZeCache<ZeStruct<ze_mutable_command_list_exp_properties_t>>
222222
ZeDeviceMutableCmdListsProperties;
223223

224+
// Map device bindless image offset to corresponding host image handle.
225+
std::unordered_map<ur_exp_image_native_handle_t, ze_image_handle_t>
226+
ZeOffsetToImageHandleMap;
227+
224228
// unique ephemeral identifer of the device in the adapter
225229
DeviceId Id;
226230
};

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)