2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-01-14 21:32:11 +08:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unit_tests/fixtures/device_fixture.h"
|
2019-12-04 20:45:32 +08:00
|
|
|
#include "unit_tests/fixtures/multi_root_device_fixture.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "unit_tests/mocks/mock_context.h"
|
|
|
|
#include "unit_tests/mocks/mock_device.h"
|
|
|
|
#include "unit_tests/mocks/mock_graphics_allocation.h"
|
|
|
|
#include "unit_tests/mocks/mock_kernel.h"
|
|
|
|
#include "unit_tests/mocks/mock_mdi.h"
|
|
|
|
#include "unit_tests/mocks/mock_program.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "gtest/gtest.h"
|
2020-02-22 16:28:27 +08:00
|
|
|
#include "program/printf_handler.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
TEST(PrintfHandlerTest, givenNotPreparedPrintfHandlerWhenGetSurfaceIsCalledThenResultIsNullptr) {
|
2020-01-14 21:32:11 +08:00
|
|
|
MockClDevice *device = new MockClDevice{MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)};
|
2017-12-21 07:45:38 +08:00
|
|
|
MockContext context;
|
|
|
|
SPatchAllocateStatelessPrintfSurface *pPrintfSurface = new SPatchAllocateStatelessPrintfSurface();
|
|
|
|
pPrintfSurface->DataParamOffset = 0;
|
|
|
|
pPrintfSurface->DataParamSize = 8;
|
|
|
|
|
2018-08-16 20:28:58 +08:00
|
|
|
auto pKernelInfo = std::make_unique<KernelInfo>();
|
2017-12-21 07:45:38 +08:00
|
|
|
pKernelInfo->patchInfo.pAllocateStatelessPrintfSurface = pPrintfSurface;
|
|
|
|
|
2020-02-20 15:12:44 +08:00
|
|
|
MockProgram *pProgram = new MockProgram(*device->getExecutionEnvironment(), &context, false, &device->getDevice());
|
2017-12-21 07:45:38 +08:00
|
|
|
MockKernel *pKernel = new MockKernel(pProgram, *pKernelInfo, *device);
|
|
|
|
|
|
|
|
MockMultiDispatchInfo multiDispatchInfo(pKernel);
|
|
|
|
PrintfHandler *printfHandler = PrintfHandler::create(multiDispatchInfo, *device);
|
|
|
|
|
|
|
|
EXPECT_EQ(nullptr, printfHandler->getSurface());
|
|
|
|
|
|
|
|
delete printfHandler;
|
|
|
|
delete pPrintfSurface;
|
|
|
|
delete pKernel;
|
2018-08-16 20:28:58 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
delete pProgram;
|
|
|
|
delete device;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(PrintfHandlerTest, givenPreparedPrintfHandlerWhenGetSurfaceIsCalledThenResultIsNullptr) {
|
2020-01-14 21:32:11 +08:00
|
|
|
MockClDevice *device = new MockClDevice{MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)};
|
2017-12-21 07:45:38 +08:00
|
|
|
MockContext context;
|
|
|
|
SPatchAllocateStatelessPrintfSurface *pPrintfSurface = new SPatchAllocateStatelessPrintfSurface();
|
|
|
|
pPrintfSurface->DataParamOffset = 0;
|
|
|
|
pPrintfSurface->DataParamSize = 8;
|
|
|
|
|
2018-08-16 20:28:58 +08:00
|
|
|
auto pKernelInfo = std::make_unique<KernelInfo>();
|
2017-12-21 07:45:38 +08:00
|
|
|
pKernelInfo->patchInfo.pAllocateStatelessPrintfSurface = pPrintfSurface;
|
|
|
|
|
2020-02-20 15:12:44 +08:00
|
|
|
MockProgram *pProgram = new MockProgram(*device->getExecutionEnvironment(), &context, false, &device->getDevice());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
uint64_t crossThread[10];
|
|
|
|
MockKernel *pKernel = new MockKernel(pProgram, *pKernelInfo, *device);
|
|
|
|
pKernel->setCrossThreadData(&crossThread, sizeof(uint64_t) * 8);
|
|
|
|
|
|
|
|
MockMultiDispatchInfo multiDispatchInfo(pKernel);
|
|
|
|
PrintfHandler *printfHandler = PrintfHandler::create(multiDispatchInfo, *device);
|
|
|
|
printfHandler->prepareDispatch(multiDispatchInfo);
|
|
|
|
EXPECT_NE(nullptr, printfHandler->getSurface());
|
|
|
|
|
|
|
|
delete printfHandler;
|
|
|
|
delete pPrintfSurface;
|
|
|
|
delete pKernel;
|
2018-08-16 20:28:58 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
delete pProgram;
|
|
|
|
delete device;
|
|
|
|
}
|
2019-12-04 20:45:32 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
TEST(PrintfHandlerTest, givenParentKernelWihoutPrintfAndBlockKernelWithPrintfWhenPrintfHandlerCreateCalledThenResaultIsAnObject) {
|
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
2018-07-30 20:13:37 +08:00
|
|
|
MockContext context(device.get());
|
|
|
|
std::unique_ptr<MockParentKernel> parentKernelWithoutPrintf(MockParentKernel::create(context, false, false, false, false));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
MockMultiDispatchInfo multiDispatchInfo(parentKernelWithoutPrintf.get());
|
|
|
|
|
2018-07-30 20:13:37 +08:00
|
|
|
std::unique_ptr<PrintfHandler> printfHandler(PrintfHandler::create(multiDispatchInfo, *device));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
ASSERT_NE(nullptr, printfHandler.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(PrintfHandlerTest, givenParentKernelAndBlockKernelWithoutPrintfWhenPrintfHandlerCreateCalledThenResaultIsNullptr) {
|
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
2018-07-30 20:13:37 +08:00
|
|
|
MockContext context(device.get());
|
|
|
|
std::unique_ptr<MockParentKernel> blockKernelWithoutPrintf(MockParentKernel::create(context, false, false, false, false, false));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
MockMultiDispatchInfo multiDispatchInfo(blockKernelWithoutPrintf.get());
|
|
|
|
|
2018-07-30 20:13:37 +08:00
|
|
|
std::unique_ptr<PrintfHandler> printfHandler(PrintfHandler::create(multiDispatchInfo, *device));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
ASSERT_EQ(nullptr, printfHandler.get());
|
|
|
|
}
|
|
|
|
TEST(PrintfHandlerTest, givenParentKernelWithPrintfAndBlockKernelWithoutPrintfWhenPrintfHandlerCreateCalledThenResaultIsAnObject) {
|
|
|
|
|
2020-01-14 21:32:11 +08:00
|
|
|
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
2018-07-30 20:13:37 +08:00
|
|
|
MockContext context(device.get());
|
|
|
|
std::unique_ptr<MockParentKernel> parentKernelWithPrintfBlockKernelWithoutPrintf(MockParentKernel::create(context, false, false, false, true, false));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
MockMultiDispatchInfo multiDispatchInfo(parentKernelWithPrintfBlockKernelWithoutPrintf.get());
|
|
|
|
|
2018-07-30 20:13:37 +08:00
|
|
|
std::unique_ptr<PrintfHandler> printfHandler(PrintfHandler::create(multiDispatchInfo, *device));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
ASSERT_NE(nullptr, printfHandler);
|
|
|
|
}
|
2018-08-17 21:13:04 +08:00
|
|
|
|
|
|
|
TEST(PrintfHandlerTest, givenMultiDispatchInfoWithMultipleKernelsWhenCreatingAndDispatchingPrintfHandlerThenPickMainKernel) {
|
|
|
|
MockContext context;
|
2020-01-14 21:32:11 +08:00
|
|
|
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
2020-02-20 15:12:44 +08:00
|
|
|
auto program = std::make_unique<MockProgram>(*device->getExecutionEnvironment(), &context, false, &device->getDevice());
|
2018-08-17 21:13:04 +08:00
|
|
|
auto mainKernelInfo = std::make_unique<KernelInfo>();
|
|
|
|
auto kernelInfo = std::make_unique<KernelInfo>();
|
|
|
|
|
|
|
|
auto printfSurface = std::make_unique<SPatchAllocateStatelessPrintfSurface>();
|
|
|
|
printfSurface->DataParamOffset = 0;
|
|
|
|
printfSurface->DataParamSize = 8;
|
|
|
|
|
|
|
|
mainKernelInfo->patchInfo.pAllocateStatelessPrintfSurface = printfSurface.get();
|
|
|
|
|
|
|
|
uint64_t crossThread[8];
|
|
|
|
auto mainKernel = std::make_unique<MockKernel>(program.get(), *mainKernelInfo, *device);
|
|
|
|
auto kernel1 = std::make_unique<MockKernel>(program.get(), *kernelInfo, *device);
|
|
|
|
auto kernel2 = std::make_unique<MockKernel>(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(PrintfHandler::create(multiDispatchInfo, *device));
|
|
|
|
ASSERT_NE(nullptr, printfHandler.get());
|
|
|
|
|
|
|
|
printfHandler->prepareDispatch(multiDispatchInfo);
|
|
|
|
EXPECT_NE(nullptr, printfHandler->getSurface());
|
|
|
|
}
|
2019-11-30 00:34:18 +08:00
|
|
|
|
|
|
|
TEST(PrintfHandlerTest, GivenEmptyMultiDispatchInfoWhenCreatingPrintfHandlerThenPrintfHandlerIsNotCreated) {
|
2020-01-14 21:32:11 +08:00
|
|
|
MockClDevice device{new MockDevice};
|
2019-11-30 00:34:18 +08:00
|
|
|
MockKernelWithInternals mockKernelWithInternals{device};
|
|
|
|
MockMultiDispatchInfo multiDispatchInfo{mockKernelWithInternals.mockKernel};
|
|
|
|
multiDispatchInfo.dispatchInfos.resize(0);
|
|
|
|
EXPECT_EQ(nullptr, multiDispatchInfo.peekMainKernel());
|
|
|
|
|
|
|
|
auto printfHandler = PrintfHandler::create(multiDispatchInfo, device);
|
|
|
|
EXPECT_EQ(nullptr, printfHandler);
|
|
|
|
}
|
2019-12-04 20:45:32 +08:00
|
|
|
|
|
|
|
using PrintfHandlerMultiRootDeviceTests = MultiRootDeviceFixture;
|
|
|
|
|
|
|
|
TEST_F(PrintfHandlerMultiRootDeviceTests, printfSurfaceHasCorrectRootDeviceIndex) {
|
|
|
|
auto printfSurface = std::make_unique<SPatchAllocateStatelessPrintfSurface>();
|
|
|
|
printfSurface->DataParamOffset = 0;
|
|
|
|
printfSurface->DataParamSize = 8;
|
|
|
|
|
|
|
|
auto kernelInfo = std::make_unique<KernelInfo>();
|
|
|
|
kernelInfo->patchInfo.pAllocateStatelessPrintfSurface = printfSurface.get();
|
|
|
|
|
2020-02-20 15:12:44 +08:00
|
|
|
auto program = std::make_unique<MockProgram>(*device->getExecutionEnvironment(), context.get(), false, &device->getDevice());
|
2019-12-04 20:45:32 +08:00
|
|
|
|
|
|
|
uint64_t crossThread[10];
|
|
|
|
auto kernel = std::make_unique<MockKernel>(program.get(), *kernelInfo, *device);
|
|
|
|
kernel->setCrossThreadData(&crossThread, sizeof(uint64_t) * 8);
|
|
|
|
|
|
|
|
MockMultiDispatchInfo multiDispatchInfo(kernel.get());
|
|
|
|
std::unique_ptr<PrintfHandler> printfHandler(PrintfHandler::create(multiDispatchInfo, *device));
|
|
|
|
printfHandler->prepareDispatch(multiDispatchInfo);
|
|
|
|
auto surface = printfHandler->getSurface();
|
|
|
|
|
|
|
|
ASSERT_NE(nullptr, surface);
|
|
|
|
EXPECT_EQ(expectedRootDeviceIndex, surface->getRootDeviceIndex());
|
|
|
|
}
|