From 56562963ef61975d988fde3a0d08306db334f803 Mon Sep 17 00:00:00 2001 From: "Dunajski, Bartosz" Date: Fri, 17 Aug 2018 15:13:04 +0200 Subject: [PATCH] Pick main Kernel for PrintfHandler and AubSubCapture Change-Id: I9ff3bdaa5da82e162642deeaf4a8e0821ff00da2 Signed-off-by: Dunajski, Bartosz --- runtime/command_stream/aub_subcapture.cpp | 4 +-- runtime/program/printf_handler.cpp | 4 +-- .../command_stream/aub_subcapture_tests.cpp | 27 ++++++++++++++ unit_tests/program/printf_handler_tests.cpp | 35 +++++++++++++++++++ 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/runtime/command_stream/aub_subcapture.cpp b/runtime/command_stream/aub_subcapture.cpp index 45e95572e0..de708702fd 100644 --- a/runtime/command_stream/aub_subcapture.cpp +++ b/runtime/command_stream/aub_subcapture.cpp @@ -115,7 +115,7 @@ std::string AubSubCaptureManager::generateToggleFileName(const MultiDispatchInfo std::string toggleFileName = baseFileName + "_toggle"; toggleFileName += "_from_" + std::to_string(kernelCurrentIdx - 1); if (!dispatchInfo.empty()) { - toggleFileName += "_" + dispatchInfo.begin()->getKernel()->getKernelInfo().name; + toggleFileName += "_" + dispatchInfo.peekMainKernel()->getKernelInfo().name; } toggleFileName += ".aub"; return toggleFileName; @@ -123,7 +123,7 @@ std::string AubSubCaptureManager::generateToggleFileName(const MultiDispatchInfo bool AubSubCaptureManager::isSubCaptureFilterActive(const MultiDispatchInfo &dispatchInfo, uint32_t kernelIdx) const { DEBUG_BREAK_IF(dispatchInfo.size() > 1); - auto kernelName = dispatchInfo.begin()->getKernel()->getKernelInfo().name; + auto kernelName = dispatchInfo.peekMainKernel()->getKernelInfo().name; auto subCaptureIsActive = false; if (isKernelIndexInSubCaptureRange(kernelIdx)) { diff --git a/runtime/program/printf_handler.cpp b/runtime/program/printf_handler.cpp index ecaf564267..35dfa7b2e8 100644 --- a/runtime/program/printf_handler.cpp +++ b/runtime/program/printf_handler.cpp @@ -40,7 +40,7 @@ PrintfHandler::~PrintfHandler() { PrintfHandler *PrintfHandler::create(const MultiDispatchInfo &multiDispatchInfo, Device &device) { if (multiDispatchInfo.usesStatelessPrintfSurface() || - (multiDispatchInfo.begin()->getKernel()->checkIfIsParentKernelAndBlocksUsesPrintf())) { + (multiDispatchInfo.peekMainKernel()->checkIfIsParentKernelAndBlocksUsesPrintf())) { return new PrintfHandler(device); } return nullptr; @@ -51,7 +51,7 @@ void PrintfHandler::prepareDispatch(const MultiDispatchInfo &multiDispatchInfo) if (printfSurfaceSize == 0) { return; } - kernel = multiDispatchInfo.begin()->getKernel(); + kernel = multiDispatchInfo.peekMainKernel(); printfSurface = device.getMemoryManager()->allocateGraphicsMemoryInPreferredPool(true, nullptr, printfSurfaceSize, GraphicsAllocation::AllocationType::PRINTF_SURFACE); *reinterpret_cast(printfSurface->getUnderlyingBuffer()) = printfSurfaceInitialDataSize; diff --git a/unit_tests/command_stream/aub_subcapture_tests.cpp b/unit_tests/command_stream/aub_subcapture_tests.cpp index 041821ef63..13685db8fa 100644 --- a/unit_tests/command_stream/aub_subcapture_tests.cpp +++ b/unit_tests/command_stream/aub_subcapture_tests.cpp @@ -477,3 +477,30 @@ TEST_F(AubSubCaptureTest, givenSubCaptureManagerInToggleModeWhenGenerateToggleFi std::string toggleFileName = aubSubCaptureManager.generateToggleFileName(dispatchInfo); EXPECT_EQ(std::string::npos, toggleFileName.find(kernelName)); } + +TEST_F(AubSubCaptureTest, givenMultiDispatchInfoWithMultipleKernelsWhenGenerateToggleFileNameThenPickMainKernel) { + AubSubCaptureManagerMock aubSubCaptureManager("aubfile.aub"); + KernelInfo mainKernelInfo = {}; + mainKernelInfo.name = "main_kernel"; + + MockKernel mainKernel(program.get(), mainKernelInfo, *pDevice); + MockKernel kernel1(program.get(), kernelInfo, *pDevice); + MockKernel kernel2(program.get(), kernelInfo, *pDevice); + + DispatchInfo mainDispatchInfo(&mainKernel, 1, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}); + DispatchInfo dispatchInfo1(&kernel1, 1, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}); + DispatchInfo dispatchInfo2(&kernel2, 1, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}); + + MultiDispatchInfo multiDispatchInfo(&mainKernel); + multiDispatchInfo.push(dispatchInfo1); + multiDispatchInfo.push(mainDispatchInfo); + multiDispatchInfo.push(dispatchInfo2); + + std::string externalFileName = ""; + aubSubCaptureManager.setExternalFileName(externalFileName); + + aubSubCaptureManager.subCaptureMode = AubSubCaptureManager::SubCaptureMode::Toggle; + std::string toggleFileName = aubSubCaptureManager.generateToggleFileName(multiDispatchInfo); + EXPECT_NE(std::string::npos, toggleFileName.find(mainKernelInfo.name)); + EXPECT_STREQ(toggleFileName.c_str(), aubSubCaptureManager.getSubCaptureFileName(multiDispatchInfo).c_str()); +} diff --git a/unit_tests/program/printf_handler_tests.cpp b/unit_tests/program/printf_handler_tests.cpp index 57ca4ef577..142ec73cfb 100644 --- a/unit_tests/program/printf_handler_tests.cpp +++ b/unit_tests/program/printf_handler_tests.cpp @@ -123,3 +123,38 @@ TEST(PrintfHandlerTest, givenParentKernelWithPrintfAndBlockKernelWithoutPrintfWh ASSERT_NE(nullptr, printfHandler); } + +TEST(PrintfHandlerTest, givenMultiDispatchInfoWithMultipleKernelsWhenCreatingAndDispatchingPrintfHandlerThenPickMainKernel) { + MockContext context; + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + auto program = std::make_unique(*device->getExecutionEnvironment(), &context, false); + auto mainKernelInfo = std::make_unique(); + auto kernelInfo = std::make_unique(); + + auto printfSurface = std::make_unique(); + printfSurface->DataParamOffset = 0; + printfSurface->DataParamSize = 8; + + mainKernelInfo->patchInfo.pAllocateStatelessPrintfSurface = printfSurface.get(); + + uint64_t crossThread[8]; + auto mainKernel = std::make_unique(program.get(), *mainKernelInfo, *device); + auto kernel1 = std::make_unique(program.get(), *kernelInfo, *device); + auto kernel2 = std::make_unique(program.get(), *kernelInfo, *device); + mainKernel->setCrossThreadData(&crossThread, sizeof(uint64_t) * 8); + + DispatchInfo mainDispatchInfo(mainKernel.get(), 1, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}); + DispatchInfo dispatchInfo1(kernel1.get(), 1, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}); + DispatchInfo dispatchInfo2(kernel2.get(), 1, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}); + + MultiDispatchInfo multiDispatchInfo(mainKernel.get()); + multiDispatchInfo.push(dispatchInfo1); + multiDispatchInfo.push(mainDispatchInfo); + multiDispatchInfo.push(dispatchInfo2); + + std::unique_ptr printfHandler(PrintfHandler::create(multiDispatchInfo, *device)); + ASSERT_NE(nullptr, printfHandler.get()); + + printfHandler->prepareDispatch(multiDispatchInfo); + EXPECT_NE(nullptr, printfHandler->getSurface()); +}