From 1d44699adb962d9f33ef9a873fc20e7449664ae4 Mon Sep 17 00:00:00 2001 From: "Jobczyk, Lukasz" Date: Mon, 13 Jan 2020 11:35:19 +0100 Subject: [PATCH] Enable hw path in the memory manager multi device test Resolves: NEO-4136 Change-Id: I95b1de2804b61516bda9d6eb76d30ea9752d0771 Signed-off-by: Jobczyk, Lukasz Signed-off-by: Lukasz Jobczyk --- .../unit_test/fixtures/linux/CMakeLists.txt | 15 ++++++++ ...y_allocator_multi_device_fixture_linux.cpp | 24 ++++++++++++ .../memory_allocator_multi_device_fixture.h | 24 ++++++++++-- .../unit_test/fixtures/windows/CMakeLists.txt | 15 ++++++++ ...allocator_multi_device_fixture_windows.cpp | 37 +++++++++++++++++++ .../memory_manager_multi_device_tests.cpp | 32 +++++----------- .../mocks/linux/mock_drm_memory_manager.h | 3 ++ shared/source/gmm_helper/gmm.cpp | 2 + shared/source/gmm_helper/gmm.h | 2 +- 9 files changed, 127 insertions(+), 27 deletions(-) create mode 100644 opencl/test/unit_test/fixtures/linux/CMakeLists.txt create mode 100644 opencl/test/unit_test/fixtures/linux/memory_allocator_multi_device_fixture_linux.cpp create mode 100644 opencl/test/unit_test/fixtures/windows/CMakeLists.txt create mode 100644 opencl/test/unit_test/fixtures/windows/memory_allocator_multi_device_fixture_windows.cpp diff --git a/opencl/test/unit_test/fixtures/linux/CMakeLists.txt b/opencl/test/unit_test/fixtures/linux/CMakeLists.txt new file mode 100644 index 0000000000..b3dd0335c6 --- /dev/null +++ b/opencl/test/unit_test/fixtures/linux/CMakeLists.txt @@ -0,0 +1,15 @@ +# +# Copyright (C) 2020 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +set(IGDRCL_SRCS_tests_fixtures_linux + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/memory_allocator_multi_device_fixture_linux.cpp +) +if(UNIX) + target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_fixtures_linux}) +endif() +set_property(GLOBAL PROPERTY IGDRCL_SRCS_tests_fixtures_linux ${IGDRCL_SRCS_tests_fixtures_linux}) +add_subdirectories() diff --git a/opencl/test/unit_test/fixtures/linux/memory_allocator_multi_device_fixture_linux.cpp b/opencl/test/unit_test/fixtures/linux/memory_allocator_multi_device_fixture_linux.cpp new file mode 100644 index 0000000000..af41207ca7 --- /dev/null +++ b/opencl/test/unit_test/fixtures/linux/memory_allocator_multi_device_fixture_linux.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "opencl/test/unit_test/fixtures/memory_allocator_multi_device_fixture.h" +#include "opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h" + +using namespace NEO; + +void MemoryAllocatorMultiDeviceSystemSpecificFixture::SetUp(ExecutionEnvironment &executionEnvironment) { + auto memoryManager = static_cast(executionEnvironment.memoryManager.get()); + auto bufferObject = memoryManager->createSharedBufferObject(0u, 10, true, 0u); + memoryManager->pushSharedBufferObject(bufferObject); +} + +void MemoryAllocatorMultiDeviceSystemSpecificFixture::TearDown(ExecutionEnvironment &executionEnvironment) { + auto memoryManager = static_cast(executionEnvironment.memoryManager.get()); + auto bufferObject = memoryManager->sharingBufferObjects.back(); + memoryManager->eraseSharedBufferObject(bufferObject); + delete bufferObject; +} diff --git a/opencl/test/unit_test/fixtures/memory_allocator_multi_device_fixture.h b/opencl/test/unit_test/fixtures/memory_allocator_multi_device_fixture.h index cce200c002..1b1f1c2fc8 100644 --- a/opencl/test/unit_test/fixtures/memory_allocator_multi_device_fixture.h +++ b/opencl/test/unit_test/fixtures/memory_allocator_multi_device_fixture.h @@ -7,20 +7,26 @@ #pragma once -#include "shared/source/execution_environment/execution_environment.h" +#include "shared/source/gmm_helper/gmm.h" #include "shared/test/unit_test/helpers/debug_manager_state_restore.h" #include "shared/test/unit_test/helpers/ult_hw_config.h" -#include "opencl/source/memory_manager/os_agnostic_memory_manager.h" #include "opencl/test/unit_test/fixtures/memory_management_fixture.h" #include "opencl/test/unit_test/helpers/variable_backup.h" -#include "opencl/test/unit_test/mocks/mock_memory_manager.h" #include "opencl/test/unit_test/mocks/mock_platform.h" using namespace NEO; +class MemoryAllocatorMultiDeviceSystemSpecificFixture { + public: + void SetUp(ExecutionEnvironment &executionEnvironment); + void TearDown(ExecutionEnvironment &executionEnvironment); + + std::unique_ptr gmm; +}; + template -class MemoryAllocatorMultiDeviceFixture : public MemoryManagementFixture, public ::testing::TestWithParam { +class MemoryAllocatorMultiDeviceFixture : public MemoryManagementFixture, public MemoryAllocatorMultiDeviceSystemSpecificFixture, public ::testing::TestWithParam { public: void SetUp() override { MemoryManagementFixture::SetUp(); @@ -34,6 +40,16 @@ class MemoryAllocatorMultiDeviceFixture : public MemoryManagementFixture, public initPlatform(); executionEnvironment = platform()->peekExecutionEnvironment(); memoryManager = executionEnvironment->memoryManager.get(); + + if (!isOsAgnosticMemoryManager) { + MemoryAllocatorMultiDeviceSystemSpecificFixture::SetUp(*executionEnvironment); + } + } + + void TearDown() override { + if (!isOsAgnosticMemoryManager) { + MemoryAllocatorMultiDeviceSystemSpecificFixture::TearDown(*executionEnvironment); + } } uint32_t getNumRootDevices() { return numRootDevices; } diff --git a/opencl/test/unit_test/fixtures/windows/CMakeLists.txt b/opencl/test/unit_test/fixtures/windows/CMakeLists.txt new file mode 100644 index 0000000000..11e1b6c281 --- /dev/null +++ b/opencl/test/unit_test/fixtures/windows/CMakeLists.txt @@ -0,0 +1,15 @@ +# +# Copyright (C) 2020 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +set(IGDRCL_SRCS_tests_fixtures_windows + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/memory_allocator_multi_device_fixture_windows.cpp +) +if(WIN32) + target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_fixtures_windows}) +endif() +set_property(GLOBAL PROPERTY IGDRCL_SRCS_tests_fixtures_windows ${IGDRCL_SRCS_tests_fixtures_windows}) +add_subdirectories() diff --git a/opencl/test/unit_test/fixtures/windows/memory_allocator_multi_device_fixture_windows.cpp b/opencl/test/unit_test/fixtures/windows/memory_allocator_multi_device_fixture_windows.cpp new file mode 100644 index 0000000000..65c2046f2d --- /dev/null +++ b/opencl/test/unit_test/fixtures/windows/memory_allocator_multi_device_fixture_windows.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/gmm_helper/resource_info.h" +#include "shared/source/os_interface/windows/os_interface.h" +#include "shared/test/unit_test/os_interface/windows/mock_gdi_interface.h" + +#include "opencl/test/unit_test/fixtures/memory_allocator_multi_device_fixture.h" +#include "opencl/test/unit_test/mock_gdi/mock_gdi.h" +#include "opencl/test/unit_test/mocks/mock_wddm.h" + +using namespace NEO; + +void MemoryAllocatorMultiDeviceSystemSpecificFixture::SetUp(ExecutionEnvironment &executionEnvironment) { + static D3DDDI_OPENALLOCATIONINFO allocationInfo; + for (auto i = 0u; i < executionEnvironment.rootDeviceEnvironments.size(); i++) { + gmm = std::make_unique(executionEnvironment.rootDeviceEnvironments[i]->getGmmClientContext(), nullptr, 0, false); + auto wddm = static_cast(executionEnvironment.rootDeviceEnvironments[i]->osInterface->get()->getWddm()); + wddm->callBaseMapGpuVa = false; + auto gdi = new MockGdi(); + wddm->resetGdi(gdi); + gdi->getQueryResourceInfoArgOut().NumAllocations = 1; + + allocationInfo.pPrivateDriverData = gmm->gmmResourceInfo->peekHandle(); + allocationInfo.hAllocation = ALLOCATION_HANDLE; + allocationInfo.PrivateDriverDataSize = sizeof(GMM_RESOURCE_INFO); + + gdi->getOpenResourceArgOut().pOpenAllocationInfo = &allocationInfo; + } +} + +void MemoryAllocatorMultiDeviceSystemSpecificFixture::TearDown(ExecutionEnvironment &executionEnvironment) {} diff --git a/opencl/test/unit_test/memory_manager/memory_manager_multi_device_tests.cpp b/opencl/test/unit_test/memory_manager/memory_manager_multi_device_tests.cpp index c420d4c98e..eb138af258 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_multi_device_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_multi_device_tests.cpp @@ -5,21 +5,11 @@ * */ -#include "shared/source/memory_manager/internal_allocation_storage.h" +#include "shared/source/memory_manager/graphics_allocation.h" #include "shared/source/memory_manager/memory_constants.h" -#include "shared/source/os_interface/os_context.h" -#include "shared/source/os_interface/os_interface.h" +#include "shared/source/memory_manager/memory_manager.h" -#include "opencl/source/mem_obj/image.h" -#include "opencl/source/mem_obj/mem_obj_helper.h" -#include "opencl/source/platform/platform.h" #include "opencl/test/unit_test/fixtures/memory_allocator_multi_device_fixture.h" -#include "opencl/test/unit_test/fixtures/memory_manager_fixture.h" -#include "opencl/test/unit_test/helpers/execution_environment_helper.h" -#include "opencl/test/unit_test/mocks/mock_execution_environment.h" -#include "opencl/test/unit_test/mocks/mock_graphics_allocation.h" -#include "opencl/test/unit_test/mocks/mock_memory_manager.h" -#include "opencl/test/unit_test/mocks/mock_os_context.h" #include "test.h" using namespace NEO; @@ -53,17 +43,15 @@ TEST_P(MemoryManagerMultiDeviceTest, givenRootDeviceIndexSpecifiedWhenAllocateGr EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex()); memoryManager->freeGraphicsMemory(gfxAllocation); - if (isOsAgnosticMemoryManager) { - gfxAllocation = memoryManager->createGraphicsAllocationFromSharedHandle((osHandle)1u, properties, false); - ASSERT_NE(gfxAllocation, nullptr); - EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex()); - memoryManager->freeGraphicsMemory(gfxAllocation); + gfxAllocation = memoryManager->createGraphicsAllocationFromSharedHandle((osHandle)0u, properties, false); + ASSERT_NE(gfxAllocation, nullptr); + EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex()); + memoryManager->freeGraphicsMemory(gfxAllocation); - gfxAllocation = memoryManager->createGraphicsAllocationFromSharedHandle((osHandle)1u, properties, true); - ASSERT_NE(gfxAllocation, nullptr); - EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex()); - memoryManager->freeGraphicsMemory(gfxAllocation); - } + gfxAllocation = memoryManager->createGraphicsAllocationFromSharedHandle((osHandle)0u, properties, true); + ASSERT_NE(gfxAllocation, nullptr); + EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex()); + memoryManager->freeGraphicsMemory(gfxAllocation); } } } diff --git a/opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h b/opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h index 2b4132345a..fa7df13367 100644 --- a/opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h +++ b/opencl/test/unit_test/mocks/linux/mock_drm_memory_manager.h @@ -40,12 +40,15 @@ class TestedDrmMemoryManager : public MemoryManagerCreate { using DrmMemoryManager::AllocationData; using DrmMemoryManager::allocUserptr; using DrmMemoryManager::createGraphicsAllocation; + using DrmMemoryManager::createSharedBufferObject; + using DrmMemoryManager::eraseSharedBufferObject; using DrmMemoryManager::getDefaultDrmContextId; using DrmMemoryManager::getDrm; using DrmMemoryManager::gfxPartitions; using DrmMemoryManager::lockResourceInLocalMemoryImpl; using DrmMemoryManager::pinBBs; using DrmMemoryManager::pinThreshold; + using DrmMemoryManager::pushSharedBufferObject; using DrmMemoryManager::releaseGpuRange; using DrmMemoryManager::setDomainCpu; using DrmMemoryManager::sharingBufferObjects; diff --git a/shared/source/gmm_helper/gmm.cpp b/shared/source/gmm_helper/gmm.cpp index 021754ba7d..71d69472d2 100644 --- a/shared/source/gmm_helper/gmm.cpp +++ b/shared/source/gmm_helper/gmm.cpp @@ -57,6 +57,8 @@ Gmm::Gmm(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmm) : clientC gmmResourceInfo.reset(GmmResourceInfo::create(clientContext, inputGmm)); } +Gmm::~Gmm() = default; + Gmm::Gmm(GmmClientContext *clientContext, ImageInfo &inputOutputImgInfo, StorageInfo storageInfo) : clientContext(clientContext) { this->resourceParams = {}; setupImageResourceParams(inputOutputImgInfo); diff --git a/shared/source/gmm_helper/gmm.h b/shared/source/gmm_helper/gmm.h index 36ee0bf64c..6e131df373 100644 --- a/shared/source/gmm_helper/gmm.h +++ b/shared/source/gmm_helper/gmm.h @@ -23,7 +23,7 @@ class GmmClientContext; class Gmm { public: - virtual ~Gmm() = default; + virtual ~Gmm(); Gmm() = delete; Gmm(GmmClientContext *clientContext, ImageInfo &inputOutputImgInfo, StorageInfo storageInfo); Gmm(GmmClientContext *clientContext, const void *alignedPtr, size_t alignedSize, bool uncacheable);