From baea633bddb2af5176c4de83c4dcc121db0d8cdb Mon Sep 17 00:00:00 2001 From: Krzysztof Gibala Date: Fri, 20 Nov 2020 12:04:46 +0100 Subject: [PATCH] Correct logic in MultiRootDeviceFixture Related-To: NEO-4589 Signed-off-by: Krzysztof Gibala --- .../test/unit_tests/CMakeLists.txt | 2 ++ .../tools/test/unit_tests/CMakeLists.txt | 2 ++ .../command_stream_receiver_tests.cpp | 4 ++-- .../experimental_command_buffer_tests.cpp | 2 +- .../test/unit_test/d3d_sharing/d3d9_tests.cpp | 12 +++++----- .../fixtures/multi_root_device_fixture.h | 23 ++++++++++++------- .../kernel_reflection_surface_tests.cpp | 12 +++++----- opencl/test/unit_test/kernel/kernel_tests.cpp | 4 ++-- .../libult/create_command_stream.cpp | 13 +++-------- .../test/unit_test/mem_obj/buffer_tests.cpp | 3 ++- .../test/unit_test/mem_obj/mem_obj_tests.cpp | 6 ++--- .../memory_manager/memory_manager_tests.cpp | 8 +++---- .../unit_test/mocks/ult_cl_device_factory.cpp | 7 ++++++ .../unit_test/mocks/ult_cl_device_factory.h | 3 +++ .../os_interface/device_factory_tests.cpp | 12 ++++++++++ .../unit_test/program/kernel_info_tests.cpp | 2 +- .../program/printf_handler_tests.cpp | 6 ++--- .../test/unit_test/program/program_tests.cpp | 12 +++++----- shared/source/os_interface/device_factory.cpp | 5 ++++ shared/source/os_interface/device_factory.h | 1 + shared/test/unit_test/mocks/mock_device.h | 1 - .../unit_test/mocks/ult_device_factory.cpp | 14 +++++++++++ .../test/unit_test/mocks/ult_device_factory.h | 2 ++ 23 files changed, 102 insertions(+), 54 deletions(-) diff --git a/level_zero/experimental/test/unit_tests/CMakeLists.txt b/level_zero/experimental/test/unit_tests/CMakeLists.txt index 34df338d54..0f446a499c 100644 --- a/level_zero/experimental/test/unit_tests/CMakeLists.txt +++ b/level_zero/experimental/test/unit_tests/CMakeLists.txt @@ -29,6 +29,8 @@ add_executable( ${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_management.cpp ${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_leak_listener.h ${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_leak_listener.cpp + ${NEO_SOURCE_DIR}/shared/test/unit_test/mocks/ult_device_factory.cpp + ${NEO_SOURCE_DIR}/shared/test/unit_test/mocks/ult_device_factory.h ${L0_CORE_ENABLERS} ) diff --git a/level_zero/tools/test/unit_tests/CMakeLists.txt b/level_zero/tools/test/unit_tests/CMakeLists.txt index 049b70deaa..af9982742d 100644 --- a/level_zero/tools/test/unit_tests/CMakeLists.txt +++ b/level_zero/tools/test/unit_tests/CMakeLists.txt @@ -24,6 +24,8 @@ add_executable(${TARGET_NAME} ${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_management.cpp ${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_leak_listener.h ${NEO_SOURCE_DIR}/shared/test/unit_test/helpers/memory_leak_listener.cpp + ${NEO_SOURCE_DIR}/shared/test/unit_test/mocks/ult_device_factory.cpp + ${NEO_SOURCE_DIR}/shared/test/unit_test/mocks/ult_device_factory.h ${L0_CORE_ENABLERS} ) diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp index 6825218b2a..344c581c0d 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp @@ -1302,13 +1302,13 @@ HWTEST_F(SimulatedCommandStreamReceiverTest, givenOsContextWithNoDeviceBitfieldW using CommandStreamReceiverMultiRootDeviceTest = MultiRootDeviceFixture; TEST_F(CommandStreamReceiverMultiRootDeviceTest, WhenCreatingCommandStreamGraphicsAllocationsThenTheyHaveCorrectRootDeviceIndex) { - auto commandStreamReceiver = &device->getGpgpuCommandStreamReceiver(); + auto commandStreamReceiver = &device1->getGpgpuCommandStreamReceiver(); ASSERT_NE(nullptr, commandStreamReceiver); EXPECT_EQ(expectedRootDeviceIndex, commandStreamReceiver->getRootDeviceIndex()); // Linear stream / Command buffer - GraphicsAllocation *allocation = mockMemoryManager->allocateGraphicsMemoryWithProperties({expectedRootDeviceIndex, 128u, GraphicsAllocation::AllocationType::COMMAND_BUFFER, device->getDeviceBitfield()}); + GraphicsAllocation *allocation = mockMemoryManager->allocateGraphicsMemoryWithProperties({expectedRootDeviceIndex, 128u, GraphicsAllocation::AllocationType::COMMAND_BUFFER, device1->getDeviceBitfield()}); LinearStream commandStream{allocation}; commandStreamReceiver->ensureCommandBufferAllocation(commandStream, 100u, 0u); diff --git a/opencl/test/unit_test/command_stream/experimental_command_buffer_tests.cpp b/opencl/test/unit_test/command_stream/experimental_command_buffer_tests.cpp index fd8c487a9a..9935043e37 100644 --- a/opencl/test/unit_test/command_stream/experimental_command_buffer_tests.cpp +++ b/opencl/test/unit_test/command_stream/experimental_command_buffer_tests.cpp @@ -384,7 +384,7 @@ HWTEST_F(ExperimentalCommandBufferTest, givenEnabledExperimentalCmdBufferWhenCom using ExperimentalCommandBufferRootDeviceIndexTest = MultiRootDeviceFixture; TEST_F(ExperimentalCommandBufferRootDeviceIndexTest, GivenExperimentalCommandBufferGraphicsAllocationsThenItHasCorrectRootDeviceIndex) { - auto experimentalCommandBuffer = std::make_unique(&device->getGpgpuCommandStreamReceiver()); + auto experimentalCommandBuffer = std::make_unique(&device1->getGpgpuCommandStreamReceiver()); ASSERT_NE(nullptr, experimentalCommandBuffer); EXPECT_EQ(expectedRootDeviceIndex, experimentalCommandBuffer->experimentalAllocation->getRootDeviceIndex()); diff --git a/opencl/test/unit_test/d3d_sharing/d3d9_tests.cpp b/opencl/test/unit_test/d3d_sharing/d3d9_tests.cpp index f938d870af..627a69697f 100644 --- a/opencl/test/unit_test/d3d_sharing/d3d9_tests.cpp +++ b/opencl/test/unit_test/d3d_sharing/d3d9_tests.cpp @@ -1151,9 +1151,9 @@ TEST_F(D3D9MultiRootDeviceTest, givenD3DHandleIsNullWhenCreatingSharedSurfaceAnd imgDesc.image_depth = 1; imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - auto gmm = MockGmm::queryImgParams(device->getGmmClientContext(), imgInfo).release(); + auto gmm = MockGmm::queryImgParams(device1->getGmmClientContext(), imgInfo).release(); - auto memoryManager = std::make_unique(*device->executionEnvironment); + auto memoryManager = std::make_unique(*device1->executionEnvironment); memoryManager->forceGmm = gmm; auto mockSharingFcns = new NiceMock>(); @@ -1166,7 +1166,7 @@ TEST_F(D3D9MultiRootDeviceTest, givenD3DHandleIsNullWhenCreatingSharedSurfaceAnd ON_CALL(*mockSharingFcns, getTexture2dDesc(_, _)).WillByDefault(SetArgPointee<0>(mockSharingFcns->mockTexture2dDesc)); - MockContext ctx(device.get()); + MockContext ctx(device1); ctx.setSharingFunctions(mockSharingFcns); ctx.memoryManager = memoryManager.get(); @@ -1184,9 +1184,9 @@ TEST_F(D3D9MultiRootDeviceTest, givenD3DHandleIsNotNullWhenCreatingSharedSurface imgDesc.image_depth = 1; imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - auto gmm = MockGmm::queryImgParams(device->getGmmClientContext(), imgInfo).release(); + auto gmm = MockGmm::queryImgParams(device1->getGmmClientContext(), imgInfo).release(); - auto memoryManager = std::make_unique(*device->executionEnvironment); + auto memoryManager = std::make_unique(*device1->executionEnvironment); memoryManager->forceGmm = gmm; auto mockSharingFcns = new NiceMock>(); @@ -1199,7 +1199,7 @@ TEST_F(D3D9MultiRootDeviceTest, givenD3DHandleIsNotNullWhenCreatingSharedSurface ON_CALL(*mockSharingFcns, getTexture2dDesc(_, _)).WillByDefault(SetArgPointee<0>(mockSharingFcns->mockTexture2dDesc)); - MockContext ctx(device.get()); + MockContext ctx(device1); ctx.setSharingFunctions(mockSharingFcns); ctx.memoryManager = memoryManager.get(); diff --git a/opencl/test/unit_test/fixtures/multi_root_device_fixture.h b/opencl/test/unit_test/fixtures/multi_root_device_fixture.h index fb6a2500d0..a9974337cc 100644 --- a/opencl/test/unit_test/fixtures/multi_root_device_fixture.h +++ b/opencl/test/unit_test/fixtures/multi_root_device_fixture.h @@ -6,7 +6,9 @@ */ #pragma once +#include "shared/source/os_interface/device_factory.h" #include "shared/test/unit_test/helpers/debug_manager_state_restore.h" +#include "shared/test/unit_test/helpers/variable_backup.h" #include "shared/test/unit_test/mocks/mock_device.h" #include "opencl/test/unit_test/mocks/mock_cl_device.h" @@ -17,23 +19,28 @@ namespace NEO { class MultiRootDeviceFixture : public ::testing::Test { public: void SetUp() override { - DebugManager.flags.CreateMultipleRootDevices.set(3 * expectedRootDeviceIndex); + createMemoryManagerFuncBackup = [](ExecutionEnvironment &executionEnvironment) -> void { + executionEnvironment.memoryManager = std::make_unique(executionEnvironment); + }; - device = std::make_unique(MockDevice::createWithNewExecutionEnvironment(nullptr, expectedRootDeviceIndex)); - device2 = std::make_unique(MockDevice::createWithNewExecutionEnvironment(nullptr, 2u)); + deviceFactory = std::make_unique(3, 0); + device1 = deviceFactory->rootDevices[1]; + device2 = deviceFactory->rootDevices[2]; - cl_device_id devices[] = { - device.get(), device2.get()}; + cl_device_id devices[] = {device1, device2}; context.reset(new MockContext(ClDeviceVector(devices, 2), false)); - mockMemoryManager = reinterpret_cast(device->getMemoryManager()); + mockMemoryManager = static_cast(device1->getMemoryManager()); + ASSERT_EQ(mockMemoryManager, device1->getMemoryManager()); } const uint32_t expectedRootDeviceIndex = 1; DebugManagerStateRestore restorer; - std::unique_ptr device; - std::unique_ptr device2; + std::unique_ptr deviceFactory; + MockClDevice *device1 = nullptr; + MockClDevice *device2 = nullptr; std::unique_ptr context; MockMemoryManager *mockMemoryManager; + VariableBackup createMemoryManagerFuncBackup{&DeviceFactory::createMemoryManagerFunc}; }; }; // namespace NEO diff --git a/opencl/test/unit_test/kernel/kernel_reflection_surface_tests.cpp b/opencl/test/unit_test/kernel/kernel_reflection_surface_tests.cpp index a833b50f49..0541101fbc 100644 --- a/opencl/test/unit_test/kernel/kernel_reflection_surface_tests.cpp +++ b/opencl/test/unit_test/kernel/kernel_reflection_surface_tests.cpp @@ -2107,13 +2107,13 @@ TEST_F(ReflectionSurfaceConstantValuesPatchingTest, GivenBlockWithConstantMemory using KernelReflectionMultiDeviceTest = MultiRootDeviceFixture; TEST_F(KernelReflectionMultiDeviceTest, GivenNoKernelArgsWhenObtainingKernelReflectionSurfaceThenParamsAreCorrect) { - REQUIRE_DEVICE_ENQUEUE_OR_SKIP(device.get()); + REQUIRE_DEVICE_ENQUEUE_OR_SKIP(device1); - MockProgram program(context.get(), false, toClDeviceVector(*device)); + MockProgram program(context.get(), false, toClDeviceVector(*device1)); KernelInfo *blockInfo = new KernelInfo; KernelInfo &info = *blockInfo; cl_queue_properties properties[1] = {0}; - DeviceQueue devQueue(context.get(), device.get(), properties[0]); + DeviceQueue devQueue(context.get(), device1, properties[0]); SPatchExecutionEnvironment environment = {}; environment.HasDeviceEnqueue = 1; @@ -2156,14 +2156,14 @@ TEST_F(KernelReflectionMultiDeviceTest, GivenNoKernelArgsWhenObtainingKernelRefl } TEST_F(KernelReflectionMultiDeviceTest, GivenDeviceQueueKernelArgWhenObtainingKernelReflectionSurfaceThenParamsAreCorrect) { - REQUIRE_DEVICE_ENQUEUE_OR_SKIP(device.get()); + REQUIRE_DEVICE_ENQUEUE_OR_SKIP(device1); - MockProgram program(context.get(), false, toClDeviceVector(*device)); + MockProgram program(context.get(), false, toClDeviceVector(*device1)); KernelInfo *blockInfo = new KernelInfo; KernelInfo &info = *blockInfo; cl_queue_properties properties[1] = {0}; - DeviceQueue devQueue(context.get(), device.get(), properties[0]); + DeviceQueue devQueue(context.get(), device1, properties[0]); uint32_t devQueueCurbeOffset = 16; uint32_t devQueueCurbeSize = 4; diff --git a/opencl/test/unit_test/kernel/kernel_tests.cpp b/opencl/test/unit_test/kernel/kernel_tests.cpp index 42f791ffd8..0c5e38cb65 100644 --- a/opencl/test/unit_test/kernel/kernel_tests.cpp +++ b/opencl/test/unit_test/kernel/kernel_tests.cpp @@ -3227,11 +3227,11 @@ TEST_F(KernelMultiRootDeviceTest, WhenGettingRootDeviceIndexThenCorrectRootDevic tokenSPS.PerThreadPrivateMemorySize = 112; kernelInfo->patchInfo.pAllocateStatelessPrivateSurface = &tokenSPS; - MockProgram program(context.get(), false, toClDeviceVector(*device)); + MockProgram program(context.get(), false, toClDeviceVector(*device1)); std::unique_ptr kernel(new MockKernel(&program, *kernelInfo)); kernel->initialize(); - auto privateSurface = kernel->kernelDeviceInfos[device->getRootDeviceIndex()].privateSurface; + auto privateSurface = kernel->kernelDeviceInfos[device1->getRootDeviceIndex()].privateSurface; ASSERT_NE(nullptr, privateSurface); EXPECT_EQ(expectedRootDeviceIndex, privateSurface->getRootDeviceIndex()); } diff --git a/opencl/test/unit_test/libult/create_command_stream.cpp b/opencl/test/unit_test/libult/create_command_stream.cpp index 497b8b5b81..c993f4a67a 100644 --- a/opencl/test/unit_test/libult/create_command_stream.cpp +++ b/opencl/test/unit_test/libult/create_command_stream.cpp @@ -9,8 +9,10 @@ #include "shared/source/command_stream/command_stream_receiver.h" #include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/os_interface/device_factory.h" #include "shared/test/unit_test/helpers/default_hw_info.h" #include "shared/test/unit_test/helpers/ult_hw_config.h" +#include "shared/test/unit_test/mocks/ult_device_factory.h" #include "opencl/source/command_stream/aub_command_stream_receiver.h" #include "opencl/source/command_stream/create_command_stream_impl.h" @@ -49,16 +51,7 @@ bool prepareDeviceEnvironments(ExecutionEnvironment &executionEnvironment) { } if (ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc) { uint32_t numRootDevices = DebugManager.flags.CreateMultipleRootDevices.get() != 0 ? DebugManager.flags.CreateMultipleRootDevices.get() : 1u; - executionEnvironment.prepareRootDeviceEnvironments(numRootDevices); - for (auto i = 0u; i < numRootDevices; i++) { - if (executionEnvironment.rootDeviceEnvironments[i]->getHardwareInfo() == nullptr || - (executionEnvironment.rootDeviceEnvironments[i]->getHardwareInfo()->platform.eProductFamily == IGFX_UNKNOWN && - executionEnvironment.rootDeviceEnvironments[i]->getHardwareInfo()->platform.eRenderCoreFamily == IGFX_UNKNOWN_CORE)) { - executionEnvironment.rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get()); - } - } - executionEnvironment.calculateMaxOsContextCount(); - executionEnvironment.initializeMemoryManager(); + UltDeviceFactory::prepareDeviceEnvironments(executionEnvironment, numRootDevices); return ultHwConfig.mockedPrepareDeviceEnvironmentsFuncResult; } diff --git a/opencl/test/unit_test/mem_obj/buffer_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_tests.cpp index 94e9deac3e..1c57769078 100644 --- a/opencl/test/unit_test/mem_obj/buffer_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_tests.cpp @@ -1835,8 +1835,8 @@ TEST_F(MultiRootDeviceBufferTest, WhenBufferIsCreatedAndEnqueueWriteCalledThenBu cl_mem_flags flags = CL_MEM_READ_WRITE; std::unique_ptr buffer(Buffer::create(context.get(), flags, MemoryConstants::pageSize, nullptr, retVal)); - void *ptr = buffer->getCpuAddressForMemoryTransfer(); + void *ptr = buffer->getCpuAddressForMemoryTransfer(); auto cmdQ1 = context->getSpecialQueue(1u); cmdQ1->enqueueWriteBuffer(buffer.get(), CL_FALSE, 0, MemoryConstants::pageSize, ptr, nullptr, 0, nullptr, nullptr); EXPECT_EQ(buffer->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 1u); @@ -1861,6 +1861,7 @@ TEST_F(MultiRootDeviceBufferTest, WhenBufferIsCreatedAndEnqueueReadCalledThenBuf cl_mem_flags flags = CL_MEM_READ_WRITE; std::unique_ptr buffer(Buffer::create(context.get(), flags, MemoryConstants::pageSize, nullptr, retVal)); + void *ptr = buffer->getCpuAddressForMemoryTransfer(); auto cmdQ1 = context->getSpecialQueue(1u); diff --git a/opencl/test/unit_test/mem_obj/mem_obj_tests.cpp b/opencl/test/unit_test/mem_obj/mem_obj_tests.cpp index 4f2dcef196..bcf0b55086 100644 --- a/opencl/test/unit_test/mem_obj/mem_obj_tests.cpp +++ b/opencl/test/unit_test/mem_obj/mem_obj_tests.cpp @@ -501,17 +501,17 @@ TEST(MemObj, givenMemObjNotUsingHostPtrWhenGettingBasePtrTwiceReturnSameMapPtr) using MemObjMultiRootDeviceTests = MultiRootDeviceFixture; TEST_F(MemObjMultiRootDeviceTests, WhenMemObjMapIsCreatedThenAllocationHasCorrectRootDeviceIndex) { - auto allocation = mockMemoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), MemoryConstants::pageSize}); + auto allocation = mockMemoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device1->getRootDeviceIndex(), MemoryConstants::pageSize}); auto memoryProperties = MemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context->getDevice(0)->getDevice()); std::unique_ptr memObj( new MemObj(context.get(), CL_MEM_OBJECT_BUFFER, memoryProperties, CL_MEM_READ_WRITE, 0, 1, nullptr, nullptr, GraphicsAllocationHelper::toMultiGraphicsAllocation(allocation), true, false, false)); - void *mapPtr = memObj->getBasePtrForMap(device->getRootDeviceIndex()); + void *mapPtr = memObj->getBasePtrForMap(device1->getRootDeviceIndex()); EXPECT_NE(nullptr, mapPtr); - auto mapAllocation = memObj->getMapAllocation(device->getRootDeviceIndex()); + auto mapAllocation = memObj->getMapAllocation(device1->getRootDeviceIndex()); ASSERT_NE(nullptr, mapAllocation); EXPECT_EQ(expectedRootDeviceIndex, mapAllocation->getRootDeviceIndex()); diff --git a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp index 7cc8a9755b..8c7c941d9d 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -2400,7 +2400,7 @@ HWTEST_F(MemoryAllocatorTest, givenMemoryManagerWhenEnableHostPtrTrackingFlagIsS using MemoryManagerMultiRootDeviceTests = MultiRootDeviceFixture; TEST_F(MemoryManagerMultiRootDeviceTests, WhenAllocatingGlobalSurfaceThenItHasCorrectRootDeviceIndex) { - if (device->getMemoryManager()->isLimitedRange(expectedRootDeviceIndex)) { + if (device1->getMemoryManager()->isLimitedRange(expectedRootDeviceIndex)) { delete context->svmAllocsManager; context->svmAllocsManager = nullptr; } @@ -2409,13 +2409,13 @@ TEST_F(MemoryManagerMultiRootDeviceTests, WhenAllocatingGlobalSurfaceThenItHasCo WhiteBox linkerInput; linkerInput.traits.exportsGlobalConstants = true; linkerInput.traits.exportsGlobalVariables = true; - GraphicsAllocation *allocation = allocateGlobalsSurface(context->svmAllocsManager, device->getDevice(), initData.size(), false, &linkerInput, initData.data()); + GraphicsAllocation *allocation = allocateGlobalsSurface(context->svmAllocsManager, device1->getDevice(), initData.size(), false, &linkerInput, initData.data()); ASSERT_NE(nullptr, allocation); EXPECT_EQ(expectedRootDeviceIndex, allocation->getRootDeviceIndex()); - if (device->getMemoryManager()->isLimitedRange(expectedRootDeviceIndex)) { - device->getMemoryManager()->freeGraphicsMemory(allocation); + if (device1->getMemoryManager()->isLimitedRange(expectedRootDeviceIndex)) { + device1->getMemoryManager()->freeGraphicsMemory(allocation); } else { context->getSVMAllocsManager()->freeSVMAlloc(allocation->getUnderlyingBuffer()); } diff --git a/opencl/test/unit_test/mocks/ult_cl_device_factory.cpp b/opencl/test/unit_test/mocks/ult_cl_device_factory.cpp index d6c1056bfe..2ad9450ab5 100644 --- a/opencl/test/unit_test/mocks/ult_cl_device_factory.cpp +++ b/opencl/test/unit_test/mocks/ult_cl_device_factory.cpp @@ -7,14 +7,21 @@ #include "opencl/test/unit_test/mocks/ult_cl_device_factory.h" +#include "shared/source/os_interface/device_factory.h" +#include "shared/test/unit_test/helpers/ult_hw_config.h" #include "shared/test/unit_test/mocks/ult_device_factory.h" +#include "opencl/source/command_stream/create_command_stream_impl.h" #include "opencl/test/unit_test/mocks/mock_cl_device.h" +#include "opencl/test/unit_test/mocks/mock_memory_manager.h" using namespace NEO; UltClDeviceFactory::UltClDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevicesCount) { + auto executionEnvironment = new ClExecutionEnvironment(); + UltDeviceFactory::prepareDeviceEnvironments(*executionEnvironment, rootDevicesCount); + pUltDeviceFactory = std::make_unique(rootDevicesCount, subDevicesCount, *executionEnvironment); for (auto &pRootDevice : pUltDeviceFactory->rootDevices) { diff --git a/opencl/test/unit_test/mocks/ult_cl_device_factory.h b/opencl/test/unit_test/mocks/ult_cl_device_factory.h index 36dcfddaaf..5d59229178 100644 --- a/opencl/test/unit_test/mocks/ult_cl_device_factory.h +++ b/opencl/test/unit_test/mocks/ult_cl_device_factory.h @@ -11,7 +11,10 @@ #include namespace NEO { +class ExecutionEnvironment; class ClDevice; +class MemoryManager; +class MockMemoryManager; class MockClDevice; struct UltDeviceFactory; diff --git a/opencl/test/unit_test/os_interface/device_factory_tests.cpp b/opencl/test/unit_test/os_interface/device_factory_tests.cpp index 533c4cc673..611750a773 100644 --- a/opencl/test/unit_test/os_interface/device_factory_tests.cpp +++ b/opencl/test/unit_test/os_interface/device_factory_tests.cpp @@ -12,9 +12,11 @@ #include "shared/source/os_interface/os_interface.h" #include "shared/source/os_interface/os_library.h" #include "shared/test/unit_test/helpers/debug_manager_state_restore.h" +#include "shared/test/unit_test/mocks/ult_device_factory.h" #include "opencl/source/platform/platform.h" #include "opencl/test/unit_test/mocks/mock_execution_environment.h" +#include "opencl/test/unit_test/mocks/mock_memory_manager.h" #include "opencl/test/unit_test/mocks/mock_platform.h" #include "test.h" @@ -270,3 +272,13 @@ TEST(DiscoverDevices, whenDiscoverDevicesAndForceDeviceIdIsDifferentFromTheExist auto result = DeviceFactory::prepareDeviceEnvironments(executionEnviornment); EXPECT_FALSE(result); } + +using UltClDeviceFactoryTest = DeviceFactoryTest; + +TEST_F(UltClDeviceFactoryTest, givenUltClDeviceFactoryPrepareDeviceEnvironmentsCallWhenItIsDoneThenMockMemoryManagerIsAllocated) { + UltDeviceFactory::prepareDeviceEnvironments(*executionEnvironment, 2u); + + EXPECT_EQ(2u, executionEnvironment->rootDeviceEnvironments.size()); + EXPECT_NE(nullptr, executionEnvironment->memoryManager.get()); + EXPECT_EQ(true, executionEnvironment->memoryManager.get()->isInitialized()); +} diff --git a/opencl/test/unit_test/program/kernel_info_tests.cpp b/opencl/test/unit_test/program/kernel_info_tests.cpp index d6ba840f13..2d282c954e 100644 --- a/opencl/test/unit_test/program/kernel_info_tests.cpp +++ b/opencl/test/unit_test/program/kernel_info_tests.cpp @@ -269,7 +269,7 @@ TEST_F(KernelInfoMultiRootDeviceTests, kernelAllocationHasCorrectRootDeviceIndex kernelInfo.heapInfo.KernelHeapSize = heapSize; kernelInfo.heapInfo.pKernelHeap = &heap; - auto retVal = kernelInfo.createKernelAllocation(device->getDevice(), false); + auto retVal = kernelInfo.createKernelAllocation(device1->getDevice(), false); EXPECT_TRUE(retVal); auto allocation = kernelInfo.kernelAllocation; ASSERT_NE(nullptr, allocation); diff --git a/opencl/test/unit_test/program/printf_handler_tests.cpp b/opencl/test/unit_test/program/printf_handler_tests.cpp index 2e5581c45f..2c595dc65d 100644 --- a/opencl/test/unit_test/program/printf_handler_tests.cpp +++ b/opencl/test/unit_test/program/printf_handler_tests.cpp @@ -224,14 +224,14 @@ TEST_F(PrintfHandlerMultiRootDeviceTests, printfSurfaceHasCorrectRootDeviceIndex auto kernelInfo = std::make_unique(); kernelInfo->patchInfo.pAllocateStatelessPrintfSurface = printfSurface.get(); - auto program = std::make_unique(context.get(), false, toClDeviceVector(*device)); + auto program = std::make_unique(context.get(), false, toClDeviceVector(*device1)); uint64_t crossThread[10]; auto kernel = std::make_unique(program.get(), *kernelInfo); kernel->setCrossThreadData(&crossThread, sizeof(uint64_t) * 8); - MockMultiDispatchInfo multiDispatchInfo(device.get(), kernel.get()); - std::unique_ptr printfHandler(PrintfHandler::create(multiDispatchInfo, *device)); + MockMultiDispatchInfo multiDispatchInfo(device1, kernel.get()); + std::unique_ptr printfHandler(PrintfHandler::create(multiDispatchInfo, *device1)); printfHandler->prepareDispatch(multiDispatchInfo); auto surface = printfHandler->getSurface(); diff --git a/opencl/test/unit_test/program/program_tests.cpp b/opencl/test/unit_test/program/program_tests.cpp index d0b8b00bca..bf94b1d016 100644 --- a/opencl/test/unit_test/program/program_tests.cpp +++ b/opencl/test/unit_test/program/program_tests.cpp @@ -2880,7 +2880,7 @@ TEST_F(ProgramBinTest, GivenDebugDataAvailableWhenLinkingProgramThenDebugDataIsS using ProgramMultiRootDeviceTests = MultiRootDeviceFixture; TEST_F(ProgramMultiRootDeviceTests, WhenPrivateSurfaceIsCreatedThenItHasCorrectRootDeviceIndex) { - auto program = std::make_unique(context.get(), false, toClDeviceVector(*device)); + auto program = std::make_unique(context.get(), false, toClDeviceVector(*device1)); auto privateSurfaceBlock = std::make_unique(); privateSurfaceBlock->DataParamOffset = 0; @@ -2894,7 +2894,7 @@ TEST_F(ProgramMultiRootDeviceTests, WhenPrivateSurfaceIsCreatedThenItHasCorrectR infoBlock->patchInfo.pAllocateStatelessPrivateSurface = privateSurfaceBlock.get(); program->blockKernelManager->addBlockKernelInfo(infoBlock.release()); - program->allocateBlockPrivateSurfaces(*device); + program->allocateBlockPrivateSurfaces(*device1); auto privateSurface = program->getBlockKernelManager()->getPrivateSurface(0); EXPECT_NE(nullptr, privateSurface); @@ -2904,8 +2904,8 @@ TEST_F(ProgramMultiRootDeviceTests, WhenPrivateSurfaceIsCreatedThenItHasCorrectR TEST_F(ProgramMultiRootDeviceTests, WhenProgramIsCreatedThenBuildInfosVectorIsProperlyResized) { { ClDeviceVector deviceVector; - deviceVector.push_back(device.get()); - deviceVector.push_back(device2.get()); + deviceVector.push_back(device1); + deviceVector.push_back(device2); EXPECT_EQ(1u, deviceVector[0]->getRootDeviceIndex()); auto program = std::make_unique(context.get(), false, deviceVector); @@ -2914,8 +2914,8 @@ TEST_F(ProgramMultiRootDeviceTests, WhenProgramIsCreatedThenBuildInfosVectorIsPr } { ClDeviceVector deviceVector; - deviceVector.push_back(device2.get()); - deviceVector.push_back(device.get()); + deviceVector.push_back(device2); + deviceVector.push_back(device1); EXPECT_EQ(2u, deviceVector[0]->getRootDeviceIndex()); auto program = std::make_unique(context.get(), false, deviceVector); diff --git a/shared/source/os_interface/device_factory.cpp b/shared/source/os_interface/device_factory.cpp index 9532b21cde..6e2b609b54 100644 --- a/shared/source/os_interface/device_factory.cpp +++ b/shared/source/os_interface/device_factory.cpp @@ -147,4 +147,9 @@ std::vector> DeviceFactory::createDevices(ExecutionEnvir std::unique_ptr (*DeviceFactory::createRootDeviceFunc)(ExecutionEnvironment &, uint32_t) = [](ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) -> std::unique_ptr { return std::unique_ptr(Device::create(&executionEnvironment, rootDeviceIndex)); }; + +void (*DeviceFactory::createMemoryManagerFunc)(ExecutionEnvironment &) = [](ExecutionEnvironment &executionEnvironment) -> void { + executionEnvironment.initializeMemoryManager(); +}; + } // namespace NEO diff --git a/shared/source/os_interface/device_factory.h b/shared/source/os_interface/device_factory.h index e06a3b1abc..c92c779534 100644 --- a/shared/source/os_interface/device_factory.h +++ b/shared/source/os_interface/device_factory.h @@ -23,5 +23,6 @@ class DeviceFactory { static bool isHwModeSelected(); static std::unique_ptr (*createRootDeviceFunc)(ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex); + static void (*createMemoryManagerFunc)(ExecutionEnvironment &executionEnvironment); }; } // namespace NEO diff --git a/shared/test/unit_test/mocks/mock_device.h b/shared/test/unit_test/mocks/mock_device.h index 336d585ed9..58f0986cc8 100644 --- a/shared/test/unit_test/mocks/mock_device.h +++ b/shared/test/unit_test/mocks/mock_device.h @@ -116,7 +116,6 @@ class MockDevice : public RootDevice { pHwInfo = pHwInfo ? pHwInfo : defaultHwInfo.get(); for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(pHwInfo); - executionEnvironment->rootDeviceEnvironments[i]->initGmm(); } return createWithExecutionEnvironment(pHwInfo, executionEnvironment, rootDeviceIndex); } diff --git a/shared/test/unit_test/mocks/ult_device_factory.cpp b/shared/test/unit_test/mocks/ult_device_factory.cpp index b864bbd03c..c841e0a413 100644 --- a/shared/test/unit_test/mocks/ult_device_factory.cpp +++ b/shared/test/unit_test/mocks/ult_device_factory.cpp @@ -45,3 +45,17 @@ UltDeviceFactory::~UltDeviceFactory() { pDevice->decRefInternal(); } } + +void NEO::UltDeviceFactory::prepareDeviceEnvironments(ExecutionEnvironment &executionEnvironment, uint32_t rootDevicesCount) { + uint32_t numRootDevices = rootDevicesCount; + executionEnvironment.prepareRootDeviceEnvironments(numRootDevices); + for (auto i = 0u; i < numRootDevices; i++) { + if (executionEnvironment.rootDeviceEnvironments[i]->getHardwareInfo() == nullptr || + (executionEnvironment.rootDeviceEnvironments[i]->getHardwareInfo()->platform.eProductFamily == IGFX_UNKNOWN && + executionEnvironment.rootDeviceEnvironments[i]->getHardwareInfo()->platform.eRenderCoreFamily == IGFX_UNKNOWN_CORE)) { + executionEnvironment.rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get()); + } + } + executionEnvironment.calculateMaxOsContextCount(); + DeviceFactory::createMemoryManagerFunc(executionEnvironment); +} diff --git a/shared/test/unit_test/mocks/ult_device_factory.h b/shared/test/unit_test/mocks/ult_device_factory.h index 93e556aeaa..68a40d8174 100644 --- a/shared/test/unit_test/mocks/ult_device_factory.h +++ b/shared/test/unit_test/mocks/ult_device_factory.h @@ -19,6 +19,8 @@ struct UltDeviceFactory { UltDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevicesCount, ExecutionEnvironment &executionEnvironment); ~UltDeviceFactory(); + static void prepareDeviceEnvironments(ExecutionEnvironment &executionEnvironment, uint32_t rootDevicesCount); + std::vector rootDevices; std::vector subDevices; };