Skip to content

Commit 99238df

Browse files
[Bindless Image] Implement support for device to device copy
usm image to usm image copy Signed-off-by: Zhang, Winston <[email protected]>
1 parent 3ce6fcc commit 99238df

File tree

1 file changed

+54
-12
lines changed

1 file changed

+54
-12
lines changed

source/adapters/level_zero/image.cpp

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -972,18 +972,60 @@ ur_result_t urBindlessImagesImageCopyExp(
972972
WaitList.Length, WaitList.ZeEventList));
973973
}
974974
} else if (imageCopyFlags == UR_EXP_IMAGE_COPY_FLAG_DEVICE_TO_DEVICE) {
975-
ze_image_region_t DstRegion;
976-
UR_CALL(getImageRegionHelper(ZeImageDesc, &pCopyRegion->dstOffset,
977-
&pCopyRegion->copyExtent, DstRegion));
978-
ze_image_region_t SrcRegion;
979-
UR_CALL(getImageRegionHelper(ZeImageDesc, &pCopyRegion->srcOffset,
980-
&pCopyRegion->copyExtent, SrcRegion));
981-
auto *UrImageDst = static_cast<_ur_image *>(pDst);
982-
auto *UrImageSrc = static_cast<const _ur_image *>(pSrc);
983-
ZE2UR_CALL(zeCommandListAppendImageCopyRegion,
984-
(ZeCommandList, UrImageDst->ZeImage, UrImageSrc->ZeImage,
985-
&DstRegion, &SrcRegion, ZeEvent, WaitList.Length,
986-
WaitList.ZeEventList));
975+
if (pSrcImageDesc->rowPitch != 0 && pDstImageDesc->rowPitch != 0) {
976+
// Copy from pitched USM memory to pitched USM memory
977+
uint32_t SrcRowPitch = pSrcImageDesc->rowPitch;
978+
uint32_t DstRowPitch = pDstImageDesc->rowPitch;
979+
ze_copy_region_t ZeDstRegion = {(uint32_t)pCopyRegion->dstOffset.x,
980+
(uint32_t)pCopyRegion->dstOffset.y,
981+
(uint32_t)pCopyRegion->dstOffset.z,
982+
DstRowPitch,
983+
(uint32_t)pCopyRegion->copyExtent.height,
984+
(uint32_t)pCopyRegion->copyExtent.depth};
985+
uint32_t DstSlicePitch = 0;
986+
uint32_t SrcSlicePitch = 0;
987+
ze_copy_region_t ZeSrcRegion = {(uint32_t)pCopyRegion->srcOffset.x,
988+
(uint32_t)pCopyRegion->srcOffset.y,
989+
(uint32_t)pCopyRegion->srcOffset.z,
990+
SrcRowPitch,
991+
(uint32_t)pCopyRegion->copyExtent.height,
992+
(uint32_t)pCopyRegion->copyExtent.depth};
993+
ZE2UR_CALL(zeCommandListAppendMemoryCopyRegion,
994+
(ZeCommandList, pDst, &ZeDstRegion, DstRowPitch, DstSlicePitch,
995+
pSrc, &ZeSrcRegion, SrcRowPitch, SrcSlicePitch, ZeEvent,
996+
WaitList.Length, WaitList.ZeEventList));
997+
} else if (pSrcImageDesc->rowPitch == 0 && pDstImageDesc->rowPitch == 0) {
998+
// Copy from Non-USM memory to Non-USM memory
999+
ze_image_region_t DstRegion;
1000+
UR_CALL(getImageRegionHelper(ZeImageDesc, &pCopyRegion->dstOffset,
1001+
&pCopyRegion->copyExtent, DstRegion));
1002+
ze_image_region_t SrcRegion;
1003+
UR_CALL(getImageRegionHelper(ZeImageDesc, &pCopyRegion->srcOffset,
1004+
&pCopyRegion->copyExtent, SrcRegion));
1005+
auto *UrImageDst = static_cast<_ur_image *>(pDst);
1006+
auto *UrImageSrc = static_cast<const _ur_image *>(pSrc);
1007+
ZE2UR_CALL(zeCommandListAppendImageCopyRegion,
1008+
(ZeCommandList, UrImageDst->ZeImage, UrImageSrc->ZeImage,
1009+
&DstRegion, &SrcRegion, ZeEvent, WaitList.Length,
1010+
WaitList.ZeEventList));
1011+
1012+
} else {
1013+
// Copy from Non-USM/pitched USM memory to pitched USM/Non-USM memory
1014+
// Note: This might be the same procedure as pitched USM to pitched USM
1015+
// Need further testing.
1016+
ze_image_region_t DstRegion;
1017+
UR_CALL(getImageRegionHelper(ZeImageDesc, &pCopyRegion->dstOffset,
1018+
&pCopyRegion->copyExtent, DstRegion));
1019+
ze_image_region_t SrcRegion;
1020+
UR_CALL(getImageRegionHelper(ZeImageDesc, &pCopyRegion->srcOffset,
1021+
&pCopyRegion->copyExtent, SrcRegion));
1022+
auto *UrImageDst = static_cast<_ur_image *>(pDst);
1023+
auto *UrImageSrc = static_cast<const _ur_image *>(pSrc);
1024+
ZE2UR_CALL(zeCommandListAppendImageCopyRegion,
1025+
(ZeCommandList, UrImageDst->ZeImage, UrImageSrc->ZeImage,
1026+
&DstRegion, &SrcRegion, ZeEvent, WaitList.Length,
1027+
WaitList.ZeEventList));
1028+
}
9871029
} else {
9881030
logger::error("urBindlessImagesImageCopyExp: unexpected imageCopyFlags");
9891031
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;

0 commit comments

Comments
 (0)