Skip to content

Commit 5caa8bc

Browse files
kgibalaCompute-Runtime-Automation
authored andcommitted
Add detailed tests for ReadBuffeRect scenario
Related-To: NEO-4013 Change-Id: I3d43aec3c63f8cfb11a7bb2e601f41ce5b191166 Signed-off-by: Krzysztof Gibala <[email protected]>
1 parent 6c4621f commit 5caa8bc

File tree

1 file changed

+185
-59
lines changed

1 file changed

+185
-59
lines changed

opencl/test/unit_test/command_stream/command_stream_receiver_hw_tests.cpp

Lines changed: 185 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -561,36 +561,104 @@ HWTEST_F(BcsTests, givenBltSizeWithLeftoverWhenDispatchedThenProgramAllRequiredC
561561
}
562562
}
563563

564-
HWTEST_F(BcsTests, givenBltSizeWithLeftoverWhenDispatchedThenProgramAllRequiredCommandsForReadBufferRect) {
565-
using MI_FLUSH_DW = typename FamilyType::MI_FLUSH_DW;
566-
using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT;
567-
constexpr auto max2DBlitSize = BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight;
564+
struct BcsTestParam {
565+
Vec3<size_t> copySize;
566+
567+
Vec3<size_t> hostPtrOffset;
568+
Vec3<size_t> copyOffset;
569+
570+
size_t dstRowPitch;
571+
size_t dstSlicePitch;
572+
size_t srcRowPitch;
573+
size_t srcSlicePitch;
574+
} BlitterProperties[] = {
575+
{{(2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17, 1, 1},
576+
{0, 1, 1},
577+
{BlitterConstants::maxBlitWidth, 1, 1},
578+
(2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17,
579+
(2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17,
580+
(2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17,
581+
(2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17},
582+
{{(2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17, 2, 1},
583+
{BlitterConstants::maxBlitWidth, 2, 2},
584+
{BlitterConstants::maxBlitWidth, 1, 1},
585+
0,
586+
((2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17) * 2,
587+
0,
588+
((2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17) * 2},
589+
{{(2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17, 1, 3},
590+
{BlitterConstants::maxBlitWidth, 2, 2},
591+
{BlitterConstants::maxBlitWidth, 1, 1},
592+
0,
593+
((2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17) * 2,
594+
0,
595+
((2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17) * 2},
596+
{{(2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17, 4, 2},
597+
{0, 0, 0},
598+
{0, 0, 0},
599+
(2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17,
600+
((2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17) * 4,
601+
(2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17,
602+
((2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17) * 4},
603+
{{(2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17, 3, 2},
604+
{BlitterConstants::maxBlitWidth, 2, 2},
605+
{BlitterConstants::maxBlitWidth, 1, 1},
606+
((2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17) + 2,
607+
(((2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17) * 3) + 2,
608+
((2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17) + 2,
609+
(((2 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight) + 17) * 3) + 2}};
610+
611+
template <typename ParamType>
612+
struct BcsDetaliedTests : public BcsTests,
613+
public ::testing::WithParamInterface<ParamType> {
614+
void SetUp() override {
615+
BcsTests::SetUp();
616+
}
617+
618+
void TearDown() override {
619+
BcsTests::TearDown();
620+
}
621+
};
568622

623+
using BcsDetaliedTestsWithParams = BcsDetaliedTests<BcsTestParam>;
624+
625+
HWTEST_P(BcsDetaliedTestsWithParams, givenBltSizeWithLeftoverWhenDispatchedThenProgramAddresseForReadBufferRect) {
569626
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
570627
static_cast<OsAgnosticMemoryManager *>(csr.getMemoryManager())->turnOnFakingBigAllocations();
571628

572629
uint32_t bltLeftover = 17;
573-
Vec3<size_t> bltSize = {(2 * max2DBlitSize) + bltLeftover, 2, 2};
574-
size_t numberOfBlts = 3 * bltSize.y * bltSize.z;
630+
Vec3<size_t> bltSize = GetParam().copySize;
631+
632+
size_t numberOfBltsForSingleBltSizeProgramm = 3;
633+
size_t totalNumberOfBits = numberOfBltsForSingleBltSizeProgramm * bltSize.y * bltSize.z;
575634

576635
cl_int retVal = CL_SUCCESS;
577-
auto buffer = clUniquePtr<Buffer>(Buffer::create(context.get(), CL_MEM_READ_WRITE, static_cast<size_t>(bltSize.x * bltSize.y * bltSize.z), nullptr, retVal));
636+
auto buffer = clUniquePtr<Buffer>(Buffer::create(context.get(), CL_MEM_READ_WRITE, static_cast<size_t>(8 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight), nullptr, retVal));
578637
void *hostPtr = reinterpret_cast<void *>(0x12340000);
579638

580-
uint32_t newTaskCount = 19;
581-
csr.taskCount = newTaskCount - 1;
582-
EXPECT_EQ(0u, csr.recursiveLockCounter.load());
583-
auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::BufferToHostPtr,
584-
csr, buffer->getGraphicsAllocation(), nullptr, hostPtr,
585-
buffer->getGraphicsAllocation()->getGpuAddress(), 0,
586-
0, 0, bltSize, 0, 0, 0, 0);
587-
639+
Vec3<size_t> hostPtrOffset = GetParam().hostPtrOffset;
640+
Vec3<size_t> copyOffset = GetParam().copyOffset;
641+
642+
size_t dstRowPitch = GetParam().dstRowPitch;
643+
size_t dstSlicePitch = GetParam().dstSlicePitch;
644+
size_t srcRowPitch = GetParam().srcRowPitch;
645+
size_t srcSlicePitch = GetParam().srcSlicePitch;
646+
647+
auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::BufferToHostPtr, //blitDirection
648+
csr, buffer->getGraphicsAllocation(), //commandStreamReceiver
649+
nullptr, //memObjAllocation
650+
hostPtr, //preallocatedHostAllocation
651+
buffer->getGraphicsAllocation()->getGpuAddress(), //memObjGpuVa
652+
0, //hostAllocGpuVa
653+
hostPtrOffset, //hostPtrOffset
654+
copyOffset, //copyOffset
655+
bltSize, //copySize
656+
dstRowPitch, //hostRowPitch
657+
dstSlicePitch, //hostSlicePitch
658+
srcRowPitch, //gpuRowPitch
659+
srcSlicePitch //gpuSlicePitch
660+
);
588661
blitBuffer(&csr, blitProperties, true);
589-
EXPECT_EQ(newTaskCount, csr.taskCount);
590-
EXPECT_EQ(newTaskCount, csr.latestFlushedTaskCount);
591-
EXPECT_EQ(newTaskCount, csr.latestSentTaskCount);
592-
EXPECT_EQ(newTaskCount, csr.latestSentTaskCountValueDuringFlush);
593-
EXPECT_EQ(1u, csr.recursiveLockCounter.load());
594662

595663
HardwareParse hwParser;
596664
hwParser.parseCommands<FamilyType>(csr.commandStream);
@@ -599,69 +667,127 @@ HWTEST_F(BcsTests, givenBltSizeWithLeftoverWhenDispatchedThenProgramAllRequiredC
599667
auto cmdIterator = cmdList.begin();
600668

601669
uint64_t offset = 0;
602-
for (uint32_t i = 0; i < numberOfBlts; i++) {
670+
for (uint32_t i = 0; i < totalNumberOfBits; i++) {
603671
auto bltCmd = genCmdCast<typename FamilyType::XY_COPY_BLT *>(*(cmdIterator++));
604672
EXPECT_NE(nullptr, bltCmd);
605673

606674
uint32_t expectedWidth = static_cast<uint32_t>(BlitterConstants::maxBlitWidth);
607675
uint32_t expectedHeight = static_cast<uint32_t>(BlitterConstants::maxBlitHeight);
608-
if (i % 3 == 2) {
676+
if (i % numberOfBltsForSingleBltSizeProgramm == numberOfBltsForSingleBltSizeProgramm - 1) {
609677
expectedWidth = bltLeftover;
610678
expectedHeight = 1;
611679
}
612-
EXPECT_EQ(expectedWidth, bltCmd->getTransferWidth());
613-
EXPECT_EQ(expectedHeight, bltCmd->getTransferHeight());
614-
EXPECT_EQ(expectedWidth, bltCmd->getDestinationPitch());
615-
EXPECT_EQ(expectedWidth, bltCmd->getSourcePitch());
616680

617-
auto dstAddr = NEO::BlitCommandsHelper<FamilyType>::calculateBlitCommandDestinationBaseAddress(blitProperties, offset, i % bltSize.y, i % bltSize.z);
618-
auto srcAddr = NEO::BlitCommandsHelper<FamilyType>::calculateBlitCommandSourceBaseAddress(blitProperties, offset, i % bltSize.y, i % bltSize.z);
681+
if (i % numberOfBltsForSingleBltSizeProgramm == 0) {
682+
offset = 0;
683+
}
619684

620-
EXPECT_EQ(dstAddr, bltCmd->getDestinationBaseAddress());
621-
EXPECT_EQ(srcAddr, bltCmd->getSourceBaseAddress());
685+
auto rowIndex = (i / numberOfBltsForSingleBltSizeProgramm) % blitProperties.copySize.y;
686+
auto sliceIndex = i / (numberOfBltsForSingleBltSizeProgramm * blitProperties.copySize.y);
622687

623-
offset = (i % 3 == 2) ? 0 : offset + (expectedWidth * expectedHeight);
624-
}
688+
auto expectedDstAddr = blitProperties.dstGpuAddress + blitProperties.dstOffset.x + offset +
689+
blitProperties.dstOffset.y * blitProperties.dstRowPitch +
690+
blitProperties.dstOffset.z * blitProperties.dstSlicePitch +
691+
rowIndex * blitProperties.dstRowPitch +
692+
sliceIndex * blitProperties.dstSlicePitch;
693+
auto expectedSrcAddr = blitProperties.srcGpuAddress + blitProperties.srcOffset.x + offset +
694+
blitProperties.srcOffset.y * blitProperties.srcRowPitch +
695+
blitProperties.srcOffset.z * blitProperties.srcSlicePitch +
696+
rowIndex * blitProperties.srcRowPitch +
697+
sliceIndex * blitProperties.srcSlicePitch;
625698

626-
if (UnitTestHelper<FamilyType>::isSynchronizationWArequired(pDevice->getHardwareInfo())) {
627-
auto miSemaphoreWaitCmd = genCmdCast<MI_SEMAPHORE_WAIT *>(*(cmdIterator++));
628-
EXPECT_NE(nullptr, miSemaphoreWaitCmd);
629-
EXPECT_TRUE(UnitTestHelper<FamilyType>::isAdditionalMiSemaphoreWait(*miSemaphoreWaitCmd));
699+
auto dstAddr = NEO::BlitCommandsHelper<FamilyType>::calculateBlitCommandDestinationBaseAddress(blitProperties, offset, rowIndex, sliceIndex);
700+
auto srcAddr = NEO::BlitCommandsHelper<FamilyType>::calculateBlitCommandSourceBaseAddress(blitProperties, offset, rowIndex, sliceIndex);
701+
702+
EXPECT_EQ(dstAddr, expectedDstAddr);
703+
EXPECT_EQ(srcAddr, expectedSrcAddr);
704+
705+
offset += (expectedWidth * expectedHeight);
630706
}
707+
}
631708

632-
auto miFlushCmd = genCmdCast<MI_FLUSH_DW *>(*(cmdIterator++));
709+
HWTEST_P(BcsDetaliedTestsWithParams, givenBltSizeWithLeftoverWhenDispatchedThenProgramAllRequiredCommandsForReadBufferRect) {
710+
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
711+
static_cast<OsAgnosticMemoryManager *>(csr.getMemoryManager())->turnOnFakingBigAllocations();
633712

634-
if (UnitTestHelper<FamilyType>::additionalMiFlushDwRequired) {
635-
uint64_t gpuAddress = 0x0;
636-
uint64_t immData = 0;
713+
uint32_t bltLeftover = 17;
714+
Vec3<size_t> bltSize = GetParam().copySize;
637715

638-
EXPECT_NE(nullptr, miFlushCmd);
639-
EXPECT_EQ(MI_FLUSH_DW::POST_SYNC_OPERATION_NO_WRITE, miFlushCmd->getPostSyncOperation());
640-
EXPECT_EQ(gpuAddress, miFlushCmd->getDestinationAddress());
641-
EXPECT_EQ(immData, miFlushCmd->getImmediateData());
716+
size_t numberOfBltsForSingleBltSizeProgramm = 3;
717+
size_t totalNumberOfBits = numberOfBltsForSingleBltSizeProgramm * bltSize.y * bltSize.z;
642718

643-
miFlushCmd = genCmdCast<MI_FLUSH_DW *>(*(cmdIterator++));
644-
}
719+
cl_int retVal = CL_SUCCESS;
720+
auto buffer = clUniquePtr<Buffer>(Buffer::create(context.get(), CL_MEM_READ_WRITE, static_cast<size_t>(8 * BlitterConstants::maxBlitWidth * BlitterConstants::maxBlitHeight), nullptr, retVal));
721+
void *hostPtr = reinterpret_cast<void *>(0x12340000);
645722

646-
EXPECT_NE(cmdIterator, cmdList.end());
647-
EXPECT_EQ(MI_FLUSH_DW::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA_QWORD, miFlushCmd->getPostSyncOperation());
648-
EXPECT_EQ(csr.getTagAllocation()->getGpuAddress(), miFlushCmd->getDestinationAddress());
649-
EXPECT_EQ(newTaskCount, miFlushCmd->getImmediateData());
723+
Vec3<size_t> hostPtrOffset = GetParam().hostPtrOffset;
724+
Vec3<size_t> copyOffset = GetParam().copyOffset;
725+
726+
size_t dstRowPitch = GetParam().dstRowPitch;
727+
size_t dstSlicePitch = GetParam().dstSlicePitch;
728+
size_t srcRowPitch = GetParam().srcRowPitch;
729+
size_t srcSlicePitch = GetParam().srcSlicePitch;
730+
731+
auto blitProperties = BlitProperties::constructPropertiesForReadWriteBuffer(BlitterConstants::BlitDirection::BufferToHostPtr, //blitDirection
732+
csr, buffer->getGraphicsAllocation(), //commandStreamReceiver
733+
nullptr, //memObjAllocation
734+
hostPtr, //preallocatedHostAllocation
735+
buffer->getGraphicsAllocation()->getGpuAddress(), //memObjGpuVa
736+
0, //hostAllocGpuVa
737+
hostPtrOffset, //hostPtrOffset
738+
copyOffset, //copyOffset
739+
bltSize, //copySize
740+
dstRowPitch, //hostRowPitch
741+
dstSlicePitch, //hostSlicePitch
742+
srcRowPitch, //gpuRowPitch
743+
srcSlicePitch //gpuSlicePitch
744+
);
745+
blitBuffer(&csr, blitProperties, true);
650746

651-
if (UnitTestHelper<FamilyType>::isSynchronizationWArequired(pDevice->getHardwareInfo())) {
652-
auto miSemaphoreWaitCmd = genCmdCast<MI_SEMAPHORE_WAIT *>(*(cmdIterator++));
653-
EXPECT_NE(nullptr, miSemaphoreWaitCmd);
654-
EXPECT_TRUE(UnitTestHelper<FamilyType>::isAdditionalMiSemaphoreWait(*miSemaphoreWaitCmd));
655-
}
747+
HardwareParse hwParser;
748+
hwParser.parseCommands<FamilyType>(csr.commandStream);
749+
auto &cmdList = hwParser.cmdList;
656750

657-
EXPECT_NE(nullptr, genCmdCast<typename FamilyType::MI_BATCH_BUFFER_END *>(*(cmdIterator++)));
751+
auto cmdIterator = cmdList.begin();
658752

659-
// padding
660-
while (cmdIterator != cmdList.end()) {
661-
EXPECT_NE(nullptr, genCmdCast<typename FamilyType::MI_NOOP *>(*(cmdIterator++)));
753+
uint64_t offset = 0;
754+
for (uint32_t i = 0; i < totalNumberOfBits; i++) {
755+
auto bltCmd = genCmdCast<typename FamilyType::XY_COPY_BLT *>(*(cmdIterator++));
756+
EXPECT_NE(nullptr, bltCmd);
757+
758+
uint32_t expectedWidth = static_cast<uint32_t>(BlitterConstants::maxBlitWidth);
759+
uint32_t expectedHeight = static_cast<uint32_t>(BlitterConstants::maxBlitHeight);
760+
if (i % numberOfBltsForSingleBltSizeProgramm == numberOfBltsForSingleBltSizeProgramm - 1) {
761+
expectedWidth = bltLeftover;
762+
expectedHeight = 1;
763+
}
764+
765+
if (i % numberOfBltsForSingleBltSizeProgramm == 0) {
766+
offset = 0;
767+
}
768+
769+
EXPECT_EQ(expectedWidth, bltCmd->getTransferWidth());
770+
EXPECT_EQ(expectedHeight, bltCmd->getTransferHeight());
771+
EXPECT_EQ(expectedWidth, bltCmd->getDestinationPitch());
772+
EXPECT_EQ(expectedWidth, bltCmd->getSourcePitch());
773+
774+
auto rowIndex = (i / numberOfBltsForSingleBltSizeProgramm) % blitProperties.copySize.y;
775+
auto sliceIndex = i / (numberOfBltsForSingleBltSizeProgramm * blitProperties.copySize.y);
776+
777+
auto dstAddr = NEO::BlitCommandsHelper<FamilyType>::calculateBlitCommandDestinationBaseAddress(blitProperties, offset, rowIndex, sliceIndex);
778+
auto srcAddr = NEO::BlitCommandsHelper<FamilyType>::calculateBlitCommandSourceBaseAddress(blitProperties, offset, rowIndex, sliceIndex);
779+
780+
EXPECT_EQ(dstAddr, bltCmd->getDestinationBaseAddress());
781+
EXPECT_EQ(srcAddr, bltCmd->getSourceBaseAddress());
782+
783+
offset += (expectedWidth * expectedHeight);
662784
}
663785
}
664786

787+
INSTANTIATE_TEST_CASE_P(BcsDetaliedTest,
788+
BcsDetaliedTestsWithParams,
789+
::testing::ValuesIn(BlitterProperties));
790+
665791
HWTEST_F(BcsTests, givenCsrDependenciesWhenProgrammingCommandStreamThenAddSemaphoreAndAtomic) {
666792
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
667793

0 commit comments

Comments
 (0)