Skip to content

Commit c5e1fcf

Browse files
fix: Copy tiled 1D array per array element with BLT
Related-To: NEO-14147, HSD-14024424096, HSD-14024424178 Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
1 parent e644b09 commit c5e1fcf

File tree

8 files changed

+344
-3
lines changed

8 files changed

+344
-3
lines changed

level_zero/core/source/cmdlist/cmdlist_hw.inl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,8 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendCopyImageBlit(NEO::Graph
14591459
commandContainer.addToResidencyContainer(clearColorAllocation);
14601460

14611461
appendEventForProfiling(signalEvent, nullptr, true, false, false, true);
1462+
blitProperties.transform1DArrayTo2DArrayIfNeeded();
1463+
14621464
NEO::BlitCommandsHelper<GfxFamily>::dispatchBlitCommandsForImageRegion(blitProperties, *commandContainer.getCommandStream(), *dummyBlitWa.rootDeviceEnvironment);
14631465
dummyBlitWa.isWaRequired = true;
14641466

level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_blit.cpp

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2024 Intel Corporation
2+
* Copyright (C) 2020-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -8,6 +8,9 @@
88
#include "shared/source/helpers/register_offsets.h"
99
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
1010
#include "shared/test/common/mocks/mock_device.h"
11+
#include "shared/test/common/mocks/mock_gmm.h"
12+
#include "shared/test/common/mocks/mock_gmm_client_context.h"
13+
#include "shared/test/common/mocks/mock_gmm_resource_info.h"
1114
#include "shared/test/common/mocks/mock_graphics_allocation.h"
1215
#include "shared/test/common/test_macros/hw_test.h"
1316

@@ -352,5 +355,79 @@ HWTEST2_F(AppendMemoryCopyFromContext, givenCommandListThenUpOnPerformingAppendM
352355
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
353356
}
354357

358+
struct IsAtLeastXeHpCoreAndNotXe2HpgCoreWith2DArrayImageSupport {
359+
template <PRODUCT_FAMILY productFamily>
360+
static constexpr bool isMatched() {
361+
return IsAtLeastGfxCore<IGFX_XE_HP_CORE>::isMatched<productFamily>() && !IsXe2HpgCore::isMatched<productFamily>() && NEO::HwMapper<productFamily>::GfxProduct::supportsSampler;
362+
}
363+
};
364+
HWTEST2_F(AppendMemoryCopyTests, givenCopyCommandListWhenTiled1DArrayImagePassedToImageCopyBlitThenTransformedTo2DArrayCopy, IsAtLeastXeHpCoreAndNotXe2HpgCoreWith2DArrayImageSupport) {
365+
using XY_BLOCK_COPY_BLT = typename FamilyType::XY_BLOCK_COPY_BLT;
366+
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
367+
commandList->initialize(device, NEO::EngineGroupType::copy, 0u);
368+
369+
auto gmmSrc = std::make_unique<MockGmm>(device->getNEODevice()->getGmmHelper());
370+
auto resourceInfoSrc = static_cast<MockGmmResourceInfo *>(gmmSrc->gmmResourceInfo.get());
371+
resourceInfoSrc->getResourceFlags()->Info.Tile64 = 1;
372+
resourceInfoSrc->mockResourceCreateParams.Type = GMM_RESOURCE_TYPE::RESOURCE_1D;
373+
resourceInfoSrc->mockResourceCreateParams.ArraySize = 8;
374+
375+
NEO::MockGraphicsAllocation mockAllocationSrc(0, 1u /*num gmms*/, NEO::AllocationType::internalHostMemory,
376+
reinterpret_cast<void *>(0x1234), 0x1000, 0, sizeof(uint32_t),
377+
MemoryPool::system4KBPages, MemoryManager::maxOsContextCount);
378+
NEO::MockGraphicsAllocation mockAllocationDst(0, 1u /*num gmms*/, NEO::AllocationType::internalHostMemory,
379+
reinterpret_cast<void *>(0x1234), 0x1000, 0, sizeof(uint32_t),
380+
MemoryPool::system4KBPages, MemoryManager::maxOsContextCount);
381+
382+
mockAllocationSrc.setGmm(gmmSrc.get(), 0);
383+
mockAllocationDst.setGmm(gmmSrc.get(), 0);
384+
385+
size_t arrayLevels = 8;
386+
size_t depth = 1;
387+
commandList->appendCopyImageBlit(&mockAllocationDst, &mockAllocationSrc, {0, 0, 0}, {0, 0, 0}, 4, 4, 4, 4, 1, {1, arrayLevels, depth}, {1, arrayLevels, depth}, {1, arrayLevels, depth}, nullptr);
388+
GenCmdList cmdList;
389+
ASSERT_TRUE(FamilyType::Parse::parseCommandBuffer(
390+
cmdList, ptrOffset(commandList->getCmdContainer().getCommandStream()->getCpuBase(), 0), commandList->getCmdContainer().getCommandStream()->getUsed()));
391+
auto itor = find<XY_BLOCK_COPY_BLT *>(cmdList.begin(), cmdList.end());
392+
EXPECT_NE(cmdList.end(), itor);
393+
auto cmd = genCmdCast<XY_BLOCK_COPY_BLT *>(*itor);
394+
EXPECT_EQ(cmd->getSourceSurfaceDepth(), arrayLevels);
395+
EXPECT_EQ(cmd->getSourceSurfaceHeight(), depth);
396+
}
397+
398+
HWTEST2_F(AppendMemoryCopyTests, givenCopyCommandListWhenNotTiled1DArrayImagePassedToImageCopyBlitThenNotTransformedTo2DArrayCopy, IsAtLeastXeHpCoreAndNotXe2HpgCoreWith2DArrayImageSupport) {
399+
using XY_BLOCK_COPY_BLT = typename FamilyType::XY_BLOCK_COPY_BLT;
400+
auto commandList = std::make_unique<WhiteBox<::L0::CommandListCoreFamily<gfxCoreFamily>>>();
401+
commandList->initialize(device, NEO::EngineGroupType::copy, 0u);
402+
403+
auto gmmSrc = std::make_unique<MockGmm>(device->getNEODevice()->getGmmHelper());
404+
auto resourceInfoSrc = static_cast<MockGmmResourceInfo *>(gmmSrc->gmmResourceInfo.get());
405+
resourceInfoSrc->getResourceFlags()->Info.Tile64 = 0;
406+
resourceInfoSrc->mockResourceCreateParams.Type = GMM_RESOURCE_TYPE::RESOURCE_1D;
407+
resourceInfoSrc->mockResourceCreateParams.ArraySize = 8;
408+
409+
NEO::MockGraphicsAllocation mockAllocationSrc(0, 1u /*num gmms*/, NEO::AllocationType::internalHostMemory,
410+
reinterpret_cast<void *>(0x1234), 0x1000, 0, sizeof(uint32_t),
411+
MemoryPool::system4KBPages, MemoryManager::maxOsContextCount);
412+
NEO::MockGraphicsAllocation mockAllocationDst(0, 1u /*num gmms*/, NEO::AllocationType::internalHostMemory,
413+
reinterpret_cast<void *>(0x1234), 0x1000, 0, sizeof(uint32_t),
414+
MemoryPool::system4KBPages, MemoryManager::maxOsContextCount);
415+
416+
mockAllocationSrc.setGmm(gmmSrc.get(), 0);
417+
mockAllocationDst.setGmm(gmmSrc.get(), 0);
418+
419+
size_t arrayLevels = 8;
420+
size_t depth = 1;
421+
commandList->appendCopyImageBlit(&mockAllocationDst, &mockAllocationSrc, {0, 0, 0}, {0, 0, 0}, 1, 1, 1, 1, 1, {1, arrayLevels, depth}, {1, arrayLevels, depth}, {1, arrayLevels, depth}, nullptr);
422+
GenCmdList cmdList;
423+
ASSERT_TRUE(FamilyType::Parse::parseCommandBuffer(
424+
cmdList, ptrOffset(commandList->getCmdContainer().getCommandStream()->getCpuBase(), 0), commandList->getCmdContainer().getCommandStream()->getUsed()));
425+
auto itor = find<XY_BLOCK_COPY_BLT *>(cmdList.begin(), cmdList.end());
426+
EXPECT_NE(cmdList.end(), itor);
427+
auto cmd = genCmdCast<XY_BLOCK_COPY_BLT *>(*itor);
428+
EXPECT_EQ(cmd->getSourceSurfaceDepth(), depth);
429+
EXPECT_EQ(cmd->getSourceSurfaceHeight(), arrayLevels);
430+
}
431+
355432
} // namespace ult
356433
} // namespace L0

opencl/source/helpers/cl_blit_properties.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct ClBlitProperties {
5656
blitProperties.blitDirection = blitDirection;
5757
setBlitPropertiesForImage(blitProperties, builtinOpParams);
5858
}
59+
blitProperties.transform1DArrayTo2DArrayIfNeeded();
5960
return blitProperties;
6061
}
6162

@@ -142,6 +143,7 @@ struct ClBlitProperties {
142143
setBlitPropertiesForImage(blitProperties, builtinOpParams);
143144
}
144145

146+
blitProperties.transform1DArrayTo2DArrayIfNeeded();
145147
return blitProperties;
146148
}
147149

opencl/test/unit_test/command_stream/command_stream_receiver_hw_2_tests.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include "shared/test/common/mocks/mock_allocation_properties.h"
2121
#include "shared/test/common/mocks/mock_direct_submission_hw.h"
2222
#include "shared/test/common/mocks/mock_gfx_core_helper.h"
23+
#include "shared/test/common/mocks/mock_gmm.h"
24+
#include "shared/test/common/mocks/mock_gmm_client_context.h"
25+
#include "shared/test/common/mocks/mock_gmm_resource_info.h"
2326
#include "shared/test/common/mocks/mock_internal_allocation_storage.h"
2427
#include "shared/test/common/mocks/mock_memory_manager.h"
2528
#include "shared/test/common/mocks/mock_timestamp_container.h"
@@ -2201,3 +2204,57 @@ HWTEST_F(BcsTests, givenHostPtrToImageWhenBlitBufferIsCalledThenBlitCmdIsFound)
22012204
auto cmdIterator = find<typename FamilyType::XY_BLOCK_COPY_BLT *>(hwParser.cmdList.begin(), hwParser.cmdList.end());
22022205
EXPECT_NE(hwParser.cmdList.end(), cmdIterator);
22032206
}
2207+
HWTEST_F(BcsTests, given1DTiledArrayImageWhenConstructPropertiesThenImageTransformedTo2DArray) {
2208+
if (!pDevice->getHardwareInfo().capabilityTable.supportsImages) {
2209+
GTEST_SKIP();
2210+
}
2211+
2212+
auto gmmSrc = std::make_unique<MockGmm>(pDevice->getGmmHelper());
2213+
auto resourceInfoSrc = static_cast<MockGmmResourceInfo *>(gmmSrc->gmmResourceInfo.get());
2214+
resourceInfoSrc->getResourceFlags()->Info.Tile64 = 1;
2215+
resourceInfoSrc->mockResourceCreateParams.Type = GMM_RESOURCE_TYPE::RESOURCE_1D;
2216+
resourceInfoSrc->mockResourceCreateParams.ArraySize = 8;
2217+
2218+
std::unique_ptr<Image> image(Image2dHelper<>::create(context.get()));
2219+
auto oldGmm = std::unique_ptr<Gmm>(image->getGraphicsAllocation(pDevice->getRootDeviceIndex())->getDefaultGmm());
2220+
image->getGraphicsAllocation(pDevice->getRootDeviceIndex())->setGmm(gmmSrc.release(), 0);
2221+
BuiltinOpParams builtinOpParams{};
2222+
builtinOpParams.srcMemObj = image.get();
2223+
builtinOpParams.dstMemObj = image.get();
2224+
builtinOpParams.size = {1, 8, 1};
2225+
2226+
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
2227+
csr.getCmdSizeForComputeMode();
2228+
auto blitProperties = ClBlitProperties::constructProperties(BlitterConstants::BlitDirection::imageToImage,
2229+
csr,
2230+
builtinOpParams);
2231+
EXPECT_EQ(blitProperties.copySize.z, builtinOpParams.size.y);
2232+
EXPECT_EQ(blitProperties.copySize.y, builtinOpParams.size.z);
2233+
}
2234+
HWTEST_F(BcsTests, given1DNotTiledArrayImageWhenConstructPropertiesThenImageNotTransformedTo2DArray) {
2235+
if (!pDevice->getHardwareInfo().capabilityTable.supportsImages) {
2236+
GTEST_SKIP();
2237+
}
2238+
2239+
auto gmmSrc = std::make_unique<MockGmm>(pDevice->getGmmHelper());
2240+
auto resourceInfoSrc = static_cast<MockGmmResourceInfo *>(gmmSrc->gmmResourceInfo.get());
2241+
resourceInfoSrc->getResourceFlags()->Info.Tile64 = 0;
2242+
resourceInfoSrc->mockResourceCreateParams.Type = GMM_RESOURCE_TYPE::RESOURCE_1D;
2243+
resourceInfoSrc->mockResourceCreateParams.ArraySize = 8;
2244+
2245+
std::unique_ptr<Image> image(Image2dHelper<>::create(context.get()));
2246+
auto oldGmm = std::unique_ptr<Gmm>(image->getGraphicsAllocation(pDevice->getRootDeviceIndex())->getDefaultGmm());
2247+
image->getGraphicsAllocation(pDevice->getRootDeviceIndex())->setGmm(gmmSrc.release(), 0);
2248+
BuiltinOpParams builtinOpParams{};
2249+
builtinOpParams.srcMemObj = image.get();
2250+
builtinOpParams.dstMemObj = image.get();
2251+
builtinOpParams.size = {1, 8, 1};
2252+
2253+
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
2254+
csr.getCmdSizeForComputeMode();
2255+
auto blitProperties = ClBlitProperties::constructProperties(BlitterConstants::BlitDirection::imageToImage,
2256+
csr,
2257+
builtinOpParams);
2258+
EXPECT_EQ(blitProperties.copySize.y, builtinOpParams.size.y);
2259+
EXPECT_EQ(blitProperties.copySize.z, builtinOpParams.size.z);
2260+
}

shared/source/helpers/blit_properties.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "shared/source/helpers/blit_properties.h"
99

1010
#include "shared/source/command_stream/command_stream_receiver.h"
11+
#include "shared/source/gmm_helper/gmm.h"
12+
#include "shared/source/gmm_helper/resource_info.h"
1113
#include "shared/source/helpers/timestamp_packet.h"
1214
#include "shared/source/memory_manager/surface.h"
1315

@@ -179,5 +181,43 @@ bool BlitProperties::isImageOperation() const {
179181
blitDirection == BlitterConstants::BlitDirection::imageToHostPtr ||
180182
blitDirection == BlitterConstants::BlitDirection::imageToImage;
181183
}
184+
bool BlitProperties::isSrc1DTiledArray() const {
185+
if (srcAllocation->getDefaultGmm()) {
186+
return is1DTiledArray(srcAllocation->getDefaultGmm()->gmmResourceInfo.get());
187+
}
188+
return false;
189+
}
190+
bool BlitProperties::isDst1DTiledArray() const {
191+
if (dstAllocation->getDefaultGmm()) {
192+
return is1DTiledArray(dstAllocation->getDefaultGmm()->gmmResourceInfo.get());
193+
}
194+
return false;
195+
}
196+
bool BlitProperties::is1DTiledArray(GmmResourceInfo *resInfo) const {
197+
auto resourceType = resInfo->getResourceType();
198+
auto isArray = resInfo->getArraySize() > 1;
199+
auto isTiled = resInfo->getResourceFlags()->Info.Tile4 || resInfo->getResourceFlags()->Info.Tile64;
200+
if (resourceType == GMM_RESOURCE_TYPE::RESOURCE_1D && isTiled && isArray) {
201+
return true;
202+
}
203+
return false;
204+
}
205+
void BlitProperties::transform1DArrayTo2DArrayIfNeeded() {
206+
if (this->isSrc1DTiledArray() || this->isDst1DTiledArray()) {
207+
this->srcSize.z = this->srcSize.y;
208+
this->srcSize.y = 1;
182209

210+
this->dstSize.z = this->dstSize.y;
211+
this->dstSize.y = 1;
212+
213+
this->srcOffset.z = this->srcOffset.y;
214+
this->srcOffset.y = 0;
215+
216+
this->dstOffset.z = this->dstOffset.y;
217+
this->dstOffset.y = 0;
218+
219+
this->copySize.z = this->copySize.y;
220+
this->copySize.y = 1;
221+
}
222+
}
183223
} // namespace NEO

shared/source/helpers/blit_properties.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class TagNodeBase;
2121
class TimestampPacketContainer;
2222
class GraphicsAllocation;
2323
class CommandStreamReceiver;
24+
class GmmResourceInfo;
2425

2526
enum class BlitSyncMode {
2627
none = 0,
@@ -66,6 +67,12 @@ struct BlitProperties {
6667
TimestampPacketContainer &kernelTimestamps, const CsrDependencies &depsFromEvents,
6768
CommandStreamReceiver &gpguCsr, CommandStreamReceiver &bcsCsr);
6869

70+
bool isImageOperation() const;
71+
bool isSrc1DTiledArray() const;
72+
bool isDst1DTiledArray() const;
73+
bool is1DTiledArray(GmmResourceInfo *resInfo) const;
74+
void transform1DArrayTo2DArrayIfNeeded();
75+
6976
BlitSyncProperties blitSyncProperties = {};
7077
CsrDependencies csrDependencies;
7178
TagNodeBase *multiRootDeviceEventSync = nullptr;
@@ -95,8 +102,6 @@ struct BlitProperties {
95102
GMM_YUV_PLANE_ENUM dstPlane = GMM_YUV_PLANE_ENUM::GMM_NO_PLANE;
96103
GMM_YUV_PLANE_ENUM srcPlane = GMM_YUV_PLANE_ENUM::GMM_NO_PLANE;
97104
bool isSystemMemoryPoolUsed = false;
98-
99-
bool isImageOperation() const;
100105
};
101106

102107
} // namespace NEO
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (C) 2020-2025 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
#
6+
7+
target_sources(neo_shared_tests PRIVATE
8+
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
9+
${CMAKE_CURRENT_SOURCE_DIR}/blitter_properties_tests.cpp
10+
)
11+
12+
add_subdirectories()

0 commit comments

Comments
 (0)