Skip to content

Commit 13f69b5

Browse files
committed
[L0][Bindless Image] Use L0 ImageCopy ext API for copying to/from non-usm
This PR fixes read_write_*D_subregion.cpp tests on DG2.
1 parent 4c22f5c commit 13f69b5

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

source/adapters/level_zero/image.cpp

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -797,62 +797,70 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageCopyExp(
797797
const auto &ZeCommandList = CommandList->first;
798798
const auto &WaitList = (*Event)->WaitList;
799799

800+
uint32_t PixelSizeInBytes = getPixelSizeBytes(pImageFormat);
801+
800802
if (imageCopyFlags == UR_EXP_IMAGE_COPY_FLAG_HOST_TO_DEVICE) {
803+
uint32_t SrcRowPitch = hostExtent.width * PixelSizeInBytes;
804+
uint32_t SrcSlicePitch = SrcRowPitch * hostExtent.height;
801805
if (pImageDesc->rowPitch == 0) {
802806
// Copy to Non-USM memory
803807
ze_image_region_t DstRegion;
804808
UR_CALL(getImageRegionHelper(ZeImageDesc, &dstOffset, &copyExtent,
805809
DstRegion));
806810
auto *UrImage = static_cast<_ur_image *>(pDst);
807-
ZE2UR_CALL(zeCommandListAppendImageCopyFromMemory,
808-
(ZeCommandList, UrImage->ZeImage, pSrc, &DstRegion, ZeEvent,
809-
WaitList.Length, WaitList.ZeEventList));
811+
char *SrcPtr = static_cast<char *>(pSrc) + srcOffset.z * SrcSlicePitch +
812+
srcOffset.y * SrcRowPitch + srcOffset.x * PixelSizeInBytes;
813+
ZE2UR_CALL(zeCommandListAppendImageCopyFromMemoryExt,
814+
(ZeCommandList, UrImage->ZeImage, SrcPtr, &DstRegion,
815+
SrcRowPitch, SrcSlicePitch, ZeEvent, WaitList.Length,
816+
WaitList.ZeEventList));
810817
} else {
811818
// Copy to pitched USM memory
812-
uint32_t DstPitch = pImageDesc->rowPitch;
819+
uint32_t DstRowPitch = pImageDesc->rowPitch;
813820
ze_copy_region_t ZeDstRegion = {
814821
(uint32_t)dstOffset.x, (uint32_t)dstOffset.y,
815-
(uint32_t)dstOffset.z, DstPitch,
822+
(uint32_t)dstOffset.z, DstRowPitch,
816823
(uint32_t)copyExtent.height, (uint32_t)copyExtent.depth};
817824
uint32_t DstSlicePitch = 0;
818-
uint32_t SrcPitch = hostExtent.width * getPixelSizeBytes(pImageFormat);
819825
ze_copy_region_t ZeSrcRegion = {
820826
(uint32_t)srcOffset.x, (uint32_t)srcOffset.y,
821-
(uint32_t)srcOffset.z, SrcPitch,
827+
(uint32_t)srcOffset.z, SrcRowPitch,
822828
(uint32_t)copyExtent.height, (uint32_t)copyExtent.depth};
823-
uint32_t SrcSlicePitch = 0;
824829
ZE2UR_CALL(zeCommandListAppendMemoryCopyRegion,
825-
(ZeCommandList, pDst, &ZeDstRegion, DstPitch, DstSlicePitch,
826-
pSrc, &ZeSrcRegion, SrcPitch, SrcSlicePitch, ZeEvent,
830+
(ZeCommandList, pDst, &ZeDstRegion, DstRowPitch, DstSlicePitch,
831+
pSrc, &ZeSrcRegion, SrcRowPitch, SrcSlicePitch, ZeEvent,
827832
WaitList.Length, WaitList.ZeEventList));
828833
}
829834
} else if (imageCopyFlags == UR_EXP_IMAGE_COPY_FLAG_DEVICE_TO_HOST) {
835+
uint32_t DstRowPitch = hostExtent.width * PixelSizeInBytes;
836+
uint32_t DstSlicePitch = DstRowPitch * hostExtent.height;
830837
if (pImageDesc->rowPitch == 0) {
831838
// Copy from Non-USM memory to host
832839
ze_image_region_t SrcRegion;
833840
UR_CALL(getImageRegionHelper(ZeImageDesc, &srcOffset, &copyExtent,
834841
SrcRegion));
835842
auto *UrImage = static_cast<_ur_image *>(pSrc);
836-
ZE2UR_CALL(zeCommandListAppendImageCopyToMemory,
837-
(ZeCommandList, pDst, UrImage->ZeImage, &SrcRegion, ZeEvent,
838-
WaitList.Length, WaitList.ZeEventList));
843+
char *DstPtr = static_cast<char *>(pDst) + dstOffset.z * DstSlicePitch +
844+
dstOffset.y * DstRowPitch + dstOffset.x * PixelSizeInBytes;
845+
ZE2UR_CALL(zeCommandListAppendImageCopyToMemoryExt,
846+
(ZeCommandList, DstPtr, UrImage->ZeImage, &SrcRegion,
847+
DstRowPitch, DstSlicePitch, ZeEvent, WaitList.Length,
848+
WaitList.ZeEventList));
839849
} else {
840850
// Copy from pitched USM memory to host
841-
uint32_t DstPitch = copyExtent.width * getPixelSizeBytes(pImageFormat);
842851
ze_copy_region_t ZeDstRegion = {
843852
(uint32_t)dstOffset.x, (uint32_t)dstOffset.y,
844-
(uint32_t)dstOffset.z, DstPitch,
853+
(uint32_t)dstOffset.z, DstRowPitch,
845854
(uint32_t)copyExtent.height, (uint32_t)copyExtent.depth};
846-
uint32_t DstSlicePitch = 0;
847-
uint32_t SrcPitch = pImageDesc->rowPitch;
855+
uint32_t SrcRowPitch = pImageDesc->rowPitch;
848856
ze_copy_region_t ZeSrcRegion = {
849857
(uint32_t)srcOffset.x, (uint32_t)srcOffset.y,
850-
(uint32_t)srcOffset.z, SrcPitch,
858+
(uint32_t)srcOffset.z, SrcRowPitch,
851859
(uint32_t)copyExtent.height, (uint32_t)copyExtent.depth};
852860
uint32_t SrcSlicePitch = 0;
853861
ZE2UR_CALL(zeCommandListAppendMemoryCopyRegion,
854-
(ZeCommandList, pDst, &ZeDstRegion, DstPitch, DstSlicePitch,
855-
pSrc, &ZeSrcRegion, SrcPitch, SrcSlicePitch, ZeEvent,
862+
(ZeCommandList, pDst, &ZeDstRegion, DstRowPitch, DstSlicePitch,
863+
pSrc, &ZeSrcRegion, SrcRowPitch, SrcSlicePitch, ZeEvent,
856864
WaitList.Length, WaitList.ZeEventList));
857865
}
858866
} else {

0 commit comments

Comments
 (0)