From e22b49894f24f85b2d74032e5cbc7e73cb7b7705 Mon Sep 17 00:00:00 2001 From: "Zhang, Winston" Date: Mon, 23 Jun 2025 18:50:11 -0700 Subject: [PATCH 1/4] [UR][L0] Implement support for device to device copy Bindless Image: pitched usm image to pitched usm image copy Signed-off-by: Zhang, Winston --- .../adapters/level_zero/image_common.cpp | 68 +++++++++++++++---- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/unified-runtime/source/adapters/level_zero/image_common.cpp b/unified-runtime/source/adapters/level_zero/image_common.cpp index 9b76788b6a65e..ddecdcdad3adf 100644 --- a/unified-runtime/source/adapters/level_zero/image_common.cpp +++ b/unified-runtime/source/adapters/level_zero/image_common.cpp @@ -865,21 +865,61 @@ ur_result_t bindlessImagesHandleCopyFlags( return UR_RESULT_SUCCESS; }; case UR_EXP_IMAGE_COPY_FLAG_DEVICE_TO_DEVICE: { - ze_image_region_t DstRegion; - UR_CALL(getImageRegionHelper(zeSrcImageDesc, &pCopyRegion->dstOffset, - &pCopyRegion->copyExtent, DstRegion)); - ze_image_region_t SrcRegion; - UR_CALL(getImageRegionHelper(zeSrcImageDesc, &pCopyRegion->srcOffset, - &pCopyRegion->copyExtent, SrcRegion)); - - auto *urImgSrc = reinterpret_cast(pSrc); - auto *urImgDst = reinterpret_cast(pDst); - - ZE2UR_CALL(zeCommandListAppendImageCopyRegion, - (ZeCommandList, urImgDst->getZeImage(), urImgSrc->getZeImage(), - &DstRegion, &SrcRegion, zeSignalEvent, numWaitEvents, - phWaitEvents)); + if (pSrcImageDesc->rowPitch != 0 && pDstImageDesc->rowPitch != 0) { + // Copy from pitched USM memory to pitched USM memory + uint32_t SrcRowPitch = pSrcImageDesc->rowPitch; + uint32_t DstRowPitch = pDstImageDesc->rowPitch; + ze_copy_region_t ZeDstRegion = {(uint32_t)pCopyRegion->dstOffset.x, + (uint32_t)pCopyRegion->dstOffset.y, + (uint32_t)pCopyRegion->dstOffset.z, + DstRowPitch, + (uint32_t)pCopyRegion->copyExtent.height, + (uint32_t)pCopyRegion->copyExtent.depth}; + uint32_t DstSlicePitch = 0; + uint32_t SrcSlicePitch = 0; + ze_copy_region_t ZeSrcRegion = {(uint32_t)pCopyRegion->srcOffset.x, + (uint32_t)pCopyRegion->srcOffset.y, + (uint32_t)pCopyRegion->srcOffset.z, + SrcRowPitch, + (uint32_t)pCopyRegion->copyExtent.height, + (uint32_t)pCopyRegion->copyExtent.depth}; + ZE2UR_CALL(zeCommandListAppendMemoryCopyRegion, + (ZeCommandList, pDst, &ZeDstRegion, DstRowPitch, DstSlicePitch, + pSrc, &ZeSrcRegion, SrcRowPitch, SrcSlicePitch, zeSignalEvent, + numWaitEvents, phWaitEvents)); + } else if (pSrcImageDesc->rowPitch == 0 && pDstImageDesc->rowPitch == 0) { + // Copy from Non-USM memory to Non-USM memory + ze_image_region_t DstRegion; + UR_CALL(getImageRegionHelper(zeSrcImageDesc, &pCopyRegion->dstOffset, + &pCopyRegion->copyExtent, DstRegion)); + ze_image_region_t SrcRegion; + UR_CALL(getImageRegionHelper(zeSrcImageDesc, &pCopyRegion->srcOffset, + &pCopyRegion->copyExtent, SrcRegion)); + auto *UrImageDst = static_cast(pDst); + auto *UrImageSrc = static_cast(pSrc); + ZE2UR_CALL(zeCommandListAppendImageCopyRegion, + (ZeCommandList, UrImageDst->getZeImage(), UrImageSrc->getZeImage(), + &DstRegion, &SrcRegion, zeSignalEvent, numWaitEvents, + phWaitEvents)); + } else { + // Copy from Non-USM/pitched USM memory to pitched USM/Non-USM memory + // Note: This might be the same procedure as pitched USM to + // pitched USM. Need further testing. + ze_image_region_t DstRegion; + UR_CALL(getImageRegionHelper(zeSrcImageDesc, &pCopyRegion->dstOffset, + &pCopyRegion->copyExtent, DstRegion)); + ze_image_region_t SrcRegion; + UR_CALL(getImageRegionHelper(zeSrcImageDesc, &pCopyRegion->srcOffset, + &pCopyRegion->copyExtent, SrcRegion)); + auto *UrImageDst = static_cast(pDst); + auto *UrImageSrc = static_cast(pSrc); + ZE2UR_CALL(zeCommandListAppendImageCopyRegion, + (ZeCommandList, UrImageDst->getZeImage(), UrImageSrc->getZeImage(), + &DstRegion, &SrcRegion, zeSignalEvent, numWaitEvents, + phWaitEvents)); + } + return UR_RESULT_SUCCESS; }; default: From d9f65f52e6a14285655061ff590504f2c1f60b2b Mon Sep 17 00:00:00 2001 From: "Zhang, Winston" Date: Mon, 23 Jun 2025 18:58:55 -0700 Subject: [PATCH 2/4] [UR][L0] Implement support for device to device copy Bindless Image: pitched usm image to pitched usm image copy Signed-off-by: Zhang, Winston --- unified-runtime/source/adapters/level_zero/image_common.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/unified-runtime/source/adapters/level_zero/image_common.cpp b/unified-runtime/source/adapters/level_zero/image_common.cpp index ddecdcdad3adf..b253fd78ba8a1 100644 --- a/unified-runtime/source/adapters/level_zero/image_common.cpp +++ b/unified-runtime/source/adapters/level_zero/image_common.cpp @@ -901,7 +901,6 @@ ur_result_t bindlessImagesHandleCopyFlags( (ZeCommandList, UrImageDst->getZeImage(), UrImageSrc->getZeImage(), &DstRegion, &SrcRegion, zeSignalEvent, numWaitEvents, phWaitEvents)); - } else { // Copy from Non-USM/pitched USM memory to pitched USM/Non-USM memory // Note: This might be the same procedure as pitched USM to @@ -919,7 +918,6 @@ ur_result_t bindlessImagesHandleCopyFlags( &DstRegion, &SrcRegion, zeSignalEvent, numWaitEvents, phWaitEvents)); } - return UR_RESULT_SUCCESS; }; default: From f264ec6a02540226d51b5e6b3e4ca7d12820379e Mon Sep 17 00:00:00 2001 From: "Zhang, Winston" Date: Tue, 24 Jun 2025 10:18:13 -0700 Subject: [PATCH 3/4] Format image_common.cpp to comply with clang-format --- .../source/adapters/level_zero/image_common.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/unified-runtime/source/adapters/level_zero/image_common.cpp b/unified-runtime/source/adapters/level_zero/image_common.cpp index b253fd78ba8a1..6420626b6f57d 100644 --- a/unified-runtime/source/adapters/level_zero/image_common.cpp +++ b/unified-runtime/source/adapters/level_zero/image_common.cpp @@ -898,9 +898,9 @@ ur_result_t bindlessImagesHandleCopyFlags( auto *UrImageDst = static_cast(pDst); auto *UrImageSrc = static_cast(pSrc); ZE2UR_CALL(zeCommandListAppendImageCopyRegion, - (ZeCommandList, UrImageDst->getZeImage(), UrImageSrc->getZeImage(), - &DstRegion, &SrcRegion, zeSignalEvent, numWaitEvents, - phWaitEvents)); + (ZeCommandList, UrImageDst->getZeImage(), + UrImageSrc->getZeImage(), &DstRegion, &SrcRegion, + zeSignalEvent, numWaitEvents, phWaitEvents)); } else { // Copy from Non-USM/pitched USM memory to pitched USM/Non-USM memory // Note: This might be the same procedure as pitched USM to @@ -914,9 +914,9 @@ ur_result_t bindlessImagesHandleCopyFlags( auto *UrImageDst = static_cast(pDst); auto *UrImageSrc = static_cast(pSrc); ZE2UR_CALL(zeCommandListAppendImageCopyRegion, - (ZeCommandList, UrImageDst->getZeImage(), UrImageSrc->getZeImage(), - &DstRegion, &SrcRegion, zeSignalEvent, numWaitEvents, - phWaitEvents)); + (ZeCommandList, UrImageDst->getZeImage(), + UrImageSrc->getZeImage(), &DstRegion, &SrcRegion, + zeSignalEvent, numWaitEvents, phWaitEvents)); } return UR_RESULT_SUCCESS; }; From 1e85a56ffbc6f4ee9c265e25f63dab340dee1008 Mon Sep 17 00:00:00 2001 From: "Zhang, Winston" Date: Wed, 6 Aug 2025 13:49:24 -0700 Subject: [PATCH 4/4] Removed redundant condition --- .../source/adapters/level_zero/image_common.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/unified-runtime/source/adapters/level_zero/image_common.cpp b/unified-runtime/source/adapters/level_zero/image_common.cpp index 6420626b6f57d..fe9152197bd74 100644 --- a/unified-runtime/source/adapters/level_zero/image_common.cpp +++ b/unified-runtime/source/adapters/level_zero/image_common.cpp @@ -887,24 +887,8 @@ ur_result_t bindlessImagesHandleCopyFlags( (ZeCommandList, pDst, &ZeDstRegion, DstRowPitch, DstSlicePitch, pSrc, &ZeSrcRegion, SrcRowPitch, SrcSlicePitch, zeSignalEvent, numWaitEvents, phWaitEvents)); - } else if (pSrcImageDesc->rowPitch == 0 && pDstImageDesc->rowPitch == 0) { - // Copy from Non-USM memory to Non-USM memory - ze_image_region_t DstRegion; - UR_CALL(getImageRegionHelper(zeSrcImageDesc, &pCopyRegion->dstOffset, - &pCopyRegion->copyExtent, DstRegion)); - ze_image_region_t SrcRegion; - UR_CALL(getImageRegionHelper(zeSrcImageDesc, &pCopyRegion->srcOffset, - &pCopyRegion->copyExtent, SrcRegion)); - auto *UrImageDst = static_cast(pDst); - auto *UrImageSrc = static_cast(pSrc); - ZE2UR_CALL(zeCommandListAppendImageCopyRegion, - (ZeCommandList, UrImageDst->getZeImage(), - UrImageSrc->getZeImage(), &DstRegion, &SrcRegion, - zeSignalEvent, numWaitEvents, phWaitEvents)); } else { // Copy from Non-USM/pitched USM memory to pitched USM/Non-USM memory - // Note: This might be the same procedure as pitched USM to - // pitched USM. Need further testing. ze_image_region_t DstRegion; UR_CALL(getImageRegionHelper(zeSrcImageDesc, &pCopyRegion->dstOffset, &pCopyRegion->copyExtent, DstRegion));