From 2169d8f3aa30d8b458a8eff2039d36467ffef710 Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Thu, 8 Oct 2020 15:54:46 +0200 Subject: [PATCH] Add ULT for PrintfHandler::prepareDispatch Verify blitter usage. Change-Id: I4ceb9c4cd4affea93751eb518aed5efaa0a6d829 Signed-off-by: Filip Hazubski --- .../program/printf_handler_tests.cpp | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/opencl/test/unit_test/program/printf_handler_tests.cpp b/opencl/test/unit_test/program/printf_handler_tests.cpp index 7ab2254265..ddc6ae9897 100644 --- a/opencl/test/unit_test/program/printf_handler_tests.cpp +++ b/opencl/test/unit_test/program/printf_handler_tests.cpp @@ -6,6 +6,7 @@ */ #include "shared/test/unit_test/mocks/mock_device.h" +#include "shared/test/unit_test/test_macros/test_checks_shared.h" #include "opencl/source/program/printf_handler.h" #include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h" @@ -158,6 +159,61 @@ TEST(PrintfHandlerTest, GivenEmptyMultiDispatchInfoWhenCreatingPrintfHandlerThen EXPECT_EQ(nullptr, printfHandler); } +TEST(PrintfHandlerTest, GivenAllocationInLocalMemoryWhichRequiresBlitterWhenPreparingPrintfSurfaceDispatchThenBlitterIsUsed) { + REQUIRE_BLITTER_OR_SKIP(defaultHwInfo.get()); + + DebugManagerStateRestore restorer; + + auto hwInfo = *defaultHwInfo; + hwInfo.capabilityTable.blitterOperationsSupported = true; + + uint32_t blitsCounter = 0; + uint32_t expectedBlitsCount = 0; + auto mockBlitMemoryToAllocation = [&blitsCounter](const Device &device, GraphicsAllocation *memory, size_t offset, const void *hostPtr, + Vec3 size) -> BlitOperationResult { + blitsCounter++; + return BlitOperationResult::Success; + }; + VariableBackup blitMemoryToAllocationFuncBackup{ + &BlitHelperFunctions::blitMemoryToAllocation, mockBlitMemoryToAllocation}; + + LocalMemoryAccessMode localMemoryAccessModes[] = { + LocalMemoryAccessMode::Default, + LocalMemoryAccessMode::CpuAccessAllowed, + LocalMemoryAccessMode::CpuAccessDisallowed}; + + for (auto localMemoryAccessMode : localMemoryAccessModes) { + DebugManager.flags.ForceLocalMemoryAccessMode.set(static_cast(localMemoryAccessMode)); + for (auto isLocalMemorySupported : ::testing::Bool()) { + DebugManager.flags.EnableLocalMemory.set(isLocalMemorySupported); + auto pClDevice = std::make_unique(MockDevice::createWithNewExecutionEnvironment(&hwInfo)); + MockContext context{pClDevice.get()}; + + auto printfSurface = std::make_unique(); + printfSurface->DataParamOffset = 0; + printfSurface->DataParamSize = 8; + + auto kernelInfo = std::make_unique(); + kernelInfo->patchInfo.pAllocateStatelessPrintfSurface = printfSurface.get(); + + auto program = std::make_unique(*pClDevice->getExecutionEnvironment(), &context, false, &pClDevice->getDevice()); + uint64_t crossThread[10]; + auto kernel = std::make_unique(program.get(), *kernelInfo, *pClDevice); + kernel->setCrossThreadData(&crossThread, sizeof(uint64_t) * 8); + + MockMultiDispatchInfo multiDispatchInfo(kernel.get()); + std::unique_ptr printfHandler(PrintfHandler::create(multiDispatchInfo, *pClDevice)); + printfHandler->prepareDispatch(multiDispatchInfo); + + if (printfHandler->getSurface()->isAllocatedInLocalMemoryPool() && + (localMemoryAccessMode == LocalMemoryAccessMode::CpuAccessDisallowed)) { + expectedBlitsCount++; + } + EXPECT_EQ(expectedBlitsCount, blitsCounter); + } + } +} + using PrintfHandlerMultiRootDeviceTests = MultiRootDeviceFixture; TEST_F(PrintfHandlerMultiRootDeviceTests, printfSurfaceHasCorrectRootDeviceIndex) {